style: fix access specifier ordering

This commit is contained in:
light7734 2025-07-05 16:07:51 +03:30
parent ff56283c19
commit 6445d7b9ca
Signed by: light7734
GPG key ID: 8C30176798F1A6BA
72 changed files with 740 additions and 587 deletions

View file

@ -10,40 +10,39 @@ namespace Light {
class Window;
class Event;
class Instrumentor;
class Application /* singleton */
class Application
{
private:
static Application *s_Context;
private:
Scope<logger> m_logger;
Scope<Instrumentor> m_instrumentor;
Scope<LayerStack> m_layer_stack;
Scope<Input> m_input;
Scope<ResourceManager> m_resource_manager;
protected:
Scope<Window> m_window;
public:
Application(const Application &) = delete;
Application &operator=(const Application &) = delete;
virtual ~Application();
void game_loop();
// To be defined in client project
static void quit();
protected:
Application();
Scope<Window> m_window;
private:
static Application *s_context;
Scope<logger> m_logger;
Scope<Instrumentor> m_instrumentor;
Scope<LayerStack> m_layer_stack;
Scope<Input> m_input;
Scope<ResourceManager> m_resource_manager;
void on_event(const Event &event);
void log_debug_data();

View file

@ -6,13 +6,6 @@ namespace Light {
class UUID
{
private:
static std::mt19937_64 s_Engine;
static std::uniform_int_distribution<uint64_t> s_UniformDistribution;
private:
uint64_t m_uuid;
public:
UUID(uint64_t uuid = -1);
@ -20,6 +13,13 @@ public:
{
return m_uuid;
}
private:
static std::mt19937_64 s_engine;
static std::uniform_int_distribution<uint64_t> s_distribution;
uint64_t m_uuid;
};
} // namespace Light

View file

@ -17,11 +17,6 @@ struct WindowProperties
class Window
{
protected:
Scope<GraphicsContext> m_graphics_context;
WindowProperties m_properties;
bool b_Closed;
public:
static Scope<Window> create(std::function<void(Event &)> callback);
@ -30,15 +25,15 @@ public:
}
Window(const Window &) = delete;
Window &operator=(const Window &) = delete;
virtual ~Window() = default;
/* events */
virtual void poll_events() = 0;
virtual void on_event(const Event &event) = 0;
//======================================== SETTERS ========================================//
virtual void set_properties(
const WindowProperties &properties,
bool affectVisibility = false
@ -47,18 +42,17 @@ public:
virtual void set_title(const std::string &title) = 0;
virtual void set_size(const glm::uvec2 &size, bool additive = false) = 0; // pass 0 for width or
// height for single
// dimension resizing
// height for single
// dimension resizing
inline void close()
{
b_Closed = true;
}
virtual void set_v_sync(bool vsync, bool toggle = false) = 0;
virtual void set_visibility(bool visible, bool toggle = false) = 0;
//======================================== SETTERS ========================================//
//============================== GETTERS ==============================//
virtual void set_visibility(bool visible, bool toggle = false) = 0;
inline GraphicsContext *GetGfxContext() const
{
return m_graphics_context.get();
@ -91,9 +85,13 @@ public:
{
return m_properties.visible;
}
//============================== GETTERS ==============================//
protected:
Scope<GraphicsContext> m_graphics_context;
WindowProperties m_properties;
bool b_Closed;
};
} // namespace Light

View file

@ -13,39 +13,36 @@ struct ScopeProfileResult
uint32_t threadID;
};
// #todo: add event categories
// #todo: use ofstream in a separate thread
class Instrumentor /* singleton */
class Instrumentor
{
private:
static Instrumentor *s_Context;
private:
std::ofstream m_output_file_stream;
unsigned int m_current_session_count;
public:
static Scope<Instrumentor> create();
static inline void begin_session(const std::string &outputPath)
{
s_Context->begin_session_impl(outputPath);
s_context->begin_session_impl(outputPath);
}
static inline void end_session()
{
s_Context->end_session_impl();
s_context->end_session_impl();
}
static inline void submit_scope_profile(const ScopeProfileResult &profileResult)
{
s_Context->submit_scope_profile_impl(profileResult);
s_context->submit_scope_profile_impl(profileResult);
}
private:
static Instrumentor *s_context;
std::ofstream m_output_file_stream;
unsigned int m_current_session_count;
Instrumentor();
void begin_session_impl(const std::string &outputPath);
void end_session_impl();
void submit_scope_profile_impl(const ScopeProfileResult &profileResult);
@ -53,13 +50,15 @@ private:
class InstrumentorTimer
{
private:
ScopeProfileResult m_result;
std::chrono::time_point<std::chrono::steady_clock> m_start;
public:
InstrumentorTimer(const std::string &scopeName);
~InstrumentorTimer();
private:
ScopeProfileResult m_result;
std::chrono::time_point<std::chrono::steady_clock> m_start;
};
} // namespace Light

View file

@ -8,48 +8,46 @@
#define LT_LOG_FILE_LOCATION "Logs/logger.txt"
#ifndef LIGHT_DIST
#define lt_log(logLevel, ...) \
SPDLOG_LOGGER_CALL( \
#define lt_log(logLevel, ...) \
SPDLOG_LOGGER_CALL( \
::Light::logger::get_engine_logger(), \
spdlog::level::logLevel, \
__VA_ARGS__ \
spdlog::level::logLevel, \
__VA_ARGS__ \
)
#else
#define lt_log(logLevel, ...) \
SPDLOG_LOGGER_CALL( \
#define lt_log(logLevel, ...) \
SPDLOG_LOGGER_CALL( \
::Light::logger::get_file_logger(), \
spdlog::level::logLevel, \
__VA_ARGS__ \
spdlog::level::logLevel, \
__VA_ARGS__ \
)
#endif
namespace Light {
// #todo: extend
class logger /* singleton */
class logger
{
private:
static logger *s_Context;
private:
Ref<spdlog::logger> m_engine_logger, m_file_logger;
std::string m_log_file_path;
public:
static Scope<logger> create();
static inline Ref<spdlog::logger> get_engine_logger()
{
return s_Context->m_engine_logger;
return s_context->m_engine_logger;
}
static inline Ref<spdlog::logger> get_file_logger()
{
return s_Context->m_file_logger;
return s_context->m_file_logger;
}
void log_debug_data();
private:
static logger *s_context;
Ref<spdlog::logger> m_engine_logger, m_file_logger;
std::string m_log_file_path;
logger();
};

View file

@ -8,9 +8,6 @@ namespace Light {
class SetCharEvent: public Event
{
private:
const unsigned int m_character;
public:
SetCharEvent(unsigned int character): m_character(character)
{
@ -27,8 +24,13 @@ public:
ss << "CharSet: " << m_character;
return ss.str();
}
event_type(SetChar)
event_category(InputEventCategory | KeyboardEventCategory)
event_type(SetChar);
event_category(InputEventCategory | KeyboardEventCategory);
private:
const unsigned int m_character;
};
} // namespace Light

View file

@ -8,9 +8,6 @@ namespace Light {
class KeyPressedEvent: public Event
{
private:
const int m_key;
public:
KeyPressedEvent(int key): m_key(key)
{
@ -27,15 +24,17 @@ public:
ss << "KeyPressed: " << m_key;
return ss.str();
}
event_type(KeyPressed)
event_category(InputEventCategory | KeyboardEventCategory)
event_type(KeyPressed);
event_category(InputEventCategory | KeyboardEventCategory);
private:
const int m_key;
};
class KeyRepeatEvent: public Event
{
private:
const int m_key;
public:
KeyRepeatEvent(int key): m_key(key)
{
@ -52,15 +51,15 @@ public:
ss << "KeyRepeated: " << m_key;
return ss.str();
}
event_type(KeyRepeated)
event_category(InputEventCategory | KeyboardEventCategory)
event_type(KeyRepeated);
event_category(InputEventCategory | KeyboardEventCategory);
private:
const int m_key;
};
class KeyReleasedEvent: public Event
{
private:
const int m_key;
public:
KeyReleasedEvent(int key): m_key(key)
{
@ -77,8 +76,12 @@ public:
ss << "KeyReleased: " << m_key;
return ss.str();
}
event_type(KeyReleased)
event_category(InputEventCategory | KeyboardEventCategory)
event_type(KeyReleased);
event_category(InputEventCategory | KeyboardEventCategory);
private:
const int m_key;
};
} // namespace Light

View file

@ -9,9 +9,6 @@ namespace Light {
class MouseMovedEvent: public Event
{
private:
const glm::vec2 m_position;
public:
MouseMovedEvent(float x, float y): m_position(x, y)
{
@ -37,15 +34,15 @@ public:
ss << "MouseMoved: " << m_position.x << ", " << m_position.y;
return ss.str();
}
event_type(MouseMoved)
event_category(InputEventCategory | MouseEventCategory)
event_type(MouseMoved);
event_category(InputEventCategory | MouseEventCategory);
private:
const glm::vec2 m_position;
};
class WheelScrolledEvent: public Event
{
private:
const float m_offset;
public:
WheelScrolledEvent(float offset): m_offset(offset)
{
@ -62,15 +59,15 @@ public:
ss << "WheelScrolled: " << m_offset;
return ss.str();
}
event_type(WheelScrolled)
event_category(InputEventCategory | MouseEventCategory)
event_type(WheelScrolled);
event_category(InputEventCategory | MouseEventCategory);
private:
const float m_offset;
};
class ButtonPressedEvent: public Event
{
private:
const int m_button;
public:
ButtonPressedEvent(int button): m_button(button)
{
@ -87,15 +84,15 @@ public:
ss << "ButtonPressed: " << m_button;
return ss.str();
}
event_type(ButtonPressed)
event_category(InputEventCategory | MouseEventCategory)
event_type(ButtonPressed);
event_category(InputEventCategory | MouseEventCategory);
private:
const int m_button;
};
class ButtonReleasedEvent: public Event
{
private:
const int m_button;
public:
ButtonReleasedEvent(int button): m_button(button)
{
@ -112,8 +109,12 @@ public:
ss << "ButtonReleased: " << m_button;
return ss.str();
}
event_type(ButtonReleased)
event_category(InputEventCategory | MouseEventCategory)
event_type(ButtonReleased);
event_category(InputEventCategory | MouseEventCategory);
private:
const int m_button;
};
} // namespace Light

View file

@ -14,15 +14,14 @@ public:
{
return "WindowClosedEvent";
}
event_type(WindowClosed)
event_category(WindowEventCategory)
event_type(WindowClosed);
event_category(WindowEventCategory);
};
class WindowMovedEvent: public Event
{
private:
const glm::ivec2 m_position;
public:
WindowMovedEvent(int x, int y): m_position(x, y)
{
@ -40,15 +39,17 @@ public:
return ss.str();
;
}
event_type(WindowMoved)
event_category(WindowEventCategory)
event_type(WindowMoved);
event_category(WindowEventCategory);
private:
const glm::ivec2 m_position;
};
class WindowResizedEvent: public Event
{
private:
const glm::uvec2 m_size;
public:
WindowResizedEvent(unsigned int width, unsigned int height): m_size(width, height)
{
@ -65,8 +66,13 @@ public:
ss << "WindowResized: " << m_size.x << ", " << m_size.y;
return ss.str();
}
event_type(WindowResized)
event_category(WindowEventCategory)
event_type(WindowResized);
event_category(WindowEventCategory);
private:
const glm::uvec2 m_size;
};
class WindowLostFocusEvent: public Event
@ -76,8 +82,9 @@ public:
{
return "WindowLostFocus";
}
event_type(WindowLostFocus)
event_category(WindowEventCategory)
event_type(WindowLostFocus);
event_category(WindowEventCategory);
};
class WindowGainFocusEvent: public Event
@ -87,8 +94,9 @@ public:
{
return "WindowGainFocus";
}
event_type(WindowGainFocus)
event_category(WindowEventCategory)
event_type(WindowGainFocus);
event_category(WindowEventCategory);
};
} // namespace Light

