Overhaul of animstep, implement tangible.build

This commit is contained in:
2021-03-28 15:12:09 -04:00
parent f88fafc585
commit 98d261ce37
4 changed files with 316 additions and 191 deletions

View File

@@ -38,10 +38,13 @@ class AnimStep {
public:
enum {
HAS_FACING = 1,
HAS_XYZ = 2,
HAS_GRAPHIC = 4,
HAS_PLANE = 8,
HAS_EVERYTHING = 15,
HAS_X = 2,
HAS_Y = 4,
HAS_Z = 8,
HAS_XYZ = 14,
HAS_GRAPHIC = 16,
HAS_PLANE = 32,
HAS_EVERYTHING = 63,
};
private:
@@ -60,17 +63,54 @@ public:
int64_t id() const { return id_; }
int bits() const { return bits_; }
const std::string &action() const { return action_; }
const std::string &action() const { return action_; }
double facing() const { return facing_; }
util::XYZ xyz() const { return xyz_; }
float x() const { return xyz_.x; }
float y() const { return xyz_.y; }
float z() const { return xyz_.z; }
const util::XYZ &xyz() const { return xyz_; }
const std::string &graphic() const { return graphic_; }
const std::string &plane() const { return plane_; }
bool has_facing() const { return bits_ & AnimStep::HAS_FACING; }
bool has_xyz() const { return bits_ & AnimStep::HAS_XYZ; }
bool has_facing() const { return bits_ & HAS_FACING; }
bool has_x() const { return bits_ & HAS_X; }
bool has_y() const { return bits_ & HAS_Y; }
bool has_z() const { return bits_ & HAS_Z; }
bool has_xyz() const { return (bits_ & HAS_XYZ) == HAS_XYZ; }
bool has_graphic() const { return bits_ & AnimStep::HAS_GRAPHIC; }
bool has_plane() const { return bits_ & AnimStep::HAS_PLANE; }
void set_action(const std::string &action);
void set_facing(float f);
void set_x(float f);
void set_y(float f);
void set_z(float z);
void set_xyz(const util::XYZ &xyz);
void set_graphic(const std::string &g);
void set_plane(const std::string &p);
void clear();
// Create an AnimStep from a lua table.
//
// Lua stack must contain a table, which may contain:
// action: "action"
// facing: 0.0 - 360.0
// x: x-coordinate
// y: y-coordinate
// z: z-coordinate
// graphic: "graphic"
// plane: "plane"
//
void from_lua(lua_State *L, int idx);
// For any values that are unchanged in this step,
// echo the values of the previous step.
void echo(const AnimStep &prev);
// Verify that this step echoes the previous step.
bool echoes(const AnimStep &prev) const;
};
class AnimQueue {
@@ -85,37 +125,22 @@ public:
size_t size() const { return steps_.size(); }
int32_t size_limit() const { return size_limit_; }
// Clear the steps. Doesn't affect size_limit or id.
// Discard all but the most recent N steps.
void keep_only(int n);
// Clear the steps.
// The resulting steps aren't empty. There will be one
// step in the queue, which will be on the plane "", at (0,0,0).
// Doesn't affect size_limit.
void clear_steps();
// Mutators to create new steps from C++
//
void add(int64_t id, const std::string &action);
void set_facing(float f);
void set_xyz(util::XYZ xyz);
void set_graphic(const std::string &g);
void set_plane(const std::string &p);
// Mutator to create a new step.
void add(int64_t id, const AnimStep &step);
// Serialize or deserialize to a StreamBuffer
void serialize(StreamBuffer *sb);
void deserialize(StreamBuffer *sb);
// Mutator to create new steps from lua.
//
// Lua stack must contain a table, which may contain:
// action: "action"
// facing: 0.0 - 360.0
// x: x-coordinate
// y: y-coordinate
// z: z-coordinate
// dx: delta-x
// dy: delta-y
// dz: delta-z
// graphic: "graphic"
// plane: "plane"
//
void add(int64_t id, lua_State *L, int idx);
// Get the final resting place after all animations are complete.
const AnimStep &back() const;