Merge remote-tracking branch 'origin/master' into Importer
# Conflicts: # resources/Schema/Entities/RenderingWorld.xml # resources/Shaders/ForwardPlus.frag.glsl # src/Engine/Editor/EditorSystem.cpp # src/Engine/Network/Server.cpp # src/Engine/Rendering/DrawFinalPass.cpp # src/Tests/OctTreeTestGameClass.cpp # src/Tests/OctTreeTestHardCodedTestWorld.h # src/Tests/ResourceManagerTest.cpp
This commit is contained in:
@@ -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_World,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(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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -207,9 +207,9 @@ BOOST_AUTO_TEST_CASE(octTest)
|
||||
{
|
||||
glm::vec3 mini = glm::vec3(-1, -1, -1);
|
||||
glm::vec3 maxi = glm::vec3(1, 1, 1);
|
||||
Octree tree(AABB(mini, maxi), 2);
|
||||
Octree<AABB> tree(AABB(mini, maxi), 2);
|
||||
tree.AddDynamicObject(AABB(mini, -0.9f*maxi));
|
||||
Octree::Output data;
|
||||
OctSpace::Output data;
|
||||
glm::vec3 origin = 3.0f * mini;
|
||||
bool rayIntersected = tree.RayCollides(Ray(origin , mini - origin), data);
|
||||
BOOST_CHECK(rayIntersected);
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 = new SystemPipeline(m_World,m_EventBroker);
|
||||
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();
|
||||
@@ -102,13 +103,13 @@ void GameHealthSystemTest::Tick()
|
||||
m_LastTime = currentTime;
|
||||
|
||||
// Iterate through systems and update world!
|
||||
m_SystemPipeline->Update(m_World, dt);
|
||||
m_SystemPipeline->Update(dt);
|
||||
|
||||
m_EventBroker->Swap();
|
||||
m_EventBroker->Clear();
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
@@ -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,6 +1,6 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include "Engine\Core\InputManager.h"
|
||||
#include "Engine/Core/InputManager.h"
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(inputManagerTests)
|
||||
|
||||
|
||||
+23
-14
@@ -13,12 +13,12 @@ BOOST_AUTO_TEST_CASE(octSameRegionTest)
|
||||
{
|
||||
glm::vec3 mini = glm::vec3(-1, -1, -1);
|
||||
glm::vec3 maxi = glm::vec3(1, 1, 1);
|
||||
Octree tree(AABB(mini, maxi), 2);
|
||||
Octree<AABB> tree(AABB(mini, maxi), 2);
|
||||
AABB firstQuadrant(mini, 0.8f*mini);
|
||||
tree.AddStaticObject(firstQuadrant);
|
||||
AABB testBox(0.9f*mini, 0.8f*mini);
|
||||
std::vector<AABB> region;
|
||||
tree.BoxesInSameRegion(testBox, region);
|
||||
tree.ObjectsInSameRegion(testBox, region);
|
||||
BOOST_REQUIRE(region.size() == 1);
|
||||
AABB& box = region[0];
|
||||
BOOST_CHECK_CLOSE_FRACTION(box.Origin().x, firstQuadrant.Origin().x, 0.00001f);
|
||||
@@ -40,19 +40,28 @@ const int NUM_FUNCTION_LOOPS = 25;
|
||||
const int TESTS = 0; //10
|
||||
|
||||
template<typename Tree>
|
||||
void RegionTest(Tree& tree)
|
||||
void RegionTestOld(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);
|
||||
}
|
||||
|
||||
template<typename Tree>
|
||||
void RegionTest(Tree& tree)
|
||||
{
|
||||
AABB aabb = 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.ObjectsInSameRegion(aabb, outVec);
|
||||
}
|
||||
|
||||
template<typename Tree, typename Output>
|
||||
void RayTest(Tree& tree)
|
||||
{
|
||||
Tree::Output data;
|
||||
Output data;
|
||||
glm::vec3 rayStart = glm::vec3(rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS);
|
||||
glm::vec3 rayEnd = glm::vec3(rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS, rand() % LEVEL_BOUNDS);
|
||||
tree.RayCollides({ rayStart , glm::normalize(rayEnd - rayStart) }, data);
|
||||
@@ -63,7 +72,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 +97,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);
|
||||
}
|
||||
|
||||
@@ -111,13 +120,13 @@ void TestLoop(TestFunction xTest)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(octRegionPerfTestWithDuplicates)
|
||||
{
|
||||
TestLoop<Old::OctTree>(RegionTest<Old::OctTree>);
|
||||
TestLoop<Old::OctTree>(RegionTestOld<Old::OctTree>);
|
||||
BOOST_CHECK(true);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(octRegionPerfTestNoDuplicates)
|
||||
{
|
||||
TestLoop<Octree>(RegionTest<Octree>);
|
||||
TestLoop<Octree<AABB>>(RegionTest<Octree<AABB>>);
|
||||
BOOST_CHECK(true);
|
||||
}
|
||||
|
||||
@@ -129,19 +138,19 @@ BOOST_AUTO_TEST_CASE(octBoxPerfTestWithDuplicates)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(octBoxPerfTestNoDuplicates)
|
||||
{
|
||||
TestLoop<Octree>(BoxTest<Octree>);
|
||||
TestLoop<Octree<AABB>>(BoxTest<Octree<AABB>>);
|
||||
BOOST_CHECK(true);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(octRayPerfTestWithDuplicates)
|
||||
{
|
||||
TestLoop<Old::OctTree>(RayTest<Old::OctTree>);
|
||||
TestLoop<Old::OctTree>(RayTest<Old::OctTree, Old::OctTree::Output>);
|
||||
BOOST_CHECK(true);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(octRayPerfTestNoDuplicates)
|
||||
{
|
||||
TestLoop<Octree>(RayTest<Octree>);
|
||||
TestLoop<Octree<AABB>>(RayTest<Octree<AABB>, OctSpace::Output>);
|
||||
BOOST_CHECK(true);
|
||||
}
|
||||
|
||||
@@ -153,7 +162,7 @@ BOOST_AUTO_TEST_CASE(octNopPerfTestWithDuplicates)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(octNopPerfTestNoDuplicates)
|
||||
{
|
||||
TestLoop<Octree>(NopTest<Octree>);
|
||||
TestLoop<Octree<AABB>>(NopTest<Octree<AABB>>);
|
||||
BOOST_CHECK(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
@@ -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.mesh"; // 360NoScope UnitBox
|
||||
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();
|
||||
}
|
||||
@@ -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
|
||||
@@ -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()
|
||||
|
||||
@@ -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.mesh"; // 360NoScope UnitBox
|
||||
}
|
||||
|
||||
void AddBoxModel(const glm::vec3 ¢er, 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.mesh"; // 360NoScope unitBox
|
||||
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);
|
||||
}
|
||||
};
|
||||
@@ -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");
|
||||
|
||||
@@ -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.mesh"); // 360NoScope ScreenQuad
|
||||
BOOST_CHECK(!ResourceManager::IsResourceLoaded("Model", "Models/Core/ScreenQuad.mesh"));
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user