2-3 Corrections
This commit is contained in:
parent
6e562f51c7
commit
3a363d06a3
@ -22,7 +22,7 @@ Chunk::~Chunk() {
|
||||
std::ostringstream pos;
|
||||
pos << CHUNK_PATH << m_posX << '_' << m_posY << ".chunk";
|
||||
|
||||
std::ofstream output(pos.str().c_str(), std::fstream::binary);
|
||||
std::ofstream output(pos.str(), std::fstream::binary);
|
||||
output.write(data, sizeof(data));
|
||||
output.close();
|
||||
}
|
||||
|
@ -6,7 +6,13 @@
|
||||
|
||||
Engine::Engine() { }
|
||||
|
||||
Engine::~Engine() { }
|
||||
Engine::~Engine() {
|
||||
m_world.CleanUpWorld(m_renderCount, true);
|
||||
for (int x = 0; x < WORLD_SIZE_X; ++x) // Les destructeurs de Chunks ont de la misère, je les aide un peu!
|
||||
for (int y = 0; y < WORLD_SIZE_Y; ++y)
|
||||
if (m_world.GetChunks().Get(x, y))
|
||||
m_world.GetChunks().Get(x, y)->~Chunk();
|
||||
}
|
||||
|
||||
void Engine::Init() {
|
||||
GLenum glewErr = glewInit();
|
||||
@ -209,12 +215,6 @@ void Engine::Render(float elapsedTime) {
|
||||
void Engine::KeyPressEvent(unsigned char key) {
|
||||
switch (key) {
|
||||
case 36: // ESC
|
||||
m_world.CleanUpWorld(m_renderCount, true);
|
||||
for (int x = 0; x < WORLD_SIZE_X; ++x) // Les destructeurs de Chunks ont de la misère je les aide un peu!
|
||||
for (int y = 0; y < WORLD_SIZE_Y; ++y)
|
||||
if (m_world.GetChunks().Get(x,y))
|
||||
m_world.GetChunks().Get(x, y)->~Chunk();
|
||||
m_world.GetChunks().Reset(nullptr); // Hack cheap qui empêche d'avoir une exception en sortant du jeu
|
||||
Stop();
|
||||
break;
|
||||
case 94: // F10
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user