From 5d00a246f5acdc8e72ca3fb0ec8b39949b8ade0e Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Mon, 15 Feb 2021 23:31:25 -0500 Subject: [PATCH] First commit of EventCenterPlugin (not working, wip) --- EventCenterPlugin.uplugin | 24 +++++++ .../EventCenterPlugin.Build.cs | 66 +++++++++++++++++ .../Private/EventCenterPlugin.cpp | 20 ++++++ .../Private/EventSourceActor.cpp | 62 ++++++++++++++++ .../Public/EventCenterPlugin.h | 15 ++++ .../Public/EventSourceActor.h | 70 +++++++++++++++++++ 6 files changed, 257 insertions(+) create mode 100644 EventCenterPlugin.uplugin create mode 100644 Source/EventCenterPlugin/EventCenterPlugin.Build.cs create mode 100644 Source/EventCenterPlugin/Private/EventCenterPlugin.cpp create mode 100644 Source/EventCenterPlugin/Private/EventSourceActor.cpp create mode 100644 Source/EventCenterPlugin/Public/EventCenterPlugin.h create mode 100644 Source/EventCenterPlugin/Public/EventSourceActor.h diff --git a/EventCenterPlugin.uplugin b/EventCenterPlugin.uplugin new file mode 100644 index 0000000..2f58d51 --- /dev/null +++ b/EventCenterPlugin.uplugin @@ -0,0 +1,24 @@ +{ + "FileVersion": 3, + "Version": 1, + "VersionName": "1.0", + "FriendlyName": "EventCenterPlugin", + "Description": "Poll or subscribe to events, then dispatch throughout the game engine", + "Category": "Other", + "CreatedBy": "Brandon Thomas", + "CreatedByURL": "http://brand.io", + "DocsURL": "", + "MarketplaceURL": "", + "SupportURL": "", + "CanContainContent": true, + "IsBetaVersion": false, + "IsExperimentalVersion": false, + "Installed": false, + "Modules": [ + { + "Name": "EventCenterPlugin", + "Type": "Runtime", + "LoadingPhase": "Default" + } + ] +} \ No newline at end of file diff --git a/Source/EventCenterPlugin/EventCenterPlugin.Build.cs b/Source/EventCenterPlugin/EventCenterPlugin.Build.cs new file mode 100644 index 0000000..a5e1b52 --- /dev/null +++ b/Source/EventCenterPlugin/EventCenterPlugin.Build.cs @@ -0,0 +1,66 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +using UnrealBuildTool; + +public class EventCenterPlugin : ModuleRules +{ + public EventCenterPlugin(ReadOnlyTargetRules Target) : base(Target) + { + PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; + + PublicIncludePaths.AddRange(new string[] {}); + + PublicIncludePaths.AddRange( + new string[] { + // ... add public include paths required here ... + + // NB(bt): Using the commercial Redis Plugin by GameSeed (AKA "SDRedis") + // Add this in the Unreal Engine Plugins menu. + // If not present, use the Epic Games Launcher's Unreal Library Marketplace. + "RedisPlugin/Public", + "RedisPlugin/Classes" + } + ); + + + PrivateIncludePaths.AddRange( + new string[] { + // ... add other private include paths required here ... + } + ); + + + PublicDependencyModuleNames.AddRange( + new string[] + { + "Core", + // ... add other public dependencies that you statically link with here ... + + // NB(bt): Using the commercial Redis Plugin by GameSeed (AKA "SDRedis") + // Add this in the Unreal Engine Plugins menu. + // If not present, use the Epic Games Launcher's Unreal Library Marketplace. + "RedisPlugin" + } + ); + + + PrivateDependencyModuleNames.AddRange( + new string[] + { + "CoreUObject", + "Engine", + "Slate", + "SlateCore", + // ... add private dependencies that you statically link with here ... + } + ); + + + DynamicallyLoadedModuleNames.AddRange( + new string[] + { + // ... add any modules that your module loads dynamically here ... + } + ); + } +} diff --git a/Source/EventCenterPlugin/Private/EventCenterPlugin.cpp b/Source/EventCenterPlugin/Private/EventCenterPlugin.cpp new file mode 100644 index 0000000..6dda5e1 --- /dev/null +++ b/Source/EventCenterPlugin/Private/EventCenterPlugin.cpp @@ -0,0 +1,20 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include "EventCenterPlugin.h" + +#define LOCTEXT_NAMESPACE "FEventCenterPluginModule" + +void FEventCenterPluginModule::StartupModule() +{ + // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module +} + +void FEventCenterPluginModule::ShutdownModule() +{ + // This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, + // we call this function before unloading the module. +} + +#undef LOCTEXT_NAMESPACE + +IMPLEMENT_MODULE(FEventCenterPluginModule, EventCenterPlugin) \ No newline at end of file diff --git a/Source/EventCenterPlugin/Private/EventSourceActor.cpp b/Source/EventCenterPlugin/Private/EventSourceActor.cpp new file mode 100644 index 0000000..05e9042 --- /dev/null +++ b/Source/EventCenterPlugin/Private/EventSourceActor.cpp @@ -0,0 +1,62 @@ +#include "EventSourceActor.h" + +#include "UObject/Object.h" + +DEFINE_LOG_CATEGORY(EventSourceLog); + +AEventSourceActor::AEventSourceActor() +{ + // Set this actor to call Tick() every frame. + // You can turn this off to improve performance if you don't need it. + PrimaryActorTick.bCanEverTick = true; + + //redis = NewObject(this, TEXT("RedisObject")); + redis = CreateDefaultSubobject(TEXT("RedisObject")); + + //RootComponent = redis; +} + +AEventSourceActor::~AEventSourceActor() +{ + // TODO: Memory leak (somehow placing a BP derivation into the editor causes the below lines to segfault) + //delete redis; + //redis = nullptr; +} + +void AEventSourceActor::BeginPlay() +{ + UE_LOG(EventSourceLog, Log, TEXT("BeginPlay()")); + + Super::BeginPlay(); + + UE_LOG(EventSourceLog, Log, TEXT("BeginPlay(): Redis is null? %b"), redis != nullptr); + //UE_LOG(EventSourceLog, Log, TEXT("BeginPlay(): Redis host: %s"), redisHost); + UE_LOG(EventSourceLog, Log, TEXT("BeginPlay(): Redis port: %d"), redisPort); + //UE_LOG(EventSourceLog, Log, TEXT("BeginPlay(): Redis password (no secrets): %s"), redisPassword); + + //redis->Init(redisHost, redisPort, redisPassword); + +} + +void AEventSourceActor::BeginDestroy() +{ + Super::BeginDestroy(); +} + +void AEventSourceActor::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); + + // NB: Handled by RedisObject internal delegate + //redis->Tick(DeltaTime); +} + +void AEventSourceActor::Subscribe(const FString& Channel) +{ + redis->Subscribe(Channel); +} + +void AEventSourceActor::Unsubscribe(const FString& Channel) +{ + redis->Unsubscribe(Channel); +} diff --git a/Source/EventCenterPlugin/Public/EventCenterPlugin.h b/Source/EventCenterPlugin/Public/EventCenterPlugin.h new file mode 100644 index 0000000..ed046c6 --- /dev/null +++ b/Source/EventCenterPlugin/Public/EventCenterPlugin.h @@ -0,0 +1,15 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#pragma once + +#include "CoreMinimal.h" +#include "Modules/ModuleManager.h" + +class FEventCenterPluginModule : public IModuleInterface +{ +public: + + /** IModuleInterface implementation */ + virtual void StartupModule() override; + virtual void ShutdownModule() override; +}; diff --git a/Source/EventCenterPlugin/Public/EventSourceActor.h b/Source/EventCenterPlugin/Public/EventSourceActor.h new file mode 100644 index 0000000..0da3807 --- /dev/null +++ b/Source/EventCenterPlugin/Public/EventSourceActor.h @@ -0,0 +1,70 @@ +#pragma once + +// Unreal Core +#include "CoreMinimal.h" +#include "UObject/NoExportTypes.h" + +// RedisPlugin +#include "RedisObject.h" + +// EventCenterPlugin +#include "EventSourceActor.generated.h" + +DECLARE_LOG_CATEGORY_EXTERN(EventSourceLog, Log, All); + +/** + * AEventSourceActor + * + * Manages an underlying Redis pubsub subscription and coordinates dispatch to other actors. + */ + +// NB(bt): "Blueprintable" seems to remove the ability to add BP event nodes. +UCLASS() +class EVENTCENTERPLUGIN_API AEventSourceActor : public AActor +{ + GENERATED_BODY() + +public: + + AEventSourceActor(); + ~AEventSourceActor(); + + /** Redis Hostname */ + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EventCenter") + FString redisHost; + + /** Redis Port */ + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EventCenter") + int32 redisPort = 6379; + + /** Redis Password */ + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EventCenter") + FString redisPassword; + + /** Subscribe to a named Redis PubSub channel. */ + UFUNCTION(BlueprintCallable, Category = "EventCenter") + void Subscribe(const FString& Channel); + + /** Unsubscribe from a named Redis PubSub channel. */ + UFUNCTION(BlueprintCallable, Category = "EventCenter") + void Unsubscribe(const FString& Channel); + + /** I have no idea what do... */ + UPROPERTY(BlueprintAssignable) + FSubscribeReply SubscribeReplyy; + + +protected: + // Called when the game starts or when spawned + virtual void BeginPlay() override; + + virtual void BeginDestroy() override; + +private: + URedisObject* redis; + +public: + // Called every frame + virtual void Tick(float DeltaTime) override; + +};