From fab0e60b36d8d770a0ceb8d1181bde1340398b80 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Sat, 19 Oct 2019 02:03:20 +0700 Subject: [PATCH] fix assign filled feature bug, add registry_filler --- headers/ecs.hpp/ecs.hpp | 17 ++++++++++++++++- scripts/gen_msvc2017_project.bat | 12 ++++++++++++ scripts/gen_msvc2019_project.bat | 12 ++++++++++++ scripts/gen_xcode_project.sh | 7 +++++++ untests/ecs_tests.cpp | 9 +++++---- 5 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 scripts/gen_msvc2017_project.bat create mode 100644 scripts/gen_msvc2019_project.bat create mode 100755 scripts/gen_xcode_project.sh diff --git a/headers/ecs.hpp/ecs.hpp b/headers/ecs.hpp/ecs.hpp index 198de46..5b87fe6 100644 --- a/headers/ecs.hpp/ecs.hpp +++ b/headers/ecs.hpp/ecs.hpp @@ -68,6 +68,7 @@ namespace ecs_hpp class aspect; class entity_filler; + class registry_filler; } namespace ecs_hpp @@ -1813,6 +1814,20 @@ namespace ecs_hpp private: entity& entity_; }; + + class registry_filler final { + public: + registry_filler(registry& registry) noexcept + : registry_(registry) {} + + template < typename Tag, typename... Args > + registry_filler& feature(Args&&... args) { + registry_.assign_feature(std::forward(args)...); + return *this; + } + private: + registry& registry_; + }; } // ----------------------------------------------------------------------------- @@ -2836,7 +2851,7 @@ namespace ecs_hpp return *f = feature{std::forward(args)...}; } assert(!features_locker_.is_locked()); - return *features_.insert(feature_id, feature()).first; + return *features_.insert(feature_id, feature{std::forward(args)...}).first; } template < typename Tag, typename... Args > diff --git a/scripts/gen_msvc2017_project.bat b/scripts/gen_msvc2017_project.bat new file mode 100644 index 0000000..56c48d6 --- /dev/null +++ b/scripts/gen_msvc2017_project.bat @@ -0,0 +1,12 @@ +@echo off +set BUILD_DIR=%~dp0%\..\build +mkdir %BUILD_DIR%\msvc2017 || goto :error +cd %BUILD_DIR%\msvc2017 || goto :error +cmake -G "Visual Studio 15 2017" ..\.. || goto :error +start ecs.hpp.sln || goto :error + +goto :EOF + +:error +echo Failed with error #%errorlevel%. +exit /b %errorlevel% diff --git a/scripts/gen_msvc2019_project.bat b/scripts/gen_msvc2019_project.bat new file mode 100644 index 0000000..cc0efdb --- /dev/null +++ b/scripts/gen_msvc2019_project.bat @@ -0,0 +1,12 @@ +@echo off +set BUILD_DIR=%~dp0%\..\build +mkdir %BUILD_DIR%\msvc2019 || goto :error +cd %BUILD_DIR%\msvc2019 || goto :error +cmake -G "Visual Studio 16 2019" ..\.. || goto :error +start ecs.hpp.sln || goto :error + +goto :EOF + +:error +echo Failed with error #%errorlevel%. +exit /b %errorlevel% diff --git a/scripts/gen_xcode_project.sh b/scripts/gen_xcode_project.sh new file mode 100755 index 0000000..c18052b --- /dev/null +++ b/scripts/gen_xcode_project.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -e +BUILD_DIR=`dirname "$BASH_SOURCE"`/../build +mkdir -p $BUILD_DIR/xcode +cd $BUILD_DIR/xcode +cmake -G Xcode ../.. +open ecs.hpp.xcodeproj diff --git a/untests/ecs_tests.cpp b/untests/ecs_tests.cpp index bd13427..baf5fd3 100644 --- a/untests/ecs_tests.cpp +++ b/untests/ecs_tests.cpp @@ -1583,10 +1583,11 @@ TEST_CASE("registry") { ecs::registry w; - w.assign_feature() - .add_system(9) - .add_system() - .add_system(); + ecs::registry_filler(w) + .feature(ecs::feature() + .add_system(9) + .add_system() + .add_system()); ecs::entity e = w.create_entity(); e.assign_component(1,2);