#pragma once #include "pxl8_types.h" #ifdef __cplusplus extern "C" { #endif #define PXL8_PROTOCOL_VERSION 1 #define PXL8_MAX_SNAPSHOT_ENTITIES 256 #define PXL8_MAX_SNAPSHOT_EVENTS 32 #define PXL8_COMMAND_PAYLOAD_SIZE 64 #define PXL8_EVENT_PAYLOAD_SIZE 15 typedef enum pxl8_msg_type { PXL8_MSG_NONE = 0, PXL8_MSG_CHUNK, PXL8_MSG_CHUNK_ENTER, PXL8_MSG_CHUNK_EXIT, PXL8_MSG_COMMAND, PXL8_MSG_CONNECT, PXL8_MSG_DISCONNECT, PXL8_MSG_EVENT, PXL8_MSG_INPUT, PXL8_MSG_SNAPSHOT } pxl8_msg_type; typedef struct pxl8_msg_header { u32 sequence; u16 size; u8 type; u8 version; } pxl8_msg_header; typedef enum pxl8_cmd_type { PXL8_CMD_NONE = 0, PXL8_CMD_SPAWN_ENTITY, PXL8_CMD_EXIT_CHUNK, PXL8_CMD_ENTER_CHUNK, PXL8_CMD_SET_CHUNK_SETTINGS, } pxl8_cmd_type; typedef struct pxl8_input_msg { u32 buttons; f32 look_dx; f32 look_dy; f32 move_x; f32 move_y; f32 yaw; u64 tick; u64 timestamp; } pxl8_input_msg; typedef struct pxl8_command_msg { u16 cmd_type; u8 payload[PXL8_COMMAND_PAYLOAD_SIZE]; u16 payload_size; u64 tick; } pxl8_command_msg; typedef struct pxl8_entity_state { u64 entity_id; u8 userdata[56]; } pxl8_entity_state; typedef struct pxl8_event_msg { u8 event_type; u8 payload[PXL8_EVENT_PAYLOAD_SIZE]; } pxl8_event_msg; typedef struct pxl8_snapshot_header { u16 entity_count; u16 event_count; u64 player_id; u64 tick; f32 time; } pxl8_snapshot_header; #define PXL8_CHUNK_TYPE_VXL 0 #define PXL8_CHUNK_TYPE_BSP 1 #define PXL8_CHUNK_FLAG_RLE 0x01 #define PXL8_CHUNK_FLAG_FINAL 0x04 #define PXL8_CHUNK_MAX_PAYLOAD 1400 typedef struct pxl8_chunk_msg_header { u8 chunk_type; u8 flags; u8 fragment_idx; u8 fragment_count; u32 id; i32 cx, cy, cz; u32 version; u16 payload_size; u16 reserved; } pxl8_chunk_msg_header; typedef struct pxl8_bsp_wire_header { u32 num_cell_portals; u32 num_edges; u32 num_faces; u32 num_leafs; u32 num_marksurfaces; u32 num_nodes; u32 num_planes; u32 num_surfedges; u32 num_vertex_lights; u32 num_vertices; u32 visdata_size; } pxl8_bsp_wire_header; usize pxl8_protocol_serialize_header(const pxl8_msg_header* msg, u8* buf, usize len); usize pxl8_protocol_deserialize_header(const u8* buf, usize len, pxl8_msg_header* msg); usize pxl8_protocol_serialize_input(const pxl8_input_msg* msg, u8* buf, usize len); usize pxl8_protocol_deserialize_input(const u8* buf, usize len, pxl8_input_msg* msg); usize pxl8_protocol_serialize_command(const pxl8_command_msg* msg, u8* buf, usize len); usize pxl8_protocol_deserialize_command(const u8* buf, usize len, pxl8_command_msg* msg); usize pxl8_protocol_serialize_entity_state(const pxl8_entity_state* state, u8* buf, usize len); usize pxl8_protocol_deserialize_entity_state(const u8* buf, usize len, pxl8_entity_state* state); usize pxl8_protocol_serialize_event(const pxl8_event_msg* msg, u8* buf, usize len); usize pxl8_protocol_deserialize_event(const u8* buf, usize len, pxl8_event_msg* msg); usize pxl8_protocol_serialize_snapshot_header(const pxl8_snapshot_header* hdr, u8* buf, usize len); usize pxl8_protocol_deserialize_snapshot_header(const u8* buf, usize len, pxl8_snapshot_header* hdr); usize pxl8_protocol_serialize_chunk_msg_header(const pxl8_chunk_msg_header* hdr, u8* buf, usize len); usize pxl8_protocol_deserialize_chunk_msg_header(const u8* buf, usize len, pxl8_chunk_msg_header* hdr); usize pxl8_protocol_deserialize_bsp_wire_header(const u8* buf, usize len, pxl8_bsp_wire_header* hdr); typedef struct pxl8_chunk_enter_msg { u32 chunk_id; u8 chunk_type; u8 reserved[3]; } pxl8_chunk_enter_msg; usize pxl8_protocol_serialize_chunk_enter(const pxl8_chunk_enter_msg* msg, u8* buf, usize len); usize pxl8_protocol_deserialize_chunk_enter(const u8* buf, usize len, pxl8_chunk_enter_msg* msg); #ifdef __cplusplus } #endif