From a3c0dee1f2212ebaf1988949d5527b09a33522dc Mon Sep 17 00:00:00 2001 From: MarcEricMartel <74071476+MarcEricMartel@users.noreply.github.com> Date: Sat, 4 Dec 2021 09:55:43 -0500 Subject: [PATCH] Optimization de performance du renderer! --- SQCSim2021/engine.cpp | 6 ++-- SQCSim2021/engine.h | 2 +- SQCSim2021/media/chunks/16357_16343.chunk | 1 - SQCSim2021/media/chunks/16382_16360.chunk | Bin 32768 -> 0 bytes SQCSim2021/media/chunks/16382_16377.chunk | Bin 32768 -> 0 bytes SQCSim2021/media/chunks/16382_16382.chunk | Bin 32768 -> 0 bytes SQCSim2021/media/chunks/16382_16383.chunk | Bin 32768 -> 0 bytes SQCSim2021/media/chunks/16383_16382.chunk | Bin 32768 -> 0 bytes SQCSim2021/media/chunks/16383_16383.chunk | Bin 32768 -> 0 bytes SQCSim2021/world.cpp | 37 +++++++++++----------- 10 files changed, 23 insertions(+), 23 deletions(-) delete mode 100644 SQCSim2021/media/chunks/16357_16343.chunk delete mode 100644 SQCSim2021/media/chunks/16382_16360.chunk delete mode 100644 SQCSim2021/media/chunks/16382_16377.chunk delete mode 100644 SQCSim2021/media/chunks/16382_16382.chunk delete mode 100644 SQCSim2021/media/chunks/16382_16383.chunk delete mode 100644 SQCSim2021/media/chunks/16383_16382.chunk delete mode 100644 SQCSim2021/media/chunks/16383_16383.chunk diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index fc03441..431897a 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -35,7 +35,7 @@ void Engine::Init() { m_skybox.Init(0.00013f); // Objet de musique! - m_audio.ToggleMusicState(); + //m_audio.ToggleMusicState(); // Init Chunks m_world.GetChunks().Reset(nullptr); @@ -52,9 +52,9 @@ void Engine::LoadResource() { LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp"); LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp"); TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png"); - TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "dirt.png"); + TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png"); TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png"); - TextureAtlas::TextureIndex texMetalIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal.png"); + TextureAtlas::TextureIndex texMetalIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal1.png"); if (!m_textureAtlas.Generate(512, false)) { std::cout << " Unable to generate texture atlas ..." << std::endl; diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index 1eeff0d..e1e4626 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -47,7 +47,7 @@ private: TextureAtlas m_textureAtlas = TextureAtlas(BTYPE_LAST); World m_world = World(); - Perlin m_perlin = Perlin(4,32.f,7.f,12345); + Perlin m_perlin = Perlin(8,45.f,7.f,12345); Texture m_textureSkybox; Texture m_textureFont; diff --git a/SQCSim2021/media/chunks/16357_16343.chunk b/SQCSim2021/media/chunks/16357_16343.chunk deleted file mode 100644 index 96cfa40..0000000 --- a/SQCSim2021/media/chunks/16357_16343.chunk +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/SQCSim2021/media/chunks/16382_16360.chunk b/SQCSim2021/media/chunks/16382_16360.chunk deleted file mode 100644 index 7f5c4748bb58c80c573f775fa35f3eddf50b1155..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 32768 zcmeIvF>b<800dDZ-~Y}*1d(_sQl&`tQF%TF{hc{a9|jm;fB^;=V1NMz7+`<_1{h#~ z0R|XgfB^;=VBmilIF92o=$$WLpLzWk_^10^Z*afw<>0~J{^FCr4xaq_&5QeR>%kb? zKNdW5^^cG-)PF2^=IS3IW2paF@XXaeLdH=4vEZ4je}s&o{$s&2SN{kZL;c5sXRiJc zGKTt(1OU4dbM=pqG1Px7c;@OKA!DfjSn$l%KSIV(|FPhi ztAB)yq5fmRGgtoz8AJWYf@iM&5i*AQj|IdjIHv3^2d|0}L?0 O00Rs#zyJe(+rS53y-ltF diff --git a/SQCSim2021/media/chunks/16382_16377.chunk b/SQCSim2021/media/chunks/16382_16377.chunk deleted file mode 100644 index a62d18d79cb0b5c84916525908086a796fab78e2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 32768 zcmeIvOKQUa5CuU;zW<$LBmc4pfzX==rIiNZVO)K^dVUo+j^p+1_I`iP`FwxO@8SOa z$7CQtfB*pk1PBlyK!5-N0tEgcaQXbr<@UVi`}8rNpe|c8UJ8>5{|sPZ(#H=s%k-Ib8pQadwIRv+0t<^-maQm*_v6E;(HPgmHF>{pe|c8UJ8>5{|sPZ(#H=s%k- zIb8pQadwIRv+0t<^-maQm*_v6E;(HPgmHF>{pg85&{GW5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs S0RjXF5FkK+009Dj348-$A0sRP diff --git a/SQCSim2021/media/chunks/16382_16382.chunk b/SQCSim2021/media/chunks/16382_16382.chunk deleted file mode 100644 index 21dacccdb2e2ec2d7b2088278857dbda1e783619..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 32768 zcmeIzL6(9*3;v4MWC7YoQ<2Q-wQR}5lNLK^K4CrwbJ+$&wIj?-Wcx*FS_r9 zjrO+j*Lb_)mVb#~8}IW={M^{jw<~OS@}2kbS1$3eF@KED36FYCH@?(&-1sd%B^;A| zMgRc>5I_I{1Q0*~0R$QZZp%89I>ys*J}n!E{A>J3IGtbOX*j>c=dXVuT8qrS-0#`a z*TU5w_unr67JvNJ@Bg1B;Q3GM*Z+ZM@|gIYi$opm6?^RGjd^cq^|!ef^!mrSHSGQU0sEW1a}&3D zoI^wXRUYqppT`H}^B>Lb2oNAZfB*pk1PBnAULc)D!ALHNNI@Eh1t))O#b~(fBxzI@eWLY009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNCfOyCPA CDYYv44k`4dR7So`a5#s7Zu7yI3fOMn0Y0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U pAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t9{{FawoDAff;O diff --git a/SQCSim2021/media/chunks/16383_16383.chunk b/SQCSim2021/media/chunks/16383_16383.chunk deleted file mode 100644 index 578182415d92e10f9c231c1d628cb883c8a9266a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 32768 zcmeI)K~BR!5Jb_~zW<#eF(Tsu^pIv#owOH-@y`_XyOG#&9OJX^|xuVO%^ZbF!?LPDbdICLxo= zO}gzr4dmVSKmSHg@pcq~8hctI4DpE%;< zvHZm21yN9b;)svO@)M62L_zt9BR(F>Pdr`_1?4A>_;@To@pwTLl%F`_yqe6OR`}LHUUz zJ|4?YJYEn5Pdr`_ z1?4A>_;@To@pwTLl%F`_yqe6OR`}LHUUzJ|4?YJYEn5-SetBlock(x, y, z, BTYPE_METAL, this); } @@ -158,7 +158,7 @@ bool World::GenerateChunk(int chx, int chy, Perlin& perlin) { float xnoiz, ynoiz; xnoiz = (double)(x + (chx / CHUNK_SIZE_X + m_center[0]) * CHUNK_SIZE_X) / (double)INT16_MAX; ynoiz = (double)(z + (chy / CHUNK_SIZE_Z + m_center[1]) * CHUNK_SIZE_Z) / (double)INT16_MAX; - float height = (perlin.Get(xnoiz, ynoiz) + 16.f); + float height = perlin.Get(xnoiz, ynoiz) * 5.f + 16.f; for (int y = 0; y <= (int)height % CHUNK_SIZE_Y; ++y) { if (chunk->GetBlock(x, y, z) == BTYPE_AIR) chunk->SetBlock(x, y, z, BTYPE_GRASS, this); @@ -272,14 +272,14 @@ void World::RenderWorld(int& rendercount, int& badhitcount, Player& player, Tran direct.Normalize(); pos.y = 1; - static Vector3i renderManifest[VIEW_DISTANCE * 4]; + static Vector3f renderManifest[VIEW_DISTANCE * 4]; for (int dist = VIEW_DISTANCE; dist >= 0; dist -= CHUNK_SIZE_X) { // Configuration du radar. float sinus, cosinus; int echantillons; - if (dist > VIEW_DISTANCE * .375f) { + if (dist > VIEW_DISTANCE * .625f) { sinus = .01745240643; // sin(1 degré) cosinus = .99984769515; // cos(1 degré) echantillons = 90; @@ -289,7 +289,7 @@ void World::RenderWorld(int& rendercount, int& badhitcount, Player& player, Tran cosinus = .99965732497; echantillons = 60; } - else if (dist > VIEW_DISTANCE * .625f) { + else if (dist > VIEW_DISTANCE * .375f) { sinus = .0348994967; cosinus = .99939082701; echantillons = 45; @@ -313,7 +313,7 @@ void World::RenderWorld(int& rendercount, int& badhitcount, Player& player, Tran angle.Normalize(); cursor = pos - direct * CHUNK_SIZE_X * 2 + angle * dist; - if (cursor.y >= 128.f || cursor.y >= 0.f) cursor.y = 1; + if (cursor.y >= 128.f || cursor.y >= 0.f) cursor.y = CHUNK_SIZE_Y / 2.f; bool valide = true; @@ -321,24 +321,25 @@ void World::RenderWorld(int& rendercount, int& badhitcount, Player& player, Tran int chx, chy; ChunkAt(cursor)->GetPosition(chx, chy); for (int index = 0; index < rendercount; ++index) // Permet de vérifier seulement contre celles ajoutées dans la frame, et ne pas avoir à refaire l'array à chaque frame. - if (renderManifest[index] == Vector3i(chx, 0, chy)) { + if (renderManifest[index].x == chx && renderManifest[index].z == chy) { valide = false; ++badhitcount; } - if (valide) { - world.ApplyTranslation((chx - m_center[0]) * CHUNK_SIZE_X, 0, (chy - m_center[1]) * CHUNK_SIZE_Z); - world.Use(); - float dist = (pos - cursor).Length(); - float blend = ((float)VIEW_DISTANCE - dist * 2.f + 128.f) / (float)VIEW_DISTANCE; - glBlendColor(0.f, 0.f, 0.f, blend); - ChunkAt(cursor)->Render(); - world.ApplyTranslation(-(chx - m_center[0]) * CHUNK_SIZE_X, 0, -(chy - m_center[1]) * CHUNK_SIZE_Z); - renderManifest[++rendercount] = Vector3i(chx, 0, chy); - } + float ray = (pos - cursor).Length(); + if (valide) renderManifest[rendercount++] = Vector3f(chx, (VIEW_DISTANCE - ray * 2 + 128) / (float)VIEW_DISTANCE, chy); } } } + for (int index = 0; index < rendercount; ++index) { + int chx = (renderManifest[index].x - m_center[0]) * CHUNK_SIZE_X, chy = (renderManifest[index].z - m_center[1]) * CHUNK_SIZE_Z; + + world.ApplyTranslation(chx, 0, chy); + world.Use(); + glBlendColor(0.f, 0.f, 0.f, renderManifest[index].y); + ChunkAt(chx, 1, chy)->Render(); + world.ApplyTranslation(-chx, 0, -chy); + } shader.Disable(); };