xml/xsd files changed type to double. fixed cooldownbug in PlayerSystem. Added 4 tests in ShootEventTest and generalized it a lot
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
|
||||
|
||||
<xs:element name="Player">
|
||||
<xs:annotation>
|
||||
<xs:documentation>The player charachter</xs:documentation>
|
||||
</xs:annotation>
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="Velocity" type="t:Vector" minOccurs="0"/>
|
||||
@@ -11,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:int" minOccurs="0"/>
|
||||
<xs:element name="EquippedItem" type="t:double" minOccurs="0"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<c:PrimaryItem>
|
||||
<Ammo>0</Ammo>
|
||||
<CoolDownTimer>0</CoolDownTimer>
|
||||
</c:Player>
|
||||
</c:PrimaryItem>
|
||||
@@ -4,10 +4,17 @@
|
||||
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
|
||||
|
||||
<xs:element name="PrimaryItem">
|
||||
<xs:annotation>
|
||||
<xs:documentation>The Players Primary Item/Weapon</xs:documentation>
|
||||
</xs:annotation>
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="Ammo" type="t:int" minOccurs="0"/>
|
||||
<xs:element name="CoolDownTimer" type="t:double" minOccurs="0"/>
|
||||
<xs:element name="Ammo" type="t:double" minOccurs="0">
|
||||
<xs:annotation><xs:documentation>Ammo count</xs:documentation></xs:annotation>
|
||||
</xs:element>
|
||||
<xs:element name="CoolDownTimer" type="t:double" minOccurs="0">
|
||||
<xs:annotation><xs:documentation>Cooldown till next item/weapon use</xs:documentation></xs:annotation>
|
||||
</xs:element>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<c:SecondaryItem>
|
||||
<Ammo>0</Ammo>
|
||||
<CoolDownTimer>0</CoolDownTimer>
|
||||
</c:Player>
|
||||
</c:SecondaryItem>
|
||||
@@ -4,10 +4,17 @@
|
||||
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
|
||||
|
||||
<xs:element name="SecondaryItem">
|
||||
<xs:annotation>
|
||||
<xs:documentation>The Players Secondary Item/Weapon</xs:documentation>
|
||||
</xs:annotation>
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="Ammo" type="t:int" minOccurs="0"/>
|
||||
<xs:element name="CoolDownTimer" type="t:double" minOccurs="0"/>
|
||||
<xs:element name="Ammo" type="t:double" minOccurs="0">
|
||||
<xs:annotation><xs:documentation>Ammo count</xs:documentation></xs:annotation>
|
||||
</xs:element>
|
||||
<xs:element name="CoolDownTimer" type="t:double" minOccurs="0">
|
||||
<xs:annotation><xs:documentation>Cooldown till next item/weapon use</xs:documentation></xs:annotation>
|
||||
</xs:element>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
+22
-12
@@ -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;
|
||||
|
||||
+169
-26
@@ -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>("ConfigFile");
|
||||
ResourceManager::RegisterType<EntityXMLFile>("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<std::string>("Debug.LoadMap", "");
|
||||
if (!mapToLoad.empty()) {
|
||||
@@ -54,30 +102,40 @@ ShootEventTest::ShootEventTest()
|
||||
m_SystemPipeline->AddSystem<HealthSystem>(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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user