Voxellancer  0.3
A game about voxels in space
 All Classes Functions Pages
scriptengine.h
1 #pragma once
2 
3 #include <list>
4 #include <memory>
5 #include <unordered_map>
6 
7 
8 class GamePlayScript;
9 class Scriptable;
10 class World;
11 
12 /*
13  Main class for accessing scripts during gameplay.
14  The ScriptEngine connects Scripts with the World by tunneling events from World to the Script
15  and all sorts of actions (Objectcreation, Tasks) back to the World.
16 */
17 class ScriptEngine {
18 public:
19  ScriptEngine(World* world);
20  ~ScriptEngine();
21 
22  void addScript(std::shared_ptr<GamePlayScript> script);
23 
24  /* start (call the "main" function) all added scripts and all future
25  added scripts until stop is called */
26  void start();
27 
28  /* Stops the ScriptEngine, continuing to update after start() is called again. */
29  void stop();
30 
31  /* Register Scriptables that are managed by other objects
32  and equip them with a valid scriptKey */
33  void registerScriptable(Scriptable* scriptable);
34 
35  /* Unregister Scriptable. If it is scriptlocal, remove it from the game */
36  void unregisterScriptable(Scriptable* scriptable);
37 
38 
39  template<class T>
40  T* get(int key);
41 
42  bool keyValid(int key) const;
43 
44  void update(float deltaSec);
45 
46 
47 protected:
48  World* m_world;
49 
50  std::list<std::shared_ptr<GamePlayScript>> m_scripts;
51  std::unordered_map<int, Scriptable*> m_scriptables;
52 
53  int m_keyIncrementor;
54  bool m_running;
55 
56 
57  Scriptable* getScriptable(int key);
58  void performRemovals();
59  void removeScriptable(Scriptable* scriptable);
60 };
61 
62 #include "scriptengine.inl"
Definition: world.h:20
Definition: gameplayscript.h:17
Definition: scriptengine.h:17
Definition: scriptable.h:4