world: fix chunk partitioning

isolation_bkp/dynres
Dominik Madarász 2021-07-19 10:28:23 +02:00
parent 20ad88adf4
commit ee0db9c8c1
5 changed files with 21 additions and 13 deletions

BIN
art/gen/water.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 KiB

View File

@ -31,6 +31,9 @@ Image texgen_build_block(uint32_t biome, uint32_t kind) {
case BLOCK_KIND_HILL:{ case BLOCK_KIND_HILL:{
return LoadImageEco("rock"); return LoadImageEco("rock");
}break; }break;
case BLOCK_KIND_WATER:{
return LoadImageEco("water");
}break;
} }
} }
} }

View File

@ -27,8 +27,13 @@ uint64_t player_spawn(char *name) {
ecs_set(world_ecs(), e, Input, {0}); ecs_set(world_ecs(), e, Input, {0});
ecs_add(world_ecs(), e, Player); ecs_add(world_ecs(), e, Player);
Position *pos = ecs_get_mut(world_ecs(), e, Position, NULL); Position *pos = ecs_get_mut(world_ecs(), e, Position, NULL);
#if 1
pos->x=rand() % world_dim(); pos->x=rand() % world_dim();
pos->y=rand() % world_dim(); pos->y=rand() % world_dim();
#else
pos->x=10;
pos->y=10;
#endif
librg_entity_owner_set(world_tracker(), e, (int64_t)e); librg_entity_owner_set(world_tracker(), e, (int64_t)e);
librg_entity_radius_set(world_tracker(), e, 3); librg_entity_radius_set(world_tracker(), e, 3);

View File

@ -154,10 +154,10 @@ int32_t world_init(int32_t seed, uint16_t chunk_size, uint16_t chunk_amount) {
for (int y = 0; y < world.chunk_size; y += 1) { for (int y = 0; y < world.chunk_size; y += 1) {
for (int x = 0; x < world.chunk_size; x += 1) { for (int x = 0; x < world.chunk_size; x += 1) {
int chk = world.chunk_size * i; int chk = world.chunk_size * i;
int chk_x = chk % world.chunk_amount; int chk_x = chk % world.dim;
int chk_y = chk / world.chunk_amount; int chk_y = chk / world.dim;
uint8_t *c = ecs_vector_add(&chunk->blocks, uint8_t); uint8_t *c = ecs_vector_add(&chunk->blocks, uint8_t);
*c = world.data[(chk_y+y)*world.chunk_amount + (chk_x+x)]; *c = world.data[(chk_y+y)*world.dim + (chk_x+x)];
} }
} }
} }

View File

@ -129,7 +129,7 @@ int32_t worldgen_test(world_data *wld) {
uint8_t wall_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_WALL); uint8_t wall_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_WALL);
uint8_t grnd_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_GROUND); uint8_t grnd_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_GROUND);
uint8_t dirt_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_DIRT); uint8_t dirt_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_DIRT);
//uint8_t watr_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_WATER); uint8_t watr_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_WATER);
srand(world->seed); srand(world->seed);
@ -141,18 +141,18 @@ int32_t worldgen_test(world_data *wld) {
world_fill_rect(dirt_id, 1, 1, world->dim-2, world->dim-2, shaper_noise50); world_fill_rect(dirt_id, 1, 1, world->dim-2, world->dim-2, shaper_noise50);
// water // water
#if 0 #if 1
for (int i=0; i<RAND_RANGE(0, 12); i++) { for (int i=0; i<RAND_RANGE(8, 22); i++) {
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); 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_noise80);
} }
#endif #endif
// hills // hills
#if 0 #if 1
const uint32_t HILLS_SIZE = 44; const uint32_t HILLS_SIZE = 21;
for (int i=0; i<RAND_RANGE(32, 224); i++) { for (int i=0; i<RAND_RANGE(8, 124); i++) {
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); 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_noise50);
} }
#endif #endif