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
- Related Pages
- Modules
- Namespaces
- 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 "GDCore/PlatformDefinition/VariablesContainer.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
38 class GD_API RuntimeObject
39 {
40 public:
54 RuntimeObject(RuntimeScene & scene, const gd::Object & object);
55
59 RuntimeObject(const RuntimeObject & object) { Init(object); };
60
64 RuntimeObject& operator=(const RuntimeObject & object) {if( (this) != &object ) Init(object); return *this; }
65
68 virtual ~RuntimeObject();
69
78 virtual RuntimeObject * Clone() const { return new RuntimeObject(*this);}
79
86 virtual bool ExtraInitializationFromInitialInstance(const gd::InitialInstance & position) {return true;}
87
92 virtual bool Draw(sf::RenderTarget & renderTarget) {return true;};
93
97
102 inline const gd::VariablesContainer & GetVariables() const { return objectVariables; }
103
107 inline gd::VariablesContainer & GetVariables() { return objectVariables; }
108
110
111
115
119 void DoAutomatismsPreEvents(RuntimeScene & scene);
120
124 void DoAutomatismsPostEvents(RuntimeScene & scene);
125
129 gd::Automatism* GetAutomatismRawPointer(const std::string & name);
130
134 gd::Automatism* GetAutomatismRawPointer(const std::string & name) const;
135
139 virtual bool HasAutomatismNamed(const std::string & name) const { return automatisms.find(name) != automatisms.end(); };
141
145 inline const std::string & GetName() const { return name; };
146
150 inline const std::string & GetType() const { return type; };
151
155 inline int GetZOrder() const { return zOrder; }
156
160 inline void SetZOrder(int zOrder_ ) { zOrder = zOrder_; }
161
165 inline bool IsHidden() const {return hidden;};
166
170 inline bool IsVisible() const {return !hidden;};
171
175 inline void SetHidden(bool hide = true) {hidden = hide;};
176
180 inline void SetLayer(const std::string & layer_) { layer = layer_;}
181
185 inline const std::string & GetLayer() const { return layer; }
186
190 inline bool IsOnLayer(const std::string & layer_) const { return layer == layer_; }
191
196 virtual std::vector<Polygon2d> GetHitBoxes() const;
197
202 virtual void UpdateTime(float timeElapsed) {};
203
207 virtual float GetWidth() const {return 0;};
208
212 virtual float GetHeight() const {return 0;};
213
219 virtual void SetWidth(float ) {};
220
226 virtual void SetHeight(float ) {};
227
233 virtual bool SetAngle(float ) {return false;};
234
238 virtual float GetAngle() const {return 0;};
239
243 inline float GetX() const { return X; }
244
248 inline float GetY() const { return Y; }
249
254 void SetX(float x_) { X = x_; OnPositionChanged(); }
255
260 void SetY(float y_) { Y = y_; OnPositionChanged(); }
261
266 virtual void OnPositionChanged() {};
267
274 virtual float GetDrawableX() const {return GetX();};
275
282 virtual float GetDrawableY() const {return GetY();};
283
287 virtual float GetCenterX() const {return GetWidth()/2;};
288
292 virtual float GetCenterY() const {return GetHeight()/2;};
293
295
300
302 Force force5;
303
307 bool UpdateForce(float ElapsedTime);
308
309 float TotalForceX() const;
310 float TotalForceY() const;
311 float TotalForceAngle() const;
312 float TotalForceLength() const;
314
318 bool ClearForce();
319
320 #if defined(GD_IDE_ONLY)
321
324
334 virtual void GetPropertyForDebugger (unsigned int propertyNb, std::string & name, std::string & value) const;
335
346 virtual bool ChangeProperty(unsigned int propertyNb, std::string newValue);
347
351 virtual unsigned int GetNumberOfProperties() const;
353 #endif
354
357 void DeleteFromScene(RuntimeScene & scene);
359 void PutAroundAPosition( float positionX, float positionY, float distance, float angleInDegrees );
360 void AddForce( float x, float y, float clearing );
361 void AddForceUsingPolarCoordinates( float angle, float length, float clearing );
362 void AddForceTowardPosition( float positionX, float positionY, float length, float clearing );
363 void AddForceToMoveAround( float positionX, float positionY, float angularVelocity, float distance, float clearing );
364 void AddForceTowardObject( RuntimeObject * object, float length, float clearing );
365 void AddForceToMoveAroundObject( RuntimeObject * object, float velocity, float length, float clearing );
366 void PutAroundObject( RuntimeObject * object, float length, float angleInDegrees );
367
368 void SetXY( const char* xOperator, float xValue, const char* yOperator, float yValue );
369
370 void Duplicate( RuntimeScene & scene, std::map <std::string, std::vector<RuntimeObject*> *> pickedObjectLists );
371 void ActivateAutomatism( const std::string & automatismName, bool activate = true );
372 bool AutomatismActivated( const std::string & automatismName );
373
374 bool IsStopped();
375 bool TestAngleOfDisplacement( float angle, float tolerance );
376
377 double GetSqDistanceWithObject( RuntimeObject * other );
378 double GetDistanceWithObject( RuntimeObject * other );
379
380 double GetVariableValue( const std::string & variable );
381 const std::string & GetVariableString( const std::string & variable );
383 void SeparateFromObjects( std::map <std::string, std::vector<RuntimeObject*> *> pickedObjectLists);
384
387 void SeparateObjectsWithoutForces( std::map <std::string, std::vector<RuntimeObject*> *> pickedObjectLists);
388
391 void SeparateObjectsWithForces( std::map <std::string, std::vector<RuntimeObject*> *> pickedObjectLists);
393
394 protected:
395
396 std::string name;
397 std::string type;
398 float X;
399 float Y;
400 int zOrder;
401 bool hidden;
402 std::string layer;
403 std::map<std::string, gd::Automatism* > automatisms;
404 gd::VariablesContainer objectVariables;
405 std::vector < Force > forces;
406
411 void Init(const RuntimeObject & object);
412 };
413
417 void DestroyBaseRuntimeObject(RuntimeObject * object);
418
422 RuntimeObject * CreateBaseRuntimeObject(RuntimeScene & scene, const gd::Object & object);
423
424 #endif // RUNTIMEOBJECT_H