Photon Documentation Repository

Photon.Registry

Vehicle Registry. Keeps a live list of every Photon vehicle, and of the emergency vehicles among them, without scanning the entity list to find them.

Membership is derived from networked state, so it is maintained by subscribing to Photon.SimpleNet.ValueChanged rather than by polling. Neither HasPhoton nor VehicleIndex is knowable when an entity is created — both arrive later, over the wire — so entity-creation hooks are not a usable trigger and are deliberately not used here.

Functions

Maintenance

SharedPhoton.Registry.Forget(ent)Source ☍

Drop an entity from every set.

Parameters

SharedPhoton.Registry.Rebuild()Source ☍

Rebuild both sets from the entity list.

The one place the registry scans, run on load and on the events that can invalidate it wholesale. Idempotent, because GM:OnReloaded can fire more than once for a single refresh.

Also the recovery path if a membership flag ever desyncs from its list, which is why it clears flags across the entity list rather than only through the lists themselves: an entity flagged as a member of a set that does not contain it would otherwise be skipped by Add forever.

SharedPhoton.Registry.Update(ent)Source ☍

Recheck which sets an entity belongs to and correct both.

Membership is recomputed from scratch every call rather than added to as values arrive. A resync sends an entity's fields in table order, so VehicleIndex can land before HasPhoton; deriving both answers together makes the result the same whichever order they turn up in.

Safe to call repeatedly with no change, which it is: the client runs Photon.SimpleNet.ValueChanged on every receipt, not only on a change.

Parameters

Classes

SharedPhoton.RegistrySource ☍

Fields

SharedPhoton.RegistrySource ☍

Sets

SharedPhoton.Registry.EMVsSource ☍

Every registered vehicle that is also an emergency vehicle. A strict subset of Photon.Registry.Vehicles.

SharedPhoton.Registry.VehiclesSource ☍

Every vehicle Photon:SetupCar has run on.

Photon.Registry.Set

3 fields Source ☍

A set of vehicles, held as a dense array plus its length.

The length is tracked rather than measured because # costs roughly as much as a loop iteration, and these are read every frame. list stays dense from 1 to count, so #list and count agree; prefer count.

SharedPhoton.Registry.Set.countSource ☍

Number of members.

SharedPhoton.Registry.Set.flagSource ☍

Field set on a member entity to mark it as one.

SharedPhoton.Registry.Set.listSource ☍

Members, 1 through count.