Add support for animate replace=true

This commit is contained in:
2023-10-03 18:17:24 -04:00
parent c1594a1d83
commit edea43839f
3 changed files with 187 additions and 122 deletions

View File

@@ -268,6 +268,13 @@ public:
//
void add(const AnimState &state);
// Replace the most recent animation step.
//
// Note: replace does not automatically compose the step with the previous
// step, you have to do that yourself.
//
void replace(const AnimState &state);
// Serialize or deserialize to a StreamBuffer
//
void serialize(StreamBuffer *sb) const;
@@ -316,14 +323,41 @@ public:
util::SharedStdString get_encoded_queue() const { return encqueue_; }
private:
// Update the encoded queue.
//
// You must specify the new size limit.
// You may optionally specify an encstep to add.
// If keepold, then old steps will be retained up to the size limit.
//
void update_encqueue(int limit, bool add, std::string_view add_enc, bool keepold);
struct QueueRange {
int size;
std::string_view entries;
QueueRange(int sz, std::string_view ent) : size(sz), entries(ent) {}
};
// Get a range of entries from the queue.
//
// You must specify a range (lo-hi) of steps. In this numbering, 0 is the
// most recent entry in the queue. The indices lo and hi are automatically
// clamped to the valid range (0 to actual_size). If lo >= hi, then an
// empty range is returned.
//
QueueRange get_range(int lo, int hi);
// Hash a new step given the range of steps that precede it.
//
static uint64_t hash_encstep(const QueueRange &prev, std::string_view step);
// Update the animation queue.
//
// The range (keeplo to keephi) specifies which old steps should be
// retained. The numbers keephi and keeplo are automatically clamped
// so that they lie inside the actual size of the queue.
//
// If add is true, then an additional step is added to the queue.
// The hash of the new step is calculated automatically.
//
// There is no enforcement that you respected the size limit that you
// specified. For example, you could say "keep 0-5, and add 1." That
// would make 6 entries in the queue. It is up to the caller to respect
// the size limit. The value passed in is just for reporting.
//
void update_encqueue(int limit, bool add, std::string_view add_enc, int keeplo, int keephi);
// Read values from the header of the encqueue.
//
int get_size_limit() const;