EquippedItem,Ammo got changed to int instead of double. Loading entities from map the new way in Tests. ComponentWrapper:s Name is now Type
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<xs:element name="Left" type="t:bool" minOccurs="0"/>
|
||||
<xs:element name="Back" type="t:bool" minOccurs="0"/>
|
||||
<xs:element name="Right" type="t:bool" minOccurs="0"/>
|
||||
<xs:element name="EquippedItem" type="t:double" minOccurs="0"/>
|
||||
<xs:element name="EquippedItem" type="t:int" minOccurs="0"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</xs:annotation>
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="Ammo" type="t:double" minOccurs="0">
|
||||
<xs:element name="Ammo" type="t:int" minOccurs="0">
|
||||
<xs:annotation><xs:documentation>Ammo count</xs:documentation></xs:annotation>
|
||||
</xs:element>
|
||||
<xs:element name="CoolDownTimer" type="t:double" minOccurs="0">
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</xs:annotation>
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="Ammo" type="t:double" minOccurs="0">
|
||||
<xs:element name="Ammo" type="t:int" minOccurs="0">
|
||||
<xs:annotation><xs:documentation>Ammo count</xs:documentation></xs:annotation>
|
||||
</xs:element>
|
||||
<xs:element name="CoolDownTimer" type="t:double" minOccurs="0">
|
||||
|
||||
+10
-12
@@ -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
|
||||
|
||||
@@ -30,7 +30,7 @@ BOOST_AUTO_TEST_SUITE_END()
|
||||
GameHealthSystemTest::GameHealthSystemTest()
|
||||
{
|
||||
ResourceManager::RegisterType<ConfigFile>("ConfigFile");
|
||||
ResourceManager::RegisterType<EntityXMLFile>("EntityXMLFile");
|
||||
ResourceManager::RegisterType<EntityFile>("EntityFile");
|
||||
|
||||
m_Config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||
LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get<int>("Debug.LogLevel", 1));
|
||||
@@ -41,8 +41,13 @@ GameHealthSystemTest::GameHealthSystemTest()
|
||||
// Create a world
|
||||
m_World = new World();
|
||||
std::string mapToLoad = m_Config->Get<std::string>("Debug.LoadMap", "");
|
||||
|
||||
if (!mapToLoad.empty()) {
|
||||
ResourceManager::Load<EntityXMLFile>(mapToLoad)->PopulateWorld(m_World);
|
||||
auto file = ResourceManager::Load<EntityFile>(mapToLoad);
|
||||
EntityFilePreprocessor fpp(file);
|
||||
fpp.RegisterComponents(m_World);
|
||||
EntityFileParser fp(file);
|
||||
fp.MergeEntities(m_World);
|
||||
}
|
||||
|
||||
// Create system pipeline
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -5,7 +5,7 @@ Game::Game(int argc, char* argv[]) : someOctTree(AABB(-0.5f*worldSize, 0.5f*worl
|
||||
ResourceManager::RegisterType<ConfigFile>("ConfigFile");
|
||||
ResourceManager::RegisterType<Model>("Model");
|
||||
ResourceManager::RegisterType<Texture>("Texture");
|
||||
ResourceManager::RegisterType<EntityXMLFile>("EntityXMLFile");
|
||||
ResourceManager::RegisterType<EntityFile>("EntityFile");
|
||||
ResourceManager::RegisterType<ShaderProgram>("ShaderProgram");
|
||||
|
||||
m_Config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -81,9 +81,10 @@ BOOST_AUTO_TEST_SUITE_END()
|
||||
ShootEventTest::ShootEventTest(int runTestNumber)
|
||||
{
|
||||
ResourceManager::RegisterType<ConfigFile>("ConfigFile");
|
||||
ResourceManager::RegisterType<EntityXMLFile>("EntityXMLFile");
|
||||
ResourceManager::RegisterType<EntityFile>("EntityFile");
|
||||
|
||||
m_Config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||
std::string mapToLoad = m_Config->Get<std::string>("Debug.LoadMap", "");
|
||||
LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get<int>("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<std::string>("Debug.LoadMap", "");
|
||||
if (!mapToLoad.empty()) {
|
||||
ResourceManager::Load<EntityXMLFile>(mapToLoad)->PopulateWorld(m_World);
|
||||
}
|
||||
|
||||
// Create system pipeline
|
||||
m_SystemPipeline = new SystemPipeline(m_EventBroker);
|
||||
m_SystemPipeline->AddSystem<PlayerSystem>(0);
|
||||
m_SystemPipeline->AddSystem<HealthSystem>(0);
|
||||
|
||||
if (!mapToLoad.empty()) {
|
||||
auto file = ResourceManager::Load<EntityFile>(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()
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user