ScummVM API documentation
script.h
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 modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * This file is based on WME Lite.
24  * http://dead-code.org/redir.php?target=wmelite
25  * Copyright (c) 2011 Jan Nedoma
26  */
27 
28 #ifndef WINTERMUTE_SCSCRIPT_H
29 #define WINTERMUTE_SCSCRIPT_H
30 
31 
32 #include "engines/wintermute/base/base.h"
33 #include "engines/wintermute/base/scriptables/dcscript.h" // Added by ClassView
34 #include "engines/wintermute/coll_templ.h"
35 #include "engines/wintermute/persistent.h"
36 
37 namespace Wintermute {
38 class BaseScriptHolder;
39 class BaseObject;
40 class ScEngine;
41 class ScStack;
42 class ScValue;
43 
44 class ScScript : public BaseClass {
45 public:
46  BaseArray<int> _breakpoints;
47  bool _tracingMode;
48 
49  ScScript *_parentScript;
50  bool _unbreakable;
51  bool finishThreads();
52  bool copyParameters(ScStack *stack);
53 
54  void afterLoad();
55 
56  ScValue *_operand;
57  ScValue *_reg1;
58  bool _freezable;
59  bool resume();
60  bool pause();
61  bool canHandleEvent(const char *eventName);
62  bool canHandleMethod(const char *methodName);
63  bool createThread(ScScript *original, uint32 initIP, const char *eventName);
64  bool createMethodThread(ScScript *original, const char *methodName);
65  ScScript *invokeEventHandler(const char *eventName, bool unbreakable = false);
66  uint32 _timeSlice;
67  DECLARE_PERSISTENT(ScScript, BaseClass)
68  void runtimeError(const char *fmt, ...);
69  bool run();
70  bool finish(bool includingThreads = false);
71  bool sleep(uint32 duration);
72  bool waitForExclusive(BaseObject *object);
73  bool waitFor(BaseObject *object);
74  uint32 _waitTime;
75  bool _waitFrozen;
76  BaseObject *_waitObject;
77  ScScript *_waitScript;
78  TScriptState _state;
79  TScriptState _origState;
80  ScValue *getVar(char *name);
81  uint32 getFuncPos(const char *name);
82  uint32 getEventPos(const char *name);
83  uint32 getMethodPos(const char *name);
84  typedef struct {
85  uint32 magic;
86  uint32 version;
87  uint32 codeStart;
88  uint32 funcTable;
89  uint32 symbolTable;
90  uint32 eventTable;
91  uint32 externalsTable;
92  uint32 methodTable;
93  } TScriptHeader;
94 
95  TScriptHeader _header{};
96 
97  typedef struct {
98  char *name;
99  uint32 pos;
100  } TFunctionPos;
101 
102  typedef struct {
103  char *name;
104  uint32 pos;
105  } TMethodPos;
106 
107  typedef struct {
108  char *name;
109  uint32 pos;
110  } TEventPos;
111 
112  typedef struct {
113  char *name;
114  char *dll_name;
115  TCallType call_type;
116  TExternalType returns;
117  int32 numParams;
118  TExternalType *params;
120 
121 
122  ScStack *_callStack;
123  ScStack *_thisStack;
124  ScStack *_scopeStack;
125  ScStack *_stack;
126  ScValue *_globals;
127  ScEngine *_engine;
128  int32 _currentLine;
129  virtual bool executeInstruction();
130  char *getString();
131  uint32 getDWORD();
132  double getFloat();
133  void cleanup();
134  bool create(const char *filename, byte *buffer, uint32 size, BaseScriptHolder *owner);
135  uint32 _iP;
136  void readHeader();
137  uint32 _bufferSize;
138  byte *_buffer;
139  Common::SeekableReadStream *_scriptStream;
140  ScScript(BaseGame *inGame, ScEngine *engine);
141  ~ScScript() override;
142  char *_filename;
143  char **_symbols;
144  uint32 _numSymbols;
145  TFunctionPos *_functions;
146  TMethodPos *_methods;
147  TEventPos *_events;
148  uint32 _numExternals;
149  TExternalFunction *_externals;
150  uint32 _numFunctions;
151  uint32 _numMethods;
152  uint32 _numEvents;
153  bool _thread;
154  bool _methodThread;
155  char *_threadEvent;
156  BaseScriptHolder *_owner;
157  ScScript::TExternalFunction *getExternal(char *name);
158  bool externalCall(ScStack *stack, ScStack *thisStack, ScScript::TExternalFunction *function);
159 private:
160 
161  bool initScript();
162  bool initTables();
163 
164  virtual void preInstHook(uint32 inst);
165  virtual void postInstHook(uint32 inst);
166 
167 #ifdef ENABLE_FOXTAIL
168  TOpcodesType _opcodesType;
169  void initOpcodesType();
170  uint32 decodeAltOpcodes(uint32 inst);
171 #endif
172 
173  bool _enableFloatCompareWA{};
174 };
175 
176 } // End of namespace Wintermute
177 
178 #endif
Definition: script.h:44
Definition: base_game.h:79
Definition: script_value.h:42
Definition: script.h:97
Definition: stream.h:745
Definition: script_stack.h:41
Definition: script.h:102
Definition: script.h:107
Definition: base_script_holder.h:37
Definition: base.h:43
Definition: script_engine.h:43
Definition: base_object.h:49
Definition: achievements_tables.h:27