From 1c51806e4af5d7d8dd09ce8e19903f1079296199 Mon Sep 17 00:00:00 2001 From: Ubpa <641614112@qq.com> Date: Thu, 30 Jul 2020 21:19:05 +0800 Subject: [PATCH] del namespace Ubpa::UECS::CmptTag --- doc/API.md | 8 +-- include/UECS/CmptTag.h | 95 +++++++++++++-------------- include/UECS/EntityLocator.h | 2 +- include/UECS/RTDCmptsView.h | 14 ++-- include/UECS/SystemFunc.h | 2 +- include/UECS/detail/CmptTag.inl | 2 +- include/UECS/detail/EntityLocator.inl | 14 ++-- include/UECS/detail/SystemFunc.inl | 8 +-- src/core/EntityLocator.cpp | 8 +-- src/test/01_tag/main.cpp | 4 +- src/test/12_framegraph/main.cpp | 2 +- 11 files changed, 79 insertions(+), 80 deletions(-) diff --git a/doc/API.md b/doc/API.md index 44da6dc..a627d4b 100644 --- a/doc/API.md +++ b/doc/API.md @@ -181,9 +181,9 @@ if `e` is invalid, throw `std::invalid_argument`. use tag to dstinguish write, read before write and read after write -- `CmptTag::LastFrame`: read before write -- `CmptTag::Write`: write, equal to ` *` -- `CmptTag::Latest`: read after write, equal to `const *` +- `LastFrame`: read before write +- `Write`: write, equal to ` *` +- `Latest`: read after write, equal to `const *` ## `EntityLocator` @@ -210,7 +210,7 @@ query.filter can be change dynamically by other `` with Schedule [system function kind] (distinguish by argument list) - per entity function: `[[const] Entity e, ] [size_t indexInQuery, ] ...` - - tagged component: `CmptTag::{LastFrame|Write|Latest}` + - tagged component: `{LastFrame|Write|Latest}` - job: empty argument list - runtime dynamic function: `const EntityLocator* locator, void** cmpts` diff --git a/include/UECS/CmptTag.h b/include/UECS/CmptTag.h index c5c8545..406ffaa 100644 --- a/include/UECS/CmptTag.h +++ b/include/UECS/CmptTag.h @@ -3,64 +3,63 @@ #include namespace Ubpa::UECS { - namespace CmptTag { - // LastFrame -> Write -> Latest - enum class Mode { - LAST_FRAME, - WRITE, - LATEST - }; + // LastFrame -> Write -> Latest - template - class LastFrame { - public: - LastFrame(const Cmpt* cmpt) noexcept : cmpt{ cmpt } {} - const Cmpt* get() const noexcept { return cmpt; } - operator const Cmpt* () const noexcept { return cmpt; } - const Cmpt* operator->() const noexcept { return cmpt; } - private: - const Cmpt* cmpt; - }; + enum class Mode { + LAST_FRAME, + WRITE, + LATEST + }; - template - using Write = Cmpt*; + template + class LastFrame { + public: + LastFrame(const Cmpt* cmpt) noexcept : cmpt{ cmpt } {} + const Cmpt* get() const noexcept { return cmpt; } + operator const Cmpt* () const noexcept { return cmpt; } + const Cmpt* operator->() const noexcept { return cmpt; } + private: + const Cmpt* cmpt; + }; - template - using Latest = const Cmpt*; + template + using Write = Cmpt*; - // - template - struct RemoveTag; - template - using RemoveTag_t = typename RemoveTag::type; + template + using Latest = const Cmpt*; - // * - template - struct DecayTag; - template - using DecayTag_t = typename DecayTag::type; + // + template + struct RemoveTag; + template + using RemoveTag_t = typename RemoveTag::type; - template - struct IsLastFrame; - template - static constexpr bool IsLastFrame_v = IsLastFrame::value; + // * + template + struct DecayTag; + template + using DecayTag_t = typename DecayTag::type; - template - struct IsWrite; - template - static constexpr bool IsWrite_v = IsWrite::value; + template + struct IsLastFrame; + template + static constexpr bool IsLastFrame_v = IsLastFrame::value; - template - struct IsLatest; - template - static constexpr bool IsLatest_v = IsLatest::value; + template + struct IsWrite; + template + static constexpr bool IsWrite_v = IsWrite::value; - template - struct IsTaggedCmpt : IValue || IsWrite_v || IsLatest_v> {}; - template - static constexpr bool IsTaggedCmpt_v = IsTaggedCmpt::value; - } + template + struct IsLatest; + template + static constexpr bool IsLatest_v = IsLatest::value; + + template + struct IsTaggedCmpt : IValue || IsWrite_v || IsLatest_v> {}; + template + static constexpr bool IsTaggedCmpt_v = IsTaggedCmpt::value; } #include "detail/CmptTag.inl" diff --git a/include/UECS/EntityLocator.h b/include/UECS/EntityLocator.h index 3ae4237..60a589a 100644 --- a/include/UECS/EntityLocator.h +++ b/include/UECS/EntityLocator.h @@ -27,7 +27,7 @@ namespace Ubpa::UECS { const std::set& LatestCmptTypes() const noexcept { return latestCmptTypes; } const std::set& CmptTypes() const noexcept { return cmptTypes; } - CmptTag::Mode GetCmptTagMode(CmptType type) const; + Mode GetCmptTagMode(CmptType type) const; bool operator==(const EntityLocator& locator) const noexcept; private: diff --git a/include/UECS/RTDCmptsView.h b/include/UECS/RTDCmptsView.h index 9ad2aec..2d61b9b 100644 --- a/include/UECS/RTDCmptsView.h +++ b/include/UECS/RTDCmptsView.h @@ -17,28 +17,28 @@ namespace Ubpa::UECS { // for read/write control class CmptHandle { public: - CmptHandle(CmptType type, void* cmpt, CmptTag::Mode mode) + CmptHandle(CmptType type, void* cmpt, Mode mode) : type{ type }, cmpt{ cmpt }, mode{ mode }{} CmptType GetCmptType() const noexcept { return type; } - CmptTag::Mode GetMode() const noexcept { return mode; } + Mode GetMode() const noexcept { return mode; } CmptCPtr AsLastFrame() const noexcept { - assert(mode == CmptTag::Mode::LAST_FRAME); + assert(mode == Mode::LAST_FRAME); return { type, cmpt }; } CmptPtr AsWrite() const noexcept { - assert(mode == CmptTag::Mode::WRITE); + assert(mode == Mode::WRITE); return { type, cmpt }; } CmptCPtr AsLatest() const noexcept { - assert(mode == CmptTag::Mode::LATEST); + assert(mode == Mode::LATEST); return { type, cmpt }; } private: CmptType type; void* cmpt; - CmptTag::Mode mode; + Mode mode; }; // forward @@ -69,7 +69,7 @@ namespace Ubpa::UECS { EntityLocator* locator; std::set::iterator typeIter; void* const* ptr_cmpt; - mutable CmptHandle handle{ CmptType::Invalid(), nullptr, CmptTag::Mode{} }; + mutable CmptHandle handle{ CmptType::Invalid(), nullptr, Mode{} }; }; RTDCmptsView(EntityLocator* locator, void** cmpts) diff --git a/include/UECS/SystemFunc.h b/include/UECS/SystemFunc.h index c2806ce..157e7d2 100644 --- a/include/UECS/SystemFunc.h +++ b/include/UECS/SystemFunc.h @@ -14,7 +14,7 @@ namespace Ubpa::UECS { // 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, ] ... - // - - tagged component: CmptTag::{LastFrame|Write|Latest} + // - - tagged component: {LastFrame|Write|Latest} // 2. job: empty argument list // 3. runtime dynamic function: const EntityLocator* locator, void** cmpts class SystemFunc { diff --git a/include/UECS/detail/CmptTag.inl b/include/UECS/detail/CmptTag.inl index 6e65293..6d4860b 100644 --- a/include/UECS/detail/CmptTag.inl +++ b/include/UECS/detail/CmptTag.inl @@ -7,7 +7,7 @@ namespace Ubpa::UECS { class EntityLocator; } -namespace Ubpa::UECS::CmptTag { +namespace Ubpa::UECS { template struct RemoveTag : IType {}; template struct RemoveTag : IType {}; template struct RemoveTag> : IType {}; diff --git a/include/UECS/detail/EntityLocator.inl b/include/UECS/detail/EntityLocator.inl index d4a1f7d..3cd6adf 100644 --- a/include/UECS/detail/EntityLocator.inl +++ b/include/UECS/detail/EntityLocator.inl @@ -9,18 +9,18 @@ namespace Ubpa::UECS { template EntityLocator::EntityLocator(TaggedCmptList) - : EntityLocator{ Filter_t{}, - Filter_t{}, - Filter_t{} } + : EntityLocator{ Filter_t{}, + Filter_t{}, + Filter_t{} } { } template EntityLocator::EntityLocator(TypeList, TypeList, TypeList) - : lastFrameCmptTypes{ CmptType::Of>... }, - writeCmptTypes{ CmptType::Of>... }, - latestCmptTypes{ CmptType::Of>... }, - cmptTypes{ CmptType::Of>..., CmptType::Of>...,CmptType::Of>... }, + : lastFrameCmptTypes{ CmptType::Of>... }, + writeCmptTypes{ CmptType::Of>... }, + latestCmptTypes{ CmptType::Of>... }, + cmptTypes{ CmptType::Of>..., CmptType::Of>...,CmptType::Of>... }, hashCode{ GenHashCode() } { } diff --git a/include/UECS/detail/SystemFunc.inl b/include/UECS/detail/SystemFunc.inl index 9b30187..0170bac 100644 --- a/include/UECS/detail/SystemFunc.inl +++ b/include/UECS/detail/SystemFunc.inl @@ -35,7 +35,7 @@ namespace Ubpa::UECS { func{ detail::System_::Pack(std::forward(func)) }, name{ std::move(name) }, hashCode{ HashCode(this->name) }, - query{ std::move(filter), EntityLocator{Filter_t{}} } + query{ std::move(filter), EntityLocator{Filter_t{}} } { } } @@ -60,12 +60,12 @@ namespace Ubpa::UECS::detail::System_ { auto Pack(Func&& func) noexcept { using ArgList = FuncTraits_ArgList; - using DecayedArgList = Transform_t; + using DecayedArgList = Transform_t; static_assert(IsSet_v, "detail::System_::Pack: 's argument types must be a set"); - using TaggedCmptList = Filter_t; + using TaggedCmptList = Filter_t; - using CmptList = Transform_t; + using CmptList = Transform_t; using SortedCmptList = QuickSort_t; return Packer::run(std::forward(func)); diff --git a/src/core/EntityLocator.cpp b/src/core/EntityLocator.cpp index bcdd4b1..5ae5ca8 100644 --- a/src/core/EntityLocator.cpp +++ b/src/core/EntityLocator.cpp @@ -30,12 +30,12 @@ bool EntityLocator::operator==(const EntityLocator& locator) const noexcept { && latestCmptTypes == latestCmptTypes; } -CmptTag::Mode EntityLocator::GetCmptTagMode(CmptType type) const { +Mode EntityLocator::GetCmptTagMode(CmptType type) const { assert(cmptTypes.find(type) != cmptTypes.end()); if (lastFrameCmptTypes.find(type) != lastFrameCmptTypes.end()) - return CmptTag::Mode::LAST_FRAME; + return Mode::LAST_FRAME; else if (writeCmptTypes.find(type) != writeCmptTypes.end()) - return CmptTag::Mode::WRITE; + return Mode::WRITE; else // lastestCmptTypes.find(type) != lastestCmptTypes.end()) - return CmptTag::Mode::LATEST; + return Mode::LATEST; } diff --git a/src/test/01_tag/main.cpp b/src/test/01_tag/main.cpp index d242df8..0744704 100644 --- a/src/test/01_tag/main.cpp +++ b/src/test/01_tag/main.cpp @@ -10,8 +10,8 @@ struct Data {}; struct DataSystem { static void OnUpdate(Schedule& schedule) { schedule - .Register([](CmptTag::LastFrame d) { cout << "lastFrame_sys0" << endl; }, "lastFrame_sys0") - .Register([](CmptTag::LastFrame d) { cout << "lastFrame_sys1" << endl; }, "lastFrame_sys1") + .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") diff --git a/src/test/12_framegraph/main.cpp b/src/test/12_framegraph/main.cpp index 70afb38..1fee98d 100644 --- a/src/test/12_framegraph/main.cpp +++ b/src/test/12_framegraph/main.cpp @@ -23,7 +23,7 @@ struct MySystem { ); schedule .Register( - [](CmptTag::LastFrame a, CmptTag::Write b, CmptTag::Latest c) {}, + [](LastFrame a, Write b, Latest c) {}, "System Func", filter );