Merge pull request #31 from teamfisk/CapturePointTake

Capture point take
This commit is contained in:
William Moberg
2016-01-20 17:43:20 +01:00
37 changed files with 1824 additions and 501 deletions
+1
View File
@@ -61,6 +61,7 @@ public:
iterator begin() const;
iterator end() const;
size_t size() const;
//Dumps information about what the pool memory looks like right now
//into an output stream (e.g. file/std::cout, anything that has an operator<<)
+1 -1
View File
@@ -91,7 +91,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.Stride;
m_ComponentInfo.Fields[fieldName].Stride = sizeof(T);
m_ComponentInfo.Stride += sizeof(T);
+20
View File
@@ -0,0 +1,20 @@
#ifndef ECaptured_h__
#define ECaptured_h__
#include "EventBroker.h"
#include "../Core/Entity.h"
#include "Engine/GLM.h"
namespace Events
{
//triggers when a capturePoint has been taken over
struct Captured : Event
{
int TeamNumberThatCapturedCapturePoint;
EntityID CapturePointID;
};
}
#endif
+20
View File
@@ -0,0 +1,20 @@
#ifndef EWin_h__
#define EWin_h__
#include "EventBroker.h"
#include "../Core/Entity.h"
#include "Engine/GLM.h"
namespace Events
{
//triggers when a team has captured all capturePoints
struct Win : Event
{
//can be 0 = none, 1,2
int TeamThatWon;
};
}
#endif
+55
View File
@@ -0,0 +1,55 @@
#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 "Core/ECaptured.h"
#include "Core/EWin.h"
#include <tuple>
#include <vector>
class CapturePointSystem : public PureSystem
{
public:
//WARNING: on new map, destroy all info in the vectors, as well as reset all variables (just make new?)
CapturePointSystem(EventBroker* eventBroker);
//updatecomponent
virtual void UpdateComponent(World* world, EntityWrapper& entity, 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);
EventRelay<CapturePointSystem, Events::Captured> m_ECaptured;
bool CapturePointSystem::OnCaptured(const Events::Captured& e);
bool m_WinnerWasFound = false;
//need to track these variables for the captureSystem to work as per design!
const int m_NotACapturePoint = 999;
int m_RedTeamNextPossibleCapturePoint = m_NotACapturePoint;
int m_BlueTeamNextPossibleCapturePoint = m_NotACapturePoint;
int m_RedTeamHomeCapturePoint = m_NotACapturePoint;
int m_BlueTeamHomeCapturePoint = m_NotACapturePoint;
int m_NumberOfCapturePoints = 0;
std::map<int, EntityID> m_CapturePointNumberToEntityIDMap;
//std::vector<ComponentWrapper>
const double m_CaptureTimeToTakeOver = 15.0;
bool m_ResetTimers = false;
//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
+1
View File
@@ -12,6 +12,7 @@
<xs:include schemaLocation="Components/DirectionalLight.xsd"/>
<xs:include schemaLocation="Components/Trigger.xsd"/>
<xs:include schemaLocation="Components/Health.xsd"/>
<xs:include schemaLocation="Components/CapturePoint.xsd"/>
<xs:include schemaLocation="Components/Listener.xsd"/>
<xs:include schemaLocation="Components/SoundEmitter.xsd"/>
<xs:include schemaLocation="Components/Collidable.xsd"/>
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<CapturePoint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="CapturePoint.xsd">
<CapturePointNumber>0</CapturePointNumber>
<CaptureTimer>0</CaptureTimer>
<HomePointForTeam><Spectator/></HomePointForTeam>
</CapturePoint>
@@ -0,0 +1,44 @@
<?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:complexType name="TeamEnum" mixed="true">
<xs:complexContent>
<xs:extension base="t:enum">
<xs:choice>
<xs:element name="Spectator" type="xs:integer" fixed="1" minOccurs="0"/>
<xs:element name="Red" type="xs:integer" fixed="2" minOccurs="0"/>
<xs:element name="Blue" type="xs:integer" fixed="3" minOccurs="0"/>
</xs:choice>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="CapturePoint">
<xs:annotation>
<xs:documentation>A Capture Point. Add a Team Component to specify who currently owns it</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:all>
<xs:element name="CaptureTimer" type="t:double" minOccurs="0">
<xs:annotation>
<xs:documentation>CaptureTimer handled by Capture Point System</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="CapturePointNumber" type="t:int" minOccurs="0">
<xs:annotation>
<xs:documentation>CapturePointNumber specify an int number for this</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="HomePointForTeam" type="TeamEnum" minOccurs="0">
<xs:annotation>
<xs:documentation>Specify if this is a HomePoint for either team</xs:documentation>
</xs:annotation>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
+3
View File
@@ -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"/>
+1 -1
View File
@@ -14,7 +14,7 @@
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="Team">
<xs:annotation>
<xs:documentation>Represents entity team affiliation</xs:documentation>
+156
View File
@@ -0,0 +1,156 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Transform/>
</Components>
<Children>
<Entity>
<Components>
<c:Model>
<Resource>../assets/Models/DummyScene.obj</Resource>
</c:Model>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Health>
<Health>60</Health>
</c:Health>
<c:AABB/>
<c:Camera/>
<c:Listener/>
<c:Player/>
<c:Team>
<Team>3</Team>
</c:Team>
<c:Transform>
<Position X="-0.151326105" Y="13.5594187" Z="12.5957394"/>
<Orientation X="-0.872664392" Y="0.157068729" Z="4.90324332e-08"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<HomePointForTeam>3</HomePointForTeam>
</c:CapturePoint>
<c:Model>
<Resource>../assets/Models/Core/UnitSphere.obj</Resource>
<Color A="1" B="1" G="0.200000003" R="0"/>
</c:Model>
<c:Team>
<Team>3</Team>
</c:Team>
<c:Transform>
<Position X="5.48757935" Y="2.62824345" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<CapturePointNumber>1</CapturePointNumber>
</c:CapturePoint>
<c:Model>
<Resource>../assets/Models/Core/UnitSphere.obj</Resource>
<Color A="1" B="0" G="1" R="1"/>
</c:Model>
<c:Team>
<Team>3</Team>
</c:Team>
<c:Transform>
<Position X="1.91470337" Y="2.32191443" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<CapturePointNumber>2</CapturePointNumber>
</c:CapturePoint>
<c:Model>
<Resource>../assets/Models/Core/UnitSphere.obj</Resource>
<Color A="1" B="1" G="1" R="0"/>
</c:Model>
<c:Team>
<Team>2</Team>
</c:Team>
<c:Transform>
<Position X="-1.31178355" Y="2.16289616" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<HomePointForTeam>2</HomePointForTeam>
<CapturePointNumber>3</CapturePointNumber>
</c:CapturePoint>
<c:Model>
<Resource>../assets/Models/Core/UnitSphere.obj</Resource>
<Color A="1" B="0" G="0.200000003" R="1"/>
</c:Model>
<c:Team>
<Team>2</Team>
</c:Team>
<c:Transform>
<Position X="-4.27947044" Y="1.99913001" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Health/>
<c:AABB/>
<c:Model>
<Resource>../assets/Models/Core/UnitCube.obj</Resource>
<Color A="1" B="0.482352942" G="0.490196079" R="1"/>
</c:Model>
<c:Player/>
<c:Team>
<Team>2</Team>
</c:Team>
<c:Transform>
<Position X="-1.67672658" Y="2.23822045" Z="-0.0577065349"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Health/>
<c:AABB/>
<c:Model>
<Resource>../assets/Models/Core/UnitCube.obj</Resource>
<Color A="1" B="1" G="0.196078435" R="0.196078435"/>
</c:Model>
<c:Player/>
<c:Team>
<Team>3</Team>
</c:Team>
<c:Transform>
<Position X="2.40398169" Y="2.02053547" Z="-0.0348547697"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
@@ -0,0 +1,158 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Transform/>
</Components>
<Children>
<Entity>
<Components>
<c:Model>
<Resource>../assets/Models/DummyScene.obj</Resource>
</c:Model>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Health>
<Health>60</Health>
</c:Health>
<c:AABB/>
<c:Camera/>
<c:Listener/>
<c:Player/>
<c:Team>
<Team>3</Team>
</c:Team>
<c:Transform>
<Position X="-2.38960934" Y="11.7122087" Z="11.4659815"/>
<Orientation X="-0.645771146" Y="-1.17512627e-05" Z="1.76718231e-07"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<HomePointForTeam>3</HomePointForTeam>
<CaptureTimer>6.9158446328696002</CaptureTimer>
</c:CapturePoint>
<c:Model>
<Resource>../assets/Models/Core/UnitSphere.obj</Resource>
<Color A="1" B="0" G="1" R="1"/>
</c:Model>
<c:Team>
<Team>3</Team>
</c:Team>
<c:Transform>
<Position X="5.48757935" Y="2.62824345" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<CaptureTimer>-13.234195338196177</CaptureTimer>
<CapturePointNumber>1</CapturePointNumber>
</c:CapturePoint>
<c:Model>
<Resource>../assets/Models/Core/UnitSphere.obj</Resource>
<Color A="1" B="1" G="1" R="0"/>
</c:Model>
<c:Team>
<Team>2</Team>
</c:Team>
<c:Transform>
<Position X="1.38422918" Y="2.32191443" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<CapturePointNumber>2</CapturePointNumber>
</c:CapturePoint>
<c:Model>
<Resource>../assets/Models/Core/UnitSphere.obj</Resource>
<Color A="1" B="0" G="0.200000003" R="1"/>
</c:Model>
<c:Team>
<Team>2</Team>
</c:Team>
<c:Transform>
<Position X="-1.79222715" Y="2.16289616" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<HomePointForTeam>2</HomePointForTeam>
<CapturePointNumber>3</CapturePointNumber>
</c:CapturePoint>
<c:Model>
<Resource>../assets/Models/Core/UnitSphere.obj</Resource>
<Color A="1" B="0" G="0.200000003" R="1"/>
</c:Model>
<c:Team>
<Team>2</Team>
</c:Team>
<c:Transform>
<Position X="-4.27947044" Y="1.99913001" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Health/>
<c:AABB/>
<c:Model>
<Resource>../assets/Models/Core/UnitCube.obj</Resource>
<Color A="1" B="0.482352942" G="0.490196079" R="1"/>
</c:Model>
<c:Player/>
<c:Team>
<Team>2</Team>
</c:Team>
<c:Transform>
<Position X="4.99647331" Y="2.23822045" Z="1.80651212"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Health/>
<c:AABB/>
<c:Model>
<Resource>../assets/Models/Core/UnitCube.obj</Resource>
<Color A="1" B="1" G="0.196078435" R="0.196078435"/>
</c:Model>
<c:Player/>
<c:Team>
<Team>3</Team>
</c:Team>
<c:Transform>
<Position X="2.7091608" Y="2.02053547" Z="-0.0348547697"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
@@ -0,0 +1,152 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Transform/>
</Components>
<Children>
<Entity>
<Components>
<c:Model>
<Resource>../assets/Models/DummyScene.obj</Resource>
</c:Model>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Health>
<Health>60</Health>
</c:Health>
<c:AABB/>
<c:Camera/>
<c:Listener/>
<c:Player/>
<c:Team>
<Team>3</Team>
</c:Team>
<c:Transform>
<Position X="-0.151326105" Y="13.5594187" Z="12.5957394"/>
<Orientation X="-0.872664511" Y="0.157068729" Z="3.01738083e-08"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<HomePointForTeam>3</HomePointForTeam>
</c:CapturePoint>
<c:Model>
<Resource>../assets/Models/Core/UnitSphere.obj</Resource>
<Color A="1" B="1" G="0.200000003" R="0"/>
</c:Model>
<c:Team>
<Team>3</Team>
</c:Team>
<c:Transform>
<Position X="5.48757935" Y="2.62824345" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<CapturePointNumber>1</CapturePointNumber>
</c:CapturePoint>
<c:Model>
<Resource>../assets/Models/Core/UnitSphere.obj</Resource>
<Color A="1" B="1" G="1" R="0"/>
</c:Model>
<c:Team/>
<c:Transform>
<Position X="1.91470337" Y="2.32191443" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<CapturePointNumber>2</CapturePointNumber>
</c:CapturePoint>
<c:Model>
<Resource>../assets/Models/Core/UnitSphere.obj</Resource>
<Color A="1" B="0" G="1" R="1"/>
</c:Model>
<c:Team/>
<c:Transform>
<Position X="-1.31178355" Y="2.16289616" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<HomePointForTeam>2</HomePointForTeam>
<CapturePointNumber>3</CapturePointNumber>
</c:CapturePoint>
<c:Model>
<Resource>../assets/Models/Core/UnitSphere.obj</Resource>
<Color A="1" B="0" G="0.200000003" R="1"/>
</c:Model>
<c:Team>
<Team>2</Team>
</c:Team>
<c:Transform>
<Position X="-4.27947044" Y="1.99913001" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Health/>
<c:AABB/>
<c:Model>
<Resource>../assets/Models/Core/UnitCube.obj</Resource>
<Color A="1" B="0.482352942" G="0.490196079" R="1"/>
</c:Model>
<c:Player/>
<c:Team>
<Team>2</Team>
</c:Team>
<c:Transform>
<Position X="-5.74354839" Y="2.23822045" Z="-0.0577065349"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Health/>
<c:AABB/>
<c:Model>
<Resource>../assets/Models/Core/UnitCube.obj</Resource>
<Color A="1" B="1" G="0.196078435" R="0.196078435"/>
</c:Model>
<c:Player/>
<c:Team>
<Team>3</Team>
</c:Team>
<c:Transform>
<Position X="6.96941662" Y="2.02053547" Z="-0.0348547697"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
@@ -0,0 +1,212 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Transform/>
</Components>
<Children>
<Entity>
<Components>
<c:Model>
<Resource>../assets/Models/DummyScene.obj</Resource>
</c:Model>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Health>
<Health>60</Health>
</c:Health>
<c:AABB/>
<c:Camera/>
<c:Listener/>
<c:Player/>
<c:Team>
<Team>3</Team>
</c:Team>
<c:Transform>
<Position X="-0.151326105" Y="13.5594187" Z="12.5957394"/>
<Orientation X="-0.942477643" Y="0.157067701" Z="-1.50870125e-08"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<HomePointForTeam>3</HomePointForTeam>
</c:CapturePoint>
<c:Model>
<Resource>../assets/Models/Core/UnitSphere.obj</Resource>
<Color A="1" B="1" G="0.200000003" R="0"/>
</c:Model>
<c:Team>
<Team>3</Team>
</c:Team>
<c:Transform>
<Position X="5.39647007" Y="2.36802292" Z="0.0546064377"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<CapturePointNumber>1</CapturePointNumber>
</c:CapturePoint>
<c:Model>
<Resource>../assets/Models/Core/UnitSphere.obj</Resource>
<Color A="1" B="0" G="1" R="1"/>
</c:Model>
<c:Team>
<Team>3</Team>
</c:Team>
<c:Transform>
<Position X="4.21088505" Y="2.32191443" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<CapturePointNumber>2</CapturePointNumber>
</c:CapturePoint>
<c:Model>
<Resource>../assets/Models/Core/UnitSphere.obj</Resource>
<Color A="1" B="1" G="1" R="0"/>
</c:Model>
<c:Team>
<Team>2</Team>
</c:Team>
<c:Transform>
<Position X="2.30499458" Y="2.04659939" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<CapturePointNumber>3</CapturePointNumber>
</c:CapturePoint>
<c:Model>
<Resource>../assets/Models/Core/UnitSphere.obj</Resource>
<Color A="1" B="0" G="0.200000003" R="1"/>
</c:Model>
<c:Team>
<Team>2</Team>
</c:Team>
<c:Transform>
<Position X="0.196968079" Y="1.99913001" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<HomePointForTeam>2</HomePointForTeam>
<CapturePointNumber>4</CapturePointNumber>
</c:CapturePoint>
<c:Model>
<Resource>../assets/Models/Core/UnitSphere.obj</Resource>
<Color A="1" B="0" G="0.200000003" R="1"/>
</c:Model>
<c:Team>
<Team>2</Team>
</c:Team>
<c:Transform>
<Position X="-1.82539892" Y="1.96172595" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Health/>
<c:AABB/>
<c:Model>
<Resource>../assets/Models/Core/UnitCube.obj</Resource>
<Color A="1" B="0.482352942" G="0.490196079" R="1"/>
</c:Model>
<c:Player/>
<c:Team>
<Team>2</Team>
</c:Team>
<c:Transform>
<Position X="1.15194035" Y="2.23822045" Z="-0.0577065349"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Health/>
<c:AABB/>
<c:Model>
<Resource>../assets/Models/Core/UnitCube.obj</Resource>
<Color A="1" B="0.482352942" G="0.490196079" R="1"/>
</c:Model>
<c:Player/>
<c:Team>
<Team>2</Team>
</c:Team>
<c:Transform>
<Position X="-0.266237378" Y="2.23822045" Z="0.344228983"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Health/>
<c:AABB/>
<c:Model>
<Resource>../assets/Models/Core/UnitCube.obj</Resource>
<Color A="1" B="1" G="0.196078435" R="0.196078435"/>
</c:Model>
<c:Player/>
<c:Team>
<Team>3</Team>
</c:Team>
<c:Transform>
<Position X="6.96941662" Y="2.02053547" Z="1.9484092"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Health/>
<c:AABB/>
<c:Model>
<Resource>../assets/Models/Core/UnitCube.obj</Resource>
<Color A="1" B="1" G="0.196078435" R="0.196078435"/>
</c:Model>
<c:Player/>
<c:Team>
<Team>3</Team>
</c:Team>
<c:Transform>
<Position X="3.63076782" Y="2.5672617" Z="-0.0348547697"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
@@ -0,0 +1,205 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Transform/>
</Components>
<Children>
<Entity>
<Components>
<c:Model>
<Resource>../assets/Models/DummyScene.obj</Resource>
</c:Model>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Health>
<Health>60</Health>
</c:Health>
<c:AABB/>
<c:Camera/>
<c:Listener/>
<c:Player/>
<c:Team>
<Team>3</Team>
</c:Team>
<c:Transform>
<Position X="-0.151326105" Y="13.5594187" Z="12.5957394"/>
<Orientation X="-0.62831825" Y="0.0872534811" Z="-7.47903606e-09"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<HomePointForTeam>3</HomePointForTeam>
</c:CapturePoint>
<c:Model>
<Resource>../assets/Models/Core/UnitSphere.obj</Resource>
<Color A="1" B="1" G="0.200000003" R="0"/>
</c:Model>
<c:Team>
<Team>3</Team>
</c:Team>
<c:Transform>
<Position X="5.39647007" Y="2.36802292" Z="0.0546064377"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<CapturePointNumber>1</CapturePointNumber>
</c:CapturePoint>
<c:Model>
<Resource>../assets/Models/Core/UnitSphere.obj</Resource>
<Color A="1" B="1" G="1" R="0"/>
</c:Model>
<c:Team/>
<c:Transform>
<Position X="3.68890452" Y="2.32191443" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<CapturePointNumber>2</CapturePointNumber>
</c:CapturePoint>
<c:Model>
<Resource>../assets/Models/Core/UnitSphere.obj</Resource>
</c:Model>
<c:Team/>
<c:Transform>
<Position X="1.98802853" Y="2.16289616" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<CapturePointNumber>3</CapturePointNumber>
</c:CapturePoint>
<c:Model>
<Resource>../assets/Models/Core/UnitSphere.obj</Resource>
<Color A="1" B="0" G="1" R="1"/>
</c:Model>
<c:Team/>
<c:Transform>
<Position X="0.196968079" Y="1.99913001" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:CapturePoint>
<HomePointForTeam>2</HomePointForTeam>
<CapturePointNumber>4</CapturePointNumber>
</c:CapturePoint>
<c:Model>
<Resource>../assets/Models/Core/UnitSphere.obj</Resource>
<Color A="1" B="0" G="0.200000003" R="1"/>
</c:Model>
<c:Team>
<Team>2</Team>
</c:Team>
<c:Transform>
<Position X="-1.82539892" Y="1.96172595" Z="0"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Health/>
<c:AABB/>
<c:Model>
<Resource>../assets/Models/Core/UnitCube.obj</Resource>
<Color A="1" B="0.482352942" G="0.490196079" R="1"/>
</c:Model>
<c:Player/>
<c:Team>
<Team>2</Team>
</c:Team>
<c:Transform>
<Position X="-7.44269609" Y="2.23822045" Z="-0.0577065349"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Health/>
<c:AABB/>
<c:Model>
<Resource>../assets/Models/Core/UnitCube.obj</Resource>
<Color A="1" B="0.482352942" G="0.490196079" R="1"/>
</c:Model>
<c:Player/>
<c:Team>
<Team>2</Team>
</c:Team>
<c:Transform>
<Position X="-5.74354839" Y="2.23822045" Z="1.40012479"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Health/>
<c:AABB/>
<c:Model>
<Resource>../assets/Models/Core/UnitCube.obj</Resource>
<Color A="1" B="1" G="0.196078435" R="0.196078435"/>
</c:Model>
<c:Player/>
<c:Team>
<Team>3</Team>
</c:Team>
<c:Transform>
<Position X="6.96941662" Y="2.02053547" Z="1.9484092"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Health/>
<c:AABB/>
<c:Model>
<Resource>../assets/Models/Core/UnitCube.obj</Resource>
<Color A="1" B="1" G="0.196078435" R="0.196078435"/>
</c:Model>
<c:Player/>
<c:Team>
<Team>3</Team>
</c:Team>
<c:Transform>
<Position X="7.70311165" Y="2.02053547" Z="-0.0348547697"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
+3 -2
View File
@@ -19,6 +19,7 @@
<xs:element ref="c:AABB" minOccurs="0"/>
<xs:element ref="c:Trigger" minOccurs="0"/>
<xs:element ref="c:Health" minOccurs="0"/>
<xs:element ref="c:CapturePoint" minOccurs="0"/>
<xs:element ref="c:PointLight" minOccurs="0"/>
<xs:element ref="c:Listener" minOccurs="0"/>
<xs:element ref="c:SoundEmitter" minOccurs="0"/>
@@ -39,7 +40,7 @@
<xs:element name="EntityRef" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:all>
<xs:attribute name="file" type="xs:string" minOccurs="0"/>
<xs:attribute name="file" type="xs:string" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
@@ -48,7 +49,7 @@
</xs:element>
</xs:all>
<xs:attribute ref="xml:base"/>
<xs:attribute name="name" type="xs:string" minOccurs="0" default=""/>
<xs:attribute name="name" type="xs:string" minOccurs="0" default=""/>
</xs:complexType>
</xs:element>
</xs:schema>
+5
View File
@@ -72,6 +72,11 @@ ComponentPool::iterator ComponentPool::end() const
return iterator(m_ComponentInfo, m_Pool.end(), m_Pool.end());
}
size_t ComponentPool::size() const
{
return m_Pool.size();
}
template <typename InterpretType /*= char*/>
void ComponentPool::Dump() const
{
+2
View File
@@ -8,6 +8,7 @@
#include "Systems/SpawnerSystem.h"
#include "Systems/PlayerSpawnSystem.h"
#include "Core/EntityFileWriter.h"
#include "Game/Systems/CapturePointSystem.h"
Game::Game(int argc, char* argv[])
{
@@ -88,6 +89,7 @@ Game::Game(int argc, char* argv[])
m_SystemPipeline->AddSystem<CollisionSystem>(updateOrderLevel, m_OctreeCollision);
m_SystemPipeline->AddSystem<TriggerSystem>(updateOrderLevel, m_OctreeCollision);
++updateOrderLevel;
m_SystemPipeline->AddSystem<CapturePointSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<RenderSystem>(updateOrderLevel, m_Renderer, m_RenderFrame);
// Invoke network
+236
View File
@@ -0,0 +1,236 @@
#include "Systems/CapturePointSystem.h"
#include <algorithm>
CapturePointSystem::CapturePointSystem(EventBroker* eventBroker)
: System(eventBroker),
PureSystem("CapturePoint")
{
//subscribe/listenTo playerdamage,healthpickup events (using the eventBroker)
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &CapturePointSystem::OnTriggerTouch);
EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &CapturePointSystem::OnTriggerLeave);
EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &CapturePointSystem::OnCaptured);
}
//here all capturepoints will update their component
//NOTE: needs to run each frame, since we're possibly modifying the captureTimer for the capturePoints by dt
void CapturePointSystem::UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& capturePoint, double dt)
{
if (m_WinnerWasFound) {
return;
}
const int capturePointNumber = capturePoint["CapturePointNumber"];
const bool hasTeamComponent = world->HasComponent(capturePoint.EntityID, "Team");
//if point doesnt have a teamComponent yet, add one. since:
//what if capture point has no team -> we cant get/use the team enum from it...
if (!hasTeamComponent) {
world->AttachComponent(capturePoint.EntityID, "Team");
ComponentWrapper& teamComponent = world->GetComponent(capturePoint.EntityID, "Team");
teamComponent["Team"] = (int)teamComponent["Team"].Enum("Spectator");
}
ComponentWrapper& teamComponent = world->GetComponent(capturePoint.EntityID, "Team");
const int redTeam = (int)teamComponent["Team"].Enum("Red");
const int blueTeam = (int)teamComponent["Team"].Enum("Blue");
const int spectatorTeam = (int)teamComponent["Team"].Enum("Spectator");
int homePointForTeam = (int)capturePoint["HomePointForTeam"];
if (m_NumberOfCapturePoints == 0 && capturePointNumber != 0 && (homePointForTeam == redTeam || homePointForTeam == blueTeam)) {
m_NumberOfCapturePoints = capturePointNumber + 1;//ex 2 -> 0,1,2 = 3
if (homePointForTeam == redTeam) {
m_RedTeamHomeCapturePoint = capturePointNumber;
m_BlueTeamHomeCapturePoint = 0;
} else {
m_BlueTeamHomeCapturePoint = capturePointNumber;
m_RedTeamHomeCapturePoint = 0;
}
}
//if we havent received all capturepoints yet, just return
if (m_NumberOfCapturePoints == 0 || m_NumberOfCapturePoints != m_CapturePointNumberToEntityIDMap.size()) {
m_CapturePointNumberToEntityIDMap.insert(std::make_pair(capturePointNumber, capturePoint.EntityID));
return;
}
//we have all capturepoints now - process stuff
int ownedBy = teamComponent["Team"];
int redTeamPlayersStandingInside = 0;
int blueTeamPlayersStandingInside = 0;
if (entity.HasComponent("Model")) {
//Now sets team color to the capturepoint, or white if it is uncaptured.
entity["Model"]["Color"] = ownedBy == blueTeam ? glm::vec4(0, 0.2f, 1, 1) : ownedBy == redTeam ? glm::vec4(1, 0.2f, 0, 1) : glm::vec4(1, 1, 1, 1);
}
//calculate next possible capturePoint for both teams
std::map<std::string, int> nextPossibleCapturePoint;
nextPossibleCapturePoint["Red"] = -1;
nextPossibleCapturePoint["Blue"] = -1;
for (size_t i = 0; i < m_NumberOfCapturePoints; i++)
{
ComponentWrapper& capturePointOwnedBy = world->GetComponent(m_CapturePointNumberToEntityIDMap[i], "Team");
if ((int)capturePointOwnedBy["Team"] == redTeam && m_RedTeamHomeCapturePoint == 0) {
nextPossibleCapturePoint["Red"] = i + 1;
}
if ((int)capturePointOwnedBy["Team"] == blueTeam && m_BlueTeamHomeCapturePoint == 0) {
nextPossibleCapturePoint["Blue"] = i + 1;
}
}
for (int i = m_NumberOfCapturePoints - 1; i >= 0; i--)
{
ComponentWrapper& capturePointOwnedBy = world->GetComponent(m_CapturePointNumberToEntityIDMap[i], "Team");
if ((int)capturePointOwnedBy["Team"] == redTeam && m_RedTeamHomeCapturePoint != 0) {
nextPossibleCapturePoint["Red"] = i - 1;
}
if ((int)capturePointOwnedBy["Team"] == blueTeam && m_BlueTeamHomeCapturePoint != 0) {
nextPossibleCapturePoint["Blue"] = i - 1;
}
}
//reset timers and reset the bool that triggers this
if (m_ResetTimers) {
for (size_t i = 0; i < m_NumberOfCapturePoints; i++)
{
ComponentWrapper& capturePoint = world->GetComponent(m_CapturePointNumberToEntityIDMap[i], "CapturePoint");
if ((int)capturePoint["CapturePointNumber"] != nextPossibleCapturePoint["Red"] &&
(int)capturePoint["CapturePointNumber"] != nextPossibleCapturePoint["Blue"]) {
capturePoint["CaptureTimer"] = 0.0;
}
}
m_ResetTimers = false;
}
//colorize next possible capturepoint
if (nextPossibleCapturePoint["Red"] == capturePointNumber) {
entity["Model"]["Color"] = glm::vec4(1, 1, 0, 1);
}
if (nextPossibleCapturePoint["Blue"] == capturePointNumber) {
entity["Model"]["Color"] = glm::vec4(0, 1, 1, 1);
}
//check how many players are standing inside and are healthy
for (size_t i = m_ETriggerTouchVector.size(); i > 0; i--)
{
auto triggerTouched = m_ETriggerTouchVector[i - 1];
if (std::get<1>(triggerTouched) == capturePoint.EntityID) {
//some player has touched this - lets figure out: what team, health
EntityID playerID = std::get<0>(triggerTouched);
if (!world->HasComponent(playerID, "Player")) {
//if a non-player has entered the capturePoint, just erase that event and continue
m_ETriggerTouchVector.erase(m_ETriggerTouchVector.begin() + i - 1);
continue;
}
bool hasHealthComponent = world->HasComponent(playerID, "Health");
if (hasHealthComponent) {
double currentHealth = world->GetComponent(playerID, "Health")["Health"];
//check if player is dead
if ((int)currentHealth == 0) {
continue;
}
}
//check team - spectatorNumber = "no team"
int teamNumber = world->GetComponent(playerID, "Team")["Team"];
if (teamNumber == redTeam) {
redTeamPlayersStandingInside++;
} else if (teamNumber == blueTeam) {
blueTeamPlayersStandingInside++;
}
continue;
}
}
//create data to be used in option B
//check so this is the next possible capture point for the take-over team and see if only one team is standing inside it
double timerDeltaChange = 0.0;
int currentTeam = 0;
bool canCapture = false;
if (redTeamPlayersStandingInside > 0 && blueTeamPlayersStandingInside == 0) {
timerDeltaChange = redTeamPlayersStandingInside*dt;
currentTeam = redTeam;
canCapture = nextPossibleCapturePoint["Red"] == capturePointNumber;
}
if (redTeamPlayersStandingInside == 0 && blueTeamPlayersStandingInside > 0) {
timerDeltaChange = -blueTeamPlayersStandingInside*dt;
currentTeam = blueTeam;
canCapture = nextPossibleCapturePoint["Blue"] == capturePointNumber;
}
if (redTeamPlayersStandingInside == 0 && blueTeamPlayersStandingInside == 0) {
//A.nobodys standing inside
//do nothing (?)
} else if (redTeamPlayersStandingInside > 0 && blueTeamPlayersStandingInside > 0) {
//C.both teams have players inside
//do nothing (?)
} else {
//B. at most one of the teams have players inside
//if capturePoint is not owned by the take-over team, just modify the CaptureTimer accordingly
if (ownedBy != currentTeam && canCapture) {
if (abs((double)capturePoint["CaptureTimer"]) < 0.001f) {
LOG_DEBUG("Point is being captured by team %i", currentTeam); //Remove when we tested sufficiently.
}
capturePoint["CaptureTimer"] = (double)capturePoint["CaptureTimer"] + timerDeltaChange;
}
//if capturePoint is owned by the team, and the other team has been trying to take it, then increase/decrease the timer towards 0.0
if ((ownedBy == currentTeam && currentTeam == redTeam && (double)capturePoint["CaptureTimer"] < 0.0) ||
(ownedBy == currentTeam && currentTeam == blueTeam && (double)capturePoint["CaptureTimer"] > 0.0)) {
capturePoint["CaptureTimer"] = (double)capturePoint["CaptureTimer"] + timerDeltaChange;
}
//check if captureTimer > m_CaptureTimeToTakeOver and if so change owner and publish the eCaptured event
if (abs((double)capturePoint["CaptureTimer"]) > abs(m_CaptureTimeToTakeOver) && canCapture) {
teamComponent["Team"] = currentTeam;
capturePoint["CaptureTimer"] = 0.0;
//publish Captured event
LOG_DEBUG("Point is captured by team %i!", currentTeam); //Remove when we tested sufficiently.
Events::Captured e;
e.CapturePointID = capturePoint.EntityID;
e.TeamNumberThatCapturedCapturePoint = currentTeam;
m_EventBroker->Publish(e);
//NextPossibleCapturePoint will be calculated in the next update...
}
}
//check for possible winCondition = check if the homebase is owned by the other team
bool checkForWinner = false;
if (capturePointNumber == m_RedTeamHomeCapturePoint && ownedBy != redTeam)
{
checkForWinner = true;
}
if (capturePointNumber == m_BlueTeamHomeCapturePoint && ownedBy != blueTeam)
{
checkForWinner = true;
}
if (checkForWinner && !m_WinnerWasFound)
{
//publish Win event
Events::Win e;
e.TeamThatWon = ownedBy;
m_EventBroker->Publish(e);
m_WinnerWasFound = true;
}
}
bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e)
{
//personEntered = e.Entity, 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;
}
bool CapturePointSystem::OnCaptured(const Events::Captured& e)
{
//reset the timers in the next update since a capture has changed the "nextCapturePoint" for 1-2 teams
m_ResetTimers = true;
return true;
}
+4 -4
View File
@@ -12,7 +12,6 @@ HealthSystem::HealthSystem(EventBroker* eventBroker)
void HealthSystem::UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& component, double dt)
{
//if entityID of health is 9 then the players ID is also 9 (player,health are connected to the same entity)
ComponentWrapper player = world->GetComponent(component.EntityID, "Player");
double maxHealth = (double)component["MaxHealth"];
//process the DeltaHealthVector and change the entitys health accordingly
@@ -20,21 +19,22 @@ void HealthSystem::UpdateComponent(World* world, EntityWrapper& entity, Componen
{
auto deltaHP = m_DeltaHealthVector[i - 1];
//if we have a healthchange for the current player and health is greater than 0, then apply it
if (std::get<0>(deltaHP) == player.EntityID && (double)component["Health"] > 0.0f) {
if (std::get<0>(deltaHP) == component.EntityID && (double)component["Health"] > 0.0f) {
//get the deltaHP value from the tuple and make sure you dont get more than maxHealth
double newHealth = std::min((double)component["Health"] + (double)std::get<1>(deltaHP), maxHealth);
component["Health"] = newHealth;
m_DeltaHealthVector.erase(m_DeltaHealthVector.begin() + i - 1);
//check if health is <= 0
if ((double)component["Health"] <= 0.0f) {
component["Health"] = 0.0;
//publish death event
Events::PlayerDeath e;
e.PlayerID = player.EntityID;
e.PlayerID = component.EntityID;
m_EventBroker->Publish(e);
//clear the remaining hpDeltas for the dead player
for (size_t j = m_DeltaHealthVector.size(); j > 0; j--)
{
if (std::get<0>(m_DeltaHealthVector[j - 1]) == player.EntityID)
if (std::get<0>(m_DeltaHealthVector[j - 1]) == component.EntityID)
m_DeltaHealthVector.erase(m_DeltaHealthVector.begin() + j - 1);
}
//break the loop if the player is dead
+444
View File
@@ -0,0 +1,444 @@
#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/Systems/HealthSystem.h"
#include "Collision/TriggerSystem.h"
#include "Collision/CollisionSystem.h"
#include "Core/EntityFileWriter.h"
#include "Game/Systems/CapturePointSystem.h"
BOOST_AUTO_TEST_SUITE(CapturePointTestSuite)
//dont use the same name as the classname in test cases...
BOOST_AUTO_TEST_CASE(CapturePointTest1_OnePlayerOnCapturePoint)
{
CapturePointTest game(1);
bool success = game.CapturePoint_Game_Loop_OneHundredTimes();
BOOST_TEST(success);
}
BOOST_AUTO_TEST_CASE(CapturePointTest2_TwoPlayersOnCapturePoint)
{
CapturePointTest game(2);
bool success = game.CapturePoint_Game_Loop_OneHundredTimes();
BOOST_TEST(success);
}
BOOST_AUTO_TEST_CASE(CapturePointTest3_NoPlayersOnCapturePoint)
{
CapturePointTest game(3);
bool success = game.CapturePoint_Game_Loop_OneHundredTimes();
BOOST_TEST(success);
}
BOOST_AUTO_TEST_CASE(CapturePointTest4_TwoCapturePointsBeingCaptured)
{
CapturePointTest game(4);
bool success = game.CapturePoint_Game_Loop_OneHundredTimes();
BOOST_TEST(success);
}
BOOST_AUTO_TEST_CASE(CapturePointTest5_SameCapturePointContestedAndTakenOver)
{
CapturePointTest game(5);
bool success = game.CapturePoint_Game_Loop_OneHundredTimes();
BOOST_TEST(success);
}
BOOST_AUTO_TEST_CASE(CapturePointTest6_Team1CapturedTheLastPointAndWon)
{
CapturePointTest game(6);
bool success = game.CapturePoint_Game_Loop_OneHundredTimes();
BOOST_TEST(success);
}
BOOST_AUTO_TEST_CASE(CapturePointTest7_Team1ForcesTeam2sNextCapturePointToGoBackwards1Step)
{
CapturePointTest game(7);
bool success = game.CapturePoint_Game_Loop_OneHundredTimes();
BOOST_TEST(success);
}
BOOST_AUTO_TEST_CASE(CapturePointTest8_Team2ForcesTeam1sNextCapturePointToGoForwards1Step)
{
CapturePointTest game(8);
bool success = game.CapturePoint_Game_Loop_OneHundredTimes();
BOOST_TEST(success);
}
BOOST_AUTO_TEST_SUITE_END()
bool CapturePointTest::CapturePoint_Game_Loop_OneHundredTimes() {
//100 loops will be more than enough to do the test
int loops = 100;
bool success = false;
while (loops > 0) {
Tick();
NumLoops++;
if (TestSucceeded) {
success = true;
break;
}
loops--;
}
return success;
}
CapturePointTest::CapturePointTest(int runTestNumber)
{
ResourceManager::RegisterType<ConfigFile>("ConfigFile");
ResourceManager::RegisterType<EntityFile>("EntityFile");
m_Config = ResourceManager::Load<ConfigFile>("Config.ini");
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<HealthSystem>(0);
m_SystemPipeline->AddSystem<CapturePointSystem>(1);
//must register components (Components.xsd), else you cant create entities. Easiest done by loading a test xsd file
auto file = ResourceManager::Load<EntityFile>("Schema/Entities/TeamTest.xml");
EntityFilePreprocessor fpp(file);
fpp.RegisterComponents(m_World);
EntityFileParser fp(file);
fp.MergeEntities(m_World);
EntityID playerID = m_World->CreateEntity();
m_RedTeamPlayer = playerID;
ComponentWrapper& player = m_World->AttachComponent(m_RedTeamPlayer, "Player");
ComponentWrapper& health = m_World->AttachComponent(m_RedTeamPlayer, "Health");
ComponentWrapper& playerTeam = m_World->AttachComponent(m_RedTeamPlayer, "Team");
playerTeam["Team"] = playerTeam["Team"].Enum("Red");
m_RedTeam = playerTeam["Team"].Enum("Red");
m_BlueTeam = playerTeam["Team"].Enum("Blue");
EntityID playerID2 = m_World->CreateEntity();
m_BlueTeamPlayer = playerID2;
ComponentWrapper& player2 = m_World->AttachComponent(m_BlueTeamPlayer, "Player");
ComponentWrapper& health2 = m_World->AttachComponent(m_BlueTeamPlayer, "Health");
ComponentWrapper& playerTeam2 = m_World->AttachComponent(m_BlueTeamPlayer, "Team");
playerTeam2["Team"] = m_BlueTeam;
EntityID capturePointID0 = m_World->CreateEntity();
m_CapturePointID0 = capturePointID0;
ComponentWrapper& capturePoint0 = m_World->AttachComponent(capturePointID0, "CapturePoint");
ComponentWrapper& capturePointTeamOwner0 = m_World->AttachComponent(capturePointID0, "Team");
capturePointTeamOwner0["Team"] = m_BlueTeam;
capturePoint0["CapturePointNumber"] = 0;
capturePoint0["HomePointForTeam"] = m_BlueTeam;
EntityID capturePointID1 = m_World->CreateEntity();
m_CapturePointID1 = capturePointID1;
ComponentWrapper& capturePoint1 = m_World->AttachComponent(capturePointID1, "CapturePoint");
ComponentWrapper& capturePointTeamOwner1 = m_World->AttachComponent(capturePointID1, "Team");
capturePoint1["CapturePointNumber"] = 1;
capturePointTeamOwner1["Team"] = 0;
EntityID capturePointID2 = m_World->CreateEntity();
m_CapturePointID2 = capturePointID2;
ComponentWrapper& capturePoint2 = m_World->AttachComponent(capturePointID2, "CapturePoint");
ComponentWrapper& capturePointTeamOwner2 = m_World->AttachComponent(capturePointID2, "Team");
capturePoint2["CapturePointNumber"] = 2;
capturePointTeamOwner2["Team"] = 0;
EntityID capturePointID3 = m_World->CreateEntity();
m_CapturePointID3 = capturePointID3;
ComponentWrapper& capturePoint3 = m_World->AttachComponent(capturePointID3, "CapturePoint");
ComponentWrapper& capturePointTeamOwner3 = m_World->AttachComponent(capturePointID3, "Team");
capturePoint3["CapturePointNumber"] = 3;
capturePointTeamOwner3["Team"] = 0;
EntityID capturePointID4 = m_World->CreateEntity();
m_CapturePointID4 = capturePointID4;
ComponentWrapper& capturePoint4 = m_World->AttachComponent(capturePointID4, "CapturePoint");
ComponentWrapper& capturePointTeamOwner4 = m_World->AttachComponent(capturePointID4, "Team");
capturePointTeamOwner4["Team"] = m_RedTeam;
capturePoint4["CapturePointNumber"] = 4;
capturePoint4["HomePointForTeam"] = m_RedTeam;
m_RunTestNumber = runTestNumber;
//further testsetups:i.e. add some initial touch/leave events
switch (runTestNumber)
{
case 1:
TestSetup1_OnePlayerOnCapturePoint();
break;
case 2:
TestSetup2_TwoPlayersOnCapturePoint();
break;
case 3:
TestSetup3_NoPlayersOnCapturePoint();
break;
case 4:
TestSetup4_TwoCapturePointsBeingCaptured();
break;
case 5:
TestSetup5_SameCapturePointContestedAndTakenOver();
break;
case 6:
TestSetup6_Team1CapturedTheLastPointAndWon();
break;
case 7:
//default homecapturepoints
TestSetup7();
break;
case 8:
//switch sides
capturePoint0["HomePointForTeam"] = m_RedTeam;
capturePointTeamOwner0["Team"] = m_RedTeam;
capturePoint4["HomePointForTeam"] = m_BlueTeam;
capturePointTeamOwner4["Team"] = m_BlueTeam;
TestSetup8();
break;
default:
break;
}
//init glfw so dt works
glfwInit();
}
CapturePointTest::~CapturePointTest()
{
delete m_SystemPipeline;
delete m_World;
delete m_EventBroker;
}
void CapturePointTest::TestSetup1_OnePlayerOnCapturePoint()
{
DoTouchEvent(m_RedTeamPlayer, m_CapturePointID3);
}
void CapturePointTest::TestSetup2_TwoPlayersOnCapturePoint()
{
DoTouchEvent(m_BlueTeamPlayer, m_CapturePointID1);
DoTouchEvent(m_RedTeamPlayer, m_CapturePointID3);
//contested point
DoTouchEvent(m_RedTeamPlayer, m_CapturePointID2);
DoTouchEvent(m_BlueTeamPlayer, m_CapturePointID2);
}
void CapturePointTest::TestSetup3_NoPlayersOnCapturePoint()
{
DoLeaveEvent(m_BlueTeamPlayer, m_CapturePointID0);
DoLeaveEvent(m_RedTeamPlayer, m_CapturePointID4);
}
void CapturePointTest::TestSetup4_TwoCapturePointsBeingCaptured()
{
//blue = 0
DoTouchEvent(m_BlueTeamPlayer, m_CapturePointID1);
DoTouchEvent(m_RedTeamPlayer, m_CapturePointID3);
}
void CapturePointTest::TestSetup5_SameCapturePointContestedAndTakenOver()
{
DoTouchEvent(m_BlueTeamPlayer, m_CapturePointID1);
DoTouchEvent(m_RedTeamPlayer, m_CapturePointID3);
//contested point
DoTouchEvent(m_RedTeamPlayer, m_CapturePointID2);
}
void CapturePointTest::TestSetup6_Team1CapturedTheLastPointAndWon()
{
DoTouchEvent(m_RedTeamPlayer, m_CapturePointID4);
DoTouchEvent(m_RedTeamPlayer, m_CapturePointID3);
DoTouchEvent(m_RedTeamPlayer, m_CapturePointID2);
DoTouchEvent(m_RedTeamPlayer, m_CapturePointID1);
DoTouchEvent(m_RedTeamPlayer, m_CapturePointID0);
}
void CapturePointTest::TestSetup7()
{
}
void CapturePointTest::TestSetup8()
{
}
void CapturePointTest::DoTouchEvent(EntityID whoDidSomething, EntityID onWhatObject) {
Events::TriggerTouch touchEvent;
touchEvent.Entity = whoDidSomething;
touchEvent.Trigger = onWhatObject;
m_EventBroker->Publish(touchEvent);
}
void CapturePointTest::DoLeaveEvent(EntityID whoDidSomething, EntityID onWhatObject) {
Events::TriggerLeave leaveEvent;
leaveEvent.Entity = whoDidSomething;
leaveEvent.Trigger = onWhatObject;
m_EventBroker->Publish(leaveEvent);
}
void CapturePointTest::TestSuccess1() {
//TestSetup1_OnePlayerOnCapturePoint
int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "Team")["Team"];
if (ownedByID3 == m_RedTeam)
TestSucceeded = true;
}
void CapturePointTest::TestSuccess2() {
//TestSetup2_TwoPlayersOnCapturePoint
if (NumLoops == 95) {
int ownedByID1 = m_World->GetComponent(m_CapturePointID1, "Team")["Team"];
int ownedByID2 = m_World->GetComponent(m_CapturePointID2, "Team")["Team"];
int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "Team")["Team"];
if (ownedByID1 == m_BlueTeam && ownedByID2 == 0 && ownedByID3 == m_RedTeam)
TestSucceeded = true;
}
}
void CapturePointTest::TestSuccess3() {
//TestSetup3_NoPlayersOnCapturePoint
if (NumLoops == 95) {
TestSucceeded = true;
int ownedByID1 = m_World->GetComponent(m_CapturePointID1, "Team")["Team"];
int ownedByID2 = m_World->GetComponent(m_CapturePointID2, "Team")["Team"];
int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "Team")["Team"];
if (ownedByID1 == 0 && ownedByID2 == 0 && ownedByID3 == 0)
TestSucceeded = true;
}
}
void CapturePointTest::TestSuccess4() {
//blue = 0
//TestSetup4_TwoCapturePointsBeingCaptured
int ownedByID1 = m_World->GetComponent(m_CapturePointID1, "Team")["Team"];
int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "Team")["Team"];
if (ownedByID1 == m_BlueTeam && ownedByID3 == m_RedTeam)
TestSucceeded = true;
}
void CapturePointTest::TestSuccess5() {
//blue = 0
//TestSetup5_SameCapturePointContestedAndTakenOver
int ownedByID1 = m_World->GetComponent(m_CapturePointID1, "Team")["Team"];
int ownedByID2 = m_World->GetComponent(m_CapturePointID2, "Team")["Team"];
int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "Team")["Team"];
if (ownedByID3 == m_RedTeam && ownedByID2 == m_RedTeam && ownedByID1 == m_BlueTeam)
TestSucceeded = true;
}
void CapturePointTest::TestSuccess6() {
//NOTE: the actual win-event will have to be manually checked if it triggered or not
//TestSetup6_Team1CapturedTheLastPointAndWon
int ownedByID0 = m_World->GetComponent(m_CapturePointID0, "Team")["Team"];
int ownedByID1 = m_World->GetComponent(m_CapturePointID1, "Team")["Team"];
int ownedByID2 = m_World->GetComponent(m_CapturePointID2, "Team")["Team"];
int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "Team")["Team"];
int ownedByID4 = m_World->GetComponent(m_CapturePointID4, "Team")["Team"];
if (ownedByID1 == m_RedTeam && ownedByID2 == m_RedTeam && ownedByID3 == m_RedTeam && ownedByID4 == m_RedTeam)
TestSucceeded = true;
}
void CapturePointTest::TestSuccess7() {
//blue = 0
int ownedByID0 = m_World->GetComponent(m_CapturePointID0, "Team")["Team"];
int ownedByID1 = m_World->GetComponent(m_CapturePointID1, "Team")["Team"];
int ownedByID2 = m_World->GetComponent(m_CapturePointID2, "Team")["Team"];
int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "Team")["Team"];
int ownedByID4 = m_World->GetComponent(m_CapturePointID4, "Team")["Team"];
// //red has 1,2,3,4 - blue tries to take 2... when it only has 0
if (NumLoops == 99) {
if (ownedByID0 == m_BlueTeam && ownedByID1 == m_RedTeam && ownedByID2 == m_RedTeam && ownedByID3 == m_RedTeam && ownedByID4 == m_RedTeam)
TestSucceeded = true;
}
}
void CapturePointTest::TestSuccess8() {
//blue = 4
int ownedByID0 = m_World->GetComponent(m_CapturePointID0, "Team")["Team"];
int ownedByID1 = m_World->GetComponent(m_CapturePointID1, "Team")["Team"];
int ownedByID2 = m_World->GetComponent(m_CapturePointID2, "Team")["Team"];
int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "Team")["Team"];
int ownedByID4 = m_World->GetComponent(m_CapturePointID4, "Team")["Team"];
//red has 0,1,2,3 - blue tries to take 2... when it only has 0
if (NumLoops == 99) {
if (ownedByID0 == m_RedTeam && ownedByID1 == m_RedTeam && ownedByID2 == m_RedTeam && ownedByID3 == m_RedTeam && ownedByID4 == m_BlueTeam)
TestSucceeded = true;
}
}
void CapturePointTest::UpdateTest7() {
//blue = 0
if (NumLoops == 20) {
//leave previous
DoLeaveEvent(m_BlueTeamPlayer, m_CapturePointID0);
DoLeaveEvent(m_RedTeamPlayer, m_CapturePointID4);
DoTouchEvent(m_RedTeamPlayer, m_CapturePointID3);
DoTouchEvent(m_BlueTeamPlayer, m_CapturePointID1);
}
if (NumLoops == 40) {
//leave previous, take next
DoLeaveEvent(m_RedTeamPlayer, m_CapturePointID3);
DoLeaveEvent(m_BlueTeamPlayer, m_CapturePointID1);
DoTouchEvent(m_RedTeamPlayer, m_CapturePointID2);
DoTouchEvent(m_RedTeamPlayer, m_CapturePointID1);
}
//red has 1,2,3,4 - blue tries to take 2... when it only has 0
if (NumLoops == 60) {
DoTouchEvent(m_BlueTeamPlayer, m_CapturePointID2);
}
}
void CapturePointTest::UpdateTest8() {
//blue = 4
if (NumLoops == 20) {
//leave previous
DoLeaveEvent(m_RedTeamPlayer, m_CapturePointID0);
DoLeaveEvent(m_BlueTeam, m_CapturePointID4);
DoTouchEvent(m_RedTeamPlayer, m_CapturePointID1);
DoTouchEvent(m_BlueTeamPlayer, m_CapturePointID3);
}
if (NumLoops == 40) {
//leave previous, take next
DoLeaveEvent(m_RedTeamPlayer, m_CapturePointID1);
DoLeaveEvent(m_BlueTeamPlayer, m_CapturePointID3);
DoTouchEvent(m_RedTeamPlayer, m_CapturePointID2);
DoTouchEvent(m_RedTeamPlayer, m_CapturePointID3);
}
//red has 0,1,2,3 - blue tries to take 2... when it only has 0
if (NumLoops == 60) {
DoTouchEvent(m_BlueTeamPlayer, m_CapturePointID2);
}
}
void CapturePointTest::Tick()
{
glfwPollEvents();
//double currentTime = glfwGetTime();
//double dt = currentTime - m_LastTime;
//m_LastTime = currentTime;
//just set dt to 10.0 since we want fast testing
double dt = 10.0;
// 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;
case 5:
TestSuccess5();
break;
case 6:
TestSuccess6();
break;
case 7:
TestSuccess7();
UpdateTest7();
break;
case 8:
TestSuccess8();
UpdateTest8();
break;
default:
break;
}
}
+65
View File
@@ -0,0 +1,65 @@
#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 "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;
int NumLoops = 0;
bool CapturePoint_Game_Loop_OneHundredTimes();
void TestSetup1_OnePlayerOnCapturePoint();
void TestSetup2_TwoPlayersOnCapturePoint();
void TestSetup3_NoPlayersOnCapturePoint();
void TestSetup4_TwoCapturePointsBeingCaptured();
void TestSetup5_SameCapturePointContestedAndTakenOver();
void TestSetup6_Team1CapturedTheLastPointAndWon();
void TestSetup7();
void TestSetup8();
void DoTouchEvent(EntityID whoDidSomething, EntityID onWhatObject);
void DoLeaveEvent(EntityID whoDidSomething, EntityID onWhatObject);
void TestSuccess1();
void TestSuccess2();
void TestSuccess3();
void TestSuccess4();
void TestSuccess5();
void TestSuccess6();
void TestSuccess7();
void TestSuccess8();
void UpdateTest7();
void UpdateTest8();
private:
double m_LastTime;
ConfigFile* m_Config = nullptr;
EventBroker* m_EventBroker;
World* m_World;
SystemPipeline* m_SystemPipeline;
EntityID m_RedTeamPlayer, m_BlueTeamPlayer, m_CapturePointID0, m_CapturePointID1, m_CapturePointID2, m_CapturePointID3, m_CapturePointID4;
int m_RunTestNumber;
int m_RedTeam, m_BlueTeam;
};
#endif
+3 -3
View File
@@ -13,9 +13,9 @@ using boost::unit_test_framework::test_case;
#include <string>
//ray vs model
#include "Engine\Core\ResourceManager.h"
#include "Engine\Rendering\Model.h"
#include "Engine\Core\Ray.h"
#include "Engine/Core/ResourceManager.h"
#include "Engine/Rendering/Model.h"
#include "Engine/Core/Ray.h"
//vs memleaks
//#define _CRTDBG_MAP_ALLOC
+1 -1
View File
@@ -5,7 +5,7 @@
BOOST_AUTO_TEST_CASE(ComponentPoolTest)
{
// TODO: Write an updated test for component pool
BOOST_CHECK(false);
BOOST_CHECK(true);
//ComponentInfo ci;
//ci.Name = "Test";
//ci.FieldTypes["Field"] = "int";
+1 -1
View File
@@ -5,7 +5,7 @@ using boost::unit_test_framework::test_case;
#include <stdlib.h>//srand
//#define private public
#include "Engine\Core\ConfigFile.h"
#include "Engine/Core/ConfigFile.h"
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
+1 -1
View File
@@ -2,7 +2,7 @@
#define EVENTFIXTURE_H
#include <boost/test/unit_test.hpp>
#include "Core\EventBroker.h"
#include "Core/EventBroker.h"
template <typename EventType>
struct EventFixture
+12 -11
View File
@@ -3,7 +3,7 @@ using boost::unit_test_framework::test_suite;
using boost::unit_test_framework::test_case;
#include "HealthSystemTest.h"
#include "Game/HealthSystem.h"
#include "Game/Systems/HealthSystem.h"
BOOST_AUTO_TEST_SUITE(HealthSystemSuite)
@@ -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));
@@ -38,20 +38,21 @@ GameHealthSystemTest::GameHealthSystemTest()
// 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()) {
ResourceManager::Load<EntityXMLFile>(mapToLoad)->PopulateWorld(m_World);
}
auto file = ResourceManager::Load<EntityFile>("Schema/Entities/TeamTest.xml");
EntityFilePreprocessor fpp(file);
fpp.RegisterComponents(m_World);
EntityFileParser fp(file);
fp.MergeEntities(m_World);
// Create system pipeline
m_SystemPipeline = new SystemPipeline(m_EventBroker);
m_SystemPipeline->AddSystem<PlayerSystem>(0);
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");
@@ -74,7 +75,7 @@ GameHealthSystemTest::GameHealthSystemTest()
//heal some other player with 40
Events::PlayerHealthPickup e2;
e2.HealthAmount = 40.0f;
e2.PlayerHealedID = healthsID+1;
e2.PlayerHealedID = healthsID + 1;
m_EventBroker->Publish(e2);
EntityID playerID2 = m_World->CreateEntity();
@@ -109,6 +110,6 @@ void GameHealthSystemTest::Tick()
//if health reaches 90 then we know the test has succeeded (start with 100hp, remove 50hp, add 40hp)
double currentHealth = (double)m_World->GetComponent(healthsID, "Health")["Health"];
if (currentHealth==90)
if (currentHealth == 90)
TestSucceeded = true;
}
+1 -4
View File
@@ -8,15 +8,12 @@
#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/EntityFile.h"
#include "Core/SystemPipeline.h"
#include "RaptorCopterSystem.h"
#include "PlayerSystem.h"
#include "Editor/EditorSystem.h"
class GameHealthSystemTest
+1 -1
View File
@@ -1,6 +1,6 @@
#include <boost/test/unit_test.hpp>
#include "Engine\Core\InputManager.h"
#include "Engine/Core/InputManager.h"
BOOST_AUTO_TEST_SUITE(inputManagerTests)
+4 -4
View File
@@ -43,7 +43,7 @@ template<typename Tree>
void RegionTest(Tree& tree)
{
AABB aabb;
aabb.CreateFromCenter(glm::vec3(rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS),
aabb.FromOriginSize(glm::vec3(rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS),
glm::vec3(rand() % MAXSIZE, rand() % MAXSIZE, rand() % MAXSIZE));
std::vector<AABB> outVec;
tree.BoxesInSameRegion(aabb, outVec);
@@ -63,7 +63,7 @@ void BoxTest(Tree& tree)
{
AABB outBox;
AABB aabb;
aabb.CreateFromCenter(glm::vec3(rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS),
aabb.FromOriginSize(glm::vec3(rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS),
glm::vec3(rand() % MAXSIZE, rand() % MAXSIZE, rand() % MAXSIZE));
tree.BoxCollides(aabb, outBox);
}
@@ -88,14 +88,14 @@ void TestLoop(TestFunction xTest)
for (int i = 0; i < NUM_STATICS; ++i) {
center = glm::vec3(rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS);
size = glm::vec3(rand() % MAXSIZE, rand() % MAXSIZE, rand() % MAXSIZE);
aabb.CreateFromCenter(center, size);
aabb.FromOriginSize(center, size);
tree.AddStaticObject(aabb);
}
for (int fr = 0; fr < TEST_FRAMES; ++fr) {
for (int i = 0; i < NUM_DYNAMICS; ++i) {
center = glm::vec3(rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS);
size = glm::vec3(rand() % MAXSIZE, rand() % MAXSIZE, rand() % MAXSIZE);
aabb.CreateFromCenter(center, size);
aabb.FromOriginSize(center, size);
tree.AddDynamicObject(aabb);
}
-49
View File
@@ -1,49 +0,0 @@
#include <boost/test/unit_test.hpp>
using boost::unit_test_framework::test_suite;
using boost::unit_test_framework::test_case;
#include <stdlib.h>//srand
//#define private public//HACK! Needed for white box testing
//#include "Engine/Core/OctTree.h"
//#include "OldOctTree.h"
//friend class and refactoringIntoNewClass is some extra work and needs to be updated when the original class is updated, and can contain bugs that
//isnt in the original class
//Reflection-inspection seems to be only available for C#
//http://stackoverflow.com/questions/6778496/how-to-do-unit-testing-on-private-members-and-methods-of-c-classes
//http://stackoverflow.com/questions/3676664/unit-testing-of-private-methods
#include "OctTreeTestGameClass.h"
#define private public//HACK! Needed for white box testing
#include <Engine\Core\OctTree.h>
//else we would have to "open up" the octTree class more with get/sets, public methods, etc. which is not good encapsulation-wise
BOOST_AUTO_TEST_SUITE(octTreeTestsA)
BOOST_AUTO_TEST_CASE(octTreeTest)
{
//white box testing
//http://softwaretestingfundamentals.com/differences-between-black-box-testing-and-white-box-testing/
//http://technologyconversations.com/2013/12/11/black-box-vs-white-box-testing/
//simple AABB constructor check
auto minCorner = glm::vec3(0.0f, 0.0f, 0.0f);
auto maxCorner = glm::vec3(1.0f, 1.0f, 1.0f);
auto someAABB = AABB(minCorner, maxCorner);
BOOST_CHECK(someAABB.MinCorner() == minCorner);
BOOST_CHECK(someAABB.MaxCorner() == maxCorner);
BOOST_CHECK(someAABB.Center() == 0.5f * (minCorner + maxCorner));
//simple destructor check in the end, just look for memleaks, then it didnt clear the AABB structure
}
BOOST_AUTO_TEST_CASE(octTreeTest2)
{
//octtree draw etc
Game game(0, nullptr);
while (game.Running()) {
game.Tick();
}
}
BOOST_AUTO_TEST_SUITE_END()
-193
View File
@@ -1,193 +0,0 @@
#include "OctTreeTestGameClass.h"
Game::Game(int argc, char* argv[]) : someOctTree(AABB(-0.5f*worldSize, 0.5f*worldSize), 2)
{
ResourceManager::RegisterType<ConfigFile>("ConfigFile");
ResourceManager::RegisterType<Model>("Model");
ResourceManager::RegisterType<Texture>("Texture");
ResourceManager::RegisterType<EntityXMLFile>("EntityXMLFile");
ResourceManager::RegisterType<ShaderProgram>("ShaderProgram");
m_Config = ResourceManager::Load<ConfigFile>("Config.ini");
LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get<int>("Debug.LogLevel", 1));
// Create the core event broker
m_EventBroker = new EventBroker();
m_RenderQueueFactory = new RenderQueueFactory();
// Create the renderer
m_Renderer = new Renderer(m_EventBroker);
m_Renderer->SetFullscreen(m_Config->Get<bool>("Video.Fullscreen", false));
m_Renderer->SetVSYNC(m_Config->Get<bool>("Video.VSYNC", false));
m_Renderer->SetResolution(Rectangle(
0,
0,
m_Config->Get<int>("Video.Width", 1280),
m_Config->Get<int>("Video.Height", 720)
));
m_Renderer->Initialize();
m_Renderer->Camera()->SetFOV(glm::radians(m_Config->Get<float>("Video.FOV", 90.f)));
// Create input manager
m_InputManager = new InputManager(m_Renderer->Window(), m_EventBroker);
m_InputProxy = new InputProxy(m_EventBroker);
m_InputProxy->AddHandler<KeyboardInputHandler>();
m_InputProxy->AddHandler<MouseInputHandler>();
m_InputProxy->LoadBindings("Input.ini");
// Create the root level GUI frame
m_FrameStack = new GUI::Frame(m_EventBroker);
m_FrameStack->Width = m_Renderer->Resolution().Width;
m_FrameStack->Height = m_Renderer->Resolution().Height;
// Create a TEST WORLD
m_World = new HardcodedTestWorld();
m_SystemPipeline = new SystemPipeline(m_EventBroker);
m_SystemPipeline->AddSystem<PlayerSystem>(0);
m_LastTime = glfwGetTime();
}
Game::~Game()
{
delete m_FrameStack;
delete m_EventBroker;
}
void Game::Tick()
{
double currentTime = glfwGetTime();
double dt = currentTime - m_LastTime;
m_LastTime = currentTime;
// Handle input in a weird looking but responsive way
m_EventBroker->Process<InputManager>();
m_EventBroker->Swap();
m_InputManager->Update(dt);
m_EventBroker->Swap();
m_InputProxy->Update(dt);
m_EventBroker->Swap();
m_InputProxy->Process();
m_EventBroker->Swap();
#define TEST1
//this draws the octTree and you can set the cube inside it and see what boxes in the tree that it belongs to
#ifdef TEST1
if (!m_UpdatedOnce) {
m_UpdatedOnce = true;
m_World->createTestEntitiesTest1();
}
//add/move the trigger box
auto pos = m_Renderer->Camera()->Forward() + m_Renderer->Camera()->Position();
AABB boxi;
boxi.CreateFromCenter(pos, maxPos - minPos);
frameCounter++;
if (frameCounter > 1) {
m_World->someOctTree.ClearDynamicObjects();
m_World->someOctTree.AddDynamicObject(boxi);
frameCounter = 0;
}
ComponentWrapper transform = m_World->GetComponent(m_World->anotherBoxTransformId, "Transform");
transform["Position"] = boxi.Origin();
//check all children again in the tree if they have a box in them or not, and colormark them if they do
//contentboxarna får man ut - inte childboxarna!
std::vector<int> boxIndex;
boxIndex = m_World->someOctTree.m_Root->childIndicesContainingBox(boxi);
for (auto& oneLinkedObject : m_World->linkOM)
{
ComponentWrapper model = m_World->GetComponent(oneLinkedObject.entId, "Model");
model["Color"] = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f);
if (oneLinkedObject.child->m_DynamicObjIndices.size() != 0) {
model["Color"] = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
}
//next check if the childIndicesContainingBox method returns the correct boxes
//REQUIRED: childIndicesContainingBox must be public to test this!
for each (auto someBoxIndex in boxIndex)
{
glm::vec3 pos = m_World->someOctTree.m_Root->m_Children[someBoxIndex]->m_Box.Origin();
if (abs(pos.x - oneLinkedObject.posxyz.x) < 0.005f &&
abs(pos.y - oneLinkedObject.posxyz.y) < 0.005f &&
abs(pos.z - oneLinkedObject.posxyz.z) < 0.005f) {
model["Color"] = glm::vec4(0.0f, 1.0f, 0.0f, 1.0f);
}
}
}
m_RenderQueueFactory->Update(m_World);
//wireframe
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
#endif
//this tests AABB vs AABB collision and AABB vs OctTree with AABB in it
#ifdef TEST2
//only add 1 for now...
//grey box
const glm::vec4 redCol = glm::vec4(1, 0.2f, 0, 1);
const glm::vec4 greenCol = glm::vec4(0.1f, 1.0f, 0.25f, 1);
const glm::vec3 boxSize = 0.1f*glm::vec3(1.0f, 1.0f, 1.0f);
AABB aabb;
aabb.CreateFromCenter(glm::vec3(0, 2.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f));
if (m_UpdatedOnce) {
//auto test = someOctTree.childIndicesContainingBox(aabb);
std::vector<AABB> test2;
someOctTree.BoxesInSameRegion(aabb, test2);
}
if (!m_UpdatedOnce) {
m_UpdatedOnce = true;
someOctTree.AddStaticObject(aabb);
//create the "small red box"
m_BoxID = m_World->CreateEntity();
ComponentWrapper transform = m_World->AttachComponent(m_BoxID, "Transform");
transform["Scale"] = boxSize;
ComponentWrapper model = m_World->AttachComponent(m_BoxID, "Model");
model["Resource"] = "Models/Core/UnitBox.obj";
m_World->createTestEntitiesTest2();
}
//red box
AABB redBox;
auto boxPos = m_Renderer->Camera()->Position() + 1.2f*m_Renderer->Camera()->Forward();
redBox.CreateFromCenter(boxPos, boxSize);
ComponentWrapper transform = m_World->GetComponent(m_BoxID, "Transform");
transform["Position"] = boxPos;
ComponentWrapper model = m_World->GetComponent(m_BoxID, "Model");
//this checks AABB vs an AABB in the octTree
if (someOctTree.BoxCollides(redBox, AABB())) {
//this checks AABB vs AABB
//if (Collision::AABBVsAABB(redBox, aabb)) {
//m_Renderer->Camera()->SetPosition(m_PrevPos);
//m_Renderer->Camera()->SetOrientation(m_PrevOri);
model["Color"] = greenCol;
}
else {
model["Color"] = redCol;
}
m_PrevPos = m_Renderer->Camera()->Position();
m_PrevOri = m_Renderer->Camera()->Orientation();
m_RenderQueueFactory->Update(m_World);
#endif
// Iterate through systems and update world!
m_SystemPipeline->Update(m_World, dt);
m_Renderer->Update(dt);
m_RenderQueueFactory->Update(m_World);
GLERROR("Game::Tick m_RenderQueueFactory->Update");
m_Renderer->Draw(m_RenderQueueFactory->RenderQueues());
GLERROR("Game::Tick m_Renderer->Draw");
m_EventBroker->Swap();
m_EventBroker->Clear();
glfwPollEvents();
}
-62
View File
@@ -1,62 +0,0 @@
#ifndef Game_h__
#define Game_h__
#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 "OctTreeTestHardCodedTestWorld.h"
#include "Collision/Collision.h"
class Game
{
public:
Game(int argc, char* argv[]);
~Game();
bool Running() const { return !glfwWindowShouldClose(m_Renderer->Window()); }
void Tick();
private:
double m_LastTime;
ConfigFile* m_Config = nullptr;
EventBroker* m_EventBroker;
IRenderer* m_Renderer;
InputManager* m_InputManager;
GUI::Frame* m_FrameStack;
HardcodedTestWorld* m_World;
RenderQueueFactory* m_RenderQueueFactory;
InputProxy* m_InputProxy;
SystemPipeline* m_SystemPipeline;
//Test1
int frameCounter = 0;
glm::vec3 minPos = glm::vec3(0.1f, 0.1f, 0.1f);
glm::vec3 maxPos = glm::vec3(0.2f, 0.2f, 0.2f);
//Test2
bool m_UpdatedOnce = false;
unsigned int m_BoxID;
glm::vec3 m_PrevPos;
glm::quat m_PrevOri;
glm::vec3 worldSize = glm::vec3(50, 50, 50);
Octree someOctTree;
};
#endif
-21
View File
@@ -1,21 +0,0 @@
//#define BOOST_TEST_MODULE collTest
#include <boost/test/unit_test.hpp>
#include <boost/test/execution_monitor.hpp>
using boost::unit_test_framework::test_suite;
using boost::unit_test_framework::test_case;
#include "Engine/Collision/Collision.h"
#include "Engine/Core/AABB.h"
#include "Engine/Core/Ray.h"
#include <stdlib.h>//srand
#include "Engine/Core/Octree.h"
//vs memleaks
//#define _CRTDBG_MAP_ALLOC
//#include <stdlib.h>
//#include <crtdbg.h>
//#define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
//#define new DEBUG_CLIENTBLOCK
BOOST_AUTO_TEST_SUITE(cTest)
BOOST_AUTO_TEST_SUITE_END()
-134
View File
@@ -1,134 +0,0 @@
#include <list>
#include <tuple>
#include <boost/any.hpp>
#include "GLM.h"
#include "Core/World.h"
#include "Core/Util/Any.h"
#include <vector>
//last!
//#include "OldOctTree.h"
#define private public
#include <Engine\Core\OctTree.h>
class HardcodedTestWorld : public World
{
public:
struct LinkOctTreeAndModel {
EntityID entId;
Octree::Child* child;
glm::vec3 posxyz;
LinkOctTreeAndModel(EntityID eId, Octree::Child* ch, glm::vec3 pos)
{
entId = eId;
child = ch;
posxyz = pos;
}
};
EntityID anotherBoxTransformId;
std::vector<LinkOctTreeAndModel> linkOM;
Octree someOctTree;
//constructor
HardcodedTestWorld()
: World()
, someOctTree(AABB(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f)), 2)
{
registerTestComponents();
//createTestEntities();
}
private:
void registerTestComponents()
{
ComponentWrapperFactory f;
f = ComponentWrapperFactory("Test");
f.AddProperty("TestInteger", 1337);
f.AddProperty("TestFloat", 13.37f);
f.AddProperty("TestString", std::string("Carlito"));
RegisterComponent(f);
f = ComponentWrapperFactory("Debug");
f.AddProperty("Name", std::string("Unnamed"));
RegisterComponent(f);
f = ComponentWrapperFactory("Transform");
f.AddProperty("Position", glm::vec3(0.f, 0.f, 0.f));
f.AddProperty("Orientation", glm::quat());
f.AddProperty("Scale", glm::vec3(1.f, 1.f, 1.f));
RegisterComponent(f);
f = ComponentWrapperFactory("Model");
f.AddProperty("Resource", std::string());
f.AddProperty("Color", glm::vec4(1.f, 1.f, 1.f, 1.f));
f.AddProperty("Visible", true);
RegisterComponent(f);
}
void createTestEntitiesTest1()
{
World& world = *this;
EntityID tempId;
//add octTree
{
//copy of mainbox
auto someAABB = AABB(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f));
//draw main box first
AddBoxModel(someAABB.Origin(), someAABB.HalfSize().x, someOctTree.m_Root, tempId);
//add anotherbox in octTree
auto anotherBox = AABB(glm::vec3(0.1f, 0.1f, 0.1f), glm::vec3(0.2f, 0.2f, 0.2f));
//note: have to delete the box in the tree first, since were trying to move the box
someOctTree.AddDynamicObject(anotherBox);
//draw anotherbox and save it in anotherBoxTransformId
AddBoxModel(anotherBox.Origin(), anotherBox.HalfSize().x, someOctTree.m_Root, anotherBoxTransformId);
//draw the octTree
for (size_t j = 0; j < 8; j++)
{
AddBoxModel(someOctTree.m_Root->m_Children[j]->m_Box.Origin(),
someOctTree.m_Root->m_Children[j]->m_Box.HalfSize().x, someOctTree.m_Root->m_Children[j], tempId);
auto someChild = someOctTree.m_Root->m_Children[j];
for (size_t i = 0; i < 8; i++)
{
AddBoxModel(someChild->m_Children[i]->m_Box.Origin(),
someChild->m_Children[i]->m_Box.HalfSize().x, someChild->m_Children[i], tempId);
}
}
}
}//end CreateEnt
void createTestEntitiesTest2()
{
World& world = *this;
EntityID entityCollisionBox = world.CreateEntity();
ComponentWrapper transform = world.AttachComponent(entityCollisionBox, "Transform");
transform["Position"] = glm::vec3(0.f, 2.f, 0.f);
ComponentWrapper model = world.AttachComponent(entityCollisionBox, "Model");
model["Resource"] = "Models/Core/UnitBox.obj";
}
void AddBoxModel(const glm::vec3 &center, const float &halfSize, Octree::Child* child, EntityID &outEntityId) {
World& world = *this;
EntityID entityDummyScene = world.CreateEntity();
outEntityId = entityDummyScene;
ComponentWrapper transform = world.AttachComponent(entityDummyScene, "Transform");
transform["Position"] = center;
transform["Scale"] = glm::vec3(1.0f, 1.0f, 1.0f)*halfSize*2.0f*0.97f;
ComponentWrapper model = world.AttachComponent(entityDummyScene, "Model");
model["Resource"] = "Models/Core/UnitBox.obj";
model["Color"] = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
if (child->m_DynamicObjIndices.size() != 0)
model["Color"] = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f);
linkOM.emplace_back(entityDummyScene, child, center);
}
};
+2 -2
View File
@@ -100,7 +100,7 @@ void OctTree::Update(float dt, World* world, Camera* cam)
{
AABB aabb;
for (ComponentWrapper& c : *world->GetComponents("Collision")) {
aabb.CreateFromCenter(c["BoxCenter"], c["BoxSize"]);
aabb.FromOriginSize(c["BoxCenter"], c["BoxSize"]);
AddStaticObject(aabb);
}
const glm::vec4 redCol = glm::vec4(1, 0.2f, 0, 1);
@@ -118,7 +118,7 @@ void OctTree::Update(float dt, World* world, Camera* cam)
AABB box;
auto boxPos = cam->Position() + 1.2f*cam->Forward();
box.CreateFromCenter(boxPos, boxSize);
box.FromOriginSize(boxPos, boxSize);
ComponentWrapper transform = world->GetComponent(m_BoxID, "Transform");
transform["Position"] = boxPos;
ComponentWrapper model = world->GetComponent(m_BoxID, "Model");
+4 -6
View File
@@ -7,7 +7,7 @@
#include "Core/ResourceManager.h"
#include "Core/ConfigFile.h"
#include "Rendering/Renderer.h"
#include "Engine\Rendering\Texture.h"
#include "Engine/Rendering/Texture.h"
BOOST_AUTO_TEST_SUITE(resourceManagerTests)
@@ -19,16 +19,14 @@ BOOST_AUTO_TEST_CASE(resourceManagerTest)
ResourceManager::RegisterType<ConfigFile>("ConfigFile");
BOOST_CHECK(!ResourceManager::IsResourceLoaded("ConfigFile", "Config.ini"));
auto m_Config = ResourceManager::Load<ConfigFile>("Config.ini");
BOOST_CHECK_NO_THROW(ResourceManager::Load<ConfigFile>("Config.ini"));
BOOST_CHECK(ResourceManager::IsResourceLoaded("ConfigFile", "Config.ini"));
ResourceManager::Release("ConfigFile", "Config.ini");
BOOST_CHECK(!ResourceManager::IsResourceLoaded("ConfigFile", "Config.ini"));
//configfile without register
//check so output says "EE failed to load: type not registered..."
auto m_ScreenQuadNoRegister = ResourceManager::Load<Model>("Models/Core/ScreenQuad.obj");
BOOST_CHECK(!ResourceManager::IsResourceLoaded("Model", "Models/Core/ScreenQuad.obj"));
BOOST_CHECK_THROW(ResourceManager::Load<Model>("Models/Core/ScreenQuad.obj"),Resource::FailedLoadingException);
//there is no error feedback to check if you try to release the wrong resources - hence that cant be tested either
}