Merge remote-tracking branch 'origin/vehicle-helicopter' into havok
Conflicts: src/GameWorld.cpp vs11/Returngeance/Returngeance.vcxproj
This commit is contained in:
@@ -60,27 +60,27 @@ void Systems::FreeSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
||||
bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnCommand(const Events::InputCommand &event)
|
||||
{
|
||||
// Movement
|
||||
if (event.Command == "vertical")
|
||||
if (event.Command == "cam_vertical")
|
||||
{
|
||||
Movement.z = -event.Value;
|
||||
}
|
||||
else if (event.Command == "horizontal")
|
||||
else if (event.Command == "cam_horizontal")
|
||||
{
|
||||
Movement.x = event.Value;
|
||||
}
|
||||
else if (event.Command == "normal")
|
||||
else if (event.Command == "cam_normal")
|
||||
{
|
||||
Movement.y = event.Value;
|
||||
}
|
||||
|
||||
// Speed
|
||||
else if (event.Command == "speed")
|
||||
else if (event.Command == "cam_speed")
|
||||
{
|
||||
SpeedMultiplier = event.Value;
|
||||
}
|
||||
|
||||
// Mouse click
|
||||
else if (event.Command == "attack")
|
||||
else if (event.Command == "cam_attack")
|
||||
{
|
||||
OrientationActive = event.Value > 0;
|
||||
|
||||
@@ -96,11 +96,11 @@ bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnCommand(const E
|
||||
}
|
||||
}
|
||||
|
||||
else if (event.Command == "vertical2")
|
||||
else if (event.Command == "cam_vertical2")
|
||||
{
|
||||
ControllerOrientation.x = event.Value;
|
||||
}
|
||||
else if (event.Command == "horizontal2")
|
||||
else if (event.Command == "cam_horizontal2")
|
||||
{
|
||||
ControllerOrientation.y = -event.Value;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "HelicopterSteeringSystem.h"
|
||||
#include "World.h"
|
||||
|
||||
void Systems::HelicopterSteeringSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
cf->Register("HelicopterSteering", []() { return new Components::HelicopterSteering(); });
|
||||
}
|
||||
|
||||
void Systems::HelicopterSteeringSystem::Initialize()
|
||||
{
|
||||
m_InputController = std::unique_ptr<HelicopterSteeringInputController>(new HelicopterSteeringInputController(EventBroker));
|
||||
}
|
||||
|
||||
void Systems::HelicopterSteeringSystem::Update(double dt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Systems::HelicopterSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
if (!transform)
|
||||
return;
|
||||
|
||||
auto helicopterComponent = m_World->GetComponent<Components::HelicopterSteering>(entity, "HelicopterSteering");
|
||||
if (helicopterComponent)
|
||||
{
|
||||
glm::vec3 controllerRotationEuler = m_InputController->Rotation * (float)dt;
|
||||
transform->Orientation *= glm::quat(controllerRotationEuler);
|
||||
|
||||
Events::ApplyForce e;
|
||||
e.Entity = entity;
|
||||
e.DeltaTime = dt;
|
||||
e.Force = glm::normalize(transform->Orientation * glm::vec3(0, 1, 0)) * (m_InputController->Power * 3000.f * 9.82f * 8.f);
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
}
|
||||
|
||||
bool Systems::HelicopterSteeringSystem::HelicopterSteeringInputController::OnCommand(const Events::InputCommand &event)
|
||||
{
|
||||
if (event.Command == "horizontal")
|
||||
{
|
||||
Rotation.z = -event.Value;
|
||||
}
|
||||
else if (event.Command == "vertical")
|
||||
{
|
||||
Rotation.x = -event.Value;
|
||||
}
|
||||
|
||||
else if (event.Command == "normal")
|
||||
{
|
||||
Power = event.Value;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::HelicopterSteeringSystem::HelicopterSteeringInputController::OnMouseMove(const Events::MouseMove &event)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void Systems::HelicopterSteeringSystem::HelicopterSteeringInputController::Update(double dt)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
#include "System.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/HelicopterSteering.h"
|
||||
#include "Events/SetVelocity.h"
|
||||
#include "Events/ApplyForce.h"
|
||||
#include "InputController.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
class HelicopterSteeringSystem : public System
|
||||
{
|
||||
public:
|
||||
HelicopterSteeringSystem(World* world, std::shared_ptr<::EventBroker> eventBroker)
|
||||
: System(world, eventBroker) { }
|
||||
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
void Initialize() override;
|
||||
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
|
||||
private:
|
||||
class HelicopterSteeringInputController;
|
||||
std::unique_ptr<HelicopterSteeringInputController> m_InputController;
|
||||
|
||||
std::map<EntityID, double> m_TimeSinceLastShot;
|
||||
};
|
||||
|
||||
class HelicopterSteeringSystem::HelicopterSteeringInputController : InputController
|
||||
{
|
||||
public:
|
||||
HelicopterSteeringInputController(std::shared_ptr<::EventBroker> eventBroker)
|
||||
: InputController(eventBroker)
|
||||
, Power(0.f)
|
||||
{ }
|
||||
|
||||
float Power;
|
||||
glm::vec3 Rotation;
|
||||
|
||||
void Update(double dt);
|
||||
|
||||
protected:
|
||||
bool OnCommand(const Events::InputCommand &event) override;
|
||||
bool OnMouseMove(const Events::MouseMove &event) override;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -34,6 +34,7 @@ void Systems::PhysicsSystem::Initialize()
|
||||
// Events
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ETankSteer, &Systems::PhysicsSystem::OnTankSteer);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESetVelocity, &Systems::PhysicsSystem::OnSetVelocity);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EApplyForce, &Systems::PhysicsSystem::OnApplyForce);
|
||||
|
||||
hkMemorySystem::FrameInfo finfo(6000 * 1024); // Allocate 6MB of Physics solver buffer
|
||||
hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo);
|
||||
@@ -164,7 +165,7 @@ void Systems::PhysicsSystem::Update(double dt)
|
||||
m_Accumulator += dt;
|
||||
while (m_Accumulator >= timestep)
|
||||
{
|
||||
m_PhysicsWorld->stepMultithreaded(m_JobQueue, m_ThreadPool, timestep);
|
||||
hkpStepResult stepresult = m_PhysicsWorld->stepMultithreaded(m_JobQueue, m_ThreadPool, timestep);
|
||||
//m_PhysicsWorld->stepDeltaTime(timestep);
|
||||
|
||||
m_Accumulator -= timestep;
|
||||
@@ -176,10 +177,7 @@ void Systems::PhysicsSystem::Update(double dt)
|
||||
// Clear accumulated timer data in this thread and all slave threads
|
||||
hkMonitorStream::getInstance().reset();
|
||||
m_ThreadPool->clearTimerData();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
@@ -595,5 +593,15 @@ bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event )
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_RigidBodies[event.Entity]->setLinearVelocity(ConvertPosition(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, ConvertPosition(event.Force));
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "Components/TowerSteering.h"
|
||||
#include "Events/TankSteer.h"
|
||||
#include "Events/SetVelocity.h"
|
||||
#include "Events/ApplyForce.h"
|
||||
#include "OBJ.h"
|
||||
|
||||
// Math and base include
|
||||
@@ -103,9 +104,10 @@ private:
|
||||
// Events
|
||||
EventRelay<Events::TankSteer> m_ETankSteer;
|
||||
bool OnTankSteer(const Events::TankSteer &event);
|
||||
|
||||
EventRelay<Events::SetVelocity> m_ESetVelocity;
|
||||
bool OnSetVelocity(const Events::SetVelocity &event);
|
||||
EventRelay<Events::ApplyForce> m_EApplyForce;
|
||||
bool OnApplyForce(const Events::ApplyForce &event);
|
||||
|
||||
void SetUpPhysicsState(EntityID entity, EntityID parent);
|
||||
void TearDownPhysicsState(EntityID entity, EntityID parent);
|
||||
|
||||
Reference in New Issue
Block a user