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  HYPERWALK = 747,
69  ACTION_900 = 900,
70  ACTION_902 = 902
71 };
72 
73 // A message request
74 struct msgRequest {
75  msgRequest *nextMsg = nullptr;
76  uint32 msgHash = 0;
77  frac16 msgValue = 0;
78  int32 pcOffset = 0;
79  int32 pcCount = 0;
80 };
81 
82 struct machine;
83 typedef void (*MessageCB)(frac16 myMessage, struct machine *sender);
84 
85 //timebase request structure.
86 struct onTimeReq {
87  onTimeReq *next = nullptr;
88  int32 myTime = 0;
89  struct machine *myXM = nullptr;
90  int32 pcOffset = 0;
91  int32 pcCount = 0;
92 };
93 
94 // rails algorithm struct
95 struct railNode {
96  uint8 nodeID = 0;
97  int32 x = 0, y = 0;
98  railNode *shortPath = nullptr;
99  int32 pathWeight = 0;
100 };
101 
102 struct CCB {
103  uint32 flags = 0;
104  M4sprite *source = nullptr;
105  M4Rect *currLocation = nullptr;
106  M4Rect *newLocation = nullptr;
107  M4Rect *maxArea = nullptr;
108  int32 scaleX = 0;
109  int32 scaleY = 0;
110  int32 layer = 0;
111  uint32 *streamSSHeader = nullptr;
112  uint32 *streamSpriteSource = nullptr;
113  void *myStream = nullptr;
114  char *seriesName = nullptr;
115 };
116 
117 #define JSR_STACK_MAX 8
118 struct Anim8 {
119  machine *myMachine = nullptr; // Pointer back to myMachine
120  int32 eosReqOffset = 0; // The machine PC offset to be executed at the EOS
121  int32 eosReqCount = 0;
122  Anim8 *next = nullptr; // The linked list used for execution order
123  Anim8 *prev = nullptr;
124  int32 myLayer = 0;
125  Anim8 *infront = nullptr; // The linked list used for layering
126  Anim8 *behind = nullptr;
127  Anim8 *myParent = nullptr; // The parent anim8
128  int32 sequHash = 0; // The current sequence Hash = 0;
129  MemHandle sequHandle = nullptr; // The sequence Handle
130  int32 pcOffset = 0; // The offset into the sequence of the current PC
131  CCB *myCCB = nullptr;
132  int32 dataHash = 0; // The array of data
133  MemHandle dataHandle = nullptr;
134  int32 dataOffset = 0;
135  int32 startTime = 0;
136  int32 switchTime = 0;
137  frac16 transTime = 0;
138  int32 flags = 0;
139  frac16 start_s = 0;
140  frac16 start_r = 0;
141  frac16 start_x = 0;
142  frac16 start_y = 0;
143  int32 numLocalVars = 0;
144  frac16 *myRegs = nullptr;
145  bool active = false;
146  int32 returnStackIndex = 0;
147  uint32 returnHashes[JSR_STACK_MAX] = { 0 };
148  int32 returnOffsets[JSR_STACK_MAX] = { 0 };
149 
150  Anim8() {
151  Common::fill(returnHashes, returnHashes + JSR_STACK_MAX, 0);
152  Common::fill(returnOffsets, returnOffsets + JSR_STACK_MAX, 0);
153  }
154 };
155 
156 struct machine {
157  machine *next = nullptr;
158  machine *prev = nullptr;
159  uint32 myHash = 0;
160  uint32 machID = 0;
161  char *machName = nullptr;
162  MemHandle machHandle = nullptr;
163  int32 machInstrOffset = 0;
164  int32 stateTableOffset = 0;
165  int32 curState = 0;
166  int32 numOfStates = 0;
167  uint32 recurseLevel = 0;
168  Anim8 *myAnim8 = nullptr;
169  Anim8 *parentAnim8 = nullptr;
170  int32 dataHash = 0;
171  MemHandle dataHandle = nullptr;
172  int32 dataOffset = 0;
173  int32 targetCount = 0;
174  struct machine *msgReplyXM = nullptr;
175  MessageCB CintrMsg;
176  msgRequest *myMsgs = nullptr;
177  msgRequest *myPersistentMsgs = nullptr;
178  msgRequest *usedPersistentMsgs = nullptr;
179  railNode *walkPath = nullptr;
180 };
181 
182 struct globalMsgReq {
183  globalMsgReq *next = nullptr;
184  ulong msgHash = 0;
185  frac16 msgValue = 0;
186  ulong machHash = 0;
187  machine *sendM = nullptr;
188  int32 msgCount = 0;
189 };
190 
192  int32 _pauseTime = 0;
193  int32 _oldTime = 0;
194  bool _enginesPaused = false;
195 
196  int32 *_dataFormats = nullptr;
197  uint32 _machineIDCount = 0;
198  machine *_firstMachine = nullptr;
199 
200  machine *_nextXM = nullptr;
201  globalMsgReq *_myGlobalMessages = nullptr;
202 
203  // Used for processing pCodes
204  frac16 *_ws_globals = nullptr;
205  void *_addrExists = nullptr;
206 };
207 
208 bool ws_Initialize(frac16 *theGlobals);
209 void ws_Shutdown();
210 void pauseEngines();
211 void unpauseEngines();
212 
213 void cycleEngines(Buffer *cleanBackground, int16 *depth_table, Buffer *screenCodes,
214  uint8 *myPalette, uint8 *ICT, bool updateVideo);
215 void ws_RefreshWoodscriptBuffer(Buffer *cleanBackground, int16 *depth_table,
216  Buffer *screenCodes, uint8 *myPalette, uint8 *ICT);
217 
218 void terminateMachine(machine *m);
219 void terminateMachinesByHash(uint32 machHash);
220 void terminateMachineAndNull(machine *&m);
221 bool verifyMachineExists(machine *m);
222 int32 ws_KillMachines();
223 void ws_KillDeadMachines();
224 void ws_StepWhile(machine *m, int32 pcOffset, int32 pcCount);
225 void IntoTheState(machine *m);
226 machine *TriggerMachineByHash(int32 myHash, Anim8 *parentAnim8, int32 dataHash, int32 dataRow, MessageCB CintrMsg, bool debug, const char *machName);
227 machine *TriggerMachineByHash(int32 val1, int32 val2, int32 val3, int32 val4, int32 val5, int32 val6,
228  int32 x, int32 y, int32 scale, int32 layer, bool flag,
229  MessageCB intrMsg, const char *machName);
230 machine *TriggerMachineByHash(MessageCB intrMsg, const char *machName);
231 
235 void sendWSMessage(uint32 msgHash, frac16 msgValue, machine *recvM,
236  uint32 machHash, machine *sendM, int32 msgCount);
237 void sendWSMessage(int32 val1, machine *recv, int32 series1, int32 val3, int32 val4,
238  int32 trigger, int32 series2, int32 val6, int32 val7, int32 val8);
239 
240 #define kernel_spawn_machine(name,hash,callback) TriggerMachineByHash(hash, nullptr, -1, -1, callback, false, name)
241 #define kernel_terminate_machine(m) terminateMachine(m)
242 
243 } // End of namespace M4
244 
245 #endif
Definition: ws_machine.h:156
Definition: ws_machine.h:86
Definition: ws_machine.h:118
Definition: ws_machine.h:74
intptr frac16
Definition: m4_types.h:45
void debug(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: m4_types.h:54
Definition: database.h:28
Definition: gui.h:31
Definition: ws_machine.h:182
Definition: ws_machine.h:191
signed char * fill(signed char *first, signed char *last, Value val)
Definition: algorithm.h:168
Definition: ws_machine.h:95
Definition: ws_machine.h:102
Definition: gui.h:52
void sendWSMessage(uint32 msgHash, frac16 msgValue, machine *recvM, uint32 machHash, machine *sendM, int32 msgCount)