Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubpa committed May 22, 2020
1 parent c119d1a commit 65aaf0a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
6 changes: 6 additions & 0 deletions include/UECS/RTDCmptTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename Cmpt>
void Register();

Expand Down
2 changes: 1 addition & 1 deletion include/UECS/detail/EntityMngr.inl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ namespace Ubpa {
template<typename... Cmpts>
std::tuple<Cmpts*...> EntityMngr::Attach(Entity e) {
static_assert((std::is_constructible_v<Cmpts> &&...),
"EntityMngr::Attach: <Cmpts> isn't default constructable");
"EntityMngr::Attach: <Cmpts> isn't default constructible");
if (!Exist(e)) throw std::invalid_argument("Entity is invalid");

using CmptList = TypeList<Cmpts...>;
Expand Down
8 changes: 8 additions & 0 deletions include/UECS/detail/RTDCmptTraits.inl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace Ubpa {

template<typename Cmpt>
void RTDCmptTraits::Register() {
static_assert(std::is_default_constructible_v<Cmpt>, "<Cmpt> must be default-constructible");
static_assert(std::is_copy_constructible_v<Cmpt>, "<Cmpt> must be copy-constructible");
static_assert(std::is_move_constructible_v<Cmpt>, "<Cmpt> must be move-constructible");
static_assert(std::is_destructible_v<Cmpt>, "<Cmpt> must be destructible");
Expand All @@ -55,6 +56,11 @@ namespace Ubpa {
sizeofs[type] = sizeof(Cmpt);
alignments[type] = alignof(Cmpt);

if constexpr (!std::is_trivially_default_constructible_v<Cmpt>) {
default_constructors[type] = [](void* cmpt) {
new(cmpt)Cmpt;
};
}
if constexpr (!std::is_trivially_destructible_v<Cmpt>) {
destructors[type] = [](void* cmpt) {
reinterpret_cast<Cmpt*>(cmpt)->~Cmpt();
Expand All @@ -79,6 +85,8 @@ namespace Ubpa {
sizeofs.erase(type);
alignments.erase(type);

if constexpr (!std::is_trivially_constructible_v<Cmpt>)
default_constructors.erase(type);
if constexpr (!std::is_trivially_destructible_v<Cmpt>)
destructors.erase(type);
if constexpr (!std::is_trivially_move_constructible_v<Cmpt>)
Expand Down
2 changes: 1 addition & 1 deletion src/test/11_runtime_cmpt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<RTDSystem>();
Expand Down

0 comments on commit 65aaf0a

Please sign in to comment.