From 51485e980eef86f7478530a0d11b1933b9e092a1 Mon Sep 17 00:00:00 2001 From: ShadesAndGrays Date: Wed, 22 Jul 2026 11:05:40 +0100 Subject: [PATCH] feat: engine variant integrate engine variant add property registry and database modify render system to use new transform components --- .gitignore | 1 + src/engine/core/application.cpp | 100 ++++++------ .../engine-variant-operation.hpp} | 2 +- .../engine-variant-property.hpp | 82 ++++++++++ .../core/engine-variant/engine-variant.hpp | 149 ++++++++++++++++++ src/engine/core/engine_variant.hpp | 109 ------------- src/engine/ecs/bindings.cpp | 92 +++++++++++ src/engine/ecs/bindings.hpp | 8 + src/engine/ecs/components.hpp | 55 ++++--- src/engine/render/render-system.cpp | 43 ++--- src/game/main.cpp | 4 + src/game/scenes/menu-scene/menu.cpp | 33 +++- 12 files changed, 474 insertions(+), 204 deletions(-) rename src/engine/core/{engine_variant_operation.hpp => engine-variant/engine-variant-operation.hpp} (99%) create mode 100644 src/engine/core/engine-variant/engine-variant-property.hpp create mode 100644 src/engine/core/engine-variant/engine-variant.hpp delete mode 100644 src/engine/core/engine_variant.hpp create mode 100644 src/engine/ecs/bindings.cpp create mode 100644 src/engine/ecs/bindings.hpp diff --git a/.gitignore b/.gitignore index b3046dc..4af05aa 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ build-web/ bin/ web/ debug/ +vendor/ # artifacts compile_commands.json diff --git a/src/engine/core/application.cpp b/src/engine/core/application.cpp index 823c7a9..a58a932 100644 --- a/src/engine/core/application.cpp +++ b/src/engine/core/application.cpp @@ -1,87 +1,89 @@ // src/engine/core/application.cpp #include "engine/core/application.hpp" -#include "engine/core/service-locator.hpp" #include "engine/asset/raylib-asset.hpp" +#include "engine/core/engine-variant/engine-variant-property.hpp" +#include "engine/core/service-locator.hpp" +#include "engine/ecs/bindings.hpp" #include "engine/scene/scene.hpp" #include "imgui.h" #include "raylib.h" #include "rlImGui.h" #include - #ifdef __EMSCRIPTEN__ #include #endif namespace varicle { - void game_loop(void){ +void game_loop(void) { - auto& scene_manager = ServiceLocator::get(); + auto &scene_manager = ServiceLocator::get(); - float dt = GetFrameTime(); + float dt = GetFrameTime(); - // Update - scene_manager.update(dt); + // Update + scene_manager.update(dt); - // Draw - BeginDrawing(); - ClearBackground(RAYWHITE); // Or a configurable engine default color + // Draw + BeginDrawing(); + ClearBackground(RAYWHITE); // Or a configurable engine default color - scene_manager.render(); + scene_manager.render(); - rlImGuiBegin(); - scene_manager.ui(); - rlImGuiEnd(); + rlImGuiBegin(); + scene_manager.ui(); + rlImGuiEnd(); - EndDrawing(); + EndDrawing(); - scene_manager.process_scene_switch(); - } + scene_manager.process_scene_switch(); +} - void Application::run() { - // 1. Initialize Raylib - SetTraceLogLevel(LOG_NONE); - SetConfigFlags(FLAG_VSYNC_HINT); - InitWindow(m_window_width, m_window_height, m_window_title); - SetTargetFPS(60); - rlImGuiSetup(true); // initialize gui +void Application::run() { + // 1. Initialize Raylib + SetTraceLogLevel(LOG_NONE); + SetConfigFlags(FLAG_VSYNC_HINT); + InitWindow(m_window_width, m_window_height, m_window_title); + SetTargetFPS(60); + rlImGuiSetup(true); // initialize gui - ServiceLocator::provide(std::make_unique()); - ServiceLocator::provide(std::make_unique()); + // 2. Setup Service Locators + ServiceLocator::provide(std::make_unique()); + ServiceLocator::provide(std::make_unique()); + ServiceLocator::provide(std::make_unique()); - // 2. Call game-specific startup (where the game creates its first scene) - on_init(); + register_all_component_properties(ServiceLocator::get()); - auto& scene_manager = ServiceLocator::get(); + // 3. Call game-specific startup (where the game creates its first scene) + on_init(); + auto &scene_manager = ServiceLocator::get(); #ifdef __EMSCRIPTEN__ - emscripten_set_main_loop(game_loop, 0, 1); + emscripten_set_main_loop(game_loop, 0, 1); #else - while (!scene_manager.should_game_close()){ - game_loop(); - } + while (!scene_manager.should_game_close()) { + game_loop(); + } #endif - // 4. Call game-specific cleanup - on_shutdown(); + // 4. Call game-specific cleanup + on_shutdown(); - ServiceLocator::shutdown(); // Clean up services - - // 5. Close Raylib - rlImGuiShutdown(); - CloseWindow(); - } - - void Application::change_scene(std::string scene_id) { - ServiceLocator::get().switch_to_scene(scene_id); - } - - void Application::quit() { - ServiceLocator::get().quit(); - } + ServiceLocator::shutdown(); // Clean up services + // 5. Close Raylib + rlImGuiShutdown(); + CloseWindow(); } + +void Application::change_scene(std::string scene_id) { + ServiceLocator::get().switch_to_scene(scene_id); +} + +void Application::quit() { ServiceLocator::get().quit(); } + +} // namespace varicle diff --git a/src/engine/core/engine_variant_operation.hpp b/src/engine/core/engine-variant/engine-variant-operation.hpp similarity index 99% rename from src/engine/core/engine_variant_operation.hpp rename to src/engine/core/engine-variant/engine-variant-operation.hpp index 9216ecb..a0d00c9 100644 --- a/src/engine/core/engine_variant_operation.hpp +++ b/src/engine/core/engine-variant/engine-variant-operation.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include "engine-variant.hpp" template struct overloaded : Ts... { using Ts::operator()...; }; template overloaded(Ts...) -> overloaded; diff --git a/src/engine/core/engine-variant/engine-variant-property.hpp b/src/engine/core/engine-variant/engine-variant-property.hpp new file mode 100644 index 0000000..4191f29 --- /dev/null +++ b/src/engine/core/engine-variant/engine-variant-property.hpp @@ -0,0 +1,82 @@ +#pragma once + +#include "engine-variant.hpp" + +#include +#include +#include + +using VariantGetter = + std::function; +using VariantSetter = std::function; + +struct PropertyRef { + uint32_t property_id; + VariantSetter setter; + VariantGetter getter; + + EngineVariant get(const entt::registry ®, entt::entity e) const { + return getter ? getter(reg, e) : EngineVariant(); + } + + void set(entt::registry ®, entt::entity e, + const EngineVariant &value) const { + if (setter) + setter(reg, e, value); + } +}; + +class PropertyRegistry { + public: + template + static PropertyRef bind_field(uint32_t prop_hash, T Component::*member) { + return PropertyRef{.property_id = prop_hash, + + .setter = + [member](entt::registry ®, entt::entity e, + const EngineVariant &val) { + if (auto *comp = reg.try_get(e)) { + (*comp).*member = val.Get(); + } + }, + .getter = [member](const entt::registry ®, + entt::entity e) -> EngineVariant { + if (auto *component = + reg.try_get(e)) { + return EngineVariant((*component).*member); + } + return EngineVariant(); + } + }; + } +}; + +class PropertyDatabase { + private: + std::unordered_map properites; + + public: + void register_property(uint32_t prop_hash, PropertyRef ref) { + properites[prop_hash] = std::move(ref); + } + + EngineVariant get_value(const entt::registry ®, entt::entity e, + uint32_t prop_hash) const { + auto it = properites.find(prop_hash); + if (it != properites.end()) { + return it->second.get(reg, e); + } + return EngineVariant(); + } + + bool set_value(entt::registry ®, entt::entity e, + uint32_t prop_hash, const EngineVariant &value) const { + auto it = properites.find(prop_hash); + if (it != properites.end()) { + it->second.set(reg, e, value); + return true; + } + return false; + } +}; diff --git a/src/engine/core/engine-variant/engine-variant.hpp b/src/engine/core/engine-variant/engine-variant.hpp new file mode 100644 index 0000000..a705323 --- /dev/null +++ b/src/engine/core/engine-variant/engine-variant.hpp @@ -0,0 +1,149 @@ +#pragma once +#include +#include +#include + +// Overload helper pattern +template struct Overloaded : Ts... { + using Ts::operator()...; +}; +template Overloaded(Ts...) -> Overloaded; + +struct Vec2 { + float x = 0.0f; + float y = 0.0f; + + bool operator==(const Vec2 &o) const { return x == o.x && y == o.y; } + bool operator!=(const Vec2 &o) const { return !(*this == o); } + Vec2 operator+(const Vec2 &o) const { return {x + o.x, y + o.y}; } + Vec2 operator-(const Vec2 &o) const { return {x - o.x, y - o.y}; } + Vec2 operator*(float scalar) const { return {x * scalar, y * scalar}; } +}; + +struct Vec3 { + float x = 0.0f; + float y = 0.0f; + float z = 0.0f; + + bool operator==(const Vec3 &o) const { + return x == o.x && y == o.y && z == o.z; + } + bool operator!=(const Vec3 &o) const { return !(*this == o); } + Vec3 operator+(const Vec3 &o) const { return {x + o.x, y + o.y, z + o.z}; } + Vec3 operator-(const Vec3 &o) const { return {x - o.x, y - o.y, z - o.z}; } + Vec3 operator*(float scalar) const { + return {x * scalar, y * scalar, z * scalar}; + } +}; + +struct Vec4 { + float x = 0.0f; + float y = 0.0f; + float z = 0.0f; + float w = 1.0f; + + bool operator==(const Vec4 &o) const { + return x == o.x && y == o.y && z == o.z && w == o.w; + } + bool operator!=(const Vec4 &o) const { return !(*this == o); } + Vec4 operator+(const Vec4 &o) const { + return {x + o.x, y + o.y, z + o.z, w + o.w}; + } + Vec4 operator-(const Vec4 &o) const { + return {x - o.x, y - o.y, z - o.z, w - o.w}; + } + Vec4 operator*(float scalar) const { + return {x * scalar, y * scalar, z * scalar, w * scalar}; + } +}; + +// Standalone Interpolation Helpers +inline Vec2 Vec2Lerp(const Vec2 &s, const Vec2 &e, float a) { + return {s.x + (e.x - s.x) * a, s.y + (e.y - s.y) * a}; +} +inline Vec3 Vec3Lerp(const Vec3 &s, const Vec3 &e, float a) { + return {s.x + (e.x - s.x) * a, s.y + (e.y - s.y) * a, + s.z + (e.z - s.z) * a}; +} +inline Vec4 Vec4Lerp(const Vec4 &s, const Vec4 &e, float a) { + return {s.x + (e.x - s.x) * a, s.y + (e.y - s.y) * a, s.z + (e.z - s.z) * a, + s.w + (e.w - s.w) * a}; +} + +enum class VariantType { Null, Float, Vector2, Vector3, Vector4, String }; + +class EngineVariant { + + public: + using InternalVariant = + std::variant; + + EngineVariant() : data(std::monostate{}) {} + EngineVariant(float v) : data(v) {} + EngineVariant(Vec2 v) : data(v) {} + EngineVariant(Vec3 v) : data(v) {} + EngineVariant(Vec4 v) : data(v) {} + EngineVariant(std::string v) : data(v) {} + EngineVariant(bool v) : data(v) {} + + template T Get() const { return std::get(data); } + template T *TryGet() { return std::get_if(&data); } + + std::string ToString() const { + return std::visit( + Overloaded{[](std::monostate) { return std::string("!"); }, + [](float v) { return std::to_string(v); }, + [](const Vec2 &v) { + return "(" + std::to_string(v.x) + ", " + + std::to_string(v.y) + ")"; + }, + [](const Vec3 &v) { + return "(" + std::to_string(v.x) + ", " + + std::to_string(v.y) + ", " + + std::to_string(v.z) + ")"; + }, + [](const Vec4 &v) { + return "(" + std::to_string(v.x) + ", " + + std::to_string(v.y) + ", " + + std::to_string(v.z) + ", " + + std::to_string(v.w) + ")"; + }, + [](const std::string &s) { return s; }, + [](const bool &b) { return std::string(b ? "true" : "false"); }}, + data); + } + + friend std::ostream &operator<<(std::ostream &os, + const EngineVariant &variant) { + return os << variant.GetTypeName() << variant.ToString(); + } + + private: + InternalVariant data; + + std::string GetTypeName() const { + return std::visit( + [](auto &&arg) -> std::string { + using T = std::decay_t; + if constexpr (std::is_same_v) + return "Null"; + else if constexpr (std::is_same_v) + return "Float"; + else if constexpr (std::is_same_v) + return "Vec2"; + else if constexpr (std::is_same_v) + return "Vec3"; + else if constexpr (std::is_same_v) + return "Vec4"; + else if constexpr (std::is_same_v) + return "String"; + else if constexpr (std::is_same_v) + return "Bool"; + else + return "Unknown"; + }, + data); + } + + friend class VariantOpManager; +}; diff --git a/src/engine/core/engine_variant.hpp b/src/engine/core/engine_variant.hpp deleted file mode 100644 index d80bf74..0000000 --- a/src/engine/core/engine_variant.hpp +++ /dev/null @@ -1,109 +0,0 @@ -#pragma once -#include -#include -#include -#include - -struct Vec2 { - float x = 0.0f; - float y = 0.0f; - - bool operator==(const Vec2& o) const { return x == o.x && y == o.y; } - bool operator!=(const Vec2& o) const { return !(*this == o); } - Vec2 operator+(const Vec2& o) const { return { x + o.x, y + o.y }; } - Vec2 operator-(const Vec2& o) const { return { x - o.x, y - o.y }; } - Vec2 operator*(float scalar) const { return { x * scalar, y * scalar }; } -}; - -struct Vec3 { - float x = 0.0f; - float y = 0.0f; - float z = 0.0f; - - bool operator==(const Vec3& o) const { return x == o.x && y == o.y && z == o.z; } - bool operator!=(const Vec3& o) const { return !(*this == o); } - Vec3 operator+(const Vec3& o) const { return { x + o.x, y + o.y, z + o.z }; } - Vec3 operator-(const Vec3& o) const { return { x - o.x, y - o.y, z - o.z }; } - Vec3 operator*(float scalar) const { return { x * scalar, y * scalar, z * scalar }; } -}; - -struct Vec4 { - float x = 0.0f; - float y = 0.0f; - float z = 0.0f; - float w = 1.0f; - - bool operator==(const Vec4& o) const { return x == o.x && y == o.y && z == o.z && w == o.w; } - bool operator!=(const Vec4& o) const { return !(*this == o); } - Vec4 operator+(const Vec4& o) const { return { x + o.x, y + o.y, z + o.z, w + o.w }; } - Vec4 operator-(const Vec4& o) const { return { x - o.x, y - o.y, z - o.z, w - o.w }; } - Vec4 operator*(float scalar) const { return { x * scalar, y * scalar, z * scalar, w * scalar }; } -}; - - -// Standalone Interpolation Helpers -inline Vec2 Vec2Lerp(const Vec2& s, const Vec2& e, float a) { return { s.x + (e.x - s.x) * a, s.y + (e.y - s.y) * a }; } -inline Vec3 Vec3Lerp(const Vec3& s, const Vec3& e, float a) { return { s.x + (e.x - s.x) * a, s.y + (e.y - s.y) * a, s.z + (e.z - s.z) * a }; } -inline Vec4 Vec4Lerp(const Vec4& s, const Vec4& e, float a) { return { s.x + (e.x - s.x) * a, s.y + (e.y - s.y) * a, s.z + (e.z - s.z) * a, s.w + (e.w - s.w) * a }; } - - - - -enum class VariantType { Null, Float, Vector2, Vector3, Vector4, String }; - -class EngineVariant{ - - public: - using InternalVariant = std::variant; - - EngineVariant() : data(std::monostate{}), type(VariantType::Null){} - EngineVariant(float v) : data(v), type(VariantType::Float){} - EngineVariant(Vec2 v) : data(v), type(VariantType::Vector2){} - EngineVariant(Vec3 v) : data(v), type(VariantType::Vector3){} - EngineVariant(Vec4 v) : data(v), type(VariantType::Vector4){} - EngineVariant(std::string v) : data(v), type(VariantType::String){} - - VariantType GetType() const { return type; } - - template - T Get() const { - std::lock_guard lock(v_mutex); - return std::get(data); - } - - void Print() const { - - std::lock_guard lock(v_mutex); - std::cout << "[Variant " << TypeToString(type) << "]: "; - std::visit([](auto &&arg){ - using T = std::decay_t; - if constexpr (std::is_same_v) std::cout << "Null"; - else if constexpr (std::is_same_v) std::cout << arg; - else if constexpr (std::is_same_v) std::cout << "(" << arg.x << ", " << arg.y << ")"; - else if constexpr (std::is_same_v) std::cout << "(" << arg.x << ", " << arg.y << ", " << arg.z << ")"; - else if constexpr (std::is_same_v) std::cout << "(" << arg.x << ", " << arg.y << ", " << arg.z << ", " << arg.w << ")"; - else if constexpr (std::is_same_v) std::cout << "\"" << arg << "\""; - - },data); - - std::cout << "\n"; - } - - private: - InternalVariant data; - VariantType type; - mutable std::mutex v_mutex; - - static std::string TypeToString(VariantType t) { - switch(t) { - case VariantType::Float: return "Float"; - case VariantType::Vector2: return "Vector2"; - case VariantType::Vector3: return "Vector3"; - case VariantType::Vector4: return "Vector4"; - case VariantType::String: return "String"; - default: return "Null"; - } - } - - friend class VariantOpManager; -}; diff --git a/src/engine/ecs/bindings.cpp b/src/engine/ecs/bindings.cpp new file mode 100644 index 0000000..c931e82 --- /dev/null +++ b/src/engine/ecs/bindings.cpp @@ -0,0 +1,92 @@ +#include "bindings.hpp" +#include "components.hpp" + +using namespace entt::literals; + +void varicle::register_all_component_properties(PropertyDatabase &db) { + + //---------------------------------------------------------- + // LocalTransform2D + //---------------------------------------------------------- + db.register_property( + "position"_hs, + PropertyRegistry::bind_field("position"_hs, + &varicle::LocalTransform2D::position)); + + db.register_property("scale"_hs, + PropertyRegistry::bind_field( + "scale"_hs, &varicle::LocalTransform2D::scale)); + + db.register_property( + "rotation"_hs, + PropertyRegistry::bind_field("rotation"_hs, + &varicle::LocalTransform2D::rotation)); + + //---------------------------------------------------------- + // GlobalTransform2D + //---------------------------------------------------------- + db.register_property( + "global_position"_hs, + PropertyRegistry::bind_field("global_position"_hs, + &varicle::GlobalTransform2D::position)); + + db.register_property("global_scale"_hs, + PropertyRegistry::bind_field( + "global_scale"_hs, &varicle::GlobalTransform2D::scale)); + + db.register_property( + "global_rotation"_hs, + PropertyRegistry::bind_field("global_rotation"_hs, + &varicle::GlobalTransform2D::rotation)); + + //---------------------------------------------------------- + // Velocity + //---------------------------------------------------------- + + db.register_property( + "velocity:x"_hs, + PropertyRegistry::bind_field("velocity:x"_hs, &varicle::Velocity::dx)); + + db.register_property( + "velocity:y"_hs, + PropertyRegistry::bind_field("velocity:y"_hs, &varicle::Velocity::dy)); + + //---------------------------------------------------------- + // Sprite + //---------------------------------------------------------- + + db.register_property( + "sprite:texture_path"_hs, + PropertyRegistry::bind_field("sprite:texture_path"_hs, &varicle::Sprite::texture_path)); + + db.register_property( + "sprite:offset:y"_hs, + PropertyRegistry::bind_field("sprite:offset:y"_hs, &varicle::Sprite::offset_y)); + + db.register_property( + "sprite:offset:x"_hs, + PropertyRegistry::bind_field("sprite:offset:x"_hs, &varicle::Sprite::offset_x)); + + + db.register_property( + "sprite:width"_hs, + PropertyRegistry::bind_field("sprite:width"_hs, &varicle::Sprite::width)); + + + db.register_property( + "sprite:height"_hs, + PropertyRegistry::bind_field("sprite:height"_hs, &varicle::Sprite::height)); + + db.register_property( + "sprite:flip_h"_hs, + PropertyRegistry::bind_field("sprite:flip_h"_hs, &varicle::Sprite::flip_h)); + + db.register_property( + "sprite:flip_v"_hs, + PropertyRegistry::bind_field("sprite:flip_v"_hs, &varicle::Sprite::flip_v)); + + db.register_property( + "sprite:rotation"_hs, + PropertyRegistry::bind_field("sprite:rotation"_hs, &varicle::Sprite::rotation)); + +} diff --git a/src/engine/ecs/bindings.hpp b/src/engine/ecs/bindings.hpp new file mode 100644 index 0000000..fd1e189 --- /dev/null +++ b/src/engine/ecs/bindings.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include "engine/core/engine-variant/engine-variant-property.hpp" + +namespace varicle { + // Single point of initialization for all engine component properties + void register_all_component_properties(PropertyDatabase& db); +} diff --git a/src/engine/ecs/components.hpp b/src/engine/ecs/components.hpp index 45845b9..4fea51b 100644 --- a/src/engine/ecs/components.hpp +++ b/src/engine/ecs/components.hpp @@ -1,28 +1,43 @@ #pragma once +#include "engine/core/engine-variant/engine-variant.hpp" +#include #include -namespace varicle{ +namespace varicle { - struct Position{ - float x; - float y; - }; +struct Position { + float x; + float y; +}; - struct Velocity{ - float dx; - float dy; - }; +struct Velocity { + float dx; + float dy; +}; - struct Sprite{ - Texture *texture; - float offset_x; - float offset_y; - float width; - float height; - bool flip_h; - bool flip_v; - float rotation; - }; +struct LocalTransform2D { + Vec2 position; + float scale; + float rotation; +}; -} +struct GlobalTransform2D { + Vec2 position; + float scale; + float rotation; +}; + +struct Sprite { + std::string texture_path; + float offset_x; + float offset_y; + float width; + float height; + bool flip_h; + bool flip_v; + float rotation; +}; + + +} // namespace varicle diff --git a/src/engine/render/render-system.cpp b/src/engine/render/render-system.cpp index d9d1c15..4081552 100644 --- a/src/engine/render/render-system.cpp +++ b/src/engine/render/render-system.cpp @@ -1,4 +1,6 @@ #include "engine/render/render-system.hpp" +#include "engine/asset/raylib-asset.hpp" +#include "engine/core/service-locator.hpp" #include "engine/ecs/components.hpp" #include @@ -7,40 +9,45 @@ namespace varicle { void update_render_system(entt::registry ®istry){ - auto view = registry.view(); + auto view = registry.view(); for (entt::entity entity : view){ const Sprite &sprite = view.get(entity); - const Position &pos = view.get(entity); + auto [global_position,global_scale,global_rotation] = view.get(entity); + auto texture = ServiceLocator::get().get_texture(sprite.texture_path); - if (sprite.texture){ + float width = sprite.width * global_scale; + float height = sprite.height * global_scale; + float rotation = sprite.rotation + global_rotation; + + if (texture){ DrawTexturePro( - *(sprite.texture), + *(texture), Rectangle{ 0, 0, - (float)sprite.texture->width, - (float)sprite.texture->height, + (float)texture->width, + (float)texture->height, }, Rectangle { - sprite.offset_x + pos.x, - sprite.offset_y + pos.y, - sprite.width, - sprite.height + sprite.offset_x + global_position.x, + sprite.offset_y + global_position.y, + width, + height, }, - Vector2 {sprite.width * 0.5f, sprite.height*0.5f}, - sprite.rotation, + Vector2 {width * 0.5f, height*0.5f}, + rotation, WHITE); }else{ DrawRectanglePro(Rectangle { - sprite.offset_x + pos.x, - sprite.offset_y + pos.y, - sprite.width, - sprite.height + sprite.offset_x + global_position.x, + sprite.offset_y + global_position.y, + width, + height }, - Vector2 {sprite.width * 0.5f, sprite.height*0.5f}, - sprite.rotation, + Vector2 {width * 0.5f, height*0.5f}, + rotation, PURPLE ); } diff --git a/src/game/main.cpp b/src/game/main.cpp index bd1a6d4..3cd0091 100644 --- a/src/game/main.cpp +++ b/src/game/main.cpp @@ -1,9 +1,13 @@ #include "engine/core/application.hpp" +#include "engine/core/engine-variant/engine-variant-property.hpp" +#include "engine/core/engine-variant/engine-variant.hpp" #include "engine/core/service-locator.hpp" +#include "engine/ecs/components.hpp" #include "engine/scene/scene.hpp" #include "game/scenes/menu-scene/menu.hpp" +#include #include class Game : public varicle::Application { diff --git a/src/game/scenes/menu-scene/menu.cpp b/src/game/scenes/menu-scene/menu.cpp index 0ae0347..d37404d 100644 --- a/src/game/scenes/menu-scene/menu.cpp +++ b/src/game/scenes/menu-scene/menu.cpp @@ -1,6 +1,8 @@ #include "menu.hpp" #include "engine/asset/raylib-asset.hpp" +#include "engine/core/engine-variant/engine-variant-property.hpp" +#include "engine/core/engine-variant/engine-variant.hpp" #include "engine/core/service-locator.hpp" #include "engine/ecs/components.hpp" #include "engine/render/render-system.hpp" @@ -9,25 +11,42 @@ #include #include +using namespace entt::literals; + void MenuScene::init() { using namespace varicle; ServiceLocator::provide(std::make_unique()); - - auto& asset_loader =ServiceLocator::get(); asset_loader.load_asset("assets/bird.png"); + auto &asset_loader = ServiceLocator::get(); + asset_loader.load_asset("assets/bird.png"); auto x = asset_loader.get_reader().get_asset_list(); - for (auto i :x) { + for (auto i : x) { std::cout << i << std::endl; } auto e = registry.create(); - registry.emplace(e,650.0f,150.0f); - auto bird_texture = asset_loader.get_texture("assets/bird.png"); - registry.emplace(e,bird_texture,0.0f,0.f,100.f,100.f,false,false,0.f); - auto img = LoadImageFromTexture(*bird_texture); + registry.emplace(e, 650.0f, 150.0f, 1.0f,0.0f); + // registry.emplace(e, 650.0f, 150.0f); + registry.emplace(e, "assets/bird.png", 0.0f, 0.f, 100.f, 100.f, + false, false, 0.f); + auto img = + LoadImageFromTexture(*asset_loader.get_texture("assets/bird.png")); SetWindowIcon(img); UnloadImage(img); + auto &p_database = varicle::ServiceLocator::get(); + + registry.emplace(e, 100.0f, 100.0f, 10.0f, + 5.0f); + + EngineVariant current_pos = + p_database.get_value(registry, e, "global_position"_hs); + EngineVariant current_scale = + p_database.get_value(registry, e, "scale"_hs); + EngineVariant current_rot = + p_database.get_value(registry, e, "rotation"_hs); + + std::cout << current_pos << current_scale << current_rot << std::endl; } void MenuScene::update(float dt) {}