pub enum SaveMode {
EveryFrame,
Sparse,
}Expand description
Controls how game states are saved for rollback.
This enum replaces the boolean sparse_saving parameter for improved API clarity.
Using an enum makes the code self-documenting and prevents accidentally passing
the wrong boolean value.
§Choosing a Save Mode
-
SaveMode::EveryFrame(default): Saves state every frame. Best when:- State serialization is fast
- You want minimal rollback distance
- You have sufficient memory for frame history
-
SaveMode::Sparse: Only saves the minimum confirmed frame. Best when:- State serialization is expensive (complex game state)
- You want to minimize save overhead
- You can tolerate potentially longer rollbacks
§Example
use fortress_rollback::{SessionBuilder, SaveMode, Config};
// For games with expensive state serialization
let builder = SessionBuilder::<MyConfig>::new()
.with_save_mode(SaveMode::Sparse);
// For games with fast state serialization (default)
let builder = SessionBuilder::<MyConfig>::new()
.with_save_mode(SaveMode::EveryFrame);Variants§
EveryFrame
Save game state every frame.
This is the default mode. It provides the shortest possible rollback distance since the most recent confirmed state is always available. However, it requires a save operation every frame, which may be expensive for complex game states.
Use this mode when:
- Your game state is small or fast to serialize
- You want minimal rollback distance
- You have sufficient memory for the frame history
Sparse
Only save the minimum confirmed frame.
In this mode, only the frame for which all inputs from all players are confirmed correct will be saved. This dramatically reduces the number of save operations but may result in longer rollbacks when predictions are incorrect.
Use this mode when:
- Saving your game state is expensive (large or complex state)
- Advancing the game state is relatively cheap
- You can tolerate longer rollbacks in exchange for fewer saves