Convert anim step hashes from uint64 to int64, because blueprint has no uint64

This commit is contained in:
2025-10-10 19:03:04 -04:00
parent e7cb47db5b
commit 63dcbb7434
4 changed files with 45 additions and 28 deletions

View File

@@ -4,7 +4,7 @@
#include "GameFramework/Actor.h" #include "GameFramework/Actor.h"
#include <iostream> #include <iostream>
FlxAnimationStep::FlxAnimationStep(uint64 hash, std::string_view body) { FlxAnimationStep::FlxAnimationStep(int64 hash, std::string_view body) {
Finished = false; Finished = false;
Hash = hash; Hash = hash;
Body.SetNum(body.size()); Body.SetNum(body.size());
@@ -107,7 +107,7 @@ void UlxAnimationStepLibrary::UnpackAnimationStep(bool &bChanged, FString &Actio
} }
FlxAnimationStep* stepstorage = stepproperty->ContainerPtrToValuePtr<FlxAnimationStep>(target); FlxAnimationStep* stepstorage = stepproperty->ContainerPtrToValuePtr<FlxAnimationStep>(target);
uint64 oldhash = stepstorage->Hash; int64 oldhash = stepstorage->Hash;
FlxAnimationField actionfield; FlxAnimationField actionfield;
actionfield.Name = "action"; actionfield.Name = "action";
@@ -265,7 +265,7 @@ FlxAnimationField FlxAnimationStepDecoder::ReadField() {
return result; 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; FString result;
FlxAnimationStepDecoder decoder(body); FlxAnimationStepDecoder decoder(body);
result.Appendf(TEXT("Hash=%016llx"), hash); result.Appendf(TEXT("Hash=%016llx"), hash);
@@ -300,14 +300,14 @@ FString FlxAnimationStepDecoder::DebugString(bool finished, uint64 hash, std::st
FlxAnimationStepView FlxAnimQueueDecoder::ReadStep() { FlxAnimationStepView FlxAnimQueueDecoder::ReadStep() {
FlxAnimationStepView result; FlxAnimationStepView result;
result.Hash = Decoder.read_uint64(); result.Hash = Decoder.read_int64();
result.Body = Decoder.read_string_view(); result.Body = Decoder.read_string_view();
return result; return result;
} }
uint64 FlxAnimQueueDecoder::PeekHash() { int64 FlxAnimQueueDecoder::PeekHash() {
int64_t read_count = Decoder.total_reads(); int64_t read_count = Decoder.total_reads();
uint64 result = Decoder.read_uint64(); int64 result = Decoder.read_int64();
Decoder.unread_to(read_count); Decoder.unread_to(read_count);
return result; return result;
} }
@@ -337,7 +337,7 @@ void FlxAnimTracker::Clear() {
Changed = true; Changed = true;
} }
void FlxAnimTracker::FinishedAnimation(uint64 hash) { void FlxAnimTracker::FinishedAnimation(int64 hash) {
for (int i = 0; i < AQ.Num(); i++) { for (int i = 0; i < AQ.Num(); i++) {
if (AQ[i].Hash == hash) { if (AQ[i].Hash == hash) {
AQ[i].Finished = true; 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++) { for (int i = 0; i < AQ.Num(); i++) {
if (AQ[i].Hash == hash) { if (AQ[i].Hash == hash) {
return AQ[i].Finished; return AQ[i].Finished;
@@ -364,6 +364,17 @@ void FlxAnimTracker::SkipToEnd() {
} }
} }
TArray<int64> FlxAnimTracker::GetHashes()
{
TArray<int64> 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 const FlxAnimationStep *FlxAnimTracker::FirstUnfinished() const
{ {
for (int i = 0; i < AQ.Num(); i++) { for (int i = 0; i < AQ.Num(); i++) {
@@ -380,7 +391,7 @@ const FlxAnimationStep *FlxAnimTracker::LastFinished() const
return nullptr; return nullptr;
} }
const FlxAnimationStep *FlxAnimTracker::FindAnimation(uint64 hash) const const FlxAnimationStep *FlxAnimTracker::FindAnimation(int64 hash) const
{ {
for (int i = 0; i < AQ.Num(); i++) { for (int i = 0; i < AQ.Num(); i++) {
if (AQ[i].Hash == hash) return &AQ[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. // Build a map indexing the steps in AQ.
// //
TMap<uint64, int32> HashToIndex; TMap<int64, int32> HashToIndex;
for (int i = 0; i < AQ.Num(); i++) { for (int i = 0; i < AQ.Num(); i++) {
HashToIndex.Emplace(AQ[i].Hash, i); HashToIndex.Emplace(AQ[i].Hash, i);
} }

View File

@@ -28,7 +28,7 @@ public:
bool Finished; bool Finished;
UPROPERTY() UPROPERTY()
uint64 Hash; int64 Hash;
UPROPERTY() UPROPERTY()
TArray<uint8> Body; TArray<uint8> Body;
@@ -37,7 +37,7 @@ public:
FString Blueprint; FString Blueprint;
FlxAnimationStep() : Finished(false), Hash(0), Body(), Blueprint() {} FlxAnimationStep() : Finished(false), Hash(0), Body(), Blueprint() {}
FlxAnimationStep(uint64 h, std::string_view b); FlxAnimationStep(int64 h, std::string_view b);
// Auto-Execute // Auto-Execute
// //
@@ -122,11 +122,11 @@ public:
//////////////////////////////////////////////// ////////////////////////////////////////////////
struct FlxAnimationStepView { struct FlxAnimationStepView {
uint64 Hash; int64 Hash;
std::string_view Body; std::string_view Body;
FlxAnimationStepView() : Hash(0), 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. // Peek at the hash of the next animation step.
// //
uint64 PeekHash(); int64 PeekHash();
// Convert an AnimQueue to an FString. // Convert an AnimQueue to an FString.
// //
@@ -231,7 +231,7 @@ public:
// Convert an AnimStep to an FString. // 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 // animation to be marked as finished, which in turn causes
// 'GetCurrentStep' to advance to the next animation. // 'GetCurrentStep' to advance to the next animation.
// //
void FinishedAnimation(uint64 Hash); void FinishedAnimation(int64 Hash);
// Return true if an animation step is marked finished. // Return true if an animation step is marked finished.
// //
// Also return true if the animation step is not found. // 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. // Skip to the end of the animation queue.
// //
@@ -309,6 +309,10 @@ public:
// //
void SkipToEnd(); void SkipToEnd();
// Get all the hashes of all the animation steps.
//
TArray<int64> GetHashes();
// Return the first unfinished animation. // Return the first unfinished animation.
// //
const FlxAnimationStep *FirstUnfinished() const; const FlxAnimationStep *FirstUnfinished() const;
@@ -319,7 +323,7 @@ public:
// Return the first animation with the specified hash. // Return the first animation with the specified hash.
// //
const FlxAnimationStep *FindAnimation(uint64 hash) const; const FlxAnimationStep *FindAnimation(int64 hash) const;
// Clear the 'Changed' flag. // Clear the 'Changed' flag.
// //

View File

@@ -19,8 +19,10 @@ void AnimQueue::initialize_module() {
blankqueue_ = queue.get_encoded_queue(); blankqueue_ = queue.get_encoded_queue();
} }
static uint64_t hash_encstep(uint64_t prev, std::string_view s) { static int64_t hash_encstep(int64_t prev, std::string_view s) {
return util::hash_string(util::HashValue(123, prev), s).first; // 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 // 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(); return sb.read_uint8();
} }
uint64_t AnimQueue::get_final_hash() const { int64_t AnimQueue::get_final_hash() const {
if (encqueue_ == nullptr) return 0; if (encqueue_ == nullptr) return 0;
StreamBuffer sb(*encqueue_); StreamBuffer sb(*encqueue_);
sb.read_bytes(2); 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)); return QueueRange(hi-lo, queueview.substr(pos1, pos2 - pos1));
} }
uint64_t AnimQueue::hash_encstep(const QueueRange &prev, std::string_view s) { int64_t AnimQueue::hash_encstep(const QueueRange &prev, std::string_view s) {
uint64_t prev_hash = 0; int64_t prev_hash = 0;
if (prev.size > 0) { if (prev.size > 0) {
StreamBuffer retsb(prev.entries); StreamBuffer retsb(prev.entries);
prev_hash = retsb.read_uint64(); prev_hash = retsb.read_int64();
} }
return ::hash_encstep(prev_hash, s); 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(limit);
result.write_uint8(keeprange.size + (add ? 1:0)); result.write_uint8(keeprange.size + (add ? 1:0));
if (add) { 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_uint64(add_hash);
result.write_string(add_enc); result.write_string(add_enc);
} }

View File

@@ -367,7 +367,7 @@ private:
// Hash a new step given the range of steps that precede it. // 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. // Update the animation queue.
// //
@@ -389,7 +389,7 @@ private:
// //
int get_size_limit() const; int get_size_limit() const;
int get_actual_size() 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; std::string_view get_final_encstep() const;
private: private: