Code cleanup and refactoring.

This commit is contained in:
2026-02-09 13:54:00 -05:00
parent 56765fdc16
commit db35967fb9
23 changed files with 271 additions and 275 deletions

View File

@@ -1,4 +1,5 @@
#include "Common.h"
#include "AnimQueue.h"
#include "UtilityLibrary.h"
#include "GameFramework/Actor.h"
@@ -6,7 +7,6 @@
#include "Components/StaticMeshComponent.h"
#include "Components/SkeletalMeshComponent.h"
#include "AssetLookup.h"
#include "LuprexGameModeBase.h"
#include "Materials/MaterialInstanceDynamic.h"
#include <iostream>
@@ -42,35 +42,35 @@ static bool SetProperty(const FString& prefix, UObject* obj, const FlxAnimationF
FString sname(field.Name.size(), (const UTF8CHAR*)field.Name.data());
FName nname(prefix + sname);
switch (field.Type) {
case SimpleDynamicTag::STRING: {
case LuaValueType::STRING: {
FStrProperty* fprop = FindFProperty<FStrProperty>(uclass, nname);
if (fprop == nullptr) return false;
FString* pptr = fprop->ContainerPtrToValuePtr<FString>(obj);
*pptr = FString(field.S.size(), (const UTF8CHAR*)field.S.data());
return true;
}
case SimpleDynamicTag::TOKEN: {
case LuaValueType::TOKEN: {
FNameProperty* fprop = FindFProperty<FNameProperty>(uclass, nname);
if (fprop == nullptr) return false;
FName* pptr = fprop->ContainerPtrToValuePtr<FName>(obj);
*pptr = FName(field.S.size(), (const UTF8CHAR*)field.S.data(), FNAME_Add);
return true;
}
case SimpleDynamicTag::NUMBER: {
case LuaValueType::NUMBER: {
FDoubleProperty* fprop = FindFProperty<FDoubleProperty>(uclass, nname);
if (fprop == nullptr) return false;
double* pptr = fprop->ContainerPtrToValuePtr<double>(obj);
*pptr = field.X;
return true;
}
case SimpleDynamicTag::BOOLEAN: {
case LuaValueType::BOOLEAN: {
FBoolProperty* fprop = FindFProperty<FBoolProperty>(uclass, nname);
if (fprop == nullptr) return false;
uint8* pptr = fprop->ContainerPtrToValuePtr<uint8>(obj);
fprop->SetPropertyValue(pptr, (field.X == 1.0));
return true;
}
case SimpleDynamicTag::VECTOR: {
case LuaValueType::VECTOR: {
FStructProperty* fprop = FindFProperty<FStructProperty>(uclass, nname);
if (fprop == nullptr) return false;
if (fprop->Struct != TBaseStructure<FVector>::Get()) return false;
@@ -128,14 +128,14 @@ void UlxAnimationStepLibrary::UnpackAnimationStep(bool &bChanged, FString &Actio
FlxAnimationField actionfield;
actionfield.Name = "action";
actionfield.Persistent = false;
actionfield.Type = SimpleDynamicTag::STRING;
actionfield.Type = LuaValueType::STRING;
actionfield.S = "unknown";
// Decode everything. If an action field is found, save it for later.
ClearProperties(prefix, target, stepproperty);
while (!decoder.AtEOF()) {
FlxAnimationField field = decoder.ReadField();
if ((field.Type == SimpleDynamicTag::STRING) && (field.Name == "action")) {
if ((field.Type == LuaValueType::STRING) && (field.Name == "action")) {
actionfield.S = field.S;
continue;
}
@@ -174,7 +174,7 @@ static FlxAnimationField FindAnimationFieldLL(const FlxAnimationStep& step, std:
return result;
}
}
result.Type = SimpleDynamicTag::UNINITIALIZED;
result.Type = LuaValueType::UNINITIALIZED;
return result;
}
@@ -186,21 +186,21 @@ static FlxAnimationField FindAnimationField(const FlxAnimationStep& step, const
void FlxAnimationStep::AutoUpdateXYZ(AActor *actor) const {
FlxAnimationField xyz = FindAnimationFieldLL(*this, "xyz");
if (xyz.Type == SimpleDynamicTag::VECTOR) {
if (xyz.Type == LuaValueType::VECTOR) {
actor->SetActorLocation(FVector(xyz.X, xyz.Y, xyz.Z));
}
}
void FlxAnimationStep::AutoUpdateFacing(AActor *actor) const {
FlxAnimationField facing = FindAnimationFieldLL(*this, "facing");
if (facing.Type == SimpleDynamicTag::NUMBER) {
if (facing.Type == LuaValueType::NUMBER) {
actor->SetActorRotation(FRotator(0, facing.X, 0));
}
}
void FlxAnimationStep::AutoUpdatePlane(FName *planep) const {
FlxAnimationField plane = FindAnimationFieldLL(*this, "plane");
if (plane.Type == SimpleDynamicTag::STRING) {
if (plane.Type == LuaValueType::STRING) {
FString pname(plane.S.size(), (const UTF8CHAR*)(plane.S.data()));
*planep = FName(pname);
}
@@ -216,13 +216,13 @@ bool UlxAnimationStepLibrary::AnimationStepIsIdle(const FlxAnimationStep &step)
FVector UlxAnimationStepLibrary::AnimationStepGetVector(const FlxAnimationStep& step, const FString& name) {
FlxAnimationField field = FindAnimationField(step, name);
if (field.Type != SimpleDynamicTag::VECTOR) return FVector(0, 0, 0);
if (field.Type != LuaValueType::VECTOR) return FVector(0, 0, 0);
return FVector(field.X, field.Y, field.Z);
}
double UlxAnimationStepLibrary::AnimationStepGetFloat(const FlxAnimationStep& step, const FString& name) {
FlxAnimationField field = FindAnimationField(step, name);
if (field.Type != SimpleDynamicTag::NUMBER) return 0.0;
if (field.Type != LuaValueType::NUMBER) return 0.0;
return field.X;
}
@@ -231,19 +231,19 @@ FString UlxAnimationStepLibrary::AnimationStepGetString(const FlxAnimationStep&
return TEXT("idle");
}
FlxAnimationField field = FindAnimationField(step, name);
if (field.Type != SimpleDynamicTag::STRING) return TEXT("");
if (field.Type != LuaValueType::STRING) return TEXT("");
return FString(field.S.size(), (const UTF8CHAR*)(field.S.data()));
}
FName UlxAnimationStepLibrary::AnimationStepGetName(const FlxAnimationStep& step, const FString& name) {
FlxAnimationField field = FindAnimationField(step, name);
if (field.Type != SimpleDynamicTag::TOKEN) return FName();
if (field.Type != LuaValueType::TOKEN) return FName();
return FName(field.S.size(), (const UTF8CHAR*)(field.S.data()), FNAME_Add);
}
bool UlxAnimationStepLibrary::AnimationStepGetBool(const FlxAnimationStep& step, const FString& name) {
FlxAnimationField field = FindAnimationField(step, name);
if (field.Type != SimpleDynamicTag::BOOLEAN) return false;
if (field.Type != LuaValueType::BOOLEAN) return false;
return field.X == 1.0;
}
@@ -252,25 +252,25 @@ FlxAnimationField FlxAnimationStepDecoder::ReadField() {
FlxAnimationField result;
result.Name = Decoder.read_string_view();
result.Persistent = Decoder.read_bool();
result.Type = (SimpleDynamicTag)Decoder.read_uint8();
result.Type = (LuaValueType)Decoder.read_uint8();
switch (result.Type) {
case SimpleDynamicTag::STRING: {
case LuaValueType::STRING: {
result.S = Decoder.read_string_view();
break;
}
case SimpleDynamicTag::TOKEN: {
case LuaValueType::TOKEN: {
result.S = Decoder.read_string_view();
break;
}
case SimpleDynamicTag::NUMBER: {
case LuaValueType::NUMBER: {
result.X = Decoder.read_double();
break;
}
case SimpleDynamicTag::BOOLEAN: {
case LuaValueType::BOOLEAN: {
result.X = Decoder.read_bool() ? 1.0 : 0.0;
break;
}
case SimpleDynamicTag::VECTOR: {
case LuaValueType::VECTOR: {
result.X = Decoder.read_double();
result.Y = Decoder.read_double();
result.Z = Decoder.read_double();
@@ -278,7 +278,7 @@ FlxAnimationField FlxAnimationStepDecoder::ReadField() {
}
default: {
Decoder.read_bytes(Decoder.fill());
result.Type = SimpleDynamicTag::UNINITIALIZED;
result.Type = LuaValueType::UNINITIALIZED;
break;
}
}
@@ -298,19 +298,19 @@ FString FlxAnimationStepDecoder::DebugString(bool finished, int64 hash, std::str
result.Append(FString(field.Name.size(), (const UTF8CHAR*)field.Name.data()));
result.Append(field.Persistent ? TEXT("=") : TEXT(":"));
switch (field.Type) {
case SimpleDynamicTag::STRING:
case LuaValueType::STRING:
result.Append(FString(field.S.size(), (const UTF8CHAR*)field.S.data()));
break;
case SimpleDynamicTag::TOKEN:
case LuaValueType::TOKEN:
result.Appendf(TEXT("[%s]"), *FString(field.S.size(), (const UTF8CHAR*)field.S.data()));
break;
case SimpleDynamicTag::NUMBER:
case LuaValueType::NUMBER:
result.Appendf(TEXT("%lf"), field.X);
break;
case SimpleDynamicTag::BOOLEAN:
case LuaValueType::BOOLEAN:
result.Append((field.X) == 1.0 ? TEXT("true") : TEXT("false"));
break;
case SimpleDynamicTag::VECTOR:
case LuaValueType::VECTOR:
result.Appendf(TEXT("%lf,%lf,%lf"), field.X, field.Y, field.Z);
break;
}
@@ -557,9 +557,9 @@ void UlxAnimationStepLibrary::AnimationStepApplyMaterials(const FlxAnimationStep
if (field.Name.substr(0, 4) != "mat_") continue;
std::string_view suffix = field.Name.substr(4);
FName paramName(suffix.size(), (const UTF8CHAR*)suffix.data());
if (field.Type == SimpleDynamicTag::VECTOR) {
if (field.Type == LuaValueType::VECTOR) {
VectorParams.Add(paramName, FVector(field.X, field.Y, field.Z));
} else if (field.Type == SimpleDynamicTag::NUMBER) {
} else if (field.Type == LuaValueType::NUMBER) {
ScalarParams.Add(paramName, (float)field.X);
}
}
@@ -658,13 +658,12 @@ void UlxAnimationStepLibrary::AnimationStepApplyMesh(const FlxAnimationStep& ste
StaticComp->SetStaticMesh(NewMesh);
}
} else if (USkeletalMeshComponent* SkelComp = Cast<USkeletalMeshComponent>(MeshComp)) {
// TODO: Skeletal mesh support
// USkeletalMesh* NewMesh = nullptr;
// UlxAssetLookup::LoadSkeletalMeshAsset(NewMesh, actor, MeshName, true);
// if (NewMesh == nullptr) return;
// if (SkelComp->GetSkeletalMeshAsset() != NewMesh) {
// SkelComp->SetSkeletalMeshAsset(NewMesh);
// }
USkeletalMesh* NewMesh = nullptr;
UlxAssetLookup::LoadSkeletalMeshAsset(NewMesh, actor, MeshName, true);
if (NewMesh == nullptr) return;
if (SkelComp->GetSkeletalMeshAsset() != NewMesh) {
SkelComp->SetSkeletalMeshAsset(NewMesh);
}
} else {
UE_LOG(LogLuprexIntegration, Error, TEXT("AnimationStepApplyMesh: Actor %s has unsupported mesh component type"), *actor->GetName());
}