75 lines
2.8 KiB
C
75 lines
2.8 KiB
C
|
|
#pragma once
|
||
|
|
|
||
|
|
#include "pxl8_net.h"
|
||
|
|
#include "demo3d_protocol.h"
|
||
|
|
#include "pxl8_types.h"
|
||
|
|
|
||
|
|
#define DEMO3D_NET_INPUT_HISTORY_SIZE 64
|
||
|
|
#define DEMO3D_NET_USERDATA_SIZE 56
|
||
|
|
#define DEMO3D_NET_TICK_RATE 30.0f
|
||
|
|
|
||
|
|
typedef struct demo3d_world demo3d_world;
|
||
|
|
typedef struct demo3d_chunk_cache demo3d_chunk_cache;
|
||
|
|
|
||
|
|
typedef struct demo3d_net {
|
||
|
|
pxl8_net* transport;
|
||
|
|
|
||
|
|
demo3d_chunk_cache* chunk_cache;
|
||
|
|
i32 chunk_cx;
|
||
|
|
i32 chunk_cz;
|
||
|
|
bool has_chunk;
|
||
|
|
demo3d_world* world;
|
||
|
|
|
||
|
|
u64 highest_tick;
|
||
|
|
f32 interp_time;
|
||
|
|
|
||
|
|
demo3d_entity_state entities[DEMO3D_MAX_SNAPSHOT_ENTITIES];
|
||
|
|
demo3d_entity_state prev_entities[DEMO3D_MAX_SNAPSHOT_ENTITIES];
|
||
|
|
demo3d_snapshot_header prev_snapshot;
|
||
|
|
demo3d_snapshot_header snapshot;
|
||
|
|
|
||
|
|
u64 input_head;
|
||
|
|
demo3d_input_msg input_history[DEMO3D_NET_INPUT_HISTORY_SIZE];
|
||
|
|
u64 input_oldest_tick;
|
||
|
|
|
||
|
|
u8 predicted_state[DEMO3D_NET_USERDATA_SIZE];
|
||
|
|
u64 predicted_tick;
|
||
|
|
} demo3d_net;
|
||
|
|
|
||
|
|
demo3d_net* demo3d_net_create(const pxl8_net_config* config);
|
||
|
|
void demo3d_net_destroy(demo3d_net* ng);
|
||
|
|
pxl8_result demo3d_net_connect(demo3d_net* ng);
|
||
|
|
bool demo3d_net_connected(const demo3d_net* ng);
|
||
|
|
void demo3d_net_disconnect(demo3d_net* ng);
|
||
|
|
|
||
|
|
const demo3d_entity_state* demo3d_net_entities(const demo3d_net* ng);
|
||
|
|
const u8* demo3d_net_entity_prev_userdata(const demo3d_net* ng, u64 entity_id);
|
||
|
|
const u8* demo3d_net_entity_userdata(const demo3d_net* ng, u64 entity_id);
|
||
|
|
const demo3d_input_msg* demo3d_net_input_at(const demo3d_net* ng, u64 tick);
|
||
|
|
u64 demo3d_net_input_oldest_tick(const demo3d_net* ng);
|
||
|
|
void demo3d_net_input_push(demo3d_net* ng, const demo3d_input_msg* input);
|
||
|
|
f32 demo3d_net_lerp_alpha(const demo3d_net* ng);
|
||
|
|
bool demo3d_net_needs_correction(const demo3d_net* ng);
|
||
|
|
u64 demo3d_net_player_id(const demo3d_net* ng);
|
||
|
|
bool demo3d_net_poll(demo3d_net* ng);
|
||
|
|
u8* demo3d_net_predicted_state(demo3d_net* ng);
|
||
|
|
void demo3d_net_predicted_tick_set(demo3d_net* ng, u64 tick);
|
||
|
|
pxl8_result demo3d_net_send_command(demo3d_net* ng, const demo3d_command_msg* cmd);
|
||
|
|
pxl8_result demo3d_net_send_input(demo3d_net* ng, const demo3d_input_msg* input);
|
||
|
|
const demo3d_snapshot_header* demo3d_net_snapshot(const demo3d_net* ng);
|
||
|
|
u64 demo3d_net_tick(const demo3d_net* ng);
|
||
|
|
void demo3d_net_update(demo3d_net* ng, f32 dt);
|
||
|
|
void demo3d_net_set_chunk_cache(demo3d_net* ng, demo3d_chunk_cache* cache);
|
||
|
|
demo3d_chunk_cache* demo3d_net_chunk_cache(demo3d_net* ng);
|
||
|
|
void demo3d_net_set_world(demo3d_net* ng, demo3d_world* world);
|
||
|
|
i32 demo3d_net_chunk_cx(const demo3d_net* ng);
|
||
|
|
i32 demo3d_net_chunk_cz(const demo3d_net* ng);
|
||
|
|
bool demo3d_net_has_chunk(const demo3d_net* ng);
|
||
|
|
pxl8_result demo3d_net_spawn(demo3d_net* ng, f32 x, f32 y, f32 z, f32 yaw, f32 pitch);
|
||
|
|
|
||
|
|
#ifdef PXL8_ASYNC_THREADS
|
||
|
|
void demo3d_net_start_thread(demo3d_net* ng);
|
||
|
|
void demo3d_net_stop_thread(demo3d_net* ng);
|
||
|
|
bool demo3d_net_dispatch_packet(demo3d_net* ng, const pxl8_packet* pkt);
|
||
|
|
#endif
|