Restored to try anew.
This commit is contained in:
@@ -42,9 +42,6 @@
|
|||||||
#include "Game/CBrick.h"
|
#include "Game/CBrick.h"
|
||||||
#include "Game/CPad.h"
|
#include "Game/CPad.h"
|
||||||
|
|
||||||
#include "GUI/Frame.h"
|
|
||||||
#include "GUI/GameFrame.h"
|
|
||||||
|
|
||||||
#include "Physics/PhysicsSystem.h"
|
#include "Physics/PhysicsSystem.h"
|
||||||
#include "Physics/CPhysics.h"
|
#include "Physics/CPhysics.h"
|
||||||
#include "Physics/CBoxShape.h"
|
#include "Physics/CBoxShape.h"
|
||||||
|
|||||||
@@ -88,10 +88,6 @@ struct SpriteJob : RenderJob
|
|||||||
unsigned int ShaderID;
|
unsigned int ShaderID;
|
||||||
unsigned int TextureID;
|
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;
|
glm::mat4 ModelMatrix;
|
||||||
GLuint DiffuseTexture;
|
GLuint DiffuseTexture;
|
||||||
GLuint NormalTexture;
|
GLuint NormalTexture;
|
||||||
|
|||||||
@@ -51,32 +51,6 @@ 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 Initialize();
|
||||||
void Draw(RenderQueueCollection& rq);
|
void Draw(RenderQueueCollection& rq);
|
||||||
|
|
||||||
@@ -90,14 +64,6 @@ private:
|
|||||||
|
|
||||||
const dd::Camera* m_Camera = 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];
|
int m_GLVersion[2];
|
||||||
std::string m_GLVendor;
|
std::string m_GLVendor;
|
||||||
GLFWwindow* m_Window = nullptr;
|
GLFWwindow* m_Window = nullptr;
|
||||||
|
|||||||
@@ -108,11 +108,6 @@ public:
|
|||||||
@param resourceName Fully qualified name of the resource to fetch.
|
@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>
|
template <typename T>
|
||||||
static T* Fetch(std::string resourceName);
|
static T* Fetch(std::string resourceName);
|
||||||
|
|
||||||
@@ -168,25 +163,6 @@ T* ResourceManager::Load(std::string resourceName, Resource* parent /* = nullptr
|
|||||||
return CreateResource<T>(resourceName, parent);
|
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>
|
template <typename T>
|
||||||
T* ResourceManager::Fetch(std::string resourceName)
|
T* ResourceManager::Fetch(std::string resourceName)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,261 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Administrator on 2015-09-16.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef DAYDREAM_FRAME_H
|
|
||||||
#define DAYDREAM_FRAME_H
|
|
||||||
|
|
||||||
namespace dd
|
|
||||||
{
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
#include "Core/Util/Rectangle.h"
|
|
||||||
#include "Core/EventBroker.h"
|
|
||||||
#include "Core/EKeyDown.h"
|
|
||||||
#include "Core/EKeyUp.h"
|
|
||||||
#include "Input/EInputCommand.h"
|
|
||||||
#include "Core/ResourceManager.h"
|
|
||||||
#include "Core/Renderer.h"
|
|
||||||
#include "Core/RenderQueue.h"
|
|
||||||
#include "Core/Texture.h"
|
|
||||||
|
|
||||||
class Frame : public Rectangle
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum class Anchor
|
|
||||||
{
|
|
||||||
Left,
|
|
||||||
Right,
|
|
||||||
Top,
|
|
||||||
Bottom
|
|
||||||
};
|
|
||||||
|
|
||||||
static const int BaseWidth = 1280;
|
|
||||||
static const int BaseHeight = 720;
|
|
||||||
|
|
||||||
// Set up a base frame with an event broker
|
|
||||||
Frame(std::shared_ptr<dd::EventBroker> eventBroker, std::shared_ptr<dd::ResourceManager> resourceManager)
|
|
||||||
: EventBroker(eventBroker)
|
|
||||||
, ResourceManager(resourceManager)
|
|
||||||
, Rectangle()
|
|
||||||
, m_Parent(nullptr)
|
|
||||||
, m_Name("UIParent")
|
|
||||||
, m_Layer(0)
|
|
||||||
, m_Hidden(false)
|
|
||||||
{ Initialize(); }
|
|
||||||
|
|
||||||
// Create a frame as a child
|
|
||||||
Frame(Frame* parent, std::string name)
|
|
||||||
: m_Name(name)
|
|
||||||
, m_Layer(0)
|
|
||||||
, m_Hidden(false)
|
|
||||||
{ SetParent(parent); Initialize(); }
|
|
||||||
|
|
||||||
~Frame()
|
|
||||||
{
|
|
||||||
/*for (auto layer : m_Children)
|
|
||||||
{
|
|
||||||
for (auto child : layer.second)
|
|
||||||
{
|
|
||||||
delete child.second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (m_Parent)
|
|
||||||
{
|
|
||||||
m_Parent->RemoveChild(this);
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
||||||
dd::RenderQueuePair RenderQueue;
|
|
||||||
|
|
||||||
Frame* Parent() const { return m_Parent; }
|
|
||||||
void SetParent(Frame* parent)
|
|
||||||
{
|
|
||||||
if (parent == nullptr)
|
|
||||||
{
|
|
||||||
LOG_ERROR("Failed to create frame \"%s\": Invalid parent", m_Name.c_str());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Width = parent->Width;
|
|
||||||
Height = parent->Height;
|
|
||||||
m_Layer = parent->Layer() + 1;
|
|
||||||
parent->AddChild(this);
|
|
||||||
m_Parent = parent;
|
|
||||||
EventBroker = parent->EventBroker;
|
|
||||||
ResourceManager = parent->ResourceManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AddChild(Frame* child)
|
|
||||||
{
|
|
||||||
m_Children[child->m_Layer].insert(std::make_pair(child->Name(), child));
|
|
||||||
if (m_Parent)
|
|
||||||
{
|
|
||||||
m_Parent->AddChild(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RemoveChild(Frame* child)
|
|
||||||
{
|
|
||||||
auto it = m_Children.find(child->m_Layer);
|
|
||||||
if (it != m_Children.end())
|
|
||||||
{
|
|
||||||
m_Children.erase(it);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_Parent)
|
|
||||||
{
|
|
||||||
m_Parent->RemoveChild(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Name() const { return m_Name; }
|
|
||||||
void SetName(std::string val) { m_Name = val; }
|
|
||||||
int Layer() const { return m_Layer; }
|
|
||||||
bool Hidden() const
|
|
||||||
{
|
|
||||||
if (m_Parent)
|
|
||||||
return m_Parent->Hidden() || m_Hidden;
|
|
||||||
else
|
|
||||||
return m_Hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Visible() const
|
|
||||||
{
|
|
||||||
return !Hidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void Hide() { m_Hidden = true; }
|
|
||||||
virtual void Show() { m_Hidden = false; }
|
|
||||||
|
|
||||||
int Left() const override
|
|
||||||
{
|
|
||||||
if (m_Parent)
|
|
||||||
return m_Parent->Left() + X;
|
|
||||||
else
|
|
||||||
return X;
|
|
||||||
}
|
|
||||||
int Right() const override
|
|
||||||
{
|
|
||||||
if (m_Parent)
|
|
||||||
return std::min(m_Parent->Right(), Left() + Width);
|
|
||||||
else
|
|
||||||
return Left() + Width;
|
|
||||||
}
|
|
||||||
int Top() const override
|
|
||||||
{
|
|
||||||
if (m_Parent)
|
|
||||||
return m_Parent->Top() + Y;
|
|
||||||
else
|
|
||||||
return Y;
|
|
||||||
}
|
|
||||||
int Bottom() const override
|
|
||||||
{
|
|
||||||
if (m_Parent)
|
|
||||||
return std::min(m_Parent->Bottom(), Top() + Height);
|
|
||||||
else
|
|
||||||
return Top() + Height;
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::vec2 Scale()
|
|
||||||
{
|
|
||||||
if (m_Parent)
|
|
||||||
return m_Parent->Scale();
|
|
||||||
else
|
|
||||||
return glm::vec2(Width, Height) / glm::vec2(BaseWidth, BaseHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle AbsoluteRectangle()
|
|
||||||
{
|
|
||||||
int left = Left();
|
|
||||||
if (m_Parent)
|
|
||||||
left = std::max(left, m_Parent->Left());
|
|
||||||
int top = Top();
|
|
||||||
if (m_Parent)
|
|
||||||
top = std::max(top, m_Parent->Top());
|
|
||||||
int width = Right() - left;
|
|
||||||
int height = Bottom() - top;
|
|
||||||
return Rectangle(left, top, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdateLayered(double dt)
|
|
||||||
{
|
|
||||||
// Update ourselves
|
|
||||||
this->Update(dt);
|
|
||||||
|
|
||||||
// Update children
|
|
||||||
for (auto &pairLayer : m_Children)
|
|
||||||
{
|
|
||||||
auto children = pairLayer.second;
|
|
||||||
for (auto &pairChild : children)
|
|
||||||
{
|
|
||||||
auto child = pairChild.second;
|
|
||||||
child->Update(dt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
virtual void Update(double dt) { }
|
|
||||||
|
|
||||||
void DrawLayered(std::shared_ptr<Renderer> renderer)
|
|
||||||
{
|
|
||||||
if (this->Hidden())
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Draw ourselves
|
|
||||||
renderer->SetScissor(AbsoluteRectangle());
|
|
||||||
this->Draw(renderer);
|
|
||||||
|
|
||||||
// Draw children
|
|
||||||
for (auto &pairLayer : m_Children)
|
|
||||||
{
|
|
||||||
auto children = pairLayer.second;
|
|
||||||
for (auto &pairChild : children)
|
|
||||||
{
|
|
||||||
auto child = pairChild.second;
|
|
||||||
if (child->Hidden())
|
|
||||||
continue;
|
|
||||||
Rectangle rect = child->AbsoluteRectangle();
|
|
||||||
renderer->SetScissor(rect);
|
|
||||||
child->Draw(renderer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void Draw(std::shared_ptr<Renderer> renderer) { }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
std::shared_ptr<EventBroker> EventBroker;
|
|
||||||
std::shared_ptr<ResourceManager> ResourceManager;
|
|
||||||
|
|
||||||
std::string m_Name;
|
|
||||||
int m_Layer;
|
|
||||||
bool m_Hidden;
|
|
||||||
|
|
||||||
Frame* m_Parent;
|
|
||||||
typedef std::multimap<std::string, Frame*> Children_t; // name -> frame
|
|
||||||
std::map<int, Children_t> m_Children; // layer -> Children_t
|
|
||||||
|
|
||||||
virtual bool OnKeyDown(const dd::Events::KeyDown &event) { return false; }
|
|
||||||
virtual bool OnKeyUp(const dd::Events::KeyUp &event) { return false; }
|
|
||||||
//virtual bool OnMouseDown(const Events::KeyDown &event) { }
|
|
||||||
//virtual bool OnMouseUp(const Events::KeyDown &event) { }
|
|
||||||
virtual bool OnCommand(const dd::Events::InputCommand &event) { return false; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
EventRelay<Frame, dd::Events::KeyDown> m_EKeyDown;
|
|
||||||
EventRelay<Frame, dd::Events::KeyUp> m_EKeyUp;
|
|
||||||
EventRelay<Frame, dd::Events::InputCommand> m_EInputCommand;
|
|
||||||
|
|
||||||
void Initialize()
|
|
||||||
{
|
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Frame::OnKeyDown);
|
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Frame::OnKeyUp);
|
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &Frame::OnCommand);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif //DAYDREAM_FRAME_H
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Administrator on 2015-09-16.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef DAYDREAM_GAMEFRAME_H
|
|
||||||
#define DAYDREAM_GAMEFRAME_H
|
|
||||||
|
|
||||||
#include "GUI/Frame.h"
|
|
||||||
#include "GUI/MainMenuFrame.h"
|
|
||||||
//#include "GUI/WorldFrame.h"
|
|
||||||
#include "GUI/Viewport.h"
|
|
||||||
#include "GUI/TextureFrame.h"
|
|
||||||
//#include "GUI/PlayerHUD.h"
|
|
||||||
|
|
||||||
//#include "GameWorld.h"
|
|
||||||
#include "Game/EGameStart.h"
|
|
||||||
#include "Game/EGameOver.h"
|
|
||||||
//#include "Events/Dead.h"
|
|
||||||
|
|
||||||
namespace dd
|
|
||||||
{
|
|
||||||
|
|
||||||
class GameFrame : public Frame
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
GameFrame(Frame* parent, std::string name)
|
|
||||||
: Frame(parent, name)
|
|
||||||
, m_GameOver(false)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
{
|
|
||||||
vp1 = new Viewport(m_WorldFrame, "Viewport1", m_World);
|
|
||||||
vp1->X = 0;
|
|
||||||
vp1->Width = this->Width / 2.f;
|
|
||||||
new PlayerHUD(vp1, "PlayerHUD", m_World, 1);
|
|
||||||
|
|
||||||
vp2 = new Viewport(m_WorldFrame, "Viewport2", m_World);
|
|
||||||
vp2->X = vp1->Right();
|
|
||||||
vp2->Width = this->Width / 2.f;
|
|
||||||
new PlayerHUD(vp2, "PlayerHUD", m_World, 2);
|
|
||||||
|
|
||||||
m_FreeCamViewport = new Viewport(m_WorldFrame, "ViewportFreeCam", m_World);
|
|
||||||
m_FreeCamViewport->Hide();
|
|
||||||
}*/
|
|
||||||
//m_WorldFrame->Hide();
|
|
||||||
//m_World->Initialize();
|
|
||||||
|
|
||||||
m_MainMenuFrame = new MainMenuFrame(this, "MainMenu");
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
EventRelay<Frame, dd::Events::GameStart> m_EGameStart;
|
|
||||||
bool OnGameStart(const dd::Events::GameStart &event)
|
|
||||||
{
|
|
||||||
//m_WorldFrame->Show();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
EventRelay<Frame, Events::GameOver> m_EGameOver;
|
|
||||||
bool OnGameOver(const Events::GameOver &event)
|
|
||||||
{
|
|
||||||
m_GameOver = true;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//std::shared_ptr<GameWorld> m_World;
|
|
||||||
|
|
||||||
MainMenuFrame* m_MainMenuFrame;
|
|
||||||
//WorldFrame* m_WorldFrame;
|
|
||||||
//Viewport* vp1;
|
|
||||||
//Viewport* vp2;
|
|
||||||
//Viewport* m_FreeCamViewport;
|
|
||||||
|
|
||||||
bool m_GameOver;
|
|
||||||
|
|
||||||
bool OnKeyUp(const dd::Events::KeyUp &event) override
|
|
||||||
{
|
|
||||||
if (event.KeyCode == GLFW_KEY_1)
|
|
||||||
{
|
|
||||||
/*if (m_FreeCamViewport->Hidden())
|
|
||||||
m_FreeCamViewport->Show();
|
|
||||||
else
|
|
||||||
m_FreeCamViewport->Hide();*/
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif //DAYDREAM_GAMEFRAME_H
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Administrator on 2015-09-16.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef DAYDREAM_MAINMENUFRAME_H
|
|
||||||
#define DAYDREAM_MAINMENUFRAME_H
|
|
||||||
|
|
||||||
#include "GUI/Frame.h"
|
|
||||||
#include "GUI/TextureFrame.h"
|
|
||||||
//#include "GUI/HealthOverlay.h"
|
|
||||||
|
|
||||||
#include "Game/EGameStart.h"
|
|
||||||
//#include "Events/PlayBGM.h"
|
|
||||||
|
|
||||||
namespace dd
|
|
||||||
{
|
|
||||||
|
|
||||||
class MainMenuFrame : public Frame
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
MainMenuFrame(Frame* parent, std::string name)
|
|
||||||
: Frame(parent, name)
|
|
||||||
{
|
|
||||||
m_CurrentSelection = 0;
|
|
||||||
|
|
||||||
//Hide();
|
|
||||||
m_Background = new TextureFrame(this, "Background");
|
|
||||||
m_Background->SetTexture("Textures/GUI/MainMenu/BackGround.png");
|
|
||||||
|
|
||||||
m_Buttons = new TextureFrame(this, "Message");
|
|
||||||
m_Buttons->SetTexture("Textures/GUI/MainMenu/Buttons.png");
|
|
||||||
m_CurrentCoordinate = -m_SelectionCoordinates[0] * Scale();
|
|
||||||
m_TargetCoordinate = m_CurrentCoordinate;
|
|
||||||
m_Buttons->X = m_CurrentCoordinate.x;
|
|
||||||
m_Buttons->Y = m_CurrentCoordinate.y;
|
|
||||||
|
|
||||||
/*Events::PlayBGM e;
|
|
||||||
e.Resource = "Sounds/BGM/DiesIrae.mp3";
|
|
||||||
EventBroker->Publish(e);*/
|
|
||||||
}
|
|
||||||
|
|
||||||
void Update(double dt) override
|
|
||||||
{
|
|
||||||
if (Hidden())
|
|
||||||
return;
|
|
||||||
|
|
||||||
glm::vec2 posDiff = m_TargetCoordinate - m_CurrentCoordinate;
|
|
||||||
m_CurrentCoordinate += posDiff * 4.f * (float)dt;
|
|
||||||
|
|
||||||
m_Buttons->X = m_CurrentCoordinate.x;
|
|
||||||
m_Buttons->Y = m_CurrentCoordinate.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool m_Victory;
|
|
||||||
TextureFrame* m_Background;
|
|
||||||
TextureFrame* m_Buttons;
|
|
||||||
|
|
||||||
int m_CurrentSelection;
|
|
||||||
static glm::vec2 m_SelectionCoordinates[2];
|
|
||||||
glm::vec2 m_CurrentCoordinate;
|
|
||||||
glm::vec2 m_TargetCoordinate;
|
|
||||||
|
|
||||||
bool OnCommand(const Events::InputCommand &event) override
|
|
||||||
{
|
|
||||||
if (Hidden())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const float deadzone = 0.5f;
|
|
||||||
|
|
||||||
if (event.Command == "interface_horizontal")
|
|
||||||
{
|
|
||||||
if (event.Value > deadzone)
|
|
||||||
m_CurrentSelection++;
|
|
||||||
else if (event.Value < -deadzone)
|
|
||||||
m_CurrentSelection--;
|
|
||||||
}
|
|
||||||
m_CurrentSelection = (m_CurrentSelection < 0) ? 0 : ((m_CurrentSelection > 1) ? 1 : m_CurrentSelection);
|
|
||||||
m_TargetCoordinate = -m_SelectionCoordinates[m_CurrentSelection] * Scale();
|
|
||||||
|
|
||||||
if (event.Command == "interface_confirm" && event.Value > 0)
|
|
||||||
{
|
|
||||||
// Play
|
|
||||||
if (m_CurrentSelection == 0)
|
|
||||||
{
|
|
||||||
Hide();
|
|
||||||
Events::GameStart e1;
|
|
||||||
EventBroker->Publish(e1);
|
|
||||||
/*Events::PlayBGM e2;
|
|
||||||
e2.Resource = "Sounds/BGM/FlightOfTheBumblebee.mp3";
|
|
||||||
EventBroker->Publish(e2);*/
|
|
||||||
}
|
|
||||||
// Quit
|
|
||||||
else if (m_CurrentSelection == 1)
|
|
||||||
{
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
glm::vec2 MainMenuFrame::m_SelectionCoordinates[2] = {
|
|
||||||
glm::vec2(0, 0),
|
|
||||||
glm::vec2(193, 0),
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif //DAYDREAM_MAINMENUFRAME_H
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Administrator on 2015-09-16.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef DAYDREAM_TEXTUREFRAME_H
|
|
||||||
#define DAYDREAM_TEXTUREFRAME_H
|
|
||||||
|
|
||||||
#include "GUI/Frame.h"
|
|
||||||
#include "Core/Texture.h"
|
|
||||||
|
|
||||||
namespace dd
|
|
||||||
{
|
|
||||||
|
|
||||||
class TextureFrame : public Frame {
|
|
||||||
public:
|
|
||||||
TextureFrame(Frame *parent, std::string name)
|
|
||||||
: Frame(parent, name), m_Texture(nullptr), m_FadeTexture(nullptr),
|
|
||||||
m_Color(glm::vec4(1.f, 1.f, 1.f, 1.f)), m_FadeDuration(0.f), m_CurrentFade(1.f) { }
|
|
||||||
|
|
||||||
void Draw(std::shared_ptr<Renderer> renderer) override {
|
|
||||||
if (m_Texture == nullptr)
|
|
||||||
return;
|
|
||||||
|
|
||||||
RenderQueue.Clear();
|
|
||||||
|
|
||||||
// Main texture
|
|
||||||
{
|
|
||||||
SpriteJob job;
|
|
||||||
job.TextureID = m_Texture->ResourceID;
|
|
||||||
job.Texture = *m_Texture;
|
|
||||||
job.Color = glm::vec4(m_Color.r, m_Color.g, m_Color.b, m_Color.a * m_CurrentFade);
|
|
||||||
RenderQueue.Forward.Add(job);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Texture while fading
|
|
||||||
if (m_FadeTexture && m_CurrentFade < 1) {
|
|
||||||
SpriteJob job;
|
|
||||||
job.TextureID = m_FadeTexture->ResourceID;
|
|
||||||
job.Texture = *m_FadeTexture;
|
|
||||||
job.Color = glm::vec4(m_Color.r, m_Color.g, m_Color.b, m_Color.a);
|
|
||||||
RenderQueue.Forward.Add(job);
|
|
||||||
}
|
|
||||||
|
|
||||||
renderer->SetCamera(nullptr);
|
|
||||||
renderer->SetViewport(Rectangle(Left(), Top(), Width, Height));
|
|
||||||
renderer->DrawFrame(RenderQueue);
|
|
||||||
}
|
|
||||||
|
|
||||||
Texture *Texture() const { return m_Texture; }
|
|
||||||
|
|
||||||
void SetTexture(std::string resourceName) {
|
|
||||||
m_Texture = ResourceManager->Load<dd::Texture>("Texture", resourceName);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FadeToTexture(std::string resourceName, double duration) {
|
|
||||||
m_FadeTexture = m_Texture;
|
|
||||||
SetTexture(resourceName);
|
|
||||||
m_FadeDuration = duration;
|
|
||||||
m_CurrentFade = 0.f;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Update(double dt) override {
|
|
||||||
if (m_CurrentFade < 1) {
|
|
||||||
m_CurrentFade += dt / m_FadeDuration;
|
|
||||||
if (m_CurrentFade > 1) {
|
|
||||||
m_FadeTexture = nullptr;
|
|
||||||
m_CurrentFade = 1;
|
|
||||||
m_FadeDuration = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::vec4 Color() const { return m_Color; }
|
|
||||||
|
|
||||||
void SetColor(glm::vec4 val) { m_Color = val; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
dd::Texture *m_Texture;
|
|
||||||
dd::Texture *m_FadeTexture;
|
|
||||||
glm::vec4 m_Color;
|
|
||||||
float m_FadeDuration;
|
|
||||||
float m_CurrentFade;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif //DAYDREAM_TEXTUREFRAME_H
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Administrator on 2015-09-16.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef DAYDREAM_VIEWPORT_H
|
|
||||||
#define DAYDREAM_VIEWPORT_H
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include "GUI/Frame.h"
|
|
||||||
#include "Core/World.h"
|
|
||||||
#include "Transform/TransformSystem.h"
|
|
||||||
#include "Core/CTransform.h"
|
|
||||||
#include "Rendering/CCamera.h"
|
|
||||||
#include "Core/RenderQueue.h"
|
|
||||||
#include "Core/Camera.h"
|
|
||||||
|
|
||||||
namespace dd
|
|
||||||
{
|
|
||||||
|
|
||||||
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<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<dd::Systems::TransformSystem>();
|
|
||||||
|
|
||||||
auto transformComponent = m_World->GetComponent<dd::Components::Transform>(m_CameraEntity);
|
|
||||||
if (!transformComponent)
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto cameraComponent = m_World->GetComponent<dd::Components::Camera>(m_CameraEntity);
|
|
||||||
if (!cameraComponent)
|
|
||||||
return;
|
|
||||||
|
|
||||||
dd::Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(m_CameraEntity);
|
|
||||||
|
|
||||||
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<dd::Renderer> renderer) override {
|
|
||||||
if (!m_FrameCamera)
|
|
||||||
return;
|
|
||||||
|
|
||||||
renderer->SetCamera(m_FrameCamera);
|
|
||||||
renderer->SetViewport(AbsoluteRectangle());
|
|
||||||
renderer->DrawWorld(m_Parent->RenderQueue);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif //DAYDREAM_VIEWPORT_H
|
|
||||||
@@ -464,103 +464,3 @@ void dd::Renderer::DebugKeys()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//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
|
|
||||||
|
|
||||||
|
|||||||
@@ -83,25 +83,3 @@ void dd::ResourceManager::Update()
|
|||||||
{
|
{
|
||||||
m_FileWatcher.Check();
|
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
|
|
||||||
|
|||||||
Reference in New Issue
Block a user