Skip to content

Commit fae3ae3

Browse files
committed
feat: Benchmarks for mass end ecsact ready for measuring
1 parent 508a60d commit fae3ae3

File tree

13 files changed

+150
-48
lines changed

13 files changed

+150
-48
lines changed

unreal-cpp-benchmark/Config/DefaultEcsact.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CustomEcsactRuntimeLibraryPath=
44
BuildReportFilter=None
55
+Recipes=rt_entt
66
+Recipes=si_wasmer
7-
Runner=Automatic
7+
Runner=Custom
88
CustomRunnerClass=None
99
bAutoCollectBlueprintRunnerSubsystems=True
1010
+RunnerSubsystems=/Game/Blueprints/BP_EcsactBenchmarkMassSpawner.BP_EcsactBenchmarkMassSpawner_C

unreal-cpp-benchmark/Config/DefaultEngine.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

22

33
[/Script/EngineSettings.GameMapsSettings]
4-
GameDefaultMap=/Engine/Maps/Templates/OpenWorld
4+
GameDefaultMap=/Game/Maps/Benchmark.Benchmark
5+
EditorStartupMap=/Game/Maps/Benchmark.Benchmark
56

67
[/Script/Engine.RendererSettings]
78
r.AllowStaticLighting=False
Binary file not shown.
Binary file not shown.
Binary file not shown.
18.5 KB
Binary file not shown.
Binary file not shown.
Lines changed: 95 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,68 @@
11

22
#include "EcsactBenchmarkMassSpawner.h"
3+
#include "Ecsact/Private/EcsactGameInstanceSubsystem.h"
34
#include "EcsactBenchmark/EcsactBenchmark.ecsact.hh"
45
#include "EcsactBenchmark/EcsactBenchmark__ecsact__ue.h"
6+
#include "EcsactBenchmarkRunner.h"
7+
#include "EcsactUnreal/EcsactExecution.h"
58
#include "EcsactUnreal/EcsactRunner.h"
9+
#include "EcsactUnreal/EcsactUnrealExecutionOptions.h"
10+
#include "Logging/LogVerbosity.h"
11+
#include "MassEntitySubsystem.h"
12+
#include "MassSpawnerSubsystem.h"
613
#include "ecsact/si/wasm.h"
714
#include <filesystem>
815

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{};
1234

1335
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);
3247
}
3348
}
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+
3466
auto UEcsactBenchmarkMassSpawner::LoadWASMFiles() -> void {
3567
auto cwd = FString{std::filesystem::current_path().string().c_str()};
3668

@@ -67,23 +99,54 @@ auto UEcsactBenchmarkMassSpawner::LoadWASMFiles() -> void {
6799
break;
68100
}
69101
#undef HANDLE_ECSACT_SI_ERROR_CASE
70-
} else {
71-
72-
UE_LOG(LogTemp, Log, TEXT("yay"));
73102
}
74103
}
75104

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 {
79107

80108
UE_LOG(LogTemp, Log, TEXT("Counter started on entity %i"), Entity);
81109
}
82110

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));
86128

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+
}
89152
}
Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,58 @@
11
#pragma once
22

3+
#include <optional>
4+
#include <string>
5+
36
#include "CoreMinimal.h"
7+
#include "MassEntityConfigAsset.h"
8+
#include "ecsact/runtime/core.hh"
49

510
#include "EcsactBenchmark__ecsact__mass__ue.h"
611
#include "EcsactBenchmark__ecsact__ue.h"
712

813
#include "EcsactBenchmarkMassSpawner.generated.h"
914

15+
UENUM(BlueprintType)
16+
enum class EcsactBenchmarkType : uint8 {
17+
EcsactCounter UMETA(DisplayName = "Ecsact Counter"),
18+
MassCounter UMETA(DisplayName = "Mass Counter")
19+
};
20+
1021
UCLASS(Abstract)
11-
class UEcsactBenchmarkMassSpawner : public UOneToOneBenchmarkMassSpawner {
22+
class UEcsactBenchmarkMassSpawner : public UBenchmarkMassSpawner {
1223
GENERATED_BODY()
24+
UEcsactBenchmarkMassSpawner();
25+
26+
std::optional<ecsact::core::registry> registry;
27+
std::optional<ecsact::core::execution_events_collector<>> evc;
28+
29+
TArray<ecsact_entity_id> entities;
30+
TArray<FMassEntityHandle> mass_entities;
31+
32+
UPROPERTY(EditAnywhere)
33+
UMassEntityConfigAsset *config;
1334

1435
public:
36+
UFUNCTION(BlueprintCallable, Meta = (WorldContext = "WorldContext"))
37+
static void StartMassSpawner(UObject *WorldContext,
38+
EcsactBenchmarkType BenchmarkType);
39+
40+
UFUNCTION(BlueprintCallable)
41+
void CreateMassEntities(int count);
42+
1543
UFUNCTION(BlueprintCallable)
16-
void CreateMassEntities(int count, bool UseEcsact);
44+
void CreateEcsactEntities(int count);
1745

1846
UFUNCTION(BlueprintCallable)
1947
void LoadWASMFiles();
2048

21-
void InitCounter_Implementation(int32 Entity,
22-
FBenchmarkCounter counter) override;
23-
void UpdateCounter_Implementation(int32 Entity,
24-
FBenchmarkCounter counter) override;
49+
UFUNCTION(BlueprintCallable)
50+
void ExecuteSystems(int count);
51+
52+
void InitCounter(ecsact_entity_id Entity, const benchmark::Counter &Counter);
53+
void UpdateCounter(ecsact_entity_id Entity,
54+
const benchmark::Counter &Counter);
55+
56+
UFUNCTION(BlueprintImplementableEvent)
57+
void OnStartButtonPressed(EcsactBenchmarkType BenchmarkType);
2558
};

unreal-cpp-benchmark/Source/EcsactBenchmark/EcsactBenchmarkRunner.cpp

Whitespace-only changes.

0 commit comments

Comments
 (0)