improve sw renderer
This commit is contained in:
parent
415d424057
commit
39ee0fefb7
89 changed files with 9380 additions and 2307 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#include "pxl8_net.h"
|
||||
#include "pxl8_mem.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
|
@ -94,7 +95,7 @@ bool pxl8_net_connected(const pxl8_net* net) {
|
|||
}
|
||||
|
||||
pxl8_net* pxl8_net_create(const pxl8_net_config* config) {
|
||||
pxl8_net* net = calloc(1, sizeof(pxl8_net));
|
||||
pxl8_net* net = pxl8_calloc(1, sizeof(pxl8_net));
|
||||
if (!net) return NULL;
|
||||
|
||||
net->mode = config->mode;
|
||||
|
|
@ -116,7 +117,7 @@ pxl8_net* pxl8_net_create(const pxl8_net_config* config) {
|
|||
void pxl8_net_destroy(pxl8_net* net) {
|
||||
if (!net) return;
|
||||
pxl8_net_disconnect(net);
|
||||
free(net);
|
||||
pxl8_free(net);
|
||||
}
|
||||
|
||||
void pxl8_net_disconnect(pxl8_net* net) {
|
||||
|
|
@ -203,11 +204,11 @@ u64 pxl8_net_player_id(const pxl8_net* net) {
|
|||
bool pxl8_net_poll(pxl8_net* net) {
|
||||
if (!net || !net->connected) return false;
|
||||
|
||||
size_t len = pxl8_net_recv(net, net->recv_buf, sizeof(net->recv_buf));
|
||||
usize len = pxl8_net_recv(net, net->recv_buf, sizeof(net->recv_buf));
|
||||
if (len < sizeof(pxl8_msg_header)) return false;
|
||||
|
||||
pxl8_msg_header hdr;
|
||||
size_t offset = pxl8_protocol_deserialize_header(net->recv_buf, len, &hdr);
|
||||
usize offset = pxl8_protocol_deserialize_header(net->recv_buf, len, &hdr);
|
||||
if (hdr.type != PXL8_MSG_SNAPSHOT) return false;
|
||||
|
||||
pxl8_snapshot_header snap;
|
||||
|
|
@ -243,17 +244,17 @@ void pxl8_net_predicted_tick_set(pxl8_net* net, u64 tick) {
|
|||
net->predicted_tick = tick;
|
||||
}
|
||||
|
||||
size_t pxl8_net_recv(pxl8_net* net, u8* buf, size_t len) {
|
||||
usize pxl8_net_recv(pxl8_net* net, u8* buf, usize len) {
|
||||
if (!net || !net->connected) return 0;
|
||||
|
||||
struct sockaddr_in from;
|
||||
socklen_t from_len = sizeof(from);
|
||||
ssize_t received = recvfrom(net->sock, (char*)buf, len, 0,
|
||||
(struct sockaddr*)&from, &from_len);
|
||||
return (received > 0) ? (size_t)received : 0;
|
||||
return (received > 0) ? (usize)received : 0;
|
||||
}
|
||||
|
||||
pxl8_result pxl8_net_send(pxl8_net* net, const u8* data, size_t len) {
|
||||
pxl8_result pxl8_net_send(pxl8_net* net, const u8* data, usize len) {
|
||||
if (!net || !net->connected) return PXL8_ERROR_INVALID_ARGUMENT;
|
||||
|
||||
ssize_t sent = sendto(net->sock, (const char*)data, len, 0,
|
||||
|
|
@ -273,7 +274,7 @@ pxl8_result pxl8_net_send_command(pxl8_net* net, const pxl8_command_msg* cmd) {
|
|||
.sequence = 0
|
||||
};
|
||||
|
||||
size_t offset = pxl8_protocol_serialize_header(&hdr, buf, sizeof(buf));
|
||||
usize offset = pxl8_protocol_serialize_header(&hdr, buf, sizeof(buf));
|
||||
offset += pxl8_protocol_serialize_command(cmd, buf + offset, sizeof(buf) - offset);
|
||||
|
||||
return pxl8_net_send(net, buf, offset);
|
||||
|
|
@ -290,7 +291,7 @@ pxl8_result pxl8_net_send_input(pxl8_net* net, const pxl8_input_msg* input) {
|
|||
.sequence = 0
|
||||
};
|
||||
|
||||
size_t offset = pxl8_protocol_serialize_header(&hdr, buf, sizeof(buf));
|
||||
usize offset = pxl8_protocol_serialize_header(&hdr, buf, sizeof(buf));
|
||||
offset += pxl8_protocol_serialize_input(input, buf + offset, sizeof(buf) - offset);
|
||||
|
||||
return pxl8_net_send(net, buf, offset);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue