diff --git a/SQCSim2021/SQCSim2021.vcxproj b/SQCSim2021/SQCSim2021.vcxproj index b5b30e5..70fb842 100644 --- a/SQCSim2021/SQCSim2021.vcxproj +++ b/SQCSim2021/SQCSim2021.vcxproj @@ -70,27 +70,27 @@ Application true Unicode - ClangCL + v142 Application true Unicode - ClangCL + v142 Application false true Unicode - ClangCL + v142 Application false true Unicode - ClangCL + v142 diff --git a/SQCSim2021/define.h b/SQCSim2021/define.h index 1bd66b8..a8c36c1 100644 --- a/SQCSim2021/define.h +++ b/SQCSim2021/define.h @@ -15,7 +15,18 @@ #define CHUNK_SIZE_X 16 #define CHUNK_SIZE_Y 128 #define CHUNK_SIZE_Z 16 +#define MAX_SELECTION_DISTANCE 5 +#ifdef _DEBUG +#define WORLD_SIZE_X 32 +#define WORLD_SIZE_Y 32 + +#define FRAMES_RENDER_CHUNKS 4 +#define FRAMES_UPDATE_CHUNKS 4 +#define FRAMES_DELETE_CHUNKS 4 + +#define VIEW_DISTANCE 128 +#else #define WORLD_SIZE_X 128 #define WORLD_SIZE_Y 128 @@ -24,7 +35,8 @@ #define FRAMES_DELETE_CHUNKS 2 #define VIEW_DISTANCE 512 -#define MAX_SELECTION_DISTANCE 5 +#endif + typedef uint8_t BlockType; enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_LAST }; diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 431897a..5d71628 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -15,24 +15,26 @@ void Engine::Init() { abort(); } - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glDisable(GL_FRAMEBUFFER_SRGB); + glClearColor(0.f, 0.f, 0.f, 1.f); glEnable(GL_TEXTURE_2D); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluPerspective(45.0f, (float)Width() / (float)Height(), 0.0001f, 1000.0f); + gluPerspective(45.0f, (float)Width() / (float)Height(), 0.1f, VIEW_DISTANCE); glEnable(GL_DEPTH_TEST); + glEnable(GL_STENCIL_TEST); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glShadeModel(GL_SMOOTH); - glEnable(GL_LINE_SMOOTH); + + glEnable(GL_POINT_SMOOTH); glEnable(GL_CULL_FACE); - glDisable(GL_FRAMEBUFFER_SRGB); - glEnable(GL_BLEND); - glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA); + glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); // , GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_SUBTRACT);// , GL_FUNC_ADD); // Objet de skybox avec sa propre texture et son propre shader! - m_skybox.Init(0.00013f); + m_skybox.Init(0.2f); // Objet de musique! //m_audio.ToggleMusicState(); @@ -54,7 +56,7 @@ void Engine::LoadResource() { TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.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 "metal1.png"); + TextureAtlas::TextureIndex texMetalIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "dirt.png"); if (!m_textureAtlas.Generate(512, false)) { std::cout << " Unable to generate texture atlas ..." << std::endl; @@ -89,6 +91,7 @@ void Engine::DrawHud(float elapsedTime) { // Setter le blend function , tout ce qui sera noir sera transparent glColor4f(1.f, 1.f, 1.f, 1.f); glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glBlendEquation(GL_FUNC_ADD); glDisable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glPushMatrix(); @@ -135,7 +138,8 @@ void Engine::DrawHud(float elapsedTime) { glTexCoord2f(0, 1); glVertex2i(0, crossSize); glEnd(); - glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA); + glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); // , GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_SUBTRACT);// , GL_FUNC_ADD); glEnable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glPopMatrix(); @@ -174,7 +178,7 @@ void Engine::Render(float elapsedTime) { Transformation all; Transformation skybox; - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // Transformations initiales glMatrixMode(GL_MODELVIEW); @@ -188,19 +192,23 @@ void Engine::Render(float elapsedTime) { m_player.ApplyTransformation(skybox, false); // Version d'ApplyTransformation qui ne tient compte que de la rotation // (donc l'objet ne bouge pas relativement au joueur, ce qui est pratique pour une skybox!). - if (m_isSkybox) m_skybox.Render(skybox); - if (m_mouseL) m_world.ChangeBlockAtCursor(BTYPE_DIRT, m_player, m_block); else if (m_mouseR) m_world.ChangeBlockAtCursor(BTYPE_AIR, m_player, m_block); - + glStencilFunc(GL_EQUAL, 1, 0x00); + glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); m_world.Update(m_renderCount, m_badHitCount, m_player, all, m_shader01, m_textureAtlas, m_perlin, m_blockinfo); + glStencilFunc(GL_GREATER, 1, 0xFF); + if (m_isSkybox) m_skybox.Render(skybox); + if (m_wireframe) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glDisable(GL_STENCIL_TEST); DrawHud(elapsedTime); + glEnable(GL_STENCIL_TEST); if (m_wireframe) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); diff --git a/SQCSim2021/media/chunks/16325_16384.chunk b/SQCSim2021/media/chunks/16325_16384.chunk new file mode 100644 index 0000000..0137b36 Binary files /dev/null and b/SQCSim2021/media/chunks/16325_16384.chunk differ diff --git a/SQCSim2021/media/chunks/16364_16379.chunk b/SQCSim2021/media/chunks/16364_16379.chunk new file mode 100644 index 0000000..507340d --- /dev/null +++ b/SQCSim2021/media/chunks/16364_16379.chunk @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/SQCSim2021/media/chunks/16369_16385.chunk b/SQCSim2021/media/chunks/16369_16385.chunk new file mode 100644 index 0000000..1a5b1e4 --- /dev/null +++ b/SQCSim2021/media/chunks/16369_16385.chunk @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/SQCSim2021/media/chunks/16371_16383.chunk b/SQCSim2021/media/chunks/16371_16383.chunk new file mode 100644 index 0000000..a197f63 --- /dev/null +++ b/SQCSim2021/media/chunks/16371_16383.chunk @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/SQCSim2021/media/chunks/16378_16383.chunk b/SQCSim2021/media/chunks/16378_16383.chunk new file mode 100644 index 0000000..dd1dcbf Binary files /dev/null and b/SQCSim2021/media/chunks/16378_16383.chunk differ diff --git a/SQCSim2021/media/chunks/16381_16247.chunk b/SQCSim2021/media/chunks/16381_16247.chunk new file mode 100644 index 0000000..5e744b5 Binary files /dev/null and b/SQCSim2021/media/chunks/16381_16247.chunk differ diff --git a/SQCSim2021/media/chunks/16397_16373.chunk b/SQCSim2021/media/chunks/16397_16373.chunk new file mode 100644 index 0000000..f88e52d Binary files /dev/null and b/SQCSim2021/media/chunks/16397_16373.chunk differ diff --git a/SQCSim2021/media/chunks/16398_16392.chunk b/SQCSim2021/media/chunks/16398_16392.chunk new file mode 100644 index 0000000..96064c8 Binary files /dev/null and b/SQCSim2021/media/chunks/16398_16392.chunk differ diff --git a/SQCSim2021/media/chunks/16400_16392.chunk b/SQCSim2021/media/chunks/16400_16392.chunk new file mode 100644 index 0000000..e49266c Binary files /dev/null and b/SQCSim2021/media/chunks/16400_16392.chunk differ diff --git a/SQCSim2021/media/chunks/16505_16212.chunk b/SQCSim2021/media/chunks/16505_16212.chunk new file mode 100644 index 0000000..a00f373 Binary files /dev/null and b/SQCSim2021/media/chunks/16505_16212.chunk differ diff --git a/SQCSim2021/media/textures/metal.png b/SQCSim2021/media/textures/metal.png index 29f7c18..08a1cf5 100644 Binary files a/SQCSim2021/media/textures/metal.png and b/SQCSim2021/media/textures/metal.png differ diff --git a/SQCSim2021/media/textures/metal1.png b/SQCSim2021/media/textures/metal1.png index 705ce35..1062711 100644 Binary files a/SQCSim2021/media/textures/metal1.png and b/SQCSim2021/media/textures/metal1.png differ diff --git a/SQCSim2021/media/textures/metal2.png b/SQCSim2021/media/textures/metal2.png index cdd0ff3..6791d40 100644 Binary files a/SQCSim2021/media/textures/metal2.png and b/SQCSim2021/media/textures/metal2.png differ diff --git a/SQCSim2021/media/textures/metal3.png b/SQCSim2021/media/textures/metal3.png index d4f436c..9a72a66 100644 Binary files a/SQCSim2021/media/textures/metal3.png and b/SQCSim2021/media/textures/metal3.png differ diff --git a/SQCSim2021/media/textures/metal4.png b/SQCSim2021/media/textures/metal4.png index c341243..6e08a79 100644 Binary files a/SQCSim2021/media/textures/metal4.png and b/SQCSim2021/media/textures/metal4.png differ diff --git a/SQCSim2021/skybox.cpp b/SQCSim2021/skybox.cpp index 2bd16b4..947535c 100644 --- a/SQCSim2021/skybox.cpp +++ b/SQCSim2021/skybox.cpp @@ -44,12 +44,14 @@ void Skybox::Init(float size){ void Skybox::Render(Transformation tran) const { glDisable(GL_DEPTH_TEST); + glDisable(GL_BLEND); tran.Use(); m_texture.Bind(); m_shader.Use(); m_vertexBuffer.Render(); m_shader.Disable(); glEnable(GL_DEPTH_TEST); + glEnable(GL_BLEND); } Texture& Skybox::GetTexture() { return m_texture; } diff --git a/SQCSim2021/world.cpp b/SQCSim2021/world.cpp index eadf6c8..23c798e 100644 --- a/SQCSim2021/world.cpp +++ b/SQCSim2021/world.cpp @@ -99,7 +99,6 @@ void World::CleanUpWorld(int& deleteframes, bool clear = false) { m_tbDeleted.pop_back(); deleteframes = FRAMES_DELETE_CHUNKS; } - std::cout << "Chunk Write Buffer: " << m_tbDeleted.size() << std::endl; } void World::GetScope(int& x, int& y) { @@ -124,7 +123,7 @@ bool World::GenerateChunk(int chx, int chy, Perlin& perlin) { for (int index = 0; index < m_tbDeleted.size(); ++index) { // Vérifie l'existence d'un chunk dans le buffer de suppression avec sa position. int x, y; - if (&m_tbDeleted.at(index)) { + if (m_tbDeleted.at(index)) { m_tbDeleted.at(index)->GetPosition(x, y); if (chx / CHUNK_SIZE_X + m_center[0] == x && chy / CHUNK_SIZE_Z + m_center[1] == y) { @@ -143,7 +142,7 @@ bool World::GenerateChunk(int chx, int chy, Perlin& perlin) { 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])); Chunk* chunk = GetChunks().Get(chx / CHUNK_SIZE_X, chy / CHUNK_SIZE_Z); - for (int x = 0; x < CHUNK_SIZE_X; ++x) + for (int x = 0; x < CHUNK_SIZE_X; ++x) // Montagnes for (int z = 0; z < CHUNK_SIZE_Z; ++z) { float xnoiz, ynoiz; xnoiz = (double)(x + (chx / CHUNK_SIZE_X + m_center[0]) * CHUNK_SIZE_X) / (double)INT16_MAX; @@ -153,26 +152,44 @@ bool World::GenerateChunk(int chx, int chy, Perlin& perlin) { chunk->SetBlock(x, y, z, BTYPE_METAL, this); } - for (int x = 0; x < CHUNK_SIZE_X; ++x) + for (int x = 0; x < CHUNK_SIZE_X; ++x) // Collines for (int z = 0; z < CHUNK_SIZE_Z; ++z) { 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) * 5.f + 16.f; + float height = perlin.Get(xnoiz, ynoiz) * 5.f + 24.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); } } - for (int x = 0; x < CHUNK_SIZE_X; ++x) + for (int x = 0; x < CHUNK_SIZE_X; ++x) // "Lacs" for (int z = 0; z < CHUNK_SIZE_Z; ++z) { - for (int y = 0; y < 15; ++y) { + for (int y = 0; y < 12; ++y) { if (chunk->GetBlock(x, y, z) == BTYPE_AIR) chunk->SetBlock(x, y, z, BTYPE_ICE, this); } } + for (int x = 0; x < CHUNK_SIZE_X; ++x) // "Arbres" + for (int z = 0; z < CHUNK_SIZE_Z; ++z) { + float xnoiz, ynoiz; + xnoiz = (double)(z * CHUNK_SIZE_Y + (chx / CHUNK_SIZE_X + m_center[0]) * CHUNK_SIZE_X) / (double)INT16_MAX; + ynoiz = (double)(x * CHUNK_SIZE_Y + (chy / CHUNK_SIZE_Z + m_center[1]) * CHUNK_SIZE_Z) / (double)INT16_MAX; + bool tree = (int)(abs(perlin.Get(xnoiz, ynoiz)) * 17933.f) % CHUNK_SIZE_Y > 126 ? true: false; + + for (int y = 0; y < CHUNK_SIZE_Y - 10; ++y) + if (chunk->GetBlock(x, y, z) == BTYPE_AIR) + if (chunk->GetBlock(x, y - 1, z) == BTYPE_GRASS) + if (tree) { + for (int i = 0; i < (int)(abs(perlin.Get(xnoiz, ynoiz))) % 3 + 1; ++i) + chunk->SetBlock(x, y + i, z, BTYPE_DIRT, this); + break; + } + + } + } else { input.seekg(0, std::ios_base::end); @@ -274,31 +291,28 @@ void World::RenderWorld(int& rendercount, int& badhitcount, Player& player, Tran static Vector3f renderManifest[VIEW_DISTANCE * 4]; - for (int dist = VIEW_DISTANCE; dist >= 0; dist -= CHUNK_SIZE_X) { + //for (int dist = VIEW_DISTANCE; dist >= 0; dist -= CHUNK_SIZE_X) { + for (int dist = 0; dist <= VIEW_DISTANCE; dist += CHUNK_SIZE_X) { // Configuration du radar. float sinus, cosinus; int echantillons; + if (dist > VIEW_DISTANCE * .625f) { sinus = .01745240643; // sin(1 degré) cosinus = .99984769515; // cos(1 degré) echantillons = 90; } - else if (dist > VIEW_DISTANCE * .5f) { + else if (dist > VIEW_DISTANCE * .325f) { sinus = .0261769483; cosinus = .99965732497; echantillons = 60; } - else if (dist > VIEW_DISTANCE * .375f) { + else { sinus = .0348994967; cosinus = .99939082701; echantillons = 45; } - else { - sinus = .05233595624; - cosinus = .99862953475; - echantillons = 30; - } angle.x = direct.z + direct.x; angle.z = direct.z - direct.x; @@ -326,8 +340,7 @@ void World::RenderWorld(int& rendercount, int& badhitcount, Player& player, Tran ++badhitcount; } - float ray = (pos - cursor).Length(); - if (valide) renderManifest[rendercount++] = Vector3f(chx, (VIEW_DISTANCE - ray * 2 + 128) / (float)VIEW_DISTANCE, chy); + if (valide) renderManifest[rendercount++] = Vector3f(chx, (VIEW_DISTANCE - (pos - cursor).Length() * 2.f + 128) / (float)VIEW_DISTANCE, chy); } } } @@ -336,7 +349,7 @@ void World::RenderWorld(int& rendercount, int& badhitcount, Player& player, Tran world.ApplyTranslation(chx, 0, chy); world.Use(); - glBlendColor(0.f, 0.f, 0.f, renderManifest[index].y); + glBlendColor(renderManifest[index].y, renderManifest[index].y, renderManifest[index].y, 1.f); ChunkAt(chx, 1, chy)->Render(); world.ApplyTranslation(-chx, 0, -chy); }