Created AnimViewMap

This commit is contained in:
2021-01-22 19:10:47 -05:00
parent b0440a4e12
commit 827a114752
10 changed files with 302 additions and 266 deletions

View File

@@ -28,6 +28,7 @@
#include <string>
#include <deque>
#include <cassert>
#include <unordered_map>
#include "util.hpp"
@@ -73,10 +74,13 @@ public:
class AnimQueue {
private:
int64_t id_;
int size_limit_;
std::deque<AnimStep> steps_;
public:
AnimQueue();
int64_t get_id() const { return id_; }
void set_id(int64_t id) { id_ = id; }
const AnimStep &nth(int n) const { return steps_[n]; }
int size() const { return steps_.size(); }
@@ -97,25 +101,52 @@ public:
};
class AnimView {
friend class AnimViewMap;
private:
int64_t id_;
std::string graphic_;
std::string plane_;
util::XYZ xyz_;
bool updated_;
bool updated_; // Used by AnimViewMap.
public:
const std::string &get_graphic() { return graphic_; }
const std::string &get_plane() { return plane_; }
const util::XYZ &get_xyz() { return xyz_; }
bool updated() { return updated_; }
AnimView() : id_(0), updated_(true) {}
void update_from(const AnimQueue &queue) {
graphic_ = queue.get_graphic();
plane_ = queue.get_plane();
xyz_ = queue.get_xyz();
updated_ = true;
}
int64_t get_id() const { return id_; }
const std::string &get_graphic() const { return graphic_; }
const std::string &get_plane() const { return plane_; }
const util::XYZ &get_xyz() const { return xyz_; }
void set_updated(bool u) { updated_ = u; }
void update_from(const AnimQueue &queue);
};
// AnimViewMap: basically just a map from tangible ID to AnimView.
//
// Also provides a simple garbage collector to get rid of AnimViews
// that haven't been updated recently.
//
class AnimViewMap {
public:
using ViewMap = std::unordered_map<int64_t, AnimView>;
private:
ViewMap view_map_;
public:
AnimViewMap() {}
~AnimViewMap() {}
// Get the entire view map for iterating over.
ViewMap &get_map() { return view_map_; }
// Get one entry from the view map, if it exists.
AnimView *get_one(int64_t id);
// Clear the updated bits on all the AnimViews.
void clear_updated_bits();
// Delete any AnimViews whose updated bits are not set.
void delete_non_updated();
// Update one AnimView, and set its updated bit.
void update_one(const AnimQueue &queue);
};
#endif // ANIMQUEUE_HPP