Skip to main content
Verticopolis engineGitHub

ViewReader

Struct ViewReader 

Source
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

Source

pub fn new() -> ViewReader

A reader that has sent nothing, so its first frame is full.

Source

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.

Trait Implementations§

Source§

impl Default for ViewReader

Source§

fn default() -> ViewReader

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.