Merge remote-tracking branch 'origin/master' into Sound

Conflicts:
	include/Core/Engine.h
This commit is contained in:
Stiffly
2015-09-17 13:18:56 +02:00
44 changed files with 18806 additions and 228 deletions
+1 -1
View File
@@ -78,7 +78,7 @@ set(SOURCE_FILES
${SOURCE_FILES_Rendering}
${SOURCE_FILES_Transform}
${SOURCE_FILES_Physics}
${SOURCE_FILES_Game} ../../include/Game/CLife.h ../../include/Game/ELifeLost.h)
${SOURCE_FILES_Game})
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
+11 -11
View File
@@ -77,20 +77,20 @@ void dd::Camera::SetOrientation(glm::quat val)
void dd::Camera::UpdateProjectionMatrix()
{
m_ProjectionMatrix = glm::ortho(
-16.f,
16.f,
-9.f,
9.f,
m_NearClip,
m_FarClip
);
// m_ProjectionMatrix = glm::perspective(
// m_FOV,
// m_AspectRatio,
// m_ProjectionMatrix = glm::ortho(
// -16.f,
// 16.f,
// -9.f,
// 9.f,
// m_NearClip,
// m_FarClip
// );
m_ProjectionMatrix = glm::perspective(
m_FOV,
m_AspectRatio,
m_NearClip,
m_FarClip
);
}
void dd::Camera::UpdateViewMatrix()
+1
View File
@@ -40,6 +40,7 @@ void dd::EventBroker::Unsubscribe(BaseEventRelay &relay) // ?
{
if (it->second == &relay)
{
relay.m_Broker = nullptr;
eventRelays.erase(it);
break;
}
+16 -5
View File
@@ -113,6 +113,8 @@ void dd::Renderer::CreateBuffers()
m_ScreenQuad = CreateQuad();
m_UnitQuad = ResourceManager::Load<Model>("Models/Core/UnitQuad.obj");
m_UnitSphere = ResourceManager::Load<Model>("Models/Core/UnitSphere.obj");
m_StandardNormal = ResourceManager::Load<Texture>("Textures/Core/NeutralNormalMap.png");
m_StandardSpecular = ResourceManager::Load<Texture>("Textures/Core/NeutralSpecularMap.png");
glGenRenderbuffers(1, &m_rbDepthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, m_rbDepthBuffer);
@@ -208,7 +210,7 @@ void dd::Renderer::CreateBuffers()
void dd::Renderer::Draw(RenderQueueCollection& rq)
{
//DrawDeferred(rq.Deferred, rq.Lights);
DrawDeferred(rq.Deferred, rq.Lights);
rq.Forward.Jobs.sort(dd::Renderer::DepthSort);
DrawForward(rq.Forward, rq.Lights);
@@ -289,8 +291,8 @@ void dd::Renderer::DrawForward(RenderQueue &objects, RenderQueue &lights)
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred3);
glClearColor(1, 0.9, 0.8f, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// glClearColor(1, 0.9, 0.8f, 1);
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
m_spForward->Bind();
DrawScene(objects, *m_spForward);
@@ -321,14 +323,23 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture);
if (modelJob->NormalTexture != 0) {
if (modelJob->NormalTexture != 0 && false) {
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, modelJob->NormalTexture);
} else {
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, *m_StandardNormal);
}
if (modelJob->SpecularTexture != 0) {
if (modelJob->SpecularTexture != 0 && false) {
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, modelJob->SpecularTexture);
}
else {
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, *m_StandardSpecular);
}
glBindVertexArray(modelJob->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->ElementBuffer);
@@ -39,6 +39,7 @@ void main()
//frag_Diffuse = DiffuseTexel * (vec4(La, 0.0) * (vec4(LightingTexel.rgb, 0.0) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0)));
//frag_Diffuse = DiffuseTexel * (vec4(La, 0.0) + LightingTexel);
//frag_Diffuse = DiffuseTexel * (vec4(1.f, 1.f, 1.f, 0.0) + LightingTexel);
frag_Diffuse = DiffuseTexel;
frag_Diffuse = DiffuseTexel + LightingTexel;
//frag_Diffuse = DiffuseTexel;
//frag_Diffuse = vec4(LightingTexel.r, LightingTexel.g, LightingTexel.b, 1.0);
}
+1 -1
View File
@@ -163,7 +163,7 @@ void dd::World::Initialize()
}
}
void dd::World::CommitEntity(EntityID entity)
int dd::World::CommitEntity(EntityID entity)
{
for (auto pair : m_Systems)
{
Regular → Executable
+58 -44
View File
@@ -11,9 +11,9 @@ void dd::Systems::LevelSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EContact, LevelSystem::OnContact);
EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, LevelSystem::LifeLost);
EVENT_SUBSCRIBE_MEMBER(m_EScoreEvent, LevelSystem::ScoreEvent);
for (int i = 0; i < lives; i++)
{
for (int i = 0; i < Lives(); i++) {
CreateLife(i);
}
@@ -24,14 +24,17 @@ void dd::Systems::LevelSystem::CreateLife(int number)
{
auto life = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(life);
transform->Position = glm::vec3(-11.f + number, -8.f, -10.f);
transform->Scale = glm::vec3(0.5f, 0.5f, 0.5f);
transform->Position = glm::vec3(-4.f + number * 0.5f, -2.f, -5.f);
transform->Scale = glm::vec3(0.25f, 0.25f, 0.25f);
std::shared_ptr<Components::Life> lifeNr = m_World->AddComponent<Components::Life>(life);
lifeNr->number = number;
lifeNr->Number = number;
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(life);
sprite->SpriteFile = "Textures/Ball.png";
auto model = m_World->AddComponent<Components::Model>(life);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
/*std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(life);
sprite->SpriteFile = "Textures/Ball.png";*/
m_World->CommitEntity(life);
}
@@ -39,44 +42,35 @@ void dd::Systems::LevelSystem::CreateLife(int number)
void dd::Systems::LevelSystem::Update(double dt)
{
if (!m_Initialized) {
CreateBasicLevel(tRows, tLines, tSpaceBetweenBricks, tSpaceToEdge);
CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge());
m_Initialized = true;
}
if (entityToRemove != NULL)
{
//m_World->RemoveEntity(entityToRemove);
entityToRemove = NULL;
}
}
void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto ball = m_World->GetComponent<Components::Ball>(entity);
if (ball != NULL)
{
if (ball != NULL) {
auto transformBall = m_World->GetComponent<Components::Transform>(entity);
if (transformBall->Position.y < -10)
{
if (lives == pastLives)
{
if (transformBall->Position.y < -10) {
if (Lives() == PastLives()) {
Events::LifeLost e;
e.entity = entity;
e.Entity = entity;
EventBroker->Publish(e);
Events::ResetBall be;
EventBroker->Publish(be);
return;
}
}
}
if (lives != pastLives)
{
if (Lives() != PastLives()) {
auto life = m_World->GetComponent<Components::Life>(entity);
if (life != NULL)
{
if (life->number + 1 == pastLives) {
if (life != NULL) {
if (life->Number + 1 == PastLives()) {
m_World->RemoveEntity(entity);
pastLives = lives;
SetPastLives(Lives());
}
}
}
@@ -85,12 +79,10 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID
void dd::Systems::LevelSystem::CreateBasicLevel(int rows, int lines, glm::vec2 spacesBetweenBricks, int spaceToEdge)
{
int num = 0;
numberOfBricks = rows * lines;
for (int i = 0; i < rows; i++)
{
SetNumberOfBricks(rows * lines);
for (int i = 0; i < rows; i++) {
num++;
for (int j = 0; j < lines; j++)
{
for (int j = 0; j < Lines(); j++) {
CreateBrick(i, j, spacesBetweenBricks, spaceToEdge, num);
}
if (num == 7)
@@ -104,18 +96,21 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe
{
auto brick = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(brick);
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(brick);
//std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(brick);
auto model = m_World->AddComponent<Components::Model>(brick);
std::shared_ptr<Components::Brick> cBrick = m_World->AddComponent<Components::Brick>(brick);
std::shared_ptr<Components::RectangleShape> cRec = m_World->AddComponent<Components::RectangleShape>(brick);
std::shared_ptr<Components::Physics> cPhys = m_World->AddComponent<Components::Physics>(brick);
std::string fileName = "Textures/Bricks/";
fileName.append(std::to_string(num));
fileName.append(".png");
sprite->SpriteFile = fileName;
//sprite->SpriteFile = fileName;
model->ModelFile = "Models/Test/Brick/Brick.obj";
float x = spaceToEdge + line * spacesBetweenBricks.x;
float y = spaceToEdge + row * spacesBetweenBricks.y;
transform->Scale = glm::vec3(1.6, 0.4, 0.);
transform->Scale = glm::vec3(1.6, 0.35, 0.5);
transform->Position = glm::vec3(x - 7, y + 1, -10.f);
cBrick->Score = 10 * num;
m_World->CommitEntity(brick);
return;
}
@@ -128,15 +123,13 @@ void dd::Systems::LevelSystem::ProcessCollision()
void dd::Systems::LevelSystem::OnEntityRemoved(EntityID entity)
{
auto brick = m_World->GetComponent<Components::Brick>(entity);
if (brick != NULL)
{
/*auto brick = m_World->GetComponent<Components::Brick>(entity);
if (brick != NULL) {
numberOfBricks--;
if (numberOfBricks < 1)
{
if (numberOfBricks < 1) {
EndLevel();
}
}
}*/
return;
}
@@ -144,20 +137,41 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
{
EntityID entityBrick = event.Entity1;
auto brick = m_World->GetComponent<Components::Brick>(entityBrick);
if (brick == NULL)
{
if (brick == NULL) {
return false;
}
EntityID entityBall = event.Entity2;
m_World->RemoveEntity(entityBrick);
SetNumberOfBricks(NumberOfBricks() - 1);
if (NumberOfBricks() == 0) {
Events::ScoreEvent es;
es.Score = 500;
EventBroker->Publish(es);
Events::ResetBall e;
EventBroker->Publish(e);
CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge());
}
Events::ScoreEvent es;
es.Score = brick->Score;
EventBroker->Publish(es);
std::cout << "Score: " << Score() << std::endl;
return true;
}
bool dd::Systems::LevelSystem::LifeLost(const dd::Events::LifeLost &event)
{
lives--;
SetLives(Lives() - 1);
return true;
}
bool dd::Systems::LevelSystem::ScoreEvent(const dd::Events::ScoreEvent &event)
{
SetScore(Score() += event.Score);
return true;
}
Regular → Executable
+65 -71
View File
@@ -7,6 +7,7 @@
#include "Core/World.h"
#include <iostream>
#include <Game/CPad.h>
#include <Rendering/CPointLight.h>
void dd::Systems::PadSystem::Initialize()
@@ -24,7 +25,7 @@ void dd::Systems::PadSystem::Initialize()
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, PadSystem::OnKeyDown);
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, PadSystem::OnKeyUp);
EVENT_SUBSCRIBE_MEMBER(m_EContact, PadSystem::OnContact);
EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, PadSystem::LifeLost);
EVENT_SUBSCRIBE_MEMBER(m_EResetBall, PadSystem::ResetBall);
return;
}
@@ -33,22 +34,34 @@ void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID p
{
auto ball = m_World->GetComponent<Components::Ball>(entity);
if (ball != NULL) {
if (replaceBall == true) {
replaceBall = false;
if (ReplaceBall() == true) {
SetReplaceBall(false);
auto transformEntity = m_World->GetComponent<Components::Transform>(entity);
transformEntity->Position = glm::vec3(20, 20, -10);
//Temporary. Create new ball.
auto ent = m_World->CreateEntity();
/*auto ent = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
transform->Position = glm::vec3(0.5f, 0.f, -10.f);;
transform->Position = glm::vec3(0.5f, 0.f, -10.f);
transform->Scale = glm::vec3(1.f, 1.f, 1.f);
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(ent);
sprite->SpriteFile = "Textures/Ball.png";
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
std::shared_ptr<Components::Ball> cball = m_World->AddComponent<Components::Ball>(ent);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
physics->Static = false;*/
auto ent = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
transform->Position = glm::vec3(0.5f, 0.f, -10.f);
transform->Scale = glm::vec3(1.f, 1.f, 1.f);
auto model = m_World->AddComponent<Components::Model>(ent);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
//auto pointlight = m_World->AddComponent<Components::PointLight>(ent);
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
std::shared_ptr<Components::Ball> cball = m_World->AddComponent<Components::Ball>(ent);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
physics->Static = false;
m_World->RemoveEntity(entity);
@@ -65,70 +78,65 @@ void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID p
void dd::Systems::PadSystem::Update(double dt)
{
if (ent == 0) {
if (Entity() == 0) {
for (auto it = m_World->GetEntities()->begin(); it != m_World->GetEntities()->end(); it++) {
if (m_World->GetProperty<std::string>(it->first, "Name") == "Pad") {
ent = it->first;
transform = m_World->GetComponent<Components::Transform>(ent);
SetEntity(it->first);
SetTransform(m_World->GetComponent<Components::Transform>(Entity()));
SetPad(m_World->GetComponent<Components::Pad>(Entity()));
break;
}
}
}
if (transform->Velocity.x < -maxSpeed)
{
transform->Velocity.x = -maxSpeed;
auto transform = Transform();
auto pad = Pad();
auto acceleration = Acceleration();
if (transform->Velocity.x < -pad->MaxSpeed) {
transform->Velocity.x = -pad->MaxSpeed;
}
else if (transform->Velocity.x > maxSpeed)
{
transform->Velocity.x = maxSpeed;
else if (transform->Velocity.x > pad->MaxSpeed) {
transform->Velocity.x = pad->MaxSpeed;
}
transform->Position += transform->Velocity * (float)dt;
transform->Velocity += acceleration * (float)dt;
transform->Velocity -= transform->Velocity * slowdownModifier * (float)dt;
transform->Velocity -= transform->Velocity * pad->SlowdownModifier * (float)dt;
if (left)
{
acceleration.x = -accelerationSpeed;
if (Left()) {
acceleration.x = -pad->AccelerationSpeed;
}
else if (right)
{
acceleration.x = accelerationSpeed;
else if (Right()) {
acceleration.x = pad->AccelerationSpeed;
}
else
{
else {
acceleration.x = 0.f;
}
SetTransform(transform);
SetPad(pad);
SetAcceleration(acceleration);
return;
}
bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event)
{
int val = event.KeyCode;
if (val == 265)
{
if (val == GLFW_KEY_UP) {
//std::cout << "Up!" << std::endl;
}
else if (val == 264)
{
} else if (val == GLFW_KEY_DOWN) {
//std::cout << "Down!" << std::endl;
}
else if (val == 263)
{
} else if (val == GLFW_KEY_LEFT) {
//std::cout << "Left!" << std::endl;
//acceleration.x = -0.01f;
left = true;
}
else if (val == 262)
{
SetLeft(true);
} else if (val == GLFW_KEY_RIGHT) {
//std::cout << "Right!" << std::endl;
//acceleration.x = 0.01f;
right = true;
}
else if (val == 82)
{
replaceBall = true;
SetRight(true);
} else if (val == GLFW_KEY_R) {
SetReplaceBall(true);
}
return true;
}
@@ -136,21 +144,14 @@ bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event)
bool dd::Systems::PadSystem::OnKeyUp(const dd::Events::KeyUp &event)
{
int val = event.KeyCode;
if (val == 265)
{
if (val == GLFW_KEY_UP) {
}
else if (val == 264)
{
} else if (val == GLFW_KEY_DOWN) {
}
else if (val == 263)
{
left = false;
}
else if (val == 262)
{
right = false;
} else if (val == GLFW_KEY_LEFT) {
SetLeft(false);
} else if (val == GLFW_KEY_RIGHT) {
SetRight(false);
}
return true;
}
@@ -159,14 +160,12 @@ bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event)
{
EntityID entityBall = event.Entity2;
auto ball = m_World->GetComponent<Components::Ball>(entityBall);
if (ball == NULL)
{
if (ball == NULL) {
return false;
}
EntityID entityPad = event.Entity1;
auto pad = m_World->GetComponent<Components::Pad>(entityPad);
if (pad == NULL)
{
if (pad == NULL) {
return false;
}
auto transformBall = m_World->GetComponent<Components::Transform>(entityBall);
@@ -176,13 +175,10 @@ bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event)
float whatX = transformBall->Position.x - transformPad->Position.x;
float movementX;
if (whatX > 0)
{
if (whatX > 0) {
movementX = movementMultiplier * whatX;
//std::cout << "Right!" << std::endl;
}
else
{
} else {
movementX = movementMultiplier * whatX;
//std::cout << "Left!" << std::endl;
}
@@ -199,8 +195,9 @@ bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event)
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
transform->Position = glm::vec3(transformBall->Position.x, transformBall->Position.y + 0.01f, -10.f);
transform->Scale = glm::vec3(1.f, 1.f, 1.f);
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(ent);
sprite->SpriteFile = "Textures/Ball.png";
auto model = m_World->AddComponent<Components::Model>(ent);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
//auto pointlight = m_World->AddComponent<Components::PointLight>(ent);
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
std::shared_ptr<Components::Ball> cball = m_World->AddComponent<Components::Ball>(ent);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
@@ -216,9 +213,9 @@ bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event)
EventBroker->Publish(e);
}
bool dd::Systems::PadSystem::LifeLost(const dd::Events::LifeLost &event)
bool dd::Systems::PadSystem::ResetBall(const dd::Events::ResetBall &event)
{
replaceBall = true;
SetReplaceBall(true);
return true;
}
@@ -228,12 +225,9 @@ bool dd::Systems::PadSystem::PadSteeringInputController::OnCommand(const Events:
std::cout << "Command!" << std::endl;
if (command == "right")
{
if (command == "right") {
std::cout << "Right!" << std::endl;
}
else if (command == "left")
{
} else if (command == "left") {
std::cout << "Left!" << std::endl;
}
+10
View File
@@ -52,6 +52,11 @@ void dd::Systems::PhysicsSystem::Update(double dt)
if (! transformComponent)
continue;
if (body == nullptr) {
//LOG_ERROR("This body should not exist");
continue;
}
if (m_World->GetEntityParent(entity) == 0) {
b2Vec2 position;
@@ -86,6 +91,11 @@ void dd::Systems::PhysicsSystem::Update(double dt)
EntityID entity = i.first;
b2Body* body = i.second;
if (body == nullptr) {
//LOG_ERROR("This body should not exist");
continue;
}
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if (! transformComponent)
continue;
+2
View File
@@ -10,7 +10,9 @@ include_directories(
set(SOURCE_FILES
main.cpp
FileWatcherTest.cpp
EventTest.cpp
ComponentCopyTest.cpp
EntityCloneTest.cpp
)
if(CMAKE_COMPILER_IS_GNUCXX)
+46
View File
@@ -0,0 +1,46 @@
#include <boost/test/unit_test.hpp>
#include "Core/EventBroker.h"
#include "Core/World.h"
#include "Core/CTemplate.h"
using namespace dd;
struct TestComponent : public Component
{
int Int = 5;
float Float = 1.33333f;
double Double = 1.33333;
std::string String = "Hello World";
};
BOOST_AUTO_TEST_CASE(EntityCloneTest)
{
// Setup world
std::shared_ptr<EventBroker> eventBroker = std::make_shared<EventBroker>();
World world(eventBroker);
world.ComponentFactory.Register<Components::Template>();
world.ComponentFactory.Register<TestComponent>();
// Create our original entity
EntityID entOriginal = world.CreateEntity();
world.AddComponent<Components::Template>(entOriginal);
world.AddComponent<TestComponent>(entOriginal);
// Clone it
EntityID entClone = world.CloneEntity(entOriginal);
// Check
// EntityID of clone should not be same as original (obviously)
BOOST_CHECK(entOriginal != entClone);
// Template component SHOULD be in clone
auto templateComponentClone = world.GetComponent<Components::Template>(entClone);
BOOST_REQUIRE(templateComponentClone != nullptr);
// Values should be the same across the clone
auto testComponentOriginal = world.GetComponent<TestComponent>(entOriginal);
BOOST_REQUIRE(testComponentOriginal != nullptr);
auto testComponentClone = world.GetComponent<TestComponent>(entClone);
BOOST_REQUIRE(testComponentClone != nullptr);
BOOST_CHECK(testComponentClone->Int == testComponentOriginal->Int);
BOOST_CHECK(testComponentClone->Float == testComponentOriginal->Float);
BOOST_CHECK(testComponentClone->Double == testComponentOriginal->Double);
BOOST_CHECK(testComponentClone->String == testComponentOriginal->String);
}
+54
View File
@@ -0,0 +1,54 @@
#ifndef EVENTFIXTURE_H
#define EVENTFIXTURE_H
#include <boost/test/unit_test.hpp>
#include "Core/EventBroker.h"
template <typename EventType>
struct EventFixture
{
EventFixture()
{
this->EventBroker = new dd::EventBroker();
m_EEventType = decltype(m_EEventType)(std::bind(&OnEvent, this, std::placeholders::_1));
this->EventBroker->Subscribe(m_EEventType);
Run();
Check();
}
~EventFixture()
{
this->EventBroker->Unsubscribe(m_EEventType);
delete this->EventBroker;
}
dd::EventBroker* EventBroker = nullptr;
dd::EventRelay<EventFixture, EventType> m_EEventType;
bool m_EventRecieved = false;
EventType Before;
EventType After;
bool OnEvent(const EventType& event)
{
m_EventRecieved = true;
After = event;
return true;
}
void Run()
{
// Publish the event
this->EventBroker->Publish(Before);
// Clear to swap buffers
this->EventBroker->Clear();
// Process the event
this->EventBroker->template Process<EventFixture>();
}
void Check()
{
BOOST_CHECK(m_EventRecieved);
}
};
#endif
+21
View File
@@ -0,0 +1,21 @@
#include <boost/test/unit_test.hpp>
#include "EventFixture.h"
using namespace dd;
struct ETestEvent : public Event
{
int Int = 5;
float Float = 1.33333f;
double Double = 1.33333;
std::string String = "Hello World";
};
BOOST_AUTO_TEST_CASE(EventBrokerTest)
{
EventFixture<ETestEvent> f;
BOOST_CHECK(f.Before.Int == f.After.Int);
BOOST_CHECK_CLOSE(f.Before.Float, f.After.Float, 0.00001f);
BOOST_CHECK_CLOSE(f.Before.Double, f.After.Double, 0.00001f);
BOOST_CHECK(f.Before.String == f.After.String);
}