Support for StartAnimation,WarpToFinal,BlendToFinal

This commit is contained in:
2023-09-15 15:44:01 -04:00
parent cd3c82f2c4
commit fb65d23230
5 changed files with 124 additions and 78 deletions

View File

@@ -14,19 +14,19 @@ FlxAnimField FlxAnimStepDecoder::ReadField() {
result.Persistent = Decoder.read_bool();
result.Type = (ElxAnimValueType)Decoder.read_uint8();
switch (result.Type) {
case T_STRING: {
case ElxAnimValueType::STRING: {
result.S = Decoder.read_string_view();
break;
}
case T_NUMBER: {
case ElxAnimValueType::NUMBER: {
result.X = Decoder.read_double();
break;
}
case T_BOOLEAN: {
case ElxAnimValueType::BOOLEAN: {
result.X = Decoder.read_bool() ? 1.0 : 0.0;
break;
}
case T_XYZ: {
case ElxAnimValueType::XYZ: {
result.X = Decoder.read_double();
result.Y = Decoder.read_double();
result.Z = Decoder.read_double();
@@ -34,7 +34,7 @@ FlxAnimField FlxAnimStepDecoder::ReadField() {
}
default: {
Decoder.set_at_eof();
result.Type = T_BOOLEAN;
result.Type = ElxAnimValueType::BOOLEAN;
result.X = 0;
break;
}
@@ -65,16 +65,16 @@ FString FlxAnimStepDecoder::DebugString(const FlxAnimStep& step) {
result.Append(FString(field.Name.size(), (const UTF8CHAR*)field.Name.data()));
result.Append(field.Persistent ? TEXT("=") : TEXT(":"));
switch (field.Type) {
case ElxAnimValueType::T_STRING:
case ElxAnimValueType::STRING:
result.Append(FString(field.S.size(), (const UTF8CHAR*)field.S.data()));
break;
case ElxAnimValueType::T_NUMBER:
case ElxAnimValueType::NUMBER:
result.Appendf(TEXT("%lf"), field.X);
break;
case ElxAnimValueType::T_BOOLEAN:
case ElxAnimValueType::BOOLEAN:
result.Append((field.X) == 1.0 ? TEXT("true") : TEXT("false"));
break;
case ElxAnimValueType::T_XYZ:
case ElxAnimValueType::XYZ:
result.Appendf(TEXT("%lf,%lf,%lf"), field.X, field.Y, field.Z);
break;
}
@@ -84,33 +84,12 @@ FString FlxAnimStepDecoder::DebugString(const FlxAnimStep& step) {
}
//// Our own copy of the animation queue. We only
//// store the hashes, not the steps. The First element
//// of the queue is the oldest item.
////
//TDeque<FlxAnimStoredStep> AQ;
//// The sequence number of the first item in AQ.
////
//int32 FirstSeqno;
//// Map from hash to sequence number.
////
//TMap<uint64, int32> HashToSeqno;
//// The sequence number of the first unstarted animation.
////
//int32 UnstartedSeqno;
//// Array of recently-aborted hash values.
//TArray<uint64> AbortedHashes;
FlxAnimTracker::FlxAnimTracker() {
AQ.Empty();
FirstSeqno = 0;
HashToSeqno.Empty();
UnstartedSeqno = 0;
PlaybackMode = ElxAnimPlaybackMode::INVALID;
AbortedHashes.Empty();
}
@@ -157,18 +136,34 @@ void FlxAnimTracker::Update(std::string_view encqueue) {
}
}
// Abort all animations after the most recent matching
// record. Animations are aborted in most-recent-first order.
//
int32 nabort = (FirstSeqno + AQ.Num()) - (matchingseqno + 1);
check((nabort >= 0) && (nabort <= AQ.Num()));
for (int32 i = 0; i < nabort; i++) {
// Remove all animations after the most recent matching
// record. If we remove a 'started' animation, add that
// animation to the list of aborted animations.
//
int32 nremove = (FirstSeqno + AQ.Num()) - (matchingseqno + 1);
check((nremove >= 0) && (nremove <= AQ.Num()));
for (int32 i = 0; i < nremove; i++) {
uint64 lasthash = AQ.Last().Hash;
int32 seqno = FirstSeqno + AQ.Num() - 1;
HashToSeqno.Remove(lasthash);
AbortedHashes.Emplace(lasthash);
if (seqno < UnstartedSeqno) {
AbortedHashes.Emplace(lasthash);
}
AQ.PopLast();
}
// If we aborted a 'started' animation, we have to fix
// up the Unstarted animation pointer.
//
// Note: this could leave the Unstarted pointer at
// seqno less than FirstSeqno. We will fix that state
// of affairs up later.
//
if (UnstartedSeqno > (FirstSeqno + AQ.Num())) {
UnstartedSeqno = matchingseqno;
PlaybackMode = ElxAnimPlaybackMode::BLEND_TO_FINAL;
}
// Transfer the new animations onto the queue.
//
while (!newsteps.IsEmpty()) {
@@ -178,13 +173,6 @@ void FlxAnimTracker::Update(std::string_view encqueue) {
HashToSeqno.Emplace(step.Hash, seqno);
}
// Move back the Unstarted pointer, so that the
// unstarted range includes all the new animations.
//
if (UnstartedSeqno > matchingseqno + 1) {
UnstartedSeqno = matchingseqno + 1;
}
// If there are too many animations in AQ, discard
// any very old ones.
//
@@ -194,11 +182,21 @@ void FlxAnimTracker::Update(std::string_view encqueue) {
uint64 hash = AQ.First().Hash;
HashToSeqno.Remove(hash);
AQ.PopFirst();
FirstSeqno += 1;
}
FirstSeqno += ndiscard;
if (UnstartedSeqno < FirstSeqno) {
}
// If UnstartedSeqno is before the live range,
// then the whole queue has to be replayed. Don't
// do that: just fast skip to the end.
//
if (UnstartedSeqno <= FirstSeqno) {
if (AQ.Num() == 0) {
UnstartedSeqno = FirstSeqno;
} else {
UnstartedSeqno = FirstSeqno + AQ.Num() - 1;
}
PlaybackMode = ElxAnimPlaybackMode::WARP_TO_FINAL;
}
}
@@ -209,21 +207,23 @@ TArray<uint64> FlxAnimTracker::GetAborted() {
return result;
}
bool FlxAnimTracker::AnyUnstarted() {
ElxAnimPlaybackMode FlxAnimTracker::GetNextStep(FlxAnimStoredStep &step) {
int offset = UnstartedSeqno - FirstSeqno;
return (offset < AQ.Num());
if (offset < AQ.Num()) {
step = AQ[offset];
return PlaybackMode;
} else {
step.Hash = 0;
step.Body = "";
return ElxAnimPlaybackMode::INVALID;
}
}
FlxAnimStoredStep FlxAnimTracker::GetUnstarted() {
int offset = UnstartedSeqno - FirstSeqno;
check(offset < AQ.Num());
return AQ[offset];
}
void FlxAnimTracker::Started(uint64 hash) {
void FlxAnimTracker::StartedStep(uint64 hash) {
int offset = UnstartedSeqno - FirstSeqno;
check(offset < AQ.Num());
check(AQ[offset].Hash == hash);
UnstartedSeqno += 1;
PlaybackMode = ElxAnimPlaybackMode::START_ANIMATION;
}