2021-01-11 20:08:16 +00:00
|
|
|
#define ZPL_IMPL
|
|
|
|
#include "zpl.h"
|
2021-05-04 17:39:50 +00:00
|
|
|
#include "system.h"
|
2021-01-10 16:42:01 +00:00
|
|
|
#include "game.h"
|
2021-05-10 06:28:56 +00:00
|
|
|
#include "entity.h"
|
2021-05-04 20:32:12 +00:00
|
|
|
#include "utils/options.h"
|
2021-05-14 05:59:33 +00:00
|
|
|
#include "editors/texed.h"
|
2021-05-10 06:28:56 +00:00
|
|
|
#include "signal_handling.h"
|
2021-05-13 12:17:44 +00:00
|
|
|
#include "profiler.h"
|
2021-05-04 17:39:50 +00:00
|
|
|
|
2021-05-08 20:32:31 +00:00
|
|
|
#include "flecs/flecs.h"
|
|
|
|
#include "flecs/flecs_dash.h"
|
|
|
|
#include "flecs/flecs_systems_civetweb.h"
|
|
|
|
#include "flecs/flecs_os_api_stdcpp.h"
|
|
|
|
|
|
|
|
#include "modules/general.h"
|
|
|
|
#include "modules/physics.h"
|
|
|
|
#include "modules/controllers.h"
|
|
|
|
|
2021-05-04 17:39:50 +00:00
|
|
|
#define DEFAULT_WORLD_SEED 302097
|
2021-05-06 21:45:55 +00:00
|
|
|
#define DEFAULT_CHUNK_SIZE 16 /* amount of blocks within a chunk (single axis) */
|
2021-05-09 22:40:25 +00:00
|
|
|
#define DEFAULT_WORLD_SIZE 32 /* amount of chunks within a world (single axis) */
|
2021-05-04 17:39:50 +00:00
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
2021-01-10 16:42:01 +00:00
|
|
|
{
|
2021-05-04 17:39:50 +00:00
|
|
|
zpl_opts opts={0};
|
|
|
|
zpl_opts_init(&opts, zpl_heap(), argv[0]);
|
|
|
|
|
|
|
|
zpl_opts_add(&opts, "?", "help", "the HELP section", ZPL_OPTS_FLAG);
|
2021-05-14 05:59:33 +00:00
|
|
|
zpl_opts_add(&opts, "td", "texed", "run text editor", ZPL_OPTS_FLAG);
|
2021-05-07 10:51:32 +00:00
|
|
|
zpl_opts_add(&opts, "v", "viewer-only", "run viewer-only client", ZPL_OPTS_FLAG);
|
2021-05-06 15:30:38 +00:00
|
|
|
zpl_opts_add(&opts, "c", "viewer-count", "number of viewers (detachable clients)", ZPL_OPTS_INT);
|
2021-05-04 20:32:12 +00:00
|
|
|
zpl_opts_add(&opts, "p", "preview-map", "draw world preview", ZPL_OPTS_FLAG);
|
2021-05-10 07:10:26 +00:00
|
|
|
zpl_opts_add(&opts, "ed", "enable-dash", "enables flecs dash", ZPL_OPTS_FLAG);
|
2021-05-04 17:39:50 +00:00
|
|
|
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, "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-05-09 10:27:10 +00:00
|
|
|
zpl_opts_add(&opts, "n", "npc-count", "amount of demo npcs to spawn", ZPL_OPTS_INT);
|
2021-05-04 17:39:50 +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-05-07 10:51:32 +00:00
|
|
|
int8_t is_viewer_only = zpl_opts_has_arg(&opts, "viewer-only");
|
2021-05-10 07:10:26 +00:00
|
|
|
int8_t is_dash_enabled = zpl_opts_has_arg(&opts, "enable-dash");
|
2021-05-04 17:39:50 +00:00
|
|
|
int32_t seed = zpl_opts_integer(&opts, "seed", DEFAULT_WORLD_SEED);
|
2021-05-06 15:30:38 +00:00
|
|
|
uint16_t num_viewers = zpl_opts_integer(&opts, "viewer-count", 1);
|
2021-05-04 17:39:50 +00:00
|
|
|
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-05-09 22:40:25 +00:00
|
|
|
uint32_t npc_count = zpl_opts_integer(&opts, "npc-count", 1000);
|
2021-05-04 17:39:50 +00:00
|
|
|
|
2021-05-14 05:59:33 +00:00
|
|
|
if (zpl_opts_has_arg(&opts, "texed")) {
|
|
|
|
texed_run();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-05-04 17:39:50 +00:00
|
|
|
if (zpl_opts_has_arg(&opts, "random-seed")) {
|
|
|
|
zpl_random rnd={0};
|
|
|
|
zpl_random_init(&rnd);
|
|
|
|
seed = zpl_random_gen_u32(&rnd);
|
|
|
|
zpl_printf("Seed: %u\n", seed);
|
|
|
|
}
|
|
|
|
|
2021-05-04 20:32:12 +00:00
|
|
|
if (zpl_opts_has_arg(&opts, "preview-map")) {
|
2021-05-12 16:28:39 +00:00
|
|
|
generate_minimap(seed, WORLD_BLOCK_SIZE, chunk_size, world_size);
|
2021-05-04 20:32:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-11 21:12:26 +00:00
|
|
|
sighandler_register();
|
2021-05-12 16:28:39 +00:00
|
|
|
game_init(is_viewer_only, num_viewers, seed, chunk_size, world_size, is_dash_enabled);
|
|
|
|
|
2021-05-08 20:32:31 +00:00
|
|
|
// TODO(zaklaus): VERY TEMPORARY -- SPAWN SOME NPCS THAT RANDOMLY MOVE
|
|
|
|
{
|
|
|
|
ECS_IMPORT(world_ecs(), General);
|
|
|
|
ECS_IMPORT(world_ecs(), Controllers);
|
|
|
|
ECS_IMPORT(world_ecs(), Physics);
|
2021-05-12 14:42:22 +00:00
|
|
|
for (uint32_t i = 0; i < npc_count; i++) {
|
2021-05-08 20:32:31 +00:00
|
|
|
uint64_t e = entity_spawn(NULL);
|
|
|
|
ecs_add(world_ecs(), e, EcsDemoNPC);
|
|
|
|
Position *pos = ecs_get_mut(world_ecs(), e, Position, NULL);
|
|
|
|
pos->x=rand() % world_dim();
|
|
|
|
pos->y=rand() % world_dim();
|
|
|
|
|
|
|
|
Velocity *v = ecs_get_mut(world_ecs(), e, Velocity, NULL);
|
|
|
|
v->x = (rand()%3-1) * 100;
|
|
|
|
v->y = (rand()%3-1) * 100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-04 19:45:51 +00:00
|
|
|
while (game_is_running()) {
|
2021-05-13 12:17:44 +00:00
|
|
|
profile (PROF_MAIN_LOOP) {
|
|
|
|
game_input();
|
|
|
|
game_update();
|
|
|
|
game_render();
|
|
|
|
}
|
|
|
|
|
|
|
|
profiler_collate();
|
2021-01-10 16:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
game_shutdown();
|
2021-01-11 21:12:26 +00:00
|
|
|
sighandler_unregister();
|
2021-05-04 17:39:50 +00:00
|
|
|
|
|
|
|
zpl_opts_free(&opts);
|
2021-01-10 16:42:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|