allow client to generate_minimap

isolation_bkp/dynres
Dominik Madarász 2021-05-04 22:32:12 +02:00
parent 5d824bbd27
commit dbc7617f61
9 changed files with 42 additions and 14 deletions

View File

@ -4,6 +4,7 @@ add_library(client-common STATIC
source/network.c
source/game.c
source/main.c
source/utils/options.c
header/network.h
)

View File

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

View File

@ -2,6 +2,7 @@
#include "zpl.h"
#include "system.h"
#include "game.h"
#include "utils/options.h"
#define DEFAULT_WORLD_SEED 302097
#define DEFAULT_BLOCK_SIZE 64 /* amount of units within a block (single axis) */
@ -15,6 +16,7 @@ int main(int argc, char** argv)
zpl_opts_add(&opts, "?", "help", "the HELP section", ZPL_OPTS_FLAG);
zpl_opts_add(&opts, "s", "single-player", "play single-player game.", 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, "r", "random-seed", "generate random world seed", ZPL_OPTS_FLAG);
zpl_opts_add(&opts, "bs", "block-size", "amount of units within a block (single axis)", ZPL_OPTS_INT);
@ -42,6 +44,11 @@ int main(int argc, char** argv)
zpl_printf("Seed: %u\n", seed);
}
if (zpl_opts_has_arg(&opts, "preview-map")) {
generate_minimap(seed, block_size, chunk_size, world_size);
return 0;
}
sighandler_register();
game_init(is_networked_play, seed, block_size, chunk_size, world_size);

View File

@ -0,0 +1,23 @@
#include <stdio.h>
#include "world/world.h"
#include "world/blocks.h"
#include "utils/options.h"
void generate_minimap(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t world_size) {
world_init(seed, block_size, chunk_size, world_size, NULL, NULL);
uint8_t const *world;
uint32_t world_length = chunk_size * world_size;
uint32_t len = world_buf(&world, NULL);
for (int i=0; i<len; i++) {
if (i > 0 && i % world_length == 0) {
putc('\n', stdout);
}
putc(blocks_get_symbol(world[i]), stdout);
}
putc('\n', stdout);
world_destroy();
}

View File

@ -17,13 +17,6 @@
#define DEFAULT_CHUNK_SIZE 3 /* amount of blocks within a chunk (single axis) */
#define DEFAULT_WORLD_SIZE 8 /* amount of chunks within a world (single axis) */
#define IF(call) do { \
if (call != 0) { \
zpl_printf("[ERROR] A call to a function %s failed\n", #call); \
return 1; \
} \
} while (0)
zpl_global zpl_b32 is_running = true;
int main(int argc, char** argv) {

View File

@ -5,7 +5,7 @@
#include "utils/options.h"
void generate_minimap(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t world_size) {
world_init(seed, block_size, chunk_size, world_size, NULL, NULL);
world_init(seed, 3, chunk_size, world_size, NULL, NULL);
uint8_t const *world;
uint32_t world_length = chunk_size * world_size;

View File

@ -2,6 +2,8 @@
#include "world.h"
#include "game.h"
#define PKT_01_WELCOME_ARGC 3
pkt_desc pkt_01_welcome_desc[] = {
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, block_size) },
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, chunk_size) },
@ -11,14 +13,14 @@ pkt_desc pkt_01_welcome_desc[] = {
size_t pkt_01_welcome_encode(pkt_01_welcome *table) {
cw_pack_context pc = {0};
pkt_pack_msg(&pc, 3);
pkt_pack_msg(&pc, PKT_01_WELCOME_ARGC);
pkt_pack_struct(&pc, pkt_01_welcome_desc, PKT_STRUCT_PTR(table));
return pkt_pack_msg_size(&pc);
}
int32_t pkt_01_welcome_handler(pkt_header *header) {
pkt_01_welcome table;
PKT_IF(pkt_msg_decode(header, pkt_01_welcome_desc, 3, PKT_STRUCT_PTR(&table)));
PKT_IF(pkt_msg_decode(header, pkt_01_welcome_desc, PKT_01_WELCOME_ARGC, PKT_STRUCT_PTR(&table)));
zpl_printf("we received: block_size: %d, chunk_size: %d and world_size: %d\n", table.block_size, table.chunk_size, table.world_size);

View File

@ -1,8 +1,6 @@
#pragma once
#include "packet_utils.h"
#define PKT_01_NUMBERS_SIZ 32
typedef struct {
uint16_t block_size;
uint16_t chunk_size;

View File

@ -59,8 +59,8 @@ int32_t world_init_minimal(uint16_t block_size, uint16_t chunk_size, uint16_t wo
world.width = chunk_size * world_size;
world.height = chunk_size * world_size;
world.size = world.width * world.height;
world.block_size = block_size;
world.size = world.width * world.height;
if (world.tracker != NULL) {
librg_world_destroy(world.tracker);
@ -88,7 +88,7 @@ int32_t world_init(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint1
}
world.seed = seed;
world_init_minimal(chunk_size, block_size, world_size, reader_proc, writer_proc);
world_init_minimal(block_size, chunk_size, world_size, reader_proc, writer_proc);
world.data = zpl_malloc(sizeof(uint8_t)*world.size);
if (!world.data) {