2-3 Corrections

This commit is contained in:
MarcEricMartel
2021-12-06 21:41:50 -05:00
parent 6e562f51c7
commit 3a363d06a3
3 changed files with 10 additions and 16 deletions

View File

@@ -118,7 +118,6 @@ void World::Update(int& rendercount, int& badhitcount, Player& player, Transform
}
bool World::GenerateChunk(int chx, int chy, Perlin& perlin) {
if (chx < WORLD_SIZE_X * CHUNK_SIZE_X && chy < WORLD_SIZE_Y * CHUNK_SIZE_Z &&
chx >= 0 && chy >= 0)
if (!ChunkAt(chx, 1, chy)) {
@@ -138,8 +137,7 @@ bool World::GenerateChunk(int chx, int chy, Perlin& perlin) {
std::ostringstream pos; // V<>rifie l'existence d'un fichier .chunk avec sa position.
pos << CHUNK_PATH << chx / CHUNK_SIZE_X + m_center[0] << '_' << chy / CHUNK_SIZE_Z + m_center[1] << ".chunk";
std::ifstream input(pos.str().c_str(), std::fstream::binary);
std::ifstream input(pos.str(), std::fstream::binary);
if (input.fail()) {
GetChunks().Set(chx / CHUNK_SIZE_X, chy / CHUNK_SIZE_Z, new Chunk(chx / CHUNK_SIZE_X + m_center[0], chy / CHUNK_SIZE_Z + m_center[1]));
@@ -190,24 +188,20 @@ bool World::GenerateChunk(int chx, int chy, Perlin& perlin) {
chunk->SetBlock(x, y + i, z, BTYPE_DIRT, this);
break;
}
}
}
else {
input.seekg(0, std::ios_base::end);
int size = input.tellg();
input.seekg(0, std::ios_base::beg);
char* data = new char[size];
char data[CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z];
input.read(data, size);
input.close();
GetChunks().Set(chx / CHUNK_SIZE_X, chy / CHUNK_SIZE_Z, new Chunk(chx / CHUNK_SIZE_X + m_center[0], chy / CHUNK_SIZE_Z + m_center[1], data));
delete[] data;
}
return true;
}
return false;