RioEngine  0.1
My first attempt to create a 3D WYSIWYG Game Engine
cgamescene.h
Go to the documentation of this file.
1 //--------------------------------------------------------------- @License begins
2 // RioEngine: The late night Coke -without whores- debugging sessions
3 // 2012-2015 Leopoldo Lomas Flores. Torreon, Coahuila. MEXICO
4 // leopoldolomas [at] gmail
5 // www.rioengine.com
6 // www.leopoldolomas.info
7 // "You have a problem, you face it like a man."
8 //
9 // This is free and unencumbered software released into the public domain.
10 //
11 // Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
12 // software, either in source code form or as a compiled binary, for any purpose,
13 // commercial or non-commercial, and by any means.
14 //
15 // In jurisdictions that recognize copyright laws, the author or authors of this
16 // software dedicate any and all copyright interest in the software to the public
17 // domain. We make this dedication for the benefit of the public at large and to
18 // the detriment of our heirs and successors. We intend this dedication to be
19 // an overt act of relinquishment in perpetuity of all present and future
20 // rights to this software under copyright law.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS
24 // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
26 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //--------------------------------------------------------------- @License ends
29 
30 #ifndef RIOENGINE_CENGINE_CGAMESCENE_H_
31 #define RIOENGINE_CENGINE_CGAMESCENE_H_
32 
33 #include <vector>
34 #include <string>
35 #include "cengine/cobject.h"
36 #include "cengine/cgameobject.h"
37 
38 class CGameScene : public CObject {
39  Q_OBJECT
40  Q_PROPERTY(QList<CGameObject> GameObjects READ gameObjects WRITE setGameObjects)
41 
42 public:
43  CGameScene();
44  CGameScene(const CGameScene& game_scene);
45  CGameScene& operator=(const CGameScene& game_scene);
46  virtual void copyValuesFromObject(const CGameScene& game_scene);
47 
55  CGameObject* createGameObjectWithNode(const std::string& node_id, bool add_to_scene = true, const char* object_type = NULL);
56 
60  void addGameObject(CGameObject* game_object);
61 
65  const CGameObject* getGameObject(const std::string& name) const;
66 
70  const CGameObject* getGameObject(uint uid) const;
71 
72  std::vector<CGameObject*>* getGameObjects() const;
73 
77  CGameObject* getGameObjectHavingTag(int tag) const;
78 
82  bool existsGameObjectWithName(const std::string& name);
83 
87  CGameObject* duplicateGameObject(const CGameObject* game_object);
88 
94  bool removeGameObject(uint uid);
95 
100  void removeGameObjectWhenAble(CGameObject* game_object);
101 
105  virtual void clear();
106 
110  virtual void run();
111 
115  virtual void preUpdate();
116 
120  virtual void update();
121 
125  virtual void postUpdate();
126 
131  virtual void updateWorld();
132 
136  virtual void postUpdateWorld();
137 
138  virtual void deleteWorld();
139 
140  virtual void performCollisionCallbacks();
141 
142  QList<CGameObject> gameObjects();
143  void setGameObjects(QList<CGameObject> game_objects);
144 
145  btDiscreteDynamicsWorld* dynamicsWorld() const;
146 
147  virtual ~CGameScene();
148 
149 protected:
150  std::string& createUniqueGameObjectName(std::string& original_name);
151 
152  virtual void start();
153 
157  virtual void stopAllActions();
158 
160 
161  std::vector<CGameObject*>* m_gameObjects;
162 
164  std::vector<CGameObject*>* m_gameObjectsPendingToBeAdded;
165 
167  std::vector<CGameObject*>* m_gameObjectsPendingToBeRemoved;
168 
169  // ------------------ bullet physics
170  btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
171  btDefaultCollisionConfiguration* m_collisionConfiguration;
172  btCollisionDispatcher* m_dispatcher;
173  btBroadphaseInterface* m_overlappingPairCache;
174  btSequentialImpulseConstraintSolver* m_solver;
175  btDiscreteDynamicsWorld* m_dynamicsWorld;
176 
177 private:
178  std::string& fixName(std::string& name);
179 
183  void callStart_R(CGameObject* child);
184 
188  void callPreUpdate_R(CGameObject* child);
189 
193  void callUpdate_R(CGameObject* child);
194 
198  void callPostUpdate_R(CGameObject* child);
199 };
200 
201 #endif // RIOENGINE_CENGINE_CGAMESCENE_H_
virtual void clear()
Definition: cgamescene.cpp:384
btSequentialImpulseConstraintSolver * m_solver
Definition: cgamescene.h:174
virtual void start()
Definition: cgamescene.cpp:148
btDefaultCollisionConfiguration * m_collisionConfiguration
Definition: cgamescene.h:171
CGameObject * duplicateGameObject(const CGameObject *game_object)
Definition: cgamescene.cpp:339
btDiscreteDynamicsWorld * m_dynamicsWorld
Definition: cgamescene.h:175
btBroadphaseInterface * m_overlappingPairCache
Definition: cgamescene.h:173
btDiscreteDynamicsWorld * dynamicsWorld() const
Definition: cgamescene.cpp:86
QList< CGameObject > GameObjects
Definition: cgamescene.h:40
std::vector< CGameObject * > * m_gameObjectsPendingToBeAdded
stores GameObjects added during the update loop
Definition: cgamescene.h:164
virtual void performCollisionCallbacks()
Definition: cgamescene.cpp:529
virtual ~CGameScene()
Definition: cgamescene.cpp:572
virtual void run()
Definition: cgamescene.cpp:423
std::vector< CGameObject * > * m_gameObjectsPendingToBeRemoved
stores GameObjects removed during the update loop
Definition: cgamescene.h:167
virtual void deleteWorld()
Definition: cgamescene.cpp:475
CGameObject * getGameObjectHavingTag(int tag) const
Definition: cgamescene.cpp:558
btAlignedObjectArray< btCollisionShape * > m_collisionShapes
Definition: cgamescene.h:170
bool m_isRunningUpdateLoops
Definition: cgamescene.h:159
virtual void postUpdate()
Definition: cgamescene.cpp:184
virtual void update()
Definition: cgamescene.cpp:170
std::string & createUniqueGameObjectName(std::string &original_name)
Definition: cgamescene.cpp:330
virtual void postUpdateWorld()
Definition: cgamescene.cpp:465
btCollisionDispatcher * m_dispatcher
Definition: cgamescene.h:172
void setGameObjects(QList< CGameObject > game_objects)
Definition: cgamescene.cpp:412
CGameObject * createGameObjectWithNode(const std::string &node_id, bool add_to_scene=true, const char *object_type=NULL)
Creates a GameObject based upon the specified Node id.
Definition: cgamescene.cpp:214
bool existsGameObjectWithName(const std::string &name)
Definition: cgamescene.cpp:294
std::vector< CGameObject * > * getGameObjects() const
Definition: cgamescene.cpp:288
const CGameObject * getGameObject(const std::string &name) const
Definition: cgamescene.cpp:260
bool removeGameObject(uint uid)
Definition: cgamescene.cpp:350
QList< CGameObject > gameObjects()
Definition: cgamescene.cpp:399
virtual void copyValuesFromObject(const CGameScene &game_scene)
Definition: cgamescene.cpp:80
virtual void stopAllActions()
Definition: cgamescene.cpp:512
virtual void preUpdate()
Definition: cgamescene.cpp:159
CGameScene & operator=(const CGameScene &game_scene)
Definition: cgamescene.cpp:69
CGameScene()
used to serialize the GameScene
Definition: cgamescene.cpp:43
void removeGameObjectWhenAble(CGameObject *game_object)
Definition: cgamescene.cpp:374
std::vector< CGameObject * > * m_gameObjects
Definition: cgamescene.h:161
void addGameObject(CGameObject *game_object)
Definition: cgamescene.cpp:244
virtual void updateWorld()
Definition: cgamescene.cpp:446