GekkoNet 1.0
C/C++ Peer to Peer Game Networking SDK
Loading...
Searching...
No Matches
storage.cpp
Go to the documentation of this file.
1#include "storage.h"
2
7
8
9void Gekko::StateStorage::Init(u32 num_states, u32 state_size, bool limited)
10{
11 const u32 num = limited ? 2 : num_states + 2;
12 _max_num_states = num;
13
14 for (u32 i = 0; i < _max_num_states; i++) {
15 _states.push_back(std::make_unique<StateEntry>());
16 _states.back().get()->state = std::make_unique<u8[]>(state_size);
17 _states.back().get()->state_len = state_size;
18 }
19
20 _runahead_state.state = std::make_unique<u8[]>(state_size);
21 _runahead_state.state_len = state_size;
23}
24
29
31{
32 frame = frame < 0 ? frame + _max_num_states : frame;
33 return _states[frame % _max_num_states].get();
34}
StateEntry * GetRunaheadState()
Definition storage.cpp:25
StateEntry * GetState(Frame frame)
Definition storage.cpp:30
std::vector< std::unique_ptr< StateEntry > > _states
Definition storage.h:30
void Init(u32 num_states, u32 state_size, bool limited)
Definition storage.cpp:9
StateEntry _runahead_state
Definition storage.h:32
int32_t Frame
Definition gekko_types.h:18
uint32_t u32
Definition gekko_types.h:7
static const i32 NULL_FRAME
Definition input.h:21