pub struct CheckpointManager {
pub max_checkpoints: usize,
/* private fields */
}Expand description
Manages a bounded list of checkpoints.
When the checkpoint count exceeds max_checkpoints, the oldest (by
created_at) is evicted automatically.
Fields§
§max_checkpoints: usizeImplementations§
Source§impl CheckpointManager
impl CheckpointManager
Sourcepub fn create(
&mut self,
name: impl Into<String>,
pos: Vec2,
snapshot: WorldSnapshot,
) -> u64
pub fn create( &mut self, name: impl Into<String>, pos: Vec2, snapshot: WorldSnapshot, ) -> u64
Create a new checkpoint and return its id.
If the checkpoint list is at capacity, the oldest checkpoint is removed.
Sourcepub fn create_with_time(
&mut self,
name: impl Into<String>,
pos: Vec2,
snapshot: WorldSnapshot,
created_at: f64,
) -> u64
pub fn create_with_time( &mut self, name: impl Into<String>, pos: Vec2, snapshot: WorldSnapshot, created_at: f64, ) -> u64
Like create but with an explicit game-time timestamp.
Sourcepub fn get(&self, id: u64) -> Option<&Checkpoint>
pub fn get(&self, id: u64) -> Option<&Checkpoint>
Get a checkpoint by id.
Sourcepub fn get_mut(&mut self, id: u64) -> Option<&mut Checkpoint>
pub fn get_mut(&mut self, id: u64) -> Option<&mut Checkpoint>
Get a mutable checkpoint by id.
Sourcepub fn get_nearest(&self, pos: Vec2) -> Option<&Checkpoint>
pub fn get_nearest(&self, pos: Vec2) -> Option<&Checkpoint>
Get the checkpoint closest to pos (Euclidean distance).
Sourcepub fn get_most_recent(&self) -> Option<&Checkpoint>
pub fn get_most_recent(&self) -> Option<&Checkpoint>
Get the most recently created checkpoint (highest created_at).
Sourcepub fn get_within_radius(&self, pos: Vec2, radius: f32) -> Vec<&Checkpoint>
pub fn get_within_radius(&self, pos: Vec2, radius: f32) -> Vec<&Checkpoint>
Get all checkpoints within radius of pos, sorted by distance.
Sourcepub fn list(&self) -> &[Checkpoint]
pub fn list(&self) -> &[Checkpoint]
Iterate over all checkpoints.
Sourcepub fn remove(&mut self, id: u64) -> bool
pub fn remove(&mut self, id: u64) -> bool
Remove the checkpoint with the given id. Returns true if found.
pub fn is_empty(&self) -> bool
pub fn is_at_cap(&self) -> bool
Sourcepub fn serialize_all(&self) -> Vec<u8> ⓘ
pub fn serialize_all(&self) -> Vec<u8> ⓘ
Serialize all checkpoints to a JSON byte vector.
Sourcepub fn deserialize_all(
bytes: &[u8],
) -> Result<Vec<Checkpoint>, DeserializeError>
pub fn deserialize_all( bytes: &[u8], ) -> Result<Vec<Checkpoint>, DeserializeError>
Deserialize checkpoints from a JSON byte vector (as produced by serialize_all).
Sourcepub fn load_from_bytes(&mut self, bytes: &[u8]) -> Result<(), DeserializeError>
pub fn load_from_bytes(&mut self, bytes: &[u8]) -> Result<(), DeserializeError>
Restore checkpoints from bytes, replacing any existing ones.