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"