19#ifndef HEADER_REWIND_MANAGER_HPP
20#define HEADER_REWIND_MANAGER_HPP
22#include "network/rewind_queue.hpp"
23#include "utils/stk_process.hpp"
94 std::map<int, std::vector<std::function<void()> > > m_local_state;
116 std::vector<RewindInfoEventFunction*> m_pending_rief;
118 bool m_schedule_reset_network_body;
120 std::set<std::string> m_missing_rewinders;
125 void clearExpiredRewinder()
129 if (it->second.expired())
138 void mergeRewindInfoEventFunction();
154 ProcessType pt = STKProcess::getType();
162 ProcessType pt = STKProcess::getType();
171 void rewindTo(
int target_ticks,
int ticks_now,
bool fast_forward);
174 bool confirmed,
int ticks = -1);
180 std::shared_ptr<Rewinder> getRewinder(
const std::string& name)
185 if (
auto r = it->second.lock())
191 bool addRewinder(std::shared_ptr<Rewinder> rewinder);
197 int getNotRewoundWorldTicks()
const
208 bool useLocalEvent()
const;
211 { m_pending_rief.push_back(rief); }
216 bool shouldSaveState(
int ticks)
222 void resetSmoothNetworkBody() { m_schedule_reset_network_body =
true; }
226 void addMissingRewinder(
const std::string& name)
227 { m_missing_rewinders.insert(name); }
229 bool hasMissingRewinder(
const std::string& name)
const
230 {
return m_missing_rewinders.find(name) != m_missing_rewinders.end(); }
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:53
A simple class that defines an interface to event rewinding: an undo() function when going back in ti...
Definition: event_rewinder.hpp:29
Definition: rewind_info.hpp:182
Used to store rewind information for a given time for all rewind instances.
Definition: rewind_info.hpp:45
This class manages rewinding.
Definition: rewind_manager.hpp:85
void handleResetSmoothNetworkBody()
Reset all smooth network body of rewinders so the rubber band effect of moveable does not exist durin...
Definition: rewind_manager.cpp:429
std::map< std::string, std::weak_ptr< Rewinder > > m_all_rewinder
A list of all objects that can be rewound.
Definition: rewind_manager.hpp:97
bool m_is_rewinding
Indicates if currently a rewind is happening.
Definition: rewind_manager.hpp:106
static RewindManager * m_rewind_manager[PT_COUNT]
Singleton pointer.
Definition: rewind_manager.hpp:88
int getLatestConfirmedState() const
Returns the time of the latest confirmed state.
Definition: rewind_manager.hpp:203
static std::atomic_bool m_enable_rewind_manager
En- or Disable the rewind manager.
Definition: rewind_manager.hpp:92
void rewindTo(int target_ticks, int ticks_now, bool fast_forward)
Rewinds to the specified time, then goes forward till the current World::getTime() is reached again: ...
Definition: rewind_manager.cpp:294
void saveState()
Saves a state using the GameProtocol function to combine several independent rewinders to write one s...
Definition: rewind_manager.cpp:155
static RewindManager * get()
Returns the singleton.
Definition: rewind_manager.hpp:160
void addNetworkState(BareNetworkString *buffer, int ticks)
Adds a state to the list of network rewind data.
Definition: rewind_manager.cpp:145
unsigned int m_overall_state_size
Overall amount of memory allocated by states.
Definition: rewind_manager.hpp:103
RewindManager()
The constructor.
Definition: rewind_manager.cpp:65
void update(int ticks)
Determines if a new state snapshot should be taken, and if so calls all rewinder to do so.
Definition: rewind_manager.cpp:189
static void setEnable(bool m)
En- or disables rewinding.
Definition: rewind_manager.hpp:147
int m_state_frequency
How much time between consecutive state saves.
Definition: rewind_manager.hpp:109
void addNetworkEvent(EventRewinder *event_rewinder, BareNetworkString *buffer, int ticks)
Adds an event to the list of network rewind data.
Definition: rewind_manager.cpp:131
static RewindManager * create()
Creates the singleton.
Definition: rewind_manager.cpp:44
void playEventsTill(int world_ticks, bool fast_forward)
Replays all events from the last event played till the specified time.
Definition: rewind_manager.cpp:230
static void destroy()
Destroys the singleton.
Definition: rewind_manager.cpp:54
~RewindManager()
Frees all saved state information.
Definition: rewind_manager.cpp:74
static bool isEnabled()
Returns if rewinding is enabled or not.
Definition: rewind_manager.hpp:150
std::atomic< int > m_not_rewound_ticks
This stores the original World time in ticks during a rewind.
Definition: rewind_manager.hpp:114
bool addRewinder(std::shared_ptr< Rewinder > rewinder)
Adds a Rewinder to the list of all rewinders.
Definition: rewind_manager.cpp:273
bool isRewinding() const
Returns true if currently a rewind is happening.
Definition: rewind_manager.hpp:194
void reset()
Frees all saved state information and all destroyable rewinder.
Definition: rewind_manager.cpp:84
void addEvent(EventRewinder *event_rewinder, BareNetworkString *buffer, bool confirmed, int ticks=-1)
Adds an event to the rewind data.
Definition: rewind_manager.cpp:107
RewindQueue m_rewind_queue
The queue that stores all rewind infos.
Definition: rewind_manager.hpp:100
Definition: rewind_queue.hpp:37
int getLatestConfirmedState() const
Returns the time of the latest confirmed state.
Definition: rewind_queue.hpp:89
Definition: rewinder.hpp:44