Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace dxle{
- class animation_graph
- {
- public:
- namespace ch = std::chrono;
- animation_graph() = delete;
- animation_graph(const std::vector<texture_2d>& images, dxle::time::timing_maker::count_per_second interval, dxle::animation_mode mode)
- : elem_(images, interval, mode)
- {};
- animation_graph(const animation_graph&) = delete;
- animation_graph(animation_graph&&) = delete;
- animation_graph& operator=(const animation_graph&) = delete;
- animation_graph& operator=(animation_graph&&) = delete;
- class container_elem;
- class container_iterator;
- typedef value_type;
- // 差分の型
- typedef ch::microseconds difference_type;
- // サイズの型
- typedef size_t size_type;
- // 要素の型
- typedef container_elem value_type;
- // 要素を指すポインタ
- typedef value_type* pointer;
- // 要素を指すconstなポインタ
- typedef const value_type* const_pointer;
- // 要素の非const参照
- typedef value_type& reference;
- // 要素のconst参照
- typedef const value_type& const_reference;
- typedef container_iterator itarator;
- itarator begin() noexcept { return itarator(*elem_, false); }
- itarator end() noexcept { return itarator(*elem_, true); }
- private:
- container_elem elem_;
- };
- class animation_graph::container_elem {
- public:
- container_elem() = delete;
- container_elem(const container_elem&) = delete;
- container_elem(container_elem&&) = delete;
- container_elem& operator=(const container_elem&) = delete;
- container_elem& operator=(container_elem&&) = delete;
- void start() noexcept {
- if(is_animaton_finished){
- this->is_animation_started = true;
- this->begin_time_ = ch::steady_clock::now();
- }
- }
- bool is_started() noexcept { return this->is_animation_started; }
- void stop() noexcept {
- if(this->is_animation_started) this->is_animaton_finished = true;
- }
- bool is_finished() noexcept { return this->is_animaton_finished; }
- int DrawGraph(const pointi& p, bool TransFlag)const noexcept{
- const size_t index = this->interval_ * ch::time_point_cast<ch::seconds>(this->begin_time_) % this->images_.size();
- this->images_[index].DrawGraph(p, TransFlag);
- }
- private:
- container_elem(const std::vector<texture_2d>& images, dxle::time::timing_maker::count_per_second interval, dxle::animation_mode mode)
- : images_(images), interval_(interval), mode_(mode), begin_time_(), is_animation_started(false), is_animaton_finished(true)
- {};
- const std::vector<texture_2d>& images_;
- dxle::time::timing_maker::count_per_second interval_;
- dxle::animation_mode mode_;
- ch::microseconds begin_time_;
- bool is_animation_started;
- bool is_animaton_finished;
- };
- class animation_graph::container_iterator
- : std::iterator<std::input_iterator_tag, value_type, difference_type, const_pointer, const_reference>
- {
- public:
- animation_graph::container_iterator() = default;
- animation_graph::container_iterator(const animation_graph::container_iterator&) = default;
- animation_graph::container_iterator(animation_graph::container_iterator&&) = default;
- animation_graph::container_iterator& operator=(const animation_graph::container_iterator&) = default;
- animation_graph::container_iterator& operator=(animation_graph::container_iterator&&) = default;
- ~animation_graph::container_iterator(){
- this.elem_ = nullptr;
- }
- value_type& operator*(){ return this->elem_; }
- animation_graph::container_iterator& operator++(){
- if(!this->elem->is_started()) this->elem->start();
- return *this;
- }
- animation_graph::container_iterator& operator++(int){
- if(!this->elem->is_started()) this->elem->start();
- return *this;
- }
- bool operator!=(const animation_graph::container_iterator& r) noexcept {
- return (this->elem_ != r.elem_ && this->end_flg_ != r.end_flg_);
- }
- bool operator==(const animation_graph::container_iterator& r) noexcept { return !(*this != r); }
- private:
- animation_graph::container_iterator(value_type* elem, bool end_flg) noexcept
- : elem_(elem), end_flg_(end_flg)
- {};
- value_type* elem_;
- bool end_flg_;
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement