diff --git a/CMakeLists.txt b/CMakeLists.txt index d2fec37..d04d5b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR) -project(UECS VERSION 0.11.1) +project(UECS VERSION 0.11.2) message(STATUS "[Project] ${PROJECT_NAME}") include(cmake/InitUCMake.cmake) diff --git a/include/UECS/ArchetypeFilter.h b/include/UECS/ArchetypeFilter.h index 6d25f62..f8c2798 100644 --- a/include/UECS/ArchetypeFilter.h +++ b/include/UECS/ArchetypeFilter.h @@ -54,7 +54,7 @@ namespace Ubpa::UECS { template void EraseAny(const CmptTypeContainer&); template void EraseNone(const CmptTypeContainer&); - bool operator==(const ArchetypeFilter& filter) const noexcept; + bool operator==(const ArchetypeFilter& rhs) const noexcept; private: size_t GenAllHashCode() const noexcept; diff --git a/include/UECS/EntityMngr.h b/include/UECS/EntityMngr.h index 41bc8f7..b5b3b81 100644 --- a/include/UECS/EntityMngr.h +++ b/include/UECS/EntityMngr.h @@ -59,6 +59,8 @@ namespace Ubpa::UECS { size_t EntityNum(const EntityQuery&) const; + std::tuple> LocateSingletons(const SingletonLocator&) const; + bool IsSingleton(CmptType) const; Entity GetSingletonEntity(CmptType) const; CmptPtr GetSingleton(CmptType) const; @@ -66,6 +68,8 @@ namespace Ubpa::UECS { CmptPtr GetIfSingleton(CmptType) const; template Cmpt* GetSingleton() const { return GetSingleton(CmptType::Of).As(); } + template + Cmpt* GetIfSingleton() const { return GetIfSingleton(CmptType::Of).As(); } void Accept(IListener* listener) const; @@ -86,8 +90,6 @@ namespace Ubpa::UECS { void AttachWithoutInit(Entity); void AttachWithoutInit(Entity, const CmptType* types, size_t num); - std::tuple> LocateSingletons(const SingletonLocator& locator) const; - void GenEntityJob(World*, Job*, SystemFunc*) const; void GenChunkJob(World*, Job*, SystemFunc*) const; void GenJob(World*, Job*, SystemFunc*) const; diff --git a/include/UECS/EntityQuery.h b/include/UECS/EntityQuery.h index 4907bff..2722d47 100644 --- a/include/UECS/EntityQuery.h +++ b/include/UECS/EntityQuery.h @@ -13,7 +13,7 @@ namespace Ubpa::UECS { template EntityQuery(TypeList, TypeList, TypeList, TypeList); - EntityQuery(ArchetypeFilter filter, CmptLocator locator = {}) + EntityQuery(ArchetypeFilter filter = {}, CmptLocator locator = {}) :filter{ std::move(filter) }, locator{ std::move(locator) } {} // without locator's singletons diff --git a/include/UECS/IListener.h b/include/UECS/IListener.h index d5f2a04..38f4272 100644 --- a/include/UECS/IListener.h +++ b/include/UECS/IListener.h @@ -10,22 +10,22 @@ namespace Ubpa::UECS { class IListener { public: - virtual void EnterWorld(const World* w) = 0; - virtual void ExistWorld(const World* w) = 0; + virtual void EnterWorld(const World*) = 0; + virtual void ExistWorld(const World*) = 0; - virtual void EnterSystemMngr(const SystemMngr* sm) = 0; - virtual void ExistSystemMngr(const SystemMngr* sm) = 0; + virtual void EnterSystemMngr(const SystemMngr*) = 0; + virtual void ExistSystemMngr(const SystemMngr*) = 0; - virtual void EnterSystem(const System* s) = 0; - virtual void ExistSystem(const System* s) = 0; + virtual void EnterSystem(const System*) = 0; + virtual void ExistSystem(const System*) = 0; - virtual void EnterEntityMngr(const EntityMngr* em) = 0; - virtual void ExistEntityMngr(const EntityMngr* em) = 0; + virtual void EnterEntityMngr(const EntityMngr*) = 0; + virtual void ExistEntityMngr(const EntityMngr*) = 0; - virtual void EnterEntity(const Entity* e) = 0; - virtual void ExistEntity(const Entity* e) = 0; + virtual void EnterEntity(const Entity*) = 0; + virtual void ExistEntity(const Entity*) = 0; - virtual void EnterCmptPtr(const CmptPtr* cmpt) = 0; - virtual void ExistCmptPtr(const CmptPtr* cmpt) = 0; + virtual void EnterCmptPtr(const CmptPtr*) = 0; + virtual void ExistCmptPtr(const CmptPtr*) = 0; }; } diff --git a/include/UECS/RTDCmptTraits.h b/include/UECS/RTDCmptTraits.h index 02739b3..6899af5 100644 --- a/include/UECS/RTDCmptTraits.h +++ b/include/UECS/RTDCmptTraits.h @@ -25,38 +25,38 @@ namespace Ubpa::UECS { RTDCmptTraits& Clear(); // neccessary - RTDCmptTraits& RegisterSize(CmptType type, size_t size); + RTDCmptTraits& RegisterSize(CmptType, size_t size); // optional - RTDCmptTraits& RegisterAlignment(CmptType type, size_t alignment); + RTDCmptTraits& RegisterAlignment(CmptType, size_t alignment); // optional - RTDCmptTraits& RegisterDefaultConstructor(CmptType type, std::function f); + RTDCmptTraits& RegisterDefaultConstructor(CmptType, std::function); // optional - RTDCmptTraits& RegisterCopyConstructor(CmptType type, std::function f); + RTDCmptTraits& RegisterCopyConstructor(CmptType, std::function); // optional - RTDCmptTraits& RegisterMoveConstructor(CmptType type, std::function f); + RTDCmptTraits& RegisterMoveConstructor(CmptType, std::function); // optional - RTDCmptTraits& RegisterMoveAssignment(CmptType type, std::function f); + RTDCmptTraits& RegisterMoveAssignment(CmptType, std::function); // optional - RTDCmptTraits& RegisterDestructor(CmptType type, std::function f); + RTDCmptTraits& RegisterDestructor(CmptType, std::function); // optional - RTDCmptTraits& RegisterName(CmptType type, std::string name); + RTDCmptTraits& RegisterName(CmptType, std::string name); - size_t Sizeof(CmptType type) const; - size_t Alignof(CmptType type) const; - void CopyConstruct(CmptType type, void* dst, void* src) const; - void MoveConstruct(CmptType type, void* dst, void* src) const; - void MoveAssign(CmptType type, void* dst, void* src) const; - void Destruct(CmptType type, void* cmpt) const; - std::string_view Nameof(CmptType type) const; + size_t Sizeof(CmptType) const; + size_t Alignof(CmptType) const; + void CopyConstruct(CmptType, void* dst, void* src) const; + void MoveConstruct(CmptType, void* dst, void* src) const; + void MoveAssign(CmptType, void* dst, void* src) const; + void Destruct(CmptType, void* cmpt) const; + std::string_view Nameof(CmptType) const; - RTDCmptTraits& Deregister(CmptType type) noexcept; + RTDCmptTraits& Deregister(CmptType) noexcept; template void Register(); diff --git a/include/UECS/Schedule.h b/include/UECS/Schedule.h index 5a44228..3ebb1f5 100644 --- a/include/UECS/Schedule.h +++ b/include/UECS/Schedule.h @@ -26,21 +26,29 @@ namespace Ubpa::UECS { class Schedule { public: template - const SystemFunc* Register( - Func&& func, + const SystemFunc* RegisterEntityJob( + Func&&, std::string name, - ArchetypeFilter filter = ArchetypeFilter{}, - SingletonLocator singletonLocator = SingletonLocator{} + ArchetypeFilter = {}, + CmptLocator = {}, + SingletonLocator = {} ); - // run-time dynamic function template - const SystemFunc* Register( - Func&& func, + const SystemFunc* RegisterChunkJob( + Func&&, std::string name, - CmptLocator locator, - ArchetypeFilter filter = ArchetypeFilter{}, - SingletonLocator singletonLocator = SingletonLocator{}); + ArchetypeFilter = {}, + SingletonLocator = {} + ); + + // Mode::Job + template + const SystemFunc* RegisterJob( + Func&&, + std::string name, + SingletonLocator = {} + ); Schedule& LockFilter(std::string_view sys); @@ -55,7 +63,7 @@ namespace Ubpa::UECS { private: template - const SystemFunc* Request(Args&&... args); + const SystemFunc* Request(Args&&...); void Clear(); diff --git a/include/UECS/SingletonLocator.h b/include/UECS/SingletonLocator.h index a9f8341..8318d1f 100644 --- a/include/UECS/SingletonLocator.h +++ b/include/UECS/SingletonLocator.h @@ -21,6 +21,8 @@ namespace Ubpa::UECS { const std::set& SingletonTypes() const noexcept { return singletonTypes; } + bool HasWriteSingletonType() const noexcept; + private: std::set singletonTypes; }; diff --git a/include/UECS/System.h b/include/UECS/System.h index 7c17eb1..1a0a0a5 100644 --- a/include/UECS/System.h +++ b/include/UECS/System.h @@ -12,7 +12,7 @@ namespace Ubpa::UECS { World* GetWorld() const noexcept { return world; } const std::string& GetName() const noexcept { return name; } - virtual void OnUpdate(Schedule& schedule) = 0; + virtual void OnUpdate(Schedule&) = 0; private: World* world; std::string name; diff --git a/include/UECS/SystemFunc.h b/include/UECS/SystemFunc.h index 6c24d8b..b425bb3 100644 --- a/include/UECS/SystemFunc.h +++ b/include/UECS/SystemFunc.h @@ -35,11 +35,17 @@ namespace Ubpa::UECS { EntityQuery entityQuery; SingletonLocator singletonLocator; + // Mode::Entity template - SystemFunc(Func&& func, std::string name, ArchetypeFilter archetypeFilter, SingletonLocator singletonLocator); + SystemFunc(Func&&, std::string name, ArchetypeFilter, CmptLocator, SingletonLocator); + // Mode::Chunk template - SystemFunc(Func&& func, std::string name, CmptLocator cmptLocator, ArchetypeFilter archetypeFilter, SingletonLocator singletonLocator); + SystemFunc(Func&&, std::string name, ArchetypeFilter, SingletonLocator); + + // Mode::Job + template + SystemFunc(Func&&, std::string name, SingletonLocator); const std::string& Name() const noexcept { return name; } @@ -47,15 +53,15 @@ namespace Ubpa::UECS { size_t HashCode() const noexcept { return hashCode; } - void operator()(World*, SingletonsView singletonsView, Entity e, size_t entityIndexInQuery, CmptsView cmptsView); - void operator()(World*, SingletonsView singletonsView, ChunkView chunkView); - void operator()(World*, SingletonsView singletonsView); + void operator()(World*, SingletonsView, Entity, size_t entityIndexInQuery, CmptsView); + void operator()(World*, SingletonsView, ChunkView); + void operator()(World*, SingletonsView); Mode GetMode() const noexcept { return mode; } - bool operator==(const SystemFunc& func) const noexcept { return name == func.name; } + bool operator==(const SystemFunc& sysFunc) const noexcept { return name == sysFunc.name; } private: - std::function func; + std::function func; std::string name; Mode mode; diff --git a/include/UECS/SystemMngr.h b/include/UECS/SystemMngr.h index 3f654cd..1ddd364 100644 --- a/include/UECS/SystemMngr.h +++ b/include/UECS/SystemMngr.h @@ -38,7 +38,7 @@ namespace Ubpa::UECS{ template void Deregister() noexcept; - void Accept(IListener* listener) const; + void Accept(IListener*) const; private: template diff --git a/include/UECS/World.h b/include/UECS/World.h index 448747b..d56a6bb 100644 --- a/include/UECS/World.h +++ b/include/UECS/World.h @@ -33,7 +33,7 @@ namespace Ubpa::UECS { // use RTDCmptTraits' registered component name UGraphviz::Graph GenUpdateFrameGraph() const; - void Accept(IListener* listener) const; + void Accept(IListener*) const; void AddCommand(std::function command); diff --git a/include/UECS/detail/Archetype.h b/include/UECS/detail/Archetype.h index 7122bb8..946adfc 100644 --- a/include/UECS/detail/Archetype.h +++ b/include/UECS/detail/Archetype.h @@ -49,7 +49,7 @@ namespace Ubpa::UECS { Chunk* GetChunk(size_t chunkIdx) const { return chunks[chunkIdx]; } - void* At(CmptType type, size_t idx) const; + void* At(CmptType, size_t idx) const; template Cmpt* At(size_t idx) const; @@ -63,11 +63,11 @@ namespace Ubpa::UECS { // init cmpts, set Entity // size_t: index in archetype template - std::tuple> Create(Entity e); - size_t Create(Entity e); + std::tuple> Create(Entity); + size_t Create(Entity); // return index in archetype - size_t Instantiate(Entity e, size_t srcIdx); + size_t Instantiate(Entity, size_t srcIdx); // erase idx-th entity // if idx != num-1, back entity will put at idx, return moved Entity's index diff --git a/include/UECS/detail/Schedule.inl b/include/UECS/detail/Schedule.inl index 0e80cf9..ebf70ae 100644 --- a/include/UECS/detail/Schedule.inl +++ b/include/UECS/detail/Schedule.inl @@ -2,37 +2,51 @@ namespace Ubpa::UECS { template - const SystemFunc* Schedule::Register( + const SystemFunc* Schedule::RegisterEntityJob( Func&& func, std::string name, ArchetypeFilter filter, + CmptLocator cmptLocator, SingletonLocator singletonLocator) { return Request( std::forward(func), std::move(name), std::move(filter), + std::move(cmptLocator), std::move(singletonLocator) ); } + template - const SystemFunc* Schedule::Register( + const SystemFunc* Schedule::RegisterChunkJob( Func&& func, std::string name, - CmptLocator locator, ArchetypeFilter filter, SingletonLocator singletonLocator ) { return Request( std::forward(func), std::move(name), - std::move(locator), std::move(filter), std::move(singletonLocator) ); } + template + const SystemFunc* Schedule::RegisterJob( + Func&& func, + std::string name, + SingletonLocator singletonLocator + ) { + return Request( + std::forward(func), + std::move(name), + std::move(singletonLocator) + ); + } + template const SystemFunc* Schedule::Request(Args&&... args) { SystemFunc* sysFunc = sysFuncPool.Request(std::forward(args)...); diff --git a/include/UECS/detail/SingletonsView.h b/include/UECS/detail/SingletonsView.h deleted file mode 100644 index e69de29..0000000 diff --git a/include/UECS/detail/SystemFunc.inl b/include/UECS/detail/SystemFunc.inl index 86bb070..dd47fd6 100644 --- a/include/UECS/detail/SystemFunc.inl +++ b/include/UECS/detail/SystemFunc.inl @@ -10,53 +10,80 @@ namespace Ubpa::UECS::detail { } namespace Ubpa::UECS { + // Mode::Entity template SystemFunc::SystemFunc( Func&& func, std::string name, ArchetypeFilter archetypeFilter, + CmptLocator cmptLocator, SingletonLocator singletonLocator ) : + mode{ Mode::Entity }, func{ detail::Pack(std::forward(func)) }, - entityQuery{ std::move(archetypeFilter), CmptLocator::Generate() }, + entityQuery{ std::move(archetypeFilter), std::move(cmptLocator.Combine()) }, singletonLocator{ std::move(singletonLocator.Combine()) }, name{ std::move(name) }, hashCode{ HashCode(this->name) } { using ArgList = FuncTraits_ArgList>; - static_assert(!Contain_v); - if constexpr (Length_v> > 0) { - static_assert(!Contain_v); - mode = Mode::Entity; - } - else { - static_assert(!Contain_v && !Contain_v); - if constexpr (Contain_v) - mode = Mode::Chunk; - else - mode = Mode::Job; - } + static_assert(Length_v> == 0, + "(Mode::Entity) SystemFunc can't write singletons, use {Latest|LastFrame}Singleton instead"); + + static_assert(!Contain_v); + + assert("(Mode::Entity) SystemFunc can't write singletons, use {Latest|LastFrame}Singleton instead" + && !singletonLocator.HasWriteSingletonType()); } + + // Mode::Chunk template SystemFunc::SystemFunc( Func&& func, std::string name, - CmptLocator cmptLocator, ArchetypeFilter archetypeFilter, SingletonLocator singletonLocator ) : - mode{ Mode::Entity }, + mode{ Mode::Chunk }, func{ detail::Pack(std::forward(func)) }, - entityQuery{ std::move(archetypeFilter), std::move(cmptLocator.Combine()) }, + entityQuery{ std::move(archetypeFilter) }, singletonLocator{ std::move(singletonLocator.Combine()) }, name{ std::move(name) }, hashCode{ HashCode(this->name) } { using ArgList = FuncTraits_ArgList>; - static_assert(!Contain_v); - assert(!entityQuery.locator.CmptTypes().empty()); + + static_assert(Length_v> == 0, + "(Mode::Chunk) SystemFunc can't write singletons, use {Latest|LastFrame}Singleton instead"); + + static_assert(Contain_v); + + static_assert(Length_v> == 0, + "(Mode::Chunk) SystemFunc can't directly access entities' components"); + + assert("(Mode::Chunk) SystemFunc can't write singletons, use {Latest|LastFrame}Singleton instead" + && !singletonLocator.HasWriteSingletonType()); + } + + // Mode::Job + template + SystemFunc::SystemFunc(Func&& func, std::string name, SingletonLocator singletonLocator) + : + mode{ Mode::Job }, + func{ detail::Pack(std::forward(func)) }, + singletonLocator{ std::move(singletonLocator.Combine()) }, + name{ std::move(name) }, + hashCode{ HashCode(this->name) } + { + using ArgList = FuncTraits_ArgList>; + + static_assert(Length_v> == 0, + "(Mode::Job) SystemFunc can't access entities' components"); + + static_assert(!Contain_v && !Contain_v && !Contain_v, + "(Mode::Job) SystemFunc's argument list cann't have Entity, indexInQuery or ChunkView"); } } @@ -80,12 +107,13 @@ namespace Ubpa::UECS::detail { { auto args = std::tuple{ w, + singletons, reinterpret_cast(singletons.Singletons()[Find_v].Ptr())..., e, entityIndexInQuery, cmpts, + reinterpret_cast(cmpts.Components()[Find_v].Ptr())..., chunkView, - reinterpret_cast(cmpts.Components()[Find_v].Ptr())... }; func(std::get(args)...); }; diff --git a/src/core/ArchetypeFilter.cpp b/src/core/ArchetypeFilter.cpp index a7b6d12..8580947 100644 --- a/src/core/ArchetypeFilter.cpp +++ b/src/core/ArchetypeFilter.cpp @@ -101,8 +101,8 @@ size_t ArchetypeFilter::GenCombinedHashCode() const noexcept { return hash_combine(std::array{allHashCode, anyHashCode, noneHashCode}); } -bool ArchetypeFilter::operator==(const ArchetypeFilter& filter) const noexcept { - return allCmptTypes == filter.allCmptTypes - && anyCmptTypes == filter.anyCmptTypes - && noneCmptTypes == filter.noneCmptTypes; +bool ArchetypeFilter::operator==(const ArchetypeFilter& rhs) const noexcept { + return allCmptTypes == rhs.allCmptTypes + && anyCmptTypes == rhs.anyCmptTypes + && noneCmptTypes == rhs.noneCmptTypes; } diff --git a/src/core/SingletonLocator.cpp b/src/core/SingletonLocator.cpp index c0134be..bc8f123 100644 --- a/src/core/SingletonLocator.cpp +++ b/src/core/SingletonLocator.cpp @@ -14,3 +14,11 @@ SingletonLocator::SingletonLocator(const CmptType* types, size_t num) { } SingletonLocator::SingletonLocator() {} + +bool SingletonLocator::HasWriteSingletonType() const noexcept { + for (const auto& type : singletonTypes) { + if (type.GetAccessMode() == AccessMode::WRITE_SINGLETON) + return true; + } + return false; +} diff --git a/src/test/00_basic/main.cpp b/src/test/00_basic/main.cpp index 6fef810..a4a9115 100644 --- a/src/test/00_basic/main.cpp +++ b/src/test/00_basic/main.cpp @@ -11,7 +11,7 @@ class MoverSystem : public System { virtual void OnUpdate(Schedule& schedule) override { schedule - .Register( + .RegisterEntityJob( [](const Velocity* v, Position* p) { p->val += v->val; }, diff --git a/src/test/01_tag/main.cpp b/src/test/01_tag/main.cpp index f4362d3..e089f45 100644 --- a/src/test/01_tag/main.cpp +++ b/src/test/01_tag/main.cpp @@ -12,13 +12,13 @@ class DataSystem : public System { using System::System; virtual void OnUpdate(Schedule& schedule) override { - schedule.Register([](LastFrame d) { cout << "lastFrame_sys0" << endl; }, "lastFrame_sys0"); - schedule.Register([](LastFrame d) { cout << "lastFrame_sys1" << endl; }, "lastFrame_sys1"); - schedule.Register([](Data* d) { cout << "writer_sys0" << endl; }, "writer_sys0"); - schedule.Register([](Data* d) { cout << "writer_sys1" << endl; }, "writer_sys1"); - schedule.Register([](Data* d) { cout << "writer_sys2" << endl; }, "writer_sys2"); - schedule.Register([](const Data* d) { cout << "latest_sys0" << endl; }, "latest_sys0"); - schedule.Register([](const Data* d) { cout << "latest_sys1" << endl; }, "latest_sys1"); + schedule.RegisterEntityJob([](LastFrame d) { cout << "lastFrame_sys0" << endl; }, "lastFrame_sys0"); + schedule.RegisterEntityJob([](LastFrame d) { cout << "lastFrame_sys1" << endl; }, "lastFrame_sys1"); + schedule.RegisterEntityJob([](Data* d) { cout << "writer_sys0" << endl; }, "writer_sys0"); + schedule.RegisterEntityJob([](Data* d) { cout << "writer_sys1" << endl; }, "writer_sys1"); + schedule.RegisterEntityJob([](Data* d) { cout << "writer_sys2" << endl; }, "writer_sys2"); + schedule.RegisterEntityJob([](const Data* d) { cout << "latest_sys0" << endl; }, "latest_sys0"); + schedule.RegisterEntityJob([](const Data* d) { cout << "latest_sys1" << endl; }, "latest_sys1"); } }; diff --git a/src/test/02_order/main.cpp b/src/test/02_order/main.cpp index f714420..ac489d0 100644 --- a/src/test/02_order/main.cpp +++ b/src/test/02_order/main.cpp @@ -13,10 +13,10 @@ class DataSystem : public System { using System::System; virtual void OnUpdate(Schedule& schedule) noexcept { - schedule.Register([](Data1* d1, Data2* d2) { cout << "writer_sys0" << endl; }, "writer_sys0"); - schedule.Register([](Data1* d) { cout << "writer_sys1" << endl; }, "writer_sys1"); - schedule.Register([](Data2* d2) { cout << "writer_sys2" << endl; }, "writer_sys2"); - schedule.Register([](Data1* d, Data2* d2) { cout << "writer_sys3" << endl; }, "writer_sys3"); + schedule.RegisterEntityJob([](Data1* d1, Data2* d2) { cout << "writer_sys0" << endl; }, "writer_sys0"); + schedule.RegisterEntityJob([](Data1* d) { cout << "writer_sys1" << endl; }, "writer_sys1"); + schedule.RegisterEntityJob([](Data2* d2) { cout << "writer_sys2" << endl; }, "writer_sys2"); + schedule.RegisterEntityJob([](Data1* d, Data2* d2) { cout << "writer_sys3" << endl; }, "writer_sys3"); schedule .Order("writer_sys0", "writer_sys1") diff --git a/src/test/03_query_entity/main.cpp b/src/test/03_query_entity/main.cpp index bf17067..e3426da 100644 --- a/src/test/03_query_entity/main.cpp +++ b/src/test/03_query_entity/main.cpp @@ -14,7 +14,7 @@ class MySystem : public System { using System::System; virtual void OnUpdate(Schedule& schedule) override { - schedule.Register( + schedule.RegisterEntityJob( [](World* w, Entity e, const A* a, const B* b) { w->AddCommand( [e](World* w) { @@ -27,7 +27,7 @@ class MySystem : public System { }, "AB" ); - schedule.Register( + schedule.RegisterEntityJob( [](World* w, Entity e, const A* a, const B* b, const C* c) { w->AddCommand( [e](World* w) { diff --git a/src/test/04_filter/main.cpp b/src/test/04_filter/main.cpp index cf6f1a6..4c8a694 100644 --- a/src/test/04_filter/main.cpp +++ b/src/test/04_filter/main.cpp @@ -22,7 +22,7 @@ class MySystem : public System { TypeList{}, // any TypeList{} // none ); - schedule.Register( + schedule.RegisterEntityJob( [](const E* e) { cout << e->val << endl; }, "test filter", filter diff --git a/src/test/06_none_parallel/main.cpp b/src/test/06_none_parallel/main.cpp index d7db21c..7da8037 100644 --- a/src/test/06_none_parallel/main.cpp +++ b/src/test/06_none_parallel/main.cpp @@ -24,8 +24,8 @@ class MySystem : public System { TypeList<>{}, // any TypeList<>{} // none ); - schedule.Register([](B*) {}, "need B, none A", filter_w0); - schedule.Register([](B*) {}, "need A, B", filter_w1);; + schedule.RegisterEntityJob([](B*) {}, "need B, none A", filter_w0); + schedule.RegisterEntityJob([](B*) {}, "need A, B", filter_w1);; } }; diff --git a/src/test/07_overload/main.cpp b/src/test/07_overload/main.cpp index 4ea5b5b..52634ff 100644 --- a/src/test/07_overload/main.cpp +++ b/src/test/07_overload/main.cpp @@ -14,7 +14,7 @@ class VP_System : public System { using System::System; virtual void OnUpdate(Schedule& schedule) override { - schedule.Register([](const V*, P*) {cout << "VP" << endl; }, "VP"); + schedule.RegisterEntityJob([](const V*, P*) {cout << "VP" << endl; }, "VP"); } }; @@ -23,7 +23,7 @@ class AVP_System : public System { using System::System; virtual void OnUpdate(Schedule& schedule) override { - schedule.Register([](const A*, V*, P*) {cout << "AVP" << endl; }, "AVP"); + schedule.RegisterEntityJob([](const A*, V*, P*) {cout << "AVP" << endl; }, "AVP"); schedule.InsertNone("VP", CmptType::Of); } }; diff --git a/src/test/08_job/main.cpp b/src/test/08_job/main.cpp index 72a1dcf..1e287e8 100644 --- a/src/test/08_job/main.cpp +++ b/src/test/08_job/main.cpp @@ -13,12 +13,12 @@ class MySystem : public System { virtual void OnUpdate(Schedule& schedule) override { auto buffer = std::make_shared>(); - auto f = schedule.Register([buffer](size_t idxInQuery, const Data* data) { + auto f = schedule.RegisterEntityJob([buffer](size_t idxInQuery, const Data* data) { buffer->at(idxInQuery) = data->value; }, "system function" ); - schedule.Register([buffer]() { + schedule.RegisterJob([buffer]() { size_t sum = 0; for (size_t i : *buffer) sum += i; diff --git a/src/test/09_idx_in_query/main.cpp b/src/test/09_idx_in_query/main.cpp index 2517d26..f0e6d53 100644 --- a/src/test/09_idx_in_query/main.cpp +++ b/src/test/09_idx_in_query/main.cpp @@ -14,12 +14,12 @@ class MySystem : public System { virtual void OnUpdate(Schedule& schedule) override { auto flags = std::make_shared>(); - auto f = schedule.Register( + auto f = schedule.RegisterEntityJob( [flags](Entity e, size_t indexInQuery, const A*) { flags->at(indexInQuery) = true; }, "set flag" ); - schedule.Register( + schedule.RegisterJob( [flags]() { for (auto flag : *flags) cout << flag << endl; diff --git a/src/test/10_instantiate/main.cpp b/src/test/10_instantiate/main.cpp index a4dc3ba..4b403b3 100644 --- a/src/test/10_instantiate/main.cpp +++ b/src/test/10_instantiate/main.cpp @@ -12,7 +12,7 @@ class MySystem : public System { using System::System; virtual void OnUpdate(Schedule& schedule) override { - schedule.Register([](Entity e, const A* a) { + schedule.RegisterEntityJob([](Entity e, const A* a) { cout << e.Idx() << ": " << a->val << endl; }, ""); } diff --git a/src/test/11_runtime_cmpt/main.cpp b/src/test/11_runtime_cmpt/main.cpp index f2ab6eb..a61299e 100644 --- a/src/test/11_runtime_cmpt/main.cpp +++ b/src/test/11_runtime_cmpt/main.cpp @@ -24,18 +24,18 @@ class RTDSystem: public System{ cmpts_read.data(), cmpts_read.size() ); - schedule.Register( + schedule.RegisterEntityJob( [](CmptsView cmpts) { auto luaCmpt = cmpts.GetCmpt(CmptType{ "LuaCmpt", AccessMode::WRITE }); double& val = *reinterpret_cast(luaCmpt.Ptr()); val = 520.; - }, "write", locator_write); - schedule.Register( + }, "write", ArchetypeFilter{}, locator_write); + schedule.RegisterEntityJob( [](CmptsView cmpts) { auto luaCmpt = cmpts.GetCmpt(CmptType{ "LuaCmpt", AccessMode::LATEST }); const double& val = *reinterpret_cast(luaCmpt.Ptr()); cout << "value : " << val << endl; - }, "read", locator_read); + }, "read", ArchetypeFilter{}, locator_read); } }; diff --git a/src/test/12_framegraph/main.cpp b/src/test/12_framegraph/main.cpp index 2d46f2f..0180d83 100644 --- a/src/test/12_framegraph/main.cpp +++ b/src/test/12_framegraph/main.cpp @@ -25,7 +25,7 @@ class MySystem : public System { TypeList{} // none ); schedule - .Register( + .RegisterEntityJob( [](LastFrame a, Write b, Latest c) {}, "System Func", filter diff --git a/src/test/13_performance/main.cpp b/src/test/13_performance/main.cpp index 08ce46a..4ad4c79 100644 --- a/src/test/13_performance/main.cpp +++ b/src/test/13_performance/main.cpp @@ -13,7 +13,7 @@ class TestSystem : public System { using System::System; virtual void OnUpdate(Schedule& schedule) override { - schedule.Register( + schedule.RegisterEntityJob( [](const A* a, B* b) { // 256 floating-point operations for (size_t i = 0; i < 256; i++) diff --git a/src/test/14_serialize/main.cpp b/src/test/14_serialize/main.cpp index 147164b..326bb2a 100644 --- a/src/test/14_serialize/main.cpp +++ b/src/test/14_serialize/main.cpp @@ -156,7 +156,7 @@ class MoverSystem : public System { using System::System; virtual void OnUpdate(Schedule& schedule) override { - schedule.Register( + schedule.RegisterEntityJob( [](const Velocity* v, Position* p) { p->val += v->val; }, "Mover"); diff --git a/src/test/15_chunk_job/main.cpp b/src/test/15_chunk_job/main.cpp index 670c05f..0387022 100644 --- a/src/test/15_chunk_job/main.cpp +++ b/src/test/15_chunk_job/main.cpp @@ -23,7 +23,7 @@ class SAB_System : public System { TypeList<>{} // none }; - schedule.Register([](ChunkView chunk) { + schedule.RegisterChunkJob([](ChunkView chunk) { auto arrayS = chunk.GetCmptArray(); auto arrayA = chunk.GetCmptArray(); auto arrayB = chunk.GetCmptArray(); diff --git a/src/test/16_singleton/main.cpp b/src/test/16_singleton/main.cpp index 9a1d5c7..17455ed 100644 --- a/src/test/16_singleton/main.cpp +++ b/src/test/16_singleton/main.cpp @@ -16,13 +16,13 @@ class MoverSystem : public System { using System::System; virtual void OnUpdate(Schedule& schedule) override { - schedule.Register([](Singleton timer) { + schedule.RegisterJob([](Singleton timer) { timer->dt = 0.03f; }, "Timer"); - schedule.Register([](const Velocity* v, Position* p, Latest> timer) { + schedule.RegisterEntityJob([](const Velocity* v, Position* p, Latest> timer) { p->val += timer->dt * v->val; }, "Mover"); - schedule.Register([](const Position* p) { + schedule.RegisterEntityJob([](const Position* p) { std::cout << p->val << std::endl; }, "Print"); }