Added several delete/destructor, speeds up exit & saves memory.legacy
| @@ -322,6 +322,13 @@ void BtPhysTest::TickDraw(float seconds) | |||||
| BtPhysTest::~BtPhysTest() | BtPhysTest::~BtPhysTest() | ||||
| { | { | ||||
| Ticker::Unref(m_camera); | Ticker::Unref(m_camera); | ||||
| Ticker::Unref(m_ground_object); | |||||
| while (m_physobj_list.Count()) | |||||
| { | |||||
| PhysicsObject* CurPop = m_physobj_list.Last(); | |||||
| m_physobj_list.Pop(); | |||||
| Ticker::Unref(CurPop); | |||||
| } | |||||
| #if 0 | #if 0 | ||||
| //Exit Physics | //Exit Physics | ||||
| @@ -62,16 +62,28 @@ public: | |||||
| MeshRand << "[sc#ada scb#ada ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]"; | MeshRand << "[sc#ada scb#ada ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]"; | ||||
| MeshRand << "[sc#aad scb#aad ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]"; | MeshRand << "[sc#aad scb#aad ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]"; | ||||
| int CylLimit = MeshRand.Count(); | |||||
| MeshRand << "[sc#add scb#add ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]"; | |||||
| MeshRand << "[sc#dad scb#dad ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]"; | |||||
| MeshRand << "[sc#dda scb#dda ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]"; | |||||
| MeshRand << "[sc#daa scb#daa ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]"; | |||||
| MeshRand << "[sc#ada scb#ada ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]"; | |||||
| MeshRand << "[sc#aad scb#aad ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]"; | |||||
| int RandValue = (int)(lol::RandF() * (MeshRand.Count() - 1)); | int RandValue = (int)(lol::RandF() * (MeshRand.Count() - 1)); | ||||
| m_mesh.Compile(MeshRand[RandValue]); | m_mesh.Compile(MeshRand[RandValue]); | ||||
| vec3 BoxSize = vec3(2.0f); | vec3 BoxSize = vec3(2.0f); | ||||
| if (RandValue >= SphereLimit && RandValue < ConeLimit) | |||||
| if (RandValue < SphereLimit) | |||||
| m_physics.SetShapeToBox(BoxSize); | |||||
| else if (RandValue < ConeLimit) | |||||
| m_physics.SetShapeToSphere(BoxSize.x); | m_physics.SetShapeToSphere(BoxSize.x); | ||||
| else if (RandValue >= ConeLimit) | |||||
| else if (RandValue < CylLimit) | |||||
| m_physics.SetShapeToCone(BoxSize.x, BoxSize.y); | m_physics.SetShapeToCone(BoxSize.x, BoxSize.y); | ||||
| else | else | ||||
| m_physics.SetShapeToBox(BoxSize); | |||||
| m_physics.SetShapeToCylinder(BoxSize); | |||||
| m_physics.SetMass(base_mass); | m_physics.SetMass(base_mass); | ||||
| m_physics.SetBaseTransform(base_location); | m_physics.SetBaseTransform(base_location); | ||||
| m_physics.InitBodyToRigid(); | m_physics.InitBodyToRigid(); | ||||
| @@ -40,6 +40,13 @@ EasyPhysics::EasyPhysics() : | |||||
| { | { | ||||
| } | } | ||||
| EasyPhysics::~EasyPhysics() | |||||
| { | |||||
| delete m_collision_object; | |||||
| delete m_collision_shape; | |||||
| delete m_motion_state; | |||||
| } | |||||
| //------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
| //Set Shape functions | //Set Shape functions | ||||
| //-- | //-- | ||||
| @@ -79,6 +86,13 @@ void EasyPhysics::SetShapeToCone(float radius, float height) | |||||
| height * LOL2BT_UNIT)); | height * LOL2BT_UNIT)); | ||||
| } | } | ||||
| void EasyPhysics::SetShapeToCylinder(lol::vec3& cyl_size) | |||||
| { | |||||
| vec3 new_cyl_size = cyl_size * LOL2BT_UNIT; | |||||
| new_cyl_size.y *= LOL2BT_SIZE; | |||||
| SetShapeTo(new btCylinderShape(LOL2BT_VEC3(new_cyl_size))); | |||||
| } | |||||
| //------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
| //Base Location/Rotation setup | //Base Location/Rotation setup | ||||
| //-- | //-- | ||||
| @@ -34,10 +34,13 @@ class EasyPhysics | |||||
| #ifdef HAVE_PHYS_USE_BULLET | #ifdef HAVE_PHYS_USE_BULLET | ||||
| public: | public: | ||||
| EasyPhysics(); | EasyPhysics(); | ||||
| ~EasyPhysics(); | |||||
| void SetShapeToBox(lol::vec3& box_size); | void SetShapeToBox(lol::vec3& box_size); | ||||
| void SetShapeToSphere(float radius); | void SetShapeToSphere(float radius); | ||||
| void SetShapeToCone(float radius, float height); | void SetShapeToCone(float radius, float height); | ||||
| void SetShapeToCylinder(lol::vec3& cyl_size); | |||||
| void SetBaseTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f))); | void SetBaseTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f))); | ||||
| void SetMass(float mass); | void SetMass(float mass); | ||||
| void InitBodyToRigid(); | void InitBodyToRigid(); | ||||
| @@ -32,7 +32,10 @@ public: | |||||
| m_dynamics_world(NULL) | m_dynamics_world(NULL) | ||||
| { | { | ||||
| } | } | ||||
| ~Simulation() { } | |||||
| ~Simulation() | |||||
| { | |||||
| ExitContext(); | |||||
| } | |||||
| char const *GetName() { return "<Simulation>"; } | char const *GetName() { return "<Simulation>"; } | ||||
| @@ -72,11 +75,11 @@ public: | |||||
| void ExitContext() | void ExitContext() | ||||
| { | { | ||||
| delete m_broadphase; | |||||
| delete m_collision_configuration; | |||||
| delete m_dispatcher; | |||||
| delete m_solver; | |||||
| delete m_dynamics_world; | delete m_dynamics_world; | ||||
| delete m_solver; | |||||
| delete m_dispatcher; | |||||
| delete m_collision_configuration; | |||||
| delete m_broadphase; | |||||
| } | } | ||||
| btDiscreteDynamicsWorld* GetWorld() | btDiscreteDynamicsWorld* GetWorld() | ||||