1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Snapshot metadata and station snapshot containers.
use crate::entity::EntityRecord;
use crate::ids::{InstanceId, OwnerEpoch, StationId, Tick};
/// Version metadata associated with a snapshot.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct SnapshotVersion {
/// Runtime version selected by the embedding application.
pub runtime_version: u32,
/// Entity/schema version selected by the embedding application.
pub schema_version: u32,
/// Ruleset version selected by the embedding application.
pub ruleset_version: u32,
/// Module version selected by the embedding application.
pub module_version: u32,
}
impl Default for SnapshotVersion {
fn default() -> Self {
Self {
runtime_version: 1,
schema_version: 1,
ruleset_version: 1,
module_version: 1,
}
}
}
/// Snapshot metadata for a single station.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct SnapshotMeta {
/// World instance id.
pub instance_id: InstanceId,
/// Station id.
pub station_id: StationId,
/// Tick captured by the snapshot.
pub tick: Tick,
/// Entity count captured by the snapshot.
pub entity_count: usize,
/// Current station owner epoch.
pub owner_epoch: OwnerEpoch,
/// Version metadata.
pub version: SnapshotVersion,
}
/// In-memory station snapshot.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct StationSnapshot {
/// Snapshot metadata.
pub meta: SnapshotMeta,
/// Entity records captured by the snapshot.
pub entities: Vec<EntityRecord>,
}
/// Hook interface for runtime version upgrades around a full barrier.
pub trait RuntimeUpgradeHook {
/// Called before state migration while the runtime is frozen.
fn pre_upgrade(&mut self, _meta: &SnapshotMeta) {}
/// Called to migrate a station snapshot while frozen.
fn migrate_state(&mut self, snapshot: StationSnapshot) -> StationSnapshot {
snapshot
}
/// Called after migration and before resume.
fn post_upgrade(&mut self, _meta: &SnapshotMeta) {}
}