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

Conflicts:
	include/Core/Engine.h
	src/game/Game/PadSystem.cpp
	src/game/Physics/PhysicsSystem.cpp
This commit is contained in:
viktorljung
2015-09-17 17:11:37 +02:00
48 changed files with 19163 additions and 223 deletions
+45 -41
View File
@@ -72,9 +72,6 @@ public:
m_World->SystemFactory.Register<Systems::TransformSystem>(
[this]() { return new Systems::TransformSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::TransformSystem>();
// m_World->ComponentFactory.Register<Components::Model>();
// m_World->ComponentFactory.Register<Components::Template>();
m_World->ComponentFactory.Register<Components::Sprite>();
@@ -83,6 +80,7 @@ public:
m_World->ComponentFactory.Register<Components::Ball>();
m_World->ComponentFactory.Register<Components::Brick>();
m_World->ComponentFactory.Register<Components::Pad>();
m_World->ComponentFactory.Register<Components::Life>();
m_World->SystemFactory.Register<Systems::PhysicsSystem>(
[this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::PhysicsSystem>();
@@ -101,18 +99,10 @@ public:
//TODO: Remove tobias light-test code.
{
auto t_BrickWall = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_BrickWall);
transform->Position = glm::vec3(0.f, 0.f, -10.f);
auto sprite = m_World->AddComponent<Components::Sprite>(t_BrickWall);
//TODO: Rename SpriteFile to DiffuseTexture or similar.
sprite->SpriteFile = "Textures/Test/Brick_Diffuse.png";
sprite->NormalTexture = "Textures/Test/Brick_Normal.png";
sprite->SpecularTexture = "Textures/Test/Brick_Specular.png";
}
/*{
}*/
//OctoBall
{
auto ent = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
@@ -120,8 +110,8 @@ public:
transform->Scale = glm::vec3(1.f, 1.f, 1.f);
transform->Velocity = glm::vec3(-1.0f, -5.f, 0.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";
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
std::shared_ptr<Components::Ball> ball = m_World->AddComponent<Components::Ball>(ent);
@@ -137,10 +127,40 @@ public:
}
//PointLightTest
{
auto t_Light = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_Light);
transform->Position = glm::vec3(2.f, 1.5f, -9.f);
auto pl = m_World->AddComponent<Components::PointLight>(t_Light);
pl->Radius = 8.f;
}
//Halfpipe background test model.
{
auto t_halfPipe = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_halfPipe);
transform->Position = glm::vec3(0.f, 0.f, -15.f);
transform->Scale = glm::vec3(15.f);
auto model = m_World->AddComponent<Components::Model>(t_halfPipe);
model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj";
}
//Brick test model
{
auto t_Brick = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_Brick);
transform->Position = glm::vec3(0.f, 0.f, -12.f);
transform->Orientation = glm::rotate(glm::quat(), 0.5f, glm::vec3(0,-1,-1));
auto model = m_World->AddComponent<Components::Model>(t_Brick);
model->ModelFile = "Models/Test/Brick/Brick.obj";
}
{
auto topWall = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(topWall);
transform->Position = glm::vec3(0.f, 5.f, -10.f);
transform->Position = glm::vec3(0.f, 6.f, -10.f);
transform->Scale = glm::vec3(20.f, 0.5f, 1.f);
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
@@ -186,25 +206,6 @@ public:
m_World->CommitEntity(rightWall);
}
/*{
auto ent = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
transform->Position = glm::vec3(0.f, -3.f, -10.f);
transform->Scale = glm::vec3(8.f, 0.5f, 1.f);
transform->Orientation = glm::rotate(transform->Orientation, glm::radians(25.f), glm::vec3(0, 0, -1));
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(ent);
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(ent);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
physics->Static = true;
m_World->CommitEntity(ent);
}*/
{
auto ent = m_World->CreateEntity();
m_World->SetProperty(ent, "Name", "Pad");
@@ -304,7 +305,7 @@ public:
glm::mat4 modelMatrix = glm::translate(glm::mat4(), absoluteTransform.Position)
* glm::toMat4(absoluteTransform.Orientation)
* glm::scale(absoluteTransform.Scale);
EnqueueModel(modelAsset, modelMatrix, modelComponent->Transparent, modelComponent->Color);
EnqueueModel(modelAsset, modelMatrix, modelComponent->Transparent, modelComponent->Color, modelComponent->ModelFile);
}
}
@@ -344,7 +345,7 @@ public:
glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position)
* glm::toMat4(orientation2D)
* glm::scale(absoluteTransform.Scale);
EnqueueSprite(texturediff, texturenorm, texturespec, modelMatrix, spriteComponent->Color);
EnqueueSprite(texturediff, texturenorm, texturespec, modelMatrix, spriteComponent->Color, absoluteTransform.Position.z);
}
}
@@ -352,7 +353,7 @@ public:
}
//TODO: Get this out of engine.h
void EnqueueModel(Model* model, glm::mat4 modelMatrix, float transparent, glm::vec4 color)
void EnqueueModel(Model* model, glm::mat4 modelMatrix, float transparent, glm::vec4 color, std::string fileName)
{
for (auto texGroup : model->TextureGroups)
{
@@ -367,13 +368,14 @@ public:
job.EndIndex = texGroup.EndIndex;
job.ModelMatrix = modelMatrix;
job.Color = color;
job.fileName = fileName;
m_RendererQueue.Deferred.Add(job);
}
}
// TODO: Get this out of engine.h
void EnqueueSprite(Texture* texture, Texture* normalTexture, Texture* specularTexture, glm::mat4 modelMatrix, glm::vec4 color)
void EnqueueSprite(Texture* texture, Texture* normalTexture, Texture* specularTexture, glm::mat4 modelMatrix, glm::vec4 color, float depth)
{
SpriteJob job;
job.TextureID = texture->ResourceID;
@@ -382,8 +384,10 @@ public:
job.SpecularTexture = *specularTexture;
job.ModelMatrix = modelMatrix;
job.Color = color;
job.Depth = depth;
m_RendererQueue.Deferred.Add(job);
m_RendererQueue.Forward.Add(job);
}
void EnqueuePointLight(glm::vec3 position, glm::vec3 diffuseColor, glm::vec3 specularColor, float radius)
-9
View File
@@ -121,8 +121,6 @@ public:
int Process(std::string contextTypeName);
void Clear();
void Unsubscribe(BaseEventRelay &relay);
template <typename ContextType>
void UnsubscribeAll();
private:
typedef std::string ContextTypeName_t; // typeid(ContextType).name()
@@ -156,13 +154,6 @@ int EventBroker::Process()
return Process(contextTypeName);
}
template <typename ContextType>
void EventBroker::UnsubscribeAll()
{
const std::string contextTypeName = typeid(ContextType).name();
m_ContextRelays.erase(contextTypeName);
}
}
#endif // MessageRelay_h__
+2
View File
@@ -52,6 +52,8 @@ struct ModelJob : RenderJob
unsigned int ShaderID;
unsigned int TextureID;
std::string fileName;
glm::mat4 ModelMatrix;
GLuint DiffuseTexture;
GLuint NormalTexture;
+4
View File
@@ -76,6 +76,8 @@ private:
GLuint m_ScreenQuad = 0;
Model* m_UnitSphere = nullptr;
Model* m_UnitQuad = nullptr;
Texture* m_StandardNormal;
Texture* m_StandardSpecular;
GLuint m_rbDepthBuffer = 0;
GLuint m_fbDeferred1 = 0;
@@ -93,6 +95,8 @@ private:
void CreateBuffers();
GLuint CreateQuad();
static bool DepthSort(const std::shared_ptr<RenderJob> &i, const std::shared_ptr<RenderJob> &j) { return (i->Depth < j->Depth); }
void DrawDeferred(RenderQueue &objects, RenderQueue &lights);
void DrawForward(RenderQueue &objects, RenderQueue &lights);
void DrawScene(RenderQueue &objects, ShaderProgram &program);
+1 -1
View File
@@ -194,7 +194,7 @@ public:
// Triggers commit events in systems
// TODO: Replace completely by EComponentCreated?
void CommitEntity(EntityID entity);
int CommitEntity(EntityID entity);
/** Get all components of a specific type.
+1 -1
View File
@@ -15,7 +15,7 @@ namespace Components
struct Ball : Component
{
int Number = 0;
};
}
+1
View File
@@ -17,6 +17,7 @@ struct Brick : Component
{
int Points = 10;
int Hits = 1;
int Score = 50;
};
}
+26
View File
@@ -0,0 +1,26 @@
//
// Created by Adniklastrator on 2015-09-15.
//
#ifndef DAYDREAM_CLIFE_H
#define DAYDREAM_CLIFE_H
#include "Core/Component.h"
namespace dd
{
namespace Components
{
struct Life : Component {
int Number = 0;
};
}
}
#endif //DAYDREAM_CLIFE_H
+4
View File
@@ -19,6 +19,10 @@ struct Pad : Component
{
int Lives;
int Points;
float SlowdownModifier = 5.f;
float AccelerationSpeed = 80.f;
float MaxSpeed = 40.f;
};
}
+27
View File
@@ -0,0 +1,27 @@
//
// Created by Adniklastrator on 2015-09-15.
//
#ifndef DAYDREAM_ELIFELOST_H
#define DAYDREAM_ELIFELOST_H
#include "Core/EventBroker.h"
#include "Core/Entity.h"
namespace dd
{
namespace Events
{
struct LifeLost : Event
{
EntityID Entity;
};
}
}
#endif //DAYDREAM_ELIFELOST_H
+25
View File
@@ -0,0 +1,25 @@
//
// Created by Adniklastrator on 2015-09-15.
//
#ifndef DAYDREAM_ERESETBALL_H
#define DAYDREAM_ERESETBALL_H
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct ResetBall : Event
{
};
}
}
#endif //DAYDREAM_ERESETBALL_H
+25
View File
@@ -0,0 +1,25 @@
//
// Created by Adniklastrator on 2015-09-15.
//
#ifndef DAYDREAM_ESCOREEVENT_H
#define DAYDREAM_ESCOREEVENT_H
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct ScoreEvent : Event
{
int Score = 0;
};
}
}
#endif //DAYDREAM_ESCOREEVENT_H
Regular → Executable
+45 -10
View File
@@ -8,14 +8,21 @@
#include "Core/System.h"
#include "Core/CTransform.h"
#include "Rendering/CSprite.h"
#include "Rendering/CModel.h"
#include "Game/CBrick.h"
#include "Physics/EContact.h"
#include "Core/EventBroker.h"
#include "Core/World.h"
#include "Game/CBall.h"
#include "Game/CLife.h"
#include "Game/EStageCleared.h"
#include "Game/ELifeLost.h"
#include "Game/EResetBall.h"
#include "Game/EScoreEvent.h"
#include "Physics/CBoxShape.h"
#include "Physics/CPhysics.h"
#include "Physics/CCircleShape.h"
#include "Physics/ESetImpulse.h"
#include "Physics/EContact.h"
#include <fstream>
#include <iostream>
#include <intrin.h>
@@ -47,6 +54,7 @@ public:
void Initialize() override;
void CreateBasicLevel(int, int, glm::vec2, int);
void CreateLife(int);
void SaveLevel(int, int, glm::vec2, int); // Shouldn't be here, but I'm experimenting.
void LoadLevel(char[20]);
void CreateBrick(int, int, glm::vec2, int, int);
@@ -56,20 +64,47 @@ public:
void EndLevel();
void Update(double dt);
void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
bool Initialized() const { return m_Initialized; }
void SetInitialized(const bool& initialized) { m_Initialized = initialized; }
int& Lives() { return m_Lives; }
void SetLives(const int& lives) { m_Lives = lives; }
int& PastLives() { return m_PastLives; }
void SetPastLives(const int& pastLives) { m_PastLives = pastLives; }
int& Score() { return m_Score; }
void SetScore(const int& score) { m_Score = score; }
int& NumberOfBricks() { return m_NumberOfBricks; }
void SetNumberOfBricks(const int& numberOfBricks) { m_NumberOfBricks = numberOfBricks; }
int& Rows() { return m_Rows; }
void SetRows(const int& rows) { m_Rows = rows; }
int& Lines() { return m_Lines; }
void SetLines(const int& lines) { m_Lines = lines; }
int& SpaceToEdge() { return m_SpaceToEdge; }
void SetSpaceToEdge(const int& spaceToEdge) { m_SpaceToEdge = spaceToEdge; }
glm::vec2& SpaceBetweenBricks() { return m_SpaceBetweenBricks; }
void SetSpaceBetweenBricks(const glm::vec2& spaceBetweenBricks) { m_SpaceBetweenBricks = spaceBetweenBricks; }
private:
bool m_Initialized = false;
int m_Lives = 3;
int m_PastLives = 3;
int m_Score = 0;
int m_NumberOfBricks;
int m_Rows = 7;
int m_Lines = 8;
int m_SpaceToEdge = 0;
glm::vec2 m_SpaceBetweenBricks = glm::vec2(2, 0.5);
dd::EventRelay<LevelSystem, dd::Events::Contact> m_EContact;
dd::EventRelay<LevelSystem, dd::Events::LifeLost> m_ELifeLost;
dd::EventRelay<LevelSystem, dd::Events::ScoreEvent> m_EScoreEvent;
bool OnContact(const dd::Events::Contact &event);
bool m_Initialized = false;
int numberOfBricks;
int tRows = 7;
int tLines = 8;
glm::vec2 tSpaceBetweenBricks = glm::vec2(2, 0.5);
int tSpaceToEdge = 0;
bool LifeLost(const dd::Events::LifeLost &event);
bool ScoreEvent(const dd::Events::ScoreEvent &event);
};
}
Regular → Executable
+35 -17
View File
@@ -7,19 +7,22 @@
#include "Core/InputController.h"
#include "Core/System.h"
#include "Core/Component.h"
#include "Core/CTransform.h"
#include "Core/EventBroker.h"
#include "Core/EKeyDown.h"
#include "Core/EKeyUp.h"
#include "Input/EBindKey.h"
#include "Physics/EContact.h"
#include "Core/CTransform.h"
#include "Physics/CBoxShape.h"
#include "Physics/CPhysics.h"
#include "Rendering/CSprite.h"
#include "Game/CBall.h"
#include "Core/Component.h"
#include "Physics/ESetImpulse.h"
#include "Physics/CCircleShape.h"
#include "Physics/ESetImpulse.h"
#include "Rendering/CSprite.h"
#include "Rendering/CModel.h"
#include "Game/CBall.h"
#include "Game/EResetBall.h"
#include "CPad.h"
namespace dd
@@ -32,34 +35,49 @@ class PadSystem : public System
{
public:
PadSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
: System(world, eventBroker)
{ }
: System(world, eventBroker) { }
void Initialize() override;
void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
EntityID& Entity() { return m_Entity; }
void SetEntity(const EntityID& ent) { m_Entity = ent; }
glm::vec3 Acceleration() const { return m_Acceleration; }
void SetAcceleration(const glm::vec3& acceleration) { m_Acceleration = acceleration; }
bool Left() const { return m_Left; }
void SetLeft(const bool& left) { m_Left = left; }
bool Right() const { return m_Right; }
void SetRight(const bool& right) { m_Right = right; }
bool ReplaceBall() const { return m_ReplaceBall; }
void SetReplaceBall(const bool& replaceBall) { m_ReplaceBall = replaceBall; }
Components::Transform* Transform() const { return m_Transform; }
void SetTransform(const Components::Transform* transform) { m_Transform = transform; }
Components::Pad* Pad() const { return m_Pad; }
void SetPad(const Components::Pad* pad) { m_Pad = pad; }
private:
EntityID m_Entity = 0;
glm::vec3 m_Acceleration = glm::vec3(0.f, 0.f, 0.f);
bool m_Left = false, m_Right = false, m_ReplaceBall = false;
Components::Transform* m_Transform;
Components::Pad* m_Pad;
dd::EventRelay<PadSystem, dd::Events::KeyDown> m_EKeyDown;
dd::EventRelay<PadSystem, dd::Events::KeyUp> m_EKeyUp;
dd::EventRelay<PadSystem, dd::Events::Contact> m_EContact;
dd::EventRelay<PadSystem, dd::Events::ResetBall> m_EResetBall;
bool OnKeyDown(const dd::Events::KeyDown &event);
bool OnKeyUp(const dd::Events::KeyUp &event);
bool OnContact(const dd::Events::Contact &event);
bool ResetBall(const dd::Events::ResetBall &event);
class PadSteeringInputController;
std::array<std::shared_ptr<PadSteeringInputController>, 4> m_PadInputControllers;
EntityID ent = 0;
Components::Transform* transform;
glm::vec3 acceleration = glm::vec3(0.f, 0.f, 0.f);
bool left = false, right = false;
};
class PadSystem::PadSteeringInputController : InputController<PadSystem>