From c2e05de89f0a236864b8259d9a3ce4691452818d Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Thu, 21 Jan 2016 10:24:34 +0100 Subject: [PATCH] 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