code cleanup

isolation_bkp/dynres
Dominik Madarász 2021-05-05 16:00:10 +02:00
parent f5f35d0187
commit df6e844c98
3 changed files with 4 additions and 114 deletions

View File

@ -15,11 +15,8 @@
static ENetHost *host = NULL;
static ENetPeer *peer = NULL;
static librg_world *world = NULL;
static zpl_timer nettimer = {0};
int32_t network_init() {
zpl_timer_set(&nettimer, NETWORK_UPDATE_DELAY, -1, network_client_update);
return enet_initialize() != 0;
}
@ -29,6 +26,7 @@ int32_t network_destroy() {
}
#if 0
int32_t client_read_create(librg_world *w, librg_event *e) {
int64_t owner_id = librg_event_owner_get(w, e);
int64_t entity_id = librg_event_entity_get(w, e);
@ -47,13 +45,10 @@ int32_t client_read_update(librg_world *w, librg_event *e) {
// int64_t entity_id = librg_event_entity_get(w, e);
size_t actual_length = librg_event_size_get(w, e);
char *buffer = librg_event_buffer_get(w, e);
// if (actual_length != sizeof(vec3)) return 0;
// vec3 position = {0};
// memcpy(&position, buffer, actual_length);
return 0;
}
#endif
int32_t network_client_connect(const char *hostname, uint16_t port) {
ENetAddress address = {0}; address.port = port;
@ -70,18 +65,16 @@ int32_t network_client_connect(const char *hostname, uint16_t port) {
world = librg_world_create();
librg_world_userdata_set(world, peer);
#if 0
librg_event_set(world, LIBRG_READ_CREATE, client_read_create);
librg_event_set(world, LIBRG_READ_UPDATE, client_read_update);
librg_event_set(world, LIBRG_READ_REMOVE, client_read_remove);
zpl_timer_start(&nettimer, NETWORK_UPDATE_DELAY);
#endif
return 0;
}
int32_t network_client_disconnect() {
zpl_timer_stop(&nettimer);
enet_peer_disconnect_now(peer, 0);
enet_host_destroy(host);
@ -111,15 +104,6 @@ int32_t network_client_tick() {
if (!world_read(event.packet->data, event.packet->dataLength, NULL)) {
zpl_printf("[INFO] Server sent us an unsupported packet.\n");
}
/* handle a newly received event */
// librg_world_read(
// world,
// ID,
// (char *)event.packet->data,
// event.packet->dataLength,
// NULL
// );
/* Clean up the packet now that we're done using it. */
enet_packet_destroy(event.packet);
@ -129,30 +113,9 @@ int32_t network_client_tick() {
}
}
zpl_timer_update(&nettimer);
return 0;
}
void network_client_update(void *data) {
// /* send our data to the server */
// char buffer[1024] = {0};
// size_t buffer_length = 1024;
// /* serialize peer's the world view to a buffer */
// librg_world_write(
// world,
// ID,
// buffer,
// &buffer_length,
// NULL
// );
// /* create packet with actual length, and send it */
// ENetPacket *packet = enet_packet_create(buffer, buffer_length, ENET_PACKET_FLAG_RELIABLE);
// enet_peer_send(peer, 0, packet);
}
bool network_client_is_connected() {
return peer ? enet_peer_get_state(peer) == ENET_PEER_STATE_CONNECTED : false;
}

View File

@ -25,7 +25,6 @@
#define NETWORK_MAX_CLIENTS 32
static ENetHost *server = NULL;
static zpl_timer nettimer = {0};
WORLD_PKT_WRITER(mp_pkt_writer) {
if (pkt->is_reliable) {
@ -37,7 +36,6 @@ WORLD_PKT_WRITER(mp_pkt_writer) {
}
int32_t network_init(void) {
zpl_timer_set(&nettimer, NETWORK_UPDATE_DELAY, -1, network_server_update);
return enet_initialize() != 0;
}
@ -63,14 +61,12 @@ int32_t network_server_start(const char *host, uint16_t port) {
}
zpl_printf("[INFO] Started an ENet server...\n");
zpl_timer_start(&nettimer, NETWORK_UPDATE_DELAY);
return 0;
}
int32_t network_server_stop(void) {
zpl_printf("[INFO] Shutting down the ENet server...\n");
zpl_timer_stop(&nettimer);
enet_host_destroy(server);
server = NULL;
return 0;
@ -104,15 +100,6 @@ int32_t network_server_tick(void) {
network_client_destroy(e);
}
// /* handle a newly received event */
// librg_world_read(
// world_tracker(),
// event.peer->incomingPeerID,
// (char *)event.packet->data,
// event.packet->dataLength,
// NULL
// );
/* Clean up the packet now that we're done using it. */
enet_packet_destroy(event.packet);
} break;
@ -121,37 +108,9 @@ int32_t network_server_tick(void) {
}
}
zpl_timer_update(&nettimer);
return 0;
}
void network_server_update(void *data) {
// /* iterate peers and send them updates */
// ENetPeer *currentPeer;
// for (currentPeer = server->peers; currentPeer < &server->peers[server->peerCount]; ++currentPeer) {
// if (currentPeer->state != ENET_PEER_STATE_CONNECTED) {
// continue;
// }
// char buffer[1024] = {0};
// size_t buffer_length = 1024;
// /* serialize peer's the world view to a buffer */
// librg_world_write(
// world_tracker(),
// currentPeer->incomingPeerID,
// buffer,
// &buffer_length,
// NULL
// );
// /* create packet with actual length, and send it */
// ENetPacket *packet = enet_packet_create(buffer, buffer_length, ENET_PACKET_FLAG_RELIABLE);
// enet_peer_send(currentPeer, 0, packet);
// }
}
uint64_t network_client_create(ENetPeer *peer) {
ECS_IMPORT(world_ecs(), Net);
ecs_entity_t e = (ecs_entity_t)player_spawn(zpl_bprintf("client_%d", peer->incomingPeerID));

View File

@ -29,34 +29,6 @@ static world_data world = {0};
int32_t world_gen();
int32_t world_write_update(librg_world *w, librg_event *e) {
int64_t owner_id = librg_event_owner_get(w, e);
int64_t entity_id = librg_event_entity_get(w, e);
return 0;
// /* prevent sending updates to users who own that entity */
// /* since they will be responsible on telling where that entity is supposed to be */
// if (librg_entity_owner_get(w, entity_id) == owner_id) {
// return LIBRG_WRITE_REJECT;
// }
// /* read our current position */
// ENetPeer *peer = (ENetPeer *)librg_entity_userdata_get(w, entity_id);
// char *buffer = librg_event_buffer_get(w, e);
// size_t max_length = librg_event_size_get(w, e);
// /* check if we have enough space to write and valid position */
// if (sizeof(vec3) > max_length || !peer->data) {
// return LIBRG_WRITE_REJECT;
// }
// /* write data and return how much we've written */
// memcpy(buffer, peer->data, sizeof(vec3));
// return sizeof(vec3);
}
int32_t world_init_minimal(uint16_t block_size, uint16_t chunk_size, uint16_t world_size, world_pkt_reader_proc *reader_proc, world_pkt_writer_proc *writer_proc) {
world.chunk_size = chunk_size;
world.world_size = world_size;
@ -104,7 +76,6 @@ int32_t world_init(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint1
world.ecs = ecs_init();
ecs_set_entity_range(world.ecs, 0, UINT32_MAX);
//ecs_set_threads(world.ecs, 4);
ECS_IMPORT(world.ecs, General);
@ -119,9 +90,6 @@ int32_t world_init(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint1
librg_entity_chunk_set(world.tracker, e, i);
}
// librg_event_set(world.tracker, LIBRG_WRITE_UPDATE, world_write_update);
// librg_event_set(world.tracker, LIBRG_READ_UPDATE, server_read_update);
zpl_printf("[INFO] Created a new server world\n");
return world_gen();