Skip to content

Commit 6fecd48

Browse files
authored
added entity event index param (#38)
1 parent 2b86a8c commit 6fecd48

File tree

6 files changed

+44
-19
lines changed

6 files changed

+44
-19
lines changed

.gitignore

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/bazel-*
2-
/user.bazelrc
3-
/compile_commands.json
4-
/external
5-
/.cache/
1+
/bazel-*
2+
/user.bazelrc
3+
/compile_commands.json
4+
/external
5+
/.cache/

WORKSPACE.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ http_archive(
2525

2626
http_archive(
2727
name = "ecsact_runtime",
28-
sha256 = "ab8270dfbe7fb6360e3b395fb3ad141a99d18b43bb0f3a897cf04e8a736036b8",
29-
strip_prefix = "ecsact_runtime-94b3c740e69b1bc1d35ec3dd8218e80d6bf8fa00",
30-
url = "https://github.com/ecsact-dev/ecsact_runtime/archive/94b3c740e69b1bc1d35ec3dd8218e80d6bf8fa00.zip",
28+
sha256 = "", # https://github.com/ecsact-dev/ecsact_runtime/pull/139
29+
strip_prefix = "ecsact_runtime-9d243cca4550fe3fa92aa3526466e7933d5d77ae",
30+
url = "https://github.com/ecsact-dev/ecsact_runtime/archive/9d243cca4550fe3fa92aa3526466e7933d5d77ae.zip",
3131
)
3232

3333
load("@rules_ecsact//ecsact:repositories.bzl", "ecsact_register_toolchains", "rules_ecsact_dependencies")

ecsact/entt/detail/execution_events_collector.hh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,24 @@ struct execution_events_collector {
100100
);
101101
}
102102

103-
void invoke_entity_created_callback(ecsact_entity_id entity) {
103+
void invoke_entity_created_callback(
104+
ecsact_entity_id entity,
105+
ecsact_placeholder_entity_id placeholder_entity_id
106+
) {
104107
target->entity_created_callback(
105108
ECSACT_EVENT_CREATE_ENTITY,
106-
static_cast<ecsact_entity_id>(entity),
109+
entity,
110+
placeholder_entity_id,
107111
target->entity_created_callback_user_data
108112
);
109113
}
110114

111115
void invoke_entity_destroyed_callback(ecsact_entity_id entity) {
112116
target->entity_destroyed_callback(
113117
ECSACT_EVENT_DESTROY_ENTITY,
114-
static_cast<ecsact_entity_id>(entity),
118+
entity,
119+
// This value doesn't matter for the destroy callback
120+
static_cast<ecsact_placeholder_entity_id>(entity),
115121
target->entity_destroyed_callback_user_data
116122
);
117123
}

ecsact/entt/detail/internal_markers.hh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <cstdint>
44
#include <type_traits>
55
#include <concepts>
6+
#include "ecsact/runtime/common.h"
67

78
namespace ecsact::entt::detail {
89

@@ -56,7 +57,9 @@ struct pending_add<C> {
5657
template<typename C>
5758
struct pending_remove {};
5859

59-
struct created_entity {};
60+
struct created_entity {
61+
ecsact_placeholder_entity_id placeholder_entity_id;
62+
};
6063

6164
struct destroyed_entity {};
6265

ecsact/entt/runtime.hh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,8 @@ private:
941941

942942
for(entt_entity_type entity : created_view) {
943943
events_collector.invoke_entity_created_callback(
944-
info.get_ecsact_entity_id(entity)
944+
info.get_ecsact_entity_id(entity),
945+
created_view.template get<created_entity>(entity).placeholder_entity_id
945946
);
946947
}
947948
}
@@ -1100,7 +1101,10 @@ private:
11001101

11011102
for(int i = 0; options.create_entities_length > i; i++) {
11021103
auto entity = info.create_entity().entt_entity_id;
1103-
info.registry.template emplace<created_entity>(entity);
1104+
info.registry.template emplace<created_entity>(
1105+
entity,
1106+
options.create_entities[i]
1107+
);
11041108

11051109
for(int j = 0; options.create_entities_components_length[i] > j; j++) {
11061110
const ecsact_component& comp = options.create_entities_components[i][j];

runtime/test/runtime_test.cc

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -729,15 +729,20 @@ TEST(Core, CreateAndDestroyEntity) {
729729

730730
pointer_vector.push_back(entity_component.data());
731731

732+
auto create_entities =
733+
std::array{static_cast<ecsact_placeholder_entity_id>(42)};
734+
735+
options.create_entities = create_entities.data();
732736
options.create_entities_components = pointer_vector.data();
733737
options.create_entities_components_length = entity_component_length.data();
734738
options.create_entities_length = entity_component_length.size();
735739

736740
auto evc = ecsact_execution_events_collector{};
737741

738742
struct callback_info {
739-
ecsact_entity_id entity_id;
740-
bool entity_created = false;
743+
ecsact_entity_id entity_id;
744+
bool entity_created = false;
745+
ecsact_placeholder_entity_id placeholder_entity_id;
741746
};
742747

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

747752
auto entity_created_callback = //
748753
[](
749-
ecsact_event event,
750-
ecsact_entity_id entity_id,
751-
void* callback_user_data
754+
ecsact_event event,
755+
ecsact_entity_id entity_id,
756+
ecsact_placeholder_entity_id placeholder_entity_id,
757+
void* callback_user_data
752758
) {
753759
auto& info = *static_cast<callback_info*>(callback_user_data);
754760
info.entity_created = true;
755761
info.entity_id = entity_id;
762+
info.placeholder_entity_id = placeholder_entity_id;
756763
};
757764

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

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

771+
EXPECT_EQ(
772+
info.placeholder_entity_id,
773+
static_cast<ecsact_placeholder_entity_id>(42)
774+
);
775+
764776
auto comp = reg.get_component<runtime_test::EntityTesting>(info.entity_id);
765777

766778
ASSERT_EQ(comp.a, 6);

0 commit comments

Comments
 (0)