From 74cd2f6c5f5329102a1e9dd333cc544b7e69c027 Mon Sep 17 00:00:00 2001 From: Diogo Miranda Date: Sun, 11 Feb 2024 15:59:55 +0000 Subject: [PATCH] refactor(core): change param given in blueprint::merge and command::spawn --- core/include/cubos/core/ecs/blueprint.hpp | 5 ++--- core/include/cubos/core/ecs/command_buffer.hpp | 2 +- core/include/cubos/core/ecs/system/arguments/commands.hpp | 2 +- core/src/ecs/blueprint.cpp | 4 ++-- core/src/ecs/command_buffer.cpp | 4 ++-- core/src/ecs/name.cpp | 2 +- core/src/ecs/system/arguments/commands.cpp | 4 ++-- core/tests/ecs/blueprint.cpp | 2 ++ engine/samples/scene/main.cpp | 2 +- engine/src/scene/bridge.cpp | 2 +- tools/tesseratos/src/tesseratos/scene_editor/plugin.cpp | 2 +- 11 files changed, 16 insertions(+), 15 deletions(-) diff --git a/core/include/cubos/core/ecs/blueprint.hpp b/core/include/cubos/core/ecs/blueprint.hpp index 415128e849..97b44171f8 100644 --- a/core/include/cubos/core/ecs/blueprint.hpp +++ b/core/include/cubos/core/ecs/blueprint.hpp @@ -99,8 +99,7 @@ namespace cubos::core::ecs /// /// @param prefix Name to prefix with the merged blueprint. /// @param other Blueprint to merge. - /// @param withName Whether to use the entity names from the other blueprint. - void merge(const std::string& prefix, const Blueprint& other, bool withName); + void merge(const std::string& prefix, const Blueprint& other); /// @brief Clears the blueprint. void clear(); @@ -114,7 +113,7 @@ namespace cubos::core::ecs /// @param create Function used to create entities. /// @param add Function used to add components to entities. /// @param relate Function used to add relations to entities. - /// @param withName Whether to use the entity names from the blueprint. + /// @param withName Whether to add the 'Name' component to instantiated entities. void instantiate(void* userData, Create create, Add add, Relate relate, bool withName) const; /// @brief Instantiates the blueprint by calling the given functors. diff --git a/core/include/cubos/core/ecs/command_buffer.hpp b/core/include/cubos/core/ecs/command_buffer.hpp index e6136c366c..c55a73fffd 100644 --- a/core/include/cubos/core/ecs/command_buffer.hpp +++ b/core/include/cubos/core/ecs/command_buffer.hpp @@ -42,7 +42,7 @@ namespace cubos::core::ecs /// @param blueprint Blueprint to spawn. /// @param withName Whether to use the entity names from the blueprint. /// @return Map of entity names to their identifiers. - std::unordered_map spawn(const Blueprint& blueprint, bool withName); + std::unordered_map spawn(const Blueprint& blueprint); /// @brief Adds a component to an entity. /// @param entity Entity identifier. diff --git a/core/include/cubos/core/ecs/system/arguments/commands.hpp b/core/include/cubos/core/ecs/system/arguments/commands.hpp index 63d6c4a5e2..3bf07ea4fd 100644 --- a/core/include/cubos/core/ecs/system/arguments/commands.hpp +++ b/core/include/cubos/core/ecs/system/arguments/commands.hpp @@ -48,7 +48,7 @@ namespace cubos::core::ecs /// @param blueprint Blueprint to spawn. /// @param withName Whether to use the entity names from the blueprint. /// @return Blueprint builder. - BlueprintBuilder spawn(const Blueprint& blueprint, bool withName); + BlueprintBuilder spawn(const Blueprint& blueprint); /// @brief Adds a component to an entity. /// @param entity Entity identifier. diff --git a/core/src/ecs/blueprint.cpp b/core/src/ecs/blueprint.cpp index 8e5399a402..d4a38be767 100644 --- a/core/src/ecs/blueprint.cpp +++ b/core/src/ecs/blueprint.cpp @@ -78,7 +78,7 @@ void Blueprint::relate(Entity fromEntity, Entity toEntity, AnyValue relation) mRelations.at(relation.type())[fromEntity].insert_or_assign(toEntity, std::move(relation)); } -void Blueprint::merge(const std::string& prefix, const Blueprint& other, bool withName) +void Blueprint::merge(const std::string& prefix, const Blueprint& other) { other.instantiate( [&](std::string name) -> Entity { @@ -95,7 +95,7 @@ void Blueprint::merge(const std::string& prefix, const Blueprint& other, bool wi [&](Entity fromEntity, Entity toEntity, AnyValue relation) { this->relate(fromEntity, toEntity, std::move(relation)); }, - withName); + false); } void Blueprint::clear() diff --git a/core/src/ecs/command_buffer.cpp b/core/src/ecs/command_buffer.cpp index 02bc9762e4..592ffbac70 100644 --- a/core/src/ecs/command_buffer.cpp +++ b/core/src/ecs/command_buffer.cpp @@ -28,7 +28,7 @@ void CommandBuffer::destroy(Entity entity) mCommands.emplace_back([entity](World& world) { world.destroy(entity); }); } -std::unordered_map CommandBuffer::spawn(const Blueprint& blueprint, bool withName) +std::unordered_map CommandBuffer::spawn(const Blueprint& blueprint) { std::unordered_map nameToEntity{}; @@ -42,7 +42,7 @@ std::unordered_map CommandBuffer::spawn(const Blueprint& bl [&](Entity fromEntity, Entity toEntity, memory::AnyValue relation) { this->relate(fromEntity, toEntity, relation.type(), relation.get()); }, - withName); + true); return nameToEntity; } diff --git a/core/src/ecs/name.cpp b/core/src/ecs/name.cpp index 91f959ecad..bd77897952 100644 --- a/core/src/ecs/name.cpp +++ b/core/src/ecs/name.cpp @@ -5,4 +5,4 @@ CUBOS_REFLECT_IMPL(cubos::core::ecs::Name) { return core::ecs::TypeBuilder("cubos::core::ecs::Name").withField("name", &Name::value).build(); -} \ No newline at end of file +} diff --git a/core/src/ecs/system/arguments/commands.cpp b/core/src/ecs/system/arguments/commands.cpp index a6f06da3a8..4e631eadc7 100644 --- a/core/src/ecs/system/arguments/commands.cpp +++ b/core/src/ecs/system/arguments/commands.cpp @@ -22,9 +22,9 @@ void Commands::destroy(Entity entity) mBuffer.destroy(entity); } -Commands::BlueprintBuilder Commands::spawn(const Blueprint& blueprint, bool withName) +Commands::BlueprintBuilder Commands::spawn(const Blueprint& blueprint) { - auto nameToEntity = mBuffer.spawn(blueprint, withName); + auto nameToEntity = mBuffer.spawn(blueprint); return {mBuffer, std::move(nameToEntity)}; } diff --git a/core/tests/ecs/blueprint.cpp b/core/tests/ecs/blueprint.cpp index 8f744d1919..c56bcced6b 100644 --- a/core/tests/ecs/blueprint.cpp +++ b/core/tests/ecs/blueprint.cpp @@ -206,6 +206,8 @@ TEST_CASE("ecs::Blueprint") REQUIRE(components1.has()); REQUIRE(components0.has()); REQUIRE(components1.has()); + CHECK(components0.get().value == "0"); + CHECK(components1.get().value == "1"); CHECK(components0.get().value == 0); CHECK(components1.get().value == 1); } diff --git a/engine/samples/scene/main.cpp b/engine/samples/scene/main.cpp index ae25dc2d8c..b45615181f 100644 --- a/engine/samples/scene/main.cpp +++ b/engine/samples/scene/main.cpp @@ -60,7 +60,7 @@ int main(int argc, char** argv) .tagged("cubos.assets") .call([](Commands commands, const Assets& assets) { auto sceneRead = assets.read(SceneAsset); - commands.spawn(sceneRead->blueprint, true); + commands.spawn(sceneRead->blueprint); }); /// [Spawning the scene] diff --git a/engine/src/scene/bridge.cpp b/engine/src/scene/bridge.cpp index 36e89bf4cb..3dfdd46a5e 100644 --- a/engine/src/scene/bridge.cpp +++ b/engine/src/scene/bridge.cpp @@ -100,7 +100,7 @@ bool SceneBridge::loadFromFile(Assets& assets, const AnyAsset& handle, Stream& s for (const auto& [name, asset] : scene.imports) { - scene.blueprint.merge(name, assets.read(asset)->blueprint, true); + scene.blueprint.merge(name, assets.read(asset)->blueprint); } } diff --git a/tools/tesseratos/src/tesseratos/scene_editor/plugin.cpp b/tools/tesseratos/src/tesseratos/scene_editor/plugin.cpp index b672c39a37..88b4ec6c4b 100644 --- a/tools/tesseratos/src/tesseratos/scene_editor/plugin.cpp +++ b/tools/tesseratos/src/tesseratos/scene_editor/plugin.cpp @@ -85,7 +85,7 @@ static void openScene(const Asset& sceneToSpawn, Commands& commands, cons { closeScene(commands, scene); auto sceneRead = assets.read(sceneToSpawn); - auto builder = commands.spawn(sceneRead->blueprint, true); + auto builder = commands.spawn(sceneRead->blueprint); for (const auto& [entity, name] : sceneRead->blueprint.bimap()) { placeEntity(name, builder.entity(name), scene);