Character can now move interactively

This commit is contained in:
2024-02-16 15:48:22 -05:00
parent abb967f20b
commit 89fcb6bf8d
8 changed files with 75 additions and 8 deletions

View File

@@ -279,6 +279,9 @@ FlxAnimTracker::FlxAnimTracker() {
void FlxAnimTracker::Clear() {
AQ.Empty();
Changed = true;
AutoFinish = false;
AutoFinishAction.Empty();
AutoFinishXYZ.Set(0,0,0);
}
void FlxAnimTracker::FinishedAnimation(uint64 hash) {
@@ -358,7 +361,6 @@ 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
@@ -374,6 +376,36 @@ void FlxAnimTracker::Update(std::string_view encqueue) {
AQ.PopFirst();
}
}
// Autofinish up to one animation.
//
if (AutoFinish) {
for (int i = 0; i < AQ.Num(); i++) {
if (!AQ[i].Finished) {
if (MatchesAutoFinish(AQ[i])) {
AQ[i].Finished = true;
}
break;
}
}
AutoFinish = false;
AutoFinishAction.Empty();
AutoFinishXYZ.Set(0,0,0);
}
}
void FlxAnimTracker::SetAutoFinish(const FString &action, const FVector &xyz) {
AutoFinish = true;
AutoFinishAction = action;
AutoFinishXYZ = xyz;
}
bool FlxAnimTracker::MatchesAutoFinish(const FlxAnimationStep &step) {
FVector xyz = UlxAnimationStepLibrary::AnimationStepGetVector(step, TEXT("xyz"));
if (xyz != AutoFinishXYZ) return false;
FString action = UlxAnimationStepLibrary::AnimationStepGetString(step, TEXT("action"));
if (action != AutoFinishAction) return false;
return true;
}
FString FlxAnimTracker::GetCurrentBlueprintName() {
@@ -393,6 +425,8 @@ FlxAnimationStep FlxAnimTracker::GetCurrentAnimation() {
}
}
result = AQ.Last();
result.Hash = 0;
// This next line is a hack. We need the idle step to have a unique
// hash. This is a passable way to get a unique hash value.
result.Hash += 1;
return result;
}