supertux
path_walker.hpp
1 // SuperTux
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HEADER_SUPERTUX_OBJECT_PATH_WALKER_HPP
18 #define HEADER_SUPERTUX_OBJECT_PATH_WALKER_HPP
19 
20 #include <string.h>
21 #include <memory>
22 
23 #include "math/sizef.hpp"
24 #include "object/path.hpp"
25 #include "util/uid.hpp"
26 
27 template<typename T>
28 class ObjectOption;
29 
31 class PathWalker final
32 {
33 public:
35  class Handle
36  {
37  public:
39  Vector get_pos(const Sizef& size, const Vector& pos) const;
40 
41  public:
42  Vector m_scalar_pos;
43  Vector m_pixel_offset;
44  };
45 
46 public:
47  PathWalker(UID path_uid, bool running = true);
48  ~PathWalker();
49 
51  void update(float dt_sec);
52 
54  Vector get_pos(const Sizef& object_size, const Handle& handle) const;
55 
57  void goto_node(int node_idx);
58 
60  void jump_to_node(int node_idx, bool instantaneous = false);
61 
63  void start_moving();
64 
66  void stop_moving();
67 
69  bool is_running() const { return m_running; }
70 
71 private:
72  void advance_node();
73  void goback_node();
74  Path* get_path() const;
75 
76 public:
77  UID m_path_uid;
78 
80  bool m_running;
81 
82 private:
83  size_t m_current_node_nr;
84  size_t m_next_node_nr;
85 
87  int m_stop_at_node_nr;
88 
91  float m_node_time;
92  float m_node_mult;
93 
94  float m_walking_speed;
95 
96 private:
97  PathWalker(const PathWalker&) = delete;
98  PathWalker& operator=(const PathWalker&) = delete;
99 };
100 
101 #endif
102 
103 /* EOF */
A walker that travels along a path.
Definition: path_walker.hpp:31
bool m_running
set to false to immediately stop advancing
Definition: path_walker.hpp:80
Definition: object_option.hpp:77
Helper class that allows to displace a handle on an object.
Definition: path_walker.hpp:35
void start_moving()
start advancing automatically
Definition: path_walker.cpp:170
Definition: path.hpp:48
Definition: uid.hpp:37
void jump_to_node(int node_idx, bool instantaneous=false)
teleport instantly to given node
Definition: path_walker.cpp:150
Vector m_pixel_offset
The secondary displacement, in absolute size (pixels)
Definition: path_walker.hpp:43
bool is_running() const
returns true if PathWalker is currently moving
Definition: path_walker.hpp:69
void goto_node(int node_idx)
advance until at given node, then stop
Definition: path_walker.cpp:139
void stop_moving()
stop advancing automatically
Definition: path_walker.cpp:177
void update(float dt_sec)
advances the path walker on the path and returns its new position
Definition: path_walker.cpp:77
Vector m_scalar_pos
The scale of the object the handle should be displaced to ((0,0) = top left, (1,1) = bottom right) ...
Definition: path_walker.hpp:42
Definition: sizef.hpp:26