1 Component added: CapturePoint
1 System added: CapturePointSystem 1 Test added: CapturePointTest added 1 variable in PlayerComponent (TeamNumber) added 2 variables in CapturePoint (CaptureTimer,OwnedBy) CapturePointSystem is now handling 2 events: OnTriggerTouch,OnTriggerLeave Added the CapturePointSystem to Game.cpp
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#ifndef CapturePointSystem_h__
|
||||
#define CapturePointSystem_h__
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glm/common.hpp>
|
||||
|
||||
#include "Common.h"
|
||||
#include "Core/System.h"
|
||||
#include "Engine/Collision/ETrigger.h"
|
||||
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
class CapturePointSystem : public PureSystem
|
||||
{
|
||||
public:
|
||||
//TODO: on new map, destroy all info in the vectors
|
||||
CapturePointSystem(EventBroker* eventBroker);
|
||||
|
||||
//updatecomponent
|
||||
virtual void UpdateComponent(World* world, ComponentWrapper& capturePoint, double dt) override;
|
||||
|
||||
private:
|
||||
//methods which will take care of specific events
|
||||
EventRelay<CapturePointSystem, Events::TriggerTouch> m_ETriggerTouch;
|
||||
bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e);
|
||||
EventRelay<CapturePointSystem, Events::TriggerLeave> m_ETriggerLeave;
|
||||
bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e);
|
||||
|
||||
//vectors which will keep track of enter/leave changes
|
||||
std::vector<std::tuple<EntityID, EntityID>> m_ETriggerTouchVector;
|
||||
std::vector<std::tuple<EntityID, EntityID>> m_ETriggerLeaveVector;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -11,5 +11,5 @@
|
||||
<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>
|
||||
@@ -0,0 +1,4 @@
|
||||
<c:CapturePoint>
|
||||
<CaptureTimer>0</CaptureTimer>
|
||||
<OwnedBy>0</OwnedBy>
|
||||
</c:CapturePoint>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?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="CapturePoint">
|
||||
<xs:annotation>
|
||||
<xs:documentation>A Capture Point</xs:documentation>
|
||||
</xs:annotation>
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="CaptureTimer" type="t:double" minOccurs="0"/>
|
||||
<xs:element name="OwnedBy" type="t:int" minOccurs="0"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
@@ -1,4 +1,5 @@
|
||||
<c:Player>
|
||||
<TeamNumber>0</TeamNumber>
|
||||
<EquippedItem>0</EquippedItem>
|
||||
<Velocity X="0" Y="0" Z="0"/>
|
||||
<Forward>false</Forward>
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
<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>
|
||||
</xs:element>
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
<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>
|
||||
</xs:element>
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
#include "CapturePointSystem.h"
|
||||
#include <algorithm>
|
||||
|
||||
CapturePointSystem::CapturePointSystem(EventBroker* eventBroker)
|
||||
: PureSystem(eventBroker, "CapturePoint")
|
||||
{
|
||||
//subscribe/listenTo playerdamage,healthpickup events (using the eventBroker)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &CapturePointSystem::OnTriggerTouch);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &CapturePointSystem::OnTriggerLeave);
|
||||
}
|
||||
|
||||
//here all capturepoints will update their component
|
||||
void CapturePointSystem::UpdateComponent(World *world, ComponentWrapper &capturePoint, double dt)
|
||||
{
|
||||
//NOTE: needs to run each frame, since we're possibly increasing the captureTimer for the capturePoint by dt
|
||||
int firstTeamPlayersStandingInside = 0;
|
||||
int secondTeamPlayersStandingInside = 0;
|
||||
|
||||
for (size_t i = 0; i < m_ETriggerTouchVector.size(); i++)
|
||||
{
|
||||
auto triggerTouched = m_ETriggerTouchVector[i];
|
||||
if (std::get<1>(triggerTouched) == capturePoint.EntityID) {
|
||||
//some player has touched this - lets figure out: what team, health
|
||||
EntityID playerID = std::get<0>(triggerTouched);
|
||||
bool hasHealthComponent = world->HasComponent(playerID, "Health");
|
||||
if (!hasHealthComponent)
|
||||
continue;
|
||||
double currentHealth = world->GetComponent(playerID, "Health")["Health"];
|
||||
//check if player is dead
|
||||
if ((int)currentHealth == 0)
|
||||
continue;
|
||||
//check team - 0 = no team
|
||||
int teamNumber = (int)world->GetComponent(playerID, "Player")["TeamNumber"];
|
||||
if (teamNumber == 1)
|
||||
firstTeamPlayersStandingInside++;
|
||||
if (teamNumber == 2)
|
||||
secondTeamPlayersStandingInside++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
int ownedBy = capturePoint["OwnedBy"];
|
||||
double captureTimer = capturePoint["CaptureTimer"];
|
||||
|
||||
//A.nobodys standing inside
|
||||
if (firstTeamPlayersStandingInside == 0 && secondTeamPlayersStandingInside == 0) {
|
||||
//do nothing (?)
|
||||
}
|
||||
//B.first team has players but second none
|
||||
if (firstTeamPlayersStandingInside > 0 && secondTeamPlayersStandingInside == 0) {
|
||||
if (ownedBy == 2 || ownedBy == 0)
|
||||
capturePoint["CaptureTimer"] = (double)capturePoint["CaptureTimer"] + dt;
|
||||
//check if captureTimer > 5 and if so change owner
|
||||
if ((double)capturePoint["CaptureTimer"] > 5.0) {
|
||||
capturePoint["OwnedBy"] = 1;
|
||||
capturePoint["CaptureTimer"] = 0;
|
||||
}
|
||||
}
|
||||
//C.second team has players but second none
|
||||
if (firstTeamPlayersStandingInside == 0 && secondTeamPlayersStandingInside > 0) {
|
||||
|
||||
}
|
||||
//D.both teams have players inside
|
||||
if (firstTeamPlayersStandingInside > 0 && secondTeamPlayersStandingInside > 0) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e)
|
||||
{
|
||||
//auto personEntered = e.Entity;
|
||||
//auto thingEntered = e.Trigger;
|
||||
m_ETriggerTouchVector.push_back(std::make_tuple(e.Entity, e.Trigger));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e)
|
||||
{
|
||||
for (size_t i = 0; i < m_ETriggerTouchVector.size(); i++)
|
||||
{
|
||||
auto triggerTouched = m_ETriggerTouchVector[i];
|
||||
if (std::get<0>(triggerTouched) == e.Entity && std::get<1>(triggerTouched) == e.Trigger) {
|
||||
m_ETriggerTouchVector.erase(m_ETriggerTouchVector.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "Collision/CollisionSystem.h"
|
||||
#include "Game/HealthSystem.h"
|
||||
#include "Core/EntityFileWriter.h"
|
||||
#include "Game/CapturePointSystem.h"
|
||||
|
||||
Game::Game(int argc, char* argv[])
|
||||
{
|
||||
@@ -70,6 +71,7 @@ Game::Game(int argc, char* argv[])
|
||||
++updateOrderLevel;
|
||||
m_SystemPipeline->AddSystem<CollisionSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<TriggerSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<CapturePointSystem>(updateOrderLevel);
|
||||
|
||||
// Invoke network
|
||||
if (m_Config->Get<bool>("Networking.StartNetwork", false)) {
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
using boost::unit_test_framework::test_suite;
|
||||
using boost::unit_test_framework::test_case;
|
||||
|
||||
#include "CapturePointTest.h"
|
||||
#include "Game/HealthSystem.h"
|
||||
|
||||
#include "Collision/TriggerSystem.h"
|
||||
#include "Collision/CollisionSystem.h"
|
||||
#include "Core/EntityFileWriter.h"
|
||||
#include "Game/CapturePointSystem.h"
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(ShootEventTestSuite)
|
||||
|
||||
//dont use the same name as the classname in test cases...
|
||||
BOOST_AUTO_TEST_CASE(CapturePointTest1)
|
||||
{
|
||||
//Test firing primary weapon
|
||||
CapturePointTest 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_SUITE_END()
|
||||
|
||||
CapturePointTest::CapturePointTest(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);
|
||||
m_SystemPipeline->AddSystem<CollisionSystem>(1);
|
||||
m_SystemPipeline->AddSystem<TriggerSystem>(1);
|
||||
m_SystemPipeline->AddSystem<CapturePointSystem>(1);
|
||||
|
||||
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");
|
||||
player["TeamNumber"] = 1;
|
||||
|
||||
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;
|
||||
|
||||
EntityID capturePointID = m_World->CreateEntity();
|
||||
ComponentWrapper& capPointComp = m_World->AttachComponent(capturePointID, "CapturePoint");
|
||||
m_CapturePointID = capturePointID;
|
||||
m_RunTestNumber = runTestNumber;
|
||||
|
||||
//add some touch/leave events
|
||||
Events::TriggerTouch eTriggerTouched;
|
||||
eTriggerTouched.Entity = m_PlayerID;
|
||||
eTriggerTouched.Trigger = m_CapturePointID;
|
||||
m_EventBroker->Publish(eTriggerTouched);
|
||||
|
||||
Events::TriggerTouch eTriggerTouched2;
|
||||
eTriggerTouched2.Entity = m_PlayerID2;
|
||||
eTriggerTouched2.Trigger = m_CapturePointID;
|
||||
m_EventBroker->Publish(eTriggerTouched2);
|
||||
|
||||
Events::TriggerLeave eTriggerLeft;
|
||||
eTriggerLeft.Entity = m_PlayerID;
|
||||
eTriggerLeft.Trigger = m_CapturePointID;
|
||||
m_EventBroker->Publish(eTriggerLeft);
|
||||
|
||||
Events::TriggerTouch eTriggerTouched3;
|
||||
eTriggerTouched3.Entity = m_PlayerID;
|
||||
eTriggerTouched3.Trigger = m_CapturePointID;
|
||||
m_EventBroker->Publish(eTriggerTouched3);
|
||||
|
||||
}
|
||||
|
||||
CapturePointTest::~CapturePointTest()
|
||||
{
|
||||
delete m_SystemPipeline;
|
||||
delete m_World;
|
||||
delete m_EventBroker;
|
||||
}
|
||||
|
||||
void CapturePointTest::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();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef CapturePointTest_h__
|
||||
#define CapturePointTest_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 "Engine/Collision/ETrigger.h"
|
||||
|
||||
class CapturePointTest
|
||||
{
|
||||
public:
|
||||
CapturePointTest(int runTestNumber);
|
||||
~CapturePointTest();
|
||||
|
||||
void Tick();
|
||||
bool TestSucceeded = false;
|
||||
|
||||
private:
|
||||
double m_LastTime;
|
||||
ConfigFile* m_Config = nullptr;
|
||||
EventBroker* m_EventBroker;
|
||||
World* m_World;
|
||||
SystemPipeline* m_SystemPipeline;
|
||||
int m_PlayerID, m_PlayerID2, m_CapturePointID;
|
||||
int m_RunTestNumber;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user