Skip to content

Commit

Permalink
feat: ecsact package subsystems
Browse files Browse the repository at this point in the history
  • Loading branch information
zaucy committed Aug 26, 2024
1 parent e454e94 commit 3c4ec3f
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 29 deletions.
1 change: 0 additions & 1 deletion Source/Ecsact/Ecsact.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public Ecsact(ReadOnlyTargetRules Target) : base(Target) {
"Engine",
"Slate",
"SlateCore",
"Kismet",
});

DynamicallyLoadedModuleNames.AddRange(new string[] {
Expand Down
7 changes: 7 additions & 0 deletions Source/Ecsact/Public/EcsactUnreal/EcsactRunner.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "EcsactUnreal/EcsactRunner.h"
#include "EcsactUnreal/EcsactRunnerSubsystem.h"

auto UEcsactRunner::Tick(float DeltaTime) -> void {
}
Expand All @@ -13,3 +14,9 @@ auto UEcsactRunner::GetStatId() const -> TStatId {
auto UEcsactRunner::IsTickable() const -> bool {
return !IsTemplate();
}

auto UEcsactRunner::InitRunnerSubsystems() -> void {
}

auto UEcsactRunner::ShutdownRunnerSubsystems() -> void {
}
5 changes: 5 additions & 0 deletions Source/Ecsact/Public/EcsactUnreal/EcsactRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ UCLASS(Abstract)
class UEcsactRunner : public UObject, public FTickableGameObject {
GENERATED_BODY() // NOLINT

TArray<class UEcsactRunnerSubsystem*> RunnerSubsystems;

protected:
UPROPERTY()
class UEcsactUnrealEventsCollector* EventsCollector;

UPROPERTY()
class UEcsactUnrealExecutionOptions* ExecutionOptions;

virtual auto InitRunnerSubsystems() -> void;
virtual auto ShutdownRunnerSubsystems() -> void;

public:
auto Tick(float DeltaTime) -> void override;
auto GetStatId() const -> TStatId override;
Expand Down
11 changes: 11 additions & 0 deletions Source/Ecsact/Public/EcsactUnreal/EcsactRunnerSubsystem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "EcsactRunnerSubsystem.h"

auto UEcsactRunnerSubsystem::RunnerStart_Implementation(
class UEcsactRunner* Runner
) -> void {
}

auto UEcsactRunnerSubsystem::RunnerStop_Implementation(
class UEcsactRunner* Runner
) -> void {
}
23 changes: 23 additions & 0 deletions Source/Ecsact/Public/EcsactUnreal/EcsactRunnerSubsystem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include "ecsact/runtime/common.h"
#include "EcsactRunnerSubsystem.generated.h"

UCLASS(Blueprintable)

class ECSACT_API UEcsactRunnerSubsystem : public UObject {
GENERATED_BODY() // NOLINT
public:
UFUNCTION(BlueprintNativeEvent, Category = "Ecsact Runner")
void RunnerStart(class UEcsactRunner* Runner);

UFUNCTION(BlueprintNativeEvent, Category = "Ecsact Runner")
void RunnerStop(class UEcsactRunner* Runner);

virtual auto RunnerStart_Implementation( //
class UEcsactRunner* Runner
) -> void;
virtual auto RunnerStop_Implementation( //
class UEcsactRunner* Runner
) -> void;
};
3 changes: 3 additions & 0 deletions Source/Ecsact/Public/EcsactUnreal/EcsactSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ class ECSACT_API UEcsactSettings : public UObject {
)
)
TSubclassOf<UEcsactRunner> CustomRunnerClass;

UPROPERTY(VisibleAnywhere, Config, Category = "Runtime")
TArray<TSubclassOf<class UEcsactRunnerSubsystem>> RunnerSubsystems;
};
84 changes: 56 additions & 28 deletions Source/EcsactUnrealCodegenPlugin/EcsactUnrealCodegenPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ static auto generate_header(ecsact::codegen_plugin_context ctx) -> void {

inc_header(ctx, "CoreMinimal.h");
inc_header(ctx, "UObject/Interface.h");
inc_header(ctx, "EcsactUnreal/EcsactRunnerSubsystem.h");
inc_package_header(ctx, ctx.package_id, ".hh");
inc_package_header_no_ext(ctx, ctx.package_id, "__ecsact__ue.generated.h");

Expand All @@ -106,46 +107,73 @@ static auto generate_header(ecsact::codegen_plugin_context ctx) -> void {

ctx.writef("\n\n");

ctx.write(std::format(
"UCLASS(Blueprintable, meta = "
"(DisplayName = \"Ecsact Runner Package Subsystem ({})\"))\n",
ecsact::meta::package_name(ctx.package_id)
));
block(
ctx,
std::format(
"class U{}EcsactRunnerSubsystem : public UEcsactRunnerSubsystem",
prefix
),
[&] {
ctx.writef("GENERATED_BODY() // NOLINT\n");
ctx.indentation -= 1;
ctx.writef("\n");
ctx.writef("public:");
ctx.indentation += 1;
ctx.writef("\n");

for(auto comp_id : ecsact::meta::get_component_ids(ctx.package_id)) {
auto comp_full_name = ecsact::meta::decl_full_name(comp_id);
auto comp_type_cpp_name = cpp_identifier(comp_full_name);
auto comp_name = ecsact::meta::component_name(comp_id);
auto comp_pascal_name = ecsact_decl_name_to_pascal(comp_name);
ctx.write(std::format(
"UFUNCTION(BlueprintNativeEvent, Category = \"Ecsact Runner\", meta "
"= "
"(DisplayName = \"Init {}\"))\n",
comp_full_name
));
ctx.write(std::format("void Init{}();\n", comp_pascal_name));
ctx.write(std::format(
"virtual void Init{}_Implementation();\n",
comp_pascal_name
));
}
}
);
ctx.writef(";\n");
}

static auto generate_source(ecsact::codegen_plugin_context ctx) -> void {
inc_package_header_no_ext(ctx, ctx.package_id, "__ecsact__ue.h");

auto package_pascal_name =
ecsact_decl_name_to_pascal(ecsact::meta::package_name(ctx.package_id));

for(auto comp_id : ecsact::meta::get_component_ids(ctx.package_id)) {
auto comp_full_name = ecsact::meta::decl_full_name(comp_id);
auto comp_name = ecsact::meta::component_name(comp_id);
ctx.write(
"UINTERFACE(MinimalAPI, Blueprintable, meta = (DisplayName = \"",
std::format(
"requires {} (ecsact)",
ecsact::meta::decl_full_name(comp_id)
),
"\"))\n"
);
auto comp_pascal_name = ecsact_decl_name_to_pascal(comp_name);

block(
ctx,
std::format(
"class UEcsactRequires{}{} : public UInterface",
prefix,
comp_name
"void U{}EcsactRunnerSubsystem::Init{}_Implementation()",
package_pascal_name,
comp_pascal_name
),
[&] { ctx.writef("GENERATED_BODY() // NOLINT"); }
);
ctx.writef(";\n");

block(
ctx,
std::format("class IEcsactRequires{}{}", prefix, comp_name),
[&] {
ctx.writef("GENERATED_BODY() // NOLINT\n");
ctx.indentation -= 1;
ctx.writef("\n");
ctx.writef("public:");
ctx.indentation += 1;
ctx.writef("\n");

}
);
ctx.writef(";\n");
ctx.writef("\n\n");
}
}

static auto generate_source(ecsact::codegen_plugin_context ctx) -> void {
}

auto ecsact_codegen_plugin(
ecsact_package_id package_id,
ecsact_codegen_write_fn_t write_fn,
Expand Down

0 comments on commit 3c4ec3f

Please sign in to comment.