Skip to content

feat: use new assoc api #130

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

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ root = true
[*]
end_of_line = lf
insert_final_newline = true
indent_size = 4

36 changes: 25 additions & 11 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,35 @@ 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.6")
bazel_dep(name = "ecsact_lang_cpp", version = "0.4.4")
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_cli", version = "0.3.11")
bazel_dep(name = "xxhash", version = "0.8.2")
bazel_dep(name = "googletest", version = "1.14.0.bcr.1")

# local_path_override(
# module_name = "ecsact_lang_cpp",
# path = "../ecsact_lang_cpp",
# )

git_override(
module_name = "ecsact_lang_cpp",
remote = "[email protected]:ecsact-dev/ecsact_lang_cpp.git",
commit = "1add2a6144776659b4f69f3b4132eefb0cb07a50",
)

# local_path_override(
# module_name = "ecsact_runtime",
# path = "../ecsact_runtime",
# )

git_override(
module_name = "ecsact_runtime",
remote = "[email protected]:ecsact-dev/ecsact_runtime.git",
commit = "bb28aff1a1fbf214a0740f94ffddc35bf3f09043",
)

bazel_dep(name = "toolchains_llvm", version = "1.0.0", dev_dependency = True)
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
Expand All @@ -24,13 +45,6 @@ git_override(
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
)

# TODO: https://github.com/bazelbuild/bazel-central-registry/pull/1916
git_override(
module_name = "libarchive",
commit = "7c331f92acea5243c195cdc6fb46ecfa11ce1ce2",
remote = "https://github.com/zaucy/libarchive.git",
)

llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm", dev_dependency = True)
llvm.toolchain(llvm_version = "17.0.6")
use_repo(llvm, "llvm_toolchain")
Expand Down
10 changes: 6 additions & 4 deletions build_recipe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ sources:
outdir: include/entt/entity
- fetch: https://raw.githubusercontent.com/skypjack/entt/v3.12.2/src/entt/entity/sparse_set.hpp
outdir: include/entt/entity
- fetch: https://raw.githubusercontent.com/skypjack/entt/v3.12.2/src/entt/entity/group.hpp
outdir: include/entt/entity
- fetch: https://raw.githubusercontent.com/skypjack/entt/v3.12.2/src/entt/entity/storage.hpp
outdir: include/entt/entity
- fetch: https://raw.githubusercontent.com/skypjack/entt/v3.12.2/src/entt/entity/component.hpp
outdir: include/entt/entity
- fetch: https://raw.githubusercontent.com/skypjack/entt/v3.12.2/src/entt/entity/mixin.hpp
Expand Down Expand Up @@ -189,6 +185,12 @@ sources:
outdir: include/ecsact/entt/detail
- path: ./ecsact/entt/detail/hash.hh
outdir: include/ecsact/entt/detail
- path: ./ecsact/entt/detail/assoc_fields_hash.hh
outdir: include/ecsact/entt/detail
- path: ./ecsact/entt/detail/codegen_error.hh
outdir: include/ecsact/entt/detail
- path: ./ecsact/entt/detail/indexed_storage.hh
outdir: include/ecsact/entt/detail
# ecsact/entt/wrapper
- path: ./ecsact/entt/wrapper/core.hh
outdir: include/ecsact/entt/wrapper
Expand Down
16 changes: 16 additions & 0 deletions ecsact/entt/assoc.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <cstddef>

namespace ecsact::entt {

/**
* This struct is used to tag an entity as 'indexed'. The template parameter @tp
* C is only to make the code generation more clear which component is being
* indexed. Since the storage name is the identifying factor it should have no
* effect.
*/
template<typename C>
struct indexed {};

} // namespace ecsact::entt
2 changes: 2 additions & 0 deletions ecsact/entt/detail/apply_pending.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <entt/entt.hpp>
#include "ecsact/entt/detail/registry.hh"
#include "ecsact/entt/wrapper/core.hh"
#include "ecsact/entt/detail/internal_markers.hh"

