world_fill_dot

isolation_bkp/dynres
Dominik Madarász 2021-01-11 17:49:00 +01:00
parent 9b6b80e5fe
commit f6dd28e5ee
3 changed files with 16 additions and 7 deletions

View File

@ -4,7 +4,6 @@ add_executable(eco2d-server
source/perlin.c source/perlin.c
source/options.c source/options.c
source/world.c source/world.c
source/world_gen.c
source/blocks.c source/blocks.c
header/network.h header/network.h

View File

@ -34,3 +34,5 @@ uint32_t world_buf(uint8_t const **ptr, uint32_t *width) {
if (width) *width = world_width; if (width) *width = world_width;
return world_size; return world_size;
} }
#include "world_gen.c"

View File

@ -2,16 +2,24 @@
#include "blocks.h" #include "blocks.h"
#include "zpl.h" #include "zpl.h"
static void world_fill(uint8_t *world, uint32_t width, uint32_t id, uint32_t x, uint32_t y, uint32_t w, uint32_t h) { #include <math.h>
static void world_fill_rect(uint32_t id, uint32_t x, uint32_t y, uint32_t w, uint32_t h) {
for (uint32_t cy=y; cy<y+h; cy++) { for (uint32_t cy=y; cy<y+h; cy++) {
for (uint32_t cx=x; cx<x+w; cx++) { for (uint32_t cx=x; cx<x+w; cx++) {
uint32_t i = (cy*width) + cx; uint32_t i = (cy*world_width) + cx;
world[i] = id; world[i] = id;
} }
} }
} }
int32_t world_gen(uint8_t *world, uint32_t size, uint32_t width, uint32_t height, int32_t seed) { static void world_fill_dot(uint32_t id, uint32_t x, uint32_t y, uint32_t w, uint32_t h) {
uint32_t w2 = (uint32_t)floor(w/2.0);
uint32_t h2 = (uint32_t)floor(h/2.0);
world_fill_rect(id, x-w2, y-h2, w, h);
}
int32_t world_gen(int32_t seed) {
// TODO: perform world gen // TODO: perform world gen
// atm, we will fill the world with ground and surround it by walls // atm, we will fill the world with ground and surround it by walls
uint32_t wall_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_WALL); uint32_t wall_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_WALL);
@ -19,13 +27,13 @@ int32_t world_gen(uint8_t *world, uint32_t size, uint32_t width, uint32_t height
uint32_t watr_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_WATER); uint32_t watr_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_WATER);
// walls // walls
world_fill(world, width, wall_id, 0, 0, width, height); world_fill_rect(wall_id, 0, 0, world_width, world_height);
// ground // ground
world_fill(world, width, grnd_id, 1, 1, width-2, height-2); world_fill_rect(grnd_id, 1, 1, world_width-2, world_height-2);
// water // water
world_fill(world, width, watr_id, 5, 5, 3, 3); world_fill_dot(watr_id, 8, 8, 4, 4);
return WORLD_ERROR_NONE; return WORLD_ERROR_NONE;
} }