From 0e9fb16399a648a4571351b579da9e02ecadd135 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Mon, 8 Feb 2016 17:58:07 +0100 Subject: [PATCH 01/11] Work started on DamageIndicatorSystem. Made some initial tests and test calculations --- include/Engine/Core/EPlayerDamage.h | 1 + include/Game/Systems/DamageIndicatorSystem.h | 41 ++ resources/Schema/Entities/GameMapTest.xml | 430 ++++++++++++++++++ .../Schema/Entities/SpriteTestTemporary.xml | 24 + src/Game/Game.cpp | 2 + src/Game/Systems/DamageIndicatorSystem.cpp | 101 ++++ 6 files changed, 599 insertions(+) create mode 100644 include/Game/Systems/DamageIndicatorSystem.h create mode 100644 resources/Schema/Entities/GameMapTest.xml create mode 100644 resources/Schema/Entities/SpriteTestTemporary.xml create mode 100644 src/Game/Systems/DamageIndicatorSystem.cpp diff --git a/include/Engine/Core/EPlayerDamage.h b/include/Engine/Core/EPlayerDamage.h index 8ba3907e..c11b121f 100644 --- a/include/Engine/Core/EPlayerDamage.h +++ b/include/Engine/Core/EPlayerDamage.h @@ -11,6 +11,7 @@ struct PlayerDamage : Event { //NOTE: this struct is missing information on what the damageSource is EntityWrapper Player; + EntityWrapper PlayerShooter; double Damage; }; diff --git a/include/Game/Systems/DamageIndicatorSystem.h b/include/Game/Systems/DamageIndicatorSystem.h new file mode 100644 index 00000000..646887e2 --- /dev/null +++ b/include/Game/Systems/DamageIndicatorSystem.h @@ -0,0 +1,41 @@ +#ifndef DamageIndicatorSystem_h__ +#define DamageIndicatorSystem_h__ + +#include "Core/System.h" +#include "Core/Transform.h" +#include "Core/ResourceManager.h" +#include "Core/EntityFileParser.h" +#include "Core/EPickupSpawned.h" +#include "Core/EPlayerDamage.h" +#include "Engine/Collision/ETrigger.h" +#include "Common.h" +#include + +//temp +#include "Input/EInputCommand.h" +#include "Rendering/ESetCamera.h" + +#include + +class DamageIndicatorSystem : public ImpureSystem +{ +public: + DamageIndicatorSystem(World* world, EventBroker* eventBroker); + + virtual void Update(double dt) override; + +private: + + EventRelay m_DamageTakenFromPlayer; + bool OnPlayerDamageTaken(Events::PlayerDamage& e); + + //temp + EventRelay m_EInputCommand; + bool OnInputCommand(Events::InputCommand& e); + + EventRelay m_ESetCamera; + bool OnSetCamera(const Events::SetCamera& e); + + EntityID m_CurrentCamera = -1; +}; +#endif diff --git a/resources/Schema/Entities/GameMapTest.xml b/resources/Schema/Entities/GameMapTest.xml new file mode 100644 index 00000000..ee68da96 --- /dev/null +++ b/resources/Schema/Entities/GameMapTest.xml @@ -0,0 +1,430 @@ + + + + + + + + + + + + + + + Models\MapVersion1.mesh + + + + + + + + + 2 + + + Models/DirectionalLightWidget.mesh + false + + + + + + + + + + + + + 8 + 2.7999999523162842 + + + + + + + + + + + 8 + 2.7999999523162842 + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + false + + + Schema/Entities/Player.xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Models/Core/UnitCube.mesh + false + + + Schema/Entities/Player.xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 99 + + + + + + 5 + + + + + + + + + + + + + + + + + + + + + + + Fonts/DroidSans.ttf,100 + + + + + + + + + + + + + + Models/Camera.mesh + false + + + + + + + + + + + + + + + + + + + 0.99000000953674316 + + + + + Models/Core/UnitHexagon.mesh + + + + + + + + + + + + + + Models/CrosshairQuad.mesh + + + + + + + + + + + + + Models/AssaultWeaponRed.mesh + + + + + + + + + + + + + + + + + + + + + + + + + Models/Camera.mesh + false + + + + + + + + + + + + Hold Pos + + 1 + + + + Models/AssaultAnimated.mesh + + + + + + + + + + Models/Core/UnitCube.mesh + + false + + + + + + + + + + + + Models/Core/UnitCube.mesh + + false + + + + + + + + + + + + diff --git a/resources/Schema/Entities/SpriteTestTemporary.xml b/resources/Schema/Entities/SpriteTestTemporary.xml new file mode 100644 index 00000000..f66e9158 --- /dev/null +++ b/resources/Schema/Entities/SpriteTestTemporary.xml @@ -0,0 +1,24 @@ + + + + + + Textures/DefenderGunRedDiff.png + Textures/DefenderGunRedIncd.png + + + + Models/Core/UnitQuad.mesh + + + + + + + 1.5 + + + + + + diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 0cc41a73..5875bc81 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -12,6 +12,7 @@ #include "Core/EntityFileWriter.h" #include "Game/Systems/CapturePointSystem.h" #include "Game/Systems/PickupSpawnSystem.h" +#include "Game/Systems/DamageIndicatorSystem.h" #include "Game/Systems/WeaponSystem.h" #include "Game/Systems/PlayerHUD.h" #include "Game/Systems/LifetimeSystem.h" @@ -96,6 +97,7 @@ Game::Game(int argc, char* argv[]) m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); + m_SystemPipeline->AddSystem(updateOrderLevel); // Populate Octree with collidables ++updateOrderLevel; m_SystemPipeline->AddSystem(updateOrderLevel, m_OctreeCollision, "Collidable"); diff --git a/src/Game/Systems/DamageIndicatorSystem.cpp b/src/Game/Systems/DamageIndicatorSystem.cpp new file mode 100644 index 00000000..5f6ad725 --- /dev/null +++ b/src/Game/Systems/DamageIndicatorSystem.cpp @@ -0,0 +1,101 @@ +#include "Systems/DamageIndicatorSystem.h" + +DamageIndicatorSystem::DamageIndicatorSystem(World* m_World, EventBroker* eventBroker) + : System(m_World, eventBroker) +{ + EVENT_SUBSCRIBE_MEMBER(m_DamageTakenFromPlayer, &DamageIndicatorSystem::OnPlayerDamageTaken); + //TEMP + EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &DamageIndicatorSystem::OnInputCommand); + //current camera + EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &DamageIndicatorSystem::OnSetCamera); + +} + +void DamageIndicatorSystem::Update(double dt) +{ + +} + + +bool DamageIndicatorSystem::OnPlayerDamageTaken(Events::PlayerDamage& e) +{ + auto test1 = (glm::vec3)e.PlayerShooter["Transform"]["Orientation"]; + auto test2 = (glm::vec3)e.Player["Transform"]["Orientation"]; + //calculate direction + auto enemyOrientation = glm::quat(((glm::vec3)e.PlayerShooter["Transform"]["Orientation"])); + auto playerOrientation = glm::quat((glm::vec3)e.Player["Transform"]["Orientation"]); + //calculate difference in angle (quaternion math) + auto angle1 = glm::angle(playerOrientation); + auto angle2 = glm::angle(enemyOrientation); + auto quat = glm::angleAxis(angle2 - angle1, glm::vec3(0, 1, 0)); + auto vec3Orientation = glm::eulerAngles(quat); + + //load & set the "2d" sprite + auto entityFile = ResourceManager::Load("Schema/Entities/SpriteTestTemporary.xml"); + EntityFileParser parser(entityFile); + EntityID spriteID = parser.MergeEntities(m_World); + m_World->SetParent(spriteID, m_CurrentCamera); + auto cameraWrapper = EntityWrapper(m_World, spriteID); + cameraWrapper["Transform"]["Orientation"] = vec3Orientation; + + return true; +} + +//TEMP +bool DamageIndicatorSystem::OnInputCommand(Events::InputCommand& e) +{ + if (e.Command != "Jump" || e.Value > 0) { + return false; + } + //auto entityFile = ResourceManager::Load("Schema/Entities/SpriteTestTemporary.xml"); + //EntityFileParser parser(entityFile); + //EntityID spriteID = parser.MergeEntities(m_World); + ////get currently active camera + ////auto cameras = m_World->GetComponents("Camera"); + ////for (auto& cCamera : *cameras) { + //// + //// //auto temp = m_World->GetParent(cCamera.EntityID); + //// m_World->SetParent(spriteID, cCamera.EntityID); + ////} + ////m_CurrentCamera + //m_World->SetParent(spriteID, m_CurrentCamera); + + //auto cameraWrapper = EntityWrapper(m_World, spriteID); + //cameraWrapper["Transform"]["Orientation"] = glm::vec3(1, 1, 1); + //ray player-enemyplayer eller bara spelarnas direction + + + //TODO: life time, rotering +//den ska väl vara där hela tiden, bara det att den inte syns + + + //EntityWrapper(m_World, spriteID); + + auto players = m_World->GetComponents("Player"); + EntityID id1 = (*players->begin()).EntityID; + EntityID id2; + int lameCounter = 0; + for (auto& cPlayers : *players) { + if (lameCounter == 1) { + id2 = cPlayers.EntityID; + } + lameCounter++; + } + if (lameCounter != 2) { + return false; + } + + //do something here + Events::PlayerDamage ePlayerDamage; + ePlayerDamage.Player = EntityWrapper(m_World, id1); + ePlayerDamage.PlayerShooter = EntityWrapper(m_World, id2); + ePlayerDamage.Damage = 1; + m_EventBroker->Publish(ePlayerDamage); + + return true; +} + +bool DamageIndicatorSystem::OnSetCamera(const Events::SetCamera& e) { + m_CurrentCamera = e.CameraEntity.ID; + return true; +} \ No newline at end of file From 971fee4a0cfaa0b9017718a8a9e2ade928bc05f2 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Tue, 9 Feb 2016 15:38:21 +0100 Subject: [PATCH 02/11] DamageIndicatorSystem code looking good. Test working well. Sprite display fixed by Viktor --- include/Game/Systems/DamageIndicatorSystem.h | 1 + .../Schema/Entities/SpriteTestTemporary.xml | 7 +--- resources/Shaders/Sprite.vert.glsl | 2 +- src/Game/Systems/DamageIndicatorSystem.cpp | 42 +++++++++++++++---- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/include/Game/Systems/DamageIndicatorSystem.h b/include/Game/Systems/DamageIndicatorSystem.h index 646887e2..561654d1 100644 --- a/include/Game/Systems/DamageIndicatorSystem.h +++ b/include/Game/Systems/DamageIndicatorSystem.h @@ -16,6 +16,7 @@ #include "Rendering/ESetCamera.h" #include +#include class DamageIndicatorSystem : public ImpureSystem { diff --git a/resources/Schema/Entities/SpriteTestTemporary.xml b/resources/Schema/Entities/SpriteTestTemporary.xml index f66e9158..2d02443c 100644 --- a/resources/Schema/Entities/SpriteTestTemporary.xml +++ b/resources/Schema/Entities/SpriteTestTemporary.xml @@ -3,13 +3,10 @@ - Textures/DefenderGunRedDiff.png - Textures/DefenderGunRedIncd.png + Textures/TempDamageIndicator.png + Textures/TempDamageIndicator.png - - Models/Core/UnitQuad.mesh - diff --git a/resources/Shaders/Sprite.vert.glsl b/resources/Shaders/Sprite.vert.glsl index e910a26a..61b387ad 100644 --- a/resources/Shaders/Sprite.vert.glsl +++ b/resources/Shaders/Sprite.vert.glsl @@ -16,7 +16,7 @@ out VertexData{ void main() { - gl_Position = P * M * vec4(Position, 1.0); + gl_Position = P * V * M * vec4(Position, 1.0); Output.Position = Position; Output.TextureCoordinate = TextureCoords; diff --git a/src/Game/Systems/DamageIndicatorSystem.cpp b/src/Game/Systems/DamageIndicatorSystem.cpp index 5f6ad725..24d1cfa4 100644 --- a/src/Game/Systems/DamageIndicatorSystem.cpp +++ b/src/Game/Systems/DamageIndicatorSystem.cpp @@ -21,22 +21,46 @@ bool DamageIndicatorSystem::OnPlayerDamageTaken(Events::PlayerDamage& e) { auto test1 = (glm::vec3)e.PlayerShooter["Transform"]["Orientation"]; auto test2 = (glm::vec3)e.Player["Transform"]["Orientation"]; - //calculate direction - auto enemyOrientation = glm::quat(((glm::vec3)e.PlayerShooter["Transform"]["Orientation"])); + + //grab players direction auto playerOrientation = glm::quat((glm::vec3)e.Player["Transform"]["Orientation"]); - //calculate difference in angle (quaternion math) - auto angle1 = glm::angle(playerOrientation); - auto angle2 = glm::angle(enemyOrientation); - auto quat = glm::angleAxis(angle2 - angle1, glm::vec3(0, 1, 0)); - auto vec3Orientation = glm::eulerAngles(quat); + + //get the position vectors, but ignore the y-height + auto enemyPosition = (glm::vec3) e.PlayerShooter["Transform"]["Position"]; + auto playerPosition = (glm::vec3) e.Player["Transform"]["Position"]; + enemyPosition.y = 0.0f; + playerPosition.y = 0.0f; + + //calculate the enemy to player vector + auto enemyPlayerVector = glm::normalize((glm::vec3) playerPosition - enemyPosition); + + //get angle from players current rotation, this angle is how much you rotate around the y-axis + auto playerAngle = glm::angle(playerOrientation); + auto playerRotationVector = glm::normalize(glm::rotateY(glm::vec3(0, 0, 1), playerAngle)); + + //dot product of players direction-vector and enemys-to-playervector will give the cos of the angle between the vectors + auto playerRotationDot = glm::dot(playerRotationVector, enemyPlayerVector); + //to get the angle between the vectors just do cos-inverse + auto angleBetweenVectors = glm::acos(playerRotationDot); + + //rotate the direction-vector 90 degrees to get the players side-vector + auto playerSideVector = glm::normalize(glm::rotateY(glm::vec3(0, 0, 1), playerAngle + 1.57f)); + //dot of sidevector positive = enemy is on the right side, dot sidevector negative = left side + auto playerSideVectorDot = glm::dot(playerSideVector, enemyPlayerVector); + if (playerSideVectorDot < 0) { + angleBetweenVectors = -angleBetweenVectors; + } + + //LOG_INFO("vector angle %f %f %f %f", t1, t3, t4, enemyPlayerVector.x); //load & set the "2d" sprite auto entityFile = ResourceManager::Load("Schema/Entities/SpriteTestTemporary.xml"); EntityFileParser parser(entityFile); EntityID spriteID = parser.MergeEntities(m_World); m_World->SetParent(spriteID, m_CurrentCamera); - auto cameraWrapper = EntityWrapper(m_World, spriteID); - cameraWrapper["Transform"]["Orientation"] = vec3Orientation; + auto spriteWrapper = EntityWrapper(m_World, spriteID); + //simply set the rotation z-wise to the angleBetweenVectors + spriteWrapper["Transform"]["Orientation"] = glm::vec3(0, 0, angleBetweenVectors); return true; } From 8bdf87da12663aeb6b8b6a23b7288b032411b8f0 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Tue, 9 Feb 2016 16:15:19 +0100 Subject: [PATCH 03/11] Some cleanup of the code --- include/Game/Systems/DamageIndicatorSystem.h | 14 +--- src/Game/Systems/DamageIndicatorSystem.cpp | 70 +------------------- src/Game/Systems/WeaponSystem.cpp | 1 + 3 files changed, 5 insertions(+), 80 deletions(-) diff --git a/include/Game/Systems/DamageIndicatorSystem.h b/include/Game/Systems/DamageIndicatorSystem.h index 561654d1..fd3ba33f 100644 --- a/include/Game/Systems/DamageIndicatorSystem.h +++ b/include/Game/Systems/DamageIndicatorSystem.h @@ -5,35 +5,23 @@ #include "Core/Transform.h" #include "Core/ResourceManager.h" #include "Core/EntityFileParser.h" -#include "Core/EPickupSpawned.h" #include "Core/EPlayerDamage.h" -#include "Engine/Collision/ETrigger.h" #include "Common.h" #include -//temp -#include "Input/EInputCommand.h" #include "Rendering/ESetCamera.h" - #include #include -class DamageIndicatorSystem : public ImpureSystem +class DamageIndicatorSystem : public System { public: DamageIndicatorSystem(World* world, EventBroker* eventBroker); - virtual void Update(double dt) override; - private: - EventRelay m_DamageTakenFromPlayer; bool OnPlayerDamageTaken(Events::PlayerDamage& e); - //temp - EventRelay m_EInputCommand; - bool OnInputCommand(Events::InputCommand& e); - EventRelay m_ESetCamera; bool OnSetCamera(const Events::SetCamera& e); diff --git a/src/Game/Systems/DamageIndicatorSystem.cpp b/src/Game/Systems/DamageIndicatorSystem.cpp index 24d1cfa4..0acb24c3 100644 --- a/src/Game/Systems/DamageIndicatorSystem.cpp +++ b/src/Game/Systems/DamageIndicatorSystem.cpp @@ -4,23 +4,15 @@ DamageIndicatorSystem::DamageIndicatorSystem(World* m_World, EventBroker* eventB : System(m_World, eventBroker) { EVENT_SUBSCRIBE_MEMBER(m_DamageTakenFromPlayer, &DamageIndicatorSystem::OnPlayerDamageTaken); - //TEMP - EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &DamageIndicatorSystem::OnInputCommand); //current camera EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &DamageIndicatorSystem::OnSetCamera); - } -void DamageIndicatorSystem::Update(double dt) -{ - -} - - bool DamageIndicatorSystem::OnPlayerDamageTaken(Events::PlayerDamage& e) { - auto test1 = (glm::vec3)e.PlayerShooter["Transform"]["Orientation"]; - auto test2 = (glm::vec3)e.Player["Transform"]["Orientation"]; + if (m_CurrentCamera == -1) { + return false; + } //grab players direction auto playerOrientation = glm::quat((glm::vec3)e.Player["Transform"]["Orientation"]); @@ -51,8 +43,6 @@ bool DamageIndicatorSystem::OnPlayerDamageTaken(Events::PlayerDamage& e) angleBetweenVectors = -angleBetweenVectors; } - //LOG_INFO("vector angle %f %f %f %f", t1, t3, t4, enemyPlayerVector.x); - //load & set the "2d" sprite auto entityFile = ResourceManager::Load("Schema/Entities/SpriteTestTemporary.xml"); EntityFileParser parser(entityFile); @@ -65,60 +55,6 @@ bool DamageIndicatorSystem::OnPlayerDamageTaken(Events::PlayerDamage& e) return true; } -//TEMP -bool DamageIndicatorSystem::OnInputCommand(Events::InputCommand& e) -{ - if (e.Command != "Jump" || e.Value > 0) { - return false; - } - //auto entityFile = ResourceManager::Load("Schema/Entities/SpriteTestTemporary.xml"); - //EntityFileParser parser(entityFile); - //EntityID spriteID = parser.MergeEntities(m_World); - ////get currently active camera - ////auto cameras = m_World->GetComponents("Camera"); - ////for (auto& cCamera : *cameras) { - //// - //// //auto temp = m_World->GetParent(cCamera.EntityID); - //// m_World->SetParent(spriteID, cCamera.EntityID); - ////} - ////m_CurrentCamera - //m_World->SetParent(spriteID, m_CurrentCamera); - - //auto cameraWrapper = EntityWrapper(m_World, spriteID); - //cameraWrapper["Transform"]["Orientation"] = glm::vec3(1, 1, 1); - //ray player-enemyplayer eller bara spelarnas direction - - - //TODO: life time, rotering -//den ska väl vara där hela tiden, bara det att den inte syns - - - //EntityWrapper(m_World, spriteID); - - auto players = m_World->GetComponents("Player"); - EntityID id1 = (*players->begin()).EntityID; - EntityID id2; - int lameCounter = 0; - for (auto& cPlayers : *players) { - if (lameCounter == 1) { - id2 = cPlayers.EntityID; - } - lameCounter++; - } - if (lameCounter != 2) { - return false; - } - - //do something here - Events::PlayerDamage ePlayerDamage; - ePlayerDamage.Player = EntityWrapper(m_World, id1); - ePlayerDamage.PlayerShooter = EntityWrapper(m_World, id2); - ePlayerDamage.Damage = 1; - m_EventBroker->Publish(ePlayerDamage); - - return true; -} - bool DamageIndicatorSystem::OnSetCamera(const Events::SetCamera& e) { m_CurrentCamera = e.CameraEntity.ID; return true; diff --git a/src/Game/Systems/WeaponSystem.cpp b/src/Game/Systems/WeaponSystem.cpp index 1613cb7a..bc7c86b6 100644 --- a/src/Game/Systems/WeaponSystem.cpp +++ b/src/Game/Systems/WeaponSystem.cpp @@ -134,6 +134,7 @@ bool WeaponSystem::OnShoot(Events::Shoot& eShoot) // TODO: Weapon damage calculations etc Events::PlayerDamage ePlayerDamage; ePlayerDamage.Player = player; + ePlayerDamage.PlayerShooter = eShoot.Player; ePlayerDamage.Damage = 100; m_EventBroker->Publish(ePlayerDamage); From e9f5a3d263bc6a00b7526db945732e7dcfc448d0 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Tue, 9 Feb 2016 16:28:43 +0100 Subject: [PATCH 04/11] Renamed some files from temporary filenames to DamageIndicator filenames --- .../Entities/{SpriteTestTemporary.xml => DamageIndicator.xml} | 0 .../Entities/{GameMapTest.xml => DamageIndicatorTest.xml} | 0 src/Game/Systems/DamageIndicatorSystem.cpp | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename resources/Schema/Entities/{SpriteTestTemporary.xml => DamageIndicator.xml} (100%) rename resources/Schema/Entities/{GameMapTest.xml => DamageIndicatorTest.xml} (100%) diff --git a/resources/Schema/Entities/SpriteTestTemporary.xml b/resources/Schema/Entities/DamageIndicator.xml similarity index 100% rename from resources/Schema/Entities/SpriteTestTemporary.xml rename to resources/Schema/Entities/DamageIndicator.xml diff --git a/resources/Schema/Entities/GameMapTest.xml b/resources/Schema/Entities/DamageIndicatorTest.xml similarity index 100% rename from resources/Schema/Entities/GameMapTest.xml rename to resources/Schema/Entities/DamageIndicatorTest.xml diff --git a/src/Game/Systems/DamageIndicatorSystem.cpp b/src/Game/Systems/DamageIndicatorSystem.cpp index 0acb24c3..638307bf 100644 --- a/src/Game/Systems/DamageIndicatorSystem.cpp +++ b/src/Game/Systems/DamageIndicatorSystem.cpp @@ -44,7 +44,7 @@ bool DamageIndicatorSystem::OnPlayerDamageTaken(Events::PlayerDamage& e) } //load & set the "2d" sprite - auto entityFile = ResourceManager::Load("Schema/Entities/SpriteTestTemporary.xml"); + auto entityFile = ResourceManager::Load("Schema/Entities/DamageIndicator.xml"); EntityFileParser parser(entityFile); EntityID spriteID = parser.MergeEntities(m_World); m_World->SetParent(spriteID, m_CurrentCamera); From b6b96c5f11f52b12954ac170b9496330668ced1e Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Wed, 10 Feb 2016 11:51:58 +0100 Subject: [PATCH 05/11] Added DoubleJumpHexagon entity. Spawned DoubleJumpHexagon as the player doublejumps. Fixed DoubleJumping bug where you couldnt doublejump on rocks (where velocity wasnt 0.0) --- include/Game/Systems/PlayerMovementSystem.h | 3 ++ resources/DefaultInput.ini | 3 ++ .../Schema/Entities/DoubleJumpHexagon.xml | 30 +++++++++++++++++++ src/Game/Systems/PlayerMovementSystem.cpp | 8 ++++- 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 resources/Schema/Entities/DoubleJumpHexagon.xml diff --git a/include/Game/Systems/PlayerMovementSystem.h b/include/Game/Systems/PlayerMovementSystem.h index 34862e90..a0194545 100644 --- a/include/Game/Systems/PlayerMovementSystem.h +++ b/include/Game/Systems/PlayerMovementSystem.h @@ -5,6 +5,9 @@ #include "Input/FirstPersonInputController.h" #include +#include "Core/EntityFile.h" +#include "Core/EntityFileParser.h" + class PlayerMovementSystem : public ImpureSystem, PureSystem { public: diff --git a/resources/DefaultInput.ini b/resources/DefaultInput.ini index 589dfb3f..eb5b7658 100644 --- a/resources/DefaultInput.ini +++ b/resources/DefaultInput.ini @@ -2,6 +2,9 @@ Sensitivity=0.5 InvertPitch=false +[KeyBoard] +DoubleTapToDash=true + [Bindings] MouseLeft=PrimaryFire MouseX=Yaw diff --git a/resources/Schema/Entities/DoubleJumpHexagon.xml b/resources/Schema/Entities/DoubleJumpHexagon.xml new file mode 100644 index 00000000..bbc41119 --- /dev/null +++ b/resources/Schema/Entities/DoubleJumpHexagon.xml @@ -0,0 +1,30 @@ + + + + + + Models/JumpEffectHexagon.mesh + + true + + + + + + + 1.5 + + + true + + + true + 3 + + true + + + + + + diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 52890c3a..6b26db1c 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -90,9 +90,15 @@ void PlayerMovementSystem::Update(double dt) //you cant jump and dash at the same time - since there is no friction in the air and we would thus dash much further in the air if (!controller->PlayerIsDashing() && controller->Jumping() && !controller->Crouching() && (isOnGround || !controller->DoubleJumping())) { (bool)cPhysics["IsOnGround"] = false; - if (velocity.y == 0.f) { + if (isOnGround) { controller->SetDoubleJumping(false); } else { + //put a hexagon at the players feet + auto hexagonEffect = ResourceManager::Load("Schema/Entities/DoubleJumpHexagon.xml"); + EntityFileParser parser(hexagonEffect); + EntityID hexagonEffectID = parser.MergeEntities(m_World); + EntityWrapper hexagonEW = EntityWrapper(m_World, hexagonEffectID); + hexagonEW["Transform"]["Position"] = (glm::vec3)player["Transform"]["Position"]; controller->SetDoubleJumping(true); } velocity.y = 4.f; From a53ab7f74574e2bdd018563ded7a62d2a7357314 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Wed, 10 Feb 2016 20:46:16 +0100 Subject: [PATCH 06/11] A few fixes for DashAbility. Default DoubleTapToDash is now set to false. --- .../Engine/Input/FirstPersonInputController.h | 25 +++++++++++-------- resources/DefaultInput.ini | 4 +-- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/include/Engine/Input/FirstPersonInputController.h b/include/Engine/Input/FirstPersonInputController.h index 2bbd768d..20402cd0 100644 --- a/include/Engine/Input/FirstPersonInputController.h +++ b/include/Engine/Input/FirstPersonInputController.h @@ -54,6 +54,7 @@ protected: //specialabilitys bool m_MovementKeyDown = false; bool m_SpecialAbilityKeyDown = false; + int m_NumberOfMovementKeysDown = 0; EventRelay m_ELockMouse; bool OnLockMouse(const Events::LockMouse& e); @@ -131,6 +132,7 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm } //if value = 0 then you have just released this key if (e.Value != 0) { + m_NumberOfMovementKeysDown++; m_MovementKeyDown = true; //if you pressed the same key within m_AssaultDashDoubleTapSensitivityTimer then you have doubletapped it if (m_AssaultDashDoubleTapDeltaTime < m_AssaultDashDoubleTapSensitivityTimer && m_AssaultDashTapDirection == m_CurrentDirectionVector) { @@ -138,10 +140,14 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm } } else { //== 0 - m_MovementKeyDown = false; - //you have just released the key, store what key it was and reset the doubletap-sensitivity-timer - m_AssaultDashTapDirection = m_CurrentDirectionVector; - m_AssaultDashDoubleTapDeltaTime = 0.f; + m_NumberOfMovementKeysDown--; + if (m_NumberOfMovementKeysDown == 0) { + m_MovementKeyDown = false; + } + //you have just released the key, store what key it was and reset the doubletap-sensitivity-timer + m_AssaultDashTapDirection = m_CurrentDirectionVector; + m_AssaultDashDoubleTapDeltaTime = 0.f; + } } @@ -201,12 +207,6 @@ void FirstPersonInputController::AssaultDashCheck(double dt, bool m_AssaultDashCoolDownTimer = assaultDashCoolDownMaxTimer; m_AssaultDashDoubleTapped = true; m_AssaultDashDoubleTapDeltaTime = 0.f; - //moving to the side has priority - return; - } - - //dashing with doubletap - check if doubletap to dash enabled - if (ResourceManager::Load("Input.ini")->Get("Keyboard.DoubleTapToDash", false)) { return; } @@ -215,6 +215,11 @@ void FirstPersonInputController::AssaultDashCheck(double dt, bool m_AssaultDashDoubleTapped = false; } + //dashing with doubletap - check if doubletap to dash enabled + if (!ResourceManager::Load("Input.ini")->Get("Keyboard.DoubleTapToDash", false)) { + return; + } + //check if we have received a valid doubletap if (!m_ValidDoubleTap) { return; diff --git a/resources/DefaultInput.ini b/resources/DefaultInput.ini index eb5b7658..35aceeb1 100644 --- a/resources/DefaultInput.ini +++ b/resources/DefaultInput.ini @@ -2,8 +2,8 @@ Sensitivity=0.5 InvertPitch=false -[KeyBoard] -DoubleTapToDash=true +[Keyboard] +DoubleTapToDash=false [Bindings] MouseLeft=PrimaryFire From 73f59b89ccce4709376beb9cc5273f68afc71178 Mon Sep 17 00:00:00 2001 From: William Moberg Date: Thu, 11 Feb 2016 00:11:37 +0100 Subject: [PATCH 07/11] Added method EntityFirstHitByRay, takes an Octree or a vector of sorted entities and outputs the frist entity hit by a ray. --- include/Engine/Collision/Collision.h | 23 +++++++-- include/Engine/Core/Octree.h | 75 ++++++++++++++++++++++++++++ src/Engine/Collision/Collision.cpp | 66 ++++++++++++++++++------ src/Engine/Core/Octree.cpp | 25 +++------- 4 files changed, 151 insertions(+), 38 deletions(-) diff --git a/include/Engine/Collision/Collision.h b/include/Engine/Collision/Collision.h index c3759393..5b4150d8 100644 --- a/include/Engine/Collision/Collision.h +++ b/include/Engine/Collision/Collision.h @@ -20,6 +20,9 @@ class World; struct ComponentWrapper; +template +class Octree; + namespace Collision { //Return true if the ray hits the box. @@ -44,21 +47,24 @@ bool RayVsTriangle(const Ray& ray, float& outVCoord, bool trueOnNegativeDistance = false); //Return true if the ray hits any of the triangles in the model. Stops checking when a hit is detected. -bool RayVsModel(const Ray& ray, - const std::vector& modelVertices, - const std::vector& modelIndices); +bool RayVsModel(const Ray& ray, + const RawModel::Vertex* modelVertices, + const std::vector& modelIndices, + const glm::mat4& modelMatrix); //Return true if the ray hits any of the triangles in the model. //Also returns the position of the intersection point. Will loop through all the whole model indices. bool RayVsModel(const Ray& ray, - const std::vector& modelVertices, + const RawModel::Vertex* modelVertices, const std::vector& modelIndices, + const glm::mat4& modelMatrix, glm::vec3& outHitPosition); //Return true if the ray hits any of the triangles in the model. //Also returns the distance from the ray origin to the closest //intersection point, and the barycentric u,v-coordinates. Will loop through all the whole model indices. bool RayVsModel(const Ray& ray, - const std::vector& modelVertices, + const RawModel::Vertex* modelVertices, const std::vector& modelIndices, + const glm::mat4& modelMatrix, float& outDistance, float& outUCoord, float& outVCoord); @@ -81,6 +87,13 @@ bool AABBVsAABB(const AABB& a, const AABB& b, glm::vec3& minimumTranslation); // Calculates an absolute AABB from an entity AABB component boost::optional EntityAbsoluteAABB(EntityWrapper& entity, bool takeModelBox = false); boost::optional AbsoluteAABBExplosionEffect(EntityWrapper& entity); +//Returns the first entity hit by the input ray. entitiesPotentiallyHitSorted needs to be sorted +//by their distance to the ray, e.g. result from Octree::ObjectsPossiblyHitByRay. +//Returns boost::none if none was hit. outDistance will be the distance to the intersection point if the ray intersects. +boost::optional EntityFirstHitByRay(const Ray& ray, std::vector entitiesPotentiallyHitSorted, float outDistance, glm::vec3& outIntersectPos); +//Returns the first entity hit by the input ray that exists in the octree. +//outDistance will be the distance to the intersection point if the ray intersects. +boost::optional EntityFirstHitByRay(const Ray& ray, Octree* octree, float outDistance, glm::vec3& outIntersectPos); } diff --git a/include/Engine/Core/Octree.h b/include/Engine/Core/Octree.h index 6bdea4d3..be0cac95 100644 --- a/include/Engine/Core/Octree.h +++ b/include/Engine/Core/Octree.h @@ -43,6 +43,8 @@ public: void ObjectsInSameRegion(const Box& box, std::vector& outObjects); //Get the objects that are inside the frustum, the objects are put in outObjects. void ObjectsInFrustum(const Frustum& frustum, std::vector& outObjects); + //Get objects, which AABB the input ray intersects, the objects are put in outObjects. + void ObjectsPossiblyHitByRay(const Ray& ray, std::vector& outObjects); //Empty the tree of all objects, static and dynamic. void ClearObjects(); //Empty the tree of all dynamic objects. Static objects remain in the tree. @@ -102,6 +104,8 @@ struct Child void ObjectsInSameRegion(const Box& box, std::vector& outObjects) const; template void ObjectsInFrustum(const Frustum& frustum, std::vector& outObjects, bool takeAllDontTest) const; + template + void ObjectsPossiblyHitByRay(const Ray& ray, std::vector& outObjects) const; void ClearObjects(); void ClearDynamicObjects(); bool RayCollides(const Ray& ray, Output& data) const; @@ -121,6 +125,15 @@ struct Child std::vector childIndicesContainingBox(const AABB& box) const; }; +//To be able to sort child nodes and contained objects based on distance to ray origin. +struct RaySorterInfo +{ + int Index; + float Distance; +}; + +bool isFirstLower(const RaySorterInfo& first, const RaySorterInfo& second); + } template @@ -166,6 +179,13 @@ void Octree::ObjectsInFrustum(const Frustum& frustum, std::vector& outObje m_Root->ObjectsInFrustum(frustum, outObjects, false); } +template +void Octree::ObjectsPossiblyHitByRay(const Ray& ray, std::vector& outObjects) +{ + falsifyObjectChecks(); + m_Root->ObjectsPossiblyHitByRay(ray, outObjects); +} + template void Octree::ClearObjects() { @@ -284,4 +304,59 @@ void OctSpace::Child::ObjectsInFrustum(const Frustum& frustum, std::vector& o } } +template +void OctSpace::Child::ObjectsPossiblyHitByRay(const Ray& ray, std::vector& outObjects) const +{ + //If the node AABB is missed, everything it contains is missed. + if (Collision::RayAABBIntr(ray, m_Box)) { + //If the ray shoots the tree, and it is a parent. + if (hasChildren()) { + //Sort children according to their distance from the ray origin. + std::vector childInfos; + childInfos.resize(8); + for (int i = 0; i < 8; ++i) { + childInfos[i] = { i, glm::distance(ray.Origin(), m_Children[i]->m_Box.Origin()) }; + } + std::sort(childInfos.begin(), childInfos.end(), isFirstLower); + //Loop through the children, starting with the one closest to the ray origin. I.e the first to be hit. + for (const RaySorterInfo& info : childInfos) { + m_Children[info.Index]->ObjectsPossiblyHitByRay(ray, outObjects); + } + } else { + //Check against boxes in the node. + bool intersected = false; + float dist; + //Sort all contained objects according to the distance from the ray origin to + //the intersection, if they are intersecting. + std::vector objectHitInfos; + objectHitInfos.reserve(m_StaticObjIndices.size() + m_DynamicObjIndices.size()); + for (int i : m_StaticObjIndices) { + //If we haven't tested against this object before, and the ray hits. + if (!m_StaticObjectsRef[i].Checked && + Collision::RayVsAABB(ray, *m_StaticObjectsRef[i].Box, dist)) { + objectHitInfos.push_back({ i, dist }); + } + m_StaticObjectsRef[i].Checked = true; + } + for (int i : m_DynamicObjIndices) { + //If we haven't tested against this object before, and the ray hits. + if (!m_DynamicObjectsRef[i].Checked && + Collision::RayVsAABB(ray, *m_DynamicObjectsRef[i].Box, dist)) { + objectHitInfos.push_back({ i + (int)m_StaticObjIndices.size(), dist }); + } + m_DynamicObjectsRef[i].Checked = true; + } + std::sort(objectHitInfos.begin(), objectHitInfos.end(), isFirstLower); + int startSize = (int)outObjects.size(); + outObjects.resize(startSize + objectHitInfos.size()); + for (int i = 0; i < objectHitInfos.size(); ++i) { + outObjects[startSize + i] = (objectHitInfos[i].Index < m_StaticObjIndices.size()) ? + *static_cast(m_StaticObjectsRef[objectHitInfos[i].Index].Box.get()) : + *static_cast(m_DynamicObjectsRef[objectHitInfos[i].Index - m_StaticObjIndices.size()].Box.get()); + } + } + } +} + + #endif \ No newline at end of file diff --git a/src/Engine/Collision/Collision.cpp b/src/Engine/Collision/Collision.cpp index b7b21969..7b182de1 100644 --- a/src/Engine/Collision/Collision.cpp +++ b/src/Engine/Collision/Collision.cpp @@ -6,6 +6,7 @@ #include "Core/World.h" #include "Rendering/Model.h" #include "imgui/imgui.h" +#include "Core/Octree.h" namespace Collision { @@ -145,13 +146,14 @@ bool RayVsTriangle(const Ray& ray, } bool RayVsModel(const Ray& ray, - const std::vector& modelVertices, - const std::vector& modelIndices) + const RawModel::Vertex* modelVertices, + const std::vector& modelIndices, + const glm::mat4& modelMatrix) { - for (int i = 0; i < modelIndices.size(); ++i) { - glm::vec3 v0 = modelVertices[modelIndices[i]].Position; - glm::vec3 v1 = modelVertices[modelIndices[++i]].Position; - glm::vec3 v2 = modelVertices[modelIndices[++i]].Position; + for (int i = 0; i < modelIndices.size();) { + glm::vec3 v0 = Transform::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix); + glm::vec3 v1 = Transform::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix); + glm::vec3 v2 = Transform::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix); if (RayVsTriangle(ray, v0, v1, v2)) { return true; } @@ -192,19 +194,20 @@ bool RayVsTriangle(const Ray& ray, } bool RayVsModel(const Ray& ray, - const std::vector& modelVertices, + const RawModel::Vertex* modelVertices, const std::vector& modelIndices, + const glm::mat4& modelMatrix, float& outDistance, float& outUCoord, float& outVCoord) { outDistance = INFINITY; bool hit = false; - for (int i = 0; i < modelIndices.size(); ++i) { - glm::vec3 v0 = modelVertices[modelIndices[i]].Position; - glm::vec3 v1 = modelVertices[modelIndices[++i]].Position; - glm::vec3 v2 = modelVertices[modelIndices[++i]].Position; - float dist; + for (int i = 0; i < modelIndices.size();) { + glm::vec3 v0 = Transform::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix); + glm::vec3 v1 = Transform::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix); + glm::vec3 v2 = Transform::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix); + float dist = INFINITY; float u; float v; if (RayVsTriangle(ray, v0, v1, v2, dist, u, v)) { @@ -218,14 +221,15 @@ bool RayVsModel(const Ray& ray, } bool RayVsModel(const Ray& ray, - const std::vector& modelVertices, + const RawModel::Vertex* modelVertices, const std::vector& modelIndices, + const glm::mat4& modelMatrix, glm::vec3& outHitPosition) { float u; float v; float dist; - bool hit = RayVsModel(ray, modelVertices, modelIndices, dist, u, v); + bool hit = RayVsModel(ray, modelVertices, modelIndices, modelMatrix, dist, u, v); outHitPosition = ray.Origin() + dist * ray.Direction(); return hit; } @@ -572,11 +576,11 @@ boost::optional EntityAbsoluteAABB(EntityWrapper& entity, bool takeM ComponentWrapper& cAABB = entity["AABB"]; modelSpaceBox = EntityAABB::FromOriginSize((glm::vec3)cAABB["Origin"], (glm::vec3)cAABB["Size"]); } else if (entity.HasComponent("Model")) { - Model* model; std::string res = entity["Model"]["Resource"]; if (res.empty()) { return boost::none; } + Model* model; try { model = ResourceManager::Load<::Model, true>(res); } catch (const Resource::StillLoadingException&) { @@ -638,4 +642,36 @@ boost::optional AbsoluteAABBExplosionEffect(EntityWrapper& entity) return aabb; } +boost::optional EntityFirstHitByRay(const Ray& ray, std::vector entitiesPotentiallyHitSorted, float outDistance, glm::vec3& outIntersectPos) +{ + for (EntityAABB& entityBox : entitiesPotentiallyHitSorted) { + if (!entityBox.Entity.HasComponent("Model")) { + continue; + } + std::string res = entityBox.Entity["Model"]["Resource"]; + if (res.empty()) { + continue; + } + Model* model; + try { + model = ResourceManager::Load<::Model, true>(res); + } catch (const std::exception&) { + continue; + } + float u, v; + if (RayVsModel(ray, model->Vertices(), model->m_RawModel->m_Indices, Transform::ModelMatrix(entityBox.Entity), outDistance, u, v)) { + outIntersectPos = ray.Origin() + outDistance * ray.Direction(); + return entityBox; + } + } + return boost::none; +} + +boost::optional EntityFirstHitByRay(const Ray& ray, Octree* octree, float outDistance, glm::vec3& outIntersectPos) +{ + std::vector outObjects; + octree->ObjectsPossiblyHitByRay(ray, outObjects); + return Collision::EntityFirstHitByRay(ray, outObjects, outDistance, outIntersectPos); +} + } \ No newline at end of file diff --git a/src/Engine/Core/Octree.cpp b/src/Engine/Core/Octree.cpp index 7eee1f81..dca06c6f 100644 --- a/src/Engine/Core/Octree.cpp +++ b/src/Engine/Core/Octree.cpp @@ -5,22 +5,6 @@ #include "Core/Octree.h" #include "Collision/Collision.h" -namespace -{ -//To be able to sort nodes based on distance to ray origin. -struct ChildInfo -{ - int Index; - float Distance; -}; - -bool isFirstLower(const ChildInfo& first, const ChildInfo& second) -{ - return first.Distance < second.Distance; -} - -} - namespace OctSpace { @@ -123,14 +107,14 @@ bool Child::RayCollides(const Ray& ray, OctSpace::Output& data) const //If the ray shoots the tree, and it is a parent to 8 children :o if (hasChildren()) { //Sort children according to their distance from the ray origin. - std::vector childInfos; + std::vector childInfos; childInfos.reserve(8); for (int i = 0; i < 8; ++i) { childInfos.push_back({ i, glm::distance(ray.Origin(), m_Children[i]->m_Box.Origin()) }); } std::sort(childInfos.begin(), childInfos.end(), isFirstLower); //Loop through the children, starting with the one closest to the ray origin. I.e the first to be hit. - for (const ChildInfo& info : childInfos) { + for (const RaySorterInfo& info : childInfos) { if (m_Children[info.Index]->RayCollides(ray, data)) { return true; } @@ -275,4 +259,9 @@ std::vector Child::childIndicesContainingBox(const AABB& box) const } } +bool isFirstLower(const RaySorterInfo& first, const RaySorterInfo& second) +{ + return first.Distance < second.Distance; +} + } \ No newline at end of file From f11bd24d539cd9847b3307250bea8202272f02f3 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Thu, 11 Feb 2016 11:46:34 +0100 Subject: [PATCH 08/11] Added CapturePointMaxTimer in CapturePointComponent. Removed next-capturepoint Color. Modified captureTimer to +-captureTimeToTakeOver after a capture. --- include/Game/Systems/CapturePointSystem.h | 1 - resources/Schema/Components/CapturePoint.xml | 1 + resources/Schema/Components/CapturePoint.xsd | 6 +- .../Schema/Entities/CaptureTestState5.xml | 323 ++++++++++++++---- src/Game/Systems/CapturePointSystem.cpp | 29 +- 5 files changed, 273 insertions(+), 87 deletions(-) diff --git a/include/Game/Systems/CapturePointSystem.h b/include/Game/Systems/CapturePointSystem.h index 18c32c76..33ba40c8 100644 --- a/include/Game/Systems/CapturePointSystem.h +++ b/include/Game/Systems/CapturePointSystem.h @@ -44,7 +44,6 @@ private: //std::vector - const double m_CaptureTimeToTakeOver = 15.0; bool m_ResetTimers = false; //vectors which will keep track of enter/leave changes diff --git a/resources/Schema/Components/CapturePoint.xml b/resources/Schema/Components/CapturePoint.xml index ba164fd9..638b16c3 100644 --- a/resources/Schema/Components/CapturePoint.xml +++ b/resources/Schema/Components/CapturePoint.xml @@ -2,5 +2,6 @@ 0 0 + 15 \ No newline at end of file diff --git a/resources/Schema/Components/CapturePoint.xsd b/resources/Schema/Components/CapturePoint.xsd index fbdb3568..3c91dfdd 100644 --- a/resources/Schema/Components/CapturePoint.xsd +++ b/resources/Schema/Components/CapturePoint.xsd @@ -20,7 +20,11 @@ CapturePointNumber specify an int number for this - + + + The time needed to take over a Capture Point + + Specify if this is a HomePoint for either team diff --git a/resources/Schema/Entities/CaptureTestState5.xml b/resources/Schema/Entities/CaptureTestState5.xml index 8fe85068..c733706c 100644 --- a/resources/Schema/Entities/CaptureTestState5.xml +++ b/resources/Schema/Entities/CaptureTestState5.xml @@ -2,12 +2,246 @@ - - - + + + + + + + + + Models/LevelBase/MapVersion1.mesh + + + + + + + + + 2 + + + Models/Widgets/Lights/DirectionalLightWidget.mesh + false + + + + + + + + + + + + + 8 + 2.7999999523162842 + + + + + + + + + + + 8 + 2.7999999523162842 + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + false + + + Schema/Entities/Player.xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Models/Core/UnitCube.mesh + false + + + Schema/Entities/Player.xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -15,10 +249,12 @@ + 15 Models/Core/UnitSphere.mesh - + + true @@ -26,7 +262,7 @@ - + @@ -40,11 +276,12 @@ Models/Core/UnitSphere.mesh - + + true - + @@ -58,15 +295,12 @@ Models/Core/UnitSphere.mesh - + + true - - - - - + - + @@ -76,11 +310,13 @@ + -15 3 Models/Core/UnitSphere.mesh - + + true @@ -88,7 +324,7 @@ - + @@ -101,11 +337,13 @@ + -15 4 Models/Core/UnitSphere.mesh - + + true @@ -113,61 +351,12 @@ - + - - - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - - - - - - Models/Core/UnitCube.mesh - - - - - - - - - - - - - - - - - Models/Test/DummyScene.mesh - - - - - - - diff --git a/src/Game/Systems/CapturePointSystem.cpp b/src/Game/Systems/CapturePointSystem.cpp index a943e234..971c194c 100644 --- a/src/Game/Systems/CapturePointSystem.cpp +++ b/src/Game/Systems/CapturePointSystem.cpp @@ -1,7 +1,7 @@ #include "Systems/CapturePointSystem.h" #include -CapturePointSystem::CapturePointSystem(World* world, EventBroker* eventBroker) +CapturePointSystem::CapturePointSystem(World* world, EventBroker* eventBroker) : System(world, eventBroker) , PureSystem("CapturePoint") { @@ -32,6 +32,7 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp const int redTeam = (int)teamComponent["Team"].Enum("Red"); const int blueTeam = (int)teamComponent["Team"].Enum("Blue"); const int spectatorTeam = (int)teamComponent["Team"].Enum("Spectator"); + const double captureTimeToTakeOver = (double)cCapturePoint["CapturePointMaxTimer"]; int homePointForTeam = (int)cCapturePoint["HomePointForTeam"]; if (m_NumberOfCapturePoints == 0 && capturePointNumber != 0 && (homePointForTeam == redTeam || homePointForTeam == blueTeam)) { @@ -57,7 +58,7 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp int blueTeamPlayersStandingInside = 0; if (capturePointEntity.HasComponent("Model")) { //Now sets team color to the capturepoint, or white if it is uncaptured. - capturePointEntity["Model"]["Color"] = ownedBy == blueTeam ? glm::vec4(0, 0.2f, 1, 0.3) : ownedBy == redTeam ? glm::vec4(1, 0.2f, 0, 0.3) : glm::vec4(1, 1, 1, 0.3); + capturePointEntity["Model"]["Color"] = ownedBy == blueTeam ? glm::vec4(0, 0.0f, 1, 0.3) : ownedBy == redTeam ? glm::vec4(1, 0.0f, 0, 0.3) : glm::vec4(1, 1, 1, 0.3); } //calculate next possible capturePoint for both teams @@ -98,20 +99,16 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp ComponentWrapper& capturePoint = m_CapturePointNumberToEntityMap[i]["CapturePoint"]; if ((int)capturePoint["CapturePointNumber"] != nextPossibleCapturePoint["Red"] && (int)capturePoint["CapturePointNumber"] != nextPossibleCapturePoint["Blue"]) { - capturePoint["CaptureTimer"] = 0.0; + //RED = +, BLUE = -, NONE + auto teamOwners = (int)m_CapturePointNumberToEntityMap[i]["Team"]["Team"]; + if (teamOwners == redTeam || teamOwners == blueTeam) { + capturePoint["CaptureTimer"] = teamOwners == blueTeam ? -captureTimeToTakeOver : captureTimeToTakeOver; + } } } m_ResetTimers = false; } - //colorize next possible capturepoint - if (nextPossibleCapturePoint["Red"] == capturePointNumber) { - capturePointEntity["Model"]["Color"] = glm::vec4(1, 1, 0, 0.3); - } - if (nextPossibleCapturePoint["Blue"] == capturePointNumber) { - capturePointEntity["Model"]["Color"] = glm::vec4(0, 1, 1, 0.3); - } - //check how many players are standing inside and are healthy for (size_t i = m_ETriggerTouchVector.size(); i > 0; i--) { @@ -170,9 +167,6 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp //B. at most one of the teams have players inside //if capturePoint is not owned by the take-over team, just modify the CaptureTimer accordingly if (ownedBy != currentTeam && canCapture) { - if (abs((double)cCapturePoint["CaptureTimer"]) < 0.001f) { - LOG_DEBUG("Point is being captured by team %i", currentTeam); //Remove when we tested sufficiently. - } cCapturePoint["CaptureTimer"] = (double)cCapturePoint["CaptureTimer"] + timerDeltaChange; } //if capturePoint is owned by the team, and the other team has been trying to take it, then increase/decrease the timer towards 0.0 @@ -180,12 +174,11 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp (ownedBy == currentTeam && currentTeam == blueTeam && (double)cCapturePoint["CaptureTimer"] > 0.0)) { cCapturePoint["CaptureTimer"] = (double)cCapturePoint["CaptureTimer"] + timerDeltaChange; } - //check if captureTimer > m_CaptureTimeToTakeOver and if so change owner and publish the eCaptured event - if (abs((double)cCapturePoint["CaptureTimer"]) > abs(m_CaptureTimeToTakeOver) && canCapture) { + //check if captureTimer > captureTimeToTakeOver and if so change owner and publish the eCaptured event + if (abs((double)cCapturePoint["CaptureTimer"]) > captureTimeToTakeOver && canCapture) { teamComponent["Team"] = currentTeam; - cCapturePoint["CaptureTimer"] = 0.0; + cCapturePoint["CaptureTimer"] = glm::sign((double)cCapturePoint["CaptureTimer"])*captureTimeToTakeOver; //publish Captured event - LOG_DEBUG("Point is captured by team %i!", currentTeam); //Remove when we tested sufficiently. Events::Captured e; e.CapturePointID = cCapturePoint.EntityID; e.TeamNumberThatCapturedCapturePoint = currentTeam; From 4e23e7bf3097abd5ff60dbf1468dc89e435ff848 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Thu, 11 Feb 2016 15:58:58 +0100 Subject: [PATCH 09/11] misc changes do the DoubleJumpHexagon.xml --- resources/Schema/Entities/DoubleJumpHexagon.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/Schema/Entities/DoubleJumpHexagon.xml b/resources/Schema/Entities/DoubleJumpHexagon.xml index bbc41119..c1aaec34 100644 --- a/resources/Schema/Entities/DoubleJumpHexagon.xml +++ b/resources/Schema/Entities/DoubleJumpHexagon.xml @@ -3,8 +3,8 @@ - Models/JumpEffectHexagon.mesh - + Models/Effects/JumpEffectHexagon.mesh + true @@ -12,14 +12,14 @@ - 1.5 + 0.5 true true - 3 + 0.5 true From 8f500965d481a2621a8f4a9e5d8536f5938d9d92 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Thu, 11 Feb 2016 20:34:25 +0100 Subject: [PATCH 10/11] Changed DamageIndicator.xml to not use a glowmap and not a depthsort. --- include/Game/Systems/DamageIndicatorSystem.h | 5 ++++- resources/Schema/Entities/DamageIndicator.xml | 5 +++-- resources/Schema/Entities/DamageIndicatorTest.xml | 8 ++------ src/Game/Systems/CapturePointHUDSystem.cpp | 3 +++ src/Game/Systems/DamageIndicatorSystem.cpp | 10 +++++++--- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/include/Game/Systems/DamageIndicatorSystem.h b/include/Game/Systems/DamageIndicatorSystem.h index fd3ba33f..e70a69a9 100644 --- a/include/Game/Systems/DamageIndicatorSystem.h +++ b/include/Game/Systems/DamageIndicatorSystem.h @@ -13,10 +13,12 @@ #include #include +#include "Rendering/Util/CommonFunctions.h" + class DamageIndicatorSystem : public System { public: - DamageIndicatorSystem(World* world, EventBroker* eventBroker); + DamageIndicatorSystem(SystemParams params); private: EventRelay m_DamageTakenFromPlayer; @@ -26,5 +28,6 @@ private: bool OnSetCamera(const Events::SetCamera& e); EntityID m_CurrentCamera = -1; + }; #endif diff --git a/resources/Schema/Entities/DamageIndicator.xml b/resources/Schema/Entities/DamageIndicator.xml index 2d02443c..3e9e4fef 100644 --- a/resources/Schema/Entities/DamageIndicator.xml +++ b/resources/Schema/Entities/DamageIndicator.xml @@ -3,8 +3,9 @@ - Textures/TempDamageIndicator.png - Textures/TempDamageIndicator.png + Textures/DamageIndicator.png + + false diff --git a/resources/Schema/Entities/DamageIndicatorTest.xml b/resources/Schema/Entities/DamageIndicatorTest.xml index ee68da96..1155ddd5 100644 --- a/resources/Schema/Entities/DamageIndicatorTest.xml +++ b/resources/Schema/Entities/DamageIndicatorTest.xml @@ -382,14 +382,10 @@ - - Hold Pos - - 1 - + - Models/AssaultAnimated.mesh + Models/Characters/Assault/AssaultAnimations.mesh diff --git a/src/Game/Systems/CapturePointHUDSystem.cpp b/src/Game/Systems/CapturePointHUDSystem.cpp index 784c7e16..21737fbe 100644 --- a/src/Game/Systems/CapturePointHUDSystem.cpp +++ b/src/Game/Systems/CapturePointHUDSystem.cpp @@ -16,6 +16,9 @@ void CapturePointHUDSystem::Update(double dt) auto CapturePointHUDElements = m_World->GetComponents("CapturePointHUD"); auto CapturePoints = m_World->GetComponents("CapturePoint"); + if (CapturePointHUDElements == nullptr) { + return; + } for (auto& cCapturePointHUD : *CapturePointHUDElements) { int HUD_ID = cCapturePointHUD["CapturePointNumber"]; diff --git a/src/Game/Systems/DamageIndicatorSystem.cpp b/src/Game/Systems/DamageIndicatorSystem.cpp index 638307bf..93385e48 100644 --- a/src/Game/Systems/DamageIndicatorSystem.cpp +++ b/src/Game/Systems/DamageIndicatorSystem.cpp @@ -1,11 +1,15 @@ #include "Systems/DamageIndicatorSystem.h" -DamageIndicatorSystem::DamageIndicatorSystem(World* m_World, EventBroker* eventBroker) - : System(m_World, eventBroker) +DamageIndicatorSystem::DamageIndicatorSystem(SystemParams params) + : System(params) { EVENT_SUBSCRIBE_MEMBER(m_DamageTakenFromPlayer, &DamageIndicatorSystem::OnPlayerDamageTaken); //current camera EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &DamageIndicatorSystem::OnSetCamera); + + //load texture to cache + auto texture = CommonFunctions::LoadTexture("Textures/DamageIndicator.png", false); + auto entityFile = ResourceManager::Load("Schema/Entities/DamageIndicator.xml"); } bool DamageIndicatorSystem::OnPlayerDamageTaken(Events::PlayerDamage& e) @@ -58,4 +62,4 @@ bool DamageIndicatorSystem::OnPlayerDamageTaken(Events::PlayerDamage& e) bool DamageIndicatorSystem::OnSetCamera(const Events::SetCamera& e) { m_CurrentCamera = e.CameraEntity.ID; return true; -} \ No newline at end of file +} From 3a15550b57faf975d0e651199b748f933d0e49b2 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Thu, 11 Feb 2016 21:07:47 +0100 Subject: [PATCH 11/11] maybe a good commit --- assets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets b/assets index 8ffd0a99..dfa0fc61 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 8ffd0a99b9a2e5c140307d382a25c4a470cc8f33 +Subproject commit dfa0fc61ab88456f3461779bd7c6ac97d15f6493