Persist remote control settings

This commit is contained in:
krustophski 2026-08-07 04:26:01 +03:00
parent 021ef9409d
commit a17866efcd
5 changed files with 276 additions and 1 deletions

View file

@ -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

View file

@ -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 <typename EnumType>
void SaveEnumValue(const TCHAR* Key, EnumType Value)
{
GConfig->SetInt(LedRemoteSettingsSection, Key, static_cast<int32>(Value), GGameUserSettingsIni);
}
template <typename EnumType>
bool LoadEnumValue(const TCHAR* Key, EnumType& Value)
{
int32 IntValue = 0;
if (!GConfig->GetInt(LedRemoteSettingsSection, Key, IntValue, GGameUserSettingsIni))
{
return false;
}
Value = static_cast<EnumType>(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 <typename ObjectType>
bool LoadObjectValue(const TCHAR* Key, TObjectPtr<ObjectType>& Value)
{
FString Path;
if (!GConfig->GetString(LedRemoteSettingsSection, Key, Path, GGameUserSettingsIni))
{
return false;
}
Value = Path.IsEmpty() ? nullptr : Cast<ObjectType>(StaticLoadObject(ObjectType::StaticClass(), nullptr, *Path));
return true;
}
template <typename ObjectType>
void SaveObjectArrayValue(const TCHAR* Key, const TArray<TObjectPtr<ObjectType>>& Values)
{
TArray<FString> Paths;
Paths.Reserve(Values.Num());
for (const TObjectPtr<ObjectType>& Value : Values)
{
Paths.Add(Value ? FSoftObjectPath(Value).ToString() : FString());
}
GConfig->SetArray(LedRemoteSettingsSection, Key, Paths, GGameUserSettingsIni);
}
template <typename ObjectType>
bool LoadObjectArrayValue(const TCHAR* Key, TArray<TObjectPtr<ObjectType>>& Values)
{
TArray<FString> 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<ObjectType>(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<UWorld>(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())

View file

@ -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;
};