Merge branch 'deffered_rendering'
Conflicts: assets src/Components/Physics.h src/GameWorld.cpp src/GameWorld.h src/Systems/PhysicsSystem.cpp vs11/Returngeance/Returngeance.vcxproj vs11/Returngeance/Returngeance.vcxproj.filters
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "DamageSystem.h"
|
||||
#include "World.h"
|
||||
|
||||
void Systems::DamageSystem::RegisterComponents( ComponentFactory* cf )
|
||||
{
|
||||
cf->Register<Components::Health>([]() { return new Components::Health(); });
|
||||
@@ -15,8 +14,16 @@ void Systems::DamageSystem::Initialize()
|
||||
|
||||
bool Systems::DamageSystem::OnDamage( const Events::Damage &event )
|
||||
{
|
||||
if(!m_World->ValidEntity(event.Entity))
|
||||
return false;
|
||||
auto health = m_World->GetComponent<Components::Health>(event.Entity);
|
||||
health->Amount -= event.Amount;
|
||||
if(health->Amount <= 0)
|
||||
{
|
||||
Events::OnDead e;
|
||||
e.Entity = event.Entity;
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
LOG_INFO("Damaged entity %i, Health left: %f", event.Entity, health->Amount);
|
||||
return true;
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "System.h"
|
||||
#include "Components/Health.h"
|
||||
#include "Events/Damage.h"
|
||||
#include "Events/OnDead.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
@@ -80,7 +80,7 @@ void Systems::PhysicsSystem::Initialize()
|
||||
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(1500.0f);
|
||||
worldInfo.setBroadPhaseWorldSize(500.0f);
|
||||
m_PhysicsWorld = new hkpWorld(worldInfo);
|
||||
|
||||
// When the simulation type is SIMULATION_TYPE_MULTITHREADED, in the debug build, the sdk performs checks
|
||||
@@ -151,6 +151,10 @@ void Systems::PhysicsSystem::Update(double dt)
|
||||
EntityID entity = pair.first;
|
||||
EntityID parent = pair.second;
|
||||
|
||||
auto templateComponent = m_World->GetComponent<Components::Template>(entity);
|
||||
if(templateComponent)
|
||||
continue;
|
||||
|
||||
if (m_RigidBodies.find(entity) == m_RigidBodies.end())
|
||||
continue;
|
||||
|
||||
@@ -218,6 +222,10 @@ void Systems::PhysicsSystem::Update(double dt)
|
||||
|
||||
void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto templateComponent = m_World->GetComponent<Components::Template>(entity);
|
||||
if(templateComponent)
|
||||
return;
|
||||
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (!transformComponent)
|
||||
return;
|
||||
@@ -297,14 +305,14 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
|
||||
if (physicsComponent && m_Shapes[entity].size() > 0)
|
||||
{
|
||||
if(entityParent != 0 && !physicsComponent->Static)
|
||||
if(entityParent != 0 && physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Dynamic)
|
||||
{
|
||||
LOG_ERROR("Entity: %i, Only the baseparent can have a dynamic PhysicsComponent", entity);
|
||||
return;
|
||||
}
|
||||
|
||||
hkpShape* shape;
|
||||
if(! physicsComponent->Static) // Not static
|
||||
if(physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Dynamic)
|
||||
{
|
||||
hkArray<hkpShape*> shapeArray;
|
||||
for (auto &shapeData : m_Shapes[entity])
|
||||
@@ -368,6 +376,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
rigidBodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor;
|
||||
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);
|
||||
@@ -381,7 +390,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
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;
|
||||
rigidBodyInfo.m_enableDeactivation = true;;
|
||||
}
|
||||
// Create RigidBody
|
||||
hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo);
|
||||
@@ -438,7 +447,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
rigidBody->removeReference();
|
||||
}
|
||||
}
|
||||
else // Static
|
||||
else if(physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Fixed || physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Keyframed)
|
||||
{
|
||||
// Create the hkpStaticCompoundShape and add the instances.
|
||||
// "meshShape" should not be modified by the user in any way after adding it as an instance.
|
||||
@@ -490,7 +499,15 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
hkpRigidBodyCinfo rigidBodyInfo;
|
||||
{
|
||||
rigidBodyInfo.m_shape = shape;
|
||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_KEYFRAMED;
|
||||
if(physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Fixed)
|
||||
{
|
||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
|
||||
}
|
||||
else if(physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Keyframed)
|
||||
{
|
||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_KEYFRAMED;
|
||||
}
|
||||
|
||||
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
|
||||
hkVector4 position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position);
|
||||
hkQuaternion rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation);
|
||||
@@ -513,7 +530,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
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;
|
||||
rigidBodyInfo.m_enableDeactivation = true;
|
||||
}
|
||||
// Create RigidBody
|
||||
hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo);
|
||||
@@ -752,6 +769,7 @@ bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event )
|
||||
{
|
||||
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_RigidBodies[event.Entity]->activate();
|
||||
m_RigidBodies[event.Entity]->setLinearVelocity(GLMVEC3_TO_HKVECTOR4(event.Velocity));
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity);
|
||||
transformComponent->Velocity = event.Velocity;
|
||||
@@ -795,7 +813,6 @@ void Systems::PhysicsSystem::OnComponentRemoved(EntityID entity, std::string typ
|
||||
m_RigidBodies.erase(entity);
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -139,6 +139,9 @@ bool Systems::TankSteeringSystem::OnCollision(const Events::Collision &e)
|
||||
return false;
|
||||
}
|
||||
|
||||
if(m_World->GetComponent<Components::Template>(shellEntity))
|
||||
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);
|
||||
@@ -205,8 +208,6 @@ bool Systems::TankSteeringSystem::OnCollision(const Events::Collision &e)
|
||||
EventBroker->Publish(d);
|
||||
}
|
||||
|
||||
|
||||
|
||||
m_World->RemoveEntity(shellEntity);
|
||||
}
|
||||
}
|
||||
@@ -329,7 +330,7 @@ EntityID Systems::TankSteeringSystem::CreateTank(int playerID)
|
||||
//transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0));
|
||||
auto physics = m_World->AddComponent<Components::Physics>(tank);
|
||||
physics->Mass = 63000 - 16000;
|
||||
physics->Static = false;
|
||||
physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic;
|
||||
auto vehicle = m_World->AddComponent<Components::Vehicle>(tank);
|
||||
vehicle->MaxTorque = 8000.f;
|
||||
vehicle->MaxSteeringAngle = 90.f;
|
||||
@@ -397,7 +398,7 @@ EntityID Systems::TankSteeringSystem::CreateTank(int playerID)
|
||||
m_World->AddComponent<Components::Template>(shot);
|
||||
auto physics = m_World->AddComponent<Components::Physics>(shot);
|
||||
physics->Mass = 25.f;
|
||||
physics->Static = false;
|
||||
physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic;
|
||||
physics->CollisionEvent = true;
|
||||
auto modelComponent = m_World->AddComponent<Components::Model>(shot);
|
||||
modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj";
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "WallSystem.h"
|
||||
#include "World.h"
|
||||
|
||||
void Systems::WallSystem::RegisterComponents( ComponentFactory* cf )
|
||||
{
|
||||
cf->Register<Components::Wall>([]() { return new Components::Wall(); });
|
||||
}
|
||||
|
||||
void Systems::WallSystem::Initialize()
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_eDamage, &Systems::WallSystem::Damage);
|
||||
}
|
||||
|
||||
bool Systems::WallSystem::Damage( const Events::Damage &event )
|
||||
{
|
||||
auto wallComponent = m_World->GetComponent<Components::Wall>(event.Entity);
|
||||
if(!wallComponent)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
LOG_INFO("WallSystem::Damage");
|
||||
auto wallhealthcomponent = m_World->GetComponent<Components::Health>(event.Entity);
|
||||
if(wallhealthcomponent->Amount > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
LOG_INFO("You are dead");
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity);
|
||||
|
||||
for(auto d : wallComponent->Walldebris)
|
||||
{
|
||||
auto debris = m_World->CloneEntity(d);
|
||||
|
||||
auto transform = m_World->GetComponent<Components::Transform>(debris);
|
||||
transform->Position += transformComponent->Position;
|
||||
|
||||
// DO STUFF! :D
|
||||
float distance = glm::distance(transform->Position, transformComponent->Position);
|
||||
float radius = 5.f;
|
||||
float strength = (1.f - pow(distance / radius, 2)) * 500.f;
|
||||
glm::vec3 direction = glm::normalize(transformComponent->Position - transform->Position);
|
||||
|
||||
Events::ApplyPointImpulse e;
|
||||
e.Entity = debris;
|
||||
e.Impulse = direction * strength;
|
||||
e.Position = transformComponent->Position;
|
||||
EventBroker->Publish(e);
|
||||
|
||||
}
|
||||
|
||||
m_World->RemoveEntity(event.Entity);
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef WallSystem_h__
|
||||
#define WallSystem_h__
|
||||
|
||||
|
||||
#include "System.h"
|
||||
#include "Events/OnDead.h"
|
||||
#include "Events/Damage.h"
|
||||
#include "Events/ApplyPointImpulse.h"
|
||||
#include "Components/Model.h"
|
||||
#include "Components/Wall.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/Physics.h"
|
||||
#include "Components/MeshShape.h"
|
||||
#include "Components/Tankshell.h"
|
||||
#include "Components/Health.h"
|
||||
|
||||
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
class WallSystem : public System
|
||||
{
|
||||
public:
|
||||
|
||||
WallSystem(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<WallSystem, Events::Damage> m_eDamage;
|
||||
bool Damage(const Events::Damage &event);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif // WallSystem_h__
|
||||
Reference in New Issue
Block a user