1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef SCI_ENGINE_SELECTOR_H
24 #define SCI_ENGINE_SELECTOR_H
25 
26 #include "common/scummsys.h"
27 
28 #include "sci/engine/vm_types.h"	// for reg_t
29 #include "sci/engine/vm.h"
30 
31 namespace Sci {
32 
33 /** Contains selector IDs for a few selected selectors */
34 struct SelectorCache {
SelectorCacheSelectorCache35 	SelectorCache() {
36 		memset(this, 0, sizeof(*this));
37 	}
38 
39 	// Statically defined selectors, (almost the) same in all SCI versions
40 	Selector _info_;	///< Removed in SCI3
41 	Selector y;
42 	Selector x;
43 	Selector view, loop, cel; ///< Description of a specific image
44 	Selector underBits; ///< Used by the graphics subroutines to store backupped BG pic data
45 	Selector nsTop, nsLeft, nsBottom, nsRight; ///< View boundaries ('now seen')
46 	Selector lsTop, lsLeft, lsBottom, lsRight; ///< Used by Animate() subfunctions and scroll list controls
47 	Selector signal; ///< Used by Animate() to control a view's behavior
48 	Selector illegalBits; ///< Used by CanBeHere
49 	Selector brTop, brLeft, brBottom, brRight; ///< Bounding Rectangle
50 	// name, key, time
51 	Selector text; ///< Used by controls
52 	Selector elements; ///< Used by SetSynonyms()
53 	// color, back
54 	Selector mode; ///< Used by text controls (-> DrawControl())
55 	// style
56 	Selector state, font, type;///< Used by controls
57 	// window
58 	Selector cursor; ///< Used by EditControl
59 	Selector max; ///< Used by EditControl, removed in SCI3
60 	Selector mark; //< Used by list controls (script internal, is needed by us for the QfG import rooms)
61 	Selector sort; //< Used by list controls (script internal, is needed by us for QfG3 import room)
62 	// who
63 	Selector message; ///< Used by GetEvent
64 	// edit
65 	Selector play; ///< Play function (first function to be called)
66 	Selector restore;
67 	Selector number;
68 	Selector handle;	///< Replaced by nodePtr in SCI1+
69 	Selector nodePtr;	///< Replaces handle in SCI1+
70 	Selector client; ///< The object that wants to be moved
71 	Selector dx, dy; ///< Deltas
72 	Selector b_movCnt, b_i1, b_i2, b_di, b_xAxis, b_incr; ///< Various Bresenham vars
73 	Selector xStep, yStep; ///< BR adjustments
74 	Selector xLast, yLast; ///< BR last position of client
75 	Selector moveSpeed; ///< Used for DoBresen
76 	Selector canBeHere; ///< Funcselector: Checks for movement validity in SCI0
77 	Selector heading, mover; ///< Used in DoAvoider
78 	Selector doit; ///< Called (!) by the Animate() system call
79 	Selector isBlocked, looper;	///< Used in DoAvoider
80 	Selector priority;
81 	Selector modifiers; ///< Used by GetEvent
82 	Selector replay; ///< Replay function
83 	// setPri, at, next, done, width
84 	Selector wordFail, syntaxFail; ///< Used by Parse()
85 	// semanticFail, pragmaFail
86 	// said
87 	Selector claimed; ///< Used generally by the event mechanism
88 	// value, save, restore, title, button, icon, draw
89 	Selector delete_; ///< Called by Animate() to dispose a view object
90 	Selector z;
91 	Selector setPri;
92 
93 	// SCI1+ static selectors
94 	Selector parseLang;
95 	Selector printLang; ///< Used for i18n
96 	Selector subtitleLang;
97 	Selector size;
98 	Selector points; ///< Used by AvoidPath()
99 	Selector palette;	///< Used by the SCI0-SCI1.1 animate code, unused in SCI2-SCI2.1, removed in SCI3
100 	Selector dataInc;	///< Used to sync music with animations, removed in SCI3
101 	// handle (in SCI1)
102 	Selector min; ///< SMPTE time format
103 	Selector sec;
104 	Selector frame;
105 	Selector vol;
106 	Selector pri;
107 	// perform
108 	Selector moveDone;	///< used for DoBresen
109 
110 	// SCI1 selectors which have been moved a bit in SCI1.1, but otherwise static
111 	Selector cantBeHere; ///< Checks for movement avoidance in SCI1+. Replaces canBeHere
112 	Selector topString; ///< SCI1 scroll lists use this instead of lsTop. Removed in SCI3
113 	Selector flags;
114 
115 	// SCI1+ audio sync related selectors, not static. They're used for lip syncing in
116 	// CD talkie games
117 	Selector syncCue; ///< Used by DoSync()
118 	Selector syncTime;
119 
120 	// SCI1.1 specific selectors
121 	Selector scaleSignal; //< Used by kAnimate() for cel scaling (SCI1.1+)
122 	Selector scaleX, scaleY;	///< SCI1.1 view scaling
123 	Selector maxScale;		///< SCI1.1 view scaling, limit for cel, when using global scaling
124 	Selector vanishingX;	///< SCI1.1 view scaling, used by global scaling
125 	Selector vanishingY;	///< SCI1.1 view scaling, used by global scaling
126 
127 	// Used for auto detection purposes
128 	Selector overlay;	///< Used to determine if a game is using old gfx functions or not
129 
130 	// SCI1.1 Mac icon bar selectors
131 	Selector iconIndex; ///< Used to index icon bar objects
132 	Selector select;
133 
134 	Selector handsOff;
135 	Selector setStep;
136 	Selector setMotion;
137 	Selector cycleSpeed;
138 	Selector owner;
139 
140 	Selector curPos; // for LSL6 volume sync
141 	Selector update; // for LSL6 volume sync
142 
143 #ifdef ENABLE_SCI32
144 	Selector data; // Used by Array()/String()
145 	Selector picture; // Used to hold the picture ID for SCI32 pictures
146 	Selector bitmap; // Used to hold the text bitmap for SCI32 texts
147 
148 	Selector plane;
149 	Selector top, left, bottom, right;
150 	Selector resX, resY;
151 
152 	Selector fore;
153 	Selector back;
154 	Selector skip;
155 	Selector dimmed;
156 	Selector borderColor;
157 	Selector width;
158 
159 	Selector fixPriority;
160 	Selector mirrored;
161 	Selector visible;
162 
163 	Selector seenRect;
164 	Selector useInsetRect;
165 	Selector inTop, inLeft, inBottom, inRight;
166 	Selector textTop, textLeft, textBottom, textRight;
167 	Selector title, titleFont, titleFore, titleBack;
168 
169 	Selector magnifier;
170 	Selector frameOut;
171 	Selector casts; // needed for sync'ing screen items/planes with scripts, when our save/restore code is patched in (see GfxFrameout::syncWithScripts)
172 	Selector setVol; // for GK2 volume sync on restore
173 	Selector reSyncVol; // for Torin volume sync on restore
174 	Selector set; // for LSL6hires subtitle sync
175 	Selector clear; // for LSL6hires subtitle sync
176 	Selector show; // for GK1 volume sync
177 	Selector position; // for GK1 volume sync
178 	Selector musicVolume; // for GK1 volume sync
179 	Selector soundVolume; // for GK1 volume sync
180 	Selector initialOff; // for GK2 volume sync
181 	Selector setPos; // for Torin volume sync
182 	Selector setSize; // for PQ4 volume sync
183 	Selector displayValue; // for PQ:SWAT volume sync
184 	Selector new_; // for Torin/LSL7 save/load patching
185 	Selector mainCel; // for MGDX volume sync
186 	Selector move; // for Phant2 volume sync
187 	Selector eachElementDo; // for Phant2 volume sync
188 	Selector physicalBar; // for Phant2 volume sync
189 	Selector init; // for Phant2 save/load patching
190 	Selector scratch; // for Phant2 save/load patching
191 	Selector num; // for Phant2 restore from launcher
192 	Selector reallyRestore; // for Phant2 restore from launcher
193 	Selector canInput; // for Phant2 restore from launcher
194 	Selector bookMark; // for Phant2 auto-save
195 	Selector fileNumber; // for RAMA save/load
196 	Selector description; // for RAMA save/load
197 	Selector dispose; // for RAMA save/load save from launcher
198 	Selector masterVolume; // for RAMA volume sync
199 	Selector setCel; // for RAMA volume sync
200 	Selector value; // for QFG4 import dialog
201 #endif
202 };
203 
204 /**
205  * Map a selector name to a selector id. Shortcut for accessing the selector cache.
206  */
207 #define SELECTOR(_slc_)		(g_sci->getKernel()->_selectorCache._slc_)
208 
209 /**
210  * Retrieves a selector from an object.
211  * @param segMan	the segment mananger
212  * @param _obj_		the address of the object which the selector should be read from
213  * @param _slc_		the selector to refad
214  * @return			the selector value as a reg_t
215  * This macro halts on error. 'selector' must be a selector name registered in vm.h's
216  * SelectorCache and mapped in script.cpp.
217  */
218 reg_t readSelector(SegManager *segMan, reg_t object, Selector selectorId);
219 #define readSelectorValue(segMan, _obj_, _slc_) (readSelector(segMan, _obj_, _slc_).getOffset())
220 
221 /**
222  * Writes a selector value to an object.
223  * @param segMan	the segment mananger
224  * @param _obj_		the address of the object which the selector should be written to
225  * @param _slc_		the selector to read
226  * @param _val_		the value to write
227  * This macro halts on error. 'selector' must be a selector name registered in vm.h's
228  * SelectorCache and mapped in script.cpp.
229  */
230 void writeSelector(SegManager *segMan, reg_t object, Selector selectorId, reg_t value);
231 #define writeSelectorValue(segMan, _obj_, _slc_, _val_) writeSelector(segMan, _obj_, _slc_, make_reg(0, _val_))
232 
233 /**
234  * Invokes a selector from an object.
235  */
236 void invokeSelector(EngineState *s, reg_t object, int selectorId,
237 	int k_argc, StackPtr k_argp, int argc = 0, const reg_t *argv = 0);
238 
239 #ifdef ENABLE_SCI32
240 /**
241  * SCI32 set kInfoFlagViewVisible in the -info- selector if a certain
242  * range of properties was written to.
243  * This function checks if index is in the right range, and sets the flag
244  * on obj.-info- if it is.
245  */
246 void updateInfoFlagViewVisible(Object *obj, int index, bool fromPropertyOp = false);
247 #endif
248 
249 } // End of namespace Sci
250 
251 #endif // SCI_ENGINE_KERNEL_H
252