feat: refactoring

This commit is contained in:
2025-10-22 14:25:02 +02:00
parent 71f1b2c6d2
commit ea593feb8d
36 changed files with 220 additions and 71 deletions

View File

@ -4,6 +4,8 @@
#include <iostream>
#include <sstream>
namespace Engine {
FileManager::FileManager()
{
}
@ -30,4 +32,6 @@ std::string FileManager::read(const std::string &filename)
}
return fileStream.str();
}
}
}

View File

@ -4,6 +4,8 @@
#include "engine/IO/parser.h"
namespace Engine {
// Skip whitespace
void Parser::SkipSpaces() {
while (*m_sv == ' ' || *m_sv == '\t') ++m_sv;
@ -120,4 +122,6 @@ bool Parser::TakeFaceIndices(int &vi, int &ti, int &ni) {
// At this point m_sv is either at whitespace, end, or next token char.
// Do NOT mutate indices (leave them raw). Let NormalizeIndex handle conversion.
return true;
}
}
}

View File

@ -2,6 +2,8 @@
#include "engine/components/batch.h"
namespace Engine {
unsigned int batch::LastID = 0;
batch::batch() {
@ -27,4 +29,6 @@ void batch::prepare(glm::mat4 *instances, unsigned int count) {
// Just update the data region — much cheaper
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(glm::mat4) * count, instances);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
}
}

View File

@ -5,6 +5,8 @@
#include "engine/window/event.hpp"
#include "engine/renderer/wavefront.h"
namespace Engine {
Engine* Engine::s_instance = nullptr;
void Engine::Run(std::unique_ptr<IApplication> app) {
@ -66,3 +68,4 @@ Engine* Engine::GetInstance() {
return s_instance;
}
}

View File

@ -2,6 +2,8 @@
#include <iostream>
namespace Engine {
void MessageCallback(GLenum source,
GLenum type,
GLuint id,
@ -59,3 +61,5 @@ void MessageCallback(GLenum source,
// (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""),
// type, severity, message);
}
}

View File

@ -2,6 +2,8 @@
#include "engine/renderer/mesh.h"
namespace Engine {
Mesh::Mesh() {
m_vao = 0;
m_vbo = 0;
@ -57,4 +59,6 @@ void Mesh::Render(unsigned int count)
glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(m_indexBuffer.size()), GL_UNSIGNED_INT, 0);
}
Unbind();
}
}
}

View File

@ -18,6 +18,8 @@
#include "engine/components/mesh.h"
#include "engine/components/batch.h"
namespace Engine {
Renderer::Renderer(std::shared_ptr<Scene> scene) : m_scene(scene)
{
m_proj = glm::perspective(
@ -245,4 +247,6 @@ void Renderer::Render() {
ApplyLights(m_shader);
UpdateView();
RenderScene(m_shader);
}
}
}

View File

@ -2,6 +2,8 @@
#include <GL/glew.h>
#include "engine/renderer/shader.h"
namespace Engine {
Shader::Shader()
{
}
@ -132,4 +134,6 @@ void Shader::checkLinkingError()
<< infoLog
<< std::endl;
}
}
}
}

View File

@ -7,6 +7,8 @@
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
namespace Engine {
std::unique_ptr<Texture> Texture::LoadFile(const std::string& filename) {
auto texture = std::make_unique<Texture>();
@ -34,3 +36,5 @@ std::unique_ptr<Texture> Texture::LoadFile(const std::string& filename) {
return std::move(texture);
}
}

View File

@ -12,6 +12,8 @@
#define DEFAULT_MATERIAL_NAME "default"
namespace Engine {
// ObjElement toElement(const std::string &s) {
// if (s == "#") return ObjElement::OHASH;
// if (s == "mtllib") return ObjElement::MTLLIB;
@ -509,4 +511,4 @@ void Object::Render(Shader& shader, unsigned int count)
}
}
}

View File

@ -1,4 +1,11 @@
#include "engine/scene/scene.h"
Scene::Scene() : m_registry() {
namespace Engine {
Scene::Scene() = default;
std::unique_ptr<Entity> Scene::CreateEntity() {
return std::unique_ptr<Entity>(new Entity(m_registry.create(), this));
}
} // namespace Engine

View File

@ -8,6 +8,8 @@
#include "engine/renderer/debug.h"
namespace Engine {
std::shared_ptr<Window> Window::s_instance = nullptr;
Window::Window(const char* title, int width, int height) {
@ -100,12 +102,10 @@ void Window::ProcessEvents() {
switch (event.type) {
case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
case SDL_EVENT_QUIT:
Dispatch(WindowCloseEvent());
EmitEvent(WindowCloseEvent{});
break;
case SDL_EVENT_KEY_DOWN:
if (event.key.scancode == SDL_SCANCODE_ESCAPE) {
Dispatch(WindowCloseEvent());
EmitEvent(WindowCloseEvent{});
}
if (event.key.scancode == SDL_SCANCODE_F11) {
@ -125,7 +125,6 @@ void Window::ProcessEvents() {
width,
height);
auto event = WindowResizeEvent(static_cast<unsigned int>(m_width), static_cast<unsigned int>(m_height));
Dispatch(event);
EmitEvent(event);
SDL_SetWindowRelativeMouseMode(m_handle, true);
SDL_Rect boundaries = {0, 0, m_width, m_height};
@ -152,3 +151,4 @@ void Window::Destroy() const {
SDL_DestroyWindow(m_handle);
}
}