Skip to content

Commit

Permalink
feat: toggle working, tests passing but currently flaky
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelwan committed Sep 19, 2024
1 parent 0ed2a75 commit 05d98ef
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 39 deletions.
1 change: 0 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ bazel_dep(name = "xxhash", version = "0.8.2")
bazel_dep(name = "googletest", version = "1.14.0.bcr.1")
bazel_dep(name = "boost.dll", version = "1.83.0.bzl.2")
bazel_dep(name = "boost.process", version = "1.83.0.bzl.2")
bazel_dep(name = "magic_enum", version = "0.9.6")

bazel_dep(name = "toolchains_llvm", version = "1.0.0", dev_dependency = True)
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
Expand Down
26 changes: 16 additions & 10 deletions ecsact/entt/detail/apply_component_stream_data.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,27 @@ auto apply_component_stream_data(
::entt::registry& main_reg,
::entt::registry& stream_reg
) -> void {
auto stream_view = stream_reg.template view<
auto view = main_reg.template view<
C>(::entt::exclude<ecsact::entt::detail::run_on_stream<C>>);

for(auto entity : stream_view) {
auto& in_component = stream_view.get<C>(entity);
auto& current_comp = main_reg.get<C>(entity);
for(auto entity : view) {
if(!stream_reg.any_of<C>(entity)) {
continue;
}

auto& in_component = stream_reg.get<C>(entity);
if(main_reg.any_of<C>(entity)) {
auto& current_comp = main_reg.get<C>(entity);

auto& beforechange =
main_reg.template get<exec_beforechange_storage<C>>(entity);
auto& beforechange =
main_reg.template get<exec_beforechange_storage<C>>(entity);

if(!beforechange.has_update_occurred) {
beforechange.value = current_comp;
beforechange.has_update_occurred = true;
if(!beforechange.has_update_occurred) {
beforechange.value = current_comp;
beforechange.has_update_occurred = true;
}
current_comp = in_component;
}
current_comp = in_component;
}
}
} // namespace ecsact::entt::detail
8 changes: 6 additions & 2 deletions ecsact/entt/wrapper/dynamic.hh
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,13 @@ auto context_stream_toggle(
auto& registry = *context->registry;

if(streaming_enabled) {
registry.template remove<run_on_stream<C>>(entity);
if(registry.any_of<run_on_stream<C>>(entity)) {
registry.template remove<run_on_stream<C>>(entity);
}
} else {
registry.template emplace<run_on_stream<C>>(entity);
if(!registry.any_of<run_on_stream<C>>(entity)) {
registry.template emplace<run_on_stream<C>>(entity);
}
}
}

Expand Down
1 change: 0 additions & 1 deletion rt_entt_codegen/core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ _CORE_CODEGEN_METHODS = {
"//rt_entt_codegen/core/system_provider",
"@entt//:entt",
"@ecsact_rt_entt//:lib",
"@magic_enum",
],
"check_error": [],
"execution_options": [],
Expand Down
6 changes: 0 additions & 6 deletions rt_entt_codegen/core/print_sys_exec.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#include "core.hh"

#include <stdexcept>
#include <string>
#include <memory>
#include <algorithm>
#include <unordered_map>
#include "magic_enum.hpp"

#include "ecsact/runtime/meta.hh"
#include "ecsact/runtime/common.h"
Expand Down Expand Up @@ -402,9 +400,6 @@ static auto add_stream_component_if_needed(
for(auto [comp_id, capability] : comp_caps) {
auto comp_type = ecsact_meta_component_type(comp_id);

ctx.warn("COMP TYPE: {}", magic_enum::enum_name(comp_type));
ctx.warn("COMP CAPABILITY: {}", magic_enum::enum_name(capability));

if(comp_type != ECSACT_COMPONENT_TYPE_STREAM &&
comp_type != ECSACT_COMPONENT_TYPE_LAZY_STREAM) {
continue;
Expand Down Expand Up @@ -442,7 +437,6 @@ static auto print_execute_systems(

auto system_name = cpp_identifier(decl_full_name(sys_like_id));

ctx.warn("SYSTEM NAME: {}", system_name);
add_stream_component_if_needed(ctx, sys_like_id, additional_view_components);

ecsact::rt_entt_codegen::util::make_view(
Expand Down
2 changes: 1 addition & 1 deletion rt_entt_codegen/shared/parallel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static auto is_capability_safe_entities(
}

std::underlying_type_t<ecsact_system_capability> unsafe_caps =
ECSACT_SYS_CAP_ADDS | ECSACT_SYS_CAP_REMOVES;
ECSACT_SYS_CAP_ADDS | ECSACT_SYS_CAP_REMOVES | ECSACT_SYS_CAP_STREAM_TOGGLE;
unsafe_caps &= ~(ECSACT_SYS_CAP_EXCLUDE | ECSACT_SYS_CAP_INCLUDE);

return (unsafe_caps & capability) == 0b0;
Expand Down
46 changes: 28 additions & 18 deletions test/runtime_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,20 @@ void runtime_test::MixedNotify::impl(context& ctx) {
void runtime_test::StreamTestSystem::impl(context& ctx) {
auto comp = ctx.get<StreamTestCounter>();

std::cout << "VAL: " << comp.val << std::endl;
if(comp.val == 100) {
std::cout << "SteamTest TOGGLED!" << std::endl;
if(comp.val == 0) {
ctx.stream_toggle<StreamTestToggle>(false);
}

if(comp.val == 10) {
ctx.stream_toggle<StreamTestToggle>(true);
}
}

void runtime_test::StreamTestSystemCounter::impl(context& ctx) {
auto comp = ctx.get<StreamTestToggle>();
std::cout << "STREAM TEST SYSTEM COUNTER ITERATED" << std::endl;
comp.val += 10;
ctx.update(comp);
auto toggle_comp = ctx.get<StreamTestToggle>();

toggle_comp.val += 10;
ctx.update(toggle_comp);
}

TEST(Core, CreateRegistry) {
Expand Down Expand Up @@ -1389,28 +1391,36 @@ TEST(Core, StreamComponentToggle) {

exec_options.add_component(entity, &stream_component);
exec_options.add_component(entity, &stream_comp_counter);
exec_options = ecsact::core::execution_options{};

auto error = reg.execute_systems(std::array{exec_options});
int prev_val = 0;
int prev_val = 10;

for(int i = 0; i < 10; i++) {
stream_comp_counter.val += 10;
exec_options
// ecsact_stream(reg.id(), entity, StreamTestToggle::id,
// &stream_component);
for(int i = 0; i < 5; i++) {
stream_component.val += 10;
ecsact_stream(reg.id(), entity, StreamTestToggle::id, &stream_component);

reg.execute_systems();
reg.execute_systems();

stream_component = reg.get_component<StreamTestToggle>(entity);
stream_comp_counter = reg.get_component<StreamTestCounter>(entity);
ASSERT_EQ(stream_component.val, prev_val + 10);
ASSERT_EQ(stream_comp_counter.val, 0);
prev_val = stream_component.val;
}

std::cout << "VAL: " << stream_component.val << std::endl;
stream_comp_counter.val += 10;
exec_options.clear();
exec_options.update_component(entity, &stream_comp_counter);
error = reg.execute_systems(std::array{exec_options});

for(int i = 0; i < 5; i++) {
stream_component.val += 10;
ecsact_stream(reg.id(), entity, StreamTestToggle::id, &stream_component);

reg.execute_systems();

for(int i = 0; i < 10; i++) {
stream_component = reg.get_component<StreamTestToggle>(entity);
stream_comp_counter = reg.get_component<StreamTestCounter>(entity);
ASSERT_EQ(stream_component.val, prev_val + 10);
prev_val = stream_component.val;
}
}

0 comments on commit 05d98ef

Please sign in to comment.