60 lines
1.4 KiB
C++
60 lines
1.4 KiB
C++
#ifndef ISTD_TILEMAP_CHUNK_H
|
|
#define ISTD_TILEMAP_CHUNK_H
|
|
#include "tile.h"
|
|
#include <cstdint>
|
|
|
|
namespace istd {
|
|
|
|
// Forward declaration
|
|
enum class BiomeType : std::uint8_t;
|
|
|
|
// Position within a chunk's sub-chunk grid
|
|
struct SubChunkPos {
|
|
std::uint8_t sub_x;
|
|
std::uint8_t sub_y;
|
|
|
|
constexpr SubChunkPos(std::uint8_t x, std::uint8_t y): sub_x(x), sub_y(y) {}
|
|
};
|
|
|
|
// Represents the position of a tile in the map, using chunk and local
|
|
// coordinates
|
|
struct TilePos {
|
|
uint8_t chunk_x;
|
|
uint8_t chunk_y;
|
|
uint8_t local_x;
|
|
uint8_t local_y;
|
|
};
|
|
|
|
struct Chunk {
|
|
// Size of a chunk in tiles (64 x 64)
|
|
static constexpr uint8_t size = 64;
|
|
|
|
// Sub-chunk size in tiles
|
|
static constexpr uint8_t subchunk_size = 4;
|
|
|
|
// Number of sub-chunks in each dimension
|
|
static constexpr uint8_t subchunk_count = size / subchunk_size;
|
|
|
|
// array of tile types
|
|
Tile tiles[size][size];
|
|
|
|
// array of biomes for sub-chunks
|
|
BiomeType biome[subchunk_count][subchunk_count];
|
|
|
|
// Get biome for a specific sub-chunk position
|
|
BiomeType &get_biome(SubChunkPos pos) {
|
|
return biome[pos.sub_x][pos.sub_y];
|
|
}
|
|
|
|
// Get biome for a specific sub-chunk position (const version)
|
|
const BiomeType &get_biome(SubChunkPos pos) const {
|
|
return biome[pos.sub_x][pos.sub_y];
|
|
}
|
|
};
|
|
|
|
// Get the starting tile coordinates for a sub-chunk
|
|
std::pair<std::uint8_t, std::uint8_t> subchunk_to_tile_start(SubChunkPos pos);
|
|
|
|
} // namespace istd
|
|
|
|
#endif |