diff --git a/CMakeLists.txt b/CMakeLists.txt index 63e549b..a8940d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR) -project(UECS VERSION 0.9.2) +project(UECS VERSION 0.9.3) message(STATUS "[Project] ${PROJECT_NAME}") include(FetchContent) diff --git a/include/UECS/RTDCmptTraits.h b/include/UECS/RTDCmptTraits.h index 8c140cc..501583b 100644 --- a/include/UECS/RTDCmptTraits.h +++ b/include/UECS/RTDCmptTraits.h @@ -40,6 +40,12 @@ namespace Ubpa { inline RTDCmptTraits& Deregister(CmptType type) noexcept; + // register all for Cmpt + // static_assert + // - is_default_constructible_v + // - is_copy_constructible_v + // - is_move_constructible_v + // - is_destructible_v template void Register(); diff --git a/include/UECS/detail/EntityMngr.inl b/include/UECS/detail/EntityMngr.inl index 776cb98..473601d 100644 --- a/include/UECS/detail/EntityMngr.inl +++ b/include/UECS/detail/EntityMngr.inl @@ -115,7 +115,7 @@ namespace Ubpa { template std::tuple EntityMngr::Attach(Entity e) { static_assert((std::is_constructible_v &&...), - "EntityMngr::Attach: isn't default constructable"); + "EntityMngr::Attach: isn't default constructible"); if (!Exist(e)) throw std::invalid_argument("Entity is invalid"); using CmptList = TypeList; diff --git a/include/UECS/detail/RTDCmptTraits.inl b/include/UECS/detail/RTDCmptTraits.inl index 6d92bba..2625b0f 100644 --- a/include/UECS/detail/RTDCmptTraits.inl +++ b/include/UECS/detail/RTDCmptTraits.inl @@ -46,6 +46,7 @@ namespace Ubpa { template void RTDCmptTraits::Register() { + static_assert(std::is_default_constructible_v, " must be default-constructible"); static_assert(std::is_copy_constructible_v, " must be copy-constructible"); static_assert(std::is_move_constructible_v, " must be move-constructible"); static_assert(std::is_destructible_v, " must be destructible"); @@ -55,6 +56,11 @@ namespace Ubpa { sizeofs[type] = sizeof(Cmpt); alignments[type] = alignof(Cmpt); + if constexpr (!std::is_trivially_default_constructible_v) { + default_constructors[type] = [](void* cmpt) { + new(cmpt)Cmpt; + }; + } if constexpr (!std::is_trivially_destructible_v) { destructors[type] = [](void* cmpt) { reinterpret_cast(cmpt)->~Cmpt(); @@ -79,6 +85,8 @@ namespace Ubpa { sizeofs.erase(type); alignments.erase(type); + if constexpr (!std::is_trivially_constructible_v) + default_constructors.erase(type); if constexpr (!std::is_trivially_destructible_v) destructors.erase(type); if constexpr (!std::is_trivially_move_constructible_v) diff --git a/src/test/11_runtime_cmpt/main.cpp b/src/test/11_runtime_cmpt/main.cpp index ae9cfc9..ccb35f2 100644 --- a/src/test/11_runtime_cmpt/main.cpp +++ b/src/test/11_runtime_cmpt/main.cpp @@ -50,7 +50,7 @@ int main() { // } RTDCmptTraits::Instance().RegisterSize(type, 8); RTDCmptTraits::Instance().RegisterDefaultConstructor(type, [](void*) { cout << "construct" << endl;}); - RTDCmptTraits::Instance().RegisterDestructor(type, [](void*) { cout << "destructor" << endl; }); + RTDCmptTraits::Instance().RegisterDestructor(type, [](void*) { cout << "destruct" << endl; }); World w; w.systemMngr.Register();