From fc8175098963b1c270d6474b079b742532678803 Mon Sep 17 00:00:00 2001 From: Ubpa <641614112@qq.com> Date: Thu, 6 Aug 2020 00:21:46 +0800 Subject: [PATCH] clean up 1. command : EntityMngr -> World, + World* 2. SystemFunc += World* 3. Schedule's Register() return SystemFunc 4. RTDCmptTraits += Clear --- CMakeLists.txt | 2 +- doc/comparison.md | 29 +++++++++++++++++---- include/UECS/EntityMngr.h | 13 ++-------- include/UECS/RTDCmptTraits.h | 2 ++ include/UECS/Schedule.h | 16 +++--------- include/UECS/SystemFunc.h | 18 ++++++++------ include/UECS/World.h | 9 +++++++ include/UECS/detail/CmptTag.inl | 9 +++---- include/UECS/detail/EntityMngr.inl | 5 ---- include/UECS/detail/RTDCmptTraits.inl | 14 +++++++++++ include/UECS/detail/Schedule.inl | 16 +++++------- include/UECS/detail/SystemFunc.inl | 36 +++++++++++++++++++++------ src/core/EntityMngr.cpp | 15 +++-------- src/core/Schedule.cpp | 12 --------- src/core/SystemFunc.cpp | 9 ++++--- src/core/World.cpp | 28 +++++++++++++-------- src/test/01_tag/main.cpp | 15 ++++++----- src/test/02_order/main.cpp | 9 ++++--- src/test/03_query_entity/main.cpp | 26 ++++++++++--------- src/test/06_none_parallel/main.cpp | 5 ++-- src/test/07_overload/main.cpp | 5 ++-- src/test/08_job/main.cpp | 32 ++++++++++++------------ src/test/09_idx_in_query/main.cpp | 27 ++++++++++---------- src/test/11_runtime_cmpt/main.cpp | 25 +++++++++---------- 24 files changed, 202 insertions(+), 175 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 379aa31..2ff054a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR) -project(UECS VERSION 0.10.4) +project(UECS VERSION 0.10.5) message(STATUS "[Project] ${PROJECT_NAME}") include(cmake/InitUCMake.cmake) diff --git a/doc/comparison.md b/doc/comparison.md index 8804d71..894f171 100644 --- a/doc/comparison.md +++ b/doc/comparison.md @@ -96,14 +96,33 @@ use `CmptTag::LastFrame (like const *)`, `CmptTag::Write == : {LastFrame|Write|Latest}\ +- chunk + - [[const] World*] + - [[const] ChunkView] + +```c++ +// 1. + // * [[const] World*] + // * [[const] Entity] + // * [size_t indexInQuery] + // * [[const] CmptsView] + // * : {LastFrame|Write|Latest} + // 2. chunk: [[const] World*], [const] ChunkView + // 3. job: [[const] World*] +``` + + ### 3.2 System update order diff --git a/include/UECS/EntityMngr.h b/include/UECS/EntityMngr.h index b8c7ef4..4cfcd84 100644 --- a/include/UECS/EntityMngr.h +++ b/include/UECS/EntityMngr.h @@ -7,8 +7,6 @@ #include -#include - namespace Ubpa::UECS { class World; @@ -61,8 +59,6 @@ namespace Ubpa::UECS { size_t EntityNum(const EntityQuery&) const; - void AddCommand(const std::function& command); - void Accept(IListener* listener) const; private: @@ -82,8 +78,8 @@ namespace Ubpa::UECS { void AttachWithoutInit(Entity); void AttachWithoutInit(Entity, const CmptType* types, size_t num); - void GenEntityJob(Job* job, SystemFunc* sys) const; - void GenChunkJob(Job* job, SystemFunc* sys) const; + void GenEntityJob(World*, Job*, SystemFunc*) const; + void GenChunkJob(World*, Job*, SystemFunc*) const; struct EntityInfo { Archetype* archetype{ nullptr }; @@ -98,11 +94,6 @@ namespace Ubpa::UECS { std::unordered_map h2a; // archetype's hashcode to archetype mutable std::unordered_map> queryCache; - - // command - std::vector> commandBuffer; - std::mutex commandBufferMutex; - void RunCommands(); }; } diff --git a/include/UECS/RTDCmptTraits.h b/include/UECS/RTDCmptTraits.h index aab3dff..02739b3 100644 --- a/include/UECS/RTDCmptTraits.h +++ b/include/UECS/RTDCmptTraits.h @@ -22,6 +22,8 @@ namespace Ubpa::UECS { static RTDCmptTraits& Instance() noexcept; + RTDCmptTraits& Clear(); + // neccessary RTDCmptTraits& RegisterSize(CmptType type, size_t size); diff --git a/include/UECS/Schedule.h b/include/UECS/Schedule.h index 408b0e3..28a3537 100644 --- a/include/UECS/Schedule.h +++ b/include/UECS/Schedule.h @@ -26,21 +26,14 @@ namespace Ubpa::UECS { class Schedule { public: template - Schedule& Register(Func&& func, std::string name, EntityFilter filter = EntityFilter{}); + const SystemFunc* Register(Func&& func, std::string name, EntityFilter filter = EntityFilter{}); // run-time dynamic function template - Schedule& Register(Func&& func, std::string name, EntityLocator locator, EntityFilter filter = EntityFilter{}); + const SystemFunc* Register(Func&& func, std::string name, EntityLocator locator, EntityFilter filter = EntityFilter{}); Schedule& LockFilter(std::string_view sys); - // if sys is unregistered, return size_t_invalid - // call LockFilterChange(std::string_view) - size_t EntityNumInQuery(std::string_view sys) const; - - EntityMngr* GetEntityMngr() const noexcept { return entityMngr; } - SystemMngr* GetSystemMngr() const noexcept { return systemMngr; } - Schedule& Order(std::string_view x, std::string_view y); Schedule& InsertAll(std::string_view sys, CmptType); @@ -52,9 +45,8 @@ namespace Ubpa::UECS { private: template - void Request(Args&&... args); + const SystemFunc* Request(Args&&... args); - Schedule(EntityMngr* entityMngr, SystemMngr* systemMngr); void Clear(); struct CmptSysFuncs { @@ -86,8 +78,6 @@ namespace Ubpa::UECS { std::unordered_set sysLockFilter; Pool sysFuncPool; - EntityMngr* entityMngr; - SystemMngr* systemMngr; friend class World; }; } diff --git a/include/UECS/SystemFunc.h b/include/UECS/SystemFunc.h index 21ab1da..78ad05e 100644 --- a/include/UECS/SystemFunc.h +++ b/include/UECS/SystemFunc.h @@ -14,10 +14,14 @@ namespace Ubpa::UECS { // name must be unique in global // query.filter can be change dynamically by other with Schedule // [system function kind] (distinguish by argument list) - // 1. per entity function: [[const] Entity e] [size_t indexInQuery] [CmptsView] ... + // 1. per entity function + // * [[const] World*] + // * [[const] Entity] + // * [size_t indexInQuery] + // * [[const] CmptsView] // * : {LastFrame|Write|Latest} - // 2. chunk: ChunkView - // 3. job: empty argument list + // 2. chunk: [[const] World*], [const] ChunkView + // 3. job: [[const] World*] class SystemFunc { public: enum class Mode { @@ -41,9 +45,9 @@ namespace Ubpa::UECS { size_t HashCode() const noexcept { return hashCode; } - void operator()(Entity e, size_t entityIndexInQuery, CmptsView rtdcmpts); - void operator()(ChunkView chunkView); - void operator()(); + void operator()(World*, Entity e, size_t entityIndexInQuery, CmptsView rtdcmpts); + void operator()(World*, ChunkView chunkView); + void operator()(World*); Mode GetMode() const noexcept { return mode; } @@ -52,7 +56,7 @@ namespace Ubpa::UECS { template SystemFunc(Func&& func, std::string name, EntityFilter filter, ArgList); - std::function func; + std::function func; std::string name; Mode mode; diff --git a/include/UECS/World.h b/include/UECS/World.h index 5a87af4..448747b 100644 --- a/include/UECS/World.h +++ b/include/UECS/World.h @@ -6,6 +6,8 @@ #include +#include + namespace Ubpa::UECS { class IListener; @@ -33,6 +35,8 @@ namespace Ubpa::UECS { void Accept(IListener* listener) const; + void AddCommand(std::function command); + private: mutable JobExecutor executor; Schedule schedule; @@ -41,6 +45,11 @@ namespace Ubpa::UECS { std::vector jobs; Pool jobPool; + // command + std::vector> commandBuffer; + std::mutex commandBufferMutex; + void RunCommands(); + // ================================================== World(const World& world) = delete; World(World&& world) = delete; diff --git a/include/UECS/detail/CmptTag.inl b/include/UECS/detail/CmptTag.inl index 6c7f97f..f718564 100644 --- a/include/UECS/detail/CmptTag.inl +++ b/include/UECS/detail/CmptTag.inl @@ -5,6 +5,7 @@ namespace Ubpa::UECS { class Entity; class EntityLocator; + class World; } namespace Ubpa::UECS { @@ -14,11 +15,9 @@ namespace Ubpa::UECS { template struct RemoveTag> : IType {}; template struct DecayTag : IType {}; - // template struct DecayTag : IType {}; template struct DecayTag : IType {}; template struct DecayTag> : IType {}; - template<> struct DecayTag : IType {}; - template<> struct DecayTag : IType {}; + template struct DecayTag : IType {}; template struct IsLastFrame : std::false_type {}; template struct IsLastFrame> : std::true_type {}; @@ -26,11 +25,11 @@ namespace Ubpa::UECS { template struct IsWrite : std::false_type {}; template struct IsWrite : std::false_type {}; template struct IsWrite : std::true_type {}; - template<> struct IsWrite : std::false_type {}; + template<> struct IsWrite : std::false_type {}; template struct IsLatest : std::false_type {}; - template<> struct IsLatest : std::false_type {}; template struct IsLatest : std::true_type {}; + template<> struct IsLatest : std::false_type {}; template struct IsTimePoint : IValue || IsLastFrame_v || IsLatest_v> {}; diff --git a/include/UECS/detail/EntityMngr.inl b/include/UECS/detail/EntityMngr.inl index 273fad4..57f4b21 100644 --- a/include/UECS/detail/EntityMngr.inl +++ b/include/UECS/detail/EntityMngr.inl @@ -149,9 +149,4 @@ namespace Ubpa::UECS { inline bool EntityMngr::Exist(Entity e) const { return e.Idx() < entityTable.size() && e.Version() == entityTable[e.Idx()].version; } - - inline void EntityMngr::AddCommand(const std::function& command) { - std::lock_guard guard(commandBufferMutex); - commandBuffer.push_back(command); - } } diff --git a/include/UECS/detail/RTDCmptTraits.inl b/include/UECS/detail/RTDCmptTraits.inl index 0e6426f..7171b77 100644 --- a/include/UECS/detail/RTDCmptTraits.inl +++ b/include/UECS/detail/RTDCmptTraits.inl @@ -166,12 +166,26 @@ namespace Ubpa::UECS { } inline RTDCmptTraits& RTDCmptTraits::Deregister(CmptType type) noexcept { + names.erase(type); sizeofs.erase(type); alignments.erase(type); default_constructors.erase(type); copy_constructors.erase(type); move_constructors.erase(type); + move_assignments.erase(type); destructors.erase(type); return *this; } + + inline RTDCmptTraits& RTDCmptTraits::Clear() { + names.clear(); + sizeofs.clear(); + alignments.clear(); + default_constructors.clear(); + copy_constructors.clear(); + move_constructors.clear(); + move_assignments.clear(); + destructors.clear(); + return *this; + } } diff --git a/include/UECS/detail/Schedule.inl b/include/UECS/detail/Schedule.inl index c8e8bf7..2258a30 100644 --- a/include/UECS/detail/Schedule.inl +++ b/include/UECS/detail/Schedule.inl @@ -2,26 +2,22 @@ namespace Ubpa::UECS { template - Schedule& Schedule::Register(Func&& func, std::string name, EntityFilter filter) { - Request(std::forward(func), std::move(name), std::move(filter)); - return *this; + const SystemFunc* Schedule::Register(Func&& func, std::string name, EntityFilter filter) { + return Request(std::forward(func), std::move(name), std::move(filter)); } template - Schedule& Schedule::Register(Func&& func, std::string name, EntityLocator locator, EntityFilter filter) { - Request(std::forward(func), std::move(name), std::move(locator), std::move(filter)); - return *this; + const SystemFunc* Schedule::Register(Func&& func, std::string name, EntityLocator locator, EntityFilter filter) { + return Request(std::forward(func), std::move(name), std::move(locator), std::move(filter)); } template - void Schedule::Request(Args&&... args) { + const SystemFunc* Schedule::Request(Args&&... args) { SystemFunc* sysFunc = sysFuncPool.Request(std::forward(args)...); sysFuncs.emplace(sysFunc->HashCode(), sysFunc); + return sysFunc; } - inline Schedule::Schedule(EntityMngr* entityMngr, SystemMngr* systemMngr) - : entityMngr{ entityMngr }, systemMngr{ systemMngr }{} - inline Schedule& Schedule::LockFilter(std::string_view sys) { sysLockFilter.insert(SystemFunc::HashCode(sys)); return *this; diff --git a/include/UECS/detail/SystemFunc.inl b/include/UECS/detail/SystemFunc.inl index beb0edd..630a9fa 100644 --- a/include/UECS/detail/SystemFunc.inl +++ b/include/UECS/detail/SystemFunc.inl @@ -17,12 +17,13 @@ namespace Ubpa::UECS { query{ std::move(filter), std::move(locator) } { using ArgList = FuncTraits_ArgList; + using DecayedArgList = Transform_t; - static_assert(Contain_v, - "(Mode::Entity) 's argument list must contain CmptsView"); + static_assert(Contain_v, + "(Mode::Entity) 's argument list must contain [const] CmptsView"); - static_assert(!Contain_v, - "(Mode::Entity) 's argument list must not contain ChunkView"); + static_assert(!Contain_v, + "(Mode::Entity) 's argument list must not contain [const] ChunkView"); } template @@ -40,13 +41,31 @@ namespace Ubpa::UECS { hashCode{ HashCode(this->name) }, query{ std::move(filter), EntityLocator{Filter_t{}} } { - static_assert(!Contain_v, + using DecayedArgList = Transform_t; + + static_assert(!Contain_v, "'s argument list contains CmptsView, so you should use the constructor of the run-time dynamic version"); - if constexpr (IsEmpty_v) + + if constexpr ( + IsEmpty_v + || Length_v == 1 && Contain_v + ) { + // [[const] World*] mode = Mode::Job; - else if constexpr (std::is_same_v>) + } + else if constexpr ( + Contain_v + && ( + Length_v == 1 + || Length_v == 2 && Contain_v + ) + ) { + // [[const] World*] + // [const] ChunkView mode = Mode::Chunk; + } else { + // default static_assert(!Contain_v, "(Mode::Entity) 's argument list must not contain ChunkView"); mode = Mode::Entity; @@ -63,8 +82,9 @@ namespace Ubpa::UECS::detail::System_ { using CmptList = TypeList; // sorted template static auto run(Func&& func) noexcept { - return [func = std::forward(func)](Entity e, size_t entityIndexInQuery, CmptsView rtdcmpts, ChunkView chunkView) { + return [func = std::forward(func)](World* w, Entity e, size_t entityIndexInQuery, CmptsView rtdcmpts, ChunkView chunkView) { auto unsorted_arg_tuple = std::make_tuple( + w, e, entityIndexInQuery, rtdcmpts, diff --git a/src/core/EntityMngr.cpp b/src/core/EntityMngr.cpp index c173fb7..3274fdc 100644 --- a/src/core/EntityMngr.cpp +++ b/src/core/EntityMngr.cpp @@ -258,7 +258,7 @@ void EntityMngr::Destroy(Entity e) { RecycleEntityEntry(e); } -void EntityMngr::GenEntityJob(Job* job, SystemFunc* sys) const { +void EntityMngr::GenEntityJob(World* w, Job* job, SystemFunc* sys) const { assert(sys->GetMode() == SystemFunc::Mode::Entity); size_t indexOffsetInQuery = 0; @@ -276,7 +276,7 @@ void EntityMngr::GenEntityJob(Job* job, SystemFunc* sys) const { size_t J = min(chunkCapacity, num - idxOffsetInChunk); for (size_t j = 0; j < J; j++) { - (*sys)(entities[j], indexOffsetInQueryChunk + j, { &sys->query.locator, cmpts.data() }); + (*sys)(w, entities[j], indexOffsetInQueryChunk + j, { &sys->query.locator, cmpts.data() }); for (size_t k = 0; k < cmpts.size(); k++) reinterpret_cast(cmpts[k]) += sizes[k]; } @@ -287,7 +287,7 @@ void EntityMngr::GenEntityJob(Job* job, SystemFunc* sys) const { } } -void EntityMngr::GenChunkJob(Job* job, SystemFunc* sys) const { +void EntityMngr::GenChunkJob(World* w, Job* job, SystemFunc* sys) const { assert(sys->GetMode() == SystemFunc::Mode::Chunk); for (Archetype* archetype : QueryArchetypes(sys->query)) { @@ -295,19 +295,12 @@ void EntityMngr::GenChunkJob(Job* job, SystemFunc* sys) const { for (size_t i = 0; i < chunkNum; i++) { job->emplace([=]() { - (*sys)(ChunkView{ archetype, i, archetype->GetChunk(i) }); + (*sys)(w, ChunkView{ archetype, i, archetype->GetChunk(i) }); }); } } } -void EntityMngr::RunCommands() { - lock_guard guard(commandBufferMutex); - for (const auto& command : commandBuffer) - command(); - commandBuffer.clear(); -} - void EntityMngr::Accept(IListener* listener) const { listener->EnterEntityMngr(this); for (const auto& [h, a] : h2a) { diff --git a/src/core/Schedule.cpp b/src/core/Schedule.cpp index 2990094..2c3fc1b 100644 --- a/src/core/Schedule.cpp +++ b/src/core/Schedule.cpp @@ -153,18 +153,6 @@ Schedule& Schedule::Order(string_view x, string_view y) { return *this; } -size_t Schedule::EntityNumInQuery(string_view sys) const { - size_t hashcode = SystemFunc::HashCode(sys); - auto target = sysFuncs.find(hashcode); - if (target == sysFuncs.end()) - return size_t_invalid; - - const_cast(this)->LockFilter(sys); - - auto func = target->second; - return entityMngr->EntityNum(func->query); -} - Schedule& Schedule::InsertAll(string_view sys, CmptType type) { size_t hashcode = SystemFunc::HashCode(sys); auto& change = sysFilterChange[hashcode]; diff --git a/src/core/SystemFunc.cpp b/src/core/SystemFunc.cpp index 2bbca13..68d3611 100644 --- a/src/core/SystemFunc.cpp +++ b/src/core/SystemFunc.cpp @@ -2,9 +2,10 @@ using namespace Ubpa::UECS; -void SystemFunc::operator()(Entity e, size_t entityIndexInQuery, CmptsView rtdcmpts) { +void SystemFunc::operator()(World* w, Entity e, size_t entityIndexInQuery, CmptsView rtdcmpts) { assert(mode == Mode::Entity); return func( + w, e, entityIndexInQuery, rtdcmpts, @@ -12,9 +13,10 @@ void SystemFunc::operator()(Entity e, size_t entityIndexInQuery, CmptsView rtdcm ); } -void SystemFunc::operator()(ChunkView chunkView) { +void SystemFunc::operator()(World* w, ChunkView chunkView) { assert(mode == Mode::Chunk); return func( + w, Entity::Invalid(), size_t_invalid, CmptsView{ nullptr, nullptr }, @@ -22,9 +24,10 @@ void SystemFunc::operator()(ChunkView chunkView) { ); } -void SystemFunc::operator()() { +void SystemFunc::operator()(World* w) { assert(mode == Mode::Job); return func( + w, Entity::Invalid(), size_t_invalid, CmptsView{ nullptr, nullptr }, diff --git a/src/core/World.cpp b/src/core/World.cpp index 502a250..48aea0a 100644 --- a/src/core/World.cpp +++ b/src/core/World.cpp @@ -6,12 +6,7 @@ using namespace Ubpa::UECS; using namespace Ubpa; using namespace std; -World::World() - : - schedule{ &entityMngr, &systemMngr }, - systemMngr{ this } -{ -} +World::World() : systemMngr{ this } {} void World::Update() { schedule.Clear(); @@ -33,14 +28,14 @@ void World::Update() { switch (func->GetMode()) { case Ubpa::UECS::SystemFunc::Mode::Entity: - entityMngr.GenEntityJob(job, func); + entityMngr.GenEntityJob(this, job, func); break; case Ubpa::UECS::SystemFunc::Mode::Chunk: - entityMngr.GenChunkJob(job, func); + entityMngr.GenChunkJob(this, job, func); break; case Ubpa::UECS::SystemFunc::Mode::Job: - job->emplace([func = func]() { - (*func)(); + job->emplace([this, func = func]() { + (*func)(this); }); break; default: @@ -57,7 +52,7 @@ void World::Update() { executor.run(jobGraph).wait(); - entityMngr.RunCommands(); + RunCommands(); } string World::DumpUpdateJobGraph() const { @@ -252,3 +247,14 @@ void World::Accept(IListener* listener) const { entityMngr.Accept(listener); listener->ExistWorld(this); } + +void World::AddCommand(std::function command) { + std::lock_guard guard(commandBufferMutex); + commandBuffer.push_back(std::move(command)); +} + +void World::RunCommands() { + for (const auto& command : commandBuffer) + command(this); + commandBuffer.clear(); +} diff --git a/src/test/01_tag/main.cpp b/src/test/01_tag/main.cpp index e022b33..f4362d3 100644 --- a/src/test/01_tag/main.cpp +++ b/src/test/01_tag/main.cpp @@ -12,14 +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") - .Register([](LastFrame d) { cout << "lastFrame_sys1" << endl; }, "lastFrame_sys1") - .Register([](Data* d) { cout << "writer_sys0" << endl; }, "writer_sys0") - .Register([](Data* d) { cout << "writer_sys1" << endl; }, "writer_sys1") - .Register([](Data* d) { cout << "writer_sys2" << endl; }, "writer_sys2") - .Register([](const Data* d) { cout << "latest_sys0" << endl; }, "latest_sys0") - .Register([](const Data* d) { cout << "latest_sys1" << endl; }, "latest_sys1"); + 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"); } }; diff --git a/src/test/02_order/main.cpp b/src/test/02_order/main.cpp index 98ac26a..f714420 100644 --- a/src/test/02_order/main.cpp +++ b/src/test/02_order/main.cpp @@ -13,11 +13,12 @@ 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 - .Register([](Data1* d1, Data2* d2) { cout << "writer_sys0" << endl; }, "writer_sys0") - .Register([](Data1* d) { cout << "writer_sys1" << endl; }, "writer_sys1") - .Register([](Data2* d2) { cout << "writer_sys2" << endl; }, "writer_sys2") - .Register([](Data1* d, Data2* d2) { cout << "writer_sys3" << endl; }, "writer_sys3") .Order("writer_sys0", "writer_sys1") .Order("writer_sys1", "writer_sys3"); } diff --git a/src/test/03_query_entity/main.cpp b/src/test/03_query_entity/main.cpp index bef6b98..bf17067 100644 --- a/src/test/03_query_entity/main.cpp +++ b/src/test/03_query_entity/main.cpp @@ -15,28 +15,30 @@ class MySystem : public System { virtual void OnUpdate(Schedule& schedule) override { schedule.Register( - [em = schedule.GetEntityMngr()](Entity e, const A* a, const B* b) { - em->AddCommand( - [e, em]() { - if (!em->Have(e, CmptType::Of)) { + [](World* w, Entity e, const A* a, const B* b) { + w->AddCommand( + [e](World* w) { + if (!w->entityMngr.Have(e, CmptType::Of)) { cout << "Attach C" << endl; - em->Attach(e); + w->entityMngr.Attach(e); } } ); - }, "AB" + }, + "AB" ); schedule.Register( - [em = schedule.GetEntityMngr()](Entity e, const A* a, const B* b, const C* c) { - em->AddCommand( - [e, em]() { - if (em->Have(e, CmptType::Of)) { + [](World* w, Entity e, const A* a, const B* b, const C* c) { + w->AddCommand( + [e](World* w) { + if (w->entityMngr.Have(e, CmptType::Of)) { cout << "Dettach C" << endl; - em->Detach(e, &CmptType::Of, 1); + w->entityMngr.Detach(e, &CmptType::Of, 1); } } ); - }, "ABC" + }, + "ABC" ); } }; diff --git a/src/test/06_none_parallel/main.cpp b/src/test/06_none_parallel/main.cpp index 7710b59..b4b4aa2 100644 --- a/src/test/06_none_parallel/main.cpp +++ b/src/test/06_none_parallel/main.cpp @@ -24,9 +24,8 @@ class MySystem : public System { TypeList<>{}, // any TypeList<>{} // none ); - schedule - .Register([](B*) {}, "need B, none A", filter_w0) - .Register([](B*) {}, "need A, B", filter_w1); + schedule.Register([](B*) {}, "need B, none A", filter_w0); + schedule.Register([](B*) {}, "need A, B", filter_w1);; } }; diff --git a/src/test/07_overload/main.cpp b/src/test/07_overload/main.cpp index 6147f35..4ea5b5b 100644 --- a/src/test/07_overload/main.cpp +++ b/src/test/07_overload/main.cpp @@ -23,9 +23,8 @@ class AVP_System : public System { using System::System; virtual void OnUpdate(Schedule& schedule) override { - schedule - .Register([](const A*, V*, P*) {cout << "AVP" << endl; }, "AVP") - .InsertNone("VP", CmptType::Of); + schedule.Register([](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 afd9ee1..c840e5f 100644 --- a/src/test/08_job/main.cpp +++ b/src/test/08_job/main.cpp @@ -13,22 +13,22 @@ class MySystem : public System { virtual void OnUpdate(Schedule& schedule) override { auto buffer = std::make_shared>(); - schedule - .Register( - [buffer](size_t idxInQuery, const Data* data) { - buffer->at(idxInQuery) = data->value; - }, "system function" - ) - .Register( - [buffer]() { - size_t sum = 0; - for (size_t i : *buffer) - sum += i; - cout << sum << endl; - }, "job" - ) - .Order("system function", "job"); - size_t num = schedule.EntityNumInQuery("system function"); + auto f = schedule.Register([buffer](size_t idxInQuery, const Data* data) { + buffer->at(idxInQuery) = data->value; + }, + "system function" + ); + schedule.Register([buffer]() { + size_t sum = 0; + for (size_t i : *buffer) + sum += i; + cout << sum << endl; + }, + "job" + ); + schedule.Order("system function", "job"); + + size_t num = GetWorld()->entityMngr.EntityNum(f->query); buffer->resize(num); } }; diff --git a/src/test/09_idx_in_query/main.cpp b/src/test/09_idx_in_query/main.cpp index 840c908..a059f6c 100644 --- a/src/test/09_idx_in_query/main.cpp +++ b/src/test/09_idx_in_query/main.cpp @@ -14,20 +14,19 @@ class MySystem : public System { virtual void OnUpdate(Schedule& schedule) override { auto flags = std::make_shared>(); - schedule - .Register( - [flags](Entity e, size_t indexInQuery, const A*) { - flags->at(indexInQuery) = true; - }, "set flag" - ) - .Register( - [flags]() { - for (auto flag : *flags) - cout << flag << endl; - }, "print flag" - ) - .Order("set flag", "print flag"); - size_t num = schedule.EntityNumInQuery("set flag"); + auto f = schedule.Register( + [flags](Entity e, size_t indexInQuery, const A*) { + flags->at(indexInQuery) = true; + }, "set flag" + ); + schedule.Register( + [flags]() { + for (auto flag : *flags) + cout << flag << endl; + }, "print flag" + ); + schedule.Order("set flag", "print flag"); + size_t num = GetWorld()->entityMngr.EntityNum(f->query); flags->insert(flags->begin(), num, false); } }; diff --git a/src/test/11_runtime_cmpt/main.cpp b/src/test/11_runtime_cmpt/main.cpp index 62a860e..a421b09 100644 --- a/src/test/11_runtime_cmpt/main.cpp +++ b/src/test/11_runtime_cmpt/main.cpp @@ -24,19 +24,18 @@ class RTDSystem: public System{ cmpts_read.data(), cmpts_read.size() ); - schedule - .Register( - [](CmptsView cmpts) { - auto luaCmpt = cmpts.GetCmpt(CmptType{ "LuaCmpt", AccessMode::WRITE }); - double& val = *reinterpret_cast(luaCmpt.Ptr()); - val = 520.; - }, "write", locator_write) - .Register( - [](CmptsView cmpts) { - auto luaCmpt = cmpts.GetCmpt(CmptType{ "LuaCmpt", AccessMode::LATEST }); - const double& val = *reinterpret_cast(luaCmpt.Ptr()); - cout << "value : " << val << endl; - }, "read", locator_read); + schedule.Register( + [](CmptsView cmpts) { + auto luaCmpt = cmpts.GetCmpt(CmptType{ "LuaCmpt", AccessMode::WRITE }); + double& val = *reinterpret_cast(luaCmpt.Ptr()); + val = 520.; + }, "write", locator_write); + schedule.Register( + [](CmptsView cmpts) { + auto luaCmpt = cmpts.GetCmpt(CmptType{ "LuaCmpt", AccessMode::LATEST }); + const double& val = *reinterpret_cast(luaCmpt.Ptr()); + cout << "value : " << val << endl; + }, "read", locator_read); } };