summaryrefslogtreecommitdiffstats
path: root/src/Generating
diff options
context:
space:
mode:
authorAlexander Harkness <bearbin@gmail.com>2013-11-24 15:37:03 +0100
committerAlexander Harkness <bearbin@gmail.com>2013-11-24 15:37:03 +0100
commitc3cd436ec3526962f0f0698ab2d75774247c340b (patch)
treeaf5fa89e891ede194f981399af8b830afc6dec97 /src/Generating
parentRemoved pedantic build and added optimisation to debug builds. (diff)
parentRCONClient: Initial implementation. (diff)
downloadcuberite-c3cd436ec3526962f0f0698ab2d75774247c340b.tar
cuberite-c3cd436ec3526962f0f0698ab2d75774247c340b.tar.gz
cuberite-c3cd436ec3526962f0f0698ab2d75774247c340b.tar.bz2
cuberite-c3cd436ec3526962f0f0698ab2d75774247c340b.tar.lz
cuberite-c3cd436ec3526962f0f0698ab2d75774247c340b.tar.xz
cuberite-c3cd436ec3526962f0f0698ab2d75774247c340b.tar.zst
cuberite-c3cd436ec3526962f0f0698ab2d75774247c340b.zip
Diffstat (limited to '')
-rw-r--r--src/Generating/Caves.cpp104
-rw-r--r--src/Generating/ChunkDesc.cpp16
-rw-r--r--src/Generating/ChunkGenerator.cpp36
-rw-r--r--src/Generating/DistortedHeightmap.cpp24
-rw-r--r--src/Generating/EndGen.cpp30
-rw-r--r--src/Generating/MineShafts.cpp119
-rw-r--r--src/Generating/Noise3DGenerator.cpp57
7 files changed, 190 insertions, 196 deletions
diff --git a/src/Generating/Caves.cpp b/src/Generating/Caves.cpp
index 4221ea187..df45bb4c2 100644
--- a/src/Generating/Caves.cpp
+++ b/src/Generating/Caves.cpp
@@ -55,7 +55,7 @@ struct cCaveDefPoint
int m_BlockY;
int m_BlockZ;
int m_Radius;
-
+
cCaveDefPoint(int a_BlockX, int a_BlockY, int a_BlockZ, int a_Radius) :
m_BlockX(a_BlockX),
m_BlockY(a_BlockY),
@@ -78,22 +78,22 @@ class cCaveTunnel
int m_MinBlockX, m_MaxBlockX;
int m_MinBlockY, m_MaxBlockY;
int m_MinBlockZ, m_MaxBlockZ;
-
+
/// Generates the shaping defpoints for the ravine, based on the ravine block coords and noise
void Randomize(cNoise & a_Noise);
-
+
/// Refines (adds and smooths) defpoints from a_Src into a_Dst; returns false if no refinement possible (segments too short)
bool RefineDefPoints(const cCaveDefPoints & a_Src, cCaveDefPoints & a_Dst);
-
+
/// Does rounds of smoothing, two passes of RefineDefPoints(), as long as they return true
void Smooth(void);
-
+
/// Linearly interpolates the points so that the maximum distance between two neighbors is max 1 block
void FinishLinear(void);
-
+
/// Calculates the bounding box of the points present
void CalcBoundingBox(void);
-
+
public:
cCaveDefPoints m_Points;
@@ -102,14 +102,14 @@ public:
int a_BlockEndX, int a_BlockEndY, int a_BlockEndZ, int a_EndRadius,
cNoise & a_Noise
);
-
+
/// Carves the tunnel into the chunk specified
void ProcessChunk(
- int a_ChunkX, int a_ChunkZ,
- cChunkDef::BlockTypes & a_BlockTypes,
+ int a_ChunkX, int a_ChunkZ,
+ cChunkDef::BlockTypes & a_BlockTypes,
cChunkDef::HeightMap & a_HeightMap
);
-
+
#ifdef _DEBUG
AString ExportAsSVG(int a_Color, int a_OffsetX, int a_OffsetZ) const;
#endif // _DEBUG
@@ -128,17 +128,17 @@ public:
// The generating block position; is read directly in cStructGenWormNestCaves::GetCavesForChunk()
int m_BlockX;
int m_BlockZ;
-
+
cCaveSystem(int a_BlockX, int a_BlockZ, int a_MaxOffset, int a_Size, cNoise & a_Noise);
~cCaveSystem();
-
+
/// Carves the cave system into the chunk specified
void ProcessChunk(
- int a_ChunkX, int a_ChunkZ,
- cChunkDef::BlockTypes & a_BlockTypes,
+ int a_ChunkX, int a_ChunkZ,
+ cChunkDef::BlockTypes & a_BlockTypes,
cChunkDef::HeightMap & a_HeightMap
);
-
+
#ifdef _DEBUG
AString ExportAsSVG(int a_Color, int a_OffsetX, int a_OffsetZ) const;
#endif // _DEBUG
@@ -146,15 +146,15 @@ public:
protected:
int m_Size;
cCaveTunnels m_Tunnels;
-
+
void Clear(void);
/// Generates a_Segment successive tunnels, with possible branches. Generates the same output for the same [x, y, z, a_Segments]
void GenerateTunnelsFromPoint(
- int a_OriginX, int a_OriginY, int a_OriginZ,
+ int a_OriginX, int a_OriginY, int a_OriginZ,
cNoise & a_Noise, int a_Segments
);
-
+
/// Returns a radius based on the location provided.
int GetRadius(cNoise & a_Noise, int a_OriginX, int a_OriginY, int a_OriginZ);
} ;
@@ -174,19 +174,19 @@ cCaveTunnel::cCaveTunnel(
{
m_Points.push_back(cCaveDefPoint(a_BlockStartX, a_BlockStartY, a_BlockStartZ, a_StartRadius));
m_Points.push_back(cCaveDefPoint(a_BlockEndX, a_BlockEndY, a_BlockEndZ, a_EndRadius));
-
+
if ((a_BlockStartY <= 0) && (a_BlockEndY <= 0))
{
// Don't bother detailing this cave, it's under the world anyway
return;
}
-
+
Randomize(a_Noise);
Smooth();
-
+
// We know that the linear finishing won't affect the bounding box, so let's calculate it now, as we have less data:
CalcBoundingBox();
-
+
FinishLinear();
}
@@ -308,7 +308,7 @@ void cCaveTunnel::FinishLinear(void)
// For each segment, use Bresenham's 3D line algorithm to draw a "line" of defpoints
cCaveDefPoints Pts;
std::swap(Pts, m_Points);
-
+
m_Points.reserve(Pts.size() * 3);
int PrevX = Pts.front().m_BlockX;
int PrevY = Pts.front().m_BlockY;
@@ -324,7 +324,6 @@ void cCaveTunnel::FinishLinear(void)
int sx = (PrevX < x1) ? 1 : -1;
int sy = (PrevY < y1) ? 1 : -1;
int sz = (PrevZ < z1) ? 1 : -1;
- int err = dx - dz;
int R = itr->m_Radius;
if (dx >= std::max(dy, dz)) // x dominant
@@ -418,7 +417,7 @@ void cCaveTunnel::FinishLinear(void)
PrevY += sy;
yd -= dz;
}
-
+
// move along z
PrevZ += sz;
xd += dx;
@@ -453,8 +452,8 @@ void cCaveTunnel::CalcBoundingBox(void)
void cCaveTunnel::ProcessChunk(
- int a_ChunkX, int a_ChunkZ,
- cChunkDef::BlockTypes & a_BlockTypes,
+ int a_ChunkX, int a_ChunkZ,
+ cChunkDef::BlockTypes & a_BlockTypes,
cChunkDef::HeightMap & a_HeightMap
)
{
@@ -462,7 +461,7 @@ void cCaveTunnel::ProcessChunk(
int BaseZ = a_ChunkZ * cChunkDef::Width;
if (
(BaseX > m_MaxBlockX) || (BaseX + cChunkDef::Width < m_MinBlockX) ||
- (BaseX > m_MaxBlockX) || (BaseX + cChunkDef::Width < m_MinBlockX)
+ (BaseZ > m_MaxBlockZ) || (BaseZ + cChunkDef::Width < m_MinBlockZ)
)
{
// Tunnel does not intersect the chunk at all, bail out
@@ -485,7 +484,7 @@ void cCaveTunnel::ProcessChunk(
// Cannot intersect, bail out early
continue;
}
-
+
// Carve out a sphere around the xyz point, m_Radius in diameter; skip 3/7 off the top and bottom:
int DifX = itr->m_BlockX - BlockStartX; // substitution for faster calc
int DifY = itr->m_BlockY;
@@ -493,7 +492,7 @@ void cCaveTunnel::ProcessChunk(
int Bottom = std::max(itr->m_BlockY - 3 * itr->m_Radius / 7, 1);
int Top = std::min(itr->m_BlockY + 3 * itr->m_Radius / 7, (int)(cChunkDef::Height));
int SqRad = itr->m_Radius * itr->m_Radius;
- for (int z = 0; z < cChunkDef::Width; z++) for (int x = 0; x < cChunkDef::Width; x++)
+ for (int z = 0; z < cChunkDef::Width; z++) for (int x = 0; x < cChunkDef::Width; x++)
{
for (int y = Bottom; y <= Top; y++)
{
@@ -527,9 +526,9 @@ void cCaveTunnel::ProcessChunk(
} // for y
} // for x, z
} // for itr - m_Points[]
-
+
/*
- #ifdef _DEBUG
+ #ifdef _DEBUG
// For debugging purposes, outline the shape of the cave using glowstone, *after* carving the entire cave:
for (cCaveDefPoints::const_iterator itr = m_Points.begin(), end = m_Points.end(); itr != end; ++itr)
{
@@ -587,7 +586,7 @@ cStructGenWormNestCaves::cCaveSystem::cCaveSystem(int a_BlockX, int a_BlockZ, in
int OriginX = a_BlockX + (a_Noise.IntNoise3DInt(13 * a_BlockX, 17 * a_BlockZ, 11 * i) / 19) % a_MaxOffset;
int OriginZ = a_BlockZ + (a_Noise.IntNoise3DInt(17 * a_BlockX, 13 * a_BlockZ, 11 * i) / 23) % a_MaxOffset;
int OriginY = 20 + (a_Noise.IntNoise3DInt(19 * a_BlockX, 13 * a_BlockZ, 11 * i) / 17) % 20;
-
+
// Generate three branches from the origin point:
// The tunnels generated depend on X, Y, Z and Branches,
// for the same set of numbers it generates the same offsets!
@@ -613,8 +612,8 @@ cStructGenWormNestCaves::cCaveSystem::~cCaveSystem()
void cStructGenWormNestCaves::cCaveSystem::ProcessChunk(
- int a_ChunkX, int a_ChunkZ,
- cChunkDef::BlockTypes & a_BlockTypes,
+ int a_ChunkX, int a_ChunkZ,
+ cChunkDef::BlockTypes & a_BlockTypes,
cChunkDef::HeightMap & a_HeightMap
)
{
@@ -645,14 +644,14 @@ AString cStructGenWormNestCaves::cCaveSystem::ExportAsSVG(int a_Color, int a_Off
AppendPrintf(SVG, "<path style=\"fill:none;stroke:#ff0000;stroke-width:1px;\"\nd=\"M %d,%d L %d,%d\"/>\n",
a_OffsetX + m_BlockX, a_OffsetZ + m_BlockZ - 5, a_OffsetX + m_BlockX, a_OffsetZ + m_BlockZ + 5
);
-
+
// A gray line from the base point to the first point of the ravine, for identification:
AppendPrintf(SVG, "<path style=\"fill:none;stroke:#cfcfcf;stroke-width:1px;\"\nd=\"M %d,%d L %d,%d\"/>\n",
- a_OffsetX + m_BlockX, a_OffsetZ + m_BlockZ,
- a_OffsetX + m_Tunnels.front()->m_Points.front().m_BlockX,
+ a_OffsetX + m_BlockX, a_OffsetZ + m_BlockZ,
+ a_OffsetX + m_Tunnels.front()->m_Points.front().m_BlockX,
a_OffsetZ + m_Tunnels.front()->m_Points.front().m_BlockZ
);
-
+
// Offset guides:
if (a_OffsetX > 0)
{
@@ -666,7 +665,7 @@ AString cStructGenWormNestCaves::cCaveSystem::ExportAsSVG(int a_Color, int a_Off
a_OffsetZ, a_OffsetZ
);
}
-
+
return SVG;
}
#endif // _DEBUG
@@ -689,7 +688,7 @@ void cStructGenWormNestCaves::cCaveSystem::Clear(void)
void cStructGenWormNestCaves::cCaveSystem::GenerateTunnelsFromPoint(
- int a_OriginX, int a_OriginY, int a_OriginZ,
+ int a_OriginX, int a_OriginY, int a_OriginZ,
cNoise & a_Noise, int a_NumSegments
)
{
@@ -727,7 +726,7 @@ int cStructGenWormNestCaves::cCaveSystem::GetRadius(cNoise & a_Noise, int a_Orig
// We want mapping 384 -> 3, 0 -> 19, 768 -> 19, so divide by 24 to get [0 .. 31] with center at 16, then use abs() to fold around the center
int res = 3 + abs((sum / 24) - 16);
*/
-
+
// Algorithm of choice: random value in the range of zero to random value - heavily towards zero
int res = MIN_RADIUS + (rnd >> 8) % ((rnd % (MAX_RADIUS - MIN_RADIUS)) + 1);
return res;
@@ -815,7 +814,7 @@ void cStructGenWormNestCaves::GetCavesForChunk(int a_ChunkX, int a_ChunkZ, cStru
++itr;
}
} // for itr - m_Cache[]
-
+
for (int x = 0; x < NEIGHBORHOOD_SIZE; x++)
{
int RealX = (BaseX + x) * m_Grid;
@@ -837,11 +836,11 @@ void cStructGenWormNestCaves::GetCavesForChunk(int a_ChunkX, int a_ChunkZ, cStru
}
}
}
-
+
// Copy a_Caves into m_Cache to the beginning:
cCaveSystems CavesCopy(a_Caves);
m_Cache.splice(m_Cache.begin(), CavesCopy, CavesCopy.begin(), CavesCopy.end());
-
+
// Trim the cache if it's too long:
if (m_Cache.size() > 100)
{
@@ -855,7 +854,7 @@ void cStructGenWormNestCaves::GetCavesForChunk(int a_ChunkX, int a_ChunkZ, cStru
std::advance(itr, 100);
m_Cache.erase(itr, m_Cache.end());
}
-
+
/*
// Uncomment this block for debugging the caves' shapes in 2D using an SVG export
#ifdef _DEBUG
@@ -869,7 +868,7 @@ void cStructGenWormNestCaves::GetCavesForChunk(int a_ChunkX, int a_ChunkZ, cStru
SVG.append((*itr)->ExportAsSVG(Color, 512, 512));
}
SVG.append("</svg>\n");
-
+
AString fnam;
Printf(fnam, "wnc\\%03d_%03d.svg", a_ChunkX, a_ChunkZ);
cFile File(fnam, cFile::fmWrite);
@@ -905,13 +904,13 @@ static float GetMarbleNoise( float x, float y, float z, cNoise & a_Noise )
void cStructGenMarbleCaves::GenStructures(cChunkDesc & a_ChunkDesc)
{
cNoise Noise(m_Seed);
- for (int z = 0; z < cChunkDef::Width; z++)
+ for (int z = 0; z < cChunkDef::Width; z++)
{
const float zz = (float)(a_ChunkDesc.GetChunkZ() * cChunkDef::Width + z);
for (int x = 0; x < cChunkDef::Width; x++)
{
const float xx = (float)(a_ChunkDesc.GetChunkX() * cChunkDef::Width + x);
-
+
int Top = a_ChunkDesc.GetHeight(x, z);
for (int y = 1; y < Top; ++y )
{
@@ -940,18 +939,17 @@ void cStructGenMarbleCaves::GenStructures(cChunkDesc & a_ChunkDesc)
void cStructGenDualRidgeCaves::GenStructures(cChunkDesc & a_ChunkDesc)
{
- for (int z = 0; z < cChunkDef::Width; z++)
+ for (int z = 0; z < cChunkDef::Width; z++)
{
const float zz = (float)(a_ChunkDesc.GetChunkZ() * cChunkDef::Width + z) / 10;
for (int x = 0; x < cChunkDef::Width; x++)
{
const float xx = (float)(a_ChunkDesc.GetChunkX() * cChunkDef::Width + x) / 10;
-
+
int Top = a_ChunkDesc.GetHeight(x, z);
for (int y = 1; y <= Top; ++y)
{
const float yy = (float)y / 10;
- const float WaveNoise = 1;
float n1 = m_Noise1.CubicNoise3D(xx, yy, zz);
float n2 = m_Noise2.CubicNoise3D(xx, yy, zz);
float n3 = m_Noise1.CubicNoise3D(xx * 4, yy * 4, zz * 4) / 4;
diff --git a/src/Generating/ChunkDesc.cpp b/src/Generating/ChunkDesc.cpp
index 9fb306996..6050430fd 100644
--- a/src/Generating/ChunkDesc.cpp
+++ b/src/Generating/ChunkDesc.cpp
@@ -271,7 +271,7 @@ void cChunkDesc::ReadBlockArea(cBlockArea & a_Dest, int a_MinRelX, int a_MaxRelX
a_MaxRelX += 1;
a_MaxRelY += 1;
a_MaxRelZ += 1;
-
+
// Check coords validity:
if (a_MinRelX < 0)
{
@@ -314,7 +314,7 @@ void cChunkDesc::ReadBlockArea(cBlockArea & a_Dest, int a_MinRelX, int a_MaxRelX
LOGWARNING("%s: MaxRelY more than chunk height, adjusting to chunk height", __FUNCTION__);
a_MaxRelY = cChunkDef::Height - 1;
}
-
+
if (a_MinRelZ < 0)
{
LOGWARNING("%s: MinRelZ less than zero, adjusting to zero", __FUNCTION__);
@@ -371,7 +371,7 @@ void cChunkDesc::ReadBlockArea(cBlockArea & a_Dest, int a_MinRelX, int a_MaxRelX
HEIGHTTYPE cChunkDesc::GetMaxHeight(void) const
{
HEIGHTTYPE MaxHeight = m_HeightMap[0];
- for (int i = 1; i < ARRAYCOUNT(m_HeightMap); i++)
+ for (unsigned int i = 1; i < ARRAYCOUNT(m_HeightMap); i++)
{
if (m_HeightMap[i] > MaxHeight)
{
@@ -398,7 +398,7 @@ void cChunkDesc::FillRelCuboid(
int MaxX = std::min(a_MaxX, cChunkDef::Width - 1);
int MaxY = std::min(a_MaxY, cChunkDef::Height - 1);
int MaxZ = std::min(a_MaxZ, cChunkDef::Width - 1);
-
+
for (int y = MinY; y <= MaxY; y++)
{
for (int z = MinZ; z <= MaxZ; z++)
@@ -429,7 +429,7 @@ void cChunkDesc::ReplaceRelCuboid(
int MaxX = std::min(a_MaxX, cChunkDef::Width - 1);
int MaxY = std::min(a_MaxY, cChunkDef::Height - 1);
int MaxZ = std::min(a_MaxZ, cChunkDef::Width - 1);
-
+
for (int y = MinY; y <= MaxY; y++)
{
for (int z = MinZ; z <= MaxZ; z++)
@@ -465,7 +465,7 @@ void cChunkDesc::FloorRelCuboid(
int MaxX = std::min(a_MaxX, cChunkDef::Width - 1);
int MaxY = std::min(a_MaxY, cChunkDef::Height - 1);
int MaxZ = std::min(a_MaxZ, cChunkDef::Width - 1);
-
+
for (int y = MinY; y <= MaxY; y++)
{
for (int z = MinZ; z <= MaxZ; z++)
@@ -506,7 +506,7 @@ void cChunkDesc::RandomFillRelCuboid(
int MaxX = std::min(a_MaxX, cChunkDef::Width - 1);
int MaxY = std::min(a_MaxY, cChunkDef::Height - 1);
int MaxZ = std::min(a_MaxZ, cChunkDef::Width - 1);
-
+
for (int y = MinY; y <= MaxY; y++)
{
for (int z = MinZ; z <= MaxZ; z++)
@@ -565,7 +565,7 @@ cBlockEntity * cChunkDesc::GetBlockEntity(int a_RelX, int a_RelY, int a_RelZ)
void cChunkDesc::CompressBlockMetas(cChunkDef::BlockNibbles & a_DestMetas)
{
const NIBBLETYPE * AreaMetas = m_BlockArea.GetBlockMetas();
- for (int i = 0; i < ARRAYCOUNT(a_DestMetas); i++)
+ for (unsigned int i = 0; i < ARRAYCOUNT(a_DestMetas); i++)
{
a_DestMetas[i] = AreaMetas[2 * i] | (AreaMetas[2 * i + 1] << 4);
}
diff --git a/src/Generating/ChunkGenerator.cpp b/src/Generating/ChunkGenerator.cpp
index 59a00b540..33c956eba 100644
--- a/src/Generating/ChunkGenerator.cpp
+++ b/src/Generating/ChunkGenerator.cpp
@@ -15,10 +15,10 @@
/// If the generation queue size exceeds this number, a warning will be output
-const int QUEUE_WARNING_LIMIT = 1000;
+const unsigned int QUEUE_WARNING_LIMIT = 1000;
/// If the generation queue size exceeds this number, chunks with no clients will be skipped
-const int QUEUE_SKIP_LIMIT = 500;
+const unsigned int QUEUE_SKIP_LIMIT = 500;
@@ -53,7 +53,7 @@ bool cChunkGenerator::Start(cWorld * a_World, cIniFile & a_IniFile)
m_World = a_World;
m_Seed = a_IniFile.GetValueSetI("Seed", "Seed", rnd.randInt());
AString GeneratorName = a_IniFile.GetValueSet("Generator", "Generator", "Composable");
-
+
if (NoCaseCompare(GeneratorName, "Noise3D") == 0)
{
m_Generator = new cNoise3DGenerator(*this);
@@ -72,9 +72,9 @@ bool cChunkGenerator::Start(cWorld * a_World, cIniFile & a_IniFile)
LOGERROR("Generator could not start, aborting the server");
return false;
}
-
+
m_Generator->Initialize(a_World, a_IniFile);
-
+
return super::Start();
}
@@ -101,7 +101,7 @@ void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkY, int a_Chunk
{
{
cCSLock Lock(m_CS);
-
+
// Check if it is already in the queue:
for (cChunkCoordsList::iterator itr = m_Queue.begin(); itr != m_Queue.end(); ++itr)
{
@@ -111,7 +111,7 @@ void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkY, int a_Chunk
return;
}
} // for itr - m_Queue[]
-
+
// Add to queue, issue a warning if too many:
if (m_Queue.size() >= QUEUE_WARNING_LIMIT)
{
@@ -119,7 +119,7 @@ void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkY, int a_Chunk
}
m_Queue.push_back(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ));
}
-
+
m_Event.Set();
}
@@ -196,7 +196,7 @@ void cChunkGenerator::Execute(void)
int NumChunksGenerated = 0; // Number of chunks generated since the queue was last empty
clock_t GenerationStart = clock(); // Clock tick when the queue started to fill
clock_t LastReportTick = clock(); // Clock tick of the last report made (so that performance isn't reported too often)
-
+
while (!m_ShouldTerminate)
{
cCSLock Lock(m_CS);
@@ -219,7 +219,7 @@ void cChunkGenerator::Execute(void)
GenerationStart = clock();
LastReportTick = clock();
}
-
+
cChunkCoords coords = m_Queue.front(); // Get next coord from queue
m_Queue.erase( m_Queue.begin() ); // Remove coordinate from queue
bool SkipEnabled = (m_Queue.size() > QUEUE_SKIP_LIMIT);
@@ -243,19 +243,19 @@ void cChunkGenerator::Execute(void)
// Already generated, ignore request
continue;
}
-
+
if (SkipEnabled && !m_World->HasChunkAnyClients(coords.m_ChunkX, coords.m_ChunkZ))
{
LOGWARNING("Chunk generator overloaded, skipping chunk [%d, %d]", coords.m_ChunkX, coords.m_ChunkZ);
continue;
}
-
+
LOGD("Generating chunk [%d, %d, %d]", coords.m_ChunkX, coords.m_ChunkY, coords.m_ChunkZ);
DoGenerate(coords.m_ChunkX, coords.m_ChunkY, coords.m_ChunkZ);
-
+
// Save the chunk right after generating, so that we don't have to generate it again on next run
m_World->GetStorage().QueueSaveChunk(coords.m_ChunkX, coords.m_ChunkY, coords.m_ChunkZ);
-
+
NumChunksGenerated++;
} // while (!bStop)
}
@@ -269,17 +269,17 @@ void cChunkGenerator::DoGenerate(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
cRoot::Get()->GetPluginManager()->CallHookChunkGenerating(m_World, a_ChunkX, a_ChunkZ, &ChunkDesc);
m_Generator->DoGenerate(a_ChunkX, a_ChunkZ, ChunkDesc);
cRoot::Get()->GetPluginManager()->CallHookChunkGenerated(m_World, a_ChunkX, a_ChunkZ, &ChunkDesc);
-
+
#ifdef _DEBUG
// Verify that the generator has produced valid data:
ChunkDesc.VerifyHeightmap();
#endif
-
+
cChunkDef::BlockNibbles BlockMetas;
ChunkDesc.CompressBlockMetas(BlockMetas);
-
+
m_World->SetChunkData(
- a_ChunkX, a_ChunkZ,
+ a_ChunkX, a_ChunkZ,
ChunkDesc.GetBlockTypes(), BlockMetas,
NULL, NULL, // We don't have lighting, chunk will be lighted when needed
&ChunkDesc.GetHeightMap(), &ChunkDesc.GetBiomeMap(),
diff --git a/src/Generating/DistortedHeightmap.cpp b/src/Generating/DistortedHeightmap.cpp
index 98eab31b5..7e46c251e 100644
--- a/src/Generating/DistortedHeightmap.cpp
+++ b/src/Generating/DistortedHeightmap.cpp
@@ -30,7 +30,7 @@ const cDistortedHeightmap::sGenParam cDistortedHeightmap::m_GenParam[biNumBiomes
/* biExtremeHills */ {16.0f, 16.0f},
/* biForest */ { 3.0f, 3.0f},
/* biTaiga */ { 1.5f, 1.5f},
-
+
/* biSwampland */ { 0.0f, 0.0f},
/* biRiver */ { 0.0f, 0.0f},
/* biNether */ { 0.0f, 0.0f}, // Unused, but must be here due to indexing
@@ -81,7 +81,7 @@ void cDistortedHeightmap::Initialize(cIniFile & a_IniFile)
{
return;
}
-
+
// Read the params from the INI file:
m_SeaLevel = a_IniFile.GetValueSetI("Generator", "DistortedHeightmapSeaLevel", 62);
m_FrequencyX = (NOISE_DATATYPE)a_IniFile.GetValueSetF("Generator", "DistortedHeightmapFrequencyX", 10);
@@ -103,8 +103,8 @@ void cDistortedHeightmap::PrepareState(int a_ChunkX, int a_ChunkZ)
}
m_CurChunkX = a_ChunkX;
m_CurChunkZ = a_ChunkZ;
-
-
+
+
m_HeightGen.GenHeightMap(a_ChunkX, a_ChunkZ, m_CurChunkHeights);
UpdateDistortAmps();
GenerateHeightArray();
@@ -126,13 +126,13 @@ void cDistortedHeightmap::GenerateHeightArray(void)
NOISE_DATATYPE EndY = ((NOISE_DATATYPE)(257)) / m_FrequencyY;
NOISE_DATATYPE StartZ = ((NOISE_DATATYPE)(m_CurChunkZ * cChunkDef::Width)) / m_FrequencyZ;
NOISE_DATATYPE EndZ = ((NOISE_DATATYPE)((m_CurChunkZ + 1) * cChunkDef::Width - 1)) / m_FrequencyZ;
-
+
m_NoiseDistortX.Generate3D(DistortNoiseX, DIM_X, DIM_Y, DIM_Z, StartX, EndX, StartY, EndY, StartZ, EndZ, Workspace);
m_NoiseDistortZ.Generate3D(DistortNoiseZ, DIM_X, DIM_Y, DIM_Z, StartX, EndX, StartY, EndY, StartZ, EndZ, Workspace);
// The distorted heightmap, before linear upscaling
NOISE_DATATYPE DistHei[DIM_X * DIM_Y * DIM_Z];
-
+
// Distort the heightmap using the distortion:
for (int z = 0; z < DIM_Z; z++)
{
@@ -151,7 +151,7 @@ void cDistortedHeightmap::GenerateHeightArray(void)
}
}
}
-
+
// Upscale the distorted heightmap into full dimensions:
LinearUpscale3DArray(
DistHei, DIM_X, DIM_Y, DIM_Z,
@@ -208,7 +208,7 @@ void cDistortedHeightmap::ComposeTerrain(cChunkDesc & a_ChunkDesc)
// Prepare the internal state for generating this chunk:
PrepareState(a_ChunkDesc.GetChunkX(), a_ChunkDesc.GetChunkZ());
-
+
// Compose:
a_ChunkDesc.FillBlocks(E_BLOCK_AIR, 0);
for (int z = 0; z < cChunkDef::Width; z++)
@@ -348,7 +348,7 @@ int cDistortedHeightmap::GetHeightmapAt(NOISE_DATATYPE a_X, NOISE_DATATYPE a_Z)
{
return cChunkDef::GetHeight(m_CurChunkHeights, RelX, RelZ);
}
-
+
// Ask the cache:
HEIGHTTYPE res = 0;
if (m_HeightGen.GetHeightAt(ChunkX, ChunkZ, RelX, RelZ, res))
@@ -356,7 +356,7 @@ int cDistortedHeightmap::GetHeightmapAt(NOISE_DATATYPE a_X, NOISE_DATATYPE a_Z)
// The height was in the cache
return res;
}
-
+
// The height is not in the cache, generate full heightmap and get it there:
cChunkDef::HeightMap Heightmap;
m_HeightGen.GenHeightMap(ChunkX, ChunkZ, Heightmap);
@@ -385,7 +385,7 @@ void cDistortedHeightmap::UpdateDistortAmps(void)
GetDistortAmpsAt(Biomes, x * INTERPOL_X, z * INTERPOL_Z, m_DistortAmpX[x + DIM_X * z], m_DistortAmpZ[x + DIM_X * z]);
}
}
-}
+}
@@ -430,7 +430,7 @@ void cDistortedHeightmap::GetDistortAmpsAt(BiomeNeighbors & a_Neighbors, int a_R
// For each biome type that has a nonzero count, calc its amps and add it:
NOISE_DATATYPE AmpX = 0;
NOISE_DATATYPE AmpZ = 0;
- for (int i = 0; i < ARRAYCOUNT(BiomeCounts); i++)
+ for (unsigned int i = 0; i < ARRAYCOUNT(BiomeCounts); i++)
{
AmpX += BiomeCounts[i] * m_GenParam[i].m_DistortAmpX;
AmpZ += BiomeCounts[i] * m_GenParam[i].m_DistortAmpZ;
diff --git a/src/Generating/EndGen.cpp b/src/Generating/EndGen.cpp
index 3eba5c47b..90a8071fa 100644
--- a/src/Generating/EndGen.cpp
+++ b/src/Generating/EndGen.cpp
@@ -18,7 +18,7 @@ enum
INTERPOL_X = 4,
INTERPOL_Y = 4,
INTERPOL_Z = 4,
-
+
// Size of chunk data, downscaled before interpolation:
DIM_X = 16 / INTERPOL_X + 1,
DIM_Y = 256 / INTERPOL_Y + 1,
@@ -59,7 +59,7 @@ void cEndGen::Initialize(cIniFile & a_IniFile)
m_FrequencyX = (NOISE_DATATYPE)a_IniFile.GetValueSetF("Generator", "EndGenFrequencyX", m_FrequencyX);
m_FrequencyY = (NOISE_DATATYPE)a_IniFile.GetValueSetF("Generator", "EndGenFrequencyY", m_FrequencyY);
m_FrequencyZ = (NOISE_DATATYPE)a_IniFile.GetValueSetF("Generator", "EndGenFrequencyZ", m_FrequencyZ);
-
+
// Recalculate the min and max chunk coords of the island
m_MaxChunkX = (m_IslandSizeX + cChunkDef::Width - 1) / cChunkDef::Width;
m_MinChunkX = -m_MaxChunkX;
@@ -75,15 +75,15 @@ void cEndGen::Initialize(cIniFile & a_IniFile)
void cEndGen::PrepareState(int a_ChunkX, int a_ChunkZ)
{
ASSERT(!IsChunkOutsideRange(a_ChunkX, a_ChunkZ)); // Should be filtered before calling this function
-
+
if ((m_LastChunkX == a_ChunkX) && (m_LastChunkZ == a_ChunkZ))
{
return;
}
-
+
m_LastChunkX = a_ChunkX;
m_LastChunkZ = a_ChunkZ;
-
+
GenerateNoiseArray();
}
@@ -96,7 +96,7 @@ void cEndGen::GenerateNoiseArray(void)
{
NOISE_DATATYPE NoiseData[DIM_X * DIM_Y * DIM_Z]; // [x + DIM_X * z + DIM_X * DIM_Z * y]
NOISE_DATATYPE Workspace[DIM_X * DIM_Y * DIM_Z]; // [x + DIM_X * z + DIM_X * DIM_Z * y]
-
+
// Generate the downscaled noise:
NOISE_DATATYPE StartX = ((NOISE_DATATYPE)(m_LastChunkX * cChunkDef::Width)) / m_FrequencyX;
NOISE_DATATYPE EndX = ((NOISE_DATATYPE)((m_LastChunkX + 1) * cChunkDef::Width)) / m_FrequencyX;
@@ -105,7 +105,7 @@ void cEndGen::GenerateNoiseArray(void)
NOISE_DATATYPE StartY = 0;
NOISE_DATATYPE EndY = ((NOISE_DATATYPE)257) / m_FrequencyY;
m_Perlin.Generate3D(NoiseData, DIM_X, DIM_Z, DIM_Y, StartX, EndX, StartZ, EndZ, StartY, EndY, Workspace);
-
+
// Add distance:
int idx = 0;
for (int y = 0; y < DIM_Y; y++)
@@ -125,7 +125,7 @@ void cEndGen::GenerateNoiseArray(void)
} // for x
} // for z
} // for y
-
+
// Upscale into real chunk size:
LinearUpscale3DArray(NoiseData, DIM_X, DIM_Z, DIM_Y, m_NoiseArray, INTERPOL_X, INTERPOL_Z, INTERPOL_Y);
}
@@ -133,14 +133,14 @@ void cEndGen::GenerateNoiseArray(void)
-
+
/// Returns true if the chunk is outside of the island's dimensions
bool cEndGen::IsChunkOutsideRange(int a_ChunkX, int a_ChunkZ)
{
return (
(a_ChunkX < m_MinChunkX) || (a_ChunkX > m_MaxChunkX) ||
(a_ChunkZ < m_MinChunkZ) || (a_ChunkZ > m_MaxChunkZ)
- );
+ );
}
@@ -151,15 +151,15 @@ void cEndGen::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_
{
if (IsChunkOutsideRange(a_ChunkX, a_ChunkZ))
{
- for (int i = 0; i < ARRAYCOUNT(a_HeightMap); i++)
+ for (unsigned int i = 0; i < ARRAYCOUNT(a_HeightMap); i++)
{
a_HeightMap[i] = 0;
}
return;
}
-
+
PrepareState(a_ChunkX, a_ChunkZ);
-
+
int MaxY = std::min((int)(1.75 * m_IslandSizeY + 1), cChunkDef::Height - 1);
for (int z = 0; z < cChunkDef::Width; z++)
{
@@ -189,9 +189,9 @@ void cEndGen::ComposeTerrain(cChunkDesc & a_ChunkDesc)
a_ChunkDesc.FillBlocks(E_BLOCK_AIR, 0);
return;
}
-
+
PrepareState(a_ChunkDesc.GetChunkX(), a_ChunkDesc.GetChunkZ());
-
+
int MaxY = std::min((int)(1.75 * m_IslandSizeY + 1), cChunkDef::Height - 1);
for (int z = 0; z < cChunkDef::Width; z++)
{
diff --git a/src/Generating/MineShafts.cpp b/src/Generating/MineShafts.cpp
index 159e6b4ea..f42240e55 100644
--- a/src/Generating/MineShafts.cpp
+++ b/src/Generating/MineShafts.cpp
@@ -41,8 +41,8 @@ public:
mskCrossing,
mskStaircase,
} ;
-
-
+
+
enum eDirection
{
dirXP,
@@ -50,8 +50,8 @@ public:
dirXM,
dirZM,
} ;
-
-
+
+
cStructGenMineShafts::cMineShaftSystem & m_ParentSystem;
eKind m_Kind;
cCuboid m_BoundingBox;
@@ -62,25 +62,25 @@ public:
m_Kind(a_Kind)
{
}
-
+
cMineShaft(cStructGenMineShafts::cMineShaftSystem & a_ParentSystem, eKind a_Kind, const cCuboid & a_BoundingBox) :
m_ParentSystem(a_ParentSystem),
m_Kind(a_Kind),
m_BoundingBox(a_BoundingBox)
{
}
-
+
/// Returns true if this mineshaft intersects the specified cuboid
bool DoesIntersect(const cCuboid & a_Other)
{
return m_BoundingBox.DoesIntersect(a_Other);
}
-
+
/** If recursion level is not too large, appends more branches to the parent system,
using exit points specific to this class.
*/
virtual void AppendBranches(int a_RecursionLevel, cNoise & a_Noise) = 0;
-
+
/// Imprints this shape into the specified chunk's data
virtual void ProcessChunk(cChunkDesc & a_ChunkDesc) = 0;
} ;
@@ -95,10 +95,10 @@ class cMineShaftDirtRoom :
public cMineShaft
{
typedef cMineShaft super;
-
+
public:
cMineShaftDirtRoom(cStructGenMineShafts::cMineShaftSystem & a_Parent, cNoise & a_Noise);
-
+
// cMineShaft overrides:
virtual void AppendBranches(int a_RecursionLevel, cNoise & a_Noise) override;
virtual void ProcessChunk(cChunkDesc & a_ChunkDesc) override;
@@ -112,7 +112,7 @@ class cMineShaftCorridor :
public cMineShaft
{
typedef cMineShaft super;
-
+
public:
/** Creates a new Corridor attached to the specified pivot point and direction.
Checks all ParentSystem's objects and disallows intersecting. Initializes the new object to fit.
@@ -123,36 +123,36 @@ public:
int a_PivotX, int a_PivotY, int a_PivotZ, eDirection a_Direction,
cNoise & a_Noise
);
-
+
protected:
static const int MAX_SEGMENTS = 5;
-
+
int m_NumSegments;
eDirection m_Direction;
bool m_HasFullBeam[MAX_SEGMENTS]; ///< If true, segment at that index has a full beam support (planks in the top center block)
int m_ChestPosition; ///< If <0, no chest; otherwise an offset from m_BoundingBox's p1.x or p1.z, depenging on m_Direction
int m_SpawnerPosition; ///< If <0, no spawner; otherwise an offset from m_BoundingBox's p1.x or p1.z, depenging on m_Direction
bool m_HasTracks; ///< If true, random tracks will be placed on the floor
-
+
cMineShaftCorridor(
cStructGenMineShafts::cMineShaftSystem & a_ParentSystem,
const cCuboid & a_BoundingBox, int a_NumSegments, eDirection a_Direction,
cNoise & a_Noise
);
-
+
// cMineShaft overrides:
virtual void AppendBranches(int a_RecursionLevel, cNoise & a_Noise) override;
virtual void ProcessChunk(cChunkDesc & a_ChunkDesc) override;
/// Places a chest, if the corridor has one
void PlaceChest(cChunkDesc & a_ChunkDesc);
-
+
/// If this corridor has tracks, places them randomly
void PlaceTracks(cChunkDesc & a_ChunkDesc);
-
+
/// If this corridor has a spawner, places the spawner
void PlaceSpawner(cChunkDesc & a_ChunkDesc);
-
+
/// Randomly places torches around the central beam block
void PlaceTorches(cChunkDesc & a_ChunkDesc);
} ;
@@ -165,7 +165,7 @@ class cMineShaftCrossing :
public cMineShaft
{
typedef cMineShaft super;
-
+
public:
/** Creates a new Crossing attached to the specified pivot point and direction.
Checks all ParentSystem's objects and disallows intersecting. Initializes the new object to fit.
@@ -176,10 +176,10 @@ public:
int a_PivotX, int a_PivotY, int a_PivotZ, eDirection a_Direction,
cNoise & a_Noise
);
-
+
protected:
cMineShaftCrossing(cStructGenMineShafts::cMineShaftSystem & a_ParentSystem, const cCuboid & a_BoundingBox);
-
+
// cMineShaft overrides:
virtual void AppendBranches(int a_RecursionLevel, cNoise & a_Noise) override;
virtual void ProcessChunk(cChunkDesc & a_ChunkDesc) override;
@@ -193,14 +193,14 @@ class cMineShaftStaircase :
public cMineShaft
{
typedef cMineShaft super;
-
+
public:
enum eSlope
{
sUp,
sDown,
} ;
-
+
/** Creates a new Staircase attached to the specified pivot point and direction.
Checks all ParentSystem's objects and disallows intersecting. Initializes the new object to fit.
May return NULL if cannot fit.
@@ -210,12 +210,12 @@ public:
int a_PivotX, int a_PivotY, int a_PivotZ, eDirection a_Direction,
cNoise & a_Noise
);
-
+
protected:
eDirection m_Direction;
eSlope m_Slope;
-
-
+
+
cMineShaftStaircase(
cStructGenMineShafts::cMineShaftSystem & a_ParentSystem,
const cCuboid & a_BoundingBox,
@@ -257,7 +257,7 @@ public:
/// Carves the system into the chunk data
void ProcessChunk(cChunkDesc & a_Chunk);
-
+
/** Creates new cMineShaft descendant connected at the specified point, heading the specified direction,
if it fits, appends it to the list and calls its AppendBranches()
*/
@@ -266,7 +266,7 @@ public:
cMineShaft::eDirection a_Direction, cNoise & a_Noise,
int a_RecursionLevel
);
-
+
/// Returns true if none of the objects in m_MineShafts intersect with the specified bounding box and the bounding box is valid
bool CanAppend(const cCuboid & a_BoundingBox);
} ;
@@ -294,7 +294,7 @@ cStructGenMineShafts::cMineShaftSystem::cMineShaftSystem(
m_ChanceTorch(1000) // TODO: settable
{
m_MineShafts.reserve(100);
-
+
cMineShaft * Start = new cMineShaftDirtRoom(*this, a_Noise);
m_MineShafts.push_back(Start);
@@ -302,9 +302,9 @@ cStructGenMineShafts::cMineShaftSystem::cMineShaftSystem(
Start->m_BoundingBox.p1.x - a_MaxSystemSize / 2, 2, Start->m_BoundingBox.p1.z - a_MaxSystemSize / 2,
Start->m_BoundingBox.p2.x + a_MaxSystemSize / 2, 50, Start->m_BoundingBox.p2.z + a_MaxSystemSize / 2
);
-
+
Start->AppendBranches(0, a_Noise);
-
+
for (cMineShafts::const_iterator itr = m_MineShafts.begin(), end = m_MineShafts.end(); itr != end; ++itr)
{
ASSERT((*itr)->m_BoundingBox.IsSorted());
@@ -341,7 +341,7 @@ void cStructGenMineShafts::cMineShaftSystem::ProcessChunk(cChunkDesc & a_Chunk)
void cStructGenMineShafts::cMineShaftSystem::AppendBranch(
- int a_PivotX, int a_PivotY, int a_PivotZ,
+ int a_PivotX, int a_PivotY, int a_PivotZ,
cMineShaft::eDirection a_Direction, cNoise & a_Noise,
int a_RecursionLevel
)
@@ -350,7 +350,7 @@ void cStructGenMineShafts::cMineShaftSystem::AppendBranch(
{
return;
}
-
+
cMineShaft * Next = NULL;
int rnd = (a_Noise.IntNoise3DInt(a_PivotX, a_PivotY + a_RecursionLevel * 16, a_PivotZ) / 13) % m_ProbLevelStaircase;
if (rnd < m_ProbLevelCorridor)
@@ -384,7 +384,7 @@ bool cStructGenMineShafts::cMineShaftSystem::CanAppend(const cCuboid & a_Boundin
// Too far away, or too low / too high
return false;
}
-
+
// Check intersections:
for (cMineShafts::const_iterator itr = m_MineShafts.begin(), end = m_MineShafts.end(); itr != end; ++itr)
{
@@ -436,7 +436,7 @@ void cMineShaftDirtRoom::AppendBranches(int a_RecursionLevel, cNoise & a_Noise)
rnd >>= 4;
m_ParentSystem.AppendBranch(x, m_BoundingBox.p1.y + (rnd % Height), m_BoundingBox.p2.z + 1, dirZP, a_Noise, a_RecursionLevel);
}
-
+
for (int z = m_BoundingBox.p1.z + 1; z < m_BoundingBox.p2.z; z += 4)
{
int rnd = a_Noise.IntNoise3DInt(m_BoundingBox.p1.x, a_RecursionLevel, z) / 13;
@@ -464,13 +464,13 @@ void cMineShaftDirtRoom::ProcessChunk(cChunkDesc & a_ChunkDesc)
// Early bailout - cannot intersect this chunk
return;
}
-
+
// Chunk-relative coords of the boundaries:
int MinX = std::max(BlockX, m_BoundingBox.p1.x) - BlockX;
int MaxX = std::min(BlockX + cChunkDef::Width, m_BoundingBox.p2.x + 1) - BlockX;
int MinZ = std::max(BlockZ, m_BoundingBox.p1.z) - BlockZ;
int MaxZ = std::min(BlockZ + cChunkDef::Width, m_BoundingBox.p2.z + 1) - BlockZ;
-
+
// Carve the room out:
for (int z = MinZ; z < MaxZ; z++)
{
@@ -513,7 +513,7 @@ cMineShaftCorridor::cMineShaftCorridor(
rnd >>= 2;
}
m_HasTracks = ((rnd % 4) < 2); // 50 % chance of tracks
-
+
rnd = a_Noise.IntNoise3DInt(a_BoundingBox.p1.z, a_BoundingBox.p1.x, a_BoundingBox.p1.y) / 7;
int ChestCheck = rnd % 250;
rnd >>= 8;
@@ -597,7 +597,7 @@ void cMineShaftCorridor::AppendBranches(int a_RecursionLevel, cNoise & a_Noise)
}
break;
}
-
+
case dirZM:
{
m_ParentSystem.AppendBranch(m_BoundingBox.p1.x + 1, Height, m_BoundingBox.p1.z - 1, dirZM, a_Noise, a_RecursionLevel);
@@ -646,14 +646,14 @@ void cMineShaftCorridor::ProcessChunk(cChunkDesc & a_ChunkDesc)
Top.p2.y += 1;
Top.p1.y = Top.p2.y;
a_ChunkDesc.FillRelCuboid(RelBoundingBox, E_BLOCK_AIR, 0);
- a_ChunkDesc.RandomFillRelCuboid(Top, E_BLOCK_AIR, 0, BlockX ^ BlockZ + BlockX, 8000);
+ a_ChunkDesc.RandomFillRelCuboid(Top, E_BLOCK_AIR, 0, (BlockX ^ (BlockZ + BlockX)), 8000);
if (m_SpawnerPosition >= 0)
{
// Cobwebs around the spider spawner
- a_ChunkDesc.RandomFillRelCuboid(RelBoundingBox, E_BLOCK_COBWEB, 0, BlockX ^ BlockZ + BlockZ, 8000);
- a_ChunkDesc.RandomFillRelCuboid(Top, E_BLOCK_COBWEB, 0, BlockX ^ BlockZ + BlockX, 5000);
+ a_ChunkDesc.RandomFillRelCuboid(RelBoundingBox, E_BLOCK_COBWEB, 0, (BlockX ^ (BlockZ + BlockZ)), 8000);
+ a_ChunkDesc.RandomFillRelCuboid(Top, E_BLOCK_COBWEB, 0, (BlockX ^ (BlockZ + BlockX)), 5000);
}
- a_ChunkDesc.RandomFillRelCuboid(Top, E_BLOCK_COBWEB, 0, BlockX ^ BlockZ + BlockX + 10, 500);
+ a_ChunkDesc.RandomFillRelCuboid(Top, E_BLOCK_COBWEB, 0, (BlockX ^ (BlockZ + BlockX + 10)), 500);
RelBoundingBox.p1.y = m_BoundingBox.p1.y;
RelBoundingBox.p2.y = m_BoundingBox.p1.y;
a_ChunkDesc.FloorRelCuboid(RelBoundingBox, E_BLOCK_PLANKS, 0);
@@ -693,7 +693,7 @@ void cMineShaftCorridor::ProcessChunk(cChunkDesc & a_ChunkDesc)
} // for i - NumSegments
break;
}
-
+
case dirZM:
case dirZP:
{
@@ -729,7 +729,7 @@ void cMineShaftCorridor::ProcessChunk(cChunkDesc & a_ChunkDesc)
break;
} // case dirZ?
} // for i
-
+
PlaceChest(a_ChunkDesc);
PlaceTracks(a_ChunkDesc);
PlaceSpawner(a_ChunkDesc); // (must be after Tracks!)
@@ -762,7 +762,7 @@ void cMineShaftCorridor::PlaceChest(cChunkDesc & a_ChunkDesc)
{
return;
}
-
+
int BlockX = a_ChunkDesc.GetChunkX() * cChunkDef::Width;
int BlockZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width;
int x, z;
@@ -777,9 +777,10 @@ void cMineShaftCorridor::PlaceChest(cChunkDesc & a_ChunkDesc)
Meta = E_META_CHEST_FACING_ZP;
break;
}
-
+
case dirZM:
case dirZP:
+ default:
{
x = m_BoundingBox.p1.x - BlockX;
z = m_BoundingBox.p1.z + m_ChestPosition - BlockZ;
@@ -829,7 +830,7 @@ void cMineShaftCorridor::PlaceTracks(cChunkDesc & a_ChunkDesc)
Meta = E_META_TRACKS_X;
break;
}
-
+
case dirZM:
case dirZP:
{
@@ -921,7 +922,7 @@ void cMineShaftCorridor::PlaceTorches(cChunkDesc & a_ChunkDesc)
} // for i
break;
}
-
+
case dirZM:
case dirZP:
{
@@ -1034,14 +1035,14 @@ void cMineShaftCrossing::AppendBranches(int a_RecursionLevel, cNoise & a_Noise)
{ 5, 5, 2, dirXP},
{ 2, 5, 5, dirZP},
} ;
- for (int i = 0; i < ARRAYCOUNT(Exits); i++)
+ for (unsigned int i = 0; i < ARRAYCOUNT(Exits); i++)
{
if (m_BoundingBox.p1.y + Exits[i].y >= m_BoundingBox.p2.y)
{
// This exit is not available (two-level exit on a one-level crossing)
continue;
}
-
+
int Height = m_BoundingBox.p1.y + Exits[i].y;
m_ParentSystem.AppendBranch(m_BoundingBox.p1.x + Exits[i].x, Height, m_BoundingBox.p1.z + Exits[i].z, Exits[i].dir, a_Noise, a_RecursionLevel);
} // for i
@@ -1089,7 +1090,7 @@ void cMineShaftCrossing::ProcessChunk(cChunkDesc & a_ChunkDesc)
a_ChunkDesc.FillRelCuboid(box.p1.x + 1, box.p2.x - 1, Mid, Ceil, box.p1.z, box.p1.z, E_BLOCK_AIR, 0);
a_ChunkDesc.FillRelCuboid(box.p1.x + 1, box.p2.x - 1, Mid, Ceil, box.p2.z, box.p2.z, E_BLOCK_AIR, 0);
}
-
+
// The floor, if needed:
box.p2.y = box.p1.y;
a_ChunkDesc.FloorRelCuboid(box, E_BLOCK_PLANKS, 0);
@@ -1198,7 +1199,7 @@ void cMineShaftStaircase::ProcessChunk(cChunkDesc & a_ChunkDesc)
// No intersection between this staircase and this chunk
return;
}
-
+
int SFloor = RelB.p1.y + ((m_Slope == sDown) ? 5 : 1);
int DFloor = RelB.p1.y + ((m_Slope == sDown) ? 1 : 5);
int Add = (m_Slope == sDown) ? -1 : 1;
@@ -1221,7 +1222,7 @@ void cMineShaftStaircase::ProcessChunk(cChunkDesc & a_ChunkDesc)
}
break;
}
-
+
case dirXP:
{
a_ChunkDesc.FillRelCuboid (RelB.p1.x, RelB.p1.x + 1, SFloor, SFloor + 2, RelB.p1.z, RelB.p2.z, E_BLOCK_AIR, 0);
@@ -1253,7 +1254,7 @@ void cMineShaftStaircase::ProcessChunk(cChunkDesc & a_ChunkDesc)
}
break;
}
-
+
case dirZP:
{
a_ChunkDesc.FillRelCuboid (RelB.p1.x, RelB.p2.x, SFloor, SFloor + 2, RelB.p1.z, RelB.p1.z + 1, E_BLOCK_AIR, 0);
@@ -1269,7 +1270,7 @@ void cMineShaftStaircase::ProcessChunk(cChunkDesc & a_ChunkDesc)
}
break;
}
-
+
} // switch (m_Direction)
}
@@ -1359,7 +1360,7 @@ void cStructGenMineShafts::GetMineShaftSystemsForChunk(
++itr;
}
} // for itr - m_Cache[]
-
+
for (int x = 0; x < NEIGHBORHOOD_SIZE; x++)
{
int RealX = (BaseX + x) * m_GridSize;
@@ -1381,11 +1382,11 @@ void cStructGenMineShafts::GetMineShaftSystemsForChunk(
}
} // for z
} // for x
-
+
// Copy a_MineShafts into m_Cache to the beginning:
cMineShaftSystems MineShaftsCopy(a_MineShafts);
m_Cache.splice(m_Cache.begin(), MineShaftsCopy, MineShaftsCopy.begin(), MineShaftsCopy.end());
-
+
// Trim the cache if it's too long:
if (m_Cache.size() > 100)
{
diff --git a/src/Generating/Noise3DGenerator.cpp b/src/Generating/Noise3DGenerator.cpp
index f47c64430..03626a800 100644
--- a/src/Generating/Noise3DGenerator.cpp
+++ b/src/Generating/Noise3DGenerator.cpp
@@ -25,8 +25,8 @@ public:
DoTest1();
DoTest2();
}
-
-
+
+
void DoTest1(void)
{
float In[3 * 3 * 3];
@@ -39,8 +39,8 @@ public:
LinearUpscale3DArray(In, 3, 3, 3, Out, 8, 16, 17);
Debug3DNoise(Out, 17, 33, 35, "Upscale3D test");
}
-
-
+
+
void DoTest2(void)
{
float In[3 * 3];
@@ -53,7 +53,7 @@ public:
LinearUpscale2DArray(In, 3, 3, Out, 8, 16);
Debug2DNoise(Out, 17, 33, "Upscale2D test");
}
-
+
} gTest;
//*/
@@ -72,7 +72,7 @@ cNoise3DGenerator::cNoise3DGenerator(cChunkGenerator & a_ChunkGenerator) :
m_Perlin.AddOctave(1, (NOISE_DATATYPE)0.5);
m_Perlin.AddOctave((NOISE_DATATYPE)0.5, 1);
m_Perlin.AddOctave((NOISE_DATATYPE)0.5, 2);
-
+
#if 0
// DEBUG: Test the noise generation:
// NOTE: In order to be able to run MCS with this code, you need to increase the default thread stack size
@@ -84,7 +84,7 @@ cNoise3DGenerator::cNoise3DGenerator(cChunkGenerator & a_ChunkGenerator) :
m_FrequencyY = 4;
m_FrequencyZ = 4;
m_AirThreshold = 0.5;
-
+
const int NumChunks = 4;
NOISE_DATATYPE Noise[NumChunks][cChunkDef::Width * cChunkDef::Width * cChunkDef::Height];
for (int x = 0; x < NumChunks; x++)
@@ -153,7 +153,7 @@ cNoise3DGenerator::~cNoise3DGenerator()
void cNoise3DGenerator::Initialize(cWorld * a_World, cIniFile & a_IniFile)
{
m_World = a_World;
-
+
// Params:
m_SeaLevel = a_IniFile.GetValueSetI("Generator", "Noise3DSeaLevel", 62);
m_HeightAmplification = (NOISE_DATATYPE)a_IniFile.GetValueSetF("Generator", "Noise3DHeightAmplification", 0);
@@ -170,7 +170,7 @@ void cNoise3DGenerator::Initialize(cWorld * a_World, cIniFile & a_IniFile)
void cNoise3DGenerator::GenerateBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap)
{
- for (int i = 0; i < ARRAYCOUNT(a_BiomeMap); i++)
+ for (unsigned int i = 0; i < ARRAYCOUNT(a_BiomeMap); i++)
{
a_BiomeMap[i] = biExtremeHills;
}
@@ -184,7 +184,7 @@ void cNoise3DGenerator::DoGenerate(int a_ChunkX, int a_ChunkZ, cChunkDesc & a_Ch
{
NOISE_DATATYPE Noise[17 * 257 * 17];
GenerateNoiseArray(a_ChunkX, a_ChunkZ, Noise);
-
+
// Output noise into chunk:
for (int z = 0; z < cChunkDef::Width; z++)
{
@@ -207,7 +207,7 @@ void cNoise3DGenerator::DoGenerate(int a_ChunkX, int a_ChunkZ, cChunkDesc & a_Ch
}
}
}
-
+
UpdateHeightmap(a_ChunkDesc);
ComposeTerrain (a_ChunkDesc);
}
@@ -228,19 +228,19 @@ void cNoise3DGenerator::GenerateNoiseArray(int a_ChunkX, int a_ChunkZ, NOISE_DAT
NOISE_DATATYPE EndZ = ((NOISE_DATATYPE)((a_ChunkZ + 1) * cChunkDef::Width) - 1) / m_FrequencyZ;
NOISE_DATATYPE StartY = 0;
NOISE_DATATYPE EndY = ((NOISE_DATATYPE)256) / m_FrequencyY;
-
+
m_Perlin.Generate3D(NoiseO, DIM_X, DIM_Y, DIM_Z, StartX, EndX, StartY, EndY, StartZ, EndZ, NoiseW);
-
+
// DEBUG: Debug3DNoise(NoiseO, DIM_X, DIM_Y, DIM_Z, Printf("Chunk_%d_%d_orig", a_ChunkX, a_ChunkZ));
-
+
// Precalculate a "height" array:
NOISE_DATATYPE Height[DIM_X * DIM_Z]; // Output for the cubic noise heightmap ("source")
m_Cubic.Generate2D(Height, DIM_X, DIM_Z, StartX / 25, EndX / 25, StartZ / 25, EndZ / 25);
- for (int i = 0; i < ARRAYCOUNT(Height); i++)
+ for (unsigned int i = 0; i < ARRAYCOUNT(Height); i++)
{
Height[i] = abs(Height[i]) * m_HeightAmplification + 1;
}
-
+
// Modify the noise by height data:
for (int y = 0; y < DIM_Y; y++)
{
@@ -257,13 +257,13 @@ void cNoise3DGenerator::GenerateNoiseArray(int a_ChunkX, int a_ChunkZ, NOISE_DAT
}
// DEBUG: Debug3DNoise(NoiseO, DIM_X, DIM_Y, DIM_Z, Printf("Chunk_%d_%d_hei", a_ChunkX, a_ChunkZ));
-
+
// Upscale the Perlin noise into full-blown chunk dimensions:
LinearUpscale3DArray(
NoiseO, DIM_X, DIM_Y, DIM_Z,
a_OutNoise, UPSCALE_X, UPSCALE_Y, UPSCALE_Z
);
-
+
// DEBUG: Debug3DNoise(a_OutNoise, 17, 257, 17, Printf("Chunk_%d_%d_lerp", a_ChunkX, a_ChunkZ));
}
@@ -383,15 +383,11 @@ void cNoise3DComposable::GenerateNoiseArrayIfNeeded(int a_ChunkX, int a_ChunkZ)
}
m_LastChunkX = a_ChunkX;
m_LastChunkZ = a_ChunkZ;
-
+
// Upscaling parameters:
const int UPSCALE_X = 8;
const int UPSCALE_Y = 4;
const int UPSCALE_Z = 8;
-
- const int DIM_X = 1 + cChunkDef::Width / UPSCALE_X;
- const int DIM_Y = 1 + cChunkDef::Height / UPSCALE_Y;
- const int DIM_Z = 1 + cChunkDef::Width / UPSCALE_Z;
// Precalculate a "height" array:
NOISE_DATATYPE Height[17 * 17]; // x + 17 * z
@@ -405,8 +401,7 @@ void cNoise3DComposable::GenerateNoiseArrayIfNeeded(int a_ChunkX, int a_ChunkZ)
Height[x + 17 * z] = val * val * val;
}
}
-
- int idx = 0;
+
for (int y = 0; y < 257; y += UPSCALE_Y)
{
NOISE_DATATYPE NoiseY = ((NOISE_DATATYPE)y) / m_FrequencyY;
@@ -419,7 +414,7 @@ void cNoise3DComposable::GenerateNoiseArrayIfNeeded(int a_ChunkX, int a_ChunkZ)
for (int x = 0; x < 17; x += UPSCALE_X)
{
NOISE_DATATYPE NoiseX = ((NOISE_DATATYPE)(a_ChunkX * cChunkDef::Width + x)) / m_FrequencyX;
- CurFloor[x + 17 * z] =
+ CurFloor[x + 17 * z] =
m_Noise1.CubicNoise3D(NoiseX, NoiseY, NoiseZ) * (NOISE_DATATYPE)0.5 +
m_Noise2.CubicNoise3D(NoiseX / 2, NoiseY / 2, NoiseZ / 2) +
m_Noise3.CubicNoise3D(NoiseX / 4, NoiseY / 4, NoiseZ / 4) * 2 +
@@ -429,7 +424,7 @@ void cNoise3DComposable::GenerateNoiseArrayIfNeeded(int a_ChunkX, int a_ChunkZ)
// Linear-interpolate this XZ floor:
LinearUpscale2DArrayInPlace(CurFloor, 17, 17, UPSCALE_X, UPSCALE_Z);
}
-
+
// Finish the 3D linear interpolation by interpolating between each XZ-floors on the Y axis
for (int y = 1; y < cChunkDef::Height; y++)
{
@@ -455,7 +450,7 @@ void cNoise3DComposable::GenerateNoiseArrayIfNeeded(int a_ChunkX, int a_ChunkZ)
idx += 1; // Skipping one X column
}
}
-
+
// The noise array is now fully interpolated
/*
// DEBUG: Output two images of the array, sliced by XY and XZ:
@@ -504,7 +499,7 @@ void cNoise3DComposable::GenerateNoiseArrayIfNeeded(int a_ChunkX, int a_ChunkZ)
void cNoise3DComposable::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap)
{
GenerateNoiseArrayIfNeeded(a_ChunkX, a_ChunkZ);
-
+
for (int z = 0; z < cChunkDef::Width; z++)
{
for (int x = 0; x < cChunkDef::Width; x++)
@@ -529,9 +524,9 @@ void cNoise3DComposable::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::Hei
void cNoise3DComposable::ComposeTerrain(cChunkDesc & a_ChunkDesc)
{
GenerateNoiseArrayIfNeeded(a_ChunkDesc.GetChunkX(), a_ChunkDesc.GetChunkZ());
-
+
a_ChunkDesc.FillBlocks(E_BLOCK_AIR, 0);
-
+
// Make basic terrain composition:
for (int z = 0; z < cChunkDef::Width; z++)
{