/////////////////////////////////////////////////////////////////// // // ANIMATION QUEUES // // An animation queue is a fifo queue of animation steps. New animations are // pushed on the back, and old ones are popped from the front. // // An animation step has an "action" which is usually the name of an animation, // or it's a special token like "walk" or "warp." Each animation step shows the // resulting AnimState that the player finds himself in after executing the // action. // // The first step in an animation queue always has id=0 and action="". This step // represents the initial state of the sprite before any animations or // movements. // // To add new items to the AnimQueue, use this process: first, call add(id, // action). This adds a new step to the queue. Then, call set_xyz, set_facing, // set_plane, or an other setter. These setters are meant to only be used // immediately after calling 'add' to populate the new step. // /////////////////////////////////////////////////////////////////// #ifndef ANIMQUEUE_HPP #define ANIMQUEUE_HPP #include #include #include #include #include #include "streambuffer.hpp" #include "util.hpp" class AnimStep { friend class AnimQueue; public: enum { HAS_FACING = 1, HAS_XYZ = 2, HAS_GRAPHIC = 4, HAS_PLANE = 8, HAS_EVERYTHING = 15, }; private: int64_t id_; int16_t bits_; std::string action_; float facing_; util::XYZ xyz_; std::string graphic_; std::string plane_; public: AnimStep(); ~AnimStep(); int64_t id() const { return id_; } int bits() const { return bits_; } const std::string &action() const { return action_; } double facing() const { return facing_; } 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_graphic() const { return bits_ & AnimStep::HAS_GRAPHIC; } bool has_plane() const { return bits_ & AnimStep::HAS_PLANE; } }; class AnimQueue { private: int32_t size_limit_; std::deque steps_; public: AnimQueue(); const AnimStep &nth(int n) const { return steps_[n]; } 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. 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); // 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 std::string &get_graphic() const; const std::string &get_plane() const; const util::XYZ &get_xyz() const; // (For testing): change the size limit. void set_size_limit(int32_t n); // (For testing): make sure the invariants are preserved. bool valid(); }; #endif // ANIMQUEUE_HPP