Merge remote-tracking branch 'origin/master' into deffered_rendering

Conflicts:
	src/GameWorld.cpp
	src/GameWorld.h
	vs11/Returngeance/Returngeance.vcxproj
	vs11/Returngeance/Returngeance.vcxproj.filters
This commit is contained in:
Tleety
2014-06-05 03:03:00 +02:00
45 changed files with 1430 additions and 299 deletions
+1
View File
@@ -4,6 +4,7 @@
void Systems::DamageSystem::RegisterComponents( ComponentFactory* cf )
{
cf->Register<Components::Health>([]() { return new Components::Health(); });
cf->Register<Components::DamageModel>([]() { return new Components::DamageModel(); });
}
void Systems::DamageSystem::Initialize()
+1
View File
@@ -4,6 +4,7 @@
#include "System.h"
#include "Components/Health.h"
#include "Components/DamageModel.h"
#include "Events/Damage.h"
#include "Events/OnDead.h"
+19
View File
@@ -0,0 +1,19 @@
#include "PrecompiledHeader.h"
#include "GameStateSystem.h"
#include "World.h"
void Systems::GameStateSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EFlagCaptured, &Systems::GameStateSystem::OnFlagCaptured);
}
bool Systems::GameStateSystem::OnFlagCaptured(const Events::FlagCaptured &event)
{
m_InGame = false;
Events::GameOver e;
e.Winner = event.Player;
EventBroker->Publish(e);
return true;
}
+37
View File
@@ -0,0 +1,37 @@
#ifndef GameStateSystem_h__
#define GameStateSystem_h__
#include <set>
#include "System.h"
#include "Components/Transform.h"
#include "Components/Player.h"
#include "Events/FlagCaptured.h"
#include "Events/GameOver.h"
namespace Systems
{
class GameStateSystem : public System
{
public:
GameStateSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker, resourceManager)
, m_InGame(true)
{ }
void Initialize() override;
bool InGame() const { return m_InGame; }
private:
bool m_InGame;
EventRelay<GameStateSystem, Events::FlagCaptured> m_EFlagCaptured;
bool OnFlagCaptured(const Events::FlagCaptured &event);
};
}
#endif // GameStateSystem_h__
+28 -5
View File
@@ -34,6 +34,14 @@ bool Systems::GarageSystem::OnEnterTrigger(const Events::EnterTrigger &event)
if (!garageComponent)
return false;
auto teamComponent = m_World->GetComponent<Components::Team>(event.Trigger);
auto playerComponent = m_World->GetComponent<Components::Player>(event.Entity);
if(!teamComponent || !playerComponent)
return false;
if (teamComponent->TeamID != playerComponent->ID)
return false;
std::string name = m_World->GetProperty<std::string>(event.Trigger, "Name");
if (name == "BoundsTrigger")
@@ -56,6 +64,15 @@ bool Systems::GarageSystem::OnLeaveTrigger(const Events::LeaveTrigger &event)
if (!garageComponent)
return false;
auto teamComponent = m_World->GetComponent<Components::Team>(event.Trigger);
auto playerComponent = m_World->GetComponent<Components::Player>(event.Entity);
if(!teamComponent || !playerComponent)
return false;
if (teamComponent->TeamID != playerComponent->ID)
return false;
std::string name = m_World->GetProperty<std::string>(event.Trigger, "Name");
if (name == "BoundsTrigger")
@@ -76,18 +93,24 @@ bool Systems::GarageSystem::OnCommand(const Events::InputCommand &event)
{
EntityID trigger = pair.first;
auto entities = pair.second;
std::string name = m_World->GetProperty<std::string>(trigger, "Name");
if (name != "ElevatorShaftTrigger")
continue;
auto triggerBaseParent = m_World->GetEntityBaseParent(trigger);
auto triggerPlayerComponent = m_World->GetComponent<Components::Player>(triggerBaseParent);
auto triggerTeamComponent = m_World->GetComponent<Components::Team>(trigger);
if (!triggerTeamComponent)
continue;
for (EntityID entity : entities)
{
auto entityPlayerComponent = m_World->GetComponent<Components::Player>(triggerBaseParent);
if (triggerPlayerComponent == entityPlayerComponent)
auto entityPlayerComponent = m_World->GetComponent<Components::Player>(entity);
if(!entityPlayerComponent)
continue;
if (entityPlayerComponent->ID != event.PlayerID)
continue;
if (triggerTeamComponent->TeamID == entityPlayerComponent->ID)
{
EntityID garage = m_World->GetEntityParent(trigger);
auto garageComponent = m_World->GetComponent<Components::Garage>(garage);
+1
View File
@@ -18,6 +18,7 @@
#include "Events/Rotate.h"
#include "Components/Move.h"
#include "Components/Rotate.h"
#include "Components/Team.h"
namespace Systems
{
+356
View File
@@ -0,0 +1,356 @@
#include "PrecompiledHeader.h"
#include "JeepSteeringSystem.h"
#include "World.h"
void Systems::JeepSteeringSystem::RegisterComponents(ComponentFactory* cf)
{
cf->Register<Components::JeepSteering>([]() { return new Components::JeepSteering(); });
}
void Systems::JeepSteeringSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_ESpawnVehicle, &Systems::JeepSteeringSystem::OnSpawnVehicle);
for (int i = 0; i < 4; i++)
{
m_JeepInputControllers[i] = std::shared_ptr<JeepSteeringInputController>(new JeepSteeringInputController(EventBroker, i + 1));
}
}
void Systems::JeepSteeringSystem::Update(double dt)
{
for (int i = 0; i < 4; i++)
{
m_JeepInputControllers[i]->Update(dt);
}
}
void Systems::JeepSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto tankSteeringComponent = m_World->GetComponent<Components::JeepSteering>(entity);
if(!tankSteeringComponent)
return;
auto playerComponent = m_World->GetComponent<Components::Player>(entity);
if (!playerComponent)
return;
if (playerComponent->ID == 0)
return;
auto inputController = m_JeepInputControllers[playerComponent->ID - 1];
Events::JeepSteer eSteering;
eSteering.Entity = entity;
eSteering.PositionX = inputController->PositionX;
eSteering.PositionY = inputController->PositionY;
eSteering.Handbrake = inputController->Handbrake;
EventBroker->Publish(eSteering);
}
bool Systems::JeepSteeringSystem::OnSpawnVehicle(const Events::SpawnVehicle &event)
{
if (event.VehicleType != "Jeep")
return false;
auto spawnPointComponents = m_World->GetComponentsOfType<Components::SpawnPoint>();
if (!spawnPointComponents)
{
LOG_ERROR("Found no spawn points!");
return false;
}
for (auto &component : *spawnPointComponents)
{
auto spawnPoint = component->Entity;
auto spawnPointComponent = std::dynamic_pointer_cast<Components::SpawnPoint>(component);
auto teamComponent = m_World->GetComponent<Components::Team>(spawnPoint);
if(!teamComponent)
{
LOG_ERROR("SpawnPoint has no TeamComponent");
continue;
}
if (teamComponent->TeamID != event.PlayerID)
continue;
Components::Transform absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(spawnPoint);
// Create a Jeep
EntityID Jeep = CreateJeep(event.PlayerID);
auto tankTransform = m_World->GetComponent<Components::Transform>(Jeep);
tankTransform->Position = absoluteTransform.Position;
tankTransform->Orientation = absoluteTransform.Orientation;
// Set the viewport correctly
Events::SetViewportCamera e;
e.CameraEntity = m_World->GetProperty<EntityID>(Jeep, "Camera");
if (event.PlayerID == 1)
e.ViewportFrame = "Viewport1";
else if (event.PlayerID == 2)
e.ViewportFrame = "Viewport2";
EventBroker->Publish(e);
}
return true;
}
EntityID Systems::JeepSteeringSystem::CreateJeep(int playerID)
{
auto jeep = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(jeep);
transform->Position = glm::vec3(0, 5, 0);
//transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0));
auto physics = m_World->AddComponent<Components::Physics>(jeep);
physics->Mass = 2000;
physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic;
physics->CenterOfMass = glm::vec3(0, 0, 0);
auto vehicle = m_World->AddComponent<Components::Vehicle>(jeep);
vehicle->MaxTorque = 500.0f;
vehicle->MaxSteeringAngle = 40.f;
vehicle->MaxSpeedFullSteeringAngle = 12.f;
vehicle->MinRPM = 1000.0f;
vehicle->OptimalRPM = 5500.0f,
vehicle->MaxRPM = 7500.0f;
vehicle->TopSpeed = 90.0f;
vehicle->SpringDamping = 5.f;
vehicle->UpshiftRPM = 6500.0f;
vehicle->DownshiftRPM = 3500.0f;
vehicle->gearsRatio0 = 3.0f;
vehicle->gearsRatio1 = 2.25f;
vehicle->gearsRatio2 = 1.5f;
vehicle->gearsRatio3 = 1.0f;
auto player = m_World->AddComponent<Components::Player>(jeep);
player->ID = playerID;
auto jeepSteering = m_World->AddComponent<Components::JeepSteering>(jeep);
m_World->AddComponent<Components::Input>(jeep);
auto health = m_World->AddComponent<Components::Health>(jeep);
health->Amount = 100.f;
/*{
auto shape = m_World->CreateEntity(jeep);
auto transform = m_World->AddComponent<Components::Transform>(shape);
auto meshShape = m_World->AddComponent<Components::MeshShape>(shape);
meshShape->ResourceName = "Models/Jeep/Chassi/ChassiCollision.obj";
m_World->CommitEntity(shape);
}*/
{
auto chassis = m_World->CreateEntity(jeep);
auto transform = m_World->AddComponent<Components::Transform>(chassis);
transform->Position = glm::vec3(0, 0, 0);
auto model = m_World->AddComponent<Components::Model>(chassis);
model->ModelFile = "Models/Jeep/Chassi/Chassi.OBJ";
}
{
auto shape = m_World->CreateEntity(jeep);
auto transform = m_World->AddComponent<Components::Transform>(shape);
transform->Position = glm::vec3(-0.0219f ,0.88937f, -0.48469f);
auto box = m_World->AddComponent<Components::BoxShape>(shape);
box->Width = 0.993f;
box->Height = 0.626f;
box->Depth = 1.316f;
m_World->CommitEntity(shape);
}
{
auto shape = m_World->CreateEntity(jeep);
auto transform = m_World->AddComponent<Components::Transform>(shape);
transform->Position = glm::vec3(-0.02551f ,0.55419f, 1.78935f);
auto box = m_World->AddComponent<Components::BoxShape>(shape);
box->Width = 0.849f;
box->Height = 0.415f;
box->Depth = 1.058f;
m_World->CommitEntity(shape);
}
{
auto shape = m_World->CreateEntity(jeep);
auto transform = m_World->AddComponent<Components::Transform>(shape);
transform->Position = glm::vec3(-1.63274f ,0.98825f, -0.89907f);
auto box = m_World->AddComponent<Components::BoxShape>(shape);
box->Width = 0.697f;
box->Height = 0.401f;
box->Depth = 0.868f;
m_World->CommitEntity(shape);
}
{
auto shape = m_World->CreateEntity(jeep);
auto transform = m_World->AddComponent<Components::Transform>(shape);
transform->Position = glm::vec3(1.63274f ,0.98825f, -0.89907f);
auto box = m_World->AddComponent<Components::BoxShape>(shape);
box->Width = 0.697f;
box->Height = 0.401f;
box->Depth = 0.868f;
m_World->CommitEntity(shape);
}
auto cameraTower = m_World->CreateEntity(jeep);
{
auto transform = m_World->AddComponent<Components::Transform>(cameraTower);
transform->Position.z = 16.f;
transform->Position.y = 4.f;
transform->Orientation = glm::quat(glm::vec3(-glm::radians(5.f), 0.f, 0.f));
auto cameraComp = m_World->AddComponent<Components::Camera>(cameraTower);
cameraComp->FarClip = 2000.f;
m_World->SetProperty(jeep, "Camera", cameraTower);
}
#pragma region Wheels
//Create wheels
float wheelOffset = 0.f;//-0.83f;
const float suspensionStrength = 15.f;
const float springLength = 0.3f;
AddJeepWheels(jeep);
#pragma endregion
{
auto entity = m_World->CreateEntity(jeep);
auto transformComponent = m_World->AddComponent<Components::Transform>(entity);
transformComponent->Position = glm::vec3(-2, -1.7, 2.0);
transformComponent->Scale = glm::vec3(3, 3, 3);
transformComponent->Orientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
auto emitterComponent = m_World->AddComponent<Components::ParticleEmitter>(entity);
emitterComponent->SpawnCount = 2;
emitterComponent->SpawnFrequency = 0.005;
emitterComponent->SpreadAngle = glm::pi<float>();
emitterComponent->UseGoalVelocity = false;
emitterComponent->LifeTime = 0.5;
//emitterComponent->AngularVelocitySpectrum.push_back(glm::pi<float>() / 100);
emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05));
m_World->CommitEntity(entity);
auto particleEntity = m_World->CreateEntity(entity);
auto TEMP = m_World->AddComponent<Components::Transform>(particleEntity);
TEMP->Scale = glm::vec3(0);
auto spriteComponent = m_World->AddComponent<Components::Sprite>(particleEntity);
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
emitterComponent->ParticleTemplate = particleEntity;
m_World->CommitEntity(particleEntity);
}
m_World->CommitEntity(jeep);
return jeep;
}
void Systems::JeepSteeringSystem::AddJeepWheels(EntityID jeepEntity)
{
//Create wheels
float wheelOffset = 0.5f;
float springLength = 0.2f;
float suspensionStrength = 35.f;
{
auto wheel = m_World->CreateEntity(jeepEntity);
auto transform = m_World->AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(1.9f, 0.5546f - wheelOffset, -0.9242f);
transform->Scale = glm::vec3(1.0f);
auto model = m_World->AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj";
auto Wheel = m_World->AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 50;
Wheel->Radius = 0.837f;
Wheel->Steering = true;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 2.5f;
Wheel->ConnectedToHandbrake = true;
m_World->CommitEntity(wheel);
}
{
auto wheel = m_World->CreateEntity(jeepEntity);
auto transform = m_World->AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(-1.9f, 0.5546f - wheelOffset, -0.9242f);
transform->Scale = glm::vec3(1.0f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
auto model = m_World->AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj";
auto Wheel = m_World->AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 50;
Wheel->Radius = 0.837f;
Wheel->Steering = true;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 2.5f;
Wheel->ConnectedToHandbrake = true;
m_World->CommitEntity(wheel);
}
{
auto wheel = m_World->CreateEntity(jeepEntity);
auto transform = m_World->AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(0.2726f, 0.2805f - (wheelOffset/2), 1.9307f);
auto model = m_World->AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj";
auto Wheel = m_World->AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 150;
Wheel->Radius = 0.737f;
Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 2.5f;
Wheel->ConnectedToHandbrake = true;
m_World->CommitEntity(wheel);
}
{
auto wheel = m_World->CreateEntity(jeepEntity);
auto transform = m_World->AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(-0.2726f, 0.2805f - (wheelOffset/2), 1.9307f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
auto model = m_World->AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj";
auto Wheel = m_World->AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 150;
Wheel->Radius = 0.737f;
Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 2.5f;
Wheel->ConnectedToHandbrake = true;
m_World->CommitEntity(wheel);
}
}
void Systems::JeepSteeringSystem::JeepSteeringInputController::Update( double dt )
{
PositionX = m_Horizontal;
PositionY = m_Vertical;
}
bool Systems::JeepSteeringSystem::JeepSteeringInputController::OnCommand(const Events::InputCommand &event)
{
if (event.PlayerID != this->PlayerID)
return false;
float val = event.Value;
// Tank
if (event.Command == "horizontal")
{
m_Horizontal = val;
}
else if (event.Command == "jeep_vertical")
{
m_Vertical = -val;
}
else if (event.Command == "handbrake")
{
Handbrake = val > 0;
}
return true;
}
+93
View File
@@ -0,0 +1,93 @@
#include <array>
#include "System.h"
#include "Components/Transform.h"
#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/Trigger.h"
#include "Components/Vehicle.h"
#include "Components/Player.h"
#include "Events/SpawnVehicle.h"
#include "Components/SpawnPoint.h"
#include "Components/Wheel.h"
#include "Components/MeshShape.h"
#include "Components/Camera.h"
#include "Components/BoxShape.h"
#include "Components/WheelPair.h"
#include "Components/Input.h"
#include "Components/JeepSteering.h"
#include "Events/JeepSteer.h"
#include "Components/Team.h"
#include "Events/SetViewportCamera.h"
namespace Systems
{
class JeepSteeringSystem : public System
{
public:
JeepSteeringSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker, resourceManager)
{ }
void RegisterComponents(ComponentFactory* cf) override;
void Initialize() override;
void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
private:
std::map<EntityID, double> m_TimeSinceLastShot;
EventRelay<JeepSteeringSystem, Events::SpawnVehicle> m_ESpawnVehicle;
bool OnSpawnVehicle(const Events::SpawnVehicle &e);
class JeepSteeringInputController;
std::array<std::shared_ptr<JeepSteeringInputController>, 4> m_JeepInputControllers;
EntityID CreateJeep(int playerID);
void AddJeepWheels(EntityID jeepEntity);
};
class JeepSteeringSystem::JeepSteeringInputController : InputController<JeepSteeringSystem>
{
public:
JeepSteeringInputController(std::shared_ptr<::EventBroker> eventBroker, int playerID)
: InputController(eventBroker)
{
PlayerID = playerID;
m_Horizontal = 0.f;
m_Vertical = 0.f;
PositionX = 0;
PositionY = 0;
Handbrake = false;
}
int PlayerID;
float PositionY;
float PositionX;
bool Handbrake;
void Update(double dt);
protected:
virtual bool OnCommand(const Events::InputCommand &event);
//virtual bool OnMouseMove(const Events::MouseMove &event);
private:
float m_Horizontal;
float m_Vertical;
};
}
+64 -58
View File
@@ -33,6 +33,7 @@ void Systems::PhysicsSystem::Initialize()
// Events
EVENT_SUBSCRIBE_MEMBER(m_ETankSteer, &Systems::PhysicsSystem::OnTankSteer);
EVENT_SUBSCRIBE_MEMBER(m_EJeepSteer, &Systems::PhysicsSystem::OnJeepSteer);
EVENT_SUBSCRIBE_MEMBER(m_ESetVelocity, &Systems::PhysicsSystem::OnSetVelocity);
EVENT_SUBSCRIBE_MEMBER(m_EApplyForce, &Systems::PhysicsSystem::OnApplyForce);
EVENT_SUBSCRIBE_MEMBER(m_EApplyPointImpulse, &Systems::PhysicsSystem::OnApplyPointImpulse);
@@ -274,27 +275,10 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
else if(m_RigidBodies.find(entity) != m_RigidBodies.end())
{
auto transformComponentParent = m_World->GetComponent<Components::Transform>(parent);
/* if(transformComponentParent)
{
auto absoluteTransformParent = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(parent);
transformComponent->Position = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getPosition());
transformComponent->Orientation = glm::inverse(HKQUATERNION_TO_GLMQUAT(m_RigidBodies[entity]->getRotation())) * absoluteTransformParent.Orientation;
transformComponent->Velocity = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getLinearVelocity());
}
else
{
auto transformComponentParent = m_World->GetComponent<Components::Transform>(parent);
transformComponent->Position = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getPosition());
transformComponent->Orientation = HKQUATERNION_TO_GLMQUAT(m_RigidBodies[entity]->getRotation());
transformComponent->Velocity = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getLinearVelocity());
}*/
transformComponent->Position = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getPosition());
transformComponent->Orientation = HKQUATERNION_TO_GLMQUAT(m_RigidBodies[entity]->getRotation());
transformComponent->Velocity = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getLinearVelocity());
// HACK: WTF IS THIS?
if (transformComponentParent)
{
auto absoluteTransformParent = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(parent);
@@ -758,47 +742,6 @@ void HK_CALL Systems::PhysicsSystem::HavokErrorReport(const char* msg, void*)
LOG_INFO("%s", msg);
}
bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event)
{
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(event.Entity);
if (vehicleComponent && m_Vehicles.find(event.Entity) != m_Vehicles.end() && m_RigidBodies.find(event.Entity) != m_RigidBodies.end())
{
hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[event.Entity]->m_deviceStatus;
auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity);
float steeringX = event.PositionX;
glm::vec3 velocityNormalized = glm::normalize(HKVECTOR4_TO_GLMVEC3(m_RigidBodies[event.Entity]->getLinearVelocity()));
glm::vec3 forward = glm::normalize(transformComponent->Orientation * glm::vec3(0, 0, -1));
float dotProduct = glm::dot(forward, velocityNormalized);
if(dotProduct < 0)
{
steeringX = (1 - (glm::clamp(abs(m_Vehicles[event.Entity]->calcKMPH() /vehicleComponent->TopSpeed), 0.f, 0.7f))) * steeringX;
}
if(abs(m_Vehicles[event.Entity]->calcKMPH()) < 2 && abs(m_Vehicles[event.Entity]->m_mainSteeringAngle) > 80.f * (HK_REAL_PI / 180))
{
deviceStatus->m_positionY = -0.4f;
deviceStatus->m_positionX = steeringX;
}
else
{
deviceStatus->m_positionX = event.PositionX;
deviceStatus->m_positionY = event.PositionY;
}
if(event.PositionY > 0)
{
deviceStatus->m_reverseButtonPressed = true;
}
deviceStatus->m_handbrakeButtonPressed = event.Handbrake;
}
return true;
}
bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event )
{
if(m_RigidBodies.find(event.Entity) != m_RigidBodies.end())
@@ -894,3 +837,66 @@ bool Systems::PhysicsSystem::OnDisableCollisions( const Events::DisableCollision
m_PhysicsWorld->unmarkForWrite();
return true;
}
bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event)
{
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(event.Entity);
if (vehicleComponent && m_Vehicles.find(event.Entity) != m_Vehicles.end() && m_RigidBodies.find(event.Entity) != m_RigidBodies.end())
{
hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[event.Entity]->m_deviceStatus;
auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity);
float steeringX = event.PositionX;
glm::vec3 velocityNormalized = glm::normalize(HKVECTOR4_TO_GLMVEC3(m_RigidBodies[event.Entity]->getLinearVelocity()));
glm::vec3 forward = glm::normalize(transformComponent->Orientation * glm::vec3(0, 0, -1));
float dotProduct = glm::dot(forward, velocityNormalized);
if(dotProduct < 0)
{
steeringX = (1 - (glm::clamp(abs(m_Vehicles[event.Entity]->calcKMPH() /vehicleComponent->TopSpeed), 0.f, 0.7f))) * steeringX;
}
if(abs(m_Vehicles[event.Entity]->calcKMPH()) < 2 && abs(m_Vehicles[event.Entity]->m_mainSteeringAngle) > 80.f * (HK_REAL_PI / 180))
{
deviceStatus->m_positionY = -0.4f;
deviceStatus->m_positionX = steeringX;
}
else
{
deviceStatus->m_positionX = event.PositionX;
deviceStatus->m_positionY = event.PositionY;
}
if(event.PositionY > 0)
{
deviceStatus->m_reverseButtonPressed = true;
}
deviceStatus->m_handbrakeButtonPressed = event.Handbrake;
}
return true;
}
bool Systems::PhysicsSystem::OnJeepSteer( const Events::JeepSteer &event )
{
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(event.Entity);
if (vehicleComponent && m_Vehicles.find(event.Entity) != m_Vehicles.end() && m_RigidBodies.find(event.Entity) != m_RigidBodies.end())
{
hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[event.Entity]->m_deviceStatus;
deviceStatus->m_positionX = event.PositionX;
deviceStatus->m_positionY = event.PositionY;
if(event.PositionY > 0)
{
deviceStatus->m_reverseButtonPressed = true;
}
deviceStatus->m_handbrakeButtonPressed = event.Handbrake;
}
return true;
}
+3
View File
@@ -88,6 +88,7 @@
#include "Components/Template.h"
#include "Events/EnterTrigger.h"
#include "Events/JeepSteer.h"
namespace Systems
{
@@ -178,6 +179,8 @@ private:
// Events
EventRelay<PhysicsSystem, Events::TankSteer> m_ETankSteer;
bool OnTankSteer(const Events::TankSteer &event);
EventRelay<PhysicsSystem, Events::JeepSteer> m_EJeepSteer;
bool OnJeepSteer(const Events::JeepSteer &event);
EventRelay<PhysicsSystem, Events::SetVelocity> m_ESetVelocity;
bool OnSetVelocity(const Events::SetVelocity &event);
EventRelay<PhysicsSystem, Events::ApplyForce> m_EApplyForce;
+82 -50
View File
@@ -50,7 +50,6 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
eSteering.Handbrake = inputController->Handbrake;
EventBroker->Publish(eSteering);
auto towerSteeringComponent = m_World->GetComponent<Components::TowerSteering>(tankSteeringComponent->Turret);
auto barrelSteeringComponent = m_World->GetComponent<Components::BarrelSteering>(tankSteeringComponent->Barrel);
@@ -65,7 +64,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
{
auto tankTransform = m_World->GetComponent<Components::Transform>(entity);
auto transformComponent = m_World->GetComponent<Components::Transform>(tankSteeringComponent->Barrel);
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(tankSteeringComponent->Barrel);
glm::quat orientation = glm::angleAxis(barrelSteeringComponent->TurnSpeed * inputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis);
transformComponent->Orientation *= orientation;
@@ -81,7 +80,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
transformComponent->Orientation = glm::quat(angles);
}
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(tankSteeringComponent->Barrel);
if(inputController->Shoot && m_TimeSinceLastShot[tankSteeringComponent->Barrel] > 0.5)
{
@@ -138,7 +137,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
auto clonePhysicsComponent = m_World->GetComponent<Components::Physics>(clone);
//1,670m/s
//25kg
Events::ApplyPointImpulse ePointImpulse ;
Events::ApplyPointImpulse ePointImpulse;
ePointImpulse.Entity = entity;
ePointImpulse.Position = absoluteTransform.Position;
ePointImpulse.Impulse = glm::normalize(absoluteTransform.Orientation * glm::vec3(0, 0, 1)) * clonePhysicsComponent->Mass * 6.f * 1670.f;
@@ -194,39 +193,39 @@ bool Systems::TankSteeringSystem::OnCollision(const Events::Collision &e)
//auto otherTransform = m_World->GetComponent<Components::Transform>(otherEntity);
{
// Events::CreateExplosion e;
// e.LifeTime = 3;
// e.ParticleScale.push_back(8);
// e.ParticlesToSpawn = 20;
// e.Position = shellTransform->Position;
// e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1,0,0));
// e.Speed = 3;
// e.SpreadAngle = glm::pi<float>();
// e.spritePath = "Textures/Sprites/Smoke1.png";
// e.Color = glm::vec4(0.6,0.6,0.6,1);
// EventBroker->Publish(e);
// e.LifeTime = 0.7;
// e.ParticleScale.push_back(12);
// e.ParticlesToSpawn = 10;
// e.Position = shellTransform->Position;
// e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1,0,0));
// e.Speed = 17;
// e.SpreadAngle = glm::pi<float>();
// e.spritePath = "Textures/Sprites/Fire.png";
// EventBroker->Publish(e);
// e.LifeTime = 0.2;
// e.ParticleScale.push_back(1);
// e.ParticleScale.push_back(15);
// e.ParticlesToSpawn = 5;
// e.Position = shellTransform->Position;
// e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1,0,0));
// e.Speed = 6;
// e.SpreadAngle = glm::pi<float>();
// e.spritePath = "Textures/Sprites/Blast1.png";
// e.Color = glm::vec4(2, 2, 2, 0.2);
// EventBroker->Publish(e);
Events::CreateExplosion e;
e.LifeTime = 3;
e.ParticleScale.push_back(8);
e.ParticlesToSpawn = 20;
e.Position = shellTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
e.Speed = 3;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/Smoke1.png";
e.Color = glm::vec4(0.6, 0.6, 0.6, 1);
EventBroker->Publish(e);
e.LifeTime = 0.7;
e.ParticleScale.push_back(12);
e.ParticlesToSpawn = 10;
e.Position = shellTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
e.Speed = 17;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/Fire.png";
EventBroker->Publish(e);
e.LifeTime = 0.2;
e.ParticleScale.push_back(1);
e.ParticleScale.push_back(15);
e.ParticlesToSpawn = 5;
e.Position = shellTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
e.Speed = 6;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/Blast1.png";
e.Color = glm::vec4(2, 2, 2, 0.2);
EventBroker->Publish(e);
/*Events::CreateExplosion e;
e.LifeTime = 1.5;
e.ParticleScale.push_back(1);
e.ParticleScale.push_back(6);
@@ -253,7 +252,7 @@ bool Systems::TankSteeringSystem::OnCollision(const Events::Collision &e)
e.Speed = 12;
e.spritePath = "Textures/Sprites/Splash.png";
e.Color = glm::vec4(1.f,1.f,1.f,1);
EventBroker->Publish(e);
EventBroker->Publish(e);*/
}
{
Events::PlaySFX e;
@@ -263,27 +262,41 @@ bool Systems::TankSteeringSystem::OnCollision(const Events::Collision &e)
EventBroker->Publish(e);
}
// Direct damage
auto health = m_World->GetComponent<Components::Health>(otherEntity);
if (health)
{
Events::Damage d;
d.Entity = otherEntity;
d.Amount = shellComponent->Damage;
EventBroker->Publish(d);
}
// Splash damage
for (auto &physComponent : *physicsComponents)
{
EntityID physicsEntity = std::dynamic_pointer_cast<Components::Physics>(physComponent)->Entity;
auto physEntityTransform = m_World->GetComponent<Components::Transform>(physicsEntity);
EntityID physicsEntity = physComponent->Entity;
// No splash damage to the direct hit target
if (physicsEntity == otherEntity)
continue;
auto physEntityTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(physicsEntity);
float distance = glm::distance(physEntityTransform->Position, shellTransform->Position);
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);
glm::vec3 direction = glm::normalize(physEntityTransform.Position - shellTransform->Position);
Events::ApplyPointImpulse e;
e.Entity = physicsEntity;
e.Impulse = direction * strength;
e.Position = physEntityTransform->Position;
e.Position = physEntityTransform.Position;
EventBroker->Publish(e);
auto health = m_World->GetComponent<Components::Health>(physicsEntity);
if(health)
if (health && health->VulnerableToSplash)
{
Events::Damage d;
d.Entity = physicsEntity;
@@ -375,7 +388,7 @@ bool Systems::TankSteeringSystem::OnSpawnVehicle(const Events::SpawnVehicle &eve
{
if (event.VehicleType != "Tank")
return false;
auto spawnPointComponents = m_World->GetComponentsOfType<Components::SpawnPoint>();
if (!spawnPointComponents)
{
@@ -387,8 +400,15 @@ bool Systems::TankSteeringSystem::OnSpawnVehicle(const Events::SpawnVehicle &eve
{
auto spawnPoint = component->Entity;
auto spawnPointComponent = std::dynamic_pointer_cast<Components::SpawnPoint>(component);
auto playerComponent = m_World->GetComponent<Components::Player>(spawnPointComponent->Player);
if (!playerComponent || playerComponent->ID != event.PlayerID)
auto teamComponent = m_World->GetComponent<Components::Team>(spawnPoint);
if(!teamComponent)
{
LOG_ERROR("SpawnPoint has no TeamComponent");
continue;
}
if (teamComponent->TeamID != event.PlayerID)
continue;
Components::Transform absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(spawnPoint);
@@ -396,8 +416,8 @@ bool Systems::TankSteeringSystem::OnSpawnVehicle(const Events::SpawnVehicle &eve
// Create a tank
EntityID tank = CreateTank(event.PlayerID);
auto tankTransform = m_World->GetComponent<Components::Transform>(tank);
tankTransform->Position = absoluteTransform.Position;
tankTransform->Orientation = absoluteTransform.Orientation;
tankTransform->Position = absoluteTransform.Position;
tankTransform->Orientation = absoluteTransform.Orientation;
// Set the viewport correctly
Events::SetViewportCamera e;
e.CameraEntity = m_World->GetProperty<EntityID>(tank, "Camera");
@@ -424,6 +444,18 @@ EntityID Systems::TankSteeringSystem::CreateTank(int playerID)
vehicle->MaxTorque = 8000.f;
vehicle->MaxSteeringAngle = 90.f;
vehicle->MaxSpeedFullSteeringAngle = 4.f;
vehicle->MinRPM = 200.0f;
vehicle->OptimalRPM = 2500.0f,
vehicle->MaxRPM = 4000.0f;
vehicle->TopSpeed = 90.0f;
vehicle->SpringDamping = 1.f;
vehicle->UpshiftRPM = 3500.0f;
vehicle->DownshiftRPM = 1000.0f;
vehicle->gearsRatio0 = 3.0f;
vehicle->gearsRatio1 = 2.25f;
vehicle->gearsRatio2 = 1.5f;
vehicle->gearsRatio3 = 1.0f;
auto player = m_World->AddComponent<Components::Player>(tank);
player->ID = playerID;
auto tankSteering = m_World->AddComponent<Components::TankSteering>(tank);
@@ -494,8 +526,8 @@ EntityID Systems::TankSteeringSystem::CreateTank(int playerID)
modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj";
auto tankShellComponent = m_World->AddComponent<Components::TankShell>(shot);
tankShellComponent->Damage = 20.f;
tankShellComponent->ExplosionRadius = 30.f;
tankShellComponent->ExplosionStrength = 300000.f;
tankShellComponent->ExplosionRadius = 20.f;
tankShellComponent->ExplosionStrength = 140.f;
{
auto shape = m_World->CreateEntity(shot);
auto transform = m_World->AddComponent<Components::Transform>(shape);
+2
View File
@@ -15,6 +15,7 @@
#include "Components/Vehicle.h"
#include "Components/Player.h"
#include "Components/Model.h"
#include "Components/Team.h"
#include "Systems/TransformSystem.h"
#include "Systems/ParticleSystem.h"
#include "InputController.h"
@@ -48,6 +49,7 @@
#include "Components/Input.h"
#include "Events/SetViewportCamera.h"
#include "Events/GameOver.h"
namespace Systems
{
+20 -1
View File
@@ -44,10 +44,18 @@ void Systems::TriggerSystem::OnEntityRemoved( EntityID entity )
bool Systems::TriggerSystem::OnEnterTrigger( const Events::EnterTrigger &event )
{
auto teamComponent = m_World->GetComponent<Components::Team>(event.Trigger);
auto playerComponent = m_World->GetComponent<Components::Player>(event.Entity);
if(!teamComponent || !playerComponent)
return false;
if (teamComponent->TeamID != playerComponent->ID)
return false;
auto flagComponent1 = m_World->GetComponent<Components::Flag>(event.Trigger);
auto flagComponent2 = m_World->GetComponent<Components::Flag>(event.Entity);
//HACK: SIMON IS DISSING AMERICA
if(flagComponent1)
{
@@ -77,6 +85,17 @@ bool Systems::TriggerSystem::OnEnterTrigger( const Events::EnterTrigger &event )
bool Systems::TriggerSystem::OnLeaveTrigger( const Events::LeaveTrigger &event )
{
auto teamComponent = m_World->GetComponent<Components::Team>(event.Trigger);
auto playerComponent = m_World->GetComponent<Components::Player>(event.Entity);
if(!teamComponent || !playerComponent)
return false;
if (teamComponent->TeamID != playerComponent->ID)
return false;
auto flagComponent1 = m_World->GetComponent<Components::Flag>(event.Trigger);
auto flagComponent2 = m_World->GetComponent<Components::Flag>(event.Entity);
auto triggerMoveComponent = m_World->GetComponent<Components::TriggerMove>(event.Trigger);
if (triggerMoveComponent)
{
+1
View File
@@ -21,6 +21,7 @@
#include "Components/Move.h"
#include "Components/Rotate.h"
#include "Components/Player.h"
#include "Components/Team.h"
#include "Events/Move.h"
#include "Events/Rotate.h"
#include <math.h>
+13
View File
@@ -20,6 +20,18 @@ bool Systems::WallSystem::Damage( const Events::Damage &event )
return false;
}
LOG_INFO("WallSystem::Damage");
// Change to damage model
auto modelComponent = m_World->GetComponent<Components::Model>(event.Entity);
auto damageModel = m_World->GetComponent<Components::DamageModel>(event.Entity);
if (modelComponent)
{
modelComponent->ModelFile = damageModel->ModelFile;
modelComponent->Color = damageModel->Color;
modelComponent->ShadowCaster = damageModel->ShadowCaster;
modelComponent->Transparent = damageModel->Transparent;
}
auto wallhealthcomponent = m_World->GetComponent<Components::Health>(event.Entity);
if(wallhealthcomponent->Amount > 0)
{
@@ -29,6 +41,7 @@ bool Systems::WallSystem::Damage( const Events::Damage &event )
//auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity);
Components::Transform transformComponent = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(event.Entity);
// Spawn debris
for(auto d : wallComponent->Walldebris)
{
auto debris = m_World->CloneEntity(d);
+1
View File
@@ -8,6 +8,7 @@
#include "Events/Damage.h"
#include "Events/ApplyPointImpulse.h"
#include "Components/Model.h"
#include "Components/DamageModel.h"
#include "Components/Wall.h"
#include "Components/Transform.h"
#include "Components/Physics.h"