View file

@ -40,7 +40,7 @@ public:
static Scope<Blender> create(Ref<SharedContext> sharedContext);
virtual void enable(BlendFactor srcFactor, BlendFactor dstFactor) = 0;
virtual void disable() = 0;
virtual void disable() = 0;
protected:
Blender() = default;

View file

@ -9,9 +9,7 @@ namespace Light {
class renderer;
class resource_manager;
class SharedContext;
class UserInterface;
class WindowResizedEvent;
enum class GraphicsAPI
@ -19,41 +17,56 @@ enum class GraphicsAPI
Default = 0,
OpenGL,
DirectX,
Vulkan, // :#todo
Metal // :#todo
Vulkan,
Metal
};
class GraphicsContext /* singleton */
class GraphicsContext
{
private:
static GraphicsContext* s_Context;
private:
Scope<UserInterface> m_user_interface;
Scope<renderer> m_renderer;
protected:
GraphicsAPI m_graphics_api;
Ref<SharedContext> m_shared_context = nullptr;
public:
static Scope<GraphicsContext> create(GraphicsAPI api, GLFWwindow* windowHandle);
static Scope<GraphicsContext> create(GraphicsAPI api, GLFWwindow *windowHandle);
GraphicsContext(const GraphicsContext&) = delete;
GraphicsContext& operator=(const GraphicsContext&) = delete;
GraphicsContext(const GraphicsContext &) = delete;
GraphicsContext &operator=(const GraphicsContext &) = delete;
virtual ~GraphicsContext();
virtual void log_debug_data() = 0;
static inline GraphicsAPI get_graphics_api() { return s_Context->m_graphics_api; }
static inline Ref<SharedContext> get_shared_context() { return s_Context->m_shared_context; }
static inline GraphicsAPI get_graphics_api()
{
return s_context->m_graphics_api;
}
inline renderer* GetRenderer() { return m_renderer.get(); }
inline UserInterface* GetUserInterface() { return m_user_interface.get(); }
static inline Ref<SharedContext> get_shared_context()
{
return s_context->m_shared_context;
}
inline renderer *GetRenderer()
{
return m_renderer.get();
}
inline UserInterface *GetUserInterface()
{
return m_user_interface.get();
}
protected:
GraphicsContext() = default;
GraphicsAPI m_graphics_api;
Ref<SharedContext> m_shared_context = nullptr;
private:
static GraphicsContext *s_context;
Scope<UserInterface> m_user_interface;
Scope<renderer> m_renderer;
};
} // namespace Light

View file

@ -15,14 +15,17 @@ public:
static Scope<RenderCommand> create(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext);
RenderCommand(const RenderCommand &) = delete;
RenderCommand &operator=(const RenderCommand &) = delete;
virtual ~RenderCommand() = default;
virtual void swap_buffers() = 0;
virtual void clear_back_buffer(const glm::vec4 &clearColor) = 0;
virtual void draw(unsigned int count) = 0;
virtual void draw_indexed(unsigned int count) = 0;
virtual void default_target_framebuffer() = 0;

View file

@ -18,34 +18,12 @@ class ConstantBuffer;
class Framebuffer;
class RenderCommand;
class Texture;
class SharedContext;
class Camera;
class WindowResizedEvent;
class renderer
{
private:
static renderer *s_Context;
// renderer programs
QuadRendererProgram m_quad_renderer;
TextureRendererProgram m_texture_renderer;
TintedTextureRendererProgram m_tinted_texture_renderer;
// constant buffers
Scope<ConstantBuffer> m_view_projection_buffer;
Scope<RenderCommand> m_render_command;
Scope<Blender> m_blender;
Camera *m_default_framebuffer_camera;
Ref<Framebuffer> m_target_framebuffer;
bool m_should_clear_backbuffer;
public:
static Scope<renderer> create(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext);
@ -56,36 +34,40 @@ public:
Ref<Texture> texture
)
{
s_Context->draw_quad_impl(position, size, tint, texture);
s_context->draw_quad_impl(position, size, tint, texture);
}
static inline void draw_quad(
const glm::vec3 &position,
const glm::vec2 &size,
const glm::vec4 &tint
)
{
s_Context->draw_quad_impl(position, size, tint);
s_context->draw_quad_impl(position, size, tint);
}
static inline void draw_quad(
const glm::vec3 &position,
const glm::vec2 &size,
Ref<Texture> texture
)
{
s_Context->draw_quad_impl(position, size, texture);
s_context->draw_quad_impl(position, size, texture);
}
static void draw_quad(const glm::mat4 &transform, const glm::vec4 &tint, Ref<Texture> texture)
{
s_Context->draw_quad_impl(transform, tint, texture);
s_context->draw_quad_impl(transform, tint, texture);
}
static void draw_quad(const glm::mat4 &transform, const glm::vec4 &tint)
{
s_Context->draw_quad_impl(transform, tint);
s_context->draw_quad_impl(transform, tint);
}
static void draw_quad(const glm::mat4 &transform, Ref<Texture> texture)
{
s_Context->draw_quad_impl(transform, texture);
s_context->draw_quad_impl(transform, texture);
}
static inline void begin_scene(
@ -94,11 +76,11 @@ public:
const Ref<Framebuffer> &targetFrameBuffer = nullptr
)
{
s_Context->begin_scene_impl(camera, cameraTransform, targetFrameBuffer);
s_context->begin_scene_impl(camera, cameraTransform, targetFrameBuffer);
}
static inline void end_scene()
{
s_Context->end_scene_impl();
s_context->end_scene_impl();
}
void on_window_resize(const WindowResizedEvent &event);
@ -107,6 +89,26 @@ public:
void end_frame();
private:
static renderer *s_context;
QuadRendererProgram m_quad_renderer;
TextureRendererProgram m_texture_renderer;
TintedTextureRendererProgram m_tinted_texture_renderer;
Scope<ConstantBuffer> m_view_projection_buffer;
Scope<RenderCommand> m_render_command;
Scope<Blender> m_blender;
Camera *m_default_framebuffer_camera;
Ref<Framebuffer> m_target_framebuffer;
bool m_should_clear_backbuffer;
renderer(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext);
void draw_quad_impl(
@ -115,11 +117,15 @@ private:
const glm::vec4 &tint,
Ref<Texture> texture
);
void draw_quad_impl(const glm::vec3 &position, const glm::vec2 &size, const glm::vec4 &tint);
void draw_quad_impl(const glm::vec3 &position, const glm::vec2 &size, Ref<Texture> texture);
void draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint, Ref<Texture> texture);
void draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint);
void draw_quad_impl(const glm::mat4 &transform, Ref<Texture> texture);
void begin_scene_impl(
@ -127,7 +133,9 @@ private:
const glm::mat4 &cameraTransform,
const Ref<Framebuffer> &targetFrameBuffer = nullptr
);
void flush_scene();
void end_scene_impl();
};

