refactor a bit

This commit is contained in:
A-lex-Ra 2023-12-18 20:48:03 +06:00
parent 667a90b724
commit afedd103e8
3 changed files with 8 additions and 9 deletions

View File

@ -11,7 +11,7 @@
using glm::vec3;
// All in-game definitions (blocks, items, etc..)
void setup_definitions(ContentBuilder* builder) {
void setup_definitions(ContentBuilder* builder) { // Strange function, need to REDO ?
Block* block = new Block("core:air", "air");
block->replaceable = true;
block->drawGroup = 1;

View File

@ -238,22 +238,18 @@ ubyte* WorldFiles::getData(unordered_map<ivec2, WorldRegion*>& regions,
int localX = x - (regionX * REGION_SIZE);
int localZ = z - (regionZ * REGION_SIZE);
WorldRegion* region = getRegion(regions, regionX, regionZ);
if (region == nullptr) {
region = new WorldRegion();
regions[ivec2(regionX, regionZ)] = region;
}
WorldRegion* region = getOrCreateRegion(regions, regionX, regionZ);
ubyte* data = region->get(localX, localZ);
if (data == nullptr) {
uint32_t size;
data = readChunkData(x, z, size,
folder/getRegionFilename(regionX, regionZ));
if (data) {
if (data != nullptr) {
region->put(localX, localZ, data, size);
}
}
if (data) {
if (data != nullptr) {
return decompress(data, region->getSize(localX, localZ), CHUNK_DATA_LEN);
}
return nullptr;
@ -291,6 +287,9 @@ ubyte* WorldFiles::readChunkData(int x, int z, uint32_t& length, path filename){
ubyte* data = new ubyte[length];
input.read((char*)data, length);
input.close();
if (data == nullptr) {
std::cerr << "ERROR: failed to read data of chunk x("<< x <<"), z("<< z <<")" << std::endl;
}
return data;
}

View File

@ -50,7 +50,7 @@ char* files::read_bytes(path filename, size_t& length) {
length = input.tellg();
input.seekg(0, std::ios_base::beg);
unique_ptr<char> data {new char[length]};
unique_ptr<char> data(new char[length]);
input.read(data.get(), length);
input.close();
return data.release();