Initial work on PlayerMovementSystem

This commit is contained in:
2016-01-14 17:03:42 +01:00
parent 986af01091
commit 6ad1839def
22 changed files with 146 additions and 30 deletions
+1 -1
Submodule assets updated: c8e631f449...a0d1615e51
-2
View File
@@ -15,8 +15,6 @@
#include "Core/EKeyDown.h"
#include "Core/EntityFilePreprocessor.h"
#include "Core/SystemPipeline.h"
#include "RaptorCopterSystem.h"
#include "PlayerSystem.h"
#include "Editor/EditorSystem.h"
#include "Core/EntityFile.h"
#include "Core/EntityFileParser.h"
@@ -6,9 +6,9 @@
#include "Common.h"
#include "Core/System.h"
#include "Core\EPlayerDamage.h";
#include "Core\EPlayerHealthPickup.h";
#include "Core\EPlayerDeath.h";
#include "Core/EPlayerDamage.h"
#include "Core/EPlayerHealthPickup.h"
#include "Core/EPlayerDeath.h"
#include <tuple>
#include <vector>
@@ -1,11 +1,13 @@
#include "Common.h"
#include "GLM.h"
#include "Core/System.h"
class PlayerMovementSystem : public PureSystem
{
public:
PlayerMovementSystem(EventBroker* eventBroker)
: PureSystem(eventBroker, "Player")
: System(eventBroker)
, PureSystem("Player")
{ }
virtual void UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& component, double dt);
+1
View File
@@ -2,6 +2,7 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="components" elementFormDefault="qualified">
<xs:include schemaLocation="Components/Transform.xsd"/>
<xs:include schemaLocation="Components/Physics.xsd"/>
<xs:include schemaLocation="Components/Model.xsd"/>
<xs:include schemaLocation="Components/Test.xsd"/>
<xs:include schemaLocation="Components/RaptorCopter.xsd"/>
@@ -1,3 +1,2 @@
<c:Collidable>
<Static>true</Static>
</c:Collidable>
@@ -4,10 +4,5 @@
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="Collidable">
<xs:complexType>
<xs:all>
<xs:element name="Static" type="t:bool" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
+3
View File
@@ -0,0 +1,3 @@
<c:Physics>
<Velocity X="0" Y="0" Z="0"/>
</c:Physics>
+16
View File
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="Physics">
<xs:annotation>
<xs:documentation>Physics stuff</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:all>
<xs:element name="Velocity" type="t:Vector" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
+1 -1
View File
@@ -17,4 +17,4 @@
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
</xs:schema>
@@ -0,0 +1,64 @@
<?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:Transform/>
</Components>
<Children>
<Entity>
<Components>
<c:AABB/>
<c:Collidable/>
<c:Model>
<Resource>Models/Core/UnitCube.obj</Resource>
<Color A="1" B="0.513725519" G="0" R="1"/>
</c:Model>
<c:Transform>
<Position X="0" Y="2" Z="0"/>
<Scale X="5" Y="1" Z="5"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="Player">
<Components>
<c:AABB>
<Origin X="0" Y="0.773000062" Z="0"/>
<Size X="1" Y="1.60000002" Z="1"/>
</c:AABB>
<c:Collidable/>
<c:Physics/>
<c:Model>
<Resource>Models/Assault.obj</Resource>
<Color A="1" B="1" G="0" R="0"/>
</c:Model>
<c:Player/>
<c:Transform>
<Position X="0" Y="2.52699995" Z="0.0542778969"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:Collidable/>
<c:Physics>
<Velocity X="0" Y="-0.0934068039" Z="0"/>
</c:Physics>
<c:Model>
<Resource>Models/Core/UnitCube.obj</Resource>
<Color A="1" B="0" G="1" R="1"/>
</c:Model>
<c:Player/>
<c:Transform>
<Position X="0" Y="4.15580511" Z="0"/>
<Scale X="0.704558551" Y="0.115156889" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
+17
View File
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity name="Player" 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/UnitSphere.obj</Resource>
<Color A="1" B="1" G="0" R="0"/>
</c:Model>
<c:Player/>
<c:Transform/>
</Components>
<Children/>
</Entity>
+1
View File
@@ -11,6 +11,7 @@
<xs:complexType>
<xs:all>
<xs:element ref="c:Transform" minOccurs="0"/>
<xs:element ref="c:Physics" minOccurs="0"/>
<xs:element ref="c:Model" minOccurs="0"/>
<xs:element ref="c:Test" minOccurs="0"/>
<xs:element ref="c:RaptorCopter" minOccurs="0"/>
+9 -1
View File
@@ -4,6 +4,11 @@
void CollisionSystem::UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& component, double dt)
{
if (!entity.HasComponent("Physics")) {
return;
}
ComponentWrapper& cPhysics = entity["Physics"];
boost::optional<AABB> boundingBox = Collision::EntityAbsoluteAABB(entity);
if (!boundingBox) {
return;
@@ -25,7 +30,10 @@ void CollisionSystem::UpdateComponent(World* world, EntityWrapper& entity, Compo
continue;
}
if (Collision::AABBVsAABB(boxA, boxB, resolutionVector)) {
(glm::vec3&)cTransform["Position"] += resolutionVector;
if (entity.HasComponent("Physics")) {
(glm::vec3&)cTransform["Position"] += resolutionVector;
cPhysics["Velocity"] = glm::vec3(0, 0, 0);
}
}
}
+4 -5
View File
@@ -11,16 +11,15 @@ include_directories(
)
file(GLOB SOURCE_FILES
"${INCLUDE_PATH}/*.h"
#"*.cpp"
"${INCLUDE_PATH}/Systems/*.h"
"Systems/*.cpp"
)
#source_group(Core FILES ${SOURCE_FILES})
source_group(Systems FILES ${SOURCE_FILES_Systems})
set(SOURCE_FILES
${SOURCE_FILES}
"Game.cpp"
"HealthSystem.cpp"
"PlayerSystem.cpp"
${SOURCE_FILES_Systems}
)
set(LIBRARIES
+5 -1
View File
@@ -2,7 +2,10 @@
#include "Collision/CollidableOctreeSystem.h"
#include "Collision/TriggerSystem.h"
#include "Collision/CollisionSystem.h"
#include "Game/HealthSystem.h"
#include "Systems/RaptorCopterSystem.h"
#include "Systems/PlayerSystem.h"
#include "Systems/HealthSystem.h"
#include "Systems/PlayerMovementSystem.h"
#include "Core/EntityFileWriter.h"
Game::Game(int argc, char* argv[])
@@ -69,6 +72,7 @@ Game::Game(int argc, char* argv[])
m_SystemPipeline->AddSystem<PlayerSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<EditorSystem>(updateOrderLevel, m_Renderer);
m_SystemPipeline->AddSystem<HealthSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<PlayerMovementSystem>(updateOrderLevel);
// Populate Octree with collidables
++updateOrderLevel;
m_SystemPipeline->AddSystem<CollidableOctreeSystem>(updateOrderLevel, m_OctreeCollision);
-6
View File
@@ -1,6 +0,0 @@
#include "RaptorCopterSystem.h"
void PlayerMovementSystem::UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& component, double dt)
{
ComponentWrapper& transform = world->GetComponent(component.EntityID);
}
@@ -1,5 +1,4 @@
#include "HealthSystem.h"
#include <algorithm>
#include "Systems/HealthSystem.h"
HealthSystem::HealthSystem(EventBroker* eventBroker)
: System(eventBroker)
+16
View File
@@ -0,0 +1,16 @@
#include "Systems/PlayerMovementSystem.h"
void PlayerMovementSystem::UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& component, double dt)
{
ComponentWrapper& cTransform = entity["Transform"];
if (!entity.HasComponent("Physics")) {
return;
}
ComponentWrapper& cPhysics = entity["Physics"];
glm::vec3& velocity = cPhysics["Velocity"];
velocity.y -= 9.82 * dt;
glm::vec3& position = cTransform["Position"];
position += velocity * (float)dt;
}
@@ -1,4 +1,4 @@
#include "PlayerSystem.h"
#include "Systems/PlayerSystem.h"
void PlayerSystem::UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& component, double dt)
{