Skip to content

Commit

Permalink
refactor(core): change param given in blueprint::merge and command::s…
Browse files Browse the repository at this point in the history
…pawn
  • Loading branch information
diogomsmiranda committed Feb 11, 2024
1 parent ac67407 commit 74cd2f6
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 15 deletions.
5 changes: 2 additions & 3 deletions core/include/cubos/core/ecs/blueprint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion core/include/cubos/core/ecs/command_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, Entity> spawn(const Blueprint& blueprint, bool withName);
std::unordered_map<std::string, Entity> spawn(const Blueprint& blueprint);

/// @brief Adds a component to an entity.
/// @param entity Entity identifier.
Expand Down
2 changes: 1 addition & 1 deletion core/include/cubos/core/ecs/system/arguments/commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions core/src/ecs/blueprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions core/src/ecs/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void CommandBuffer::destroy(Entity entity)
mCommands.emplace_back([entity](World& world) { world.destroy(entity); });
}

std::unordered_map<std::string, Entity> CommandBuffer::spawn(const Blueprint& blueprint, bool withName)
std::unordered_map<std::string, Entity> CommandBuffer::spawn(const Blueprint& blueprint)
{
std::unordered_map<std::string, Entity> nameToEntity{};

Expand All @@ -42,7 +42,7 @@ std::unordered_map<std::string, Entity> CommandBuffer::spawn(const Blueprint& bl
[&](Entity fromEntity, Entity toEntity, memory::AnyValue relation) {
this->relate(fromEntity, toEntity, relation.type(), relation.get());
},
withName);
true);

return nameToEntity;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/ecs/name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
CUBOS_REFLECT_IMPL(cubos::core::ecs::Name)
{
return core::ecs::TypeBuilder<Name>("cubos::core::ecs::Name").withField("name", &Name::value).build();
}
}
4 changes: 2 additions & 2 deletions core/src/ecs/system/arguments/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)};
}

Expand Down
2 changes: 2 additions & 0 deletions core/tests/ecs/blueprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ TEST_CASE("ecs::Blueprint")
REQUIRE(components1.has<IntegerComponent>());
REQUIRE(components0.has<Name>());
REQUIRE(components1.has<Name>());
CHECK(components0.get<Name>().value == "0");
CHECK(components1.get<Name>().value == "1");
CHECK(components0.get<IntegerComponent>().value == 0);
CHECK(components1.get<IntegerComponent>().value == 1);
}
Expand Down
2 changes: 1 addition & 1 deletion engine/samples/scene/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion engine/src/scene/bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tools/tesseratos/src/tesseratos/scene_editor/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static void openScene(const Asset<Scene>& 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);
Expand Down

0 comments on commit 74cd2f6

Please sign in to comment.