From e3b59e37ebc44a3a1f2e05be2ec77a58e3ef7848 Mon Sep 17 00:00:00 2001 From: Louis-CharlesG Date: Mon, 27 Nov 2023 16:47:10 -0500 Subject: [PATCH] Les arbres avec le seed. --- SQCSim-common/chunk.cpp | 109 ++++++++++++++++++++++------------------ SQCSim-common/chunk.h | 2 +- 2 files changed, 60 insertions(+), 51 deletions(-) diff --git a/SQCSim-common/chunk.cpp b/SQCSim-common/chunk.cpp index 7a5485e..63fe17e 100644 --- a/SQCSim-common/chunk.cpp +++ b/SQCSim-common/chunk.cpp @@ -33,51 +33,45 @@ Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y if (iy < 20) { //std::cout << "" << ynoiz << std::endl; - SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr); // Blocs de montagnes + SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr); } else if (iy == 20 || iy == 21) { - // Utilisez la partie décimale de la valeur de ynoiz pour déterminer le type de bloc double fractionalPart = ynoiz - static_cast(ynoiz); - // Variation pour iy égal à 24 if (iy == 20) { if (fractionalPart < 0.3) { - SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr); // Blocs de montagnes - Grass + SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr); } else { - SetBlock(ix, iy, iz, BTYPE_METAL, nullptr); // Blocs de montagnes - Metal + SetBlock(ix, iy, iz, BTYPE_METAL, nullptr); } } - // Variation pour iy égal à 25 else if (iy == 21) { if (fractionalPart < 0.6) { - SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr); // Blocs de montagnes - Grass + SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr); } else { - SetBlock(ix, iy, iz, BTYPE_METAL, nullptr); // Blocs de montagnes - Metal + SetBlock(ix, iy, iz, BTYPE_METAL, nullptr); } } } else { - SetBlock(ix, iy, iz, BTYPE_METAL, nullptr); // Grass des montagnes + SetBlock(ix, iy, iz, BTYPE_METAL, nullptr); } } } #pragma endregion #pragma region Lacs - - - - for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Lacs" + for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { for (int iy = 0; iy < 13; ++iy) { if (iy < 5 && GetBlock(ix, iy, iz) == BTYPE_AIR) { - SetBlock(ix, iy, iz, BTYPE_ICE, nullptr); // Partie inférieure du lac + SetBlock(ix, iy, iz, BTYPE_ICE, nullptr); } else if (iy >= 5 && GetBlock(ix, iy, iz) == BTYPE_AIR) { - SetBlock(ix, iy, iz, BTYPE_ICE, nullptr); // Partie supérieure du lac (simulée avec de l'eau) + SetBlock(ix, iy, iz, BTYPE_ICE, nullptr); } } } @@ -86,16 +80,19 @@ Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y #pragma region Arbre + double valeurRnd = 0; + int treeheight = 10; + + int lastTreeX = -1; + int lastTreeZ = -1; + + int minDistanceBetweenTrees = 10; // Définir la distance minimale entre les arbres + for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) { for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { - - - - // Vérifiez d'abord que le bloc n'est pas un lac if (GetBlock(ix, 0, iz) != BTYPE_ICE) { - // Recalculez la hauteur en fonction de la topographie du terrain - float xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 5096.; - float ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 5096.; + float xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 4796.; + float ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 4796.; double height = 0; for (int i = 0; i < 39; ++i) { height += simplex.eval(xnoiz, ynoiz); @@ -107,40 +104,48 @@ Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y height /= (CHUNK_SIZE_Y / 1.9); height += 15.; + if (GetBlock(ix, (int)height, iz) == BTYPE_GRASS || (GetBlock(ix, (int)height, iz) == BTYPE_METAL)) { + valeurRnd = simplex.eval(xnoiz, ynoiz); - double minInput = 3068.84; - double maxInput = 3074.7; - double minOutput = 0.0; - double maxOutput = 100.0; - double valeurRnd = ((ynoiz - minInput) * (maxOutput - minOutput)) / (maxInput - minInput); + int distanceThreshold = 20; - //std::cout << valeurRnd << std::endl; + // Vérifie si l'emplacement n'est pas à l'intérieur des lacs + bool isInsideLake = false; + for (int iy = 0; iy < 13; ++iy) { + if (GetBlock(ix, iy, iz) == BTYPE_ICE) { + isInsideLake = true; + break; + } + } + if (!isInsideLake && ((valeurRnd > -0.4 && valeurRnd < -0.38) || (valeurRnd > -0.35 && valeurRnd < -0.31) + || (valeurRnd > 0.3 && valeurRnd < 0.32) || (valeurRnd > 0.37 && valeurRnd < 0.39)) + ) { + if (lastTreeX == -1 || abs(ix - lastTreeX) > minDistanceBetweenTrees || abs(iz - lastTreeZ) > minDistanceBetweenTrees) { + if (valeurRnd < 0.1) + treeheight = 10; + else { + treeheight = valeurRnd * 20; + if (treeheight < 5) + treeheight = 5; + } - // Ajout des arbres uniquement sur des blocs de type BTYPE_GRASS et avec une probabilité réduite - if (GetBlock(ix, 0, iz) != BTYPE_ICE && GetBlock(ix, (int)height, iz) == BTYPE_GRASS) { - // Vérifiez si vous souhaitez placer un arbre en fonction de votre logique de génération - if (valeurRnd < 20) { - // Calculez la position et la hauteur de l'arbre - - // Exemple : Place un arbre à la position calculée avec une hauteur donnée - // - //PlaceTree(ix, height, iz, 10, 5 <= 5); + PlaceTree(ix, height, iz, treeheight); + lastTreeX = ix; + lastTreeZ = iz; + } } } } } } - - - - #pragma endregion + //else { // input.seekg(0, std::ios_base::end); // int size = input.tellg(); @@ -177,19 +182,18 @@ Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y } -void Chunk::PlaceTree(int x, int y, int z, int height, int valeurRnd) -{ - // Place le tronc - for (int iy = 0; iy < height; ++iy) { +void Chunk::PlaceTree(int x, int y, int z, int height) { + + for (int iy = 0; iy < height + 1; ++iy) { SetBlock(x, y + iy, z, BTYPE_LAST, nullptr); } - // Place les feuilles autour du tronc - int foliageHeight = height - 2; + int foliageHeight = height / 2; + for (int dy = 1; dy < foliageHeight; ++dy) { - for (int dx = -2; dx <= 2; ++dx) { - for (int dz = -2; dz <= 2; ++dz) { - if (valeurRnd < 50) { + for (int dx = -3; dx <= 3; ++dx) { + for (int dz = -3; dz <= 3; ++dz) { + if (dx * dx + dy * dy + dz * dz < 10) { SetBlock(x + dx, y + height + dy, z + dz, BTYPE_DIRT, nullptr); } } @@ -198,6 +202,9 @@ void Chunk::PlaceTree(int x, int y, int z, int height, int valeurRnd) } + + + Chunk::~Chunk() { /*if (m_isModified) { char data[CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z]; @@ -254,6 +261,8 @@ void Chunk::GetPosition(unsigned int& x, unsigned int& y) const { x = m_posX; y + + bool Chunk::IsDirty() const { return m_isDirty; } void Chunk::MakeDirty() { m_isDirty = true; } diff --git a/SQCSim-common/chunk.h b/SQCSim-common/chunk.h index 61570ad..6b80e75 100644 --- a/SQCSim-common/chunk.h +++ b/SQCSim-common/chunk.h @@ -27,7 +27,7 @@ class Chunk { BlockType GetBlock(int x, int y, int z); void CheckNeighbors(unsigned int x, unsigned int z, World* world); void GetPosition(unsigned int& x, unsigned int& y) const; - void PlaceTree(int x, int y, int z, int height,int valeurRnd); + void PlaceTree(int x, int y, int z, int height); bool IsDirty() const; void MakeDirty(); void MakeClean();