From f4ad43b05f51693616dbdf737407109cbbe3060c Mon Sep 17 00:00:00 2001 From: ShadesAndGrays Date: Wed, 22 Jul 2026 12:34:18 +0100 Subject: [PATCH] minor update --- .../engine-variant-operation.hpp | 143 +++++++++++------- .../engine-variant-property.hpp | 14 +- .../core/engine-variant/engine-variant.hpp | 10 +- src/engine/render/render-system.cpp | 77 +++++----- src/game/scenes/menu-scene/menu.cpp | 2 +- 5 files changed, 142 insertions(+), 104 deletions(-) diff --git a/src/engine/core/engine-variant/engine-variant-operation.hpp b/src/engine/core/engine-variant/engine-variant-operation.hpp index a0d00c9..ca2af26 100644 --- a/src/engine/core/engine-variant/engine-variant-operation.hpp +++ b/src/engine/core/engine-variant/engine-variant-operation.hpp @@ -2,73 +2,110 @@ #include "engine-variant.hpp" -template struct overloaded : Ts... { using Ts::operator()...; }; -template overloaded(Ts...) -> overloaded; +namespace varicle { + +template struct overloaded : Ts... { + using Ts::operator()...; +}; +template overloaded(Ts...) -> overloaded; enum class OpType { - Assign, // Replace the old value entirely - Add, // Add to the current value - Multiply, // Add to the current value - Lerp // Smoothly blend toward a value + Assign, // Replace the old value entirely + Add, // Add to the current value + Multiply, // Add to the current value + Lerp // Smoothly blend toward a value }; struct VariantOpRequest { - EngineVariant* target; // The variable we want to change - OpType operation; // How we want to change it - EngineVariant operand; // The value we are using to make the change - float alpha; // Used ONLY for Lerp (0.0 to 1.0) + EngineVariant *target; // The variable we want to change + OpType operation; // How we want to change it + EngineVariant operand; // The value we are using to make the change + float alpha; // Used ONLY for Lerp (0.0 to 1.0) }; -class VariantOpManager{ +class VariantOpManager { - public: - VariantOpManager(){} - void ExecuteOperation(const VariantOpRequest& req) { + public: + VariantOpManager() {} + void ExecuteOperation(const VariantOpRequest &req) { - if (req.target == nullptr) return; + if (req.target == nullptr) + return; - switch (req.operation){ + switch (req.operation) { - case OpType::Assign: - req.target->data = req.operand.data; - req.target->type = req.operand.type; - break; - case OpType::Add: - req.target->data = std::visit( - overloaded{ - [](float p, float n) -> EngineVariant::InternalVariant {return p + n;}, - [](Vec2 p, Vec2 n) -> EngineVariant::InternalVariant {return p + n;}, - [](Vec3 p, Vec3 n) -> EngineVariant::InternalVariant {return p + n;}, - [](Vec4 p, Vec4 n) -> EngineVariant::InternalVariant {return p + n;}, + case OpType::Assign: + req.target->data = req.operand.data; + break; + case OpType::Add: + req.target->data = std::visit( + overloaded{ + [](float p, float n) -> EngineVariant::InternalVariant { + return p + n; + }, + [](Vec2 p, Vec2 n) -> EngineVariant::InternalVariant { + return p + n; + }, + [](Vec3 p, Vec3 n) -> EngineVariant::InternalVariant { + return p + n; + }, + [](Vec4 p, Vec4 n) -> EngineVariant::InternalVariant { + return p + n; + }, - // Fallback - [](auto p, auto n) -> EngineVariant::InternalVariant {return p;}, - },req.target->data,req.operand.data); - break; + // Fallback + [](auto p, auto n) -> EngineVariant::InternalVariant { + return p; + }, + }, + req.target->data, req.operand.data); + break; - case OpType::Lerp: - req.target->data = std::visit(overloaded{ - [&](float p, float n) -> EngineVariant::InternalVariant { return p + (n - p) * req.alpha; }, - [&](Vec2 p, Vec2 n) -> EngineVariant::InternalVariant { return Vec2Lerp(p, n, req.alpha); }, - [&](Vec3 p, Vec3 n) -> EngineVariant::InternalVariant { return Vec3Lerp(p, n, req.alpha); }, - [&](Vec4 p, Vec4 n) -> EngineVariant::InternalVariant { return Vec4Lerp(p, n, req.alpha); }, - [&](const std::string& p, const std::string& n) -> EngineVariant::InternalVariant { - return req.alpha >= 0.5f ? n : p; // Discrete switch for strings - }, + case OpType::Lerp: + req.target->data = std::visit( + overloaded{ + [&](float p, float n) -> EngineVariant::InternalVariant { + return p + (n - p) * req.alpha; + }, + [&](Vec2 p, Vec2 n) -> EngineVariant::InternalVariant { + return Vec2Lerp(p, n, req.alpha); + }, + [&](Vec3 p, Vec3 n) -> EngineVariant::InternalVariant { + return Vec3Lerp(p, n, req.alpha); + }, + [&](Vec4 p, Vec4 n) -> EngineVariant::InternalVariant { + return Vec4Lerp(p, n, req.alpha); + }, + [&](const std::string &p, const std::string &n) + -> EngineVariant::InternalVariant { + return req.alpha >= 0.5f + ? n + : p; // Discrete switch for strings + }, - // Fallback - [](auto p, auto n) -> EngineVariant::InternalVariant { return p; } - }, req.target->data, req.operand.data); - break; - - case OpType::Multiply: - req.target->data = std::visit(overloaded{ - [](float p, float n) -> EngineVariant::InternalVariant { return p * n; }, - [](Vec2 p, float n) -> EngineVariant::InternalVariant { return p * n; }, // Scale a vector! - [](auto p, auto n) -> EngineVariant::InternalVariant { return p; } - }, req.target->data, req.operand.data); - break; - } + // Fallback + [](auto p, auto n) -> EngineVariant::InternalVariant { + return p; + }}, + req.target->data, req.operand.data); + break; + case OpType::Multiply: + req.target->data = std::visit( + overloaded{ + [](float p, float n) -> EngineVariant::InternalVariant { + return p * n; + }, + [](Vec2 p, float n) -> EngineVariant::InternalVariant { + return p * n; + }, // Scale a vector! + [](auto p, auto n) -> EngineVariant::InternalVariant { + return p; + }}, + req.target->data, req.operand.data); + break; } + } }; + +} // namespace varicle diff --git a/src/engine/core/engine-variant/engine-variant-property.hpp b/src/engine/core/engine-variant/engine-variant-property.hpp index 4191f29..11f3260 100644 --- a/src/engine/core/engine-variant/engine-variant-property.hpp +++ b/src/engine/core/engine-variant/engine-variant-property.hpp @@ -6,10 +6,12 @@ #include #include +namespace varicle { + using VariantGetter = std::function; -using VariantSetter = std::function; +using VariantSetter = + std::function; struct PropertyRef { uint32_t property_id; @@ -47,8 +49,7 @@ class PropertyRegistry { return EngineVariant((*component).*member); } return EngineVariant(); - } - }; + }}; } }; @@ -70,8 +71,8 @@ class PropertyDatabase { return EngineVariant(); } - bool set_value(entt::registry ®, entt::entity e, - uint32_t prop_hash, const EngineVariant &value) const { + 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); @@ -80,3 +81,4 @@ class PropertyDatabase { return false; } }; +} // namespace varicle diff --git a/src/engine/core/engine-variant/engine-variant.hpp b/src/engine/core/engine-variant/engine-variant.hpp index a705323..bf13e20 100644 --- a/src/engine/core/engine-variant/engine-variant.hpp +++ b/src/engine/core/engine-variant/engine-variant.hpp @@ -3,6 +3,7 @@ #include #include +namespace varicle { // Overload helper pattern template struct Overloaded : Ts... { using Ts::operator()...; @@ -75,8 +76,8 @@ enum class VariantType { Null, Float, Vector2, Vector3, Vector4, String }; class EngineVariant { public: - using InternalVariant = - std::variant; + using InternalVariant = std::variant; EngineVariant() : data(std::monostate{}) {} EngineVariant(float v) : data(v) {} @@ -109,7 +110,9 @@ class EngineVariant { std::to_string(v.w) + ")"; }, [](const std::string &s) { return s; }, - [](const bool &b) { return std::string(b ? "true" : "false"); }}, + [](const bool &b) { + return std::string(b ? "true" : "false"); + }}, data); } @@ -147,3 +150,4 @@ class EngineVariant { friend class VariantOpManager; }; +} // namespace varicle diff --git a/src/engine/render/render-system.cpp b/src/engine/render/render-system.cpp index 4081552..9d53e25 100644 --- a/src/engine/render/render-system.cpp +++ b/src/engine/render/render-system.cpp @@ -3,55 +3,50 @@ #include "engine/core/service-locator.hpp" #include "engine/ecs/components.hpp" -#include #include +#include namespace varicle { - void update_render_system(entt::registry ®istry){ - auto view = registry.view(); +void update_render_system(entt::registry ®istry) { + auto view = registry.view(); - for (entt::entity entity : view){ - const Sprite &sprite = view.get(entity); - auto [global_position,global_scale,global_rotation] = view.get(entity); - auto texture = ServiceLocator::get().get_texture(sprite.texture_path); + for (entt::entity entity : view) { + const Sprite &sprite = view.get(entity); + auto [global_position, global_scale, global_rotation] = + view.get(entity); + auto texture = ServiceLocator::get().get_texture( + sprite.texture_path); - float width = sprite.width * global_scale; - float height = sprite.height * global_scale; - float rotation = sprite.rotation + global_rotation; + float width = sprite.width * global_scale; + float height = sprite.height * global_scale; + float rotation = sprite.rotation + global_rotation; - if (texture){ - DrawTexturePro( - *(texture), - Rectangle{ - 0, - 0, - (float)texture->width, - (float)texture->height, - }, - Rectangle { - sprite.offset_x + global_position.x, - sprite.offset_y + global_position.y, - width, - height, - }, - Vector2 {width * 0.5f, height*0.5f}, - rotation, - WHITE); + if (texture) { + DrawTexturePro( + *(texture), + Rectangle{ + 0.0f, + 0.0f, + static_cast(sprite.flip_h ? -texture->width + : texture->width), + static_cast(sprite.flip_v ? -texture->height + : texture->height), + }, + Rectangle{ + sprite.offset_x + global_position.x, + sprite.offset_y + global_position.y, + width, + height, + }, + Vector2{width * 0.5f, height * 0.5f}, rotation, WHITE); - }else{ - DrawRectanglePro(Rectangle { - sprite.offset_x + global_position.x, - sprite.offset_y + global_position.y, - width, - height - }, - Vector2 {width * 0.5f, height*0.5f}, - rotation, - PURPLE - ); - } + } else { + DrawRectanglePro( + Rectangle{sprite.offset_x + global_position.x, + sprite.offset_y + global_position.y, width, height}, + Vector2{width * 0.5f, height * 0.5f}, rotation, PURPLE); } - } } +} // namespace varicle diff --git a/src/game/scenes/menu-scene/menu.cpp b/src/game/scenes/menu-scene/menu.cpp index d37404d..f0d86a9 100644 --- a/src/game/scenes/menu-scene/menu.cpp +++ b/src/game/scenes/menu-scene/menu.cpp @@ -28,7 +28,7 @@ void MenuScene::init() { 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); + true, false, 0.f); auto img = LoadImageFromTexture(*asset_loader.get_texture("assets/bird.png")); SetWindowIcon(img);