Object API
Overview
Networked object types representing replicated entities.
All classes live in the SharedMode namespace.
Header: Types.h
Object (Base Class)
Abstract base class for all networked objects.
Contains the replicated word buffer, string heap and per-object metadata.
Public Constants
| Constant | Value | Description |
|---|---|---|
ExtraTailWords |
sizeof(ObjectTail) / 4 (8) |
Words reserved for the ObjectTail at the end of the buffer. |
DynamicOwnerCooldownTime |
1.0 / 3 |
Ownership transfer cooldown in seconds. |
Constructor
C++
explicit Object(SharedMode::Client *client);
Public Fields
| Field | Type | Description |
|---|---|---|
Id |
ObjectId |
Unique network identifier. |
Type |
TypeRef |
Type descriptor (hash + word count). |
Engine |
void * |
Opaque pointer to the engine-side object. |
EngineBlob |
Data |
Engine-specific binary data blob. |
EngineFlags |
uint32_t |
Engine-specific bitflags. |
EngineHash |
uint64_t |
Engine-specific hash (used for sub-object identification). |
Shadow |
BufferT<Word> |
Previous-tick state for dirty detection. |
Words |
BufferT<Word> |
Current replicated state buffer. |
StringHeap |
NetworkedStringHeap |
Per-object string heap for networked string properties. Default capacity 1024 bytes. |
Public Methods
| Method | Signature | Description |
|---|---|---|
Root |
virtual ObjectRoot *Root() = 0 |
Returns the root object (self for roots, parent's root for children). |
GetHasValidData |
bool GetHasValidData() const |
Returns true if the object has received at least one state update. |
SetHasValidData |
void SetHasValidData() |
Mark the object as having valid replicated data. |
SetSendUpdates |
void SetSendUpdates(bool sendUpdates) |
Enable or disable outgoing state updates for this object. |
GetSendReport |
EMAReport GetSendReport() const |
Returns EMA statistics for bytes sent by this object. |
GetRecvReport |
EMAReport GetRecvReport() const |
Returns EMA statistics for bytes received by this object. |
RecordBytesSent |
void RecordBytesSent(uint32_t bytes) |
Record outgoing bytes for EMA tracking. |
RecordBytesReceived |
void RecordBytesReceived(uint32_t bytes) |
Record incoming bytes for EMA tracking. |
AddString |
StringHandle AddString(const PhotonCommon::CharType *str) |
Allocate and replicate a string in this object's string heap. |
ResolveString |
const PhotonCommon::CharType *ResolveString(const StringHandle &handle, StringMessage &OutStatus) |
Look up a string by handle. Sets OutStatus to indicate validity. |
FreeString |
StringHandle FreeString(const StringHandle &handle) |
Free a string from the heap. Returns an invalidated handle. |
IsValidStringHandle |
bool IsValidStringHandle(const StringHandle &handle) |
Returns true if the handle points to a live entry. |
GetStringLength |
uint32_t GetStringLength(const StringHandle &handle) |
Returns the byte length of the string referenced by the handle. |
LogStringData |
void LogStringData(const StringHandle &handle) |
Dump debug info about a string handle to the log. |
ObjectRoot
Final class inheriting from Object.
Represents a top-level networked entity that can own sub-objects.
Public Methods
| Method | Signature | Description |
|---|---|---|
Root |
ObjectRoot *Root() override |
Returns this. |
GetSubObjects |
const std::vector<ObjectId> &GetSubObjects() const |
Returns all child sub-object IDs. |
GetMap |
Map GetMap() const |
Returns the map index this object belongs to. |
GetOwnerMode |
ObjectOwnerModes GetOwnerMode() const |
Returns the ownership model for this object. |
GetCombinedSendReport |
EMAReport GetCombinedSendReport() const |
Returns combined EMA send statistics for the root and all sub-objects. |
GetCombinedRecvReport |
EMAReport GetCombinedRecvReport() const |
Returns combined EMA receive statistics for the root and all sub-objects. |
IsRequired |
bool IsRequired(ObjectId id) const |
Returns true if id is in the required objects list. |
RequiredObjectsCount |
int32_t RequiredObjectsCount() const |
Returns the number of required objects. |
RequiredObjects |
ObjectId *RequiredObjects() const |
Returns a pointer to the required objects array (stored in the tail). |
Static Methods
| Method | Signature | Description |
|---|---|---|
Is |
static bool Is(const Object *obj) |
Returns true if the object is an ObjectRoot. |
Cast |
static ObjectRoot *Cast(Object *obj) |
Safe downcast from Object*. Returns nullptr if not a root. |
Cast |
static const ObjectRoot *Cast(const Object *obj) |
Const overload of the safe downcast. |
ObjectChild
Final class inheriting from Object.
Represents a sub-object attached to a root.
Public Methods
| Method | Signature | Description |
|---|---|---|
Root |
ObjectRoot *Root() override |
Returns the parent root object via the client. |
Static Methods
| Method | Signature | Description |
|---|---|---|
GetParent |
static ObjectId GetParent(const Object *obj) |
Returns the parent ObjectId if obj is a child, otherwise ObjectId(0). |
Is |
static bool Is(const Object *obj) |
Returns true if the object is an ObjectChild. |
Cast |
static ObjectChild *Cast(Object *obj) |
Safe downcast from Object*. Returns nullptr if not a child. |
Cast |
static const ObjectChild *Cast(const Object *obj) |
Const overload of the safe downcast. |
ObjectTail
Packed struct appended after the replicated word buffer of every object.
Stored inline in the Words buffer.
C++
#pragma pack(push, 4)
struct ObjectTail {
int32_t RequiredObjectsCount;
uint64_t InterestKey;
int32_t Destroyed;
int32_t RoomSendRate;
PlayerId PredictingPlayer;
uint32_t InputSequence;
int32_t Dummy;
};
#pragma pack(pop)
static_assert(sizeof(ObjectTail) == 32);
| Field | Offset | Size | Description |
|---|---|---|---|
RequiredObjectsCount |
0 | 4 | Number of ObjectIds following the tail in the word buffer. |
InterestKey |
4 | 8 | The interest key assigned to this object. See Interest Keys. |
Destroyed |
12 | 4 | Non-zero when the object has been destroyed. |
RoomSendRate |
16 | 4 | Server-authoritative ticks between sends (0 = default). |
PredictingPlayer |
20 | 2 | PlayerId of the player currently predicting this object. |
InputSequence |
24 | 4 | Input sequence number for prediction reconciliation. |
Dummy |
28 | 4 | Unused reserved field. |
ObjectPacketEnvelope
Tracks which objects were included in a single outgoing packet.
Used for delivery and loss callbacks.
C++
class ObjectPacketEnvelope {
public:
std::vector<std::tuple<ObjectId, Tick>> ObjectUpdates{};
};
| Field | Type | Description |
|---|---|---|
ObjectUpdates |
vector<tuple<ObjectId, Tick>> |
List of (ObjectId, Tick) pairs for each object update included in the packet. |
Related
- Objects -- Object hierarchy and Words buffer
- Client API -- Object creation and destruction methods
- StringHeap API -- Per-object string heap
- Types API -- ObjectId, TypeRef, enums