Shots fired! ( ゚Д゚)

This commit is contained in:
ViktorLjung
2014-05-13 03:32:58 +02:00
parent 74d3269e35
commit ce5b62cf6d
12 changed files with 70 additions and 74 deletions
+5 -2
View File
@@ -31,7 +31,7 @@ void Systems::PhysicsSystem::Initialize()
// Events
EVENT_SUBSCRIBE_MEMBER(m_ETankSteer, &Systems::PhysicsSystem::OnTankSteer);
EVENT_SUBSCRIBE_MEMBER(m_ETankSteer, &Systems::PhysicsSystem::OnSetVelocity);
EVENT_SUBSCRIBE_MEMBER(m_ESetVelocity, &Systems::PhysicsSystem::OnSetVelocity);
hkMemorySystem::FrameInfo finfo(6000 * 1024); // Allocate 6MB of Physics solver buffer
hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo);
@@ -583,5 +583,8 @@ bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event)
bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event )
{
m_PhysicsWorld->markForWrite();
m_RigidBodies[event.Entity]->setLinearVelocity(ConvertPosition(event.Velocity));
m_PhysicsWorld->unmarkForWrite();
return true;
}
+16 -12
View File
@@ -38,7 +38,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
if(towerSteeringComponent)
{
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
glm::quat orientation = glm::angleAxis(towerSteeringComponent->Velocity * m_TowerInputController->TowerDirection * (float)dt, towerSteeringComponent->Axis);
glm::quat orientation = glm::angleAxis(towerSteeringComponent->TurnSpeed * m_TowerInputController->TowerDirection * (float)dt, towerSteeringComponent->Axis);
transformComponent->Orientation *= orientation;
}
@@ -46,21 +46,25 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
if(barrelSteeringComponent)
{
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
glm::quat orientation = glm::angleAxis(barrelSteeringComponent->Velocity * m_TowerInputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis);
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(entity);
glm::quat orientation = glm::angleAxis(barrelSteeringComponent->TurnSpeed * m_TowerInputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis);
transformComponent->Orientation *= orientation;
}
auto shotComponent = m_World->GetComponent<Components::Shot>(entity, "Shot");
if(shotComponent)
{
if(m_TowerInputController->shoot)
if(m_TowerInputController->Shoot && m_TimeSinceLastShot[entity] > 1.0)
{
auto absoluteOrientation = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteOrientation(entity);
EntityID clone = m_World->CloneEntity(barrelSteeringComponent->ShotTemplate);
auto templateAbsoluteTransform = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(barrelSteeringComponent->ShotTemplate);
auto cloneTransform = m_World->GetComponent<Components::Transform>(clone, "Transform");
cloneTransform->Position = templateAbsoluteTransform.Position;
cloneTransform->Orientation = absoluteTransform.Orientation * cloneTransform->Orientation;
Events::SetVelocity e;
e.Entity = entity;
e.Velocity = absoluteOrientation * (glm::vec3(0.f, 0.f, 1.f) * shotComponent->Speed * (float)dt);
e.Entity = clone;
e.Velocity = absoluteTransform.Orientation * (glm::vec3(0.f, 0.f, -1.f) * barrelSteeringComponent->ShotSpeed);
EventBroker->Publish(e);
m_TimeSinceLastShot[entity] = 0;
}
m_TimeSinceLastShot[entity] += dt;
}
}
@@ -74,7 +78,7 @@ void Systems::TankSteeringSystem::TowerSteeringInputController::Update( double d
{
TowerDirection = m_TowerDirection;
BarrelDirection = m_BarrelDirection;
shoot = m_Shoot;
Shoot = m_Shoot;
}
bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const Events::InputCommand &event)
@@ -111,7 +115,7 @@ bool Systems::TankSteeringSystem::TowerSteeringInputController::OnCommand( const
else if (event.Command == "shoot")
{
shoot = (bool)val;
m_Shoot = val > 0;
}
return true;
}
+3 -2
View File
@@ -8,7 +8,6 @@
#include "Components/TowerSteering.h"
#include "Components/BarrelSteering.h"
#include "Components/Vehicle.h"
#include "Components/Shot.h"
#include "Systems/TransformSystem.h"
#include "InputController.h"
@@ -32,6 +31,8 @@ namespace Systems
std::unique_ptr<TankSteeringInputController> m_TankInputController;
class TowerSteeringInputController;
std::unique_ptr<TowerSteeringInputController> m_TowerInputController;
std::map<EntityID, double> m_TimeSinceLastShot;
};
class TankSteeringSystem::TankSteeringInputController : InputController
@@ -76,7 +77,7 @@ namespace Systems
float TowerDirection;
float BarrelDirection;
bool shoot;
bool Shoot;
void Update(double dt);
protected:
virtual bool OnCommand(const Events::InputCommand &event);