Skip to content

feat: new assoc api placeholder #139

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 1 commit into from
Jul 2, 2024
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
8 changes: 4 additions & 4 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ module(
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "bazel_skylib", version = "1.6.1")
bazel_dep(name = "rules_ecsact", version = "0.5.2")
bazel_dep(name = "ecsact_runtime", version = "0.6.2")
bazel_dep(name = "ecsact_lang_cpp", version = "0.4.1")
bazel_dep(name = "ecsact_runtime", version = "0.6.7")
bazel_dep(name = "ecsact_lang_cpp", version = "0.4.5")
bazel_dep(name = "boost.mp11", version = "1.83.0.bzl.1")
bazel_dep(name = "entt", version = "3.12.2")
bazel_dep(name = "ecsact_codegen", version = "0.2.0")
bazel_dep(name = "ecsact_cli", version = "0.3.9")
bazel_dep(name = "ecsact_codegen", version = "0.3.1")
bazel_dep(name = "ecsact_cli", version = "0.3.12")
bazel_dep(name = "xxhash", version = "0.8.2")
bazel_dep(name = "googletest", version = "1.14.0.bcr.1")

Expand Down
22 changes: 0 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,3 @@ entt::basic_view<entt::entity, entt::get_t<example::Health>, entt::exclude_t<exa
// EnTT view for StopHealing
entt::basic_view<entt::entity, entt::get_t<example::Health, example::Healing>, entt::exclude_t<>>
```

As soon as system association occurs there now requires multiple views to be iterated at the same time.

```ecsact
package example;
component Health { f32 value; }
component Attacking { entity target; }
action Attack {
entity target;
adds Attacking;
}
system AttackDamage {
readonly Attacking with target {
readwrite Health;
}
}
```

```cpp
entt::basic_view<entt::entity, entt:get_t<example::Attacking>, entt::exclude_t<>>
entt::basic_view<entt::entity, entt:get_t<example::Health, ecsact::entt::association<example::Attacking, 0/*target*/>>, entt::exclude_t<>>
```
70 changes: 0 additions & 70 deletions ecsact/entt/detail/globals.hh
Original file line number Diff line number Diff line change
Expand Up @@ -91,76 +91,6 @@ extern const std::unordered_map< //
decltype(&ecsact_has_component)>
has_component_fns;

/**
* ecsact_system_execution_context_get fn pointers
*
* NOTE: This gets is filled in by ecsact_rt_entt_codegen
*/
extern const std::unordered_map< //
ecsact_system_like_id,
std::unordered_map<
ecsact::entt::assoc_index,
std::unordered_map< //
ecsact_component_like_id,
decltype(&ecsact_system_execution_context_get)>>>
exec_ctx_get_fns;

/**
* ecsact_system_execution_context_add fn pointers
*
* NOTE: This adds is filled in by ecsact_rt_entt_codegen
*/
extern const std::unordered_map< //
ecsact_system_like_id,
std::unordered_map<
ecsact::entt::assoc_index,
std::unordered_map< //
ecsact_component_like_id,
decltype(&ecsact_system_execution_context_add)>>>
exec_ctx_add_fns;

/**
* ecsact_system_execution_context_update fn pointers
*
* NOTE: This updates is filled in by ecsact_rt_entt_codegen
*/
extern const std::unordered_map< //
ecsact_system_like_id,
std::unordered_map<
ecsact::entt::assoc_index,
std::unordered_map< //
ecsact_component_like_id,
decltype(&ecsact_system_execution_context_update)>>>
exec_ctx_update_fns;

/**
* ecsact_system_execution_context_remove fn pointers
*
* NOTE: This removes is filled in by ecsact_rt_entt_codegen
*/
extern const std::unordered_map< //
ecsact_system_like_id,
std::unordered_map<
ecsact::entt::assoc_index,
std::unordered_map< //
ecsact_component_like_id,
decltype(&ecsact_system_execution_context_remove)>>>
exec_ctx_remove_fns;

/**
* ecsact_system_execution_context_has fn pointers
*
* NOTE: This has is filled in by ecsact_rt_entt_codegen
*/
extern const std::unordered_map< //
ecsact_system_like_id,
std::unordered_map<
ecsact::entt::assoc_index,
std::unordered_map< //
ecsact_component_like_id,
decltype(&ecsact_system_execution_context_has)>>>
exec_ctx_has_fns;

/**
* ecsact_system_execution_context_action fn pointers
*
Expand Down
14 changes: 0 additions & 14 deletions ecsact/entt/detail/internal_markers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,6 @@

namespace ecsact::entt::detail {

template<typename C, std::size_t FieldOffset>
struct association {
using component = C;
static constexpr auto field_offset = FieldOffset;
std::int_fast16_t ref_count = 0;
};

template<typename Assoc>
concept association_concept = //
requires {
{ typename Assoc::component_type{} };
{ Assoc::field_offset } -> std::convertible_to<std::size_t>;
};

template<typename C>
struct beforeremove_storage;

Expand Down
20 changes: 1 addition & 19 deletions ecsact/entt/detail/system_execution_context.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,6 @@
#include "ecsact/entt/entity.hh"
#include "ecsact/entt/detail/registry.hh"

namespace ecsact::entt {
/**
* Opaque index representing a system-likes association where `0` means no
* association.
*/
enum class assoc_index : unsigned;

constexpr auto empty_assoc_index(assoc_index n) -> bool {
return n == assoc_index{};
}

constexpr auto underlying_assoc_index(assoc_index n) -> unsigned {
assert(!empty_assoc_index(n));
return static_cast<unsigned>(n);
}

} // namespace ecsact::entt

struct ecsact_system_execution_context {
ecsact_system_like_id id;
ecsact::entt::entity_id entity;
Expand Down Expand Up @@ -81,6 +63,6 @@ struct ecsact_system_execution_context {
virtual auto parent() -> const ecsact_system_execution_context* = 0;

virtual auto other( //
ecsact_entity_id entity
ecsact_system_assoc_id assoc_id
) -> ecsact_system_execution_context* = 0;
};
18 changes: 12 additions & 6 deletions ecsact/entt/wrapper/core.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ template<typename C>
inline auto has_component( //
ecsact_registry_id registry_id,
ecsact_entity_id entity_id,
[[maybe_unused]] ecsact_component_id component_id
[[maybe_unused]] ecsact_component_id component_id,
...
) -> bool {
auto& reg = ecsact::entt::get_registry(registry_id);
auto entity = ecsact::entt::entity_id{entity_id};
Expand All @@ -28,7 +29,8 @@ template<typename C>
inline auto get_component(
ecsact_registry_id registry_id,
ecsact_entity_id entity_id,
[[maybe_unused]] ecsact_component_id component_id
[[maybe_unused]] ecsact_component_id component_id,
...
) -> const void* {
auto& reg = ecsact::entt::get_registry(registry_id);
auto entity = ecsact::entt::entity_id{entity_id};
Expand Down Expand Up @@ -116,7 +118,8 @@ inline auto update_component( //
ecsact_registry_id registry_id,
ecsact_entity_id entity_id,
[[maybe_unused]] ecsact_component_id component_id,
const void* component_data
const void* component_data,
...
) -> ecsact_update_error {
using ecsact::entt::detail::exec_beforechange_storage;

Expand Down Expand Up @@ -148,7 +151,8 @@ inline auto update_component_exec_options( //
ecsact_registry_id registry_id,
ecsact_entity_id entity_id,
[[maybe_unused]] ecsact_component_id component_id,
const void* component_data
const void* component_data,
...
) -> ecsact_update_error {
using ecsact::entt::detail::exec_beforechange_storage;

Expand Down Expand Up @@ -184,7 +188,8 @@ template<typename C>
auto remove_component(
ecsact_registry_id registry_id,
ecsact_entity_id entity_id,
[[maybe_unused]] ecsact_component_id component_id
[[maybe_unused]] ecsact_component_id component_id,
...
) -> void {
auto& reg = ecsact::entt::get_registry(registry_id);
auto entity = ecsact::entt::entity_id{entity_id};
Expand All @@ -203,7 +208,8 @@ template<typename C>
auto remove_component_exec_options(
ecsact_registry_id registry_id,
ecsact_entity_id entity_id,
[[maybe_unused]] ecsact_component_id component_id
[[maybe_unused]] ecsact_component_id component_id,
...
) -> void {
using ecsact::entt::detail::pending_remove;

Expand Down
9 changes: 6 additions & 3 deletions ecsact/entt/wrapper/dynamic.hh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ template<typename C>
auto context_remove(
ecsact_system_execution_context* context,
[[maybe_unused]] ecsact_component_like_id component_id,
auto& view
auto& view,
...
) -> void {
assert(ecsact_id_cast<ecsact_component_like_id>(C::id) == component_id);

Expand Down Expand Up @@ -125,7 +126,8 @@ auto context_get(
ecsact_system_execution_context* context,
[[maybe_unused]] ecsact_component_like_id component_id,
void* out_component_data,
auto& view
auto& view,
...
) -> void {
auto entity = context->entity;

Expand Down Expand Up @@ -158,7 +160,8 @@ auto context_update(
template<typename C>
auto context_has(
ecsact_system_execution_context* context,
[[maybe_unused]] ecsact_component_like_id component_id
[[maybe_unused]] ecsact_component_like_id component_id,
...
) -> bool {
auto entity = context->entity;
auto& registry = *context->registry;
Expand Down
27 changes: 11 additions & 16 deletions rt_entt_codegen/core/print_sys_exec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static auto print_sys_exec_ctx_action(
});

if(result == system_providers.end()) {
throw std::logic_error("print context action was not handled by providers");
ctx.fatal("INTERNAL: print context action was not handled by providers");
}
}

Expand All @@ -83,7 +83,7 @@ static auto print_sys_exec_ctx_add(
});

if(result == system_providers.end()) {
throw std::logic_error("print context add was not handled by providers");
ctx.fatal("INTERNAL: print context add was not handled by providers");
}
}

Expand All @@ -103,7 +103,7 @@ static auto print_sys_exec_ctx_remove(
});

if(result == system_providers.end()) {
throw std::logic_error("print context remove was not handled by providers");
ctx.fatal("INTERNAL: print context remove was not handled by providers");
}
}

Expand All @@ -124,7 +124,7 @@ static auto print_sys_exec_ctx_get(
});

if(result == system_providers.end()) {
throw std::logic_error("print context get was not handled by providers");
ctx.fatal("INTERNAL: print context get was not handled by providers");
}
}

Expand All @@ -145,7 +145,7 @@ static auto print_sys_exec_ctx_update(
});

if(result == system_providers.end()) {
throw std::logic_error("print context update was not handled by providers");
ctx.fatal("INTERNAL: print context update was not handled by providers");
}
}

Expand All @@ -165,7 +165,7 @@ static auto print_sys_exec_ctx_has(
});

if(result == system_providers.end()) {
throw std::logic_error("print context has was not handled by providers");
ctx.fatal("INTERNAL: print context has was not handled by providers");
}
}

Expand All @@ -187,8 +187,7 @@ static auto print_sys_exec_ctx_generate(
});

if(result == system_providers.end()) {
throw std::logic_error("print context generate was not handled by providers"
);
ctx.fatal("INTERNAL: print context generate was not handled by providers");
}
}

Expand All @@ -207,7 +206,7 @@ static auto print_sys_exec_ctx_parent( //
});

if(result == system_providers.end()) {
throw std::logic_error("print context parent was not handled by providers");
ctx.fatal("INTERNAL: print context parent was not handled by providers");
}
}

Expand All @@ -218,7 +217,7 @@ auto print_sys_exec_ctx_other(
) -> void {
auto printer = //
method_printer{ctx, "other"}
.parameter("ecsact_entity_id", "entity")
.parameter("ecsact_system_assoc_id", "assoc_id")
.return_type("ecsact_system_execution_context* final");

auto result = std::ranges::find_if(system_providers, [&](auto provider) {
Expand All @@ -227,7 +226,7 @@ auto print_sys_exec_ctx_other(
});

if(result == system_providers.end()) {
throw std::logic_error("print context other was not handled by providers");
ctx.fatal("INTERNAL: print context other was not handled by providers");
}
}

Expand Down Expand Up @@ -353,10 +352,6 @@ static auto setup_system_providers(system_like_id_variant sys_like_id
system_providers.push_back(std::make_shared<lazy>(sys_like_id));
}

if(!sys_details.association_details.empty()) {
system_providers.push_back(std::make_shared<association>(sys_like_id));
}

if(can_entities_parallel(sys_like_id)) {
system_providers.push_back(std::make_shared<parallel>(sys_like_id));
}
Expand Down Expand Up @@ -443,7 +438,7 @@ static auto print_execute_systems(
});

if(result == system_providers.end()) {
throw std::logic_error("system_impl was not handled by providers");
ctx.fatal("INTERNAL: system_impl was not handled by providers");
}
}

Expand Down
Loading