SuperTuxKart
track_sector.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2011-2015 Joerg Henrichs
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef HEADER_TRACK_SECTOR_HPP
20 #define HEADER_TRACK_SECTOR_HPP
21 
22 #include "utils/vec3.hpp"
23 
24 class BareNetworkString;
25 class Track;
26 
39 {
40 private:
43 
46 
49 
54 
55  Vec3 m_estimated_valid_track_coords;
56 
57  Vec3 m_latest_valid_track_coords;
58 
60  bool m_on_road;
61 
62  int m_last_triggered_checkline;
63 
64 public:
65  TrackSector();
66  void reset();
67  void rescue();
68  void update(const Vec3 &xyz, bool ignore_vertical = false);
69  float getRelativeDistanceToCenter() const;
70  // ------------------------------------------------------------------------
72  float getDistanceFromStart(bool account_for_checklines, bool strict=false) const
73  {
74  if (account_for_checklines && strict)
75  return m_latest_valid_track_coords.getZ();
76  else if (account_for_checklines)
77  return m_estimated_valid_track_coords.getZ();
78  else
79  return m_current_track_coords.getZ();
80  }
81  // ------------------------------------------------------------------------
83  float getDistanceToCenter() const { return m_current_track_coords.getX(); }
84  // ------------------------------------------------------------------------
87  // ------------------------------------------------------------------------
89  bool isOnRoad() const { return m_on_road; }
90  // ------------------------------------------------------------------------
91  void setLastTriggeredCheckline(int i) { m_last_triggered_checkline = i; }
92  // ------------------------------------------------------------------------
93  int getLastTriggeredCheckline() const
94  { return m_last_triggered_checkline; }
95  // ------------------------------------------------------------------------
96  int getLastValidGraphNode() const { return m_last_valid_graph_node; }
97  // ------------------------------------------------------------------------
98  void saveState(BareNetworkString* buffer) const;
99  // ------------------------------------------------------------------------
100  void rewindTo(BareNetworkString* buffer);
101  // ------------------------------------------------------------------------
103  // ------------------------------------------------------------------------
104  void restoreCompleteState(const BareNetworkString& b);
105 
106 }; // TrackSector
107 
108 #endif
109 
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:53
This object keeps track of which sector an object is on.
Definition: track_sector.hpp:39
float getRelativeDistanceToCenter() const
Returns the relative distance of the corresponding kart from the center, i.e.
Definition: track_sector.cpp:166
void rescue()
Sets current and last valid graph node to the rescue location.
Definition: track_sector.cpp:144
bool m_on_road
True if the object is on the road (driveline), or not.
Definition: track_sector.hpp:60
float getDistanceFromStart(bool account_for_checklines, bool strict=false) const
Returns how far the the object is from the start line.
Definition: track_sector.hpp:72
void saveState(BareNetworkString *buffer) const
Only basket ball is used for rewind for TrackSector so save the minimum.
Definition: track_sector.cpp:182
float getDistanceToCenter() const
Returns the distance to the centre driveline.
Definition: track_sector.hpp:83
void saveCompleteState(BareNetworkString *bns)
Save completely for spectating in linear race.
Definition: track_sector.cpp:199
void update(const Vec3 &xyz, bool ignore_vertical=false)
Updates the current graph node index, and the track coordinates for the specified point.
Definition: track_sector.cpp:54
TrackSector()
Initialises the object, and sets the current graph node to be undefined.
Definition: track_sector.cpp:34
int m_current_graph_node
The graph node the object is on.
Definition: track_sector.hpp:42
int m_last_valid_graph_node
The index of the last valid graph node.
Definition: track_sector.hpp:48
bool isOnRoad() const
Returns if this object is on the road (driveline).
Definition: track_sector.hpp:89
Vec3 m_current_track_coords
The coordinates of this object on the track, i.e.
Definition: track_sector.hpp:53
int m_estimated_valid_graph_node
The index of the estimated valid graph node.
Definition: track_sector.hpp:45
int getCurrentGraphNode() const
Returns the current graph node.
Definition: track_sector.hpp:86
Definition: track.hpp:115
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35