View file

@ -24,24 +24,12 @@ public:
glm::vec4 tint;
};
private:
Ref<Shader> m_shader;
Ref<VertexBuffer> m_vertex_buffer;
Ref<IndexBuffer> m_index_buffer;
Ref<VertexLayout> m_vertex_layout;
QuadVertexData *m_map_current = nullptr;
QuadVertexData *m_map_end = nullptr;
unsigned int m_quad_count = 0u;
unsigned int m_max_vertices = 0u;
public:
QuadRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext);
bool advance();
void map() override;
void un_map() override;
void bind() override;
@ -50,14 +38,33 @@ public:
{
return m_map_current;
}
inline unsigned int get_quad_count() const
{
return m_quad_count;
}
inline constexpr unsigned int get_vertex_size() const
{
return sizeof(QuadVertexData);
}
private:
Ref<Shader> m_shader;
Ref<VertexBuffer> m_vertex_buffer;
Ref<IndexBuffer> m_index_buffer;
Ref<VertexLayout> m_vertex_layout;
QuadVertexData *m_map_current = nullptr;
QuadVertexData *m_map_end = nullptr;
unsigned int m_quad_count = 0u;
unsigned int m_max_vertices = 0u;
};
} // namespace Light

View file

@ -8,7 +8,8 @@ class OrthographicCamera;
class RendererProgram
{
virtual void map() = 0;
virtual void map() = 0;
virtual void un_map() = 0;
virtual void bind() = 0;

View file

@ -10,9 +10,7 @@ class Shader;
class VertexBuffer;
class IndexBuffer;
class VertexLayout;
class OrthographicCamera;
class SharedContext;
class TextureRendererProgram: RendererProgram
@ -24,24 +22,12 @@ public:
glm::vec2 texcoord;
};
private:
Ref<Shader> m_shader;
Ref<VertexBuffer> m_vertex_buffer;
Ref<IndexBuffer> m_index_buffer;
Ref<VertexLayout> m_vertex_layout;
TextureVertexData *m_map_current = nullptr;
TextureVertexData *m_map_end = nullptr;
unsigned int m_quad_count;
unsigned int m_max_vertices;
public:
TextureRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext);
bool advance();
void map() override;
void un_map() override;
void bind() override;
@ -60,6 +46,23 @@ public:
{
return sizeof(TextureVertexData);
}
private:
Ref<Shader> m_shader;
Ref<VertexBuffer> m_vertex_buffer;
Ref<IndexBuffer> m_index_buffer;
Ref<VertexLayout> m_vertex_layout;
TextureVertexData *m_map_current = nullptr;
TextureVertexData *m_map_end = nullptr;
unsigned int m_quad_count;
unsigned int m_max_vertices;
};
} // namespace Light

View file

@ -25,19 +25,6 @@ public:
glm::vec2 texcoord;
};
private:
Ref<Shader> m_shader;
Ref<VertexBuffer> m_vertex_buffer;
Ref<IndexBuffer> m_index_buffer;
Ref<VertexLayout> m_vertex_layout;
TintedTextureVertexData *m_map_current = nullptr;
TintedTextureVertexData *m_map_end = nullptr;
unsigned int m_quad_count;
unsigned int m_max_vertices;
public:
TintedTextureRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext);
bool advance();
@ -61,6 +48,23 @@ public:
{
return sizeof(TintedTextureVertexData);
}
private:
Ref<Shader> m_shader;
Ref<VertexBuffer> m_vertex_buffer;
Ref<IndexBuffer> m_index_buffer;
Ref<VertexLayout> m_vertex_layout;
TintedTextureVertexData *m_map_current = nullptr;
TintedTextureVertexData *m_map_end = nullptr;
unsigned int m_quad_count;
unsigned int m_max_vertices;
};
} // namespace Light

View file

@ -19,16 +19,16 @@ public:
GEOMETRY = 3
};
public:
static Ref<Shader> create(
basic_file_handle vertexFile,
basic_file_handle pixelFile,
BasicFileHandle vertexFile,
BasicFileHandle pixelFile,
Ref<SharedContext> sharedContext
);
virtual ~Shader() = default;
virtual void bind() = 0;
virtual void un_bind() = 0;
protected:

View file

@ -10,24 +10,34 @@ class SharedContext;
class Texture
{
public:
static Ref<Texture> create(unsigned int width, unsigned int height, unsigned int components, unsigned char* pixels, Ref<SharedContext> sharedContext, const std::string& filePath);
static Ref<Texture> create(
unsigned int width,
unsigned int height,
unsigned int components,
unsigned char *pixels,
Ref<SharedContext> sharedContext,
const std::string &filePath
);
Texture(const Texture&) = delete;
Texture& operator=(const Texture&) = delete;
Texture(const Texture &) = delete;
Texture &operator=(const Texture &) = delete;
virtual ~Texture() = default;
virtual void bind(unsigned int slot = 0) = 0;
virtual void* get_texture() = 0;
virtual void *get_texture() = 0;
inline const std::string& GetFilePath() const { return m_file_path; }
protected:
Texture(const std::string& filePath);
inline const std::string &GetFilePath() const
{
return m_file_path;
}
protected:
std::string m_file_path;
Texture(const std::string &filePath);
};
} // namespace Light

View file

@ -6,7 +6,6 @@ namespace Light {
class VertexBuffer;
class Shader;
class SharedContext;
enum class VertexElementType
@ -42,9 +41,9 @@ public:
);
virtual ~VertexLayout() = default;
;
virtual void bind() = 0;
virtual void un_bind() = 0;
protected:

View file

