Rockets deleted properly

This commit is contained in:
ViktorLjung
2014-05-21 18:30:16 +02:00
parent 6d3aa5d394
commit 6137adf604
10 changed files with 132 additions and 51 deletions
+15 -11
View File
@@ -122,6 +122,7 @@ void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
cf->Register<Components::MeshShape>([]() { return new Components::MeshShape(); });
cf->Register<Components::HingeConstraint>([]() { return new Components::HingeConstraint(); });
cf->Register<Components::WheelPair>([]() { return new Components::WheelPair(); });
cf->Register<Components::TankShell>([]() { return new Components::TankShell(); });
}
void Systems::PhysicsSystem::Update(double dt)
@@ -159,7 +160,6 @@ void Systems::PhysicsSystem::Update(double dt)
m_PhysicsWorld->unmarkForWrite();
}
}
static const double timestep = 1 / 60.0;
@@ -580,14 +580,18 @@ bool Systems::PhysicsSystem::OnApplyPointImpulse( const Events::ApplyPointImpuls
void Systems::PhysicsSystem::OnEntityRemoved( EntityID entity )
{
// TODO:
/*auto rigidBodyIt = m_RigidBodies.find(entity);
if (rigidBodyIt == m_RigidBodies.end())
return;
auto rigidBody = rigidBodyIt->second;
m_RigidBodies.erase(entity);
m_RigidBodyEntities.erase(rigidBody);
rigidBody->removeReference();*/
if(m_RigidBodies.find(entity) != m_RigidBodies.end())
{
m_RigidBodyEntities.erase(m_RigidBodies[entity]);
m_PhysicsWorld->markForWrite();
m_PhysicsWorld->removeEntity(m_RigidBodies[entity]);
m_PhysicsWorld->unmarkForWrite();
m_RigidBodies.erase(entity);
}
if(m_Vehicles.find(entity) != m_Vehicles.end())
{
m_PhysicsWorld->markForWrite();
m_Vehicles[entity]->removeFromWorld();
m_PhysicsWorld->unmarkForWrite();
}
}
+32 -11
View File
@@ -76,7 +76,8 @@
#include <Physics2012/Dynamics/Collide/ContactListener/hkpContactListener.h>
#include "Components/Model.h"
#include "Components/TankShell.h"
#include <Physics2012/Collide/Shape/Misc/PhantomCallback/hkpPhantomCallbackShape.h>
namespace Systems
{
class PhysicsSystem : public System
@@ -94,27 +95,47 @@ public:
EntityID entity1 = m_PhysicsSystem->m_RigidBodyEntities[event.getBody(0)];
EntityID entity2 = m_PhysicsSystem->m_RigidBodyEntities[event.getBody(1)];
m_PhysicsSystem->m_PhysicsWorld->unmarkForRead();
Events::Collision e;
e.Entity1 = entity1;
e.Entity2 = entity2;
m_PhysicsSystem->EventBroker->Publish(e);
auto modelComponent = m_PhysicsSystem->m_World->GetComponent<Components::Model>(entity1);
if (modelComponent && modelComponent->ModelFile == "Models/Placeholders/rocket/Rocket.obj" && entity2 == 6)
{
m_PhysicsSystem->m_PhysicsWorld->markForWrite();
m_PhysicsSystem->m_RigidBodies[entity1]->setPosition(hkVector4(2000, -2000, 2000));
m_PhysicsSystem->m_PhysicsWorld->unmarkForWrite();
}
m_PhysicsSystem->m_PhysicsWorld->markForRead();
}
private:
Systems::PhysicsSystem* m_PhysicsSystem;
};
friend class MyCollisionResolution;
/*class PhantomCallbackShape: public hkpPhantomCallbackShape
{
public:
PhantomCallbackShape(Systems::PhysicsSystem* physicsSystem)
: m_PhysicsSystem(physicsSystem) { }
virtual void phantomEnterEvent( const hkpCollidable* collidableA, const hkpCollidable* collidableB, const hkpCollisionInput& env )
{
Events::ApplyPointImpulse e;
e.Entity = m_PhysicsSystem->m_RigidBodyEntities[hkpGetRigidBody(collidableB)];
e.Position = HKVECTOR4_TO_GLMVEC3(hkpGetRigidBody(collidableB)->getPosition());
glm::vec3 impulse;
impulse = HKVECTOR4_TO_GLMVEC3(hkpGetRigidBody(collidableA)->getPosition()) - HKVECTOR4_TO_GLMVEC3(hkpGetRigidBody(collidableB)->getPosition());
e.Impulse = impulse;
}
virtual void phantomLeaveEvent( const hkpCollidable* collidableA, const hkpCollidable* collidableB )
{
}
private:
Systems::PhysicsSystem* m_PhysicsSystem;
};
friend class PhantomCallbackShape;
*/
PhysicsSystem(World* world, std::shared_ptr<::EventBroker> eventBroker)
: System(world, eventBroker) { }
+32 -18
View File
@@ -97,26 +97,40 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
bool Systems::TankSteeringSystem::OnCollision( const Events::Collision &e )
{
// TODO:
auto modelComponent = m_World->GetComponent<Components::Model>(e.Entity1);
if (modelComponent && modelComponent->ModelFile == "Models/Placeholders/rocket/Rocket.obj")
if(m_World->ValidEntity(e.Entity1) && m_World->ValidEntity(e.Entity1))
{
auto transform = m_World->GetComponent<Components::Transform>(e.Entity1);
m_World->GetSystem<Systems::ParticleSystem>()->CreateExplosion(
transform->Position,
1,
60,
"Textures/Sprites/NewtonTreeDeleteASAPPlease.png",
glm::angleAxis(glm::pi<float>()/2, glm::vec3(1,0,0)),
40,
glm::pi<float>(),
0.5f
);
//m_World->RemoveEntity(e.Entity1);
}
auto tankShell1 = m_World->GetComponent<Components::TankShell>(e.Entity1);
auto tankShell2 = m_World->GetComponent<Components::TankShell>(e.Entity2);
//LOG_INFO("Ent1 %i Ent2 %i", e.Entity1, e.Entity2);
if(tankShell1)
{
auto transform = m_World->GetComponent<Components::Transform>(e.Entity1);
m_World->GetSystem<Systems::ParticleSystem>()->CreateExplosion(transform->Position, 1, 60, "Textures/Sprites/NewtonTreeDeleteASAPPlease.png", glm::angleAxis(glm::pi<float>()/2, glm::vec3(1,0,0)), 40, glm::pi<float>(), 0.5f);
auto health2 = m_World->GetComponent<Components::Health>(e.Entity2);
if(health2)
{
health2->health -= tankShell1->Damage;
}
m_World->RemoveEntity(e.Entity1);
}
if(tankShell2)
{
auto transform = m_World->GetComponent<Components::Transform>(e.Entity2);
m_World->GetSystem<Systems::ParticleSystem>()->CreateExplosion(transform->Position, 1, 60, "Textures/Sprites/NewtonTreeDeleteASAPPlease.png", glm::angleAxis(glm::pi<float>()/2, glm::vec3(1,0,0)), 40, glm::pi<float>(), 0.5f);
auto health1 = m_World->GetComponent<Components::Health>(e.Entity2);
if(health1)
{
health1->health -= tankShell1->Damage;
}
m_World->RemoveEntity(e.Entity2);
}
}
return true;
}
+4
View File
@@ -18,6 +18,10 @@
#include "Systems/ParticleSystem.h"
#include "InputController.h"
#include "Components/Health.h"
#include "Components/TankShell.h"
#include "Components/SphereShape.h"
namespace Systems
{