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

@ -3,6 +3,8 @@
#include <string>
namespace Engine {
class FileManager
{
public:
@ -12,4 +14,6 @@ public:
static std::string read(const std::string &filename);
};
}
#endif // FILE_MANAGER_H

View File

@ -1,6 +1,8 @@
#ifndef PARSER_H_
#define PARSER_H_
namespace Engine {
// Very fast OBJ/MTL line parser
class Parser {
private:
@ -17,4 +19,6 @@ public:
int TakeIndex(int baseCount);
};
}
#endif // PARSER_H_

View File

@ -9,10 +9,10 @@
#include "engine/app/app.h"
#include "engine/renderer/core.h"
extern IApplication* CreateApplication();
extern Engine::IApplication* CreateApplication();
int main() {
auto engine = Engine::GetInstance();
engine->Run(std::unique_ptr<IApplication>(CreateApplication()));
auto engine = Engine::Engine::GetInstance();
engine->Run(std::unique_ptr<Engine::IApplication>(CreateApplication()));
return 0;
}

View File

@ -5,15 +5,17 @@
#include "engine/window/event.hpp"
#include "engine/export.h"
class ENGINE_API IApplication {
public:
virtual ~IApplication() = default;
namespace Engine {
class ENGINE_API IApplication {
public:
virtual ~IApplication() = default;
virtual void OnInit(std::shared_ptr<Scene> scene) {};
virtual void OnUpdate() {};
virtual void OnShutdown() {};
virtual void OnEvent(const Event& event) {};
};
virtual void OnInit(std::shared_ptr<Scene> scene) {};
virtual void OnUpdate() {};
virtual void OnShutdown() {};
virtual void OnEvent(const Event& event) {};
};
}
#endif // APPLICATION_H_

View File

@ -4,6 +4,7 @@
#include <glm/mat4x4.hpp>
#include "engine/export.h"
namespace Engine {
// requires mesh component
struct ENGINE_API batch {
friend class Renderer;
@ -25,5 +26,6 @@ private:
private:
void prepare(glm::mat4 *instances, unsigned int count);
};
}
#endif // COMPONENT_BATCH_H_

View File

@ -3,6 +3,8 @@
#include "engine/export.h"
namespace Engine {
struct ENGINE_API camera {};
}
#endif // COMPONENTS_PLAYER_H_

View File

@ -6,6 +6,7 @@
#include "engine/renderer/renderer.h"
#include "engine/export.h"
namespace Engine {
struct ENGINE_API light {
friend class Renderer;
public:
@ -25,5 +26,6 @@ private:
glm::mat4 lightSpace;
int shadowRes{1024};
};
}
#endif // COMPONENTS_LIGHT_H_

View File

@ -6,8 +6,10 @@
#include "engine/renderer/wavefront.h"
#include "engine/export.h"
namespace Engine {
struct ENGINE_API mesh {
std::shared_ptr<Object> object;
};
}
#endif // COMPONENTS_MESH_H_

View File

@ -3,6 +3,8 @@
#include "engine/export.h"
namespace Engine {
struct ENGINE_API rotate {};
}
#endif // COMPONENT_ROTATE_H_

View File

@ -4,10 +4,12 @@
#include <glm/glm.hpp>
#include "engine/export.h"
namespace Engine {
struct ENGINE_API transform {
glm::vec3 position;
glm::vec3 rotation;
glm::vec3 scale;
};
}
#endif // COMPONENTS_TRANSFORM_H_

View File

@ -3,6 +3,8 @@
#include <glm/glm.hpp>
namespace Engine {
class Vertex {
friend class Mesh;
private:
@ -14,4 +16,6 @@ public:
: m_position(position), m_normal(normal), m_texCoord(texCoord) {}
};
}
#endif // RENDERER_BASICS_H

View File

@ -13,6 +13,8 @@
#include "engine/app/app.h"
#include "engine/export.h"
namespace Engine {
class ENGINE_API Engine : public EventHandler {
public:
static Engine* GetInstance();
@ -31,5 +33,6 @@ private:
bool m_running;
};
}
#endif // ENGINE_H_

View File

