refactor: place y before x
Signed-off-by: szdytom <szdytom@qq.com>
This commit is contained in:
parent
849b7b2ed9
commit
75b362037c
@ -103,12 +103,12 @@ void print_statistics(const istd::TileMap &tilemap) {
|
||||
const int chunks_per_side = tilemap.get_size();
|
||||
const int tiles_per_chunk = istd::Chunk::size;
|
||||
|
||||
for (int chunk_y = 0; chunk_y < chunks_per_side; ++chunk_y) {
|
||||
for (int chunk_x = 0; chunk_x < chunks_per_side; ++chunk_x) {
|
||||
for (int chunk_x = 0; chunk_x < chunks_per_side; ++chunk_x) {
|
||||
for (int chunk_y = 0; chunk_y < chunks_per_side; ++chunk_y) {
|
||||
const auto &chunk = tilemap.get_chunk(chunk_x, chunk_y);
|
||||
|
||||
for (int tile_y = 0; tile_y < tiles_per_chunk; ++tile_y) {
|
||||
for (int tile_x = 0; tile_x < tiles_per_chunk; ++tile_x) {
|
||||
for (int tile_x = 0; tile_x < tiles_per_chunk; ++tile_x) {
|
||||
for (int tile_y = 0; tile_y < tiles_per_chunk; ++tile_y) {
|
||||
const auto &tile = chunk.tiles[tile_x][tile_y];
|
||||
tile_counts[static_cast<int>(tile.base)]++;
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ void TerrainGenerator::generate_map(TileMap &tilemap) {
|
||||
|
||||
// Then generate terrain for each chunk
|
||||
std::uint8_t map_size = tilemap.get_size();
|
||||
for (std::uint8_t chunk_y = 0; chunk_y < map_size; ++chunk_y) {
|
||||
for (std::uint8_t chunk_x = 0; chunk_x < map_size; ++chunk_x) {
|
||||
for (std::uint8_t chunk_x = 0; chunk_x < map_size; ++chunk_x) {
|
||||
for (std::uint8_t chunk_y = 0; chunk_y < map_size; ++chunk_y) {
|
||||
generate_chunk(tilemap, chunk_x, chunk_y);
|
||||
}
|
||||
}
|
||||
@ -33,14 +33,14 @@ void TerrainGenerator::generate_biomes(TileMap &tilemap) {
|
||||
std::uint8_t map_size = tilemap.get_size();
|
||||
|
||||
// Generate biomes for each sub-chunk
|
||||
for (std::uint8_t chunk_y = 0; chunk_y < map_size; ++chunk_y) {
|
||||
for (std::uint8_t chunk_x = 0; chunk_x < map_size; ++chunk_x) {
|
||||
for (std::uint8_t chunk_x = 0; chunk_x < map_size; ++chunk_x) {
|
||||
for (std::uint8_t chunk_y = 0; chunk_y < map_size; ++chunk_y) {
|
||||
Chunk &chunk = tilemap.get_chunk(chunk_x, chunk_y);
|
||||
|
||||
for (std::uint8_t sub_y = 0; sub_y < Chunk::subchunk_count;
|
||||
++sub_y) {
|
||||
for (std::uint8_t sub_x = 0; sub_x < Chunk::subchunk_count;
|
||||
++sub_x) {
|
||||
for (std::uint8_t sub_x = 0; sub_x < Chunk::subchunk_count;
|
||||
++sub_x) {
|
||||
for (std::uint8_t sub_y = 0; sub_y < Chunk::subchunk_count;
|
||||
++sub_y) {
|
||||
// Calculate global position for this sub-chunk's center
|
||||
auto [start_x, start_y]
|
||||
= subchunk_to_tile_start(SubChunkPos(sub_x, sub_y));
|
||||
@ -56,7 +56,7 @@ void TerrainGenerator::generate_biomes(TileMap &tilemap) {
|
||||
|
||||
// Determine biome and store directly in chunk
|
||||
BiomeType biome = determine_biome(temperature, humidity);
|
||||
chunk.biome[sub_y][sub_x] = biome;
|
||||
chunk.biome[sub_x][sub_y] = biome;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -69,10 +69,10 @@ void TerrainGenerator::generate_chunk(
|
||||
const Chunk &chunk = tilemap.get_chunk(chunk_x, chunk_y);
|
||||
|
||||
// Generate each sub-chunk with its corresponding biome
|
||||
for (std::uint8_t sub_y = 0; sub_y < 4; ++sub_y) {
|
||||
for (std::uint8_t sub_x = 0; sub_x < 4; ++sub_x) {
|
||||
for (std::uint8_t sub_x = 0; sub_x < 4; ++sub_x) {
|
||||
for (std::uint8_t sub_y = 0; sub_y < 4; ++sub_y) {
|
||||
SubChunkPos sub_pos(sub_x, sub_y);
|
||||
BiomeType biome = chunk.biome[sub_y][sub_x];
|
||||
BiomeType biome = chunk.biome[sub_x][sub_y];
|
||||
generate_subchunk(tilemap, chunk_x, chunk_y, sub_pos, biome);
|
||||
}
|
||||
}
|
||||
@ -88,10 +88,10 @@ void TerrainGenerator::generate_subchunk(
|
||||
auto [start_x, start_y] = subchunk_to_tile_start(sub_pos);
|
||||
|
||||
// Generate terrain for each tile in the 16x16 sub-chunk
|
||||
for (std::uint8_t local_y = start_y;
|
||||
local_y < start_y + Chunk::subchunk_size; ++local_y) {
|
||||
for (std::uint8_t local_x = start_x;
|
||||
local_x < start_x + Chunk::subchunk_size; ++local_x) {
|
||||
for (std::uint8_t local_x = start_x;
|
||||
local_x < start_x + Chunk::subchunk_size; ++local_x) {
|
||||
for (std::uint8_t local_y = start_y;
|
||||
local_y < start_y + Chunk::subchunk_size; ++local_y) {
|
||||
// Calculate global coordinates
|
||||
double global_x = chunk_x * Chunk::size + local_x;
|
||||
double global_y = chunk_y * Chunk::size + local_y;
|
||||
|
@ -19,7 +19,7 @@ Chunk &TileMap::get_chunk(std::uint8_t chunk_x, std::uint8_t chunk_y) {
|
||||
if (chunk_x >= size_ || chunk_y >= size_) {
|
||||
throw std::out_of_range("Chunk coordinates out of bounds");
|
||||
}
|
||||
return chunks_[chunk_y][chunk_x];
|
||||
return chunks_[chunk_x][chunk_y];
|
||||
}
|
||||
|
||||
const Chunk &TileMap::get_chunk(
|
||||
@ -28,7 +28,7 @@ const Chunk &TileMap::get_chunk(
|
||||
if (chunk_x >= size_ || chunk_y >= size_) {
|
||||
throw std::out_of_range("Chunk coordinates out of bounds");
|
||||
}
|
||||
return chunks_[chunk_y][chunk_x];
|
||||
return chunks_[chunk_x][chunk_y];
|
||||
}
|
||||
|
||||
Tile &TileMap::get_tile(const TilePos &pos) {
|
||||
@ -38,7 +38,7 @@ Tile &TileMap::get_tile(const TilePos &pos) {
|
||||
if (pos.local_x >= Chunk::size || pos.local_y >= Chunk::size) {
|
||||
throw std::out_of_range("Local coordinates out of bounds");
|
||||
}
|
||||
return chunks_[pos.chunk_y][pos.chunk_x].tiles[pos.local_y][pos.local_x];
|
||||
return chunks_[pos.chunk_x][pos.chunk_y].tiles[pos.local_x][pos.local_y];
|
||||
}
|
||||
|
||||
const Tile &TileMap::get_tile(const TilePos &pos) const {
|
||||
@ -48,7 +48,7 @@ const Tile &TileMap::get_tile(const TilePos &pos) const {
|
||||
if (pos.local_x >= Chunk::size || pos.local_y >= Chunk::size) {
|
||||
throw std::out_of_range("Local coordinates out of bounds");
|
||||
}
|
||||
return chunks_[pos.chunk_y][pos.chunk_x].tiles[pos.local_y][pos.local_x];
|
||||
return chunks_[pos.chunk_x][pos.chunk_y].tiles[pos.local_x][pos.local_y];
|
||||
}
|
||||
|
||||
void TileMap::set_tile(const TilePos &pos, const Tile &tile) {
|
||||
@ -58,7 +58,7 @@ void TileMap::set_tile(const TilePos &pos, const Tile &tile) {
|
||||
if (pos.local_x >= Chunk::size || pos.local_y >= Chunk::size) {
|
||||
throw std::out_of_range("Local coordinates out of bounds");
|
||||
}
|
||||
chunks_[pos.chunk_y][pos.chunk_x].tiles[pos.local_y][pos.local_x] = tile;
|
||||
chunks_[pos.chunk_x][pos.chunk_y].tiles[pos.local_x][pos.local_y] = tile;
|
||||
}
|
||||
|
||||
} // namespace istd
|
||||
|
Loading…
x
Reference in New Issue
Block a user