Omg dem filter merge skillz
Merge remote-tracking branch 'origin/deffered_rendering' into particles Conflicts: src/GameWorld.cpp src/Systems/ParticleSystem.cpp src/Systems/ParticleSystem.h vs11/Returngeance/Returngeance.vcxproj vs11/Returngeance/Returngeance.vcxproj.filters
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "DamageSystem.h"
|
||||
#include "World.h"
|
||||
|
||||
void Systems::DamageSystem::RegisterComponents( ComponentFactory* cf )
|
||||
{
|
||||
cf->Register<Components::Health>([]() { return new Components::Health(); });
|
||||
}
|
||||
|
||||
void Systems::DamageSystem::Initialize()
|
||||
{
|
||||
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EDamage, &Systems::DamageSystem::OnDamage);
|
||||
}
|
||||
|
||||
bool Systems::DamageSystem::OnDamage( const Events::Damage &event )
|
||||
{
|
||||
auto health = m_World->GetComponent<Components::Health>(event.Entity);
|
||||
health->Amount -= event.Amount;
|
||||
LOG_INFO("Damaged entity %i, Health left: %f", event.Entity, health->Amount);
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef DamageSystem_h__
|
||||
#define DamageSystem_h__
|
||||
|
||||
|
||||
#include "System.h"
|
||||
#include "Components/Health.h"
|
||||
#include "Events/Damage.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
class DamageSystem : public System
|
||||
{
|
||||
public:
|
||||
|
||||
DamageSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
|
||||
: System(world, eventBroker, resourceManager) { }
|
||||
|
||||
|
||||
void Initialize() override;
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
|
||||
|
||||
|
||||
EventRelay<DamageSystem, Events::Damage> m_EDamage;
|
||||
bool OnDamage(const Events::Damage &event);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif // DamageSystem_h__
|
||||
@@ -12,8 +12,9 @@ namespace Systems
|
||||
class DebugSystem : public System
|
||||
{
|
||||
public:
|
||||
DebugSystem(World* world, std::shared_ptr<::EventBroker> eventBroker)
|
||||
: System(world, eventBroker) { }
|
||||
DebugSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
|
||||
: System(world, eventBroker, resourceManager)
|
||||
{ }
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ void Systems::FreeSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
||||
|
||||
glm::quat mouseOrientationPitch = glm::quat(m_InputController->MouseOrientation * glm::vec3(1, 0, 0));
|
||||
glm::quat mouseOrientationYaw = glm::quat(m_InputController->MouseOrientation * glm::vec3(0, 1, 0));
|
||||
m_InputController->MouseOrientation = glm::vec3(0);
|
||||
|
||||
glm::vec3 controllerOrientationEuler = m_InputController->ControllerOrientation * (float)dt;
|
||||
glm::quat controllerOrientationPitch = glm::quat(controllerOrientationEuler * glm::vec3(1, 0, 0));
|
||||
@@ -53,8 +54,6 @@ void Systems::FreeSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
||||
//---------------------------------------------------------------------
|
||||
// TOUCHING THIS CODE MIGHT CAUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
|
||||
}
|
||||
|
||||
m_InputController->MouseOrientation = glm::vec3(0);
|
||||
}
|
||||
|
||||
bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnCommand(const Events::InputCommand &event)
|
||||
@@ -80,7 +79,7 @@ bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnCommand(const E
|
||||
}
|
||||
|
||||
// Mouse click
|
||||
else if (event.Command == "cam_attack")
|
||||
else if (event.Command == "cam_lock")
|
||||
{
|
||||
OrientationActive = event.Value > 0;
|
||||
|
||||
@@ -113,6 +112,7 @@ bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnMouseMove(const
|
||||
if (OrientationActive)
|
||||
{
|
||||
MouseOrientation = -glm::vec3(event.DeltaY / 300.f, event.DeltaX / 300.f, 0.f);
|
||||
LOG_DEBUG("Mouse DX: %f", event.DeltaX);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -12,8 +12,9 @@ namespace Systems
|
||||
class FreeSteeringSystem : public System
|
||||
{
|
||||
public:
|
||||
FreeSteeringSystem(World* world, std::shared_ptr<::EventBroker> eventBroker)
|
||||
: System(world, eventBroker) { }
|
||||
FreeSteeringSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
|
||||
: System(world, eventBroker, resourceManager)
|
||||
{ }
|
||||
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
void Initialize() override;
|
||||
|
||||
@@ -11,8 +11,9 @@ namespace Systems
|
||||
class HelicopterSteeringSystem : public System
|
||||
{
|
||||
public:
|
||||
HelicopterSteeringSystem(World* world, std::shared_ptr<::EventBroker> eventBroker)
|
||||
: System(world, eventBroker) { }
|
||||
HelicopterSteeringSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
|
||||
: System(world, eventBroker, resourceManager)
|
||||
{ }
|
||||
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
void Initialize() override;
|
||||
|
||||
@@ -25,8 +25,9 @@ namespace Systems
|
||||
class InputSystem : public System
|
||||
{
|
||||
public:
|
||||
InputSystem(World* world, std::shared_ptr<::EventBroker> eventBroker)
|
||||
: System(world, eventBroker) { }
|
||||
InputSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
|
||||
: System(world, eventBroker, resourceManager)
|
||||
{ }
|
||||
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
void Initialize() override;
|
||||
|
||||
@@ -26,6 +26,7 @@ void Systems::ParticleSystem::Update(double dt)
|
||||
{
|
||||
m_World->RemoveEntity(explosionID);
|
||||
it = m_ExplosionEmitters.erase(it);
|
||||
//LOG_INFO("Deleted explosion emitter successfully");
|
||||
LOG_INFO("Deleted explosion emitter successfully");
|
||||
}
|
||||
else
|
||||
|
||||
@@ -28,8 +28,9 @@ namespace Systems
|
||||
class ParticleSystem : public System
|
||||
{
|
||||
public:
|
||||
ParticleSystem(World* world, std::shared_ptr<::EventBroker> eventBroker)
|
||||
: System(world, eventBroker) { }
|
||||
ParticleSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
|
||||
: System(world, eventBroker, resourceManager)
|
||||
{ }
|
||||
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
void Update(double dt) override;
|
||||
|
||||
+296
-59
@@ -36,8 +36,10 @@ void Systems::PhysicsSystem::Initialize()
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESetVelocity, &Systems::PhysicsSystem::OnSetVelocity);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EApplyForce, &Systems::PhysicsSystem::OnApplyForce);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EApplyPointImpulse, &Systems::PhysicsSystem::OnApplyPointImpulse);
|
||||
|
||||
hkMemorySystem::FrameInfo finfo(6000 * 1024); // Allocate 6MB of Physics solver buffer
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EEnableCollisions, &Systems::PhysicsSystem::OnEnableCollisions);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EDisableCollisions, &Systems::PhysicsSystem::OnDisableCollisions);
|
||||
|
||||
hkMemorySystem::FrameInfo finfo(10000 * 1024); // Allocate 10MB of Physics solver buffer
|
||||
hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo);
|
||||
hkBaseSystem::init(memoryRouter, HavokErrorReport);
|
||||
|
||||
@@ -75,10 +77,10 @@ void Systems::PhysicsSystem::Initialize()
|
||||
|
||||
worldInfo.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM);
|
||||
worldInfo.m_gravity = hkVector4(0.0f, -9.82f, 0.0f);
|
||||
worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_DO_NOTHING;
|
||||
worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_FIX_ENTITY;
|
||||
|
||||
// You must specify the size of the broad phase - objects should not be simulated outside this region
|
||||
worldInfo.setBroadPhaseWorldSize(1000.0f);
|
||||
worldInfo.setBroadPhaseWorldSize(1500.0f);
|
||||
m_PhysicsWorld = new hkpWorld(worldInfo);
|
||||
|
||||
// When the simulation type is SIMULATION_TYPE_MULTITHREADED, in the debug build, the sdk performs checks
|
||||
@@ -102,14 +104,40 @@ void Systems::PhysicsSystem::Initialize()
|
||||
m_Context = new hkpPhysicsContext;
|
||||
hkpPhysicsContext::registerAllPhysicsProcesses(); // all the physics viewers
|
||||
m_Context->addWorld(m_PhysicsWorld); // add the physics world so the viewers can see it
|
||||
|
||||
SetupVisualDebugger(m_Context);
|
||||
|
||||
m_CollisionFilter = new hkpGroupFilter();
|
||||
m_PhysicsWorld->setCollisionFilter( m_CollisionFilter );
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
|
||||
m_collisionResolution = new MyCollisionResolution;
|
||||
m_collisionResolution = new MyCollisionResolution(this);
|
||||
}
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
GROUND_LAYER = 1,
|
||||
VEHICLE1_LAYER = 2,
|
||||
VEHICLE2_LAYER = 3,
|
||||
EXPLOSION_LAYER = 4,
|
||||
};
|
||||
/*
|
||||
{
|
||||
Events::DisableCollisions e;
|
||||
e.Layer1 = GROUND_LAYER;
|
||||
e.Layer2 = EXPLOSION_LAYER;
|
||||
EventBroker->Publish(e);
|
||||
}*/
|
||||
/*{
|
||||
Events::DisableCollisions e;
|
||||
e.Layer1 = VEHICLE1_LAYER;
|
||||
e.Layer2 = EXPLOSION_LAYER;
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
{
|
||||
Events::DisableCollisions e;
|
||||
e.Layer1 = VEHICLE2_LAYER;
|
||||
e.Layer2 = EXPLOSION_LAYER;
|
||||
EventBroker->Publish(e);
|
||||
}*/
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
|
||||
@@ -122,6 +150,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 +188,6 @@ void Systems::PhysicsSystem::Update(double dt)
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static const double timestep = 1 / 60.0;
|
||||
@@ -230,6 +258,10 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
|
||||
|
||||
void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
{
|
||||
auto tempalteComponent = m_World->GetComponent<Components::Template>(entity);
|
||||
if(tempalteComponent)
|
||||
return;
|
||||
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (!transformComponent)
|
||||
return;
|
||||
@@ -255,21 +287,36 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
}
|
||||
|
||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
|
||||
if (physicsComponent)
|
||||
if (physicsComponent && m_Shapes[entity].size() > 0)
|
||||
{
|
||||
hkpShape* shape;
|
||||
if(entityParent != entity)
|
||||
{
|
||||
LOG_ERROR("Entity: %i , Only the baseparent can have a PhysicsComponent", entity);
|
||||
return;
|
||||
}
|
||||
|
||||
hkpShape* shape;
|
||||
if(! physicsComponent->Static) // Not static
|
||||
{
|
||||
hkArray<hkpShape*> shapeArray;
|
||||
for (auto &shapeData : m_Shapes[entity])
|
||||
{
|
||||
shapeArray.pushBack(shapeData.Shape);
|
||||
auto childTransformComponent = m_World->GetComponent<Components::Transform>(shapeData.Entity);
|
||||
hkpShape* shape;
|
||||
|
||||
if(shapeData.ConvexShape != nullptr)
|
||||
{
|
||||
hkQsTransform transform( GLMVEC3_TO_HKVECTOR4(childTransformComponent->Position), GLMQUAT_TO_HKQUATERNION(childTransformComponent->Orientation), GLMVEC3_TO_HKVECTOR4(childTransformComponent->Scale));
|
||||
hkpConvexTransformShape* transformedBoxShape = new hkpConvexTransformShape( shapeData.ConvexShape, transform );
|
||||
shapeArray.pushBack(transformedBoxShape);
|
||||
|
||||
}
|
||||
|
||||
if(shapeData.Shape != nullptr)
|
||||
{
|
||||
shapeArray.pushBack(shapeData.Shape);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -277,15 +324,28 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
hkpListShape* listShape = new hkpListShape(shapeArray.begin(), shapeArray.getSize(), hkpShapeContainer::REFERENCE_POLICY_INCREMENT);
|
||||
// Save the listShape for further use
|
||||
m_ListShapes[entity] = listShape;
|
||||
//shape = listShape;
|
||||
hkMassProperties massProperties;
|
||||
hkpBoxShape* box = new hkpBoxShape(listShape->m_aabbHalfExtents, 0.0f);
|
||||
shape = new hkpBvShape(listShape, box);
|
||||
|
||||
hkpInertiaTensorComputer::computeShapeVolumeMassProperties(shape, physicsComponent->Mass, massProperties);
|
||||
|
||||
|
||||
for (auto &shapeData : m_Shapes[entity])
|
||||
{
|
||||
if(shapeData.ConvexShape != nullptr)
|
||||
{
|
||||
shapeData.ConvexShape->removeReference();
|
||||
}
|
||||
if(shapeData.Shape != nullptr)
|
||||
{
|
||||
shapeData.Shape->removeReference();
|
||||
}
|
||||
}
|
||||
// Clean up for less memory usage
|
||||
m_Shapes.erase(entity);
|
||||
|
||||
hkMassProperties massProperties;
|
||||
hkpInertiaTensorComputer::computeShapeVolumeMassProperties(shape, physicsComponent->Mass, massProperties);
|
||||
|
||||
|
||||
|
||||
hkpRigidBodyCinfo rigidBodyInfo;
|
||||
{
|
||||
@@ -298,8 +358,22 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
rigidBodyInfo.m_rotation.set(rotation(0), rotation(1), rotation(2), rotation(3));
|
||||
|
||||
rigidBodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor;
|
||||
//rigidBodyInfo.m_centerOfMass = massProperties.m_centerOfMass; //HACK: CENTER OF MASS ALWAYS IN THE CENTER
|
||||
if(physicsComponent->CalculateCenterOfMass)
|
||||
physicsComponent->CenterOfMass = HKVECTOR4_TO_GLMVEC3(massProperties.m_centerOfMass);
|
||||
rigidBodyInfo.m_centerOfMass = GLMVEC3_TO_HKVECTOR4(physicsComponent->CenterOfMass);
|
||||
rigidBodyInfo.m_mass = massProperties.m_mass;
|
||||
rigidBodyInfo.m_linearVelocity = GLMVEC3_TO_HKVECTOR4(physicsComponent->InitialLinearVelocity);
|
||||
rigidBodyInfo.m_angularVelocity = GLMVEC3_TO_HKVECTOR4(physicsComponent->InitialAngularVelocity);
|
||||
rigidBodyInfo.m_linearDamping = physicsComponent->LinearDamping;
|
||||
rigidBodyInfo.m_angularDamping = physicsComponent->AngularDamping;
|
||||
rigidBodyInfo.m_gravityFactor = physicsComponent->GravityFactor;
|
||||
rigidBodyInfo.m_linearDamping = physicsComponent->LinearDamping;
|
||||
rigidBodyInfo.m_friction = physicsComponent->Friction;
|
||||
rigidBodyInfo.m_restitution = physicsComponent->Restitution;
|
||||
rigidBodyInfo.m_maxLinearVelocity = physicsComponent->MaxLinearVelocity;
|
||||
rigidBodyInfo.m_maxAngularVelocity = physicsComponent->MaxAngularVelocity;
|
||||
rigidBodyInfo.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(physicsComponent->CollisionLayer, physicsComponent->CollisionSystemGroup, physicsComponent->CollisionSubSystemId, physicsComponent->CollisionSubSystemDontCollideWith);
|
||||
rigidBodyInfo.m_enableDeactivation = false;
|
||||
}
|
||||
// Create RigidBody
|
||||
hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo);
|
||||
@@ -323,10 +397,13 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
m_PhysicsWorld->markForWrite();
|
||||
vehicleSetup.buildVehicle(m_World, m_PhysicsWorld, *m_Vehicles[entity], entity, m_Wheels);
|
||||
// Add the vehicle's entities and phantoms to the world
|
||||
rigidBody->addContactListener( m_collisionResolution );
|
||||
if(physicsComponent->CollisionEvent)
|
||||
{
|
||||
rigidBody->addContactListener( m_collisionResolution );
|
||||
}
|
||||
m_Vehicles[entity]->addToWorld(m_PhysicsWorld);
|
||||
m_RigidBodies[entity] = rigidBody;
|
||||
m_collisionResolution->m_RigidBodies[rigidBody] = entity;
|
||||
m_RigidBodyEntities[rigidBody] = entity;
|
||||
|
||||
|
||||
// The vehicle is an action
|
||||
@@ -341,10 +418,13 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
else
|
||||
{
|
||||
m_PhysicsWorld->markForWrite();
|
||||
rigidBody->addContactListener( m_collisionResolution );
|
||||
if(physicsComponent->CollisionEvent)
|
||||
{
|
||||
rigidBody->addContactListener( m_collisionResolution );
|
||||
}
|
||||
m_PhysicsWorld->addEntity(rigidBody);
|
||||
m_RigidBodies[entity] = rigidBody;
|
||||
m_collisionResolution->m_RigidBodies[rigidBody] = entity;
|
||||
m_RigidBodyEntities[rigidBody] = entity;
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
|
||||
shape->removeReference();
|
||||
@@ -367,15 +447,38 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
hkVector4 scale = GLMVEC3_TO_HKVECTOR4(childTransformComponent->Scale);
|
||||
hkQsTransform transform(position, rotation, scale);
|
||||
|
||||
staticCompoundShape->addInstance(shapeData.Shape, transform);
|
||||
if(shapeData.ConvexShape != nullptr)
|
||||
{
|
||||
staticCompoundShape->addInstance(shapeData.ConvexShape, transform);
|
||||
}
|
||||
|
||||
if(shapeData.Shape != nullptr)
|
||||
{
|
||||
staticCompoundShape->addInstance(shapeData.Shape, transform);
|
||||
}
|
||||
}
|
||||
|
||||
// This must be called after adding the instances and before using the shape.
|
||||
staticCompoundShape->bake();
|
||||
shape = staticCompoundShape;
|
||||
m_Shapes.erase(entity);
|
||||
hkMassProperties massProperties;
|
||||
hkpInertiaTensorComputer::computeShapeVolumeMassProperties(shape, physicsComponent->Mass, massProperties);
|
||||
|
||||
|
||||
for (auto &shapeData : m_Shapes[entity])
|
||||
{
|
||||
if(shapeData.ConvexShape != nullptr)
|
||||
{
|
||||
shapeData.ConvexShape->removeReference();
|
||||
}
|
||||
if(shapeData.Shape != nullptr)
|
||||
{
|
||||
shapeData.Shape->removeReference();
|
||||
}
|
||||
}
|
||||
m_Shapes.erase(entity);
|
||||
|
||||
|
||||
|
||||
hkpRigidBodyCinfo rigidBodyInfo;
|
||||
{
|
||||
@@ -386,10 +489,24 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
hkQuaternion rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation);
|
||||
rigidBodyInfo.m_position.set(position(0), position(1), position(2), position(3));
|
||||
rigidBodyInfo.m_rotation.set(rotation(0), rotation(1), rotation(2), rotation(3));
|
||||
|
||||
|
||||
rigidBodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor;
|
||||
//rigidBodyInfo.m_centerOfMass = massProperties.m_centerOfMass; //HACK: CENTER OF MASS ALWAYS IN THE CENTER
|
||||
if(physicsComponent->CalculateCenterOfMass)
|
||||
physicsComponent->CenterOfMass = HKVECTOR4_TO_GLMVEC3(massProperties.m_centerOfMass);
|
||||
rigidBodyInfo.m_centerOfMass = GLMVEC3_TO_HKVECTOR4(physicsComponent->CenterOfMass);
|
||||
rigidBodyInfo.m_mass = massProperties.m_mass;
|
||||
rigidBodyInfo.m_linearVelocity = GLMVEC3_TO_HKVECTOR4(physicsComponent->InitialLinearVelocity);
|
||||
rigidBodyInfo.m_angularVelocity = GLMVEC3_TO_HKVECTOR4(physicsComponent->InitialAngularVelocity);
|
||||
rigidBodyInfo.m_linearDamping = physicsComponent->LinearDamping;
|
||||
rigidBodyInfo.m_angularDamping = physicsComponent->AngularDamping;
|
||||
rigidBodyInfo.m_gravityFactor = physicsComponent->GravityFactor;
|
||||
rigidBodyInfo.m_linearDamping = physicsComponent->LinearDamping;
|
||||
rigidBodyInfo.m_friction = physicsComponent->Friction;
|
||||
rigidBodyInfo.m_restitution = physicsComponent->Restitution;
|
||||
rigidBodyInfo.m_maxLinearVelocity = physicsComponent->MaxLinearVelocity;
|
||||
rigidBodyInfo.m_maxAngularVelocity = physicsComponent->MaxAngularVelocity;
|
||||
rigidBodyInfo.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(physicsComponent->CollisionLayer, physicsComponent->CollisionSystemGroup, physicsComponent->CollisionSubSystemId, physicsComponent->CollisionSubSystemDontCollideWith);
|
||||
rigidBodyInfo.m_enableDeactivation = false;
|
||||
}
|
||||
// Create RigidBody
|
||||
hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo);
|
||||
@@ -397,47 +514,107 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_PhysicsWorld->addEntity(rigidBody);
|
||||
m_RigidBodies[entity] = rigidBody;
|
||||
m_collisionResolution->m_RigidBodies[rigidBody] = entity;
|
||||
m_RigidBodyEntities[rigidBody] = entity;
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
|
||||
shape->removeReference();
|
||||
rigidBody->removeReference();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
//TODO: COMMENT THIS SECTION
|
||||
if(sphereComponent)
|
||||
{
|
||||
hkpSphereShape* sphereShape = new hkpSphereShape(sphereComponent->Radius);
|
||||
|
||||
hkQsTransform transform( GLMVEC3_TO_HKVECTOR4(transformComponent->Position), GLMQUAT_TO_HKQUATERNION(transformComponent->Orientation), GLMVEC3_TO_HKVECTOR4(transformComponent->Scale));
|
||||
hkpConvexTransformShape* transformedSphereShape = new hkpConvexTransformShape( sphereShape, transform );
|
||||
|
||||
m_Shapes[entityParent].push_back(ShapeArrayData(entity, transformedSphereShape));
|
||||
//sphereShape->removeReference();
|
||||
|
||||
sphereShape->removeReference();
|
||||
auto triggerComponent = m_World->GetComponent<Components::Trigger >(entityParent);
|
||||
if(triggerComponent)
|
||||
{
|
||||
auto parentTransformComponent = m_World->GetComponent<Components::Transform >(entityParent);
|
||||
|
||||
PhantomCallbackShape* phantom = new PhantomCallbackShape(this);
|
||||
hkpBvShape* phantomShape = new hkpBvShape(sphereShape, phantom);
|
||||
|
||||
hkpRigidBodyCinfo rigidBodyInfo;
|
||||
{
|
||||
rigidBodyInfo.m_shape = phantomShape;
|
||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
|
||||
rigidBodyInfo.m_position = GLMVEC3_TO_HKVECTOR4(parentTransformComponent->Position);
|
||||
|
||||
rigidBodyInfo.m_mass = 1;
|
||||
rigidBodyInfo.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(4, 0, 0, 0);
|
||||
}
|
||||
// Create RigidBody
|
||||
|
||||
hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo);
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_PhysicsWorld->addEntity(rigidBody);
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
|
||||
m_RigidBodies[entityParent] = rigidBody;
|
||||
m_RigidBodyEntities[rigidBody] = entityParent;
|
||||
|
||||
phantomShape->removeReference();
|
||||
phantom->removeReference();
|
||||
sphereShape->removeReference();
|
||||
rigidBody->removeReference();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Shapes[entityParent].push_back(ShapeArrayData(entity, sphereShape, nullptr));
|
||||
}
|
||||
}
|
||||
//TODO: COMMENT THIS SECTION
|
||||
else if(boxComponent)
|
||||
{
|
||||
hkReal thickness = 0.05;
|
||||
hkpBoxShape* boxShape = new hkpBoxShape(hkVector4(boxComponent->Width- thickness, boxComponent->Height -thickness, boxComponent->Depth - thickness), thickness);
|
||||
|
||||
auto triggerComponent = m_World->GetComponent<Components::Trigger >(entityParent);
|
||||
if(triggerComponent)
|
||||
{
|
||||
auto parentTransformComponent = m_World->GetComponent<Components::Transform >(entityParent);
|
||||
|
||||
PhantomCallbackShape* phantom = new PhantomCallbackShape(this);
|
||||
hkpBvShape* phantomShape = new hkpBvShape(boxShape, phantom);
|
||||
|
||||
hkpRigidBodyCinfo rigidBodyInfo;
|
||||
{
|
||||
rigidBodyInfo.m_shape = phantomShape;
|
||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
|
||||
rigidBodyInfo.m_position = GLMVEC3_TO_HKVECTOR4(parentTransformComponent->Position);
|
||||
|
||||
rigidBodyInfo.m_mass = 1;
|
||||
rigidBodyInfo.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(4, 0, 0, 0); // HACK:
|
||||
}
|
||||
// Create RigidBody
|
||||
|
||||
hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo);
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_PhysicsWorld->addEntity(rigidBody);
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
|
||||
m_RigidBodies[entityParent] = rigidBody;
|
||||
m_RigidBodyEntities[rigidBody] = entityParent;
|
||||
|
||||
phantomShape->removeReference();
|
||||
boxShape->removeReference();
|
||||
phantom->removeReference();
|
||||
rigidBody->removeReference();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Shapes[entityParent].push_back(ShapeArrayData(entity, boxShape, nullptr));
|
||||
}
|
||||
|
||||
hkQsTransform transform( GLMVEC3_TO_HKVECTOR4(transformComponent->Position), GLMQUAT_TO_HKQUATERNION(transformComponent->Orientation), GLMVEC3_TO_HKVECTOR4(transformComponent->Scale));
|
||||
hkpConvexTransformShape* transformedBoxShape = new hkpConvexTransformShape( boxShape, transform );
|
||||
m_Shapes[entityParent].push_back(ShapeArrayData(entity, transformedBoxShape));
|
||||
boxShape->removeReference();
|
||||
}
|
||||
else if(meshShapeComponent)
|
||||
{
|
||||
std::vector<hkReal>* vertices = new std::vector<hkReal>;
|
||||
std::vector<hkUint16>* vertexIndices = new std::vector<hkUint16>;
|
||||
auto meshShape = m_World->GetResourceManager()->Load<OBJ>("OBJ", meshShapeComponent->ResourceName);
|
||||
auto meshShape = ResourceManager->Load<OBJ>("OBJ", meshShapeComponent->ResourceName);
|
||||
|
||||
for (auto &vertex : meshShape->Vertices)
|
||||
{
|
||||
@@ -480,12 +657,9 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
|
||||
m_ExtendedMeshShapes[entity].Code = code;
|
||||
m_ExtendedMeshShapes[entity].MoppShape = moppShape;
|
||||
m_Shapes[entityParent].push_back(ShapeArrayData(entity, moppShape)); //HACK: Should maybe have transform, not sure yet
|
||||
m_Shapes[entityParent].push_back(ShapeArrayData(entity, nullptr, moppShape));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::TearDownPhysicsState(EntityID entity, EntityID parent)
|
||||
@@ -498,12 +672,6 @@ void Systems::PhysicsSystem::OnComponentCreated(std::string type, std::shared_pt
|
||||
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::OnComponentRemoved(std::string type, Component* component)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Systems::PhysicsSystem::SetupVisualDebugger(hkpPhysicsContext* worlds)
|
||||
{
|
||||
// Setup the visual debugger
|
||||
@@ -556,24 +724,93 @@ bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event)
|
||||
|
||||
bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event )
|
||||
{
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_RigidBodies[event.Entity]->setLinearVelocity(GLMVEC3_TO_HKVECTOR4(event.Velocity));
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
if(m_RigidBodies.find(event.Entity) != m_RigidBodies.end())
|
||||
{
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_RigidBodies[event.Entity]->setLinearVelocity(GLMVEC3_TO_HKVECTOR4(event.Velocity));
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::PhysicsSystem::OnApplyForce(const Events::ApplyForce &event)
|
||||
{
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_RigidBodies[event.Entity]->applyForce(event.DeltaTime, GLMVEC3_TO_HKVECTOR4(event.Force));
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
if(m_RigidBodies.find(event.Entity) != m_RigidBodies.end())
|
||||
{
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_RigidBodies[event.Entity]->applyForce(event.DeltaTime, GLMVEC3_TO_HKVECTOR4(event.Force));
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::PhysicsSystem::OnApplyPointImpulse( const Events::ApplyPointImpulse &event )
|
||||
{
|
||||
if(m_RigidBodies.find(event.Entity) != m_RigidBodies.end())
|
||||
{
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_RigidBodies[event.Entity]->applyPointImpulse(GLMVEC3_TO_HKVECTOR4(event.Impulse), GLMVEC3_TO_HKVECTOR4(event.Position));
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Systems::PhysicsSystem::OnComponentRemoved(EntityID entity, std::string type, Component* component)
|
||||
{
|
||||
|
||||
if(m_RigidBodies.find(entity) != m_RigidBodies.end())
|
||||
{
|
||||
LOG_INFO("Removed Trigger of entity %i", entity);
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_RigidBodyEntities.erase(m_RigidBodies[entity]);
|
||||
m_PhysicsWorld->removeEntity(m_RigidBodies[entity]);
|
||||
m_RigidBodies.erase(entity);
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Systems::PhysicsSystem::OnEntityRemoved( EntityID entity )
|
||||
{
|
||||
if(m_RigidBodies.find(entity) != m_RigidBodies.end())
|
||||
{
|
||||
LOG_INFO("Removed rigid body of entity %i", entity);
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_RigidBodyEntities.erase(m_RigidBodies[entity]);
|
||||
if(m_ListShapes.find(entity) != m_ListShapes.end())
|
||||
{
|
||||
m_ListShapes[entity]->removeReference();
|
||||
m_ListShapes.erase(entity);
|
||||
}
|
||||
|
||||
m_PhysicsWorld->removeEntity(m_RigidBodies[entity]);
|
||||
m_RigidBodies.erase(entity);
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
}
|
||||
if(m_Vehicles.find(entity) != m_Vehicles.end())
|
||||
{
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_Vehicles[entity]->removeFromWorld();
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
}
|
||||
}
|
||||
|
||||
bool Systems::PhysicsSystem::OnEnableCollisions( const Events::EnableCollisions &e )
|
||||
{
|
||||
m_CollisionFilter->enableCollisionsBetween(e.Layer1, e.Layer2);
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_RigidBodies[event.Entity]->applyPointImpulse(GLMVEC3_TO_HKVECTOR4(event.Impulse), GLMVEC3_TO_HKVECTOR4(event.Position));
|
||||
m_PhysicsWorld->setCollisionFilter(m_CollisionFilter);
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::PhysicsSystem::OnDisableCollisions( const Events::DisableCollisions &e )
|
||||
{
|
||||
m_CollisionFilter->disableCollisionsBetween(e.Layer1, e.Layer2);
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_PhysicsWorld->setCollisionFilter(m_CollisionFilter);
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
return true;
|
||||
}
|
||||
+79
-17
@@ -27,6 +27,7 @@
|
||||
#include "Events/SetVelocity.h"
|
||||
#include "Events/ApplyForce.h"
|
||||
#include "Events/ApplyPointImpulse.h"
|
||||
#include "Events/Collision.h"
|
||||
#include "OBJ.h"
|
||||
|
||||
// Math and base include
|
||||
@@ -75,29 +76,79 @@
|
||||
|
||||
#include <Physics2012/Dynamics/Collide/ContactListener/hkpContactListener.h>
|
||||
|
||||
class MyCollisionResolution: public hkReferencedObject, public hkpContactListener
|
||||
{
|
||||
public:
|
||||
std::unordered_map<hkpRigidBody*, EntityID> m_RigidBodies;
|
||||
#include <Physics2012/Collide/Agent/CompoundAgent/BvTree/hkpBvTreeAgent.h>
|
||||
|
||||
virtual void contactPointCallback( const hkpContactPointEvent& event )
|
||||
{
|
||||
|
||||
EntityID entity1 = m_RigidBodies[event.getBody(0)];
|
||||
EntityID entity2 = m_RigidBodies[event.getBody(1)];
|
||||
//LOG_INFO("Entities colliding: %i, %i ", entity1, entity2);
|
||||
|
||||
}
|
||||
};
|
||||
#include "Components/TankShell.h"
|
||||
#include <Physics2012/Collide/Shape/Misc/PhantomCallback/hkpPhantomCallbackShape.h>
|
||||
#include "Events/EnableCollisions.h"
|
||||
#include "Events/DisableCollisions.h"
|
||||
#include "Components/Trigger.h"
|
||||
#include "Components/Template.h"
|
||||
|
||||
#include "Events/EnterTrigger.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
class PhysicsSystem : public System
|
||||
{
|
||||
public:
|
||||
PhysicsSystem(World* world, std::shared_ptr<::EventBroker> eventBroker)
|
||||
: System(world, eventBroker) { }
|
||||
class MyCollisionResolution: public hkReferencedObject, public hkpContactListener
|
||||
{
|
||||
public:
|
||||
|
||||
MyCollisionResolution(Systems::PhysicsSystem* physicsSystem)
|
||||
: m_PhysicsSystem(physicsSystem) { }
|
||||
|
||||
virtual void contactPointCallback( const hkpContactPointEvent& event )
|
||||
{
|
||||
EntityID entity1 = m_PhysicsSystem->m_RigidBodyEntities[event.getBody(0)];
|
||||
EntityID entity2 = m_PhysicsSystem->m_RigidBodyEntities[event.getBody(1)];
|
||||
|
||||
Events::Collision e;
|
||||
e.Entity1 = entity1;
|
||||
e.Entity2 = entity2;
|
||||
m_PhysicsSystem->EventBroker->Publish(e);
|
||||
LOG_INFO("CollisionEvent!");
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
EntityID entity1 = m_PhysicsSystem->m_RigidBodyEntities[hkpGetRigidBody(collidableA)];
|
||||
EntityID entity2 = m_PhysicsSystem->m_RigidBodyEntities[hkpGetRigidBody(collidableB)];
|
||||
|
||||
if(m_PhysicsSystem->m_World->ValidEntity(entity1) && m_PhysicsSystem->m_World->ValidEntity(entity2))
|
||||
{
|
||||
Events::EnterTrigger e;
|
||||
e.Entity1 = entity1;
|
||||
e.Entity2 = entity2;
|
||||
m_PhysicsSystem->EventBroker->Publish(e);
|
||||
}
|
||||
}
|
||||
|
||||
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, std::shared_ptr<::ResourceManager> resourceManager)
|
||||
: System(world, eventBroker, resourceManager) { }
|
||||
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
void Initialize() override;
|
||||
@@ -105,12 +156,14 @@ public:
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
|
||||
void OnComponentRemoved(std::string type, Component* component) override;
|
||||
void OnComponentRemoved(EntityID entity, std::string type, Component* component) override;
|
||||
void OnEntityCommit(EntityID entity) override;
|
||||
void OnEntityRemoved(EntityID entity) override;
|
||||
|
||||
private:
|
||||
double m_Accumulator;
|
||||
hkpWorld* m_PhysicsWorld;
|
||||
hkpGroupFilter* m_CollisionFilter;
|
||||
|
||||
// Events
|
||||
EventRelay<PhysicsSystem, Events::TankSteer> m_ETankSteer;
|
||||
@@ -122,6 +175,12 @@ private:
|
||||
EventRelay<PhysicsSystem, Events::ApplyPointImpulse> m_EApplyPointImpulse;
|
||||
bool OnApplyPointImpulse(const Events::ApplyPointImpulse &event);
|
||||
|
||||
EventRelay<PhysicsSystem, Events::EnableCollisions> m_EEnableCollisions;
|
||||
bool OnEnableCollisions(const Events::EnableCollisions &e);
|
||||
EventRelay<PhysicsSystem, Events::DisableCollisions> m_EDisableCollisions;
|
||||
bool OnDisableCollisions(const Events::DisableCollisions &e);
|
||||
|
||||
|
||||
void SetUpPhysicsState(EntityID entity, EntityID parent);
|
||||
void TearDownPhysicsState(EntityID entity, EntityID parent);
|
||||
|
||||
@@ -132,6 +191,7 @@ private:
|
||||
void SetupPhysics(hkpWorld* physicsWorld);
|
||||
|
||||
std::unordered_map<EntityID, hkpRigidBody*> m_RigidBodies;
|
||||
std::unordered_map<hkpRigidBody*, EntityID> m_RigidBodyEntities;
|
||||
|
||||
hkJobThreadPool* m_ThreadPool;
|
||||
hkJobQueue* m_JobQueue;
|
||||
@@ -146,12 +206,14 @@ private:
|
||||
|
||||
struct ShapeArrayData
|
||||
{
|
||||
ShapeArrayData(EntityID entity, hkpShape* shape)
|
||||
ShapeArrayData(EntityID entity, hkpConvexShape* convexShape, hkpShape* shape)
|
||||
{
|
||||
Entity = entity;
|
||||
ConvexShape = convexShape;
|
||||
Shape = shape;
|
||||
}
|
||||
EntityID Entity;
|
||||
hkpConvexShape* ConvexShape;
|
||||
hkpShape* Shape;
|
||||
};
|
||||
std::unordered_map<EntityID, std::list<ShapeArrayData>> m_Shapes;
|
||||
|
||||
@@ -2,11 +2,9 @@
|
||||
#include "RenderSystem.h"
|
||||
#include "World.h"
|
||||
|
||||
void Systems::RenderSystem::RegisterResourceTypes(ResourceManager* rm)
|
||||
void Systems::RenderSystem::RegisterResourceTypes(std::shared_ptr<::ResourceManager> rm)
|
||||
{
|
||||
rm->RegisterType("Model", [rm](std::string resourceName) { return new Model(rm, *rm->Load<OBJ>("OBJ", resourceName)); });
|
||||
rm->RegisterType("OBJ", [](std::string resourceName) { return new OBJ(resourceName); });
|
||||
rm->RegisterType("Texture", [](std::string resourceName) { return new Texture(resourceName); });
|
||||
rm->RegisterType("Shader", [](std::string resourceName) { return new ShaderProgram(resourceName); });
|
||||
}
|
||||
|
||||
void Systems::RenderSystem::RegisterComponents(ComponentFactory* cf)
|
||||
@@ -21,100 +19,99 @@ void Systems::RenderSystem::RegisterComponents(ComponentFactory* cf)
|
||||
|
||||
void Systems::RenderSystem::OnEntityCommit(EntityID entity)
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
//auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
|
||||
auto camera = m_World->GetComponent<Components::Camera>(entity);
|
||||
if (transform && camera)
|
||||
{
|
||||
m_Renderer->RegisterCamera(entity, camera->FOV, camera->NearClip, camera->FarClip);
|
||||
m_Renderer->UpdateCamera(entity, m_TransformSystem->AbsolutePosition(entity), m_TransformSystem->AbsoluteOrientation(entity), camera->FOV, camera->NearClip, camera->FarClip);
|
||||
}
|
||||
//auto camera = m_World->GetComponent<Components::Camera>(entity);
|
||||
//if (transform && camera)
|
||||
//{
|
||||
// m_Renderer->RegisterCamera(entity, camera->FOV, camera->NearClip, camera->FarClip);
|
||||
// m_Renderer->UpdateCamera(entity, m_TransformSystem->AbsolutePosition(entity), m_TransformSystem->AbsoluteOrientation(entity), camera->FOV, camera->NearClip, camera->FarClip);
|
||||
//}
|
||||
|
||||
auto viewport = m_World->GetComponent<Components::Viewport>(entity);
|
||||
if (viewport)
|
||||
{
|
||||
m_Renderer->RegisterViewport(entity, viewport->Left, viewport->Top, viewport->Right, viewport->Bottom);
|
||||
if (viewport->Camera != 0)
|
||||
{
|
||||
m_Renderer->UpdateViewport(entity, viewport->Camera);
|
||||
}
|
||||
}
|
||||
//auto viewport = m_World->GetComponent<Components::Viewport>(entity);
|
||||
//if (viewport)
|
||||
//{
|
||||
// m_Renderer->RegisterViewport(entity, viewport->Left, viewport->Top, viewport->Right, viewport->Bottom);
|
||||
// if (viewport->Camera != 0)
|
||||
// {
|
||||
// m_Renderer->UpdateViewport(entity, viewport->Camera);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto templateComponent = m_World->GetComponent<Components::Template>(entity);
|
||||
if (templateComponent)
|
||||
return;
|
||||
//auto templateComponent = m_World->GetComponent<Components::Template>(entity);
|
||||
//if (templateComponent)
|
||||
// return;
|
||||
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
//auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
|
||||
// Draw models
|
||||
auto modelComponent = m_World->GetComponent<Components::Model>(entity);
|
||||
if (transformComponent && modelComponent)
|
||||
{
|
||||
auto model = m_World->GetResourceManager()->Load<Model>("Model", modelComponent->ModelFile);
|
||||
if (model)
|
||||
{
|
||||
/*glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
|
||||
glm::quat orientation = m_TransformSystem->AbsoluteOrientation(entity);
|
||||
glm::vec3 scale = m_TransformSystem->AbsoluteScale(entity);*/
|
||||
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
|
||||
m_Renderer->AddModelToDraw(model, absoluteTransform.Position, absoluteTransform.Orientation, absoluteTransform.Scale, modelComponent->Visible, modelComponent->ShadowCaster);
|
||||
}
|
||||
}
|
||||
//// Draw models
|
||||
//auto modelComponent = m_World->GetComponent<Components::Model>(entity);
|
||||
//if (transformComponent && modelComponent)
|
||||
//{
|
||||
// auto model = m_World->ResourceManager->Load<Model>("Model", modelComponent->ModelFile);
|
||||
// if (model)
|
||||
// {
|
||||
// /*glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
|
||||
// glm::quat orientation = m_TransformSystem->AbsoluteOrientation(entity);
|
||||
// glm::vec3 scale = m_TransformSystem->AbsoluteScale(entity);*/
|
||||
// Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
|
||||
// m_Renderer->AddModelToDraw(model, absoluteTransform.Position, absoluteTransform.Orientation, absoluteTransform.Scale, modelComponent->Visible, modelComponent->ShadowCaster);
|
||||
// }
|
||||
//}
|
||||
|
||||
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity);
|
||||
if (transformComponent && pointLightComponent)
|
||||
{
|
||||
glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
|
||||
m_Renderer->AddPointLightToDraw(
|
||||
position,
|
||||
pointLightComponent->Specular,
|
||||
pointLightComponent->Diffuse,
|
||||
pointLightComponent->specularExponent,
|
||||
pointLightComponent->ConstantAttenuation,
|
||||
pointLightComponent->LinearAttenuation,
|
||||
pointLightComponent->QuadraticAttenuation
|
||||
);
|
||||
}
|
||||
//auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity);
|
||||
//if (transformComponent && pointLightComponent)
|
||||
//{
|
||||
// glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
|
||||
// m_Renderer->AddPointLightToDraw(
|
||||
// position,
|
||||
// pointLightComponent->Specular,
|
||||
// pointLightComponent->Diffuse,
|
||||
// pointLightComponent->specularExponent,
|
||||
// pointLightComponent->ConstantAttenuation,
|
||||
// pointLightComponent->LinearAttenuation,
|
||||
// pointLightComponent->QuadraticAttenuation
|
||||
// );
|
||||
//}
|
||||
|
||||
auto cameraComponent = m_World->GetComponent<Components::Camera>(entity);
|
||||
if (transformComponent && cameraComponent)
|
||||
{
|
||||
m_Renderer->UpdateCamera(entity
|
||||
, m_TransformSystem->AbsolutePosition(entity)
|
||||
, m_TransformSystem->AbsoluteOrientation(entity)
|
||||
, cameraComponent->FOV
|
||||
, cameraComponent->NearClip
|
||||
, cameraComponent->FarClip);
|
||||
}
|
||||
//auto cameraComponent = m_World->GetComponent<Components::Camera>(entity);
|
||||
//if (transformComponent && cameraComponent)
|
||||
//{
|
||||
// m_Renderer->UpdateCamera(entity
|
||||
// , m_TransformSystem->AbsolutePosition(entity)
|
||||
// , m_TransformSystem->AbsoluteOrientation(entity)
|
||||
// , cameraComponent->FOV
|
||||
// , cameraComponent->NearClip
|
||||
// , cameraComponent->FarClip);
|
||||
//}
|
||||
|
||||
auto viewportComponent = m_World->GetComponent<Components::Viewport>(entity);
|
||||
if (viewportComponent)
|
||||
{
|
||||
if (viewportComponent->Camera != 0)
|
||||
{
|
||||
m_Renderer->UpdateViewport(entity, viewportComponent->Camera);
|
||||
}
|
||||
}
|
||||
//auto viewportComponent = m_World->GetComponent<Components::Viewport>(entity);
|
||||
//if (viewportComponent)
|
||||
//{
|
||||
// if (viewportComponent->Camera != 0)
|
||||
// {
|
||||
// m_Renderer->UpdateViewport(entity, viewportComponent->Camera);
|
||||
// }
|
||||
//}
|
||||
|
||||
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
|
||||
if (transformComponent && spriteComponent)
|
||||
{
|
||||
//TEMP
|
||||
Texture* texture = m_World->GetResourceManager()->Load<Texture>("Texture", spriteComponent->SpriteFile);
|
||||
//glBindTexture(GL_TEXTURE_2D, texture);
|
||||
auto transform = m_World->GetComponent<Components::Transform>(spriteComponent->Entity);
|
||||
glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(transform->Orientation).z, glm::vec3(0, 0, -1));
|
||||
m_Renderer->AddTextureToDraw(texture, transform->Position, orientation2D, transform->Scale);
|
||||
}
|
||||
//auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
|
||||
//if (transformComponent && spriteComponent)
|
||||
//{
|
||||
// //TEMP
|
||||
// Texture* texture = m_World->ResourceManager->Load<Texture>("Texture", spriteComponent->SpriteFile);
|
||||
// //glBindTexture(GL_TEXTURE_2D, texture);
|
||||
// auto transform = m_World->GetComponent<Components::Transform>(spriteComponent->Entity);
|
||||
// glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(transform->Orientation).z, glm::vec3(0, 0, -1));
|
||||
// m_Renderer->AddTextureToDraw(texture, transform->Position, orientation2D, transform->Scale);
|
||||
//}
|
||||
}
|
||||
|
||||
void Systems::RenderSystem::Initialize()
|
||||
{
|
||||
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
|
||||
|
||||
m_Renderer->SetSphereModel(m_World->GetResourceManager()->Load<Model>("Model", "Models/Placeholders/PhysicsTest/Sphere.obj"));
|
||||
}
|
||||
//m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
|
||||
|
||||
//m_Renderer->SetSphereModel(m_World->ResourceManager->Load<Model>("Model", "Models/Placeholders/PhysicsTest/Sphere.obj"));
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "System.h"
|
||||
#include "Systems/TransformSystem.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "Model.h"
|
||||
#include "Texture.h"
|
||||
#include "Components/Transform.h"
|
||||
@@ -14,10 +15,11 @@
|
||||
#include "Components/PointLight.h"
|
||||
#include "Components/DirectionalLight.h"
|
||||
#include "Components/Viewport.h"
|
||||
|
||||
#include "Components/Template.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Renderer.h"
|
||||
#include "RenderQueue.h"
|
||||
#include "Events/SetViewportCamera.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
@@ -25,12 +27,12 @@ namespace Systems
|
||||
class RenderSystem : public System
|
||||
{
|
||||
public:
|
||||
RenderSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<Renderer> renderer)
|
||||
: System(world, eventBroker)
|
||||
, m_Renderer(renderer) { }
|
||||
RenderSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
|
||||
: System(world, eventBroker, resourceManager)
|
||||
{ }
|
||||
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
void RegisterResourceTypes(ResourceManager* rm) override;
|
||||
void RegisterResourceTypes(std::shared_ptr<::ResourceManager> rm) override;
|
||||
void Initialize() override;
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<Model>> m_CachedModels;
|
||||
@@ -38,12 +40,12 @@ public:
|
||||
void OnEntityCommit(EntityID entity) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
std::shared_ptr<Renderer> m_Renderer;
|
||||
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
|
||||
|
||||
void EnqueueModel(Model* model, glm::mat4 modelMatrix);
|
||||
void EnqueueSprite(Texture* texture, glm::mat4 modelMatrix);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ void Systems::SoundSystem::RegisterComponents(ComponentFactory* cf)
|
||||
cf->Register<Components::SoundEmitter>([]() { return new Components::SoundEmitter(); });
|
||||
}
|
||||
|
||||
void Systems::SoundSystem::RegisterResourceTypes(ResourceManager* rm)
|
||||
void Systems::SoundSystem::RegisterResourceTypes(std::shared_ptr<::ResourceManager> rm)
|
||||
{
|
||||
rm->RegisterType("Sound", [](std::string resourceName) { return new Sound(resourceName); });
|
||||
}
|
||||
@@ -94,7 +94,7 @@ void Systems::SoundSystem::PlaySound(Components::SoundEmitter* emitter, std::str
|
||||
if (m_Sources.find(emitter) == m_Sources.end())
|
||||
return;
|
||||
|
||||
ALuint buffer = *m_World->GetResourceManager()->Load<Sound>("Sound", fileName);
|
||||
ALuint buffer = *ResourceManager->Load<Sound>("Sound", fileName);
|
||||
if (buffer == 0)
|
||||
return;
|
||||
ALuint source = m_Sources[emitter];
|
||||
@@ -104,7 +104,7 @@ void Systems::SoundSystem::PlaySound(Components::SoundEmitter* emitter, std::str
|
||||
|
||||
void Systems::SoundSystem::PlaySound(std::shared_ptr<Components::SoundEmitter> emitter)
|
||||
{
|
||||
ALuint buffer = *m_World->GetResourceManager()->Load<Sound>("Sound", emitter->Path);
|
||||
ALuint buffer = *ResourceManager->Load<Sound>("Sound", emitter->Path);
|
||||
ALuint source = m_Sources[emitter.get()];
|
||||
alSourcei(source, AL_BUFFER, buffer);
|
||||
alSourcePlay(m_Sources[emitter.get()]);
|
||||
@@ -124,7 +124,7 @@ void Systems::SoundSystem::OnComponentCreated(std::string type, std::shared_ptr<
|
||||
}
|
||||
}
|
||||
|
||||
void Systems::SoundSystem::OnComponentRemoved(std::string type, Component* component)
|
||||
void Systems::SoundSystem::OnComponentRemoved(EntityID entity, std::string type, Component* component)
|
||||
{
|
||||
if(type == "SoundEmitter")
|
||||
{
|
||||
@@ -151,7 +151,7 @@ bool Systems::SoundSystem::OnPlaySound(const Events::PlaySound &event)
|
||||
{
|
||||
LOG_DEBUG("Events::PlaySound.Resource = %s", event.Resource.c_str());
|
||||
|
||||
ALuint buffer = *m_World->GetResourceManager()->Load<Sound>("Sound", event.Resource);
|
||||
ALuint buffer = *ResourceManager->Load<Sound>("Sound", event.Resource);
|
||||
ALuint source = m_Sources.begin()->second;
|
||||
alSourcei(source, AL_BUFFER, buffer);
|
||||
alSourcePlay(source);
|
||||
|
||||
@@ -16,17 +16,18 @@ namespace Systems
|
||||
class SoundSystem : public System
|
||||
{
|
||||
public:
|
||||
SoundSystem(World* world, std::shared_ptr<::EventBroker> eventBroker)
|
||||
: System(world, eventBroker) { }
|
||||
SoundSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
|
||||
: System(world, eventBroker, resourceManager)
|
||||
{ }
|
||||
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
void RegisterResourceTypes(ResourceManager* rm) override;
|
||||
void RegisterResourceTypes(std::shared_ptr<::ResourceManager> rm) override;
|
||||
void Initialize() override;
|
||||
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
|
||||
void OnComponentRemoved(std::string type, Component* component) override;
|
||||
void OnComponentRemoved(EntityID entity, std::string type, Component* component) override;
|
||||
void PlaySound(Components::SoundEmitter* emitter, std::string path); // Use if you want to play a temporary .wav file not from component
|
||||
void PlaySound(std::shared_ptr<Components::SoundEmitter> emitter); // Use if you want to play .wav file from component // imon no hate plx T.T
|
||||
void StopSound(std::shared_ptr<Components::SoundEmitter> emitter);
|
||||
|
||||
@@ -11,6 +11,8 @@ void Systems::TankSteeringSystem::RegisterComponents( ComponentFactory* cf )
|
||||
|
||||
void Systems::TankSteeringSystem::Initialize()
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ECollision, &Systems::TankSteeringSystem::OnCollision);
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
m_TankInputControllers[i] = std::shared_ptr<TankSteeringInputController>(new TankSteeringInputController(EventBroker, i + 1));
|
||||
@@ -93,6 +95,147 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
||||
}
|
||||
}
|
||||
|
||||
bool Systems::TankSteeringSystem::OnCollision( const Events::Collision &e )
|
||||
{
|
||||
if(m_World->ValidEntity(e.Entity1) && m_World->ValidEntity(e.Entity2))
|
||||
{
|
||||
auto tankShell1 = m_World->GetComponent<Components::TankShell>(e.Entity1);
|
||||
auto tankShell2 = m_World->GetComponent<Components::TankShell>(e.Entity2);
|
||||
|
||||
EntityID shellEntity = 0;
|
||||
Components::TankShell* shellComponent;
|
||||
EntityID otherEntity = 0;
|
||||
|
||||
if (tankShell1)
|
||||
{
|
||||
shellEntity = e.Entity1;
|
||||
otherEntity = e.Entity2;
|
||||
shellComponent = tankShell1;
|
||||
}
|
||||
else if (tankShell2)
|
||||
{
|
||||
shellEntity = e.Entity2;
|
||||
otherEntity = e.Entity1;
|
||||
shellComponent = tankShell2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto physicsComponents = m_World->GetComponentsOfType<Components::Physics>();
|
||||
auto shellTransform = m_World->GetComponent<Components::Transform>(shellEntity);
|
||||
//auto otherTransform = m_World->GetComponent<Components::Transform>(otherEntity);
|
||||
for (auto &physComponent : *physicsComponents)
|
||||
{
|
||||
EntityID physicsEntity = std::dynamic_pointer_cast<Components::Physics>(physComponent)->Entity;
|
||||
auto physEntityTransform = m_World->GetComponent<Components::Transform>(physicsEntity);
|
||||
|
||||
float distance = glm::distance(physEntityTransform->Position, shellTransform->Position);
|
||||
if (distance <= shellComponent->ExplosionRadius)
|
||||
{
|
||||
// DO STUFF! :D
|
||||
float radius = shellComponent->ExplosionRadius;
|
||||
float strength = (1.f - pow(distance / radius, 2)) * shellComponent->ExplosionStrength;
|
||||
glm::vec3 direction = glm::normalize(physEntityTransform->Position - shellTransform->Position);
|
||||
|
||||
Events::ApplyPointImpulse e;
|
||||
e.Entity = physicsEntity;
|
||||
e.Impulse = direction * strength;
|
||||
e.Position = physEntityTransform->Position;
|
||||
EventBroker->Publish(e);
|
||||
|
||||
auto health = m_World->GetComponent<Components::Health>(physicsEntity);
|
||||
if(health)
|
||||
{
|
||||
Events::Damage d;
|
||||
d.Entity = physicsEntity;
|
||||
d.Amount = (1.f - pow(distance / radius, 2)) * shellComponent->Damage;
|
||||
EventBroker->Publish(d);
|
||||
}
|
||||
|
||||
|
||||
|
||||
m_World->RemoveEntity(shellEntity);
|
||||
}
|
||||
}
|
||||
|
||||
//if(tankShell1)
|
||||
//{
|
||||
// LOG_DEBUG("%i collided with %i", e.Entity1, e.Entity2);
|
||||
// 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);
|
||||
|
||||
// glm::vec3 pointOfImpact = transform->Position;
|
||||
|
||||
|
||||
// {
|
||||
// auto ent = m_World->CreateEntity();
|
||||
// LOG_DEBUG("Created trigger entity %i", ent);
|
||||
// auto transform = m_World->AddComponent<Components::Transform>(ent);
|
||||
// transform->Position = pointOfImpact;
|
||||
|
||||
// auto trigger = m_World->AddComponent<Components::Trigger>(ent);
|
||||
// trigger->TriggerOnce = true;
|
||||
// auto frameTimer = m_World->AddComponent<Components::FrameTimer>(ent);
|
||||
// frameTimer->Frames = 100;
|
||||
// auto explosion = m_World->AddComponent<Components::TriggerExplosion>(ent);
|
||||
// explosion->MaxVelocity = 50.f;
|
||||
// explosion->Radius = 30.f;
|
||||
// {
|
||||
// auto shape = m_World->CreateEntity(ent);
|
||||
// auto transformshape = m_World->AddComponent<Components::Transform>(shape);
|
||||
// auto sphere = m_World->AddComponent<Components::SphereShape>(shape);
|
||||
// sphere->Radius = 30.f;
|
||||
// m_World->CommitEntity(shape);
|
||||
|
||||
// }
|
||||
// m_World->CommitEntity(ent);
|
||||
// }
|
||||
//
|
||||
// m_World->RemoveEntity(e.Entity1);
|
||||
//}
|
||||
|
||||
//if(tankShell2)
|
||||
//{
|
||||
// LOG_DEBUG("%i collided with %i", e.Entity1, e.Entity2);
|
||||
// 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);
|
||||
|
||||
// glm::vec3 pointOfImpact = transform->Position;
|
||||
|
||||
|
||||
// {
|
||||
// auto ent = m_World->CreateEntity();
|
||||
// LOG_DEBUG("Created trigger entity %i", ent);
|
||||
// auto transform = m_World->AddComponent<Components::Transform>(ent);
|
||||
// transform->Position = pointOfImpact;
|
||||
|
||||
// auto trigger = m_World->AddComponent<Components::Trigger>(ent);
|
||||
// trigger->TriggerOnce = true;
|
||||
// auto frameTimer = m_World->AddComponent<Components::FrameTimer>(ent);
|
||||
// frameTimer->Frames = 100;
|
||||
// auto explosion = m_World->AddComponent<Components::TriggerExplosion>(ent);
|
||||
// explosion->MaxVelocity = 50.f;
|
||||
// explosion->Radius = 30.f;
|
||||
// {
|
||||
// auto shape = m_World->CreateEntity(ent);
|
||||
// auto transformshape = m_World->AddComponent<Components::Transform>(shape);
|
||||
// auto sphere = m_World->AddComponent<Components::SphereShape>(shape);
|
||||
// sphere->Radius = 30.f;
|
||||
// m_World->CommitEntity(shape);
|
||||
|
||||
// }
|
||||
// m_World->CommitEntity(ent);
|
||||
// }
|
||||
|
||||
// m_World->RemoveEntity(e.Entity2);
|
||||
//}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Systems::TankSteeringSystem::TankSteeringInputController::Update( double dt )
|
||||
{
|
||||
PositionX = m_Horizontal;
|
||||
@@ -141,6 +284,20 @@ bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const E
|
||||
m_Shoot = val > 0;
|
||||
}
|
||||
|
||||
else if(event.Command == "EnableCollisions")
|
||||
{
|
||||
Events::EnableCollisions e;
|
||||
e.Layer1 = 1;
|
||||
e.Layer2 = 2;
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
else if(event.Command == "DisableCollisions")
|
||||
{
|
||||
Events::DisableCollisions e;
|
||||
e.Layer1 = 1;
|
||||
e.Layer2 = 2;
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "Events/SetVelocity.h"
|
||||
#include "Events/ApplyForce.h"
|
||||
#include "Events/ApplyPointImpulse.h"
|
||||
#include "Events/Collision.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/TankSteering.h"
|
||||
#include "Components/TowerSteering.h"
|
||||
@@ -12,17 +13,32 @@
|
||||
#include "Components/Physics.h"
|
||||
#include "Components/Vehicle.h"
|
||||
#include "Components/Player.h"
|
||||
#include "Components/Model.h"
|
||||
#include "Systems/TransformSystem.h"
|
||||
#include "Systems/ParticleSystem.h"
|
||||
#include "InputController.h"
|
||||
|
||||
#include "Components/Health.h"
|
||||
#include "Components/TankShell.h"
|
||||
#include "Components/SphereShape.h"
|
||||
|
||||
#include "Events/EnableCollisions.h"
|
||||
#include "Events/DisableCollisions.h"
|
||||
#include "Components/Trigger.h"
|
||||
#include "Components/TriggerExplosion.h"
|
||||
#include "Components/FrameTimer.h"
|
||||
|
||||
#include "Events/Damage.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
class TankSteeringSystem : public System
|
||||
{
|
||||
public:
|
||||
TankSteeringSystem(World* world, std::shared_ptr<::EventBroker> eventBroker)
|
||||
: System(world, eventBroker) { }
|
||||
TankSteeringSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
|
||||
: System(world, eventBroker, resourceManager)
|
||||
{ }
|
||||
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
void Initialize() override;
|
||||
@@ -31,6 +47,9 @@ namespace Systems
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
|
||||
private:
|
||||
EventRelay<TankSteeringSystem, Events::Collision> m_ECollision;
|
||||
bool OnCollision(const Events::Collision &e);
|
||||
|
||||
class TankSteeringInputController;
|
||||
std::array<std::shared_ptr<TankSteeringInputController>, 4> m_TankInputControllers;
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "TimerSystem.h"
|
||||
#include "World.h"
|
||||
|
||||
void Systems::TimerSystem::RegisterComponents( ComponentFactory* cf )
|
||||
{
|
||||
cf->Register<Components::Timer>([]() { return new Components::Timer(); });
|
||||
cf->Register<Components::FrameTimer>([]() { return new Components::FrameTimer(); });
|
||||
}
|
||||
|
||||
void Systems::TimerSystem::UpdateEntity( double dt, EntityID entity, EntityID parent )
|
||||
{
|
||||
auto timer = m_World->GetComponent<Components::Timer>(entity);
|
||||
if(timer)
|
||||
{
|
||||
timer->Time -= dt;
|
||||
|
||||
if(timer->Time <= 0)
|
||||
{
|
||||
m_World->RemoveEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
auto frameTimer = m_World->GetComponent<Components::FrameTimer>(entity);
|
||||
if(frameTimer)
|
||||
{
|
||||
frameTimer->Frames -= 1;
|
||||
|
||||
if(frameTimer->Frames <= 0)
|
||||
{
|
||||
m_World->RemoveEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef TimerSystem_h__
|
||||
#define TimerSystem_h__
|
||||
|
||||
|
||||
#include "System.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/Timer.h"
|
||||
#include "Components/FrameTimer.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
class TimerSystem : public System
|
||||
{
|
||||
public:
|
||||
|
||||
TimerSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
|
||||
: System(world, eventBroker, resourceManager) { }
|
||||
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
|
||||
private:
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif // TimerSystem_h__
|
||||
@@ -10,8 +10,9 @@ namespace Systems
|
||||
class TransformSystem : public System
|
||||
{
|
||||
public:
|
||||
TransformSystem(World* world, std::shared_ptr<::EventBroker> eventBroker)
|
||||
: System(world, eventBroker) { }
|
||||
TransformSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
|
||||
: System(world, eventBroker, resourceManager)
|
||||
{ }
|
||||
//void Update(double dt) override;
|
||||
//void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "TriggerSystem.h"
|
||||
#include "World.h"
|
||||
|
||||
void Systems::TriggerSystem::RegisterComponents( ComponentFactory* cf )
|
||||
{
|
||||
cf->Register<Components::Trigger>([]() { return new Components::Trigger(); });
|
||||
cf->Register<Components::TriggerExplosion>([]() { return new Components::TriggerExplosion(); });
|
||||
}
|
||||
|
||||
void Systems::TriggerSystem::Initialize()
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EEnterTrigger, &Systems::TriggerSystem::OnEnterTrigger);
|
||||
}
|
||||
|
||||
void Systems::TriggerSystem::Update( double dt )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Systems::TriggerSystem::UpdateEntity( double dt, EntityID entity, EntityID parent )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Systems::TriggerSystem::OnComponentCreated( std::string type, std::shared_ptr<Component> component )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Systems::TriggerSystem::OnComponentRemoved(EntityID entity, std::string type, Component* component )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Systems::TriggerSystem::OnEntityCommit( EntityID entity )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Systems::TriggerSystem::OnEntityRemoved( EntityID entity )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool Systems::TriggerSystem::OnEnterTrigger( const Events::EnterTrigger &event )
|
||||
{
|
||||
/*auto explosionComponent1 = m_World->GetComponent<Components::TriggerExplosion>(event.Entity1);
|
||||
auto explosionComponent2 = m_World->GetComponent<Components::TriggerExplosion>(event.Entity2);
|
||||
|
||||
if(explosionComponent1)
|
||||
{
|
||||
Explosion(event.Entity2, event.Entity1);
|
||||
}
|
||||
else if (explosionComponent2)
|
||||
{
|
||||
Explosion(event.Entity1, event.Entity2);
|
||||
}*/
|
||||
|
||||
auto flagComponent1 = m_World->GetComponent<Components::Flag>(event.Entity1);
|
||||
auto flagComponent2 = m_World->GetComponent<Components::Flag>(event.Entity2);
|
||||
|
||||
if(flagComponent1)
|
||||
{
|
||||
Flag(event.Entity2, event.Entity1);
|
||||
}
|
||||
else if (flagComponent2)
|
||||
{
|
||||
Flag(event.Entity1, event.Entity2);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Systems::TriggerSystem::Flag( EntityID entity, EntityID phantomEntity )
|
||||
{
|
||||
auto tankSteering = m_World->GetComponent<Components::TankSteering>(entity);
|
||||
if (!tankSteering)
|
||||
return;
|
||||
|
||||
m_World->RemoveComponent<Components::Trigger>(phantomEntity);
|
||||
m_World->SetEntityParent(phantomEntity, entity);
|
||||
auto phantomTransform = m_World->GetComponent<Components::Transform>(phantomEntity);
|
||||
phantomTransform->Position = glm::vec3(1.f, 0.1f, 2.f);
|
||||
}
|
||||
|
||||
|
||||
void Systems::TriggerSystem::Explosion( EntityID entity, EntityID phantomEntity )
|
||||
{
|
||||
/*auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
auto PhantomTransformComponent = m_World->GetComponent<Components::Transform>(phantomEntity);
|
||||
auto explosionComponent = m_World->GetComponent<Components::TriggerExplosion>(phantomEntity);
|
||||
|
||||
if(transformComponent && PhantomTransformComponent)
|
||||
{
|
||||
// Velocity = (1 - (distance / radius)^2) * Strength;
|
||||
glm::vec3 vect = transformComponent->Position - PhantomTransformComponent->Position;
|
||||
float distance = glm::length(vect);
|
||||
float radius = explosionComponent->Radius;
|
||||
float velocity = (1.f - pow(distance / radius, 2)) * explosionComponent->MaxVelocity;
|
||||
|
||||
glm::vec3 direction = glm::normalize(transformComponent->Position - PhantomTransformComponent->Position);
|
||||
|
||||
Events::SetVelocity e;
|
||||
e.Entity = entity;
|
||||
e.Velocity = direction*velocity;
|
||||
EventBroker->Publish(e);
|
||||
|
||||
m_World->RemoveEntity(phantomEntity);
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#ifndef TriggerSystem_h__
|
||||
#define TriggerSystem_h__
|
||||
|
||||
|
||||
#include "System.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/TankSteering.h"
|
||||
#include "Events/SetVelocity.h"
|
||||
#include "Events/ApplyForce.h"
|
||||
#include "Events/ApplyPointImpulse.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "Components/Trigger.h"
|
||||
#include "Components/TriggerExplosion.h"
|
||||
#include "Events/EnterTrigger.h"
|
||||
#include "Components/Flag.h"
|
||||
#include <math.h>
|
||||
namespace Systems
|
||||
{
|
||||
class TriggerSystem : public System
|
||||
{
|
||||
public:
|
||||
|
||||
TriggerSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
|
||||
: System(world, eventBroker, resourceManager) { }
|
||||
|
||||
void Initialize() override;
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
|
||||
void OnComponentRemoved(EntityID entity, std::string type, Component* component) override;
|
||||
void OnEntityCommit(EntityID entity) override;
|
||||
void OnEntityRemoved(EntityID entity) override;
|
||||
|
||||
EventRelay<TriggerSystem, Events::EnterTrigger> m_EEnterTrigger;
|
||||
bool OnEnterTrigger(const Events::EnterTrigger &event);
|
||||
private:
|
||||
void Flag(EntityID entity, EntityID phantomEntity);
|
||||
void Explosion(EntityID entity, EntityID phantomEntity);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif // TriggerSystem_h__
|
||||
Reference in New Issue
Block a user