Overhaul encqueue to add a header: size_limit and actual_size

This commit is contained in:
2023-09-28 19:31:48 -04:00
parent c6b6f3bc84
commit c1594a1d83
2 changed files with 128 additions and 86 deletions

View File

@@ -64,16 +64,19 @@
// value, which is a function that accepts the encstep and also the hash
// of the previous encstep. Note that the hash is not part of the encstep.
//
// An animation queue consists of a list of steps. Each step has a hash
// and an encstep. An animation queue is serialized as follows:
// A serialized animation queue consists of the following information:
//
// for all animation steps, starting with the most recent, do:
// write_uint64(hash)
// write_string(encstep)
// write_uint8(size_limit);
// write_uint8(actual_size);
// for all animation steps, starting with the most recent, do:
// write_uint64(hash)
// write_string(encstep)
//
// The encoded string produced by the loop above is called an "encqueue",
// because it encodes everything in the animation queue (except for the
// size limit, which is separate).
// because it encodes everything in the animation queue.
//
// Note that the 'serialize' routine for animation queues just returns
// the encqueue string, which is the whole thing.
//
// Since the steps in an encqueue are stored most-recent first, if you
// want some information about the most recent animation entry, you
@@ -249,18 +252,14 @@ public:
//
AnimQueue();
// Size limit.
//
int32_t size_limit() const { return size_limit_; }
// Clear and set the initial state.
// Clear the steps to an initial state.
//
void clear();
void clear(const AnimState &initial);
// Set the size limit. Must be 2-250
// Change the size limit.
//
void set_limit(int n);
void set_limit(int limit);
// Add an animation step.
//
@@ -317,8 +316,22 @@ public:
util::SharedStdString get_encoded_queue() const { return encqueue_; }
private:
int size_limit_;
// 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);
// Read values from the header of the encqueue.
//
int get_size_limit() const;
int get_actual_size() const;
uint64_t get_final_hash() const;
std::string_view get_final_encstep() const;
private:
// Note: this is stored as a std::string, not an eng::string, because the
// ownership ends up being shared between us and the graphics engine. We
// can't have the graphics engine affecting the behavior of the engine heap.