mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-11 22:11:51 +00:00
refactor: WorldRegions and chunks saving
This commit is contained in:
parent
f206042b00
commit
c67e4b04bb
8 changed files with 50 additions and 45 deletions
|
|
@ -5,8 +5,9 @@
|
|||
#include <stdlib.h>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "../constants.hpp"
|
||||
#include "voxel.hpp"
|
||||
|
||||
#include "../constants.hpp"
|
||||
#include "../lighting/Lightmap.hpp"
|
||||
|
||||
inline constexpr int CHUNK_DATA_LEN = CHUNK_VOL*4;
|
||||
|
|
@ -15,6 +16,10 @@ class Lightmap;
|
|||
class ContentLUT;
|
||||
class Inventory;
|
||||
|
||||
namespace dynamic {
|
||||
class Map;
|
||||
}
|
||||
|
||||
using chunk_inventories_map = std::unordered_map<uint, std::shared_ptr<Inventory>>;
|
||||
|
||||
class Chunk {
|
||||
|
|
@ -32,7 +37,7 @@ public:
|
|||
bool loadedLights: 1;
|
||||
} flags {};
|
||||
|
||||
/* Block inventories map where key is index of block in voxels array */
|
||||
/// @brief Block inventories map where key is index of block in voxels array
|
||||
chunk_inventories_map inventories;
|
||||
|
||||
Chunk(int x, int z);
|
||||
|
|
@ -44,14 +49,15 @@ public:
|
|||
// unused
|
||||
std::unique_ptr<Chunk> clone() const;
|
||||
|
||||
/* Creates new block inventory given size
|
||||
@return inventory id or 0 if block does not exists */
|
||||
void addBlockInventory(std::shared_ptr<Inventory> inventory,
|
||||
uint x, uint y, uint z);
|
||||
/// @brief Creates new block inventory given size
|
||||
/// @return inventory id or 0 if block does not exists
|
||||
void addBlockInventory(
|
||||
std::shared_ptr<Inventory> inventory, uint x, uint y, uint z
|
||||
);
|
||||
void removeBlockInventory(uint x, uint y, uint z);
|
||||
void setBlockInventories(chunk_inventories_map map);
|
||||
|
||||
/* @return inventory bound to the given block or nullptr */
|
||||
/// @return inventory bound to the given block or nullptr
|
||||
std::shared_ptr<Inventory> getBlockInventory(uint x, uint y, uint z) const;
|
||||
|
||||
inline void setModifiedAndUnsaved() {
|
||||
|
|
@ -61,9 +67,7 @@ public:
|
|||
|
||||
std::unique_ptr<ubyte[]> encode() const;
|
||||
|
||||
/**
|
||||
* @return true if all is fine
|
||||
**/
|
||||
/// @return true if all is fine
|
||||
bool decode(const ubyte* data);
|
||||
|
||||
static void convert(ubyte* data, const ContentLUT* lut);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue