ReplicationSystem class
Public types
- struct NetFrameStats
Constructors, destructors, conversion operators
- ReplicationSystem() defaulted
- ~ReplicationSystem()
Public functions
- void Initialize(WorldBase* serverWorld)
- void DispatchFrameJobs()
- void Flush(NetConnectionManager* connMgr)
- Drain each channel's send queue to the wire. Call from Sentinel at NetworkUpdateHz.
- void RegisterEntity(Registry* reg, EntityHandle localHandle, uint8_t ownerID)
-
template<typename T>auto RegisterConstruct(ConstructRegistry* reg, T* ptr, uint8_t ownerID, uint16_t typeHash, int64_t prefabIDRaw) -> ConstructRef
- auto EnqueuePlayerConfirm(uint8_t ownerID, uint32_t serverFrame, const RPCHeader& rpcHdr, const void* params, uint16_t paramSize) -> bool
- void AddPendingResim(uint8_t ownerID, uint32_t serverFrame)
- void OpenChannel(uint8_t ownerID, uint32_t logDepth, ConnectionInfo* ci, NetConnectionManager* mgr)
- void CloseChannel(uint8_t ownerID)
- Close and reset the channel for ownerID (called on disconnect).
- auto GetChannelIfActive(uint8_t ownerID) -> ServerClientChannel*
- Returns the channel if it is active, nullptr otherwise.
- void AdvanceCommittedHorizon(uint32_t frameNumber)
- auto GetCommittedFrameHorizon() const -> uint32_t
- auto GetStats() const -> const NetFrameStats&
- void WaitForBuildJobs()
- auto GetActiveOwnerIDs() const -> const std::vector<uint8_t>&
Function documentation
void ReplicationSystem:: DispatchFrameJobs()
Check for newly published logic frames and dispatch spawn/correction build jobs. Call from Sentinel on every loop tick — no-ops if no new frame is available.
void ReplicationSystem:: RegisterEntity(Registry* reg,
EntityHandle localHandle,
uint8_t ownerID)
Pre-register a server entity with a specific OwnerID. Allocates a NetIndex, wires NetToRecord, and sets the record's NetworkID. SendSpawns will use the pre-assigned NetHandle instead of assigning a new one. Call within a Spawn() lambda on the server world.
template<typename T>
ConstructRef ReplicationSystem:: RegisterConstruct(ConstructRegistry* reg,
T* ptr,
uint8_t ownerID,
uint16_t typeHash,
int64_t prefabIDRaw)
Register a Construct for replication. Allocates a ConstructNetHandle, resolves its view EntityNetHandles, pre-builds the ConstructSpawn payload, and queues it for the next DispatchFrameJobs. Returns a valid ConstructRef — safe to pass to Soul::
bool ReplicationSystem:: EnqueuePlayerConfirm(uint8_t ownerID,
uint32_t serverFrame,
const RPCHeader& rpcHdr,
const void* params,
uint16_t paramSize)
Defer a PlayerBeginConfirm until EntitySpawn/ConstructSpawn are in the SendQueue. Returns false if no active channel for ownerID (caller falls back to direct send).
void ReplicationSystem:: AddPendingResim(uint8_t ownerID,
uint32_t serverFrame)
Record that the server resimulated ownerID's input from serverFrame. Called from AuthoritySim::OnSimInput when an input mismatch fires. Thread-safe: atomic min-update so multiple dirty marks coalesce to the earliest.
void ReplicationSystem:: OpenChannel(uint8_t ownerID,
uint32_t logDepth,
ConnectionInfo* ci,
NetConnectionManager* mgr)
Open a channel for ownerID — initializes the input log and spawn tracking. logDepth should be max(TemporalFrameCount, maxLead + 1).
void ReplicationSystem:: AdvanceCommittedHorizon(uint32_t frameNumber)
Advance the committed frame horizon to frameNumber (no-op if already past it). Called by AuthoritySim::OnFramePublished once per fixed tick. Step 7 (networked despawn) uses this to gate phase-1 graduation.
void ReplicationSystem:: WaitForBuildJobs()
Block until all in-flight build jobs from the last DispatchFrameJobs() have completed. Must be called before destroying the ReplicationSystem or any world data those jobs point to (channels, slab headers, Stats).
const std::vector<uint8_t>& ReplicationSystem:: GetActiveOwnerIDs() const
Ordered list of owner IDs with live channels — used by AuthoritySim to iterate only connected players rather than the full MaxOwnerIDs range.