SuperTuxKart
history.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2006-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_HISTORY_HPP
20 #define HEADER_HISTORY_HPP
21 
22 
23 #include "input/input.hpp"
24 #include "karts/controller/kart_control.hpp"
25 
26 #include <string>
27 #include <vector>
28 
29 class Kart;
30 
34 class History
35 {
36 private:
39 
41  unsigned int m_event_index;
42 
44  std::vector<std::string> m_kart_ident;
45 
46  // ------------------------------------------------------------------------
47  struct InputEvent
48  {
49  /* Time at which this event occurred. */
50  int m_world_ticks;
56  int m_value;
57  }; // InputEvent
58  // ------------------------------------------------------------------------
59 
61  std::vector<InputEvent> m_all_input_events;
62 
63  void allocateMemory(int size=-1);
64 public:
65  static bool m_online_history_replay;
66  History ();
67  void initRecording ();
68  void Save ();
69  void Load ();
70  void updateReplay(int world_ticks);
71  void addEvent(int kart_id, PlayerAction pa, int value);
72 
73  // -------------------I-----------------------------------------------------
75  const std::string& getKartIdent(unsigned int n)
76  {
77  return m_kart_ident[n];
78  } // getKartIdent
79  // ------------------------------------------------------------------------
81  bool replayHistory() const { return m_replay_history; }
82  // ------------------------------------------------------------------------
84  void setReplayHistory(bool b) { m_replay_history=b; }
85 };
86 
87 extern History* history;
88 
89 #endif
PlayerAction m_action
Which action it was.
Definition: history.hpp:54
The main kart class.
Definition: kart.hpp:68
void setReplayHistory(bool b)
Set if replay is enabled or not.
Definition: history.hpp:84
std::vector< InputEvent > m_all_input_events
All input events.
Definition: history.hpp:61
PlayerAction
types of input events / what actions the players can do
Definition: input.hpp:116
void initRecording()
Initialise the history for a new recording.
Definition: history.cpp:49
void Save()
Saves the history stored in the internal data structures into a file called history....
Definition: history.cpp:133
unsigned int m_event_index
Points to the last used input event index.
Definition: history.hpp:41
Definition: history.hpp:34
void allocateMemory(int size=-1)
Allocates memory for the history.
Definition: history.cpp:61
int m_value
The value to use.
Definition: history.hpp:56
void updateReplay(int world_ticks)
Sets the kart position and controls to the recorded history value.
Definition: history.cpp:95
int m_kart_index
For which kart the event was.
Definition: history.hpp:52
void Load()
Loads a history from history.dat in the current directory.
Definition: history.cpp:189
std::vector< std::string > m_kart_ident
The identities of the karts to use.
Definition: history.hpp:44
History()
Initialises the history object and sets the mode to none.
Definition: history.cpp:40
Definition: history.hpp:47
const std::string & getKartIdent(unsigned int n)
Returns the identifier of the n-th kart.
Definition: history.hpp:75
void addEvent(int kart_id, PlayerAction pa, int value)
Stores an input event (e.g.
Definition: history.cpp:78
bool m_replay_history
True if a history should be replayed,.
Definition: history.hpp:38
bool replayHistory() const
Returns if a history is replayed, i.e.
Definition: history.hpp:81