add support for message channeling
parent
347f85063e
commit
21ca700626
|
@ -48,20 +48,20 @@ static WORLD_PKT_WRITER(sp_pkt_writer) {
|
|||
|
||||
static WORLD_PKT_WRITER(mp_pkt_writer) {
|
||||
if (pkt->is_reliable) {
|
||||
return network_msg_send(udata, pkt->data, pkt->datalen);
|
||||
return network_msg_send(udata, pkt->data, pkt->datalen, pkt->channel_id);
|
||||
}
|
||||
else {
|
||||
return network_msg_send_unreliable(udata, pkt->data, pkt->datalen);
|
||||
return network_msg_send_unreliable(udata, pkt->data, pkt->datalen, pkt->channel_id);
|
||||
}
|
||||
}
|
||||
|
||||
static WORLD_PKT_WRITER(mp_cli_pkt_writer) {
|
||||
(void)udata;
|
||||
if (pkt->is_reliable) {
|
||||
return network_msg_send(0, pkt->data, pkt->datalen);
|
||||
return network_msg_send(0, pkt->data, pkt->datalen, pkt->channel_id);
|
||||
}
|
||||
else {
|
||||
return network_msg_send_unreliable(0, pkt->data, pkt->datalen);
|
||||
return network_msg_send_unreliable(0, pkt->data, pkt->datalen, pkt->channel_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ int32_t network_server_start(const char *host, uint16_t port) {
|
|||
address.host = ENET_HOST_ANY;
|
||||
address.port = port;
|
||||
|
||||
server = enet_host_create(&address, 100, 2, 0, 0);
|
||||
server = enet_host_create(&address, 8, 2, 0, 0);
|
||||
|
||||
if (server == NULL) {
|
||||
zpl_printf("[ERROR] An error occured while trying to create a server host.\n");
|
||||
|
@ -173,16 +173,16 @@ uint64_t network_server_get_entity(void *peer_id) {
|
|||
|
||||
//~ NOTE(zaklaus): messaging
|
||||
|
||||
static int32_t network_msg_send_raw(ENetPeer *peer_id, void *data, size_t datalen, uint32_t flags) {
|
||||
static int32_t network_msg_send_raw(ENetPeer *peer_id, void *data, size_t datalen, uint32_t flags, uint16_t channel_id) {
|
||||
if (peer_id == 0) peer_id = peer;
|
||||
ENetPacket *packet = enet_packet_create(data, datalen, flags);
|
||||
return enet_peer_send(peer_id, 0, packet);
|
||||
return enet_peer_send(peer_id, channel_id, packet);
|
||||
}
|
||||
|
||||
int32_t network_msg_send(void *peer_id, void *data, size_t datalen) {
|
||||
return network_msg_send_raw(peer_id, data, datalen, ENET_PACKET_FLAG_RELIABLE);
|
||||
int32_t network_msg_send(void *peer_id, void *data, size_t datalen, uint16_t channel_id) {
|
||||
return network_msg_send_raw(peer_id, data, datalen, ENET_PACKET_FLAG_RELIABLE, channel_id);
|
||||
}
|
||||
|
||||
int32_t network_msg_send_unreliable(void *peer_id, void *data, size_t datalen) {
|
||||
return network_msg_send_raw(peer_id, data, datalen, 0);
|
||||
int32_t network_msg_send_unreliable(void *peer_id, void *data, size_t datalen, uint16_t channel_id) {
|
||||
return network_msg_send_raw(peer_id, data, datalen, 0, channel_id);
|
||||
}
|
||||
|
|
|
@ -19,5 +19,5 @@ void network_server_assign_entity(void *peer_id, uint64_t ent_id);
|
|||
uint64_t network_server_get_entity(void *peer_id);
|
||||
|
||||
// NOTE(zaklaus): messaging
|
||||
int32_t network_msg_send(void *peer_id, void *data, size_t datalen);
|
||||
int32_t network_msg_send_unreliable(void *peer_id, void *data, size_t datalen);
|
||||
int32_t network_msg_send(void *peer_id, void *data, size_t datalen, uint16_t channel_id);
|
||||
int32_t network_msg_send_unreliable(void *peer_id, void *data, size_t datalen, uint16_t channel_id);
|
||||
|
|
|
@ -15,6 +15,7 @@ typedef struct pkt_header {
|
|||
uint16_t id;
|
||||
uint16_t sender;
|
||||
uint16_t view_id;
|
||||
uint16_t channel_id;
|
||||
uint8_t *data;
|
||||
uint32_t datalen;
|
||||
int8_t is_reliable;
|
||||
|
|
|
@ -39,7 +39,7 @@ static inline size_t pkt_pack_msg_size(cw_pack_context *pc) {
|
|||
return pc->current - pc->start; // NOTE(zaklaus): length
|
||||
}
|
||||
|
||||
static inline int32_t pkt_prep_msg(pkt_header *pkt, pkt_messages id, uint16_t view_id, size_t pkt_size, int8_t is_reliable) {
|
||||
static inline int32_t pkt_prep_msg(pkt_header *pkt, pkt_messages id, uint16_t view_id, size_t pkt_size, int8_t is_reliable, uint16_t channel_id) {
|
||||
zpl_zero_item(pkt);
|
||||
static uint8_t pkt_data[PKT_BUFSIZ] = {0};
|
||||
zpl_memcopy(pkt_data, pkt_buffer, pkt_size);
|
||||
|
@ -48,15 +48,16 @@ static inline int32_t pkt_prep_msg(pkt_header *pkt, pkt_messages id, uint16_t vi
|
|||
pkt->view_id = view_id;
|
||||
pkt->datalen = pkt_header_encode(id, view_id, pkt_data, pkt_size);
|
||||
pkt->is_reliable = is_reliable;
|
||||
pkt->channel_id = channel_id;
|
||||
pkt->id = id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern int32_t world_write(pkt_header *pkt, void *udata);
|
||||
|
||||
static inline int32_t pkt_world_write(pkt_messages id, size_t pkt_size, int8_t is_reliable, uint16_t view_id, void *udata) {
|
||||
static inline int32_t pkt_world_write(pkt_messages id, size_t pkt_size, int8_t is_reliable, uint16_t view_id, void *udata, uint16_t channel_id) {
|
||||
pkt_header pkt;
|
||||
PKT_IF(pkt_prep_msg(&pkt, id, view_id, pkt_size, is_reliable));
|
||||
PKT_IF(pkt_prep_msg(&pkt, id, view_id, pkt_size, is_reliable, channel_id));
|
||||
return world_write(&pkt, udata);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ size_t pkt_00_init_encode(pkt_00_init *table) {
|
|||
|
||||
size_t pkt_00_init_send(uint16_t view_id) {
|
||||
pkt_00_init table = {.view_id = view_id };
|
||||
return pkt_world_write(MSG_ID_00_INIT, pkt_00_init_encode(&table), 1, view_id, NULL);
|
||||
return pkt_world_write(MSG_ID_00_INIT, pkt_00_init_encode(&table), 1, view_id, NULL, 1);
|
||||
}
|
||||
|
||||
int32_t pkt_00_init_handler(pkt_header *header) {
|
||||
|
|
|
@ -26,7 +26,7 @@ size_t pkt_01_welcome_send(uint32_t seed,
|
|||
uint16_t chunk_size,
|
||||
uint16_t world_size) {
|
||||
pkt_01_welcome table = {.seed = seed, .ent_id = ent_id, .chunk_size = chunk_size, .world_size = world_size};
|
||||
return pkt_world_write(MSG_ID_01_WELCOME, pkt_01_welcome_encode(&table), 1, view_id, (void*)peer_id);
|
||||
return pkt_world_write(MSG_ID_01_WELCOME, pkt_01_welcome_encode(&table), 1, view_id, (void*)peer_id, 0);
|
||||
}
|
||||
|
||||
int32_t pkt_01_welcome_handler(pkt_header *header) {
|
||||
|
|
|
@ -37,7 +37,7 @@ size_t pkt_send_keystate_send(uint16_t view_id,
|
|||
uint8_t swap_from,
|
||||
uint8_t swap_to) {
|
||||
pkt_send_keystate table = { .x = x, .y = y, .mx = mx, .my = my, .use = use, .sprint = sprint, .ctrl = ctrl, .drop = drop, .selected_item = selected_item, .swap = swap, .swap_from = swap_from, .swap_to = swap_to };
|
||||
return pkt_world_write(MSG_ID_SEND_KEYSTATE, pkt_send_keystate_encode(&table), 1, view_id, NULL);
|
||||
return pkt_world_write(MSG_ID_SEND_KEYSTATE, pkt_send_keystate_encode(&table), 1, view_id, NULL, 1);
|
||||
}
|
||||
|
||||
size_t pkt_send_keystate_encode(pkt_send_keystate *table) {
|
||||
|
|
|
@ -9,7 +9,7 @@ size_t pkt_send_librg_update(uint64_t peer_id,
|
|||
uint8_t ticker,
|
||||
void *data,
|
||||
size_t datalen) {
|
||||
return pkt_world_write(MSG_ID_LIBRG_UPDATE, pkt_send_librg_update_encode(data, (int32_t)datalen, ticker), 1, view_id, (void*)peer_id);
|
||||
return pkt_world_write(MSG_ID_LIBRG_UPDATE, pkt_send_librg_update_encode(data, (int32_t)datalen, ticker), 1, view_id, (void*)peer_id, 0);
|
||||
}
|
||||
|
||||
size_t pkt_send_librg_update_encode(void *data, int32_t data_length, uint8_t layer_id) {
|
||||
|
|
Loading…
Reference in New Issue