Merge remote-tracking branch 'origin/PlayerMovement' into Networking

This commit is contained in:
stiffly
2016-01-22 16:19:35 +01:00
25 changed files with 540 additions and 181 deletions
+1 -1
Submodule assets updated: 6ffb46e155...2a800ea92b
+1
View File
@@ -25,6 +25,7 @@ struct EntityWrapper
bool HasComponent(const std::string& componentName); bool HasComponent(const std::string& componentName);
EntityWrapper Parent(); EntityWrapper Parent();
EntityWrapper FirstChildByName(const std::string& name);
bool Valid(); bool Valid();
ComponentWrapper operator[](const char* componentName); ComponentWrapper operator[](const char* componentName);
+5
View File
@@ -3,13 +3,18 @@
#include "../GLM.h" #include "../GLM.h"
#include "World.h" #include "World.h"
#include "EntityWrapper.h"
namespace Transform namespace Transform
{ {
glm::vec3 AbsolutePosition(EntityWrapper entity);
glm::vec3 AbsolutePosition(World* world, EntityID entity); glm::vec3 AbsolutePosition(World* world, EntityID entity);
glm::quat AbsoluteOrientation(EntityWrapper entity);
glm::quat AbsoluteOrientation(World* world, EntityID entity); glm::quat AbsoluteOrientation(World* world, EntityID entity);
glm::vec3 AbsoluteScale(EntityWrapper entity);
glm::vec3 AbsoluteScale(World* world, EntityID entity); glm::vec3 AbsoluteScale(World* world, EntityID entity);
glm::mat4 ModelMatrix(EntityWrapper entity);
glm::mat4 ModelMatrix(EntityID entity, World* world); glm::mat4 ModelMatrix(EntityID entity, World* world);
} }
@@ -0,0 +1,98 @@
#ifndef EditorCameraInputController_h__
#define EditorCameraInputController_h__
#include <imgui/imgui.h>
#include "../Input/FirstPersonInputController.h"
#include "../Core/EMousePress.h"
#include "../Core/EMouseRelease.h"
#include "../Core/EMouseScroll.h"
#include "../Core/ConfigFile.h"
template <typename EventContext>
class EditorCameraInputController : public FirstPersonInputController<EventContext>
{
public:
EditorCameraInputController(EventBroker* eventBroker, unsigned int playerID)
: FirstPersonInputController(eventBroker, playerID)
{
EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &EditorCameraInputController::OnMousePress);
EVENT_SUBSCRIBE_MEMBER(m_EMouseRelease, &EditorCameraInputController::OnMouseRelease);
EVENT_SUBSCRIBE_MEMBER(m_EMouseScroll, &EditorCameraInputController::OnMouseScroll);
m_Config = ResourceManager::Load<ConfigFile>("Config.ini");
m_SpeedMultiplier = m_Config->Get<float>("Editor.CameraSpeed", 3.f);
}
virtual const glm::vec3 Movement() const override
{
return m_Movement * m_SpeedMultiplier;
}
virtual bool OnCommand(const Events::InputCommand& e) override
{
ImGuiIO& io = ImGui::GetIO();
if (glm::abs(e.Value) > 0 && (io.WantCaptureKeyboard || io.WantCaptureMouse)) {
return false;
}
if (e.Command == "Jump") {
if (e.Value > 0) {
m_Movement.y = glm::max(e.Value, 1.f);
} else {
m_Movement.y = 0.f;
}
}
if (e.Command == "Crouch") {
if (e.Value > 0) {
m_Movement.y = glm::min(-e.Value, -1.f);
} else {
m_Movement.y = 0.f;
}
}
if (e.Command == "Sprint") {
if (e.Value > 0) {
m_SpeedMultiplier *= 2.f;
} else {
m_SpeedMultiplier /= 2.f;
}
}
return FirstPersonInputController::OnCommand(e);
}
protected:
ConfigFile* m_Config;
float m_SpeedMultiplier = 1.f;
EventRelay<EventContext, Events::MousePress> m_EMousePress;
bool OnMousePress(const Events::MousePress& e)
{
if (e.Button == GLFW_MOUSE_BUTTON_2) {
ImGuiIO& io = ImGui::GetIO();
if (!io.WantCaptureMouse) {
LockMouse();
}
}
return true;
}
EventRelay<EventContext, Events::MouseRelease> m_EMouseRelease;
bool OnMouseRelease(const Events::MouseRelease& e)
{
if (e.Button == GLFW_MOUSE_BUTTON_2) {
UnlockMouse();
}
return true;
}
EventRelay<EventContext, Events::MouseScroll> m_EMouseScroll;
bool OnMouseScroll(const Events::MouseScroll& e)
{
m_SpeedMultiplier += e.DeltaY * (0.1f * m_SpeedMultiplier);
m_Config->Set("Editor.CameraSpeed", m_SpeedMultiplier);
m_Config->SaveToDisk();
return true;
}
};
#endif
+15 -4
View File
@@ -1,7 +1,6 @@
#include "../Core/System.h" #include "../Core/System.h"
#include "../Rendering/IRenderer.h" #include "../Rendering/IRenderer.h"
#include "../Rendering/Camera.h" #include "../Rendering/Camera.h"
#include "../Rendering/DebugCameraInputController.h"
#include "../Rendering/ESetCamera.h" #include "../Rendering/ESetCamera.h"
#include "../Core/World.h" #include "../Core/World.h"
#include "../Core/SystemPipeline.h" #include "../Core/SystemPipeline.h"
@@ -10,8 +9,10 @@
#include "../Core/EntityFileParser.h" #include "../Core/EntityFileParser.h"
#include "../Core/EntityFileWriter.h" #include "../Core/EntityFileWriter.h"
#include "../Core/EMousePress.h" #include "../Core/EMousePress.h"
#include "../Input/EInputCommand.h"
#include "EditorGUI.h" #include "EditorGUI.h"
#include "EditorStats.h" #include "EditorStats.h"
#include "EditorCameraInputController.h"
class EditorSystem : public ImpureSystem class EditorSystem : public ImpureSystem
{ {
@@ -21,18 +22,24 @@ public:
void Update(double dt); void Update(double dt);
void Enable();
void Disable();
private: private:
IRenderer* m_Renderer; IRenderer* m_Renderer;
RenderFrame* m_RenderFrame; RenderFrame* m_RenderFrame;
World* m_EditorWorld; World* m_EditorWorld;
SystemPipeline* m_EditorWorldSystemPipeline; SystemPipeline* m_EditorWorldSystemPipeline;
Camera* m_EditorCamera; //Camera* m_EditorCamera;
EntityWrapper m_Camera = EntityWrapper::Invalid; EntityWrapper m_EditorCamera = EntityWrapper::Invalid;
DebugCameraInputController<EditorSystem>* m_DebugCameraInputController; EntityWrapper m_ActualCamera = EntityWrapper::Invalid;
EditorCameraInputController<EditorSystem>* m_EditorCameraInputController;
EditorGUI* m_EditorGUI; EditorGUI* m_EditorGUI;
EditorStats* m_EditorStats; EditorStats* m_EditorStats;
// State // State
double m_LastTime = 0.f;
bool m_Enabled = true;
EditorGUI::WidgetMode m_WidgetMode = EditorGUI::WidgetMode::Translate; EditorGUI::WidgetMode m_WidgetMode = EditorGUI::WidgetMode::Translate;
EntityWrapper m_Widget = EntityWrapper::Invalid; EntityWrapper m_Widget = EntityWrapper::Invalid;
EntityWrapper m_CurrentSelection = EntityWrapper::Invalid; EntityWrapper m_CurrentSelection = EntityWrapper::Invalid;
@@ -56,4 +63,8 @@ private:
bool OnMousePress(const Events::MousePress& e); bool OnMousePress(const Events::MousePress& e);
EventRelay<EditorSystem, Events::WidgetDelta> m_EWidgetDelta; EventRelay<EditorSystem, Events::WidgetDelta> m_EWidgetDelta;
bool OnWidgetDelta(const Events::WidgetDelta& e); bool OnWidgetDelta(const Events::WidgetDelta& e);
EventRelay<EditorSystem, Events::InputCommand> m_EInputCommand;
bool OnInputCommand(const Events::InputCommand& e);
EventRelay<EditorSystem, Events::SetCamera> m_ESetCamera;
bool OnSetCamera(const Events::SetCamera& e);
}; };
+1 -1
View File
@@ -9,7 +9,7 @@ namespace Events
struct InputCommand : Event struct InputCommand : Event
{ {
/** Numerical ID of the player. */ /** Numerical ID of the player. */
unsigned int PlayerID; int PlayerID;
/** The command that was sent. */ /** The command that was sent. */
std::string Command; std::string Command;
/** The value of the command. */ /** The value of the command. */
@@ -9,7 +9,7 @@ template <typename EventContext>
class FirstPersonInputController : public InputController<EventContext> class FirstPersonInputController : public InputController<EventContext>
{ {
public: public:
FirstPersonInputController(EventBroker* eventBroker, unsigned int playerID) FirstPersonInputController(EventBroker* eventBroker, int playerID)
: InputController(eventBroker) : InputController(eventBroker)
, m_PlayerID(playerID) , m_PlayerID(playerID)
{ {
@@ -17,7 +17,8 @@ public:
EVENT_SUBSCRIBE_MEMBER(m_EUnlockMouse, &FirstPersonInputController::OnUnlockMouse); EVENT_SUBSCRIBE_MEMBER(m_EUnlockMouse, &FirstPersonInputController::OnUnlockMouse);
} }
const glm::quat Orientation() const { return m_Orientation; } virtual const glm::vec3 Movement() const { return m_Movement; }
virtual const glm::vec3 Orientation() const { return m_Orientation; }
void LockMouse() void LockMouse()
{ {
@@ -42,24 +43,44 @@ public:
if (m_MouseLocked) { if (m_MouseLocked) {
if (e.Command == "Pitch") { if (e.Command == "Pitch") {
float val = glm::radians(e.Value); float val = glm::radians(e.Value);
m_Orientation = m_Orientation * glm::angleAxis<float>(-val, glm::vec3(1, 0, 0)); m_Orientation.x += -val;
m_Orientation.x = glm::clamp(m_Orientation.x, -glm::half_pi<float>(), glm::half_pi<float>());
//m_Orientation = m_Orientation * glm::angleAxis<float>(-val, glm::vec3(1.f, 0, 0));
return true; return true;
} }
if (e.Command == "Yaw") { if (e.Command == "Yaw") {
float val = glm::radians(e.Value); float val = glm::radians(e.Value);
m_Orientation = glm::angleAxis<float>(-val, glm::vec3(0, 1, 0)) * m_Orientation; m_Orientation.y += -val;
//m_Orientation = glm::angleAxis<float>(-val, glm::vec3(0, 1.f, 0)) * m_Orientation;
return true; return true;
} }
} }
if (e.Command == "Forward" || e.Command == "Right") {
if (e.Command == "Forward") {
float val = glm::clamp(e.Value, -1.f, 1.f);
m_Movement.z = -val;
return true;
}
if (e.Command == "Right") {
float val = glm::clamp(e.Value, -1.f, 1.f);
m_Movement.x = val;
return true;
}
if (glm::length2(m_Movement) > 0) {
m_Movement = glm::normalize(m_Movement);
}
}
return false; return false;
} }
protected: protected:
const unsigned int m_PlayerID; const int m_PlayerID;
glm::quat m_Orientation;
bool m_MouseLocked = false; bool m_MouseLocked = false;
glm::vec3 m_Orientation;
glm::vec3 m_Movement;
EventRelay<EventContext, Events::LockMouse> m_ELockMouse; EventRelay<EventContext, Events::LockMouse> m_ELockMouse;
bool OnLockMouse(const Events::LockMouse& e) { m_MouseLocked = true; return true; } bool OnLockMouse(const Events::LockMouse& e) { m_MouseLocked = true; return true; }
@@ -1,84 +0,0 @@
#ifndef DebugCameraInputController_h__
#define DebugCameraInputController_h__
#include <imgui/imgui.h>
#include "../Input/FirstPersonInputController.h"
#include "../Core/EMousePress.h"
#include "../Core/EMouseRelease.h"
template <typename EventContext>
class DebugCameraInputController : public FirstPersonInputController<EventContext>
{
public:
DebugCameraInputController(EventBroker* eventBroker, unsigned int playerID)
: FirstPersonInputController(eventBroker, playerID)
{
EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &DebugCameraInputController::OnMousePress);
EVENT_SUBSCRIBE_MEMBER(m_EMouseRelease, &DebugCameraInputController::OnMouseRelease);
}
void SetPosition(const glm::vec3 position) { m_Position = position; }
void SetOrientation(const glm::quat orientation) { m_Orientation = orientation; }
const glm::vec3 Position() const { return m_Position; }
void SetBaseSpeed(float speed) { m_BaseSpeed = speed; }
virtual bool OnCommand(const Events::InputCommand& e) override
{
ImGuiIO& io = ImGui::GetIO();
if (!io.WantCaptureKeyboard) {
if (e.Command == "Right") {
float value = std::max(-1.f, std::min(e.Value, 1.f));
m_Velocity.x = value;
}
if (e.Command == "Forward") {
float value = std::max(-1.f, std::min(e.Value, 1.f));
m_Velocity.z = -value;
}
if (e.Command == "Sprint") {
if (e.Value > 0.f) {
m_Speed = m_BaseSpeed * 2.f * (e.Value);
} else {
m_Speed = m_BaseSpeed;
}
}
}
return FirstPersonInputController::OnCommand(e);
}
void Update(double dt)
{
if (glm::length2(m_Velocity) > 0) {
m_Position += m_Orientation * (glm::normalize(m_Velocity) * m_Speed * (float)dt);
}
}
protected:
glm::vec3 m_Position = glm::vec3(0, 0, 0);
glm::vec3 m_Velocity = glm::vec3(0, 0, 0);
float m_BaseSpeed = 2.0f;
float m_Speed = m_BaseSpeed;
EventRelay<EventContext, Events::MousePress> m_EMousePress;
bool OnMousePress(const Events::MousePress& e)
{
if (e.Button == GLFW_MOUSE_BUTTON_2) {
ImGuiIO& io = ImGui::GetIO();
if (!io.WantCaptureMouse) {
LockMouse();
}
}
return true;
}
EventRelay<EventContext, Events::MouseRelease> m_EMouseRelease;
bool OnMouseRelease(const Events::MouseRelease& e)
{
if (e.Button == GLFW_MOUSE_BUTTON_2) {
UnlockMouse();
}
return true;
}
};
#endif
-1
View File
@@ -15,7 +15,6 @@
#include "Renderer.h" #include "Renderer.h"
#include "PointLightJob.h" #include "PointLightJob.h"
#include "../Core/Transform.h" #include "../Core/Transform.h"
#include "DebugCameraInputController.h"
class RenderSystem : public ImpureSystem class RenderSystem : public ImpureSystem
{ {
+19
View File
@@ -0,0 +1,19 @@
#ifndef EPlayerSpawned_h__
#define EPlayerSpawned_h__
#include "Core/Event.h"
#include "Core/EntityWrapper.h"
namespace Events
{
struct PlayerSpawned : Event
{
int PlayerID;
EntityWrapper Player;
EntityWrapper Spawner;
};
}
#endif
+13 -5
View File
@@ -1,14 +1,22 @@
#include "Common.h" #include "Common.h"
#include "GLM.h" #include "GLM.h"
#include "Core/System.h" #include "Core/System.h"
#include "Events/EPlayerSpawned.h"
#include "Input/FirstPersonInputController.h"
class PlayerMovementSystem : public PureSystem class PlayerMovementSystem : public ImpureSystem, PureSystem
{ {
public: public:
PlayerMovementSystem(World* world, EventBroker* eventBroker) PlayerMovementSystem(World* world, EventBroker* eventBroker);
: System(world, eventBroker) ~PlayerMovementSystem();
, PureSystem("Player")
{ }
virtual void Update(double dt) override;
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt); virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt);
private:
// State
std::unordered_map<EntityWrapper, FirstPersonInputController<PlayerMovementSystem>*> m_PlayerInputControllers;
EventRelay<PlayerMovementSystem, Events::PlayerSpawned> m_EPlayerSpawned;
bool OnPlayerSpawned(Events::PlayerSpawned& e);
}; };
+9 -1
View File
@@ -2,6 +2,8 @@
#include "Input/EInputCommand.h" #include "Input/EInputCommand.h"
#include "Systems/SpawnerSystem.h" #include "Systems/SpawnerSystem.h"
#include "Events/ESpawnerSpawn.h" #include "Events/ESpawnerSpawn.h"
#include "Events/EPlayerSpawned.h"
#include "Rendering/ESetCamera.h"
class PlayerSpawnSystem : public ImpureSystem class PlayerSpawnSystem : public ImpureSystem
{ {
@@ -11,8 +13,14 @@ public:
virtual void Update(double dt) override; virtual void Update(double dt) override;
private: private:
struct SpawnRequest
{
int PlayerID;
ComponentInfo::EnumType Team;
};
EventRelay<PlayerSpawnSystem, Events::InputCommand> m_OnInputCommand; EventRelay<PlayerSpawnSystem, Events::InputCommand> m_OnInputCommand;
bool OnInputCommand(const Events::InputCommand& e); bool OnInputCommand(const Events::InputCommand& e);
std::vector<int> m_SpawnRequests; std::vector<SpawnRequest> m_SpawnRequests;
}; };
+3 -1
View File
@@ -1,11 +1,13 @@
[Debug] [Debug]
LogLevel=1 LogLevel=1
LoadMap= LoadMap=
EditorEnabled=false
; if true -> Pool allocation is not used when calling Allocate/Free, just use regular dynamic allocation. ; if true -> Pool allocation is not used when calling Allocate/Free, just use regular dynamic allocation.
; if false -> Use pool allocation. ; if false -> Use pool allocation.
DisableMemoryPool=false DisableMemoryPool=false
[Editor]
CameraSpeed=3
[Video] [Video]
Fullscreen=false Fullscreen=false
VSYNC=false VSYNC=false
+1 -5
View File
@@ -1,8 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Player xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Player.xsd"> <Player xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Player.xsd">
<Velocity X="0" Y="0" Z="0"/> <MovementSpeed>0.2</MovementSpeed>
<Forward>false</Forward>
<Left>false</Left>
<Back>false</Back>
<Right>false</Right>
</Player> </Player>
+1 -5
View File
@@ -9,11 +9,7 @@
</xs:annotation> </xs:annotation>
<xs:complexType> <xs:complexType>
<xs:all> <xs:all>
<xs:element name="Velocity" type="t:Vector" minOccurs="0"/> <xs:element name="MovementSpeed" type="t:float" minOccurs="0"/>
<xs:element name="Forward" type="t:bool" minOccurs="0"/>
<xs:element name="Left" type="t:bool" minOccurs="0"/>
<xs:element name="Back" type="t:bool" minOccurs="0"/>
<xs:element name="Right" type="t:bool" minOccurs="0"/>
</xs:all> </xs:all>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:AABB/>
<c:Collidable/>
<c:Model>
<Resource>Models/Core/UnitCube.obj</Resource>
</c:Model>
<c:Transform/>
</Components>
<Children/>
</Entity>
+94 -31
View File
@@ -6,14 +6,7 @@
</Components> </Components>
<Children> <Children>
<Entity> <Entity name="Ground">
<Components>
<c:Camera/>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity>
<Components> <Components>
<c:AABB/> <c:AABB/>
<c:Collidable/> <c:Collidable/>
@@ -22,46 +15,116 @@
<Color A="1" B="0.513725519" G="0" R="1"/> <Color A="1" B="0.513725519" G="0" R="1"/>
</c:Model> </c:Model>
<c:Transform> <c:Transform>
<Position X="0" Y="2" Z="0"/> <Position X="7" Y="-0.727000058" Z="-1.22800004"/>
<Scale X="5" Y="1" Z="5"/> <Scale X="50" Y="1.45100009" Z="50"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children/> <Children/>
</Entity> </Entity>
<Entity name="Player"> <Entity name="Spawner">
<Components> <Components>
<c:AABB> <c:PlayerSpawn/>
<Origin X="0" Y="0.773000062" Z="0"/> <c:Spawner>
<Size X="1" Y="1.60000002" Z="1"/> <EntityFile>Schema/Entities/Player.xml</EntityFile>
</c:AABB> </c:Spawner>
<c:Collidable/> <c:Team>
<c:Physics/> <Team>
<c:Model> <Red/>
<Resource>Models/Assault.obj</Resource> </Team>
<Color A="1" B="1" G="0" R="0"/> </c:Team>
</c:Model>
<c:Player/>
<c:Transform> <c:Transform>
<Position X="0" Y="2.52699995" Z="0.0542778969"/> <Position X="0.300000012" Y="0.0270000007" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:SpawnPoint/>
<c:Model>
<Resource>Models/Assault.obj</Resource>
<Color A="1" B="0" G="0" R="1"/>
</c:Model>
<c:Transform>
<Position X="0.800000012" Y="0" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:SpawnPoint/>
<c:Model>
<Resource>Models/Assault.obj</Resource>
<Color A="1" B="0.0117647061" G="0" R="1"/>
</c:Model>
<c:Transform>
<Position X="-0.600000024" Y="0" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="DirectionalLight">
<Components>
<c:DirectionalLight/>
<c:Model>
<Resource>Models/DirectionalLightWidget.obj</Resource>
</c:Model>
<c:Transform>
<Position X="-6.00145912" Y="1.42697716" Z="3.04144025"/>
<Orientation X="5.69400024" Y="841.179565" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children/> <Children/>
</Entity> </Entity>
<Entity> <Entity name="ObstacleCourse">
<Components>
<c:Model>
<Resource>Models/Test/ObstacleCourse.obj</Resource>
</c:Model>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity name="ObstacleCoursePlayerBox">
<Components> <Components>
<c:AABB/> <c:AABB/>
<c:Collidable/> <c:Collidable/>
<c:Physics>
<Velocity X="0" Y="-0.0934068039" Z="0"/>
</c:Physics>
<c:Model> <c:Model>
<Resource>Models/Core/UnitCube.obj</Resource> <Resource>Models/Core/UnitCube.obj</Resource>
<Color A="1" B="0" G="1" R="1"/>
</c:Model> </c:Model>
<c:Player/>
<c:Transform> <c:Transform>
<Position X="0" Y="4.15580511" Z="0"/> <Position X="6.32800007" Y="0.807000041" Z="-2.2750001"/>
<Scale X="0.704558551" Y="0.115156889" Z="1"/> <Scale X="1" Y="1.60000002" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="ObstacleCourse1uHigh">
<Components>
<c:AABB/>
<c:Collidable/>
<c:Model>
<Resource>Models/Core/UnitCube.obj</Resource>
</c:Model>
<c:Transform>
<Position X="9.11900043" Y="0.5" Z="-2.10900021"/>
<Scale X="1" Y="1" Z="8.1960001"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="ObstacleCourseWhoTheFuckKnows">
<Components>
<c:AABB/>
<c:Collidable/>
<c:Model>
<Resource>Models/Core/UnitCube.obj</Resource>
</c:Model>
<c:Transform>
<Position X="13.2370005" Y="1.28600001" Z="-1.71700013"/>
<Scale X="2.58000016" Y="2.58300018" Z="21.1860008"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children/> <Children/>
+52 -9
View File
@@ -2,17 +2,60 @@
<Entity name="Player" xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd"> <Entity name="Player" xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components> <Components>
<c:AABB/> <c:AABB>
<c:Physics/> <Origin X="0" Y="0.772000015" Z="0"/>
<Size X="1" Y="1.60000002" Z="1"/>
</c:AABB>
<c:Collidable/> <c:Collidable/>
<c:Model> <c:Physics/>
<Resource>Models/Core/UnitSphere.obj</Resource> <c:Player>
<Color A="1" B="1" G="0" R="0"/> <MovementSpeed>3</MovementSpeed>
</c:Model> </c:Player>
<c:Player/> <c:Transform>
<c:Transform/> <Position X="0.173066795" Y="0.0264999717" Z="4.19288635"/>
<Orientation X="0" Y="-12.7723045" Z="0"/>
</c:Transform>
</Components> </Components>
<Children/> <Children>
<Entity name="Camera">
<Components>
<c:Camera/>
<c:Model>
<Resource>Models/Camera.obj</Resource>
<Visible>false</Visible>
</c:Model>
<c:Transform>
<Position X="0" Y="1.37700009" Z="0"/>
<Orientation X="-0.186750308" Y="0" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="ThirdPersonCamera">
<Components>
<c:Camera/>
<c:Model>
<Resource>Models/Camera.obj</Resource>
</c:Model>
<c:Transform>
<Position X="-0.284000009" Y="1.83800006" Z="1.18900001"/>
<Orientation X="5.95600033" Y="0" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="PlayerModel">
<Components>
<c:Model>
<Resource>Models/Assault.obj</Resource>
</c:Model>
<c:Transform>
<Orientation X="0" Y="3.14159274" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity> </Entity>
+3
View File
@@ -16,6 +16,9 @@
<xs:simpleType name="double"> <xs:simpleType name="double">
<xs:restriction base="xs:decimal"></xs:restriction> <xs:restriction base="xs:decimal"></xs:restriction>
</xs:simpleType> </xs:simpleType>
<xs:simpleType name="float">
<xs:restriction base="xs:decimal"></xs:restriction>
</xs:simpleType>
<xs:simpleType name="string"> <xs:simpleType name="string">
<xs:restriction base="xs:string"></xs:restriction> <xs:restriction base="xs:string"></xs:restriction>
</xs:simpleType> </xs:simpleType>
+16
View File
@@ -17,6 +17,22 @@ EntityWrapper EntityWrapper::Parent()
} }
} }
EntityWrapper EntityWrapper::FirstChildByName(const std::string& name)
{
auto itPair = this->World->GetChildren(this->ID);
if (itPair.first == itPair.second) {
return EntityWrapper::Invalid;
}
for (auto it = itPair.first; it != itPair.second; ++it) {
if (this->World->GetName(it->second) == name) {
return EntityWrapper(this->World, it->second);
}
}
return EntityWrapper::Invalid;
}
bool EntityWrapper::Valid() bool EntityWrapper::Valid()
{ {
if (this->World == nullptr) { if (this->World == nullptr) {
+20
View File
@@ -1,5 +1,10 @@
#include "Core/Transform.h" #include "Core/Transform.h"
glm::vec3 Transform::AbsolutePosition(EntityWrapper entity)
{
return AbsolutePosition(entity.World, entity.ID);
}
glm::vec3 Transform::AbsolutePosition(World* world, EntityID entity) glm::vec3 Transform::AbsolutePosition(World* world, EntityID entity)
{ {
glm::vec3 position; glm::vec3 position;
@@ -14,6 +19,11 @@ glm::vec3 Transform::AbsolutePosition(World* world, EntityID entity)
return position; return position;
} }
glm::quat Transform::AbsoluteOrientation(EntityWrapper entity)
{
return AbsoluteOrientation(entity.World, entity.ID);
}
glm::quat Transform::AbsoluteOrientation(World* world, EntityID entity) glm::quat Transform::AbsoluteOrientation(World* world, EntityID entity)
{ {
glm::quat orientation; glm::quat orientation;
@@ -27,6 +37,11 @@ glm::quat Transform::AbsoluteOrientation(World* world, EntityID entity)
return orientation; return orientation;
} }
glm::vec3 Transform::AbsoluteScale(EntityWrapper entity)
{
return AbsoluteScale(entity.World, entity.ID);
}
glm::vec3 Transform::AbsoluteScale(World* world, EntityID entity) glm::vec3 Transform::AbsoluteScale(World* world, EntityID entity)
{ {
glm::vec3 scale(1.f); glm::vec3 scale(1.f);
@@ -40,6 +55,11 @@ glm::vec3 Transform::AbsoluteScale(World* world, EntityID entity)
return scale; return scale;
} }
glm::mat4 Transform::ModelMatrix(EntityWrapper entity)
{
return ModelMatrix(entity.ID, entity.World);
}
glm::mat4 Transform::ModelMatrix(EntityID entity, World* world) glm::mat4 Transform::ModelMatrix(EntityID entity, World* world)
{ {
glm::vec3 position = Transform::AbsolutePosition(world, entity); glm::vec3 position = Transform::AbsolutePosition(world, entity);
+69 -17
View File
@@ -14,10 +14,11 @@ EditorSystem::EditorSystem(World* world, EventBroker* eventBroker, IRenderer* re
m_EditorWorldSystemPipeline->AddSystem<EditorWidgetSystem>(0, m_Renderer); m_EditorWorldSystemPipeline->AddSystem<EditorWidgetSystem>(0, m_Renderer);
m_EditorWorldSystemPipeline->AddSystem<EditorRenderSystem>(1, m_Renderer, m_RenderFrame); m_EditorWorldSystemPipeline->AddSystem<EditorRenderSystem>(1, m_Renderer, m_RenderFrame);
m_Camera = importEntity(EntityWrapper(m_EditorWorld, EntityID_Invalid), "Schema/Entities/Empty.xml"); m_EditorCamera = importEntity(EntityWrapper(m_EditorWorld, EntityID_Invalid), "Schema/Entities/Empty.xml");
m_EditorWorld->AttachComponent(m_Camera.ID, "Transform"); m_ActualCamera = m_EditorCamera;
m_EditorWorld->AttachComponent(m_Camera.ID, "Camera"); m_EditorWorld->AttachComponent(m_EditorCamera.ID, "Transform");
m_DebugCameraInputController = new DebugCameraInputController<EditorSystem>(m_EventBroker, -1); m_EditorWorld->AttachComponent(m_EditorCamera.ID, "Camera");
m_EditorCameraInputController = new EditorCameraInputController<EditorSystem>(m_EventBroker, -1);
m_EditorGUI = new EditorGUI(m_World, m_EventBroker); m_EditorGUI = new EditorGUI(m_World, m_EventBroker);
m_EditorGUI->SetEntitySelectedCallback(std::bind(&EditorSystem::OnEntitySelected, this, std::placeholders::_1)); m_EditorGUI->SetEntitySelectedCallback(std::bind(&EditorSystem::OnEntitySelected, this, std::placeholders::_1));
@@ -33,38 +34,66 @@ EditorSystem::EditorSystem(World* world, EventBroker* eventBroker, IRenderer* re
EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &EditorSystem::OnMousePress); EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &EditorSystem::OnMousePress);
EVENT_SUBSCRIBE_MEMBER(m_EWidgetDelta, &EditorSystem::OnWidgetDelta); EVENT_SUBSCRIBE_MEMBER(m_EWidgetDelta, &EditorSystem::OnWidgetDelta);
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &EditorSystem::OnInputCommand);
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &EditorSystem::OnSetCamera);
m_EditorStats = new EditorStats(); m_EditorStats = new EditorStats();
Events::SetCamera e; if (m_Enabled) {
e.CameraEntity = m_Camera; Enable();
m_EventBroker->Publish(e); }
} }
EditorSystem::~EditorSystem() EditorSystem::~EditorSystem()
{ {
delete m_EditorStats; delete m_EditorStats;
delete m_EditorGUI; delete m_EditorGUI;
delete m_DebugCameraInputController; delete m_EditorCameraInputController;
delete m_EditorWorldSystemPipeline; delete m_EditorWorldSystemPipeline;
delete m_EditorWorld; delete m_EditorWorld;
} }
void EditorSystem::Update(double dt) void EditorSystem::Update(double dt)
{ {
m_EventBroker->Process<EditorGUI>(); double now = glfwGetTime();
m_EditorGUI->Draw(); double actualDelta = now - m_LastTime;
m_EditorStats->Draw(dt); m_LastTime = now;
if (m_CurrentSelection.Valid() && m_Widget.Valid()) { if (m_Enabled) {
(glm::vec3&)m_Widget["Transform"]["Position"] = Transform::AbsolutePosition(m_CurrentSelection.World, m_CurrentSelection.ID); m_EventBroker->Process<EditorGUI>();
m_EditorGUI->Draw();
m_EditorStats->Draw(actualDelta);
if (m_CurrentSelection.Valid() && m_Widget.Valid()) {
(glm::vec3&)m_Widget["Transform"]["Position"] = Transform::AbsolutePosition(m_CurrentSelection.World, m_CurrentSelection.ID);
}
m_EditorWorldSystemPipeline->Update(actualDelta);
ComponentWrapper& cameraTransform = m_EditorCamera["Transform"];
glm::vec3& ori = cameraTransform["Orientation"];
ori.x = m_EditorCameraInputController->Orientation().x;
ori.y = m_EditorCameraInputController->Orientation().y;
glm::vec3& pos = cameraTransform["Position"];
pos += m_EditorCameraInputController->Movement() * glm::inverse(glm::quat(ori)) * (float)actualDelta;
} }
}
m_EditorWorldSystemPipeline->Update(dt); void EditorSystem::Enable()
{
Events::SetCamera e;
e.CameraEntity = m_EditorCamera;
m_EventBroker->Publish(e);
(glm::vec3&)m_EditorCamera["Transform"]["Position"] = Transform::AbsolutePosition(m_ActualCamera);
m_Enabled = true;
}
m_DebugCameraInputController->Update(dt); void EditorSystem::Disable()
m_Camera["Transform"]["Position"] = m_DebugCameraInputController->Position(); {
m_Camera["Transform"]["Orientation"] = glm::eulerAngles(m_DebugCameraInputController->Orientation()); Events::SetCamera e;
e.CameraEntity = m_ActualCamera;
m_EventBroker->Publish(e);
m_Enabled = false;
} }
void EditorSystem::OnEntitySelected(EntityWrapper entity) void EditorSystem::OnEntitySelected(EntityWrapper entity)
@@ -148,6 +177,29 @@ bool EditorSystem::OnWidgetDelta(const Events::WidgetDelta& e)
return true; return true;
} }
bool EditorSystem::OnInputCommand(const Events::InputCommand& e)
{
if (e.Command == "ToggleEditor" && e.Value > 0) {
if (m_Enabled) {
Disable();
} else {
Enable();
}
}
return true;
}
bool EditorSystem::OnSetCamera(const Events::SetCamera& e)
{
if (m_Enabled && e.CameraEntity != m_EditorCamera) {
m_ActualCamera = e.CameraEntity;
Events::SetCamera e2;
e2.CameraEntity = m_EditorCamera;
m_EventBroker->Publish(e2);
}
return true;
}
EntityWrapper EditorSystem::importEntity(EntityWrapper parent, boost::filesystem::path filePath) EntityWrapper EditorSystem::importEntity(EntityWrapper parent, boost::filesystem::path filePath)
{ {
if (parent.World == nullptr) { if (parent.World == nullptr) {
+5 -4
View File
@@ -119,11 +119,12 @@ void RenderSystem::Update(double dt)
{ {
m_EventBroker->Process<RenderSystem>(); m_EventBroker->Process<RenderSystem>();
if (m_CurrentCamera) { // Update the current camera used for rendering
ComponentWrapper cameraTransform = m_CurrentCamera["Transform"]; if (m_CurrentCamera.Valid()) {
m_Camera->SetPosition(cameraTransform["Position"]); m_Camera->SetPosition(Transform::AbsolutePosition(m_CurrentCamera));
m_Camera->SetOrientation(glm::quat((const glm::vec3&)cameraTransform["Orientation"])); m_Camera->SetOrientation(Transform::AbsoluteOrientation(m_CurrentCamera));
} }
//Only supports opaque geometry atm //Only supports opaque geometry atm
RenderScene scene; RenderScene scene;
+50 -2
View File
@@ -1,5 +1,45 @@
#include "Systems/PlayerMovementSystem.h" #include "Systems/PlayerMovementSystem.h"
PlayerMovementSystem::PlayerMovementSystem(World* world, EventBroker* eventBroker)
: System(world, eventBroker)
, PureSystem("Player")
{
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &PlayerMovementSystem::OnPlayerSpawned);
}
PlayerMovementSystem::~PlayerMovementSystem()
{
for (auto& kv : m_PlayerInputControllers) {
delete kv.second;
}
}
void PlayerMovementSystem::Update(double dt)
{
for (auto& kv : m_PlayerInputControllers) {
EntityWrapper player = kv.first;
auto& controller = kv.second;
if (!player.Valid()) {
continue;
}
EntityWrapper cameraEntity = player.FirstChildByName("Camera");
if (cameraEntity.Valid()) {
glm::vec3& cameraOrientation = cameraEntity["Transform"]["Orientation"];
cameraOrientation.x = controller->Orientation().x;
}
ComponentWrapper& cTransform = player["Transform"];
glm::vec3& ori = cTransform["Orientation"];
ori.y = controller->Orientation().y;
glm::vec3& pos = cTransform["Position"];
pos += controller->Movement() * glm::inverse(glm::quat(ori)) * (float)player["Player"]["MovementSpeed"] * (float)dt;
}
}
void PlayerMovementSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) void PlayerMovementSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt)
{ {
ComponentWrapper& cTransform = entity["Transform"]; ComponentWrapper& cTransform = entity["Transform"];
@@ -10,9 +50,17 @@ void PlayerMovementSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp
glm::vec3& velocity = cPhysics["Velocity"]; glm::vec3& velocity = cPhysics["Velocity"];
if (cPhysics["Gravity"]) { if (cPhysics["Gravity"]) {
velocity.y -= 9.82 * dt; velocity.y -= 9.82f * (float)dt;
} }
glm::vec3& position = cTransform["Position"]; glm::vec3& position = cTransform["Position"];
position += velocity * (float)dt; position += velocity * (float)dt;
} }
bool PlayerMovementSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
{
// When a player spawns, create an input controller for them
m_PlayerInputControllers[e.Player] = new FirstPersonInputController<PlayerMovementSystem>(m_EventBroker, e.PlayerID);
return true;
}
+22 -4
View File
@@ -13,7 +13,7 @@ void PlayerSpawnSystem::Update(double dt)
return; return;
} }
for (auto& team : m_SpawnRequests) { for (auto& req : m_SpawnRequests) {
for (auto& cPlayerSpawn : *playerSpawns) { for (auto& cPlayerSpawn : *playerSpawns) {
EntityWrapper spawner(m_World, cPlayerSpawn.EntityID); EntityWrapper spawner(m_World, cPlayerSpawn.EntityID);
if (!spawner.HasComponent("Spawner")) { if (!spawner.HasComponent("Spawner")) {
@@ -22,7 +22,7 @@ void PlayerSpawnSystem::Update(double dt)
// If the spawner has a team affiliation, check it // If the spawner has a team affiliation, check it
if (spawner.HasComponent("Team")) { if (spawner.HasComponent("Team")) {
if ((int)spawner["Team"]["Team"] != team) { if ((int)spawner["Team"]["Team"] != req.Team) {
continue; continue;
} }
} }
@@ -30,7 +30,22 @@ void PlayerSpawnSystem::Update(double dt)
// Spawn the player! // Spawn the player!
EntityWrapper player = SpawnerSystem::Spawn(spawner); EntityWrapper player = SpawnerSystem::Spawn(spawner);
// Set the player team affiliation // Set the player team affiliation
player["Team"]["Team"] = team; player["Team"]["Team"] = req.Team;
// Publish a PlayerSpawned event
Events::PlayerSpawned e;
e.PlayerID = req.PlayerID;
e.Player = player;
e.Spawner = spawner;
m_EventBroker->Publish(e);
// Set the camera to the correct entity
EntityWrapper cameraEntity = player.FirstChildByName("Camera");
if (cameraEntity.Valid()) {
Events::SetCamera e;
e.CameraEntity = cameraEntity;
m_EventBroker->Publish(e);
}
} }
} }
m_SpawnRequests.clear(); m_SpawnRequests.clear();
@@ -43,7 +58,10 @@ bool PlayerSpawnSystem::OnInputCommand(const Events::InputCommand& e)
} }
if (e.Value != 0) { if (e.Value != 0) {
m_SpawnRequests.push_back((int)e.Value); SpawnRequest req;
req.PlayerID = e.PlayerID;
req.Team = (ComponentInfo::EnumType)e.Value;
m_SpawnRequests.push_back(req);
} }
return true; return true;