From 63dcbb7434322375bb32773d291d3670757e520e Mon Sep 17 00:00:00 2001 From: jyelon Date: Fri, 10 Oct 2025 19:03:04 -0400 Subject: [PATCH] Convert anim step hashes from uint64 to int64, because blueprint has no uint64 --- Source/Integration/AnimQueue.cpp | 31 +++++++++++++++++++++---------- Source/Integration/AnimQueue.h | 22 +++++++++++++--------- luprex/cpp/core/animqueue.cpp | 16 +++++++++------- luprex/cpp/core/animqueue.hpp | 4 ++-- 4 files changed, 45 insertions(+), 28 deletions(-) diff --git a/Source/Integration/AnimQueue.cpp b/Source/Integration/AnimQueue.cpp index 36cce283..e79aa34f 100644 --- a/Source/Integration/AnimQueue.cpp +++ b/Source/Integration/AnimQueue.cpp @@ -4,7 +4,7 @@ #include "GameFramework/Actor.h" #include -FlxAnimationStep::FlxAnimationStep(uint64 hash, std::string_view body) { +FlxAnimationStep::FlxAnimationStep(int64 hash, std::string_view body) { Finished = false; Hash = hash; Body.SetNum(body.size()); @@ -107,7 +107,7 @@ void UlxAnimationStepLibrary::UnpackAnimationStep(bool &bChanged, FString &Actio } FlxAnimationStep* stepstorage = stepproperty->ContainerPtrToValuePtr(target); - uint64 oldhash = stepstorage->Hash; + int64 oldhash = stepstorage->Hash; FlxAnimationField actionfield; actionfield.Name = "action"; @@ -265,7 +265,7 @@ FlxAnimationField FlxAnimationStepDecoder::ReadField() { return result; } -FString FlxAnimationStepDecoder::DebugString(bool finished, uint64 hash, std::string_view body) { +FString FlxAnimationStepDecoder::DebugString(bool finished, int64 hash, std::string_view body) { FString result; FlxAnimationStepDecoder decoder(body); result.Appendf(TEXT("Hash=%016llx"), hash); @@ -300,14 +300,14 @@ FString FlxAnimationStepDecoder::DebugString(bool finished, uint64 hash, std::st FlxAnimationStepView FlxAnimQueueDecoder::ReadStep() { FlxAnimationStepView result; - result.Hash = Decoder.read_uint64(); + result.Hash = Decoder.read_int64(); result.Body = Decoder.read_string_view(); return result; } -uint64 FlxAnimQueueDecoder::PeekHash() { +int64 FlxAnimQueueDecoder::PeekHash() { int64_t read_count = Decoder.total_reads(); - uint64 result = Decoder.read_uint64(); + int64 result = Decoder.read_int64(); Decoder.unread_to(read_count); return result; } @@ -337,7 +337,7 @@ void FlxAnimTracker::Clear() { Changed = true; } -void FlxAnimTracker::FinishedAnimation(uint64 hash) { +void FlxAnimTracker::FinishedAnimation(int64 hash) { for (int i = 0; i < AQ.Num(); i++) { if (AQ[i].Hash == hash) { AQ[i].Finished = true; @@ -346,7 +346,7 @@ void FlxAnimTracker::FinishedAnimation(uint64 hash) { } } -bool FlxAnimTracker::IsFinished(uint64 hash) { +bool FlxAnimTracker::IsFinished(int64 hash) { for (int i = 0; i < AQ.Num(); i++) { if (AQ[i].Hash == hash) { return AQ[i].Finished; @@ -364,6 +364,17 @@ void FlxAnimTracker::SkipToEnd() { } } +TArray FlxAnimTracker::GetHashes() +{ + TArray Result; + Result.SetNum(AQ.Num()); + for (int i = 0; i < AQ.Num(); i++) + { + Result[i] = AQ[i].Hash; + } + return Result; +} + const FlxAnimationStep *FlxAnimTracker::FirstUnfinished() const { for (int i = 0; i < AQ.Num(); i++) { @@ -380,7 +391,7 @@ const FlxAnimationStep *FlxAnimTracker::LastFinished() const return nullptr; } -const FlxAnimationStep *FlxAnimTracker::FindAnimation(uint64 hash) const +const FlxAnimationStep *FlxAnimTracker::FindAnimation(int64 hash) const { for (int i = 0; i < AQ.Num(); i++) { if (AQ[i].Hash == hash) return &AQ[i]; @@ -408,7 +419,7 @@ void FlxAnimTracker::Update(std::string_view encqueue) { // Build a map indexing the steps in AQ. // - TMap HashToIndex; + TMap HashToIndex; for (int i = 0; i < AQ.Num(); i++) { HashToIndex.Emplace(AQ[i].Hash, i); } diff --git a/Source/Integration/AnimQueue.h b/Source/Integration/AnimQueue.h index 40de2df0..f6d00741 100644 --- a/Source/Integration/AnimQueue.h +++ b/Source/Integration/AnimQueue.h @@ -28,7 +28,7 @@ public: bool Finished; UPROPERTY() - uint64 Hash; + int64 Hash; UPROPERTY() TArray Body; @@ -37,7 +37,7 @@ public: FString Blueprint; FlxAnimationStep() : Finished(false), Hash(0), Body(), Blueprint() {} - FlxAnimationStep(uint64 h, std::string_view b); + FlxAnimationStep(int64 h, std::string_view b); // Auto-Execute // @@ -122,11 +122,11 @@ public: //////////////////////////////////////////////// struct FlxAnimationStepView { - uint64 Hash; + int64 Hash; std::string_view Body; FlxAnimationStepView() : Hash(0), Body("") {} - FlxAnimationStepView(uint64 h, std::string_view b) : Hash(h), Body(b) {} + FlxAnimationStepView(int64 h, std::string_view b) : Hash(h), Body(b) {} }; //////////////////////////////////////////////// @@ -194,7 +194,7 @@ public: // Peek at the hash of the next animation step. // - uint64 PeekHash(); + int64 PeekHash(); // Convert an AnimQueue to an FString. // @@ -231,7 +231,7 @@ public: // Convert an AnimStep to an FString. // - static FString DebugString(bool finished, uint64 hash, std::string_view body); + static FString DebugString(bool finished, int64 hash, std::string_view body); }; //////////////////////////////////////////////// @@ -294,13 +294,13 @@ public: // animation to be marked as finished, which in turn causes // 'GetCurrentStep' to advance to the next animation. // - void FinishedAnimation(uint64 Hash); + void FinishedAnimation(int64 Hash); // Return true if an animation step is marked finished. // // Also return true if the animation step is not found. // - bool IsFinished(uint64 Hash); + bool IsFinished(int64 Hash); // Skip to the end of the animation queue. // @@ -309,6 +309,10 @@ public: // void SkipToEnd(); + // Get all the hashes of all the animation steps. + // + TArray GetHashes(); + // Return the first unfinished animation. // const FlxAnimationStep *FirstUnfinished() const; @@ -319,7 +323,7 @@ public: // Return the first animation with the specified hash. // - const FlxAnimationStep *FindAnimation(uint64 hash) const; + const FlxAnimationStep *FindAnimation(int64 hash) const; // Clear the 'Changed' flag. // diff --git a/luprex/cpp/core/animqueue.cpp b/luprex/cpp/core/animqueue.cpp index 297f82c4..4336484c 100644 --- a/luprex/cpp/core/animqueue.cpp +++ b/luprex/cpp/core/animqueue.cpp @@ -19,8 +19,10 @@ void AnimQueue::initialize_module() { blankqueue_ = queue.get_encoded_queue(); } -static uint64_t hash_encstep(uint64_t prev, std::string_view s) { - return util::hash_string(util::HashValue(123, prev), s).first; +static int64_t hash_encstep(int64_t prev, std::string_view s) { + // We drop the most significant bit to ensure that the value + // can be represented as a nonnegative int64. + return int64_t(0x7FFFFFFF & util::hash_string(util::HashValue(123, prev), s).first); } // Parse a value. This is meant for unit testing only. The @@ -368,7 +370,7 @@ int AnimQueue::get_actual_size() const { return sb.read_uint8(); } -uint64_t AnimQueue::get_final_hash() const { +int64_t AnimQueue::get_final_hash() const { if (encqueue_ == nullptr) return 0; StreamBuffer sb(*encqueue_); sb.read_bytes(2); @@ -411,11 +413,11 @@ AnimQueue::QueueRange AnimQueue::get_range(int lo, int hi) { return QueueRange(hi-lo, queueview.substr(pos1, pos2 - pos1)); } -uint64_t AnimQueue::hash_encstep(const QueueRange &prev, std::string_view s) { - uint64_t prev_hash = 0; +int64_t AnimQueue::hash_encstep(const QueueRange &prev, std::string_view s) { + int64_t prev_hash = 0; if (prev.size > 0) { StreamBuffer retsb(prev.entries); - prev_hash = retsb.read_uint64(); + prev_hash = retsb.read_int64(); } return ::hash_encstep(prev_hash, s); } @@ -429,7 +431,7 @@ void AnimQueue::update_encqueue(int limit, bool add, std::string_view add_enc, i result.write_uint8(limit); result.write_uint8(keeprange.size + (add ? 1:0)); if (add) { - uint64_t add_hash = hash_encstep(keeprange, add_enc); + int64_t add_hash = hash_encstep(keeprange, add_enc); result.write_uint64(add_hash); result.write_string(add_enc); } diff --git a/luprex/cpp/core/animqueue.hpp b/luprex/cpp/core/animqueue.hpp index 72bfa828..ae6e226c 100644 --- a/luprex/cpp/core/animqueue.hpp +++ b/luprex/cpp/core/animqueue.hpp @@ -367,7 +367,7 @@ private: // Hash a new step given the range of steps that precede it. // - static uint64_t hash_encstep(const QueueRange &prev, std::string_view step); + static int64_t hash_encstep(const QueueRange &prev, std::string_view step); // Update the animation queue. // @@ -389,7 +389,7 @@ private: // int get_size_limit() const; int get_actual_size() const; - uint64_t get_final_hash() const; + int64_t get_final_hash() const; std::string_view get_final_encstep() const; private: