fix assign filled feature bug, add registry_filler

This commit is contained in:
2019-10-19 02:03:20 +07:00
parent f91b0c7081
commit fab0e60b36
5 changed files with 52 additions and 5 deletions

View File

@@ -68,6 +68,7 @@ namespace ecs_hpp
class aspect; class aspect;
class entity_filler; class entity_filler;
class registry_filler;
} }
namespace ecs_hpp namespace ecs_hpp
@@ -1813,6 +1814,20 @@ namespace ecs_hpp
private: private:
entity& entity_; 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<Tag>(std::forward<Args>(args)...);
return *this;
}
private:
registry& registry_;
};
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@@ -2836,7 +2851,7 @@ namespace ecs_hpp
return *f = feature{std::forward<Args>(args)...}; return *f = feature{std::forward<Args>(args)...};
} }
assert(!features_locker_.is_locked()); assert(!features_locker_.is_locked());
return *features_.insert(feature_id, feature()).first; return *features_.insert(feature_id, feature{std::forward<Args>(args)...}).first;
} }
template < typename Tag, typename... Args > template < typename Tag, typename... Args >

View File

@@ -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%

View File

@@ -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%

7
scripts/gen_xcode_project.sh Executable file
View File

@@ -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

View File

@@ -1583,10 +1583,11 @@ TEST_CASE("registry") {
ecs::registry w; ecs::registry w;
w.assign_feature<struct physics>() ecs::registry_filler(w)
.add_system<gravity_system>(9) .feature<struct physics>(ecs::feature()
.add_system<movement_system>() .add_system<gravity_system>(9)
.add_system<physics_system>(); .add_system<movement_system>()
.add_system<physics_system>());
ecs::entity e = w.create_entity(); ecs::entity e = w.create_entity();
e.assign_component<position_c>(1,2); e.assign_component<position_c>(1,2);