Merge remote-tracking branch 'origin/vehicle-helicopter' into havok

Conflicts:
	src/GameWorld.cpp
	vs11/Returngeance/Returngeance.vcxproj
This commit is contained in:
ViktorLjung
2014-05-18 21:09:08 +02:00
10 changed files with 208 additions and 13 deletions
+16
View File
@@ -0,0 +1,16 @@
#ifndef HelicopterSteering_h__
#define HelicopterSteering_h__
#include "Component.h"
namespace Components
{
struct HelicopterSteering : Component
{
HelicopterSteering* Clone() const override { return new HelicopterSteering(*this); }
};
}
#endif // HelicopterSteering_h__
+18
View File
@@ -0,0 +1,18 @@
#ifndef Events_ApplyForce_h__
#define Events_ApplyForce_h__
#include "Entity.h"
#include "EventBroker.h"
namespace Events
{
struct ApplyForce : Event
{
EntityID Entity;
double DeltaTime;
glm::vec3 Force;
};
}
#endif // Events_ApplyForce_h__
+1
View File
@@ -13,6 +13,7 @@
//#include "Systems/PlayerSystem.h"
#include "Systems/FreeSteeringSystem.h"
#include "Systems/TankSteeringSystem.h"
#include "Systems/HelicopterSteeringSystem.h"
#include "Systems/RenderSystem.h"
#include "Systems/SoundSystem.h"
#include "Systems/PhysicsSystem.h"
+7 -7
View File
@@ -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;
}
+67
View File
@@ -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)
{
}
+54
View File
@@ -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;
};
}
+13 -5
View File
@@ -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;
}
+3 -1
View File
@@ -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);
+4
View File
@@ -111,6 +111,7 @@
<ClCompile Include="..\..\src\Sound.cpp" />
<ClCompile Include="..\..\src\Systems\DebugSystem.cpp" />
<ClCompile Include="..\..\src\Systems\FreeSteeringSystem.cpp" />
<ClCompile Include="..\..\src\Systems\HelicopterSteeringSystem.cpp" />
<ClCompile Include="..\..\src\Systems\InputSystem.cpp" />
<ClCompile Include="..\..\src\Systems\ParticleSystem.cpp" />
<ClCompile Include="..\..\src\Systems\PhysicsSystem.cpp" />
@@ -132,6 +133,7 @@
<ClInclude Include="..\..\src\Components\ExtendedMeshShape.h" />
<ClInclude Include="..\..\src\Components\FreeSteering.h" />
<ClInclude Include="..\..\src\Components\Health.h" />
<ClInclude Include="..\..\src\Components\HelicopterSteering.h" />
<ClInclude Include="..\..\src\Components\HingeConstraint.h" />
<ClInclude Include="..\..\src\Components\Input.h" />
<ClInclude Include="..\..\src\Components\MeshShape.h" />
@@ -153,6 +155,7 @@
<ClInclude Include="..\..\src\CubemapTexture.h" />
<ClInclude Include="..\..\src\Engine.h" />
<ClInclude Include="..\..\src\Entity.h" />
<ClInclude Include="..\..\src\Events\ApplyForce.h" />
<ClInclude Include="..\..\src\Events\BindGamepadAxis.h" />
<ClInclude Include="..\..\src\Events\BindGamepadButton.h" />
<ClInclude Include="..\..\src\Events\BindKey.h" />
@@ -189,6 +192,7 @@
<ClInclude Include="..\..\src\System.h" />
<ClInclude Include="..\..\src\Systems\DebugSystem.h" />
<ClInclude Include="..\..\src\Systems\FreeSteeringSystem.h" />
<ClInclude Include="..\..\src\Systems\HelicopterSteeringSystem.h" />
<ClInclude Include="..\..\src\Systems\InputSystem.h" />
<ClInclude Include="..\..\src\Systems\ParticleSystem.h" />
<ClInclude Include="..\..\src\Systems\PhysicsSystem.h" />
@@ -63,6 +63,7 @@
<ClCompile Include="..\..\src\Systems\TankSteeringSystem.cpp">
<Filter>Physics\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\HelicopterSteeringSystem.cpp" />
</ItemGroup>
<ItemGroup>
<Filter Include="Util">
@@ -137,6 +138,21 @@
<Filter Include="Physics\Events">
<UniqueIdentifier>{42ae084f-ade8-402c-87ba-f03f6b846bc8}</UniqueIdentifier>
</Filter>
<Filter Include="Gameplay">
<UniqueIdentifier>{5b992473-73e6-485e-8f13-17e0801fb2ca}</UniqueIdentifier>
</Filter>
<Filter Include="Gameplay\Vehicles">
<UniqueIdentifier>{8a78be3a-a3c5-4054-a2f1-1456f3fcbab0}</UniqueIdentifier>
</Filter>
<Filter Include="Gameplay\Vehicles\Helicopter">
<UniqueIdentifier>{8ccc0abe-5bdd-4656-ab11-5708a39c71ae}</UniqueIdentifier>
</Filter>
<Filter Include="Gameplay\Vehicles\Helicopter\Components">
<UniqueIdentifier>{b2416d05-a49e-4fef-a5c4-cd03d8cc2efd}</UniqueIdentifier>
</Filter>
<Filter Include="Gameplay\Vehicles\Helicopter\Systems">
<UniqueIdentifier>{b34c0c95-a887-4cf4-af24-cf7c1f459aa8}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\World.h" />
@@ -358,6 +374,15 @@
<ClInclude Include="..\..\src\Events\LockMouse.h">
<Filter>Input\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\HelicopterSteering.h">
<Filter>Gameplay\Vehicles\Helicopter\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Systems\HelicopterSteeringSystem.h">
<Filter>Gameplay\Vehicles\Helicopter\Systems</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\ApplyForce.h">
<Filter>Physics\Events</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\src\Shaders\Fragment2.glsl">