Expand All @@ -11,6 +12,7 @@ auto apply_pending_add(ecsact::entt::registry_t& registry) -> void {
if constexpr(std::is_empty_v<C>) {
registry.view<pending_add<C>>().each([&](auto entity) {
registry.emplace<C>(entity);
// lifecycle_on_add<C>(registry, entity, comp);
});
} else {
registry.view<pending_add<C>>().each( //
Expand Down
24 changes: 24 additions & 0 deletions ecsact/entt/detail/assoc_fields_hash.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <cstdarg>
#include <cstdint>
#include "entt/entt.hpp"
#include "ecsact/runtime/common.h"

namespace ecsact::entt::detail {
using assoc_hash_value_t = std::uint32_t;
static_assert(
sizeof(::entt::id_type) == sizeof(assoc_hash_value_t),
"EnTT storage id type must match the size of ecsact_rt_entt internal hash "
"algorithm size"
);

auto get_assoc_fields_hash(
ecsact_composite_id compo_id,
std::va_list indexed_field_values
) -> assoc_hash_value_t;

template<typename C>
requires(C::has_assoc_fields)
auto get_assoc_fields_hash(const C&) -> assoc_hash_value_t;
} // namespace ecsact::entt::detail
4 changes: 2 additions & 2 deletions ecsact/entt/detail/bytes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace ecsact::entt::detail {

template<typename T>
requires(std::integral<T> || std::floating_point<T>)
requires(std::integral<T> || std::floating_point<T> || std::is_enum_v<T>)
constexpr auto bytes_sizeof() -> int {
using value_type = std::remove_cvref_t<T>;

Expand Down Expand Up @@ -43,7 +43,7 @@ template<typename T>
using unsigned_bit_size_equivalent_t = unsigned_bit_size_equivalent<T>::type;

template<typename T>
requires(std::integral<T> || std::floating_point<T>)
requires(std::integral<T> || std::floating_point<T> || std::is_enum_v<T>)
auto bytes_copy_into( //
T v,
auto& out_bytes,
Expand Down
7 changes: 7 additions & 0 deletions ecsact/entt/detail/codegen_error.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

namespace ecsact::entt::detail {
template<typename>
constexpr bool unimplemented_by_codegen = false;
}

116 changes: 41 additions & 75 deletions ecsact/entt/detail/globals.hh
Original file line number Diff line number Diff line change
Expand Up @@ -41,126 +41,92 @@ extern std::unordered_map< //
*/
extern const std::unordered_set<ecsact_component_id> all_component_ids;

using add_component_fn_sig_t = ecsact_add_error (*)(
ecsact_registry_id reg_id,
ecsact_entity_id entity_id,
ecsact_component_id component_id,
const void* component_data
);

/**
* ecsact_add_component fn pointers
*
* NOTE: This gets is filled in by ecsact_rt_entt_codegen
*/
extern const std::unordered_map< //
ecsact_component_id,
decltype(&ecsact_add_component)>
add_component_fn_sig_t>
add_component_fns;

using get_component_fn_sig_t = const void* (*)( //
ecsact_registry_id reg_id,
ecsact_entity_id entity_id,
ecsact_component_id component_id,
ecsact::entt::detail::assoc_hash_value_t assoc_fields_hash
);

/**
* ecsact_get_component fn pointers
*
* NOTE: This gets is filled in by ecsact_rt_entt_codegen
*/
extern const std::unordered_map< //
ecsact_component_id,
decltype(&ecsact_get_component)>
get_component_fn_sig_t>
get_component_fns;

using update_component_fn_sig_t = ecsact_update_error (*)(
ecsact_registry_id reg_id,
ecsact_entity_id entity_id,
ecsact_component_id component_id,
const void* component_data,
ecsact::entt::detail::assoc_hash_value_t assoc_fields_hash
);

/**
* ecsact_update_component fn pointers
*
* NOTE: This gets is filled in by ecsact_rt_entt_codegen
*/
extern const std::unordered_map< //
ecsact_component_id,
decltype(&ecsact_update_component)>
update_component_fn_sig_t>
update_component_fns;

using remove_component_fn_sig_t = void (*)(
ecsact_registry_id reg_id,
ecsact_entity_id entity_id,
ecsact_component_id component_id,
ecsact::entt::detail::assoc_hash_value_t assoc_fields_hash
);

/**
* ecsact_remove_component fn pointers
*
* NOTE: This gets is filled in by ecsact_rt_entt_codegen
*/
extern const std::unordered_map< //
ecsact_component_id,
decltype(&ecsact_remove_component)>
remove_component_fn_sig_t>
remove_component_fns;

using has_component_fn_sig_t = bool (*)(
ecsact_registry_id reg_id,
ecsact_entity_id entity_id,
ecsact_component_id component_id,
ecsact::entt::detail::assoc_hash_value_t assoc_fields_hash
);

/**
* ecsact_has_component fn pointers
*
* NOTE: This gets is filled in by ecsact_rt_entt_codegen
*/
extern const std::unordered_map< //
ecsact_component_id,
decltype(&ecsact_has_component)>
has_component_fn_sig_t>
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
20 changes: 19 additions & 1 deletion ecsact/entt/detail/hash.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "ecsact/entt/detail/bytes.hh"
#include <cstdint>
#include <cstddef>

Expand All @@ -11,8 +12,25 @@ namespace ecsact::entt::detail {
* @param data_length length of @p data
* @returns hash value
*/
auto bytes_hash( //
auto bytes_hash32( //
std::byte* data,
int data_length
) -> std::uint32_t;

auto bytes_hash64( //
std::byte* data,
int data_length
) -> std::uint64_t;

template<typename... Args>
auto hash_vals32(Args&&... args) -> std::uint32_t {
auto bytes = bytes_copy(args...);
return bytes_hash32(bytes.data(), bytes.size());
}

template<typename... Args>
auto hash_vals64(Args&&... args) -> std::uint64_t {
auto bytes = bytes_copy(args...);
return bytes_hash64(bytes.data(), bytes.size());
}
} // namespace ecsact::entt::detail
Loading