Implement FlxStreamBuffer and beginnings of ConsoleCommands in unreal

This commit is contained in:
2023-10-24 01:44:09 -04:00
parent 9dc9d31d54
commit 5381b5708a
6 changed files with 106 additions and 219 deletions

View File

@@ -36,28 +36,28 @@ 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 ElxAnimValueType::STRING: {
case SimpleDynamicTag::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 ElxAnimValueType::NUMBER: {
case SimpleDynamicTag::NUMBER: {
FDoubleProperty* fprop = FindFProperty<FDoubleProperty>(uclass, nname);
if (fprop == nullptr) return false;
double* pptr = fprop->ContainerPtrToValuePtr<double>(obj);
*pptr = field.X;
return true;
}
case ElxAnimValueType::BOOLEAN: {
case SimpleDynamicTag::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 ElxAnimValueType::XYZ: {
case SimpleDynamicTag::VECTOR: {
FStructProperty* fprop = FindFProperty<FStructProperty>(uclass, nname);
if (fprop == nullptr) return false;
if (fprop->Struct != TBaseStructure<FVector>::Get()) return false;
@@ -84,7 +84,7 @@ bool FlxAnimationStep::Unpack(const FString& prefix, UObject* into) const {
FlxAnimationField field;
field.Name = "action";
field.Persistent = false;
field.Type = ElxAnimValueType::STRING;
field.Type = SimpleDynamicTag::STRING;
field.S = "idle";
ok &= SetProperty(prefix, into, field);
}
@@ -110,7 +110,7 @@ static FlxAnimationField FindAnimationFieldLL(const FlxAnimationStep& step, std:
return result;
}
}
result.Type = ElxAnimValueType::INVALID;
result.Type = SimpleDynamicTag::UNINITIALIZED;
return result;
}
@@ -122,21 +122,21 @@ static FlxAnimationField FindAnimationField(const FlxAnimationStep& step, const
void FlxAnimationStep::AutoUpdateXYZ(AActor *actor) const {
FlxAnimationField xyz = FindAnimationFieldLL(*this, "xyz");
if (xyz.Type == ElxAnimValueType::XYZ) {
if (xyz.Type == SimpleDynamicTag::VECTOR) {
actor->SetActorLocation(FVector(xyz.X, xyz.Y, xyz.Z));
}
}
void FlxAnimationStep::AutoUpdateFacing(AActor *actor) const {
FlxAnimationField facing = FindAnimationFieldLL(*this, "facing");
if (facing.Type == ElxAnimValueType::NUMBER) {
if (facing.Type == SimpleDynamicTag::NUMBER) {
actor->SetActorRotation(FRotator(0, facing.X, 0));
}
}
void FlxAnimationStep::AutoUpdatePlane(FName *planep) const {
FlxAnimationField plane = FindAnimationFieldLL(*this, "plane");
if (plane.Type == ElxAnimValueType::STRING) {
if (plane.Type == SimpleDynamicTag::STRING) {
FString pname(plane.S.size(), (const UTF8CHAR*)(plane.S.data()));
*planep = FName(pname);
}
@@ -152,13 +152,13 @@ bool UlxAnimationStepLibrary::AnimationStepIsIdle(const FlxAnimationStep &step)
FVector UlxAnimationStepLibrary::AnimationStepGetVector(const FlxAnimationStep& step, const FString& name) {
FlxAnimationField field = FindAnimationField(step, name);
if (field.Type != ElxAnimValueType::XYZ) return FVector(0, 0, 0);
if (field.Type != SimpleDynamicTag::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 != ElxAnimValueType::NUMBER) return 0.0;
if (field.Type != SimpleDynamicTag::NUMBER) return 0.0;
return field.X;
}
@@ -167,58 +167,44 @@ FString UlxAnimationStepLibrary::AnimationStepGetString(const FlxAnimationStep&
return TEXT("idle");
}
FlxAnimationField field = FindAnimationField(step, name);
if (field.Type != ElxAnimValueType::STRING) return TEXT("");
if (field.Type != SimpleDynamicTag::STRING) return TEXT("");
return FString(field.S.size(), (const UTF8CHAR*)(field.S.data()));
}
bool UlxAnimationStepLibrary::AnimationStepGetBool(const FlxAnimationStep& step, const FString& name) {
FlxAnimationField field = FindAnimationField(step, name);
if (field.Type != ElxAnimValueType::BOOLEAN) return false;
if (field.Type != SimpleDynamicTag::BOOLEAN) return false;
return field.X == 1.0;
}
FlxAnimationStepView FlxAnimQueueDecoder::ReadStep() {
FlxAnimationStepView result;
result.Hash = Decoder.read_uint64();
result.Body = Decoder.read_string_view();
return result;
}
uint64 FlxAnimQueueDecoder::PeekHash() {
std::string_view rest = Decoder.GetRest();
uint64 result = Decoder.read_uint64();
Decoder.Reset(rest, false);
return result;
}
FlxAnimationField FlxAnimationStepDecoder::ReadField() {
FlxAnimationField result;
result.Name = Decoder.read_string_view();
result.Persistent = Decoder.read_bool();
result.Type = (ElxAnimValueType)Decoder.read_uint8();
result.Type = (SimpleDynamicTag)Decoder.read_uint8();
switch (result.Type) {
case ElxAnimValueType::STRING: {
case SimpleDynamicTag::STRING: {
result.S = Decoder.read_string_view();
break;
}
case ElxAnimValueType::NUMBER: {
case SimpleDynamicTag::NUMBER: {
result.X = Decoder.read_double();
break;
}
case ElxAnimValueType::BOOLEAN: {
case SimpleDynamicTag::BOOLEAN: {
result.X = Decoder.read_bool() ? 1.0 : 0.0;
break;
}
case ElxAnimValueType::XYZ: {
case SimpleDynamicTag::VECTOR: {
result.X = Decoder.read_double();
result.Y = Decoder.read_double();
result.Z = Decoder.read_double();
break;
}
default: {
Decoder.set_at_eof();
result.Type = ElxAnimValueType::BOOLEAN;
result.X = 0;
Decoder.read_bytes(Decoder.fill());
result.Type = SimpleDynamicTag::UNINITIALIZED;
break;
}
}
@@ -239,16 +225,16 @@ FString FlxAnimationStepDecoder::DebugString(bool injectidle, bool persistentonl
result.Append(FString(field.Name.size(), (const UTF8CHAR*)field.Name.data()));
result.Append(field.Persistent ? TEXT("=") : TEXT(":"));
switch (field.Type) {
case ElxAnimValueType::STRING:
case SimpleDynamicTag::STRING:
result.Append(FString(field.S.size(), (const UTF8CHAR*)field.S.data()));
break;
case ElxAnimValueType::NUMBER:
case SimpleDynamicTag::NUMBER:
result.Appendf(TEXT("%lf"), field.X);
break;
case ElxAnimValueType::BOOLEAN:
case SimpleDynamicTag::BOOLEAN:
result.Append((field.X) == 1.0 ? TEXT("true") : TEXT("false"));
break;
case ElxAnimValueType::XYZ:
case SimpleDynamicTag::VECTOR:
result.Appendf(TEXT("%lf,%lf,%lf"), field.X, field.Y, field.Z);
break;
}
@@ -256,6 +242,20 @@ FString FlxAnimationStepDecoder::DebugString(bool injectidle, bool persistentonl
return result;
}
FlxAnimationStepView FlxAnimQueueDecoder::ReadStep() {
FlxAnimationStepView result;
result.Hash = Decoder.read_uint64();
result.Body = Decoder.read_string_view();
return result;
}
uint64 FlxAnimQueueDecoder::PeekHash() {
int64_t read_count = Decoder.total_reads();
uint64 result = Decoder.read_uint64();
Decoder.unread_to(read_count);
return result;
}
FlxAnimQueueDecoder::FlxAnimQueueDecoder(std::string_view queue) : Decoder(queue) {
SizeLimit = Decoder.read_uint8();
ActualSize = Decoder.read_uint8();