329 lines
9.3 KiB
C++
329 lines
9.3 KiB
C++
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "StringDecoder.h"
|
|
#include "Containers/Deque.h"
|
|
#include "AnimQueue.generated.h"
|
|
|
|
////////////////////////////////////////////////
|
|
//
|
|
// An single animation step.
|
|
//
|
|
// The body consists of a sequence of FlxAnimationField
|
|
// records. The body is encoded, to read the
|
|
// FlxAnimationField records you need an
|
|
// FlxAnimationStepDecoder.
|
|
//
|
|
////////////////////////////////////////////////
|
|
|
|
USTRUCT(BlueprintType)
|
|
struct INTEGRATION_API FlxAnimationStep {
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
UPROPERTY()
|
|
bool Finished;
|
|
|
|
UPROPERTY()
|
|
uint64 Hash;
|
|
|
|
UPROPERTY()
|
|
TArray<uint8> Body;
|
|
|
|
UPROPERTY()
|
|
FString Blueprint;
|
|
|
|
FlxAnimationStep() : Finished(false), Hash(0), Body(), Blueprint() {}
|
|
FlxAnimationStep(uint64 h, std::string_view b);
|
|
|
|
// Auto-Execute
|
|
//
|
|
// These functions automatically update certain actor
|
|
// properties:
|
|
//
|
|
// AutoUpdateXYZ(AActor *actor); // uses 'xyz' keyword
|
|
// AutoUpdateFacing(AActor *actor); // uses 'facing' keyword.
|
|
// AutoUpdatePlane(FName *plane); // uses 'plane' keyword
|
|
//
|
|
void AutoUpdateXYZ(AActor *actor) const;
|
|
void AutoUpdateFacing(AActor *actor) const;
|
|
void AutoUpdatePlane(FName *plane) const;
|
|
};
|
|
|
|
////////////////////////////////////////////////
|
|
//
|
|
// This UClass is never instantiated. It exists to
|
|
// expose certain static functions to the blueprint
|
|
// library.
|
|
//
|
|
////////////////////////////////////////////////
|
|
|
|
UCLASS()
|
|
class INTEGRATION_API UlxAnimationStepLibrary : public UObject
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Luprex|Animation Step")
|
|
static FString AnimationStepDebugString(const FlxAnimationStep& step);
|
|
|
|
// Stores the key-value pairs in properties of the target object.
|
|
//
|
|
// The animation step contains key-value pairs. The goal of this function
|
|
// is to store these in properties of the target. The prefix parameter
|
|
// is prepended to the property names.
|
|
//
|
|
// For example, suppose the key-value pairs are "color=blue, speed=20",
|
|
// and suppose the prefix is "aq". In that case, two properties would
|
|
// be written: "aq Color" would be set to "blue", and "aq Speed" would be
|
|
// set to 20. In addition, a property "aq Animation Step" would
|
|
// be written, containing the entire animation step.
|
|
//
|
|
// If the step contains a key-value pair, but there is no corresponding
|
|
// property in the target, then the key-value pair is silently
|
|
// ignored. If the target contains properties that begin with the prefix,
|
|
// but which don't have any corresponding key-value pair, those properties
|
|
// are cleared.
|
|
//
|
|
// Returns 'Changed' if the hash-value of the "aq Animation Step" property
|
|
// has changed. Returns 'Action' string from the action=xxx property.
|
|
//
|
|
UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = "Luprex|Animation Step")
|
|
static void UnpackAnimationStep(bool &bChanged, FString &Action, const FlxAnimationStep& step, UObject* target, const FString& VariableNamePrefix = TEXT("aq"));
|
|
|
|
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Luprex|Animation Step")
|
|
static bool AnimationStepEqual(const FlxAnimationStep &StepA, const FlxAnimationStep &StepB);
|
|
|
|
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Luprex|Animation Step")
|
|
static bool AnimationStepIsIdle(const FlxAnimationStep &step);
|
|
|
|
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Luprex|Animation Step")
|
|
static FVector AnimationStepGetVector(const FlxAnimationStep& step, const FString& name);
|
|
|
|
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Luprex|Animation Step")
|
|
static double AnimationStepGetFloat(const FlxAnimationStep& step, const FString& name);
|
|
|
|
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Luprex|Animation Step")
|
|
static FString AnimationStepGetString(const FlxAnimationStep& step, const FString& name);
|
|
|
|
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Luprex|Animation Step")
|
|
static bool AnimationStepGetBool(const FlxAnimationStep& step, const FString& name);
|
|
};
|
|
|
|
////////////////////////////////////////////////
|
|
//
|
|
//
|
|
////////////////////////////////////////////////
|
|
|
|
struct FlxAnimationStepView {
|
|
uint64 Hash;
|
|
std::string_view Body;
|
|
|
|
FlxAnimationStepView() : Hash(0), Body("") {}
|
|
FlxAnimationStepView(uint64 h, std::string_view b) : Hash(h), Body(b) {}
|
|
};
|
|
|
|
////////////////////////////////////////////////
|
|
//
|
|
// A single animation field.
|
|
//
|
|
// A field consists of a variable name,
|
|
// a persistent flag, a type, and some fields
|
|
// to hold the values.
|
|
//
|
|
// If the value is boolean, it is stored in
|
|
// X, as either 1 or 0. If the value is double,
|
|
// it is stored in X.
|
|
//
|
|
////////////////////////////////////////////////
|
|
|
|
struct FlxAnimationField {
|
|
std::string_view Name;
|
|
bool Persistent;
|
|
SimpleDynamicTag Type;
|
|
double X, Y, Z;
|
|
std::string_view S;
|
|
};
|
|
|
|
////////////////////////////////////////////////
|
|
//
|
|
// An Animation Queue Decoder.
|
|
//
|
|
// This acts a lot like a stream reader,
|
|
// it reads one AnimEntry at a time from
|
|
// the animation queue until you reach
|
|
// 'end-of-file'.
|
|
//
|
|
////////////////////////////////////////////////
|
|
|
|
class FlxAnimQueueDecoder {
|
|
private:
|
|
FlxStreamBuffer Decoder;
|
|
|
|
// These values are immediately read from the header.
|
|
//
|
|
int SizeLimit;
|
|
int ActualSize;
|
|
|
|
public:
|
|
// Initialize the FlxAnimQueueDecoder with the encoded animation queue.
|
|
//
|
|
FlxAnimQueueDecoder(std::string_view s);
|
|
|
|
// Get the size limit of the animation queue.
|
|
//
|
|
int GetSizeLimit() const { return SizeLimit; }
|
|
|
|
// Get the Actual Size of the animation queue.
|
|
//
|
|
int GetActualSize() const { return ActualSize; }
|
|
|
|
// Return true if the parser has reached the end of the string.
|
|
//
|
|
bool AtEOF() { return Decoder.empty(); }
|
|
|
|
// Read one animation step.
|
|
//
|
|
FlxAnimationStepView ReadStep();
|
|
|
|
// Peek at the hash of the next animation step.
|
|
//
|
|
uint64 PeekHash();
|
|
|
|
// Convert an AnimQueue to an FString.
|
|
//
|
|
static FString DebugString(std::string_view s);
|
|
};
|
|
|
|
////////////////////////////////////////////////
|
|
//
|
|
// An Animation Step Decoder.
|
|
//
|
|
// This acts a lot like a stream reader,
|
|
// it reads one FlxAnimationField at a time from
|
|
// the animation queue until you reach
|
|
// 'end-of-file'.
|
|
//
|
|
////////////////////////////////////////////////
|
|
|
|
class FlxAnimationStepDecoder {
|
|
private:
|
|
FlxStreamBuffer Decoder;
|
|
|
|
public:
|
|
// Initialize the FlxAnimationStepDecoder from the FlxAnimationStepView.
|
|
//
|
|
FlxAnimationStepDecoder(std::string_view body) : Decoder(body) {}
|
|
|
|
// Return true if the parser has reached the end of the string.
|
|
//
|
|
bool AtEOF() { return Decoder.empty(); }
|
|
|
|
// Read one field.
|
|
//
|
|
FlxAnimationField ReadField();
|
|
|
|
// Convert an AnimStep to an FString.
|
|
//
|
|
static FString DebugString(bool injectidle, bool persistentonly, uint64 hash, std::string_view body);
|
|
};
|
|
|
|
////////////////////////////////////////////////
|
|
//
|
|
// FlxAnimTracker
|
|
//
|
|
// This class monitors the animation queue for a single
|
|
// tangible. It can identify when a new animation has
|
|
// appeared on the animation queue, and when animations have
|
|
// been removed from the animation queue. It also
|
|
// keeps track of which animations have been started.
|
|
//
|
|
////////////////////////////////////////////////
|
|
|
|
class FlxAnimTracker {
|
|
public:
|
|
// 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<FlxAnimationStep> AQ;
|
|
|
|
// True if something has recently changed.
|
|
//
|
|
bool Changed;
|
|
|
|
// Autofinish parameters.
|
|
//
|
|
bool AutoFinish;
|
|
FString AutoFinishAction;
|
|
FVector AutoFinishXYZ;
|
|
|
|
private:
|
|
bool MatchesAutoFinish(const FlxAnimationStep &step);
|
|
|
|
public:
|
|
// Construct a tracker.
|
|
//
|
|
// Initially, the tracker is in the empty (Clear) state.
|
|
//
|
|
FlxAnimTracker();
|
|
|
|
// Clear everything, reset to the initial state.
|
|
//
|
|
void Clear();
|
|
|
|
// Update from the specified animation queue.
|
|
//
|
|
// After the update is done, AQ will be a copy
|
|
// of the animation queue that is passed in.
|
|
//
|
|
void Update(std::string_view encqueue);
|
|
|
|
// Auto-finish animation.
|
|
//
|
|
// Next time 'update' is called, we will check for the presence
|
|
// of a new animation matching these parameters. If there is
|
|
// one, it is automatically marked 'finished'.
|
|
//
|
|
void SetAutoFinish(const FString &action, const FVector &xyz);
|
|
|
|
// Get the current blueprint name, as a string.
|
|
//
|
|
FString GetCurrentBlueprintName();
|
|
|
|
// Get the current animation step.
|
|
//
|
|
// Get the current animation step. This is the step that the
|
|
// blueprint should currently be playing.
|
|
//
|
|
FlxAnimationStep GetCurrentAnimation();
|
|
|
|
// Declare that an animation is finished.
|
|
//
|
|
// The blueprint uses this function call to indicate that it
|
|
// is done playing the specified animation. This will cause the
|
|
// animation to be marked as finished, which in turn causes
|
|
// 'GetCurrentStep' to advance to the next animation.
|
|
//
|
|
void FinishedAnimation(uint64 Hash);
|
|
|
|
// Skip to the end of the animation queue.
|
|
//
|
|
// This is equivalent to calling 'FinishedHash' on every
|
|
// animation in the entire queue.
|
|
//
|
|
void SkipToEnd();
|
|
|
|
// Clear the 'Changed' flag.
|
|
//
|
|
void ClearChanged() { Changed = false; }
|
|
|
|
// Get the 'Changed' flag.
|
|
//
|
|
// The changed flag is set to true whenever the Luprex animation
|
|
// queue changes from its previous state. The changed flag is also
|
|
// set to true whenever 'SetFinished' marks an animation as finished.
|
|
// The changed flag can only be set to false by 'ClearChanged,' above.
|
|
//
|
|
bool IsChanged() const { return Changed; }
|
|
}; |