Maintenance

- Some tidying
- Minor fixes
This commit is contained in:
Light 2021-06-15 22:17:28 +04:30
parent 31560897cd
commit 21e4432c60
16 changed files with 158 additions and 83 deletions

View file

@ -7,10 +7,14 @@ project "Engine"
objdir ("%{wks.location}/bin-int/" .. outputdir)
-- Compiler --
-- kind
kind "StaticLib"
-- language
language "C++"
cppdialect "C++17"
-- pch
pchsource "src/Engine/ltpch.cpp"
pchheader "ltpch.h"
@ -20,12 +24,13 @@ project "Engine"
"%{prj.location}/src/**.h" ,
"%{prj.location}/src/**.cpp" ,
"%{prj.location}/**.lua" ,
"%{prj.location}/dxgidebug.dll" ,
}
-- Dependencies --
includedirs
{
-- Engine
-- engine
"%{prj.location}/src/" ,
"%{prj.location}/src/Engine/" ,
"%{prj.location}/src/Platform/GraphicsAPI" ,
@ -35,8 +40,8 @@ project "Engine"
(dependenciesdir .. "spdlog/include/"),
(dependenciesdir .. "glfw/include/" ),
(dependenciesdir .. "glad/include" ),
(dependenciesdir .. "imgui/"),
(dependenciesdir .. "imgui/backends" ),
(dependenciesdir .. "imgui/" ),
(dependenciesdir .. "glm/" ),
}
@ -49,11 +54,10 @@ project "Engine"
--- Filters ---
-- windows
filter "system:windows"
defines "LIGHT_PLATFORM_WINDOWS"
systemversion "latest"
staticruntime "On"
staticruntime "on"
links
{
@ -62,10 +66,6 @@ project "Engine"
"D3DCompiler.lib" ,
}
filter "system:not windows"
excludes "%{prj.location}/src/Platform/GraphicsAPI/DirectX**"
excludes "%{prj.location}/src/Platform/OS/Windows**"
-- debug
filter "configurations:Debug"
defines "LIGHT_DEBUG"
@ -80,3 +80,11 @@ project "Engine"
filter "configurations:Distribution"
defines "LIGHT_DIST"
optimize "on"
--- Excludes ---
-- !windows
filter "system:not windows"
excludes "%{prj.location}/src/Platform/GraphicsAPI/DirectX**"
excludes "%{prj.location}/src/Platform/OS/Windows**"
-- !linux #todo:
-- !mac #todo:

View file

@ -8,9 +8,9 @@
#include <memory>
#define LT_WIN(x)
#define LT_LIN(x)
#define LT_MAC(x)
#define LT_WIN(x) // Windows
#define LT_LIN(x) // Linux
#define LT_MAC(x) // Mac
#if defined(LIGHT_PLATFORM_WINDOWS)
#define LT_BUILD_PLATFORM "Windows"
@ -27,5 +27,6 @@
#define BIT(x) 1 << x
// #todo: log to file in distribution builds
#define LT_ENGINE_ASSERT(x, ...) { if(!(x)) { LT_ENGINE_CRITICAL(__VA_ARGS__); __debugbreak(); } }
#define LT_CLIENT_ASSERT(x, ...) { if(!(x)) { LT_CLIENT_CRITICAL(__VA_ARGS__); __debugbreak(); } }

View file

