From 31c1c0ac8ddbdc1cb42992b97243ebdb265577fa Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Fri, 8 Jan 2016 16:19:18 +0100 Subject: [PATCH 01/13] New Event: EShoot. New Components: PrimaryItem,SecondaryItem. New Test: ShootEventTest. Added LeftMouseRelease->Shoot in PlayerSystem TODO: generalize the test --- include/Engine/Core/EShoot.h | 22 ++++ include/Game/PlayerSystem.h | 7 ++ resources/Schema/Components.xsd | 3 + resources/Schema/Components/Player.xml | 1 + resources/Schema/Components/Player.xsd | 1 + resources/Schema/Components/PrimaryItem.xml | 4 + resources/Schema/Components/PrimaryItem.xsd | 14 +++ resources/Schema/Components/SecondaryItem.xml | 4 + resources/Schema/Components/SecondaryItem.xsd | 14 +++ resources/Schema/Types/Entity.xsd | 2 + src/Game/PlayerSystem.cpp | 43 +++++++ src/Tests/ShootEventTest.cpp | 108 ++++++++++++++++++ src/Tests/ShootEventTest.h | 43 +++++++ 13 files changed, 266 insertions(+) create mode 100644 include/Engine/Core/EShoot.h create mode 100644 resources/Schema/Components/PrimaryItem.xml create mode 100644 resources/Schema/Components/PrimaryItem.xsd create mode 100644 resources/Schema/Components/SecondaryItem.xml create mode 100644 resources/Schema/Components/SecondaryItem.xsd create mode 100644 src/Tests/ShootEventTest.cpp create mode 100644 src/Tests/ShootEventTest.h diff --git a/include/Engine/Core/EShoot.h b/include/Engine/Core/EShoot.h new file mode 100644 index 00000000..d9b9e20b --- /dev/null +++ b/include/Engine/Core/EShoot.h @@ -0,0 +1,22 @@ +#ifndef EShoot_h__ +#define EShoot_h__ + +#include "EventBroker.h" +#include "../Core/Entity.h" +#include "Engine/GLM.h" + +namespace Events +{ + +struct Shoot : Event +{ + //shotgun etc has different amounts of damage probably (a sniper shot might one-shot) + //also different weapons will have different spread + std::string weaponType; + //currentAimingPoint must be sent, in case the camera is moved while the event is being processed + glm::vec2 currentAimingPoint; +}; + +} + +#endif \ No newline at end of file diff --git a/include/Game/PlayerSystem.h b/include/Game/PlayerSystem.h index 577fbbb0..87dc6f5d 100644 --- a/include/Game/PlayerSystem.h +++ b/include/Game/PlayerSystem.h @@ -7,6 +7,8 @@ #include "Common.h" #include "Core/System.h" #include "Collision/ETrigger.h" +#include "Core\EMouseRelease.h" +#include "Core\EShoot.h" class PlayerSystem : public PureSystem { @@ -17,17 +19,22 @@ public: EVENT_SUBSCRIBE_MEMBER(m_ETouch, &PlayerSystem::OnTouch); EVENT_SUBSCRIBE_MEMBER(m_EEnter, &PlayerSystem::OnEnter); EVENT_SUBSCRIBE_MEMBER(m_ELeave, &PlayerSystem::OnLeave); + EVENT_SUBSCRIBE_MEMBER(m_MouseRelease, &PlayerSystem::OnMouseRelease); } virtual void UpdateComponent(World* world, ComponentWrapper& player, double dt) override; private: float m_Speed = 5; + bool leftMouseWasReleased = false; + glm::vec2 aimingCoordinates; EventRelay m_EEnter; bool OnEnter(const Events::TriggerEnter &event); EventRelay m_ETouch; bool PlayerSystem::OnTouch(const Events::TriggerTouch &event); EventRelay m_ELeave; bool PlayerSystem::OnLeave(const Events::TriggerLeave &event); + EventRelay m_MouseRelease; + bool PlayerSystem::OnMouseRelease(const Events::MouseRelease& e); }; #endif \ No newline at end of file diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index 7fcdd565..33714638 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -9,4 +9,7 @@ + + + \ No newline at end of file diff --git a/resources/Schema/Components/Player.xml b/resources/Schema/Components/Player.xml index 190f2ed0..cd3d1620 100644 --- a/resources/Schema/Components/Player.xml +++ b/resources/Schema/Components/Player.xml @@ -1,4 +1,5 @@ + 0 false false diff --git a/resources/Schema/Components/Player.xsd b/resources/Schema/Components/Player.xsd index 76a6a8fb..fcf07879 100644 --- a/resources/Schema/Components/Player.xsd +++ b/resources/Schema/Components/Player.xsd @@ -11,6 +11,7 @@ + diff --git a/resources/Schema/Components/PrimaryItem.xml b/resources/Schema/Components/PrimaryItem.xml new file mode 100644 index 00000000..540a1518 --- /dev/null +++ b/resources/Schema/Components/PrimaryItem.xml @@ -0,0 +1,4 @@ + + 0 + 0 + \ No newline at end of file diff --git a/resources/Schema/Components/PrimaryItem.xsd b/resources/Schema/Components/PrimaryItem.xsd new file mode 100644 index 00000000..193b9213 --- /dev/null +++ b/resources/Schema/Components/PrimaryItem.xsd @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/resources/Schema/Components/SecondaryItem.xml b/resources/Schema/Components/SecondaryItem.xml new file mode 100644 index 00000000..0fae1402 --- /dev/null +++ b/resources/Schema/Components/SecondaryItem.xml @@ -0,0 +1,4 @@ + + 0 + 0 + \ No newline at end of file diff --git a/resources/Schema/Components/SecondaryItem.xsd b/resources/Schema/Components/SecondaryItem.xsd new file mode 100644 index 00000000..44e23611 --- /dev/null +++ b/resources/Schema/Components/SecondaryItem.xsd @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/resources/Schema/Types/Entity.xsd b/resources/Schema/Types/Entity.xsd index 6562f3ed..4b67276a 100644 --- a/resources/Schema/Types/Entity.xsd +++ b/resources/Schema/Types/Entity.xsd @@ -16,6 +16,8 @@ + + diff --git a/src/Game/PlayerSystem.cpp b/src/Game/PlayerSystem.cpp index 17b9a7f5..f5819ea1 100644 --- a/src/Game/PlayerSystem.cpp +++ b/src/Game/PlayerSystem.cpp @@ -21,6 +21,38 @@ void PlayerSystem::UpdateComponent(World * world, ComponentWrapper & player, dou ComponentWrapper& transform = world->GetComponent(player.EntityID, "Transform"); (glm::vec3&)transform["Position"] += (glm::vec3)player["Velocity"]; } + + //do shootEvent: if left mouse was released, and ammo/weaponcooldown/playeralive/shootingcooldown are ok + if (leftMouseWasReleased) { + leftMouseWasReleased = false; + //get the health component linked to the playerId + double currentHealth = (double)world->GetComponent(player.EntityID, "Health")["Health"]; + int currentAmmo = 0; + double currentCoolDownTimer = 0.0f; + + if ((int)player["EquippedItem"] == 1) { + ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "PrimaryItem"); + currentAmmo = currentItem["Ammo"]; + //subtract 1 ammo - the ItemSystem will probably listen to eShoot and handle the CoolDownTimer + currentItem["Ammo"] = (int)currentItem["Ammo"] -1; + int test = (int)currentItem["Ammo"]; + currentCoolDownTimer = (double)world->GetComponent(player.EntityID, "PrimaryItem")["CoolDownTimer"]; + } + if ((int)player["EquippedItem"] == 2) { + ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "SecondaryItem"); + currentAmmo = currentItem["Ammo"]; + //subtract 1 ammo - the ItemSystem will probably listen to eShoot and handle the CoolDownTimer + currentItem["Ammo"] = (int)currentItem["Ammo"] - 1; + currentCoolDownTimer = (double)world->GetComponent(player.EntityID, "SecondaryItem")["CoolDownTimer"]; + } + if (currentHealth > 0.0f && currentAmmo > 0 && currentCoolDownTimer < 0.001f) { + //create and publish the shoot event + Events::Shoot eShoot; + eShoot.currentAimingPoint = aimingCoordinates; + eShoot.weaponType = (int)player["EquippedItem"]; + m_EventBroker->Publish(eShoot); + } + } } bool PlayerSystem::OnTouch(const Events::TriggerTouch &event) @@ -39,4 +71,15 @@ bool PlayerSystem::OnLeave(const Events::TriggerLeave &event) { LOG_INFO("Player entity %i left widget (entity %i).", event.Entity, event.Trigger); return false; +} + +bool PlayerSystem::OnMouseRelease(const Events::MouseRelease& e) +{ + //kolla ammoleft, cooldowntimer shooting + //kolla om left mouse varit nere + if (e.Button != GLFW_MOUSE_BUTTON_LEFT) + return false; + aimingCoordinates = glm::vec2(e.X, e.Y); + leftMouseWasReleased = true; + return true; } \ No newline at end of file diff --git a/src/Tests/ShootEventTest.cpp b/src/Tests/ShootEventTest.cpp new file mode 100644 index 00000000..481772c1 --- /dev/null +++ b/src/Tests/ShootEventTest.cpp @@ -0,0 +1,108 @@ +#include +using boost::unit_test_framework::test_suite; +using boost::unit_test_framework::test_case; + +#include "ShootEventTest.h" +#include "Core\EPlayerDamage.h"; +#include "Core\EPlayerHealthPickup.h"; +#include "Core\EPlayerDeath.h"; +#include "Game/HealthSystem.h" + +BOOST_AUTO_TEST_SUITE(ShootEventTestSuite) + +//AShootEventTest != ShootEventTest -> else it confuses names! +BOOST_AUTO_TEST_CASE(AShootEventTest) +{ + ShootEventTest game; + //100 loops will be more than enough to do the test + int loops = 100; + bool success = false; + while (loops > 0) { + game.Tick(); + if (game.TestSucceeded) { + success = true; + break; + } + loops--; + } + //The system will process the events, hence it will take a while before we can read anything + BOOST_TEST(success); +} +BOOST_AUTO_TEST_SUITE_END() + +ShootEventTest::ShootEventTest() +{ + ResourceManager::RegisterType("ConfigFile"); + ResourceManager::RegisterType("EntityXMLFile"); + + m_Config = ResourceManager::Load("Config.ini"); + LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get("Debug.LogLevel", 1)); + + // Create the core event broker + m_EventBroker = new EventBroker(); + + // Create a world + m_World = new World(); + std::string mapToLoad = m_Config->Get("Debug.LoadMap", ""); + if (!mapToLoad.empty()) { + ResourceManager::Load(mapToLoad)->PopulateWorld(m_World); + } + + // Create system pipeline + m_SystemPipeline = new SystemPipeline(m_EventBroker); + m_SystemPipeline->AddSystem(0); + m_SystemPipeline->AddSystem(0); + + //The Test + //create entity which has transorm,player,model,health in it. i.e. is a player + EntityID playerID = m_World->CreateEntity(); + ComponentWrapper transform = m_World->AttachComponent(playerID, "Transform"); + ComponentWrapper model = m_World->AttachComponent(playerID, "Model"); + model["Resource"] = "Models/Core/UnitSphere.obj"; + ComponentWrapper& player = m_World->AttachComponent(playerID, "Player"); + ComponentWrapper health = m_World->AttachComponent(playerID, "Health"); + playersID = playerID; + //attach 2x weaps + ComponentWrapper& pItem = m_World->AttachComponent(playerID, "PrimaryItem"); + ComponentWrapper& sItem= m_World->AttachComponent(playerID, "SecondaryItem"); + //set currentweap + player["EquippedItem"] = 1; + //set ammo set cooldown + pItem["Ammo"] = 100; + pItem["CoolDownTimer"] = 0.0f; + + //trigger event leftmousedown + Events::MouseRelease eMouseRelease; + eMouseRelease.Button = GLFW_MOUSE_BUTTON_LEFT; + eMouseRelease.X = 1.0f; + eMouseRelease.Y = 1.0f; + m_EventBroker->Publish(eMouseRelease); + +} + +ShootEventTest::~ShootEventTest() +{ + delete m_SystemPipeline; + delete m_World; + delete m_EventBroker; +} + +void ShootEventTest::Tick() +{ + glfwPollEvents(); + + double currentTime = glfwGetTime(); + double dt = currentTime - m_LastTime; + m_LastTime = currentTime; + + // Iterate through systems and update world! + m_SystemPipeline->Update(m_World, dt); + + m_EventBroker->Swap(); + m_EventBroker->Clear(); + + //if ammocount reaches 99 we know the test has succeeded, i.e. a shot has been fired + int currentAmmo = (int)m_World->GetComponent(playersID, "PrimaryItem")["Ammo"]; + if (currentAmmo ==99) + TestSucceeded = true; +} diff --git a/src/Tests/ShootEventTest.h b/src/Tests/ShootEventTest.h new file mode 100644 index 00000000..49206ceb --- /dev/null +++ b/src/Tests/ShootEventTest.h @@ -0,0 +1,43 @@ +#ifndef ShootEventTest_h__ +#define ShootEventTest_h__ + +#include "Core/ResourceManager.h" +#include "Core/ConfigFile.h" +#include "Core/EventBroker.h" +#include "Rendering/Renderer.h" +#include "Core/InputManager.h" +#include "GUI/Frame.h" +#include "Core/World.h" +#include "Rendering/RenderQueueFactory.h" +#include "Input/InputProxy.h" +#include "Input/KeyboardInputHandler.h" +#include "Input/MouseInputHandler.h" +#include "Core/EKeyDown.h" +#include "Core/EntityXMLFile.h" +#include "Core/SystemPipeline.h" +#include "RaptorCopterSystem.h" +#include "PlayerSystem.h" +#include "Editor/EditorSystem.h" + +#include "Core\EMouseRelease.h" +#include "Core\EShoot.h" + +class ShootEventTest +{ +public: + ShootEventTest(); + ~ShootEventTest(); + + void Tick(); + bool TestSucceeded = false; + +private: + double m_LastTime; + ConfigFile* m_Config = nullptr; + EventBroker* m_EventBroker; + World* m_World; + SystemPipeline* m_SystemPipeline; + int playersID; +}; + +#endif From 8f92de3683c69b81664dc6ad250b0658363aeec6 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Mon, 11 Jan 2016 13:34:50 +0100 Subject: [PATCH 02/13] xml/xsd files changed type to double. fixed cooldownbug in PlayerSystem. Added 4 tests in ShootEventTest and generalized it a lot --- resources/Schema/Components/Player.xsd | 5 +- resources/Schema/Components/PrimaryItem.xml | 2 +- resources/Schema/Components/PrimaryItem.xsd | 11 +- resources/Schema/Components/SecondaryItem.xml | 2 +- resources/Schema/Components/SecondaryItem.xsd | 11 +- src/Game/PlayerSystem.cpp | 34 +-- src/Tests/ShootEventTest.cpp | 195 +++++++++++++++--- src/Tests/ShootEventTest.h | 21 +- 8 files changed, 228 insertions(+), 53 deletions(-) diff --git a/resources/Schema/Components/Player.xsd b/resources/Schema/Components/Player.xsd index fcf07879..9ffc28b0 100644 --- a/resources/Schema/Components/Player.xsd +++ b/resources/Schema/Components/Player.xsd @@ -4,6 +4,9 @@ + + The player charachter + @@ -11,7 +14,7 @@ - + diff --git a/resources/Schema/Components/PrimaryItem.xml b/resources/Schema/Components/PrimaryItem.xml index 540a1518..0d0ccca2 100644 --- a/resources/Schema/Components/PrimaryItem.xml +++ b/resources/Schema/Components/PrimaryItem.xml @@ -1,4 +1,4 @@ 0 0 - \ No newline at end of file + \ No newline at end of file diff --git a/resources/Schema/Components/PrimaryItem.xsd b/resources/Schema/Components/PrimaryItem.xsd index 193b9213..bbff122d 100644 --- a/resources/Schema/Components/PrimaryItem.xsd +++ b/resources/Schema/Components/PrimaryItem.xsd @@ -4,10 +4,17 @@ + + The Players Primary Item/Weapon + - - + + Ammo count + + + Cooldown till next item/weapon use + diff --git a/resources/Schema/Components/SecondaryItem.xml b/resources/Schema/Components/SecondaryItem.xml index 0fae1402..095dfef6 100644 --- a/resources/Schema/Components/SecondaryItem.xml +++ b/resources/Schema/Components/SecondaryItem.xml @@ -1,4 +1,4 @@ 0 0 - \ No newline at end of file + \ No newline at end of file diff --git a/resources/Schema/Components/SecondaryItem.xsd b/resources/Schema/Components/SecondaryItem.xsd index 44e23611..ab428920 100644 --- a/resources/Schema/Components/SecondaryItem.xsd +++ b/resources/Schema/Components/SecondaryItem.xsd @@ -4,10 +4,17 @@ + + The Players Secondary Item/Weapon + - - + + Ammo count + + + Cooldown till next item/weapon use + diff --git a/src/Game/PlayerSystem.cpp b/src/Game/PlayerSystem.cpp index f5819ea1..e40469cc 100644 --- a/src/Game/PlayerSystem.cpp +++ b/src/Game/PlayerSystem.cpp @@ -27,25 +27,35 @@ void PlayerSystem::UpdateComponent(World * world, ComponentWrapper & player, dou leftMouseWasReleased = false; //get the health component linked to the playerId double currentHealth = (double)world->GetComponent(player.EntityID, "Health")["Health"]; - int currentAmmo = 0; - double currentCoolDownTimer = 0.0f; + double currentAmmo = (double)0; + double currentCoolDownTimer = (double)0; - if ((int)player["EquippedItem"] == 1) { + if ((double)player["EquippedItem"] == (double)1) { ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "PrimaryItem"); currentAmmo = currentItem["Ammo"]; - //subtract 1 ammo - the ItemSystem will probably listen to eShoot and handle the CoolDownTimer - currentItem["Ammo"] = (int)currentItem["Ammo"] -1; - int test = (int)currentItem["Ammo"]; - currentCoolDownTimer = (double)world->GetComponent(player.EntityID, "PrimaryItem")["CoolDownTimer"]; + currentCoolDownTimer = (double)currentItem["CoolDownTimer"]; } - if ((int)player["EquippedItem"] == 2) { + if ((double)player["EquippedItem"] == (double)2) { ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "SecondaryItem"); currentAmmo = currentItem["Ammo"]; - //subtract 1 ammo - the ItemSystem will probably listen to eShoot and handle the CoolDownTimer - currentItem["Ammo"] = (int)currentItem["Ammo"] - 1; - currentCoolDownTimer = (double)world->GetComponent(player.EntityID, "SecondaryItem")["CoolDownTimer"]; + currentCoolDownTimer = (double)currentItem["CoolDownTimer"]; } - if (currentHealth > 0.0f && currentAmmo > 0 && currentCoolDownTimer < 0.001f) { + + if (currentHealth > (double)0.0f && currentAmmo > (double)0.0f && currentCoolDownTimer < (double)0.001f) { + //decrease ammo count + //TODO: temp, set the cooldowntimer - probably done in some other system (itemSystem?) later + if ((double)player["EquippedItem"] == (double)1) { + ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "PrimaryItem"); + int currentAmmoInt = (int)((double)currentItem["Ammo"]); + currentItem["Ammo"] = (double)(currentAmmoInt - 1); + currentItem["CoolDownTimer"] = (double)2; + } + if ((double)player["EquippedItem"] == (double)2) { + ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "SecondaryItem"); + int currentAmmoInt = (int)((double)currentItem["Ammo"]); + currentItem["Ammo"] = (double)(currentAmmoInt - 1); + currentItem["CoolDownTimer"] = (double)2; + } //create and publish the shoot event Events::Shoot eShoot; eShoot.currentAimingPoint = aimingCoordinates; diff --git a/src/Tests/ShootEventTest.cpp b/src/Tests/ShootEventTest.cpp index 481772c1..22c2a0eb 100644 --- a/src/Tests/ShootEventTest.cpp +++ b/src/Tests/ShootEventTest.cpp @@ -3,17 +3,15 @@ using boost::unit_test_framework::test_suite; using boost::unit_test_framework::test_case; #include "ShootEventTest.h" -#include "Core\EPlayerDamage.h"; -#include "Core\EPlayerHealthPickup.h"; -#include "Core\EPlayerDeath.h"; #include "Game/HealthSystem.h" BOOST_AUTO_TEST_SUITE(ShootEventTestSuite) -//AShootEventTest != ShootEventTest -> else it confuses names! -BOOST_AUTO_TEST_CASE(AShootEventTest) +//dont use the same name as the classname in test cases... +BOOST_AUTO_TEST_CASE(ShootEventTest_PrimaryWeaponFiring) { - ShootEventTest game; + //Test firing primary weapon + ShootEventTest game(1); //100 loops will be more than enough to do the test int loops = 100; bool success = false; @@ -28,9 +26,59 @@ BOOST_AUTO_TEST_CASE(AShootEventTest) //The system will process the events, hence it will take a while before we can read anything BOOST_TEST(success); } +BOOST_AUTO_TEST_CASE(ShootEventTest_SecondaryWeaponFiring) +{ + //Test firing secondary weapon + ShootEventTest game(2); + //100 loops will be more than enough to do the test + int loops = 100; + bool success = false; + while (loops > 0) { + game.Tick(); + if (game.TestSucceeded) { + success = true; + break; + } + loops--; + } + //The system will process the events, hence it will take a while before we can read anything + BOOST_TEST(success); +} +BOOST_AUTO_TEST_CASE(ShootEventTest_NoWeaponFiring) +{ + //Test firing with no weapon equipped + ShootEventTest game(3); + //100 loops will be more than enough to do the test + int loops = 100; + bool success = false; + while (loops > 0) { + game.Tick(); + loops--; + } + //The system will process the events, hence it will take a while before we can read anything + if (game.TestSucceeded) + success = true; + BOOST_TEST(success); +} +BOOST_AUTO_TEST_CASE(ShootEventTest_WeaponOnCooldown) +{ + //Test firing with weapon on cooldown + ShootEventTest game(4); + //100 loops will be more than enough to do the test + int loops = 100; + bool success = false; + while (loops > 0) { + game.Tick(); + loops--; + } + //The system will process the events, hence it will take a while before we can read anything + if (game.TestSucceeded) + success = true; + BOOST_TEST(success); +} BOOST_AUTO_TEST_SUITE_END() -ShootEventTest::ShootEventTest() +ShootEventTest::ShootEventTest(int runTestNumber) { ResourceManager::RegisterType("ConfigFile"); ResourceManager::RegisterType("EntityXMLFile"); @@ -41,7 +89,7 @@ ShootEventTest::ShootEventTest() // Create the core event broker m_EventBroker = new EventBroker(); - // Create a world + // Create a world m_World = new World(); std::string mapToLoad = m_Config->Get("Debug.LoadMap", ""); if (!mapToLoad.empty()) { @@ -54,30 +102,40 @@ ShootEventTest::ShootEventTest() m_SystemPipeline->AddSystem(0); //The Test - //create entity which has transorm,player,model,health in it. i.e. is a player + //create entity which has transform,player,model,health in it. i.e. is a player EntityID playerID = m_World->CreateEntity(); - ComponentWrapper transform = m_World->AttachComponent(playerID, "Transform"); - ComponentWrapper model = m_World->AttachComponent(playerID, "Model"); - model["Resource"] = "Models/Core/UnitSphere.obj"; - ComponentWrapper& player = m_World->AttachComponent(playerID, "Player"); + m_PlayerID = playerID; ComponentWrapper health = m_World->AttachComponent(playerID, "Health"); - playersID = playerID; + ComponentWrapper& player = m_World->AttachComponent(playerID, "Player"); //attach 2x weaps ComponentWrapper& pItem = m_World->AttachComponent(playerID, "PrimaryItem"); - ComponentWrapper& sItem= m_World->AttachComponent(playerID, "SecondaryItem"); - //set currentweap - player["EquippedItem"] = 1; - //set ammo set cooldown - pItem["Ammo"] = 100; - pItem["CoolDownTimer"] = 0.0f; + ComponentWrapper& sItem = m_World->AttachComponent(playerID, "SecondaryItem"); - //trigger event leftmousedown + m_RunTestNumber = runTestNumber; + switch (runTestNumber) + { + case 1: + TestSetup1(player, pItem, sItem); + break; + case 2: + TestSetup2(player, pItem, sItem); + break; + case 3: + TestSetup3(player, pItem, sItem); + break; + case 4: + TestSetup4(player, pItem, sItem); + break; + default: + break; + } + + //fire once = trigger event leftmousedown Events::MouseRelease eMouseRelease; eMouseRelease.Button = GLFW_MOUSE_BUTTON_LEFT; eMouseRelease.X = 1.0f; eMouseRelease.Y = 1.0f; m_EventBroker->Publish(eMouseRelease); - } ShootEventTest::~ShootEventTest() @@ -87,6 +145,77 @@ ShootEventTest::~ShootEventTest() delete m_EventBroker; } +void ShootEventTest::TestSetup1(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) +{ + //set currentweap + player["EquippedItem"] = (double)1.0f; + //set ammo set cooldown + pItem["Ammo"] = (double)100.0f; + pItem["CoolDownTimer"] = (double)0.0f; +} +void ShootEventTest::TestSetup2(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) +{ + //set currentweap + player["EquippedItem"] = (double)2.0f; + //set ammo set cooldown + sItem["Ammo"] = (double)10.0f; + sItem["CoolDownTimer"] = (double)0.0f; +} +void ShootEventTest::TestSetup3(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) +{ + player["EquippedItem"] = (double)0.0f; + pItem["Ammo"] = (double)100.0f; + sItem["Ammo"] = (double)100.0f; + //TestSucceeded will be set to false if ammo changes during the 100 loops + TestSucceeded = true; +} +void ShootEventTest::TestSetup4(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) +{ + //set currentweap + player["EquippedItem"] = (double)1.0f; + //set ammo set cooldown + pItem["Ammo"] = (double)100.0f; + pItem["CoolDownTimer"] = (double)5.0f; + //TestSucceeded will be set to false if ammo changes during the 100 loops + TestSucceeded = true; +} +void ShootEventTest::TestSuccess1() { + //if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired + double currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"]; + if (currentAmmo == (double)99) + TestSucceeded = true; +} +void ShootEventTest::TestSuccess2() { + //if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired + double currentAmmo = m_World->GetComponent(m_PlayerID, "SecondaryItem")["Ammo"]; + if (currentAmmo == (double)9) + TestSucceeded = true; +} +void ShootEventTest::TestSuccess3() { + //try firing again + Events::MouseRelease eMouseRelease; + eMouseRelease.Button = GLFW_MOUSE_BUTTON_LEFT; + eMouseRelease.X = 1.0f; + eMouseRelease.Y = 1.0f; + m_EventBroker->Publish(eMouseRelease); + //if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired + double currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"]; + double currentAmmoSecondary = m_World->GetComponent(m_PlayerID, "SecondaryItem")["Ammo"]; + if (currentAmmo != (double)100 || currentAmmoSecondary != (double)100) + TestSucceeded = false; +} +void ShootEventTest::TestSuccess4() { + //try firing again + Events::MouseRelease eMouseRelease; + eMouseRelease.Button = GLFW_MOUSE_BUTTON_LEFT; + eMouseRelease.X = 1.0f; + eMouseRelease.Y = 1.0f; + m_EventBroker->Publish(eMouseRelease); + //if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired + double currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"]; + if (currentAmmo != (double)100) + TestSucceeded = false; +} void ShootEventTest::Tick() { glfwPollEvents(); @@ -101,8 +230,22 @@ void ShootEventTest::Tick() m_EventBroker->Swap(); m_EventBroker->Clear(); - //if ammocount reaches 99 we know the test has succeeded, i.e. a shot has been fired - int currentAmmo = (int)m_World->GetComponent(playersID, "PrimaryItem")["Ammo"]; - if (currentAmmo ==99) - TestSucceeded = true; + switch (m_RunTestNumber) + { + case 1: + TestSuccess1(); + break; + case 2: + TestSuccess2(); + break; + case 3: + TestSuccess3(); + break; + case 4: + TestSuccess4(); + break; + default: + break; + } + } diff --git a/src/Tests/ShootEventTest.h b/src/Tests/ShootEventTest.h index 49206ceb..0ffa1f91 100644 --- a/src/Tests/ShootEventTest.h +++ b/src/Tests/ShootEventTest.h @@ -4,20 +4,14 @@ #include "Core/ResourceManager.h" #include "Core/ConfigFile.h" #include "Core/EventBroker.h" -#include "Rendering/Renderer.h" -#include "Core/InputManager.h" -#include "GUI/Frame.h" #include "Core/World.h" -#include "Rendering/RenderQueueFactory.h" #include "Input/InputProxy.h" #include "Input/KeyboardInputHandler.h" #include "Input/MouseInputHandler.h" #include "Core/EKeyDown.h" #include "Core/EntityXMLFile.h" #include "Core/SystemPipeline.h" -#include "RaptorCopterSystem.h" #include "PlayerSystem.h" -#include "Editor/EditorSystem.h" #include "Core\EMouseRelease.h" #include "Core\EShoot.h" @@ -25,19 +19,30 @@ class ShootEventTest { public: - ShootEventTest(); + ShootEventTest(int runTestNumber); ~ShootEventTest(); void Tick(); bool TestSucceeded = false; private: + void TestSetup1(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem); + void TestSetup2(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem); + void TestSetup3(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem); + void TestSetup4(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem); + void TestSuccess1(); + void TestSuccess2(); + void TestSuccess3(); + void TestSuccess4(); + double m_LastTime; ConfigFile* m_Config = nullptr; EventBroker* m_EventBroker; World* m_World; SystemPipeline* m_SystemPipeline; - int playersID; + int m_PlayerID; + int m_RunTestNumber; + }; #endif From 2cd0e94a6013b7bdc22e0f050fcd0fe37c7bf0d4 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Mon, 11 Jan 2016 14:37:43 +0100 Subject: [PATCH 03/13] Changed the comparison method in PlayerSystem since its currently using doubles --- src/Game/PlayerSystem.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Game/PlayerSystem.cpp b/src/Game/PlayerSystem.cpp index e40469cc..2e2120d9 100644 --- a/src/Game/PlayerSystem.cpp +++ b/src/Game/PlayerSystem.cpp @@ -30,27 +30,27 @@ void PlayerSystem::UpdateComponent(World * world, ComponentWrapper & player, dou double currentAmmo = (double)0; double currentCoolDownTimer = (double)0; - if ((double)player["EquippedItem"] == (double)1) { + if (fabs((double)player["EquippedItem"] - (double)1) < (double) 0.0001f) { ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "PrimaryItem"); - currentAmmo = currentItem["Ammo"]; + currentAmmo = (double)currentItem["Ammo"]; currentCoolDownTimer = (double)currentItem["CoolDownTimer"]; } - if ((double)player["EquippedItem"] == (double)2) { + if (fabs((double)player["EquippedItem"] - (double)2) < (double) 0.0001f) { ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "SecondaryItem"); - currentAmmo = currentItem["Ammo"]; + currentAmmo = (double)currentItem["Ammo"]; currentCoolDownTimer = (double)currentItem["CoolDownTimer"]; } if (currentHealth > (double)0.0f && currentAmmo > (double)0.0f && currentCoolDownTimer < (double)0.001f) { //decrease ammo count //TODO: temp, set the cooldowntimer - probably done in some other system (itemSystem?) later - if ((double)player["EquippedItem"] == (double)1) { + if (fabs((double)player["EquippedItem"] - (double)1) < (double) 0.0001f) { ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "PrimaryItem"); int currentAmmoInt = (int)((double)currentItem["Ammo"]); currentItem["Ammo"] = (double)(currentAmmoInt - 1); currentItem["CoolDownTimer"] = (double)2; } - if ((double)player["EquippedItem"] == (double)2) { + if (fabs((double)player["EquippedItem"] - (double)2) < (double) 0.0001f) { ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "SecondaryItem"); int currentAmmoInt = (int)((double)currentItem["Ammo"]); currentItem["Ammo"] = (double)(currentAmmoInt - 1); From 2f6261dfbf3aa7def43ae7f217f96673736fc71d Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Mon, 11 Jan 2016 15:43:12 +0100 Subject: [PATCH 04/13] EShoot: changed to string weaponType to int currentlyEquippedItem PlayerSystem.h: added HeldItem enum PlayerSystem.cpp: simplified writing doubles, uses HeldItem enum ShootEventTest.cpp: simplified writing doubles --- include/Engine/Core/EShoot.h | 2 +- include/Game/PlayerSystem.h | 5 +++++ src/Game/PlayerSystem.cpp | 20 ++++++++++---------- src/Tests/ShootEventTest.cpp | 32 ++++++++++++++++---------------- 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/include/Engine/Core/EShoot.h b/include/Engine/Core/EShoot.h index d9b9e20b..3887606b 100644 --- a/include/Engine/Core/EShoot.h +++ b/include/Engine/Core/EShoot.h @@ -12,7 +12,7 @@ struct Shoot : Event { //shotgun etc has different amounts of damage probably (a sniper shot might one-shot) //also different weapons will have different spread - std::string weaponType; + int currentlyEquippedItem; //currentAimingPoint must be sent, in case the camera is moved while the event is being processed glm::vec2 currentAimingPoint; }; diff --git a/include/Game/PlayerSystem.h b/include/Game/PlayerSystem.h index 87dc6f5d..3544c63c 100644 --- a/include/Game/PlayerSystem.h +++ b/include/Game/PlayerSystem.h @@ -35,6 +35,11 @@ private: bool PlayerSystem::OnLeave(const Events::TriggerLeave &event); EventRelay m_MouseRelease; bool PlayerSystem::OnMouseRelease(const Events::MouseRelease& e); + enum class HeldItem { + None = 0, + PrimaryWeapon = 1, + SecondaryWeapon = 2 + }; }; #endif \ No newline at end of file diff --git a/src/Game/PlayerSystem.cpp b/src/Game/PlayerSystem.cpp index 2e2120d9..ca39ed4f 100644 --- a/src/Game/PlayerSystem.cpp +++ b/src/Game/PlayerSystem.cpp @@ -27,39 +27,39 @@ void PlayerSystem::UpdateComponent(World * world, ComponentWrapper & player, dou leftMouseWasReleased = false; //get the health component linked to the playerId double currentHealth = (double)world->GetComponent(player.EntityID, "Health")["Health"]; - double currentAmmo = (double)0; - double currentCoolDownTimer = (double)0; + double currentAmmo = 0.0; + double currentCoolDownTimer = 0.0; - if (fabs((double)player["EquippedItem"] - (double)1) < (double) 0.0001f) { + if (fabs((double)player["EquippedItem"] - (double)HeldItem::PrimaryWeapon) < 0.0001) { ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "PrimaryItem"); currentAmmo = (double)currentItem["Ammo"]; currentCoolDownTimer = (double)currentItem["CoolDownTimer"]; } - if (fabs((double)player["EquippedItem"] - (double)2) < (double) 0.0001f) { + if (fabs((double)player["EquippedItem"] - (double)HeldItem::SecondaryWeapon) < 0.0001) { ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "SecondaryItem"); currentAmmo = (double)currentItem["Ammo"]; currentCoolDownTimer = (double)currentItem["CoolDownTimer"]; } - if (currentHealth > (double)0.0f && currentAmmo > (double)0.0f && currentCoolDownTimer < (double)0.001f) { + if (currentHealth > 0.0 && currentAmmo > 0.0 && currentCoolDownTimer < 0.001) { //decrease ammo count //TODO: temp, set the cooldowntimer - probably done in some other system (itemSystem?) later - if (fabs((double)player["EquippedItem"] - (double)1) < (double) 0.0001f) { + if (fabs((double)player["EquippedItem"] - (double)HeldItem::PrimaryWeapon) < 0.0001) { ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "PrimaryItem"); int currentAmmoInt = (int)((double)currentItem["Ammo"]); currentItem["Ammo"] = (double)(currentAmmoInt - 1); - currentItem["CoolDownTimer"] = (double)2; + currentItem["CoolDownTimer"] = 2.0;//change later! } - if (fabs((double)player["EquippedItem"] - (double)2) < (double) 0.0001f) { + if (fabs((double)player["EquippedItem"] - (double)HeldItem::SecondaryWeapon) < 0.0001) { ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "SecondaryItem"); int currentAmmoInt = (int)((double)currentItem["Ammo"]); currentItem["Ammo"] = (double)(currentAmmoInt - 1); - currentItem["CoolDownTimer"] = (double)2; + currentItem["CoolDownTimer"] = 2.0;//change later! } //create and publish the shoot event Events::Shoot eShoot; eShoot.currentAimingPoint = aimingCoordinates; - eShoot.weaponType = (int)player["EquippedItem"]; + eShoot.currentlyEquippedItem = (int) ((double)player["EquippedItem"]); m_EventBroker->Publish(eShoot); } } diff --git a/src/Tests/ShootEventTest.cpp b/src/Tests/ShootEventTest.cpp index 22c2a0eb..67a9985e 100644 --- a/src/Tests/ShootEventTest.cpp +++ b/src/Tests/ShootEventTest.cpp @@ -148,47 +148,47 @@ ShootEventTest::~ShootEventTest() void ShootEventTest::TestSetup1(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) { //set currentweap - player["EquippedItem"] = (double)1.0f; + player["EquippedItem"] = 1.0; //set ammo set cooldown - pItem["Ammo"] = (double)100.0f; - pItem["CoolDownTimer"] = (double)0.0f; + pItem["Ammo"] = 100.0; + pItem["CoolDownTimer"] = 0.0; } void ShootEventTest::TestSetup2(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) { //set currentweap - player["EquippedItem"] = (double)2.0f; + player["EquippedItem"] = 2.0; //set ammo set cooldown - sItem["Ammo"] = (double)10.0f; - sItem["CoolDownTimer"] = (double)0.0f; + sItem["Ammo"] = 10.0; + sItem["CoolDownTimer"] = 0.0; } void ShootEventTest::TestSetup3(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) { - player["EquippedItem"] = (double)0.0f; - pItem["Ammo"] = (double)100.0f; - sItem["Ammo"] = (double)100.0f; + player["EquippedItem"] = 0.0; + pItem["Ammo"] = 100.0; + sItem["Ammo"] = 100.0; //TestSucceeded will be set to false if ammo changes during the 100 loops TestSucceeded = true; } void ShootEventTest::TestSetup4(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) { //set currentweap - player["EquippedItem"] = (double)1.0f; + player["EquippedItem"] = 1.0; //set ammo set cooldown - pItem["Ammo"] = (double)100.0f; - pItem["CoolDownTimer"] = (double)5.0f; + pItem["Ammo"] = 100.0; + pItem["CoolDownTimer"] = 5.0; //TestSucceeded will be set to false if ammo changes during the 100 loops TestSucceeded = true; } void ShootEventTest::TestSuccess1() { //if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired double currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"]; - if (currentAmmo == (double)99) + if (currentAmmo == 99.0) TestSucceeded = true; } void ShootEventTest::TestSuccess2() { //if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired double currentAmmo = m_World->GetComponent(m_PlayerID, "SecondaryItem")["Ammo"]; - if (currentAmmo == (double)9) + if (currentAmmo == 9.0) TestSucceeded = true; } void ShootEventTest::TestSuccess3() { @@ -201,7 +201,7 @@ void ShootEventTest::TestSuccess3() { //if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired double currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"]; double currentAmmoSecondary = m_World->GetComponent(m_PlayerID, "SecondaryItem")["Ammo"]; - if (currentAmmo != (double)100 || currentAmmoSecondary != (double)100) + if (currentAmmo != 100.0 || currentAmmoSecondary != 100.0) TestSucceeded = false; } void ShootEventTest::TestSuccess4() { @@ -213,7 +213,7 @@ void ShootEventTest::TestSuccess4() { m_EventBroker->Publish(eMouseRelease); //if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired double currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"]; - if (currentAmmo != (double)100) + if (currentAmmo != 100.0) TestSucceeded = false; } void ShootEventTest::Tick() From 0cc58f088a6126abd1f72191411f688c7944cd9c Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Mon, 11 Jan 2016 17:15:49 +0100 Subject: [PATCH 05/13] EquippedItem,Ammo got changed to int instead of double. Loading entities from map the new way in Tests. ComponentWrapper:s Name is now Type --- include/Engine/Core/ComponentWrapper.h | 2 +- include/Game/PlayerSystem.h | 4 +- resources/Schema/Components/Player.xsd | 2 +- resources/Schema/Components/PrimaryItem.xsd | 2 +- resources/Schema/Components/SecondaryItem.xsd | 2 +- src/Game/PlayerSystem.cpp | 22 ++++---- src/Tests/HealthSystemTest.cpp | 9 +++- src/Tests/HealthSystemTest.h | 2 +- src/Tests/OctTreeTestGameClass.cpp | 2 +- src/Tests/OctTreeTestGameClass.h | 2 +- src/Tests/ResourceManagerTest.cpp | 1 - src/Tests/ShootEventTest.cpp | 53 ++++++++++--------- src/Tests/ShootEventTest.h | 6 ++- 13 files changed, 60 insertions(+), 49 deletions(-) diff --git a/include/Engine/Core/ComponentWrapper.h b/include/Engine/Core/ComponentWrapper.h index 922b3d79..f4761e40 100644 --- a/include/Engine/Core/ComponentWrapper.h +++ b/include/Engine/Core/ComponentWrapper.h @@ -78,7 +78,7 @@ public: void AddProperty(std::string fieldName, T defaultValue) { m_DefaultValues.push_back(defaultValue); - m_ComponentInfo.Fields[fieldName].Name = typeid(T).name(); + m_ComponentInfo.Fields[fieldName].Type = typeid(T).name(); m_ComponentInfo.Fields[fieldName].Offset = m_ComponentInfo.Meta.Stride; m_ComponentInfo.Fields[fieldName].Stride = sizeof(T); m_ComponentInfo.Meta.Stride += sizeof(T); diff --git a/include/Game/PlayerSystem.h b/include/Game/PlayerSystem.h index 3544c63c..897ee207 100644 --- a/include/Game/PlayerSystem.h +++ b/include/Game/PlayerSystem.h @@ -37,8 +37,8 @@ private: bool PlayerSystem::OnMouseRelease(const Events::MouseRelease& e); enum class HeldItem { None = 0, - PrimaryWeapon = 1, - SecondaryWeapon = 2 + PrimaryItem = 1, + SecondaryItem = 2 }; }; diff --git a/resources/Schema/Components/Player.xsd b/resources/Schema/Components/Player.xsd index 9ffc28b0..617b7d30 100644 --- a/resources/Schema/Components/Player.xsd +++ b/resources/Schema/Components/Player.xsd @@ -14,7 +14,7 @@ - + diff --git a/resources/Schema/Components/PrimaryItem.xsd b/resources/Schema/Components/PrimaryItem.xsd index bbff122d..35e2fca6 100644 --- a/resources/Schema/Components/PrimaryItem.xsd +++ b/resources/Schema/Components/PrimaryItem.xsd @@ -9,7 +9,7 @@ - + Ammo count diff --git a/resources/Schema/Components/SecondaryItem.xsd b/resources/Schema/Components/SecondaryItem.xsd index ab428920..bee25541 100644 --- a/resources/Schema/Components/SecondaryItem.xsd +++ b/resources/Schema/Components/SecondaryItem.xsd @@ -9,7 +9,7 @@ - + Ammo count diff --git a/src/Game/PlayerSystem.cpp b/src/Game/PlayerSystem.cpp index ca39ed4f..dff5c410 100644 --- a/src/Game/PlayerSystem.cpp +++ b/src/Game/PlayerSystem.cpp @@ -27,33 +27,31 @@ void PlayerSystem::UpdateComponent(World * world, ComponentWrapper & player, dou leftMouseWasReleased = false; //get the health component linked to the playerId double currentHealth = (double)world->GetComponent(player.EntityID, "Health")["Health"]; - double currentAmmo = 0.0; + int currentAmmo = 0; double currentCoolDownTimer = 0.0; - if (fabs((double)player["EquippedItem"] - (double)HeldItem::PrimaryWeapon) < 0.0001) { + if ((int)player["EquippedItem"] == (int)HeldItem::PrimaryItem) { ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "PrimaryItem"); - currentAmmo = (double)currentItem["Ammo"]; + currentAmmo = (int)currentItem["Ammo"]; currentCoolDownTimer = (double)currentItem["CoolDownTimer"]; } - if (fabs((double)player["EquippedItem"] - (double)HeldItem::SecondaryWeapon) < 0.0001) { + if ((int)player["EquippedItem"] == (int)HeldItem::SecondaryItem) { ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "SecondaryItem"); - currentAmmo = (double)currentItem["Ammo"]; + currentAmmo = (int)currentItem["Ammo"]; currentCoolDownTimer = (double)currentItem["CoolDownTimer"]; } - if (currentHealth > 0.0 && currentAmmo > 0.0 && currentCoolDownTimer < 0.001) { + if (currentHealth > 0.0 && currentAmmo > 0 && currentCoolDownTimer < 0.001) { //decrease ammo count //TODO: temp, set the cooldowntimer - probably done in some other system (itemSystem?) later - if (fabs((double)player["EquippedItem"] - (double)HeldItem::PrimaryWeapon) < 0.0001) { + if ((int)player["EquippedItem"] == (int)HeldItem::PrimaryItem) { ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "PrimaryItem"); - int currentAmmoInt = (int)((double)currentItem["Ammo"]); - currentItem["Ammo"] = (double)(currentAmmoInt - 1); + currentItem["Ammo"] = (int)currentItem["Ammo"] - 1; currentItem["CoolDownTimer"] = 2.0;//change later! } - if (fabs((double)player["EquippedItem"] - (double)HeldItem::SecondaryWeapon) < 0.0001) { + if ((int)player["EquippedItem"] == (int)HeldItem::SecondaryItem) { ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "SecondaryItem"); - int currentAmmoInt = (int)((double)currentItem["Ammo"]); - currentItem["Ammo"] = (double)(currentAmmoInt - 1); + currentItem["Ammo"] = (int)currentItem["Ammo"] - 1; currentItem["CoolDownTimer"] = 2.0;//change later! } //create and publish the shoot event diff --git a/src/Tests/HealthSystemTest.cpp b/src/Tests/HealthSystemTest.cpp index 84d6199d..feab858a 100644 --- a/src/Tests/HealthSystemTest.cpp +++ b/src/Tests/HealthSystemTest.cpp @@ -30,7 +30,7 @@ BOOST_AUTO_TEST_SUITE_END() GameHealthSystemTest::GameHealthSystemTest() { ResourceManager::RegisterType("ConfigFile"); - ResourceManager::RegisterType("EntityXMLFile"); + ResourceManager::RegisterType("EntityFile"); m_Config = ResourceManager::Load("Config.ini"); LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get("Debug.LogLevel", 1)); @@ -41,8 +41,13 @@ GameHealthSystemTest::GameHealthSystemTest() // Create a world m_World = new World(); std::string mapToLoad = m_Config->Get("Debug.LoadMap", ""); + if (!mapToLoad.empty()) { - ResourceManager::Load(mapToLoad)->PopulateWorld(m_World); + auto file = ResourceManager::Load(mapToLoad); + EntityFilePreprocessor fpp(file); + fpp.RegisterComponents(m_World); + EntityFileParser fp(file); + fp.MergeEntities(m_World); } // Create system pipeline diff --git a/src/Tests/HealthSystemTest.h b/src/Tests/HealthSystemTest.h index 664d2ef3..2890dfc1 100644 --- a/src/Tests/HealthSystemTest.h +++ b/src/Tests/HealthSystemTest.h @@ -13,7 +13,7 @@ #include "Input/KeyboardInputHandler.h" #include "Input/MouseInputHandler.h" #include "Core/EKeyDown.h" -#include "Core/EntityXMLFile.h" +#include "Core/EntityFile.h" #include "Core/SystemPipeline.h" #include "RaptorCopterSystem.h" #include "PlayerSystem.h" diff --git a/src/Tests/OctTreeTestGameClass.cpp b/src/Tests/OctTreeTestGameClass.cpp index 10d4d6a5..0f195cec 100644 --- a/src/Tests/OctTreeTestGameClass.cpp +++ b/src/Tests/OctTreeTestGameClass.cpp @@ -5,7 +5,7 @@ Game::Game(int argc, char* argv[]) : someOctTree(AABB(-0.5f*worldSize, 0.5f*worl ResourceManager::RegisterType("ConfigFile"); ResourceManager::RegisterType("Model"); ResourceManager::RegisterType("Texture"); - ResourceManager::RegisterType("EntityXMLFile"); + ResourceManager::RegisterType("EntityFile"); ResourceManager::RegisterType("ShaderProgram"); m_Config = ResourceManager::Load("Config.ini"); diff --git a/src/Tests/OctTreeTestGameClass.h b/src/Tests/OctTreeTestGameClass.h index 6dc9404e..c36707c8 100644 --- a/src/Tests/OctTreeTestGameClass.h +++ b/src/Tests/OctTreeTestGameClass.h @@ -13,7 +13,7 @@ #include "Input/KeyboardInputHandler.h" #include "Input/MouseInputHandler.h" #include "Core/EKeyDown.h" -#include "Core/EntityXMLFile.h" +#include "Core/EntityFile.h" #include "Core/SystemPipeline.h" #include "RaptorCopterSystem.h" #include "PlayerSystem.h" diff --git a/src/Tests/ResourceManagerTest.cpp b/src/Tests/ResourceManagerTest.cpp index a3edb7b8..9d62fa93 100644 --- a/src/Tests/ResourceManagerTest.cpp +++ b/src/Tests/ResourceManagerTest.cpp @@ -7,7 +7,6 @@ #include "Core/ResourceManager.h" #include "Core/ConfigFile.h" #include "Rendering/Renderer.h" -#include "Core/EntityXMLFile.h" #include "Engine\Rendering\Texture.h" BOOST_AUTO_TEST_SUITE(resourceManagerTests) diff --git a/src/Tests/ShootEventTest.cpp b/src/Tests/ShootEventTest.cpp index 67a9985e..f24bfed8 100644 --- a/src/Tests/ShootEventTest.cpp +++ b/src/Tests/ShootEventTest.cpp @@ -81,9 +81,10 @@ BOOST_AUTO_TEST_SUITE_END() ShootEventTest::ShootEventTest(int runTestNumber) { ResourceManager::RegisterType("ConfigFile"); - ResourceManager::RegisterType("EntityXMLFile"); + ResourceManager::RegisterType("EntityFile"); m_Config = ResourceManager::Load("Config.ini"); + std::string mapToLoad = m_Config->Get("Debug.LoadMap", ""); LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get("Debug.LogLevel", 1)); // Create the core event broker @@ -91,22 +92,26 @@ ShootEventTest::ShootEventTest(int runTestNumber) // Create a world m_World = new World(); - std::string mapToLoad = m_Config->Get("Debug.LoadMap", ""); - if (!mapToLoad.empty()) { - ResourceManager::Load(mapToLoad)->PopulateWorld(m_World); - } // Create system pipeline m_SystemPipeline = new SystemPipeline(m_EventBroker); m_SystemPipeline->AddSystem(0); m_SystemPipeline->AddSystem(0); + if (!mapToLoad.empty()) { + auto file = ResourceManager::Load(mapToLoad); + EntityFilePreprocessor fpp(file); + fpp.RegisterComponents(m_World); + EntityFileParser fp(file); + fp.MergeEntities(m_World); + } + //The Test //create entity which has transform,player,model,health in it. i.e. is a player EntityID playerID = m_World->CreateEntity(); m_PlayerID = playerID; - ComponentWrapper health = m_World->AttachComponent(playerID, "Health"); ComponentWrapper& player = m_World->AttachComponent(playerID, "Player"); + ComponentWrapper health = m_World->AttachComponent(playerID, "Health"); //attach 2x weaps ComponentWrapper& pItem = m_World->AttachComponent(playerID, "PrimaryItem"); ComponentWrapper& sItem = m_World->AttachComponent(playerID, "SecondaryItem"); @@ -148,47 +153,47 @@ ShootEventTest::~ShootEventTest() void ShootEventTest::TestSetup1(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) { //set currentweap - player["EquippedItem"] = 1.0; + player["EquippedItem"] = 1; //set ammo set cooldown - pItem["Ammo"] = 100.0; + pItem["Ammo"] = 100; pItem["CoolDownTimer"] = 0.0; } void ShootEventTest::TestSetup2(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) { //set currentweap - player["EquippedItem"] = 2.0; + player["EquippedItem"] = 2; //set ammo set cooldown - sItem["Ammo"] = 10.0; + sItem["Ammo"] = 10; sItem["CoolDownTimer"] = 0.0; } void ShootEventTest::TestSetup3(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) { - player["EquippedItem"] = 0.0; - pItem["Ammo"] = 100.0; - sItem["Ammo"] = 100.0; + player["EquippedItem"] = 0; + pItem["Ammo"] = 100; + sItem["Ammo"] = 100; //TestSucceeded will be set to false if ammo changes during the 100 loops TestSucceeded = true; } void ShootEventTest::TestSetup4(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) { //set currentweap - player["EquippedItem"] = 1.0; + player["EquippedItem"] = 1; //set ammo set cooldown - pItem["Ammo"] = 100.0; + pItem["Ammo"] = 100; pItem["CoolDownTimer"] = 5.0; //TestSucceeded will be set to false if ammo changes during the 100 loops TestSucceeded = true; } void ShootEventTest::TestSuccess1() { //if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired - double currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"]; - if (currentAmmo == 99.0) + int currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"]; + if (currentAmmo == 99) TestSucceeded = true; } void ShootEventTest::TestSuccess2() { //if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired - double currentAmmo = m_World->GetComponent(m_PlayerID, "SecondaryItem")["Ammo"]; - if (currentAmmo == 9.0) + int currentAmmo = m_World->GetComponent(m_PlayerID, "SecondaryItem")["Ammo"]; + if (currentAmmo == 9) TestSucceeded = true; } void ShootEventTest::TestSuccess3() { @@ -199,9 +204,9 @@ void ShootEventTest::TestSuccess3() { eMouseRelease.Y = 1.0f; m_EventBroker->Publish(eMouseRelease); //if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired - double currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"]; - double currentAmmoSecondary = m_World->GetComponent(m_PlayerID, "SecondaryItem")["Ammo"]; - if (currentAmmo != 100.0 || currentAmmoSecondary != 100.0) + int currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"]; + int currentAmmoSecondary = m_World->GetComponent(m_PlayerID, "SecondaryItem")["Ammo"]; + if (currentAmmo != 100 || currentAmmoSecondary != 100) TestSucceeded = false; } void ShootEventTest::TestSuccess4() { @@ -212,8 +217,8 @@ void ShootEventTest::TestSuccess4() { eMouseRelease.Y = 1.0f; m_EventBroker->Publish(eMouseRelease); //if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired - double currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"]; - if (currentAmmo != 100.0) + int currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"]; + if (currentAmmo != 100) TestSucceeded = false; } void ShootEventTest::Tick() diff --git a/src/Tests/ShootEventTest.h b/src/Tests/ShootEventTest.h index 0ffa1f91..21ae7d9e 100644 --- a/src/Tests/ShootEventTest.h +++ b/src/Tests/ShootEventTest.h @@ -9,10 +9,14 @@ #include "Input/KeyboardInputHandler.h" #include "Input/MouseInputHandler.h" #include "Core/EKeyDown.h" -#include "Core/EntityXMLFile.h" +#include "Core/EntityFile.h" #include "Core/SystemPipeline.h" #include "PlayerSystem.h" +#include "Core/EntityFilePreprocessor.h" +#include "Core/EntityFileParser.h" +#include "Core/EntityFileWriter.h" + #include "Core\EMouseRelease.h" #include "Core\EShoot.h" From 774bb8ce56ba5a18afaa9dab01d680e308fe42d9 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Mon, 11 Jan 2016 17:36:23 +0100 Subject: [PATCH 06/13] Simplified PlayerSystem branches a lot! Thanks William! --- src/Game/PlayerSystem.cpp | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/src/Game/PlayerSystem.cpp b/src/Game/PlayerSystem.cpp index dff5c410..c9112b01 100644 --- a/src/Game/PlayerSystem.cpp +++ b/src/Game/PlayerSystem.cpp @@ -29,36 +29,28 @@ void PlayerSystem::UpdateComponent(World * world, ComponentWrapper & player, dou double currentHealth = (double)world->GetComponent(player.EntityID, "Health")["Health"]; int currentAmmo = 0; double currentCoolDownTimer = 0.0; + std::string HeldItemString = ""; + if ((int)player["EquippedItem"] == (int)HeldItem::PrimaryItem) + HeldItemString = "PrimaryItem"; + if ((int)player["EquippedItem"] == (int)HeldItem::SecondaryItem) + HeldItemString = "SecondaryItem"; - if ((int)player["EquippedItem"] == (int)HeldItem::PrimaryItem) { - ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "PrimaryItem"); + if (HeldItemString != "") { + ComponentWrapper& currentItem = world->GetComponent(player.EntityID, HeldItemString); currentAmmo = (int)currentItem["Ammo"]; currentCoolDownTimer = (double)currentItem["CoolDownTimer"]; - } - if ((int)player["EquippedItem"] == (int)HeldItem::SecondaryItem) { - ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "SecondaryItem"); - currentAmmo = (int)currentItem["Ammo"]; - currentCoolDownTimer = (double)currentItem["CoolDownTimer"]; - } - if (currentHealth > 0.0 && currentAmmo > 0 && currentCoolDownTimer < 0.001) { - //decrease ammo count - //TODO: temp, set the cooldowntimer - probably done in some other system (itemSystem?) later - if ((int)player["EquippedItem"] == (int)HeldItem::PrimaryItem) { - ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "PrimaryItem"); + if (currentHealth > 0.0 && currentAmmo > 0 && currentCoolDownTimer < 0.001) { + //decrease ammo count + //TODO: temp, set the cooldowntimer - probably done in some other system (itemSystem?) later currentItem["Ammo"] = (int)currentItem["Ammo"] - 1; currentItem["CoolDownTimer"] = 2.0;//change later! + //create and publish the shoot event + Events::Shoot eShoot; + eShoot.currentAimingPoint = aimingCoordinates; + eShoot.currentlyEquippedItem = (int)(player["EquippedItem"]); + m_EventBroker->Publish(eShoot); } - if ((int)player["EquippedItem"] == (int)HeldItem::SecondaryItem) { - ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "SecondaryItem"); - currentItem["Ammo"] = (int)currentItem["Ammo"] - 1; - currentItem["CoolDownTimer"] = 2.0;//change later! - } - //create and publish the shoot event - Events::Shoot eShoot; - eShoot.currentAimingPoint = aimingCoordinates; - eShoot.currentlyEquippedItem = (int) ((double)player["EquippedItem"]); - m_EventBroker->Publish(eShoot); } } } From a20ca49d5327c70838ed76bba430f5d837f4cba6 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Tue, 12 Jan 2016 10:46:34 +0100 Subject: [PATCH 07/13] Fixed typo backslash instead of slash in various classes (the includes) --- include/Game/HealthSystem.h | 6 +++--- include/Game/PlayerSystem.h | 4 ++-- src/Tests/CollisionTest.cpp | 6 +++--- src/Tests/ConfigFileTest.cpp | 2 +- src/Tests/EventFixture.h | 2 +- src/Tests/InputManagerTest.cpp | 2 +- src/Tests/OctTreeTestAnders.cpp | 2 +- src/Tests/OctTreeTestHardCodedTestWorld.h | 2 +- src/Tests/ResourceManagerTest.cpp | 2 +- src/Tests/ShootEventTest.h | 4 ++-- 10 files changed, 16 insertions(+), 16 deletions(-) diff --git a/include/Game/HealthSystem.h b/include/Game/HealthSystem.h index a836e797..11ac68bd 100644 --- a/include/Game/HealthSystem.h +++ b/include/Game/HealthSystem.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 #include diff --git a/include/Game/PlayerSystem.h b/include/Game/PlayerSystem.h index 897ee207..a48af3e4 100644 --- a/include/Game/PlayerSystem.h +++ b/include/Game/PlayerSystem.h @@ -7,8 +7,8 @@ #include "Common.h" #include "Core/System.h" #include "Collision/ETrigger.h" -#include "Core\EMouseRelease.h" -#include "Core\EShoot.h" +#include "Core/EMouseRelease.h" +#include "Core/EShoot.h" class PlayerSystem : public PureSystem { diff --git a/src/Tests/CollisionTest.cpp b/src/Tests/CollisionTest.cpp index e6a29298..57329477 100644 --- a/src/Tests/CollisionTest.cpp +++ b/src/Tests/CollisionTest.cpp @@ -13,9 +13,9 @@ using boost::unit_test_framework::test_case; #include //ray vs model -#include "Engine\Core\ResourceManager.h" -#include "Engine\Rendering\Model.h" -#include "Engine\Core\Ray.h" +#include "Engine/Core/ResourceManager.h" +#include "Engine/Rendering/Model.h" +#include "Engine/Core/Ray.h" //vs memleaks //#define _CRTDBG_MAP_ALLOC diff --git a/src/Tests/ConfigFileTest.cpp b/src/Tests/ConfigFileTest.cpp index 28be5589..36cd6c05 100644 --- a/src/Tests/ConfigFileTest.cpp +++ b/src/Tests/ConfigFileTest.cpp @@ -5,7 +5,7 @@ using boost::unit_test_framework::test_case; #include //srand //#define private public -#include "Engine\Core\ConfigFile.h" +#include "Engine/Core/ConfigFile.h" #define _CRTDBG_MAP_ALLOC #include diff --git a/src/Tests/EventFixture.h b/src/Tests/EventFixture.h index 42258932..a708b962 100644 --- a/src/Tests/EventFixture.h +++ b/src/Tests/EventFixture.h @@ -2,7 +2,7 @@ #define EVENTFIXTURE_H #include -#include "Core\EventBroker.h" +#include "Core/EventBroker.h" template struct EventFixture diff --git a/src/Tests/InputManagerTest.cpp b/src/Tests/InputManagerTest.cpp index 5b447c2b..0ef9434a 100644 --- a/src/Tests/InputManagerTest.cpp +++ b/src/Tests/InputManagerTest.cpp @@ -1,6 +1,6 @@ #include -#include "Engine\Core\InputManager.h" +#include "Engine/Core/InputManager.h" BOOST_AUTO_TEST_SUITE(inputManagerTests) diff --git a/src/Tests/OctTreeTestAnders.cpp b/src/Tests/OctTreeTestAnders.cpp index b61caead..477ccbf4 100644 --- a/src/Tests/OctTreeTestAnders.cpp +++ b/src/Tests/OctTreeTestAnders.cpp @@ -15,7 +15,7 @@ using boost::unit_test_framework::test_case; #include "OctTreeTestGameClass.h" #define private public//HACK! Needed for white box testing -#include +#include "Engine/Core/OctTree.h" //else we would have to "open up" the octTree class more with get/sets, public methods, etc. which is not good encapsulation-wise BOOST_AUTO_TEST_SUITE(octTreeTestsA) diff --git a/src/Tests/OctTreeTestHardCodedTestWorld.h b/src/Tests/OctTreeTestHardCodedTestWorld.h index 512716df..6f68eba6 100644 --- a/src/Tests/OctTreeTestHardCodedTestWorld.h +++ b/src/Tests/OctTreeTestHardCodedTestWorld.h @@ -9,7 +9,7 @@ //last! //#include "OldOctTree.h" #define private public -#include +#include class HardcodedTestWorld : public World { diff --git a/src/Tests/ResourceManagerTest.cpp b/src/Tests/ResourceManagerTest.cpp index 9d62fa93..b68936ec 100644 --- a/src/Tests/ResourceManagerTest.cpp +++ b/src/Tests/ResourceManagerTest.cpp @@ -7,7 +7,7 @@ #include "Core/ResourceManager.h" #include "Core/ConfigFile.h" #include "Rendering/Renderer.h" -#include "Engine\Rendering\Texture.h" +#include "Engine/Rendering/Texture.h" BOOST_AUTO_TEST_SUITE(resourceManagerTests) diff --git a/src/Tests/ShootEventTest.h b/src/Tests/ShootEventTest.h index 21ae7d9e..e860f41f 100644 --- a/src/Tests/ShootEventTest.h +++ b/src/Tests/ShootEventTest.h @@ -17,8 +17,8 @@ #include "Core/EntityFileParser.h" #include "Core/EntityFileWriter.h" -#include "Core\EMouseRelease.h" -#include "Core\EShoot.h" +#include "Core/EMouseRelease.h" +#include "Core/EShoot.h" class ShootEventTest { From c14f3789f7bb1ee6820c56280691a85afe341e17 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Wed, 13 Jan 2016 15:26:10 +0100 Subject: [PATCH 08/13] PlayerSystem now counts down the CoolDownTimer on both HeldItems for the player. Updated ShootEventTest to verify this --- src/Game/PlayerSystem.cpp | 9 ++++++++- src/Tests/ShootEventTest.cpp | 10 ++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Game/PlayerSystem.cpp b/src/Game/PlayerSystem.cpp index c9112b01..7bf576af 100644 --- a/src/Game/PlayerSystem.cpp +++ b/src/Game/PlayerSystem.cpp @@ -1,4 +1,5 @@ #include "PlayerSystem.h" +#include void PlayerSystem::UpdateComponent(World * world, ComponentWrapper & player, double dt) { @@ -22,6 +23,12 @@ void PlayerSystem::UpdateComponent(World * world, ComponentWrapper & player, dou (glm::vec3&)transform["Position"] += (glm::vec3)player["Velocity"]; } + //decrease CoolDownTimers for both HeldItems + ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "PrimaryItem"); + ComponentWrapper& currentItem2 = world->GetComponent(player.EntityID, "SecondaryItem"); + currentItem["CoolDownTimer"] = std::max(0.0, (double)currentItem["CoolDownTimer"] - dt); + currentItem2["CoolDownTimer"] = std::max(0.0, (double)currentItem2["CoolDownTimer"] - dt); + //do shootEvent: if left mouse was released, and ammo/weaponcooldown/playeralive/shootingcooldown are ok if (leftMouseWasReleased) { leftMouseWasReleased = false; @@ -44,7 +51,7 @@ void PlayerSystem::UpdateComponent(World * world, ComponentWrapper & player, dou //decrease ammo count //TODO: temp, set the cooldowntimer - probably done in some other system (itemSystem?) later currentItem["Ammo"] = (int)currentItem["Ammo"] - 1; - currentItem["CoolDownTimer"] = 2.0;//change later! + currentItem["CoolDownTimer"] = 2.0;//change later! probably to maxCoolDownTimer //create and publish the shoot event Events::Shoot eShoot; eShoot.currentAimingPoint = aimingCoordinates; diff --git a/src/Tests/ShootEventTest.cpp b/src/Tests/ShootEventTest.cpp index f24bfed8..3af66b88 100644 --- a/src/Tests/ShootEventTest.cpp +++ b/src/Tests/ShootEventTest.cpp @@ -180,7 +180,7 @@ void ShootEventTest::TestSetup4(ComponentWrapper &player, ComponentWrapper &pIte player["EquippedItem"] = 1; //set ammo set cooldown pItem["Ammo"] = 100; - pItem["CoolDownTimer"] = 5.0; + pItem["CoolDownTimer"] = 99999999.0;//very long coolDownTimer //TestSucceeded will be set to false if ammo changes during the 100 loops TestSucceeded = true; } @@ -225,10 +225,12 @@ void ShootEventTest::Tick() { glfwPollEvents(); - double currentTime = glfwGetTime(); - double dt = currentTime - m_LastTime; - m_LastTime = currentTime; + //double currentTime = glfwGetTime(); + //double dt = currentTime - m_LastTime; + //m_LastTime = currentTime; + //just set dt to 1.0 + double dt = 0.34567; // Iterate through systems and update world! m_SystemPipeline->Update(m_World, dt); From e6527196eda97de6516719d41802d0b1c4aa1877 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Wed, 13 Jan 2016 15:50:30 +0100 Subject: [PATCH 09/13] Modified a few files according to the current CodeStandards --- include/Engine/Core/EShoot.h | 4 ++-- include/Game/PlayerSystem.h | 5 +++-- src/Game/PlayerSystem.cpp | 25 ++++++++++++------------- src/Tests/ShootEventTest.cpp | 8 ++++---- src/Tests/ShootEventTest.h | 8 ++++---- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/include/Engine/Core/EShoot.h b/include/Engine/Core/EShoot.h index 3887606b..9e395d62 100644 --- a/include/Engine/Core/EShoot.h +++ b/include/Engine/Core/EShoot.h @@ -12,9 +12,9 @@ struct Shoot : Event { //shotgun etc has different amounts of damage probably (a sniper shot might one-shot) //also different weapons will have different spread - int currentlyEquippedItem; + int CurrentlyEquippedItem; //currentAimingPoint must be sent, in case the camera is moved while the event is being processed - glm::vec2 currentAimingPoint; + glm::vec2 CurrentAimingPoint; }; } diff --git a/include/Game/PlayerSystem.h b/include/Game/PlayerSystem.h index a48af3e4..e7ef6ff0 100644 --- a/include/Game/PlayerSystem.h +++ b/include/Game/PlayerSystem.h @@ -9,6 +9,7 @@ #include "Collision/ETrigger.h" #include "Core/EMouseRelease.h" #include "Core/EShoot.h" +#include class PlayerSystem : public PureSystem { @@ -25,8 +26,8 @@ public: virtual void UpdateComponent(World* world, ComponentWrapper& player, double dt) override; private: float m_Speed = 5; - bool leftMouseWasReleased = false; - glm::vec2 aimingCoordinates; + bool m_LeftMouseWasReleased = false; + glm::vec2 m_AimingCoordinates; EventRelay m_EEnter; bool OnEnter(const Events::TriggerEnter &event); EventRelay m_ETouch; diff --git a/src/Game/PlayerSystem.cpp b/src/Game/PlayerSystem.cpp index 7bf576af..3120f035 100644 --- a/src/Game/PlayerSystem.cpp +++ b/src/Game/PlayerSystem.cpp @@ -1,7 +1,6 @@ #include "PlayerSystem.h" -#include -void PlayerSystem::UpdateComponent(World * world, ComponentWrapper & player, double dt) +void PlayerSystem::UpdateComponent(World* world, ComponentWrapper& player, double dt) { player["Velocity"] = glm::vec3(0.f, 0.f, 0.f); if ((bool&)player["Forward"] == true) { @@ -30,20 +29,20 @@ void PlayerSystem::UpdateComponent(World * world, ComponentWrapper & player, dou currentItem2["CoolDownTimer"] = std::max(0.0, (double)currentItem2["CoolDownTimer"] - dt); //do shootEvent: if left mouse was released, and ammo/weaponcooldown/playeralive/shootingcooldown are ok - if (leftMouseWasReleased) { - leftMouseWasReleased = false; + if (m_LeftMouseWasReleased) { + m_LeftMouseWasReleased = false; //get the health component linked to the playerId double currentHealth = (double)world->GetComponent(player.EntityID, "Health")["Health"]; int currentAmmo = 0; double currentCoolDownTimer = 0.0; - std::string HeldItemString = ""; + std::string heldItemString = ""; if ((int)player["EquippedItem"] == (int)HeldItem::PrimaryItem) - HeldItemString = "PrimaryItem"; + heldItemString = "PrimaryItem"; if ((int)player["EquippedItem"] == (int)HeldItem::SecondaryItem) - HeldItemString = "SecondaryItem"; + heldItemString = "SecondaryItem"; - if (HeldItemString != "") { - ComponentWrapper& currentItem = world->GetComponent(player.EntityID, HeldItemString); + if (heldItemString != "") { + ComponentWrapper& currentItem = world->GetComponent(player.EntityID, heldItemString); currentAmmo = (int)currentItem["Ammo"]; currentCoolDownTimer = (double)currentItem["CoolDownTimer"]; @@ -54,8 +53,8 @@ void PlayerSystem::UpdateComponent(World * world, ComponentWrapper & player, dou currentItem["CoolDownTimer"] = 2.0;//change later! probably to maxCoolDownTimer //create and publish the shoot event Events::Shoot eShoot; - eShoot.currentAimingPoint = aimingCoordinates; - eShoot.currentlyEquippedItem = (int)(player["EquippedItem"]); + eShoot.CurrentAimingPoint = m_AimingCoordinates; + eShoot.CurrentlyEquippedItem = (int)(player["EquippedItem"]); m_EventBroker->Publish(eShoot); } } @@ -86,7 +85,7 @@ bool PlayerSystem::OnMouseRelease(const Events::MouseRelease& e) //kolla om left mouse varit nere if (e.Button != GLFW_MOUSE_BUTTON_LEFT) return false; - aimingCoordinates = glm::vec2(e.X, e.Y); - leftMouseWasReleased = true; + m_AimingCoordinates = glm::vec2(e.X, e.Y); + m_LeftMouseWasReleased = true; return true; } \ No newline at end of file diff --git a/src/Tests/ShootEventTest.cpp b/src/Tests/ShootEventTest.cpp index 3af66b88..f9002eca 100644 --- a/src/Tests/ShootEventTest.cpp +++ b/src/Tests/ShootEventTest.cpp @@ -150,7 +150,7 @@ ShootEventTest::~ShootEventTest() delete m_EventBroker; } -void ShootEventTest::TestSetup1(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) +void ShootEventTest::TestSetup1(ComponentWrapper& player, ComponentWrapper& pItem, ComponentWrapper& sItem) { //set currentweap player["EquippedItem"] = 1; @@ -158,7 +158,7 @@ void ShootEventTest::TestSetup1(ComponentWrapper &player, ComponentWrapper &pIte pItem["Ammo"] = 100; pItem["CoolDownTimer"] = 0.0; } -void ShootEventTest::TestSetup2(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) +void ShootEventTest::TestSetup2(ComponentWrapper& player, ComponentWrapper& pItem, ComponentWrapper& sItem) { //set currentweap player["EquippedItem"] = 2; @@ -166,7 +166,7 @@ void ShootEventTest::TestSetup2(ComponentWrapper &player, ComponentWrapper &pIte sItem["Ammo"] = 10; sItem["CoolDownTimer"] = 0.0; } -void ShootEventTest::TestSetup3(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) +void ShootEventTest::TestSetup3(ComponentWrapper& player, ComponentWrapper& pItem, ComponentWrapper& sItem) { player["EquippedItem"] = 0; pItem["Ammo"] = 100; @@ -174,7 +174,7 @@ void ShootEventTest::TestSetup3(ComponentWrapper &player, ComponentWrapper &pIte //TestSucceeded will be set to false if ammo changes during the 100 loops TestSucceeded = true; } -void ShootEventTest::TestSetup4(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem) +void ShootEventTest::TestSetup4(ComponentWrapper& player, ComponentWrapper& pItem, ComponentWrapper& sItem) { //set currentweap player["EquippedItem"] = 1; diff --git a/src/Tests/ShootEventTest.h b/src/Tests/ShootEventTest.h index e860f41f..e796c17e 100644 --- a/src/Tests/ShootEventTest.h +++ b/src/Tests/ShootEventTest.h @@ -30,10 +30,10 @@ public: bool TestSucceeded = false; private: - void TestSetup1(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem); - void TestSetup2(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem); - void TestSetup3(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem); - void TestSetup4(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem); + void TestSetup1(ComponentWrapper& player, ComponentWrapper& pItem, ComponentWrapper& sItem); + void TestSetup2(ComponentWrapper& player, ComponentWrapper& pItem, ComponentWrapper& sItem); + void TestSetup3(ComponentWrapper& player, ComponentWrapper& pItem, ComponentWrapper& sItem); + void TestSetup4(ComponentWrapper& player, ComponentWrapper& pItem, ComponentWrapper& sItem); void TestSuccess1(); void TestSuccess2(); void TestSuccess3(); From c2e05de89f0a236864b8259d9a3ce4691452818d Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Thu, 21 Jan 2016 10:24:34 +0100 Subject: [PATCH 10/13] Deleted some components, etc for ShootEvent that will likely be used in a WeaponSystem instead --- include/Engine/Core/EShoot.h | 7 +- resources/Schema/Components.xsd | 3 - resources/Schema/Components/Player.xml | 1 - resources/Schema/Components/Player.xsd | 1 - resources/Schema/Components/PrimaryItem.xml | 4 - resources/Schema/Components/PrimaryItem.xsd | 21 -- resources/Schema/Components/SecondaryItem.xml | 4 - resources/Schema/Components/SecondaryItem.xsd | 21 -- resources/Schema/Types/Entity.xsd | 2 - src/Tests/ShootEventTest.cpp | 258 ------------------ src/Tests/ShootEventTest.h | 52 ---- 11 files changed, 2 insertions(+), 372 deletions(-) delete mode 100644 resources/Schema/Components/PrimaryItem.xml delete mode 100644 resources/Schema/Components/PrimaryItem.xsd delete mode 100644 resources/Schema/Components/SecondaryItem.xml delete mode 100644 resources/Schema/Components/SecondaryItem.xsd delete mode 100644 src/Tests/ShootEventTest.cpp delete mode 100644 src/Tests/ShootEventTest.h diff --git a/include/Engine/Core/EShoot.h b/include/Engine/Core/EShoot.h index 9e395d62..fd54122f 100644 --- a/include/Engine/Core/EShoot.h +++ b/include/Engine/Core/EShoot.h @@ -10,11 +10,8 @@ namespace Events struct Shoot : Event { - //shotgun etc has different amounts of damage probably (a sniper shot might one-shot) - //also different weapons will have different spread - int CurrentlyEquippedItem; - //currentAimingPoint must be sent, in case the camera is moved while the event is being processed - glm::vec2 CurrentAimingPoint; + //ID for who made the shot + EntityID shooter; }; } diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index a4931c18..bed93c1f 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -12,9 +12,6 @@ - - - diff --git a/resources/Schema/Components/Player.xml b/resources/Schema/Components/Player.xml index 4743e8c8..caefd6e6 100644 --- a/resources/Schema/Components/Player.xml +++ b/resources/Schema/Components/Player.xml @@ -1,6 +1,5 @@ - 0 false false diff --git a/resources/Schema/Components/Player.xsd b/resources/Schema/Components/Player.xsd index 617b7d30..1a315a35 100644 --- a/resources/Schema/Components/Player.xsd +++ b/resources/Schema/Components/Player.xsd @@ -14,7 +14,6 @@ - diff --git a/resources/Schema/Components/PrimaryItem.xml b/resources/Schema/Components/PrimaryItem.xml deleted file mode 100644 index 0d0ccca2..00000000 --- a/resources/Schema/Components/PrimaryItem.xml +++ /dev/null @@ -1,4 +0,0 @@ - - 0 - 0 - \ No newline at end of file diff --git a/resources/Schema/Components/PrimaryItem.xsd b/resources/Schema/Components/PrimaryItem.xsd deleted file mode 100644 index 35e2fca6..00000000 --- a/resources/Schema/Components/PrimaryItem.xsd +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - The Players Primary Item/Weapon - - - - - Ammo count - - - Cooldown till next item/weapon use - - - - - \ No newline at end of file diff --git a/resources/Schema/Components/SecondaryItem.xml b/resources/Schema/Components/SecondaryItem.xml deleted file mode 100644 index 095dfef6..00000000 --- a/resources/Schema/Components/SecondaryItem.xml +++ /dev/null @@ -1,4 +0,0 @@ - - 0 - 0 - \ No newline at end of file diff --git a/resources/Schema/Components/SecondaryItem.xsd b/resources/Schema/Components/SecondaryItem.xsd deleted file mode 100644 index bee25541..00000000 --- a/resources/Schema/Components/SecondaryItem.xsd +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - The Players Secondary Item/Weapon - - - - - Ammo count - - - Cooldown till next item/weapon use - - - - - \ No newline at end of file diff --git a/resources/Schema/Types/Entity.xsd b/resources/Schema/Types/Entity.xsd index 554996c1..b37692a9 100644 --- a/resources/Schema/Types/Entity.xsd +++ b/resources/Schema/Types/Entity.xsd @@ -21,8 +21,6 @@ - - diff --git a/src/Tests/ShootEventTest.cpp b/src/Tests/ShootEventTest.cpp deleted file mode 100644 index f9002eca..00000000 --- a/src/Tests/ShootEventTest.cpp +++ /dev/null @@ -1,258 +0,0 @@ -#include -using boost::unit_test_framework::test_suite; -using boost::unit_test_framework::test_case; - -#include "ShootEventTest.h" -#include "Game/HealthSystem.h" - -BOOST_AUTO_TEST_SUITE(ShootEventTestSuite) - -//dont use the same name as the classname in test cases... -BOOST_AUTO_TEST_CASE(ShootEventTest_PrimaryWeaponFiring) -{ - //Test firing primary weapon - ShootEventTest game(1); - //100 loops will be more than enough to do the test - int loops = 100; - bool success = false; - while (loops > 0) { - game.Tick(); - if (game.TestSucceeded) { - success = true; - break; - } - loops--; - } - //The system will process the events, hence it will take a while before we can read anything - BOOST_TEST(success); -} -BOOST_AUTO_TEST_CASE(ShootEventTest_SecondaryWeaponFiring) -{ - //Test firing secondary weapon - ShootEventTest game(2); - //100 loops will be more than enough to do the test - int loops = 100; - bool success = false; - while (loops > 0) { - game.Tick(); - if (game.TestSucceeded) { - success = true; - break; - } - loops--; - } - //The system will process the events, hence it will take a while before we can read anything - BOOST_TEST(success); -} -BOOST_AUTO_TEST_CASE(ShootEventTest_NoWeaponFiring) -{ - //Test firing with no weapon equipped - ShootEventTest game(3); - //100 loops will be more than enough to do the test - int loops = 100; - bool success = false; - while (loops > 0) { - game.Tick(); - loops--; - } - //The system will process the events, hence it will take a while before we can read anything - if (game.TestSucceeded) - success = true; - BOOST_TEST(success); -} -BOOST_AUTO_TEST_CASE(ShootEventTest_WeaponOnCooldown) -{ - //Test firing with weapon on cooldown - ShootEventTest game(4); - //100 loops will be more than enough to do the test - int loops = 100; - bool success = false; - while (loops > 0) { - game.Tick(); - loops--; - } - //The system will process the events, hence it will take a while before we can read anything - if (game.TestSucceeded) - success = true; - BOOST_TEST(success); -} -BOOST_AUTO_TEST_SUITE_END() - -ShootEventTest::ShootEventTest(int runTestNumber) -{ - ResourceManager::RegisterType("ConfigFile"); - ResourceManager::RegisterType("EntityFile"); - - m_Config = ResourceManager::Load("Config.ini"); - std::string mapToLoad = m_Config->Get("Debug.LoadMap", ""); - LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get("Debug.LogLevel", 1)); - - // Create the core event broker - m_EventBroker = new EventBroker(); - - // Create a world - m_World = new World(); - - // Create system pipeline - m_SystemPipeline = new SystemPipeline(m_EventBroker); - m_SystemPipeline->AddSystem(0); - m_SystemPipeline->AddSystem(0); - - if (!mapToLoad.empty()) { - auto file = ResourceManager::Load(mapToLoad); - EntityFilePreprocessor fpp(file); - fpp.RegisterComponents(m_World); - EntityFileParser fp(file); - fp.MergeEntities(m_World); - } - - //The Test - //create entity which has transform,player,model,health in it. i.e. is a player - EntityID playerID = m_World->CreateEntity(); - m_PlayerID = playerID; - ComponentWrapper& player = m_World->AttachComponent(playerID, "Player"); - ComponentWrapper health = m_World->AttachComponent(playerID, "Health"); - //attach 2x weaps - ComponentWrapper& pItem = m_World->AttachComponent(playerID, "PrimaryItem"); - ComponentWrapper& sItem = m_World->AttachComponent(playerID, "SecondaryItem"); - - m_RunTestNumber = runTestNumber; - switch (runTestNumber) - { - case 1: - TestSetup1(player, pItem, sItem); - break; - case 2: - TestSetup2(player, pItem, sItem); - break; - case 3: - TestSetup3(player, pItem, sItem); - break; - case 4: - TestSetup4(player, pItem, sItem); - break; - default: - break; - } - - //fire once = trigger event leftmousedown - Events::MouseRelease eMouseRelease; - eMouseRelease.Button = GLFW_MOUSE_BUTTON_LEFT; - eMouseRelease.X = 1.0f; - eMouseRelease.Y = 1.0f; - m_EventBroker->Publish(eMouseRelease); -} - -ShootEventTest::~ShootEventTest() -{ - delete m_SystemPipeline; - delete m_World; - delete m_EventBroker; -} - -void ShootEventTest::TestSetup1(ComponentWrapper& player, ComponentWrapper& pItem, ComponentWrapper& sItem) -{ - //set currentweap - player["EquippedItem"] = 1; - //set ammo set cooldown - pItem["Ammo"] = 100; - pItem["CoolDownTimer"] = 0.0; -} -void ShootEventTest::TestSetup2(ComponentWrapper& player, ComponentWrapper& pItem, ComponentWrapper& sItem) -{ - //set currentweap - player["EquippedItem"] = 2; - //set ammo set cooldown - sItem["Ammo"] = 10; - sItem["CoolDownTimer"] = 0.0; -} -void ShootEventTest::TestSetup3(ComponentWrapper& player, ComponentWrapper& pItem, ComponentWrapper& sItem) -{ - player["EquippedItem"] = 0; - pItem["Ammo"] = 100; - sItem["Ammo"] = 100; - //TestSucceeded will be set to false if ammo changes during the 100 loops - TestSucceeded = true; -} -void ShootEventTest::TestSetup4(ComponentWrapper& player, ComponentWrapper& pItem, ComponentWrapper& sItem) -{ - //set currentweap - player["EquippedItem"] = 1; - //set ammo set cooldown - pItem["Ammo"] = 100; - pItem["CoolDownTimer"] = 99999999.0;//very long coolDownTimer - //TestSucceeded will be set to false if ammo changes during the 100 loops - TestSucceeded = true; -} -void ShootEventTest::TestSuccess1() { - //if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired - int currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"]; - if (currentAmmo == 99) - TestSucceeded = true; -} -void ShootEventTest::TestSuccess2() { - //if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired - int currentAmmo = m_World->GetComponent(m_PlayerID, "SecondaryItem")["Ammo"]; - if (currentAmmo == 9) - TestSucceeded = true; -} -void ShootEventTest::TestSuccess3() { - //try firing again - Events::MouseRelease eMouseRelease; - eMouseRelease.Button = GLFW_MOUSE_BUTTON_LEFT; - eMouseRelease.X = 1.0f; - eMouseRelease.Y = 1.0f; - m_EventBroker->Publish(eMouseRelease); - //if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired - int currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"]; - int currentAmmoSecondary = m_World->GetComponent(m_PlayerID, "SecondaryItem")["Ammo"]; - if (currentAmmo != 100 || currentAmmoSecondary != 100) - TestSucceeded = false; -} -void ShootEventTest::TestSuccess4() { - //try firing again - Events::MouseRelease eMouseRelease; - eMouseRelease.Button = GLFW_MOUSE_BUTTON_LEFT; - eMouseRelease.X = 1.0f; - eMouseRelease.Y = 1.0f; - m_EventBroker->Publish(eMouseRelease); - //if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired - int currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"]; - if (currentAmmo != 100) - TestSucceeded = false; -} -void ShootEventTest::Tick() -{ - glfwPollEvents(); - - //double currentTime = glfwGetTime(); - //double dt = currentTime - m_LastTime; - //m_LastTime = currentTime; - - //just set dt to 1.0 - double dt = 0.34567; - // Iterate through systems and update world! - m_SystemPipeline->Update(m_World, dt); - - m_EventBroker->Swap(); - m_EventBroker->Clear(); - - switch (m_RunTestNumber) - { - case 1: - TestSuccess1(); - break; - case 2: - TestSuccess2(); - break; - case 3: - TestSuccess3(); - break; - case 4: - TestSuccess4(); - break; - default: - break; - } - -} diff --git a/src/Tests/ShootEventTest.h b/src/Tests/ShootEventTest.h deleted file mode 100644 index e796c17e..00000000 --- a/src/Tests/ShootEventTest.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef ShootEventTest_h__ -#define ShootEventTest_h__ - -#include "Core/ResourceManager.h" -#include "Core/ConfigFile.h" -#include "Core/EventBroker.h" -#include "Core/World.h" -#include "Input/InputProxy.h" -#include "Input/KeyboardInputHandler.h" -#include "Input/MouseInputHandler.h" -#include "Core/EKeyDown.h" -#include "Core/EntityFile.h" -#include "Core/SystemPipeline.h" -#include "PlayerSystem.h" - -#include "Core/EntityFilePreprocessor.h" -#include "Core/EntityFileParser.h" -#include "Core/EntityFileWriter.h" - -#include "Core/EMouseRelease.h" -#include "Core/EShoot.h" - -class ShootEventTest -{ -public: - ShootEventTest(int runTestNumber); - ~ShootEventTest(); - - void Tick(); - bool TestSucceeded = false; - -private: - void TestSetup1(ComponentWrapper& player, ComponentWrapper& pItem, ComponentWrapper& sItem); - void TestSetup2(ComponentWrapper& player, ComponentWrapper& pItem, ComponentWrapper& sItem); - void TestSetup3(ComponentWrapper& player, ComponentWrapper& pItem, ComponentWrapper& sItem); - void TestSetup4(ComponentWrapper& player, ComponentWrapper& pItem, ComponentWrapper& sItem); - void TestSuccess1(); - void TestSuccess2(); - void TestSuccess3(); - void TestSuccess4(); - - double m_LastTime; - ConfigFile* m_Config = nullptr; - EventBroker* m_EventBroker; - World* m_World; - SystemPipeline* m_SystemPipeline; - int m_PlayerID; - int m_RunTestNumber; - -}; - -#endif From bdebc9de62cf154fb4ad8b2f398cb2fea7f6fea7 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Thu, 21 Jan 2016 11:55:51 +0100 Subject: [PATCH 11/13] WeaponSystem now handles "PrimaryFire" input events. It sends out ePlayerDamage event if it hits a player. Included some tests --- include/Game/Systems/WeaponSystem.h | 39 ++++ resources/Schema/Entities/ShootEventTest.xml | 209 +++++++++++++++++++ src/Game/Game.cpp | 2 + src/Game/Systems/WeaponSystem.cpp | 61 ++++++ 4 files changed, 311 insertions(+) create mode 100644 include/Game/Systems/WeaponSystem.h create mode 100644 resources/Schema/Entities/ShootEventTest.xml create mode 100644 src/Game/Systems/WeaponSystem.cpp diff --git a/include/Game/Systems/WeaponSystem.h b/include/Game/Systems/WeaponSystem.h new file mode 100644 index 00000000..36af4231 --- /dev/null +++ b/include/Game/Systems/WeaponSystem.h @@ -0,0 +1,39 @@ +#ifndef WeaponSystem_h__ +#define WeaponSystem_h__ + +//#include +//#include +#include "Rendering/IRenderer.h" + +#include "Common.h" +#include "Core/System.h" +#include "Core/EPlayerDamage.h" +#include "Core/EShoot.h" +#include "Input/EInputCommand.h" + +#include +#include + + +class WeaponSystem : public ImpureSystem +{ +public: + WeaponSystem(EventBroker* eventBroker, IRenderer* renderer); + + virtual void Update(World* world, double dt) override; + +private: + //methods which will take care of specific events + EventRelay m_EShoot; + bool WeaponSystem::OnShoot(const Events::Shoot& e); + + EventRelay m_EInputCommand; + bool WeaponSystem::OnInputCommand(const Events::InputCommand& e); + + IRenderer* m_Renderer; + + std::vector> m_EShootVector; + double m_TestDamageTotal = 0.0; +}; + +#endif \ No newline at end of file diff --git a/resources/Schema/Entities/ShootEventTest.xml b/resources/Schema/Entities/ShootEventTest.xml new file mode 100644 index 00000000..eae333b6 --- /dev/null +++ b/resources/Schema/Entities/ShootEventTest.xml @@ -0,0 +1,209 @@ + + + + + + + + + + + + ../assets/Models/DummyScene.obj + + + + + + + + + 60 + + + + + + + 3 + + + + + + + + + + + + + 3 + + + ../assets/Models/Core/UnitSphere.obj + + + + 3 + + + + + + + + + + + + + 1 + + + ../assets/Models/Core/UnitSphere.obj + + + + + + + + + + + + + + + 2 + + + ../assets/Models/Core/UnitSphere.obj + + + + + + + + + + + + + + 3 + + + ../assets/Models/Core/UnitSphere.obj + + + + + + + + + + + + + + + 2 + 4 + + + ../assets/Models/Core/UnitSphere.obj + + + + 2 + + + + + + + + + + + + + + ../assets/Models/Core/UnitCube.obj + + + + + 2 + + + + + + + + + + + + + ../assets/Models/Core/UnitCube.obj + + + + + 2 + + + + + + + + + + + 0 + + + + ../assets/Models/Core/UnitCube.obj + + + + + 3 + + + + + + + + + + + 0 + + + + ../assets/Models/Core/UnitCube.obj + + + + + 3 + + + + + + + + + + diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 0dd513b6..8d647f6f 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -9,6 +9,7 @@ #include "Systems/PlayerSpawnSystem.h" #include "Core/EntityFileWriter.h" #include "Game/Systems/CapturePointSystem.h" +#include "Game/Systems/WeaponSystem.h" Game::Game(int argc, char* argv[]) { @@ -82,6 +83,7 @@ Game::Game(int argc, char* argv[]) m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); + m_SystemPipeline->AddSystem(updateOrderLevel, m_Renderer); // Populate Octree with collidables ++updateOrderLevel; m_SystemPipeline->AddSystem(updateOrderLevel, m_OctreeCollision); diff --git a/src/Game/Systems/WeaponSystem.cpp b/src/Game/Systems/WeaponSystem.cpp new file mode 100644 index 00000000..ada48b54 --- /dev/null +++ b/src/Game/Systems/WeaponSystem.cpp @@ -0,0 +1,61 @@ +#include "Systems/WeaponSystem.h" + +WeaponSystem::WeaponSystem(EventBroker* eventBroker, IRenderer* renderer) + : System(eventBroker) + , ImpureSystem() + , m_Renderer(renderer) +{ + EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &WeaponSystem::OnInputCommand); + EVENT_SUBSCRIBE_MEMBER(m_EShoot, &WeaponSystem::OnShoot); +} + +void WeaponSystem::Update(World* world, double dt) +{ + for (int i = m_EShootVector.size(); i > 0; i--) + { + //TODO: check if player has enough ammo and if weapon has a cooldown or not + + //pick the object + PickData somePickData = m_Renderer->Pick(std::get<1>(m_EShootVector[i - 1])); + if (somePickData.Entity == EntityID_Invalid) { + m_EShootVector.erase(m_EShootVector.begin() + i - 1); + continue; + } + //if its a player, do PlayerDamage event + const bool hasPlayerComponent = world->HasComponent(somePickData.Entity, "Player"); + if (hasPlayerComponent) { + Events::PlayerDamage ePlayerDamage; + //TODO: damage based on weapontype/class? + //TODO: multiple shots at the same time? (shotgunner) + ePlayerDamage.DamageAmount = 25; + ePlayerDamage.PlayerDamagedID = somePickData.Entity; + ePlayerDamage.TypeOfDamage = "Some Weapon"; + m_EventBroker->Publish(ePlayerDamage); + //tests:color + m_TestDamageTotal += 0.25f; + if (m_TestDamageTotal > 6.0f) { + m_TestDamageTotal = 0.25f; + } + ComponentWrapper& playerModel = world->GetComponent(somePickData.Entity, "Model"); + playerModel["Color"] = glm::vec4(m_TestDamageTotal, 0, 0, 1); + } + m_EShootVector.erase(m_EShootVector.begin() + i - 1); + } +} + +bool WeaponSystem::OnInputCommand(const Events::InputCommand& e) +{ + if (e.Command == "PrimaryFire" && e.Value > 0) { + Events::Shoot eShoot; + eShoot.shooter = e.PlayerID; + m_EventBroker->Publish(eShoot); + } + return true; +} +bool WeaponSystem::OnShoot(const Events::Shoot& e) { + //screen center, based on current resolution! + Rectangle screenResolution = m_Renderer->Resolution(); + glm::vec2 centerScreen = glm::vec2(screenResolution.Width / 2, screenResolution.Height / 2); + m_EShootVector.push_back(std::make_pair(e.shooter, centerScreen)); + return true; +} \ No newline at end of file From 7deb32431ef28150429bcb90f7cdb0f2e54d7b31 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Thu, 21 Jan 2016 16:03:30 +0100 Subject: [PATCH 12/13] Removed Color TestCode in WeaponSystem --- include/Game/Systems/WeaponSystem.h | 1 - src/Game/Systems/WeaponSystem.cpp | 7 ------- 2 files changed, 8 deletions(-) diff --git a/include/Game/Systems/WeaponSystem.h b/include/Game/Systems/WeaponSystem.h index 36af4231..b85ba323 100644 --- a/include/Game/Systems/WeaponSystem.h +++ b/include/Game/Systems/WeaponSystem.h @@ -33,7 +33,6 @@ private: IRenderer* m_Renderer; std::vector> m_EShootVector; - double m_TestDamageTotal = 0.0; }; #endif \ No newline at end of file diff --git a/src/Game/Systems/WeaponSystem.cpp b/src/Game/Systems/WeaponSystem.cpp index ada48b54..6a701f6d 100644 --- a/src/Game/Systems/WeaponSystem.cpp +++ b/src/Game/Systems/WeaponSystem.cpp @@ -31,13 +31,6 @@ void WeaponSystem::Update(World* world, double dt) ePlayerDamage.PlayerDamagedID = somePickData.Entity; ePlayerDamage.TypeOfDamage = "Some Weapon"; m_EventBroker->Publish(ePlayerDamage); - //tests:color - m_TestDamageTotal += 0.25f; - if (m_TestDamageTotal > 6.0f) { - m_TestDamageTotal = 0.25f; - } - ComponentWrapper& playerModel = world->GetComponent(somePickData.Entity, "Model"); - playerModel["Color"] = glm::vec4(m_TestDamageTotal, 0, 0, 1); } m_EShootVector.erase(m_EShootVector.begin() + i - 1); } From 973ccd34c9721bce9eceb7a316ee8c6a6428c3f0 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Thu, 21 Jan 2016 16:30:07 +0100 Subject: [PATCH 13/13] Removed unnecessary string in EPlayerDamage (TypeOfDamage). Renamed a variable in WeaponSystem --- include/Engine/Core/EPlayerDamage.h | 2 -- src/Engine/Network/Client.cpp | 1 - src/Engine/Network/Server.cpp | 1 - src/Game/Systems/WeaponSystem.cpp | 9 ++++----- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/include/Engine/Core/EPlayerDamage.h b/include/Engine/Core/EPlayerDamage.h index 87ad67aa..e0f2acd7 100644 --- a/include/Engine/Core/EPlayerDamage.h +++ b/include/Engine/Core/EPlayerDamage.h @@ -11,8 +11,6 @@ struct PlayerDamage : Event { double DamageAmount; EntityID PlayerDamagedID; - //optional TypeOfDamage - std::string TypeOfDamage; }; } diff --git a/src/Engine/Network/Client.cpp b/src/Engine/Network/Client.cpp index 8eee335e..10432bba 100644 --- a/src/Engine/Network/Client.cpp +++ b/src/Engine/Network/Client.cpp @@ -288,7 +288,6 @@ bool Client::OnPlayerDamage(const Events::PlayerDamage & e) Packet packet(MessageType::OnInputCommand, m_SendPacketID); packet.WritePrimitive(e.DamageAmount); packet.WritePrimitive(e.PlayerDamagedID); - packet.WriteString(e.TypeOfDamage); send(packet); return false; } diff --git a/src/Engine/Network/Server.cpp b/src/Engine/Network/Server.cpp index 8a194c0e..f4373a83 100644 --- a/src/Engine/Network/Server.cpp +++ b/src/Engine/Network/Server.cpp @@ -240,7 +240,6 @@ void Server::parseOnPlayerDamage(Packet & packet) Events::PlayerDamage e; e.DamageAmount = packet.ReadPrimitive(); e.PlayerDamagedID = packet.ReadPrimitive(); - e.TypeOfDamage = packet.ReadString(); m_EventBroker->Publish(e); //LOG_DEBUG("Server::parseOnPlayerDamage: Command is %s. Value is %f. PlayerID is %i.", e.DamageAmount, e.PlayerDamagedID, e.TypeOfDamage.c_str()); } diff --git a/src/Game/Systems/WeaponSystem.cpp b/src/Game/Systems/WeaponSystem.cpp index 6a701f6d..ec81b08b 100644 --- a/src/Game/Systems/WeaponSystem.cpp +++ b/src/Game/Systems/WeaponSystem.cpp @@ -16,20 +16,19 @@ void WeaponSystem::Update(World* world, double dt) //TODO: check if player has enough ammo and if weapon has a cooldown or not //pick the object - PickData somePickData = m_Renderer->Pick(std::get<1>(m_EShootVector[i - 1])); - if (somePickData.Entity == EntityID_Invalid) { + PickData pickDataFromShot = m_Renderer->Pick(std::get<1>(m_EShootVector[i - 1])); + if (pickDataFromShot.Entity == EntityID_Invalid) { m_EShootVector.erase(m_EShootVector.begin() + i - 1); continue; } //if its a player, do PlayerDamage event - const bool hasPlayerComponent = world->HasComponent(somePickData.Entity, "Player"); + const bool hasPlayerComponent = world->HasComponent(pickDataFromShot.Entity, "Player"); if (hasPlayerComponent) { Events::PlayerDamage ePlayerDamage; //TODO: damage based on weapontype/class? //TODO: multiple shots at the same time? (shotgunner) ePlayerDamage.DamageAmount = 25; - ePlayerDamage.PlayerDamagedID = somePickData.Entity; - ePlayerDamage.TypeOfDamage = "Some Weapon"; + ePlayerDamage.PlayerDamagedID = pickDataFromShot.Entity; m_EventBroker->Publish(ePlayerDamage); } m_EShootVector.erase(m_EShootVector.begin() + i - 1);