Now passing FlxAnimationStep into the blueprint
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "CoreMinimal.h"
|
||||
#include "StringDecoder.h"
|
||||
#include "Containers/Deque.h"
|
||||
#include "AnimQueue.generated.h"
|
||||
|
||||
////////////////////////////////////////////////
|
||||
//
|
||||
@@ -31,15 +32,16 @@ enum class ElxAnimValueType {
|
||||
//
|
||||
// 3. Blend to Final. Skip the actual animation, and blend
|
||||
// smoothly to the final state of the animation. If the current
|
||||
// state is very far from the final state, then maybe jump instantaneously
|
||||
// instead.
|
||||
// state is very far from the final state, then maybe
|
||||
// jump instantaneously instead.
|
||||
//
|
||||
////////////////////////////////////////////////
|
||||
|
||||
enum class ElxAnimPlaybackMode {
|
||||
START_ANIMATION,
|
||||
WARP_TO_FINAL,
|
||||
BLEND_TO_FINAL,
|
||||
UENUM(BlueprintType)
|
||||
enum class ElxAnimationMode : uint8 {
|
||||
StartAnimation,
|
||||
WarpToFinal,
|
||||
BlendToFinal,
|
||||
INVALID,
|
||||
};
|
||||
|
||||
@@ -47,28 +49,91 @@ enum class ElxAnimPlaybackMode {
|
||||
//
|
||||
// An single animation step.
|
||||
//
|
||||
// The body consists of a sequence of FlxAnimField
|
||||
// The body consists of a sequence of FlxAnimationField
|
||||
// records. The body is encoded, to read the
|
||||
// FlxAnimField records you need an FlxAnimStepDecoder.
|
||||
// This comes in two versions: the string version,
|
||||
// and the string_view version.
|
||||
// FlxAnimationField records you need an
|
||||
// FlxAnimationStepDecoder.
|
||||
//
|
||||
////////////////////////////////////////////////
|
||||
|
||||
struct FlxAnimStep {
|
||||
USTRUCT(Blueprintable)
|
||||
struct INTEGRATION_API FlxAnimationStep {
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY()
|
||||
uint64 Hash;
|
||||
|
||||
UPROPERTY()
|
||||
TArray<uint8> Body;
|
||||
|
||||
FlxAnimationStep() : Hash(0), Body() {}
|
||||
FlxAnimationStep(uint64 h, std::string_view b);
|
||||
|
||||
// Unpack an AnimStep into a UObject
|
||||
//
|
||||
// Stores the key-value pairs of the animation step into
|
||||
// properties of a UObject. For example, if the key-value
|
||||
// pair "color=blue" is present in the AnimStep, then this
|
||||
// routine tries to find a string property "color" in the
|
||||
// UObject, and then it sets that property to "blue."
|
||||
//
|
||||
// Returns true if all of the key-value pairs in the
|
||||
// animation step could be unpacked into fields of the UObject.
|
||||
// This could fail, for instance, if the UObject just doesn't
|
||||
// contain one of the necessary properties. It can also
|
||||
// fail if there's a type mismatch. For example, "color=blue"
|
||||
// cannot be stored in a property "color" of type int.
|
||||
//
|
||||
// The prefix is prepended to the key names. For example,
|
||||
// if one of the key-value pairs is "color=blue", and the
|
||||
// prefix is "aq", then the property "aqColor=blue" will be
|
||||
// stored in the UObject.
|
||||
//
|
||||
// If pre-clear is true, then all properties of the UObject
|
||||
// starting with the specified prefix are cleared before
|
||||
// unpacking the animation step.
|
||||
//
|
||||
bool Unpack(const FString& prefix, UObject* into, bool preclear = true) 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 = Tangibles)
|
||||
static FString AnimationStepDebugString(const FlxAnimationStep& step);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = Tangibles)
|
||||
static void UnpackAnimationStep(const FlxAnimationStep& step,
|
||||
const FString& prefix, UObject* into, bool preclear = true);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////
|
||||
//
|
||||
// Exposing functions to blueprints.
|
||||
//
|
||||
////////////////////////////////////////////////
|
||||
|
||||
//UFUNCTION(BlueprintCallable)
|
||||
//void Unpack(const FString& prefix, UObject* into, bool preclear = true);
|
||||
|
||||
struct FlxAnimationStepView {
|
||||
uint64 Hash;
|
||||
std::string_view Body;
|
||||
|
||||
FlxAnimStep() : Hash(0), Body("") {}
|
||||
FlxAnimStep(uint64 h, std::string_view b) : Hash(h), Body(b) {}
|
||||
};
|
||||
|
||||
struct FlxAnimStoredStep {
|
||||
uint64 Hash;
|
||||
std::string Body;
|
||||
|
||||
FlxAnimStoredStep() : Hash(0), Body("") {}
|
||||
FlxAnimStoredStep(uint64 h, std::string_view b) : Hash(h), Body(b) {}
|
||||
FlxAnimationStepView() : Hash(0), Body("") {}
|
||||
FlxAnimationStepView(uint64 h, std::string_view b) : Hash(h), Body(b) {}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////
|
||||
@@ -85,7 +150,7 @@ struct FlxAnimStoredStep {
|
||||
//
|
||||
////////////////////////////////////////////////
|
||||
|
||||
struct FlxAnimField {
|
||||
struct FlxAnimationField {
|
||||
std::string_view Name;
|
||||
bool Persistent;
|
||||
ElxAnimValueType Type;
|
||||
@@ -119,7 +184,7 @@ public:
|
||||
|
||||
// Read one animation step.
|
||||
//
|
||||
FlxAnimStep ReadStep();
|
||||
FlxAnimationStepView ReadStep();
|
||||
|
||||
// Convert an AnimQueue to an FString.
|
||||
//
|
||||
@@ -131,22 +196,20 @@ public:
|
||||
// An Animation Step Decoder.
|
||||
//
|
||||
// This acts a lot like a stream reader,
|
||||
// it reads one FlxAnimField at a time from
|
||||
// it reads one FlxAnimationField at a time from
|
||||
// the animation queue until you reach
|
||||
// 'end-of-file'.
|
||||
//
|
||||
////////////////////////////////////////////////
|
||||
|
||||
class FlxAnimStepDecoder {
|
||||
class FlxAnimationStepDecoder {
|
||||
private:
|
||||
FlxStringDecoder Decoder;
|
||||
|
||||
static bool ClearProperties(const FString& prefix, UObject* obj);
|
||||
static bool SetProperty(const FString& name, UObject *obj, const FlxAnimField& value);
|
||||
public:
|
||||
// Initialize the FlxAnimStepDecoder from the FlxAnimStep.
|
||||
// Initialize the FlxAnimationStepDecoder from the FlxAnimationStepView.
|
||||
//
|
||||
FlxAnimStepDecoder(std::string_view body) : Decoder(body) {}
|
||||
FlxAnimationStepDecoder(std::string_view body) : Decoder(body) {}
|
||||
|
||||
// Return true if the parser has reached the end of the string.
|
||||
//
|
||||
@@ -154,37 +217,11 @@ public:
|
||||
|
||||
// Read one field.
|
||||
//
|
||||
FlxAnimField ReadField();
|
||||
FlxAnimationField ReadField();
|
||||
|
||||
// Convert an AnimStep to an FString.
|
||||
//
|
||||
static FString DebugString(std::string_view body);
|
||||
|
||||
// Unpack an AnimStep into a UObject
|
||||
//
|
||||
// Stores the key-value pairs of the animation step into
|
||||
// properties of a UObject. For example, if the key-value
|
||||
// pair "color=blue" is present in the AnimStep, then this
|
||||
// routine tries to find a string property "color" in the
|
||||
// UObject, and then it sets that property to "blue."
|
||||
//
|
||||
// Returns true if all of the key-value pairs in the
|
||||
// animation step could be unpacked into fields of the UObject.
|
||||
// This could fail, for instance, if the UObject just doesn't
|
||||
// contain one of the necessary properties. It can also
|
||||
// fail if there's a type mismatch. For example, "color=blue"
|
||||
// cannot be stored in a property "color" of type int.
|
||||
//
|
||||
// The prefix is prepended to the key names. For example,
|
||||
// if one of the key-value pairs is "color=blue", and the
|
||||
// prefix is "aq", then the property "aqColor=blue" will be
|
||||
// stored in the UObject.
|
||||
//
|
||||
// If pre-clear is true, then all properties of the UObject
|
||||
// starting with the specified prefix are cleared before
|
||||
// unpacking the animation step.
|
||||
//
|
||||
static bool UnpackInto(std::string_view body, const FString &prefix, bool preclear, UObject* obj);
|
||||
static FString DebugString(uint64 hash, std::string_view body);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////
|
||||
@@ -205,7 +242,7 @@ public:
|
||||
// store the hashes, not the steps. The First element
|
||||
// of the queue is the oldest item.
|
||||
//
|
||||
TDeque<FlxAnimStoredStep> AQ;
|
||||
TDeque<FlxAnimationStep> AQ;
|
||||
|
||||
// The sequence number of the first item in AQ.
|
||||
//
|
||||
@@ -221,7 +258,7 @@ public:
|
||||
|
||||
// Indicates whether the unstarted animation should be played or otherwise.
|
||||
//
|
||||
ElxAnimPlaybackMode PlaybackMode;
|
||||
ElxAnimationMode PlaybackMode;
|
||||
|
||||
// Array of recently-aborted hash values.
|
||||
//
|
||||
@@ -254,7 +291,7 @@ public:
|
||||
// playback mode. If the playback mode is INVALID then there is
|
||||
// no next step to play
|
||||
//
|
||||
ElxAnimPlaybackMode GetNextStep(FlxAnimStoredStep& step);
|
||||
ElxAnimationMode GetNextStep(FlxAnimationStep& step);
|
||||
|
||||
// Declare that an animation has been started.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user