eco2d/code/apps/server/source/main.c

74 lines
2.2 KiB
C
Raw Normal View History

2021-01-11 13:47:14 +00:00
#define ZPL_IMPL
#include "zpl.h"
#include "system.h"
#include "network.h"
2021-01-17 07:57:08 +00:00
#include "world/world.h"
#include "utils/options.h"
2021-01-11 13:47:14 +00:00
#define DEFAULT_WORLD_SEED 302097
2021-01-17 07:57:08 +00:00
#define DEFAULT_CHUNK_SIZE 16
#define DEFAULT_CHUNK_AMOUNT 8
2021-01-11 13:47:14 +00:00
#define IF(call) do { \
if (call != 0) { \
zpl_printf("[ERROR] A call to a function %s failed\n", #call); \
return 1; \
} \
} while (0)
2021-01-11 13:47:14 +00:00
int main(int argc, char** argv) {
zpl_opts opts={0};
zpl_opts_init(&opts, zpl_heap(), argv[0]);
zpl_opts_add(&opts, "?", "help", "the HELP section", ZPL_OPTS_FLAG);
zpl_opts_add(&opts, "p", "preview-map", "draw world preview", ZPL_OPTS_FLAG);
zpl_opts_add(&opts, "s", "seed", "world seed", ZPL_OPTS_INT);
2021-01-11 18:10:56 +00:00
zpl_opts_add(&opts, "r", "random-seed", "generate random world seed", ZPL_OPTS_FLAG);
2021-01-17 07:57:08 +00:00
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);
2021-01-11 13:47:14 +00:00
uint32_t ok = zpl_opts_compile(&opts, argc, argv);
if (!ok) {
zpl_opts_print_errors(&opts);
zpl_opts_print_help(&opts);
return -1;
}
2021-01-17 11:05:29 +00:00
2021-01-11 13:47:14 +00:00
int32_t seed = zpl_opts_integer(&opts, "seed", DEFAULT_WORLD_SEED);
2021-01-17 07:57:08 +00:00
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;
2021-01-11 13:47:14 +00:00
2021-01-11 18:10:56 +00:00
if (zpl_opts_has_arg(&opts, "random-seed")) {
zpl_random rnd={0};
zpl_random_init(&rnd);
seed = zpl_random_gen_u32(&rnd);
2021-01-11 19:32:16 +00:00
zpl_printf("Seed: %u\n", seed);
2021-01-11 18:10:56 +00:00
}
2021-01-11 13:47:14 +00:00
if (zpl_opts_has_arg(&opts, "preview-map")) {
2021-01-17 11:05:29 +00:00
generate_minimap(seed, chunk_size, chunk_amount);
2021-01-11 13:47:14 +00:00
return 0;
}
2021-01-17 07:57:08 +00:00
zpl_printf("[INFO] Generating world of size: %d x %d\n", world_size, world_size);
2021-01-17 11:05:29 +00:00
IF(world_init(seed, chunk_size, chunk_size, chunk_amount, chunk_amount));
2021-01-17 07:57:08 +00:00
zpl_printf("[INFO] Initializing network...\n");
IF(network_init());
IF(network_server_start("0.0.0.0", 27000));
while (true) {
network_server_tick();
}
IF(network_server_stop());
IF(network_destroy());
2021-01-17 07:57:08 +00:00
IF(world_destroy());
2021-01-10 16:42:01 +00:00
return 0;
}
2021-01-17 11:05:29 +00:00
#include "packets/pkt_01_welcome.c"