|
Capycore Engine
0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
|
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. | |
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.
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.
Applies a full snapshot to a scene, creating/updating GameObjects as needed.
For each object in the snapshot:
| scene | Target scene to apply snapshot to. |
| msg | The snapshot message to deserialize. |
| spriteTexture | Name of the sprite texture to use for newly created objects. |
| 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.
| scene | The scene to snapshot. |
| messageType | The message type to assign for delta snapshots. |
| Message snapshot::create_full_snapshot | ( | const Scene & | scene, |
| DefaultMessageTypes | messageType | ||
| ) |
Builds a full snapshot message containing all networked GameObjects in a scene.
| scene | The scene to snapshot. |
| messageType | The message type to assign (usually SNAPSHOT_FULL). |
| 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.
| data | Input buffer to read from. |
| offset | Current read position; updated to point past the bytes. |
| out | Output buffer to store the deserialized data. |
| size | Number of bytes to read. |
| 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.
| data | Input buffer to read from. |
| offset | Current read position; updated to point past the string. |
| out | Output string to store the deserialized value. |
| 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.).
| out | Output buffer to write to. |
| data | Pointer to data to serialize. |
| size | Number of bytes to write. |
| 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.
| out | Output buffer to write to. |
| str | String to serialize. |