Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
snapshot Namespace Reference

Snapshot serialization/deserialization utilities for networked state synchronization. More...

Functions

void write_string (std::vector< uint8_t > &out, const std::string &str)
 Writes a length-prefixed string to a binary buffer.
 
bool read_string (const std::vector< uint8_t > &data, size_t &offset, std::string &out)
 Reads a length-prefixed string from a binary buffer.
 
void write_bytes (std::vector< uint8_t > &out, const void *data, size_t size)
 Writes raw bytes to a binary buffer.
 
bool read_bytes (const std::vector< uint8_t > &data, size_t &offset, void *out, size_t size)
 Reads raw bytes from a binary buffer.
 
Message create_full_snapshot (const Scene &scene, DefaultMessageTypes messageType)
 Builds a full snapshot message containing all networked GameObjects in a scene.
 
Message create_delta_snapshot (const Scene &scene, DefaultMessageTypes messageType)
 Builds a delta snapshot message containing only changed (dirty) networked objects.
 
void apply_full_snapshot (Scene &scene, const Message &msg)
 Applies a full snapshot to a scene, creating/updating GameObjects as needed.
 
void apply_delta_snapshot (Scene &scene, const Message &msg)
 Applies a delta snapshot to a scene, updating only the listed objects.
 

Detailed Description

Snapshot serialization/deserialization utilities for networked state synchronization.

These helpers provide a clean API for packing GameObject state into network messages and unpacking them on remote clients. The snapshot payloads are binary and compact: uint16_t count for each object: char uuid[37] float x, y, z (position)

The engine exposes creators for full snapshots and delta snapshots and corresponding apply helpers for clients.

Function Documentation

◆ apply_delta_snapshot()

void snapshot::apply_delta_snapshot ( Scene scene,
const Message msg 
)

Applies a delta snapshot to a scene, updating only the listed objects.

This will update transforms for existing networked objects and create missing ones if necessary.

◆ apply_full_snapshot()

void snapshot::apply_full_snapshot ( Scene scene,
const Message msg 
)

Applies a full snapshot to a scene, creating/updating GameObjects as needed.

For each object in the snapshot:

Parameters
sceneTarget scene to apply snapshot to.
msgThe snapshot message to deserialize.
spriteTextureName of the sprite texture to use for newly created objects.

◆ create_delta_snapshot()

Message snapshot::create_delta_snapshot ( const Scene scene,
DefaultMessageTypes  messageType 
)

Builds a delta snapshot message containing only changed (dirty) networked objects.

Implementations should mark objects dirty (via their NetworkIdentity) when their relevant state changes. This function clears the dirty flag for included objects.

Parameters
sceneThe scene to snapshot.
messageTypeThe message type to assign for delta snapshots.
Returns
A Message containing only changed objects since the last snapshot.

◆ create_full_snapshot()

Message snapshot::create_full_snapshot ( const Scene scene,
DefaultMessageTypes  messageType 
)

Builds a full snapshot message containing all networked GameObjects in a scene.

Parameters
sceneThe scene to snapshot.
messageTypeThe message type to assign (usually SNAPSHOT_FULL).
Returns
A Message ready to send, containing serialized GameObject state.

◆ read_bytes()

bool snapshot::read_bytes ( const std::vector< uint8_t > &  data,
size_t &  offset,
void *  out,
size_t  size 
)

Reads raw bytes from a binary buffer.

Copies the specified number of bytes from the buffer. Advances the offset past the read data.

Parameters
dataInput buffer to read from.
offsetCurrent read position; updated to point past the bytes.
outOutput buffer to store the deserialized data.
sizeNumber of bytes to read.
Returns
true if read succeeded, false if buffer bounds exceeded.

◆ read_string()

bool snapshot::read_string ( const std::vector< uint8_t > &  data,
size_t &  offset,
std::string &  out 
)

Reads a length-prefixed string from a binary buffer.

Decodes a uint16_t length prefix and reads the corresponding string data. Advances the offset past the read data.

Parameters
dataInput buffer to read from.
offsetCurrent read position; updated to point past the string.
outOutput string to store the deserialized value.
Returns
true if read succeeded, false if buffer bounds exceeded.

◆ write_bytes()

void snapshot::write_bytes ( std::vector< uint8_t > &  out,
const void *  data,
size_t  size 
)

Writes raw bytes to a binary buffer.

Appends the specified data to the buffer without any encoding. Used for serializing fixed-size types (floats, ints, etc.).

Parameters
outOutput buffer to write to.
dataPointer to data to serialize.
sizeNumber of bytes to write.

◆ write_string()

void snapshot::write_string ( std::vector< uint8_t > &  out,
const std::string &  str 
)

Writes a length-prefixed string to a binary buffer.

Encodes the string length as a uint16_t followed by the string data. Used for compact serialization of variable-length strings.

Parameters
outOutput buffer to write to.
strString to serialize.