@ -8,46 +8,32 @@ namespace Light {
class Event;
class Input /* singleton */
class Input
{
private:
static Input *s_Context;
private:
std::array<bool, 348> m_keyboad_keys;
std::array<bool, 8> m_mouse_buttons;
glm::vec2 m_mouse_position;
glm::vec2 m_mouse_delta;
float m_mouse_wheel_delta;
bool m_user_interface_events;
bool m_game_events;
public:
static Scope<Input> create();
static inline void receive_user_interface_events(bool receive, bool toggle = false)
{
s_Context->receive_user_interface_events_impl(receive, toggle);
s_context->receive_user_interface_events_impl(receive, toggle);
}
static inline void receive_game_events(bool receive, bool toggle = false)
{
s_Context->receieve_game_events_impl(receive, toggle);
s_context->receieve_game_events_impl(receive, toggle);
}
static inline bool get_keyboard_key(int code)
{
return s_Context->m_keyboad_keys[code];
return s_context->m_keyboad_keys[code];
}
static inline bool get_mouse_button(int code)
{
return s_Context->m_mouse_buttons[code];
return s_context->m_mouse_buttons[code];
}
static inline const glm::vec2 &GetMousePosition(int code)
static inline const glm::vec2 &get_mouse_position(int code)
{
return s_Context->m_mouse_position;
return s_context->m_mouse_position;
}
void on_event(const Event &inputEvent);
@ -62,9 +48,26 @@ public:
}
private:
static Input *s_context;
std::array<bool, 348> m_keyboad_keys;
std::array<bool, 8> m_mouse_buttons;
glm::vec2 m_mouse_position;
glm::vec2 m_mouse_delta;
float m_mouse_wheel_delta;
bool m_user_interface_events;
bool m_game_events;
Input();
void receive_user_interface_events_impl(bool receive, bool toggle = false);
void receieve_game_events_impl(bool receive, bool toggle = false);
void restart_input_state();

View file

@ -11,16 +11,10 @@ class MouseMovedEvent;
class ButtonPressedEvent;
class ButtonReleasedEvent;
class WheelScrolledEvent;
// keyboard
// key
class KeyPressedEvent;
class KeyRepeatEvent;
class KeyReleasedEvent;
// char
class SetCharEvent;
// window
class WindowClosedEvent;
class WindowResizedEvent;
class WindowMovedEvent;
@ -29,19 +23,15 @@ class WindowGainFocusEvent;
class Layer
{
protected:
std::string m_layer_name;
public:
Layer(const std::string &name);
virtual ~Layer() = default;
inline const std::string &GetName() const
const std::string &GetName() const
{
return m_layer_name;
}
/* update */
virtual void on_update(float deltaTime)
{
}
@ -56,67 +46,68 @@ public:
bool on_event(const Event &event);
protected:
/* mouse */
// cursor
std::string m_layer_name;
virtual bool on_mouse_moved(const MouseMovedEvent &event)
{
return false;
}
// button
virtual bool on_button_pressed(const ButtonPressedEvent &event)
{
return false;
}
virtual bool on_button_released(const ButtonReleasedEvent &event)
{
return false;
}
// wheel
virtual bool on_wheel_scrolled(const WheelScrolledEvent &event)
{
return false;
}
/* keyboard */
// key
virtual bool on_key_pressed(const KeyPressedEvent &event)
{
return false;
}
virtual bool on_key_repeat(const KeyRepeatEvent &event)
{
return false;
}
virtual bool on_key_released(const KeyReleasedEvent &event)
{
return false;
}
// char
virtual bool on_set_char(const SetCharEvent &event)
{
return false;
}
/* window */
// termination
virtual bool on_window_closed(const WindowClosedEvent &event)
{
return false;
}
// size/position
virtual bool on_window_resized(const WindowResizedEvent &event)
{
return false;
}
virtual bool on_window_moved(const WindowMovedEvent &event)
{
return false;
}
// focus
virtual bool on_window_lost_focus(const WindowLostFocusEvent &event)
{
return false;
}
virtual bool on_window_gain_focus(const WindowGainFocusEvent &event)
{
return false;

View file

@ -5,20 +5,10 @@
namespace Light {
class Layer;
class Event;
class LayerStack /* singleton */
{
private:
static LayerStack *s_Context;
private:
std::vector<Layer *> m_layers;
std::vector<Layer *>::iterator m_begin;
std::vector<Layer *>::iterator m_end;
public:
static Scope<LayerStack> create();
@ -28,16 +18,16 @@ public:
template<typename t, typename... Args>
static inline void emplace_layer(Args &&...args)
{
s_Context->attach_layer_impl(new t((args)...));
s_context->attach_layer_impl(new t((args)...));
}
static inline void attach_layer(Layer *layer)
{
s_Context->attach_layer_impl(layer);
s_context->attach_layer_impl(layer);
}
static inline void detach_layer(Layer *layer)
{
s_Context->detach_layer_impl(layer);
s_context->detach_layer_impl(layer);
}
inline bool is_empty()
@ -49,23 +39,35 @@ public:
{
return m_layers.begin();
}
std::vector<Layer *>::iterator end()
{
return m_layers.end();
}
std::vector<Layer *>::reverse_iterator rbegin()
{
return m_layers.rbegin();
}
std::vector<Layer *>::reverse_iterator rend()
{
return m_layers.rend();
}
private:
static LayerStack *s_context;
std::vector<Layer *> m_layers;
std::vector<Layer *>::iterator m_begin;
std::vector<Layer *>::iterator m_end;
LayerStack();
void attach_layer_impl(Layer *layer);
void detach_layer_impl(Layer *layer);
};

View file

@ -11,6 +11,13 @@ class dxSharedContext;
class dxBlender: public Blender
{
public:
dxBlender(Ref<dxSharedContext> sharedContext);
void enable(BlendFactor srcFactor, BlendFactor dstFactor) override;
void disable() override;
private:
Ref<dxSharedContext> m_context;
@ -19,12 +26,6 @@ private:
Microsoft::WRL::ComPtr<ID3D11BlendState> m_blend_state;
D3D11_BLEND_DESC m_desc;
public:
dxBlender(Ref<dxSharedContext> sharedContext);
void enable(BlendFactor srcFactor, BlendFactor dstFactor) override;
void disable() override;
};
} // namespace Light

View file

@ -9,17 +9,8 @@ namespace Light {
class dxSharedContext;
//========== CONSTANT_BUFFER ==========//
class dxConstantBuffer: public ConstantBuffer
{
private:
Ref<dxSharedContext> m_context;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_buffer;
D3D11_MAPPED_SUBRESOURCE m_map;
unsigned int m_index;
public:
dxConstantBuffer(
ConstantBufferIndex index,
@ -30,20 +21,21 @@ public:
void bind() override;
void *map() override;
void un_map() override;
};
//========== VERTEX_BUFFER ==========//
class dxVertexBuffer: public VertexBuffer
{
void un_map() override;
private:
Ref<dxSharedContext> m_context;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_buffer;
D3D11_MAPPED_SUBRESOURCE m_map;
unsigned int m_stride;
unsigned int m_index;
};
class dxVertexBuffer: public VertexBuffer
{
public:
dxVertexBuffer(
float *vertices,
@ -51,29 +43,42 @@ public:
unsigned int count,
Ref<dxSharedContext> sharedContext
);
~dxVertexBuffer();
void bind() override;
void un_bind() override;
void *map() override;
void un_map() override;
};
//========== INDEX_BUFFER ==========//
class dxIndexBuffer: public IndexBuffer
{
void un_map() override;
private:
Ref<dxSharedContext> m_context;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_buffer;
D3D11_MAPPED_SUBRESOURCE m_map;
unsigned int m_stride;
};
class dxIndexBuffer: public IndexBuffer
{
public:
dxIndexBuffer(unsigned int *indices, unsigned int count, Ref<dxSharedContext> sharedContext);
~dxIndexBuffer();
void bind() override;
void un_bind() override;
private:
Ref<dxSharedContext> m_context;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_buffer;
};
} // namespace Light

View file

@ -11,17 +11,6 @@ class dxSharedContext;
class dxFramebuffer: public Framebuffer
{
private:
Ref<dxSharedContext> m_context;
FramebufferSpecification m_specification;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_render_target_view;
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_color_attachment;
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_depth_stencil_attachment;
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_shader_resource_view;
Microsoft::WRL::ComPtr<ID3D11DepthStencilView> m_depth_stencil_view;
public:
dxFramebuffer(
const FramebufferSpecification &specification,
@ -34,9 +23,25 @@ public:
}
void bind_as_target(const glm::vec4 &clearColor) override;
void bind_as_resource() override;
void resize(const glm::uvec2 &size) override;
private:
Ref<dxSharedContext> m_context;
FramebufferSpecification m_specification;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_render_target_view;
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_color_attachment;
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_depth_stencil_attachment;
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_shader_resource_view;
Microsoft::WRL::ComPtr<ID3D11DepthStencilView> m_depth_stencil_view;
};
} // namespace Light

View file

@ -11,19 +11,20 @@ namespace Light {
class dxGraphicsContext: public GraphicsContext
{
private:
GLFWwindow *m_window_handle;
Microsoft::WRL::ComPtr<ID3D11Debug> m_debug_interface;
public:
dxGraphicsContext(GLFWwindow *windowHandle);
virtual void log_debug_data() override;
private:
GLFWwindow *m_window_handle;
Microsoft::WRL::ComPtr<ID3D11Debug> m_debug_interface;
void setup_device_and_swap_chain(GLFWwindow *windowHandle);
void setup_render_targets();
void setup_debug_interface();
};

View file

@ -11,16 +11,15 @@ class dxSharedContext;
class dxRenderCommand: public RenderCommand
{
private:
Ref<dxSharedContext> m_context;
public:
dxRenderCommand(Ref<dxSharedContext> sharedContext);
virtual void swap_buffers() override;
virtual void clear_back_buffer(const glm::vec4 &clearColor) override;
virtual void draw(unsigned int count) override;
virtual void draw_indexed(unsigned int count) override;
virtual void default_target_framebuffer() override;
@ -33,6 +32,8 @@ public:
) override;
private:
Ref<dxSharedContext> m_context;
void set_resolution(unsigned int width, unsigned int height);
};

View file

@ -12,29 +12,32 @@ class dxSharedContext;
class dxShader: public Shader
{
private:
Ref<dxSharedContext> m_context;
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vertex_shader;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_pixel_shader;
Microsoft::WRL::ComPtr<ID3DBlob> m_vertex_blob;
public:
dxShader(
basic_file_handle vertexFile,
basic_file_handle pixelFile,
BasicFileHandle vertexFile,
BasicFileHandle pixelFile,
Ref<dxSharedContext> sharedContext
);
~dxShader();
void bind() override;
void un_bind() override;
inline Microsoft::WRL::ComPtr<ID3DBlob> get_vertex_blob()
{
return m_vertex_blob;
}
private:
Ref<dxSharedContext> m_context;
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vertex_shader;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_pixel_shader;
Microsoft::WRL::ComPtr<ID3DBlob> m_vertex_blob;
};
} // namespace Light

View file

@ -9,25 +9,22 @@ namespace Light {
class dxSharedContext: public SharedContext
{
private:
Microsoft::WRL::ComPtr<ID3D11Device> m_device = nullptr;
Microsoft::WRL::ComPtr<ID3D11DeviceContext> m_deviceContext = nullptr;
Microsoft::WRL::ComPtr<IDXGISwapChain> m_swap_chain = nullptr;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_render_target_view = nullptr;
public:
inline Microsoft::WRL::ComPtr<ID3D11Device> get_device()
{
return m_device;
}
inline Microsoft::WRL::ComPtr<ID3D11DeviceContext> get_device_context()
{
return m_deviceContext;
}
inline Microsoft::WRL::ComPtr<IDXGISwapChain> get_swap_chain()
{
return m_swap_chain;
}
inline Microsoft::WRL::ComPtr<ID3D11RenderTargetView> get_render_target_view()
{
return m_render_target_view;
@ -37,18 +34,30 @@ public:
{
return m_device;
}
inline Microsoft::WRL::ComPtr<ID3D11DeviceContext> &GetDeviceContextRef()
{
return m_deviceContext;
}
inline Microsoft::WRL::ComPtr<IDXGISwapChain> &GetSwapChainRef()
{
return m_swap_chain;
}
inline Microsoft::WRL::ComPtr<ID3D11RenderTargetView> &GetRenderTargetViewRef()
{
return m_render_target_view;
}
private:
Microsoft::WRL::ComPtr<ID3D11Device> m_device = nullptr;
Microsoft::WRL::ComPtr<ID3D11DeviceContext> m_deviceContext = nullptr;
Microsoft::WRL::ComPtr<IDXGISwapChain> m_swap_chain = nullptr;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_render_target_view = nullptr;
};
} // namespace Light

View file

@ -11,13 +11,6 @@ class dxSharedContext;
class dxTexture: public Texture
{
private:
Ref<dxSharedContext> m_context;
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_texture_2d;
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_shader_resource_view;
Microsoft::WRL::ComPtr<ID3D11SamplerState> m_sampler_state;
public:
dxTexture(
unsigned int width,
@ -29,6 +22,15 @@ public:
);
void bind(unsigned int slot = 0u) override;
private:
Ref<dxSharedContext> m_context;
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_texture_2d;
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_shader_resource_view;
Microsoft::WRL::ComPtr<ID3D11SamplerState> m_sampler_state;
};
} // namespace Light

View file

@ -15,12 +15,14 @@ class dxUserInterface: public UserInterface
{
public:
dxUserInterface() = default;
~dxUserInterface();
void platform_implementation(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext)
override;
void begin() override;
void end() override;
void log_debug_data() override;

View file

@ -8,29 +8,29 @@
namespace Light {
class Shader;
class dxSharedContext;
class dxVertexLayout: public VertexLayout
{
private:
Ref<dxSharedContext> m_context;
Microsoft::WRL::ComPtr<ID3D11InputLayout> m_input_layout;
public:
dxVertexLayout(
Ref<Shader> shader,
const std::vector<std::pair<std::string, VertexElementType>> &elements,
Ref<dxSharedContext> sharedContext
);
~dxVertexLayout();
void bind() override;
void un_bind() override;
private:
DXGI_FORMAT get_dxgi_format(VertexElementType type);
Ref<dxSharedContext> m_context;
Microsoft::WRL::ComPtr<ID3D11InputLayout> m_input_layout;
};
} // namespace Light

View file

@ -7,14 +7,15 @@ namespace Light {
class glBlender: public Blender
{
private:
std::unordered_map<BlendFactor, unsigned int> m_factor_map;
public:
glBlender();
void enable(BlendFactor srcFactor, BlendFactor dstFactor) override;
void disable() override;
private:
std::unordered_map<BlendFactor, unsigned int> m_factor_map;
};
} // namespace Light

View file

@ -5,52 +5,57 @@
namespace Light {
//========== CONSTANT_BUFFER ==========//
class glConstantBuffer: public ConstantBuffer
{
private:
unsigned int m_buffer_id;
unsigned int m_index;
public:
glConstantBuffer(ConstantBufferIndex index, unsigned int size);
~glConstantBuffer();
void bind() override;
void *map() override;
void un_map() override;
};
//========== VERTEX_BUFFER ==========//
class glVertexBuffer: public VertexBuffer
{
void un_map() override;
private:
unsigned int m_buffer_id;
unsigned int m_index;
};
class glVertexBuffer: public VertexBuffer
{
public:
glVertexBuffer(float *vertices, unsigned int stride, unsigned int count);
~glVertexBuffer();
void bind() override;
void un_bind() override;
void *map() override;
void un_map() override;
};
//========== INDEX_BUFFER ==========//
class glIndexBuffer: public IndexBuffer
{
void un_map() override;
private:
unsigned int m_buffer_id;
};
class glIndexBuffer: public IndexBuffer
{
public:
glIndexBuffer(unsigned int *indices, unsigned int count);
~glIndexBuffer();
void bind() override;
void un_bind() override;
private:
unsigned int m_buffer_id;
};
} // namespace Light

View file

@ -7,17 +7,13 @@ namespace Light {
class glFramebuffer: public Framebuffer
{
private:
FramebufferSpecification m_specification;
unsigned int m_buffer_id;
unsigned int m_color_attachment_id, m_depth_stencil_attachment_id;
public:
glFramebuffer(const FramebufferSpecification &specification);
~glFramebuffer();
void bind_as_target(const glm::vec4 &clearColor) override;
void bind_as_resource() override;
void resize(const glm::uvec2 &size) override;
@ -26,6 +22,15 @@ public:
{
return (void *)m_color_attachment_id;
}
private:
FramebufferSpecification m_specification;
unsigned int m_buffer_id;
unsigned int m_color_attachment_id;
unsigned int m_depth_stencil_attachment_id;
};
} // namespace Light

View file

@ -9,15 +9,14 @@ namespace Light {
class glGraphicsContext: public GraphicsContext
{
private:
GLFWwindow *m_window_handle;
public:
glGraphicsContext(GLFWwindow *windowHandle);
void log_debug_data() override;
private:
GLFWwindow *m_window_handle;
void set_debug_message_callback();
};

View file

@ -9,22 +9,24 @@ namespace Light {
class glRenderCommand: public RenderCommand
{
private:
GLFWwindow *m_window_handle;
public:
glRenderCommand(GLFWwindow *windowHandle);
void swap_buffers() override;
void clear_back_buffer(const glm::vec4 &clearColor) override;
void draw(unsigned int count) override;
void draw_indexed(unsigned int count) override;
void default_target_framebuffer() override;
void set_viewport(unsigned int x, unsigned int y, unsigned int width, unsigned int height)
override;
private:
GLFWwindow *m_window_handle;
};
} // namespace Light

View file

@ -8,20 +8,19 @@ namespace Light {
class glShader: public Shader
{
private:
unsigned int m_shader_id;
public:
glShader(basic_file_handle vertexFile, basic_file_handle pixelFile);
glShader(BasicFileHandle vertexFile, BasicFileHandle pixelFile);
~glShader();
void bind() override;
void un_bind() override;
private:
// shaderc::SpvCompilationResult compile_glsl(basic_file_handle file, Shader::Stage stage);
unsigned int compile_shader(std::string source, Shader::Stage stage);
unsigned int m_shader_id;
};
} // namespace Light

View file

@ -7,16 +7,23 @@ namespace Light {
class glTexture: public Texture
{
private:
unsigned int m_texture_id;
public:
glTexture(unsigned int width, unsigned int height, unsigned int components, unsigned char* pixels, const std::string& filePath);
glTexture(
unsigned int width,
unsigned int height,
unsigned int components,
unsigned char *pixels,
const std::string &filePath
);
~glTexture();
void bind(unsigned int slot = 0u) override;
void* get_texture() override;
void *get_texture() override;
private:
unsigned int m_texture_id;
};
} // namespace Light

View file

@ -9,20 +9,22 @@ namespace Light {
class glUserInterface: public UserInterface
{
private:
GLFWwindow *m_window_handle;
public:
glUserInterface() = default;
~glUserInterface();
void platform_implementation(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext)
override;
void begin() override;
void end() override;
void log_debug_data() override;
private:
GLFWwindow *m_window_handle;
};
} // namespace Light

View file

@ -10,28 +10,32 @@ class VertexBuffer;
struct glVertexElementDesc
{
unsigned int type;
unsigned int count;
unsigned int typeSize;
unsigned int offset;
};
class glVertexLayout: public VertexLayout
{
private:
unsigned int m_array_id;
public:
glVertexLayout(
Ref<VertexBuffer> buffer,
const std::vector<std::pair<std::string, VertexElementType>> &elements
);
~glVertexLayout();
void bind() override;
void un_bind() override;
private:
glVertexElementDesc get_element_desc(VertexElementType type, unsigned int offset);
unsigned int m_array_id;
};
} // namespace Light

View file

@ -12,20 +12,15 @@ class WindowResizedEvent;
class lWindow: public Window
{
private:
GLFWwindow *m_handle;
std::function<void(Event &)> m_event_callback;
public:
lWindow(std::function<void(Event &)> callback);
~lWindow();
/* events */
void poll_events() override;
void on_event(const Event &event) override;
//======================================== SETTERS ========================================//
void set_properties(const WindowProperties &properties, bool overrideVisibility = false)
override;
@ -34,10 +29,14 @@ public:
void set_size(const glm::uvec2 &size, bool additive = false) override;
void set_v_sync(bool vsync, bool toggle = false) override;
void set_visibility(bool visible, bool toggle = false) override;
//======================================== SETTERS ========================================//
private:
GLFWwindow *m_handle;
std::function<void(Event &)> m_event_callback;
void on_window_resize(const WindowResizedEvent &event);
void bind_glfw_events();

View file

@ -12,20 +12,15 @@ class WindowResizedEvent;
class wWindow: public Window
{
private:
GLFWwindow *m_handle;
std::function<void(Event &)> m_event_callback;
public:
wWindow(std::function<void(Event &)> callback);
~wWindow();
/* events */
void poll_events() override;
void on_event(const Event &event) override;
//======================================== SETTERS ========================================//
void set_properties(const WindowProperties &properties, bool overrideVisibility = false)
override;
@ -34,10 +29,14 @@ public:
void set_size(const glm::uvec2 &size, bool additive = false) override;
void set_v_sync(bool vsync, bool toggle = false) override;
void set_visibility(bool visible, bool toggle = false) override;
//======================================== SETTERS ========================================//
private:
GLFWwindow *m_handle;
std::function<void(Event &)> m_event_callback;
void on_window_resize(const WindowResizedEvent &event);
void bind_glfw_events();

View file

@ -8,10 +8,8 @@ namespace Light {
struct CameraComponent
{
SceneCamera camera;
bool isPrimary;
CameraComponent() = default;
CameraComponent(const CameraComponent &) = default;
CameraComponent(SceneCamera _camera, bool _isPrimary = false)
@ -24,6 +22,10 @@ struct CameraComponent
{
return camera;
}
SceneCamera camera;
bool isPrimary;
};
} // namespace Light

View file

@ -7,9 +7,8 @@ namespace Light {
struct NativeScriptComponent
{
NativeScript *instance;
NativeScript *(*CreateInstance)();
void (*DestroyInstance)(NativeScriptComponent *);
template<typename t>
@ -23,6 +22,8 @@ struct NativeScriptComponent
nsc->instance = nullptr;
};
}
NativeScript *instance;
};
} // namespace Light

View file

@ -7,14 +7,11 @@ namespace Light {
class NativeScript
{
public:
friend class Scene;
private:
Entity m_entity;
unsigned int m_unique_identifier = 0; // :#todo
public:
NativeScript() = default;
virtual ~NativeScript() = default;
inline unsigned int get_uid() const
@ -32,12 +29,19 @@ protected:
virtual void on_create()
{
}
virtual void on_destroy()
{
}
virtual void on_update(float ts)
{
}
private:
Entity m_entity;
unsigned int m_unique_identifier = 0; // :#todo
};
} // namespace Light

View file

@ -1,6 +1,7 @@
#pragma once
#include <engine/base/base.hpp>
#include <glm/glm.hpp>
namespace Light {
@ -8,10 +9,8 @@ class Texture;
struct SpriteRendererComponent
{
Ref<Texture> texture;
glm::vec4 tint;
SpriteRendererComponent() = default;
SpriteRendererComponent(const SpriteRendererComponent &) = default;
SpriteRendererComponent(
@ -27,6 +26,10 @@ struct SpriteRendererComponent
{
return texture;
}
Ref<Texture> texture;
glm::vec4 tint;
};
} // namespace Light

View file

@ -6,9 +6,8 @@ namespace Light {
struct TagComponent
{
std::string tag = "Unnamed";
TagComponent() = default;
TagComponent(const TagComponent &) = default;
TagComponent(const std::string &_tag): tag(_tag)
@ -19,10 +18,13 @@ struct TagComponent
{
return tag;
}
operator const std::string &() const
{
return tag;
}
std::string tag = "Unnamed";
};
} // namespace Light

View file

@ -11,10 +11,6 @@ namespace Light {
struct TransformComponent
{
glm::vec3 translation;
glm::vec3 scale;
glm::vec3 rotation;
TransformComponent(const TransformComponent &) = default;
TransformComponent(
@ -39,6 +35,12 @@ struct TransformComponent
{
return get_transform();
}
glm::vec3 translation;
glm::vec3 scale;
glm::vec3 rotation;
};
} // namespace Light

View file

@ -7,12 +7,13 @@ namespace Light {
struct UUIDComponent
{
UUID uuid;
UUIDComponent(UUID _uuid): uuid(_uuid)
{
}
UUIDComponent(const UUIDComponent &) = default;
UUID uuid;
};
} // namespace Light

View file

@ -9,10 +9,6 @@ namespace Light {
class Entity
{
private:
entt::entity m_handle;
Scene *m_scene;
public:
Entity(entt::entity handle = entt::null, Scene *registry = nullptr);
@ -56,6 +52,10 @@ public:
{
return (uint32_t)m_handle;
}
private:
entt::entity m_handle;
Scene *m_scene;
};
} // namespace Light

View file

@ -9,26 +9,19 @@
namespace Light {
class Entity;
class Framebuffer;
class Scene
{
private:
friend class Entity;
friend class SceneSerializer;
friend class SceneHierarchyPanel;
private:
entt::registry m_registry;
public:
Scene();
~Scene();
void on_create();
void on_update(float deltaTime);
void on_render(const Ref<Framebuffer> &targetFrameBuffer = nullptr);
Entity create_entity(
@ -39,6 +32,12 @@ public:
Entity get_entity_by_tag(const std::string &tag);
private:
friend class Entity;
friend class SceneSerializer;
friend class SceneHierarchyPanel;
entt::registry m_registry;
Entity create_entity_with_uuid(
const std::string &name,
UUID uuid,

View file

@ -7,9 +7,6 @@ namespace Light {
class Timer
{
private:
std::chrono::time_point<std::chrono::steady_clock> m_start;
public:
Timer();
@ -26,16 +23,13 @@ public:
{
m_start = std::chrono::steady_clock::now();
}
private:
std::chrono::time_point<std::chrono::steady_clock> m_start;
};
class DeltaTimer
{
private:
Timer timer;
float m_previous_frame;
float m_delta_time;
public:
DeltaTimer();
@ -45,6 +39,13 @@ public:
{
return m_delta_time;
}
private:
Timer timer;
float m_previous_frame;
float m_delta_time;
};
} // namespace Light

View file

@ -8,22 +8,16 @@ struct GLFWwindow;
namespace Light {
class Event;
class SharedContext;
// #todo: fix the UserIntreface mess!!
class UserInterface /* singleton */
{
private:
static UserInterface *s_Context;
private:
ImGuiWindowFlags m_dockspace_flags;
public:
static Scope<UserInterface> create(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext);
UserInterface(const UserInterface &) = delete;
UserInterface &operator=(const UserInterface &) = delete;
virtual ~UserInterface() = default;
@ -31,6 +25,7 @@ public:
void init(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext);
static void dockspace_begin();
static void dockspace_end();
virtual void platform_implementation(
@ -39,6 +34,7 @@ public:
) = 0;
virtual void begin() = 0;
virtual void end() = 0;
virtual void log_debug_data() = 0;
@ -47,7 +43,12 @@ protected:
UserInterface();
private:
static UserInterface *s_context;
void set_dark_theme_colors();
ImGuiWindowFlags m_dockspace_flags;
};
} // namespace Light

View file

@ -4,10 +4,10 @@
namespace Light {
class basic_file_handle
class BasicFileHandle
{
public:
basic_file_handle(
BasicFileHandle(
uint8_t *data = nullptr,
uint32_t size = 0ull,
const std::string &path = "",
@ -17,30 +17,32 @@ public:
virtual void release();
// getters
inline uint8_t *GetData()
inline uint8_t *get_data()
{
return m_data;
}
inline uint32_t get_size()
{
return m_size;
}
inline const std::string &GetPath()
inline const std::string &get_path()
{
return m_path;
}
inline const std::string &GetName()
inline const std::string &get_name()
{
return m_name;
}
inline const std::string &GetExtension()
inline const std::string &get_extension()
{
return m_extension;
}
inline const std::string &GetNameWithExtension()
inline const std::string &get_name_with_extention()
{
return m_name + '.' + m_extension;
}
@ -50,7 +52,6 @@ public:
return !!m_data;
}
// operators
inline operator bool() const
{
return is_valid();
@ -59,16 +60,21 @@ public:
protected:
// made protected for custom free():
uint8_t *m_data;
uint32_t m_size;
private:
const std::string m_path, m_name, m_extension;
const std::string m_path;
const std::string m_name;
const std::string m_extension;
};
class image_file_handle: public basic_file_handle
class ImageFileHandle: public BasicFileHandle
{
public:
image_file_handle(
ImageFileHandle(
uint8_t *data,
uint32_t size,
const std::string &path,
@ -79,7 +85,7 @@ public:
uint32_t components,
uint32_t desiredComponents
)
: basic_file_handle(data, size, path, name, extension)
: BasicFileHandle(data, size, path, name, extension)
, m_width(width)
, m_height(height)
, m_components(components)
@ -89,33 +95,42 @@ public:
void release() override;
// getters
inline uint32_t get_width() const
{
return m_width;
}
inline uint32_t get_height() const
{
return m_height;
}
inline uint32_t get_components() const
{
return m_components;
}
inline uint32_t get_desired_components() const
{
return m_desired_components;
}
private:
uint32_t m_width, m_height, m_components, m_desired_components;
uint32_t m_width;
uint32_t m_height;
uint32_t m_components;
uint32_t m_desired_components;
};
class FileManager
{
public:
static basic_file_handle read_text_file(const std::string &path);
static image_file_handle read_image_file(const std::string &path, int32_t desiredComponents);
static BasicFileHandle read_text_file(const std::string &path);
static ImageFileHandle read_image_file(const std::string &path, int32_t desiredComponents);
};
} // namespace Light

View file

@ -6,29 +6,20 @@ namespace Light {
class Shader;
class Texture;
class SharedContext;
class ResourceManager /* singleton */
class ResourceManager
{
private:
static ResourceManager *s_Context;
private:
std::unordered_map<std::string, Ref<Shader>> m_shaders;
std::unordered_map<std::string, Ref<Texture>> m_textures;
public:
static Scope<ResourceManager> create();
// #todo: add geometry shader support
static inline void load_shader(
const std::string &name,
const std::string &vertexPath,
const std::string &pixelPath
)
{
s_Context->load_shader_impl(name, vertexPath, pixelPath);
s_context->load_shader_impl(name, vertexPath, pixelPath);
}
static inline void load_texture(
@ -37,24 +28,31 @@ public:
unsigned int desiredComponents = 4u
)
{
s_Context->load_texture_impl(name, path, desiredComponents);
s_context->load_texture_impl(name, path, desiredComponents);
}
static inline void release_texture(const std::string &name)
{
s_Context->release_texture_impl(name);
s_context->release_texture_impl(name);
}
static inline Ref<Shader> get_shader(const std::string &name)
{
return s_Context->m_shaders[name];
return s_context->m_shaders[name];
}
static inline Ref<Texture> get_texture(const std::string &name)
{
return s_Context->m_textures[name];
return s_context->m_textures[name];
}
private:
static ResourceManager *s_context;
std::unordered_map<std::string, Ref<Shader>> m_shaders;
std::unordered_map<std::string, Ref<Texture>> m_textures;
ResourceManager();
void load_shader_impl(

View file

@ -13,16 +13,17 @@ public:
SceneSerializer(const Ref<Scene> &scene);
void serialize(const std::string &filePath);
bool deserialize(const std::string &filePath);
void serialize_binary(const std::string &filePath);
bool deserialize_binary(const std::string &filePath);
private:
void serialize_entity(YAML::Emitter &out, Entity entity);
private:
Ref<Scene> m_scene;
void serialize_entity(YAML::Emitter &out, Entity entity);
};

View file

@ -12,7 +12,9 @@ class Stringifier
{
public:
static std::string glDebugMsgSeverity(unsigned int severity);
static std::string glDebugMsgSource(unsigned int source);
static std::string glDebugMsgType(unsigned int type);
static std::string spdlogLevel(unsigned int level);

View file

@ -11,7 +11,7 @@
namespace Light {
Application *Application::s_Context = nullptr;
Application *Application::s_context = nullptr;
Application::Application()
: m_instrumentor(nullptr)
@ -19,8 +19,8 @@ Application::Application()
, m_input(nullptr)
, m_window(nullptr)
{
lt_assert(!s_Context, "Repeated singleton construction");
s_Context = this;
lt_assert(!s_context, "Repeated singleton construction");
s_context = this;
m_logger = logger::create();
log_debug_data();
@ -108,7 +108,7 @@ void Application::game_loop()
void Application::quit()
{
s_Context->m_window->close();
s_context->m_window->close();
}
void Application::on_event(const Event &event)

View file

@ -2,10 +2,10 @@
namespace Light {
std::mt19937_64 UUID::s_Engine = std::mt19937_64(std::random_device()());
std::uniform_int_distribution<uint64_t> UUID::s_UniformDistribution;
std::mt19937_64 UUID::s_engine = std::mt19937_64(std::random_device()());
std::uniform_int_distribution<uint64_t> UUID::s_distribution;
UUID::UUID(uint64_t uuid /* = -1 */): m_uuid(uuid == -1 ? s_UniformDistribution(s_Engine) : uuid)
UUID::UUID(uint64_t uuid /* = -1 */): m_uuid(uuid == -1 ? s_distribution(s_engine) : uuid)
{
}

View file

@ -2,7 +2,7 @@
namespace Light {
Instrumentor *Instrumentor::s_Context = nullptr;
Instrumentor *Instrumentor::s_context = nullptr;
Scope<Instrumentor> Instrumentor::create()
{
@ -13,10 +13,10 @@ Instrumentor::Instrumentor(): m_current_session_count(0u)
{
// #todo: maintenance
lt_assert(
!s_Context,
!s_context,
"An instance of 'Instrumentor' already exists, do not construct this class!"
);
s_Context = this;
s_context = this;
}
void Instrumentor::begin_session_impl(const std::string &outputPath)

View file

@ -4,7 +4,7 @@
namespace Light {
logger *logger::s_Context = nullptr;
logger *logger::s_context = nullptr;
Scope<logger> logger::create()
{
@ -16,8 +16,8 @@ logger::logger()
, m_file_logger(nullptr)
, m_log_file_path(LT_LOG_FILE_LOCATION)
{
lt_assert(!s_Context, "An instance of 'logger' already exists, do not construct this class!");
s_Context = this;
lt_assert(!s_context, "An instance of 'logger' already exists, do not construct this class!");
s_context = this;
// set spdlog pattern
// create loggers

View file

@ -15,7 +15,7 @@
namespace Light {
GraphicsContext *GraphicsContext::s_Context = nullptr;
GraphicsContext *GraphicsContext::s_context = nullptr;
GraphicsContext::~GraphicsContext()
{
@ -24,12 +24,12 @@ GraphicsContext::~GraphicsContext()
Scope<GraphicsContext> GraphicsContext::create(GraphicsAPI api, GLFWwindow *windowHandle)
{
// terminate 'GraphicsContext' dependent classes
if (s_Context)
if (s_context)
{
s_Context->m_renderer.reset();
s_Context->m_user_interface.reset();
s_context->m_renderer.reset();
s_context->m_user_interface.reset();
delete s_Context;
delete s_context;
}
// determine the default api
@ -51,29 +51,29 @@ Scope<GraphicsContext> GraphicsContext::create(GraphicsAPI api, GLFWwindow *wind
// opengl
case GraphicsAPI::OpenGL:
scopeGfx = create_scope<glGraphicsContext>(windowHandle);
s_Context = scopeGfx.get();
s_context = scopeGfx.get();
break;
// directx
case GraphicsAPI::DirectX:
lt_win(scopeGfx = create_scope<dxGraphicsContext>(windowHandle); s_Context = scopeGfx.get();
lt_win(scopeGfx = create_scope<dxGraphicsContext>(windowHandle); s_context = scopeGfx.get();
break;)
default:
lt_assert(
false,
"Invalid/unsupported 'GraphicsAPI' {}",
Stringifier::graphics_api_to_string(api)
);
default
: lt_assert(
false,
"Invalid/unsupported 'GraphicsAPI' {}",
Stringifier::graphics_api_to_string(api)
);
return nullptr;
}
// create 'GraphicsContext' dependent classes
s_Context->m_user_interface = UserInterface::create(windowHandle, s_Context->m_shared_context);
s_Context->m_renderer = renderer::create(windowHandle, s_Context->m_shared_context);
s_context->m_user_interface = UserInterface::create(windowHandle, s_context->m_shared_context);
s_context->m_renderer = renderer::create(windowHandle, s_context->m_shared_context);
// check
lt_assert(s_Context->m_user_interface, "Failed to create UserInterface");
lt_assert(s_Context->m_renderer, "Failed to create renderer");
lt_assert(s_context->m_user_interface, "Failed to create UserInterface");
lt_assert(s_context->m_renderer, "Failed to create renderer");
return std::move(scopeGfx);
}

View file

@ -12,7 +12,7 @@
namespace Light {
renderer *renderer::s_Context = nullptr;
renderer *renderer::s_context = nullptr;
renderer::renderer(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext)
: m_quad_renderer(LT_MAX_QUAD_RENDERER_VERTICES, sharedContext)
@ -25,8 +25,8 @@ renderer::renderer(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext)
, m_target_framebuffer(nullptr)
, m_should_clear_backbuffer(false)
{
lt_assert(!s_Context, "An instance of 'renderer' already exists, do not construct this class!");
s_Context = this;
lt_assert(!s_context, "An instance of 'renderer' already exists, do not construct this class!");
s_context = this;
m_view_projection_buffer = ConstantBuffer::create(
ConstantBufferIndex::ViewProjection,
@ -67,7 +67,11 @@ void renderer::draw_quad_impl(
}
/* tint */
void renderer::draw_quad_impl(const glm::vec3 &position, const glm::vec2 &size, const glm::vec4 &tint)
void renderer::draw_quad_impl(
const glm::vec3 &position,
const glm::vec2 &size,
const glm::vec4 &tint
)
{
draw_quad(
glm::translate(glm::mat4(1.0f), position)
@ -77,7 +81,11 @@ void renderer::draw_quad_impl(const glm::vec3 &position, const glm::vec2 &size,
}
/* texture */
void renderer::draw_quad_impl(const glm::vec3 &position, const glm::vec2 &size, Ref<Texture> texture)
void renderer::draw_quad_impl(
const glm::vec3 &position,
const glm::vec2 &size,
Ref<Texture> texture
)
{
draw_quad(
glm::translate(glm::mat4(1.0f), position)
@ -147,13 +155,20 @@ void renderer::draw_quad_impl(const glm::mat4 &transform, Ref<Texture> texture)
// advance
if (!m_texture_renderer.advance())
{
lt_log(warn, "Exceeded LT_MAX_TEXTURE_RENDERER_VERTICES: {}", LT_MAX_TEXTURE_RENDERER_VERTICES
lt_log(
warn,
"Exceeded LT_MAX_TEXTURE_RENDERER_VERTICES: {}",
LT_MAX_TEXTURE_RENDERER_VERTICES
);
flush_scene();
}
}
void renderer::draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint, Ref<Texture> texture)
void renderer::draw_quad_impl(
const glm::mat4 &transform,
const glm::vec4 &tint,
Ref<Texture> texture
)
{
// #todo: implement a proper binding
lt_assert(texture, "Texture passed to renderer::draw_quad_impl");
@ -186,7 +201,10 @@ void renderer::draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint,
// advance
if (!m_tinted_texture_renderer.advance())
{
lt_log(warn, "Exceeded LT_MAX_TEXTURE_RENDERER_VERTICES: {}", LT_MAX_TEXTURE_RENDERER_VERTICES
lt_log(
warn,
"Exceeded LT_MAX_TEXTURE_RENDERER_VERTICES: {}",
LT_MAX_TEXTURE_RENDERER_VERTICES
);
flush_scene();
}
@ -203,7 +221,7 @@ void renderer::end_frame()
m_render_command->swap_buffers();
m_render_command->clear_back_buffer(
m_default_framebuffer_camera ? m_default_framebuffer_camera->GetBackgroundColor() :
glm::vec4(0.0f)
glm::vec4(0.0f)
);
m_default_framebuffer_camera = nullptr;

View file

@ -11,8 +11,8 @@
namespace Light {
Ref<Shader> Shader::create(
basic_file_handle vertexFile,
basic_file_handle pixelFile,
BasicFileHandle vertexFile,
BasicFileHandle pixelFile,
Ref<SharedContext> sharedContext
)
{

View file

@ -8,7 +8,7 @@
namespace Light {
Input *Input::s_Context = nullptr;
Input *Input::s_context = nullptr;
Scope<Input> Input::create()
{
@ -25,10 +25,10 @@ Input::Input()
, m_game_events(true)
{
lt_assert(
!s_Context,
!s_context,
"Input::Input: an instance of 'Input' already exists, do not construct this class!"
);
s_Context = this;
s_context = this;
restart_input_state();
}

View file

@ -7,7 +7,7 @@
namespace Light {
LayerStack *LayerStack::s_Context = nullptr;
LayerStack *LayerStack::s_context = nullptr;
Scope<LayerStack> LayerStack::create()
{
@ -17,9 +17,9 @@ Scope<LayerStack> LayerStack::create()
LayerStack::LayerStack(): m_layers {}, m_begin(), m_end()
{
lt_assert(
!s_Context,
!s_context,
"An instance of 'LayerStack' already exists, do not construct this class!"
) s_Context
) s_context
= this;
}

View file

@ -6,13 +6,13 @@
namespace Light {
glShader::glShader(basic_file_handle vertexFile, basic_file_handle pixelFile): m_shader_id(0u)
glShader::glShader(BasicFileHandle vertexFile, BasicFileHandle pixelFile): m_shader_id(0u)
{
// create
m_shader_id = glCreateProgram();
std::string vertexSource(vertexFile.GetData(), vertexFile.GetData() + vertexFile.get_size());
std::string pixelSource(pixelFile.GetData(), pixelFile.GetData() + pixelFile.get_size());
std::string vertexSource(vertexFile.get_data(), vertexFile.get_data() + vertexFile.get_size());
std::string pixelSource(pixelFile.get_data(), pixelFile.get_data() + pixelFile.get_size());
unsigned int vertexShader = compile_shader(vertexSource, Shader::Stage::VERTEX);
unsigned int pixelShader = compile_shader(pixelSource, Shader::Stage::PIXEL);

View file

@ -16,7 +16,7 @@
namespace Light {
UserInterface *UserInterface::s_Context = nullptr;
UserInterface *UserInterface::s_context = nullptr;
Scope<UserInterface> UserInterface::create(
GLFWwindow *windowHandle,
@ -52,11 +52,11 @@ UserInterface::UserInterface()
)
{
lt_assert(
!s_Context,
!s_context,
"UserInterface::UserInterface: an instance of 'UserInterface' already exists, do not "
"construct this class!"
);
s_Context = this;
s_context = this;
}
void UserInterface::init(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext)
@ -129,7 +129,7 @@ void UserInterface::dockspace_begin()
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::Begin("Dockspace", (bool *)0, s_Context->m_dockspace_flags);
ImGui::Begin("Dockspace", (bool *)0, s_context->m_dockspace_flags);
ImGui::PopStyleVar(3);
ImGuiStyle &style = ImGui::GetStyle();

View file

@ -4,7 +4,7 @@
namespace Light {
basic_file_handle::basic_file_handle(
BasicFileHandle::BasicFileHandle(
uint8_t *data,
uint32_t size,
const std::string &path,
@ -19,7 +19,7 @@ basic_file_handle::basic_file_handle(
{
}
void basic_file_handle::release()
void BasicFileHandle::release()
{
delete m_data;
m_data = nullptr;
@ -27,7 +27,7 @@ void basic_file_handle::release()
}
basic_file_handle FileManager::read_text_file(const std::string &path)
BasicFileHandle FileManager::read_text_file(const std::string &path)
{
// parse path info
std::string name = path.substr(0, path.find('.') + -1);
@ -57,10 +57,10 @@ basic_file_handle FileManager::read_text_file(const std::string &path)
file.read(reinterpret_cast<char *>(data), size);
file.close();
return basic_file_handle(data, size, path, name, extension);
return BasicFileHandle(data, size, path, name, extension);
}
image_file_handle FileManager::read_image_file(const std::string &path, int32_t desiredComponents)
ImageFileHandle FileManager::read_image_file(const std::string &path, int32_t desiredComponents)
{
// parse path info
std::string name = path.substr(0, path.find('.') + -1);
@ -86,7 +86,7 @@ image_file_handle FileManager::read_image_file(const std::string &path, int32_t
fetchedComponents,
desiredComponents);
return image_file_handle(
return ImageFileHandle(
pixels,
width * height,
path,
@ -99,7 +99,7 @@ image_file_handle FileManager::read_image_file(const std::string &path, int32_t
);
}
void image_file_handle::release()
void ImageFileHandle::release()
{
stbi_image_free(reinterpret_cast<void *>(m_data));
m_data = nullptr;

View file

@ -6,7 +6,7 @@
namespace Light {
ResourceManager *ResourceManager::s_Context = nullptr;
ResourceManager *ResourceManager::s_context = nullptr;
Scope<ResourceManager> ResourceManager::create()
{
@ -15,8 +15,8 @@ Scope<ResourceManager> ResourceManager::create()
ResourceManager::ResourceManager(): m_shaders {}, m_textures {}
{
lt_assert(!s_Context, "Repeated singleton construction");
s_Context = this;
lt_assert(!s_context, "Repeated singleton construction");
s_context = this;
}
void ResourceManager::load_shader_impl(
@ -26,13 +26,13 @@ void ResourceManager::load_shader_impl(
)
{
// check
lt_assert(s_Context, "Uninitliazed singleton");
lt_assert(s_context, "Uninitliazed singleton");
lt_assert(!vertexPath.empty(), "Empty 'vertexPath'");
lt_assert(!pixelPath.empty(), "Empty 'pixelPath'");
// load files
basic_file_handle vertexFile = FileManager::read_text_file(vertexPath);
basic_file_handle pixelFile = FileManager::read_text_file(pixelPath);
BasicFileHandle vertexFile = FileManager::read_text_file(vertexPath);
BasicFileHandle pixelFile = FileManager::read_text_file(pixelPath);
// check
lt_assert(vertexFile.is_valid(), "Failed to read vertex file: {}", vertexPath);
@ -54,17 +54,17 @@ void ResourceManager::load_texture_impl(
unsigned int desiredComponents /* = 4u */
)
{
lt_assert(s_Context, "Uninitliazed singleton");
lt_assert(s_context, "Uninitliazed singleton");
// load file
image_file_handle imgFile = FileManager::read_image_file(path, desiredComponents);
ImageFileHandle imgFile = FileManager::read_image_file(path, desiredComponents);
// create texture
m_textures[name] = Ref<Texture>(Texture::create(
imgFile.get_width(),
imgFile.get_height(),
imgFile.get_components(),
imgFile.GetData(),
imgFile.get_data(),
GraphicsContext::get_shared_context(),
path
));