Voxel changed from 16 bit to 32 bit + new lua functions
This commit is contained in:
@@ -8,18 +8,15 @@
|
||||
#include "../content/ContentLUT.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
using std::string;
|
||||
using std::unique_ptr;
|
||||
using fs::path;
|
||||
|
||||
WorldConverter::WorldConverter(path folder,
|
||||
WorldConverter::WorldConverter(fs::path folder,
|
||||
const Content* content,
|
||||
const ContentLUT* lut)
|
||||
: lut(lut), content(content) {
|
||||
DebugSettings settings;
|
||||
wfile = new WorldFiles(folder, settings);
|
||||
|
||||
path regionsFolder = wfile->getRegionsFolder();
|
||||
fs::path regionsFolder = wfile->getRegionsFolder();
|
||||
if (!fs::is_directory(regionsFolder)) {
|
||||
std::cerr << "nothing to convert" << std::endl;
|
||||
return;
|
||||
@@ -41,13 +38,13 @@ void WorldConverter::convertNext() {
|
||||
if (!hasNext()) {
|
||||
throw std::runtime_error("no more regions to convert");
|
||||
}
|
||||
path regfile = regions.front();
|
||||
fs::path regfile = regions.front();
|
||||
regions.pop();
|
||||
if (!fs::is_regular_file(regfile))
|
||||
return;
|
||||
int x, y;
|
||||
string name = regfile.stem().string();
|
||||
if (!WorldFiles::parseRegionFilename(name, x, y)) {
|
||||
int x, z;
|
||||
std::string name = regfile.stem().string();
|
||||
if (!WorldFiles::parseRegionFilename(name, x, z)) {
|
||||
std::cerr << "could not parse name " << name << std::endl;
|
||||
return;
|
||||
}
|
||||
@@ -55,11 +52,16 @@ void WorldConverter::convertNext() {
|
||||
for (uint cz = 0; cz < REGION_SIZE; cz++) {
|
||||
for (uint cx = 0; cx < REGION_SIZE; cx++) {
|
||||
int gx = cx + x * REGION_SIZE;
|
||||
int gz = cz + y * REGION_SIZE;
|
||||
unique_ptr<ubyte[]> data (wfile->getChunk(gx, gz));
|
||||
int gz = cz + z * REGION_SIZE;
|
||||
std::unique_ptr<ubyte[]> data (wfile->getChunk(gx, gz));
|
||||
if (data == nullptr)
|
||||
continue;
|
||||
Chunk::convert(data.get(), lut);
|
||||
if (wfile->getVoxelRegionVersion(x, z) != REGION_FORMAT_VERSION) {
|
||||
Chunk::fromOld(data.get());
|
||||
}
|
||||
if (lut) {
|
||||
Chunk::convert(data.get(), lut);
|
||||
}
|
||||
wfile->put(gx, gz, data.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@ regfile::regfile(fs::path filename) : file(filename) {
|
||||
throw std::runtime_error("invalid region file magic number");
|
||||
}
|
||||
version = header[8];
|
||||
if (version > 2) {
|
||||
throw std::runtime_error(
|
||||
if (version > REGION_FORMAT_VERSION) {
|
||||
throw illegal_region_format(
|
||||
"region format "+std::to_string(version)+" is not supported");
|
||||
}
|
||||
}
|
||||
@@ -130,6 +130,31 @@ ubyte* WorldFiles::decompress(const ubyte* src, size_t srclen, size_t dstlen) {
|
||||
return decompressed;
|
||||
}
|
||||
|
||||
int WorldFiles::getVoxelRegionVersion(int x, int z) {
|
||||
regfile* rf = getRegFile(glm::ivec3(x, z, REGION_LAYER_VOXELS), getRegionsFolder());
|
||||
if (rf == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
return rf->version;
|
||||
}
|
||||
|
||||
int WorldFiles::getVoxelRegionsVersion() {
|
||||
fs::path regionsFolder = getRegionsFolder();
|
||||
if (!fs::is_directory(regionsFolder)) {
|
||||
return REGION_FORMAT_VERSION;
|
||||
}
|
||||
for (auto file : fs::directory_iterator(regionsFolder)) {
|
||||
int x;
|
||||
int z;
|
||||
if (!parseRegionFilename(file.path().stem().string(), x, z)) {
|
||||
continue;
|
||||
}
|
||||
regfile* rf = getRegFile(glm::ivec3(x, z, REGION_LAYER_VOXELS), regionsFolder);
|
||||
return rf->version;
|
||||
}
|
||||
return REGION_FORMAT_VERSION;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compress and store chunk voxels data in region
|
||||
* @param x chunk.x
|
||||
@@ -190,8 +215,7 @@ fs::path WorldFiles::getLightsFolder() const {
|
||||
}
|
||||
|
||||
fs::path WorldFiles::getRegionFilename(int x, int z) const {
|
||||
std::string filename = std::to_string(x) + "_" + std::to_string(z) + ".bin";
|
||||
return fs::path(filename);
|
||||
return fs::path(std::to_string(x) + "_" + std::to_string(z) + ".bin");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -254,7 +278,6 @@ ubyte* WorldFiles::getData(regionsmap& regions, const fs::path& folder,
|
||||
int localZ = z - (regionZ * REGION_SIZE);
|
||||
|
||||
WorldRegion* region = getOrCreateRegion(regions, regionX, regionZ);
|
||||
|
||||
ubyte* data = region->getChunkData(localX, localZ);
|
||||
if (data == nullptr) {
|
||||
uint32_t size;
|
||||
|
||||
@@ -34,6 +34,12 @@ class Content;
|
||||
class ContentIndices;
|
||||
class World;
|
||||
|
||||
class illegal_region_format : public std::runtime_error {
|
||||
public:
|
||||
illegal_region_format(const std::string& message)
|
||||
: std::runtime_error(message) {}
|
||||
};
|
||||
|
||||
class WorldRegion {
|
||||
ubyte** chunksData;
|
||||
uint32_t* sizes;
|
||||
@@ -125,6 +131,9 @@ public:
|
||||
void put(Chunk* chunk);
|
||||
void put(int x, int z, const ubyte* voxelData);
|
||||
|
||||
int getVoxelRegionVersion(int x, int z);
|
||||
int getVoxelRegionsVersion();
|
||||
|
||||
ubyte* getChunk(int x, int z);
|
||||
light_t* getLights(int x, int z);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user