From f197993beb92bb2d33b0009ef9b49fefa285ea12 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Tue, 19 Jan 2016 15:31:15 +0100 Subject: [PATCH] Changed CapturePointSystem in light of new enums in the components and a teamcomponent. Half the tests are currently working --- .../Game/{ => Systems}/CapturePointSystem.h | 2 +- resources/Schema/Components/CapturePoint.xml | 7 +- resources/Schema/Components/CapturePoint.xsd | 16 +- resources/Schema/Components/Player.xml | 1 - resources/Schema/Components/Player.xsd | 1 - resources/Schema/Components/Team.xsd | 2 +- resources/Schema/Types/Entity.xsd | 4 +- src/Game/CMakeLists.txt | 1 - src/Game/Game.cpp | 2 +- src/Game/{ => Systems}/CapturePointSystem.cpp | 94 +++++--- src/Game/Systems/HealthSystem.cpp | 2 +- src/Tests/CapturePointTest.cpp | 226 ++++++++---------- src/Tests/CapturePointTest.h | 4 +- src/Tests/HealthSystemTest.cpp | 3 +- src/Tests/HealthSystemTest.h | 2 - src/Tests/OctTreeTest.cpp | 8 +- src/Tests/OldOctTree.cpp | 4 +- 17 files changed, 190 insertions(+), 189 deletions(-) rename include/Game/{ => Systems}/CapturePointSystem.h (92%) rename src/Game/{ => Systems}/CapturePointSystem.cpp (71%) diff --git a/include/Game/CapturePointSystem.h b/include/Game/Systems/CapturePointSystem.h similarity index 92% rename from include/Game/CapturePointSystem.h rename to include/Game/Systems/CapturePointSystem.h index 87410c92..2cac7d95 100644 --- a/include/Game/CapturePointSystem.h +++ b/include/Game/Systems/CapturePointSystem.h @@ -20,7 +20,7 @@ public: CapturePointSystem(EventBroker* eventBroker); //updatecomponent - virtual void UpdateComponent(World* world, ComponentWrapper& capturePoint, double dt) override; + virtual void UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& capturePoint, double dt) override; private: //methods which will take care of specific events diff --git a/resources/Schema/Components/CapturePoint.xml b/resources/Schema/Components/CapturePoint.xml index b2bd53d7..aa65852e 100644 --- a/resources/Schema/Components/CapturePoint.xml +++ b/resources/Schema/Components/CapturePoint.xml @@ -1,6 +1,5 @@ - + + 0 0 - 0 - 0 - \ No newline at end of file + \ No newline at end of file diff --git a/resources/Schema/Components/CapturePoint.xsd b/resources/Schema/Components/CapturePoint.xsd index 3171cf28..ff1a665d 100644 --- a/resources/Schema/Components/CapturePoint.xsd +++ b/resources/Schema/Components/CapturePoint.xsd @@ -5,14 +5,20 @@ - A Capture Point + A Capture Point. Add a Team Component to specify who currently owns it - - - - + + + CaptureTimer handled by Capture Point System + + + + + CapturePointNumber specify an int number for this + + diff --git a/resources/Schema/Components/Player.xml b/resources/Schema/Components/Player.xml index 5cf1d123..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 e6e0a4ff..1a315a35 100644 --- a/resources/Schema/Components/Player.xsd +++ b/resources/Schema/Components/Player.xsd @@ -14,7 +14,6 @@ - diff --git a/resources/Schema/Components/Team.xsd b/resources/Schema/Components/Team.xsd index 163d4a7f..a81a8978 100755 --- a/resources/Schema/Components/Team.xsd +++ b/resources/Schema/Components/Team.xsd @@ -14,7 +14,7 @@ - + Represents entity team affiliation diff --git a/resources/Schema/Types/Entity.xsd b/resources/Schema/Types/Entity.xsd index 62d8ce98..24985d62 100644 --- a/resources/Schema/Types/Entity.xsd +++ b/resources/Schema/Types/Entity.xsd @@ -39,7 +39,7 @@ - + @@ -48,7 +48,7 @@ - + \ No newline at end of file diff --git a/src/Game/CMakeLists.txt b/src/Game/CMakeLists.txt index 23adb24c..4aaff273 100644 --- a/src/Game/CMakeLists.txt +++ b/src/Game/CMakeLists.txt @@ -27,7 +27,6 @@ set(SOURCE_FILES "Game.cpp" ${SOURCE_FILES_Systems} ${SOURCE_FILES_Events} - "CapturePointSystem.cpp" ) set(LIBRARIES diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index fc1babb3..11777be7 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -8,7 +8,7 @@ #include "Systems/SpawnerSystem.h" #include "Systems/PlayerSpawnSystem.h" #include "Core/EntityFileWriter.h" -#include "Game/CapturePointSystem.h" +#include "Game/Systems/CapturePointSystem.h" Game::Game(int argc, char* argv[]) { diff --git a/src/Game/CapturePointSystem.cpp b/src/Game/Systems/CapturePointSystem.cpp similarity index 71% rename from src/Game/CapturePointSystem.cpp rename to src/Game/Systems/CapturePointSystem.cpp index 6189f066..2d02696c 100644 --- a/src/Game/CapturePointSystem.cpp +++ b/src/Game/Systems/CapturePointSystem.cpp @@ -1,8 +1,9 @@ -#include "CapturePointSystem.h" +#include "Systems/CapturePointSystem.h" #include CapturePointSystem::CapturePointSystem(EventBroker* eventBroker) - : PureSystem(eventBroker, "CapturePoint") + : System(eventBroker), + PureSystem("CapturePoint") { //subscribe/listenTo playerdamage,healthpickup events (using the eventBroker) EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &CapturePointSystem::OnTriggerTouch); @@ -11,10 +12,21 @@ CapturePointSystem::CapturePointSystem(EventBroker* eventBroker) //here all capturepoints will update their component //NOTE: needs to run each frame, since we're possibly modifying the captureTimer for the capturePoints by dt -void CapturePointSystem::UpdateComponent(World* world, ComponentWrapper& capturePoint, double dt) +void CapturePointSystem::UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& capturePoint, double dt) { + bool hasTeamComponent = world->HasComponent(capturePoint.EntityID, "Team"); + if (!hasTeamComponent) { + world->AttachComponent(capturePoint.EntityID, "Team"); + ComponentWrapper& teamComponent = world->GetComponent(capturePoint.EntityID, "Team"); + teamComponent["Team"] = 0; + } + ComponentWrapper& teamComponent = world->GetComponent(capturePoint.EntityID, "Team"); int firstTeamPlayersStandingInside = 0; int secondTeamPlayersStandingInside = 0; + //what if capture point has no TEAM? -> NO ENUM. + const int redTeam = (int)teamComponent["Team"].Enum("Red");//"team 1" + const int blueTeam = (int)teamComponent["Team"].Enum("Blue");//"team 2" + const int spectatorTeam = (int)teamComponent["Team"].Enum("Spectator"); //check how many players are standing inside and are healthy for (size_t i = m_ETriggerTouchVector.size(); i > 0; i--) @@ -36,28 +48,30 @@ void CapturePointSystem::UpdateComponent(World* world, ComponentWrapper& capture continue; } } - //check team - 0 = no team - int teamNumber = world->GetComponent(playerID, "Player")["TeamNumber"]; - if (teamNumber == 1) { + //check team - spectatorNumber = "no team" + int teamNumber = world->GetComponent(playerID, "Player")["Team"]; + if (teamNumber == redTeam) { firstTeamPlayersStandingInside++; - } - else if (teamNumber == 2) { + } else if (teamNumber == blueTeam) { secondTeamPlayersStandingInside++; } continue; } } - int ownedBy = capturePoint["OwnedBy"]; + int ownedBy = teamComponent["Team"]; + + //om ej next satt, förvänta sig att en capturepoint med en viss team färg kommer in... + //sätt isåfall next och kör på.. + //gör inget tills man fått den infon /*check what capturePoint can be taken over next: no capturepoint taken yet for at least one of the teams <-> at the start of the match the system is unaware of what capturePoint is the first one for each team*/ - if (m_Team1NextPossibleCapturePoint == m_NotACapturePoint && (int)capturePoint["IsHomeCapturePointForTeamNumber"] == 1) { + if (m_Team1NextPossibleCapturePoint == m_NotACapturePoint && (int)teamComponent["Team"] == redTeam) { m_Team1NextPossibleCapturePoint = capturePoint["CapturePointNumber"]; m_Team1HomeCapturePoint = capturePoint["CapturePointNumber"];//needed to calculate next m_Team1NextPossibleCapturePoint - } - else if (m_Team2NextPossibleCapturePoint == m_NotACapturePoint && (int)capturePoint["IsHomeCapturePointForTeamNumber"] == 2) { + } else if (m_Team2NextPossibleCapturePoint == m_NotACapturePoint && (int)teamComponent["Team"] == blueTeam) { m_Team2NextPossibleCapturePoint = capturePoint["CapturePointNumber"]; m_Team2HomeCapturePoint = capturePoint["CapturePointNumber"];//needed to calculate next m_Team2NextPossibleCapturePoint } @@ -72,34 +86,31 @@ void CapturePointSystem::UpdateComponent(World* world, ComponentWrapper& capture && m_Team1NextPossibleCapturePoint == (int)capturePoint["CapturePointNumber"]) { timerDeltaChange = firstTeamPlayersStandingInside*dt; - currentTeam = 1; - } - else if (firstTeamPlayersStandingInside == 0 && secondTeamPlayersStandingInside > 0 + currentTeam = blueTeam; + } else if (firstTeamPlayersStandingInside == 0 && secondTeamPlayersStandingInside > 0 && m_Team2NextPossibleCapturePoint == (int)capturePoint["CapturePointNumber"]) { timerDeltaChange = -secondTeamPlayersStandingInside*dt; - currentTeam = 2; + currentTeam = redTeam; } - //A.nobodys standing inside if (firstTeamPlayersStandingInside == 0 && secondTeamPlayersStandingInside == 0) { + //A.nobodys standing inside //do nothing (?) - } - - //B. at most one of the teams have players inside (this means datavariable currentTeam is not 0) - else if (currentTeam != 0) { + } else if (currentTeam == blueTeam || currentTeam == redTeam) { + //B. at most one of the teams have players inside (this means datavariable currentTeam is not 0) //if capturePoint is not owned by the take-over team, just modify the CaptureTimer accordingly if (ownedBy != currentTeam) { capturePoint["CaptureTimer"] = (double)capturePoint["CaptureTimer"] + timerDeltaChange; } //if capturePoint is owned by the team, and the other team has been trying to take it, then increase/decrease the timer towards 0.0 - if ((ownedBy == currentTeam && currentTeam == 1 && (double)capturePoint["CaptureTimer"] < 0.0) || - (ownedBy == currentTeam && currentTeam == 2 && (double)capturePoint["CaptureTimer"] > 0.0)) { + if ((ownedBy == currentTeam && currentTeam == redTeam && (double)capturePoint["CaptureTimer"] < 0.0) || + (ownedBy == currentTeam && currentTeam == blueTeam && (double)capturePoint["CaptureTimer"] > 0.0)) { capturePoint["CaptureTimer"] = (double)capturePoint["CaptureTimer"] + timerDeltaChange; } //check if captureTimer > m_CaptureTimeToTakeOver and if so change owner and publish the eCaptured event if (abs((double)capturePoint["CaptureTimer"]) > abs(m_CaptureTimeToTakeOver)) { - capturePoint["OwnedBy"] = currentTeam; + teamComponent["Team"] = currentTeam; capturePoint["CaptureTimer"] = 0.0; //publish Captured event Events::Captured e; @@ -112,10 +123,9 @@ void CapturePointSystem::UpdateComponent(World* world, ComponentWrapper& capture bool team1HasTheZeroCapturePoint = m_Team1HomeCapturePoint < m_Team2HomeCapturePoint; if (team1HasTheZeroCapturePoint) { - if (currentTeam == 1) { + if (currentTeam == redTeam) { m_Team1NextPossibleCapturePoint++; - } - else { + } else { m_Team2NextPossibleCapturePoint--; } //adjust flag for other team if their previous point has just been taken @@ -126,12 +136,10 @@ void CapturePointSystem::UpdateComponent(World* world, ComponentWrapper& capture if (m_Team1NextPossibleCapturePoint == m_Team2NextPossibleCapturePoint + 2) { m_Team1NextPossibleCapturePoint = m_Team1NextPossibleCapturePoint - 1; } - } - else { - if (currentTeam == 1) { + } else { + if (currentTeam == redTeam) { m_Team1NextPossibleCapturePoint--; - } - else { + } else { m_Team2NextPossibleCapturePoint++; } //adjust flag for other team if their previous point has just been taken @@ -144,19 +152,27 @@ void CapturePointSystem::UpdateComponent(World* world, ComponentWrapper& capture } } } - } - - //C.both teams have players inside - else if (firstTeamPlayersStandingInside > 0 && secondTeamPlayersStandingInside > 0) { + } else if (firstTeamPlayersStandingInside > 0 && secondTeamPlayersStandingInside > 0) { + //C.both teams have players inside //do nothing (?) } //check for possible winCondition = check if the homebase is owned by the other team - if (!m_WinnerWasFound && (int)capturePoint["OwnedBy"] != 0 && (int)capturePoint["IsHomeCapturePointForTeamNumber"] != 0 && - (int)capturePoint["IsHomeCapturePointForTeamNumber"] != (int)capturePoint["OwnedBy"]) { + bool checkForWinner = false; + if ((int)capturePoint["CapturePointNumber"] == m_Team1HomeCapturePoint && (int)teamComponent["Team"] != redTeam) + { + checkForWinner = true; + } + if ((int)capturePoint["CapturePointNumber"] == m_Team2HomeCapturePoint && (int)teamComponent["Team"] != blueTeam) + { + checkForWinner = true; + } + + if (checkForWinner && !m_WinnerWasFound) + { //publish Win event Events::Win e; - e.TeamThatWon = capturePoint["OwnedBy"]; + e.TeamThatWon = teamComponent["Team"]; m_EventBroker->Publish(e); m_WinnerWasFound = true; } diff --git a/src/Game/Systems/HealthSystem.cpp b/src/Game/Systems/HealthSystem.cpp index 50c65b1b..203e5019 100644 --- a/src/Game/Systems/HealthSystem.cpp +++ b/src/Game/Systems/HealthSystem.cpp @@ -27,7 +27,7 @@ void HealthSystem::UpdateComponent(World* world, EntityWrapper& entity, Componen m_DeltaHealthVector.erase(m_DeltaHealthVector.begin() + i - 1); //check if health is <= 0 if ((double)component["Health"] <= 0.0f) { - health["Health"] = 0.0; + component["Health"] = 0.0; //publish death event Events::PlayerDeath e; e.PlayerID = player.EntityID; diff --git a/src/Tests/CapturePointTest.cpp b/src/Tests/CapturePointTest.cpp index 71408636..bdba08e4 100644 --- a/src/Tests/CapturePointTest.cpp +++ b/src/Tests/CapturePointTest.cpp @@ -3,12 +3,12 @@ using boost::unit_test_framework::test_suite; using boost::unit_test_framework::test_case; #include "CapturePointTest.h" -#include "Game/HealthSystem.h" +#include "Game/Systems/HealthSystem.h" #include "Collision/TriggerSystem.h" #include "Collision/CollisionSystem.h" #include "Core/EntityFileWriter.h" -#include "Game/CapturePointSystem.h" +#include "Game/Systems/CapturePointSystem.h" BOOST_AUTO_TEST_SUITE(CapturePointTestSuite) @@ -94,7 +94,6 @@ CapturePointTest::CapturePointTest(int runTestNumber) 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 @@ -105,19 +104,15 @@ CapturePointTest::CapturePointTest(int runTestNumber) // Create system pipeline m_SystemPipeline = new SystemPipeline(m_EventBroker); - m_SystemPipeline->AddSystem(0); m_SystemPipeline->AddSystem(0); - m_SystemPipeline->AddSystem(1); - m_SystemPipeline->AddSystem(1); m_SystemPipeline->AddSystem(1); - if (!mapToLoad.empty()) { - auto file = ResourceManager::Load(mapToLoad); - EntityFilePreprocessor fpp(file); - fpp.RegisterComponents(m_World); - EntityFileParser fp(file); - fp.MergeEntities(m_World); - } + //must register components (Components.xsd), else you cant create entities. Easiest done by loading a test xsd file + auto file = ResourceManager::Load("Schema/Entities/TeamTest.xml"); + EntityFilePreprocessor fpp(file); + fpp.RegisterComponents(m_World); + EntityFileParser fp(file); + fp.MergeEntities(m_World); /* ---TESTSETUP--- @@ -128,37 +123,43 @@ CapturePointTest::CapturePointTest(int runTestNumber) capturepoint3 = home for team number 1 */ EntityID playerID = m_World->CreateEntity(); - m_PlayerID = playerID; - ComponentWrapper& player = m_World->AttachComponent(playerID, "Player"); - ComponentWrapper health = m_World->AttachComponent(playerID, "Health"); - player["TeamNumber"] = 1; + m_RedTeamPlayer = playerID; + ComponentWrapper& player = m_World->AttachComponent(m_RedTeamPlayer, "Player"); + ComponentWrapper& health = m_World->AttachComponent(m_RedTeamPlayer, "Health"); + ComponentWrapper& playerTeam = m_World->AttachComponent(m_RedTeamPlayer, "Team"); + playerTeam["Team"] = playerTeam["Team"].Enum("Red"); + m_RedTeam = playerTeam["Team"].Enum("Red"); + m_BlueTeam = playerTeam["Team"].Enum("Blue"); EntityID playerID2 = m_World->CreateEntity(); - ComponentWrapper& player2 = m_World->AttachComponent(playerID2, "Player"); - m_PlayerID2 = playerID2; - ComponentWrapper health2 = m_World->AttachComponent(playerID2, "Health"); - player2["TeamNumber"] = 2; + m_BlueTeamPlayer = playerID2; + ComponentWrapper& player2 = m_World->AttachComponent(m_BlueTeamPlayer, "Player"); + ComponentWrapper& health2 = m_World->AttachComponent(m_BlueTeamPlayer, "Health"); + ComponentWrapper& playerTeam2 = m_World->AttachComponent(m_BlueTeamPlayer, "Team"); + playerTeam2["Team"] = m_BlueTeam; EntityID capturePointID = m_World->CreateEntity(); - ComponentWrapper& capturePoint = m_World->AttachComponent(capturePointID, "CapturePoint"); - //this capturePoint is homeBase for team 2 - capturePoint["IsHomeCapturePointForTeamNumber"] = 2; - capturePoint["CapturePointNumber"] = 0; m_CapturePointID = capturePointID; + ComponentWrapper& capturePoint = m_World->AttachComponent(capturePointID, "CapturePoint"); + ComponentWrapper& capturePointHomeTeam = m_World->AttachComponent(capturePointID, "Team"); + //this capturePoint is homeBase for team 2 + capturePointHomeTeam["Team"] = m_BlueTeam; + capturePoint["CapturePointNumber"] = 0; EntityID capturePointID2 = m_World->CreateEntity(); - ComponentWrapper& capturePoint2 = m_World->AttachComponent(capturePointID2, "CapturePoint"); - //this capturePoint is homeBase for team 1 - capturePoint2["IsHomeCapturePointForTeamNumber"] = 0; - capturePoint2["CapturePointNumber"] = 1; m_CapturePointID2 = capturePointID2; + ComponentWrapper& capturePoint2 = m_World->AttachComponent(capturePointID2, "CapturePoint"); + //ComponentWrapper& capturePointHomeTeam2 = m_World->AttachComponent(capturePointID2, "Team"); + //capturePointHomeTeam2["Team"] = m_BlueTeam; + capturePoint2["CapturePointNumber"] = 1; EntityID capturePointID3 = m_World->CreateEntity(); - ComponentWrapper& capturePoint3 = m_World->AttachComponent(capturePointID3, "CapturePoint"); - //this capturePoint is homeBase for team 1 - capturePoint3["IsHomeCapturePointForTeamNumber"] = 1; - capturePoint3["CapturePointNumber"] = 2; m_CapturePointID3 = capturePointID3; + ComponentWrapper& capturePoint3 = m_World->AttachComponent(capturePointID3, "CapturePoint"); + ComponentWrapper& capturePointHomeTeam3 = m_World->AttachComponent(capturePointID3, "Team"); + //this capturePoint is homeBase for team 1 + capturePointHomeTeam3["Team"] = m_RedTeam; + capturePoint3["CapturePointNumber"] = 2; m_RunTestNumber = runTestNumber; @@ -189,8 +190,8 @@ CapturePointTest::CapturePointTest(int runTestNumber) break; case 8: //switch sides - capturePoint["IsHomeCapturePointForTeamNumber"] = 1; - capturePoint3["IsHomeCapturePointForTeamNumber"] = 2; + capturePointHomeTeam["Team"] = m_RedTeam; + capturePointHomeTeam3["Team"] = m_BlueTeam; TestSetup8(); break; default: @@ -214,10 +215,10 @@ void CapturePointTest::TestSetup1_OnePlayerOnCapturePoint() Events::TriggerLeave leaveEvent; //player touches,leaves,touches m_CapturePointID. and enters m_CapturePointID3 - DoTouchEvent(m_PlayerID, m_CapturePointID); - DoLeaveEvent(m_PlayerID, m_CapturePointID); - DoTouchEvent(m_PlayerID, m_CapturePointID); - DoTouchEvent(m_PlayerID, m_CapturePointID3); + DoTouchEvent(m_RedTeamPlayer, m_CapturePointID); + DoLeaveEvent(m_RedTeamPlayer, m_CapturePointID); + DoTouchEvent(m_RedTeamPlayer, m_CapturePointID); + DoTouchEvent(m_RedTeamPlayer, m_CapturePointID3); } void CapturePointTest::TestSetup2_TwoPlayersOnCapturePoint() { @@ -225,80 +226,65 @@ void CapturePointTest::TestSetup2_TwoPlayersOnCapturePoint() Events::TriggerLeave leaveEvent; //player touches,leaves m_CapturePointID. and enters m_CapturePointID3 - DoTouchEvent(m_PlayerID, m_CapturePointID); - DoLeaveEvent(m_PlayerID, m_CapturePointID); - DoTouchEvent(m_PlayerID, m_CapturePointID3); + DoTouchEvent(m_RedTeamPlayer, m_CapturePointID); + DoLeaveEvent(m_RedTeamPlayer, m_CapturePointID); + DoTouchEvent(m_RedTeamPlayer, m_CapturePointID3); //player2 touches m_CapturePointID,m_CapturePointID2 - DoTouchEvent(m_PlayerID2, m_CapturePointID); - DoTouchEvent(m_PlayerID2, m_CapturePointID2); + DoTouchEvent(m_BlueTeamPlayer, m_CapturePointID); + DoTouchEvent(m_BlueTeamPlayer, m_CapturePointID2); } void CapturePointTest::TestSetup3_NoPlayersOnCapturePoint() { Events::TriggerTouch touchEvent; Events::TriggerLeave leaveEvent; - - //player1 touches and leaves m_CapturePointID - DoTouchEvent(m_PlayerID, m_CapturePointID); - DoLeaveEvent(m_PlayerID, m_CapturePointID); - - //player2 touches and leaves m_CapturePointID2 - DoTouchEvent(m_PlayerID2, m_CapturePointID2); - DoLeaveEvent(m_PlayerID2, m_CapturePointID2); + DoLeaveEvent(m_RedTeamPlayer, m_CapturePointID); + DoLeaveEvent(m_BlueTeamPlayer, m_CapturePointID3); } void CapturePointTest::TestSetup4_TwoCapturePointsBeingCaptured() { Events::TriggerTouch touchEvent; //player1 touches m_CapturePointID3 - DoTouchEvent(m_PlayerID, m_CapturePointID3); + DoTouchEvent(m_RedTeamPlayer, m_CapturePointID3); //player2 touches m_CapturePointID - DoTouchEvent(m_PlayerID2, m_CapturePointID); + DoTouchEvent(m_BlueTeamPlayer, m_CapturePointID); } void CapturePointTest::TestSetup5_SameCapturePointContestedAndTakenOver() { - //NOTE: setup events need to trigger first then the real event will be allowed by the system later - - //"SETUP" homebase->same capturep - //player1 touches m_CapturePointID3 - DoTouchEvent(m_PlayerID, m_CapturePointID3); - - //player2 touches m_CapturePointID - DoTouchEvent(m_PlayerID2, m_CapturePointID); - //contested same, player1 touches the contested //player1 touches m_CapturePointID2 - DoTouchEvent(m_PlayerID, m_CapturePointID2); + DoTouchEvent(m_RedTeamPlayer, m_CapturePointID2); } void CapturePointTest::TestSetup6_Team1CapturedTheLastPointAndWon() { //player1 touches m_CapturePointID3 - DoTouchEvent(m_PlayerID, m_CapturePointID3); + DoTouchEvent(m_RedTeamPlayer, m_CapturePointID3); //TODO: this should be in UPDATE instead //player1 touches m_CapturePointID2 - DoTouchEvent(m_PlayerID, m_CapturePointID2); + DoTouchEvent(m_RedTeamPlayer, m_CapturePointID2); //player1 touches m_CapturePointID - DoTouchEvent(m_PlayerID, m_CapturePointID); + DoTouchEvent(m_RedTeamPlayer, m_CapturePointID); //player2 does nothing } void CapturePointTest::TestSetup7() { //2 owns 1 - DoTouchEvent(m_PlayerID2, m_CapturePointID); + DoTouchEvent(m_BlueTeamPlayer, m_CapturePointID); //1 owns 3 - DoTouchEvent(m_PlayerID, m_CapturePointID3); + DoTouchEvent(m_RedTeamPlayer, m_CapturePointID3); } void CapturePointTest::TestSetup8() { //2 owns 3 - DoTouchEvent(m_PlayerID2, m_CapturePointID3); + DoTouchEvent(m_BlueTeamPlayer, m_CapturePointID3); //1 owns 1 - DoTouchEvent(m_PlayerID, m_CapturePointID); + DoTouchEvent(m_RedTeamPlayer, m_CapturePointID); } void CapturePointTest::DoTouchEvent(EntityID whoDidSomething, EntityID onWhatObject) { Events::TriggerTouch touchEvent; @@ -316,15 +302,15 @@ void CapturePointTest::TestSuccess1() { //TestSetup1_OnePlayerOnCapturePoint //if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired - int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "CapturePoint")["OwnedBy"]; - if (ownedByID3 == 1) + int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "Team")["Team"]; + if (ownedByID3 == m_RedTeam) TestSucceeded = true; } void CapturePointTest::TestSuccess2() { //TestSetup2_TwoPlayersOnCapturePoint - int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "CapturePoint")["OwnedBy"]; - int ownedByID1 = m_World->GetComponent(m_CapturePointID, "CapturePoint")["OwnedBy"]; - if (ownedByID3 == 1 && ownedByID1 == 2) + int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "Team")["Team"]; + int ownedByID1 = m_World->GetComponent(m_CapturePointID, "Team")["Team"]; + if (ownedByID3 == m_RedTeam && ownedByID1 == m_BlueTeam) TestSucceeded = true; } void CapturePointTest::TestSuccess3() { @@ -333,53 +319,53 @@ void CapturePointTest::TestSuccess3() { //if any capturePoint changed then, its a failure else a success if (NumLoops == 95) { TestSucceeded = true; - int ownedByID1 = m_World->GetComponent(m_CapturePointID, "CapturePoint")["OwnedBy"]; - int ownedByID2 = m_World->GetComponent(m_CapturePointID2, "CapturePoint")["OwnedBy"]; - int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "CapturePoint")["OwnedBy"]; - if (ownedByID1 != 0 || ownedByID2 != 0 || ownedByID3 != 0) + int ownedByID1 = m_World->GetComponent(m_CapturePointID, "Team")["Team"]; + int ownedByID2 = m_World->GetComponent(m_CapturePointID2, "Team")["Team"]; + int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "Team")["Team"]; + if (ownedByID1 != m_BlueTeam || ownedByID2 == m_RedTeam || ownedByID2 == m_BlueTeam || ownedByID3 !=m_RedTeam) TestSucceeded = false; } } void CapturePointTest::TestSuccess4() { //TestSetup4_TwoCapturePointsBeingCaptured - int ownedByID1 = m_World->GetComponent(m_CapturePointID, "CapturePoint")["OwnedBy"]; - int ownedByID2 = m_World->GetComponent(m_CapturePointID2, "CapturePoint")["OwnedBy"]; - int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "CapturePoint")["OwnedBy"]; - if (ownedByID1 == 2 && ownedByID3 == 1) + int ownedByID1 = m_World->GetComponent(m_CapturePointID, "Team")["Team"]; + int ownedByID2 = m_World->GetComponent(m_CapturePointID2, "Team")["Team"]; + int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "Team")["Team"]; + if (ownedByID1 == m_BlueTeam && ownedByID3 == m_RedTeam) TestSucceeded = true; } void CapturePointTest::TestSuccess5() { //TestSetup5_SameCapturePointContestedAndTakenOver - int ownedByID1 = m_World->GetComponent(m_CapturePointID, "CapturePoint")["OwnedBy"]; - int ownedByID2 = m_World->GetComponent(m_CapturePointID2, "CapturePoint")["OwnedBy"]; - int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "CapturePoint")["OwnedBy"]; - if (ownedByID1 == 2 && ownedByID2 == 1 && ownedByID3 == 1) + int ownedByID1 = m_World->GetComponent(m_CapturePointID, "Team")["Team"]; + int ownedByID2 = m_World->GetComponent(m_CapturePointID2, "Team")["Team"]; + int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "Team")["Team"]; + if (ownedByID1 == m_BlueTeam && ownedByID2 == m_RedTeam && ownedByID3 == m_RedTeam) TestSucceeded = true; } void CapturePointTest::TestSuccess6() { //NOTE: the actual win-event will have to be manually checked if it triggered or not //TestSetup6_Team1CapturedTheLastPointAndWon - int ownedByID1 = m_World->GetComponent(m_CapturePointID, "CapturePoint")["OwnedBy"]; - int ownedByID2 = m_World->GetComponent(m_CapturePointID2, "CapturePoint")["OwnedBy"]; - int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "CapturePoint")["OwnedBy"]; - if (ownedByID1 == 1 && ownedByID2 == 1 && ownedByID3 == 1) + int ownedByID1 = m_World->GetComponent(m_CapturePointID, "Team")["Team"]; + int ownedByID2 = m_World->GetComponent(m_CapturePointID2, "Team")["Team"]; + int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "Team")["Team"]; + if (ownedByID1 == m_RedTeam && ownedByID2 == m_RedTeam && ownedByID3 == m_RedTeam) TestSucceeded = true; } void CapturePointTest::TestSuccess7() { - int ownedByID1 = m_World->GetComponent(m_CapturePointID, "CapturePoint")["OwnedBy"]; - int ownedByID2 = m_World->GetComponent(m_CapturePointID2, "CapturePoint")["OwnedBy"]; - int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "CapturePoint")["OwnedBy"]; + int ownedByID1 = m_World->GetComponent(m_CapturePointID, "Team")["Team"]; + int ownedByID2 = m_World->GetComponent(m_CapturePointID2, "Team")["Team"]; + int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "Team")["Team"]; - if (NumLoops < 20 && ownedByID1 == 2 & ownedByID3 == 1) { + if (NumLoops < 20 && ownedByID1 == m_BlueTeam & ownedByID3 == m_RedTeam) { phase1Success = true; } - if (NumLoops < 40 && NumLoops > 20 && ownedByID2 == 1) { + if (NumLoops < 40 && NumLoops > 20 && ownedByID2 == m_RedTeam) { phase2Success = true; } - if (NumLoops < 60 && NumLoops > 40 && ownedByID1 == 1) { + if (NumLoops < 60 && NumLoops > 40 && ownedByID1 == m_RedTeam) { phase3Success = true; } - if (NumLoops < 90 && NumLoops > 60 && ownedByID2 != 2) { + if (NumLoops < 90 && NumLoops > 60 && ownedByID2 != m_BlueTeam) { phase4Success = true; } @@ -389,20 +375,20 @@ void CapturePointTest::TestSuccess7() { } } void CapturePointTest::TestSuccess8() { - int ownedByID1 = m_World->GetComponent(m_CapturePointID, "CapturePoint")["OwnedBy"]; - int ownedByID2 = m_World->GetComponent(m_CapturePointID2, "CapturePoint")["OwnedBy"]; - int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "CapturePoint")["OwnedBy"]; + int ownedByID1 = m_World->GetComponent(m_CapturePointID, "CapturePoint")["Team"]; + int ownedByID2 = m_World->GetComponent(m_CapturePointID2, "CapturePoint")["Team"]; + int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "CapturePoint")["Team"]; - if (NumLoops < 20 && ownedByID3 == 2 & ownedByID1 == 1) { + if (NumLoops < 20 && ownedByID3 == m_BlueTeam & ownedByID1 == m_RedTeam) { phase1Success = true; } - if (NumLoops < 40 && NumLoops > 20 && ownedByID2 == 1) { + if (NumLoops < 40 && NumLoops > 20 && ownedByID2 == m_RedTeam) { phase2Success = true; } - if (NumLoops < 60 && NumLoops > 40 && ownedByID3 == 1) { + if (NumLoops < 60 && NumLoops > 40 && ownedByID3 == m_RedTeam) { phase3Success = true; } - if (NumLoops < 90 && NumLoops > 60 && ownedByID2 != 2) { + if (NumLoops < 90 && NumLoops > 60 && ownedByID2 != m_BlueTeam) { phase4Success = true; } @@ -416,21 +402,21 @@ void CapturePointTest::UpdateTest7() { //loop 20 = team1 takes 2, team 1 leaves 1 -> team1 next = 1, team2 next = still 2 if (NumLoops == 20) { //leave previous - DoLeaveEvent(m_PlayerID2, m_CapturePointID); - DoLeaveEvent(m_PlayerID, m_CapturePointID3); + DoLeaveEvent(m_BlueTeamPlayer, m_CapturePointID); + DoLeaveEvent(m_RedTeamPlayer, m_CapturePointID3); - DoTouchEvent(m_PlayerID, m_CapturePointID2); + DoTouchEvent(m_RedTeamPlayer, m_CapturePointID2); } //loop 40 = team1 takes 1, team2:s next cap point should now be 1 (instead of 2) if (NumLoops == 40) { //leave previous, take next - DoLeaveEvent(m_PlayerID, m_CapturePointID2); - DoTouchEvent(m_PlayerID, m_CapturePointID); + DoLeaveEvent(m_RedTeamPlayer, m_CapturePointID2); + DoTouchEvent(m_RedTeamPlayer, m_CapturePointID); } //loop 60 = team2 tries to take 2, this shouldnt work now if (NumLoops == 60) { - DoLeaveEvent(m_PlayerID, m_CapturePointID); - DoTouchEvent(m_PlayerID2, m_CapturePointID2); + DoLeaveEvent(m_RedTeamPlayer, m_CapturePointID); + DoTouchEvent(m_BlueTeamPlayer, m_CapturePointID2); } } void CapturePointTest::UpdateTest8() { @@ -440,21 +426,21 @@ void CapturePointTest::UpdateTest8() { //loop 20 = team1 takes 2, team 1 leaves 1 -> team1 next = 1, team2 next = still 2 if (NumLoops == 20) { //leave previous - DoLeaveEvent(m_PlayerID2, m_CapturePointID3); - DoLeaveEvent(m_PlayerID, m_CapturePointID); + DoLeaveEvent(m_BlueTeamPlayer, m_CapturePointID3); + DoLeaveEvent(m_RedTeamPlayer, m_CapturePointID); - DoTouchEvent(m_PlayerID, m_CapturePointID2); + DoTouchEvent(m_RedTeamPlayer, m_CapturePointID2); } //loop 40 = team1 takes 3, team2:s next cap point should now be 1 (instead of 2) if (NumLoops == 40) { //leave previous, take next - DoLeaveEvent(m_PlayerID, m_CapturePointID2); - DoTouchEvent(m_PlayerID, m_CapturePointID3); + DoLeaveEvent(m_RedTeamPlayer, m_CapturePointID2); + DoTouchEvent(m_RedTeamPlayer, m_CapturePointID3); } //loop 60 = team2 tries to take 2, this shouldnt work now if (NumLoops == 60) { - DoLeaveEvent(m_PlayerID, m_CapturePointID3); - DoTouchEvent(m_PlayerID2, m_CapturePointID2); + DoLeaveEvent(m_RedTeamPlayer, m_CapturePointID3); + DoTouchEvent(m_BlueTeamPlayer, m_CapturePointID2); } } void CapturePointTest::Tick() diff --git a/src/Tests/CapturePointTest.h b/src/Tests/CapturePointTest.h index 5646f8a6..69f63fcd 100644 --- a/src/Tests/CapturePointTest.h +++ b/src/Tests/CapturePointTest.h @@ -11,7 +11,6 @@ #include "Core/EKeyDown.h" #include "Core/EntityFile.h" #include "Core/SystemPipeline.h" -#include "PlayerSystem.h" #include "Core/EntityFilePreprocessor.h" #include "Core/EntityFileParser.h" @@ -58,9 +57,10 @@ private: EventBroker* m_EventBroker; World* m_World; SystemPipeline* m_SystemPipeline; - EntityID m_PlayerID, m_PlayerID2, m_CapturePointID, m_CapturePointID2, m_CapturePointID3; + EntityID m_RedTeamPlayer, m_BlueTeamPlayer, m_CapturePointID, m_CapturePointID2, m_CapturePointID3; int m_RunTestNumber; bool phase1Success = false, phase2Success = false, phase3Success = false, phase4Success = false; + int m_RedTeam, m_BlueTeam; }; #endif diff --git a/src/Tests/HealthSystemTest.cpp b/src/Tests/HealthSystemTest.cpp index feab858a..2c57b713 100644 --- a/src/Tests/HealthSystemTest.cpp +++ b/src/Tests/HealthSystemTest.cpp @@ -3,7 +3,7 @@ using boost::unit_test_framework::test_suite; using boost::unit_test_framework::test_case; #include "HealthSystemTest.h" -#include "Game/HealthSystem.h" +#include "Game/Systems/HealthSystem.h" BOOST_AUTO_TEST_SUITE(HealthSystemSuite) @@ -52,7 +52,6 @@ GameHealthSystemTest::GameHealthSystemTest() // Create system pipeline m_SystemPipeline = new SystemPipeline(m_EventBroker); - m_SystemPipeline->AddSystem(0); m_SystemPipeline->AddSystem(0); //The Test diff --git a/src/Tests/HealthSystemTest.h b/src/Tests/HealthSystemTest.h index bd3f3de7..62c5f55b 100644 --- a/src/Tests/HealthSystemTest.h +++ b/src/Tests/HealthSystemTest.h @@ -14,8 +14,6 @@ #include "Core/EKeyDown.h" #include "Core/EntityFile.h" #include "Core/SystemPipeline.h" -#include "RaptorCopterSystem.h" -#include "PlayerSystem.h" #include "Editor/EditorSystem.h" class GameHealthSystemTest diff --git a/src/Tests/OctTreeTest.cpp b/src/Tests/OctTreeTest.cpp index 3a130354..ccce93eb 100644 --- a/src/Tests/OctTreeTest.cpp +++ b/src/Tests/OctTreeTest.cpp @@ -43,7 +43,7 @@ template void RegionTest(Tree& tree) { AABB aabb; - aabb.CreateFromCenter(glm::vec3(rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS), + aabb.FromOriginSize(glm::vec3(rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS), glm::vec3(rand() % MAXSIZE, rand() % MAXSIZE, rand() % MAXSIZE)); std::vector outVec; tree.BoxesInSameRegion(aabb, outVec); @@ -63,7 +63,7 @@ void BoxTest(Tree& tree) { AABB outBox; AABB aabb; - aabb.CreateFromCenter(glm::vec3(rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS), + aabb.FromOriginSize(glm::vec3(rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS), glm::vec3(rand() % MAXSIZE, rand() % MAXSIZE, rand() % MAXSIZE)); tree.BoxCollides(aabb, outBox); } @@ -88,14 +88,14 @@ void TestLoop(TestFunction xTest) for (int i = 0; i < NUM_STATICS; ++i) { center = glm::vec3(rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS); size = glm::vec3(rand() % MAXSIZE, rand() % MAXSIZE, rand() % MAXSIZE); - aabb.CreateFromCenter(center, size); + aabb.FromOriginSize(center, size); tree.AddStaticObject(aabb); } for (int fr = 0; fr < TEST_FRAMES; ++fr) { for (int i = 0; i < NUM_DYNAMICS; ++i) { center = glm::vec3(rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS); size = glm::vec3(rand() % MAXSIZE, rand() % MAXSIZE, rand() % MAXSIZE); - aabb.CreateFromCenter(center, size); + aabb.FromOriginSize(center, size); tree.AddDynamicObject(aabb); } diff --git a/src/Tests/OldOctTree.cpp b/src/Tests/OldOctTree.cpp index 0fb92e18..16ecec65 100644 --- a/src/Tests/OldOctTree.cpp +++ b/src/Tests/OldOctTree.cpp @@ -100,7 +100,7 @@ void OctTree::Update(float dt, World* world, Camera* cam) { AABB aabb; for (ComponentWrapper& c : *world->GetComponents("Collision")) { - aabb.CreateFromCenter(c["BoxCenter"], c["BoxSize"]); + aabb.FromOriginSize(c["BoxCenter"], c["BoxSize"]); AddStaticObject(aabb); } const glm::vec4 redCol = glm::vec4(1, 0.2f, 0, 1); @@ -118,7 +118,7 @@ void OctTree::Update(float dt, World* world, Camera* cam) AABB box; auto boxPos = cam->Position() + 1.2f*cam->Forward(); - box.CreateFromCenter(boxPos, boxSize); + box.FromOriginSize(boxPos, boxSize); ComponentWrapper transform = world->GetComponent(m_BoxID, "Transform"); transform["Position"] = boxPos; ComponentWrapper model = world->GetComponent(m_BoxID, "Model");