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