Didn't work. Let's try again.

This commit is contained in:
PlatinumSkink
2015-09-17 15:28:57 +02:00
parent dcb23bd199
commit b3335cff05
12 changed files with 304 additions and 78 deletions
+11 -7
View File
@@ -43,6 +43,7 @@
#include "Game/CPad.h"
#include "GUI/Frame.h"
#include "GUI/GameFrame.h"
#include "Physics/PhysicsSystem.h"
#include "Physics/CPhysics.h"
@@ -103,7 +104,7 @@ public:
m_FrameStack->Width = 1920;
m_FrameStack->Height = 1080;
new dd::GameFrame(m_FrameStack, "GameFrame");
//TODO: Remove tobias light-test code.
@@ -159,14 +160,15 @@ public:
sprite->SpecularTexture = "Textures/Test/Brick_Specular.png";
}
// Top Wall
{
auto topWall = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(topWall);
transform->Position = glm::vec3(0.f, 6.f, -10.f);
transform->Scale = glm::vec3(18.f, 0.5f, 1.f);
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
//std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
//sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(topWall);
@@ -175,14 +177,15 @@ public:
m_World->CommitEntity(topWall);
}
// Left Wall
{
auto leftWall = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(leftWall);
transform->Position = glm::vec3(-9.f, 1.f, -10.f);
transform->Scale = glm::vec3(0.5f, 10.f, 1.f);
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(leftWall);
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
//std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(leftWall);
//sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(leftWall);
@@ -191,14 +194,15 @@ public:
m_World->CommitEntity(leftWall);
}
// Right Wall.
{
auto rightWall = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(rightWall);
transform->Position = glm::vec3(9.f, 1.f, -10.f);
transform->Scale = glm::vec3(0.5f, 10.f, 1.f);
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(rightWall);
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
//std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(rightWall);
//sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(rightWall);
+21
View File
@@ -88,6 +88,10 @@ struct SpriteJob : RenderJob
unsigned int ShaderID;
unsigned int TextureID;
//Niklas is trying to get Frames to work.
GLuint Texture;
//Niklas is trying to get Frames to work./end
glm::mat4 ModelMatrix;
GLuint DiffuseTexture;
GLuint NormalTexture;
@@ -167,6 +171,23 @@ struct RenderQueueCollection
}
};
struct RenderQueuePair
{
RenderQueue Deferred;
RenderQueue Forward;
void Clear() {
Deferred.Clear();
Forward.Clear();
}
void Sort() {
Deferred.Sort();
Forward.Sort();
}
};
}
#endif // RenderQueue_h__
+35
View File
@@ -51,6 +51,32 @@ public:
}
}
//Niklas is trying to implement Frames.
std::shared_ptr<dd::Camera> GetCamera() const { return m_FrameCamera; }
void SetCamera(const std::shared_ptr<dd::Camera> camera)
{
m_FrameCamera = camera;
}
void DrawFrame(RenderQueuePair &rq);
void DrawWorld(RenderQueuePair &rq);
void SetViewport(const Rectangle &viewport)
{
m_Viewport = viewport;
}
void SetScissor(const Rectangle &scissor)
{
m_Scissor = scissor;
}
int Width() const { return m_Width; }
int Height() const { return m_Height; }
//Niklas is trying to implement Frames.
void Initialize();
void Draw(RenderQueueCollection& rq);
@@ -61,8 +87,17 @@ private:
//Rectangle m_Viewport;
//Rectangle m_Scissor;
std::unique_ptr<dd::Camera> m_DefaultCamera = nullptr;
const dd::Camera* m_Camera = nullptr;
//Niklas is trying to implement Frames.
std::shared_ptr<dd::Camera> m_FrameCamera;
Rectangle m_Viewport;
Rectangle m_Scissor;
ShaderProgram m_ForwardRendering;
int m_Width = 1980, m_Height = 1080;
//Niklas is trying to implement Frames./end
int m_GLVersion[2];
std::string m_GLVendor;
GLFWwindow* m_Window = nullptr;
+26
View File
@@ -107,6 +107,12 @@ public:
@tparam T Resource type.
@param resourceName Fully qualified name of the resource to fetch.
*/
//Niklas is trying to get frames to work.
template <typename T>
T* Load(std::string resourceType, std::string resourceName);
//Niklas is trying to get frames to work./end
template <typename T>
static T* Fetch(std::string resourceName);
@@ -142,6 +148,7 @@ private:
// Internal: Create a resource and cache it
template <typename T>
static T* CreateResource(std::string resourceName, Resource* parent);
Resource* CreateResource(std::string resourceType, std::string resourceName);
};
template <typename T>
@@ -161,6 +168,25 @@ T* ResourceManager::Load(std::string resourceName, Resource* parent /* = nullptr
return CreateResource<T>(resourceName, parent);
}
//Niklas is trying to get frames to work.
template <typename T>
T* ResourceManager::Load(std::string resourceType, std::string resourceName)
{
auto it = m_ResourceCache.find(std::make_pair(resourceType, resourceName));
if (it != m_ResourceCache.end())
return static_cast<T *>(it->second);
if (m_Preloading) {
LOG_INFO("Preloading resource \"%s\"", resourceName.c_str());
}
else {
LOG_WARNING("Hot-loading resource \"%s\"", resourceName.c_str());
}
return static_cast<T *>(CreateResource(resourceType, resourceName));
}
//Niklas is trying to get frames to work./end
template <typename T>
T* ResourceManager::Fetch(std::string resourceName)
{
+1 -1
View File
@@ -11,7 +11,7 @@ namespace dd
#include <memory>
#include <map>
#include "Util/Rectangle.h"
#include "Core/Util/Rectangle.h"
#include "Core/EventBroker.h"
#include "Core/EKeyDown.h"
#include "Core/EKeyUp.h"
+14 -14
View File
@@ -8,13 +8,13 @@
#include "GUI/Frame.h"
#include "GUI/MainMenuFrame.h"
//#include "GUI/WorldFrame.h"
//#include "GUI/Viewport.h"
#include "GUI/Viewport.h"
#include "GUI/TextureFrame.h"
//#include "GUI/PlayerHUD.h"
//#include "GameWorld.h"
#include "Game/EGameStart.h"
//#include "Events/GameOver.h"
#include "Game/EGameOver.h"
//#include "Events/Dead.h"
namespace dd
@@ -27,8 +27,8 @@ namespace dd
: Frame(parent, name)
, m_GameOver(false)
{
EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &GUI::GameFrame::OnGameStart);
EVENT_SUBSCRIBE_MEMBER(m_EGameOver, &GUI::GameFrame::OnGameOver);
EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &dd::GameFrame::OnGameStart);
EVENT_SUBSCRIBE_MEMBER(m_EGameOver, &dd::GameFrame::OnGameOver);
//m_World = std::make_shared<GameWorld>(EventBroker, ResourceManager);
/*m_WorldFrame = new WorldFrame(this, "GameWorldFrame", m_World);
@@ -46,8 +46,8 @@ namespace dd
m_FreeCamViewport = new Viewport(m_WorldFrame, "ViewportFreeCam", m_World);
m_FreeCamViewport->Hide();
}*/
m_WorldFrame->Hide();
m_World->Initialize();
//m_WorldFrame->Hide();
//m_World->Initialize();
m_MainMenuFrame = new MainMenuFrame(this, "MainMenu");
}
@@ -56,11 +56,11 @@ namespace dd
EventRelay<Frame, dd::Events::GameStart> m_EGameStart;
bool OnGameStart(const dd::Events::GameStart &event)
{
m_WorldFrame->Show();
//m_WorldFrame->Show();
return true;
}
/*EventRelay<Frame, Events::GameOver> m_EGameOver;
EventRelay<Frame, Events::GameOver> m_EGameOver;
bool OnGameOver(const Events::GameOver &event)
{
m_GameOver = true;
@@ -68,15 +68,15 @@ namespace dd
return true;
}
std::shared_ptr<GameWorld> m_World;
//std::shared_ptr<GameWorld> m_World;
MainMenuFrame* m_MainMenuFrame;
WorldFrame* m_WorldFrame;
Viewport* vp1;
Viewport* vp2;
Viewport* m_FreeCamViewport;
//WorldFrame* m_WorldFrame;
//Viewport* vp1;
//Viewport* vp2;
//Viewport* m_FreeCamViewport;
bool m_GameOver;*/
bool m_GameOver;
bool OnKeyUp(const dd::Events::KeyUp &event) override
{
+3 -3
View File
@@ -49,7 +49,7 @@ public:
Texture *Texture() const { return m_Texture; }
void SetTexture(std::string resourceName) {
m_Texture = ResourceManager->Load<::Texture>("Texture", resourceName);
m_Texture = ResourceManager->Load<dd::Texture>("Texture", resourceName);
}
void FadeToTexture(std::string resourceName, double duration) {
@@ -75,8 +75,8 @@ public:
void SetColor(glm::vec4 val) { m_Color = val; }
protected:
Texture *m_Texture;
Texture *m_FadeTexture;
dd::Texture *m_Texture;
dd::Texture *m_FadeTexture;
glm::vec4 m_Color;
float m_FadeDuration;
float m_CurrentFade;
+47 -51
View File
@@ -15,70 +15,66 @@
#include "Core/RenderQueue.h"
#include "Core/Camera.h"
namespace GUI
namespace dd
{
class Viewport : public Frame
{
public:
Viewport(Frame* parent, std::string name, std::shared_ptr<World> world)
: Frame(parent, name)
, m_World(world)
{ }
class Viewport : public Frame
{
public:
Viewport(Frame *parent, std::string name, std::shared_ptr<dd::World> world)
: Frame(parent, name), m_World(world) { }
EntityID CameraEntity() const { return m_CameraEntity; }
void SetCameraEntity(EntityID cameraEntity)
{
m_CameraEntity = cameraEntity;
auto transformComponent = m_World->GetComponent<Components::Transform>(cameraEntity);
if (!transformComponent)
return;
auto cameraComponent = m_World->GetComponent<Components::Camera>(cameraEntity);
if (!cameraComponent)
return;
EntityID CameraEntity() const { return m_CameraEntity; }
m_Camera = std::make_shared<Camera>(cameraComponent->FOV, cameraComponent->NearClip, cameraComponent->FarClip);
}
void SetCameraEntity(EntityID cameraEntity) {
m_CameraEntity = cameraEntity;
auto transformComponent = m_World->GetComponent<dd::Components::Transform>(cameraEntity);
if (!transformComponent)
return;
auto cameraComponent = m_World->GetComponent<dd::Components::Camera>(cameraEntity);
if (!cameraComponent)
return;
m_FrameCamera = std::make_shared<dd::Camera>(cameraComponent->FOV, cameraComponent->NearClip, cameraComponent->FarClip);
}
void Update(double dt) override
{
if (!m_TransformSystem)
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
void Update(double dt) override {
if (!m_TransformSystem)
m_TransformSystem = m_World->GetSystem<dd::Systems::TransformSystem>();
auto transformComponent = m_World->GetComponent<Components::Transform>(m_CameraEntity);
if (!transformComponent)
return;
auto transformComponent = m_World->GetComponent<dd::Components::Transform>(m_CameraEntity);
if (!transformComponent)
return;
auto cameraComponent = m_World->GetComponent<Components::Camera>(m_CameraEntity);
if (!cameraComponent)
return;
auto cameraComponent = m_World->GetComponent<dd::Components::Camera>(m_CameraEntity);
if (!cameraComponent)
return;
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(m_CameraEntity);
dd::Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(m_CameraEntity);
m_Camera->SetFOV(cameraComponent->FOV);
m_Camera->SetNearClip(cameraComponent->NearClip);
m_Camera->SetFarClip(cameraComponent->FarClip);
m_Camera->SetPosition(absoluteTransform.Position);
m_Camera->SetOrientation(absoluteTransform.Orientation);
}
m_FrameCamera->SetFOV(cameraComponent->FOV);
m_FrameCamera->SetNearClip(cameraComponent->NearClip);
m_FrameCamera->SetFarClip(cameraComponent->FarClip);
m_FrameCamera->SetPosition(absoluteTransform.Position);
m_FrameCamera->SetOrientation(absoluteTransform.Orientation);
}
void Draw(std::shared_ptr<Renderer> renderer) override
{
if (!m_Camera)
return;
void Draw(std::shared_ptr<dd::Renderer> renderer) override {
if (!m_FrameCamera)
return;
renderer->SetCamera(m_Camera);
renderer->SetViewport(AbsoluteRectangle());
renderer->DrawWorld(m_Parent->RenderQueue);
}
renderer->SetCamera(m_FrameCamera);
renderer->SetViewport(AbsoluteRectangle());
renderer->DrawWorld(m_Parent->RenderQueue);
}
private:
std::shared_ptr<World> m_World;
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
std::shared_ptr<Camera> m_Camera;
EntityID m_CameraEntity;
};
private:
std::shared_ptr<dd::World> m_World;
std::shared_ptr<dd::Systems::TransformSystem> m_TransformSystem;
std::shared_ptr<dd::Camera> m_FrameCamera;
EntityID m_CameraEntity;
};
}
+21
View File
@@ -0,0 +1,21 @@
//
// Created by Administrator on 2015-09-17.
//
#ifndef DAYDREAM_EGAMEOVER_H
#define DAYDREAM_EGAMEOVER_H
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct GameOver : Event
{
};
}
}
#endif //DAYDREAM_EGAMEOVER_H
+1 -1
View File
@@ -75,7 +75,7 @@ set(SOURCE_FILES
${SOURCE_FILES_Rendering}
${SOURCE_FILES_Transform}
${SOURCE_FILES_Physics}
${SOURCE_FILES_Game} ../../include/GUI/Viewport.h)
${SOURCE_FILES_Game} ../../include/Game/EGameOver.h)
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
+101
View File
@@ -463,3 +463,104 @@ void dd::Renderer::DebugKeys()
m_CurrentScreenBuffer = m_tLighting;
}
}
//Niklas is trying to get frames to work.
void dd::Renderer::DrawFrame(RenderQueuePair &rq)
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glScissor(m_Scissor.X, m_Height - m_Scissor.Y - m_Scissor.Height, m_Scissor.Width, m_Scissor.Height);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glClearColor(0.0f, 0.5f, 0.0f, 1.0f);
glEnable(GL_SCISSOR_TEST);
glDisable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix((float)m_Width / m_Height) * m_Camera->ViewMatrix();
//glm::mat4 MVP;
m_ForwardRendering.Bind();
//for (auto tuple : ModelsToRender) //// Todo: Add so it's TransparentModelsToRender
//{
// Model* model;
// glm::mat4 modelMatrix;
// bool visible;
// std::tie(model, modelMatrix, visible, std::ignore) = tuple;
// if (!visible)
// continue;
// MVP = cameraMatrix * modelMatrix;
// glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
// glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
// glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
// glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix((float)m_Width / m_Height)));
// glBindVertexArray(model->VAO);
// for (auto texGroup : model->TextureGroups)
// {
// glActiveTexture(GL_TEXTURE0);
// glBindTexture(GL_TEXTURE_2D, *texGroup.Texture);
// glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1);
// }
//}
for (auto &job : rq.Forward)
{
//auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
//if (modelJob)
//{
// glm::mat4 modelMatrix = modelJob->ModelMatrix;
// MVP = cameraMatrix * modelMatrix;
// depthMVP = depthCameraMatrix * modelMatrix;
// glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
// glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP));
// glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
// glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
// glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection));
// //glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "SunDirection_cameraspace"), 1, glm::value_ptr(sunDirection_cameraview));
// glBindVertexArray(modelJob->VAO);
// glActiveTexture(GL_TEXTURE0);
// glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture);
// if (modelJob->NormalTexture != 0)
// {
// glActiveTexture(GL_TEXTURE2);
// glBindTexture(GL_TEXTURE_2D, modelJob->NormalTexture);
// }
// if (modelJob->SpecularTexture)
// {
// glActiveTexture(GL_TEXTURE3);
// glBindTexture(GL_TEXTURE_2D, modelJob->SpecularTexture);
// }
// glDrawArrays(GL_TRIANGLES, modelJob->StartIndex, modelJob->EndIndex - modelJob->StartIndex + 1);
// continue;
//}
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
if (spriteJob)
{
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(glm::mat4()));
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(glm::mat4()));
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(glm::mat4()));
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(glm::mat4()));
glUniform4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "Color"), 1, glm::value_ptr(spriteJob->Color));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, spriteJob->Texture);
glBindVertexArray(m_ScreenQuad);
glDrawArrays(GL_TRIANGLES, 0, 6);
continue;
}
}
}
//Niklas is trying to get frames to work./end
+23 -1
View File
@@ -82,4 +82,26 @@ void dd::ResourceManager::fileWatcherCallback(std::string path, FileWatcher::Fil
void dd::ResourceManager::Update()
{
m_FileWatcher.Check();
}
}
//Niklas is trying to get frames to work.
dd::Resource* dd::ResourceManager::CreateResource(std::string resourceType, std::string resourceName)
{
auto facIt = m_FactoryFunctions.find(resourceType);
if (facIt == m_FactoryFunctions.end())
{
LOG_ERROR("Failed to load resource \"%s\" of type \"%s\": Type not registered", resourceName.c_str(), resourceType.c_str());
return nullptr;
}
// Call the factory function
Resource* resource = facIt->second(resourceName);
// Store IDs
resource->TypeID = GetTypeID(resourceType);
resource->ResourceID = GetNewResourceID(resource->TypeID);
// Cache
m_ResourceCache[std::make_pair(resourceType, resourceName)] = resource;
return resource;
}
//Niklas is trying to get frames to work./end