More work on anim queues
This commit is contained in:
@@ -29,9 +29,12 @@ static bool ClearProperties(const FString& prefix, UObject* obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool SetProperty(const FString& name, UObject* obj, const FlxAnimationField& field) {
|
||||
#pragma optimize("", off)
|
||||
|
||||
static bool SetProperty(const FString& prefix, UObject* obj, const FlxAnimationField& field) {
|
||||
UClass* uclass = obj->GetClass();
|
||||
FName nname(name);
|
||||
FString sname(field.Name.size(), (const UTF8CHAR*)field.Name.data());
|
||||
FName nname(prefix + sname);
|
||||
switch (field.Type) {
|
||||
case ElxAnimValueType::STRING: {
|
||||
FStrProperty* fprop = FindFProperty<FStrProperty>(uclass, nname);
|
||||
@@ -66,29 +69,35 @@ static bool SetProperty(const FString& name, UObject* obj, const FlxAnimationFie
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FlxAnimationStep::Unpack(const FString& prefix, UObject* into, bool preclear) const {
|
||||
#pragma optimize("", off)
|
||||
bool FlxAnimationStep::Unpack(const FString& prefix, UObject* into) const {
|
||||
UClass* uclass = into->GetClass();
|
||||
std::string_view body((const char*)(Body.GetData()), Body.Num());
|
||||
FlxAnimationStepDecoder decoder(body);
|
||||
bool ok = true;
|
||||
if (preclear) {
|
||||
ok &= ClearProperties(prefix, into);
|
||||
}
|
||||
bool ok = ClearProperties(prefix, into);
|
||||
while (!decoder.AtEOF()) {
|
||||
FlxAnimationField field = decoder.ReadField();
|
||||
FString sname(field.Name.size(), (const UTF8CHAR*)field.Name.data());
|
||||
ok &= SetProperty(prefix + sname, into, field);
|
||||
if (Finished && !field.Persistent) continue;
|
||||
ok &= SetProperty(prefix, into, field);
|
||||
}
|
||||
if (Finished) {
|
||||
FlxAnimationField field;
|
||||
field.Name = "action";
|
||||
field.Persistent = false;
|
||||
field.Type = ElxAnimValueType::STRING;
|
||||
field.S = "idle";
|
||||
ok &= SetProperty(prefix, into, field);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
FString UlxAnimationStepLibrary::AnimationStepDebugString(const FlxAnimationStep& step) {
|
||||
std::string_view body((const char*)(step.Body.GetData()), step.Body.Num());
|
||||
return FlxAnimationStepDecoder::DebugString(step.Hash, body);
|
||||
return FlxAnimationStepDecoder::DebugString(step.Finished, step.Finished, step.Hash, body);
|
||||
}
|
||||
|
||||
void UlxAnimationStepLibrary::UnpackAnimationStep(UObject* into, const FlxAnimationStep& step, const FString& prefix) {
|
||||
step.Unpack(prefix, into, true);
|
||||
step.Unpack(prefix, into);
|
||||
}
|
||||
|
||||
static FlxAnimationField FindAnimationFieldLL(const FlxAnimationStep& step, std::string_view name) {
|
||||
@@ -133,6 +142,10 @@ void FlxAnimationStep::AutoUpdatePlane(FName *planep) const {
|
||||
}
|
||||
}
|
||||
|
||||
bool UlxAnimationStepLibrary::AnimationStepEqual(const FlxAnimationStep &stepa, const FlxAnimationStep &stepb) {
|
||||
return (stepa.Finished == stepb.Finished) && (stepa.Hash == stepb.Hash);
|
||||
}
|
||||
|
||||
bool UlxAnimationStepLibrary::AnimationStepIsIdle(const FlxAnimationStep &step) {
|
||||
return step.Finished;
|
||||
}
|
||||
@@ -149,8 +162,10 @@ double UlxAnimationStepLibrary::AnimationStepGetFloat(const FlxAnimationStep& st
|
||||
return field.X;
|
||||
}
|
||||
|
||||
#pragma optimize("", off)
|
||||
FString UlxAnimationStepLibrary::AnimationStepGetString(const FlxAnimationStep& step, const FString& name) {
|
||||
if (step.Finished && (name == TEXT("action"))) {
|
||||
return TEXT("idle");
|
||||
}
|
||||
FlxAnimationField field = FindAnimationField(step, name);
|
||||
if (field.Type != ElxAnimValueType::STRING) return TEXT("");
|
||||
return FString(field.S.size(), (const UTF8CHAR*)(field.S.data()));
|
||||
@@ -210,12 +225,16 @@ FlxAnimationField FlxAnimationStepDecoder::ReadField() {
|
||||
return result;
|
||||
}
|
||||
|
||||
FString FlxAnimationStepDecoder::DebugString(uint64 hash, std::string_view body) {
|
||||
FString FlxAnimationStepDecoder::DebugString(bool injectidle, bool persistentonly, uint64 hash, std::string_view body) {
|
||||
FString result;
|
||||
FlxAnimationStepDecoder decoder(body);
|
||||
result.Appendf(TEXT("Hash=%016llx"), hash);
|
||||
if (injectidle) {
|
||||
result.Appendf(TEXT(" action=idle"));
|
||||
}
|
||||
while (!decoder.AtEOF()) {
|
||||
FlxAnimationField field = decoder.ReadField();
|
||||
if (persistentonly && !field.Persistent) continue;
|
||||
result.Append(TEXT(" "));
|
||||
result.Append(FString(field.Name.size(), (const UTF8CHAR*)field.Name.data()));
|
||||
result.Append(field.Persistent ? TEXT("=") : TEXT(":"));
|
||||
@@ -247,7 +266,7 @@ FString FlxAnimQueueDecoder::DebugString(std::string_view queue) {
|
||||
FlxAnimQueueDecoder decoder(queue);
|
||||
while (!decoder.AtEOF()) {
|
||||
FlxAnimationStepView step = decoder.ReadStep();
|
||||
FString stepdebug = FlxAnimationStepDecoder::DebugString(step.Hash, step.Body);
|
||||
FString stepdebug = FlxAnimationStepDecoder::DebugString(false, false, step.Hash, step.Body);
|
||||
result.Appendf(TEXT("%s\n"), *stepdebug);
|
||||
}
|
||||
return result;
|
||||
@@ -339,6 +358,7 @@ void FlxAnimTracker::Update(std::string_view encqueue) {
|
||||
while (!newsteps.IsEmpty()) {
|
||||
FlxAnimationStepView step = newsteps.Pop();
|
||||
AQ.EmplaceLast(step.Hash, step.Body);
|
||||
|
||||
}
|
||||
|
||||
// If there are too many animations in AQ, discard
|
||||
@@ -357,10 +377,13 @@ void FlxAnimTracker::Update(std::string_view encqueue) {
|
||||
}
|
||||
|
||||
FlxAnimationStep FlxAnimTracker::GetCurrentAnimation() {
|
||||
FlxAnimationStep result;
|
||||
for (int i = 0; i < AQ.Num(); i++) {
|
||||
if (!AQ[i].Finished) {
|
||||
return AQ[i];
|
||||
}
|
||||
}
|
||||
return AQ.Last();
|
||||
result = AQ.Last();
|
||||
result.Hash = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user