Auto content packs detection
This commit is contained in:
+45
-35
@@ -42,7 +42,6 @@ using std::ios;
|
||||
using std::string;
|
||||
using std::unique_ptr;
|
||||
using std::unordered_map;
|
||||
using std::filesystem::path;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
WorldRegion::WorldRegion() {
|
||||
@@ -88,7 +87,7 @@ uint WorldRegion::getSize(uint x, uint z) {
|
||||
return sizes[z * REGION_SIZE + x];
|
||||
}
|
||||
|
||||
WorldFiles::WorldFiles(path directory, const DebugSettings& settings)
|
||||
WorldFiles::WorldFiles(fs::path directory, const DebugSettings& settings)
|
||||
: directory(directory),
|
||||
generatorTestMode(settings.generatorTestMode),
|
||||
doWriteLights(settings.doWriteLights) {
|
||||
@@ -178,17 +177,17 @@ void WorldFiles::put(Chunk* chunk){
|
||||
}
|
||||
}
|
||||
|
||||
path WorldFiles::getRegionsFolder() const {
|
||||
return directory/path("regions");
|
||||
fs::path WorldFiles::getRegionsFolder() const {
|
||||
return directory/fs::path("regions");
|
||||
}
|
||||
|
||||
path WorldFiles::getLightsFolder() const {
|
||||
return directory/path("lights");
|
||||
fs::path WorldFiles::getLightsFolder() const {
|
||||
return directory/fs::path("lights");
|
||||
}
|
||||
|
||||
path WorldFiles::getRegionFilename(int x, int y) const {
|
||||
fs::path WorldFiles::getRegionFilename(int x, int y) const {
|
||||
string filename = std::to_string(x) + "_" + std::to_string(y) + ".bin";
|
||||
return path(filename);
|
||||
return fs::path(filename);
|
||||
}
|
||||
|
||||
bool WorldFiles::parseRegionFilename(const string& name, int& x, int& y) {
|
||||
@@ -206,16 +205,20 @@ bool WorldFiles::parseRegionFilename(const string& name, int& x, int& y) {
|
||||
return true;
|
||||
}
|
||||
|
||||
path WorldFiles::getPlayerFile() const {
|
||||
return directory/path("player.json");
|
||||
fs::path WorldFiles::getPlayerFile() const {
|
||||
return directory/fs::path("player.json");
|
||||
}
|
||||
|
||||
path WorldFiles::getWorldFile() const {
|
||||
return directory/path("world.json");
|
||||
fs::path WorldFiles::getWorldFile() const {
|
||||
return directory/fs::path("world.json");
|
||||
}
|
||||
|
||||
path WorldFiles::getIndicesFile() const {
|
||||
return directory/path("indices.json");
|
||||
fs::path WorldFiles::getIndicesFile() const {
|
||||
return directory/fs::path("indices.json");
|
||||
}
|
||||
|
||||
fs::path WorldFiles::getPacksFile() const {
|
||||
return directory/fs::path("packs.list");
|
||||
}
|
||||
|
||||
ubyte* WorldFiles::getChunk(int x, int z){
|
||||
@@ -230,7 +233,7 @@ light_t* WorldFiles::getLights(int x, int z) {
|
||||
}
|
||||
|
||||
ubyte* WorldFiles::getData(unordered_map<ivec2, WorldRegion*>& regions,
|
||||
const path& folder,
|
||||
const fs::path& folder,
|
||||
int x, int z) {
|
||||
int regionX = floordiv(x, REGION_SIZE);
|
||||
int regionZ = floordiv(z, REGION_SIZE);
|
||||
@@ -255,7 +258,7 @@ ubyte* WorldFiles::getData(unordered_map<ivec2, WorldRegion*>& regions,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ubyte* WorldFiles::readChunkData(int x, int z, uint32_t& length, path filename){
|
||||
ubyte* WorldFiles::readChunkData(int x, int z, uint32_t& length, fs::path filename){
|
||||
if (generatorTestMode)
|
||||
return nullptr;
|
||||
|
||||
@@ -293,7 +296,7 @@ ubyte* WorldFiles::readChunkData(int x, int z, uint32_t& length, path filename){
|
||||
return data;
|
||||
}
|
||||
|
||||
void WorldFiles::writeRegion(int x, int y, WorldRegion* entry, path filename){
|
||||
void WorldFiles::writeRegion(int x, int y, WorldRegion* entry, fs::path filename){
|
||||
ubyte** region = entry->getChunks();
|
||||
uint32_t* sizes = entry->getSizes();
|
||||
for (size_t i = 0; i < REGION_VOL; i++) {
|
||||
@@ -336,7 +339,7 @@ void WorldFiles::writeRegion(int x, int y, WorldRegion* entry, path filename){
|
||||
}
|
||||
|
||||
void WorldFiles::writeRegions(unordered_map<ivec2, WorldRegion*>& regions,
|
||||
const path& folder) {
|
||||
const fs::path& folder) {
|
||||
for (auto it : regions){
|
||||
WorldRegion* region = it.second;
|
||||
if (region->getChunks() == nullptr || !region->isUnsaved())
|
||||
@@ -347,25 +350,32 @@ void WorldFiles::writeRegions(unordered_map<ivec2, WorldRegion*>& regions,
|
||||
}
|
||||
|
||||
void WorldFiles::write(const World* world, const Content* content) {
|
||||
{
|
||||
path directory = getRegionsFolder();
|
||||
if (!fs::is_directory(directory)) {
|
||||
fs::create_directories(directory);
|
||||
}
|
||||
}
|
||||
{
|
||||
path directory = getLightsFolder();
|
||||
if (!fs::is_directory(directory)) {
|
||||
fs::create_directories(directory);
|
||||
}
|
||||
}
|
||||
if (world)
|
||||
fs::path regionsFolder = getRegionsFolder();
|
||||
fs::path lightsFolder = getLightsFolder();
|
||||
|
||||
fs::create_directories(regionsFolder);
|
||||
fs::create_directories(lightsFolder);
|
||||
|
||||
if (world) {
|
||||
writeWorldInfo(world);
|
||||
writePacks(world);
|
||||
}
|
||||
if (generatorTestMode)
|
||||
return;
|
||||
|
||||
writeIndices(content->indices);
|
||||
writeRegions(regions, getRegionsFolder());
|
||||
writeRegions(lights, getLightsFolder());
|
||||
writeRegions(regions, regionsFolder);
|
||||
writeRegions(lights, lightsFolder);
|
||||
}
|
||||
|
||||
void WorldFiles::writePacks(const World* world) {
|
||||
const auto& packs = world->getPacks();
|
||||
std::stringstream ss;
|
||||
ss << "# autogenerated; do not modify\n";
|
||||
for (const auto& pack : packs) {
|
||||
ss << pack.id << "\n";
|
||||
}
|
||||
files::write_string(getPacksFile(), ss.str());
|
||||
}
|
||||
|
||||
void WorldFiles::writeIndices(const ContentIndices* indices) {
|
||||
@@ -397,7 +407,7 @@ void WorldFiles::writeWorldInfo(const World* world) {
|
||||
}
|
||||
|
||||
bool WorldFiles::readWorldInfo(World* world) {
|
||||
path file = getWorldFile();
|
||||
fs::path file = getWorldFile();
|
||||
if (!fs::is_regular_file(file)) {
|
||||
std::cerr << "warning: world.json does not exists" << std::endl;
|
||||
return false;
|
||||
@@ -443,7 +453,7 @@ void WorldFiles::writePlayer(Player* player){
|
||||
}
|
||||
|
||||
bool WorldFiles::readPlayer(Player* player) {
|
||||
path file = getPlayerFile();
|
||||
fs::path file = getPlayerFile();
|
||||
if (!fs::is_regular_file(file)) {
|
||||
std::cerr << "warning: player.json does not exists" << std::endl;
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user