Entities

Gamehoster.Entities is a Map of the entity views you can see, keyed by netId. Rocks, bullets and every other non-player object live here. Pick one kind with Gamehoster.Entities.ofType(type).

The map

MemberHolds
Gamehoster.Entities.get(netId)the view for that netId.
Gamehoster.Entities.ofType(type)the views of one entity type (e.g. 'rock').
Gamehoster.Entities.values()iterate every entity view.
Gamehoster.Entities.sizehow many entities are in view.

An entity view

MemberHolds
fields each entity schema field, eased for this frame, at the top level.
.currentthe newest authoritative sample, un-interpolated.
.prevthe previous sample.
.datathe view's front-end bag, kept for the entity's whole visible life.
.ida stable id for the entity's whole visible life.
.typethe entity's type name.
for (var rock of Gamehoster.Entities.ofType('rock')) drawRock(rock, Gamehoster.Frame.tick)
for (var shot of Gamehoster.Entities.ofType('bullet')) drawShot(shot, Gamehoster.Frame.tick)
Draw the rocks and the bullets at the current render tick.

Ballistic entities

A ballistic entity, a rock or a bullet, carries only its start point, its velocity and its spawn tick. It needs no per-tick sample stream: the renderer computes its position from those constants and the current Gamehoster.Frame.tick.

var t = Gamehoster.Frame.tick - rock.spawnTick
var x = rock.x0 + rock.vx * t
var y = rock.y0 + rock.vy * t
drawAt(x, y, rock.spin * t)
Compute a rock's position from its start, velocity and spawn tick.

The entity bodies

Three client-only bodies sit beside an entity type's schema. Each is optional.

BodyWhen it runsFor
gamehoster-entity-enter.js an entity appears Seed that view's .data bag.
gamehoster-entity-smooth.js each frame Shape how the view eases between authoritative samples.
gamehoster-entity-exit.js an entity leaves your view Tidy up anything the bag held, or start a fade-out.