Removed ShootEvent from CapturePoint

This commit is contained in:
verysecrethero
2016-01-15 11:17:22 +01:00
parent 76a8b43ca3
commit c8fe6853c0
13 changed files with 0 additions and 439 deletions
-22
View File
@@ -1,22 +0,0 @@
#ifndef EShoot_h__
#define EShoot_h__
#include "EventBroker.h"
#include "../Core/Entity.h"
#include "Engine/GLM.h"
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;
};
}
#endif
-10
View File
@@ -8,7 +8,6 @@
#include "Core/System.h"
#include "Collision/ETrigger.h"
#include "Core/EMouseRelease.h"
#include "Core/EShoot.h"
class PlayerSystem : public PureSystem
{
@@ -19,14 +18,11 @@ public:
EVENT_SUBSCRIBE_MEMBER(m_ETouch, &PlayerSystem::OnTouch);
EVENT_SUBSCRIBE_MEMBER(m_EEnter, &PlayerSystem::OnEnter);
EVENT_SUBSCRIBE_MEMBER(m_ELeave, &PlayerSystem::OnLeave);
EVENT_SUBSCRIBE_MEMBER(m_MouseRelease, &PlayerSystem::OnMouseRelease);
}
virtual void UpdateComponent(World* world, ComponentWrapper& player, double dt) override;
private:
float m_Speed = 5;
bool leftMouseWasReleased = false;
glm::vec2 aimingCoordinates;
EventRelay<PlayerSystem, Events::TriggerEnter> m_EEnter;
bool OnEnter(const Events::TriggerEnter &event);
EventRelay<PlayerSystem, Events::TriggerTouch> m_ETouch;
@@ -34,12 +30,6 @@ private:
EventRelay<PlayerSystem, Events::TriggerLeave> m_ELeave;
bool PlayerSystem::OnLeave(const Events::TriggerLeave &event);
EventRelay<PlayerSystem, Events::MouseRelease> m_MouseRelease;
bool PlayerSystem::OnMouseRelease(const Events::MouseRelease& e);
enum class HeldItem {
None = 0,
PrimaryItem = 1,
SecondaryItem = 2
};
};
#endif
-2
View File
@@ -9,7 +9,5 @@
<xs:include schemaLocation="Components/AABB.xsd"/>
<xs:include schemaLocation="Components/Trigger.xsd"/>
<xs:include schemaLocation="Components/Health.xsd"/>
<xs:include schemaLocation="Components/PrimaryItem.xsd"/>
<xs:include schemaLocation="Components/SecondaryItem.xsd"/>
<xs:include schemaLocation="Components/CapturePoint.xsd"/>
</xs:schema>
-1
View File
@@ -1,6 +1,5 @@
<c:Player>
<TeamNumber>0</TeamNumber>
<EquippedItem>0</EquippedItem>
<Velocity X="0" Y="0" Z="0"/>
<Forward>false</Forward>
<Left>false</Left>
-1
View File
@@ -14,7 +14,6 @@
<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="TeamNumber" type="t:int" minOccurs="0"/>
</xs:all>
</xs:complexType>
@@ -1,4 +0,0 @@
<c:PrimaryItem>
<Ammo>0</Ammo>
<CoolDownTimer>0</CoolDownTimer>
</c:PrimaryItem>
@@ -1,21 +0,0 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<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: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>
</xs:schema>
@@ -1,4 +0,0 @@
<c:SecondaryItem>
<Ammo>0</Ammo>
<CoolDownTimer>0</CoolDownTimer>
</c:SecondaryItem>
@@ -1,21 +0,0 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<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: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>
</xs:schema>
-2
View File
@@ -16,8 +16,6 @@
<xs:element ref="c:RaptorCopter" minOccurs="0"/>
<xs:element ref="c:Player" minOccurs="0"/>
<xs:element ref="c:Health" minOccurs="0"/>
<xs:element ref="c:PrimaryItem" minOccurs="0"/>
<xs:element ref="c:SecondaryItem" minOccurs="0"/>
<xs:element ref="c:CapturePoint" minOccurs="0"/>
</xs:all>
</xs:complexType>
-43
View File
@@ -21,38 +21,6 @@ void PlayerSystem::UpdateComponent(World * world, ComponentWrapper & player, dou
ComponentWrapper& transform = world->GetComponent(player.EntityID, "Transform");
(glm::vec3&)transform["Position"] += (glm::vec3)player["Velocity"];
}
//do shootEvent: if left mouse was released, and ammo/weaponcooldown/playeralive/shootingcooldown are ok
if (leftMouseWasReleased) {
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.0;
std::string HeldItemString = "";
if ((int)player["EquippedItem"] == (int)HeldItem::PrimaryItem)
HeldItemString = "PrimaryItem";
if ((int)player["EquippedItem"] == (int)HeldItem::SecondaryItem)
HeldItemString = "SecondaryItem";
if (HeldItemString != "") {
ComponentWrapper& currentItem = world->GetComponent(player.EntityID, HeldItemString);
currentAmmo = (int)currentItem["Ammo"];
currentCoolDownTimer = (double)currentItem["CoolDownTimer"];
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
currentItem["Ammo"] = (int)currentItem["Ammo"] - 1;
currentItem["CoolDownTimer"] = 2.0;//change later!
//create and publish the shoot event
Events::Shoot eShoot;
eShoot.currentAimingPoint = aimingCoordinates;
eShoot.currentlyEquippedItem = (int)(player["EquippedItem"]);
m_EventBroker->Publish(eShoot);
}
}
}
}
bool PlayerSystem::OnTouch(const Events::TriggerTouch &event)
@@ -72,14 +40,3 @@ bool PlayerSystem::OnLeave(const Events::TriggerLeave &event)
LOG_INFO("Player entity %i left widget (entity %i).", event.Entity, event.Trigger);
return false;
}
bool PlayerSystem::OnMouseRelease(const Events::MouseRelease& e)
{
//kolla ammoleft, cooldowntimer shooting
//kolla om left mouse varit nere
if (e.Button != GLFW_MOUSE_BUTTON_LEFT)
return false;
aimingCoordinates = glm::vec2(e.X, e.Y);
leftMouseWasReleased = true;
return true;
}
-256
View File
@@ -1,256 +0,0 @@
#include <boost/test/unit_test.hpp>
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>("ConfigFile");
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
m_EventBroker = new EventBroker();
// Create a world
m_World = new 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& 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"] = 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
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;
// 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;
}
}
-52
View File
@@ -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