Merge branch 'master' into havok
Conflicts: assets src/GameWorld.cpp vs11/Returngeance/Returngeance.vcxproj.filters
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
void Systems::FreeSteeringSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
cf->Register("FreeSteering", []() { return new Components::FreeSteering(); });
|
||||
cf->Register<Components::FreeSteering>([]() { return new Components::FreeSteering(); });
|
||||
}
|
||||
|
||||
void Systems::FreeSteeringSystem::Initialize()
|
||||
@@ -19,100 +19,90 @@ void Systems::FreeSteeringSystem::Update(double dt)
|
||||
|
||||
void Systems::FreeSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto steering = m_World->GetComponent<Components::FreeSteering>(entity, "FreeSteering");
|
||||
auto steering = m_World->GetComponent<Components::FreeSteering>(entity);
|
||||
if (steering)
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
|
||||
glm::vec3 cameraRight = glm::vec3(m_InputController->Orientation * glm::vec4(1, 0, 0, 0));
|
||||
glm::vec3 cameraForward = glm::vec3(m_InputController->Orientation * glm::vec4(0, 0, -1, 0));
|
||||
glm::vec3 cameraRight = glm::vec3(transform->Orientation * glm::vec4(1, 0, 0, 0));
|
||||
glm::vec3 cameraForward = glm::vec3(transform->Orientation * glm::vec4(0, 0, -1, 0));
|
||||
glm::vec3 movement;
|
||||
movement += cameraRight * m_InputController->Movement.x;
|
||||
movement.y += m_InputController->Movement.y;
|
||||
movement += cameraForward * -m_InputController->Movement.z;
|
||||
transform->Position += movement * steering->Speed * m_InputController->SpeedMultiplier * (float)dt;
|
||||
transform->Orientation = m_InputController->Orientation;
|
||||
float speedMultiplier = 1.f;
|
||||
if (m_InputController->SpeedMultiplier > 0)
|
||||
speedMultiplier *= 4;
|
||||
else if (m_InputController->SpeedMultiplier < 0)
|
||||
speedMultiplier /= 4;
|
||||
|
||||
transform->Position += movement * steering->Speed * speedMultiplier * (float)dt;
|
||||
|
||||
glm::quat mouseOrientationPitch = glm::quat(m_InputController->MouseOrientation * glm::vec3(1, 0, 0));
|
||||
glm::quat mouseOrientationYaw = glm::quat(m_InputController->MouseOrientation * glm::vec3(0, 1, 0));
|
||||
|
||||
glm::vec3 controllerOrientationEuler = m_InputController->ControllerOrientation * (float)dt;
|
||||
glm::quat controllerOrientationPitch = glm::quat(controllerOrientationEuler * glm::vec3(1, 0, 0));
|
||||
glm::quat controllerOrientationYaw = glm::quat(controllerOrientationEuler * glm::vec3(0, 1, 0));
|
||||
|
||||
// TOUCHING THIS CODE MIGHT CAUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
|
||||
//---------------------------------------------------------------------
|
||||
transform->Orientation = (mouseOrientationYaw * controllerOrientationYaw)
|
||||
* transform->Orientation
|
||||
* (mouseOrientationPitch * controllerOrientationPitch);
|
||||
//---------------------------------------------------------------------
|
||||
// TOUCHING THIS CODE MIGHT CAUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
|
||||
}
|
||||
|
||||
m_InputController->MouseOrientation = glm::vec3(0);
|
||||
}
|
||||
|
||||
bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnCommand(const Events::InputCommand &event)
|
||||
{
|
||||
// Movement
|
||||
if (event.Command == "+cam_forward")
|
||||
if (event.Command == "vertical")
|
||||
{
|
||||
Movement.z += -1.f;
|
||||
Movement.z = -event.Value;
|
||||
}
|
||||
else if (event.Command == "-cam_forward")
|
||||
else if (event.Command == "horizontal")
|
||||
{
|
||||
Movement.z -= -1.f;
|
||||
Movement.x = event.Value;
|
||||
}
|
||||
else if (event.Command == "+cam_backward")
|
||||
else if (event.Command == "normal")
|
||||
{
|
||||
Movement.z += 1.f;
|
||||
}
|
||||
else if (event.Command == "-cam_backward")
|
||||
{
|
||||
Movement.z -= 1.f;
|
||||
}
|
||||
else if (event.Command == "+cam_right")
|
||||
{
|
||||
Movement.x -= 1.f;
|
||||
}
|
||||
else if (event.Command == "-cam_right")
|
||||
{
|
||||
Movement.x += 1.f;
|
||||
}
|
||||
else if (event.Command == "+cam_left")
|
||||
{
|
||||
Movement.x -= -1.f;
|
||||
}
|
||||
else if (event.Command == "-cam_left")
|
||||
{
|
||||
Movement.x += -1.f;
|
||||
}
|
||||
else if (event.Command == "+up")
|
||||
{
|
||||
Movement.y += 1.f;
|
||||
}
|
||||
else if (event.Command == "-up")
|
||||
{
|
||||
Movement.y -= 1.f;
|
||||
}
|
||||
else if (event.Command == "+down")
|
||||
{
|
||||
Movement.y += -1.f;
|
||||
}
|
||||
else if (event.Command == "-down")
|
||||
{
|
||||
Movement.y -= -1.f;
|
||||
Movement.y = event.Value;
|
||||
}
|
||||
|
||||
// Speed
|
||||
else if (event.Command == "+fast")
|
||||
else if (event.Command == "speed")
|
||||
{
|
||||
SpeedMultiplier *= 4.f;
|
||||
}
|
||||
else if (event.Command == "-fast")
|
||||
{
|
||||
SpeedMultiplier /= 4.f;
|
||||
}
|
||||
else if (event.Command == "+slow")
|
||||
{
|
||||
SpeedMultiplier /= 4.f;
|
||||
}
|
||||
else if (event.Command == "-slow")
|
||||
{
|
||||
SpeedMultiplier *= 4.f;
|
||||
SpeedMultiplier = event.Value;
|
||||
}
|
||||
|
||||
// Mouse click
|
||||
else if (event.Command == "+attack")
|
||||
else if (event.Command == "attack")
|
||||
{
|
||||
OrientationActive = true;
|
||||
OrientationActive = event.Value > 0;
|
||||
|
||||
if (OrientationActive)
|
||||
{
|
||||
Events::LockMouse e;
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
else
|
||||
{
|
||||
Events::UnlockMouse e;
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
}
|
||||
else if (event.Command == "-attack")
|
||||
|
||||
else if (event.Command == "vertical2")
|
||||
{
|
||||
OrientationActive = false;
|
||||
ControllerOrientation.x = event.Value;
|
||||
}
|
||||
else if (event.Command == "horizontal2")
|
||||
{
|
||||
ControllerOrientation.y = -event.Value;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -122,11 +112,7 @@ bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnMouseMove(const
|
||||
{
|
||||
if (OrientationActive)
|
||||
{
|
||||
// TOUCHING THIS CODE MIGHT CAUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
|
||||
//---------------------------------------------------------------------
|
||||
Orientation = glm::angleAxis<float>(event.DeltaX / 300.f, glm::vec3(0, -1, 0)) * Orientation * glm::angleAxis<float>(event.DeltaY / 300.f, glm::vec3(-1, 0, 0));
|
||||
//---------------------------------------------------------------------
|
||||
// TOUCHING THIS CODE MIGHT CAUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
|
||||
MouseOrientation = -glm::vec3(event.DeltaY / 300.f, event.DeltaX / 300.f, 0.f);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/FreeSteering.h"
|
||||
#include "InputController.h"
|
||||
#include "Events/LockMouse.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
@@ -31,11 +32,12 @@ class FreeSteeringSystem::FreeSteeringInputController : InputController
|
||||
public:
|
||||
FreeSteeringInputController(std::shared_ptr<::EventBroker> eventBroker)
|
||||
: InputController(eventBroker)
|
||||
, SpeedMultiplier(1.f)
|
||||
, SpeedMultiplier(0.f)
|
||||
, OrientationActive(false) { }
|
||||
|
||||
glm::vec3 Movement;
|
||||
glm::quat Orientation;
|
||||
glm::vec3 MouseOrientation;
|
||||
glm::vec3 ControllerOrientation;
|
||||
float SpeedMultiplier;
|
||||
bool OrientationActive;
|
||||
|
||||
|
||||
+65
-15
@@ -4,7 +4,7 @@
|
||||
|
||||
void Systems::InputSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
cf->Register("Input", []() { return new Components::Input(); });
|
||||
cf->Register<Components::Input>([]() { return new Components::Input(); });
|
||||
}
|
||||
|
||||
void Systems::InputSystem::Initialize()
|
||||
@@ -52,8 +52,8 @@ bool Systems::InputSystem::OnKeyDown(const Events::KeyDown &event)
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_CommandValues[command] += value;
|
||||
PublishCommand(0, command, std::max(-1.f, std::min(m_CommandValues[command], 1.f)));
|
||||
m_CommandKeyboardValues[command][event.KeyCode] = value;
|
||||
PublishCommand(0, command, GetCommandTotalValue(command));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -67,8 +67,8 @@ bool Systems::InputSystem::OnKeyUp(const Events::KeyUp &event)
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_CommandValues[command] -= value;
|
||||
PublishCommand(0, command, std::max(-1.f, std::min(m_CommandValues[command], 1.f)));
|
||||
m_CommandKeyboardValues[command][event.KeyCode] = 0;
|
||||
PublishCommand(0, command, GetCommandTotalValue(command));;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -79,7 +79,11 @@ bool Systems::InputSystem::OnMousePress(const Events::MousePress &event)
|
||||
auto bindingIt = m_MouseButtonBindings.find(event.Button);
|
||||
if (bindingIt != m_MouseButtonBindings.end())
|
||||
{
|
||||
PublishCommand(0, bindingIt->second, 1.f);
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_CommandMouseButtonValues[command][event.Button] = value;
|
||||
PublishCommand(0, command, GetCommandTotalValue(command));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -90,7 +94,11 @@ bool Systems::InputSystem::OnMouseRelease(const Events::MouseRelease &event)
|
||||
auto bindingIt = m_MouseButtonBindings.find(event.Button);
|
||||
if (bindingIt != m_MouseButtonBindings.end())
|
||||
{
|
||||
PublishCommand(0, bindingIt->second, 1.f);
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_CommandMouseButtonValues[command][event.Button] = 0;
|
||||
PublishCommand(0, command, GetCommandTotalValue(command));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -104,7 +112,8 @@ bool Systems::InputSystem::OnGamepadAxis(const Events::GamepadAxis &event)
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
PublishCommand(event.GamepadID + 1, command, event.Value * value);
|
||||
m_CommandGamepadAxisValues[command][event.Axis] = event.Value * value;
|
||||
PublishCommand(event.GamepadID + 1, command, GetCommandTotalValue(command));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -118,8 +127,8 @@ bool Systems::InputSystem::OnGamepadButtonDown(const Events::GamepadButtonDown &
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_CommandValues[command] += value;
|
||||
PublishCommand(event.GamepadID + 1, command, std::max(-1.f, std::min(m_CommandValues[command], 1.f)));
|
||||
m_CommandGamepadButtonValues[command][event.Button] = value;
|
||||
PublishCommand(event.GamepadID + 1, command, GetCommandTotalValue(command));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -133,8 +142,8 @@ bool Systems::InputSystem::OnGamepadButtonUp(const Events::GamepadButtonUp &even
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_CommandValues[command] -= value;
|
||||
PublishCommand(event.GamepadID + 1, command, std::max(-1.f, std::min(m_CommandValues[command], 1.f)));
|
||||
m_CommandGamepadButtonValues[command][event.Button] = 0;
|
||||
PublishCommand(event.GamepadID + 1, command, GetCommandTotalValue(command));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -164,7 +173,7 @@ bool Systems::InputSystem::OnBindMouseButton(const Events::BindMouseButton &even
|
||||
}
|
||||
else
|
||||
{
|
||||
m_MouseButtonBindings[event.Button] = event.Command;
|
||||
m_MouseButtonBindings[event.Button] = std::make_tuple(event.Command, event.Value);
|
||||
LOG_DEBUG("Input: Bound mouse button %i to %s", event.Button, event.Command.c_str());
|
||||
}
|
||||
|
||||
@@ -201,6 +210,49 @@ bool Systems::InputSystem::OnBindGamepadButton(const Events::BindGamepadButton &
|
||||
return true;
|
||||
}
|
||||
|
||||
float Systems::InputSystem::GetCommandTotalValue(std::string command)
|
||||
{
|
||||
float value = 0.f;
|
||||
|
||||
auto keyboardIt = m_CommandKeyboardValues.find(command);
|
||||
if (keyboardIt != m_CommandKeyboardValues.end())
|
||||
{
|
||||
for (auto &key : keyboardIt->second)
|
||||
{
|
||||
value += key.second;
|
||||
}
|
||||
}
|
||||
|
||||
auto mouseButtonIt = m_CommandMouseButtonValues.find(command);
|
||||
if (mouseButtonIt != m_CommandMouseButtonValues.end())
|
||||
{
|
||||
for (auto &button : mouseButtonIt->second)
|
||||
{
|
||||
value += button.second;
|
||||
}
|
||||
}
|
||||
|
||||
auto gamepadAxisIt = m_CommandGamepadAxisValues.find(command);
|
||||
if (gamepadAxisIt != m_CommandGamepadAxisValues.end())
|
||||
{
|
||||
for (auto &axis : gamepadAxisIt->second)
|
||||
{
|
||||
value += axis.second;
|
||||
}
|
||||
}
|
||||
|
||||
auto gamepadButtonIt = m_CommandGamepadButtonValues.find(command);
|
||||
if (gamepadButtonIt != m_CommandGamepadButtonValues.end())
|
||||
{
|
||||
for (auto &button : gamepadButtonIt->second)
|
||||
{
|
||||
value += button.second;
|
||||
}
|
||||
}
|
||||
|
||||
return std::max(-1.f, std::min(value, 1.f));
|
||||
}
|
||||
|
||||
void Systems::InputSystem::PublishCommand(int playerID, std::string command, float value)
|
||||
{
|
||||
Events::InputCommand e;
|
||||
@@ -211,5 +263,3 @@ void Systems::InputSystem::PublishCommand(int playerID, std::string command, flo
|
||||
|
||||
LOG_DEBUG("Input: Published command %s=%f for player %i", e.Command.c_str(), e.Value, playerID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -34,10 +34,13 @@ public:
|
||||
void Update(double dt) override;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, float> m_CommandValues; // command string -> command current value
|
||||
std::unordered_map<std::string, std::unordered_map<int, float>> m_CommandKeyboardValues; // command string -> keyboard key value for command
|
||||
std::unordered_map<std::string, std::unordered_map<int, float>> m_CommandMouseButtonValues; // command string -> mouse button value for command
|
||||
std::unordered_map<std::string, std::unordered_map<Gamepad::Axis, float>> m_CommandGamepadAxisValues; // command string -> gamepad axis value for command
|
||||
std::unordered_map<std::string, std::unordered_map<Gamepad::Button, float>> m_CommandGamepadButtonValues; // command string -> gamepad button value for command
|
||||
// Input binding tables
|
||||
std::unordered_map<int, std::tuple<std::string, float>> m_KeyBindings; // GLFW_KEY... -> command string & value
|
||||
std::unordered_map<int, std::string> m_MouseButtonBindings; // GLFW_MOUSE_BUTTON... -> command string
|
||||
std::unordered_map<int, std::tuple<std::string, float>> m_MouseButtonBindings; // GLFW_MOUSE_BUTTON... -> command string
|
||||
std::unordered_map<Gamepad::Axis, std::tuple<std::string, float>> m_GamepadAxisBindings; // Gamepad::Axis -> command string & value
|
||||
std::unordered_map<Gamepad::Button, std::tuple<std::string, float>> m_GamepadButtonBindings; // Gamepad::Button -> command string
|
||||
|
||||
@@ -66,6 +69,7 @@ private:
|
||||
EventRelay<Events::BindGamepadButton> m_EBindGamepadButton;
|
||||
bool OnBindGamepadButton(const Events::BindGamepadButton &event);
|
||||
|
||||
float GetCommandTotalValue(std::string command);
|
||||
void PublishCommand(int playerID, std::string command, float value);
|
||||
};
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
void Systems::ParticleSystem::Initialize()
|
||||
{
|
||||
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>("TransformSystem");
|
||||
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
|
||||
}
|
||||
|
||||
void Systems::ParticleSystem::Update(double dt)
|
||||
@@ -16,15 +16,15 @@ void Systems::ParticleSystem::Update(double dt)
|
||||
|
||||
void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
if(!transformComponent)
|
||||
return;
|
||||
|
||||
auto emitterComponent = m_World->GetComponent<Components::ParticleEmitter>(entity, "ParticleEmitter");
|
||||
auto emitterComponent = m_World->GetComponent<Components::ParticleEmitter>(entity);
|
||||
if(emitterComponent)
|
||||
{
|
||||
emitterComponent->TimeSinceLastSpawn += dt;
|
||||
auto emitterTransformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto emitterTransformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
if(emitterComponent->TimeSinceLastSpawn > emitterComponent->SpawnFrequency)
|
||||
{
|
||||
SpawnParticles(entity);
|
||||
@@ -35,8 +35,8 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
||||
for(it = m_ParticleEmitter[entity].begin(); it != m_ParticleEmitter[entity].end();)
|
||||
{
|
||||
EntityID particleID = (it)->ParticleID;
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(particleID, "Transform");
|
||||
auto particleComponent = m_World->GetComponent<Components::Particle>(particleID, "Particle");
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(particleID);
|
||||
auto particleComponent = m_World->GetComponent<Components::Particle>(particleID);
|
||||
|
||||
double timeLived = glfwGetTime() - it->SpawnTime;
|
||||
if(timeLived > particleComponent->LifeTime)
|
||||
@@ -94,15 +94,15 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
||||
|
||||
void Systems::ParticleSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
cf->Register("ParticleEmitter", []() { return new Components::ParticleEmitter(); });
|
||||
cf->Register("Particle", []() { return new Components::Particle(); });
|
||||
cf->Register<Components::ParticleEmitter>([]() { return new Components::ParticleEmitter(); });
|
||||
cf->Register<Components::Particle>([]() { return new Components::Particle(); });
|
||||
}
|
||||
|
||||
|
||||
void Systems::ParticleSystem::SpawnParticles(EntityID emitterID)
|
||||
{
|
||||
auto emitterComponent = m_World->GetComponent<Components::ParticleEmitter>(emitterID, "ParticleEmitter");
|
||||
auto emitterTransform = m_World->GetComponent<Components::Transform>(emitterID, "Transform");
|
||||
auto emitterComponent = m_World->GetComponent<Components::ParticleEmitter>(emitterID);
|
||||
auto emitterTransform = m_World->GetComponent<Components::Transform>(emitterID);
|
||||
glm::vec3 emitterPos = m_TransformSystem->AbsolutePosition(emitterID);
|
||||
glm::quat emitterOrientation = emitterTransform->Orientation;
|
||||
|
||||
@@ -113,7 +113,7 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID)
|
||||
{
|
||||
auto ent = m_World->CloneEntity(emitterComponent->ParticleTemplate);
|
||||
|
||||
auto particleTransform = m_World->GetComponent<Components::Transform>(ent, "Transform");
|
||||
auto particleTransform = m_World->GetComponent<Components::Transform>(ent);
|
||||
particleTransform->Position = emitterPos;
|
||||
|
||||
particleTransform->Orientation = emitterOrientation;
|
||||
@@ -124,7 +124,7 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID)
|
||||
glm::normalize(glm::angleAxis(RandomizeAngle(spreadAngle), glm::vec3(0, 1, 0))) *
|
||||
glm::normalize(glm::angleAxis(RandomizeAngle(spreadAngle), glm::vec3(0, 0, 1)));
|
||||
|
||||
auto particle = m_World->AddComponent<Components::Particle>(ent, "Particle");
|
||||
auto particle = m_World->AddComponent<Components::Particle>(ent);
|
||||
particle->LifeTime = emitterComponent->LifeTime;
|
||||
particle->ScaleSpectrum = emitterComponent->ScaleSpectrum;
|
||||
particle->VelocitySpectrum.push_back(particleTransform->Velocity);
|
||||
|
||||
@@ -112,14 +112,14 @@ void Systems::PhysicsSystem::Initialize()
|
||||
|
||||
void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
cf->Register("Physics", []() { return new Components::Physics(); });
|
||||
cf->Register("BoxShape", []() { return new Components::BoxShape(); });
|
||||
cf->Register("SphereShape", []() { return new Components::SphereShape(); });
|
||||
cf->Register("Vehicle", []() { return new Components::Vehicle(); });
|
||||
cf->Register("Wheel", []() { return new Components::Wheel(); });
|
||||
cf->Register("MeshShape", []() { return new Components::MeshShape(); });
|
||||
cf->Register("HingeConstraint", []() { return new Components::HingeConstraint(); });
|
||||
cf->Register("WheelPair", []() { return new Components::WheelPair(); });
|
||||
cf->Register<Components::Physics>([]() { return new Components::Physics(); });
|
||||
cf->Register<Components::BoxShape>([]() { return new Components::BoxShape(); });
|
||||
cf->Register<Components::SphereShape>([]() { return new Components::SphereShape(); });
|
||||
cf->Register<Components::Vehicle>([]() { return new Components::Vehicle(); });
|
||||
cf->Register<Components::Wheel>([]() { return new Components::Wheel(); });
|
||||
cf->Register<Components::MeshShape>([]() { return new Components::MeshShape(); });
|
||||
cf->Register<Components::HingeConstraint>([]() { return new Components::HingeConstraint(); });
|
||||
cf->Register<Components::WheelPair>([]() { return new Components::WheelPair(); });
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::Update(double dt)
|
||||
@@ -132,7 +132,7 @@ void Systems::PhysicsSystem::Update(double dt)
|
||||
if (m_RigidBodies.find(entity) == m_RigidBodies.end())
|
||||
continue;
|
||||
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (!transformComponent)
|
||||
continue;
|
||||
|
||||
@@ -143,7 +143,7 @@ void Systems::PhysicsSystem::Update(double dt)
|
||||
|
||||
if (parent)
|
||||
{
|
||||
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(entity);
|
||||
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
|
||||
position = ConvertPosition(absoluteTransform.Position);
|
||||
rotation = ConvertRotation(absoluteTransform.Orientation);
|
||||
}
|
||||
@@ -184,11 +184,11 @@ void Systems::PhysicsSystem::Update(double dt)
|
||||
|
||||
void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (!transformComponent)
|
||||
return;
|
||||
|
||||
auto wheelComponent = m_World->GetComponent<Components::Wheel>(entity, "Wheel");
|
||||
auto wheelComponent = m_World->GetComponent<Components::Wheel>(entity);
|
||||
if (wheelComponent)
|
||||
{
|
||||
EntityID car = m_World->GetEntityParent(entity);
|
||||
@@ -212,7 +212,7 @@ 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, "Transform");
|
||||
auto transformComponentParent = m_World->GetComponent<Components::Transform>(parent);
|
||||
|
||||
transformComponent->Position = ConvertPosition(m_RigidBodies[entity]->getPosition());
|
||||
transformComponent->Orientation = ConvertRotation(m_RigidBodies[entity]->getRotation());
|
||||
@@ -231,11 +231,11 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
|
||||
|
||||
void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (!transformComponent)
|
||||
return;
|
||||
|
||||
auto wheelComponent = m_World->GetComponent<Components::Wheel>(entity, "Wheel");
|
||||
auto wheelComponent = m_World->GetComponent<Components::Wheel>(entity);
|
||||
if (wheelComponent)
|
||||
{
|
||||
wheelComponent->ID = m_Wheels.size();
|
||||
@@ -245,9 +245,9 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
|
||||
EntityID entityParent = m_World->GetEntityBaseParent(entity);
|
||||
|
||||
auto sphereComponent = m_World->GetComponent<Components::SphereShape>(entity, "SphereShape");
|
||||
auto boxComponent = m_World->GetComponent<Components::BoxShape>(entity, "BoxShape");
|
||||
auto meshShapeComponent = m_World->GetComponent<Components::MeshShape >(entity, "MeshShape");
|
||||
auto sphereComponent = m_World->GetComponent<Components::SphereShape>(entity);
|
||||
auto boxComponent = m_World->GetComponent<Components::BoxShape>(entity);
|
||||
auto meshShapeComponent = m_World->GetComponent<Components::MeshShape >(entity);
|
||||
|
||||
if(entityParent == entity && (sphereComponent || boxComponent || meshShapeComponent))
|
||||
{
|
||||
@@ -255,7 +255,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
return;
|
||||
}
|
||||
|
||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity, "Physics");
|
||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
|
||||
if (physicsComponent)
|
||||
{
|
||||
hkpShape* shape;
|
||||
@@ -296,7 +296,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
{
|
||||
rigidBodyInfo.m_shape = shape;
|
||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_DYNAMIC;
|
||||
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(entity);
|
||||
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
|
||||
hkVector4 position = ConvertPosition(absoluteTransform.Position);
|
||||
hkQuaternion rotation = ConvertRotation(absoluteTransform.Orientation);
|
||||
rigidBodyInfo.m_position.set(position(0), position(1), position(2), position(3));
|
||||
@@ -309,7 +309,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
// Create RigidBody
|
||||
hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo);
|
||||
|
||||
auto vehicleComponent = m_World->GetComponent<Components::Vehicle >(entity, "Vehicle");
|
||||
auto vehicleComponent = m_World->GetComponent<Components::Vehicle >(entity);
|
||||
if (vehicleComponent && m_Vehicles.find(entity) == m_Vehicles.end())
|
||||
{
|
||||
for (int i = 0; i < m_Wheels.size(); i++)
|
||||
@@ -365,7 +365,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
for (auto &shapeData : m_Shapes[entity])
|
||||
{
|
||||
|
||||
auto childTransformComponent = m_World->GetComponent<Components::Transform>(shapeData.Entity, "Transform");
|
||||
auto childTransformComponent = m_World->GetComponent<Components::Transform>(shapeData.Entity);
|
||||
|
||||
hkVector4 position = ConvertPosition(childTransformComponent->Position);
|
||||
hkQuaternion rotation = ConvertRotation(childTransformComponent->Orientation);
|
||||
@@ -386,7 +386,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
{
|
||||
rigidBodyInfo.m_shape = shape;
|
||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
|
||||
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(entity);
|
||||
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
|
||||
hkVector4 position = ConvertPosition(absoluteTransform.Position);
|
||||
hkQuaternion rotation = ConvertRotation(absoluteTransform.Orientation);
|
||||
rigidBodyInfo.m_position.set(position(0), position(1), position(2), position(3));
|
||||
@@ -576,7 +576,7 @@ const hkVector4& Systems::PhysicsSystem::ConvertScale(glm::vec3 glmScale)
|
||||
|
||||
bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event)
|
||||
{
|
||||
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(event.Entity, "Vehicle");
|
||||
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())
|
||||
{
|
||||
m_PhysicsWorld->markForWrite();
|
||||
|
||||
@@ -12,12 +12,12 @@ void Systems::RenderSystem::OnComponentCreated(std::string type, std::shared_ptr
|
||||
|
||||
void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (transformComponent == nullptr)
|
||||
return;
|
||||
|
||||
// Draw models
|
||||
auto modelComponent = m_World->GetComponent<Components::Model>(entity, "Model");
|
||||
auto modelComponent = m_World->GetComponent<Components::Model>(entity);
|
||||
if (modelComponent != nullptr)
|
||||
{
|
||||
auto model = m_World->GetResourceManager()->Load<Model>("Model", modelComponent->ModelFile);
|
||||
@@ -31,7 +31,7 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
||||
}
|
||||
}
|
||||
|
||||
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity, "PointLight");
|
||||
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity);
|
||||
if (pointLightComponent != nullptr)
|
||||
{
|
||||
glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
|
||||
@@ -39,13 +39,14 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
||||
position,
|
||||
pointLightComponent->Specular,
|
||||
pointLightComponent->Diffuse,
|
||||
pointLightComponent->constantAttenuation,
|
||||
pointLightComponent->linearAttenuation,
|
||||
pointLightComponent->quadraticAttenuation,
|
||||
pointLightComponent->spotExponent);
|
||||
pointLightComponent->specularExponent,
|
||||
pointLightComponent->ConstantAttenuation,
|
||||
pointLightComponent->LinearAttenuation,
|
||||
pointLightComponent->QuadraticAttenuation
|
||||
);
|
||||
}
|
||||
|
||||
auto cameraComponent = m_World->GetComponent<Components::Camera>(entity, "Camera");
|
||||
auto cameraComponent = m_World->GetComponent<Components::Camera>(entity);
|
||||
if (cameraComponent != nullptr)
|
||||
{
|
||||
m_Renderer->GetCamera()->Position(m_TransformSystem->AbsolutePosition(entity));
|
||||
@@ -56,13 +57,13 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
||||
m_Renderer->GetCamera()->FarClip(cameraComponent->FarClip);
|
||||
}
|
||||
|
||||
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity, "Sprite");
|
||||
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
|
||||
if(spriteComponent != nullptr)
|
||||
{
|
||||
//TEMP
|
||||
Texture* texture = m_World->GetResourceManager()->Load<Texture>("Texture", spriteComponent->SpriteFile);
|
||||
//glBindTexture(GL_TEXTURE_2D, texture);
|
||||
auto transform = m_World->GetComponent<Components::Transform>(spriteComponent->Entity, "Transform");
|
||||
auto transform = m_World->GetComponent<Components::Transform>(spriteComponent->Entity);
|
||||
glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(transform->Orientation).z, glm::vec3(0, 0, -1));
|
||||
m_Renderer->AddTextureToDraw(texture, transform->Position, orientation2D, transform->Scale);
|
||||
}
|
||||
@@ -70,16 +71,18 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
||||
|
||||
void Systems::RenderSystem::Initialize()
|
||||
{
|
||||
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>("TransformSystem");
|
||||
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
|
||||
|
||||
m_Renderer->SetSphereModel(m_World->GetResourceManager()->Load<Model>("Model", "Models/Placeholders/PhysicsTest/Sphere.obj"));
|
||||
}
|
||||
|
||||
void Systems::RenderSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
cf->Register("Camera", []() { return new Components::Camera(); });
|
||||
cf->Register("Model", []() { return new Components::Model(); });
|
||||
cf->Register("Sprite", []() { return new Components::Sprite(); });
|
||||
cf->Register("PointLight", []() { return new Components::PointLight(); });
|
||||
cf->Register("DirectionalLight", []() { return new Components::DirectionalLight(); });
|
||||
cf->Register<Components::Camera>([]() { return new Components::Camera(); });
|
||||
cf->Register<Components::Model>([]() { return new Components::Model(); });
|
||||
cf->Register<Components::Sprite>([]() { return new Components::Sprite(); });
|
||||
cf->Register<Components::PointLight>([]() { return new Components::PointLight(); });
|
||||
cf->Register<Components::DirectionalLight>([]() { return new Components::DirectionalLight(); });
|
||||
}
|
||||
|
||||
void Systems::RenderSystem::RegisterResourceTypes(ResourceManager* rm)
|
||||
|
||||
@@ -29,7 +29,7 @@ void Systems::SoundSystem::Initialize()
|
||||
|
||||
void Systems::SoundSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
cf->Register("SoundEmitter", []() { return new Components::SoundEmitter(); });
|
||||
cf->Register<Components::SoundEmitter>([]() { return new Components::SoundEmitter(); });
|
||||
}
|
||||
|
||||
void Systems::SoundSystem::RegisterResourceTypes(ResourceManager* rm)
|
||||
@@ -44,7 +44,7 @@ void Systems::SoundSystem::Update(double dt)
|
||||
|
||||
void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (transformComponent == nullptr)
|
||||
return;
|
||||
|
||||
@@ -68,7 +68,7 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par
|
||||
alListenerfv(AL_ORIENTATION, listenerOri);
|
||||
}
|
||||
|
||||
auto soundEmitter = m_World->GetComponent<Components::SoundEmitter>(entity, "SoundEmitter");
|
||||
auto soundEmitter = m_World->GetComponent<Components::SoundEmitter>(entity);
|
||||
if(soundEmitter != nullptr)
|
||||
{
|
||||
ALuint source = m_Sources[soundEmitter];
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
void Systems::TankSteeringSystem::RegisterComponents( ComponentFactory* cf )
|
||||
{
|
||||
cf->Register("TankSteering", []() { return new Components::TankSteering(); });
|
||||
cf->Register("TowerSteering", []() { return new Components::TowerSteering(); });
|
||||
cf->Register("BarrelSteering", []() { return new Components::BarrelSteering(); });
|
||||
cf->Register<Components::TankSteering>([]() { return new Components::TankSteering(); });
|
||||
cf->Register<Components::TowerSteering>([]() { return new Components::TowerSteering(); });
|
||||
cf->Register<Components::BarrelSteering>([]() { return new Components::BarrelSteering(); });
|
||||
}
|
||||
|
||||
void Systems::TankSteeringSystem::Initialize()
|
||||
@@ -23,7 +23,7 @@ void Systems::TankSteeringSystem::Update(double dt)
|
||||
|
||||
void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto tankSteeringComponent = m_World->GetComponent<Components::TankSteering>(entity, "TankSteering");
|
||||
auto tankSteeringComponent = m_World->GetComponent<Components::TankSteering>(entity);
|
||||
if(tankSteeringComponent)
|
||||
{
|
||||
Events::TankSteer e;
|
||||
@@ -34,27 +34,27 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
auto towerSteeringComponent = m_World->GetComponent<Components::TowerSteering>(entity, "TowerSteering");
|
||||
auto towerSteeringComponent = m_World->GetComponent<Components::TowerSteering>(entity);
|
||||
if(towerSteeringComponent)
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
glm::quat orientation = glm::angleAxis(towerSteeringComponent->TurnSpeed * m_TowerInputController->TowerDirection * (float)dt, towerSteeringComponent->Axis);
|
||||
transformComponent->Orientation *= orientation;
|
||||
}
|
||||
|
||||
auto barrelSteeringComponent = m_World->GetComponent<Components::BarrelSteering>(entity, "BarrelSteering");
|
||||
auto barrelSteeringComponent = m_World->GetComponent<Components::BarrelSteering>(entity);
|
||||
if(barrelSteeringComponent)
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(entity);
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
|
||||
glm::quat orientation = glm::angleAxis(barrelSteeringComponent->TurnSpeed * m_TowerInputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis);
|
||||
transformComponent->Orientation *= orientation;
|
||||
|
||||
if(m_TowerInputController->Shoot && m_TimeSinceLastShot[entity] > 1.0)
|
||||
{
|
||||
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");
|
||||
auto templateAbsoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(barrelSteeringComponent->ShotTemplate);
|
||||
auto cloneTransform = m_World->GetComponent<Components::Transform>(clone);
|
||||
cloneTransform->Position = templateAbsoluteTransform.Position;
|
||||
cloneTransform->Orientation = absoluteTransform.Orientation * cloneTransform->Orientation;
|
||||
Events::SetVelocity e;
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
// if (parent == 0)
|
||||
// return;
|
||||
//
|
||||
// auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
// auto parentTransform = m_World->GetComponent<Components::Transform>(parent, "Transform");
|
||||
// auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
// auto parentTransform = m_World->GetComponent<Components::Transform>(parent);
|
||||
//
|
||||
// transform->Position = parentTransform->Position + transform->RelativePosition;
|
||||
//}
|
||||
@@ -20,10 +20,10 @@ glm::vec3 Systems::TransformSystem::AbsolutePosition(EntityID entity)
|
||||
|
||||
do
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
//absPosition += transform->Position;
|
||||
entity = m_World->GetEntityParent(entity);
|
||||
auto transform2 = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transform2 = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (entity == 0)
|
||||
absPosition += transform->Position;
|
||||
else
|
||||
@@ -39,7 +39,7 @@ glm::quat Systems::TransformSystem::AbsoluteOrientation(EntityID entity)
|
||||
|
||||
do
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
absOrientation = transform->Orientation * absOrientation;
|
||||
entity = m_World->GetEntityParent(entity);
|
||||
} while (entity != 0);
|
||||
@@ -53,7 +53,7 @@ glm::vec3 Systems::TransformSystem::AbsoluteScale(EntityID entity)
|
||||
|
||||
do
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
absScale *= transform->Scale;
|
||||
entity = m_World->GetEntityParent(entity);
|
||||
} while (entity != 0);
|
||||
@@ -69,9 +69,9 @@ Components::Transform Systems::TransformSystem::AbsoluteTransform(EntityID entit
|
||||
|
||||
do
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
entity = m_World->GetEntityParent(entity);
|
||||
auto transform2 = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto transform2 = m_World->GetComponent<Components::Transform>(entity);
|
||||
|
||||
// Position
|
||||
if (entity == 0)
|
||||
|
||||
Reference in New Issue
Block a user