SuperTuxKart
Loading...
Searching...
No Matches
replay_recorder.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2012-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_REPLAY_RECORDER_HPP
20#define HEADER_REPLAY_RECORDER_HPP
21
22#include "items/attachment.hpp"
23#include "items/powerup_manager.hpp"
24#include "karts/controller/kart_control.hpp"
25#include "replay/replay_base.hpp"
26
27#include <vector>
28
33{
34private:
35 std::string m_filename;
36
38 std::vector< std::vector<TransformEvent> > m_transform_events;
39
41 std::vector< std::vector<PhysicInfo> > m_physic_info;
42
44 std::vector< std::vector<BonusInfo> > m_bonus_info;
45
47 std::vector< std::vector<KartReplayEvent> > m_kart_replay_event;
48
50 std::vector<float> m_last_saved_time;
51
53 std::vector<unsigned int> m_count_transforms;
54
57
58 bool m_complete_replay;
59
60 bool m_incorrect_replay;
61
62 unsigned int m_max_frames;
63
64 // Stores the steering value at the previous transform.
65 // Used to trigger the recording of new transforms.
66 float m_previous_steer = 0.0f;
67
68 const float DISTANCE_FAST_UPDATES = 10.0f;
69
70 const float DISTANCE_MAX_UPDATES = 1.0f;
71
72 uint64_t m_last_uid;
73
74#ifdef DEBUG
76 unsigned int m_count;
77
79 unsigned int m_count_skipped_time;
80
82 unsigned int m_count_skipped_interpolation;
83#endif
84
86 uint64_t computeUID(float min_time);
87
88
91public:
92 void init();
93 void reset();
94 void save();
95 void update(int ticks);
96
97 const uint64_t getLastUID() { return m_last_uid; }
98
102 static int enumToCode (Attachment::AttachmentType type);
103 static int enumToCode (PowerupManager::PowerupType type);
104 static Attachment::AttachmentType codeToEnumAttach (int code);
105 static PowerupManager::PowerupType codeToEnumItem (int code);
106
107 // ------------------------------------------------------------------------
109 static void create() {
110 assert(!m_replay_recorder);
112 }
113 // ------------------------------------------------------------------------
117 // ------------------------------------------------------------------------
119 static void destroy() { delete m_replay_recorder; m_replay_recorder=NULL; }
120 // ------------------------------------------------------------------------
122 virtual const std::string& getReplayFilename(int replay_file_number = 1) const { return m_filename; }
123 // ------------------------------------------------------------------------
124}; // ReplayRecorder
125
126#endif
127
Definition: replay_base.hpp:33
Definition: replay_recorder.hpp:33
ReplayRecorder()
Initialises the Replay engine.
Definition: replay_recorder.cpp:50
std::vector< float > m_last_saved_time
Time at which a transform was saved for the last time.
Definition: replay_recorder.hpp:50
std::vector< unsigned int > m_count_transforms
Counts the number of transform events for each kart.
Definition: replay_recorder.hpp:53
static int enumToCode(Attachment::AttachmentType type)
Functions to encode and decode attahcments and item types, so that the stored value is independent fr...
Definition: replay_recorder.cpp:489
static ReplayRecorder * get()
Returns the instance of the replay object.
Definition: replay_recorder.hpp:116
virtual const std::string & getReplayFilename(int replay_file_number=1) const
Returns the filename that was opened.
Definition: replay_recorder.hpp:122
uint64_t computeUID(float min_time)
Compute the replay's UID ; partly based on race data ; partly randomly.
Definition: replay_recorder.cpp:317
static void create()
Creates a new instance of the replay object.
Definition: replay_recorder.hpp:109
~ReplayRecorder()
Frees all stored data.
Definition: replay_recorder.cpp:62
void save()
Saves the replay data stored in the internal data structures.
Definition: replay_recorder.cpp:353
std::vector< std::vector< KartReplayEvent > > m_kart_replay_event
A separate vector of Replay Events for all other events.
Definition: replay_recorder.hpp:47
void update(int ticks)
Saves the current replay data.
Definition: replay_recorder.cpp:115
std::vector< std::vector< PhysicInfo > > m_physic_info
A separate vector of Replay Events for all physic info.
Definition: replay_recorder.hpp:41
static ReplayRecorder * m_replay_recorder
Static pointer to the one instance of the replay object.
Definition: replay_recorder.hpp:56
void init()
Initialise the replay recorder.
Definition: replay_recorder.cpp:90
std::vector< std::vector< BonusInfo > > m_bonus_info
A separate vector of Replay Events for all item/nitro info.
Definition: replay_recorder.hpp:44
void reset()
Reset the replay recorder.
Definition: replay_recorder.cpp:68
static void destroy()
Delete the instance of the replay object.
Definition: replay_recorder.hpp:119
std::vector< std::vector< TransformEvent > > m_transform_events
A separate vector of Replay Events for all transforms.
Definition: replay_recorder.hpp:38