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