feat: refactor and move out the renderer with entt registry + better event system
This commit is contained in:
@ -1,20 +1,19 @@
|
||||
#ifndef APPLICATION_H_
|
||||
#define APPLICATION_H_
|
||||
|
||||
#include "engine/window/events/window.h"
|
||||
#include "engine/scene/scene.h"
|
||||
#include "engine/window/event.h"
|
||||
#include "engine/export.h"
|
||||
|
||||
class ENGINE_API IApplication {
|
||||
public:
|
||||
virtual ~IApplication() = default;
|
||||
|
||||
virtual void OnInit() {};
|
||||
virtual void OnInit(std::shared_ptr<Scene> scene) {};
|
||||
virtual void OnUpdate() {};
|
||||
virtual void OnRender() {};
|
||||
virtual void OnShutdown() {};
|
||||
|
||||
virtual void OnEvent() {};
|
||||
virtual void OnWindowResized(const WindowResized& e) {};
|
||||
virtual void OnEvent(const Event& event) {};
|
||||
};
|
||||
|
||||
#endif // APPLICATION_H_
|
||||
@ -1,7 +1,7 @@
|
||||
#ifndef COMPONENT_BATCH_H_
|
||||
#define COMPONENT_BATCH_H_
|
||||
|
||||
#include "engine/renderer/renderer.h"
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include "engine/export.h"
|
||||
|
||||
// requires mesh component
|
||||
|
||||
@ -3,8 +3,6 @@
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include "engine/renderer/mesh.h"
|
||||
|
||||
class Vertex {
|
||||
friend class Mesh;
|
||||
private:
|
||||
@ -14,8 +12,6 @@ private:
|
||||
public:
|
||||
Vertex(glm::vec3 position, glm::vec3 normal, glm::vec2 texCoord)
|
||||
: m_position(position), m_normal(normal), m_texCoord(texCoord) {}
|
||||
public:
|
||||
static void DefineAttrib();
|
||||
};
|
||||
|
||||
#endif // RENDERER_BASICS_H
|
||||
@ -7,6 +7,9 @@
|
||||
#include "engine/window/window.h"
|
||||
#include "engine/window/events/window.h"
|
||||
|
||||
#include "engine/renderer/renderer.h"
|
||||
#include "engine/scene/scene.h"
|
||||
|
||||
#include "engine/app/app.h"
|
||||
#include "engine/export.h"
|
||||
|
||||
@ -16,6 +19,8 @@ public:
|
||||
private:
|
||||
static std::unique_ptr<IApplication> s_app;
|
||||
static std::shared_ptr<Window> s_window;
|
||||
static std::unique_ptr<Renderer> s_renderer;
|
||||
static std::shared_ptr<Scene> s_scene;
|
||||
static bool s_running;
|
||||
};
|
||||
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
#define RENDERER_H_
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <entt/entity/registry.hpp>
|
||||
|
||||
#include "engine/scene/scene.h"
|
||||
#include "engine/renderer/shader.h"
|
||||
#include "engine/export.h"
|
||||
#include "engine/components/light.h"
|
||||
@ -11,23 +11,23 @@
|
||||
// TODO: make static or singleton
|
||||
class ENGINE_API Renderer {
|
||||
public:
|
||||
Renderer(entt::registry& registry);
|
||||
Renderer(std::shared_ptr<Scene> scene);
|
||||
|
||||
void Render();
|
||||
void Init();
|
||||
void GenerateShadowMaps();
|
||||
|
||||
void OnWindowResized(int w, int h);
|
||||
private:
|
||||
void ApplyLights(Shader &shader);
|
||||
void UpdateView();
|
||||
void RenderScene(Shader &shader);
|
||||
void GenerateShadowMaps();
|
||||
void EnsureShadowResources(light& l);
|
||||
private:
|
||||
Shader m_shader;
|
||||
Shader m_depthShader;
|
||||
|
||||
entt::registry& m_registry;
|
||||
std::shared_ptr<Scene> m_scene;
|
||||
|
||||
// unsigned int m_depth_fbo;
|
||||
// unsigned int m_depthMap;
|
||||
|
||||
15
engine/include/engine/scene/scene.h
Normal file
15
engine/include/engine/scene/scene.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef ENGINE_SCENE_H_
|
||||
#define ENGINE_SCENE_H_
|
||||
|
||||
#include <entt/entt.hpp>
|
||||
|
||||
class Scene {
|
||||
public:
|
||||
Scene();
|
||||
private:
|
||||
entt::registry m_registry;
|
||||
friend class Renderer;
|
||||
friend class Game;
|
||||
};
|
||||
|
||||
#endif // ENGINE_SCENE_H_
|
||||
@ -7,6 +7,30 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
enum class EventType {
|
||||
WINDOW_RESIZE,
|
||||
WINDOW_CLOSE,
|
||||
};
|
||||
|
||||
class Event {
|
||||
public:
|
||||
enum EventCategory {
|
||||
WINDOW,
|
||||
// KEYBOARD ...
|
||||
};
|
||||
|
||||
Event(EventCategory category) : m_category(category) {}
|
||||
virtual ~Event() {}
|
||||
|
||||
Event(const Event& event) = default;
|
||||
|
||||
inline const EventCategory GetCategory() const { return m_category; }
|
||||
|
||||
inline const virtual EventType GetType() const = 0;
|
||||
private:
|
||||
EventCategory m_category;
|
||||
};
|
||||
|
||||
class EventDispatcher {
|
||||
using Type = std::type_index;
|
||||
using RawFn = std::function<void(const void*)>;
|
||||
|
||||
@ -1,7 +1,30 @@
|
||||
#ifndef WINDOW_EVENTS_H_
|
||||
#define WINDOW_EVENTS_H_
|
||||
|
||||
struct WindowResized { int w, h; };
|
||||
struct WindowCloseRequested {};
|
||||
#include "engine/window/event.h"
|
||||
|
||||
class WindowEvent : public Event {
|
||||
public:
|
||||
WindowEvent() : Event(Event::EventCategory::WINDOW) {}
|
||||
|
||||
inline const EventType GetType() const override { return EventType::WINDOW_CLOSE; }
|
||||
};
|
||||
|
||||
class WindowResizeEvent : public WindowEvent {
|
||||
public:
|
||||
WindowResizeEvent(unsigned int w, unsigned int h) : m_width(w), m_height(h) {}
|
||||
|
||||
inline const EventType GetType() const override { return EventType::WINDOW_RESIZE; }
|
||||
|
||||
inline const unsigned int GetWidth() const { return m_width; }
|
||||
inline const unsigned int GetHeight() const { return m_height; }
|
||||
private:
|
||||
unsigned int m_width, m_height;
|
||||
};
|
||||
|
||||
class WindowCloseEvent : public WindowEvent {
|
||||
public:
|
||||
WindowCloseEvent() {}
|
||||
};
|
||||
|
||||
#endif // WINDOW_EVENTS_H_
|
||||
Reference in New Issue
Block a user