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