diff --git a/include/NovelRT.Interop/Ecs/NrtComponentBufferMemoryContainer.h b/include/NovelRT.Interop/Ecs/NrtComponentBufferMemoryContainer.h index b34c54b6d..ed5c24735 100644 --- a/include/NovelRT.Interop/Ecs/NrtComponentBufferMemoryContainer.h +++ b/include/NovelRT.Interop/Ecs/NrtComponentBufferMemoryContainer.h @@ -15,6 +15,7 @@ extern "C" void* deleteInstructionState, size_t sizeOfDataTypeInBytes, NrtComponentUpdateFnPtr fnPtr, + const char* serialisedTypeName, void* context); void Nrt_ComponentBufferMemoryContainer_PrepContainerForFrame(NrtComponentBufferMemoryContainerHandle container, diff --git a/include/NovelRT.Interop/Ecs/NrtComponentCache.h b/include/NovelRT.Interop/Ecs/NrtComponentCache.h index cc7a67df0..ee96a01da 100644 --- a/include/NovelRT.Interop/Ecs/NrtComponentCache.h +++ b/include/NovelRT.Interop/Ecs/NrtComponentCache.h @@ -17,6 +17,7 @@ extern "C" size_t sizeOfDataType, const void* deleteInstructionState, NrtComponentUpdateFnPtr updateFnPtr, + const char* serialisedTypeName, void* context, NrtComponentTypeId* outputResult); diff --git a/include/NovelRT/Ecs/ComponentBuffer.h b/include/NovelRT/Ecs/ComponentBuffer.h index db5de3c54..b3c068933 100644 --- a/include/NovelRT/Ecs/ComponentBuffer.h +++ b/include/NovelRT/Ecs/ComponentBuffer.h @@ -36,18 +36,20 @@ namespace NovelRT::Ecs * * * @param poolSize The amount of worker threads being utilised in this instance of the ECS. + * @param serialisedTypeName The type name to use for serialisation of this data type. * @param deleteInstructionState The component state to treat as the delete instruction. When this state is * passed in during an update, the ComponentBuffer will delete the component from the target entity during * resolution. */ - ComponentBuffer(size_t poolSize, T deleteInstructionState) noexcept + ComponentBuffer(size_t poolSize, T deleteInstructionState, const std::string& serialisedTypeName) noexcept : _innerContainer(std::make_shared( poolSize, &deleteInstructionState, sizeof(T), [](auto rootComponent, auto updateComponent, auto) { *reinterpret_cast(rootComponent) += *reinterpret_cast(updateComponent); - })) + }, + serialisedTypeName)) { static_assert(std::is_trivially_copyable::value, "Value type must be trivially copyable for use with a ComponentBuffer. See the documentation " @@ -197,6 +199,16 @@ namespace NovelRT::Ecs return _innerContainer->HasComponent(entity); } + /** + * @brief Gets the serialised type name used for the loading and unloading to and from serialised data. + * + * @return The serialised type name as a string. + */ + [[nodiscard]] const std::string& GetSerialisedTypeName() const noexcept + { + return _innerContainer->GetSerialisedTypeName(); + } + /** * @brief Gets the length of the current immutable data snapshot within the buffer. * diff --git a/include/NovelRT/Ecs/ComponentBufferMemoryContainer.h b/include/NovelRT/Ecs/ComponentBufferMemoryContainer.h index 6179dc66c..14f979c50 100644 --- a/include/NovelRT/Ecs/ComponentBufferMemoryContainer.h +++ b/include/NovelRT/Ecs/ComponentBufferMemoryContainer.h @@ -18,6 +18,7 @@ namespace NovelRT::Ecs std::vector _deleteInstructionState; size_t _sizeOfDataTypeInBytes; std::function _componentUpdateLogic; + std::string _serialisedTypeName; public: class ImmutableDataView @@ -46,7 +47,8 @@ namespace NovelRT::Ecs ComponentBufferMemoryContainer(size_t poolSize, const void* deleteInstructionState, size_t sizeOfDataTypeInBytes, - std::function componentUpdateLogic) noexcept; + std::function componentUpdateLogic, + const std::string& serialisedTypeName) noexcept; void PrepContainerForFrame(const std::vector& destroyedEntities) noexcept; @@ -61,6 +63,11 @@ namespace NovelRT::Ecs [[nodiscard]] size_t GetImmutableDataLength() const noexcept; + [[nodiscard]] inline const std::string& GetSerialisedTypeName() const noexcept + { + return _serialisedTypeName; + } + [[nodiscard]] SparseSetMemoryContainer::ConstIterator begin() const noexcept; [[nodiscard]] SparseSetMemoryContainer::ConstIterator end() const noexcept; diff --git a/include/NovelRT/Ecs/ComponentCache.h b/include/NovelRT/Ecs/ComponentCache.h index 4c94ad2a6..1500b0050 100644 --- a/include/NovelRT/Ecs/ComponentCache.h +++ b/include/NovelRT/Ecs/ComponentCache.h @@ -26,7 +26,8 @@ namespace NovelRT::Ecs std::shared_ptr CreateContainer( size_t sizeOfDataType, const void* deleteInstructionState, - const std::function& componentUpdateLogic) const; + const std::function& componentUpdateLogic, + const std::string& serialisedTypeName) const; public: /** @@ -49,6 +50,7 @@ namespace NovelRT::Ecs * @param sizeOfDataType The size of the object type, in bytes. * @param deleteInstructionState The object state that indicates that the component should be deleted. * @param componentUpdateLogic The function to use for concurrent update consolidation. + * @param serialisedTypeName The type name to use for data serialisation. * @return the ID of the new component type and associated ComponentBufferMemoryContainer * instance. * @@ -58,7 +60,8 @@ namespace NovelRT::Ecs [[nodiscard]] ComponentTypeId RegisterComponentTypeUnsafe( size_t sizeOfDataType, const void* deleteInstructionState, - const std::function& componentUpdateLogic); + const std::function& componentUpdateLogic, + const std::string& serialisedTypeName); /** * @brief Registers a new component type to the cache. @@ -74,12 +77,14 @@ namespace NovelRT::Ecs * @exception std::bad_alloc when a ComponentBuffer could not be allocated in memory for the given component * type. */ - template void RegisterComponentType(T deleteInstructionState) + template void RegisterComponentType(T deleteInstructionState, const std::string& serialisedTypeName) { - std::shared_ptr ptr = - CreateContainer(sizeof(T), &deleteInstructionState, [](auto rootComponent, auto updateComponent, auto) { + std::shared_ptr ptr = CreateContainer( + sizeof(T), &deleteInstructionState, + [](auto rootComponent, auto updateComponent, auto) { *reinterpret_cast(rootComponent) += *reinterpret_cast(updateComponent); - }); + }, + serialisedTypeName); _bufferPrepEvent += [ptr](auto vec) { ptr->PrepContainerForFrame(vec); }; _componentMap.emplace(GetComponentTypeId(), ptr); } diff --git a/include/NovelRT/Ecs/Configurator.h b/include/NovelRT/Ecs/Configurator.h index 3c5507e55..fe33e72a9 100644 --- a/include/NovelRT/Ecs/Configurator.h +++ b/include/NovelRT/Ecs/Configurator.h @@ -28,22 +28,28 @@ namespace NovelRT::Ecs inline void AddDefaultComponentsAndSystems(SystemScheduler& target) { - target.GetComponentCache().RegisterComponentType(Graphics::RenderComponent{0, 0, 0, 0, true}); + target.GetComponentCache().RegisterComponentType(Graphics::RenderComponent{0, 0, 0, 0, true}, + "NovelRT::Ecs::Graphics::RenderComponent"); - target.GetComponentCache().RegisterComponentType(EntityGraphComponent{ - false, std::numeric_limits::max(), std::numeric_limits::max()}); + target.GetComponentCache().RegisterComponentType( + EntityGraphComponent{false, std::numeric_limits::max(), std::numeric_limits::max()}, + "NovelRT::Ecs::EntityGraphComponent"); - target.GetComponentCache().RegisterComponentType(LinkedEntityListNodeComponent{ - false, std::numeric_limits::max(), std::numeric_limits::max()}); + target.GetComponentCache().RegisterComponentType( + LinkedEntityListNodeComponent{false, std::numeric_limits::max(), + std::numeric_limits::max()}, + "NovelRT::Ecs::LinkedEntityListNodeComponent"); target.GetComponentCache().RegisterComponentType( - TransformComponent{Maths::GeoVector3F::uniform(NAN), Maths::GeoVector2F::uniform(NAN), NAN}); + TransformComponent{Maths::GeoVector3F::uniform(NAN), Maths::GeoVector2F::uniform(NAN), NAN}, + "NovelRT::Ecs::TransformComponent"); target.RegisterSystem(std::make_shared( _graphicsPluginProvider, _windowingPluginProvider, _resourceManagementPluginProvider)); target.GetComponentCache().RegisterComponentType( - Ecs::Input::InputEventComponent{0, NovelRT::Input::KeyState::Idle, 0, 0}); + Input::InputEventComponent{0, NovelRT::Input::KeyState::Idle, 0, 0}, + "NovelRT::Ecs::Input::InputEventComponent"); target.RegisterSystem( std::make_shared(_windowingPluginProvider, _inputPluginProvider)); @@ -179,12 +185,14 @@ namespace NovelRT::Ecs * This is the final method you should call to obtain the ECS instance. * * @tparam TComponentTypes List of component types to register with this ECS instance. - * @param deleteInstructionStates The state of the given component type that signals this component is to be - * deleted to the ECS. + * @tparam Names List of the names to used for type serialisation. + * @param deleteInstructionStatesAndSerialisedTypeNames The state of the given component type that signals this + * component is to be, accompanied by the serialised type name. deleted to the ECS. * @returns An instance of the ECS SystemScheduler root object based on the provided configuration. */ template - [[nodiscard]] SystemScheduler InitialiseAndRegisterComponents(TComponentTypes... deleteInstructionStates) + [[nodiscard]] SystemScheduler InitialiseAndRegisterComponents( + std::tuple... deleteInstructionStatesAndSerialisedTypeNames) { SystemScheduler scheduler(_threadCount.value_or(0)); @@ -198,7 +206,9 @@ namespace NovelRT::Ecs scheduler.RegisterSystem(system); } - scheduler.GetComponentCache().RegisterComponentType(deleteInstructionStates...); + scheduler.GetComponentCache().RegisterComponentType( + std::get<0>(deleteInstructionStatesAndSerialisedTypeNames)..., + std::get<1>(deleteInstructionStatesAndSerialisedTypeNames)...); scheduler.SpinThreads(); return scheduler; diff --git a/src/NovelRT.Interop/Ecs/Audio/NrtAudioSystem.cpp b/src/NovelRT.Interop/Ecs/Audio/NrtAudioSystem.cpp index 2a11c256c..c1812ea8f 100644 --- a/src/NovelRT.Interop/Ecs/Audio/NrtAudioSystem.cpp +++ b/src/NovelRT.Interop/Ecs/Audio/NrtAudioSystem.cpp @@ -40,9 +40,10 @@ extern "C" auto sys = reinterpret_cast(system); auto deleteState = Ecs::Audio::AudioEmitterComponent(); - sys->GetComponentCache().RegisterComponentType(deleteState); + sys->GetComponentCache().RegisterComponentType(deleteState, "NovelRT::Ecs::Audio::AudioEmitterComponent"); sys->GetComponentCache().RegisterComponentType( - Ecs::Audio::AudioEmitterStateComponent{Ecs::Audio::AudioEmitterState::Done}); + Ecs::Audio::AudioEmitterStateComponent{Ecs::Audio::AudioEmitterState::Done}, + "NovelRT::Ecs::Audio::AudioEmitterStateComponent"); return NRT_SUCCESS; } diff --git a/src/NovelRT.Interop/Ecs/NrtComponentBufferMemoryContainer.cpp b/src/NovelRT.Interop/Ecs/NrtComponentBufferMemoryContainer.cpp index c3e8220a4..28404ef29 100644 --- a/src/NovelRT.Interop/Ecs/NrtComponentBufferMemoryContainer.cpp +++ b/src/NovelRT.Interop/Ecs/NrtComponentBufferMemoryContainer.cpp @@ -18,12 +18,13 @@ extern "C" void* deleteInstructionState, size_t sizeOfDataTypeInBytes, NrtComponentUpdateFnPtr fnPtr, + const char* serialisedTypeName, void* context) { auto func = [=](void* lhs, const void* rhs, size_t size) { fnPtr(lhs, rhs, size, context); }; - return reinterpret_cast( - new ComponentBufferMemoryContainer(poolSize, deleteInstructionState, sizeOfDataTypeInBytes, func)); + return reinterpret_cast(new ComponentBufferMemoryContainer( + poolSize, deleteInstructionState, sizeOfDataTypeInBytes, func, std::string(serialisedTypeName))); } // TODO: Not sure if I should add safety here? diff --git a/src/NovelRT.Interop/Ecs/NrtComponentCache.cpp b/src/NovelRT.Interop/Ecs/NrtComponentCache.cpp index 9de68591f..d50309f0d 100644 --- a/src/NovelRT.Interop/Ecs/NrtComponentCache.cpp +++ b/src/NovelRT.Interop/Ecs/NrtComponentCache.cpp @@ -17,6 +17,7 @@ extern "C" size_t sizeOfDataType, const void* deleteInstructionState, NrtComponentUpdateFnPtr updateFnPtr, + const char* serialisedTypeName, void* context, NrtComponentTypeId* outputResult) { @@ -35,11 +36,13 @@ extern "C" *outputResult = reinterpret_cast(componentCache) ->RegisterComponentTypeUnsafe( - sizeOfDataType, deleteInstructionState, [=](auto lhs, auto rhs, auto size) { + sizeOfDataType, deleteInstructionState, + [=](auto lhs, auto rhs, auto size) { updateFnPtr(reinterpret_cast(&lhs), reinterpret_cast(&rhs), size, context); - }); + }, + std::string(serialisedTypeName)); return NRT_SUCCESS; } diff --git a/src/NovelRT/Ecs/ComponentBufferMemoryContainer.cpp b/src/NovelRT/Ecs/ComponentBufferMemoryContainer.cpp index ede986a31..3250093a2 100644 --- a/src/NovelRT/Ecs/ComponentBufferMemoryContainer.cpp +++ b/src/NovelRT/Ecs/ComponentBufferMemoryContainer.cpp @@ -10,12 +10,14 @@ namespace NovelRT::Ecs size_t poolSize, const void* deleteInstructionState, size_t sizeOfDataTypeInBytes, - std::function componentUpdateLogic) noexcept + std::function componentUpdateLogic, + const std::string& serialisedTypeName) noexcept : _rootSet(SparseSetMemoryContainer(sizeOfDataTypeInBytes)), _updateSets(std::vector{}), _deleteInstructionState(std::vector(sizeOfDataTypeInBytes)), _sizeOfDataTypeInBytes(sizeOfDataTypeInBytes), - _componentUpdateLogic(std::move(componentUpdateLogic)) + _componentUpdateLogic(std::move(componentUpdateLogic)), + _serialisedTypeName(serialisedTypeName) { std::memcpy(_deleteInstructionState.data(), deleteInstructionState, _sizeOfDataTypeInBytes); for (size_t i = 0; i < poolSize; i++) diff --git a/src/NovelRT/Ecs/ComponentCache.cpp b/src/NovelRT/Ecs/ComponentCache.cpp index b72f5b36f..10524681a 100644 --- a/src/NovelRT/Ecs/ComponentCache.cpp +++ b/src/NovelRT/Ecs/ComponentCache.cpp @@ -17,22 +17,24 @@ namespace NovelRT::Ecs std::shared_ptr ComponentCache::CreateContainer( size_t sizeOfDataType, const void* deleteInstructionState, - const std::function& componentUpdateLogic) const + const std::function& componentUpdateLogic, + const std::string& serialisedTypeName) const { return std::make_shared(_poolSize, deleteInstructionState, sizeOfDataType, - componentUpdateLogic); + componentUpdateLogic, serialisedTypeName); } ComponentTypeId ComponentCache::RegisterComponentTypeUnsafe( size_t sizeOfDataType, const void* deleteInstructionState, - const std::function& componentUpdateLogic) + const std::function& componentUpdateLogic, + const std::string& serialisedTypeName) { static AtomFactory& _componentTypeIdFactory = AtomFactoryDatabase::GetFactory("ComponentTypeId"); ComponentTypeId returnId = _componentTypeIdFactory.GetNext(); std::shared_ptr ptr = - CreateContainer(sizeOfDataType, deleteInstructionState, componentUpdateLogic); + CreateContainer(sizeOfDataType, deleteInstructionState, componentUpdateLogic, serialisedTypeName); _bufferPrepEvent += [ptr](auto vec) { ptr->PrepContainerForFrame(vec); }; _componentMap.emplace(returnId, ptr); return returnId; diff --git a/tests/NovelRT.Tests/Ecs/CatalogueTest.cpp b/tests/NovelRT.Tests/Ecs/CatalogueTest.cpp index 6ec4da842..ddea7cee4 100644 --- a/tests/NovelRT.Tests/Ecs/CatalogueTest.cpp +++ b/tests/NovelRT.Tests/Ecs/CatalogueTest.cpp @@ -20,9 +20,9 @@ class CatalogueTest : public testing::Test { componentCache = ComponentCache(1); entityCache = EntityCache(1); - componentCache.RegisterComponentType(-1); - componentCache.RegisterComponentType(-1); - componentCache.RegisterComponentType('e'); + componentCache.RegisterComponentType(-1, "THROW_AWAY"); + componentCache.RegisterComponentType(-1, "THROW_AWAY_AGAIN"); + componentCache.RegisterComponentType('e', "THROW_AWAY_AGAIN_AGAIN"); componentCache.GetComponentBuffer().PushComponentUpdateInstruction(0, 0, 10); componentCache.GetComponentBuffer().PushComponentUpdateInstruction(0, 0, 100); diff --git a/tests/NovelRT.Tests/Ecs/ComponentBufferMemoryContainerTest.cpp b/tests/NovelRT.Tests/Ecs/ComponentBufferMemoryContainerTest.cpp index ce497490e..3874cb55d 100644 --- a/tests/NovelRT.Tests/Ecs/ComponentBufferMemoryContainerTest.cpp +++ b/tests/NovelRT.Tests/Ecs/ComponentBufferMemoryContainerTest.cpp @@ -11,21 +11,23 @@ using namespace NovelRT::Ecs; TEST(ComponentBufferMemoryContainerTest, PrepComponentBuffersForFrameDoesNotThrow) { int32_t deleteState = -1; - EXPECT_NO_THROW(ComponentBufferMemoryContainer(1, &deleteState, sizeof(int32_t), [](auto, auto, auto) { - }).PrepContainerForFrame(std::vector{})); + EXPECT_NO_THROW(ComponentBufferMemoryContainer( + 1, &deleteState, sizeof(int32_t), [](auto, auto, auto) {}, "THROW_AWAY") + .PrepContainerForFrame(std::vector{})); } TEST(ComponentBufferMemoryContainerTest, GetDeleteInstructionStateReturnsCorrectState) { int32_t deleteState = -1; - auto container = ComponentBufferMemoryContainer(1, &deleteState, sizeof(int32_t), nullptr); + auto container = ComponentBufferMemoryContainer(1, &deleteState, sizeof(int32_t), nullptr, "THROW_AWAY"); EXPECT_EQ(std::memcmp(container.GetDeleteInstructionState().GetDataHandle(), &deleteState, sizeof(int32_t)), 0); } TEST(ComponentBufferMemoryContainerTest, PushComponentUpdateInstructionAddsNewEntryCorrectly) { int32_t deleteState = -1; - auto container = ComponentBufferMemoryContainer(1, &deleteState, sizeof(int32_t), [](auto, auto, auto) {}); + auto container = ComponentBufferMemoryContainer( + 1, &deleteState, sizeof(int32_t), [](auto, auto, auto) {}, "THROW_AWAY"); int32_t updateState = 10; container.PushComponentUpdateInstruction(0, 0, &updateState); container.PrepContainerForFrame(std::vector{}); @@ -37,10 +39,12 @@ TEST(ComponentBufferMemoryContainerTest, PushComponentUpdateInstructionAddsNewEn TEST(ComponentBufferMemoryContainerTest, PushComponentUpdateInstructionUpdatesExistingEntryCorrectly) { int32_t deleteState = -1; - auto container = - ComponentBufferMemoryContainer(1, &deleteState, sizeof(int32_t), [](auto intRoot, auto intUpdate, auto) { + auto container = ComponentBufferMemoryContainer( + 1, &deleteState, sizeof(int32_t), + [](auto intRoot, auto intUpdate, auto) { *reinterpret_cast(intRoot) += *reinterpret_cast(intUpdate); - }); + }, + "THROW_AWAY"); int32_t updateState = 10; container.PushComponentUpdateInstruction(0, 0, &updateState); container.PrepContainerForFrame(std::vector{}); @@ -54,7 +58,8 @@ TEST(ComponentBufferMemoryContainerTest, PushComponentUpdateInstructionUpdatesEx TEST(ComponentBufferMemoryContainerTest, PushComponentUpdateInstructionRemovesEntryCorrectly) { int32_t deleteState = -1; - auto container = ComponentBufferMemoryContainer(1, &deleteState, sizeof(int32_t), [](auto, auto, auto) {}); + auto container = ComponentBufferMemoryContainer( + 1, &deleteState, sizeof(int32_t), [](auto, auto, auto) {}, "THROW_AWAY"); int32_t updateState = 10; container.PushComponentUpdateInstruction(0, 0, &updateState); container.PrepContainerForFrame(std::vector{}); @@ -67,7 +72,8 @@ TEST(ComponentBufferMemoryContainerTest, PushComponentUpdateInstructionRemovesEn TEST(ComponentBufferMemoryContainerTest, ForRangeSupportWorksCorrectly) { int32_t deleteState = -1; - auto container = ComponentBufferMemoryContainer(1, &deleteState, sizeof(int32_t), [](auto, auto, auto) {}); + auto container = ComponentBufferMemoryContainer( + 1, &deleteState, sizeof(int32_t), [](auto, auto, auto) {}, "THROW_AWAY"); int32_t updateState = 10; container.PushComponentUpdateInstruction(0, 0, &updateState); container.PushComponentUpdateInstruction(0, 1, &updateState); @@ -83,10 +89,12 @@ TEST(ComponentBufferMemoryContainerTest, ForRangeSupportWorksCorrectly) TEST(ComponentBufferMemoryContainerTest, ConcurrentAccessWorksCorrectly) { int32_t deleteState = -1; - auto container = - ComponentBufferMemoryContainer(2, &deleteState, sizeof(int32_t), [](auto intRoot, auto intUpdate, auto) { + auto container = ComponentBufferMemoryContainer( + 2, &deleteState, sizeof(int32_t), + [](auto intRoot, auto intUpdate, auto) { *reinterpret_cast(intRoot) += *reinterpret_cast(intUpdate); - }); + }, + "THROW_AWAY"); int32_t updateState = 10; for (size_t i = 0; i < 2000; ++i) diff --git a/tests/NovelRT.Tests/Ecs/ComponentBufferTest.cpp b/tests/NovelRT.Tests/Ecs/ComponentBufferTest.cpp index 2a5555338..5d8f25855 100644 --- a/tests/NovelRT.Tests/Ecs/ComponentBufferTest.cpp +++ b/tests/NovelRT.Tests/Ecs/ComponentBufferTest.cpp @@ -10,17 +10,17 @@ using namespace NovelRT::Ecs; TEST(ComponentBufferTest, PrepComponentBuffersForFrameDoesNotThrow) { - EXPECT_NO_THROW(ComponentBuffer(1, -1).PrepComponentBufferForFrame(std::vector{})); + EXPECT_NO_THROW(ComponentBuffer(1, -1, "THROW_AWAY").PrepComponentBufferForFrame(std::vector{})); } TEST(ComponentBufferTest, GetDeleteInstructionStateReturnsCorrectState) { - EXPECT_EQ(ComponentBuffer(1, -1).GetDeleteInstructionState(), -1); + EXPECT_EQ(ComponentBuffer(1, -1, "THROW_AWAY").GetDeleteInstructionState(), -1); } TEST(ComponentBufferTest, GetComponentUnsafeGetsComponentWithValidKey) { - auto buffer = ComponentBuffer(1, -1); + auto buffer = ComponentBuffer(1, -1, "THROW_AWAY"); buffer.PushComponentUpdateInstruction(0, 0, 10); buffer.PrepComponentBufferForFrame(std::vector{}); ASSERT_EQ(buffer.GetImmutableDataLength(), 1); @@ -30,7 +30,7 @@ TEST(ComponentBufferTest, GetComponentUnsafeGetsComponentWithValidKey) TEST(ComponentBufferTest, PushComponentUpdateInstructionAddsNewEntryCorrectly) { - auto buffer = ComponentBuffer(1, -1); + auto buffer = ComponentBuffer(1, -1, "THROW_AWAY"); buffer.PushComponentUpdateInstruction(0, 0, 10); buffer.PrepComponentBufferForFrame(std::vector{}); ASSERT_EQ(buffer.GetImmutableDataLength(), 1); @@ -40,7 +40,7 @@ TEST(ComponentBufferTest, PushComponentUpdateInstructionAddsNewEntryCorrectly) TEST(ComponentBufferTest, PushComponentUpdateInstructionUpdatesExistingEntryCorrectly) { - auto buffer = ComponentBuffer(1, -1); + auto buffer = ComponentBuffer(1, -1, "THROW_AWAY"); buffer.PushComponentUpdateInstruction(0, 0, 10); buffer.PrepComponentBufferForFrame(std::vector{}); buffer.PushComponentUpdateInstruction(0, 0, 10); @@ -51,7 +51,7 @@ TEST(ComponentBufferTest, PushComponentUpdateInstructionUpdatesExistingEntryCorr TEST(ComponentBufferTest, PushComponentUpdateInstructionRemovesEntryCorrectly) { - auto buffer = ComponentBuffer(1, -1); + auto buffer = ComponentBuffer(1, -1, "THROW_AWAY"); buffer.PushComponentUpdateInstruction(0, 0, 10); buffer.PrepComponentBufferForFrame(std::vector{}); buffer.PushComponentUpdateInstruction(0, 0, -1); @@ -61,7 +61,7 @@ TEST(ComponentBufferTest, PushComponentUpdateInstructionRemovesEntryCorrectly) TEST(ComponentBufferTest, ForRangeSupportWorksCorrectly) { - auto buffer = ComponentBuffer(1, -1); + auto buffer = ComponentBuffer(1, -1, "THROW_AWAY"); buffer.PushComponentUpdateInstruction(0, 0, 10); buffer.PushComponentUpdateInstruction(0, 1, 10); buffer.PushComponentUpdateInstruction(0, 2, 10); @@ -75,7 +75,7 @@ TEST(ComponentBufferTest, ForRangeSupportWorksCorrectly) TEST(ComponentBufferTest, ConcurrentAccessWorksCorrectly) { - auto container = ComponentBuffer(2, -1); + auto container = ComponentBuffer(2, -1, "THROW_AWAY"); for (size_t i = 0; i < 2000; i++) { @@ -111,7 +111,7 @@ TEST(ComponentBufferTest, ConcurrentAccessWorksCorrectly) TEST(ComponentBufferTest, CanAccessValidUnderlyingContainer) { - auto container = ComponentBuffer(1, -1); + auto container = ComponentBuffer(1, -1, "THROW_AWAY"); for (size_t i = 0; i < 10; i++) { diff --git a/tests/NovelRT.Tests/Ecs/ComponentCacheTest.cpp b/tests/NovelRT.Tests/Ecs/ComponentCacheTest.cpp index 4c82954b0..f0ca56775 100644 --- a/tests/NovelRT.Tests/Ecs/ComponentCacheTest.cpp +++ b/tests/NovelRT.Tests/Ecs/ComponentCacheTest.cpp @@ -22,12 +22,12 @@ class ComponentCacheTest : public testing::Test TEST_F(ComponentCacheTest, RegisterComponentTypeDoesNotThrow) { - EXPECT_NO_THROW(cache.RegisterComponentType(NAN)); + EXPECT_NO_THROW(cache.RegisterComponentType(NAN, "THROW_AWAY")); } TEST_F(ComponentCacheTest, GetComponentBufferReturnsValidBuffer) { - cache.RegisterComponentType(NAN); + cache.RegisterComponentType(NAN, "THROW_AWAY"); auto buffer = cache.GetComponentBuffer(); buffer.PushComponentUpdateInstruction(0, 0, 10); buffer.PrepComponentBufferForFrame(std::vector{}); @@ -40,7 +40,7 @@ TEST_F(ComponentCacheTest, GetComponentBufferReturnsValidBuffer) TEST_F(ComponentCacheTest, PrepAllBuffersForNextFrameUpdatesEntitiesCorrectly) { - cache.RegisterComponentType(NAN); + cache.RegisterComponentType(NAN, "THROW_AWAY"); auto buffer = cache.GetComponentBuffer(); buffer.PushComponentUpdateInstruction(0, 0, 10); ASSERT_NO_THROW(cache.PrepAllBuffersForNextFrame(std::vector{})); diff --git a/tests/NovelRT.Tests/Ecs/ComponentViewTest.cpp b/tests/NovelRT.Tests/Ecs/ComponentViewTest.cpp index 02c205598..8bb8ce766 100644 --- a/tests/NovelRT.Tests/Ecs/ComponentViewTest.cpp +++ b/tests/NovelRT.Tests/Ecs/ComponentViewTest.cpp @@ -13,12 +13,12 @@ class ComponentViewTest : public testing::Test { public: ComponentView* testView = nullptr; - ComponentBuffer testBuffer = ComponentBuffer(1, -1); + ComponentBuffer testBuffer = ComponentBuffer(1, -1, "THROW_AWAY"); protected: void SetUp() override { - testBuffer = ComponentBuffer(1, -1); + testBuffer = ComponentBuffer(1, -1, "THROW_AWAY"); testView = new ComponentView(0, testBuffer); } diff --git a/tests/NovelRT.Tests/Ecs/ConfiguratorTest.cpp b/tests/NovelRT.Tests/Ecs/ConfiguratorTest.cpp index 80e82bf39..1dc482de0 100644 --- a/tests/NovelRT.Tests/Ecs/ConfiguratorTest.cpp +++ b/tests/NovelRT.Tests/Ecs/ConfiguratorTest.cpp @@ -32,7 +32,8 @@ TEST(ConfiguratorTest, ConfiguratorCanProduceSystemSchedulerWithCustomComponentA } }; - auto scheduler = Configurator().WithSystems({lambda}).InitialiseAndRegisterComponents(-1); + auto scheduler = Configurator().WithSystems({lambda}).InitialiseAndRegisterComponents( + std::make_tuple(-1, "THROW_AWAY")); scheduler.GetComponentCache().GetComponentBuffer().PushComponentUpdateInstruction(0, 1, 10); ASSERT_NO_THROW(scheduler.ExecuteIteration(Timestamp(0))); ASSERT_NO_THROW(scheduler.ExecuteIteration(Timestamp(0))); diff --git a/tests/NovelRT.Tests/Ecs/EntityGraphViewTest.cpp b/tests/NovelRT.Tests/Ecs/EntityGraphViewTest.cpp index 86c3f7d76..9113265f7 100644 --- a/tests/NovelRT.Tests/Ecs/EntityGraphViewTest.cpp +++ b/tests/NovelRT.Tests/Ecs/EntityGraphViewTest.cpp @@ -22,8 +22,8 @@ class EntityGraphViewTest : public testing::Test static NovelRT::AtomFactory& _entityIdFactory = NovelRT::AtomFactoryDatabase::GetFactory("EntityId"); componentCache = ComponentCache(1); - componentCache.RegisterComponentType(LinkedEntityListNodeComponent{false}); - componentCache.RegisterComponentType(EntityGraphComponent{false}); + componentCache.RegisterComponentType(LinkedEntityListNodeComponent{false}, "THROW_AWAY"); + componentCache.RegisterComponentType(EntityGraphComponent{false}, "THROW_AWAY_AGAIN"); parentId = _entityIdFactory.GetNext(); childId = _entityIdFactory.GetNext(); entityCache = EntityCache(1); diff --git a/tests/NovelRT.Tests/Ecs/LinkedEntityListViewTest.cpp b/tests/NovelRT.Tests/Ecs/LinkedEntityListViewTest.cpp index e06e8d98d..c607b2ed4 100644 --- a/tests/NovelRT.Tests/Ecs/LinkedEntityListViewTest.cpp +++ b/tests/NovelRT.Tests/Ecs/LinkedEntityListViewTest.cpp @@ -21,7 +21,7 @@ class LinkedEntityListViewTest : public testing::Test static NovelRT::AtomFactory& _entityIdFactory = NovelRT::AtomFactoryDatabase::GetFactory("EntityId"); componentCache = ComponentCache(1); - componentCache.RegisterComponentType(LinkedEntityListNodeComponent{false}); + componentCache.RegisterComponentType(LinkedEntityListNodeComponent{false}, "THROW_AWAY"); rootListId = _entityIdFactory.GetNext(); componentCache.GetComponentBuffer().PushComponentUpdateInstruction( 0, rootListId, LinkedEntityListNodeComponent()); diff --git a/tests/NovelRT.Tests/Ecs/SystemSchedulerTest.cpp b/tests/NovelRT.Tests/Ecs/SystemSchedulerTest.cpp index fa44ef39b..555cb3825 100644 --- a/tests/NovelRT.Tests/Ecs/SystemSchedulerTest.cpp +++ b/tests/NovelRT.Tests/Ecs/SystemSchedulerTest.cpp @@ -73,7 +73,7 @@ TEST_F(SystemSchedulerTest, IndependentSystemsObtainValidCatalogue) bool isEqual = false; EntityId entity = entityIdFactory.GetNext(); - scheduler->GetComponentCache().RegisterComponentType(-1); + scheduler->GetComponentCache().RegisterComponentType(-1, "THROW_AWAY"); scheduler->GetComponentCache().GetComponentBuffer().PushComponentUpdateInstruction(0, entity, 10); scheduler->ExecuteIteration(Timestamp(0)); scheduler->RegisterSystem([&](Timestamp delta, Catalogue catalogue) { @@ -102,7 +102,7 @@ TEST_F(SystemSchedulerTest, IndependentSystemsCanHandleRemainderWithThreeThreads EntityId entity = entityIdFactory.GetNext(); - scheduler->GetComponentCache().RegisterComponentType(-1); + scheduler->GetComponentCache().RegisterComponentType(-1, "THROW_AWAY"); scheduler->GetComponentCache().GetComponentBuffer().PushComponentUpdateInstruction(0, entity, 10); scheduler->ExecuteIteration(Timestamp(0)); @@ -163,7 +163,7 @@ TEST_F(SystemSchedulerTest, IndependentSystemsCanHandleRemainderWithThirtyTwoThr EntityId entity = entityIdFactory.GetNext(); - scheduler->GetComponentCache().RegisterComponentType(-1); + scheduler->GetComponentCache().RegisterComponentType(-1, "THROW_AWAY"); scheduler->GetComponentCache().GetComponentBuffer().PushComponentUpdateInstruction(0, entity, 10); scheduler->ExecuteIteration(Timestamp(0)); @@ -219,7 +219,7 @@ TEST_F(SystemSchedulerTest, IndependentSystemsCanHandleManySystems) { EntityId entity = entityIdFactory.GetNext(); - scheduler->GetComponentCache().RegisterComponentType(-1); + scheduler->GetComponentCache().RegisterComponentType(-1, "THROW_AWAY"); scheduler->GetComponentCache().GetComponentBuffer().PushComponentUpdateInstruction(0, entity, 10); scheduler->ExecuteIteration(Timestamp(0)); diff --git a/tests/NovelRT.Tests/Interop/Ecs/NrtCatalogueTest.cpp b/tests/NovelRT.Tests/Interop/Ecs/NrtCatalogueTest.cpp index 5c5ef6f3c..72b805e86 100644 --- a/tests/NovelRT.Tests/Interop/Ecs/NrtCatalogueTest.cpp +++ b/tests/NovelRT.Tests/Interop/Ecs/NrtCatalogueTest.cpp @@ -39,7 +39,7 @@ class InteropCatalogueTest : public testing::Test auto intRhs = reinterpret_cast(rhs); *intLhs += *intRhs; }, - nullptr, &intComponentTypeId); + "THROW_AWAY", nullptr, &intComponentTypeId); Nrt_ComponentCache_RegisterComponentTypeUnsafe( componentCache, sizeof(size_t), &sizeTDeleteState, @@ -48,11 +48,11 @@ class InteropCatalogueTest : public testing::Test auto sizeTRhs = reinterpret_cast(rhs); *sizeTLhs += *sizeTRhs; }, - nullptr, &sizeTComponentTypeId); + "THROW_AWAY_AGAIN", nullptr, &sizeTComponentTypeId); Nrt_ComponentCache_RegisterComponentTypeUnsafe( - componentCache, sizeof(char), &charDeleteState, [](auto, auto, auto, auto) {}, nullptr, - &charComponentTypeId); + componentCache, sizeof(char), &charDeleteState, [](auto, auto, auto, auto) {}, "THROW_AWAY_AGAIN_AGAIN", + nullptr, &charComponentTypeId); auto compViewInt = Nrt_Catalogue_GetComponentViewByIdUnsafe(catalogue, intComponentTypeId); auto compViewSizeT = Nrt_Catalogue_GetComponentViewByIdUnsafe(catalogue, sizeTComponentTypeId); diff --git a/tests/NovelRT.Tests/Interop/Ecs/NrtComponentBufferMemoryContainerTest.cpp b/tests/NovelRT.Tests/Interop/Ecs/NrtComponentBufferMemoryContainerTest.cpp index 17dd29af2..9428ca3b4 100644 --- a/tests/NovelRT.Tests/Interop/Ecs/NrtComponentBufferMemoryContainerTest.cpp +++ b/tests/NovelRT.Tests/Interop/Ecs/NrtComponentBufferMemoryContainerTest.cpp @@ -13,7 +13,7 @@ TEST(InteropComponentBufferMemoryContainerTest, GetDeleteInstructionStateReturns { int32_t deleteState = -1; auto container = Nrt_ComponentBufferMemoryContainer_Create( - 1, &deleteState, sizeof(int32_t), [](auto, auto, auto, auto) {}, nullptr); + 1, &deleteState, sizeof(int32_t), [](auto, auto, auto, auto) {}, "THROW_AWAY", nullptr); auto deleteInstructionState = Nrt_ComponentBufferMemoryContainer_GetDeleteInstructionState(container); EXPECT_EQ(std::memcmp(Nrt_ComponentBufferMemoryContainer_ImmutableDataView_GetDataHandle(deleteInstructionState), &deleteState, sizeof(int32_t)), @@ -28,7 +28,7 @@ TEST(InteropComponentBufferMemoryContainerTest, PushComponentUpdateInstructionAd int32_t deleteState = -1; int32_t updateState = 10; auto container = Nrt_ComponentBufferMemoryContainer_Create( - 1, &deleteState, sizeof(int32_t), [](auto, auto, auto, auto) {}, nullptr); + 1, &deleteState, sizeof(int32_t), [](auto, auto, auto, auto) {}, "THROW_AWAY", nullptr); ASSERT_EQ(Nrt_ComponentBufferMemoryContainer_PushComponentUpdateInstruction(container, 0, 0, &updateState), NRT_SUCCESS); @@ -55,7 +55,7 @@ TEST(InteropComponentBufferMemoryContainerTest, PushComponentUpdateInstructionUp [](auto lhs, auto rhs, auto, auto) { *reinterpret_cast(lhs) += *reinterpret_cast(rhs); }, - nullptr); + "THROW_AWAY", nullptr); ASSERT_EQ(Nrt_ComponentBufferMemoryContainer_PushComponentUpdateInstruction(container, 0, 0, &updateState), NRT_SUCCESS); @@ -84,7 +84,7 @@ TEST(InteropComponentBufferMemoryContainerTest, PushComponentUpdateInstructionRe int32_t deleteState = -1; int32_t updateState = 10; auto container = Nrt_ComponentBufferMemoryContainer_Create( - 1, &deleteState, sizeof(int32_t), [](auto, auto, auto, auto) {}, nullptr); + 1, &deleteState, sizeof(int32_t), [](auto, auto, auto, auto) {}, "THROW_AWAY", nullptr); ASSERT_EQ(Nrt_ComponentBufferMemoryContainer_PushComponentUpdateInstruction(container, 0, 0, &updateState), NRT_SUCCESS); @@ -109,7 +109,7 @@ TEST(InteropComponentBufferMemoryContainerTest, IterationWorksCorrectly) int32_t deleteState = -1; int32_t updateState = 10; auto container = Nrt_ComponentBufferMemoryContainer_Create( - 1, &deleteState, sizeof(int32_t), [](auto, auto, auto, auto) {}, nullptr); + 1, &deleteState, sizeof(int32_t), [](auto, auto, auto, auto) {}, "THROW_AWAY", nullptr); ASSERT_EQ(Nrt_ComponentBufferMemoryContainer_PushComponentUpdateInstruction(container, 0, 0, &updateState), NRT_SUCCESS); @@ -155,7 +155,7 @@ TEST(InteropComponentBufferMemoryContainerTest, ConcurrentAccessWorksCorrectly) [](auto lhs, auto rhs, auto, auto) { *reinterpret_cast(lhs) += *reinterpret_cast(rhs); }, - nullptr); + "THROW_AWAY", nullptr); for (int i = 0; i < 2000; ++i) { diff --git a/tests/NovelRT.Tests/Interop/Ecs/NrtComponentCacheTest.cpp b/tests/NovelRT.Tests/Interop/Ecs/NrtComponentCacheTest.cpp index ca4067016..97b41749e 100644 --- a/tests/NovelRT.Tests/Interop/Ecs/NrtComponentCacheTest.cpp +++ b/tests/NovelRT.Tests/Interop/Ecs/NrtComponentCacheTest.cpp @@ -32,7 +32,7 @@ TEST_F(InteropComponentCacheTest, RegisterComponentTypeSucceeds) int32_t deleteState = NAN; NrtComponentTypeId id = 0; EXPECT_EQ(Nrt_ComponentCache_RegisterComponentTypeUnsafe( - cache, sizeof(int32_t), &deleteState, [](auto, auto, auto, auto) {}, nullptr, &id), + cache, sizeof(int32_t), &deleteState, [](auto, auto, auto, auto) {}, "THROW_AWAY", nullptr, &id), NRT_SUCCESS); } @@ -41,7 +41,7 @@ TEST_F(InteropComponentCacheTest, GetComponentBufferByIdReturnsValidBuffer) int32_t deleteState = NAN; NrtComponentTypeId id = 0; ASSERT_EQ(Nrt_ComponentCache_RegisterComponentTypeUnsafe( - cache, sizeof(int32_t), &deleteState, [](auto, auto, auto, auto) {}, nullptr, &id), + cache, sizeof(int32_t), &deleteState, [](auto, auto, auto, auto) {}, "THROW_AWAY", nullptr, &id), NRT_SUCCESS); NrtComponentBufferMemoryContainerHandle buffer = nullptr; diff --git a/tests/NovelRT.Tests/Interop/Ecs/NrtSystemSchedulerTest.cpp b/tests/NovelRT.Tests/Interop/Ecs/NrtSystemSchedulerTest.cpp index cc77e6817..1b97bc623 100644 --- a/tests/NovelRT.Tests/Interop/Ecs/NrtSystemSchedulerTest.cpp +++ b/tests/NovelRT.Tests/Interop/Ecs/NrtSystemSchedulerTest.cpp @@ -76,7 +76,7 @@ TEST_F(InteropSystemSchedulerTest, IndependentSystemsObtainValidCatalogue) EntityId entity = entityIdFactory.GetNext(); auto cache = Nrt_SystemScheduler_GetComponentCache(scheduler); - reinterpret_cast(scheduler)->GetComponentCache().RegisterComponentType(-1); + reinterpret_cast(scheduler)->GetComponentCache().RegisterComponentType(-1, "THROW_AWAY"); NrtComponentBufferMemoryContainerHandle container = nullptr; ASSERT_EQ(Nrt_ComponentCache_GetComponentBufferById(cache, GetComponentTypeId(), &container), NRT_SUCCESS); @@ -126,7 +126,7 @@ TEST_F(InteropSystemSchedulerTest, IndependentSystemsCanHandleRemainderWithThree EntityId entity = entityIdFactory.GetNext(); auto cache = Nrt_SystemScheduler_GetComponentCache(scheduler); - reinterpret_cast(scheduler)->GetComponentCache().RegisterComponentType(-1); + reinterpret_cast(scheduler)->GetComponentCache().RegisterComponentType(-1, "THROW_AWAY"); NrtComponentBufferMemoryContainerHandle container = nullptr; ASSERT_EQ(Nrt_ComponentCache_GetComponentBufferById(cache, GetComponentTypeId(), &container), NRT_SUCCESS); @@ -218,7 +218,7 @@ TEST_F(InteropSystemSchedulerTest, IndependentSystemsCanHandleManySystems) EntityId entity = entityIdFactory.GetNext(); auto cache = Nrt_SystemScheduler_GetComponentCache(scheduler); - reinterpret_cast(scheduler)->GetComponentCache().RegisterComponentType(-1); + reinterpret_cast(scheduler)->GetComponentCache().RegisterComponentType(-1, "THROW_AWAY"); NrtComponentBufferMemoryContainerHandle container = nullptr; ASSERT_EQ(Nrt_ComponentCache_GetComponentBufferById(cache, GetComponentTypeId(), &container), NRT_SUCCESS);