diff options
author | Kester Maddock <Christopher.Maddock.1@uni.massey.ac.nz> | 2004-11-22 13:19:19 +0300 |
---|---|---|
committer | Kester Maddock <Christopher.Maddock.1@uni.massey.ac.nz> | 2004-11-22 13:19:19 +0300 |
commit | 46fbe6b01e095ddb66f3bf6e0516569cfdca8f74 (patch) | |
tree | e7a7754188ef9b290eca479df6ac59b00ea7478b /source/gameengine/Ketsji | |
parent | cf91617d7829647629c8ce04b9f047dfbdf3d910 (diff) |
Fix for bugs: 1788 (forces) and 1799 (python delattr on game objects)
Use Polytope collision for faster mesh intersection tests, so SOLID can actually use that qhull lib now.
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r-- | source/gameengine/Ketsji/KX_CameraActuator.cpp | 2 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_ConvertPhysicsObject.h | 3 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp | 269 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_IpoActuator.cpp | 2 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 107 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_Scene.cpp | 10 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_Scene.h | 1 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_TouchEventManager.cpp | 47 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_TouchEventManager.h | 15 |
9 files changed, 291 insertions, 165 deletions
diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index f96276c37f1..4952c1050a7 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -194,7 +194,7 @@ bool KX_CameraActuator::Update(double curtime, bool frame) RemoveAllEvents(); if (bNegativeEvent) return false; - + /* The rules: */ /* CONSTRAINT 1: not implemented */ /* CONSTRAINT 2: can camera see actor? */ diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h index 0cf305dd14b..909229b04c2 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h @@ -44,7 +44,8 @@ typedef enum { KX_BOUNDSPHERE, KX_BOUNDCYLINDER, KX_BOUNDCONE, - KX_BOUNDMESH + KX_BOUNDMESH, + KX_BOUNDPOLYTOPE } KX_BoundBoxClass; struct KX_BoxBounds diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp index 3e0c7768f56..b72d17aa3b5 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp @@ -78,10 +78,11 @@ #include "KX_SumoPhysicsController.h" static GEN_Map<GEN_HashedPtr,DT_ShapeHandle> map_gamemesh_to_sumoshape; +static GEN_Map<GEN_HashedPtr, DT_VertexBaseHandle> map_gamemesh_to_vertex_base_handle; // forward declarations -void BL_RegisterSumoObject(KX_GameObject* gameobj,class SM_Scene* sumoScene,class SM_Object* sumoObj,const STR_String& matname,bool isDynamic,bool isActor); -DT_ShapeHandle CreateShapeFromMesh(RAS_MeshObject* meshobj); +static void BL_RegisterSumoObject(KX_GameObject* gameobj,class SM_Scene* sumoScene,class SM_Object* sumoObj,const STR_String& matname,bool isDynamic,bool isActor); +static DT_ShapeHandle CreateShapeFromMesh(RAS_MeshObject* meshobj, bool polytope); void KX_ConvertSumoObject( KX_GameObject* gameobj, @@ -127,6 +128,7 @@ void KX_ConvertSumoObject( KX_GameObject* gameobj, if (objprop->m_dyna && objprop->m_isactor) { DT_ShapeHandle shape = NULL; + bool polytope = false; switch (objprop->m_boundclass) { case KX_BOUNDBOX: @@ -151,10 +153,13 @@ void KX_ConvertSumoObject( KX_GameObject* gameobj, smprop->m_mass*objprop->m_boundobject.c.m_height*objprop->m_boundobject.c.m_height); break; /* Dynamic mesh objects. WARNING! slow. */ + case KX_BOUNDPOLYTOPE: + polytope = true; + // fall through case KX_BOUNDMESH: if (meshobj && meshobj->NumPolygons() > 0) { - if ((shape = CreateShapeFromMesh(meshobj))) + if ((shape = CreateShapeFromMesh(meshobj, polytope))) { // TODO: calculate proper inertia smprop->m_inertia *= smprop->m_mass*smprop->m_radius*smprop->m_radius; @@ -185,6 +190,7 @@ void KX_ConvertSumoObject( KX_GameObject* gameobj, { DT_ShapeHandle complexshape=0; + bool polytope = false; switch (objprop->m_boundclass) { @@ -200,11 +206,14 @@ void KX_ConvertSumoObject( KX_GameObject* gameobj, case KX_BOUNDCONE: complexshape = DT_NewCone(objprop->m_boundobject.c.m_radius, objprop->m_boundobject.c.m_height); break; + case KX_BOUNDPOLYTOPE: + polytope = true; + // fall through default: case KX_BOUNDMESH: if (numpolys>0) { - complexshape = CreateShapeFromMesh(meshobj); + complexshape = CreateShapeFromMesh(meshobj, polytope); //std::cout << "Convert Physics Mesh: " << meshobj->GetName() << std::endl; /* if (!complexshape) { @@ -267,7 +276,7 @@ void KX_ConvertSumoObject( KX_GameObject* gameobj, -void BL_RegisterSumoObject( +static void BL_RegisterSumoObject( KX_GameObject* gameobj, class SM_Scene* sumoScene, class SM_Object* sumoObj, @@ -296,21 +305,114 @@ void BL_RegisterSumoObject( physicscontroller->SetObject(gameobj->GetSGNode()); } -DT_ShapeHandle CreateShapeFromMesh(RAS_MeshObject* meshobj) +static DT_ShapeHandle InstancePhysicsComplex(RAS_MeshObject* meshobj, int vtxarray, RAS_IPolyMaterial *mat) +{ + // instance a mesh from a single vertex array & material + const RAS_TexVert *vertex_array = &((*meshobj->GetVertexCache(mat)[vtxarray])[0]); + //const KX_IndexArray &index_array = *meshobj->GetIndexCache(mat)[vtxarray]; + DT_VertexBaseHandle vertex_base = DT_NewVertexBase(vertex_array[0].getLocalXYZ(), sizeof(RAS_TexVert)); + + DT_ShapeHandle shape = DT_NewComplexShape(vertex_base); + + std::vector<DT_Index> indices; + for (int p = 0; p < meshobj->NumPolygons(); p++) + { + RAS_Polygon* poly = meshobj->GetPolygon(p); + + // only add polygons that have the collisionflag set + if (poly->IsCollider()) + { + DT_VertexIndices(3, poly->GetVertexIndexBase().m_indexarray); + + // tesselate + if (poly->VertexCount() == 4) + { + DT_Begin(); + DT_VertexIndex(poly->GetVertexIndexBase().m_indexarray[0]); + DT_VertexIndex(poly->GetVertexIndexBase().m_indexarray[2]); + DT_VertexIndex(poly->GetVertexIndexBase().m_indexarray[3]); + DT_End(); + } + } + } + + //DT_VertexIndices(indices.size(), &indices[0]); + DT_EndComplexShape(); + + map_gamemesh_to_vertex_base_handle.insert(GEN_HashedPtr(meshobj), vertex_base); + return shape; +} + +static DT_ShapeHandle InstancePhysicsPolytope(RAS_MeshObject* meshobj, int vtxarray, RAS_IPolyMaterial *mat) +{ + // instance a mesh from a single vertex array & material + const RAS_TexVert *vertex_array = &((*meshobj->GetVertexCache(mat)[vtxarray])[0]); + //const KX_IndexArray &index_array = *meshobj->GetIndexCache(mat)[vtxarray]; + DT_VertexBaseHandle vertex_base = DT_NewVertexBase(vertex_array[0].getLocalXYZ(), sizeof(RAS_TexVert)); + + std::vector<DT_Index> indices; + for (int p = 0; p < meshobj->NumPolygons(); p++) + { + RAS_Polygon* poly = meshobj->GetPolygon(p); + + // only add polygons that have the collisionflag set + if (poly->IsCollider()) + { + indices.push_back(poly->GetVertexIndexBase().m_indexarray[0]); + indices.push_back(poly->GetVertexIndexBase().m_indexarray[1]); + indices.push_back(poly->GetVertexIndexBase().m_indexarray[2]); + + if (poly->VertexCount() == 4) + indices.push_back(poly->GetVertexIndexBase().m_indexarray[3]); + } + } + + DT_ShapeHandle shape = DT_NewPolytope(vertex_base); + DT_VertexIndices(indices.size(), &indices[0]); + DT_EndPolytope(); + + map_gamemesh_to_vertex_base_handle.insert(GEN_HashedPtr(meshobj), vertex_base); + return shape; +} + +// This will have to be a method in a class somewhere... +// Update SOLID with a changed physics mesh. +// not used... yet. +bool ReInstanceShapeFromMesh(RAS_MeshObject* meshobj, int vtxarray, RAS_IPolyMaterial *mat) +{ + DT_VertexBaseHandle *vertex_base = map_gamemesh_to_vertex_base_handle[GEN_HashedPtr(meshobj)]; + if (vertex_base) + { + const RAS_TexVert *vertex_array = &((*meshobj->GetVertexCache(mat)[vtxarray])[0]); + DT_ChangeVertexBase(*vertex_base, vertex_array[0].getLocalXYZ()); + return true; + } + return false; +} + +static DT_ShapeHandle CreateShapeFromMesh(RAS_MeshObject* meshobj, bool polytope) { DT_ShapeHandle *shapeptr = map_gamemesh_to_sumoshape[GEN_HashedPtr(meshobj)]; + // Mesh has already been converted: reuse if (shapeptr) { return *shapeptr; } + // Mesh has no polygons! int numpolys = meshobj->NumPolygons(); if (!numpolys) { return NULL; } + + // Count the number of collision polygons and check they all come from the same + // vertex array int numvalidpolys = 0; + int vtxarray = -1; + RAS_IPolyMaterial *poly_material = NULL; + bool reinstance = true; for (int p=0; p<numpolys; p++) { @@ -319,74 +421,116 @@ DT_ShapeHandle CreateShapeFromMesh(RAS_MeshObject* meshobj) // only add polygons that have the collisionflag set if (poly->IsCollider()) { + // check polygon is from the same vertex array + if (poly->GetVertexIndexBase().m_vtxarray != vtxarray) + { + if (vtxarray < 0) + vtxarray = poly->GetVertexIndexBase().m_vtxarray; + else + { + reinstance = false; + vtxarray = -1; + } + } + + // check poly is from the same material + if (poly->GetMaterial()->GetPolyMaterial() != poly_material) + { + if (poly_material) + { + reinstance = false; + poly_material = NULL; + } + else + poly_material = poly->GetMaterial()->GetPolyMaterial(); + } + + // count the number of collision polys numvalidpolys++; - break; + + // We have one collision poly, and we can't reinstance, so we + // might as well break here. + if (!reinstance) + break; } } + // No collision polygons if (numvalidpolys < 1) return NULL; - DT_ShapeHandle shape = DT_NewComplexShape(NULL); - - - numvalidpolys = 0; - - for (int p2=0; p2<numpolys; p2++) + DT_ShapeHandle shape; + if (reinstance) { - RAS_Polygon* poly = meshobj->GetPolygon(p2); - - // only add polygons that have the collisionflag set - if (poly->IsCollider()) - { /* We have to tesselate here because SOLID can only raycast triangles */ - DT_Begin(); - DT_Vector3 pt; - /* V1 */ - meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, - poly->GetVertexIndexBase().m_indexarray[2], - poly->GetMaterial()->GetPolyMaterial())->xyz().getValue(pt); - DT_Vertex(pt); - /* V2 */ - meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, - poly->GetVertexIndexBase().m_indexarray[1], - poly->GetMaterial()->GetPolyMaterial())->xyz().getValue(pt); - DT_Vertex(pt); - /* V3 */ - meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, - poly->GetVertexIndexBase().m_indexarray[0], - poly->GetMaterial()->GetPolyMaterial())->xyz().getValue(pt); - DT_Vertex(pt); - - numvalidpolys++; - DT_End(); + if (polytope) + shape = InstancePhysicsPolytope(meshobj, vtxarray, poly_material); + else + shape = InstancePhysicsComplex(meshobj, vtxarray, poly_material); + } + else + { + if (polytope) + { + std::cout << "CreateShapeFromMesh: " << meshobj->GetName() << " is not suitable for polytope." << std::endl; + if (!poly_material) + std::cout << " Check mesh materials." << std::endl; + if (vtxarray < 0) + std::cout << " Check number of vertices." << std::endl; + } + + shape = DT_NewComplexShape(NULL); - if (poly->VertexCount() == 4) - { - DT_Begin(); + numvalidpolys = 0; + + for (int p2=0; p2<numpolys; p2++) + { + RAS_Polygon* poly = meshobj->GetPolygon(p2); + + // only add polygons that have the collisionflag set + if (poly->IsCollider()) + { /* We have to tesselate here because SOLID can only raycast triangles */ + DT_Begin(); /* V1 */ - meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, - poly->GetVertexIndexBase().m_indexarray[3], - poly->GetMaterial()->GetPolyMaterial())->xyz().getValue(pt); - DT_Vertex(pt); - /* V3 */ - meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, + DT_Vertex(meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, poly->GetVertexIndexBase().m_indexarray[2], - poly->GetMaterial()->GetPolyMaterial())->xyz().getValue(pt); - DT_Vertex(pt); - /* V4 */ - meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, + poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ()); + /* V2 */ + DT_Vertex(meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, + poly->GetVertexIndexBase().m_indexarray[1], + poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ()); + /* V3 */ + DT_Vertex(meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, poly->GetVertexIndexBase().m_indexarray[0], - poly->GetMaterial()->GetPolyMaterial())->xyz().getValue(pt); - DT_Vertex(pt); - + poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ()); + numvalidpolys++; - DT_End(); + DT_End(); + + if (poly->VertexCount() == 4) + { + DT_Begin(); + /* V1 */ + DT_Vertex(meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, + poly->GetVertexIndexBase().m_indexarray[3], + poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ()); + /* V3 */ + DT_Vertex(meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, + poly->GetVertexIndexBase().m_indexarray[2], + poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ()); + /* V4 */ + DT_Vertex(meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, + poly->GetVertexIndexBase().m_indexarray[0], + poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ()); + + numvalidpolys++; + DT_End(); + } + } - } + + DT_EndComplexShape(); } - - DT_EndComplexShape(); if (numvalidpolys > 0) { @@ -398,17 +542,22 @@ DT_ShapeHandle CreateShapeFromMesh(RAS_MeshObject* meshobj) return NULL; } - void KX_ClearSumoSharedShapes() { int numshapes = map_gamemesh_to_sumoshape.size(); - for (int i=0;i<numshapes ;i++) + int i; + for (i=0;i<numshapes ;i++) { DT_ShapeHandle shape = *map_gamemesh_to_sumoshape.at(i); DT_DeleteShape(shape); } map_gamemesh_to_sumoshape.clear(); + + for (i=0; i < map_gamemesh_to_vertex_base_handle.size(); i++) + DT_DeleteVertexBase(*map_gamemesh_to_vertex_base_handle.at(i)); + + map_gamemesh_to_vertex_base_handle.clear(); } diff --git a/source/gameengine/Ketsji/KX_IpoActuator.cpp b/source/gameengine/Ketsji/KX_IpoActuator.cpp index 52d9d3e4790..08464fc88de 100644 --- a/source/gameengine/Ketsji/KX_IpoActuator.cpp +++ b/source/gameengine/Ketsji/KX_IpoActuator.cpp @@ -276,7 +276,7 @@ bool KX_IpoActuator::Update(double curtime, bool frame) m_direction = 1; SetStartTime(curtime); } - + SetLocalTime(curtime); if (ClampLocalTime() && m_localtime == m_startframe) diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index bd84e7e0104..3bd36aebc93 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -315,13 +315,13 @@ void KX_KetsjiEngine::NextFrame() m_logger->StartLog(tc_services, m_kxsystem->GetTimeInSeconds(), true); double curtime; - double localtime = m_previoustime; if (m_bFixedTime) curtime = m_previoustime + 1.0/m_ticrate; else curtime = m_kxsystem->GetTimeInSeconds(); m_deltatime += curtime - m_previoustime; m_previoustime = curtime; + double localtime = curtime - m_deltatime; // Compute the number of logic frames to do each update (fixed tic bricks) int frames = (int) (m_deltatime*m_ticrate); @@ -329,44 +329,7 @@ void KX_KetsjiEngine::NextFrame() KX_SceneList::iterator sceneit; - if (!frames) - { - for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); ++sceneit) - // for each scene, call the proceed functions - { - KX_Scene* scene = *sceneit; - - if (!scene->IsSuspended()) - { - // set Python hooks for each scene - PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment()); - PHY_SetActiveScene(scene); - - // Perform physics calculations on the scene. This can involve - // many iterations of the physics solver. - m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true); - scene->GetPhysicsEnvironment()->proceed(curtime); - // Update scenegraph after physics step. This maps physics calculations - // into node positions. - m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); - scene->UpdateParents(curtime); - - // Do some cleanup work for this logic frame - m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true); - scene->LogicUpdateFrame(curtime, false); - - // Actuators can affect the scenegraph - m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); - scene->UpdateParents(curtime); - } // suspended - - DoSound(scene); - - m_logger->StartLog(tc_services, m_kxsystem->GetTimeInSeconds(), true); - } - } - - while (frames--) + while (frames) { localtime += 1.0/m_ticrate; for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); ++sceneit) @@ -384,44 +347,46 @@ void KX_KetsjiEngine::NextFrame() if (!scene->IsSuspended()) { m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true); - scene->GetPhysicsEnvironment()->endFrame(); - scene->GetPhysicsEnvironment()->beginFrame(); - m_logger->StartLog(tc_network, m_kxsystem->GetTimeInSeconds(), true); - scene->GetNetworkScene()->proceed(curtime); + scene->GetNetworkScene()->proceed(localtime); // set Python hooks for each scene PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment()); PHY_SetActiveScene(scene); - // Perform physics calculations on the scene. This can involve - // many iterations of the physics solver. - m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true); - scene->GetPhysicsEnvironment()->proceed(curtime); + scene->GetPhysicsEnvironment()->endFrame(); + // Update scenegraph after physics step. This maps physics calculations // into node positions. m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); - scene->UpdateParents(curtime); + scene->UpdateParents(localtime); // Process sensors, and controllers m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true); - scene->LogicBeginFrame(curtime); + scene->LogicBeginFrame(localtime); // Scenegraph needs to be updated again, because Logic Controllers // can affect the local matrices. m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); - scene->UpdateParents(curtime); + scene->UpdateParents(localtime); // Process actuators // Do some cleanup work for this logic frame m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true); - scene->LogicUpdateFrame(curtime, true); + scene->LogicUpdateFrame(localtime, true); scene->LogicEndFrame(); // Actuators can affect the scenegraph m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); - scene->UpdateParents(curtime); + scene->UpdateParents(localtime); + + scene->GetPhysicsEnvironment()->beginFrame(); + + // Perform physics calculations on the scene. This can involve + // many iterations of the physics solver. + m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true); + scene->GetPhysicsEnvironment()->proceed(localtime); } // suspended DoSound(scene); @@ -445,8 +410,46 @@ void KX_KetsjiEngine::NextFrame() // scene management ProcessScheduledScenes(); + + frames--; } + // Logic update sub frame: this will let some logic bricks run at the + // full frame rate. + for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); ++sceneit) + // for each scene, call the proceed functions + { + KX_Scene* scene = *sceneit; + + if (!scene->IsSuspended()) + { + // set Python hooks for each scene + PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment()); + PHY_SetActiveScene(scene); + + // Perform physics calculations on the scene. This can involve + // many iterations of the physics solver. + m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true); + scene->GetPhysicsEnvironment()->proceed(curtime); + // Update scenegraph after physics step. This maps physics calculations + // into node positions. + m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); + scene->UpdateParents(curtime); + + // Do some cleanup work for this logic frame + m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true); + scene->LogicUpdateFrame(curtime, false); + + // Actuators can affect the scenegraph + m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); + scene->UpdateParents(curtime); + } // suspended + + DoSound(scene); + + m_logger->StartLog(tc_services, m_kxsystem->GetTimeInSeconds(), true); + } + // Start logging time spend outside main loop m_logger->StartLog(tc_outside, m_kxsystem->GetTimeInSeconds(), true); } diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index f10ea902c96..26825fe5e1f 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -860,7 +860,7 @@ void KX_Scene::MarkSubTreeVisible(SG_Tree *node, RAS_IRasterizer* rasty, bool vi for (int m=0;m<nummeshes;m++) { // this adds the vertices to the display list - (gameobj->GetMesh(m))->SchedulePolygons(t, rasty->GetDrawingMode(),rasty); + (gameobj->GetMesh(m))->SchedulePolygons(t, rasty->GetDrawingMode()); } } gameobj->MarkVisible(visible); @@ -916,7 +916,7 @@ void KX_Scene::MarkVisible(RAS_IRasterizer* rasty, KX_GameObject* gameobj) for (int m=0;m<nummeshes;m++) { // this adds the vertices to the display list - (gameobj->GetMesh(m))->SchedulePolygons(t, rasty->GetDrawingMode(),rasty); + (gameobj->GetMesh(m))->SchedulePolygons(t, rasty->GetDrawingMode()); } // Visibility/ non-visibility are marked // elsewhere now. @@ -1186,6 +1186,12 @@ PyObject* KX_Scene::_getattr(const STR_String& attr) _getattr_up(PyObjectPlus); } +int KX_Scene::_delattr(const STR_String &attr) +{ + PyDict_DelItemString(m_attrlist, const_cast<char *>(attr.ReadPtr())); + return 0; +} + int KX_Scene::_setattr(const STR_String &attr, PyObject *pyvalue) { diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index 2f867c28c40..74161a4d5b8 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -514,6 +514,7 @@ public: virtual PyObject* _getattr(const STR_String& attr); /* name, active_camera, gravity, suspended, viewport, framing, activity_culling, activity_culling_radius */ virtual int _setattr(const STR_String &attr, PyObject *pyvalue); + virtual int _delattr(const STR_String &attr); }; typedef std::vector<KX_Scene*> KX_SceneList; diff --git a/source/gameengine/Ketsji/KX_TouchEventManager.cpp b/source/gameengine/Ketsji/KX_TouchEventManager.cpp index 4f074ce9b12..a95e6a13548 100644 --- a/source/gameengine/Ketsji/KX_TouchEventManager.cpp +++ b/source/gameengine/Ketsji/KX_TouchEventManager.cpp @@ -40,31 +40,6 @@ #include "SM_Object.h" -KX_TouchEventManager::Collision::Collision(SCA_ISensor *sensor, SM_Object *obj1, SM_Object *obj2) - : m_id(next_id++), - m_sensor(sensor), - m_object1(obj1), - m_object2(obj2) -{ -} - -bool KX_TouchEventManager::Collision::operator<(const Collision &other) const -{ - if (*this == other) - return true; - - return m_id < other.m_id; -} - -bool KX_TouchEventManager::Collision::operator==(const Collision &other) const -{ - return m_sensor == other.m_sensor && - ((m_object1 == other.m_object1 && m_object2 == other.m_object2) || - (m_object1 == other.m_object2 && m_object2 == other.m_object1)); -} - -int KX_TouchEventManager::Collision::next_id = 0; - KX_TouchEventManager::KX_TouchEventManager(class SCA_LogicManager* logicmgr, SM_Scene *scene) : SCA_EventManager(TOUCH_EVENTMGR), @@ -80,15 +55,8 @@ DT_Bool KX_TouchEventManager::HandleCollision(void* object1, void* object2, cons { SM_Object * obj1 = static_cast<SM_Object*>(object1); SM_Object * obj2 = static_cast<SM_Object*>(object2); - KX_ClientObjectInfo *client_info = static_cast<KX_ClientObjectInfo *>(obj1->getClientObject()); - list<SCA_ISensor*>::iterator it; - for ( it = client_info->m_sensors.begin(); it != client_info->m_sensors.end(); ++it) - m_collisions.insert(Collision(*it, obj1, obj2)); - - client_info = static_cast<KX_ClientObjectInfo *>(obj2->getClientObject()); - for ( it = client_info->m_sensors.begin(); it != client_info->m_sensors.end(); ++it) - m_collisions.insert(Collision(*it, obj2, obj1)); + m_collisions.insert(std::pair<SM_Object*, SM_Object*>(obj1, obj2)); return DT_CONTINUE; } @@ -164,7 +132,17 @@ void KX_TouchEventManager::NextFrame() static_cast<KX_TouchSensor*>(*it)->SynchronizeTransform(); for (std::set<Collision>::iterator cit = m_collisions.begin(); cit != m_collisions.end(); ++cit) - static_cast<KX_TouchSensor*>((*cit).m_sensor)->HandleCollision((*cit).m_object1, (*cit).m_object2, NULL); + { + KX_ClientObjectInfo *client_info = static_cast<KX_ClientObjectInfo *>((*cit).first->getClientObject()); + + list<SCA_ISensor*>::iterator sit; + for ( sit = client_info->m_sensors.begin(); sit != client_info->m_sensors.end(); ++sit) + static_cast<KX_TouchSensor*>(*sit)->HandleCollision((*cit).first, (*cit).second, NULL); + + client_info = static_cast<KX_ClientObjectInfo *>((*cit).second->getClientObject()); + for ( sit = client_info->m_sensors.begin(); sit != client_info->m_sensors.end(); ++sit) + static_cast<KX_TouchSensor*>(*sit)->HandleCollision((*cit).second, (*cit).first, NULL); + } m_collisions.clear(); @@ -184,6 +162,7 @@ void KX_TouchEventManager::RemoveSensor(class SCA_ISensor* sensor) std::swap(*i, m_sensors.back()); m_sensors.pop_back(); } + // remove the sensor forever :) SCA_EventManager::RemoveSensor(sensor); } diff --git a/source/gameengine/Ketsji/KX_TouchEventManager.h b/source/gameengine/Ketsji/KX_TouchEventManager.h index eb2c26a64f3..128758f0be6 100644 --- a/source/gameengine/Ketsji/KX_TouchEventManager.h +++ b/source/gameengine/Ketsji/KX_TouchEventManager.h @@ -44,20 +44,7 @@ class SM_Object; class KX_TouchEventManager : public SCA_EventManager { - struct Collision - { - static int next_id; - int m_id; - SCA_ISensor *m_sensor; - SM_Object *m_object1; - SM_Object *m_object2; - - Collision(SCA_ISensor *sensor, SM_Object *obj1, SM_Object *obj2); - - bool operator<(const Collision &other) const; - bool operator==(const Collision &other) const; - }; - + typedef std::pair<SM_Object*, SM_Object*> Collision; class SCA_LogicManager* m_logicmgr; SM_Scene *m_scene; |