pub struct ViewReader { /* private fields */ }Expand description
Reads the view’s frame for one game, sending only what changed since its last frame. Keep one per game: a host that loads another game starts a new reader. A reader handed another game sends a full frame.
Implementations§
Source§impl ViewReader
impl ViewReader
Sourcepub fn new() -> ViewReader
pub fn new() -> ViewReader
A reader that has sent nothing, so its first frame is full.
Sourcepub fn frame(&mut self, sim: &Simulation, full: bool) -> Vec<f64>
pub fn frame(&mut self, sim: &Simulation, full: bool) -> Vec<f64>
The dynamic frame as one flat number array.
Header (HEADER slots, see layout::header): minutes, tower
revision, meta revision, meal overlay revision, logSeq, money, star,
the unlocked kinds (bit k set when the kind with code k is unlocked),
the population (as Simulation::population counts it), weather, the
Santa, explosion, thief, treasure and VIP effects and the event
counts as frameView carries them, a pending choice (0 or 1),
onHourRuns, the room count the slots index, the full flag, this
reader’s frame number (1 for its first), then the people, room record
and transport counts.
Then people records of PERSON_RECORD, every person in the crowd
as crate::frame::frame_view sends them: id, seed, staff (0 or 1), state, floor, x,
fy, wait. Then units room records of UNIT_RECORD:
the room’s slot (its position in the structural snapshot’s room list),
then state, occupants, customersIn, hotelCustomersIn, outForMeal (an
absent counter is -1). Then every transport as crate::frame::frame_view writes it.
The room records are every room, in slot order, with the full flag
set, when full is true, on this reader’s first frame, or when the
revision or the unit count moved since its last frame (the slots then
index a new structure). Otherwise they are the rooms whose fields
changed since its last frame, in slot order, a field compared bit for
bit.
A full frame makes one pass over the rooms index, which happens once
per revision move (a command), on a new tower, or when the host asks.
Any other frame visits the rooms the mark log names since this
reader’s last frame, each once, plus a binary search of the rooms
index for each; with nothing marked it visits no room. When the marks
it reads reach half the rooms (an hour can mark nearly all of them),
or the log has dropped marks this reader never read (it fell more than
MARK_CAP marks behind), the frame compares every room once instead,
which sends the same rooms for less (compare_all). The population
is a running total that each visited room corrects. One allocation,
made at the frame’s size.
The engine’s own writes go through the setters, which mark the room.
A native host that writes a unit’s frame fields or residents itself,
outside the commands and the tick, leaves the room unmarked, so its
next frame passes full.