ScummVM API documentation
script_engine.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_SCENGINE_H
29#define WINTERMUTE_SCENGINE_H
30
31#include "engines/wintermute/persistent.h"
32#include "engines/wintermute/coll_templ.h"
33#include "engines/wintermute/base/base.h"
34#include "engines/wintermute/platform_osystem.h"
35
36namespace Wintermute {
37
38#define MAX_CACHED_SCRIPTS 20
39class ScScript;
40class ScValue;
41class BaseObject;
42class BaseScriptHolder;
43class ScEngine : public BaseClass {
44public:
46 public:
47 CScCachedScript(const char *filename, byte *buffer, uint32 size) {
48 _timestamp = BasePlatform::getTime();
49 _buffer = new byte[size];
50 if (_buffer) {
51 memcpy(_buffer, buffer, size);
52 }
53 _size = size;
54 size_t filenameSize = strlen(filename) + 1;
55 _filename = new char[filenameSize];
56 Common::strcpy_s(_filename, filenameSize, filename);
57 };
58
60 if (_buffer) {
61 delete[] _buffer;
62 }
63 if (_filename)
64 delete[] _filename;
65 };
66
67 uint32 _timestamp;
68 byte *_buffer;
69 uint32 _size;
70 char *_filename;
71 };
72
73public:
74 bool clearGlobals(bool includingNatives = false);
75 bool tickUnbreakable();
76 bool removeFinishedScripts();
77 bool isValidScript(ScScript *script);
78
79 ScScript *_currentScript;
80 bool resumeAll();
81 bool pauseAll();
82 void editorCleanup();
83 bool resetObject(BaseObject *object);
84 bool resetScript(ScScript *script);
85 bool emptyScriptCache();
86 byte *getCompiledScript(const char *filename, uint32 *outSize, bool ignoreCache = false);
87 DECLARE_PERSISTENT(ScEngine, BaseClass)
88 bool cleanup();
89 int getNumScripts(int *running = nullptr, int *waiting = nullptr, int *persistent = nullptr);
90 bool tick();
91 ScValue *_globals;
92 ScScript *runScript(const char *filename, BaseScriptHolder *owner = nullptr);
93 bool isRunningScript(const char *filename);
94 static const bool _compilerAvailable = false;
95
96 ScEngine(BaseGame *inGame);
97 ~ScEngine() override;
98 static byte *loadFile(void *data, char *filename, uint32 *size);
99 static void closeFile(void *data, byte *buffer);
100 static void parseElement(void *data, int line, int type, void *elementData);
101
102 BaseArray<ScScript *> _scripts;
103
104 void enableProfiling();
105 void disableProfiling();
106 bool isProfiling() {
107 return _isProfiling;
108 }
109
110 void addScriptTime(const char *filename, uint32 time);
111 void dumpStats();
112
113private:
114
115 CScCachedScript *_cachedScripts[MAX_CACHED_SCRIPTS];
116 bool _isProfiling;
117 uint32 _profilingStartTime;
118
119 typedef Common::HashMap<Common::String, uint32> ScriptTimes;
120 ScriptTimes _scriptTimes;
121
122};
123
124} // End of namespace Wintermute
125
126#endif
Definition: coll_templ.h:345
Definition: base.h:43
Definition: base_game.h:79
Definition: base_object.h:49
Definition: base_script_holder.h:37
Definition: script_engine.h:45
Definition: script_engine.h:43
Definition: script.h:44
Definition: script_value.h:42
void strcpy_s(char *dst, size_t size, const char *src)