Advertisement
yumetodo

dxle_issue_56_example_1

Mar 31st, 2016
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.66 KB | None | 0 0
  1. namespace dxle{
  2.     class animation_graph
  3.     {
  4.     public:
  5.         namespace ch = std::chrono;
  6.         animation_graph() = delete;
  7.         animation_graph(const std::vector<texture_2d>& images, dxle::time::timing_maker::count_per_second interval, dxle::animation_mode mode)
  8.             : elem_(images, interval, mode)
  9.             {};
  10.         animation_graph(const animation_graph&) = delete;
  11.         animation_graph(animation_graph&&) = delete;
  12.         animation_graph& operator=(const animation_graph&) = delete;
  13.         animation_graph& operator=(animation_graph&&) = delete;
  14.         class container_elem;
  15.         class container_iterator;
  16.         typedef value_type;
  17.         // 差分の型
  18.         typedef ch::microseconds   difference_type;
  19.         // サイズの型
  20.         typedef size_t  size_type;
  21.         // 要素の型
  22.         typedef container_elem value_type;
  23.         // 要素を指すポインタ
  24.         typedef value_type* pointer;
  25.         // 要素を指すconstなポインタ
  26.         typedef const value_type*   const_pointer;
  27.         // 要素の非const参照
  28.         typedef value_type& reference;
  29.         // 要素のconst参照
  30.         typedef const value_type&   const_reference;
  31.         typedef container_iterator itarator;
  32.         itarator begin() noexcept { return itarator(*elem_, false); }
  33.         itarator end() noexcept { return itarator(*elem_, true); }
  34.     private:
  35.         container_elem elem_;
  36.     };
  37.     class animation_graph::container_elem {
  38.     public:
  39.         container_elem() = delete;
  40.         container_elem(const container_elem&) = delete;
  41.         container_elem(container_elem&&) = delete;
  42.         container_elem& operator=(const container_elem&) = delete;
  43.         container_elem& operator=(container_elem&&) = delete;
  44.         void start() noexcept {
  45.             if(is_animaton_finished){
  46.                 this->is_animation_started = true;
  47.                 this->begin_time_ = ch::steady_clock::now();
  48.             }
  49.         }
  50.         bool is_started() noexcept { return this->is_animation_started; }
  51.         void stop() noexcept {
  52.             if(this->is_animation_started) this->is_animaton_finished = true;
  53.         }
  54.         bool is_finished() noexcept { return this->is_animaton_finished; }
  55.         int DrawGraph(const pointi& p, bool TransFlag)const noexcept{
  56.             const size_t index = this->interval_ * ch::time_point_cast<ch::seconds>(this->begin_time_) % this->images_.size();
  57.             this->images_[index].DrawGraph(p, TransFlag);
  58.         }
  59.     private:
  60.         container_elem(const std::vector<texture_2d>& images, dxle::time::timing_maker::count_per_second interval, dxle::animation_mode mode)
  61.             : images_(images), interval_(interval), mode_(mode), begin_time_(), is_animation_started(false), is_animaton_finished(true)
  62.             {};
  63.         const std::vector<texture_2d>& images_;
  64.         dxle::time::timing_maker::count_per_second interval_;
  65.         dxle::animation_mode mode_;
  66.         ch::microseconds begin_time_;
  67.         bool is_animation_started;
  68.         bool is_animaton_finished;
  69.     };
  70.     class animation_graph::container_iterator
  71.         : std::iterator<std::input_iterator_tag, value_type, difference_type, const_pointer, const_reference>
  72.     {
  73.     public:
  74.         animation_graph::container_iterator() = default;
  75.         animation_graph::container_iterator(const animation_graph::container_iterator&) = default;
  76.         animation_graph::container_iterator(animation_graph::container_iterator&&) = default;
  77.         animation_graph::container_iterator& operator=(const animation_graph::container_iterator&) = default;
  78.         animation_graph::container_iterator& operator=(animation_graph::container_iterator&&) = default;
  79.         ~animation_graph::container_iterator(){
  80.             this.elem_ = nullptr;
  81.         }
  82.         value_type& operator*(){ return this->elem_; }
  83.         animation_graph::container_iterator& operator++(){
  84.             if(!this->elem->is_started()) this->elem->start();
  85.             return *this;
  86.         }
  87.         animation_graph::container_iterator& operator++(int){
  88.             if(!this->elem->is_started()) this->elem->start();
  89.             return *this;
  90.         }
  91.         bool operator!=(const animation_graph::container_iterator& r) noexcept {
  92.             return (this->elem_ != r.elem_ && this->end_flg_ != r.end_flg_);
  93.         }
  94.         bool operator==(const animation_graph::container_iterator& r) noexcept { return !(*this != r); }
  95.     private:
  96.         animation_graph::container_iterator(value_type* elem, bool end_flg) noexcept
  97.             : elem_(elem), end_flg_(end_flg)
  98.             {};
  99.         value_type* elem_;
  100.         bool end_flg_;
  101.     };
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement