Skip to content

Commit 705b71a

Browse files
committed
feat: using ecsact stream api
1 parent 21c871d commit 705b71a

File tree

9 files changed

+155
-23
lines changed

9 files changed

+155
-23
lines changed

Source/Ecsact/Ecsact.Build.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ public Ecsact(ReadOnlyTargetRules Target) : base(Target) {
6666
"ECSACT_SERIALIZE_API_LOAD_AT_RUNTIME",
6767
"ECSACT_STATIC_API_LOAD_AT_RUNTIME",
6868
});
69+
PrivateDefinitions.AddRange(new string[] {
70+
"ECSACT_CORE_API_EXPORT",
71+
"ECSACT_DYNAMIC_API_EXPORT",
72+
"ECSACT_ASYNC_API_EXPORT",
73+
"ECSACT_META_API_EXPORT",
74+
"ECSACT_SERIALIZE_API_EXPORT",
75+
"ECSACT_STATIC_API_EXPORT",
76+
});
6977

7078
var EcsactSources = GetEcsactSources();
7179

@@ -74,9 +82,9 @@ public Ecsact(ReadOnlyTargetRules Target) : base(Target) {
7482
"codegen",
7583
"--format=json",
7684
"--plugin=cpp_header",
77-
"--plugin=systems_header",
78-
"--plugin=cpp_systems_header",
79-
"--plugin=cpp_systems_source"
85+
// "--plugin=systems_header",
86+
// "--plugin=cpp_systems_header",
87+
// "--plugin=cpp_systems_source"
8088
};
8189

8290
if(!File.Exists(EcsactUnrealCodegenPluginPath)) {

Source/Ecsact/Public/EcsactUnreal/EcsactAsyncRunner.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ auto UEcsactAsyncRunner::StreamImpl(
2121
ecsact_component_id ComponentId,
2222
const void* ComponentData
2323
) -> void {
24+
#if WITH_EDITORONLY_DATA
25+
if(ecsact_async_stream == nullptr) {
26+
static bool notified_log = false;
27+
if(!notified_log) {
28+
notified_log = true;
29+
UE_LOG(
30+
Ecsact,
31+
Error,
32+
TEXT("ecsact_async_stream unavailable - cannot use "
33+
"UEcsactRunner::Stream")
34+
);
35+
}
36+
return;
37+
}
38+
#endif
39+
2440
ecsact_async_stream(Entity, ComponentId, ComponentData);
2541
}
2642

@@ -92,22 +108,13 @@ auto UEcsactAsyncRunner::OnAsyncRequestDoneRaw(
92108
UE_LOG(
93109
Ecsact,
94110
Warning,
95-
TEXT("Unbound async done callback for request %i (self=%i)"),
96-
req_id,
97-
(intptr_t)self
111+
TEXT("Unbound async done callback for request %i"),
112+
req_id
98113
);
99114
}
100115
}
101116

102117
cbs->Empty();
103-
} else {
104-
UE_LOG(
105-
Ecsact,
106-
Warning,
107-
TEXT("No async done callbacks for request %i (self=%i)"),
108-
req_id,
109-
(intptr_t)self
110-
);
111118
}
112119
}
113120
}
@@ -142,6 +149,8 @@ auto UEcsactAsyncRunner::EnqueueExecutionOptions() -> void {
142149
if(ExecutionOptions->IsNotEmpty()) {
143150
auto req_id =
144151
ecsact_async_enqueue_execution_options(*ExecutionOptions->GetCPtr());
152+
// UE_LOG(Ecsact, Warning, TEXT("SENDING STUFF! req_id=%i"), req_id);
153+
// ExecutionOptions->DebugLog();
145154
ExecutionOptions->Clear();
146155
}
147156
}

Source/Ecsact/Public/EcsactUnreal/EcsactRunner.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ auto UEcsactRunner::IsTickable() const -> bool {
5959
return !IsTemplate() && !bIsStopped;
6060
}
6161

62+
auto UEcsactRunner::GetSubsystem( //
63+
UClass* SubsystemClass
64+
) -> UEcsactRunnerSubsystem* {
65+
for(auto* subsystem : RunnerSubsystems) {
66+
if(subsystem->IsA(SubsystemClass)) {
67+
return subsystem;
68+
}
69+
}
70+
71+
return nullptr;
72+
}
73+
6274
auto UEcsactRunner::CreateEntity() -> EcsactRunnerCreateEntityBuilder {
6375
return {this, GeneratePlaceholderId()};
6476
}
@@ -84,10 +96,6 @@ auto UEcsactRunner::InitRunnerSubsystems() -> void {
8496
continue;
8597
}
8698

87-
if(uclass->HasAnyFlags(RF_Transient)) {
88-
continue;
89-
}
90-
9199
subsystem_types.Add(uclass);
92100
}
93101

@@ -97,6 +105,7 @@ auto UEcsactRunner::InitRunnerSubsystems() -> void {
97105
for(auto t : subsystem_types) {
98106
UE_LOG(Ecsact, Log, TEXT("Starting ecsact subsystem %s"), *t->GetName());
99107
auto subsystem = NewObject<UEcsactRunnerSubsystem>(this, t);
108+
subsystem->OwningRunner = this;
100109
subsystem->AddToRoot();
101110
RunnerSubsystems.Add(subsystem);
102111
}
@@ -173,6 +182,13 @@ auto UEcsactRunner::OnEntityCreatedRaw(
173182
if(create_callback) {
174183
create_callback->Execute(entity_id);
175184
self->CreateEntityCallbacks.Remove(placeholder_entity_id);
185+
} else {
186+
UE_LOG(
187+
Ecsact,
188+
Error,
189+
TEXT("Unable to find create entity callback for placeholder %i"),
190+
(int32)placeholder_entity_id
191+
);
176192
}
177193

178194
for(auto subsystem : self->RunnerSubsystems) {

Source/Ecsact/Public/EcsactUnreal/EcsactRunner.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ class ECSACT_API UEcsactRunner : public UObject, public FTickableGameObject {
8585
auto GetStatId() const -> TStatId override;
8686
auto IsTickable() const -> bool override;
8787

88+
auto GetSubsystem(UClass* SubsystemClass) -> class UEcsactRunnerSubsystem*;
89+
90+
template<typename RunnerSubsystemT>
91+
auto GetSubsystem() -> RunnerSubsystemT* {
92+
return Cast<RunnerSubsystemT>( //
93+
GetSubsystem(RunnerSubsystemT::StaticClass())
94+
);
95+
}
96+
8897
template<typename C>
8998
auto Stream(ecsact_entity_id Entity, const C& StreamComponent) -> void {
9099
return StreamImpl(Entity, C::id, &StreamComponent);
@@ -139,8 +148,9 @@ class ECSACT_API UEcsactRunner::EcsactRunnerCreateEntityBuilder {
139148
auto AddComponent( //
140149
const C& Component
141150
) && -> EcsactRunnerCreateEntityBuilder {
142-
static_cast<UEcsactUnrealExecutionOptions::CreateEntityBuilder&&>(Builder)
143-
.AddComponent<C>(Component);
151+
using CreateEntityBuilder =
152+
UEcsactUnrealExecutionOptions::CreateEntityBuilder;
153+
Builder = std::move(Builder).AddComponent<C>(Component);
144154
return std::move(*this);
145155
}
146156

Source/Ecsact/Public/EcsactUnreal/EcsactRunnerSubsystem.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ auto UEcsactRunnerSubsystem::RemoveComponentRaw(
2121
) -> void {
2222
}
2323

24+
auto UEcsactRunnerSubsystem::GetRunner() -> class UEcsactRunner* {
25+
return OwningRunner;
26+
}
27+
28+
auto UEcsactRunnerSubsystem::GetRunner() const -> const class UEcsactRunner* {
29+
return OwningRunner;
30+
}
31+
2432
auto UEcsactRunnerSubsystem::RunnerStart_Implementation(
2533
class UEcsactRunner* Runner
2634
) -> void {

Source/Ecsact/Public/EcsactUnreal/EcsactRunnerSubsystem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class ECSACT_API UEcsactRunnerSubsystem : public UObject {
99
GENERATED_BODY() // NOLINT
1010

1111
friend class UEcsactRunner;
12+
class UEcsactRunner* OwningRunner;
1213

1314
protected:
1415
virtual void InitComponentRaw(
@@ -27,6 +28,9 @@ class ECSACT_API UEcsactRunnerSubsystem : public UObject {
2728
const void* ComponentData
2829
);
2930

31+
auto GetRunner() -> class UEcsactRunner*;
32+
auto GetRunner() const -> const class UEcsactRunner*;
33+
3034
public:
3135
UFUNCTION(BlueprintNativeEvent, Category = "Ecsact Runner")
3236
void RunnerStart(class UEcsactRunner* Runner);

Source/Ecsact/Public/EcsactUnreal/EcsactUnrealExecutionOptions.cpp

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "EcsactUnreal/EcsactUnrealExecutionOptions.h"
2+
#include "EcsactUnreal/Ecsact.h"
23
#include "ecsact/runtime/common.h"
34

45
using CreateEntityBuilder = UEcsactUnrealExecutionOptions::CreateEntityBuilder;
@@ -41,6 +42,54 @@ auto UEcsactUnrealExecutionOptions::Clear() -> void {
4142
ExecOpts = {};
4243
}
4344

45+
#ifdef WITH_EDITORONLY_DATA
46+
auto UEcsactUnrealExecutionOptions::DebugLog() const -> void {
47+
if(!IsNotEmpty()) {
48+
UE_LOG(Ecsact, Warning, TEXT("(Empty Ecsact Execution Options)"));
49+
return;
50+
}
51+
52+
UE_LOG(Ecsact, Log, TEXT(" == Ecsact Execution Options =="));
53+
UE_LOG(Ecsact, Log, TEXT("\tActions Length: %i"), ExecOpts.actions_length);
54+
for(auto i = 0; ExecOpts.actions_length > i; ++i) {
55+
UE_LOG(
56+
Ecsact,
57+
Log,
58+
TEXT("\t\tActionId: %i"),
59+
ExecOpts.actions[i].action_id
60+
);
61+
}
62+
UE_LOG(
63+
Ecsact,
64+
Log,
65+
TEXT("\tCreate Entities Length: %i"),
66+
ExecOpts.create_entities_length
67+
);
68+
for(auto i = 0; ExecOpts.create_entities_length > i; ++i) {
69+
UE_LOG(
70+
Ecsact,
71+
Log,
72+
TEXT("\t\tPlaceholderId: %i"),
73+
ExecOpts.create_entities[i]
74+
);
75+
for(auto ci = 0; ExecOpts.create_entities_components_length[i] > ci; ++ci) {
76+
auto comp_count = ExecOpts.create_entities_components_length[i];
77+
auto comps = ExecOpts.create_entities_components[ci];
78+
UE_LOG(
79+
Ecsact,
80+
Log,
81+
TEXT("\t\tCreate Entity Component Count: %i"),
82+
comp_count
83+
);
84+
for(auto cci = 0; cci > comp_count; ++cci) {
85+
auto comp = comps[cci];
86+
UE_LOG(Ecsact, Log, TEXT("\t\t\tComponentId: %i"), comp.component_id);
87+
}
88+
}
89+
}
90+
}
91+
#endif
92+
4493
auto UEcsactUnrealExecutionOptions::CreateEntity(
4594
ecsact_placeholder_entity_id PlaceholderId
4695
) -> CreateEntityBuilder {
@@ -49,29 +98,50 @@ auto UEcsactUnrealExecutionOptions::CreateEntity(
4998

5099
CreateEntityBuilder::CreateEntityBuilder(
51100
UEcsactUnrealExecutionOptions* Owner,
52-
ecsact_placeholder_entity_id PlacerholderId
101+
ecsact_placeholder_entity_id PlaceholderId
53102
)
54103
: bValid(true), Owner(Owner), PlaceholderId(PlaceholderId) {
55104
}
56105

57106
CreateEntityBuilder::CreateEntityBuilder(CreateEntityBuilder&& Other) {
58107
bValid = Other.bValid;
59108
Owner = Other.Owner;
109+
PlaceholderId = Other.PlaceholderId;
60110
ComponentList = std::move(Other.ComponentList);
61111

62112
Other.bValid = false;
63113
Other.Owner = nullptr;
114+
Other.PlaceholderId = {};
64115
Other.ComponentList = {};
65116
}
66117

118+
auto CreateEntityBuilder::operator=(CreateEntityBuilder&& Other
119+
) -> CreateEntityBuilder& {
120+
bValid = Other.bValid;
121+
Owner = Other.Owner;
122+
PlaceholderId = Other.PlaceholderId;
123+
ComponentList = std::move(Other.ComponentList);
124+
125+
Other.bValid = false;
126+
Other.Owner = nullptr;
127+
Other.PlaceholderId = {};
128+
Other.ComponentList = {};
129+
return *this;
130+
}
131+
67132
CreateEntityBuilder::~CreateEntityBuilder() {
68-
if(bValid && Owner) {
133+
if(bValid) {
69134
Finish();
70135
}
71136
}
72137

73138
auto CreateEntityBuilder::Finish() -> void {
74-
if(!bValid || !Owner) {
139+
if(!bValid) {
140+
return;
141+
}
142+
143+
if(!Owner) {
144+
UE_LOG(Ecsact, Error, TEXT("Cannot create entity - Runner not valid"));
75145
return;
76146
}
77147

Source/Ecsact/Public/EcsactUnreal/EcsactUnrealExecutionOptions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class ECSACT_API UEcsactUnrealExecutionOptions : public UObject {
3434
auto Clear() -> void;
3535
auto IsNotEmpty() const -> bool;
3636

37+
#ifdef WITH_EDITORONLY_DATA
38+
auto DebugLog() const -> void;
39+
#endif
40+
3741
/**
3842
* Get's the C `ecsact_execution_options` pointer typically passed to
3943
* `ecsact_execute_systems` or `ecsact_async_enqueue_execution_options`. The
@@ -118,6 +122,8 @@ class ECSACT_API UEcsactUnrealExecutionOptions::CreateEntityBuilder {
118122
CreateEntityBuilder(CreateEntityBuilder&&);
119123
~CreateEntityBuilder();
120124

125+
auto operator=(CreateEntityBuilder&&) -> CreateEntityBuilder&;
126+
121127
template<typename C>
122128
auto AddComponent(const C& Component) && -> CreateEntityBuilder {
123129
auto component_data = FMemory::Malloc(sizeof(C));

Source/EcsactEditor/Private/EcsactEditor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ auto FEcsactEditorModule::RunBuild() -> void {
449449
"-o",
450450
ecsact_runtime_path,
451451
"--temp=" + temp_dir,
452+
"--debug",
452453
};
453454

454455
switch(settings->BuildReportFilter) {

0 commit comments

Comments
 (0)