AnnScriptManager.cpp
Go to the documentation of this file.
1 // This is an open source non-commercial project. Dear PVS-Studio, please check it.
2 // PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
3 
4 #include "AnnScriptManager.hpp"
5 #include "AnnLogger.hpp"
6 #include "AnnGameObject.hpp"
8 #include "AnnEngine.hpp"
9 #include "AnnGetter.hpp"
10 #include "Annwvyn.h"
11 
12 using namespace Annwvyn;
13 
14 constexpr const char* const AnnScriptManager::fileErrorPrefix;
15 constexpr const char* const AnnScriptManager::logFromScript;
16 
18  AnnSubSystem("ScriptManager"),
19  scriptFileManager(nullptr)
20 {
21  registerApi();
22  AnnDebug(Log::Important) << "Using ChaiScript version 6.0";
24 }
25 
27 {
28  using namespace Ogre;
29  using namespace chaiscript;
30  using namespace std;
31 
32  // TODO ISSUE Add to chai all the useful types (angles, vectors, quaternions...)
33  try
34  {
35  //Random maths
36  chai.add(var(&Math::PI), "PI");
37  chai.add(var(&Math::HALF_PI), "HALF_PI");
38  chai.add(var(&Math::LOG2), "LOG2");
39  chai.add(var(&Math::TWO_PI), "TWO_PI");
40  chai.add(fun([](const Vector3& a, const Vector3& b, float w) { return Math::lerp(a, b, w); }), "lerp");
41  chai.add(fun([](float a, float b, float w) { return Math::lerp(a, b, w); }), "lerp");
42  chai.add(fun([](float fT, const Quaternion& rkP, const Quaternion& rkQ) { return Quaternion::Slerp(fT, rkP, rkQ); }), "slerp");
43  chai.add(fun([](float f) { return sin(f); }), "sin");
44  chai.add(fun([](float f) { return cos(f); }), "cos");
45  chai.add(fun([](float f) { return tan(f); }), "tan");
46  chai.add(fun([](float f) { return asin(f); }), "asin");
47  chai.add(fun([](float f) { return acos(f); }), "acos");
48  chai.add(fun([](float f) { return atan(f); }), "atan");
49  chai.add(fun([](float y, float x) { return atan2(y, x); }), "atan2");
50 
51  chai.add(fun([] { return AnnGetEngine()->getTimeFromStartUp(); }), "getTimeFromStartUp");
52 
53  // 3D vector
54  chai.add(user_type<Vector3>(), "AnnVect3");
55  chai.add(constructor<Vector3()>(), "AnnVect3");
56  chai.add(constructor<Vector3(float, float, float)>(), "AnnVect3");
57  chai.add(constructor<Vector3(const float[3])>(), "AnnVect3");
58  chai.add(constructor<Vector3(const Vector3&)>(), "AnnVect3");
59  chai.add(fun(&Vector3::x), "x");
60  chai.add(fun(&Vector3::y), "y");
61  chai.add(fun(&Vector3::z), "z");
62  chai.add(fun([](Vector3& u, const Vector3& v) { u = v; }), "=");
63  chai.add(fun([](Vector3& u, const Real s) { u = s; }), "=");
64  chai.add(fun<Vector3>(&Vector3::operator+), "+");
65  chai.add(fun([](const Vector3& v) { return -v; }), "-");
66  chai.add(fun([](const Vector3& v, Vector3 w) { return v - w; }), "-");
67  chai.add(fun([](const Vector3& v, const Real w) { return v - w; }), "-");
68  chai.add(fun([](const Real& v, const Vector3& w) { return v - w; }), "-");
69  chai.add(fun([](const Vector3& vector, Real scalar) { return scalar * vector; }), "*");
70  chai.add(fun([](Real scalar, const Vector3& vector) { return scalar * vector; }), "*");
71  chai.add(fun([](const Vector3& v1, const Vector3& v2) { return v1 * v2; }), "*");
72  chai.add(fun([](const Vector3& vector, Real scalar) { return scalar / vector; }), "/");
73  chai.add(fun([](const Vector3& v1, const Vector3& v2) { return v1 / v2; }), "/");
74  chai.add(fun([](Vector3& u, Vector3 v) { u *= v; }), "*=");
75  chai.add(fun([](Vector3& u, Vector3 v) { u /= v; }), "/=");
76  chai.add(fun([](Vector3& u, Vector3 v) { u += v; }), "+=");
77  chai.add(fun([](Vector3& u, Vector3 v) { u -= v; }), "-=");
78  chai.add(fun([](Vector3& vector, Real scalar) { vector *= scalar; }), "*=");
79  chai.add(fun([](Vector3& vector, Real scalar) { vector /= scalar; }), "/=");
80  chai.add(fun([](Vector3& vector, Real scalar) { vector += scalar; }), "+=");
81  chai.add(fun([](Vector3& vector, Real scalar) { vector -= scalar; }), "-=");
82  chai.add(fun([](const Vector3& v1, const Vector3& v2) { return v1 == v2; }), "==");
83  chai.add(fun([](const Vector3& v1, const Vector3& v2) { return v1 != v2; }), "!=");
84  chai.add(fun([](const Vector3& v1, const Vector3& v2) { return v1 < v2; }), "<");
85  chai.add(fun([](const Vector3& v1, const Vector3& v2) { return v1 > v2; }), ">");
86  chai.add(fun([](const Vector3& v, const size_t i) { return v[i]; }), "[]");
87  chai.add(fun([](Vector3& u, Vector3& v) { u.swap(v); }), "swap");
88  chai.add(fun([](const Vector3& v) { return v.length(); }), "length");
89  chai.add(fun([](const Vector3& v) { return v.normalisedCopy(); }), "normalisedCopy");
90  chai.add(fun([](const Vector3& v) { return v.squaredLength(); }), "squaredLength");
91  chai.add(fun([](const Vector3& v) { return v.perpendicular(); }), "perpendicular");
92  chai.add(fun([](const Vector3& v) { return v.primaryAxis(); }), "primaryAxis");
93  chai.add(fun([](const Vector3& v) { return v.isZeroLength(); }), "isZeroLength");
94  chai.add(fun([](const Vector3& v) { return v.isNaN(); }), "isNaN");
95  chai.add(fun([](Vector3& v) { return v.normalise(); }), "normalise");
96  chai.add(var(&Vector3::UNIT_X), "AnnVect3_UNIT_X");
97  chai.add(var(&Vector3::UNIT_Y), "AnnVect3_UNIT_Y");
98  chai.add(var(&Vector3::UNIT_Z), "AnnVect3_UNIT_Z");
99  chai.add(var(&Vector3::NEGATIVE_UNIT_X), "AnnVect3_NEGATIVE_UNIT_X");
100  chai.add(var(&Vector3::NEGATIVE_UNIT_Y), "AnnVect3_NEGATIVE_UNIT_Y");
101  chai.add(var(&Vector3::NEGATIVE_UNIT_Z), "AnnVect3_NEGATIVE_UNIT_Z");
102  chai.add(var(&Vector3::UNIT_SCALE), "AnnVect3_UNIT_SCALE");
103 
104  //Angles
105  chai.add(user_type<Radian>(), "AnnRadian");
106  chai.add(user_type<Degree>(), "AnnDegree");
107  chai.add(constructor<Radian(Real)>(), "AnnRadian");
108  chai.add(constructor<Degree(Real)>(), "AnnDegree");
109  chai.add(constructor<Radian(const Degree&)>(), "AnnRadian");
110  chai.add(constructor<Degree(const Radian&)>(), "AnnDegree");
111  chai.add(fun([](const Degree& d) { return +d; }), "+");
112  chai.add(fun([](const Degree& d1, const Degree& d2) { return d1 + d2; }), "+");
113  chai.add(fun([](const Degree& d1, const Radian& d2) { return d1 + d2; }), "+");
114  chai.add(fun([](Degree& d1, const Degree& d2) { d1 += d2; }), "+=");
115  chai.add(fun([](const Degree& d) { return -d; }), "-");
116  chai.add(fun([](const Degree& d1, const Degree& d2) { return d1 - d2; }), "-");
117  chai.add(fun([](const Degree& d1, const Radian& d2) { return d1 - d2; }), "-");
118  chai.add(fun([](Degree& d1, const Degree& d2) { d1 -= d2; }), "-=");
119  chai.add(fun([](Degree& d1, const Radian& d2) { d1 -= d2; }), "-=");
120  chai.add(fun([](const Degree& d, Real f) { return d * f; }), "*");
121  chai.add(fun([](Degree& d, Real f) { d *= f; }), "*=");
122  chai.add(fun([](const Degree& d, Real f) { return d / f; }), "/");
123  chai.add(fun([](Degree& d, Real f) { d /= f; }), "/=");
124  chai.add(fun([](const Degree& d1, const Degree& d2) { return d1 < d2; }), "<");
125  chai.add(fun([](const Degree& d1, const Degree& d2) { return d1 > d2; }), ">");
126  chai.add(fun([](const Degree& d1, const Degree& d2) { return d1 <= d2; }), "<=");
127  chai.add(fun([](const Degree& d1, const Degree& d2) { return d1 >= d2; }), ">=");
128  chai.add(fun([](const Degree& d1, const Degree& d2) { return d1 == d2; }), "==");
129  chai.add(fun([](const Degree& d1, const Degree& d2) { return d1 != d2; }), "!=");
130  chai.add(fun([](const Radian& d) { return +d; }), "+");
131  chai.add(fun([](const Radian& r1, const Radian& r2) { return r1 + r2; }), "+");
132  chai.add(fun([](const Radian& r1, const Degree& r2) { return r1 + r2; }), "+");
133  chai.add(fun([](Radian& r1, const Radian& r2) { r1 += r2; }), "+=");
134  chai.add(fun([](const Radian& d) { return -d; }), "-");
135  chai.add(fun([](const Radian& r1, const Radian& r2) { return r1 - r2; }), "-");
136  chai.add(fun([](const Radian& r1, const Degree& r2) { return r1 - r2; }), "-");
137  chai.add(fun([](Radian& r1, const Radian& r2) { r1 -= r2; }), "-=");
138  chai.add(fun([](Radian& r1, const Degree& r2) { r1 -= r2; }), "-=");
139  chai.add(fun([](const Radian& d, Real f) { return d * f; }), "*");
140  chai.add(fun([](Radian& d, Real f) { d *= f; }), "*=");
141  chai.add(fun([](const Radian& d, Real f) { return d / f; }), "/");
142  chai.add(fun([](Radian& d, Real f) { d /= f; }), "/=");
143  chai.add(fun([](const Radian& r1, const Radian& r2) { return r1 < r2; }), "<");
144  chai.add(fun([](const Radian& r1, const Radian& r2) { return r1 > r2; }), ">");
145  chai.add(fun([](const Radian& r1, const Radian& r2) { return r1 <= r2; }), "<=");
146  chai.add(fun([](const Radian& r1, const Radian& r2) { return r1 >= r2; }), ">=");
147  chai.add(fun([](const Radian& r1, const Radian& r2) { return r1 == r2; }), "==");
148  chai.add(fun([](const Radian& r1, const Radian& r2) { return r1 != r2; }), "!=");
149 
150  //Quaternions
151  chai.add(user_type<Quaternion>(), "AnnQuaternion");
152  chai.add(constructor<Quaternion()>(), "AnnQuaternion");
153  chai.add(constructor<Quaternion(float, float, float, float)>(), "AnnQuaternion");
154  chai.add(constructor<Quaternion(Radian, Vector3)>(), "AnnQuaternion");
155  chai.add(constructor<Quaternion(Vector3, Vector3, Vector3)>(), "AnnQuaternion");
156  chai.add(fun(&Quaternion::x), "x");
157  chai.add(fun(&Quaternion::y), "y");
158  chai.add(fun(&Quaternion::z), "z");
159  chai.add(fun(&Quaternion::w), "w");
160  chai.add(fun([](const Quaternion& q, const Vector3 v) { return q * v; }), "*");
161  chai.add(fun([](const Quaternion& q1, const Quaternion& q2) { return q1 * q2; }), "*");
162  chai.add(fun([](const Quaternion& q, const Real& scalar) { return q * scalar; }), "*");
163  chai.add(fun([](const Quaternion& q, size_t i) { return q[i]; }), "[]");
164  chai.add(fun([](Quaternion& q1, const Quaternion& q2) { q1 = q2; }), "=");
165  chai.add(fun([](const Quaternion& q1, const Quaternion& q2) { return q1 + q2; }), "+");
166  chai.add(fun([](const Quaternion& q1, const Quaternion& q2) { return q1 - q2; }), "-");
167  chai.add(fun([](const Quaternion& q) { return -q; }), "-");
168  chai.add(fun([](const Quaternion& q1, const Quaternion& q2) { return q1 == q2; }), "==");
169  chai.add(fun([](const Quaternion& q1, const Quaternion& q2) { return q1 != q2; }), "!=");
170  chai.add(fun([](const Quaternion& q) { return q.xAxis(); }), "xAxis");
171  chai.add(fun([](const Quaternion& q) { return q.yAxis(); }), "yAxis");
172  chai.add(fun([](const Quaternion& q) { return q.zAxis(); }), "zAxis");
173  chai.add(fun([](const Quaternion& q) { return q.getRoll(); }), "getRoll");
174  chai.add(fun([](const Quaternion& q) { return q.getPitch(); }), "getPitch");
175  chai.add(fun([](const Quaternion& q) { return q.getYaw(); }), "getYaw");
176  chai.add(fun([](const Quaternion& q) { return q.isNaN(); }), "isNaN");
177  chai.add(var(&Quaternion::ZERO), "AnnQuaternion_ZERO");
178  chai.add(var(&Quaternion::IDENTITY), "AnnQuaternion_IDENTITY");
179 
180  chai.add(user_type<AnnGameObject>(), "AnnGameObject");
181  chai.add(fun([](AnnGameObject* o, Vector3 v) { o->setPosition(v); }), "setPosition");
182  chai.add(fun([](AnnGameObject* o, Quaternion q) { o->setOrientation(q); }), "setOrientation");
183  chai.add(fun([](AnnGameObject* o, Vector3 v) { o->setScale(v); }), "setScale");
184  chai.add(fun([](AnnGameObject* o) -> Vector3 { return o->getPosition(); }), "getPosition");
185  chai.add(fun([](AnnGameObject* o) -> Quaternion { return o->getOrientation(); }), "getOrientation");
186  chai.add(fun([](AnnGameObject* o) -> Vector3 { return o->getScale(); }), "getScale");
187  chai.add(fun([](AnnGameObject* o, const string& s) { o->playSound(s); }), "playSound");
188  chai.add(fun([](AnnGameObject* o, const string& s) { o->playSound(s, true); }), "playSoundLoop");
189  chai.add(fun([](AnnGameObject* o) { return o->getName(); }), "getName");
190  chai.add(fun([](AnnGameObject* o, const string& animName) { o->setAnimation(animName); }), "setAnimation");
191  chai.add(fun([](AnnGameObject* o) { o->playAnimation(); }), "playAnimation");
192  chai.add(fun([](AnnGameObject* o, bool play) { o->playAnimation(play); }), "playAnimation");
193  chai.add(fun([](AnnGameObject* o) { o->loopAnimation(); }), "loopAnimation");
194  chai.add(fun([](AnnGameObject* o, bool play) { o->loopAnimation(play); }), "loopAnimation");
195  chai.add(fun([](AnnGameObject* o) { return o->getName(); }), "getName");
196 
197  chai.add(user_type<AnnLightObject>(), "AnnLightObject");
198  chai.add(fun([](AnnLightObject* o, Vector3 v) { o->setPosition(v); }), "setPosition");
199  chai.add(fun([](AnnLightObject* o, Vector3 v) { o->setDirection(v); }), "setDirection");
200  chai.add(fun([](AnnLightObject* o, AnnColor c) { o->setDiffuseColor(c); }), "setDiffuseColor");
201  chai.add(fun([](AnnLightObject* o, AnnColor c) { o->setSpecularColor(c); }), "setSpecularColor");
202  chai.add(fun([](AnnLightObject* o, float lumens) { o->setPower(lumens); }), "setPower");
203  chai.add(fun([](AnnLightObject* o) -> Vector3 { return o->getPosition(); }), "getPosition");
204  chai.add(fun([](AnnLightObject* o) -> Vector3 { return o->getDirection(); }), "getDirection");
205  chai.add(fun([](AnnLightObject* o) -> AnnColor { return o->getSpecularColor(); }), "getSpecularColor");
206  chai.add(fun([](AnnLightObject* o) -> AnnColor { return o->getDiffuseColor(); }), "getDiffuseColor");
207  chai.add(fun([](AnnLightObject* o) { return o->getName(); }), "getName");
208 
209  //Color
210  chai.add(user_type<AnnColor>(), "AnnColor");
211  chai.add(constructor<AnnColor(float, float, float, float)>(), "AnnColor");
212  chai.add(constructor<AnnColor(const ColourValue&)>(), "AnnColor");
213  chai.add(constructor<AnnColor(const AnnColor&)>(), "AnnColor");
214  chai.add(fun([](AnnColor& c1, AnnColor& c2) { c1 = c2; }), "=");
215  chai.add(fun([](AnnColor& color) { return color.getRed(); }), "getRed");
216  chai.add(fun([](AnnColor& color) { return color.getGreen(); }), "getGreen");
217  chai.add(fun([](AnnColor& color) { return color.getBlue(); }), "getBlue");
218  chai.add(fun([](AnnColor& color) { return color.getAlpha(); }), "getAlpha");
219  chai.add(fun([](AnnColor& color, float value) { return color.setRed(value); }), "setRed");
220  chai.add(fun([](AnnColor& color, float value) { return color.setGreen(value); }), "setGreen");
221  chai.add(fun([](AnnColor& color, float value) { return color.setBlue(value); }), "setBlue");
222  chai.add(fun([](AnnColor& color, float value) { return color.setAlpha(value); }), "setAlpha");
223 
224  //Object getter
225  chai.add(fun([](string id) { return AnnGetGameObjectManager()->getGameObject(id).get(); }), "AnnGetGameObject");
226  chai.add(fun([](string id) { return AnnGetGameObjectManager()->getLightObject(id).get(); }), "AnnGetLightObject");
227 
228  //Level jumper
229  chai.add(fun([](AnnLevelID id) { AnnGetLevelManager()->switchToLevel(id); }), "AnnJumpLevel");
230 
231  //Create a GameObject form ChaiScript
232  chai.add(fun([](const string& mesh, const string& objectName) {
233  AnnGetLevelManager()->addToCurrentLevel(
234  AnnGetGameObjectManager()->createGameObject(mesh.c_str(), objectName));
235  }),
236  "AnnCreateGameObject");
237  //Remove object
238  chai.add(fun([](const string& objectName) {
239  auto obj = AnnGetGameObjectManager()->getGameObject(objectName);
240  if(!obj) return;
241  AnnGetGameObjectManager()->removeGameObject(obj);
242  AnnGetLevelManager()->removeFromCurrentLevel(obj);
243  }),
244  "AnnRemoveGameObject");
245 
246  //Change the gravity
247  chai.add(fun([](const Vector3& gravity) { AnnGetPhysicsEngine()->changeGravity(gravity); }), "AnnChangeGravity");
248  //Restore the default gravity vector
249  chai.add(fun([]() { AnnGetPhysicsEngine()->resetGravity(); }), "AnnRestoreGravity");
250 
251  //Add the types of the event representation object
252  chai.add(user_type<AnnKeyEvent>(), "AnnKeyEvent");
253  chai.add(user_type<AnnMouseEvent>(), "AnnMouseEvent");
254  chai.add(user_type<AnnControllerEvent>(), "AnnControllerEvent");
255  chai.add(user_type<AnnTimeEvent>(), "AnnTimeEvent");
256  chai.add(user_type<AnnTriggerEvent>(), "AnnTriggerEvent");
257  chai.add(user_type<AnnHandControllerEvent>(), "AnnHandControllerEvent");
258  chai.add(user_type<AnnMouseAxis>(), "AnnMouseAxis");
259  chai.add(user_type<MouseAxisID>(), "MouseAxisID");
260  chai.add(user_type<MouseButtonId>(), "MouseButtonId");
261  chai.add(user_type<AnnControllerAxis>(), "AnnControllerAxis");
262  chai.add(user_type<AnnControllerPov>(), "AnnControllerPov");
263  chai.add(user_type<AnnTimerID>(), "AnnTimerID");
264  chai.add(user_type<AnnCollisionEvent>(), "AnnCollisionEvent");
265  chai.add(user_type<AnnPlayerCollisionEvent>(), "AnnPlayerCollisionEvent");
266 
267  chai.add(fun([](AnnKeyEvent e) { return e.isPressed(); }), "isPressed");
268  chai.add(fun([](AnnKeyEvent e) { return e.isReleased(); }), "isReleased");
269  chai.add(fun([](AnnKeyEvent e) { return e.getKey(); }), "getKey");
270 
271  chai.add(fun([](AnnMouseEvent e, /*MouseAxisID*/ const int a) { return e.getAxis(MouseAxisID(a)); }), "getAxis");
272  chai.add(fun([](AnnMouseEvent e, /*MouseButtonId*/ const int b) { return e.getButtonState(MouseButtonId(b)); }), "getButtonState");
273  chai.add(fun([](AnnMouseAxis a) { return a.getRelValue(); }), "getRelValue");
274  chai.add(fun([](AnnMouseAxis a) { return a.getAbsValue(); }), "getAbsValue");
275 
276  chai.add(fun([](AnnControllerEvent e) { return e.getNbButtons(); }), "getNbButtons");
277  chai.add(fun([](AnnControllerEvent e) { return e.getAxisCount(); }), "getAxisCount");
278  chai.add(fun([](AnnControllerEvent e) { return e.getPovCount(); }), "getPovCount");
279  chai.add(fun([](AnnControllerEvent e) { return e.getVendor(); }), "getVendor");
280  chai.add(fun([](AnnControllerEvent e) { return e.getControllerID(); }), "getControllerID");
281  chai.add(fun([](AnnControllerEvent e) { return e.isXboxController(); }), "isXboxController");
282  chai.add(fun([](AnnControllerEvent e, const int i) { return e.isPressed(i); }), "isPressed");
283  chai.add(fun([](AnnControllerEvent e, const int i) { return e.isReleased(i); }), "isReleased");
284  chai.add(fun([](AnnControllerEvent e, const int i) { return e.isDown(i); }), "isDown");
285  chai.add(fun([](AnnControllerEvent e, const int i) { return e.getAxis(i); }), "getAxis");
286  chai.add(fun([](AnnControllerEvent e, const int i) { return e.getPov(i); }), "getPov");
287 
288  chai.add(fun([](AnnControllerPov pov) { return pov.getNorth(); }), "getNorth");
289  chai.add(fun([](AnnControllerPov pov) { return pov.getSouth(); }), "getSouth");
290  chai.add(fun([](AnnControllerPov pov) { return pov.getEast(); }), "getEast");
291  chai.add(fun([](AnnControllerPov pov) { return pov.getWest(); }), "getWest");
292  chai.add(fun([](AnnControllerPov pov) { return pov.getNorthEast(); }), "getNorthEast");
293  chai.add(fun([](AnnControllerPov pov) { return pov.getNorthWest(); }), "getNorthWest");
294  chai.add(fun([](AnnControllerPov pov) { return pov.getSouthEast(); }), "getSouthEast");
295  chai.add(fun([](AnnControllerPov pov) { return pov.getSouthWest(); }), "getSouthWest");
296 
297  chai.add(fun([](AnnControllerAxis a) { return a.getAxisId(); }), "getAxisId");
298  chai.add(fun([](AnnControllerAxis a) { return a.getRelValue(); }), "getRelValue");
299  chai.add(fun([](AnnControllerAxis a) { return a.getAbsValue(); }), "getAbsValue");
300 
301  chai.add(fun([](AnnTimeEvent t) { return t.getID(); }), "getID");
302 
303  chai.add(fun([](AnnTriggerEvent e) { return e.getContactStatus(); }), "getContactStatus");
304  chai.add(fun([](AnnTriggerEvent e) { return e.getSender(); }), "getSender");
305 
306  // TODO ISSUE the hand controller event interface is not finished
307  chai.add(user_type<AnnHandController>(), "AnnHandController");
308  chai.add(user_type<AnnHandControllerAxis>(), "AnnHandControllerAxis");
309  chai.add(user_type<AnnHandController::AnnHandControllerSide>(), "AnnHandControllerSide");
310  chai.add(user_type<AnnHandController::AnnHandControllerTypeHash>(), "AnnHandControllerTypeHash");
311  chai.add(user_type<AnnHandController::AnnHandControllerGestureHash>(), "AnnHandControllerGestureHash");
312  chai.add(var(AnnHandController::AnnHandControllerSide::leftHandController), "leftHandController");
313  chai.add(var(AnnHandController::AnnHandControllerSide::rightHandController), "rightHandController");
314  chai.add(var(AnnHandController::AnnHandControllerSide::invalidHandController), "invalidHandController");
315 
316  chai.add(fun([](AnnHandControllerEvent e) -> Vector3 { return e.getPosition(); }), "getPosition");
317  chai.add(fun([](AnnHandControllerEvent e) -> Quaternion { return e.getOrientation(); }), "getOrientation");
318  chai.add(fun([](AnnHandControllerEvent e) -> Vector3 { return e.getPointingDirection(); }), "getOrientation");
319  chai.add(fun([](AnnHandControllerEvent e) -> Vector3 { return e.getLinearSpeed(); }), "getLinearSpeed");
320  chai.add(fun([](AnnHandControllerEvent e) -> Vector3 { return e.getAngularSpeed(); }), "getAngularSpeed");
321  chai.add(fun([](AnnHandControllerEvent e, const uint8_t id) { return e.getAxis(id); }), "getAxis");
322  chai.add(fun([](AnnHandControllerEvent e) { return e.getAxisCount(); }), "getAxisCount");
323  chai.add(fun([](AnnHandControllerEvent e) { return e.getButtonCount(); }), "getButtonCount");
324  chai.add(fun([](AnnHandControllerEvent e, const uint8_t id) { return e.buttonPressed(id); }), "buttonPressed");
325  chai.add(fun([](AnnHandControllerEvent e, const uint8_t id) { return e.buttonReleased(id); }), "buttonReleased");
326  chai.add(fun([](AnnHandControllerEvent e, const uint8_t id) { return e.buttonState(id); }), "buttonState");
327  chai.add(fun([](AnnHandControllerEvent e) { return e.getSide(); }), "getSide");
328  chai.add(fun([](AnnHandControllerEvent e) { return e.getType(); }), "getType");
329 
330  chai.add(fun([](AnnPlayerCollisionEvent e) { return e.getObject(); }), "getObject");
331  chai.add(fun([](AnnPlayerCollisionEvent e) { return e.getObject()->getName(); }), "getObjectName");
332 
333  chai.add(fun([](AnnCollisionEvent e) { return e.getA(); }), "getAObject");
334  chai.add(fun([](AnnCollisionEvent e) { return e.getB(); }), "getBObject");
335  chai.add(fun([](AnnCollisionEvent e) { return e.getA()->getName(); }), "getAObjectName");
336  chai.add(fun([](AnnCollisionEvent e) { return e.getB()->getName(); }), "getBObjectName");
337  chai.add(fun([](AnnCollisionEvent e) -> Vector3 { return e.getPosition(); }), "getPosition");
338  chai.add(fun([](AnnCollisionEvent e) -> Vector3 { return e.getNormal(); }), "getNormal");
339  chai.add(fun([](AnnCollisionEvent e) { return e.isCeilingCollision(); }), "isCeilingCollision");
340  chai.add(fun([](AnnCollisionEvent e) { return e.isGroundCollision(); }), "isGroundCollision");
341  chai.add(fun([](AnnCollisionEvent e) { return e.isWallCollision(); }), "isWallCollision");
342 
343  //There's capacitive touch surfaces and haptic feedback that aren't available right now on the AnnHandController class
344 
345  //Register an accessors to the engine's log
346  chai.add(fun([](const string& s) { AnnDebug(Log::Important) << logFromScript << s; }), "AnnDebugLog");
347  chai.add(fun([](const Vector3& s) { AnnDebug(Log::Important) << logFromScript << s; }), "AnnDebugLog");
348  chai.add(fun([](const Vector2& s) { AnnDebug(Log::Important) << logFromScript << s; }), "AnnDebugLog");
349  chai.add(fun([](const Quaternion& s) { AnnDebug(Log::Important) << logFromScript << s; }), "AnnDebugLog");
350  chai.add(fun([](const Radian& s) { AnnDebug(Log::Important) << logFromScript << s; }), "AnnDebugLog");
351  chai.add(fun([](const Degree& s) { AnnDebug(Log::Important) << logFromScript << s; }), "AnnDebugLog");
352  chai.add(fun([](const AnnColor& s) { AnnDebug(Log::Important) << logFromScript << s; }), "AnnDebugLog");
353  chai.add(fun([](KeyCode::code c) { AnnDebug(Log::Important) << logFromScript << "keycode:" << c; }), "AnnDebugLog");
354  chai.add(fun([](MouseAxisID c) { AnnDebug(Log::Important) << logFromScript << "mouseAxis:" << c; }), "AnnDebugLog");
355  chai.add(fun([](bool b) {string s("true"); if (!b) { s = "false"; } AnnDebug(Log::Important) << logFromScript << "bool:" << s; }), "AnnDebugLog");
356  chai.add(fun([](int i) { AnnDebug(Log::Important) << logFromScript << "int:" << i; }), "AnnDebugLog");
357  chai.add(fun([](float f) { AnnDebug(Log::Important) << logFromScript << "float:" << f; }), "AnnDebugLog");
358 
360  chai.add(fun([]() { AnnGetOnScreenConsole()->bufferClear(); }), "AnnClearConsole");
361  chai.add(fun([]() { AnnEngine::setProcessPriorityHigh(); }), "AnnSetProcessPriorityHigh");
362  chai.add(fun([]() { AnnEngine::setProcessPriorityNormal(); }), "AnnSetProcessPriorityNormal");
363 
364  chai.add(fun([]() { AnnGetEngine()->requestQuit(); }), "AnnQuit");
365  chai.add(fun([](const float& multiplier) { AnnGetPhysicsEngine()->setDebugDrawerColorMultiplier(multiplier); }), "AnnSetDebugDrawerColorMultiplier");
366  chai.add(fun([](const float& ev, const float& minEv, const float& maxEv) { AnnGetSceneryManager()->setExposure(ev, minEv, maxEv); }), "AnnSetExposure");
367  chai.add(fun([](const float& threshold) { AnnGetSceneryManager()->setBloomThreshold(threshold); }), "AnnSetBloomThreshold");
368  chai.add(fun([](AnnColor& color, float& multiplier) { AnnGetSceneryManager()->setSkyColor(color, multiplier); }), "AnnSetSkyColor");
369  chai.add(fun([](const AnnColor& ucolor, const float umul, const AnnColor& lcolor, const float lmul, const Vector3& dir, const float envMapScaling) { AnnGetSceneryManager()->setAmbientLight(ucolor, umul, lcolor, lmul, dir, envMapScaling); }), "AnnSetAmbientLight");
370 
371  chai.add(fun([](int AA) { AnnOgreVRRenderer::setAntiAliasingLevel(uint8_t(AA)); }), "AnnSetAA");
372  }
373  catch(const chaiscript::exception::name_conflict_error& e)
374  {
375  throw AnnInitializationError(ANN_ERR_NOTINIT, "Cannot initialize script manager. Trhowed exception when binding APIs:\n" + string(e.what()));
376  }
377 }
378 
380 {
381  //Forgive me.
382  try
383  {
385  }
386  catch(const chaiscript::exception::eval_error&)
387  {
389  }
390 
391  //Yes. I'm doing this.
392  try
393  {
395  }
396  catch(const chaiscript::exception::eval_error&)
397  {
399  }
400 
401  //Yes, there's 6 of them
402  try
403  {
405  }
406  catch(const chaiscript::exception::eval_error&)
407  {
409  }
410 
411  //And yes, it's probable that something will be thrown, unless a script already have this function
412  try
413  {
415  }
416  catch(const chaiscript::exception::eval_error&)
417  {
419  }
420 
421  //And it's also possible than the result is not usable with this script and will throw later at eval time
422  try
423  {
425  }
426  catch(const chaiscript::exception::eval_error&)
427  {
429  }
430 
431  //Like I said. Please forgive me.
432  try
433  {
435  }
436  catch(const chaiscript::exception::eval_error&)
437  {
439  }
440  try
441  {
443  }
444  catch(const chaiscript::exception::eval_error&)
445  {
447  }
448  try
449  {
451  }
452  catch(const chaiscript::exception::eval_error&)
453  {
455  }
456 }
457 
459 {
460  try
461  {
462  chai.eval_file(file);
463  }
464  catch(const chaiscript::exception::file_not_found_error& fnfe)
465  {
466  AnnDebug() << fileErrorPrefix << fnfe.what();
467  return false;
468  }
469  catch(const chaiscript::exception::eval_error& ee)
470  {
471  AnnDebug() << fileErrorPrefix << ee.pretty_print();
472  return false;
473  }
474  return true;
475 }
476 
478 
480 {
481  auto file{ scriptName + scriptExtension };
482 
483  try
484  {
485  //Evaluate the file containing the script class if unknown to ChaiScript yet
486 
487  auto rawScript = scriptFileManager->getResourceByName(file).staticCast<AnnScriptFile>();
488  if(!rawScript)
489  {
491  if(!rawScript)
492  throw chaiscript::exception::file_not_found_error(file);
493  }
494 
495  if(!rawScript->loadedInChaiscriptInterpretor())
496  {
497  AnnDebug() << "now loading " << file << " into the script manager";
498  rawScript->signalLoadedInChaiscript();
499  chai.eval(rawScript->getSourceCode());
500  }
501 
502  //Increment ID
503  ID++;
504 
505  //Get the name of the owner of this script, if relevant;
506  std::string ownerTag = owner ? owner->getName() : "";
507 
508  //This may looks odd but it's good enough for what we're doing:
509  //Copy the template of the init code to a string
510  std::string ChaiCode{ scriptTemplate };
511 
512  //To "boot" the script, there's a little sniped of ChaiScript that is run from the C++ side. This code is generated from a string,
513  //And contains a few fixed tags to be replaced with the script name and an unique ID
514  ChaiCode.replace(ChaiCode.find(std::string(scriptNameMarker)), nameMarkerLen, scriptName);
515  ChaiCode.replace(ChaiCode.find(std::string(scriptNameMarker)), nameMarkerLen, scriptName);
516  ChaiCode.replace(ChaiCode.find(std::string(scriptObjectID)), scriptIDMarkerLen, std::to_string(ID));
517  ChaiCode.replace(ChaiCode.find(std::string(scriptObjectID)), scriptIDMarkerLen, std::to_string(ID));
518  ChaiCode.replace(ChaiCode.find(std::string(scriptObjectID)), scriptIDMarkerLen, std::to_string(ID));
519 
520  //This is the ugly bit, this will try to see if the methods functions have been declared somewhere. Note that this doesn't tell if a script has a specific method implemented.
521  //It just permit to know if "a function" with that name exist. Script themselve will deal with knowing if they own theses functions, by attempting to call them, and setting flags
522  //if exception occurs.
524 
525  //This will add a global function in ChaiScript, that will create and return the script instance
526  chai.eval(ChaiCode);
527  //Get a way to call this function
528  auto creatorFunction = chai.eval<std::function<chaiscript::Boxed_Value(std::string)>>("create" + scriptName + std::to_string(ID));
529 
530  //Now we need to get some hook to call the update on the file
531  return std::make_shared<AnnBehaviorScript>(
532  scriptName,
533  //Function to call to update the script. Update is mandatory
535 
536  //Eventual event hooks
537  tie(
546  //This return the ScriptInstance, as a Boxed_Value. We're only interested at calling something on
547  //this object, so don't need to try to unbox it. It's literally a black box for us
548  creatorFunction(ownerTag));
549  }
550 
551  catch(const chaiscript::exception::file_not_found_error& fnfe)
552  {
553  AnnDebug(Log::Important) << "Cannot find behavior script " << file;
554  AnnDebug(Log::Important) << fileErrorPrefix << fnfe.what();
555  }
556  catch(const chaiscript::exception::eval_error& ee)
557  {
558  AnnDebug(Log::Important) << "Error during evaluation of behavior script " << file;
559  AnnDebug(Log::Important) << ee.pretty_print();
560  }
561 
562  //The user should test if this script is "valid" or not. And should not do it in a loop, obviously
563  return std::make_shared<AnnBehaviorScript>();
564 }
565 
567  valid(false),
568  cannotKey(false),
569  cannotMouse(false),
570  cannotStick(false),
571  cannotTime(false),
572  cannotTrigger(false),
573  cannotHand(false),
574  cannotCollision{ false },
575  cannotPlayerCollision{ false }
576 {
577  AnnDebug() << "Invalid script object created";
578 }
579 
581  std::function<void(chaiscript::Boxed_Value&)> updateHook,
583  chaiscript::Boxed_Value scriptObjectInstance) :
585  valid{ true },
586  name{ scriptName },
587  ScriptObjectInstance{ scriptObjectInstance },
588  callUpdateOnScriptInstance{ updateHook },
589  callKeyEventOnScriptInstance{ std::get<KeyHook>(hooks) },
590  callMouseEventOnScriptInstance{ std::get<MouseHook>(hooks) },
591  callStickEventOnScriptInstance{ std::get<ControllerHook>(hooks) },
592  callTimeEventOnScriptInstance{ std::get<TimeHook>(hooks) },
593  callTriggerEventOnScriptInstance{ std::get<TriggerHook>(hooks) },
594  callHandControllertOnScriptInstance{ std::get<HandHook>(hooks) },
595  callCollisionEventOnScriptInstance{ std::get<CollisionHook>(hooks) },
596  callPlayerCollisionEventOnScriptInstance{ std::get<PlayerCollisionHook>(hooks) },
597  cannotKey{ false },
598  cannotMouse{ false },
599  cannotStick{ false },
600  cannotTime{ false },
601  cannotTrigger{ false },
602  cannotHand{ false },
603  cannotCollision{ false },
604  cannotPlayerCollision{ false }
605 {
606 }
607 
609 {
610  AnnDebug() << "Destructing " << name << "Script";
611 }
612 
614 {
615  try
616  {
618  }
619  catch(const chaiscript::exception::eval_error& ee)
620  {
621  AnnDebug() << "Evaluation error while "
622  << name
623  << " script update - "
624  << ee.pretty_print();
625  //will not crash here.
626  }
627 }
628 
630 {
631  return valid;
632 }
633 
635 {
636  AnnGetEventManager()->addListener(getSharedListener());
637 }
638 
640 {
641  AnnDebug() << "Unregistering ourself has event listener";
642  AnnGetEventManager()->removeListener(getSharedListener());
643 }
644 
646 {
647  try
648  {
651  }
652  catch(const chaiscript::exception::dispatch_error&)
653  {
654  cannotKey = true;
655  }
656  catch(const chaiscript::exception::eval_error& ee)
657  {
658  AnnDebug(Log::Important) << "Event script error " << ee.pretty_print();
659  }
660 }
661 
663 {
664  try
665  {
668  }
669  catch(const chaiscript::exception::dispatch_error&)
670  {
671  cannotMouse = true;
672  }
673  catch(const chaiscript::exception::eval_error& ee)
674  {
675  AnnDebug(Log::Important) << "Event script error " << ee.pretty_print();
676  }
677 }
678 
680 {
681  try
682  {
685  }
686  catch(const chaiscript::exception::dispatch_error&)
687  {
688  cannotStick = true;
689  }
690  catch(const chaiscript::exception::eval_error& ee)
691  {
692  AnnDebug(Log::Important) << "Event script error " << ee.pretty_print();
693  }
694 }
695 
697 {
698  try
699  {
702  }
703  catch(const chaiscript::exception::dispatch_error&)
704  {
705  cannotTime = true;
706  }
707  catch(const chaiscript::exception::eval_error& ee)
708  {
709  AnnDebug(Log::Important) << "Event script error " << ee.pretty_print();
710  }
711 }
712 
714 {
715  try
716  {
719  }
720  catch(const chaiscript::exception::dispatch_error&)
721  {
722  cannotTrigger = true;
723  }
724  catch(const chaiscript::exception::eval_error& ee)
725  {
726  AnnDebug(Log::Important) << "Event script error " << ee.pretty_print();
727  }
728 }
729 
731 {
732  try
733  {
736  }
737  catch(const chaiscript::exception::dispatch_error&)
738  {
739  cannotHand = true;
740  }
741  catch(const chaiscript::exception::eval_error& ee)
742  {
743  AnnDebug(Log::Important) << "Event script error " << ee.pretty_print();
744  }
745 }
746 
748 {
749  try
750  {
753  }
754  catch(const chaiscript::exception::dispatch_error&)
755  {
756  cannotCollision = true;
757  }
758  catch(const chaiscript::exception::eval_error& ee)
759  {
760  AnnDebug(Log::Important) << "Event script error " << ee.pretty_print();
761  }
762 }
764 {
765  //AnnDebug() << "player collision on script...";
766  try
767  {
770  }
771  catch(const chaiscript::exception::dispatch_error&)
772  {
773  cannotPlayerCollision = true;
774  }
775  catch(const chaiscript::exception::eval_error& ee)
776  {
777  AnnDebug(Log::Important) << "Event script error " << ee.pretty_print();
778  }
779 }
780 
782 {
783  chai.eval(chaiCode);
784 }
785 
787 {
789 }
790 
792 {
793  OGRE_DELETE scriptFileManager;
794  scriptFileManager = nullptr;
795 }
796 
798 {
800 }
801 
802 chaiscript::ChaiScript* AnnScriptManager::_getEngine()
803 {
804  return &chai;
805 }
std::function< void(chaiscript::Boxed_Value &, AnnHandControllerEvent)> callHandControllertOnScriptInstance
Hook for Hand Controller event.
void ControllerEvent(AnnControllerEvent e) override
Event for a Joystick.
void HandControllerEvent(AnnHandControllerEvent e) override
Event from an HandController.
Collision between the player and another object.
Definition: AnnEvents.hpp:395
std::function< void(chaiscript::Boxed_Value &, AnnTriggerEvent)> callTriggerEventOnScriptInstance
T atan(T... args)
static constexpr const char *const fileErrorPrefix
Prefix for error regarding loading script files.
bool cannotKey
Call guards for the hooks above.
std::function< void(chaiscript::Boxed_Value &, AnnPlayerCollisionEvent)> callPlayerCollisionEventOnScriptInstance
Hook for PlayerCollision event.
std::function< void(chaiscript::Boxed_Value &, AnnTimeEvent)> callTimeEventOnScriptInstance
Hook for Time event.
bool getNorth() const
Get the up (north) state.
Definition: AnnEvents.cpp:207
MouseAxisID
Name and number of axes.
Definition: AnnEvents.hpp:70
AnnEngine * AnnGetEngine()
Get the current instance of AnnEngine.
Definition: AnnGetter.cpp:10
bool getNorthEast() const
Get the north && east state.
Definition: AnnEvents.cpp:227
Class that represent a 4 channel color value.
Definition: AnnColor.hpp:17
T tie(T... args)
bool evalFile(const std::string &file)
Evaluate a file. Exceptions internally catches with messages in the log. Return true or false dependi...
void setAlpha(float alpha)
Set the alpha value.
Definition: AnnColor.cpp:113
AnnScriptFileResourceManager * scriptFileManager
Pointer to the script manager.
~AnnScriptManager()
Destruct the Script Manager. will destroy the AnnScriptFileManager.
float getAlpha() const
Get alpha red value as float.
Definition: AnnColor.cpp:60
T acos(T... args)
float getRed() const
Get the red value as float.
Definition: AnnColor.cpp:45
void TimeEvent(AnnTimeEvent e) override
Event from a timer.
Chaiscript File ResourceManager.
A mouse axis information object.
Definition: AnnEvents.hpp:89
AnnScriptManager()
Construct the script manager, initialize ChaiScript and add global functions. Will initialize the Ann...
static void setProcessPriorityNormal()
Set the process priority to "normal".
Definition: AnnEngine.cpp:570
std::function< void(chaiscript::Boxed_Value &, AnnControllerEvent)> callStickEventOnScriptInstance
Hook for Stick event.
std::string getName() const
Return the name of the object.
void setRed(float red)
Set the red value.
Definition: AnnColor.cpp:95
std::function< void(chaiscript::Boxed_Value &, AnnKeyEvent)> callKeyEventOnScriptInstance
Hook for key event.
float getGreen() const
Get the green value as float.
Definition: AnnColor.cpp:50
T to_string(T... args)
std::function< void(chaiscript::Boxed_Value &, AnnCollisionEvent)> callCollisionEventOnScriptInstance
std::function< void(chaiscript::Boxed_Value &, AnnControllerEvent)> callStickEventOnScriptInstance
void evalString(const std::string &chaiCode)
Evaluate one line of chaiCode.
virtual ~AnnBehaviorScript()
Script destructor.
std::function< void(chaiscript::Boxed_Value &, AnnMouseEvent)> callMouseEventOnScriptInstance
#define constructListener()
Macro for declaring a listener constructor.
Namespace containing the totality of Annwvyn components.
Definition: AnnGetter.cpp:8
chaiscript::ChaiScript * _getEngine()
GetAccess to the chaiscript engine. Only use for special cases.
A joystick event.
Definition: AnnEvents.hpp:240
std::function< void(chaiscript::Boxed_Value &, AnnTriggerEvent)> callTriggerEventOnScriptInstance
Hook for Trigger event.
Exception regarding engine utilisation. See message.
An object that exist in the game. Graphically and Potentially Physically.
AnnGameObjectManagerPtr AnnGetGameObjectManager()
Get the game-object manager.
Definition: AnnGetter.cpp:22
A timer timeout event.
Definition: AnnEvents.hpp:342
chaiscript::ChaiScript chai
ChaiScript engine.
T atan2(T... args)
static constexpr const char *const logFromScript
Prefix for debug print called from a script.
std::string name
Name of this script. Name of the "class" defined in the script.
static const char * getDefaultResourceGroupName()
Return the default resource group name.
T sin(T... args)
static constexpr const char *const scriptObjectID
Marker for the ID of the script.
void requestQuit()
Permit.
Definition: AnnEngine.cpp:584
void setGreen(float green)
Set the green value.
Definition: AnnColor.cpp:101
static constexpr const size_t scriptIDMarkerLen
Static lengths of constant string of the same name.
bool isValid() const
Return true if the script is valid. If the object is in a state where this returns false...
Create a ostream to the Ogre logger.
AnnLevelManagerPtr AnnGetLevelManager()
Get the level manager.
Definition: AnnGetter.cpp:15
std::function< void(chaiscript::Boxed_Value &, AnnPlayerCollisionEvent)> callPlayerCollisionEventOnScriptInstance
void KeyEvent(AnnKeyEvent e) override
Event from the keyboard.
std::function< void(chaiscript::Boxed_Value &, AnnTimeEvent)> callTimeEventOnScriptInstance
bool getEast() const
Get the right (east) state.
Definition: AnnEvents.cpp:217
A hand controller event.
Definition: AnnEvents.hpp:300
T cos(T... args)
virtual AnnScriptFilePtr load(const Ogre::String &name, const Ogre::String &group)
Load a resrouce via this manager.
Open an output stream to the engine log.
Definition: AnnLogger.hpp:24
static void setProcessPriorityHigh()
Set the process priority to "high".
Definition: AnnEngine.cpp:577
bool getNorthWest() const
Get the north && west state.
Definition: AnnEvents.cpp:237
void CollisionEvent(AnnCollisionEvent e) override
Event from the collision between 2 game objects.
void PlayerCollisionEvent(AnnPlayerCollisionEvent e) override
Event from the collision between the player and a game object.
void registerApi()
Register to the script engine all the things that are possible to do. Called by the constructor...
unsigned long getTimeFromStartUp() const
Get elapsed time from engine startup in millisecond.
Definition: AnnEngine.cpp:332
Main Annwvyn Engine class Initialize the renderer and all subsystem. Provide access to all of the eng...
MouseButtonId
Name and number of mouse button.
Definition: AnnEvents.hpp:77
std::function< void(chaiscript::Boxed_Value &, AnnHandControllerEvent)> callHandControllertOnScriptInstance
AnnSceneryManagerPtr AnnGetSceneryManager()
Get the scenery manager.
Definition: AnnGetter.cpp:19
void unregisterResourceManager()
Unregister the scriptFileManager.
T asin(T... args)
T get(T... args)
Parent class of all Annwvyn SubSystem.
AnnPhysicsEnginePtr AnnGetPhysicsEngine()
Get the physics engine.
Definition: AnnGetter.cpp:13
bool getWest() const
Get the left (west) state.
Definition: AnnEvents.cpp:222
static AnnScriptID ID
Static counter that will be incremented at each script creation.
Main Annwvyn include file (to be used by client application)
std::shared_ptr< AnnBehaviorScript > getBehaviorScript(const std::string &scriptName, AnnGameObject *owner=nullptr)
Create a instance to the script. Return a shared pointer.
const bool valid
Validity state of this object. Cannot change.
Represent a pad&#39;s POV controller.
Definition: AnnEvents.hpp:195
A keyboard event.
Definition: AnnEvents.hpp:37
void callUpdateOnScript()
Just call the update on the instance.
AnnConsolePtr AnnGetOnScreenConsole()
Get the on screen console.
Definition: AnnGetter.cpp:23
AnnEventManagerPtr AnnGetEventManager()
Get the event manager.
Definition: AnnGetter.cpp:16
static constexpr const char *const scriptNameMarker
Marker for the name of the script.
void tryAndGetEventHooks()
Hook the event listener&#39;s "methdod" to the script ones, if possible...
T c_str(T... args)
std::function< void(chaiscript::Boxed_Value &, AnnCollisionEvent)> callCollisionEventOnScriptInstance
Hook for Collision event.
T tan(T... args)
bool getSouth() const
Get the down (south) state.
Definition: AnnEvents.cpp:212
#define ANN_ERR_NOTINIT
void setBlue(float blue)
Set the blue value.
Definition: AnnColor.cpp:107
bool getSouthWest() const
Get the south && west state.
Definition: AnnEvents.cpp:242
std::function< void(chaiscript::Boxed_Value &, AnnKeyEvent)> callKeyEventOnScriptInstance
To create the event hooks for the scripts :
void registerResourceManager()
Register the scriptFileManager.
void update()
Call this to call the "update" of the script.
void TriggerEvent(AnnTriggerEvent e) override
Event from a trigger.
float getBlue() const
Get blue red value as float.
Definition: AnnColor.cpp:55
std::function< void(chaiscript::Boxed_Value &, AnnMouseEvent)> callMouseEventOnScriptInstance
Hook for Mouse event.
A mouse event information object.
Definition: AnnEvents.hpp:124
Game Object class.
void unregisterAsListener()
unregister this object as an event listener
Definition: euler.h:16
void MouseEvent(AnnMouseEvent e) override
Event from the mouse.
static constexpr const char *const scriptExtension
The extension of script files.
A joystick axis.
Definition: AnnEvents.hpp:163
AnnBehaviorScript()
Invalid script constructor.
Ogre resource that contains the source code of a loaded .chai file.
Light Object : Represent a light source.
void registerAsListener()
register this object as an event listener
Trigger in/out event.
Definition: AnnEvents.hpp:409
static void setAntiAliasingLevel(uint8_t AA)
static constexpr const char *const scriptTemplate
String constant for script loading and class initialization. This is a bit of ChaiScript code to boot...
static constexpr const size_t nameMarkerLen
Static lengths of constant string of the same name.
Collision event between 2 game objects.
Definition: AnnEvents.hpp:362
bool getSouthEast() const
Get the south && east state.
Definition: AnnEvents.cpp:232
chaiscript::Boxed_Value ScriptObjectInstance
The ChaiScript object that is an instance of "name" class. BlackBox to find what "update" to call on ...