replace regions layer index with enum
This commit is contained in:
parent
10e10955dc
commit
3dda512468
@ -16,6 +16,12 @@ inline constexpr bool ENGINE_DEBUG_BUILD = true;
|
||||
|
||||
inline const std::string ENGINE_VERSION_STRING = "0.23";
|
||||
|
||||
/// @brief world regions format version
|
||||
inline constexpr uint REGION_FORMAT_VERSION = 2;
|
||||
|
||||
/// @brief max simultaneously open world region files
|
||||
inline constexpr uint MAX_OPEN_REGION_FILES = 32;
|
||||
|
||||
inline constexpr blockid_t BLOCK_AIR = 0;
|
||||
inline constexpr itemid_t ITEM_EMPTY = 0;
|
||||
inline constexpr entityid_t ENTITY_NONE = 0;
|
||||
@ -40,6 +46,7 @@ inline constexpr itemid_t ITEM_VOID = std::numeric_limits<itemid_t>::max();
|
||||
/// @brief max number of block definitions possible
|
||||
inline constexpr blockid_t MAX_BLOCKS = BLOCK_VOID;
|
||||
|
||||
/// @brief calculates a 1D array index from 3D array indices
|
||||
inline constexpr uint vox_index(uint x, uint y, uint z, uint w=CHUNK_W, uint d=CHUNK_D) {
|
||||
return (y * d + z) * w + x;
|
||||
}
|
||||
|
||||
@ -51,8 +51,8 @@ uint WorldRegion::getChunkDataSize(uint x, uint z) {
|
||||
}
|
||||
|
||||
WorldRegions::WorldRegions(const fs::path& directory) : directory(directory) {
|
||||
for (size_t i = 0; i < sizeof(layers) / sizeof(RegionsLayer); i++) {
|
||||
layers[i].layer = i;
|
||||
for (size_t i = 0; i < REGION_LAYERS_COUNT; i++) {
|
||||
layers[i].layer = static_cast<RegionLayerIndex>(i);
|
||||
}
|
||||
auto& voxels = layers[REGION_LAYER_VOXELS];
|
||||
voxels.folder = directory / fs::path("regions");
|
||||
@ -83,7 +83,7 @@ void RegionsLayer::writeAll() {
|
||||
void WorldRegions::put(
|
||||
int x,
|
||||
int z,
|
||||
int layerid,
|
||||
RegionLayerIndex layerid,
|
||||
std::unique_ptr<ubyte[]> data,
|
||||
size_t size
|
||||
) {
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "constants.hpp"
|
||||
#include "typedefs.hpp"
|
||||
#include "data/dynamic_fwd.hpp"
|
||||
#include "util/BufferPool.hpp"
|
||||
@ -23,16 +24,18 @@ namespace fs = std::filesystem;
|
||||
|
||||
inline constexpr uint REGION_HEADER_SIZE = 10;
|
||||
|
||||
inline constexpr uint REGION_LAYER_VOXELS = 0;
|
||||
inline constexpr uint REGION_LAYER_LIGHTS = 1;
|
||||
inline constexpr uint REGION_LAYER_INVENTORIES = 2;
|
||||
inline constexpr uint REGION_LAYER_ENTITIES = 3;
|
||||
enum RegionLayerIndex : uint {
|
||||
REGION_LAYER_VOXELS = 0,
|
||||
REGION_LAYER_LIGHTS,
|
||||
REGION_LAYER_INVENTORIES,
|
||||
REGION_LAYER_ENTITIES,
|
||||
|
||||
REGION_LAYERS_COUNT
|
||||
};
|
||||
|
||||
inline constexpr uint REGION_SIZE_BIT = 5;
|
||||
inline constexpr uint REGION_SIZE = (1 << (REGION_SIZE_BIT));
|
||||
inline constexpr uint REGION_CHUNKS_COUNT = ((REGION_SIZE) * (REGION_SIZE));
|
||||
inline constexpr uint REGION_FORMAT_VERSION = 2;
|
||||
inline constexpr uint MAX_OPEN_REGION_FILES = 32;
|
||||
|
||||
class illegal_region_format : public std::runtime_error {
|
||||
public:
|
||||
@ -122,7 +125,7 @@ inline void calc_reg_coords(
|
||||
|
||||
struct RegionsLayer {
|
||||
/// @brief Layer index
|
||||
int layer;
|
||||
RegionLayerIndex layer;
|
||||
|
||||
/// @brief Regions layer folder
|
||||
fs::path folder;
|
||||
@ -180,7 +183,7 @@ class WorldRegions {
|
||||
/// @brief World directory
|
||||
fs::path directory;
|
||||
|
||||
RegionsLayer layers[4] {};
|
||||
RegionsLayer layers[REGION_LAYERS_COUNT] {};
|
||||
public:
|
||||
bool generatorTestMode = false;
|
||||
bool doWriteLights = true;
|
||||
@ -201,7 +204,7 @@ public:
|
||||
void put(
|
||||
int x,
|
||||
int z,
|
||||
int layer,
|
||||
RegionLayerIndex layer,
|
||||
std::unique_ptr<ubyte[]> data,
|
||||
size_t size
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user