diff --git a/AGENTS.md b/AGENTS.md index 3dea1a8..4de5dc2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -86,7 +86,15 @@ Verification already performed: - `http://127.0.0.1:30000/` serves the custom page. - `PUT http://127.0.0.1:30000/api/proxy` can call `/remote/presets`. - `ApplyToTarget` returns `200`. - - With the Unreal window minimized, a property write plus `ApplyToTarget` still succeeds through the proxy. +- With the Unreal window minimized, a property write plus `ApplyToTarget` still succeeds through the proxy. + +Remote Control parameter persistence: + +- `ALedVolumeRemoteControlActor` saves live Remote Control settings to local config under `[LedVolume.RemoteControl]`. +- In editor this lands in `Saved/Config/WindowsEditor/GameUserSettings.ini`, which is intentionally ignored. +- Settings are loaded in `PostLoad`, `BeginPlay`, and first tick, then applied to the display actor. +- `ApplyToTarget` and `SyncFromTarget` save the current settings immediately. +- Verified by setting `ApplyDebounceSeconds=0.11`, restarting Unreal Editor, and reading the same value back through the Remote Control API. ## Git History Milestones diff --git a/Binaries/Win64/UnrealEditor-ledcube3d.dll b/Binaries/Win64/UnrealEditor-ledcube3d.dll index d9bbf5f..09fa092 100644 Binary files a/Binaries/Win64/UnrealEditor-ledcube3d.dll and b/Binaries/Win64/UnrealEditor-ledcube3d.dll differ diff --git a/Binaries/Win64/UnrealEditor-ledcube3d.pdb b/Binaries/Win64/UnrealEditor-ledcube3d.pdb index 79ce7ff..b2b850d 100644 Binary files a/Binaries/Win64/UnrealEditor-ledcube3d.pdb and b/Binaries/Win64/UnrealEditor-ledcube3d.pdb differ diff --git a/Source/ledcube3d/LedVolumeRemoteControlActor.cpp b/Source/ledcube3d/LedVolumeRemoteControlActor.cpp index b331329..2f4e460 100644 --- a/Source/ledcube3d/LedVolumeRemoteControlActor.cpp +++ b/Source/ledcube3d/LedVolumeRemoteControlActor.cpp @@ -3,12 +3,133 @@ #include "LedVolumeRemoteControlActor.h" #include "EngineUtils.h" +#include "Engine/Texture2D.h" +#include "Engine/VolumeTexture.h" #include "LedVolumeDisplayActor.h" +#include "Misc/ConfigCacheIni.h" #include "UObject/ConstructorHelpers.h" +#include "UObject/SoftObjectPath.h" #if WITH_EDITOR #include "Editor.h" #endif +namespace +{ + const TCHAR* LedRemoteSettingsSection = TEXT("LedVolume.RemoteControl"); + + template + void SaveEnumValue(const TCHAR* Key, EnumType Value) + { + GConfig->SetInt(LedRemoteSettingsSection, Key, static_cast(Value), GGameUserSettingsIni); + } + + template + bool LoadEnumValue(const TCHAR* Key, EnumType& Value) + { + int32 IntValue = 0; + if (!GConfig->GetInt(LedRemoteSettingsSection, Key, IntValue, GGameUserSettingsIni)) + { + return false; + } + Value = static_cast(IntValue); + return true; + } + + void SaveNameValue(const TCHAR* Key, const FName& Value) + { + GConfig->SetString(LedRemoteSettingsSection, Key, *Value.ToString(), GGameUserSettingsIni); + } + + bool LoadNameValue(const TCHAR* Key, FName& Value) + { + FString StringValue; + if (!GConfig->GetString(LedRemoteSettingsSection, Key, StringValue, GGameUserSettingsIni)) + { + return false; + } + Value = FName(*StringValue); + return true; + } + + void SaveColorValue(const TCHAR* Key, const FLinearColor& Value) + { + GConfig->SetString(LedRemoteSettingsSection, Key, *Value.ToString(), GGameUserSettingsIni); + } + + bool LoadColorValue(const TCHAR* Key, FLinearColor& Value) + { + FString StringValue; + if (!GConfig->GetString(LedRemoteSettingsSection, Key, StringValue, GGameUserSettingsIni)) + { + return false; + } + Value.InitFromString(StringValue); + return true; + } + + void SaveVectorValue(const TCHAR* Key, const FVector& Value) + { + GConfig->SetString(LedRemoteSettingsSection, Key, *Value.ToString(), GGameUserSettingsIni); + } + + bool LoadVectorValue(const TCHAR* Key, FVector& Value) + { + FString StringValue; + if (!GConfig->GetString(LedRemoteSettingsSection, Key, StringValue, GGameUserSettingsIni)) + { + return false; + } + Value.InitFromString(StringValue); + return true; + } + + void SaveObjectValue(const TCHAR* Key, const UObject* Value) + { + const FString Path = Value ? FSoftObjectPath(Value).ToString() : FString(); + GConfig->SetString(LedRemoteSettingsSection, Key, *Path, GGameUserSettingsIni); + } + + template + bool LoadObjectValue(const TCHAR* Key, TObjectPtr& Value) + { + FString Path; + if (!GConfig->GetString(LedRemoteSettingsSection, Key, Path, GGameUserSettingsIni)) + { + return false; + } + Value = Path.IsEmpty() ? nullptr : Cast(StaticLoadObject(ObjectType::StaticClass(), nullptr, *Path)); + return true; + } + + template + void SaveObjectArrayValue(const TCHAR* Key, const TArray>& Values) + { + TArray Paths; + Paths.Reserve(Values.Num()); + for (const TObjectPtr& Value : Values) + { + Paths.Add(Value ? FSoftObjectPath(Value).ToString() : FString()); + } + GConfig->SetArray(LedRemoteSettingsSection, Key, Paths, GGameUserSettingsIni); + } + + template + bool LoadObjectArrayValue(const TCHAR* Key, TArray>& Values) + { + TArray Paths; + if (!GConfig->GetArray(LedRemoteSettingsSection, Key, Paths, GGameUserSettingsIni)) + { + return false; + } + Values.Reset(Paths.Num()); + for (const FString& Path : Paths) + { + Values.Add(Path.IsEmpty() ? nullptr : Cast(StaticLoadObject(ObjectType::StaticClass(), nullptr, *Path))); + } + return true; + } +} + ALedVolumeRemoteControlActor::ALedVolumeRemoteControlActor() { PrimaryActorTick.bCanEverTick = true; @@ -37,9 +158,16 @@ ALedVolumeRemoteControlActor::ALedVolumeRemoteControlActor() } } +void ALedVolumeRemoteControlActor::PostLoad() +{ + Super::PostLoad(); + LoadPersistentSettings(); +} + void ALedVolumeRemoteControlActor::BeginPlay() { Super::BeginPlay(); + LoadPersistentSettings(); ApplyToTarget(); } @@ -47,6 +175,8 @@ void ALedVolumeRemoteControlActor::Tick(float DeltaSeconds) { Super::Tick(DeltaSeconds); + LoadPersistentSettings(); + #if WITH_EDITOR MirrorEditorControllerStateForPIE(); #endif @@ -79,12 +209,14 @@ bool ALedVolumeRemoteControlActor::ShouldTickIfViewportsOnly() const void ALedVolumeRemoteControlActor::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) { Super::PostEditChangeProperty(PropertyChangedEvent); + bPersistentSettingsLoaded = true; ApplyToTarget(); } #endif void ALedVolumeRemoteControlActor::ApplyToTarget() { + LoadPersistentSettings(); ClampSettings(); if (CachedTargetActorLabel != TargetActorLabel) { @@ -213,6 +345,7 @@ void ALedVolumeRemoteControlActor::ApplyToTarget() } CacheSettings(); + SavePersistentSettings(); bApplyPending = false; UpdateStatusFromTarget(); } @@ -281,6 +414,7 @@ void ALedVolumeRemoteControlActor::SyncFromTarget() ClampSettings(); CacheSettings(); + SavePersistentSettings(); UpdateStatusFromTarget(); } @@ -626,6 +760,134 @@ bool ALedVolumeRemoteControlActor::HasSettingsChanged() const || CachedEmptyVoxelColor != EmptyVoxelColor; } +void ALedVolumeRemoteControlActor::LoadPersistentSettings() +{ + if (bPersistentSettingsLoaded || !GConfig) + { + return; + } + + bPersistentSettingsLoaded = true; + + GConfig->GetInt(LedRemoteSettingsSection, TEXT("Width"), Width, GGameUserSettingsIni); + GConfig->GetInt(LedRemoteSettingsSection, TEXT("Height"), Height, GGameUserSettingsIni); + GConfig->GetInt(LedRemoteSettingsSection, TEXT("Depth"), Depth, GGameUserSettingsIni); + GConfig->GetFloat(LedRemoteSettingsSection, TEXT("PixelSize"), PixelSize, GGameUserSettingsIni); + GConfig->GetFloat(LedRemoteSettingsSection, TEXT("Spacing"), Spacing, GGameUserSettingsIni); + GConfig->GetInt(LedRemoteSettingsSection, TEXT("PreviewStride"), PreviewStride, GGameUserSettingsIni); + LoadEnumValue(TEXT("GeometryMode"), GeometryMode); + GConfig->GetInt(LedRemoteSettingsSection, TEXT("CabinetCountX"), CabinetCountX, GGameUserSettingsIni); + GConfig->GetInt(LedRemoteSettingsSection, TEXT("CabinetCountZ"), CabinetCountZ, GGameUserSettingsIni); + GConfig->GetInt(LedRemoteSettingsSection, TEXT("DotsPerCabinetX"), DotsPerCabinetX, GGameUserSettingsIni); + GConfig->GetInt(LedRemoteSettingsSection, TEXT("DotsPerCabinetZ"), DotsPerCabinetZ, GGameUserSettingsIni); + GConfig->GetInt(LedRemoteSettingsSection, TEXT("LedsPerString"), LedsPerString, GGameUserSettingsIni); + GConfig->GetFloat(LedRemoteSettingsSection, TEXT("CabinetSizeMm"), CabinetSizeMm, GGameUserSettingsIni); + GConfig->GetFloat(LedRemoteSettingsSection, TEXT("DotPitchMm"), DotPitchMm, GGameUserSettingsIni); + GConfig->GetFloat(LedRemoteSettingsSection, TEXT("PhysicalLedSizeMm"), PhysicalLedSizeMm, GGameUserSettingsIni); + GConfig->GetFloat(LedRemoteSettingsSection, TEXT("WireThicknessMm"), WireThicknessMm, GGameUserSettingsIni); + GConfig->GetFloat(LedRemoteSettingsSection, TEXT("WireOpacity"), WireOpacity, GGameUserSettingsIni); + GConfig->GetFloat(LedRemoteSettingsSection, TEXT("PhysicalJitterMm"), PhysicalJitterMm, GGameUserSettingsIni); + GConfig->GetInt(LedRemoteSettingsSection, TEXT("WireSegmentsPerString"), WireSegmentsPerString, GGameUserSettingsIni); + GConfig->GetInt(LedRemoteSettingsSection, TEXT("PhysicalRandomSeed"), PhysicalRandomSeed, GGameUserSettingsIni); + GConfig->GetBool(LedRemoteSettingsSection, TEXT("bShowCabinets"), bShowCabinets, GGameUserSettingsIni); + GConfig->GetBool(LedRemoteSettingsSection, TEXT("bShowWires"), bShowWires, GGameUserSettingsIni); + GConfig->GetBool(LedRemoteSettingsSection, TEXT("bShowBottomFixers"), bShowBottomFixers, GGameUserSettingsIni); + LoadObjectValue(TEXT("CabinetMaterial"), CabinetMaterial); + LoadObjectValue(TEXT("WireMaterial"), WireMaterial); + LoadObjectValue(TEXT("BottomFixerMaterial"), BottomFixerMaterial); + LoadEnumValue(TEXT("VoxelShape"), VoxelShape); + LoadObjectValue(TEXT("CustomVoxelMesh"), CustomVoxelMesh); + LoadObjectValue(TEXT("LedMaterial"), LedMaterial); + LoadNameValue(TEXT("TargetActorLabel"), TargetActorLabel); + GConfig->GetFloat(LedRemoteSettingsSection, TEXT("Brightness"), Brightness, GGameUserSettingsIni); + GConfig->GetFloat(LedRemoteSettingsSection, TEXT("Gamma"), Gamma, GGameUserSettingsIni); + LoadColorValue(TEXT("SolidColor"), SolidColor); + LoadEnumValue(TEXT("SourceMode"), SourceMode); + LoadEnumValue(TEXT("TestPattern"), TestPattern); + GConfig->GetFloat(LedRemoteSettingsSection, TEXT("AnimationSpeed"), AnimationSpeed, GGameUserSettingsIni); + GConfig->GetBool(LedRemoteSettingsSection, TEXT("bAnimateInEditor"), bAnimateInEditor, GGameUserSettingsIni); + GConfig->GetBool(LedRemoteSettingsSection, TEXT("bUseGpuTestPattern"), bUseGpuTestPattern, GGameUserSettingsIni); + GConfig->GetInt(LedRemoteSettingsSection, TEXT("MaxEditorInstances"), MaxEditorInstances, GGameUserSettingsIni); + GConfig->GetInt(LedRemoteSettingsSection, TEXT("MaxRuntimeInstances"), MaxRuntimeInstances, GGameUserSettingsIni); + GConfig->GetInt(LedRemoteSettingsSection, TEXT("ColorUpdatesPerFrame"), ColorUpdatesPerFrame, GGameUserSettingsIni); + GConfig->GetFloat(LedRemoteSettingsSection, TEXT("ApplyDebounceSeconds"), ApplyDebounceSeconds, GGameUserSettingsIni); + LoadObjectArrayValue(TEXT("VolumeTextureFrames"), VolumeTextureFrames); + LoadObjectArrayValue(TEXT("TextureSliceFrames"), TextureSliceFrames); + + FString VoxelizedSublevelPath; + if (GConfig->GetString(LedRemoteSettingsSection, TEXT("VoxelizedSublevel"), VoxelizedSublevelPath, GGameUserSettingsIni)) + { + VoxelizedSublevel = TSoftObjectPtr(FSoftObjectPath(VoxelizedSublevelPath)); + } + LoadVectorValue(TEXT("CaptureBoundsExtent"), CaptureBoundsExtent); + GConfig->GetBool(LedRemoteSettingsSection, TEXT("bUseActorBoundsAsCaptureVolume"), bUseActorBoundsAsCaptureVolume, GGameUserSettingsIni); + LoadNameValue(TEXT("SourceActorTag"), SourceActorTag); + LoadColorValue(TEXT("EmptyVoxelColor"), EmptyVoxelColor); + + ClampSettings(); + bApplyPending = true; + PendingApplySeconds = 0.0f; +} + +void ALedVolumeRemoteControlActor::SavePersistentSettings() const +{ + if (!GConfig) + { + return; + } + + GConfig->SetInt(LedRemoteSettingsSection, TEXT("Width"), Width, GGameUserSettingsIni); + GConfig->SetInt(LedRemoteSettingsSection, TEXT("Height"), Height, GGameUserSettingsIni); + GConfig->SetInt(LedRemoteSettingsSection, TEXT("Depth"), Depth, GGameUserSettingsIni); + GConfig->SetFloat(LedRemoteSettingsSection, TEXT("PixelSize"), PixelSize, GGameUserSettingsIni); + GConfig->SetFloat(LedRemoteSettingsSection, TEXT("Spacing"), Spacing, GGameUserSettingsIni); + GConfig->SetInt(LedRemoteSettingsSection, TEXT("PreviewStride"), PreviewStride, GGameUserSettingsIni); + SaveEnumValue(TEXT("GeometryMode"), GeometryMode); + GConfig->SetInt(LedRemoteSettingsSection, TEXT("CabinetCountX"), CabinetCountX, GGameUserSettingsIni); + GConfig->SetInt(LedRemoteSettingsSection, TEXT("CabinetCountZ"), CabinetCountZ, GGameUserSettingsIni); + GConfig->SetInt(LedRemoteSettingsSection, TEXT("DotsPerCabinetX"), DotsPerCabinetX, GGameUserSettingsIni); + GConfig->SetInt(LedRemoteSettingsSection, TEXT("DotsPerCabinetZ"), DotsPerCabinetZ, GGameUserSettingsIni); + GConfig->SetInt(LedRemoteSettingsSection, TEXT("LedsPerString"), LedsPerString, GGameUserSettingsIni); + GConfig->SetFloat(LedRemoteSettingsSection, TEXT("CabinetSizeMm"), CabinetSizeMm, GGameUserSettingsIni); + GConfig->SetFloat(LedRemoteSettingsSection, TEXT("DotPitchMm"), DotPitchMm, GGameUserSettingsIni); + GConfig->SetFloat(LedRemoteSettingsSection, TEXT("PhysicalLedSizeMm"), PhysicalLedSizeMm, GGameUserSettingsIni); + GConfig->SetFloat(LedRemoteSettingsSection, TEXT("WireThicknessMm"), WireThicknessMm, GGameUserSettingsIni); + GConfig->SetFloat(LedRemoteSettingsSection, TEXT("WireOpacity"), WireOpacity, GGameUserSettingsIni); + GConfig->SetFloat(LedRemoteSettingsSection, TEXT("PhysicalJitterMm"), PhysicalJitterMm, GGameUserSettingsIni); + GConfig->SetInt(LedRemoteSettingsSection, TEXT("WireSegmentsPerString"), WireSegmentsPerString, GGameUserSettingsIni); + GConfig->SetInt(LedRemoteSettingsSection, TEXT("PhysicalRandomSeed"), PhysicalRandomSeed, GGameUserSettingsIni); + GConfig->SetBool(LedRemoteSettingsSection, TEXT("bShowCabinets"), bShowCabinets, GGameUserSettingsIni); + GConfig->SetBool(LedRemoteSettingsSection, TEXT("bShowWires"), bShowWires, GGameUserSettingsIni); + GConfig->SetBool(LedRemoteSettingsSection, TEXT("bShowBottomFixers"), bShowBottomFixers, GGameUserSettingsIni); + SaveObjectValue(TEXT("CabinetMaterial"), CabinetMaterial); + SaveObjectValue(TEXT("WireMaterial"), WireMaterial); + SaveObjectValue(TEXT("BottomFixerMaterial"), BottomFixerMaterial); + SaveEnumValue(TEXT("VoxelShape"), VoxelShape); + SaveObjectValue(TEXT("CustomVoxelMesh"), CustomVoxelMesh); + SaveObjectValue(TEXT("LedMaterial"), LedMaterial); + SaveNameValue(TEXT("TargetActorLabel"), TargetActorLabel); + GConfig->SetFloat(LedRemoteSettingsSection, TEXT("Brightness"), Brightness, GGameUserSettingsIni); + GConfig->SetFloat(LedRemoteSettingsSection, TEXT("Gamma"), Gamma, GGameUserSettingsIni); + SaveColorValue(TEXT("SolidColor"), SolidColor); + SaveEnumValue(TEXT("SourceMode"), SourceMode); + SaveEnumValue(TEXT("TestPattern"), TestPattern); + GConfig->SetFloat(LedRemoteSettingsSection, TEXT("AnimationSpeed"), AnimationSpeed, GGameUserSettingsIni); + GConfig->SetBool(LedRemoteSettingsSection, TEXT("bAnimateInEditor"), bAnimateInEditor, GGameUserSettingsIni); + GConfig->SetBool(LedRemoteSettingsSection, TEXT("bUseGpuTestPattern"), bUseGpuTestPattern, GGameUserSettingsIni); + GConfig->SetInt(LedRemoteSettingsSection, TEXT("MaxEditorInstances"), MaxEditorInstances, GGameUserSettingsIni); + GConfig->SetInt(LedRemoteSettingsSection, TEXT("MaxRuntimeInstances"), MaxRuntimeInstances, GGameUserSettingsIni); + GConfig->SetInt(LedRemoteSettingsSection, TEXT("ColorUpdatesPerFrame"), ColorUpdatesPerFrame, GGameUserSettingsIni); + GConfig->SetFloat(LedRemoteSettingsSection, TEXT("ApplyDebounceSeconds"), ApplyDebounceSeconds, GGameUserSettingsIni); + SaveObjectArrayValue(TEXT("VolumeTextureFrames"), VolumeTextureFrames); + SaveObjectArrayValue(TEXT("TextureSliceFrames"), TextureSliceFrames); + GConfig->SetString(LedRemoteSettingsSection, TEXT("VoxelizedSublevel"), *VoxelizedSublevel.ToSoftObjectPath().ToString(), GGameUserSettingsIni); + SaveVectorValue(TEXT("CaptureBoundsExtent"), CaptureBoundsExtent); + GConfig->SetBool(LedRemoteSettingsSection, TEXT("bUseActorBoundsAsCaptureVolume"), bUseActorBoundsAsCaptureVolume, GGameUserSettingsIni); + SaveNameValue(TEXT("SourceActorTag"), SourceActorTag); + SaveColorValue(TEXT("EmptyVoxelColor"), EmptyVoxelColor); + GConfig->Flush(false, GGameUserSettingsIni); +} + void ALedVolumeRemoteControlActor::UpdateStatusFromTarget() { if (const ALedVolumeDisplayActor* Target = GetTargetDisplay()) diff --git a/Source/ledcube3d/LedVolumeRemoteControlActor.h b/Source/ledcube3d/LedVolumeRemoteControlActor.h index b447654..cd3353e 100644 --- a/Source/ledcube3d/LedVolumeRemoteControlActor.h +++ b/Source/ledcube3d/LedVolumeRemoteControlActor.h @@ -22,6 +22,7 @@ class LEDCUBE3D_API ALedVolumeRemoteControlActor : public AActor public: ALedVolumeRemoteControlActor(); + virtual void PostLoad() override; virtual void BeginPlay() override; virtual void Tick(float DeltaSeconds) override; #if WITH_EDITOR @@ -333,7 +334,11 @@ private: void CacheSettings(); bool HasSettingsChanged() const; void UpdateStatusFromTarget(); + void LoadPersistentSettings(); + void SavePersistentSettings() const; #if WITH_EDITOR void MirrorEditorControllerStateForPIE(); #endif + + bool bPersistentSettingsLoaded = false; };