diff --git a/assets/Textures/Ball.png b/assets/Textures/Ball.png new file mode 100644 index 0000000..f43f7f8 Binary files /dev/null and b/assets/Textures/Ball.png differ diff --git a/assets/Textures/Bricks/1.png b/assets/Textures/Bricks/1.png new file mode 100644 index 0000000..adf57c9 Binary files /dev/null and b/assets/Textures/Bricks/1.png differ diff --git a/assets/Textures/Bricks/2.png b/assets/Textures/Bricks/2.png new file mode 100644 index 0000000..f2c5ec3 Binary files /dev/null and b/assets/Textures/Bricks/2.png differ diff --git a/assets/Textures/Bricks/3.png b/assets/Textures/Bricks/3.png new file mode 100644 index 0000000..3ade1a7 Binary files /dev/null and b/assets/Textures/Bricks/3.png differ diff --git a/assets/Textures/Bricks/4.png b/assets/Textures/Bricks/4.png new file mode 100644 index 0000000..5b273c2 Binary files /dev/null and b/assets/Textures/Bricks/4.png differ diff --git a/assets/Textures/Bricks/5.png b/assets/Textures/Bricks/5.png new file mode 100644 index 0000000..f85163a Binary files /dev/null and b/assets/Textures/Bricks/5.png differ diff --git a/assets/Textures/Bricks/6.png b/assets/Textures/Bricks/6.png new file mode 100644 index 0000000..7722cf2 Binary files /dev/null and b/assets/Textures/Bricks/6.png differ diff --git a/assets/Textures/Bricks/7.png b/assets/Textures/Bricks/7.png new file mode 100644 index 0000000..671952d Binary files /dev/null and b/assets/Textures/Bricks/7.png differ diff --git a/assets/Textures/Pad.png b/assets/Textures/Pad.png new file mode 100644 index 0000000..88263e8 Binary files /dev/null and b/assets/Textures/Pad.png differ diff --git a/assets/Textures/Test/Brick_Diffuse.png b/assets/Textures/Test/Brick_Diffuse.png new file mode 100755 index 0000000..f661c9d Binary files /dev/null and b/assets/Textures/Test/Brick_Diffuse.png differ diff --git a/assets/Textures/Test/Brick_Normal.png b/assets/Textures/Test/Brick_Normal.png new file mode 100755 index 0000000..af5a481 Binary files /dev/null and b/assets/Textures/Test/Brick_Normal.png differ diff --git a/assets/Textures/Test/Brick_Specular.png b/assets/Textures/Test/Brick_Specular.png new file mode 100755 index 0000000..38679bb Binary files /dev/null and b/assets/Textures/Test/Brick_Specular.png differ diff --git a/assets/Textures/Test/Single_Brick_Diffuse.png b/assets/Textures/Test/Single_Brick_Diffuse.png new file mode 100755 index 0000000..f004fcc Binary files /dev/null and b/assets/Textures/Test/Single_Brick_Diffuse.png differ diff --git a/assets/Textures/Test/Single_Brick_Diffuse2.png b/assets/Textures/Test/Single_Brick_Diffuse2.png new file mode 100755 index 0000000..db16d67 Binary files /dev/null and b/assets/Textures/Test/Single_Brick_Diffuse2.png differ diff --git a/assets/Textures/Test/Single_Brick_Diffuse3.png b/assets/Textures/Test/Single_Brick_Diffuse3.png new file mode 100755 index 0000000..b168ae6 Binary files /dev/null and b/assets/Textures/Test/Single_Brick_Diffuse3.png differ diff --git a/assets/Textures/Test/Single_Brick_Diffuse4.png b/assets/Textures/Test/Single_Brick_Diffuse4.png new file mode 100755 index 0000000..d7b2853 Binary files /dev/null and b/assets/Textures/Test/Single_Brick_Diffuse4.png differ diff --git a/assets/Textures/Test/Single_Brick_Normal.png b/assets/Textures/Test/Single_Brick_Normal.png new file mode 100755 index 0000000..2d1c1ef Binary files /dev/null and b/assets/Textures/Test/Single_Brick_Normal.png differ diff --git a/assets/Textures/Test/Single_Brick_Normal2.png b/assets/Textures/Test/Single_Brick_Normal2.png new file mode 100755 index 0000000..97aa42a Binary files /dev/null and b/assets/Textures/Test/Single_Brick_Normal2.png differ diff --git a/assets/Textures/Test/Single_Brick_Normal3.png b/assets/Textures/Test/Single_Brick_Normal3.png new file mode 100755 index 0000000..4074a7d Binary files /dev/null and b/assets/Textures/Test/Single_Brick_Normal3.png differ diff --git a/assets/Textures/Test/Single_Brick_Normal4.png b/assets/Textures/Test/Single_Brick_Normal4.png new file mode 100755 index 0000000..3efbf6c Binary files /dev/null and b/assets/Textures/Test/Single_Brick_Normal4.png differ diff --git a/assets/Textures/Test/Single_Brick_Specular.png b/assets/Textures/Test/Single_Brick_Specular.png new file mode 100755 index 0000000..824d862 Binary files /dev/null and b/assets/Textures/Test/Single_Brick_Specular.png differ diff --git a/assets/Textures/Test/Single_Brick_Specular2.png b/assets/Textures/Test/Single_Brick_Specular2.png new file mode 100755 index 0000000..c592a6c Binary files /dev/null and b/assets/Textures/Test/Single_Brick_Specular2.png differ diff --git a/assets/Textures/Test/Single_Brick_Specular3.png b/assets/Textures/Test/Single_Brick_Specular3.png new file mode 100755 index 0000000..71a4aa7 Binary files /dev/null and b/assets/Textures/Test/Single_Brick_Specular3.png differ diff --git a/assets/Textures/Test/Single_Brick_Specular4.png b/assets/Textures/Test/Single_Brick_Specular4.png new file mode 100755 index 0000000..191f633 Binary files /dev/null and b/assets/Textures/Test/Single_Brick_Specular4.png differ diff --git a/assets/Textures/Test/TestBrick.psd b/assets/Textures/Test/TestBrick.psd new file mode 100755 index 0000000..3c80e38 Binary files /dev/null and b/assets/Textures/Test/TestBrick.psd differ diff --git a/assets/Textures/Test/TestBrick_Diffuse.png b/assets/Textures/Test/TestBrick_Diffuse.png new file mode 100755 index 0000000..b68f07e Binary files /dev/null and b/assets/Textures/Test/TestBrick_Diffuse.png differ diff --git a/assets/Textures/Test/TestBrick_Diffuse_Simple.png b/assets/Textures/Test/TestBrick_Diffuse_Simple.png new file mode 100755 index 0000000..2918318 Binary files /dev/null and b/assets/Textures/Test/TestBrick_Diffuse_Simple.png differ diff --git a/assets/Textures/Test/TestBrick_Normal.png b/assets/Textures/Test/TestBrick_Normal.png new file mode 100755 index 0000000..13ae8e3 Binary files /dev/null and b/assets/Textures/Test/TestBrick_Normal.png differ diff --git a/assets/Textures/Test/TestBrick_Specular.png b/assets/Textures/Test/TestBrick_Specular.png new file mode 100755 index 0000000..632bf6d Binary files /dev/null and b/assets/Textures/Test/TestBrick_Specular.png differ diff --git a/include/Core/Engine.h b/include/Core/Engine.h index 5eb143f..1df8465 100644 --- a/include/Core/Engine.h +++ b/include/Core/Engine.h @@ -30,16 +30,22 @@ //TODO: Remove includes that are only here for the temporary draw solution. #include "World.h" #include "CTransform.h" +#include "Core/EventBroker.h" #include "Rendering/CModel.h" #include "Rendering/CSprite.h" #include "CTemplate.h" +#include "Rendering/CPointLight.h" #include "Transform/TransformSystem.h" +#include "Game/LevelSystem.h" +#include "Game/PadSystem.h" +#include "Game/CBall.h" +#include "Game/CBrick.h" +#include "Game/CPad.h" #include "Physics/PhysicsSystem.h" #include "Physics/CPhysics.h" - - #include "Physics/CBoxShape.h" +#include "Physics/ESetImpulse.h" namespace dd { @@ -67,40 +73,123 @@ public: // m_World->ComponentFactory.Register(); // m_World->ComponentFactory.Register(); + m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); + m_World->ComponentFactory.Register(); + m_World->ComponentFactory.Register(); + m_World->ComponentFactory.Register(); m_World->SystemFactory.Register( [this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); }); m_World->AddSystem(); + m_World->SystemFactory.Register([this]() { return new Systems::LevelSystem(m_World.get(), m_EventBroker); }); + m_World->AddSystem(); + m_World->SystemFactory.Register([this]() { return new Systems::PadSystem(m_World.get(), m_EventBroker); }); + m_World->AddSystem(); + m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); + m_World->ComponentFactory.Register(); m_World->Initialize(); + + //TODO: Remove tobias light-test code. + { + auto t_BrickWall = m_World->CreateEntity(); + auto transform = m_World->AddComponent(t_BrickWall); + transform->Position = glm::vec3(0.f, 0.f, -10.f); + auto sprite = m_World->AddComponent(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"; + } + + { auto ent = m_World->CreateEntity(); std::shared_ptr transform = m_World->AddComponent(ent); - transform->Position = glm::vec3(0.f, 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 sprite = m_World->AddComponent(ent); - sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; + sprite->SpriteFile = "Textures/Ball.png"; std::shared_ptr circleShape = m_World->AddComponent(ent); + std::shared_ptr ball = m_World->AddComponent(ent); std::shared_ptr physics = m_World->AddComponent(ent); physics->Static = false; + auto plight = m_World->AddComponent(ent); + plight->Radius = 2.f; + m_World->CommitEntity(ent); + + Events::SetImpulse e; + e.Entity = ent; + e.Impulse = glm::vec2(0.f, -7.f); + e.Point = glm::vec2(0.5f, 0.f); + m_EventBroker->Publish(e); } + { + auto topWall = m_World->CreateEntity(); + std::shared_ptr transform = m_World->AddComponent(topWall); + transform->Position = glm::vec3(0.f, 5.f, -10.f); + transform->Scale = glm::vec3(15.f, 0.5f, 1.f); - { + std::shared_ptr sprite = m_World->AddComponent(topWall); + sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; + + std::shared_ptr boxShape = m_World->AddComponent(topWall); + + std::shared_ptr physics = m_World->AddComponent(topWall); + physics->Static = true; + + m_World->CommitEntity(topWall); + } + { + auto leftWall = m_World->CreateEntity(); + std::shared_ptr transform = m_World->AddComponent(leftWall); + transform->Position = glm::vec3(-9.f, 1.f, -10.f); + transform->Scale = glm::vec3(0.5f, 10.f, 1.f); + + std::shared_ptr sprite = m_World->AddComponent(leftWall); + sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; + + std::shared_ptr boxShape = m_World->AddComponent(leftWall); + + std::shared_ptr physics = m_World->AddComponent(leftWall); + physics->Static = true; + + m_World->CommitEntity(leftWall); + } + { + auto rightWall = m_World->CreateEntity(); + std::shared_ptr transform = m_World->AddComponent(rightWall); + transform->Position = glm::vec3(9.f, 1.f, -10.f); + transform->Scale = glm::vec3(0.5f, 10.f, 1.f); + + std::shared_ptr sprite = m_World->AddComponent(rightWall); + sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; + + std::shared_ptr boxShape = m_World->AddComponent(rightWall); + + std::shared_ptr physics = m_World->AddComponent(rightWall); + physics->Static = true; + + m_World->CommitEntity(rightWall); + } + + + /*{ auto ent = m_World->CreateEntity(); std::shared_ptr transform = m_World->AddComponent(ent); - transform->Position = glm::vec3(0.f, -2.f, -10.f); + 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)); @@ -113,28 +202,22 @@ public: physics->Static = true; m_World->CommitEntity(ent); - } - + }*/ { auto ent = m_World->CreateEntity(); - std::shared_ptr transform = m_World->AddComponent(ent); - transform->Position = glm::vec3(-2.f, -1.f, -10.f); - transform->Scale = glm::vec3(0.5f, 8.5f, 1.f); - //transform->Orientation = glm::rotate(transform->Orientation, glm::radians(25.f), glm::vec3(0, 0, -1)); - - std::shared_ptr sprite = m_World->AddComponent(ent); - sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; - - std::shared_ptr boxShape = m_World->AddComponent(ent); - - std::shared_ptr physics = m_World->AddComponent(ent); - physics->Static = true; - + m_World->SetProperty(ent, "Name", "Pad"); + auto ctransform = m_World->AddComponent(ent); + ctransform->Position = glm::vec3(0.f, -5.f, -10.f); + ctransform->Scale = glm::vec3(3.2, 0.8, 0.); + auto rectangle = m_World->AddComponent(ent); + auto physics = m_World->AddComponent(ent); + auto csprite = m_World->AddComponent(ent); + auto pad = m_World->AddComponent(ent); + csprite->SpriteFile = "Textures/Pad.png"; m_World->CommitEntity(ent); } - m_LastTime = glfwGetTime(); } @@ -153,6 +236,19 @@ public: m_World->Update(dt); + +// +// if (glfwGetKey(m_Renderer->Window(), GLFW_KEY_R)) { +// ResourceManager::Reload("Shaders/Deferred/3/Fragment.glsl"); +// } +// + //TODO Fill up the renderQueue with models (Temp fix) +// TEMPAddToRenderQueue(); + + // Render scene + //TODO send renderqueue to draw. +// m_Renderer->Draw(m_RendererQueue); + if (glfwGetKey(m_Renderer->Window(), GLFW_KEY_R)) { ResourceManager::Reload("Shaders/Deferred/3/Fragment.glsl"); } @@ -171,6 +267,7 @@ public: } std::shared_ptr m_TransformSystem; + std::shared_ptr m_LevelSystem; //TODO: Get this out of engine.h void TEMPAddToRenderQueue() @@ -209,19 +306,43 @@ public: } } + //TODO: Add LightLoadShit + + auto pointLightComponent = m_World->GetComponent(entity); + if (pointLightComponent) + { + Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity); + EnqueuePointLight(absoluteTransform.Position, + pointLightComponent->Diffuse, + pointLightComponent->Specular, + pointLightComponent->Radius); + } + + auto spriteComponent = m_World->GetComponent(entity); if (spriteComponent) { - auto textureAsset = ResourceManager::Load(spriteComponent->SpriteFile); - if (textureAsset) - { - Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity); - glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(absoluteTransform.Orientation).z, glm::vec3(0, 0, -1)); - glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position) - * glm::toMat4(orientation2D) - * glm::scale(absoluteTransform.Scale); - EnqueueSprite(textureAsset, modelMatrix, spriteComponent->Color); + + std::string normal = spriteComponent->NormalTexture; + std::string spec = spriteComponent->SpecularTexture; + + if (normal.empty()) { + normal = "Textures/Core/NeutralNormalMap.png"; } + if (spec.empty()) { + spec = "Textures/Core/NeutralSpecularMap.png"; + } + auto texturediff = ResourceManager::Load(spriteComponent->SpriteFile); + auto texturenorm = ResourceManager::Load(normal); + auto texturespec = ResourceManager::Load(spec); + + + Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity); + glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(absoluteTransform.Orientation).z, glm::vec3(0, 0, -1)); + glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position) + * glm::toMat4(orientation2D) + * glm::scale(absoluteTransform.Scale); + EnqueueSprite(texturediff, texturenorm, texturespec, modelMatrix, spriteComponent->Color); } } @@ -250,15 +371,29 @@ public: } // TODO: Get this out of engine.h - void EnqueueSprite(Texture* texture, glm::mat4 modelMatrix, glm::vec4 color) + void EnqueueSprite(Texture* texture, Texture* normalTexture, Texture* specularTexture, glm::mat4 modelMatrix, glm::vec4 color) { SpriteJob job; job.TextureID = texture->ResourceID; - job.Texture = *texture; + job.DiffuseTexture = *texture; + job.NormalTexture = *normalTexture; + job.SpecularTexture = *specularTexture; job.ModelMatrix = modelMatrix; job.Color = color; - m_RendererQueue.Forward.Add(job); + m_RendererQueue.Deferred.Add(job); + } + + void EnqueuePointLight(glm::vec3 position, glm::vec3 diffuseColor, glm::vec3 specularColor, float radius) + { + PointLightJob job; + job.Position = position; + job.DiffuseColor = diffuseColor; + job.SpecularColor = specularColor; + job.Radius = radius; + + m_RendererQueue.Lights.Add(job); + } private: diff --git a/include/Core/InputController.h b/include/Core/InputController.h index 288db71..4eec570 100644 --- a/include/Core/InputController.h +++ b/include/Core/InputController.h @@ -34,54 +34,23 @@ class InputController public: InputController(std::shared_ptr eventBroker) : EventBroker(eventBroker) - , InGame(true) { Initialize(); } virtual void Initialize() { - EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &InputController::_OnCommand); - EVENT_SUBSCRIBE_MEMBER(m_EMouseMove, &InputController::_OnMouseMove); - EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &InputController::OnGameStart); - EVENT_SUBSCRIBE_MEMBER(m_EGameOver, &InputController::OnGameOver); + EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &InputController::OnCommand); + EVENT_SUBSCRIBE_MEMBER(m_EMouseMove, &InputController::OnMouseMove); } virtual bool OnCommand(const Events::InputCommand &event) { return false; } virtual bool OnMouseMove(const Events::MouseMove &event) { return false; } - virtual bool OnGameStart(const Events::GameStart &event) - { - InGame = true; - return true; - } - virtual bool OnGameOver(const Events::GameOver &event) - { - InGame = false; - return true; - } protected: std::shared_ptr EventBroker; - bool InGame; private: EventRelay m_EInputCommand; EventRelay m_EMouseMove; - EventRelay m_EGameStart; - EventRelay m_EGameOver; - - virtual bool _OnCommand(const Events::InputCommand &event) - { - if (InGame || event.Value == 0) - return OnCommand(event); - else - return false; - } - virtual bool _OnMouseMove(const Events::MouseMove &event) - { - if (InGame) - return OnMouseMove(event); - else - return false; - } }; } diff --git a/include/Core/RenderQueue.h b/include/Core/RenderQueue.h old mode 100644 new mode 100755 index 13c50a9..ccf1a3a --- a/include/Core/RenderQueue.h +++ b/include/Core/RenderQueue.h @@ -89,7 +89,9 @@ struct SpriteJob : RenderJob unsigned int TextureID; glm::mat4 ModelMatrix; - GLuint Texture; + GLuint DiffuseTexture; + GLuint NormalTexture; + GLuint SpecularTexture; glm::vec4 Color; void CalculateHash() override diff --git a/include/Core/Renderer.h b/include/Core/Renderer.h index d3c7054..ac84ef7 100755 --- a/include/Core/Renderer.h +++ b/include/Core/Renderer.h @@ -75,6 +75,7 @@ private: GLuint m_ScreenQuad = 0; Model* m_UnitSphere = nullptr; + Model* m_UnitQuad = nullptr; GLuint m_rbDepthBuffer = 0; GLuint m_fbDeferred1 = 0; diff --git a/include/Game/CBall.h b/include/Game/CBall.h new file mode 100644 index 0000000..d5c652f --- /dev/null +++ b/include/Game/CBall.h @@ -0,0 +1,25 @@ +// +// Created by Adniklastrator on 2015-09-10. +// + +#ifndef DAYDREAM_CBALL_H +#define DAYDREAM_CBALL_H + +#include "Core/Component.h" + +namespace dd +{ + +namespace Components +{ + +struct Ball : Component +{ + +}; + +} + +} + +#endif //DAYDREAM_CBALL_H diff --git a/include/Game/CBrick.h b/include/Game/CBrick.h new file mode 100644 index 0000000..7e7f83e --- /dev/null +++ b/include/Game/CBrick.h @@ -0,0 +1,26 @@ +// +// Created by Adniklastrator on 2015-09-09. +// + +#ifndef DAYDREAM_CBRICK_H +#define DAYDREAM_CBRICK_H + +#include "Core/Component.h" + +namespace dd +{ + +namespace Components +{ + +struct Brick : Component +{ + int Points = 10; + int Hits = 1; +}; + +} + +} + +#endif //DAYDREAM_CBRICK_H diff --git a/include/Game/CPad.h b/include/Game/CPad.h new file mode 100644 index 0000000..fef614f --- /dev/null +++ b/include/Game/CPad.h @@ -0,0 +1,28 @@ +// +// Created by Adniklastrator on 2015-09-10. +// + +#ifndef DAYDREAM_CPAD_H +#define DAYDREAM_CPAD_H + +#include "Core/Component.h" +#include "Core/EKeyDown.h" +#include "Core/EventBroker.h" + +namespace dd +{ + +namespace Components +{ + +struct Pad : Component +{ + int Lives; + int Points; +}; + +} + +} + +#endif //DAYDREAM_CPAD_H diff --git a/include/Game/EStageCleared.h b/include/Game/EStageCleared.h new file mode 100644 index 0000000..29ef021 --- /dev/null +++ b/include/Game/EStageCleared.h @@ -0,0 +1,21 @@ +// +// Created by Adniklastrator on 2015-09-09. +// + +#ifndef DAYDREAM_ESTAGECLEARED_H +#define DAYDREAM_ESTAGECLEARED_H + +#include "Core/EventBroker.h" + +namespace dd +{ +namespace Events +{ +struct StageCleared : Event +{ + +}; +} +} + +#endif //DAYDREAM_ESTAGECLEARED_H diff --git a/include/Game/LevelSystem.h b/include/Game/LevelSystem.h new file mode 100644 index 0000000..6269974 --- /dev/null +++ b/include/Game/LevelSystem.h @@ -0,0 +1,79 @@ +// +// Created by Adniklastrator on 2015-09-09. +// + +#ifndef DAYDREAM_LEVELSYSTEM_H +#define DAYDREAM_LEVELSYSTEM_H + +#include "Core/System.h" +#include "Core/CTransform.h" +#include "Rendering/CSprite.h" +#include "Game/CBrick.h" +#include "Physics/EContact.h" +#include "Core/EventBroker.h" +#include "Core/World.h" +#include "Game/CBall.h" +#include "Game/EStageCleared.h" +#include "Physics/CBoxShape.h" +#include "Physics/CPhysics.h" +#include +#include +#include + +namespace dd +{ + +namespace Systems +{ + + // Me trying things out. +class Level +{ +public: + int levelRows; + int levelLines; + int levelSpaceBetweenBricks; + int levelSpaceToEdge; + int bricks[]; +}; + +class LevelSystem : public System +{ +public: + LevelSystem(World* world, std::shared_ptr eventBroker) + : System(world, eventBroker) + { } + + void Initialize() override; + + void CreateBasicLevel(int, int, glm::vec2, 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); + void ProcessCollision(); + + void OnEntityRemoved(EntityID entity); + + void EndLevel(); + + void Update(double dt); + +private: + dd::EventRelay m_EContact; + + 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; +}; + +} + +} + +#endif //DAYDREAM_LEVELSYSTEM_H diff --git a/include/Game/PadSystem.h b/include/Game/PadSystem.h new file mode 100644 index 0000000..adce7a0 --- /dev/null +++ b/include/Game/PadSystem.h @@ -0,0 +1,82 @@ +// +// Created by Adniklastrator on 2015-09-10. +// + +#ifndef DAYDREAM_PADSYSTEM_H +#define DAYDREAM_PADSYSTEM_H + +#include "Core/InputController.h" +#include "Core/System.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" + + +namespace dd +{ + +namespace Systems +{ + +class PadSystem : public System +{ +public: + PadSystem(World* world, std::shared_ptr eventBroker) + : System(world, eventBroker) + { } + + void Initialize() override; + void Update(double dt) override; + +private: + dd::EventRelay m_EKeyDown; + dd::EventRelay m_EKeyUp; + dd::EventRelay m_EContact; + + bool OnKeyDown(const dd::Events::KeyDown &event); + bool OnKeyUp(const dd::Events::KeyUp &event); + + + bool OnContact(const dd::Events::Contact &event); + + + + + + class PadSteeringInputController; + std::array, 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 +{ +public: + PadSteeringInputController(std::shared_ptr eventBroker) + : InputController(eventBroker) + { + + } +protected: + virtual bool OnCommand(const Events::InputCommand &event); +}; + +} + +} + + +#endif //DAYDREAM_PADSYSTEM_H diff --git a/include/Physics/CPhysics.h b/include/Physics/CPhysics.h index d6c3b21..8d1f975 100644 --- a/include/Physics/CPhysics.h +++ b/include/Physics/CPhysics.h @@ -7,11 +7,11 @@ namespace dd namespace Components { - struct Physics: public Component - { - //idk if anything should be here :) - bool Static = true; - }; +struct Physics: public Component +{ + //idk if anything should be here :) + bool Static = true; +}; } diff --git a/include/Physics/PhysicsSystem.h b/include/Physics/PhysicsSystem.h index 3d1ece8..57bad34 100644 --- a/include/Physics/PhysicsSystem.h +++ b/include/Physics/PhysicsSystem.h @@ -80,8 +80,6 @@ private: e.Entity1 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()]; e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()]; - std::cout << e.Entity1 << " " << e.Entity2 << std::endl; - m_PhysicsSystem->EventBroker->Publish(e); } void EndContact(b2Contact* contact) diff --git a/include/Rendering/CSprite.h b/include/Rendering/CSprite.h old mode 100644 new mode 100755 index 6e55d7e..9c39068 --- a/include/Rendering/CSprite.h +++ b/include/Rendering/CSprite.h @@ -34,6 +34,8 @@ struct Sprite : Component Sprite() : Color(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)) { } std::string SpriteFile; + std::string NormalTexture; + std::string SpecularTexture; glm::vec4 Color; }; diff --git a/include/Transform/TransformSystem.h b/include/Transform/TransformSystem.h index 433a6cf..7583fc3 100644 --- a/include/Transform/TransformSystem.h +++ b/include/Transform/TransformSystem.h @@ -39,7 +39,7 @@ public: TransformSystem(World* world, std::shared_ptr eventBroker) : System(world, eventBroker) { } - //void Update(double dt) override; + void Update(double dt) override; Components::Transform AbsoluteTransform(EntityID entity); glm::vec3 AbsolutePosition(EntityID entity); diff --git a/src/game/Core/Camera.cpp b/src/game/Core/Camera.cpp old mode 100644 new mode 100755 index 111b11e..5e05394 --- a/src/game/Core/Camera.cpp +++ b/src/game/Core/Camera.cpp @@ -77,12 +77,20 @@ void dd::Camera::SetOrientation(glm::quat val) void dd::Camera::UpdateProjectionMatrix() { - 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() diff --git a/src/game/Core/Renderer.cpp b/src/game/Core/Renderer.cpp index c22530a..59c08b1 100755 --- a/src/game/Core/Renderer.cpp +++ b/src/game/Core/Renderer.cpp @@ -111,6 +111,7 @@ void dd::Renderer::LoadShaders() void dd::Renderer::CreateBuffers() { m_ScreenQuad = CreateQuad(); + m_UnitQuad = ResourceManager::Load("Models/Core/UnitQuad.obj"); m_UnitSphere = ResourceManager::Load("Models/Core/UnitSphere.obj"); glGenRenderbuffers(1, &m_rbDepthBuffer); @@ -264,7 +265,7 @@ void dd::Renderer::DrawDeferred(RenderQueue &objects, RenderQueue &lights) glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); m_spDeferred3->Bind(); - glUniform3fv(glGetUniformLocation(*m_spDeferred3, "La"), 1, glm::value_ptr(glm::vec3(0.3f))); + glUniform3fv(glGetUniformLocation(*m_spDeferred3, "La"), 1, glm::value_ptr(glm::vec3(0.5f))); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_GDiffuse); glActiveTexture(GL_TEXTURE1); @@ -306,6 +307,7 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program) glUniform1f(glGetUniformLocation(shaderProgramHandle, "MaterialShininess"), modelJob->Shininess); + //TODO: Make sure that a normal/specular is loaded in. glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture); if (modelJob->NormalTexture != 0) { @@ -328,17 +330,21 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program) if (spriteJob) { glm::mat4 modelMatrix = spriteJob->ModelMatrix; - modelMatrix = modelMatrix * glm::scale(glm::vec3(0.5f)); MVP = PV * modelMatrix; glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix)); glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix)); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, spriteJob->Texture); + glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture); + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, spriteJob->NormalTexture); + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, spriteJob->SpecularTexture); - glBindVertexArray(m_ScreenQuad); - glDrawArrays(GL_TRIANGLES, 0, 6); + glBindVertexArray(m_UnitQuad->VAO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_UnitQuad->ElementBuffer); + glDrawElementsBaseVertex(GL_TRIANGLES, m_UnitQuad->m_Indices.size(), GL_UNSIGNED_INT, 0, 0); continue; } diff --git a/src/game/Core/Shaders/Deferred/1/Vertex.glsl b/src/game/Core/Shaders/Deferred/1/Vertex.glsl old mode 100644 new mode 100755 index 4b4e649..8c8f058 --- a/src/game/Core/Shaders/Deferred/1/Vertex.glsl +++ b/src/game/Core/Shaders/Deferred/1/Vertex.glsl @@ -65,7 +65,7 @@ void main() + BoneWeights2[3] * Bones[int(BoneIndices2[3])]; } - gl_Position = MVP * boneTransform * vec4(Position, 1.0); + gl_Position = MVP * vec4(Position, 1.0); Output.Position = (V * M * boneTransform * vec4(Position, 1.0)).xyz; Output.Normal = (inverse(transpose(V * M)) * boneTransform * vec4(Normal, 0.0)).xyz; diff --git a/src/game/Core/Shaders/Deferred/3/Fragment.glsl b/src/game/Core/Shaders/Deferred/3/Fragment.glsl index 08b7f08..27e9c62 100755 --- a/src/game/Core/Shaders/Deferred/3/Fragment.glsl +++ b/src/game/Core/Shaders/Deferred/3/Fragment.glsl @@ -38,6 +38,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; + frag_Diffuse = DiffuseTexel * (vec4(1.f, 1.f, 1.f, 0.0) + LightingTexel); + //frag_Diffuse = DiffuseTexel; //frag_Diffuse = vec4(LightingTexel.r, LightingTexel.g, LightingTexel.b, 1.0); } \ No newline at end of file diff --git a/src/game/Core/Shaders/Forward/Fragment.glsl b/src/game/Core/Shaders/Forward/Fragment.glsl old mode 100644 new mode 100755 index 83279c0..144062f --- a/src/game/Core/Shaders/Forward/Fragment.glsl +++ b/src/game/Core/Shaders/Forward/Fragment.glsl @@ -84,6 +84,6 @@ void main() vec4 diffuseTexel = texture(DiffuseTexture, Input.TextureCoord); - //FragmentColor = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a); - FragmentColor = diffuseTexel; + FragmentColor = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a); + //FragmentColor = diffuseTexel; } \ No newline at end of file diff --git a/src/game/Core/Texture.cpp b/src/game/Core/Texture.cpp index 6e1b7c7..f9ba46e 100755 --- a/src/game/Core/Texture.cpp +++ b/src/game/Core/Texture.cpp @@ -24,7 +24,7 @@ dd::Texture::Texture(std::string path) std::unique_ptr image = std::make_unique(path); if (image->Width == 0 && image->Height == 0 || image->Format == Image::ImageFormat::Unknown) { - image = std::make_unique("Textures/ErrorTexture.png"); + image = std::make_unique("Textures/Core/ErrorTexture.png"); if (image->Width == 0 && image->Height == 0 || image->Format == Image::ImageFormat::Unknown) { LOG_ERROR("Couldn't even load the error texture. This is a dark day indeed."); return; diff --git a/src/game/Game/LevelSystem.cpp b/src/game/Game/LevelSystem.cpp new file mode 100644 index 0000000..68dce72 --- /dev/null +++ b/src/game/Game/LevelSystem.cpp @@ -0,0 +1,145 @@ +// +// Created by Adniklastrator on 2015-09-09. +// + + +#include "PrecompiledHeader.h" +#include "Game/LevelSystem.h" + + +void dd::Systems::LevelSystem::Initialize() +{ + EVENT_SUBSCRIBE_MEMBER(m_EContact, LevelSystem::OnContact); + + return; +} + +void dd::Systems::LevelSystem::Update(double dt) { + if (!m_Initialized) { + CreateBasicLevel(tRows, tLines, tSpaceBetweenBricks, tSpaceToEdge); + m_Initialized = true; + } +} + +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++) + { + num++; + for (int j = 0; j < lines; j++) + { + CreateBrick(i, j, spacesBetweenBricks, spaceToEdge, num); + } + if (num == 7) + num = 0; + } + + return; +} + +void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBetweenBricks, int spaceToEdge, int num) +{ + auto brick = m_World->CreateEntity(); + std::shared_ptr transform = m_World->AddComponent(brick); + std::shared_ptr sprite = m_World->AddComponent(brick); + std::shared_ptr cBrick = m_World->AddComponent(brick); + std::shared_ptr cRec = m_World->AddComponent(brick); + std::shared_ptr cPhys = m_World->AddComponent(brick); + std::string fileName = "Textures/Bricks/"; + fileName.append(std::to_string(num)); + fileName.append(".png"); + sprite->SpriteFile = fileName; + float x = spaceToEdge + line * spacesBetweenBricks.x; + float y = spaceToEdge + row * spacesBetweenBricks.y; + transform->Scale = glm::vec3(1.6, 0.4, 0.); + transform->Position = glm::vec3(x - 7, y + 1, -10.f); + //sprite->Color = glm::vec4(1.f, 1.f, 1.f, 1.f); + m_World->CommitEntity(brick); + return; +} + +void dd::Systems::LevelSystem::ProcessCollision() +{ + // Like, go into brick component and check what it does upon collision. Maybe not done here? + return; +} + +void dd::Systems::LevelSystem::OnEntityRemoved(EntityID entity) +{ + auto brick = m_World->GetComponent(entity); + if (brick != NULL) + { + numberOfBricks--; + if (numberOfBricks < 1) + { + EndLevel(); + } + } + return; +} + +bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event) +{ + /*event.Entity1 - Vi vet inte vilken som. + event.Entity2 - */ + EntityID entityBrick = event.Entity1; + auto brick = m_World->GetComponent(entityBrick); + if (brick == NULL) + { + return false; + } + EntityID entityBall = event.Entity2; + //EntityID entity1 = event.Entity1; + //EntityID entity2 = event.Entity2; + + //auto brick = m_World->GetComponent(entity1); + //auto ball = m_World->GetComponent(entity2); + //std::cout << brick << std::endl; + //std::cout << ball << std::endl; + /*if (brick != NULL) + { + std::cout << "Entity1 is a brick!" << std::endl; + entityBrick = entity1; + if (ball != NULL) + { + std::cout << "Entity2 is a ball!" << std::endl; + entityBall = entity2; + } + } + else + { + brick = m_World->GetComponent(entity2); + if (brick != NULL) + { + std::cout << "Entity2 is a brick!" << std::endl; + entityBrick = entity2; + } + + ball = m_World->GetComponent(entity1); + if (ball != NULL) + { + std::cout << "Entity1 is a ball!" << std::endl; + entityBall = entity1; + } + } + + if (entityBrick != NULL && entityBall != NULL) + {*/ + //std::cout << "We're destroying!" << std::endl; + m_World->RemoveEntity(entityBrick); + + return true; + //} + + return false; +} + +void dd::Systems::LevelSystem::EndLevel() +{ + Events::StageCleared e; + EventBroker->Publish(e); + return; +} + diff --git a/src/game/Game/PadSystem.cpp b/src/game/Game/PadSystem.cpp new file mode 100644 index 0000000..a465b8b --- /dev/null +++ b/src/game/Game/PadSystem.cpp @@ -0,0 +1,181 @@ +// +// Created by Adniklastrator on 2015-09-10. +// + +#include "PrecompiledHeader.h" +#include "Game/PadSystem.h" +#include "Core/World.h" +#include +#include + + +void dd::Systems::PadSystem::Initialize() +{ + Events::BindKey r; + r.KeyCode = GLFW_KEY_RIGHT; + r.Command = "right"; + EventBroker->Publish(r); + + Events::BindKey l; + l.KeyCode = GLFW_KEY_LEFT; + l.Command = "left"; + EventBroker->Publish(l); + + EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, PadSystem::OnKeyDown); + EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, PadSystem::OnKeyUp); + EVENT_SUBSCRIBE_MEMBER(m_EContact, PadSystem::OnContact); + + return; +} + +void dd::Systems::PadSystem::Update(double dt) +{ + if (ent == 0) { + for (auto it = m_World->GetEntities()->begin(); it != m_World->GetEntities()->end(); it++) { + if (m_World->GetProperty(it->first, "Name") == "Pad") { + ent = it->first; + transform = m_World->GetComponent(ent); + break; + } + } + } + + if (transform->Velocity.x < -400.f) + { + transform->Velocity.x = -400.f; + } + else if (transform->Velocity.x > 400.f) + { + transform->Velocity.x = 400.f; + } + transform->Position += transform->Velocity * (float)dt; + transform->Velocity += acceleration * (float)dt; + transform->Velocity -= transform->Velocity * (0.9f * (float)dt); + + if (left) + { + acceleration.x = -20.f; + } + else if (right) + { + acceleration.x = 20.f; + } + else + { + acceleration.x = 0.f; + } + + return; +} + +bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event) +{ + int val = event.KeyCode; + if (val == 265) + { + //std::cout << "Up!" << std::endl; + } + else if (val == 264) + { + //std::cout << "Down!" << std::endl; + } + else if (val == 263) + { + //std::cout << "Left!" << std::endl; + //acceleration.x = -0.01f; + left = true; + } + else if (val = 262) + { + //std::cout << "Right!" << std::endl; + //acceleration.x = 0.01f; + right = true; + } + return true; +} + +bool dd::Systems::PadSystem::OnKeyUp(const dd::Events::KeyUp &event) +{ + int val = event.KeyCode; + if (val == 265) + { + + } + else if (val == 264) + { + + } + else if (val == 263) + { + left = false; + } + else if (val = 262) + { + right = false; + } + return true; +} + +bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event) +{ + EntityID entityBall = event.Entity2; + auto ball = m_World->GetComponent(entityBall); + if (ball == NULL) + { + return false; + } + EntityID entityPad = event.Entity1; + auto pad = m_World->GetComponent(entityPad); + if (pad == NULL) + { + return false; + } + auto transformBall = m_World->GetComponent(entityBall); + auto transformPad = m_World->GetComponent(entityPad); + + float movementMultiplier = 2.f; + + float movementX = (event.ContactPoint.x - transformPad->Position.x) * movementMultiplier; + float movementY = glm::cos((abs(movementX) / (3.2f * movementMultiplier)) * 3.14159265359f / 2) * 2.f; + + std::cout << movementX << " " << movementY << std::endl; + + //Temporary solution. Add a new ball and delete the old one. + auto ent = m_World->CreateEntity(); + std::shared_ptr transform = m_World->AddComponent(ent); + transform->Position = glm::vec3(transformBall->Position.x, transformBall->Position.y + 0.1f, -10.f); + transform->Scale = glm::vec3(1.f, 1.f, 1.f); + std::shared_ptr sprite = m_World->AddComponent(ent); + sprite->SpriteFile = "Textures/Ball.png"; + std::shared_ptr circleShape = m_World->AddComponent(ent); + std::shared_ptr cball = m_World->AddComponent(ent); + std::shared_ptr physics = m_World->AddComponent(ent); + physics->Static = false; + + m_World->RemoveEntity(entityBall); + m_World->CommitEntity(ent); + + Events::SetImpulse e; + e.Entity = ent; + e.Impulse = glm::vec2(movementX, movementY); + e.Point = glm::vec2(event.ContactPoint); + EventBroker->Publish(e); +} + +bool dd::Systems::PadSystem::PadSteeringInputController::OnCommand(const Events::InputCommand &event) +{ + std::string command = event.Command; + + std::cout << "Command!" << std::endl; + + if (command == "right") + { + std::cout << "Right!" << std::endl; + } + else if (command == "left") + { + std::cout << "Left!" << std::endl; + } + + return true; +} \ No newline at end of file diff --git a/src/game/Physics/PhysicsSystem.cpp b/src/game/Physics/PhysicsSystem.cpp index 7d502d8..3d244a7 100644 --- a/src/game/Physics/PhysicsSystem.cpp +++ b/src/game/Physics/PhysicsSystem.cpp @@ -12,7 +12,7 @@ void dd::Systems::PhysicsSystem::Initialize() { m_ContactListener = new ContactListener(this); - m_Gravity = b2Vec2(0.f, -9.82f); + m_Gravity = b2Vec2(0.f, 0.f); m_PhysicsWorld = new b2World(m_Gravity); m_TimeStep = 1.f/60.f; @@ -188,7 +188,7 @@ void dd::Systems::PhysicsSystem::CreateBody(EntityID entity) b2FixtureDef fixtureDef; fixtureDef.shape = pShape; fixtureDef.density = 1.f; - fixtureDef.restitution = 0.0f; + fixtureDef.restitution = 1.0f; fixtureDef.friction = 0.3f; body->CreateFixture(&fixtureDef); diff --git a/src/game/Transform/TransformSystem.cpp b/src/game/Transform/TransformSystem.cpp index c015df4..d154ab3 100644 --- a/src/game/Transform/TransformSystem.cpp +++ b/src/game/Transform/TransformSystem.cpp @@ -20,6 +20,12 @@ #include "Transform/TransformSystem.h" #include "Core/World.h" +void dd::Systems::TransformSystem::Update(double dt) +{ + + return; +} + glm::vec3 dd::Systems::TransformSystem::AbsolutePosition(EntityID entity) { glm::vec3 absPosition;