diff --git a/SQCSim2021/chunk.cpp b/SQCSim2021/chunk.cpp index 2a98568..776fc74 100644 --- a/SQCSim2021/chunk.cpp +++ b/SQCSim2021/chunk.cpp @@ -7,24 +7,33 @@ Chunk::Chunk(unsigned int x, unsigned int y) : m_posX(x), m_posY(y) { std::ifstream input(pos.str(), std::fstream::binary); if (input.fail()) { - OpenSimplexNoise::Noise simplex = OpenSimplexNoise::Noise(PERLIN_SEED); + OpenSimplexNoise::Noise simplex = OpenSimplexNoise::Noise(SEED); m_blocks.Reset(BTYPE_AIR); for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Montagnes for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { float xnoiz, ynoiz; - xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 256.; - ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 256.; - float height = (simplex.eval(xnoiz, ynoiz)) * 60.f + 5.f; + xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 1024.; + ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 1024.; + double height = 0; + for (int x = 0; x < 39; ++x) { + height += simplex.eval(xnoiz, ynoiz); + height *= .79; + xnoiz *= 1.139; + ynoiz *= 1.139; + } + height = height * 2000. * simplex.eval((double)(ix + x * CHUNK_SIZE_X) / 512., (double)(iz + y * CHUNK_SIZE_Z) / 512.); + height /= (CHUNK_SIZE_Y / 1.9); + height += 15.; for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy) SetBlock(ix, iy, iz, BTYPE_METAL, nullptr); } for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Collines for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { float xnoiz, ynoiz; - xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 64.; - ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 64.; - float height = simplex.eval(xnoiz, ynoiz) * 5.f + 24.f; + xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 512.; + ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 512.; + float height = simplex.eval(xnoiz, ynoiz) * 50.f;// +1.f; for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy) { if (GetBlock(ix, iy, iz) == BTYPE_AIR) SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr); @@ -32,26 +41,26 @@ Chunk::Chunk(unsigned int x, unsigned int y) : m_posX(x), m_posY(y) { } for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Lacs" for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { - for (int iy = 0; iy < 16; ++iy) { + for (int iy = 0; iy < 13; ++iy) { if (GetBlock(ix, iy, iz) == BTYPE_AIR) SetBlock(ix, iy, iz, BTYPE_ICE, nullptr); } } - for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Arbres" - for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { - float xnoiz, ynoiz; - xnoiz = (double)(iz * CHUNK_SIZE_Y + x * CHUNK_SIZE_X) / 256.; - ynoiz = (double)(ix * CHUNK_SIZE_Y + y * CHUNK_SIZE_Z) / 256.; - bool tree = (int)(abs(simplex.eval(xnoiz, ynoiz)) * 17933.f) % CHUNK_SIZE_Y > 126 ? true : false; - for (int iy = 0; iy < CHUNK_SIZE_Y - 10; ++iy) - if (GetBlock(ix, iy, iz) == BTYPE_AIR) - if (GetBlock(ix, iy - 1, iz) == BTYPE_GRASS) - if (tree) { - for (int i = 0; i < (int)(abs(simplex.eval(xnoiz, ynoiz) * 65)) % 42 + 1; ++i) - SetBlock(ix, iy + i, iz, BTYPE_DIRT, nullptr); - break; - } - } + //for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Arbres" + // for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { + // float xnoiz, ynoiz; + // xnoiz = (double)(iz * CHUNK_SIZE_Y + x * CHUNK_SIZE_X) / 256.; + // ynoiz = (double)(ix * CHUNK_SIZE_Y + y * CHUNK_SIZE_Z) / 256.; + // bool tree = (int)(abs(simplex.eval(xnoiz, ynoiz)) * 17933.f) % CHUNK_SIZE_Y > 126 ? true : false; + // for (int iy = 0; iy < CHUNK_SIZE_Y - 10; ++iy) + // if (GetBlock(ix, iy, iz) == BTYPE_AIR) + // if (GetBlock(ix, iy - 1, iz) == BTYPE_GRASS) + // if (tree) { + // for (int i = 0; i < (int)(abs(simplex.eval(xnoiz, ynoiz) * 4)) % 42 + 1; ++i) + // SetBlock(ix, iy + i, iz, BTYPE_DIRT, nullptr); + // break; + // } + // } } else { input.seekg(0, std::ios_base::end); diff --git a/SQCSim2021/chunk.h b/SQCSim2021/chunk.h index f4d58b1..d4fdcb5 100644 --- a/SQCSim2021/chunk.h +++ b/SQCSim2021/chunk.h @@ -5,7 +5,6 @@ #include "array2d.h" #include "vertexbuffer.h" #include "blockinfo.h" -#include "perlin.h" #include "opensimplex.h" class World; diff --git a/SQCSim2021/define.h b/SQCSim2021/define.h index f3f0d93..439307f 100644 --- a/SQCSim2021/define.h +++ b/SQCSim2021/define.h @@ -16,7 +16,7 @@ #define CHUNK_SIZE_Y 128 #define CHUNK_SIZE_Z 16 #define MAX_SELECTION_DISTANCE 5 -#define PERLIN_SEED 12345 +#define SEED 12345 #ifdef _DEBUG #define WORLD_SIZE_X 64 @@ -44,10 +44,10 @@ #define FRAMES_DELETE_CHUNKS 1 #define THREADS_GENERATE_CHUNKS 12 -#define THREADS_UPDATE_CHUNKS 8 -#define THREADS_DELETE_CHUNKS 10 +#define THREADS_UPDATE_CHUNKS 5 +#define THREADS_DELETE_CHUNKS 2 -#define VIEW_DISTANCE 512 +#define VIEW_DISTANCE 1024 #define TEXTURE_SIZE 512 #define MAX_BULLETS 512 #endif diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 204d89e..89ca926 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -185,19 +185,18 @@ void Engine::PrintText(unsigned int x, unsigned int y, const std::string& t) { int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; } void Engine::Render(float elapsedTime) { - static float gameTime = elapsedTime; + //static float gameTime = elapsedTime; static float pollTime = 0; static float bulletTime = 0; static BlockType bloc = 1; if (elapsedTime > 0.1f) return; - gameTime += elapsedTime; + //gameTime += elapsedTime; pollTime += elapsedTime; Transformation all; Transformation skybox; - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // Transformations initiales @@ -208,7 +207,7 @@ void Engine::Render(float elapsedTime) { if (bulletTime < 0.f) bulletTime = 0.f; if (pollTime >= .005f) { - m_player.ApplyPhysics(m_player.GetInput(m_keyW, m_keyS, m_keyA, m_keyD, m_keySpace, (bloc == BTYPE_LAST && bulletTime <= 0.f && m_mouseL), elapsedTime), m_world, elapsedTime, &m_audio); + m_player.ApplyPhysics(m_player.GetInput(m_keyW, m_keyS, m_keyA, m_keyD, m_keySpace, (bloc == BTYPE_LAST && bulletTime <= 0.f && m_mouseL), elapsedTime), &m_world, elapsedTime, &m_audio); m_audio.Update3DAudio(m_player.GetPOV(), m_player.GetDirection(), m_player.GetVelocity()); // Ajustement du positionnement 3D avec les coordonnées du joueur et // son vecteur de vélocité (pour l'effet Doppler) pollTime = 0; diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index f00924e..86216b2 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -13,7 +13,6 @@ #include "blockinfo.h" #include "array2d.h" #include "world.h" -#include "perlin.h" #include "bullet.h" class Engine : public OpenglContext { @@ -47,7 +46,6 @@ private: TextureAtlas m_textureAtlas = TextureAtlas(BTYPE_LAST); World m_world = World(); - Perlin m_perlin = Perlin(8,45.f,7.f,12345); Texture m_textureSkybox; Texture m_textureFont; diff --git a/SQCSim2021/main.cpp b/SQCSim2021/main.cpp index 595a5f9..ea36a99 100644 --- a/SQCSim2021/main.cpp +++ b/SQCSim2021/main.cpp @@ -4,6 +4,6 @@ int main() { Engine engine; - engine.SetMaxFps(60); + engine.SetMaxFps(10000); engine.Start("Syndicat Quebecois de la Construction Simulator 2021", 1920, 1080, true); } diff --git a/SQCSim2021/player.cpp b/SQCSim2021/player.cpp index 37717a4..11fba10 100644 --- a/SQCSim2021/player.cpp +++ b/SQCSim2021/player.cpp @@ -64,25 +64,25 @@ Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jum return delta; } -void Player::ApplyPhysics(Vector3f input, World world, float elapsedTime, Audio* audio) { +void Player::ApplyPhysics(Vector3f input, World* world, float elapsedTime, Audio* audio) { static irrklang::ISound* step; // Pour les sons de pas. static float timing = 0.f; /* Gestion de collisions */ BlockType bt1, bt2, bt3; - bt1 = world.BlockAt(GetPosition().x, GetPosition().y + input.y, GetPosition().z); - bt2 = world.BlockAt(GetPosition().x, GetPosition().y + input.y - 0.9f, GetPosition().z); - bt3 = world.BlockAt(GetPosition().x, GetPosition().y + input.y - 1.7f, GetPosition().z); + bt1 = world->BlockAt(GetPosition().x, GetPosition().y + input.y, GetPosition().z); + bt2 = world->BlockAt(GetPosition().x, GetPosition().y + input.y - 0.9f, GetPosition().z); + bt3 = world->BlockAt(GetPosition().x, GetPosition().y + input.y - 1.7f, GetPosition().z); if ((bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) && m_position.y < 129.7f) { - bt1 = world.BlockAt(GetPosition().x, GetPosition().y + .3f, GetPosition().z); + bt1 = world->BlockAt(GetPosition().x, GetPosition().y + .3f, GetPosition().z); if (bt1 == BTYPE_AIR) m_position.y = (int)m_position.y + .7f; m_velocity.y = input.y = 0; m_airborne = false; } else { if (abs(m_velocity.y) < 1.1f) m_velocity.y += input.y - 1.1f * elapsedTime; - bt3 = world.BlockAt(GetPosition().x, GetPosition().y + m_velocity.y - 1.7f, GetPosition().z); - bt1 = world.BlockAt(GetPosition().x, GetPosition().y + .3f, GetPosition().z); + bt3 = world->BlockAt(GetPosition().x, GetPosition().y + m_velocity.y - 1.7f, GetPosition().z); + bt1 = world->BlockAt(GetPosition().x, GetPosition().y + .3f, GetPosition().z); if (bt3 != BTYPE_AIR) { m_velocity.y = 0; if (timing == 0.f) { @@ -100,17 +100,17 @@ void Player::ApplyPhysics(Vector3f input, World world, float elapsedTime, Audio* if (timing > 0.f) timing -= elapsedTime; if (timing < 0.f) timing = 0.f; - bt1 = world.BlockAt(GetPosition().x + input.x, GetPosition().y, GetPosition().z); - bt2 = world.BlockAt(GetPosition().x + input.x, GetPosition().y - 0.9f, GetPosition().z); - bt3 = world.BlockAt(GetPosition().x + input.x, GetPosition().y - 1.7f, GetPosition().z); + bt1 = world->BlockAt(GetPosition().x + input.x, GetPosition().y, GetPosition().z); + bt2 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 0.9f, GetPosition().z); + bt3 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 1.7f, GetPosition().z); if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) { input.x = m_velocity.x = 0; m_velocity.z *= .5f; } - bt1 = world.BlockAt(GetPosition().x, GetPosition().y, GetPosition().z + input.z); - bt2 = world.BlockAt(GetPosition().x, GetPosition().y - 0.9f, GetPosition().z + input.z); - bt3 = world.BlockAt(GetPosition().x, GetPosition().y - 1.7f, GetPosition().z + input.z); + bt1 = world->BlockAt(GetPosition().x, GetPosition().y, GetPosition().z + input.z); + bt2 = world->BlockAt(GetPosition().x, GetPosition().y - 0.9f, GetPosition().z + input.z); + bt3 = world->BlockAt(GetPosition().x, GetPosition().y - 1.7f, GetPosition().z + input.z); if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) { input.z = m_velocity.z = 0; m_velocity.x *= .5f; diff --git a/SQCSim2021/player.h b/SQCSim2021/player.h index efee2d7..9ffd0b8 100644 --- a/SQCSim2021/player.h +++ b/SQCSim2021/player.h @@ -13,7 +13,7 @@ public: void TurnLeftRight(float value); void TurnTopBottom(float value); Vector3f GetInput(bool front, bool back, bool left, bool right, bool jump, bool dash, float elapsedTime); - void ApplyPhysics(Vector3f input, World world, float elapsedTime, Audio* audio); + void ApplyPhysics(Vector3f input, World* world, float elapsedTime, Audio* audio); void ApplyTransformation(Transformation& transformation, bool rel = true) const; Vector3f GetPosition() const; diff --git a/SQCSim2021/world.cpp b/SQCSim2021/world.cpp index 3042df7..86f3e87 100644 --- a/SQCSim2021/world.cpp +++ b/SQCSim2021/world.cpp @@ -304,9 +304,9 @@ void World::RenderWorld(int& rendercount, Player& player, Transformation& world, void World::UpdateWorld(Player& player, BlockInfo* blockinfo[BTYPE_LAST]) { int cx = player.GetPosition().x; int cy = player.GetPosition().z; - static int frameGenerate = 0; - static int frameUpdate = 0; - static int frameDelete = 0; + static int frameGenerate = 1; + static int frameUpdate = 2; + static int frameDelete = 3; int side = 0; int threads = 0; std::future genThList[THREADS_GENERATE_CHUNKS]; @@ -316,7 +316,7 @@ void World::UpdateWorld(Player& player, BlockInfo* blockinfo[BTYPE_LAST]) { if (frameGenerate > 0) --frameGenerate; if (frameUpdate > 0) --frameUpdate; if (frameDelete > 0) --frameDelete; - + if (!frameGenerate) while (side * CHUNK_SIZE_X <= VIEW_DISTANCE * 2 + CHUNK_SIZE_X) { int tx = -side, ty = -side; diff --git a/SQCSim2021/x64/Debug/SQCSim2021.tlog/clang-cl.command.1.tlog b/SQCSim2021/x64/Debug/SQCSim2021.tlog/clang-cl.command.1.tlog index ea157cc..71a1162 100644 Binary files a/SQCSim2021/x64/Debug/SQCSim2021.tlog/clang-cl.command.1.tlog and b/SQCSim2021/x64/Debug/SQCSim2021.tlog/clang-cl.command.1.tlog differ diff --git a/SQCSim2021/x64/Debug/SQCSim2021.tlog/clang-cl.read.1.tlog b/SQCSim2021/x64/Debug/SQCSim2021.tlog/clang-cl.read.1.tlog index b858ec9..b3049c5 100644 Binary files a/SQCSim2021/x64/Debug/SQCSim2021.tlog/clang-cl.read.1.tlog and b/SQCSim2021/x64/Debug/SQCSim2021.tlog/clang-cl.read.1.tlog differ diff --git a/SQCSim2021/x64/Debug/SQCSim2021.tlog/clang-cl.write.1.tlog b/SQCSim2021/x64/Debug/SQCSim2021.tlog/clang-cl.write.1.tlog index 4c9e8f8..acf4414 100644 Binary files a/SQCSim2021/x64/Debug/SQCSim2021.tlog/clang-cl.write.1.tlog and b/SQCSim2021/x64/Debug/SQCSim2021.tlog/clang-cl.write.1.tlog differ diff --git a/SQCSim2021/x64/Debug/SQCSim2021.tlog/lld-link.command.1.tlog b/SQCSim2021/x64/Debug/SQCSim2021.tlog/lld-link.command.1.tlog index a565f67..a909eb8 100644 Binary files a/SQCSim2021/x64/Debug/SQCSim2021.tlog/lld-link.command.1.tlog and b/SQCSim2021/x64/Debug/SQCSim2021.tlog/lld-link.command.1.tlog differ diff --git a/SQCSim2021/x64/Debug/SQCSim2021.tlog/lld-link.read.2.tlog b/SQCSim2021/x64/Debug/SQCSim2021.tlog/lld-link.read.2.tlog index 77dbfff..e606189 100644 Binary files a/SQCSim2021/x64/Debug/SQCSim2021.tlog/lld-link.read.2.tlog and b/SQCSim2021/x64/Debug/SQCSim2021.tlog/lld-link.read.2.tlog differ diff --git a/SQCSim2021/x64/Debug/SQCSim2021.tlog/lld-link.write.1.tlog b/SQCSim2021/x64/Debug/SQCSim2021.tlog/lld-link.write.1.tlog index aa288a9..6506ab0 100644 Binary files a/SQCSim2021/x64/Debug/SQCSim2021.tlog/lld-link.write.1.tlog and b/SQCSim2021/x64/Debug/SQCSim2021.tlog/lld-link.write.1.tlog differ diff --git a/SQCSim2021/x64/Release/SQCSim2021.tlog/clang-cl.command.1.tlog b/SQCSim2021/x64/Release/SQCSim2021.tlog/clang-cl.command.1.tlog index 2eb0f68..2dc9e7f 100644 Binary files a/SQCSim2021/x64/Release/SQCSim2021.tlog/clang-cl.command.1.tlog and b/SQCSim2021/x64/Release/SQCSim2021.tlog/clang-cl.command.1.tlog differ diff --git a/SQCSim2021/x64/Release/SQCSim2021.tlog/clang-cl.read.1.tlog b/SQCSim2021/x64/Release/SQCSim2021.tlog/clang-cl.read.1.tlog index 4b0edd2..81db7d5 100644 Binary files a/SQCSim2021/x64/Release/SQCSim2021.tlog/clang-cl.read.1.tlog and b/SQCSim2021/x64/Release/SQCSim2021.tlog/clang-cl.read.1.tlog differ diff --git a/SQCSim2021/x64/Release/SQCSim2021.tlog/lld-link.command.1.tlog b/SQCSim2021/x64/Release/SQCSim2021.tlog/lld-link.command.1.tlog index 69c884a..500ab58 100644 Binary files a/SQCSim2021/x64/Release/SQCSim2021.tlog/lld-link.command.1.tlog and b/SQCSim2021/x64/Release/SQCSim2021.tlog/lld-link.command.1.tlog differ diff --git a/SQCSim2021/x64/Release/SQCSim2021.tlog/lld-link.write.1.tlog b/SQCSim2021/x64/Release/SQCSim2021.tlog/lld-link.write.1.tlog index d2744c2..8db9cac 100644 Binary files a/SQCSim2021/x64/Release/SQCSim2021.tlog/lld-link.write.1.tlog and b/SQCSim2021/x64/Release/SQCSim2021.tlog/lld-link.write.1.tlog differ diff --git a/x64/Debug/SQCSim2021.exe b/x64/Debug/SQCSim2021.exe index 658d5dd..d77787a 100644 Binary files a/x64/Debug/SQCSim2021.exe and b/x64/Debug/SQCSim2021.exe differ