|
1 | 1 |
|
2 | 2 | #include "EcsactBenchmarkMassSpawner.h"
|
| 3 | +#include "Ecsact/Private/EcsactGameInstanceSubsystem.h" |
3 | 4 | #include "EcsactBenchmark/EcsactBenchmark.ecsact.hh"
|
4 | 5 | #include "EcsactBenchmark/EcsactBenchmark__ecsact__ue.h"
|
| 6 | +#include "EcsactBenchmarkRunner.h" |
| 7 | +#include "EcsactUnreal/EcsactExecution.h" |
5 | 8 | #include "EcsactUnreal/EcsactRunner.h"
|
| 9 | +#include "EcsactUnreal/EcsactUnrealExecutionOptions.h" |
| 10 | +#include "Logging/LogVerbosity.h" |
| 11 | +#include "MassEntitySubsystem.h" |
| 12 | +#include "MassSpawnerSubsystem.h" |
6 | 13 | #include "ecsact/si/wasm.h"
|
7 | 14 | #include <filesystem>
|
8 | 15 |
|
9 |
| -auto UEcsactBenchmarkMassSpawner::CreateMassEntities(int count, bool UseEcsact) |
10 |
| - -> void { |
11 |
| - auto runner = GetRunner(); |
| 16 | +UEcsactBenchmarkMassSpawner::UEcsactBenchmarkMassSpawner() {} |
| 17 | + |
| 18 | +auto UEcsactBenchmarkMassSpawner::CreateEcsactEntities(int count) -> void { |
| 19 | + |
| 20 | + registry.emplace("Benchmark"); |
| 21 | + evc.emplace(); |
| 22 | + |
| 23 | + evc->set_init_callback<benchmark::Counter>( |
| 24 | + [this](auto entity_id, const auto comp) { |
| 25 | + this->InitCounter(entity_id, comp); |
| 26 | + }); |
| 27 | + |
| 28 | + evc->set_update_callback<benchmark::Counter>( |
| 29 | + [this](auto entity_id, const auto comp) { |
| 30 | + this->UpdateCounter(entity_id, comp); |
| 31 | + }); |
| 32 | + |
| 33 | + auto exec_options = ecsact::core::execution_options{}; |
12 | 34 |
|
13 | 35 | for (int i = 0; i < count; ++i) {
|
14 |
| - if (UseEcsact) { |
15 |
| - runner->CreateEntity() |
16 |
| - .AddComponent(benchmark::Counter{.value = 0}) |
17 |
| - .OnCreate(TDelegate<void(ecsact_entity_id)>::CreateLambda( // |
18 |
| - [](auto entity) { |
19 |
| - UE_LOG(LogTemp, Warning, TEXT("Ecsact entity %i created"), |
20 |
| - static_cast<int>(entity)); |
21 |
| - })); |
22 |
| - } else { |
23 |
| - runner->CreateEntity() |
24 |
| - .AddComponent(benchmark::Counter{.value = 0}) |
25 |
| - .AddComponent(benchmark::MassOnly{}) |
26 |
| - .OnCreate(TDelegate<void(ecsact_entity_id)>::CreateLambda( // |
27 |
| - [](auto entity) { |
28 |
| - UE_LOG(LogTemp, Warning, TEXT("Mass entity %i created"), |
29 |
| - static_cast<int>(entity)); |
30 |
| - })); |
31 |
| - } |
| 36 | + auto entity = registry->create_entity(); |
| 37 | + |
| 38 | + auto benchmark_counter = benchmark::Counter{.value = 0}; |
| 39 | + |
| 40 | + exec_options.add_component(entity, &benchmark_counter); |
| 41 | + } |
| 42 | + auto exec_err = registry->execute_systems(std::array{exec_options}, *evc); |
| 43 | + if (exec_err != ECSACT_EXEC_SYS_OK) { |
| 44 | + UE_LOG(LogTemp, Error, TEXT("Ecsact system execution failed")); |
| 45 | + } else { |
| 46 | + UE_LOG(LogTemp, Log, TEXT("ECSACT: Created %i entities"), count); |
32 | 47 | }
|
33 | 48 | }
|
| 49 | + |
| 50 | +auto UEcsactBenchmarkMassSpawner::CreateMassEntities(int count) -> void { |
| 51 | + auto *world = GetWorld(); |
| 52 | + check(world); |
| 53 | + |
| 54 | + const auto &entity_template = config->GetOrCreateEntityTemplate(*world); |
| 55 | + auto new_entity_handles = TArray<FMassEntityHandle>{}; |
| 56 | + |
| 57 | + auto mass_spawner = world->GetSubsystem<UMassSpawnerSubsystem>(); |
| 58 | + |
| 59 | + for (int i = 0; i < count; ++i) { |
| 60 | + mass_spawner->SpawnEntities(entity_template, 1, new_entity_handles); |
| 61 | + mass_entities.Add(new_entity_handles[0]); |
| 62 | + } |
| 63 | + UE_LOG(LogTemp, Log, TEXT("MASS: Created %i entities"), count); |
| 64 | +} |
| 65 | + |
34 | 66 | auto UEcsactBenchmarkMassSpawner::LoadWASMFiles() -> void {
|
35 | 67 | auto cwd = FString{std::filesystem::current_path().string().c_str()};
|
36 | 68 |
|
@@ -67,23 +99,54 @@ auto UEcsactBenchmarkMassSpawner::LoadWASMFiles() -> void {
|
67 | 99 | break;
|
68 | 100 | }
|
69 | 101 | #undef HANDLE_ECSACT_SI_ERROR_CASE
|
70 |
| - } else { |
71 |
| - |
72 |
| - UE_LOG(LogTemp, Log, TEXT("yay")); |
73 | 102 | }
|
74 | 103 | }
|
75 | 104 |
|
76 |
| -auto UEcsactBenchmarkMassSpawner::InitCounter_Implementation( |
77 |
| - int32 Entity, FBenchmarkCounter Counter) -> void { |
78 |
| - Super::InitCounter_Implementation(Entity, Counter); |
| 105 | +auto UEcsactBenchmarkMassSpawner::InitCounter( // |
| 106 | + ecsact_entity_id Entity, const benchmark::Counter &) -> void { |
79 | 107 |
|
80 | 108 | UE_LOG(LogTemp, Log, TEXT("Counter started on entity %i"), Entity);
|
81 | 109 | }
|
82 | 110 |
|
83 |
| -auto UEcsactBenchmarkMassSpawner::UpdateCounter_Implementation( |
84 |
| - int32 Entity, FBenchmarkCounter Counter) -> void { |
85 |
| - Super::UpdateCounter_Implementation(Entity, Counter); |
| 111 | +auto UEcsactBenchmarkMassSpawner::UpdateCounter( // |
| 112 | + ecsact_entity_id Entity, const benchmark::Counter &counter) -> void { |
| 113 | + |
| 114 | + UE_LOG(LogTemp, Log, TEXT("Counter update on entity %i to %i"), Entity, |
| 115 | + counter.value); |
| 116 | +} |
| 117 | + |
| 118 | +auto UEcsactBenchmarkMassSpawner::ExecuteSystems(int count) -> void { |
| 119 | + for (int i = 0; i < count; ++i) { |
| 120 | + registry->execute_systems(1, *evc); |
| 121 | + } |
| 122 | +} |
| 123 | + |
| 124 | +void UEcsactBenchmarkMassSpawner::StartMassSpawner( // |
| 125 | + UObject *WorldContext, EcsactBenchmarkType BenchmarkType) { |
| 126 | + UE_LOG(LogTemp, Warning, TEXT("BENCHMARKTYPE: %s"), |
| 127 | + *UEnum::GetValueAsString(BenchmarkType)); |
86 | 128 |
|
87 |
| - UE_LOG(LogTemp, Log, TEXT("Counter updated on entity %i to %i"), Entity, |
88 |
| - Counter.Value); |
| 129 | + auto *world = WorldContext->GetWorld(); |
| 130 | + check(world); |
| 131 | + |
| 132 | + auto ecsact_game_subsystem = |
| 133 | + world->GetGameInstance()->GetSubsystem<UEcsactGameInstanceSubsystem>(); |
| 134 | + check(ecsact_game_subsystem); |
| 135 | + |
| 136 | + ecsact_game_subsystem->StartCustomRunner<UEcsactBenchmarkRunner>(); |
| 137 | + auto runner = EcsactUnrealExecution::Runner(world); |
| 138 | + |
| 139 | + if (!runner.IsValid()) { |
| 140 | + UE_LOG(LogTemp, Error, TEXT("Provided runner is invalid")); |
| 141 | + return; |
| 142 | + } |
| 143 | + |
| 144 | + auto mass_spawner_subsystem = |
| 145 | + runner->GetSubsystem<UEcsactBenchmarkMassSpawner>(); |
| 146 | + |
| 147 | + if (mass_spawner_subsystem) { |
| 148 | + mass_spawner_subsystem->OnStartButtonPressed(BenchmarkType); |
| 149 | + } else { |
| 150 | + UE_LOG(LogTemp, Error, TEXT("BenchmarkMassSpawner can't be found")); |
| 151 | + } |
89 | 152 | }
|
0 commit comments