From 3a363d06a3dce0772c52ea357e2521de4eb9acc0 Mon Sep 17 00:00:00 2001 From: MarcEricMartel <74071476+MarcEricMartel@users.noreply.github.com> Date: Mon, 6 Dec 2021 21:41:50 -0500 Subject: [PATCH] 2-3 Corrections --- SQCSim2021/chunk.cpp | 2 +- SQCSim2021/engine.cpp | 14 +++++++------- SQCSim2021/world.cpp | 10 ++-------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/SQCSim2021/chunk.cpp b/SQCSim2021/chunk.cpp index 85df7ff..e63e1e7 100644 --- a/SQCSim2021/chunk.cpp +++ b/SQCSim2021/chunk.cpp @@ -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(); } diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 0661bd3..7f24df8 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -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 diff --git a/SQCSim2021/world.cpp b/SQCSim2021/world.cpp index 6d33a5b..c3ead37 100644 --- a/SQCSim2021/world.cpp +++ b/SQCSim2021/world.cpp @@ -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;