Engine puzzle completed
This commit is contained in:
@@ -34,6 +34,7 @@ foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
|
||||
endforeach(OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES)
|
||||
|
||||
include(cotire)
|
||||
add_subdirectory(src/Engine)
|
||||
add_subdirectory(src/Game)
|
||||
add_subdirectory(src/Tests)
|
||||
|
||||
+3809
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "Core/Util/Logging.h"
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/ini_parser.hpp>
|
||||
|
||||
#include "../Common.h"
|
||||
#include "ResourceManager.h"
|
||||
|
||||
class ConfigFile : public Resource
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef Events_GamepadAxis_h__
|
||||
#define Events_GamepadAxis_h__
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
#include "EventBroker.h"
|
||||
|
||||
namespace Gamepad
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef Events_GamepadButton_h__
|
||||
#define Events_GamepadButton_h__
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
#include "EventBroker.h"
|
||||
|
||||
namespace Gamepad
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef Events_KeyDown_h__
|
||||
#define Events_KeyDown_h__
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
#include "EventBroker.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef Events_KeyUp_h__
|
||||
#define Events_KeyUp_h__
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
#include "EventBroker.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef Events_LockMouse_h__
|
||||
#define Events_LockMouse_h__
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
#include "EventBroker.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef Events_MouseMove_h__
|
||||
#define Events_MouseMove_h__
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
#include "EventBroker.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef Events_MousePress_h__
|
||||
#define Events_MousePress_h__
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
#include "EventBroker.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef Events_MouseRelease_h__
|
||||
#define Events_MouseRelease_h__
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
#include "EventBroker.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
@@ -3,16 +3,15 @@
|
||||
|
||||
#include <typeinfo>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <list>
|
||||
#include <tuple>
|
||||
|
||||
#include "../Common.h"
|
||||
#include "Event.h"
|
||||
|
||||
#define EVENT_SUBSCRIBE_MEMBER(relay, handler) \
|
||||
relay = decltype(relay)(std::bind(handler, this, std::placeholders::_1)); \
|
||||
EventBroker->Subscribe(relay);
|
||||
m_EventBroker->Subscribe(relay);
|
||||
|
||||
class EventBroker;
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#ifndef InputController_h__
|
||||
#define InputController_h__
|
||||
|
||||
#include <memory>
|
||||
#include "../Common.h"
|
||||
|
||||
#include "EventBroker.h"
|
||||
#include "EMouseMove.h"
|
||||
#include "Input/EInputCommand.h"
|
||||
#include "../Input/EInputCommand.h"
|
||||
|
||||
template <typename EventContext>
|
||||
class InputController
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
#define InputManager_h__
|
||||
|
||||
#include <array>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
#include "../Common.h"
|
||||
#include "EventBroker.h"
|
||||
#include "EKeyDown.h"
|
||||
#include "EKeyUp.h"
|
||||
#include "EMousePress.h"
|
||||
@@ -16,9 +18,9 @@
|
||||
class InputManager
|
||||
{
|
||||
public:
|
||||
InputManager(GLFWwindow* window, std::shared_ptr<::EventBroker> eventBroker)
|
||||
InputManager(GLFWwindow* window, EventBroker* eventBroker)
|
||||
: m_GLFWWindow(window)
|
||||
, EventBroker(eventBroker)
|
||||
, m_EventBroker(eventBroker)
|
||||
, m_CurrentKeyState()
|
||||
, m_LastKeyState()
|
||||
, m_CurrentMouseState()
|
||||
@@ -37,7 +39,7 @@ public:
|
||||
|
||||
private:
|
||||
GLFWwindow* m_GLFWWindow;
|
||||
std::shared_ptr<::EventBroker> EventBroker;
|
||||
EventBroker* m_EventBroker;
|
||||
|
||||
EventRelay<InputManager, Events::LockMouse> m_ELockMouse;
|
||||
bool OnLockMouse(const Events::LockMouse &event);
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
#ifndef ResourceManager_h__
|
||||
#define ResourceManager_h__
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <fstream>
|
||||
|
||||
#include "../Common.h"
|
||||
#include "Util/UnorderedMapPair.h"
|
||||
#include "Util/FileWatcher.h"
|
||||
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
#ifndef BoostPathHash_h__
|
||||
#define BoostPathHash_h__
|
||||
|
||||
struct BoostPathHash
|
||||
namespace std
|
||||
{
|
||||
template <typename T>
|
||||
std::size_t operator()(const boost::filesystem::path& p) const
|
||||
template<> struct hash<boost::filesystem::path>
|
||||
{
|
||||
return boost::filesystem::hash_value(p);
|
||||
}
|
||||
};
|
||||
size_t operator()(const boost::filesystem::path& p) const
|
||||
{
|
||||
return boost::filesystem::hash_value(p);
|
||||
}
|
||||
};
|
||||
}
|
||||
//struct BoostPathHash
|
||||
//{
|
||||
//
|
||||
// template <typename T>
|
||||
// std::size_t operator()(const boost::filesystem::path& p) const
|
||||
// {
|
||||
// return boost::filesystem::hash_value(p);
|
||||
// }
|
||||
//};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -58,8 +58,8 @@ private:
|
||||
std::time_t Timestamp;
|
||||
};
|
||||
|
||||
std::unordered_map<boost::filesystem::path, FileEventCallback_t, BoostPathHash> m_FileCallbacks;
|
||||
std::unordered_map<boost::filesystem::path, FileInfo, BoostPathHash> m_FileInfo;
|
||||
std::unordered_map<boost::filesystem::path, FileEventCallback_t> m_FileCallbacks;
|
||||
std::unordered_map<boost::filesystem::path, FileInfo> m_FileInfo;
|
||||
boost::mutex m_Mutex;
|
||||
|
||||
FileInfo GetFileInfo(boost::filesystem::path path);
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
#ifndef Rectangle_h__
|
||||
#define Rectangle_h__
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
struct Rectangle
|
||||
{
|
||||
Rectangle()
|
||||
: X(0), Y(0), Width(0), Height(0) { }
|
||||
|
||||
Rectangle(int width, int height)
|
||||
: X(0), Y(0), Width(width), Height(height) { }
|
||||
|
||||
Rectangle(int x, int y, int width, int height)
|
||||
: X(x), Y(y), Width(width), Height(height) { }
|
||||
|
||||
/*Rectangle(const Rectangle &rect)
|
||||
: X(rect.X), Y(rect.Y), Width(rect.Width), Height(rect.Height) { }*/
|
||||
|
||||
int X;
|
||||
int Y;
|
||||
int Width;
|
||||
int Height;
|
||||
|
||||
virtual int Left() const { return X; }
|
||||
virtual void SetLeft(int left)
|
||||
{
|
||||
//Width += X - left;
|
||||
X = left;
|
||||
}
|
||||
virtual int Right() const { return X + Width; }
|
||||
virtual void SetRight(int right)
|
||||
{
|
||||
Width = right - X;
|
||||
}
|
||||
virtual int Top() const { return Y; }
|
||||
virtual void SetTop(int top)
|
||||
{
|
||||
//Height += Y - top;
|
||||
Y = top;
|
||||
}
|
||||
virtual int Bottom() const { return Y + Height; }
|
||||
virtual void SetBottom(int bottom)
|
||||
{
|
||||
Height = bottom - Y;
|
||||
}
|
||||
|
||||
Rectangle& operator+=(const Rectangle &rhs)
|
||||
{
|
||||
SetLeft(std::min(Left(), rhs.Left()));
|
||||
SetRight(std::max(Right(), rhs.Right()));
|
||||
SetTop(std::min(Top(), rhs.Top()));
|
||||
SetBottom(std::max(Bottom(), rhs.Bottom()));
|
||||
}
|
||||
|
||||
static bool Intersects(const Rectangle &r1, const Rectangle &r2)
|
||||
{
|
||||
return !(r2.Left() > r1.Right() || r2.Right() < r1.Left() || r2.Top() > r1.Bottom() || r2.Bottom() < r1.Top());
|
||||
}
|
||||
};
|
||||
|
||||
inline bool operator==(const Rectangle &r1, const Rectangle &r2)
|
||||
{
|
||||
return (r1.X == r2.X) && (r1.Y == r2.Y) && (r1.Width == r2.Width) && (r1.Height == r2.Height);
|
||||
}
|
||||
|
||||
inline bool operator!=(const Rectangle &lhs, const Rectangle &rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
inline bool operator<(const Rectangle &lhs, const Rectangle &rhs)
|
||||
{
|
||||
return (lhs.Width < rhs.Width) && (lhs.Height < rhs.Height);
|
||||
}
|
||||
|
||||
inline bool operator>(const Rectangle &lhs, const Rectangle &rhs)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
inline bool operator<=(const Rectangle &lhs, const Rectangle &rhs)
|
||||
{
|
||||
return !(lhs > rhs);
|
||||
}
|
||||
|
||||
inline bool operator>=(const Rectangle &lhs, const Rectangle &rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
inline Rectangle operator+(Rectangle lhs, const Rectangle &rhs)
|
||||
{
|
||||
lhs += rhs;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
#endif // Util_Rectangle_h__
|
||||
@@ -0,0 +1,10 @@
|
||||
// GLM
|
||||
#define GLM_FORCE_RADIANS
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/common.hpp>
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtx/rotate_vector.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
@@ -0,0 +1,165 @@
|
||||
#ifndef GUI_BUTTON_H__
|
||||
#define GUI_BUTTON_H__
|
||||
|
||||
#include "GUI/TextureFrame.h"
|
||||
#include "GUI/EButtonEnter.h"
|
||||
#include "GUI/EButtonLeave.h"
|
||||
#include "GUI/EButtonPress.h"
|
||||
#include "GUI/EButtonRelease.h"
|
||||
#include "Core/EMouseMove.h"
|
||||
#include "Core/EMousePress.h"
|
||||
#include "Core/EMouseRelease.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
namespace GUI
|
||||
{
|
||||
|
||||
class Button : public TextureFrame
|
||||
{
|
||||
public:
|
||||
Button(Frame* parent, std::string name)
|
||||
: TextureFrame(parent, name)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMouseMove, &Button::OnMouseMove);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &Button::OnMousePress);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMouseRelease, &Button::OnMouseRelease);
|
||||
}
|
||||
|
||||
void SetTextureHover(std::string resourceName)
|
||||
{
|
||||
m_TextureHover = resourceName;
|
||||
}
|
||||
void SetTextureReleased(std::string resourceName)
|
||||
{
|
||||
m_TextureReleased = resourceName;
|
||||
SetTexture(resourceName);
|
||||
}
|
||||
void SetTexturePressed(std::string resourceName)
|
||||
{
|
||||
m_TexturePressed = resourceName;
|
||||
}
|
||||
|
||||
void Draw(RenderQueueCollection& rq) override
|
||||
{
|
||||
if (m_Texture == nullptr && !m_TextureReleased.empty()) {
|
||||
SetTexture(m_TextureReleased);
|
||||
}
|
||||
|
||||
TextureFrame::Draw(rq);
|
||||
}
|
||||
|
||||
virtual void OnEnter() { }
|
||||
virtual void OnLeave() { }
|
||||
virtual void OnPress() { }
|
||||
virtual void OnRelease() { }
|
||||
|
||||
protected:
|
||||
bool m_MouseIsOver = false;
|
||||
bool m_IsDown = false;
|
||||
|
||||
virtual bool OnMouseMove(const Events::MouseMove& event)
|
||||
{
|
||||
if (Hidden()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isOver = Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1));
|
||||
if (isOver && !m_MouseIsOver) { // Enter
|
||||
if (!m_IsDown) {
|
||||
if (!m_TextureHover.empty()) {
|
||||
SetTexture(m_TextureHover);
|
||||
}
|
||||
}
|
||||
OnEnter();
|
||||
Events::ButtonEnter e;
|
||||
e.FrameName = m_Name;
|
||||
EventBroker->Publish(e);
|
||||
Events::PlaySound soundEvent;
|
||||
soundEvent.FilePath = "Sounds/GUI/hover-n.wav";
|
||||
EventBroker->Publish(soundEvent);
|
||||
|
||||
} else if (!isOver && m_MouseIsOver) { // Leave
|
||||
if (!m_IsDown) {
|
||||
if (!m_TextureReleased.empty()) {
|
||||
SetTexture(m_TextureReleased);
|
||||
}
|
||||
}
|
||||
OnLeave();
|
||||
Events::ButtonLeave e;
|
||||
e.FrameName = m_Name;
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
m_MouseIsOver = isOver;
|
||||
|
||||
return true;
|
||||
}
|
||||
virtual bool OnMousePress(const Events::MousePress& event)
|
||||
{
|
||||
if (Hidden()) {
|
||||
//LOG_DEBUG("Pressed hidden button");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_TexturePressed.empty()) {
|
||||
SetTexture(m_TexturePressed);
|
||||
}
|
||||
|
||||
m_IsDown = true;
|
||||
OnPress();
|
||||
Events::ButtonPress e;
|
||||
e.FrameName = m_Name;
|
||||
e.Button = this;
|
||||
EventBroker->Publish(e);
|
||||
|
||||
return true;
|
||||
}
|
||||
virtual bool OnMouseRelease(const Events::MouseRelease& event)
|
||||
{
|
||||
if (Hidden()) {
|
||||
//LOG_DEBUG("Released hidden button");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isOver = Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1));
|
||||
if (!isOver && !m_IsDown) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_MouseIsOver) {
|
||||
if (!m_TextureHover.empty()) {
|
||||
SetTexture(m_TextureHover);
|
||||
}
|
||||
} else {
|
||||
if (!m_TextureReleased.empty()) {
|
||||
SetTexture(m_TextureReleased);
|
||||
}
|
||||
}
|
||||
|
||||
m_IsDown = false;
|
||||
OnRelease();
|
||||
Events::ButtonRelease e;
|
||||
e.FrameName = m_Name;
|
||||
e.Button = this;
|
||||
EventBroker->Publish(e);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
EventRelay<Frame, Events::MouseMove> m_EMouseMove;
|
||||
EventRelay<Frame, Events::MousePress> m_EMousePress;
|
||||
EventRelay<Frame, Events::MouseRelease> m_EMouseRelease;
|
||||
|
||||
std::string m_TextureHover;
|
||||
std::string m_TexturePressed;
|
||||
std::string m_TextureReleased;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef Events_ButtonEnter_h__
|
||||
#define Events_ButtonEnter_h__
|
||||
|
||||
#include "../Core/EventBroker.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
/** Thrown on GUI button hover. */
|
||||
struct ButtonEnter : Event
|
||||
{
|
||||
std::string FrameName;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef Events_ButtonLeave_h__
|
||||
#define Events_ButtonLeave_h__
|
||||
|
||||
#include "../Core/EventBroker.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
/** Thrown on GUI button hover. */
|
||||
struct ButtonLeave : Event
|
||||
{
|
||||
std::string FrameName;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef Events_ButtonPress_h__
|
||||
#define Events_ButtonPress_h__
|
||||
|
||||
#include "../Core/EventBroker.h"
|
||||
|
||||
namespace GUI { class Button; }
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
/** Thrown on GUI button press. */
|
||||
struct ButtonPress : Event
|
||||
{
|
||||
std::string FrameName;
|
||||
GUI::Button* Button;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef Events_ButtonRelease_h__
|
||||
#define Events_ButtonRelease_h__
|
||||
|
||||
#include "../Core/EventBroker.h"
|
||||
|
||||
namespace GUI { class Button; }
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
/** Thrown on GUI button release. */
|
||||
struct ButtonRelease : Event
|
||||
{
|
||||
std::string FrameName;
|
||||
GUI::Button* Button;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,261 @@
|
||||
#ifndef GUI_Frame_h__
|
||||
#define GUI_Frame_h__
|
||||
|
||||
#include "../Common.h"
|
||||
#include "../Core/Util/Rectangle.h"
|
||||
#include "../Core/EventBroker.h"
|
||||
#include "../Core/EKeyDown.h"
|
||||
#include "../Core/EKeyUp.h"
|
||||
#include "../Core/ResourceManager.h"
|
||||
#include "../Rendering/RenderQueue.h"
|
||||
#include "../Rendering/Texture.h"
|
||||
#include "../Input/EInputCommand.h"
|
||||
|
||||
namespace GUI
|
||||
{
|
||||
|
||||
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(EventBroker* eventBroker)
|
||||
: m_EventBroker(eventBroker)
|
||||
, BaseFrame(this)
|
||||
, m_Name("UIParent")
|
||||
, Rectangle() { }
|
||||
|
||||
// Create a frame as a child
|
||||
Frame(Frame* parent, std::string name)
|
||||
: m_Name(name)
|
||||
{
|
||||
SetParent(parent);
|
||||
Width = parent->Width;
|
||||
Height = parent->Height;
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Frame::OnKeyDown);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Frame::OnKeyUp);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &Frame::OnCommand);
|
||||
}
|
||||
|
||||
~Frame()
|
||||
{
|
||||
/*for (auto layer : m_Children)
|
||||
{
|
||||
for (auto child : layer.second)
|
||||
{
|
||||
delete child.second;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_Parent)
|
||||
{
|
||||
m_Parent->RemoveChild(this);
|
||||
}*/
|
||||
}
|
||||
|
||||
Frame* Parent() const { return m_Parent; }
|
||||
|
||||
void SetParent(Frame* parent)
|
||||
{
|
||||
if (parent == nullptr) {
|
||||
LOG_ERROR("Failed to parent frame \"%s\": Invalid parent", m_Name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
m_Layer = parent->Layer() + 1;
|
||||
parent->AddChild(this);
|
||||
m_Parent = parent;
|
||||
m_EventBroker = parent->m_EventBroker;
|
||||
BaseFrame = parent->BaseFrame;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
void SetLeft(int absLeft) override
|
||||
{
|
||||
if (m_Parent) {
|
||||
X = absLeft - m_Parent->Left();
|
||||
} else {
|
||||
X = absLeft;
|
||||
}
|
||||
}
|
||||
int Right() const override
|
||||
{
|
||||
return Left() + Width;
|
||||
}
|
||||
void SetRight(int absRight) override
|
||||
{
|
||||
if (m_Parent) {
|
||||
X = absRight - Width - m_Parent->Left();
|
||||
} else {
|
||||
X = absRight - Width;
|
||||
}
|
||||
}
|
||||
int Top() const override
|
||||
{
|
||||
if (m_Parent)
|
||||
return m_Parent->Top() + Y;
|
||||
else
|
||||
return Y;
|
||||
}
|
||||
void SetTop(int absTop) override
|
||||
{
|
||||
if (m_Parent) {
|
||||
Y = absTop - m_Parent->Top();
|
||||
} else {
|
||||
Y = absTop;
|
||||
}
|
||||
}
|
||||
int Bottom() const override
|
||||
{
|
||||
return Top() + Height;
|
||||
}
|
||||
void SetBottom(int absBottom) override
|
||||
{
|
||||
if (m_Parent) {
|
||||
Y = absBottom - Height - m_Parent->Top();
|
||||
} else {
|
||||
Y = absBottom - 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(RenderQueueCollection& rq)
|
||||
{
|
||||
if (this->Hidden())
|
||||
return;
|
||||
|
||||
// Draw ourselves
|
||||
this->Draw(rq);
|
||||
|
||||
// Draw children
|
||||
for (auto& pairLayer : m_Children) {
|
||||
auto children = pairLayer.second;
|
||||
for (auto& pairChild : children) {
|
||||
auto child = pairChild.second;
|
||||
if (child->Hidden())
|
||||
continue;
|
||||
child->Draw(rq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void Draw(RenderQueueCollection& rq) { }
|
||||
|
||||
protected:
|
||||
::EventBroker* m_EventBroker;
|
||||
Frame* BaseFrame = nullptr;
|
||||
|
||||
std::string m_Name = "Unnamed";
|
||||
int m_Layer = 0;
|
||||
bool m_Hidden = false;
|
||||
|
||||
Frame* m_Parent = nullptr;
|
||||
typedef std::multimap<std::string, Frame*> Children_t; // name -> frame
|
||||
std::map<int, Children_t> m_Children; // layer -> Children_t
|
||||
|
||||
virtual bool OnKeyDown(const Events::KeyDown& event) { return false; }
|
||||
virtual bool OnKeyUp(const Events::KeyUp& event) { return false; }
|
||||
virtual bool OnCommand(const Events::InputCommand& event) { return false; }
|
||||
|
||||
private:
|
||||
EventRelay<Frame, Events::KeyDown> m_EKeyDown;
|
||||
EventRelay<Frame, Events::KeyUp> m_EKeyUp;
|
||||
EventRelay<Frame, Events::InputCommand> m_EInputCommand;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,111 @@
|
||||
#ifndef GUI_TextureFrame_h__
|
||||
#define GUI_TextureFrame_h__
|
||||
|
||||
#include "Frame.h"
|
||||
#include "../Rendering/Texture.h"
|
||||
|
||||
namespace GUI
|
||||
{
|
||||
|
||||
class TextureFrame : public Frame
|
||||
{
|
||||
public:
|
||||
TextureFrame(Frame* parent, std::string name)
|
||||
: Frame(parent, name) { }
|
||||
|
||||
void EnableScissor() { m_ScissorEnabled = true; }
|
||||
void DisableScissor() { m_ScissorEnabled = false; }
|
||||
|
||||
void Draw(RenderQueueCollection& rq) override
|
||||
{
|
||||
if (m_Texture == nullptr)
|
||||
return;
|
||||
|
||||
// Texture while fading
|
||||
if (m_FadeTexture && m_CurrentFade < 1) {
|
||||
FrameJob job;
|
||||
job.Scissor = (m_ScissorEnabled) ? m_Parent->AbsoluteRectangle() : Rectangle();
|
||||
job.Viewport = Rectangle(Left(), Top(), Width, Height);
|
||||
job.TextureID = m_FadeTexture->ResourceID;
|
||||
job.DiffuseTexture = m_FadeTexture;
|
||||
job.Color = glm::vec4(m_Color.r, m_Color.g, m_Color.b, m_Color.a);
|
||||
job.Name = Name();
|
||||
rq.GUI.Add(job);
|
||||
}
|
||||
|
||||
// Main texture
|
||||
{
|
||||
FrameJob job;
|
||||
job.Scissor = (m_ScissorEnabled) ? m_Parent->AbsoluteRectangle() : Rectangle();
|
||||
job.Viewport = Rectangle(Left(), Top(), Width, Height);
|
||||
job.TextureID = m_Texture->ResourceID;
|
||||
job.DiffuseTexture = m_Texture;
|
||||
job.Color = glm::vec4(m_Color.r, m_Color.g, m_Color.b, m_Color.a * m_CurrentFade);
|
||||
job.Name = Name();
|
||||
rq.GUI.Add(job);
|
||||
}
|
||||
}
|
||||
|
||||
std::string Texture() const { return m_TextureName; }
|
||||
|
||||
void SetTexture(std::string resourceName)
|
||||
{
|
||||
if (resourceName.empty()) {
|
||||
m_Texture = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
m_Texture = ResourceManager::Load<Texture>(resourceName);
|
||||
m_TextureName = resourceName;
|
||||
if (m_Texture == nullptr) {
|
||||
m_Texture = ResourceManager::Load<Texture>("Textures/Core/ErrorTexture.png");
|
||||
}
|
||||
|
||||
SizeToTexture();
|
||||
}
|
||||
|
||||
void SizeToTexture()
|
||||
{
|
||||
if (m_Texture != nullptr) {
|
||||
this->Width = m_Texture->Width;
|
||||
this->Height = m_Texture->Height;
|
||||
}
|
||||
}
|
||||
|
||||
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:
|
||||
bool m_ScissorEnabled = true;
|
||||
Texture* m_Texture = nullptr;
|
||||
std::string m_TextureName;
|
||||
Texture* m_FadeTexture = nullptr;
|
||||
glm::vec4 m_Color = glm::vec4(1.f, 1.f, 1.f, 1.f);
|
||||
float m_FadeDuration = 0.f;
|
||||
float m_CurrentFade = 1.f;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
// OpenGL
|
||||
#include <GL/glew.h>
|
||||
#define GLFW_INCLUDE_GLU
|
||||
#define NOMINMAX
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glext.h>
|
||||
#include "Rendering/Util/GLError.h"
|
||||
@@ -1,26 +0,0 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
||||
// OpenGL
|
||||
#include <GL/glew.h>
|
||||
#define GLFW_INCLUDE_GLU
|
||||
#define NOMINMAX
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glext.h>
|
||||
#include "Rendering/Util/GLError.h"
|
||||
|
||||
// GLM
|
||||
#define GLM_FORCE_RADIANS
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/common.hpp>
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtx/rotate_vector.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
#include "Core/Util/Logging.h"
|
||||
@@ -1,12 +1,7 @@
|
||||
#ifndef BaseTexture_h__
|
||||
#define BaseTexture_h__
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <cstdio>
|
||||
|
||||
#include "Core/ResourceManager.h"
|
||||
#include "Rendering/PNG.h"
|
||||
#include "../Core/ResourceManager.h"
|
||||
|
||||
class BaseTexture : public Resource
|
||||
{
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
#ifndef Camera_h__
|
||||
#define Camera_h__
|
||||
|
||||
#include "../GLM.h"
|
||||
|
||||
class Camera
|
||||
{
|
||||
public:
|
||||
/** Camera constructor.
|
||||
|
||||
@param aspectRatio Aspect ratio.
|
||||
@param yFOV Vertical FOV.
|
||||
@param nearClip Near clipping plane in meters.
|
||||
@param farClip Far clipping plane in meters.
|
||||
*/
|
||||
Camera(float aspectRatio, float yFOV, float nearClip, float farClip);
|
||||
|
||||
/** Forward vector of the camera */
|
||||
glm::vec3 Forward();
|
||||
/** Right vector of the camera */
|
||||
glm::vec3 Right();
|
||||
|
||||
glm::vec3 Position() const { return m_Position; }
|
||||
void SetPosition(glm::vec3 val);
|
||||
|
||||
glm::quat Orientation() const { return m_Orientation; }
|
||||
void SetOrientation(glm::quat val);
|
||||
|
||||
/*float Pitch() const { return m_Pitch; }
|
||||
void Pitch(float val);
|
||||
float Yaw() const { return m_Yaw; }
|
||||
void Yaw(float val);*/
|
||||
|
||||
glm::mat4 ProjectionMatrix() const { return m_ProjectionMatrix; }
|
||||
glm::mat4 ViewMatrix() const { return m_ViewMatrix; }
|
||||
|
||||
float AspectRatio() const { return m_AspectRatio; }
|
||||
void SetAspectRatio(float val);
|
||||
|
||||
float FOV() const { return m_FOV; }
|
||||
void SetFOV(float val);
|
||||
|
||||
float NearClip() const { return m_NearClip; }
|
||||
void SetNearClip(float val);
|
||||
|
||||
float FarClip() const { return m_FarClip; }
|
||||
void SetFarClip(float val);
|
||||
|
||||
float m_AspectRatio;
|
||||
float m_FOV;
|
||||
float m_NearClip;
|
||||
float m_FarClip;
|
||||
|
||||
private:
|
||||
void UpdateViewMatrix();
|
||||
void UpdateProjectionMatrix();
|
||||
|
||||
glm::vec3 m_Position;
|
||||
glm::quat m_Orientation;
|
||||
|
||||
glm::mat4 m_ProjectionMatrix;
|
||||
glm::mat4 m_ViewMatrix;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef DummyRenderer_h__
|
||||
#define DummyRenderer_h__
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "IRenderer.h"
|
||||
|
||||
class DummyRenderer : public IRenderer
|
||||
{
|
||||
public:
|
||||
virtual void Initialize() override;
|
||||
virtual void Draw(RenderQueueCollection& rq) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,44 @@
|
||||
#ifndef IRenderer_h__
|
||||
#define IRenderer_h__
|
||||
|
||||
#include "../Common.h"
|
||||
#include "../OpenGL.h"
|
||||
#include "../Core/Util/Rectangle.h"
|
||||
#include "Camera.h"
|
||||
#include "RenderQueue.h"
|
||||
|
||||
class IRenderer
|
||||
{
|
||||
public:
|
||||
GLFWwindow* Window() const { return m_Window; }
|
||||
Rectangle Resolution() const { return m_Resolution; }
|
||||
void SetResolution(const Rectangle& resolution) { m_Resolution = resolution; }
|
||||
bool Fullscreen() { return m_Fullscreen; }
|
||||
void SetFullscreen(bool fullscreen) { m_Fullscreen = fullscreen; }
|
||||
bool VSYNC() const { return m_VSYNC; }
|
||||
void SetVSYNC(bool vsync) { m_VSYNC = vsync; }
|
||||
::Camera* Camera() const { return m_Camera; }
|
||||
void SetCamera(::Camera* camera)
|
||||
{
|
||||
if (camera == nullptr) {
|
||||
m_Camera = m_DefaultCamera;
|
||||
} else {
|
||||
m_Camera = camera;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void Initialize() = 0;
|
||||
virtual void Draw(RenderQueueCollection& rq) = 0;
|
||||
|
||||
protected:
|
||||
Rectangle m_Resolution = Rectangle(1280, 720);
|
||||
bool m_Fullscreen = false;
|
||||
bool m_VSYNC = false;
|
||||
int m_GLVersion[2];
|
||||
std::string m_GLVendor;
|
||||
::Camera* m_DefaultCamera;
|
||||
::Camera* m_Camera = nullptr;
|
||||
GLFWwindow* m_Window = nullptr;
|
||||
};
|
||||
|
||||
#endif // Renderer_h__
|
||||
@@ -1,7 +1,8 @@
|
||||
#ifndef Model_h__
|
||||
#define Model_h__
|
||||
|
||||
#include "Rendering/RawModel.h"
|
||||
#include "RawModel.h"
|
||||
#include "../OpenGL.h"
|
||||
|
||||
class Model : public RawModel
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <png.h>
|
||||
|
||||
#include "../Common.h"
|
||||
#include "Image.h"
|
||||
|
||||
class PNG : public Image
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
#ifndef RawModel_h__
|
||||
#define RawModel_h__
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <cstdlib>
|
||||
#include <stack>
|
||||
|
||||
@@ -15,9 +12,11 @@
|
||||
#include <assimp/postprocess.h>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include "Core/ResourceManager.h"
|
||||
#include "Rendering/Texture.h"
|
||||
#include "Rendering/Skeleton.h"
|
||||
#include "../Common.h"
|
||||
#include "../GLM.h"
|
||||
#include "../Core/ResourceManager.h"
|
||||
#include "Texture.h"
|
||||
#include "Skeleton.h"
|
||||
|
||||
class RawModel : public Resource
|
||||
{
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
#ifndef RenderQueue_h__
|
||||
#define RenderQueue_h__
|
||||
|
||||
#include <cstdint>
|
||||
#include <forward_list>
|
||||
|
||||
#include "../Common.h"
|
||||
#include "../GLM.h"
|
||||
#include "../Core/Util/Rectangle.h"
|
||||
|
||||
class Model;
|
||||
class Skeleton;
|
||||
class Texture;
|
||||
class RenderQueue;
|
||||
|
||||
struct RenderJob
|
||||
{
|
||||
friend class RenderQueue;
|
||||
|
||||
float Depth;
|
||||
|
||||
protected:
|
||||
uint64_t Hash;
|
||||
|
||||
virtual void CalculateHash() = 0;
|
||||
|
||||
bool operator<(const RenderJob& rhs)
|
||||
{
|
||||
return this->Hash < rhs.Hash;
|
||||
}
|
||||
};
|
||||
|
||||
struct ModelJob : RenderJob
|
||||
{
|
||||
unsigned int ShaderID = 0;
|
||||
unsigned int TextureID = 0;
|
||||
|
||||
glm::mat4 ModelMatrix;
|
||||
const Texture* DiffuseTexture;
|
||||
const Texture* NormalTexture;
|
||||
const Texture* SpecularTexture;
|
||||
float Shininess = 0.f;
|
||||
glm::vec4 Color;
|
||||
const Model* Model = nullptr;
|
||||
unsigned int StartIndex = 0;
|
||||
unsigned int EndIndex = 0;
|
||||
|
||||
// Animation
|
||||
Skeleton* Skeleton = nullptr;
|
||||
bool NoRootMotion = true;
|
||||
std::string AnimationName;
|
||||
double AnimationTime = 0;
|
||||
|
||||
void CalculateHash() override
|
||||
{
|
||||
Hash = TextureID;
|
||||
}
|
||||
};
|
||||
|
||||
struct SpriteJob : RenderJob
|
||||
{
|
||||
unsigned int ShaderID = 0;
|
||||
unsigned int TextureID = 0;
|
||||
|
||||
glm::mat4 ModelMatrix;
|
||||
const Texture* DiffuseTexture = nullptr;
|
||||
const Texture* NormalTexture = nullptr;
|
||||
const Texture* SpecularTexture = nullptr;
|
||||
glm::vec4 Color;
|
||||
|
||||
void CalculateHash() override
|
||||
{
|
||||
Hash = TextureID;
|
||||
}
|
||||
};
|
||||
|
||||
struct PointLightJob : RenderJob
|
||||
{
|
||||
glm::vec3 Position;
|
||||
glm::vec3 SpecularColor = glm::vec3(1, 1, 1);
|
||||
glm::vec3 DiffuseColor = glm::vec3(1, 1, 1);
|
||||
float Radius = 1.f;
|
||||
|
||||
void CalculateHash() override
|
||||
{
|
||||
Hash = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct FrameJob : SpriteJob
|
||||
{
|
||||
Rectangle Scissor;
|
||||
Rectangle Viewport;
|
||||
std::string Name;
|
||||
|
||||
void CalculateHash() override
|
||||
{
|
||||
Hash = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct WaterParticleJob : RenderJob
|
||||
{
|
||||
glm::vec3 Position;
|
||||
glm::vec4 Color;
|
||||
glm::mat4 ModelMatrix;
|
||||
|
||||
void CalculateHash() override
|
||||
{
|
||||
Hash = 0;
|
||||
}
|
||||
};
|
||||
|
||||
class RenderQueue
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
void Add(T &job)
|
||||
{
|
||||
job.CalculateHash();
|
||||
Jobs.push_back(std::shared_ptr<T>(new T(job)));
|
||||
m_Size++;
|
||||
}
|
||||
|
||||
void Sort()
|
||||
{
|
||||
Jobs.sort();
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
Jobs.clear();
|
||||
m_Size = 0;
|
||||
}
|
||||
|
||||
int Size() const { return m_Size; }
|
||||
std::list<std::shared_ptr<RenderJob>>::const_iterator begin()
|
||||
{
|
||||
return Jobs.begin();
|
||||
}
|
||||
|
||||
std::list<std::shared_ptr<RenderJob>>::const_iterator end()
|
||||
{
|
||||
return Jobs.end();
|
||||
}
|
||||
|
||||
std::list<std::shared_ptr<RenderJob>> Jobs;
|
||||
|
||||
private:
|
||||
int m_Size = 0;
|
||||
};
|
||||
|
||||
struct RenderQueueCollection
|
||||
{
|
||||
RenderQueue Deferred;
|
||||
RenderQueue Forward;
|
||||
RenderQueue Lights;
|
||||
RenderQueue GUI;
|
||||
|
||||
void Clear()
|
||||
{
|
||||
Deferred.Clear();
|
||||
Forward.Clear();
|
||||
Lights.Clear();
|
||||
GUI.Clear();
|
||||
}
|
||||
|
||||
void Sort()
|
||||
{
|
||||
Deferred.Sort();
|
||||
Forward.Sort();
|
||||
Lights.Sort();
|
||||
GUI.Sort();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -2,6 +2,8 @@
|
||||
#define Skeleton_h__
|
||||
|
||||
#include <sstream>
|
||||
#include "Common.h"
|
||||
#include "../GLM.h"
|
||||
|
||||
//struct Bone
|
||||
//{
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#ifndef Texture_h__
|
||||
#define Texture_h__
|
||||
|
||||
#include "Rendering/BaseTexture.h"
|
||||
#include "../OpenGL.h"
|
||||
#include "BaseTexture.h"
|
||||
#include "PNG.h"
|
||||
|
||||
class Texture : public BaseTexture
|
||||
{
|
||||
|
||||
@@ -1,26 +1,8 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLError_h__
|
||||
#define GLError_h__
|
||||
|
||||
#include "PrecompiledHeader.h"
|
||||
#include <iostream>
|
||||
#include "Common.h"
|
||||
|
||||
inline bool _GLERROR(const char* info, const char* file, const char* func, unsigned int line)
|
||||
{
|
||||
@@ -37,4 +19,4 @@ inline bool _GLERROR(const char* info, const char* file, const char* func, unsig
|
||||
#define GLERROR(function) \
|
||||
_GLERROR(function, __BASE_FILE__, __func__, __LINE__)
|
||||
|
||||
#endif // GLError_h__
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef Game_h__
|
||||
#define Game_h__
|
||||
|
||||
#include "Core/ResourceManager.h"
|
||||
#include "Core/ConfigFile.h"
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Rendering/DummyRenderer.h"
|
||||
#include "Core/InputManager.h"
|
||||
|
||||
#include "GUI/Frame.h"
|
||||
|
||||
class Game
|
||||
{
|
||||
public:
|
||||
Game(int argc, char* argv[]);
|
||||
~Game();
|
||||
|
||||
bool Running() const { return true; }
|
||||
void Tick();
|
||||
|
||||
private:
|
||||
double m_LastTime;
|
||||
ConfigFile* m_Config = nullptr;
|
||||
EventBroker* m_EventBroker;
|
||||
IRenderer* m_Renderer;
|
||||
InputManager* m_InputManager;
|
||||
GUI::Frame* m_FrameStack;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,8 @@
|
||||
[Debug]
|
||||
LogLevel=1
|
||||
|
||||
[Video]
|
||||
Fullscreen=false
|
||||
VSYNC=false
|
||||
Width=1280
|
||||
Height=720
|
||||
@@ -1,7 +1,7 @@
|
||||
project(TacticalZ-Engine)
|
||||
|
||||
find_package(OpenGL REQUIRED)
|
||||
#find_package(GLEW REQUIRED)
|
||||
find_package(GLEW REQUIRED)
|
||||
find_package(GLFW REQUIRED)
|
||||
find_package(Boost REQUIRED COMPONENTS system filesystem thread chrono)
|
||||
find_package(assimp REQUIRED)
|
||||
@@ -50,10 +50,17 @@ file(GLOB SOURCE_FILES_Rendering
|
||||
)
|
||||
source_group(Rendering FILES ${SOURCE_FILES_Rendering})
|
||||
|
||||
file(GLOB SOURCE_FILES_GUI
|
||||
"${INCLUDE_PATH}/GUI/*.h"
|
||||
"GUI/*.cpp"
|
||||
)
|
||||
source_group(GUI FILES ${SOURCE_FILES_GUI})
|
||||
|
||||
set(SOURCE_FILES
|
||||
${SOURCE_FILES_Core}
|
||||
${SOURCE_FILES_Core_Util}
|
||||
#${SOURCE_FILES_Input}
|
||||
${SOURCE_FILES_GUI}
|
||||
${SOURCE_FILES_Rendering}
|
||||
)
|
||||
|
||||
@@ -78,3 +85,5 @@ add_library(Engine ${SOURCE_FILES})
|
||||
target_link_libraries(Engine
|
||||
${LIBRARIES}
|
||||
)
|
||||
#set_target_properties(Engine PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "${INCLUDE_PATH}/PrecompiledHeader.h")
|
||||
#cotire(Engine)
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Core/ConfigFile.h"
|
||||
|
||||
ConfigFile::ConfigFile(std::string path)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Core/EventBroker.h"
|
||||
|
||||
BaseEventRelay::~BaseEventRelay()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Core/InputManager.h"
|
||||
|
||||
void InputManager::Initialize()
|
||||
@@ -13,7 +12,7 @@ void InputManager::Initialize()
|
||||
|
||||
void InputManager::Update(double dt)
|
||||
{
|
||||
EventBroker->Process<InputManager>();
|
||||
m_EventBroker->Process<InputManager>();
|
||||
|
||||
m_LastKeyState = m_CurrentKeyState;
|
||||
m_LastMouseState = m_CurrentMouseState;
|
||||
@@ -28,11 +27,11 @@ void InputManager::Update(double dt)
|
||||
if (m_CurrentKeyState[i]) {
|
||||
Events::KeyDown e;
|
||||
e.KeyCode = i;
|
||||
EventBroker->Publish(e);
|
||||
m_EventBroker->Publish(e);
|
||||
} else {
|
||||
Events::KeyUp e;
|
||||
e.KeyCode = i;
|
||||
EventBroker->Publish(e);
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,13 +48,13 @@ void InputManager::Update(double dt)
|
||||
e.Button = i;
|
||||
e.X = x;
|
||||
e.Y = y;
|
||||
EventBroker->Publish(e);
|
||||
m_EventBroker->Publish(e);
|
||||
} else {
|
||||
Events::MouseRelease e;
|
||||
e.Button = i;
|
||||
e.X = x;
|
||||
e.Y = y;
|
||||
EventBroker->Publish(e);
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,7 +70,7 @@ void InputManager::Update(double dt)
|
||||
e.Y = m_CurrentMouseY;
|
||||
e.DeltaX = m_CurrentMouseDeltaX;
|
||||
e.DeltaY = m_CurrentMouseDeltaY;
|
||||
EventBroker->Publish(e);
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
// // Lock mouse while holding LMB
|
||||
@@ -174,7 +173,7 @@ void InputManager::PublishGamepadAxisIfChanged(int gamepadID, Gamepad::Axis axis
|
||||
e.GamepadID = gamepadID;
|
||||
e.Axis = axis;
|
||||
e.Value = currentValue;
|
||||
EventBroker->Publish(e);
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,12 +186,12 @@ void InputManager::PublishGamepadButtonIfChanged(int gamepadID, Gamepad::Button
|
||||
Events::GamepadButtonDown e;
|
||||
e.GamepadID = gamepadID;
|
||||
e.Button = button;
|
||||
EventBroker->Publish(e);
|
||||
m_EventBroker->Publish(e);
|
||||
} else {
|
||||
Events::GamepadButtonUp e;
|
||||
e.GamepadID = gamepadID;
|
||||
e.Button = button;
|
||||
EventBroker->Publish(e);
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Core/ResourceManager.h"
|
||||
|
||||
std::unordered_map<std::string, std::string> ResourceManager::m_CompilerTypenameToResourceType;
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
#include "Core/Util/FileWatcher.h"
|
||||
|
||||
FileWatcher::FileWatcher()
|
||||
{
|
||||
m_Worker = new Worker;
|
||||
}
|
||||
|
||||
FileWatcher::FileWatcher(std::string rootPath)
|
||||
{
|
||||
m_RootPath = rootPath;
|
||||
m_Worker = new Worker;
|
||||
}
|
||||
|
||||
FileWatcher::~FileWatcher()
|
||||
{
|
||||
m_Thread.interrupt();
|
||||
if (m_Worker != nullptr)
|
||||
{
|
||||
delete m_Worker;
|
||||
}
|
||||
}
|
||||
|
||||
void FileWatcher::AddWatch(std::string path, FileEventCallback_t callback)
|
||||
{
|
||||
m_Worker->AddWatch(path, callback);
|
||||
}
|
||||
|
||||
void FileWatcher::Start()
|
||||
{
|
||||
m_Thread.interrupt();
|
||||
m_Thread = boost::thread(boost::ref(*m_Worker));
|
||||
m_IsRunning = true;
|
||||
}
|
||||
|
||||
void FileWatcher::Stop()
|
||||
{
|
||||
m_Thread.interrupt();
|
||||
m_IsRunning = false;
|
||||
}
|
||||
|
||||
void FileWatcher::Check()
|
||||
{
|
||||
m_Worker->Check();
|
||||
}
|
||||
|
||||
|
||||
void FileWatcher::Worker::operator()()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
boost::this_thread::interruption_point();
|
||||
Check();
|
||||
boost::this_thread::sleep_for(boost::chrono::milliseconds(1000));
|
||||
}
|
||||
}
|
||||
|
||||
void FileWatcher::Worker::AddWatch(std::string path, FileEventCallback_t callback)
|
||||
{
|
||||
m_Mutex.lock();
|
||||
boost::filesystem::path bpath(path);
|
||||
m_FileCallbacks[bpath] = callback;
|
||||
if (boost::filesystem::exists(bpath))
|
||||
{
|
||||
m_FileInfo[bpath] = GetFileInfo(bpath);
|
||||
}
|
||||
m_Mutex.unlock();
|
||||
}
|
||||
|
||||
void FileWatcher::Worker::Check()
|
||||
{
|
||||
m_Mutex.lock();
|
||||
for (auto &kv : m_FileCallbacks)
|
||||
{
|
||||
boost::filesystem::path path = kv.first;
|
||||
FileEventCallback_t& callback = kv.second;
|
||||
FileEventFlags flags = UpdateFileInfo(path);
|
||||
if (flags != FileEventFlags::Nothing && callback != nullptr)
|
||||
{
|
||||
callback(path.string(), flags);
|
||||
}
|
||||
}
|
||||
m_Mutex.unlock();
|
||||
}
|
||||
|
||||
FileWatcher::Worker::FileInfo FileWatcher::Worker::GetFileInfo(boost::filesystem::path path)
|
||||
{
|
||||
FileInfo fi;
|
||||
fi.Size = boost::filesystem::file_size(path);
|
||||
fi.Timestamp = boost::filesystem::last_write_time(path);
|
||||
return fi;
|
||||
}
|
||||
|
||||
FileWatcher::FileEventFlags FileWatcher::Worker::UpdateFileInfo(boost::filesystem::path path)
|
||||
{
|
||||
FileEventFlags flags = FileEventFlags::Nothing;
|
||||
if (boost::filesystem::exists(path))
|
||||
{
|
||||
FileInfo fi = GetFileInfo(path);
|
||||
auto lastFileInfoIt = m_FileInfo.find(path);
|
||||
if (lastFileInfoIt != m_FileInfo.end())
|
||||
{
|
||||
FileInfo lastFileInfo = lastFileInfoIt->second;
|
||||
|
||||
if (fi.Size != lastFileInfo.Size)
|
||||
{
|
||||
LOG_DEBUG("FileWatcher: \"%s\" size changed!", path.string().c_str());
|
||||
flags = flags | FileEventFlags::SizeChanged;
|
||||
}
|
||||
if (fi.Timestamp != lastFileInfo.Timestamp)
|
||||
{
|
||||
LOG_DEBUG("FileWatcher: \"%s\" timestamp changed!", path.string().c_str());
|
||||
flags = flags | FileEventFlags::TimestampChanged;
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_DEBUG("FileWatcher: \"%s\" was created!", path.string().c_str());
|
||||
flags = flags | FileEventFlags::Created;
|
||||
}
|
||||
m_FileInfo[path] = GetFileInfo(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto fileInfoIt = m_FileInfo.find(path);
|
||||
if (fileInfoIt != m_FileInfo.end())
|
||||
{
|
||||
m_FileInfo.erase(fileInfoIt);
|
||||
LOG_DEBUG("FileWatcher: \"%s\" was deleted!", path.string().c_str());
|
||||
flags = flags | FileEventFlags::Deleted;
|
||||
}
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
@@ -0,0 +1,101 @@
|
||||
#include "Rendering/Camera.h"
|
||||
|
||||
Camera::Camera(float aspectRatio, float yFOV, float nearClip, float farClip)
|
||||
{
|
||||
m_AspectRatio = aspectRatio;
|
||||
m_FOV = yFOV;
|
||||
m_NearClip = nearClip;
|
||||
m_FarClip = farClip;
|
||||
|
||||
m_Position = glm::vec3(0.0);
|
||||
|
||||
UpdateProjectionMatrix();
|
||||
UpdateViewMatrix();
|
||||
}
|
||||
|
||||
glm::vec3 Camera::Forward()
|
||||
{
|
||||
return m_Orientation * glm::vec3(0, 0, -1);
|
||||
}
|
||||
//
|
||||
//glm::vec3 Camera::Right()
|
||||
//{
|
||||
// return glm::rotate(glm::vec3(1.f, 0.f, 0.f), -m_Yaw, glm::vec3(0.f, 1.f, 0.f));
|
||||
//}
|
||||
|
||||
//glm::mat4 Camera::Orientation()
|
||||
//{
|
||||
// glm::mat4 orientation(1.f);
|
||||
// orientation = glm::rotate(orientation, m_Pitch, glm::vec3(1.f, 0.f, 0.f));
|
||||
// orientation = glm::rotate(orientation, m_Yaw, glm::vec3(0.f, 1.f, 0.f));
|
||||
// return orientation;
|
||||
//}
|
||||
|
||||
void Camera::SetPosition(glm::vec3 val)
|
||||
{
|
||||
m_Position = val;
|
||||
UpdateViewMatrix();
|
||||
}
|
||||
|
||||
|
||||
void Camera::SetOrientation(glm::quat val)
|
||||
{
|
||||
m_Orientation = val;
|
||||
UpdateViewMatrix();
|
||||
}
|
||||
|
||||
//void Camera::Pitch(float val)
|
||||
//{
|
||||
// m_Pitch = val;
|
||||
// UpdateViewMatrix();
|
||||
//}
|
||||
//
|
||||
//void Camera::Yaw(float val)
|
||||
//{
|
||||
// m_Yaw = val;
|
||||
// UpdateViewMatrix();
|
||||
//}
|
||||
|
||||
void Camera::UpdateProjectionMatrix()
|
||||
{
|
||||
// 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 Camera::UpdateViewMatrix()
|
||||
{
|
||||
m_ViewMatrix = glm::toMat4(glm::inverse(m_Orientation))
|
||||
* glm::translate(-m_Position);
|
||||
}
|
||||
|
||||
void Camera::SetAspectRatio(float val)
|
||||
{
|
||||
m_AspectRatio = val;
|
||||
UpdateProjectionMatrix();
|
||||
}
|
||||
|
||||
void Camera::SetFOV(float val)
|
||||
{
|
||||
m_FOV = val;
|
||||
UpdateProjectionMatrix();
|
||||
}
|
||||
|
||||
void Camera::SetNearClip(float val)
|
||||
{
|
||||
m_NearClip = val;
|
||||
UpdateProjectionMatrix();
|
||||
}
|
||||
|
||||
void Camera::SetFarClip(float val)
|
||||
{
|
||||
m_FarClip = val;
|
||||
UpdateProjectionMatrix();
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
#include "Rendering/DummyRenderer.h"
|
||||
|
||||
void DummyRenderer::Initialize()
|
||||
{
|
||||
// Initialize GLFW
|
||||
if (!glfwInit()) {
|
||||
LOG_ERROR("GLFW: Initialization failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Create a window
|
||||
GLFWmonitor* monitor = nullptr;
|
||||
if (m_Fullscreen) {
|
||||
monitor = glfwGetPrimaryMonitor();
|
||||
}
|
||||
//glfwWindowHint(GLFW_SAMPLES, 8);
|
||||
m_Window = glfwCreateWindow(m_Resolution.Width, m_Resolution.Height, "daydream", monitor, nullptr);
|
||||
if (!m_Window) {
|
||||
LOG_ERROR("GLFW: Failed to create window");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
glfwMakeContextCurrent(m_Window);
|
||||
|
||||
// GL version info
|
||||
glGetIntegerv(GL_MAJOR_VERSION, &m_GLVersion[0]);
|
||||
glGetIntegerv(GL_MINOR_VERSION, &m_GLVersion[1]);
|
||||
m_GLVendor = (GLchar*)glGetString(GL_VENDOR);
|
||||
std::stringstream ss;
|
||||
ss << m_GLVendor << " OpenGL " << m_GLVersion[0] << "." << m_GLVersion[1];
|
||||
#ifdef DEBUG
|
||||
ss << " DEBUG";
|
||||
#endif
|
||||
LOG_INFO(ss.str().c_str());
|
||||
glfwSetWindowTitle(m_Window, ss.str().c_str());
|
||||
|
||||
// Initialize GLEW
|
||||
if (glewInit() != GLEW_OK) {
|
||||
LOG_ERROR("GLEW: Initialization failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Create default camera
|
||||
m_DefaultCamera = new ::Camera((float)m_Resolution.Width / m_Resolution.Height, glm::radians(45.f), 0.01f, 5000.f);
|
||||
m_DefaultCamera->SetPosition(glm::vec3(0, 0, 0));
|
||||
if (m_Camera == nullptr) {
|
||||
m_Camera = m_DefaultCamera;
|
||||
}
|
||||
|
||||
glfwSwapInterval(m_VSYNC);
|
||||
}
|
||||
|
||||
void DummyRenderer::Draw(RenderQueueCollection& rq)
|
||||
{
|
||||
glfwSwapBuffers(m_Window);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Rendering/Model.h"
|
||||
|
||||
Model::Model(std::string fileName)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Rendering/PNG.h"
|
||||
|
||||
PNG::PNG(std::string path)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Rendering/RawModel.h"
|
||||
|
||||
RawModel::RawModel(std::string fileName)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Rendering/Skeleton.h"
|
||||
|
||||
int Skeleton::CreateBone(int ID, int parentID, std::string name, glm::mat4 offsetMatrix)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Rendering/Texture.h"
|
||||
|
||||
Texture::Texture(std::string path)
|
||||
|
||||
+26
-4
@@ -1,13 +1,35 @@
|
||||
project(TacticalZ-Game)
|
||||
|
||||
set(INCLUDE_PATH ${CMAKE_SOURCE_DIR}/include)
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(GLEW REQUIRED)
|
||||
find_package(GLFW REQUIRED)
|
||||
find_package(Boost REQUIRED COMPONENTS system filesystem thread chrono)
|
||||
find_package(assimp REQUIRED)
|
||||
find_package(ZLIB REQUIRED)
|
||||
find_package(PNG REQUIRED)
|
||||
# Because FindOpenAL is retarded
|
||||
#set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${CMAKE_SOURCE_DIR}/deps/include/AL")
|
||||
#find_package(OpenAL REQUIRED)
|
||||
if(UNIX)
|
||||
find_package(X11 REQUIRED)
|
||||
endif()
|
||||
|
||||
set(INCLUDE_PATH ${CMAKE_SOURCE_DIR}/include/Game)
|
||||
include_directories(
|
||||
${INCLUDE_PATH}/Engine
|
||||
${INCLUDE_PATH}/Game
|
||||
${CMAKE_SOURCE_DIR}/include/Engine
|
||||
${INCLUDE_PATH}
|
||||
${OPENGL_INCLUDE_DIR}
|
||||
${GLEW_INCLUDE_DIRS}
|
||||
${GLFW_INCLUDE_DIRS}
|
||||
${Boost_INCLUDE_DIRS}
|
||||
${assimp_INCLUDE_DIRS}
|
||||
${PNG_INCLUDE_DIRS}
|
||||
${OPENAL_INCLUDE_DIR}
|
||||
${X11_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
file(GLOB SOURCE_FILES
|
||||
"${INCLUDE_PATH}*.h"
|
||||
"${INCLUDE_PATH}/*.h"
|
||||
"*.cpp"
|
||||
)
|
||||
#source_group(Core FILES ${SOURCE_FILES})
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
#include "Game.h"
|
||||
|
||||
Game::Game(int argc, char* argv[])
|
||||
{
|
||||
ResourceManager::RegisterType<ConfigFile>("ConfigFile");
|
||||
|
||||
m_Config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||
LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get<int>("Debug.LogLevel", 1));
|
||||
|
||||
// Create the core event broker
|
||||
m_EventBroker = new EventBroker();
|
||||
|
||||
// Create the renderer
|
||||
m_Renderer = new DummyRenderer();
|
||||
m_Renderer->SetFullscreen(m_Config->Get<bool>("Video.Fullscreen", false));
|
||||
m_Renderer->SetVSYNC(m_Config->Get<bool>("Video.VSYNC", false));
|
||||
m_Renderer->SetResolution(Rectangle(
|
||||
0,
|
||||
0,
|
||||
m_Config->Get<int>("Video.Width", 1280),
|
||||
m_Config->Get<int>("Video.Height", 720)
|
||||
));
|
||||
m_Renderer->Initialize();
|
||||
|
||||
// Create input manager
|
||||
m_InputManager = new InputManager(m_Renderer->Window(), m_EventBroker);
|
||||
|
||||
// Create the root level GUI frame
|
||||
m_FrameStack = new GUI::Frame(m_EventBroker);
|
||||
m_FrameStack->Width = m_Renderer->Resolution().Width;
|
||||
m_FrameStack->Height = m_Renderer->Resolution().Height;
|
||||
|
||||
m_LastTime = glfwGetTime();
|
||||
}
|
||||
|
||||
Game::~Game()
|
||||
{
|
||||
delete m_FrameStack;
|
||||
delete m_EventBroker;
|
||||
}
|
||||
|
||||
void Game::Tick()
|
||||
{
|
||||
double currentTime = glfwGetTime();
|
||||
double dt = currentTime - m_LastTime;
|
||||
m_LastTime = currentTime;
|
||||
|
||||
m_EventBroker->Swap();
|
||||
m_InputManager->Update(dt);
|
||||
m_EventBroker->Swap();
|
||||
|
||||
RenderQueueCollection rq;
|
||||
m_Renderer->Draw(rq);
|
||||
|
||||
m_EventBroker->Swap();
|
||||
m_EventBroker->Clear();
|
||||
|
||||
glfwPollEvents();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#include "Game.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
Game game(argc, argv);
|
||||
while (game.Running()) {
|
||||
game.Tick();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user