code: added chunk options

isolation_bkp/dynres
Vladyslav Hrytsenko 2021-01-17 09:57:08 +02:00
parent 82a3b9e7ff
commit 610cadb145
2 changed files with 42 additions and 4 deletions

View File

@ -3,10 +3,12 @@
#include "system.h"
#include "network.h"
#include "world/world.h"
#include "utils/options.h"
#define DEFAULT_WORLD_SEED 302097
#define DEFAULT_WORLD_DIMS 32
#define DEFAULT_CHUNK_SIZE 16
#define DEFAULT_CHUNK_AMOUNT 8
#define IF(call) do { \
if (call != 0) { \
@ -23,7 +25,8 @@ int main(int argc, char** argv) {
zpl_opts_add(&opts, "p", "preview-map", "draw world preview", ZPL_OPTS_FLAG);
zpl_opts_add(&opts, "s", "seed", "world seed", ZPL_OPTS_INT);
zpl_opts_add(&opts, "r", "random-seed", "generate random world seed", ZPL_OPTS_FLAG);
zpl_opts_add(&opts, "ws", "world-size", "world dimensions", ZPL_OPTS_INT);
zpl_opts_add(&opts, "cs", "chunk-size", "size of a single chunk", ZPL_OPTS_INT);
zpl_opts_add(&opts, "ca", "chunk-amount", "amount of chunks", ZPL_OPTS_INT);
uint32_t ok = zpl_opts_compile(&opts, argc, argv);
if (!ok) {
@ -32,7 +35,9 @@ int main(int argc, char** argv) {
return -1;
}
int32_t seed = zpl_opts_integer(&opts, "seed", DEFAULT_WORLD_SEED);
int32_t world_size = zpl_opts_integer(&opts, "world-size", DEFAULT_WORLD_DIMS);
int32_t chunk_size = zpl_opts_integer(&opts, "chunk-size", DEFAULT_CHUNK_SIZE);
int32_t chunk_amount = zpl_opts_integer(&opts, "chunk-amount", DEFAULT_CHUNK_AMOUNT);
int32_t world_size = chunk_size * chunk_amount;
if (zpl_opts_has_arg(&opts, "random-seed")) {
zpl_random rnd={0};
@ -46,6 +51,10 @@ int main(int argc, char** argv) {
return 0;
}
zpl_printf("[INFO] Generating world of size: %d x %d\n", world_size, world_size);
IF(world_init(seed, world_size, world_size));
zpl_printf("[INFO] Initializing network...\n");
IF(network_init());
IF(network_server_start("0.0.0.0", 27000));
@ -55,6 +64,7 @@ int main(int argc, char** argv) {
IF(network_server_stop());
IF(network_destroy());
IF(world_destroy());
return 0;
}

View File

@ -28,6 +28,34 @@ int32_t network_destroy(void) {
return 0;
}
int32_t server_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 network_server_start(const char *host, uint16_t port) {
zpl_unused(host);
@ -62,7 +90,7 @@ int32_t network_server_start(const char *host, uint16_t port) {
librg_config_chunkamount_set(server_world, 9, 9, 9);
librg_config_chunkoffset_set(server_world, LIBRG_OFFSET_MID, LIBRG_OFFSET_MID, LIBRG_OFFSET_MID);
// librg_event_set(server_world, LIBRG_WRITE_UPDATE, server_write_update);
librg_event_set(server_world, LIBRG_WRITE_UPDATE, server_write_update);
// librg_event_set(server_world, LIBRG_READ_UPDATE, server_read_update);
zpl_timer_start(&nettimer, NETWORK_UPDATE_DELAY);