2021-01-11 13:47:14 +00:00
|
|
|
#define ZPL_IMPL
|
|
|
|
#include "zpl.h"
|
|
|
|
|
|
|
|
#include "system.h"
|
2021-01-17 07:57:08 +00:00
|
|
|
#include "world/world.h"
|
2021-05-04 19:22:55 +00:00
|
|
|
#include "network.h"
|
2021-01-17 07:03:06 +00:00
|
|
|
#include "utils/options.h"
|
2021-01-17 23:09:29 +00:00
|
|
|
#include "signal_handling.h"
|
2021-01-11 13:47:14 +00:00
|
|
|
|
2021-01-18 16:40:47 +00:00
|
|
|
#include "flecs/flecs.h"
|
|
|
|
#include "flecs/flecs_dash.h"
|
|
|
|
#include "flecs/flecs_systems_civetweb.h"
|
2021-05-03 19:53:28 +00:00
|
|
|
#include "flecs/flecs_os_api_stdcpp.h"
|
2021-01-18 16:40:47 +00:00
|
|
|
|
2021-01-11 13:47:14 +00:00
|
|
|
#define DEFAULT_WORLD_SEED 302097
|
2021-01-17 14:23:23 +00:00
|
|
|
#define DEFAULT_BLOCK_SIZE 64 /* amount of units within a block (single axis) */
|
2021-01-17 15:06:56 +00:00
|
|
|
#define DEFAULT_CHUNK_SIZE 3 /* amount of blocks within a chunk (single axis) */
|
2021-01-17 14:23:23 +00:00
|
|
|
#define DEFAULT_WORLD_SIZE 8 /* amount of chunks within a world (single axis) */
|
2021-01-11 13:47:14 +00:00
|
|
|
|
2021-01-17 23:09:29 +00:00
|
|
|
zpl_global zpl_b32 is_running = true;
|
|
|
|
|
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 14:23:23 +00:00
|
|
|
zpl_opts_add(&opts, "bs", "block-size", "amount of units within a block (single axis)", ZPL_OPTS_INT);
|
|
|
|
zpl_opts_add(&opts, "cs", "chunk-size", "amount of blocks within a chunk (single axis)", ZPL_OPTS_INT);
|
|
|
|
zpl_opts_add(&opts, "ws", "world-size", "amount of chunks within a world (single axis)", 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 14:23:23 +00:00
|
|
|
uint16_t block_size = zpl_opts_integer(&opts, "block-size", DEFAULT_BLOCK_SIZE);
|
|
|
|
uint16_t chunk_size = zpl_opts_integer(&opts, "chunk-size", DEFAULT_CHUNK_SIZE);
|
|
|
|
uint16_t world_size = zpl_opts_integer(&opts, "world-size", DEFAULT_WORLD_SIZE);
|
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 14:23:23 +00:00
|
|
|
generate_minimap(seed, block_size, chunk_size, world_size);
|
2021-01-11 13:47:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2021-05-04 19:45:51 +00:00
|
|
|
|
|
|
|
game_init(1, seed, block_size, chunk_size, world_size);
|
2021-01-17 07:03:06 +00:00
|
|
|
|
2021-01-17 23:09:29 +00:00
|
|
|
while (is_running) {
|
2021-05-04 19:45:51 +00:00
|
|
|
game_update();
|
2021-01-17 07:03:06 +00:00
|
|
|
}
|
2021-05-04 19:45:51 +00:00
|
|
|
|
|
|
|
game_shutdown();
|
2021-01-17 07:03:06 +00:00
|
|
|
|
2021-01-10 16:42:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2021-01-17 11:05:29 +00:00
|
|
|
|
2021-01-17 23:09:29 +00:00
|
|
|
void platform_shutdown(void) {
|
|
|
|
is_running = false;
|
|
|
|
}
|