50 m_dispatcher =
new btCollisionDispatcher(m_collisionConfiguration);
52 m_solver =
new btSequentialImpulseConstraintSolver();
56 m_collisionConfiguration);
70 if (
this == &original_obj)
94 for(QObjectList::const_iterator it = child->children().begin();
95 it != child->children().end();
98 if(child_as_gameobject != NULL) {
99 callStart_R(child_as_gameobject);
106 void CGameScene::callPreUpdate_R(
CGameObject* child) {
108 for(QObjectList::const_iterator it = child->children().begin();
109 it != child->children().end();
112 if(child_as_gameobject != NULL) {
113 callPreUpdate_R(child_as_gameobject);
120 void CGameScene::callUpdate_R(
CGameObject* child) {
122 for(QObjectList::const_iterator it = child->children().begin();
123 it != child->children().end();
126 if(child_as_gameobject != NULL) {
127 callUpdate_R(child_as_gameobject);
134 void CGameScene::callPostUpdate_R(
CGameObject* child) {
136 for(QObjectList::const_iterator it = child->children().begin();
137 it != child->children().end();
140 if(child_as_gameobject != NULL) {
141 callPostUpdate_R(child_as_gameobject);
150 for (std::vector<CGameObject*>::iterator it =
m_gameObjects->begin();
161 for (std::vector<CGameObject*>::iterator it =
m_gameObjects->begin();
164 callPreUpdate_R(*it);
171 for (std::vector<CGameObject*>::iterator it =
m_gameObjects->begin();
185 for (std::vector<CGameObject*>::iterator it =
m_gameObjects->begin();
188 callPostUpdate_R(*it);
230 std::string fixed_node_id = node_id;
246 game_object->setParent(
this);
253 game_object->deployIntoDynamicsWorld();
255 callStart_R(game_object);
261 for (std::vector<CGameObject*>::iterator it =
m_gameObjects->begin();
265 if (game_obj->objectName().toStdString() == name) {
275 for (std::vector<CGameObject*>::iterator it =
m_gameObjects->begin();
279 if (game_obj->uid() == uid) {
295 for (std::vector<CGameObject*>::iterator it =
m_gameObjects->begin();
298 if ((*it)->name() == name) {
308 std::string& CGameScene::fixName(std::string& name) {
309 std::string regex_ext_str =
"_([0-9]*)";
310 std::tr1::regex regex_ext(regex_ext_str);
311 std::tr1::cmatch match;
312 if (regex_search(name.c_str(), match, regex_ext)) {
313 std::string match_str = match.str().substr(1, match.str().size() - 1);
314 unsigned int index = atoi(match_str.c_str());
316 name = name.substr(0, name.size() - match_str.length() - 1);
319 sprintf_s(suffix,
"_%i", ++index);
332 name = fixName(name);
353 for (std::vector<CGameObject*>::iterator it =
m_gameObjects->begin();
356 if ((*it)->uid() == uid) {
361 if (game_object == NULL) {
365 game_object->aboutToBeRemoved();
366 game_object->removeFromDynamicsWorld();
368 game_object->setParent(NULL);
386 for (std::vector<CGameObject*>::iterator it =
m_gameObjects->begin();
390 obj->aboutToBeRemoved();
394 CDIRECTOR->getCameraWithId(k_CDirector_DefaultCameraId)->reset();
400 QList<CGameObject> vec = QList<CGameObject>();
401 for (std::vector<CGameObject*>::iterator it =
m_gameObjects->begin();
414 for (
int i = 0; i < vec.count(); i++) {
424 for (std::vector<CGameObject*>::iterator it =
m_gameObjects->begin();
429 int type_id = QMetaType::type(obj->CObjectTypeName().toStdString().c_str());
432 new_obj =
static_cast<CGameObject*
>(QMetaType::create(type_id, obj));
433 new_obj->setParent(
this);
434 new_obj->bulletProperties = obj->bulletProperties;
437 new_obj->deployIntoDynamicsWorld();
447 BT_PROFILE(
"update");
449 for (std::vector<CGameObject*>::iterator it =
m_gameObjects->begin();
454 btRigidBody* body = obj->bulletProperties.
rigidBody();
456 body->getMotionState()->getWorldTransform(trans);
466 for (std::vector<CGameObject*>::iterator it =
m_gameObjects->begin();
469 (*it)->postWorldUpdate();
477 for (
int i =
m_dynamicsWorld->getNumCollisionObjects() - 1; i >= 0 ;i--) {
478 btCollisionObject* obj =
m_dynamicsWorld ->getCollisionObjectArray()[i];
479 btRigidBody* body = btRigidBody::upcast(obj);
480 if (body && body ->getMotionState()) {
513 for (std::vector<CGameObject*>::iterator it =
m_gameObjects->begin();
516 (*it)->stopAllActions();
517 for (QList<QObject*>::const_iterator inner_it = (*it)->children().begin();
518 inner_it != (*it)->children().end();
520 if (qobject_cast<CGameObject*>(*inner_it) != NULL) {
521 static_cast<CGameObject*
>(*inner_it)->stopAllActions();
530 int numManifolds =
dynamicsWorld()->getDispatcher()->getNumManifolds();
531 for (
int i=0;i<numManifolds;i++)
533 btPersistentManifold* contactManifold =
dynamicsWorld()->getDispatcher()->getManifoldByIndexInternal(i);
534 const btCollisionObject* obA = contactManifold->getBody0();
535 const btCollisionObject* obB = contactManifold->getBody1();
537 int numContacts = contactManifold->getNumContacts();
538 for (
int j=0;j<numContacts;j++)
540 btManifoldPoint& pt = contactManifold->getContactPoint(j);
541 if (pt.getDistance() < 0.f)
549 objectA->onCollisionWithObject(objectB);
550 objectB->onCollisionWithObject(objectA);
559 for (std::vector<CGameObject*>::iterator it =
m_gameObjects->begin();
563 if (game_obj->tag() == tag) {
void copyNodeValuesFromNode(CLNode *node)
btSequentialImpulseConstraintSolver * m_solver
void setRigidBody(btRigidBody *rigid_body)
btDefaultCollisionConfiguration * m_collisionConfiguration
static void deleteVector(std::vector< T * > *vec)
CGameObject * duplicateGameObject(const CGameObject *game_object)
static bool replaceObjectInVector(std::vector< T * > *vec, T *object_to_replace, T *replacement)
btDiscreteDynamicsWorld * m_dynamicsWorld
static CGameObject * createInstance(const char *class_name)
btBroadphaseInterface * m_overlappingPairCache
btDiscreteDynamicsWorld * dynamicsWorld() const
std::vector< CGameObject * > * m_gameObjectsPendingToBeAdded
stores GameObjects added during the update loop
virtual void performCollisionCallbacks()
std::vector< CGameObject * > * m_gameObjectsPendingToBeRemoved
stores GameObjects removed during the update loop
virtual void deleteWorld()
bool isValidCObject() const
CGameObject * getGameObjectHavingTag(int tag) const
btAlignedObjectArray< btCollisionShape * > m_collisionShapes
bool m_isRunningUpdateLoops
virtual void postUpdate()
std::string & createUniqueGameObjectName(std::string &original_name)
virtual void postUpdateWorld()
btCollisionDispatcher * m_dispatcher
void setGameObjects(QList< CGameObject > game_objects)
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.
bool existsGameObjectWithName(const std::string &name)
std::vector< CGameObject * > * getGameObjects() const
const CGameObject * getGameObject(const std::string &name) const
bool removeGameObject(uint uid)
QList< CGameObject > gameObjects()
const bool physicsEnabled() const
virtual void copyValuesFromObject(const CGameScene &game_scene)
virtual void stopAllActions()
btRigidBody * rigidBody() const
CGameScene & operator=(const CGameScene &game_scene)
#define CLASSETSREPOSITORY
static bool deleteObjectFromVector(std::vector< T * > *vec, void *object_to_delete)
CGameScene()
used to serialize the GameScene
static bool vectorContainsObject(std::vector< T > *vec, T object_to_find)
void removeGameObjectWhenAble(CGameObject *game_object)
std::vector< CGameObject * > * m_gameObjects
void addGameObject(CGameObject *game_object)
virtual void updateWorld()