TDME2  1.9.200
LogicMiniScript.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <array>
4 #include <memory>
5 #include <string>
6 #include <unordered_map>
7 #include <unordered_set>
8 #include <vector>
9 
10 #include <tdme/tdme.h>
14 #include <tdme/engine/Transform.h>
18 
19 using std::array;
20 using std::string;
21 using std::unique_ptr;
22 using std::unordered_map;
23 using std::unordered_set;
24 using std::vector;
25 
35 
36 /**
37  * Logic mini script
38  */
40  friend class MiniScriptLogic;
41 
42 protected:
43  STATIC_DLL_IMPEXT static const vector<string> CONTEXTFUNCTIONS_ENGINE;
44  STATIC_DLL_IMPEXT static const vector<string> CONTEXTFUNCTIONS_LOGIC;
45  STATIC_DLL_IMPEXT static const vector<string> CONTEXTFUNCTIONS_ENGINELOGIC;
46 
47  Context* context { nullptr };
48  MiniScriptLogic* logic { nullptr };
49 
50  // keys
51  unordered_set<int32_t> keyboardChars;
52  unordered_set<int32_t> keyboardKeys;
54  bool keyboardMetaDown { false };
55  bool keyboardControlDown { false };
56  bool keyboardAltDown { false };
57  bool keyboardShiftDown { false };
58 
59  // mouse
60  int mouseX { -1 };
61  int mouseY { -1 };
62  int mouseXUnscaled { -1 };
63  int mouseYUnscaled { -1 };
64  array<bool, 8> mouseDown {{ false, false, false, false, false, false, false, false }};
65  array<bool, 8> mouseUp {{ false, false, false, false, false, false, false, false }};
66  array<bool, 8> mouseDragging {{ false, false, false, false, false, false, false, false }};
67  bool mouseMoved = false;
68  float mouseWheelX { 0.0f };
69  float mouseWheelY { 0.0f };
70  float mouseWheelZ { 0.0f };
71 
73  int counter;
74  unique_ptr<Prototype> prototype;
75  };
76  unordered_map<string, PrototypeCounter> prototypes;
77 
78  struct PrototypeToAdd {
79  enum Type {
82  };
84  Type type,
86  const string& id,
87  const string& attachNodeId,
88  const Transform& transform,
89  const string& hierarchyId,
90  const string& hierarchyParentId
91  ):
92  type(type),
94  id(id),
99  {}
101  Prototype* prototype { nullptr };
102  string id;
103  string attachNodeId;
105  string hierarchyId;
107  };
109  vector<PrototypeToAdd> enginePrototypesToAdd;
110  vector<PrototypeToAdd> physicsPrototypesToAdd;
111 
112  /**
113  * Set context
114  * @param context context
115  */
116  inline void setContext(Context* context) {
117  this->context = context;
118  }
119 
120  /**
121  * Set logic
122  * @param logic logic
123  */
125  this->logic = logic;
126  }
127 
128  /**
129  * Get entity by given entity id and given child entity id, the latter expects a entity hierarchy to resolve given child entity
130  * @param entityId entity id
131  * @param childEntityId child entity id
132  */
133  Entity* getEntity(const string& entityId, const string& childEntityId);
134 
135 public:
136  // forbid class copy
138 
139  /**
140  * Public constructor
141  */
142  LogicMiniScript();
143 
144  /**
145  * Destructor
146  */
147  virtual ~LogicMiniScript();
148 
149  // overridden methods
150  const string getBaseClass();
151  const vector<string> getTranspilationUnits();
152  void registerStateMachineStates() override;
153  void registerMethods() override;
154  void registerVariables() override;
155 
156  /**
157  * Collect HID events
158  * @param mouseEvents mouse events
159  * @param keyEvents keyboard events
160  */
161  void collectHIDEvents(vector<GUIMouseEvent>& mouseEvents, vector<GUIKeyboardEvent>& keyEvents);
162 
163 };
Engine entity.
Definition: Entity.h:30
Transform which contain scale, rotations and translation.
Definition: Transform.h:29
Entity * getEntity(const string &entityId, const string &childEntityId)
Get entity by given entity id and given child entity id, the latter expects a entity hierarchy to res...
void setContext(Context *context)
Set context.
void setLogic(MiniScriptLogic *logic)
Set logic.
static STATIC_DLL_IMPEXT const vector< string > CONTEXTFUNCTIONS_ENGINE
vector< PrototypeToAdd > enginePrototypesToAdd
void collectHIDEvents(vector< GUIMouseEvent > &mouseEvents, vector< GUIKeyboardEvent > &keyEvents)
Collect HID events.
static STATIC_DLL_IMPEXT const vector< string > CONTEXTFUNCTIONS_LOGIC
unordered_set< int32_t > keyboardKeys
vector< PrototypeToAdd > physicsPrototypesToAdd
unordered_map< string, PrototypeCounter > prototypes
const vector< string > getTranspilationUnits()
unordered_set< int32_t > keyboardChars
static STATIC_DLL_IMPEXT const vector< string > CONTEXTFUNCTIONS_ENGINELOGIC
Rigid body class.
Definition: Body.h:41
Prototype definition.
Definition: Prototype.h:55
Mutex implementation.
Definition: Mutex.h:19
PrototypeToAdd(Type type, Prototype *prototype, const string &id, const string &attachNodeId, const Transform &transform, const string &hierarchyId, const string &hierarchyParentId)
#define STATIC_DLL_IMPEXT
Definition: tdme.h:15
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6