100 lines
2.8 KiB
C++
100 lines
2.8 KiB
C++
///////////////////////////////////////////////////////////////////
|
|
//
|
|
// 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 <set>
|
|
#include <string>
|
|
#include <deque>
|
|
#include <cassert>
|
|
#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_;
|
|
std::string action_;
|
|
int bits_;
|
|
|
|
float facing_;
|
|
util::XYZ xyz_;
|
|
std::string graphic_;
|
|
std::string plane_;
|
|
|
|
public:
|
|
AnimStep();
|
|
~AnimStep();
|
|
|
|
int64_t id() const { return id_; }
|
|
const std::string &action() const { return action_; }
|
|
int bits() const { return bits_; }
|
|
|
|
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:
|
|
int size_limit_;
|
|
std::deque<AnimStep> steps_;
|
|
public:
|
|
AnimQueue();
|
|
const AnimStep &nth(int n) const { return steps_[n]; }
|
|
int size() const { return steps_.size(); }
|
|
|
|
// Mutators to create new steps.
|
|
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);
|
|
|
|
// Get the final resting place.
|
|
const std::string &get_plane() const;
|
|
const util::XYZ &get_xyz() const;
|
|
|
|
// Functions for unit testing.
|
|
void set_size_limit(int n);
|
|
};
|
|
|
|
#endif // ANIMQUEUE_HPP
|
|
|