@ -30,15 +30,16 @@ namespace Light {
LT_ENGINE_ASSERT(!m_LayerStack.IsEmpty(), "Application::GameLoop: Layerstack is empty");
// Log window data
Logger::LogDebugData();
LogDebugData();
m_Window->GetGfxContext()->LogDebugData();
m_Window->GetGfxContext()->GetUserInterface()->LogDebugData();
// Show window
m_Window->SetVisible(true);
m_Window->SetVisibility(true);
// GAMELOOP //
while (m_Window->IsOpen())
while (!m_Window->IsClosed())
{
// Events
m_Window->PollEvents();

View file

@ -2,6 +2,8 @@
#include "Base.h"
#include <glm/glm.hpp>
namespace Light {
class Event;
@ -10,15 +12,16 @@ namespace Light {
struct WindowProperties
{
std::string title;
unsigned int width, height;
bool vsync;
glm::uvec2 size;
bool vsync, visible;
};
class Window
{
protected:
std::unique_ptr<GraphicsContext> m_GraphicsContext;
bool b_Open;
WindowProperties m_Properties = {};
bool b_Closed = false;
public:
static Window* Create(std::function<void(Event&)> callback);
@ -28,21 +31,33 @@ namespace Light {
virtual ~Window() = default;
virtual void SetProperties(const WindowProperties& properties) = 0;
virtual void SetVisible(bool visible) = 0;
inline GraphicsContext* GetGfxContext() { return m_GraphicsContext.get(); }
inline bool IsOpen() const { return b_Open; }
virtual void PollEvents() = 0;
virtual void OnEvent(const Event& event) = 0;
virtual unsigned int GetHeight() = 0;
virtual unsigned int GetWidth() = 0;
// Setters //
virtual void SetProperties(const WindowProperties& properties) = 0;
virtual inline void* GetNativeHandle() = 0;
virtual void SetTitle(const std::string& title) = 0;
virtual void SetSize(const glm::uvec2& size) = 0; // pass 0 for width or height for single dimension resizing
inline void Close() { b_Closed = true; }
virtual void SetVSync(bool vsync, bool toggle = false) = 0;
virtual void SetVisibility(bool visible, bool toggle = false) = 0;
// Getters //
inline GraphicsContext* GetGfxContext() const { return m_GraphicsContext.get(); }
inline const WindowProperties& GetProperties() const { return m_Properties; }
inline const std::string& GetTitle() const { return m_Properties.title; }
inline const glm::uvec2& GetSize() const { return m_Properties.size; }
inline bool IsClosed() const { return b_Closed; }
inline bool IsVSync() const { return m_Properties.vsync; }
inline bool IsVisible() const { return m_Properties.visible; }
protected:
Window() = default;

View file

@ -28,6 +28,7 @@ namespace Light {
LT_ENGINE_CRITICAL("________________________________________");
}
LT_WIN(
dxException::dxException(long hr, const char* file, int line)
{
char* message;
@ -44,6 +45,6 @@ namespace Light {
LT_ENGINE_CRITICAL("________________________________________");
LocalFree(message);
}
})
}

View file

@ -10,10 +10,12 @@ namespace Light {
glException(unsigned int source, unsigned int type, unsigned int id, const char* msg);
};
#ifdef LIGHT_PLATFORM_WINDOWS
// DirectX
struct dxException : std::exception
{
dxException(long hr, const char* file, int line);
};
#endif
}

View file

@ -12,16 +12,30 @@ namespace Light {
void Light::Logger::Initialize()
{
// Set spdlog pattern
// set spdlog pattern
spdlog::set_pattern("%^[%M:%S:%e] <%n>: %v%$");
// Create loggers and set levels to minimum
// create loggers
s_EngineLogger = spdlog::stdout_color_mt("Engine");
s_EngineLogger->set_level(spdlog::level::trace);
s_ClientLogger = spdlog::stdout_color_mt("Client");
s_ClientLogger->set_level(spdlog::level::trace);
// set level
#if defined(LIGHT_DEBUG)
s_EngineLogger->set_level(spdlog::level::trace);
s_ClientLogger->set_level(spdlog::level::trace);
#elif defined (LIGHT_RELEASE)
s_EngineLogger->set_level(spdlog::level::info);
s_ClientLogger->set_level(spdlog::level::info);
#else
s_EngineLogger->set_level(spdlog::level::off);
s_ClientLogger->set_level(spdlog::level::off);
#endif
}
void Logger::LogDebugData()
{
LT_ENGINE_INFO("________________________________________");
LT_ENGINE_INFO("Logger::");
LT_ENGINE_INFO(" ClientLevel: {}", Stringifier::spdlogLevel(s_ClientLogger->level()));

View file

@ -34,6 +34,7 @@
namespace Light {
// #todo: add a FileLogger
class Logger
{
private:
@ -46,6 +47,8 @@ namespace Light {
static inline std::shared_ptr<spdlog::logger> GetEngineLogger() { return s_EngineLogger; }
static inline std::shared_ptr<spdlog::logger> GetClientLogger() { return s_ClientLogger; }
static void LogDebugData();
};
}

View file

@ -18,8 +18,8 @@ namespace Light {
case GraphicsAPI::OpenGL:
return new glVertexBuffer(vertices, count);
case GraphicsAPI::DirectX:
return new dxVertexBuffer(vertices, stride, count, sharedContext);
case GraphicsAPI::DirectX: LT_WIN(
return new dxVertexBuffer(vertices, stride, count, sharedContext);)
default:
LT_ENGINE_ASSERT(false, "VertexBuffer::Create: invalid/unsupported GraphicsAPI {}", GraphicsContext::GetGraphicsAPI());

View file

@ -49,16 +49,19 @@ namespace Light {
const float xMax = position.x + size.x;
const float yMax = position.y + size.y;
// TOP_LEFT
m_QuadRenderer.mapCurrent[0].position = { xMin, yMin, position.z };
m_QuadRenderer.mapCurrent[0].tint = glm::vec4(0.1f, 0.1f, 1.0f, 1.0f);
// TOP_RIGHT
m_QuadRenderer.mapCurrent[1].position = { xMax, yMin, position.z };
m_QuadRenderer.mapCurrent[1].tint = glm::vec4(0.3f, 0.3f, 0.3f, 1.0f);
// BOTTOM_RIGHT
m_QuadRenderer.mapCurrent[2].position = { xMax, yMax, position.z };
m_QuadRenderer.mapCurrent[2].tint = glm::vec4(0.1f, 1.0f, 0.1f, 1.0f);
// BOTTOM_LEFT
m_QuadRenderer.mapCurrent[3].position = { xMin, yMax, position.z };
m_QuadRenderer.mapCurrent[3].tint = glm::vec4(1.0f, 0.1f, 0.1f, 1.0f);

View file

@ -14,7 +14,8 @@ namespace Light {
LayerStack::LayerStack()
{
s_Context = this; // TODO: ASSERT
LT_ENGINE_ASSERT(!s_Context, "LayerStack::LayerStack: context re-initialization")
s_Context = this;
}
LayerStack::~LayerStack()

View file

@ -1,33 +1,39 @@
#pragma once
// Core
// Core -------------------------
#include "Core/Application.h"
#include "Core/Window.h"
// -----------------------------
// Debug
#include "Debug/Logger.h"
// -----------------------------
// Events
// Events ----------------------
#include "Events/Event.h"
#include "Events/KeyboardEvents.h"
#include "Events/MouseEvents.h"
#include "Events/WindowEvents.h"
// -----------------------------
// Graphics
// Graphics --------------------
#include "Graphics/GraphicsContext.h"
#include "Graphics/RenderCommand.h"
#include "Graphics/Renderer.h"
// -----------------------------
// Layer
// Layer -----------------------
#include "Layer/Layer.h"
#include "Layer/LayerStack.h"
// -----------------------------
// UserInterface
// UserInterface ---------------
#include "UserInterface/UserInterface.h"
// -----------------------------
// Base
// Base -----------------------
#include "Base.h"
#ifdef LIGHT_ENTRY_POINT
#include "EntryPoint.h"
#endif
// -----------------------------

View file

@ -9,8 +9,9 @@ namespace Light {
glVertexLayout::glVertexLayout(VertexBuffer* buffer, const std::vector<std::pair<std::string, VertexElementType>>& elements)
{
// sanity check
// check
LT_ENGINE_ASSERT(dynamic_cast<glVertexBuffer*>(buffer), "glVertexLayout::glVertexLayout: failed to cast VertexBuffer to glVertexBuffer");
LT_ENGINE_ASSERT(!elements.empty(), "glVertexLayout::glVertexLayout: elements is empty");
// elements desc
std::vector<glVertexElementDesc> elementsDesc;
@ -22,7 +23,7 @@ namespace Light {
stride += elementsDesc.back().typeSize * elementsDesc.back().count;
}
// bind
// prepare
glCreateVertexArrays(1, &m_ArrayID);
buffer->Bind();
Bind();

View file

@ -20,7 +20,7 @@ namespace Light {
wWindow::wWindow(std::function<void(Event&)> callback)
: m_EventCallback(callback)
{
LT_ENGINE_ASSERT(glfwInit(), "wWindow::wWindow: glfwInit: failed to initialize glfw");
LT_ENGINE_ASSERT(glfwInit(), "wWindow::wWindow: failed to initialize glfw");
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
@ -31,7 +31,7 @@ namespace Light {
BindGlfwEvents();
m_GraphicsContext = std::unique_ptr<GraphicsContext>(GraphicsContext::Create(GraphicsAPI::DirectX, m_Handle));
LT_ENGINE_ASSERT(m_GraphicsContext, "wWindow::wWindow: graphics context creation failed");
LT_ENGINE_ASSERT(m_GraphicsContext, "wWindow::wWindow: failed to create graphics context");
}
wWindow::~wWindow()
@ -43,14 +43,16 @@ namespace Light {
{
m_Properties = properties;
glfwSetWindowSize(m_Handle, properties.width, properties.height);
glfwSetWindowSize(m_Handle, properties.size.x, properties.size.y);
glfwSetWindowTitle(m_Handle, properties.title.c_str());
glfwSwapInterval((int)properties.vsync);
}
void wWindow::SetVisible(bool visible)
void wWindow::SetVisibility(bool visible, bool toggle)
{
if (visible)
m_Properties.visible = toggle ? !m_Properties.visible : visible;
if (m_Properties.visible)
glfwShowWindow(m_Handle);
else
glfwHideWindow(m_Handle);
@ -66,24 +68,40 @@ namespace Light {
switch (event.GetEventType())
{
case EventType::WindowClosed:
b_Open = false;
b_Closed = true;
break;
case EventType::WindowResized:
m_GraphicsContext->OnWindowResize((const WindowResizedEvent&)event);
break;
}
}
unsigned int wWindow::GetWidth()
void wWindow::SetTitle(const std::string& title)
{
return m_Properties.width;
m_Properties.title = title;
glfwSetWindowTitle(m_Handle, m_Properties.title.c_str());
}
unsigned int wWindow::GetHeight()
void wWindow::SetVSync(bool vsync, bool toggle /*= false*/)
{
return m_Properties.height;
m_Properties.vsync = toggle ? !m_Properties.vsync : vsync;
glfwSwapInterval(m_Properties.vsync);
}
void wWindow::SetSize(const glm::uvec2& size)
{
m_Properties.size.x = size.x == 0u ? m_Properties.size.x : size.x;
m_Properties.size.y = size.y == 0u ? m_Properties.size.y : size.y;
glfwSetWindowSize(m_Handle, m_Properties.size.x, m_Properties.size.y);
}
void wWindow::BindGlfwEvents()
{
// Mouse Events //
glfwSetCursorPosCallback(m_Handle, [](GLFWwindow* window, double xpos, double ypos)
{
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
@ -106,6 +124,7 @@ namespace Light {
callback(WheelScrolledEvent(yoffset));
});
// Keyboard Events //
glfwSetKeyCallback(m_Handle, [](GLFWwindow* window, int key, int scancode, int action, int mods)
{
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
@ -116,6 +135,7 @@ namespace Light {
callback(KeyReleasedEvent(key));
});
// Window Events //
glfwSetWindowCloseCallback(m_Handle, [](GLFWwindow* window)
{
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);

View file

@ -13,7 +13,6 @@ namespace Light {
{
private:
GLFWwindow* m_Handle = nullptr;
WindowProperties m_Properties = {};
std::function<void(Event&)> m_EventCallback;
@ -22,17 +21,18 @@ namespace Light {
~wWindow();
virtual void SetProperties(const WindowProperties& properties) override;
void PollEvents() override;
void OnEvent(const Event& event) override;
virtual void SetVisible(bool visible) override;
// Setters //
void SetProperties(const WindowProperties& properties) override;
virtual void PollEvents() override;
virtual void OnEvent(const Event& event) override;
void SetTitle(const std::string& title) override;
virtual unsigned int GetWidth() override;
virtual unsigned int GetHeight() override;
void SetSize(const glm::uvec2& size) override;
virtual inline void* GetNativeHandle() override { return m_Handle; }
void SetVSync(bool vsync, bool toggle = false) override;
void SetVisibility(bool visible, bool toggle = false) override;
private:
void BindGlfwEvents();

View file

@ -13,8 +13,7 @@ public:
// Set window properties
Light::WindowProperties properties;
properties.title = "Sandbox";
properties.width = 800u;
properties.height = 600u;
properties.size = glm::uvec2(800u, 600u);
properties.vsync = true;
m_Window->SetProperties(properties);