void destroy_chunk(world_data* world, int x, int y) { int index = chunk_index(world, x, y); if (!chunk_at(world, index)) { return; } world->chunks.erase(index); }
void create_chunk(world_chunk* chunk, int x, int y) { chunk->index = { x, y }; size_t total_tiles = TILES_PER_ROW * TILES_PER_COL; chunk->tiles.reserve(total_tiles); for (size_t i = 0; i < total_tiles; i++) { chunk->tiles.push_back(world_tile()); chunk->tiles[i].chunk_index = chunk_index(current_world(), x, y); chunk->tiles[i].index = (uint16) i; } chunk->transform.scale.xy = { 1.0f, 1.0f }; chunk->transform.position.xy = chunk_position({ x, y }); }
element& operator() (chunk_index i, uint8_t dir) { chunk_index p (0,0,0); switch (dir) { case 0: p = chunk_index( i.y, i.z, i.x); break; case 1: p = chunk_index( 15 - i.y, i.z, 15 - i.x); break; case 2: p = chunk_index( 15 - i.x, i.z, i.y); break; case 3: p = chunk_index( i.x, i.z, 15 - i.y); break; case 4: p = chunk_index( i.x, i.y, i.z); break; case 5: p = chunk_index( i.x, 15 - i.y, 15 - i.z); break; default: assert(false); } return dirs[dir][p.z][map_index(p)]; }
world_chunk* chunk_at(world_data* world, int x, int y) { if (world->chunks.find(chunk_index(world, x, y)) == world->chunks.end()) { return nullptr; } return &world->chunks[chunk_index(world, x, y)]; }
void initialize_chunk(world_data* world, int x, int y) { int index = chunk_index(world, x, y); world->chunks.emplace(index, world_chunk()); create_chunk(&world->chunks[index], x, y); }