Game Develop C++ Platform: RuntimeObject.h Source File

| Game Develop C++ Platform Platform for developing native games based on OpenGL and SFML with Game Develop

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
RuntimeObject.h
Go to the documentation of this file.
1
5 #ifndef RUNTIMEOBJECT_H
6 #define RUNTIMEOBJECT_H
7
8 #include <string>
9 #include <vector>
10 #include <map>
11 #include "GDCpp/RuntimeVariablesContainer.h"
12 #include "GDCpp/Force.h"
13 namespace gd { class Automatism; }
14 namespace gd { class InitialInstance; }
15 namespace gd { class Object; }
16 namespace sf { class RenderTarget; }
17 class Polygon2d;
18 class RuntimeScene;
19
37 class GD_API RuntimeObject
38 {
39 public:
53 RuntimeObject(RuntimeScene & scene, const gd::Object & object);
54
58 RuntimeObject(const RuntimeObject & object) { Init(object); };
59
63 RuntimeObject& operator=(const RuntimeObject & object) {if( (this) != &object ) Init(object); return *this; }
64
67 virtual ~RuntimeObject();
68
77 virtual RuntimeObject * Clone() const { return new RuntimeObject(*this);}
78
85 virtual bool ExtraInitializationFromInitialInstance(const gd::InitialInstance & position) {return true;}
86
91 virtual bool Draw(sf::RenderTarget & renderTarget) {return true;};
92
96
101 inline const RuntimeVariablesContainer & GetVariables() const { return objectVariables; }
102
106 inline RuntimeVariablesContainer & GetVariables() { return objectVariables; }
107
109
110
114
118 void DoAutomatismsPreEvents(RuntimeScene & scene);
119
123 void DoAutomatismsPostEvents(RuntimeScene & scene);
124
128 gd::Automatism* GetAutomatismRawPointer(const std::string & name);
129
133 gd::Automatism* GetAutomatismRawPointer(const std::string & name) const;
134
138 virtual bool HasAutomatismNamed(const std::string & name) const { return automatisms.find(name) != automatisms.end(); };
140
144 inline const std::string & GetName() const { return name; };
145
149 inline const std::string & GetType() const { return type; };
150
154 inline int GetZOrder() const { return zOrder; }
155
159 inline void SetZOrder(int zOrder_ ) { zOrder = zOrder_; }
160
164 inline bool IsHidden() const {return hidden;};
165
169 inline bool IsVisible() const {return !hidden;};
170
174 inline void SetHidden(bool hide = true) {hidden = hide;};
175
179 inline void SetLayer(const std::string & layer_) { layer = layer_;}
180
184 inline const std::string & GetLayer() const { return layer; }
185
189 inline bool IsOnLayer(const std::string & layer_) const { return layer == layer_; }
190
195 virtual std::vector<Polygon2d> GetHitBoxes() const;
196
202 bool IsCollidingWith(RuntimeObject * other);
203
208 virtual void UpdateTime(float timeElapsed) {};
209
213 virtual float GetWidth() const {return 0;};
214
218 virtual float GetHeight() const {return 0;};
219
225 virtual void SetWidth(float ) {};
226
232 virtual void SetHeight(float ) {};
233
239 virtual bool SetAngle(float ) {return false;};
240
244 virtual float GetAngle() const {return 0;};
245
249 inline float GetX() const { return X; }
250
254 inline float GetY() const { return Y; }
255
260 void SetX(float x_) { X = x_; OnPositionChanged(); }
261
266 void SetY(float y_) { Y = y_; OnPositionChanged(); }
267
272 virtual void OnPositionChanged() {};
273
280 virtual float GetDrawableX() const {return GetX();};
281
288 virtual float GetDrawableY() const {return GetY();};
289
293 virtual float GetCenterX() const {return GetWidth()/2;};
294
298 virtual float GetCenterY() const {return GetHeight()/2;};
299
301
306
308 Force force5;
309
313 bool UpdateForce(float ElapsedTime);
314
315 float TotalForceX() const;
316 float TotalForceY() const;
317 float TotalForceAngle() const;
318 float TotalForceLength() const;
320
324 bool ClearForce();
325
326 #if defined(GD_IDE_ONLY)
327
330
340 virtual void GetPropertyForDebugger (unsigned int propertyNb, std::string & name, std::string & value) const;
341
352 virtual bool ChangeProperty(unsigned int propertyNb, std::string newValue);
353
357 virtual unsigned int GetNumberOfProperties() const;
359 #endif
360
363 void DeleteFromScene(RuntimeScene & scene);
365 void PutAroundAPosition( float positionX, float positionY, float distance, float angleInDegrees );
366 void AddForce( float x, float y, float clearing );
367 void AddForceUsingPolarCoordinates( float angle, float length, float clearing );
368 void AddForceTowardPosition( float positionX, float positionY, float length, float clearing );
369 void AddForceToMoveAround( float positionX, float positionY, float angularVelocity, float distance, float clearing );
370 void AddForceTowardObject( RuntimeObject * object, float length, float clearing );
371 void AddForceToMoveAroundObject( RuntimeObject * object, float velocity, float length, float clearing );
372 void PutAroundObject( RuntimeObject * object, float length, float angleInDegrees );
373
374 static gd::Variable & ReturnVariable(gd::Variable & variable) { return variable; };
375 bool VariableExists(const std::string & variable);
376 static double GetVariableValue(const gd::Variable & variable) { return variable.GetValue(); };
377 static const std::string& GetVariableString(const gd::Variable & variable) { return variable.GetString(); };
378 static bool VariableChildExists(const gd::Variable & variable, const std::string & childName);
379 static void VariableRemoveChild(gd::Variable & variable, const std::string & childName);
380
381 void SetXY( const char* xOperator, float xValue, const char* yOperator, float yValue );
382
383 void Duplicate( RuntimeScene & scene, std::map <std::string, std::vector<RuntimeObject*> *> pickedObjectLists );
384 void ActivateAutomatism( const std::string & automatismName, bool activate = true );
385 bool AutomatismActivated( const std::string & automatismName );
386
387 bool IsStopped();
388 bool TestAngleOfDisplacement( float angle, float tolerance );
389
390 double GetSqDistanceWithObject( RuntimeObject * other );
391 double GetDistanceWithObject( RuntimeObject * other );
392
393 void SeparateFromObjects( std::map <std::string, std::vector<RuntimeObject*> *> pickedObjectLists);
394
397 void SeparateObjectsWithoutForces( std::map <std::string, std::vector<RuntimeObject*> *> pickedObjectLists);
398
401 void SeparateObjectsWithForces( std::map <std::string, std::vector<RuntimeObject*> *> pickedObjectLists);
403
404 protected:
405
406 std::string name;
407 std::string type;
408 float X;
409 float Y;
410 int zOrder;
411 bool hidden;
412 std::string layer;
413 std::map<std::string, gd::Automatism* > automatisms;
414 RuntimeVariablesContainer objectVariables;
415 std::vector < Force > forces;
416
421 void Init(const RuntimeObject & object);
422 };
423
427 void DestroyBaseRuntimeObject(RuntimeObject * object);
428
432 RuntimeObject * CreateBaseRuntimeObject(RuntimeScene & scene, const gd::Object & object);
433
434 #endif // RUNTIMEOBJECT_H