diff --git a/Source/Ecsact/Ecsact.Build.cs b/Source/Ecsact/Ecsact.Build.cs index fbe1f16..1a46ca9 100644 --- a/Source/Ecsact/Ecsact.Build.cs +++ b/Source/Ecsact/Ecsact.Build.cs @@ -29,7 +29,6 @@ public Ecsact(ReadOnlyTargetRules Target) : base(Target) { "Engine", "Slate", "SlateCore", - "Kismet", }); DynamicallyLoadedModuleNames.AddRange(new string[] { diff --git a/Source/Ecsact/Public/EcsactUnreal/EcsactRunner.cpp b/Source/Ecsact/Public/EcsactUnreal/EcsactRunner.cpp index 5eb1f9d..7af46b8 100644 --- a/Source/Ecsact/Public/EcsactUnreal/EcsactRunner.cpp +++ b/Source/Ecsact/Public/EcsactUnreal/EcsactRunner.cpp @@ -1,4 +1,5 @@ #include "EcsactUnreal/EcsactRunner.h" +#include "EcsactUnreal/EcsactRunnerSubsystem.h" auto UEcsactRunner::Tick(float DeltaTime) -> void { } @@ -13,3 +14,9 @@ auto UEcsactRunner::GetStatId() const -> TStatId { auto UEcsactRunner::IsTickable() const -> bool { return !IsTemplate(); } + +auto UEcsactRunner::InitRunnerSubsystems() -> void { +} + +auto UEcsactRunner::ShutdownRunnerSubsystems() -> void { +} diff --git a/Source/Ecsact/Public/EcsactUnreal/EcsactRunner.h b/Source/Ecsact/Public/EcsactUnreal/EcsactRunner.h index 5f7e15d..4478833 100644 --- a/Source/Ecsact/Public/EcsactUnreal/EcsactRunner.h +++ b/Source/Ecsact/Public/EcsactUnreal/EcsactRunner.h @@ -11,6 +11,8 @@ UCLASS(Abstract) class UEcsactRunner : public UObject, public FTickableGameObject { GENERATED_BODY() // NOLINT + TArray RunnerSubsystems; + protected: UPROPERTY() class UEcsactUnrealEventsCollector* EventsCollector; @@ -18,6 +20,9 @@ class UEcsactRunner : public UObject, public FTickableGameObject { UPROPERTY() class UEcsactUnrealExecutionOptions* ExecutionOptions; + virtual auto InitRunnerSubsystems() -> void; + virtual auto ShutdownRunnerSubsystems() -> void; + public: auto Tick(float DeltaTime) -> void override; auto GetStatId() const -> TStatId override; diff --git a/Source/Ecsact/Public/EcsactUnreal/EcsactRunnerSubsystem.cpp b/Source/Ecsact/Public/EcsactUnreal/EcsactRunnerSubsystem.cpp new file mode 100644 index 0000000..8c39259 --- /dev/null +++ b/Source/Ecsact/Public/EcsactUnreal/EcsactRunnerSubsystem.cpp @@ -0,0 +1,11 @@ +#include "EcsactRunnerSubsystem.h" + +auto UEcsactRunnerSubsystem::RunnerStart_Implementation( + class UEcsactRunner* Runner +) -> void { +} + +auto UEcsactRunnerSubsystem::RunnerStop_Implementation( + class UEcsactRunner* Runner +) -> void { +} diff --git a/Source/Ecsact/Public/EcsactUnreal/EcsactRunnerSubsystem.h b/Source/Ecsact/Public/EcsactUnreal/EcsactRunnerSubsystem.h new file mode 100644 index 0000000..924a18d --- /dev/null +++ b/Source/Ecsact/Public/EcsactUnreal/EcsactRunnerSubsystem.h @@ -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; +}; diff --git a/Source/Ecsact/Public/EcsactUnreal/EcsactSettings.h b/Source/Ecsact/Public/EcsactUnreal/EcsactSettings.h index 5d111c8..a24b5b7 100644 --- a/Source/Ecsact/Public/EcsactUnreal/EcsactSettings.h +++ b/Source/Ecsact/Public/EcsactUnreal/EcsactSettings.h @@ -55,4 +55,7 @@ class ECSACT_API UEcsactSettings : public UObject { ) ) TSubclassOf CustomRunnerClass; + + UPROPERTY(VisibleAnywhere, Config, Category = "Runtime") + TArray> RunnerSubsystems; }; diff --git a/Source/EcsactUnrealCodegenPlugin/EcsactUnrealCodegenPlugin.cpp b/Source/EcsactUnrealCodegenPlugin/EcsactUnrealCodegenPlugin.cpp index 3f8d9b2..a63ac4d 100644 --- a/Source/EcsactUnrealCodegenPlugin/EcsactUnrealCodegenPlugin.cpp +++ b/Source/EcsactUnrealCodegenPlugin/EcsactUnrealCodegenPlugin.cpp @@ -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"); @@ -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,