Add world size option

isolation_bkp/dynres
Dominik Madarász 2021-01-11 21:25:09 +01:00
parent a9885f9763
commit c76eab22b2
3 changed files with 9 additions and 8 deletions

View File

@ -1,4 +1,4 @@
#pragma once #pragma once
#include "system.h" #include "system.h"
void generate_minimap(int32_t seed); void generate_minimap(int32_t seed, int32_t world_size);

View File

@ -9,6 +9,7 @@
#include "options.h" #include "options.h"
#define DEFAULT_WORLD_SEED 302097 #define DEFAULT_WORLD_SEED 302097
#define DEFAULT_WORLD_DIMS 32
int main(int argc, char** argv) { int main(int argc, char** argv) {
zpl_opts opts={0}; zpl_opts opts={0};
@ -18,6 +19,7 @@ int main(int argc, char** argv) {
zpl_opts_add(&opts, "p", "preview-map", "draw world preview", 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); 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, "r", "random-seed", "generate random world seed", ZPL_OPTS_FLAG);
zpl_opts_add(&opts, "ws", "world-size", "world dimensions", ZPL_OPTS_INT);
uint32_t ok = zpl_opts_compile(&opts, argc, argv); uint32_t ok = zpl_opts_compile(&opts, argc, argv);
if (!ok) { if (!ok) {
@ -26,6 +28,7 @@ int main(int argc, char** argv) {
return -1; return -1;
} }
int32_t seed = zpl_opts_integer(&opts, "seed", DEFAULT_WORLD_SEED); int32_t seed = zpl_opts_integer(&opts, "seed", DEFAULT_WORLD_SEED);
int32_t world_size = zpl_opts_integer(&opts, "world-size", DEFAULT_WORLD_DIMS);
if (zpl_opts_has_arg(&opts, "random-seed")) { if (zpl_opts_has_arg(&opts, "random-seed")) {
zpl_random rnd={0}; zpl_random rnd={0};
@ -35,7 +38,7 @@ int main(int argc, char** argv) {
} }
if (zpl_opts_has_arg(&opts, "preview-map")) { if (zpl_opts_has_arg(&opts, "preview-map")) {
generate_minimap(seed); generate_minimap(seed, world_size);
return 0; return 0;
} }

View File

@ -3,14 +3,12 @@
#include "blocks.h" #include "blocks.h"
#include "zpl.h" #include "zpl.h"
#define TEST_MAP_DIM 32 void generate_minimap(int32_t seed, int32_t world_size) {
world_init(seed, world_size, world_size);
void generate_minimap(int32_t seed) { uint8_t const *world;
world_init(seed, TEST_MAP_DIM, TEST_MAP_DIM);
uint8_t *world;
uint32_t len = world_buf(&world, NULL); uint32_t len = world_buf(&world, NULL);
for (int i=0; i<len; i++) { for (int i=0; i<len; i++) {
if (i > 0 && i % TEST_MAP_DIM == 0) { if (i > 0 && i % world_size == 0) {
zpl_printf("\n"); zpl_printf("\n");
} }
zpl_printf("%c", blocks_get_symbol(world[i])); zpl_printf("%c", blocks_get_symbol(world[i]));