addt'l world dim changes

isolation_bkp/dynres
Dominik Madarász 2021-05-08 09:07:24 +02:00
parent 57b1193ef1
commit 9612846d79
4 changed files with 20 additions and 24 deletions

View File

@ -10,8 +10,7 @@ typedef struct {
librg_world *tracker; librg_world *tracker;
uint32_t size; uint32_t size;
uint32_t width; uint32_t dim;
uint32_t height;
uint16_t block_size; uint16_t block_size;
uint16_t chunk_size; uint16_t chunk_size;
uint16_t chunk_amount; uint16_t chunk_amount;

View File

@ -45,13 +45,12 @@ world_view world_view_create(uint16_t view_id) {
void world_view_init(world_view *view, uint64_t ent_id, uint16_t block_size, uint16_t chunk_size, uint16_t chunk_amount) { void world_view_init(world_view *view, uint64_t ent_id, uint16_t block_size, uint16_t chunk_size, uint16_t chunk_amount) {
view->owner_id = ent_id; view->owner_id = ent_id;
view->block_size = block_size;
view->chunk_size = chunk_size; view->chunk_size = chunk_size;
view->chunk_amount = chunk_amount; view->chunk_amount = chunk_amount;
view->width = block_size * chunk_size * chunk_amount; view->dim = block_size * chunk_size * chunk_amount;
view->height = block_size * chunk_size * chunk_amount; view->size = view->dim * view->dim;
view->block_size = block_size;
view->size = view->width * view->height;
librg_config_chunksize_set(view->tracker, block_size * chunk_size, block_size * chunk_size, 1); librg_config_chunksize_set(view->tracker, block_size * chunk_size, block_size * chunk_size, 1);
librg_config_chunkamount_set(view->tracker, chunk_amount, chunk_amount, 1); librg_config_chunkamount_set(view->tracker, chunk_amount, chunk_amount, 1);

View File

@ -11,11 +11,10 @@ typedef struct {
uint8_t *data; uint8_t *data;
uint32_t seed; uint32_t seed;
uint32_t size; uint32_t size;
uint32_t width;
uint32_t height;
uint16_t block_size; uint16_t block_size;
uint16_t chunk_size; uint16_t chunk_size;
uint16_t chunk_amount; uint16_t chunk_amount;
uint16_t dim;
uint64_t tracker_update; uint64_t tracker_update;
ecs_world_t *ecs; ecs_world_t *ecs;
librg_world *tracker; librg_world *tracker;
@ -86,10 +85,9 @@ int32_t world_init(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint1
world.chunk_size = chunk_size; world.chunk_size = chunk_size;
world.chunk_amount = chunk_amount; world.chunk_amount = chunk_amount;
world.width = chunk_size * chunk_amount;
world.height = chunk_size * chunk_amount;
world.block_size = block_size; world.block_size = block_size;
world.size = world.width * world.height; world.dim = (world.chunk_size * world.chunk_amount);;
world.size = world.dim * world.dim;
if (world.tracker == NULL) { if (world.tracker == NULL) {
world.tracker = librg_world_create(); world.tracker = librg_world_create();
@ -201,7 +199,7 @@ uint32_t world_buf(uint8_t const **ptr, uint32_t *width) {
ZPL_ASSERT_NOT_NULL(world.data); ZPL_ASSERT_NOT_NULL(world.data);
ZPL_ASSERT_NOT_NULL(ptr); ZPL_ASSERT_NOT_NULL(ptr);
*ptr = world.data; *ptr = world.data;
if (width) *width = world.width; if (width) *width = world.dim;
return world.size; return world.size;
} }

View File

@ -16,9 +16,9 @@ typedef WORLD_BLOCK_OBSERVER(world_block_observer_proc);
static void world_fill_rect(uint32_t id, uint32_t x, uint32_t y, uint32_t w, uint32_t h, world_block_observer_proc *proc) { static void world_fill_rect(uint32_t id, uint32_t x, uint32_t y, uint32_t w, uint32_t h, world_block_observer_proc *proc) {
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++) {
if (cx < 0 || cx >= world.width) continue; if (cx < 0 || cx >= world.dim) continue;
if (cy < 0 || cy >= world.height) continue; if (cy < 0 || cy >= world.dim) continue;
uint32_t i = (cy*world.width) + cx; uint32_t i = (cy*world.dim) + cx;
if (proc) { if (proc) {
uint32_t new_id = (*proc)(id, i); uint32_t new_id = (*proc)(id, i);
@ -36,9 +36,9 @@ static void world_fill_rect(uint32_t id, uint32_t x, uint32_t y, uint32_t w, uin
static void world_fill_circle(uint32_t id, uint32_t x, uint32_t y, uint32_t w, uint32_t h, world_block_observer_proc *proc) { static void world_fill_circle(uint32_t id, uint32_t x, uint32_t y, uint32_t w, uint32_t h, world_block_observer_proc *proc) {
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++) {
if (cx < 0 || cx >= world.width) continue; if (cx < 0 || cx >= world.dim) continue;
if (cy < 0 || cy >= world.height) continue; if (cy < 0 || cy >= world.dim) continue;
uint32_t i = (cy*world.width) + cx; uint32_t i = (cy*world.dim) + cx;
if (proc) { if (proc) {
uint32_t new_id = (*proc)(id, i); uint32_t new_id = (*proc)(id, i);
@ -78,8 +78,8 @@ static WORLD_BLOCK_OBSERVER(shaper) {
} }
static uint8_t world_perlin_cond(uint32_t block_idx, double chance) { static uint8_t world_perlin_cond(uint32_t block_idx, double chance) {
uint32_t x = block_idx % world.width; uint32_t x = block_idx % world.dim;
uint32_t y = block_idx / world.width; uint32_t y = block_idx / world.dim;
return perlin_fbm(world.seed, x, y, WORLD_PERLIN_FREQ, WORLD_PERLIN_OCTAVES) < chance; return perlin_fbm(world.seed, x, y, WORLD_PERLIN_FREQ, WORLD_PERLIN_OCTAVES) < chance;
} }
@ -112,21 +112,21 @@ int32_t world_gen() {
srand(world.seed); srand(world.seed);
// walls // walls
world_fill_rect(wall_id, 0, 0, world.width, world.height, NULL); world_fill_rect(wall_id, 0, 0, world.dim, world.dim, NULL);
// ground // ground
world_fill_rect(grnd_id, 1, 1, world.width-2, world.height-2, NULL); world_fill_rect(grnd_id, 1, 1, world.dim-2, world.dim-2, NULL);
// water // water
for (int i=0; i<RAND_RANGE(0, 12); i++) { for (int i=0; i<RAND_RANGE(0, 12); i++) {
world_fill_rect_anchor(watr_id, RAND_RANGE(0, world.width), RAND_RANGE(0, world.height), 4+RAND_RANGE(0,3), 4+RAND_RANGE(0,3), 0.5f, 0.5f, shaper_noise33); world_fill_rect_anchor(watr_id, RAND_RANGE(0, world.dim), RAND_RANGE(0, world.dim), 4+RAND_RANGE(0,3), 4+RAND_RANGE(0,3), 0.5f, 0.5f, shaper_noise33);
} }
const uint32_t HILLS_SIZE = 21; const uint32_t HILLS_SIZE = 21;
// hills // hills
for (int i=0; i<RAND_RANGE(8, 224); i++) { for (int i=0; i<RAND_RANGE(8, 224); i++) {
world_fill_rect_anchor(wall_id, RAND_RANGE(0, world.width), RAND_RANGE(0, world.height), RAND_RANGE(0,HILLS_SIZE), RAND_RANGE(0,HILLS_SIZE), 0.5f, 0.5f, shaper_noise33); world_fill_rect_anchor(wall_id, RAND_RANGE(0, world.dim), RAND_RANGE(0, world.dim), RAND_RANGE(0,HILLS_SIZE), RAND_RANGE(0,HILLS_SIZE), 0.5f, 0.5f, shaper_noise33);
} }
return WORLD_ERROR_NONE; return WORLD_ERROR_NONE;