ScummVM API documentation
ws_machine.h
1 
2 /* ScummVM - Graphic Adventure Engine
3  *
4  * ScummVM is the legal property of its developers, whose names
5  * are too numerous to list here. Please refer to the COPYRIGHT
6  * file distributed with this source distribution.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef M4_WSCRIPT_WS_MACHINE_H
24 #define M4_WSCRIPT_WS_MACHINE_H
25 
26 #include "common/algorithm.h"
27 #include "m4/m4_types.h"
28 #include "m4/gui/gui.h"
29 
30 namespace M4 {
31 
32 #define DEAD_MACHINE_ID 0xdeaddead
33 
34 enum {
35  NOSEPICK = 0,
36  STARTWALK = 1,
37  WALKSEQ = 2,
38  ENDWALK = 3,
39  DEMAND_FACING = 4,
40  DEMAND_LOCATION = 5,
41  TERMINATE = 6,
42  PLAYER_HIDE = 7,
43  PLAYER_UNHIDE = 8,
44  TURN_TO_FACE = 9,
45  ACTION_11 = 11,
46  ACTION_12 = 12,
47  ACTION_13 = 13,
48  ACTION_14 = 14,
49  ACTION_15 = 15,
50  ACTION_17 = 17,
51  ACTION_18 = 18,
52  ACTION_19 = 19,
53  ACTION_20 = 20,
54  ACTION_21 = 21,
55  ACTION_22 = 22,
56  ACTION_23 = 23,
57  ACTION_24 = 24,
58  ACTION_25 = 25,
59  ACTION_26 = 26,
60  ACTION_27 = 27,
61  ACTION_28 = 28,
62  ACTION_29 = 29,
63  ACTION_30 = 30,
64  ACTION_31 = 31,
65  ACTION_32 = 32,
66  ACTION_33 = 33,
67  ACTION_666 = 666
68 };
69 
70 // A message request
71 struct msgRequest {
72  msgRequest *nextMsg = nullptr;
73  uint32 msgHash = 0;
74  frac16 msgValue = 0;
75  int32 pcOffset = 0;
76  int32 pcCount = 0;
77 };
78 
79 struct machine;
80 typedef void (*MessageCB)(frac16 myMessage, struct machine *sender);
81 
82 //timebase request structure.
83 struct onTimeReq {
84  onTimeReq *next = nullptr;
85  int32 myTime = 0;
86  struct machine *myXM = nullptr;
87  int32 pcOffset = 0;
88  int32 pcCount = 0;
89 };
90 
91 // rails algorithm struct
92 struct railNode {
93  uint8 nodeID = 0;
94  int32 x = 0, y = 0;
95  railNode *shortPath = nullptr;
96  int32 pathWeight = 0;
97 };
98 
99 struct CCB {
100  uint32 flags = 0;
101  M4sprite *source = nullptr;
102  M4Rect *currLocation = nullptr;
103  M4Rect *newLocation = nullptr;
104  M4Rect *maxArea = nullptr;
105  int32 scaleX = 0;
106  int32 scaleY = 0;
107  int32 layer = 0;
108  uint32 *streamSSHeader = nullptr;
109  uint32 *streamSpriteSource = nullptr;
110  void *myStream = nullptr;
111  char *seriesName = nullptr;
112 };
113 
114 #define JSR_STACK_MAX 8
115 struct Anim8 {
116  machine *myMachine = nullptr; // Pointer back to myMachine
117  int32 eosReqOffset = 0; // The machine PC offset to be executed at the EOS
118  int32 eosReqCount = 0;
119  Anim8 *next = nullptr; // The linked list used for execution order
120  Anim8 *prev = nullptr;
121  int32 myLayer = 0;
122  Anim8 *infront = nullptr; // The linked list used for layering
123  Anim8 *behind = nullptr;
124  Anim8 *myParent = nullptr; // The parent anim8
125  int32 sequHash = 0; // The current sequence Hash = 0;
126  MemHandle sequHandle = nullptr; // The sequence Handle
127  int32 pcOffset = 0; // The offset into the sequence of the current PC
128  CCB *myCCB = nullptr;
129  int32 dataHash = 0; // The array of data
130  MemHandle dataHandle = nullptr;
131  int32 dataOffset = 0;
132  int32 startTime = 0;
133  int32 switchTime = 0;
134  frac16 transTime = 0;
135  int32 flags = 0;
136  frac16 start_s = 0;
137  frac16 start_r = 0;
138  frac16 start_x = 0;
139  frac16 start_y = 0;
140  int32 numLocalVars = 0;
141  frac16 *myRegs = nullptr;
142  bool active = false;
143  int32 returnStackIndex = 0;
144  uint32 returnHashes[JSR_STACK_MAX] = { 0 };
145  int32 returnOffsets[JSR_STACK_MAX] = { 0 };
146 
147  Anim8() {
148  Common::fill(returnHashes, returnHashes + JSR_STACK_MAX, 0);
149  Common::fill(returnOffsets, returnOffsets + JSR_STACK_MAX, 0);
150  }
151 };
152 
153 struct machine {
154  machine *next = nullptr;
155  machine *prev = nullptr;
156  uint32 myHash = 0;
157  uint32 machID = 0;
158  char *machName = nullptr;
159  MemHandle machHandle = 0;
160  int32 machInstrOffset = 0;
161  int32 stateTableOffset = 0;
162  int32 curState = 0;
163  int32 numOfStates = 0;
164  uint32 recurseLevel = 0;
165  Anim8 *myAnim8 = nullptr;
166  Anim8 *parentAnim8 = nullptr;
167  int32 dataHash = 0;
168  MemHandle dataHandle = 0;
169  int32 dataOffset = 0;
170  int32 targetCount = 0;
171  struct machine *msgReplyXM = nullptr;
172  MessageCB CintrMsg;
173  msgRequest *myMsgs = nullptr;
174  msgRequest *myPersistentMsgs = nullptr;
175  msgRequest *usedPersistentMsgs = nullptr;
176  railNode *walkPath = nullptr;
177 };
178 
179 struct globalMsgReq {
180  globalMsgReq *next = nullptr;
181  ulong msgHash = 0;
182  frac16 msgValue = 0;
183  ulong machHash = 0;
184  machine *sendM = nullptr;
185  int32 msgCount = 0;
186 };
187 
189  int32 _pauseTime = 0;
190  int32 _oldTime = 0;
191  bool _enginesPaused = false;
192 
193  int32 *_dataFormats = nullptr;
194  uint32 _machineIDCount = 0;
195  machine *_firstMachine = nullptr;
196 
197  machine *_nextXM = nullptr;
198  globalMsgReq *_myGlobalMessages = nullptr;
199 
200  // Used for processing pCodes
201  frac16 *_ws_globals = nullptr;
202  void *_addrExists = nullptr;
203 };
204 
205 bool ws_Initialize(frac16 *theGlobals);
206 void ws_Shutdown();
207 void pauseEngines();
208 void unpauseEngines();
209 void addPauseTime(int32 myTime);
210 
211 void cycleEngines(Buffer *cleanBackground, int16 *depth_table, Buffer *screenCodes,
212  uint8 *myPalette, uint8 *ICT, bool updateVideo);
213 void ws_RefreshWoodscriptBuffer(Buffer *cleanBackground, int16 *depth_table,
214  Buffer *screenCodes, uint8 *myPalette, uint8 *ICT);
215 
216 void terminateMachine(machine *m);
217 void terminateMachinesByHash(uint32 machHash);
218 void terminateMachineAndNull(machine *&m);
219 bool verifyMachineExists(machine *m);
220 int32 ws_KillMachines();
221 void ws_KillDeadMachines();
222 void ws_StepWhile(machine *m, int32 pcOffset, int32 pcCount);
223 void IntoTheState(machine *m);
224 machine *TriggerMachineByHash(int32 myHash, Anim8 *parentAnim8, int32 dataHash, int32 dataRow, MessageCB CintrMsg, bool debug, const char *machName);
225 machine *TriggerMachineByHash(int32 val1, int32 val2, int32 val3, int32 val4, int32 val5, int32 val6,
226  int32 x, int32 y, int32 scale, int32 layer, bool flag,
227  MessageCB intrMsg, const char *machName);
228 machine *TriggerMachineByHash(MessageCB intrMsg, const char *machName);
229 
233 void sendWSMessage(uint32 msgHash, frac16 msgValue, machine *recvM,
234  uint32 machHash, machine *sendM, int32 msgCount);
235 void sendWSMessage(int32 val1, machine *recv, int32 series1, int32 val3, int32 val4,
236  int32 trigger, int32 series2, int32 val6, int32 val7, int32 val8);
237 
238 #define kernel_spawn_machine(name,hash,callback) TriggerMachineByHash(hash, nullptr, -1, -1, callback, false, name)
239 #define kernel_terminate_machine(m) terminateMachine(m)
240 
241 } // End of namespace M4
242 
243 #endif
Definition: ws_machine.h:153
Definition: ws_machine.h:83
Definition: ws_machine.h:115
Definition: ws_machine.h:71
intptr frac16
Definition: m4_types.h:46
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
void debug(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: m4_types.h:67
Definition: database.h:28
Definition: gui.h:31
Definition: ws_machine.h:179
Definition: ws_machine.h:188
signed char * fill(signed char *first, signed char *last, Value val)
Definition: algorithm.h:168
Definition: ws_machine.h:92
Definition: ws_machine.h:99
Definition: gui.h:52
void sendWSMessage(uint32 msgHash, frac16 msgValue, machine *recvM, uint32 machHash, machine *sendM, int32 msgCount)