#pragma once #include "pxl8_protocol.h" #include "pxl8_types.h" #ifdef __cplusplus extern "C" { #endif #define PXL8_NET_INPUT_HISTORY_SIZE 64 #define PXL8_NET_USERDATA_SIZE 56 #define PXL8_NET_PACKET_MAX_SIZE 2048 typedef struct pxl8_net pxl8_net; typedef struct pxl8_world pxl8_world; typedef struct pxl8_world_chunk_cache pxl8_world_chunk_cache; typedef struct pxl8_packet { u8 data[PXL8_NET_PACKET_MAX_SIZE]; usize len; } pxl8_packet; typedef struct pxl8_net_config { const char* address; u16 port; } pxl8_net_config; pxl8_result pxl8_net_connect(pxl8_net* net); bool pxl8_net_connected(const pxl8_net* net); pxl8_net* pxl8_net_create(const pxl8_net_config* config); void pxl8_net_destroy(pxl8_net* net); void pxl8_net_disconnect(pxl8_net* net); const pxl8_entity_state* pxl8_net_entities(const pxl8_net* net); const u8* pxl8_net_entity_prev_userdata(const pxl8_net* net, u64 entity_id); const u8* pxl8_net_entity_userdata(const pxl8_net* net, u64 entity_id); const pxl8_event_msg* pxl8_net_events(const pxl8_net* net); const pxl8_input_msg* pxl8_net_input_at(const pxl8_net* net, u64 tick); u64 pxl8_net_input_oldest_tick(const pxl8_net* net); void pxl8_net_input_push(pxl8_net* net, const pxl8_input_msg* input); f32 pxl8_net_lerp_alpha(const pxl8_net* net); bool pxl8_net_needs_correction(const pxl8_net* net); u64 pxl8_net_player_id(const pxl8_net* net); bool pxl8_net_poll(pxl8_net* net); u8* pxl8_net_predicted_state(pxl8_net* net); void pxl8_net_predicted_tick_set(pxl8_net* net, u64 tick); usize pxl8_net_recv(pxl8_net* net, u8* buf, usize len); pxl8_result pxl8_net_send(pxl8_net* net, const u8* data, usize len); pxl8_result pxl8_net_send_command(pxl8_net* net, const pxl8_command_msg* cmd); pxl8_result pxl8_net_send_input(pxl8_net* net, const pxl8_input_msg* input); const pxl8_snapshot_header* pxl8_net_snapshot(const pxl8_net* net); u64 pxl8_net_tick(const pxl8_net* net); void pxl8_net_update(pxl8_net* net, f32 dt); void pxl8_net_set_chunk_cache(pxl8_net* net, pxl8_world_chunk_cache* cache); pxl8_world_chunk_cache* pxl8_net_chunk_cache(pxl8_net* net); void pxl8_net_set_world(pxl8_net* net, pxl8_world* world); u32 pxl8_net_chunk_id(const pxl8_net* net); u8 pxl8_net_chunk_type(const pxl8_net* net); pxl8_result pxl8_net_send_chunk_settings(pxl8_net* net, i32 render_distance, i32 sim_distance); pxl8_result pxl8_net_spawn(pxl8_net* net, f32 x, f32 y, f32 z, f32 yaw, f32 pitch); pxl8_result pxl8_net_exit_chunk(pxl8_net* net, f32 x, f32 y, f32 z); pxl8_result pxl8_net_enter_chunk(pxl8_net* net, u32 chunk_id); #ifdef PXL8_ASYNC_THREADS void pxl8_net_start_thread(pxl8_net* net); void pxl8_net_stop_thread(pxl8_net* net); pxl8_packet* pxl8_net_pop_packet(pxl8_net* net); void pxl8_net_packet_free(pxl8_packet* pkt); bool pxl8_net_process_packet(pxl8_net* net, const pxl8_packet* pkt); #endif #ifdef __cplusplus } #endif