diff --git a/src/constants.hpp b/src/constants.hpp index 15b3e732..b1ae11d4 100644 --- a/src/constants.hpp +++ b/src/constants.hpp @@ -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::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; } diff --git a/src/files/WorldRegions.cpp b/src/files/WorldRegions.cpp index 07400895..cd0955c1 100644 --- a/src/files/WorldRegions.cpp +++ b/src/files/WorldRegions.cpp @@ -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(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 data, size_t size ) { diff --git a/src/files/WorldRegions.hpp b/src/files/WorldRegions.hpp index df77fdb2..eb2e803a 100644 --- a/src/files/WorldRegions.hpp +++ b/src/files/WorldRegions.hpp @@ -8,6 +8,7 @@ #include #include +#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 data, size_t size );