supertux
path.hpp
1 // SuperTux Path
2 // Copyright (C) 2005 Philipp <balinor@pnxs.de>
3 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef HEADER_SUPERTUX_OBJECT_PATH_HPP
20 #define HEADER_SUPERTUX_OBJECT_PATH_HPP
21 
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 #include "math/vector.hpp"
27 
28 class ObjectOption;
29 class ReaderMapping;
30 class Writer;
31 
32 enum class WalkMode {
33  // moves from first to last path node and stops
34  ONE_SHOT,
35  // moves from first to last node then in reverse order back to first
36  PING_PONG,
37  // moves from last node back to the first node
38  CIRCULAR
39 };
40 
41 WalkMode string_to_walk_mode(const std::string& mode_string);
42 std::string walk_mode_to_string(WalkMode walk_mode);
43 
44 class Path final
45 {
46 public:
48  class Node
49  {
50  public:
52  float time;
54  Node() :
55  position(),
56  time()
57  {}
58  };
59 
60 public:
61  Path();
62  Path(const Vector& pos);
63 
64  void read(const ReaderMapping& reader);
65  void save(Writer& writer);
66 
67  Vector get_base() const;
68 
70  int get_nearest_node_no(const Vector& reference_point) const;
71 
73  int get_farthest_node_no(const Vector& reference_point) const;
74 
76  void move_by(const Vector& shift);
77 
79  void edit_path();
80 
82  bool is_valid() const;
83 
84  const std::vector<Node>& get_nodes() const { return m_nodes; }
85 
86 public:
87  std::vector<Node> m_nodes;
88 
89  WalkMode m_mode;
90 
91 private:
92  Path(const Path&) = delete;
93  Path& operator=(const Path&) = delete;
94 };
95 
96 #endif
97 
98 /* EOF */
Definition: writer.hpp:27
Simple two dimensional vector.
Definition: vector.hpp:24
Definition: object_option.hpp:48
Definition: path.hpp:44
Helper class that stores an individual node of a Path.
Definition: path.hpp:48
Definition: reader_mapping.hpp:31
Vector position
the position of this node
Definition: path.hpp:51
float time
time (in seconds) to get from this node to next node
Definition: path.hpp:52