#ifndef SHARED_WORLD_CHUNK_HH_ #define SHARED_WORLD_CHUNK_HH_ #include #include #include #include #include #include #include #include #include #include #include #include "shared/math/math.hh" #include "shared/net/proto.hh" #include "shared/shared.hh" #include "shared/world/block.hh" namespace shared { namespace world { class chunk { public: static constexpr int WIDTH = 16; static constexpr int HEIGHT = 256; static constexpr int VOLUME = WIDTH * WIDTH * HEIGHT; // Stuff for unordered_map. static std::size_t hash(const shared::math::coords& c) noexcept { std::size_t seed = 0; boost::hash_combine(seed, boost::hash_value(c.x)); boost::hash_combine(seed, boost::hash_value(c.z)); return seed; } static std::size_t equal(const shared::math::coords& a, const shared::math::coords& b) noexcept { return a == b; } enum class biome { desert, islands, ocean, plains, forest, tundra, alpine }; using block_array_t = std::array; using blocks_t = std::unique_ptr; using biome_array_t = std::array, WIDTH>; using biomes_t = std::unique_ptr; protected: shared::math::coords pos; blocks_t blocks; // Use get_block for 3d index access. // Simple 2d array of enums where each column maps to the dominant biome // at that x, z location. Call get_biome_str for string. biomes_t biomes; public: static bool is_outside_chunk(const glm::ivec3& v) noexcept; static shared::math::coords get_normalised_chunk(const shared::math::coords& coords, const int x, const int z) noexcept; static std::pair get_normalised_coords(const int x, const int z) noexcept; static glm::ivec3 get_normalised_coords(const glm::ivec3& c) noexcept; public: chunk(const std::uint64_t& seed, const shared::math::coords& coords) noexcept; chunk(const std::uint64_t& seed, const proto::chunk& chunk) noexcept; virtual ~chunk() noexcept {}; protected: void pack(proto::chunk* const proto) const noexcept; public: block& get_block(const glm::ivec3& v) noexcept; const block& get_block(const glm::ivec3& v) const noexcept; const shared::math::coords& get_pos() const noexcept { return this->pos; } const char* get_biome(const int x, const int z) const noexcept; }; } // namespace world } // namespace shared #endif