SuperTuxKart
Loading...
Searching...
No Matches
kart_rewinder.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2013 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_KART_REWINDER_HPP
20#define HEADER_KART_REWINDER_HPP
21
22#include "karts/kart.hpp"
23#include "network/rewinder.hpp"
24#include "utils/cpp2011.hpp"
25
26class AbstractKart;
28
29class KartRewinder : public Rewinder, public Kart
30{
31private:
32 float m_prev_steering, m_steering_smoothing_dt, m_steering_smoothing_time;
33
34 bool m_has_server_state;
35public:
36 KartRewinder(const std::string& ident, unsigned int world_kart_id,
37 int position, const btTransform& init_transform,
38 HandicapLevel handicap,
39 std::shared_ptr<GE::GERenderInfo> ri);
40 ~KartRewinder() {}
41 virtual void saveTransform() OVERRIDE;
42 virtual void computeError() OVERRIDE;
43 virtual BareNetworkString* saveState(std::vector<std::string>* ru)
44 OVERRIDE;
45 void reset() OVERRIDE;
46 virtual void restoreState(BareNetworkString *p, int count) OVERRIDE;
47 virtual void rewindToEvent(BareNetworkString *p) OVERRIDE {}
48 virtual void update(int ticks) OVERRIDE;
49 // -------------------------------------------------------------------------
50 virtual float getSteerPercent() const OVERRIDE
51 {
52 if (m_steering_smoothing_dt >= 0.0f)
53 {
54 return m_steering_smoothing_dt * AbstractKart::getSteerPercent() +
55 (1.0f - m_steering_smoothing_dt) * m_prev_steering;
56 }
58 }
59 // -------------------------------------------------------------------------
60 virtual void updateGraphics(float dt) OVERRIDE
61 {
62 if (m_steering_smoothing_dt >= 0.0f)
63 {
64 m_steering_smoothing_dt += dt / m_steering_smoothing_time;
65 if (m_steering_smoothing_dt > 1.0f)
66 m_steering_smoothing_dt = -1.0f;
67 }
69 }
70 // -------------------------------------------------------------------------
71 virtual void undoState(BareNetworkString *p) OVERRIDE {}
72 // -------------------------------------------------------------------------
73 virtual void undoEvent(BareNetworkString *p) OVERRIDE {}
74 // ------------------------------------------------------------------------
75 virtual std::function<void()> getLocalStateRestoreFunction() OVERRIDE;
76
77
78}; // Rewinder
79#endif
80
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:62
virtual float getSteerPercent() const
Returns the current steering value for this kart.
Definition: abstract_kart.hpp:130
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:53
Definition: kart_rewinder.hpp:30
virtual float getSteerPercent() const OVERRIDE
Returns the current steering value for this kart.
Definition: kart_rewinder.hpp:50
virtual void restoreState(BareNetworkString *p, int count) OVERRIDE
Actually rewind to the specified state.
Definition: kart_rewinder.cpp:275
virtual void updateGraphics(float dt) OVERRIDE
Updates the graphics model.
Definition: kart_rewinder.hpp:60
virtual void computeError() OVERRIDE
Called when a rewind is finished, and is used to compute the error caused by the rewind (which is the...
Definition: kart_rewinder.cpp:101
virtual void saveTransform() OVERRIDE
This function is called immediately before a rewind is done and saves the current transform for the k...
Definition: kart_rewinder.cpp:88
virtual void undoEvent(BareNetworkString *p) OVERRIDE
Called when an event needs to be undone.
Definition: kart_rewinder.hpp:73
virtual void rewindToEvent(BareNetworkString *p) OVERRIDE
Called when an event needs to be replayed.
Definition: kart_rewinder.hpp:47
void reset() OVERRIDE
Resets status in case of a resetart.
Definition: kart_rewinder.cpp:66
virtual void update(int ticks) OVERRIDE
Called once a frame.
Definition: kart_rewinder.cpp:447
virtual void undoState(BareNetworkString *p) OVERRIDE
Undo the effects of the given state, but do not rewind to that state (which is done by rewindTo).
Definition: kart_rewinder.hpp:71
virtual BareNetworkString * saveState(std::vector< std::string > *ru) OVERRIDE
Saves all state information for a kart in a memory buffer.
Definition: kart_rewinder.cpp:165
The main kart class.
Definition: kart.hpp:69
virtual void updateGraphics(float dt) OVERRIDE
Updates the graphics model.
Definition: kart.cpp:3218
Definition: rewinder.hpp:44
HandicapLevel
Handicap per player.
Definition: remote_kart_info.hpp:42