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  ScValue *_operand;
55  ScValue *_reg1;
56  bool _freezable;
57  bool resume();
58  bool pause();
59  bool canHandleEvent(const Common::String &eventName) const;
60  bool canHandleMethod(const Common::String &methodName) const;
61  bool createThread(ScScript *original, uint32 initIP, const Common::String &eventName);
62  bool createMethodThread(ScScript *original, const Common::String &methodName);
63  ScScript *invokeEventHandler(const Common::String &eventName, bool unbreakable = false);
64  uint32 _timeSlice;
65  DECLARE_PERSISTENT(ScScript, BaseClass)
66  void afterLoad();
67  void runtimeError(const char *fmt, ...);
68  bool run();
69  bool finish(bool includingThreads = false);
70  bool sleep(uint32 duration);
71  bool waitForExclusive(BaseObject *object);
72  bool waitFor(BaseObject *object);
73  uint32 _waitTime;
74  bool _waitFrozen;
75  BaseObject *_waitObject;
76  ScScript *_waitScript;
77  TScriptState _state;
78  TScriptState _origState;
79  ScValue *getVar(char *name);
80  uint32 getFuncPos(const Common::String &name);
81  uint32 getEventPos(const Common::String &name) const;
82  uint32 getMethodPos(const Common::String &name) const;
83  typedef struct {
84  uint32 magic;
85  uint32 version;
86  uint32 codeStart;
87  uint32 funcTable;
88  uint32 symbolTable;
89  uint32 eventTable;
90  uint32 externalsTable;
91  uint32 methodTable;
92  } TScriptHeader;
93 
94  TScriptHeader _header{};
95 
96  typedef struct {
97  char *name;
98  uint32 pos;
99  } TFunctionPos;
100 
101  typedef struct {
102  char *name;
103  uint32 pos;
104  } TMethodPos;
105 
106  typedef struct {
107  char *name;
108  uint32 pos;
109  } TEventPos;
110 
111  typedef struct {
112  char *name;
113  char *dll_name;
114  TCallType call_type;
115  TExternalType returns;
116  int32 nu_params;
117  TExternalType *params;
119 
120 
121  ScStack *_callStack;
122  ScStack *_thisStack;
123  ScStack *_scopeStack;
124  ScStack *_stack;
125  ScValue *_globals;
126  ScEngine *_engine;
127  int32 _currentLine;
128  virtual bool executeInstruction();
129  char *getString();
130  uint32 getDWORD();
131  double getFloat();
132  void cleanup();
133  bool create(const char *filename, byte *buffer, uint32 size, BaseScriptHolder *owner);
134  uint32 _iP;
135  void readHeader();
136  uint32 _bufferSize;
137  byte *_buffer;
138  Common::SeekableReadStream *_scriptStream;
139  ScScript(BaseGame *inGame, ScEngine *engine);
140  ~ScScript() override;
141  char *_filename;
142  char **_symbols;
143  uint32 _numSymbols;
144  TFunctionPos *_functions;
145  TMethodPos *_methods;
146  TEventPos *_events;
147  uint32 _numExternals;
148  TExternalFunction *_externals;
149  uint32 _numFunctions;
150  uint32 _numMethods;
151  uint32 _numEvents;
152  bool _thread;
153  bool _methodThread;
154  char *_threadEvent;
155  BaseScriptHolder *_owner;
156  ScScript::TExternalFunction *getExternal(char *name);
157  bool externalCall(ScStack *stack, ScStack *thisStack, ScScript::TExternalFunction *function);
158 private:
159 
160  bool initScript();
161  bool initTables();
162 
163  virtual void preInstHook(uint32 inst);
164  virtual void postInstHook(uint32 inst);
165 
166 #ifdef ENABLE_FOXTAIL
167  TOpcodesType _opcodesType;
168  void initOpcodesType();
169  uint32 decodeAltOpcodes(uint32 inst);
170 #endif
171 
172  bool _enableFloatCompareWA{};
173 };
174 
175 } // End of namespace Wintermute
176 
177 #endif
Definition: script.h:44
Definition: base_game.h:75
Definition: script_value.h:42
Definition: str.h:59
Definition: script.h:96
Definition: stream.h:745
Definition: script_stack.h:41
Definition: script.h:101
Definition: script.h:106
Definition: base_script_holder.h:37
Definition: base.h:43
Definition: script_engine.h:42
Definition: base_object.h:49
Definition: achievements_tables.h:27