refactor a bit
This commit is contained in:
parent
667a90b724
commit
afedd103e8
@ -11,7 +11,7 @@
|
|||||||
using glm::vec3;
|
using glm::vec3;
|
||||||
|
|
||||||
// All in-game definitions (blocks, items, etc..)
|
// 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* block = new Block("core:air", "air");
|
||||||
block->replaceable = true;
|
block->replaceable = true;
|
||||||
block->drawGroup = 1;
|
block->drawGroup = 1;
|
||||||
|
|||||||
@ -238,22 +238,18 @@ ubyte* WorldFiles::getData(unordered_map<ivec2, WorldRegion*>& regions,
|
|||||||
int localX = x - (regionX * REGION_SIZE);
|
int localX = x - (regionX * REGION_SIZE);
|
||||||
int localZ = z - (regionZ * REGION_SIZE);
|
int localZ = z - (regionZ * REGION_SIZE);
|
||||||
|
|
||||||
WorldRegion* region = getRegion(regions, regionX, regionZ);
|
WorldRegion* region = getOrCreateRegion(regions, regionX, regionZ);
|
||||||
if (region == nullptr) {
|
|
||||||
region = new WorldRegion();
|
|
||||||
regions[ivec2(regionX, regionZ)] = region;
|
|
||||||
}
|
|
||||||
|
|
||||||
ubyte* data = region->get(localX, localZ);
|
ubyte* data = region->get(localX, localZ);
|
||||||
if (data == nullptr) {
|
if (data == nullptr) {
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
data = readChunkData(x, z, size,
|
data = readChunkData(x, z, size,
|
||||||
folder/getRegionFilename(regionX, regionZ));
|
folder/getRegionFilename(regionX, regionZ));
|
||||||
if (data) {
|
if (data != nullptr) {
|
||||||
region->put(localX, localZ, data, size);
|
region->put(localX, localZ, data, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (data) {
|
if (data != nullptr) {
|
||||||
return decompress(data, region->getSize(localX, localZ), CHUNK_DATA_LEN);
|
return decompress(data, region->getSize(localX, localZ), CHUNK_DATA_LEN);
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -291,6 +287,9 @@ ubyte* WorldFiles::readChunkData(int x, int z, uint32_t& length, path filename){
|
|||||||
ubyte* data = new ubyte[length];
|
ubyte* data = new ubyte[length];
|
||||||
input.read((char*)data, length);
|
input.read((char*)data, length);
|
||||||
input.close();
|
input.close();
|
||||||
|
if (data == nullptr) {
|
||||||
|
std::cerr << "ERROR: failed to read data of chunk x("<< x <<"), z("<< z <<")" << std::endl;
|
||||||
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -50,7 +50,7 @@ char* files::read_bytes(path filename, size_t& length) {
|
|||||||
length = input.tellg();
|
length = input.tellg();
|
||||||
input.seekg(0, std::ios_base::beg);
|
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.read(data.get(), length);
|
||||||
input.close();
|
input.close();
|
||||||
return data.release();
|
return data.release();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user