Skip to content

added entity event index param #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/bazel-*
/user.bazelrc
/compile_commands.json
/external
/.cache/
/bazel-*
/user.bazelrc
/compile_commands.json
/external
/.cache/
6 changes: 3 additions & 3 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ http_archive(

http_archive(
name = "ecsact_runtime",
sha256 = "ab8270dfbe7fb6360e3b395fb3ad141a99d18b43bb0f3a897cf04e8a736036b8",
strip_prefix = "ecsact_runtime-94b3c740e69b1bc1d35ec3dd8218e80d6bf8fa00",
url = "https://github.com/ecsact-dev/ecsact_runtime/archive/94b3c740e69b1bc1d35ec3dd8218e80d6bf8fa00.zip",
sha256 = "", # https://github.com/ecsact-dev/ecsact_runtime/pull/139
strip_prefix = "ecsact_runtime-9d243cca4550fe3fa92aa3526466e7933d5d77ae",
url = "https://github.com/ecsact-dev/ecsact_runtime/archive/9d243cca4550fe3fa92aa3526466e7933d5d77ae.zip",
)

load("@rules_ecsact//ecsact:repositories.bzl", "ecsact_register_toolchains", "rules_ecsact_dependencies")
Expand Down
12 changes: 9 additions & 3 deletions ecsact/entt/detail/execution_events_collector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,24 @@ struct execution_events_collector {
);
}

void invoke_entity_created_callback(ecsact_entity_id entity) {
void invoke_entity_created_callback(
ecsact_entity_id entity,
ecsact_placeholder_entity_id placeholder_entity_id
) {
target->entity_created_callback(
ECSACT_EVENT_CREATE_ENTITY,
static_cast<ecsact_entity_id>(entity),
entity,
placeholder_entity_id,
target->entity_created_callback_user_data
);
}

void invoke_entity_destroyed_callback(ecsact_entity_id entity) {
target->entity_destroyed_callback(
ECSACT_EVENT_DESTROY_ENTITY,
static_cast<ecsact_entity_id>(entity),
entity,
// This value doesn't matter for the destroy callback
static_cast<ecsact_placeholder_entity_id>(entity),
target->entity_destroyed_callback_user_data
);
}
Expand Down
5 changes: 4 additions & 1 deletion ecsact/entt/detail/internal_markers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstdint>
#include <type_traits>
#include <concepts>
#include "ecsact/runtime/common.h"

namespace ecsact::entt::detail {

Expand Down Expand Up @@ -56,7 +57,9 @@ struct pending_add<C> {
template<typename C>
struct pending_remove {};

struct created_entity {};
struct created_entity {
ecsact_placeholder_entity_id placeholder_entity_id;
};

struct destroyed_entity {};

Expand Down
8 changes: 6 additions & 2 deletions ecsact/entt/runtime.hh
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,8 @@ private:

for(entt_entity_type entity : created_view) {
events_collector.invoke_entity_created_callback(
info.get_ecsact_entity_id(entity)
info.get_ecsact_entity_id(entity),
created_view.template get<created_entity>(entity).placeholder_entity_id
);
}
}
Expand Down Expand Up @@ -1100,7 +1101,10 @@ private:

for(int i = 0; options.create_entities_length > i; i++) {
auto entity = info.create_entity().entt_entity_id;
info.registry.template emplace<created_entity>(entity);
info.registry.template emplace<created_entity>(
entity,
options.create_entities[i]
);

for(int j = 0; options.create_entities_components_length[i] > j; j++) {
const ecsact_component& comp = options.create_entities_components[i][j];
Expand Down
22 changes: 17 additions & 5 deletions runtime/test/runtime_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -729,15 +729,20 @@ TEST(Core, CreateAndDestroyEntity) {

pointer_vector.push_back(entity_component.data());

auto create_entities =
std::array{static_cast<ecsact_placeholder_entity_id>(42)};

options.create_entities = create_entities.data();
options.create_entities_components = pointer_vector.data();
options.create_entities_components_length = entity_component_length.data();
options.create_entities_length = entity_component_length.size();

auto evc = ecsact_execution_events_collector{};

struct callback_info {
ecsact_entity_id entity_id;
bool entity_created = false;
ecsact_entity_id entity_id;
bool entity_created = false;
ecsact_placeholder_entity_id placeholder_entity_id;
};

auto info = callback_info{};
Expand All @@ -746,13 +751,15 @@ TEST(Core, CreateAndDestroyEntity) {

auto entity_created_callback = //
[](
ecsact_event event,
ecsact_entity_id entity_id,
void* callback_user_data
ecsact_event event,
ecsact_entity_id entity_id,
ecsact_placeholder_entity_id placeholder_entity_id,
void* callback_user_data
) {
auto& info = *static_cast<callback_info*>(callback_user_data);
info.entity_created = true;
info.entity_id = entity_id;
info.placeholder_entity_id = placeholder_entity_id;
};

evc.entity_created_callback = entity_created_callback;
Expand All @@ -761,6 +768,11 @@ TEST(Core, CreateAndDestroyEntity) {

ASSERT_EQ(ecsact_count_entities(reg.id()), 1);

EXPECT_EQ(
info.placeholder_entity_id,
static_cast<ecsact_placeholder_entity_id>(42)
);

auto comp = reg.get_component<runtime_test::EntityTesting>(info.entity_id);

ASSERT_EQ(comp.a, 6);
Expand Down