@ -3,6 +3,8 @@
#include <GL/glew.h>
namespace Engine {
void MessageCallback(GLenum source,
GLenum type,
GLuint id,
@ -11,4 +13,6 @@ void MessageCallback(GLenum source,
const GLchar* message,
const void* userParam);
}
#endif // RENDERER_DEBUG_

View File

@ -6,6 +6,8 @@
#include "engine/renderer/texture.h"
namespace Engine {
class Material {
private:
glm::vec3 m_ambient { 0.2f, 0.2f, 0.2f };
@ -39,4 +41,6 @@ public:
inline void SetIllumination(float illum) { m_illum = illum; }
};
}
#endif // MATERIAL_H_

View File

@ -7,6 +7,8 @@
#include "engine/renderer/basics.h"
namespace Engine {
class Mesh {
public: // TODO: abstract away
unsigned int m_vao, m_vbo, m_ebo;
@ -24,4 +26,6 @@ public:
void Render(unsigned int count);
};
}
#endif // MESH_H_

View File

@ -8,6 +8,8 @@
#include "engine/export.h"
#include "engine/components/light.h"
namespace Engine {
// TODO: make static or singleton
class ENGINE_API Renderer {
public:
@ -37,4 +39,6 @@ private:
glm::mat4 m_view;
};
}
#endif // RENDERER_H_

View File

@ -7,6 +7,8 @@
#include "engine/export.h"
namespace Engine {
class ENGINE_API Shader
{
public:
@ -45,4 +47,6 @@ private:
void checkLinkingError();
};
}
#endif // SHADER_H

View File

@ -3,6 +3,8 @@
#include <string>
#include <memory>
namespace Engine {
class Texture {
public:
Texture() : m_id(0) {}
@ -13,4 +15,6 @@ private:
unsigned int m_id;
};
}
#endif // TEXTURE_H_

View File

@ -14,6 +14,8 @@
#include "engine/export.h"
namespace Engine {
enum ObjElement { OHASH, MTLLIB, USEMTL, O, V, VN, VT, F, OUNKNOWN };
enum MtlElement { MHASH, NEWMTL, NS, KA, KS, KD, NI, D, ILLUM, MAP_KD, MAP_KA, MUNKNOWN };
@ -53,4 +55,6 @@ private:
std::unordered_map<std::string, std::shared_ptr<Material>> m_materials;
};
}
#endif // MODEL_H_

View File

@ -2,14 +2,45 @@
#define ENGINE_SCENE_H_
#include <entt/entt.hpp>
#include <memory>
namespace Engine {
class Scene;
class Entity {
friend class Scene;
private:
Entity(entt::entity entity, Scene* scene) : m_entity(entity), m_scene(scene) {}
public:
template<typename Type, typename... Args>
inline auto AddComponent(Args &&...args) {
assert(this->m_scene != nullptr && "Scene has not been assigned to the entity");
return m_scene->m_registry.emplace<Type>(m_entity, std::forward<Args>(args)...);
}
template<typename Type>
[[nodiscard]] inline auto GetComponent() {
assert(this->m_scene != nullptr && "Scene has not been assigned to the entity");
return m_scene->m_registry.get<Type>(m_entity);
}
private:
entt::entity m_entity;
Scene *m_scene;
};
class Scene {
private:
friend class Entity;
public:
Scene();
std::unique_ptr<Entity> CreateEntity();
private:
entt::registry m_registry;
friend class Renderer;
friend class Game;
};
} // namespace Engine
#endif // ENGINE_SCENE_H_

View File

@ -7,6 +7,8 @@
#include <unordered_map>
#include <vector>
namespace Engine {
enum class EventType {
WINDOW_RESIZE,
WINDOW_CLOSE,
@ -71,4 +73,6 @@ private:
std::size_t m_next_id = 1;
};
}
#endif // EVENT_H_

View File

@ -3,6 +3,8 @@
#include "engine/window/event.hpp"
namespace Engine {
class WindowEvent : public Event {
public:
WindowEvent() : Event(Event::EventCategory::WINDOW) {}
@ -27,4 +29,6 @@ public:
WindowCloseEvent() {}
};
}
#endif // WINDOW_EVENTS_H_

View File

@ -13,6 +13,8 @@
#define DEFAULT_WIDTH 1024
#define DEFAULT_HEIGHT 768
namespace Engine {
class Window : public EventEmitter {
friend class Engine;
private:
@ -48,4 +50,6 @@ private:
int m_height;
};
}
#endif //WINDOW_H_