From 77f4297c6ee4daca51220f60b626658a22a22ea2 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 27 Jul 2014 00:03:26 +0200 Subject: RoughRavines: Initial generator implementation. This provides the basic shape of the ravines, with the basic settings based on GridStructGen, and good default values. --- src/Generating/CMakeLists.txt | 2 + src/Generating/ComposableGenerator.cpp | 14 ++- src/Generating/RoughRavines.cpp | 214 +++++++++++++++++++++++++++++++++ src/Generating/RoughRavines.h | 37 ++++++ 4 files changed, 264 insertions(+), 3 deletions(-) create mode 100644 src/Generating/RoughRavines.cpp create mode 100644 src/Generating/RoughRavines.h (limited to 'src/Generating') diff --git a/src/Generating/CMakeLists.txt b/src/Generating/CMakeLists.txt index 9063abd97..58df9d421 100644 --- a/src/Generating/CMakeLists.txt +++ b/src/Generating/CMakeLists.txt @@ -25,6 +25,7 @@ SET (SRCS PrefabPiecePool.cpp RainbowRoadsGen.cpp Ravines.cpp + RoughRavines.cpp StructGen.cpp TestRailsGen.cpp Trees.cpp @@ -52,6 +53,7 @@ SET (HDRS PrefabPiecePool.h RainbowRoadsGen.h Ravines.h + RoughRavines.h StructGen.h TestRailsGen.h Trees.h diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp index ab6accee7..757f6ddb7 100644 --- a/src/Generating/ComposableGenerator.cpp +++ b/src/Generating/ComposableGenerator.cpp @@ -26,6 +26,7 @@ #include "POCPieceGenerator.h" #include "RainbowRoadsGen.h" #include "Ravines.h" +#include "RoughRavines.h" #include "TestRailsGen.h" #include "UnderwaterBaseGen.h" #include "VillageGen.h" @@ -397,16 +398,23 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) } else if (NoCaseCompare(*itr, "RainbowRoads") == 0) { - int GridSize = a_IniFile.GetValueSetI("Generator", "RainbowRoadsGridSize", 512); + int GridSize = a_IniFile.GetValueSetI("Generator", "RainbowRoadsGridSize", 512); int MaxOffset = a_IniFile.GetValueSetI("Generator", "RainbowRoadsMaxOffset", 128); - int MaxDepth = a_IniFile.GetValueSetI("Generator", "RainbowRoadsMaxDepth", 30); - int MaxSize = a_IniFile.GetValueSetI("Generator", "RainbowRoadsMaxSize", 260); + int MaxDepth = a_IniFile.GetValueSetI("Generator", "RainbowRoadsMaxDepth", 30); + int MaxSize = a_IniFile.GetValueSetI("Generator", "RainbowRoadsMaxSize", 260); m_FinishGens.push_back(new cRainbowRoadsGen(Seed, GridSize, MaxOffset, MaxDepth, MaxSize)); } else if (NoCaseCompare(*itr, "Ravines") == 0) { m_FinishGens.push_back(new cStructGenRavines(Seed, 128)); } + else if (NoCaseCompare(*itr, "RoughRavines") == 0) + { + int GridSize = a_IniFile.GetValueSetI("Generator", "RoughRavinesGridSize", 256); + int MaxOffset = a_IniFile.GetValueSetI("Generator", "RoughRavinesMaxOffset", 128); + int MaxSize = a_IniFile.GetValueSetI("Generator", "RoughRavinesMaxSize", 64); + m_FinishGens.push_back(new cRoughRavines(Seed, MaxSize, GridSize, MaxOffset)); + } else if (NoCaseCompare(*itr, "Snow") == 0) { m_FinishGens.push_back(new cFinishGenSnow); diff --git a/src/Generating/RoughRavines.cpp b/src/Generating/RoughRavines.cpp new file mode 100644 index 000000000..1b1351a19 --- /dev/null +++ b/src/Generating/RoughRavines.cpp @@ -0,0 +1,214 @@ + +// RoughRavines.cpp + +// Implements the cRoughRavines class representing the rough ravine generator + +#include "Globals.h" + +#include "RoughRavines.h" + + + + + +//////////////////////////////////////////////////////////////////////////////// +// cRoughRavine: + +class cRoughRavine : + public cGridStructGen::cStructure +{ + typedef cGridStructGen::cStructure super; + +public: + cRoughRavine(int a_Seed, int a_MaxSize, int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) : + super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), + m_Noise(a_Seed + 100), + m_MaxSize(a_MaxSize) + { + // Create the basic structure - 2 lines meeting at the centerpoint: + m_DefPoints.resize(a_MaxSize + 1); + int Half = a_MaxSize / 2; // m_DefPoints[Half] will be the centerpoint + int rnd = m_Noise.IntNoise2DInt(a_OriginX, a_OriginZ) / 7; + float Len = (float)(3 * a_MaxSize / 4 + rnd % (a_MaxSize / 4)); // Random number between 3 / 4 * a_MaxSize and a_MaxSize + rnd = rnd / a_MaxSize; + float Angle = (float)rnd; // Angle is in radians, will be wrapped in the "sin" and "cos" operations + float OfsX = sin(Angle) * Len; + float OfsZ = cos(Angle) * Len; + m_DefPoints[0].Set (a_OriginX - OfsX, a_OriginZ - OfsZ, 1, 42, 34); + m_DefPoints[Half].Set ((float)a_OriginX, (float)a_OriginZ, Len / 10, 62, 16); + m_DefPoints[a_MaxSize].Set(a_OriginX + OfsX, a_OriginZ + OfsZ, 1, 44, 32); + + // Calculate the points in between, recursively: + SubdivideLine(0, Half); + SubdivideLine(Half, a_MaxSize); + } + +protected: + struct sRavineDefPoint + { + float m_X; + float m_Z; + float m_Radius; + float m_Top; + float m_Bottom; + + void Set(float a_X, float a_Z, float a_Radius, float a_Top, float a_Bottom) + { + m_X = a_X; + m_Z = a_Z; + m_Radius = a_Radius; + m_Top = a_Top; + m_Bottom = a_Bottom; + } + }; + typedef std::vector sRavineDefPoints; + + cNoise m_Noise; + + int m_MaxSize; + + sRavineDefPoints m_DefPoints; + + + /** Recursively subdivides the line between the points of the specified index. + Sets the midpoint to the center of the line plus or minus a random offset, then calls itself for each half + of the new line. */ + void SubdivideLine(int a_Idx1, int a_Idx2) + { + // Calculate the midpoint: + const sRavineDefPoint & p1 = m_DefPoints[a_Idx1]; + const sRavineDefPoint & p2 = m_DefPoints[a_Idx2]; + float MidX = (p1.m_X + p2.m_X) / 2; + float MidZ = (p1.m_Z + p2.m_Z) / 2; + float MidR = (p1.m_Radius + p2.m_Radius) / 2 + 0.1f; + float MidT = (p1.m_Top + p2.m_Top) / 2; + float MidB = (p1.m_Bottom + p2.m_Bottom) / 2; + + // Adjust the midpoint by a small amount of perpendicular vector in a random one of its two directions: + float dx = p2.m_X - p1.m_X; + float dz = p2.m_Z - p1.m_Z; + if ((m_Noise.IntNoise2DInt((int)MidX, (int)MidZ) / 11) % 2 == 0) + { + MidX += dz / 10; + MidZ -= dx / 10; + } + else + { + MidX -= dz / 10; + MidZ += dx / 10; + } + int MidIdx = (a_Idx1 + a_Idx2) / 2; + m_DefPoints[MidIdx].Set(MidX, MidZ, MidR, MidT, MidB); + + // Recurse the two halves, if they are worth recursing: + if (MidIdx - a_Idx1 > 1) + { + SubdivideLine(a_Idx1, MidIdx); + } + if (a_Idx2 - MidIdx > 1) + { + SubdivideLine(MidIdx, a_Idx2); + } + } + + + virtual void DrawIntoChunk(cChunkDesc & a_ChunkDesc) override + { + int BlockStartX = a_ChunkDesc.GetChunkX() * cChunkDef::Width; + int BlockStartZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width; + int BlockEndX = BlockStartX + cChunkDef::Width; + int BlockEndZ = BlockStartZ + cChunkDef::Width; + for (sRavineDefPoints::const_iterator itr = m_DefPoints.begin(), end = m_DefPoints.end(); itr != end; ++itr) + { + if ( + (ceilf (itr->m_X + itr->m_Radius) < BlockStartX) || + (floorf(itr->m_X - itr->m_Radius) > BlockEndX) || + (ceilf (itr->m_Z + itr->m_Radius) < BlockStartZ) || + (floorf(itr->m_Z - itr->m_Radius) > BlockEndZ) + ) + { + // Cannot intersect, bail out early + continue; + } + + // Carve out a cylinder around the xz point, m_Radius in diameter, from Bottom to Top: + float RadiusSq = itr->m_Radius * itr->m_Radius; // instead of doing sqrt for each distance, we do sqr of the radius + float DifX = BlockStartX - itr->m_X; // substitution for faster calc + float DifZ = BlockStartZ - itr->m_Z; // substitution for faster calc + for (int x = 0; x < cChunkDef::Width; x++) for (int z = 0; z < cChunkDef::Width; z++) + { + #ifdef _DEBUG + // DEBUG: Make the roughravine shapepoints visible on a single layer (so that we can see with Minutor what's going on) + if ((DifX + x == 0) && (DifZ + z == 0)) + { + a_ChunkDesc.SetBlockType(x, 4, z, E_BLOCK_LAPIS_ORE); + } + #endif // _DEBUG + + float DistSq = (DifX + x) * (DifX + x) + (DifZ + z) * (DifZ + z); + if (DistSq <= RadiusSq) + { + int Top = std::min((int)ceilf(itr->m_Top), +cChunkDef::Height); + for (int y = std::max((int)floorf(itr->m_Bottom), 1); y <= Top; y++) + { + switch (a_ChunkDesc.GetBlockType(x, y, z)) + { + // Only carve out these specific block types + case E_BLOCK_DIRT: + case E_BLOCK_GRASS: + case E_BLOCK_STONE: + case E_BLOCK_COBBLESTONE: + case E_BLOCK_GRAVEL: + case E_BLOCK_SAND: + case E_BLOCK_SANDSTONE: + case E_BLOCK_NETHERRACK: + case E_BLOCK_COAL_ORE: + case E_BLOCK_IRON_ORE: + case E_BLOCK_GOLD_ORE: + case E_BLOCK_DIAMOND_ORE: + case E_BLOCK_REDSTONE_ORE: + case E_BLOCK_REDSTONE_ORE_GLOWING: + { + a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_AIR); + break; + } + default: break; + } + } + } + } // for x, z - a_BlockTypes + } // for itr - m_Points[] + } +}; + + + + + +//////////////////////////////////////////////////////////////////////////////// +// cRoughRavines: + +cRoughRavines::cRoughRavines(int a_Seed, int a_MaxSize, int a_GridSize, int a_MaxOffset) : + super(a_Seed, a_GridSize, a_GridSize, a_MaxOffset, a_MaxOffset, a_MaxSize, a_MaxSize, 64), + m_Seed(a_Seed), + m_MaxSize(a_MaxSize) +{ + if (m_MaxSize < 1) + { + m_MaxSize = 16; + LOGWARNING("RoughRavines: MaxSize too small, adjusting request from %d to %d", a_MaxSize, m_MaxSize); + } +} + + + + + +cGridStructGen::cStructurePtr cRoughRavines::CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) +{ + return cStructurePtr(new cRoughRavine(m_Seed, m_MaxSize, a_GridX, a_GridZ, a_OriginX, a_OriginZ)); +} + + + + diff --git a/src/Generating/RoughRavines.h b/src/Generating/RoughRavines.h new file mode 100644 index 000000000..68c628d84 --- /dev/null +++ b/src/Generating/RoughRavines.h @@ -0,0 +1,37 @@ + +// RoughRavines.h + +// Declares the cRoughRavines class representing the rough ravine generator + + + + +#pragma once + +#include "GridStructGen.h" + + + + + +class cRoughRavines : + public cGridStructGen +{ + typedef cGridStructGen super; + +public: + cRoughRavines(int a_Seed, int a_MaxSize, int a_GridSize, int a_MaxOffset); + +protected: + int m_Seed; + + /** Maximum size of the ravine, in each of the X / Z axis */ + int m_MaxSize; + + // cGridStructGen overrides: + virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override; +}; + + + + -- cgit v1.2.3 From 472f70a6762369eb3375eb1ed874a95faaf2de71 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 27 Jul 2014 13:54:27 +0200 Subject: RoughRavines: More settings - size, width, roughness --- src/Generating/ComposableGenerator.cpp | 18 +++++++--- src/Generating/RoughRavines.cpp | 66 ++++++++++++++++++++++++---------- src/Generating/RoughRavines.h | 23 +++++++++++- 3 files changed, 84 insertions(+), 23 deletions(-) (limited to 'src/Generating') diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp index 757f6ddb7..3326dda36 100644 --- a/src/Generating/ComposableGenerator.cpp +++ b/src/Generating/ComposableGenerator.cpp @@ -410,10 +410,20 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) } else if (NoCaseCompare(*itr, "RoughRavines") == 0) { - int GridSize = a_IniFile.GetValueSetI("Generator", "RoughRavinesGridSize", 256); - int MaxOffset = a_IniFile.GetValueSetI("Generator", "RoughRavinesMaxOffset", 128); - int MaxSize = a_IniFile.GetValueSetI("Generator", "RoughRavinesMaxSize", 64); - m_FinishGens.push_back(new cRoughRavines(Seed, MaxSize, GridSize, MaxOffset)); + int GridSize = a_IniFile.GetValueSetI("Generator", "RoughRavinesGridSize", 256); + int MaxOffset = a_IniFile.GetValueSetI("Generator", "RoughRavinesMaxOffset", 128); + int MaxSize = a_IniFile.GetValueSetI("Generator", "RoughRavinesMaxSize", 128); + int MinSize = a_IniFile.GetValueSetI("Generator", "RoughRavinesMinSize", 64); + double MaxCenterWidth = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxCenterWidth", 8); + double MinCenterWidth = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinCenterWidth", 2); + double MaxRoughness = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxRoughness", 0.2); + double MinRoughness = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinRoughness", 0.05); + m_FinishGens.push_back(new cRoughRavines( + Seed, MaxSize, MinSize, + (float)MaxCenterWidth, (float)MinCenterWidth, + (float)MaxRoughness, (float)MinRoughness, + GridSize, MaxOffset + )); } else if (NoCaseCompare(*itr, "Snow") == 0) { diff --git a/src/Generating/RoughRavines.cpp b/src/Generating/RoughRavines.cpp index 1b1351a19..ddc1a0351 100644 --- a/src/Generating/RoughRavines.cpp +++ b/src/Generating/RoughRavines.cpp @@ -20,27 +20,27 @@ class cRoughRavine : typedef cGridStructGen::cStructure super; public: - cRoughRavine(int a_Seed, int a_MaxSize, int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) : + cRoughRavine(int a_Seed, int a_Size, float a_CenterWidth, float a_Roughness, int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) : super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), m_Noise(a_Seed + 100), - m_MaxSize(a_MaxSize) + m_Roughness(a_Roughness) { // Create the basic structure - 2 lines meeting at the centerpoint: - m_DefPoints.resize(a_MaxSize + 1); - int Half = a_MaxSize / 2; // m_DefPoints[Half] will be the centerpoint + int Max = 2 * a_Size; + int Half = a_Size; // m_DefPoints[Half] will be the centerpoint + m_DefPoints.resize(Max + 1); int rnd = m_Noise.IntNoise2DInt(a_OriginX, a_OriginZ) / 7; - float Len = (float)(3 * a_MaxSize / 4 + rnd % (a_MaxSize / 4)); // Random number between 3 / 4 * a_MaxSize and a_MaxSize - rnd = rnd / a_MaxSize; + float Len = (float)a_Size; float Angle = (float)rnd; // Angle is in radians, will be wrapped in the "sin" and "cos" operations float OfsX = sin(Angle) * Len; float OfsZ = cos(Angle) * Len; - m_DefPoints[0].Set (a_OriginX - OfsX, a_OriginZ - OfsZ, 1, 42, 34); - m_DefPoints[Half].Set ((float)a_OriginX, (float)a_OriginZ, Len / 10, 62, 16); - m_DefPoints[a_MaxSize].Set(a_OriginX + OfsX, a_OriginZ + OfsZ, 1, 44, 32); + m_DefPoints[0].Set (a_OriginX - OfsX, a_OriginZ - OfsZ, 1, 42, 34); + m_DefPoints[Half].Set((float)a_OriginX, (float)a_OriginZ, a_CenterWidth, 62, 16); + m_DefPoints[Max].Set (a_OriginX + OfsX, a_OriginZ + OfsZ, 1, 44, 32); // Calculate the points in between, recursively: SubdivideLine(0, Half); - SubdivideLine(Half, a_MaxSize); + SubdivideLine(Half, Max); } protected: @@ -69,6 +69,8 @@ protected: sRavineDefPoints m_DefPoints; + float m_Roughness; + /** Recursively subdivides the line between the points of the specified index. Sets the midpoint to the center of the line plus or minus a random offset, then calls itself for each half @@ -89,13 +91,13 @@ protected: float dz = p2.m_Z - p1.m_Z; if ((m_Noise.IntNoise2DInt((int)MidX, (int)MidZ) / 11) % 2 == 0) { - MidX += dz / 10; - MidZ -= dx / 10; + MidX += dz * m_Roughness; + MidZ -= dx * m_Roughness; } else { - MidX -= dz / 10; - MidZ += dx / 10; + MidX -= dz * m_Roughness; + MidZ += dx * m_Roughness; } int MidIdx = (a_Idx1 + a_Idx2) / 2; m_DefPoints[MidIdx].Set(MidX, MidZ, MidR, MidT, MidB); @@ -188,16 +190,41 @@ protected: //////////////////////////////////////////////////////////////////////////////// // cRoughRavines: -cRoughRavines::cRoughRavines(int a_Seed, int a_MaxSize, int a_GridSize, int a_MaxOffset) : +cRoughRavines::cRoughRavines( + int a_Seed, + int a_MaxSize, int a_MinSize, + float a_MaxCenterWidth, float a_MinCenterWidth, + float a_MaxRoughness, float a_MinRoughness, + int a_GridSize, int a_MaxOffset +) : super(a_Seed, a_GridSize, a_GridSize, a_MaxOffset, a_MaxOffset, a_MaxSize, a_MaxSize, 64), m_Seed(a_Seed), - m_MaxSize(a_MaxSize) + m_MaxSize(a_MaxSize), + m_MinSize(a_MinSize), + m_MaxCenterWidth(a_MaxCenterWidth), + m_MinCenterWidth(a_MinCenterWidth), + m_MaxRoughness(a_MaxRoughness), + m_MinRoughness(a_MinRoughness) { - if (m_MaxSize < 1) + if (m_MinSize > m_MaxSize) + { + std::swap(m_MinSize, m_MaxSize); + std::swap(a_MinSize, a_MaxSize); + } + if (m_MaxSize < 16) { m_MaxSize = 16; LOGWARNING("RoughRavines: MaxSize too small, adjusting request from %d to %d", a_MaxSize, m_MaxSize); } + if (m_MinSize < 16) + { + m_MinSize = 16; + LOGWARNING("RoughRavines: MinSize too small, adjusting request from %d to %d", a_MinSize, m_MinSize); + } + if (m_MinSize == m_MaxSize) + { + m_MaxSize = m_MinSize + 1; + } } @@ -206,7 +233,10 @@ cRoughRavines::cRoughRavines(int a_Seed, int a_MaxSize, int a_GridSize, int a_Ma cGridStructGen::cStructurePtr cRoughRavines::CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) { - return cStructurePtr(new cRoughRavine(m_Seed, m_MaxSize, a_GridX, a_GridZ, a_OriginX, a_OriginZ)); + int Size = m_MinSize + (m_Noise.IntNoise2DInt(a_GridX, a_GridZ) / 7) % (m_MaxSize - m_MinSize); // Random int from m_MinSize to m_MaxSize + float CenterWidth = m_MinCenterWidth + abs(m_Noise.IntNoise2D(a_GridX, a_GridZ + 10)) * (m_MaxCenterWidth - m_MinCenterWidth); // Random float from m_MinCenterWidth to m_MaxCenterWidth + float Roughness = m_MinRoughness + abs(m_Noise.IntNoise2D(a_GridX + 10, a_GridZ)) * (m_MaxRoughness - m_MinRoughness); // Random float from m_MinRoughness to m_MaxRoughness + return cStructurePtr(new cRoughRavine(m_Seed, Size, CenterWidth, Roughness, a_GridX, a_GridZ, a_OriginX, a_OriginZ)); } diff --git a/src/Generating/RoughRavines.h b/src/Generating/RoughRavines.h index 68c628d84..dce2f9ba7 100644 --- a/src/Generating/RoughRavines.h +++ b/src/Generating/RoughRavines.h @@ -20,13 +20,34 @@ class cRoughRavines : typedef cGridStructGen super; public: - cRoughRavines(int a_Seed, int a_MaxSize, int a_GridSize, int a_MaxOffset); + cRoughRavines( + int a_Seed, + int a_MaxSize, int a_MinSize, + float a_MaxCenterWidth, float a_MinCenterWidth, + float a_MaxRoughness, float a_MinRoughness, + int a_GridSize, int a_MaxOffset + ); protected: int m_Seed; /** Maximum size of the ravine, in each of the X / Z axis */ int m_MaxSize; + + /** Minimum size of the ravine */ + int m_MinSize; + + /** Maximum width of the ravine's center, in blocks */ + float m_MaxCenterWidth; + + /** Minimum width of the ravine's center, in blocks */ + float m_MinCenterWidth; + + /** Maximum roughness of the ravine */ + float m_MaxRoughness; + + /** Minimum roughness of the ravine */ + float m_MinRoughness; // cGridStructGen overrides: virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override; -- cgit v1.2.3 From 960ab982b96d23485b6c42df1ed2b08a251a0c22 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 27 Jul 2014 16:05:45 +0200 Subject: RoughRavines: Added per-height radius modifier. Ledges! --- src/Generating/RoughRavines.cpp | 105 ++++++++++++++++++++++++++++------------ 1 file changed, 73 insertions(+), 32 deletions(-) (limited to 'src/Generating') diff --git a/src/Generating/RoughRavines.cpp b/src/Generating/RoughRavines.cpp index ddc1a0351..8dec791c9 100644 --- a/src/Generating/RoughRavines.cpp +++ b/src/Generating/RoughRavines.cpp @@ -22,6 +22,7 @@ class cRoughRavine : public: cRoughRavine(int a_Seed, int a_Size, float a_CenterWidth, float a_Roughness, int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) : super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), + m_Seed(a_Seed + 100), m_Noise(a_Seed + 100), m_Roughness(a_Roughness) { @@ -41,6 +42,9 @@ public: // Calculate the points in between, recursively: SubdivideLine(0, Half); SubdivideLine(Half, Max); + + // Initialize the per-height radius modifiers: + InitPerHeightRadius(a_GridX, a_GridZ); } protected: @@ -63,6 +67,8 @@ protected: }; typedef std::vector sRavineDefPoints; + int m_Seed; + cNoise m_Noise; int m_MaxSize; @@ -71,6 +77,9 @@ protected: float m_Roughness; + /** Number to add to the radius based on the height. This creates the "ledges" in the ravine walls. */ + float m_PerHeightRadius[cChunkDef::Height]; + /** Recursively subdivides the line between the points of the specified index. Sets the midpoint to the center of the line plus or minus a random offset, then calls itself for each half @@ -114,6 +123,29 @@ protected: } + void InitPerHeightRadius(int a_GridX, int a_GridZ) + { + int h = 0; + while (h < cChunkDef::Height) + { + m_Noise.SetSeed(m_Seed + h); + int rnd = m_Noise.IntNoise2DInt(a_GridX, a_GridZ) / 13; + int NumBlocks = (rnd % 3) + 2; + rnd = rnd / 4; + float Val = (float)(rnd % 256) / 128 - 1; // Random float in range [-1, +1] + if (h + NumBlocks > cChunkDef::Height) + { + NumBlocks = cChunkDef::Height - h; + } + for (int i = 0; i < NumBlocks; i++) + { + m_PerHeightRadius[h + i] = Val; + } + h += NumBlocks; + } + } + + virtual void DrawIntoChunk(cChunkDesc & a_ChunkDesc) override { int BlockStartX = a_ChunkDesc.GetChunkX() * cChunkDef::Width; @@ -123,18 +155,20 @@ protected: for (sRavineDefPoints::const_iterator itr = m_DefPoints.begin(), end = m_DefPoints.end(); itr != end; ++itr) { if ( - (ceilf (itr->m_X + itr->m_Radius) < BlockStartX) || - (floorf(itr->m_X - itr->m_Radius) > BlockEndX) || - (ceilf (itr->m_Z + itr->m_Radius) < BlockStartZ) || - (floorf(itr->m_Z - itr->m_Radius) > BlockEndZ) + (ceilf (itr->m_X + itr->m_Radius + 2) < BlockStartX) || + (floorf(itr->m_X - itr->m_Radius - 2) > BlockEndX) || + (ceilf (itr->m_Z + itr->m_Radius + 2) < BlockStartZ) || + (floorf(itr->m_Z - itr->m_Radius - 2) > BlockEndZ) ) { // Cannot intersect, bail out early continue; } - // Carve out a cylinder around the xz point, m_Radius in diameter, from Bottom to Top: - float RadiusSq = itr->m_Radius * itr->m_Radius; // instead of doing sqrt for each distance, we do sqr of the radius + // Carve out a cylinder around the xz point, up to (m_Radius + 2) in diameter, from Bottom to Top: + // On each height level, use m_PerHeightRadius[] to modify the actual radius used + // EnlargedRadiusSq is the square of the radius enlarged by the maximum m_PerHeightRadius offset - anything outside it will never be touched. + float RadiusSq = (itr->m_Radius + 2) * (itr->m_Radius + 2); float DifX = BlockStartX - itr->m_X; // substitution for faster calc float DifZ = BlockStartZ - itr->m_Z; // substitution for faster calc for (int x = 0; x < cChunkDef::Width; x++) for (int z = 0; z < cChunkDef::Width; z++) @@ -147,37 +181,44 @@ protected: } #endif // _DEBUG + // If the column is outside the enlarged radius, bail out completely float DistSq = (DifX + x) * (DifX + x) + (DifZ + z) * (DifZ + z); - if (DistSq <= RadiusSq) + if (DistSq > RadiusSq) + { + continue; + } + + int Top = std::min((int)ceilf(itr->m_Top), +cChunkDef::Height); + for (int y = std::max((int)floorf(itr->m_Bottom), 1); y <= Top; y++) { - int Top = std::min((int)ceilf(itr->m_Top), +cChunkDef::Height); - for (int y = std::max((int)floorf(itr->m_Bottom), 1); y <= Top; y++) + if ((itr->m_Radius + m_PerHeightRadius[y]) * (itr->m_Radius + m_PerHeightRadius[y]) < DistSq) + { + continue; + } + switch (a_ChunkDesc.GetBlockType(x, y, z)) { - switch (a_ChunkDesc.GetBlockType(x, y, z)) + // Only carve out these specific block types + case E_BLOCK_DIRT: + case E_BLOCK_GRASS: + case E_BLOCK_STONE: + case E_BLOCK_COBBLESTONE: + case E_BLOCK_GRAVEL: + case E_BLOCK_SAND: + case E_BLOCK_SANDSTONE: + case E_BLOCK_NETHERRACK: + case E_BLOCK_COAL_ORE: + case E_BLOCK_IRON_ORE: + case E_BLOCK_GOLD_ORE: + case E_BLOCK_DIAMOND_ORE: + case E_BLOCK_REDSTONE_ORE: + case E_BLOCK_REDSTONE_ORE_GLOWING: { - // Only carve out these specific block types - case E_BLOCK_DIRT: - case E_BLOCK_GRASS: - case E_BLOCK_STONE: - case E_BLOCK_COBBLESTONE: - case E_BLOCK_GRAVEL: - case E_BLOCK_SAND: - case E_BLOCK_SANDSTONE: - case E_BLOCK_NETHERRACK: - case E_BLOCK_COAL_ORE: - case E_BLOCK_IRON_ORE: - case E_BLOCK_GOLD_ORE: - case E_BLOCK_DIAMOND_ORE: - case E_BLOCK_REDSTONE_ORE: - case E_BLOCK_REDSTONE_ORE_GLOWING: - { - a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_AIR); - break; - } - default: break; + a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_AIR); + break; } - } - } + default: break; + } // switch (BlockType) + } // for y } // for x, z - a_BlockTypes } // for itr - m_Points[] } -- cgit v1.2.3 From 30893e7ee2f4dbaa3e4348b07cdc77aada168e1f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 27 Jul 2014 19:57:47 +0200 Subject: RoughRavines: Made floor and ceiling settings-adjustable. The world.ini has settings for the minimum and maximum height for each at the ravines' center and edges. --- src/Generating/ComposableGenerator.cpp | 32 ++++++++++++++------- src/Generating/RoughRavines.cpp | 51 ++++++++++++++++++++++++++++------ src/Generating/RoughRavines.h | 30 +++++++++++++++++++- 3 files changed, 93 insertions(+), 20 deletions(-) (limited to 'src/Generating') diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp index 3326dda36..0d9bedf45 100644 --- a/src/Generating/ComposableGenerator.cpp +++ b/src/Generating/ComposableGenerator.cpp @@ -410,18 +410,30 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) } else if (NoCaseCompare(*itr, "RoughRavines") == 0) { - int GridSize = a_IniFile.GetValueSetI("Generator", "RoughRavinesGridSize", 256); - int MaxOffset = a_IniFile.GetValueSetI("Generator", "RoughRavinesMaxOffset", 128); - int MaxSize = a_IniFile.GetValueSetI("Generator", "RoughRavinesMaxSize", 128); - int MinSize = a_IniFile.GetValueSetI("Generator", "RoughRavinesMinSize", 64); - double MaxCenterWidth = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxCenterWidth", 8); - double MinCenterWidth = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinCenterWidth", 2); - double MaxRoughness = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxRoughness", 0.2); - double MinRoughness = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinRoughness", 0.05); + int GridSize = a_IniFile.GetValueSetI("Generator", "RoughRavinesGridSize", 256); + int MaxOffset = a_IniFile.GetValueSetI("Generator", "RoughRavinesMaxOffset", 128); + int MaxSize = a_IniFile.GetValueSetI("Generator", "RoughRavinesMaxSize", 128); + int MinSize = a_IniFile.GetValueSetI("Generator", "RoughRavinesMinSize", 64); + double MaxCenterWidth = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxCenterWidth", 8); + double MinCenterWidth = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinCenterWidth", 2); + double MaxRoughness = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxRoughness", 0.2); + double MinRoughness = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinRoughness", 0.05); + double MaxFloorHeightEdge = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxFloorHeightEdge", 8); + double MinFloorHeightEdge = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinFloorHeightEdge", 30); + double MaxFloorHeightCenter = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxFloorHeightCenter", 20); + double MinFloorHeightCenter = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinFloorHeightCenter", 6); + double MaxCeilingHeightEdge = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxCeilingHeightEdge", 56); + double MinCeilingHeightEdge = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinCeilingHeightEdge", 38); + double MaxCeilingHeightCenter = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxCeilingHeightCenter", 58); + double MinCeilingHeightCenter = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinCeilingHeightCenter", 36); m_FinishGens.push_back(new cRoughRavines( Seed, MaxSize, MinSize, - (float)MaxCenterWidth, (float)MinCenterWidth, - (float)MaxRoughness, (float)MinRoughness, + (float)MaxCenterWidth, (float)MinCenterWidth, + (float)MaxRoughness, (float)MinRoughness, + (float)MaxFloorHeightEdge, (float)MinFloorHeightEdge, + (float)MaxFloorHeightCenter, (float)MinFloorHeightCenter, + (float)MaxCeilingHeightEdge, (float)MinCeilingHeightEdge, + (float)MaxCeilingHeightCenter, (float)MinCeilingHeightCenter, GridSize, MaxOffset )); } diff --git a/src/Generating/RoughRavines.cpp b/src/Generating/RoughRavines.cpp index 8dec791c9..badc7768e 100644 --- a/src/Generating/RoughRavines.cpp +++ b/src/Generating/RoughRavines.cpp @@ -20,7 +20,13 @@ class cRoughRavine : typedef cGridStructGen::cStructure super; public: - cRoughRavine(int a_Seed, int a_Size, float a_CenterWidth, float a_Roughness, int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) : + cRoughRavine( + int a_Seed, int a_Size, + float a_CenterWidth, float a_Roughness, + float a_FloorHeightEdge1, float a_FloorHeightEdge2, float a_FloorHeightCenter, + float a_CeilingHeightEdge1, float a_CeilingHeightEdge2, float a_CeilingHeightCenter, + int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ + ) : super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), m_Seed(a_Seed + 100), m_Noise(a_Seed + 100), @@ -35,9 +41,9 @@ public: float Angle = (float)rnd; // Angle is in radians, will be wrapped in the "sin" and "cos" operations float OfsX = sin(Angle) * Len; float OfsZ = cos(Angle) * Len; - m_DefPoints[0].Set (a_OriginX - OfsX, a_OriginZ - OfsZ, 1, 42, 34); - m_DefPoints[Half].Set((float)a_OriginX, (float)a_OriginZ, a_CenterWidth, 62, 16); - m_DefPoints[Max].Set (a_OriginX + OfsX, a_OriginZ + OfsZ, 1, 44, 32); + m_DefPoints[0].Set (a_OriginX - OfsX, a_OriginZ - OfsZ, 1, a_CeilingHeightEdge1, a_FloorHeightEdge1); + m_DefPoints[Half].Set((float)a_OriginX, (float)a_OriginZ, a_CenterWidth, a_CeilingHeightCenter, a_FloorHeightCenter); + m_DefPoints[Max].Set (a_OriginX + OfsX, a_OriginZ + OfsZ, 1, a_CeilingHeightEdge2, a_FloorHeightEdge2); // Calculate the points in between, recursively: SubdivideLine(0, Half); @@ -235,7 +241,11 @@ cRoughRavines::cRoughRavines( int a_Seed, int a_MaxSize, int a_MinSize, float a_MaxCenterWidth, float a_MinCenterWidth, - float a_MaxRoughness, float a_MinRoughness, + float a_MaxRoughness, float a_MinRoughness, + float a_MaxFloorHeightEdge, float a_MinFloorHeightEdge, + float a_MaxFloorHeightCenter, float a_MinFloorHeightCenter, + float a_MaxCeilingHeightEdge, float a_MinCeilingHeightEdge, + float a_MaxCeilingHeightCenter, float a_MinCeilingHeightCenter, int a_GridSize, int a_MaxOffset ) : super(a_Seed, a_GridSize, a_GridSize, a_MaxOffset, a_MaxOffset, a_MaxSize, a_MaxSize, 64), @@ -245,7 +255,15 @@ cRoughRavines::cRoughRavines( m_MaxCenterWidth(a_MaxCenterWidth), m_MinCenterWidth(a_MinCenterWidth), m_MaxRoughness(a_MaxRoughness), - m_MinRoughness(a_MinRoughness) + m_MinRoughness(a_MinRoughness), + m_MaxFloorHeightEdge(a_MaxFloorHeightEdge), + m_MinFloorHeightEdge(a_MinFloorHeightEdge), + m_MaxFloorHeightCenter(a_MaxFloorHeightCenter), + m_MinFloorHeightCenter(a_MinFloorHeightCenter), + m_MaxCeilingHeightEdge(a_MaxCeilingHeightEdge), + m_MinCeilingHeightEdge(a_MinCeilingHeightEdge), + m_MaxCeilingHeightCenter(a_MaxCeilingHeightCenter), + m_MinCeilingHeightCenter(a_MinCeilingHeightCenter) { if (m_MinSize > m_MaxSize) { @@ -274,10 +292,25 @@ cRoughRavines::cRoughRavines( cGridStructGen::cStructurePtr cRoughRavines::CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) { + // Pick a random value for each of the ravine's parameters: int Size = m_MinSize + (m_Noise.IntNoise2DInt(a_GridX, a_GridZ) / 7) % (m_MaxSize - m_MinSize); // Random int from m_MinSize to m_MaxSize - float CenterWidth = m_MinCenterWidth + abs(m_Noise.IntNoise2D(a_GridX, a_GridZ + 10)) * (m_MaxCenterWidth - m_MinCenterWidth); // Random float from m_MinCenterWidth to m_MaxCenterWidth - float Roughness = m_MinRoughness + abs(m_Noise.IntNoise2D(a_GridX + 10, a_GridZ)) * (m_MaxRoughness - m_MinRoughness); // Random float from m_MinRoughness to m_MaxRoughness - return cStructurePtr(new cRoughRavine(m_Seed, Size, CenterWidth, Roughness, a_GridX, a_GridZ, a_OriginX, a_OriginZ)); + float CenterWidth = m_Noise.IntNoise2DInRange(a_GridX + 10, a_GridZ, m_MinCenterWidth, m_MaxCenterWidth); + float Roughness = m_Noise.IntNoise2DInRange(a_GridX + 20, a_GridZ, m_MinRoughness, m_MaxRoughness); + float FloorHeightEdge1 = m_Noise.IntNoise2DInRange(a_GridX + 30, a_GridZ, m_MinFloorHeightEdge, m_MaxFloorHeightEdge); + float FloorHeightEdge2 = m_Noise.IntNoise2DInRange(a_GridX + 40, a_GridZ, m_MinFloorHeightEdge, m_MaxFloorHeightEdge); + float FloorHeightCenter = m_Noise.IntNoise2DInRange(a_GridX + 50, a_GridZ, m_MinFloorHeightCenter, m_MaxFloorHeightCenter); + float CeilingHeightEdge1 = m_Noise.IntNoise2DInRange(a_GridX + 60, a_GridZ, m_MinCeilingHeightEdge, m_MaxCeilingHeightEdge); + float CeilingHeightEdge2 = m_Noise.IntNoise2DInRange(a_GridX + 70, a_GridZ, m_MinCeilingHeightEdge, m_MaxCeilingHeightEdge); + float CeilingHeightCenter = m_Noise.IntNoise2DInRange(a_GridX + 80, a_GridZ, m_MinCeilingHeightCenter, m_MaxCeilingHeightCenter); + + // Create a ravine: + return cStructurePtr(new cRoughRavine( + m_Seed, + Size, CenterWidth, Roughness, + FloorHeightEdge1, FloorHeightEdge2, FloorHeightCenter, + CeilingHeightEdge1, CeilingHeightEdge2, CeilingHeightCenter, + a_GridX, a_GridZ, a_OriginX, a_OriginZ + )); } diff --git a/src/Generating/RoughRavines.h b/src/Generating/RoughRavines.h index dce2f9ba7..4c905b641 100644 --- a/src/Generating/RoughRavines.h +++ b/src/Generating/RoughRavines.h @@ -24,7 +24,11 @@ public: int a_Seed, int a_MaxSize, int a_MinSize, float a_MaxCenterWidth, float a_MinCenterWidth, - float a_MaxRoughness, float a_MinRoughness, + float a_MaxRoughness, float a_MinRoughness, + float a_MaxFloorHeightEdge, float a_MinFloorHeightEdge, + float a_MaxFloorHeightCenter, float a_MinFloorHeightCenter, + float a_MaxCeilingHeightEdge, float a_MinCeilingHeightEdge, + float a_MaxCeilingHeightCenter, float a_MinCeilingHeightCenter, int a_GridSize, int a_MaxOffset ); @@ -49,6 +53,30 @@ protected: /** Minimum roughness of the ravine */ float m_MinRoughness; + /** Maximum floor height at the ravine's edge */ + float m_MaxFloorHeightEdge; + + /** Minimum floor height at the ravine's edge */ + float m_MinFloorHeightEdge; + + /** Maximum floor height at the ravine's center */ + float m_MaxFloorHeightCenter; + + /** Minimum floor height at the ravine's center */ + float m_MinFloorHeightCenter; + + /** Maximum ceiling height at the ravine's edge */ + float m_MaxCeilingHeightEdge; + + /** Minimum ceiling height at the ravine's edge */ + float m_MinCeilingHeightEdge; + + /** Maximum ceiling height at the ravine's center */ + float m_MaxCeilingHeightCenter; + + /** Minimum ceiling height at the ravine's center */ + float m_MinCeilingHeightCenter; + // cGridStructGen overrides: virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override; }; -- cgit v1.2.3