Frame needs GameFrame, TextureFrame and Viewport to work.

This commit is contained in:
PlatinumSkink
2015-09-16 16:28:49 +02:00
parent 47ad5e31ea
commit dcb23bd199
4 changed files with 194 additions and 1 deletions
+11
View File
@@ -42,6 +42,8 @@
#include "Game/CBrick.h"
#include "Game/CPad.h"
#include "GUI/Frame.h"
#include "Physics/PhysicsSystem.h"
#include "Physics/CPhysics.h"
#include "Physics/CBoxShape.h"
@@ -96,6 +98,13 @@ public:
m_World->ComponentFactory.Register<Components::PointLight>();
m_World->Initialize();
//This is frame coding which might be stupid!
m_FrameStack = new dd::Frame(m_EventBroker, m_ResourceManager);
m_FrameStack->Width = 1920;
m_FrameStack->Height = 1080;
//TODO: Remove tobias light-test code.
/*{
@@ -421,6 +430,8 @@ private:
RenderQueueCollection m_RendererQueue;
std::shared_ptr<InputManager> m_InputManager;
std::shared_ptr<World> m_World;
dd::Frame* m_FrameStack;
double m_LastTime;
};
+97
View File
@@ -0,0 +1,97 @@
//
// 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 "Events/GameOver.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, &GUI::GameFrame::OnGameStart);
EVENT_SUBSCRIBE_MEMBER(m_EGameOver, &GUI::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
+85
View File
@@ -0,0 +1,85 @@
//
// 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 GUI
{
class Viewport : public Frame
{
public:
Viewport(Frame* parent, std::string name, std::shared_ptr<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;
m_Camera = std::make_shared<Camera>(cameraComponent->FOV, cameraComponent->NearClip, cameraComponent->FarClip);
}
void Update(double dt) override
{
if (!m_TransformSystem)
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
auto transformComponent = m_World->GetComponent<Components::Transform>(m_CameraEntity);
if (!transformComponent)
return;
auto cameraComponent = m_World->GetComponent<Components::Camera>(m_CameraEntity);
if (!cameraComponent)
return;
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);
}
void Draw(std::shared_ptr<Renderer> renderer) override
{
if (!m_Camera)
return;
renderer->SetCamera(m_Camera);
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;
};
}
#endif //DAYDREAM_VIEWPORT_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/Game/CLife.h ../../include/Game/ELifeLost.h ../../include/Game/EResetBall.h ../../include/Game/EScoreEvent.h ../../include/GUI/Frame.h ../../include/GUI/MainMenuFrame.h ../../include/Game/EGameStart.h ../../include/GUI/TextureFrame.h)
${SOURCE_FILES_Game} ../../include/GUI/Viewport.h)
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")