FAuthorityLeaseSystem
- Module
- Networking
- Header
#include "Networking/Replication/AuthorityLease.h"- Namespace
Mowo
Type aliases
| Alias | Description |
|---|---|
using FLeaseListener = std::function<void(const FLeaseEvent&)> | |
using FClaimPriorityFn = std::function<int32_t(uint32_t peerId, EntityID item, int32_t priorityHint)> | |
using FClaimValidatorFn = std::function<bool(uint32_t peerId, EntityID item)> | Runs before a claim is considered at all (reach, item state...). |
using FMessageSink = std::function<void(uint32_t targetPeerId, NetworkId nid, uint16_t eventId, const uint8_t* data, size_t len, bool reliable)> | targetPeerId 0 = the host. Unset = the world's ReplicationManager. |
Properties
| Type | Name | Description |
|---|---|---|
static constexpr float | kJitterSlackSeconds | How far behind the elapsed time a pose may still be explained by arrival jitter: two packets that land in one host tick are not a doubling of speed. Default 0.05f. |
static constexpr uint32_t | kMaxRejectionsPerLease | Refused poses inside one lease before the host takes the item back. Default 5. |
Constructors
| Signature | Name | Description |
|---|---|---|
FAuthorityLeaseSystem() = default | FAuthorityLeaseSystem | |
~FAuthorityLeaseSystem() override = default | ~FAuthorityLeaseSystem |
Public functions
| Returns | Name | Description |
|---|---|---|
void | Initialize | |
void | Shutdown | |
void | Update | |
bool | RequestLease | Client: ask the host for the item. |
bool | PredictLease | Client: start simulating the item as a predicted lease WITHOUT sending a request, because a gameplay request already carries it (a carry pickup). |
bool | ReleaseLease | Client: hand the item back with its current pose and velocity (a drop or a throw). |
bool | RevokeLease | Host: take a client's lease back (HostReclaimed). |
bool | GrantLease | Host: grant directly, under the same conflict rule as a request. |
uint32_t | GetLeaseHolder | Who simulates the item: 0 = the host, otherwise the lessee's peer id. |
bool | IsHostHeld | |
bool | IsLeasedLocally | This client holds the lease and simulates the item. |
bool | IsSimulatingLocally | This client simulates the item: a granted lease or one still predicted. |
float | GetLeaseRemaining | Seconds left on the lease as this machine knows it; 0 when none. |
uint32_t | AddListener | |
void | RemoveListener | |
void | SetClaimPriorityResolver | |
void | SetClaimValidator | |
void | SetRoleOverride | |
void | ClearRoleOverride | |
ELeaseRole | GetEffectiveRole | |
uint32_t | GetLocalPeerId | |
void | SetMessageSink | |
void | HandleMessage | Inbound message (the RPC observer's path, and the headless one). |
void | ServerHandlePeerLeft | Host: the peer is gone; revoke everything it holds. |
void | SetPoseSendRateHz | |
const FStats& | GetStats | |
void | ResetStats | |
ELeasePoseVerdict | ValidatePose | Checks incoming against the last accepted pose elapsed seconds ago. |
float | ReturnBlendWeight | Remaining fraction of a return blend that started elapsed ago and lasts duration: smoothstep, 1 at the start, 0 at the end. |
Function details
FAuthorityLeaseSystem
FAuthorityLeaseSystem() = default~FAuthorityLeaseSystem
~FAuthorityLeaseSystem() override = defaultInitialize
void Initialize(World* world) overrideShutdown
void Shutdown() overrideUpdate
void Update(float deltaTime) overrideRequestLease
bool RequestLease(EntityID item, int32_t priorityHint = 0)Client: ask the host for the item. The answer arrives as a Granted or Denied event. Host: the host's own player claims it (host wins: a client lease on it is revoked).
PredictLease
bool PredictLease(EntityID item, uint32_t requestSeq)Client: start simulating the item as a predicted lease WITHOUT sending a request, because a gameplay request already carries it (a carry pickup). The host answers with GrantLease(item, peer, priority, requestSeq); a grant or deny carrying another seq is not this one.
ReleaseLease
bool ReleaseLease(EntityID item)Client: hand the item back with its current pose and velocity (a drop or a throw). Host: the host's own player lets go.
RevokeLease
bool RevokeLease(EntityID item, ELeaseRevokeReason reason = ELeaseRevokeReason::HostReclaimed)Host: take a client's lease back (HostReclaimed).
GrantLease
bool GrantLease(EntityID item, uint32_t peerId, int32_t priority = 0, uint32_t requestSeq = 0)Host: grant directly, under the same conflict rule as a request. requestSeq answers a client's PredictLease; 0 is an unasked grant.
GetLeaseHolder
uint32_t GetLeaseHolder(EntityID item) constWho simulates the item: 0 = the host, otherwise the lessee's peer id. Read from the replicated component, so it is right on every machine, late joiners included.
IsHostHeld
bool IsHostHeld(EntityID item) constIsLeasedLocally
bool IsLeasedLocally(EntityID item) constThis client holds the lease and simulates the item.
IsSimulatingLocally
bool IsSimulatingLocally(EntityID item) constThis client simulates the item: a granted lease or one still predicted.
GetLeaseRemaining
float GetLeaseRemaining(EntityID item) constSeconds left on the lease as this machine knows it; 0 when none.
AddListener
uint32_t AddListener(FLeaseListener listener)RemoveListener
void RemoveListener(uint32_t handle)SetClaimPriorityResolver
void SetClaimPriorityResolver(FClaimPriorityFn fn)SetClaimValidator
void SetClaimValidator(FClaimValidatorFn fn)SetRoleOverride
void SetRoleOverride(ELeaseRole role, uint32_t localPeerId)ClearRoleOverride
void ClearRoleOverride()GetEffectiveRole
ELeaseRole GetEffectiveRole() constGetLocalPeerId
uint32_t GetLocalPeerId() constSetMessageSink
void SetMessageSink(FMessageSink sink)HandleMessage
void HandleMessage(uint32_t senderPeerId, NetworkId nid, uint16_t eventId, const uint8_t* data, size_t len)Inbound message (the RPC observer's path, and the headless one).
ServerHandlePeerLeft
void ServerHandlePeerLeft(uint32_t peerId)Host: the peer is gone; revoke everything it holds. Also detected by polling the ReplicationManager's peer table when there is one.
SetPoseSendRateHz
void SetPoseSendRateHz(float hz)GetStats
const FStats& GetStats() constResetStats
void ResetStats()ValidatePose
static ELeasePoseVerdict ValidatePose(const FLeasePose& last, float elapsed, const FLeasePose& incoming, float maxSpeed, float teleportDistance, FLeasePose& out)Checks incoming against the last accepted pose elapsed seconds ago. Accepted: within maxSpeed. Clamped: too fast but not a jump; out is pulled back onto the speed limit along the same direction. Rejected: a teleport, out = last. Reported velocities are clamped to maxSpeed in both accepted cases.
ReturnBlendWeight
static float ReturnBlendWeight(float elapsed, float duration)Remaining fraction of a return blend that started elapsed ago and lasts duration: smoothstep, 1 at the start, 0 at the end.