1
0

Rewritten generators so that they use the cChunkDesc class (and thus can use cBlockArea merging)

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1282 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2013-03-17 17:55:03 +00:00
parent 3844523882
commit 1ed3b3aed2
16 changed files with 444 additions and 662 deletions

View File

@ -1,6 +1,6 @@
/* /*
** Lua binding: AllToLua ** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 03/14/13 10:02:26. ** Generated automatically by tolua++-1.0.92 on 03/17/13 18:47:08.
*/ */
#ifndef __cplusplus #ifndef __cplusplus
@ -347,9 +347,9 @@ static int tolua_AllToLua_cVine_DirectionToMetaData00(lua_State* tolua_S)
else else
#endif #endif
{ {
char a_Direction = ((char) tolua_tonumber(tolua_S,2,0)); char a_BlockFace = ((char) tolua_tonumber(tolua_S,2,0));
{ {
unsigned char tolua_ret = (unsigned char) cVine::DirectionToMetaData(a_Direction); unsigned char tolua_ret = (unsigned char) cVine::DirectionToMetaData(a_BlockFace);
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
} }
} }
@ -19595,6 +19595,105 @@ static int tolua_AllToLua_cBlockArea_HasBlockSkyLights00(lua_State* tolua_S)
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
/* method: GetChunkX of class cChunkDesc */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cChunkDesc_GetChunkX00
static int tolua_AllToLua_cChunkDesc_GetChunkX00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"const cChunkDesc",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
const cChunkDesc* self = (const cChunkDesc*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetChunkX'", NULL);
#endif
{
int tolua_ret = (int) self->GetChunkX();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'GetChunkX'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: GetChunkZ of class cChunkDesc */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cChunkDesc_GetChunkZ00
static int tolua_AllToLua_cChunkDesc_GetChunkZ00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"const cChunkDesc",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
const cChunkDesc* self = (const cChunkDesc*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetChunkZ'", NULL);
#endif
{
int tolua_ret = (int) self->GetChunkZ();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'GetChunkZ'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: SetChunkCoords of class cChunkDesc */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cChunkDesc_SetChunkCoords00
static int tolua_AllToLua_cChunkDesc_SetChunkCoords00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cChunkDesc",0,&tolua_err) ||
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
!tolua_isnumber(tolua_S,3,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,4,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cChunkDesc* self = (cChunkDesc*) tolua_tousertype(tolua_S,1,0);
int a_ChunkX = ((int) tolua_tonumber(tolua_S,2,0));
int a_ChunkZ = ((int) tolua_tonumber(tolua_S,3,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetChunkCoords'", NULL);
#endif
{
self->SetChunkCoords(a_ChunkX,a_ChunkZ);
}
}
return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'SetChunkCoords'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: FillBlocks of class cChunkDesc */ /* method: FillBlocks of class cChunkDesc */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cChunkDesc_FillBlocks00 #ifndef TOLUA_DISABLE_tolua_AllToLua_cChunkDesc_FillBlocks00
static int tolua_AllToLua_cChunkDesc_FillBlocks00(lua_State* tolua_S) static int tolua_AllToLua_cChunkDesc_FillBlocks00(lua_State* tolua_S)
@ -20423,6 +20522,38 @@ static int tolua_AllToLua_cChunkDesc_ReadBlockArea00(lua_State* tolua_S)
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
/* method: GetMaxHeight of class cChunkDesc */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cChunkDesc_GetMaxHeight00
static int tolua_AllToLua_cChunkDesc_GetMaxHeight00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"const cChunkDesc",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
const cChunkDesc* self = (const cChunkDesc*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetMaxHeight'", NULL);
#endif
{
unsigned char tolua_ret = ( unsigned char) self->GetMaxHeight();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'GetMaxHeight'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: new of class cCraftingGrid */ /* method: new of class cCraftingGrid */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingGrid_new00 #ifndef TOLUA_DISABLE_tolua_AllToLua_cCraftingGrid_new00
static int tolua_AllToLua_cCraftingGrid_new00(lua_State* tolua_S) static int tolua_AllToLua_cCraftingGrid_new00(lua_State* tolua_S)
@ -22505,6 +22636,9 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_endmodule(tolua_S); tolua_endmodule(tolua_S);
tolua_cclass(tolua_S,"cChunkDesc","cChunkDesc","",NULL); tolua_cclass(tolua_S,"cChunkDesc","cChunkDesc","",NULL);
tolua_beginmodule(tolua_S,"cChunkDesc"); tolua_beginmodule(tolua_S,"cChunkDesc");
tolua_function(tolua_S,"GetChunkX",tolua_AllToLua_cChunkDesc_GetChunkX00);
tolua_function(tolua_S,"GetChunkZ",tolua_AllToLua_cChunkDesc_GetChunkZ00);
tolua_function(tolua_S,"SetChunkCoords",tolua_AllToLua_cChunkDesc_SetChunkCoords00);
tolua_function(tolua_S,"FillBlocks",tolua_AllToLua_cChunkDesc_FillBlocks00); tolua_function(tolua_S,"FillBlocks",tolua_AllToLua_cChunkDesc_FillBlocks00);
tolua_function(tolua_S,"SetBlockTypeMeta",tolua_AllToLua_cChunkDesc_SetBlockTypeMeta00); tolua_function(tolua_S,"SetBlockTypeMeta",tolua_AllToLua_cChunkDesc_SetBlockTypeMeta00);
tolua_function(tolua_S,"GetBlockTypeMeta",tolua_AllToLua_cChunkDesc_GetBlockTypeMeta00); tolua_function(tolua_S,"GetBlockTypeMeta",tolua_AllToLua_cChunkDesc_GetBlockTypeMeta00);
@ -22528,6 +22662,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"IsUsingDefaultFinish",tolua_AllToLua_cChunkDesc_IsUsingDefaultFinish00); tolua_function(tolua_S,"IsUsingDefaultFinish",tolua_AllToLua_cChunkDesc_IsUsingDefaultFinish00);
tolua_function(tolua_S,"WriteBlockArea",tolua_AllToLua_cChunkDesc_WriteBlockArea00); tolua_function(tolua_S,"WriteBlockArea",tolua_AllToLua_cChunkDesc_WriteBlockArea00);
tolua_function(tolua_S,"ReadBlockArea",tolua_AllToLua_cChunkDesc_ReadBlockArea00); tolua_function(tolua_S,"ReadBlockArea",tolua_AllToLua_cChunkDesc_ReadBlockArea00);
tolua_function(tolua_S,"GetMaxHeight",tolua_AllToLua_cChunkDesc_GetMaxHeight00);
tolua_endmodule(tolua_S); tolua_endmodule(tolua_S);
#ifdef __cplusplus #ifdef __cplusplus
tolua_cclass(tolua_S,"cCraftingGrid","cCraftingGrid","",tolua_collect_cCraftingGrid); tolua_cclass(tolua_S,"cCraftingGrid","cCraftingGrid","",tolua_collect_cCraftingGrid);

View File

@ -1,6 +1,6 @@
/* /*
** Lua binding: AllToLua ** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 03/14/13 10:02:26. ** Generated automatically by tolua++-1.0.92 on 03/17/13 18:47:09.
*/ */
/* Exported function */ /* Exported function */

View File

@ -755,20 +755,15 @@ void cStructGenWormNestCaves::ClearCache(void)
void cStructGenWormNestCaves::GenStructures( void cStructGenWormNestCaves::GenStructures(cChunkDesc & a_ChunkDesc)
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
)
{ {
int ChunkX = a_ChunkDesc.GetChunkX();
int ChunkZ = a_ChunkDesc.GetChunkZ();
cCaveSystems Caves; cCaveSystems Caves;
GetCavesForChunk(a_ChunkX, a_ChunkZ, Caves); GetCavesForChunk(ChunkX, ChunkZ, Caves);
for (cCaveSystems::const_iterator itr = Caves.begin(); itr != Caves.end(); ++itr) for (cCaveSystems::const_iterator itr = Caves.begin(); itr != Caves.end(); ++itr)
{ {
(*itr)->ProcessChunk(a_ChunkX, a_ChunkZ, a_BlockTypes, a_HeightMap); (*itr)->ProcessChunk(ChunkX, ChunkZ, a_ChunkDesc.GetBlockTypes(), a_ChunkDesc.GetHeightMap());
} // for itr - Caves[] } // for itr - Caves[]
} }
@ -900,27 +895,20 @@ static float GetMarbleNoise( float x, float y, float z, cNoise & a_Noise )
void cStructGenMarbleCaves::GenStructures( void cStructGenMarbleCaves::GenStructures(cChunkDesc & a_ChunkDesc)
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
)
{ {
cNoise Noise(m_Seed); 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_ChunkZ * cChunkDef::Width + z); const float zz = (float)(a_ChunkDesc.GetChunkZ() * cChunkDef::Width + z);
for (int x = 0; x < cChunkDef::Width; x++) for (int x = 0; x < cChunkDef::Width; x++)
{ {
const float xx = (float)(a_ChunkX * cChunkDef::Width + x); const float xx = (float)(a_ChunkDesc.GetChunkX() * cChunkDef::Width + x);
int Top = cChunkDef::GetHeight(a_HeightMap, x, z); int Top = a_ChunkDesc.GetHeight(x, z);
for (int y = 1; y < Top; ++y ) for (int y = 1; y < Top; ++y )
{ {
if (cChunkDef::GetBlock(a_BlockTypes, x, y, z) != E_BLOCK_STONE) if (a_ChunkDesc.GetBlockType(x, y, z) != E_BLOCK_STONE)
{ {
continue; continue;
} }
@ -929,7 +917,7 @@ void cStructGenMarbleCaves::GenStructures(
const float WaveNoise = 1; const float WaveNoise = 1;
if (cosf(GetMarbleNoise(xx, yy * 0.5f, zz, Noise)) * fabs(cosf(yy * 0.2f + WaveNoise * 2) * 0.75f + WaveNoise) > 0.0005f) if (cosf(GetMarbleNoise(xx, yy * 0.5f, zz, Noise)) * fabs(cosf(yy * 0.2f + WaveNoise * 2) * 0.75f + WaveNoise) > 0.0005f)
{ {
cChunkDef::SetBlock(a_BlockTypes, x, y, z, E_BLOCK_AIR); a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_AIR);
} }
} // for y } // for y
} // for x } // for x
@ -943,43 +931,27 @@ void cStructGenMarbleCaves::GenStructures(
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cStructGenDualRidgeCaves: // cStructGenDualRidgeCaves:
void cStructGenDualRidgeCaves::GenStructures( void cStructGenDualRidgeCaves::GenStructures(cChunkDesc & a_ChunkDesc)
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
)
{ {
cNoise Noise1(m_Seed);
cNoise Noise2(2 * m_Seed + 19999);
for (int z = 0; z < cChunkDef::Width; z++) for (int z = 0; z < cChunkDef::Width; z++)
{ {
const float zz = (float)(a_ChunkZ * cChunkDef::Width + z) / 10; const float zz = (float)(a_ChunkDesc.GetChunkZ() * cChunkDef::Width + z) / 10;
for (int x = 0; x < cChunkDef::Width; x++) for (int x = 0; x < cChunkDef::Width; x++)
{ {
const float xx = (float)(a_ChunkX * cChunkDef::Width + x) / 10; const float xx = (float)(a_ChunkDesc.GetChunkX() * cChunkDef::Width + x) / 10;
int Top = cChunkDef::GetHeight(a_HeightMap, x, z); int Top = a_ChunkDesc.GetHeight(x, z);
for (int y = 1; y <= Top; ++y) for (int y = 1; y <= Top; ++y)
{ {
/*
if (cChunkDef::GetBlock(a_BlockTypes, x, y, z) != E_BLOCK_STONE)
{
continue;
}
*/
const float yy = (float)y / 10; const float yy = (float)y / 10;
const float WaveNoise = 1; const float WaveNoise = 1;
float n1 = Noise1.CubicNoise3D(xx, yy, zz); float n1 = m_Noise1.CubicNoise3D(xx, yy, zz);
float n2 = Noise2.CubicNoise3D(xx, yy, zz); float n2 = m_Noise2.CubicNoise3D(xx, yy, zz);
float n3 = Noise1.CubicNoise3D(xx * 4, yy * 4, zz * 4) / 4; float n3 = m_Noise1.CubicNoise3D(xx * 4, yy * 4, zz * 4) / 4;
float n4 = Noise2.CubicNoise3D(xx * 4, yy * 4, zz * 4) / 4; float n4 = m_Noise2.CubicNoise3D(xx * 4, yy * 4, zz * 4) / 4;
if ((abs(n1 + n3) * abs(n2 + n4)) > m_Threshold) if ((abs(n1 + n3) * abs(n2 + n4)) > m_Threshold)
{ {
cChunkDef::SetBlock(a_BlockTypes, x, y, z, E_BLOCK_AIR); a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_AIR);
} }
} // for y } // for y
} // for x } // for x

View File

@ -30,14 +30,7 @@ protected:
int m_Seed; int m_Seed;
// cStructureGen override: // cStructureGen override:
virtual void GenStructures( virtual void GenStructures(cChunkDesc & a_ChunkDesc) override;
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
) override;
} ; } ;
@ -49,25 +42,21 @@ class cStructGenDualRidgeCaves :
{ {
public: public:
cStructGenDualRidgeCaves(int a_Seed, float a_Threshold) : cStructGenDualRidgeCaves(int a_Seed, float a_Threshold) :
m_Noise1(a_Seed),
m_Noise2(2 * a_Seed + 19999),
m_Seed(a_Seed), m_Seed(a_Seed),
m_Threshold(a_Threshold) m_Threshold(a_Threshold)
{ {
} }
protected: protected:
cNoise m_Noise1;
cNoise m_Noise2;
int m_Seed; int m_Seed;
float m_Threshold; float m_Threshold;
// cStructureGen override: // cStructureGen override:
virtual void GenStructures( virtual void GenStructures(cChunkDesc & a_ChunkDesc) override;
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
) override;
} ; } ;
@ -105,14 +94,7 @@ protected:
void GetCavesForChunk(int a_ChunkX, int a_ChunkZ, cCaveSystems & a_Caves); void GetCavesForChunk(int a_ChunkX, int a_ChunkZ, cCaveSystems & a_Caves);
// cStructGen override: // cStructGen override:
virtual void GenStructures( virtual void GenStructures(cChunkDesc & a_ChunkDesc) override;
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
) override;
} ; } ;

View File

@ -39,6 +39,16 @@ cChunkDesc::~cChunkDesc()
void cChunkDesc::SetChunkCoords(int a_ChunkX, int a_ChunkZ)
{
m_ChunkX = a_ChunkX;
m_ChunkZ = a_ChunkZ;
}
void cChunkDesc::FillBlocks(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) void cChunkDesc::FillBlocks(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{ {
const NIBBLETYPE CompressedMeta = a_BlockMeta | (a_BlockMeta << 4); const NIBBLETYPE CompressedMeta = a_BlockMeta | (a_BlockMeta << 4);
@ -411,3 +421,19 @@ 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++)
{
if (m_HeightMap[i] > MaxHeight)
{
MaxHeight = m_HeightMap[i];
}
}
return MaxHeight;
}

View File

@ -33,6 +33,11 @@ public:
// tolua_begin // tolua_begin
int GetChunkX(void) const { return m_ChunkX; }
int GetChunkZ(void) const { return m_ChunkZ; }
void SetChunkCoords(int a_ChunkX, int a_ChunkZ);
void FillBlocks(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); void FillBlocks(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
void SetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); void SetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
void GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta); void GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta);
@ -67,16 +72,19 @@ public:
/// Reads an area from the chunk into a cBlockArea /// Reads an area from the chunk into a cBlockArea
void ReadBlockArea(cBlockArea & a_Dest, int a_MinRelX, int a_MaxRelX, int a_MinRelY, int a_MaxRelY, int a_MinRelZ, int a_MaxRelZ); void ReadBlockArea(cBlockArea & a_Dest, int a_MinRelX, int a_MaxRelX, int a_MinRelY, int a_MaxRelY, int a_MinRelZ, int a_MaxRelZ);
/// Returns the maximum height value in the heightmap
HEIGHTTYPE GetMaxHeight(void) const;
// tolua_end // tolua_end
// Accessors used by cChunkGenerator::Generator descendants: // Accessors used by cChunkGenerator::Generator descendants:
cChunkDef::BiomeMap & GetBiomeMap (void) { return m_BiomeMap; } inline cChunkDef::BiomeMap & GetBiomeMap (void) { return m_BiomeMap; }
cChunkDef::BlockTypes & GetBlockTypes (void) { return m_BlockTypes; } inline cChunkDef::BlockTypes & GetBlockTypes (void) { return m_BlockTypes; }
cChunkDef::BlockNibbles & GetBlockMetas (void) { return m_BlockMeta; } inline cChunkDef::BlockNibbles & GetBlockMetas (void) { return m_BlockMeta; }
cChunkDef::HeightMap & GetHeightMap (void) { return m_HeightMap; } inline cChunkDef::HeightMap & GetHeightMap (void) { return m_HeightMap; }
cEntityList & GetEntities (void) { return m_Entities; } inline cEntityList & GetEntities (void) { return m_Entities; }
cBlockEntityList & GetBlockEntities(void) { return m_BlockEntities; } inline cBlockEntityList & GetBlockEntities(void) { return m_BlockEntities; }
private: private:
int m_ChunkX; int m_ChunkX;

View File

@ -18,18 +18,10 @@
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cCompoGenSameBlock: // cCompoGenSameBlock:
void cCompoGenSameBlock::ComposeTerrain( void cCompoGenSameBlock::ComposeTerrain(cChunkDesc & a_ChunkDesc)
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // BlockTypes to be generated
cChunkDef::BlockNibbles & a_BlockMeta, // BlockMetas to be generated
const cChunkDef::HeightMap & a_HeightMap, // The height map to fit
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entitites may be generated along with the terrain
cBlockEntityList & a_BlockEntities // Block entitites may be generated (chests / furnaces / ...)
)
{ {
memset(a_BlockTypes, E_BLOCK_AIR, sizeof(a_BlockTypes)); memset(a_ChunkDesc.GetBlockTypes(), E_BLOCK_AIR, sizeof(a_ChunkDesc.GetBlockTypes()));
memset(a_BlockMeta, 0, sizeof(a_BlockMeta)); memset(a_ChunkDesc.GetBlockMetas(), 0, sizeof(a_ChunkDesc.GetBlockMetas()));
for (int z = 0; z < cChunkDef::Width; z++) for (int z = 0; z < cChunkDef::Width; z++)
{ {
for (int x = 0; x < cChunkDef::Width; x++) for (int x = 0; x < cChunkDef::Width; x++)
@ -37,16 +29,16 @@ void cCompoGenSameBlock::ComposeTerrain(
int Start; int Start;
if (m_IsBedrocked) if (m_IsBedrocked)
{ {
a_BlockTypes[cChunkDef::MakeIndex(x, 0, z)] = E_BLOCK_BEDROCK; a_ChunkDesc.SetBlockType(x, 0, z, E_BLOCK_BEDROCK);
Start = 1; Start = 1;
} }
else else
{ {
Start = 0; Start = 0;
} }
for (int y = a_HeightMap[x + cChunkDef::Width * z]; y >= Start; y--) for (int y = a_ChunkDesc.GetHeight(x, z); y >= Start; y--)
{ {
a_BlockTypes[cChunkDef::MakeIndex(x, y, z)] = m_BlockType; a_ChunkDesc.SetBlockType(x, y, z, m_BlockType);
} // for y } // for y
} // for z } // for z
} // for x } // for x
@ -59,15 +51,7 @@ void cCompoGenSameBlock::ComposeTerrain(
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cCompoGenDebugBiomes: // cCompoGenDebugBiomes:
void cCompoGenDebugBiomes::ComposeTerrain( void cCompoGenDebugBiomes::ComposeTerrain(cChunkDesc & a_ChunkDesc)
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // BlockTypes to be generated
cChunkDef::BlockNibbles & a_BlockMeta, // BlockMetas to be generated
const cChunkDef::HeightMap & a_HeightMap, // The height map to fit
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entitites may be generated along with the terrain
cBlockEntityList & a_BlockEntities // Block entitites may be generated (chests / furnaces / ...)
)
{ {
static BLOCKTYPE Blocks[] = static BLOCKTYPE Blocks[] =
{ {
@ -96,17 +80,17 @@ void cCompoGenDebugBiomes::ComposeTerrain(
E_BLOCK_BEDROCK, E_BLOCK_BEDROCK,
} ; } ;
memset(a_BlockTypes, E_BLOCK_AIR, sizeof(a_BlockTypes)); memset(a_ChunkDesc.GetBlockTypes(), E_BLOCK_AIR, sizeof(a_ChunkDesc.GetBlockTypes()));
memset(a_BlockMeta, 0, sizeof(a_BlockMeta)); memset(a_ChunkDesc.GetBlockMetas(), 0, sizeof(a_ChunkDesc.GetBlockMetas()));
for (int z = 0; z < cChunkDef::Width; z++) for (int z = 0; z < cChunkDef::Width; z++)
{ {
for (int x = 0; x < cChunkDef::Width; x++) for (int x = 0; x < cChunkDef::Width; x++)
{ {
BLOCKTYPE BlockType = Blocks[cChunkDef::GetBiome(a_BiomeMap, x, z) % ARRAYCOUNT(Blocks)]; BLOCKTYPE BlockType = Blocks[a_ChunkDesc.GetBiome(x, z)];
for (int y = a_HeightMap[x + cChunkDef::Width * z]; y >= 0; y--) for (int y = a_ChunkDesc.GetHeight(x, z); y >= 0; y--)
{ {
cChunkDef::SetBlock(a_BlockTypes, x, y, z, BlockType); a_ChunkDesc.SetBlockType(x, y, z, BlockType);
} // for y } // for y
} // for z } // for z
} // for x } // for x
@ -140,15 +124,7 @@ cCompoGenClassic::cCompoGenClassic(
void cCompoGenClassic::ComposeTerrain( void cCompoGenClassic::ComposeTerrain(cChunkDesc & a_ChunkDesc)
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // BlockTypes to be generated
cChunkDef::BlockNibbles & a_BlockMeta, // BlockMetas to be generated
const cChunkDef::HeightMap & a_HeightMap, // The height map to fit
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entitites may be generated along with the terrain
cBlockEntityList & a_BlockEntities // Block entitites may be generated (chests / furnaces / ...)
)
{ {
/* The classic composition means: /* The classic composition means:
- 1 layer of grass, 3 of dirt and the rest stone, if the height > sealevel + beachheight - 1 layer of grass, 3 of dirt and the rest stone, if the height > sealevel + beachheight
@ -158,13 +134,13 @@ void cCompoGenClassic::ComposeTerrain(
- bedrock at the bottom - bedrock at the bottom
*/ */
memset(a_BlockTypes, E_BLOCK_AIR, sizeof(a_BlockTypes)); memset(a_ChunkDesc.GetBlockTypes(), E_BLOCK_AIR, sizeof(a_ChunkDesc.GetBlockTypes()));
memset(a_BlockMeta, 0, sizeof(a_BlockMeta)); memset(a_ChunkDesc.GetBlockMetas(), 0, sizeof(a_ChunkDesc.GetBlockMetas()));
// The patterns to use for different situations, must be same length! // The patterns to use for different situations, must be same length!
static const BLOCKTYPE PatternGround[] = {m_BlockTop, m_BlockMiddle, m_BlockMiddle, m_BlockMiddle} ; const BLOCKTYPE PatternGround[] = {m_BlockTop, m_BlockMiddle, m_BlockMiddle, m_BlockMiddle} ;
static const BLOCKTYPE PatternBeach[] = {m_BlockBeach, m_BlockBeach, m_BlockBeach, m_BlockBeachBottom} ; const BLOCKTYPE PatternBeach[] = {m_BlockBeach, m_BlockBeach, m_BlockBeach, m_BlockBeachBottom} ;
static const BLOCKTYPE PatternOcean[] = {m_BlockMiddle, m_BlockMiddle, m_BlockMiddle, m_BlockBottom} ; const BLOCKTYPE PatternOcean[] = {m_BlockMiddle, m_BlockMiddle, m_BlockMiddle, m_BlockBottom} ;
static int PatternLength = ARRAYCOUNT(PatternGround); static int PatternLength = ARRAYCOUNT(PatternGround);
ASSERT(ARRAYCOUNT(PatternGround) == ARRAYCOUNT(PatternBeach)); ASSERT(ARRAYCOUNT(PatternGround) == ARRAYCOUNT(PatternBeach));
ASSERT(ARRAYCOUNT(PatternGround) == ARRAYCOUNT(PatternOcean)); ASSERT(ARRAYCOUNT(PatternGround) == ARRAYCOUNT(PatternOcean));
@ -173,7 +149,7 @@ void cCompoGenClassic::ComposeTerrain(
{ {
for (int x = 0; x < cChunkDef::Width; x++) for (int x = 0; x < cChunkDef::Width; x++)
{ {
int Height = cChunkDef::GetHeight(a_HeightMap, x, z); int Height = a_ChunkDesc.GetHeight(x, z);
const BLOCKTYPE * Pattern; const BLOCKTYPE * Pattern;
if (Height > m_SeaLevel + m_BeachHeight) if (Height > m_SeaLevel + m_BeachHeight)
{ {
@ -191,17 +167,17 @@ void cCompoGenClassic::ComposeTerrain(
// Fill water from sealevel down to height (if any): // Fill water from sealevel down to height (if any):
for (int y = m_SeaLevel; y >= Height; --y) for (int y = m_SeaLevel; y >= Height; --y)
{ {
cChunkDef::SetBlock(a_BlockTypes, x, y, z, m_BlockSea); a_ChunkDesc.SetBlockType(x, y, z, m_BlockSea);
} }
// Fill from height till the bottom: // Fill from height till the bottom:
for (int y = Height; y >= 1; y--) for (int y = Height; y >= 1; y--)
{ {
cChunkDef::SetBlock(a_BlockTypes, x, y, z, (Height - y < PatternLength) ? Pattern[Height - y] : m_BlockBottom); a_ChunkDesc.SetBlockType(x, y, z, (Height - y < PatternLength) ? Pattern[Height - y] : m_BlockBottom);
} }
// The last layer is always bedrock: // The last layer is always bedrock:
cChunkDef::SetBlock(a_BlockTypes, x, 0, z, E_BLOCK_BEDROCK); a_ChunkDesc.SetBlockType(x, 0, z, E_BLOCK_BEDROCK);
} // for x } // for x
} // for z } // for z
} }
@ -213,26 +189,21 @@ void cCompoGenClassic::ComposeTerrain(
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cCompoGenBiomal: // cCompoGenBiomal:
void cCompoGenBiomal::ComposeTerrain( void cCompoGenBiomal::ComposeTerrain(cChunkDesc & a_ChunkDesc)
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // BlockTypes to be generated
cChunkDef::BlockNibbles & a_BlockMeta, // BlockMetas to be generated
const cChunkDef::HeightMap & a_HeightMap, // The height map to fit
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entitites may be generated along with the terrain
cBlockEntityList & a_BlockEntities // Block entitites may be generated (chests / furnaces / ...)
)
{ {
memset(a_BlockTypes, 0, sizeof(a_BlockTypes)); memset(a_ChunkDesc.GetBlockTypes(), E_BLOCK_AIR, sizeof(a_ChunkDesc.GetBlockTypes()));
memset(a_BlockMeta, 0, sizeof(a_BlockMeta)); memset(a_ChunkDesc.GetBlockMetas(), 0, sizeof(a_ChunkDesc.GetBlockMetas()));
int ChunkX = a_ChunkDesc.GetChunkX();
int ChunkZ = a_ChunkDesc.GetChunkZ();
for (int z = 0; z < cChunkDef::Width; z++) for (int z = 0; z < cChunkDef::Width; z++)
{ {
for (int x = 0; x < cChunkDef::Width; x++) for (int x = 0; x < cChunkDef::Width; x++)
{ {
int Height = cChunkDef::GetHeight(a_HeightMap, x, z); int Height = a_ChunkDesc.GetHeight(x, z);
if (Height > m_SeaLevel) if (Height > m_SeaLevel)
{ {
switch (cChunkDef::GetBiome(a_BiomeMap, x, z)) switch (a_ChunkDesc.GetBiome(x, z))
{ {
case biOcean: case biOcean:
case biPlains: case biPlains:
@ -251,20 +222,20 @@ void cCompoGenBiomal::ComposeTerrain(
case biJungle: case biJungle:
case biJungleHills: case biJungleHills:
{ {
FillColumnGrass(x, z, Height, a_BlockTypes); FillColumnGrass(x, z, Height, a_ChunkDesc.GetBlockTypes());
break; break;
} }
case biDesertHills: case biDesertHills:
case biDesert: case biDesert:
case biBeach: case biBeach:
{ {
FillColumnSand(x, z, Height, a_BlockTypes); FillColumnSand(x, z, Height, a_ChunkDesc.GetBlockTypes());
break; break;
} }
case biMushroomIsland: case biMushroomIsland:
case biMushroomShore: case biMushroomShore:
{ {
FillColumnMycelium(x, z, Height, a_BlockTypes); FillColumnMycelium(x, z, Height, a_ChunkDesc.GetBlockTypes());
break; break;
} }
default: default:
@ -277,24 +248,24 @@ void cCompoGenBiomal::ComposeTerrain(
} }
else else
{ {
switch (cChunkDef::GetBiome(a_BiomeMap, x, z)) switch (a_ChunkDesc.GetBiome(x, z))
{ {
case biDesert: case biDesert:
case biBeach: case biBeach:
{ {
// Fill with water, sand, sandstone and stone // Fill with water, sand, sandstone and stone
FillColumnWaterSand(x, z, Height, a_BlockTypes); FillColumnWaterSand(x, z, Height, a_ChunkDesc.GetBlockTypes());
break; break;
} }
default: default:
{ {
// Fill with water, sand/dirt/clay mix and stone // Fill with water, sand/dirt/clay mix and stone
FillColumnWaterMix(a_ChunkX, a_ChunkZ, x, z, Height, a_BlockTypes); FillColumnWaterMix(ChunkX, ChunkZ, x, z, Height, a_ChunkDesc.GetBlockTypes());
break; break;
} }
} // switch (biome) } // switch (biome)
} // else (under water) } // else (under water)
cChunkDef::SetBlock(a_BlockTypes, x, 0, z, E_BLOCK_BEDROCK); a_ChunkDesc.SetBlockType(x, 0, z, E_BLOCK_BEDROCK);
} // for x } // for x
} // for z } // for z
} }
@ -440,29 +411,14 @@ cCompoGenNether::cCompoGenNether(int a_Seed) :
void cCompoGenNether::ComposeTerrain( void cCompoGenNether::ComposeTerrain(cChunkDesc & a_ChunkDesc)
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // BlockTypes to be generated
cChunkDef::BlockNibbles & a_BlockMeta, // BlockMetas to be generated
const cChunkDef::HeightMap & a_HeightMap, // The height map to fit
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entitites may be generated along with the terrain
cBlockEntityList & a_BlockEntities // Block entitites may be generated (chests / furnaces / ...)
)
{ {
HEIGHTTYPE MaxHeight = 0; HEIGHTTYPE MaxHeight = a_ChunkDesc.GetMaxHeight();
for (int i = 0; i < ARRAYCOUNT(a_HeightMap); i++)
{
if (a_HeightMap[i] > MaxHeight)
{
MaxHeight = a_HeightMap[i];
}
}
const int SEGMENT_HEIGHT = 8; const int SEGMENT_HEIGHT = 8;
const int INTERPOL_X = 16; // Must be a divisor of 16 const int INTERPOL_X = 16; // Must be a divisor of 16
const int INTERPOL_Z = 16; // Must be a divisor of 16 const int INTERPOL_Z = 16; // Must be a divisor of 16
// Interpolate the chunk in 16 * SEGMENT_HEIGHT * 16 "segments", each 8 blocks high and each linearly interpolated separately. // Interpolate the chunk in 16 * SEGMENT_HEIGHT * 16 "segments", each SEGMENT_HEIGHT blocks high and each linearly interpolated separately.
// Have two buffers, one for the lowest floor and one for the highest floor, so that Y-interpolation can be done between them // Have two buffers, one for the lowest floor and one for the highest floor, so that Y-interpolation can be done between them
// Then swap the buffers and use the previously-top one as the current-bottom, without recalculating it. // Then swap the buffers and use the previously-top one as the current-bottom, without recalculating it.
@ -470,8 +426,8 @@ void cCompoGenNether::ComposeTerrain(
int FloorBuf2[17 * 17]; int FloorBuf2[17 * 17];
int * FloorHi = FloorBuf1; int * FloorHi = FloorBuf1;
int * FloorLo = FloorBuf2; int * FloorLo = FloorBuf2;
int BaseX = a_ChunkX * cChunkDef::Width; int BaseX = a_ChunkDesc.GetChunkX() * cChunkDef::Width;
int BaseZ = a_ChunkZ * cChunkDef::Width; int BaseZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width;
// Interpolate the lowest floor: // Interpolate the lowest floor:
for (int z = 0; z <= 16 / INTERPOL_Z; z++) for (int x = 0; x <= 16 / INTERPOL_X; x++) for (int z = 0; z <= 16 / INTERPOL_Z; z++) for (int x = 0; x <= 16 / INTERPOL_X; x++)
@ -504,7 +460,7 @@ void cCompoGenNether::ComposeTerrain(
for (int y = 0; y < SEGMENT_HEIGHT; y++) for (int y = 0; y < SEGMENT_HEIGHT; y++)
{ {
int Val = Lo + (Hi - Lo) * y / SEGMENT_HEIGHT; int Val = Lo + (Hi - Lo) * y / SEGMENT_HEIGHT;
cChunkDef::SetBlock(a_BlockTypes, x, y + Segment, z, (Val < m_Threshold) ? E_BLOCK_NETHERRACK : E_BLOCK_AIR); a_ChunkDesc.SetBlockType(x, y + Segment, z, (Val < m_Threshold) ? E_BLOCK_NETHERRACK : E_BLOCK_AIR);
} }
} }
@ -515,8 +471,8 @@ void cCompoGenNether::ComposeTerrain(
// Bedrock at the bottom and at the top: // Bedrock at the bottom and at the top:
for (int z = 0; z < 16; z++) for (int x = 0; x < 16; x++) for (int z = 0; z < 16; z++) for (int x = 0; x < 16; x++)
{ {
cChunkDef::SetBlock(a_BlockTypes, x, 0, z, E_BLOCK_BEDROCK); a_ChunkDesc.SetBlockType(x, 0, z, E_BLOCK_BEDROCK);
cChunkDef::SetBlock(a_BlockTypes, x, cChunkDef::GetHeight(a_HeightMap, x, z), z, E_BLOCK_BEDROCK); a_ChunkDesc.SetBlockType(x, a_ChunkDesc.GetHeight(x, z), z, E_BLOCK_BEDROCK);
} }
} }

View File

@ -36,15 +36,7 @@ protected:
bool m_IsBedrocked; bool m_IsBedrocked;
// cTerrainCompositionGen overrides: // cTerrainCompositionGen overrides:
virtual void ComposeTerrain( virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc) override;
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // BlockTypes to be generated
cChunkDef::BlockNibbles & a_BlockMeta, // BlockMetas to be generated
const cChunkDef::HeightMap & a_HeightMap, // The height map to fit
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entitites may be generated along with the terrain
cBlockEntityList & a_BlockEntities // Block entitites may be generated (chests / furnaces / ...)
) override;
} ; } ;
@ -60,15 +52,7 @@ public:
protected: protected:
// cTerrainCompositionGen overrides: // cTerrainCompositionGen overrides:
virtual void ComposeTerrain( virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc) override;
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // BlockTypes to be generated
cChunkDef::BlockNibbles & a_BlockMeta, // BlockMetas to be generated
const cChunkDef::HeightMap & a_HeightMap, // The height map to fit
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entitites may be generated along with the terrain
cBlockEntityList & a_BlockEntities // Block entitites may be generated (chests / furnaces / ...)
) override;
} ; } ;
@ -98,15 +82,7 @@ protected:
BLOCKTYPE m_BlockSea; BLOCKTYPE m_BlockSea;
// cTerrainCompositionGen overrides: // cTerrainCompositionGen overrides:
virtual void ComposeTerrain( virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc) override;
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // BlockTypes to be generated
cChunkDef::BlockNibbles & a_BlockMeta, // BlockMetas to be generated
const cChunkDef::HeightMap & a_HeightMap, // The height map to fit
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entitites may be generated along with the terrain
cBlockEntityList & a_BlockEntities // Block entitites may be generated (chests / furnaces / ...)
) override;
} ; } ;
@ -129,15 +105,7 @@ protected:
int m_SeaLevel; int m_SeaLevel;
// cTerrainCompositionGen overrides: // cTerrainCompositionGen overrides:
virtual void ComposeTerrain( virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc) override;
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // BlockTypes to be generated
cChunkDef::BlockNibbles & a_BlockMeta, // BlockMetas to be generated
const cChunkDef::HeightMap & a_HeightMap, // The height map to fit
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entitites may be generated along with the terrain
cBlockEntityList & a_BlockEntities // Block entitites may be generated (chests / furnaces / ...)
) override;
void FillColumnGrass (int a_RelX, int a_RelZ, int a_Height, cChunkDef::BlockTypes & a_BlockTypes); void FillColumnGrass (int a_RelX, int a_RelZ, int a_Height, cChunkDef::BlockTypes & a_BlockTypes);
void FillColumnSand (int a_RelX, int a_RelZ, int a_Height, cChunkDef::BlockTypes & a_BlockTypes); void FillColumnSand (int a_RelX, int a_RelZ, int a_Height, cChunkDef::BlockTypes & a_BlockTypes);
@ -166,15 +134,7 @@ protected:
int m_Threshold; int m_Threshold;
// cTerrainCompositionGen overrides: // cTerrainCompositionGen overrides:
virtual void ComposeTerrain( virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc) override;
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // BlockTypes to be generated
cChunkDef::BlockNibbles & a_BlockMeta, // BlockMetas to be generated
const cChunkDef::HeightMap & a_HeightMap, // The height map to fit
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entitites may be generated along with the terrain
cBlockEntityList & a_BlockEntities // Block entitites may be generated (chests / furnaces / ...)
) override;
} ; } ;

View File

@ -9,7 +9,6 @@
#include "../World.h" #include "../World.h"
#include "../../iniFile/iniFile.h" #include "../../iniFile/iniFile.h"
#include "../Root.h" #include "../Root.h"
#include "ChunkDesc.h"
// Individual composed algorithms: // Individual composed algorithms:
#include "BioGen.h" #include "BioGen.h"
@ -114,14 +113,14 @@ void cComposableGenerator::DoGenerate(int a_ChunkX, int a_ChunkZ, cChunkDesc & a
if (a_ChunkDesc.IsUsingDefaultComposition()) if (a_ChunkDesc.IsUsingDefaultComposition())
{ {
m_CompositionGen->ComposeTerrain(a_ChunkX, a_ChunkZ, BlockTypes, BlockMeta, HeightMap, BiomeMap, Entities, BlockEntities); m_CompositionGen->ComposeTerrain(a_ChunkDesc);
} }
if (a_ChunkDesc.IsUsingDefaultStructures()) if (a_ChunkDesc.IsUsingDefaultStructures())
{ {
for (cStructureGenList::iterator itr = m_StructureGens.begin(); itr != m_StructureGens.end(); ++itr) for (cStructureGenList::iterator itr = m_StructureGens.begin(); itr != m_StructureGens.end(); ++itr)
{ {
(*itr)->GenStructures(a_ChunkX, a_ChunkZ, BlockTypes, BlockMeta, HeightMap, Entities, BlockEntities); (*itr)->GenStructures(a_ChunkDesc);
} // for itr - m_StructureGens[] } // for itr - m_StructureGens[]
} }
@ -129,7 +128,7 @@ void cComposableGenerator::DoGenerate(int a_ChunkX, int a_ChunkZ, cChunkDesc & a
{ {
for (cFinishGenList::iterator itr = m_FinishGens.begin(); itr != m_FinishGens.end(); ++itr) for (cFinishGenList::iterator itr = m_FinishGens.begin(); itr != m_FinishGens.end(); ++itr)
{ {
(*itr)->GenFinish(a_ChunkX, a_ChunkZ, BlockTypes, BlockMeta, HeightMap, BiomeMap, Entities, BlockEntities); (*itr)->GenFinish(a_ChunkDesc);
} // for itr - m_FinishGens[] } // for itr - m_FinishGens[]
} }
} }
@ -372,7 +371,7 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
} }
else if (NoCaseCompare(*itr, "DeadBushes") == 0) else if (NoCaseCompare(*itr, "DeadBushes") == 0)
{ {
m_FinishGens.push_back(new cFinishGenDeadBushes(Seed)); m_FinishGens.push_back(new cFinishGenSingleBiomeSingleTopBlock(Seed, E_BLOCK_DEAD_BUSH, biDesert, 2, E_BLOCK_SAND, E_BLOCK_SAND));
} }
else if (NoCaseCompare(*itr, "Ice") == 0) else if (NoCaseCompare(*itr, "Ice") == 0)
{ {
@ -384,7 +383,7 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
} }
else if (NoCaseCompare(*itr, "Lilypads") == 0) else if (NoCaseCompare(*itr, "Lilypads") == 0)
{ {
m_FinishGens.push_back(new cFinishGenLilypads(Seed)); m_FinishGens.push_back(new cFinishGenSingleBiomeSingleTopBlock(Seed, E_BLOCK_LILY_PAD, biSwampland, 4, E_BLOCK_WATER, E_BLOCK_STATIONARY_WATER));
} }
else if (NoCaseCompare(*itr, "PreSimulator") == 0) else if (NoCaseCompare(*itr, "PreSimulator") == 0)
{ {

View File

@ -18,6 +18,7 @@ See http://forum.mc-server.org/showthread.php?tid=409 for details.
#pragma once #pragma once
#include "ChunkGenerator.h" #include "ChunkGenerator.h"
#include "ChunkDesc.h"
@ -72,15 +73,7 @@ class cTerrainCompositionGen
public: public:
virtual ~cTerrainCompositionGen() {} // Force a virtual destructor in descendants virtual ~cTerrainCompositionGen() {} // Force a virtual destructor in descendants
virtual void ComposeTerrain( virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc) = 0;
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // BlockTypes to be generated (the whole array gets initialized, even air)
cChunkDef::BlockNibbles & a_BlockMeta, // BlockMetas to be generated (the whole array gets initialized)
const cChunkDef::HeightMap & a_HeightMap, // The height map to fit
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entitites may be generated along with the terrain
cBlockEntityList & a_BlockEntities // Block entitites may be generated (chests / furnaces / ...)
) = 0;
} ; } ;
@ -98,14 +91,7 @@ class cStructureGen
public: public:
virtual ~cStructureGen() {} // Force a virtual destructor in descendants virtual ~cStructureGen() {} // Force a virtual destructor in descendants
virtual void GenStructures( virtual void GenStructures(cChunkDesc & a_ChunkDesc) = 0;
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
) = 0;
} ; } ;
typedef std::list<cStructureGen *> cStructureGenList; typedef std::list<cStructureGen *> cStructureGenList;
@ -122,15 +108,7 @@ class cFinishGen
public: public:
virtual ~cFinishGen() {} // Force a virtual destructor in descendants virtual ~cFinishGen() {} // Force a virtual destructor in descendants
virtual void GenFinish( virtual void GenFinish(cChunkDesc & a_ChunkDesc) = 0;
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
) = 0;
} ; } ;
typedef std::list<cFinishGen *> cFinishGenList; typedef std::list<cFinishGen *> cFinishGenList;

View File

@ -42,12 +42,7 @@ static inline bool IsWater(BLOCKTYPE a_BlockType)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cFinishGenSprinkleFoliage: // cFinishGenSprinkleFoliage:
bool cFinishGenSprinkleFoliage::TryAddSugarcane( bool cFinishGenSprinkleFoliage::TryAddSugarcane(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelY, int a_RelZ)
int a_ChunkX, int a_ChunkZ,
int a_RelX, int a_RelY, int a_RelZ,
cChunkDef::BlockTypes & a_BlockTypes,
cChunkDef::BlockNibbles & a_BlockMeta
)
{ {
// We'll be doing comparison to neighbors, so require the coords to be 1 block away from the chunk edges: // We'll be doing comparison to neighbors, so require the coords to be 1 block away from the chunk edges:
if ( if (
@ -60,7 +55,7 @@ bool cFinishGenSprinkleFoliage::TryAddSugarcane(
} }
// Only allow dirt, grass or sand below sugarcane: // Only allow dirt, grass or sand below sugarcane:
switch (cChunkDef::GetBlock(a_BlockTypes, a_RelX, a_RelY, a_RelZ)) switch (a_ChunkDesc.GetBlockType(a_RelX, a_RelY, a_RelZ))
{ {
case E_BLOCK_DIRT: case E_BLOCK_DIRT:
case E_BLOCK_GRASS: case E_BLOCK_GRASS:
@ -76,17 +71,17 @@ bool cFinishGenSprinkleFoliage::TryAddSugarcane(
// Water is required next to the block below the sugarcane: // Water is required next to the block below the sugarcane:
if ( if (
!IsWater(cChunkDef::GetBlock(a_BlockTypes, a_RelX - 1, a_RelY, a_RelZ)) && !IsWater(a_ChunkDesc.GetBlockType(a_RelX - 1, a_RelY, a_RelZ)) &&
!IsWater(cChunkDef::GetBlock(a_BlockTypes, a_RelX + 1, a_RelY, a_RelZ)) && !IsWater(a_ChunkDesc.GetBlockType(a_RelX + 1, a_RelY, a_RelZ)) &&
!IsWater(cChunkDef::GetBlock(a_BlockTypes, a_RelX , a_RelY, a_RelZ - 1)) && !IsWater(a_ChunkDesc.GetBlockType(a_RelX , a_RelY, a_RelZ - 1)) &&
!IsWater(cChunkDef::GetBlock(a_BlockTypes, a_RelX , a_RelY, a_RelZ + 1)) !IsWater(a_ChunkDesc.GetBlockType(a_RelX , a_RelY, a_RelZ + 1))
) )
{ {
return false; return false;
} }
// All conditions met, place a sugarcane here: // All conditions met, place a sugarcane here:
cChunkDef::SetBlock(a_BlockTypes, a_RelX, a_RelY + 1, a_RelZ, E_BLOCK_SUGARCANE); a_ChunkDesc.SetBlockType(a_RelX, a_RelY + 1, a_RelZ, E_BLOCK_SUGARCANE);
return true; return true;
} }
@ -94,38 +89,29 @@ bool cFinishGenSprinkleFoliage::TryAddSugarcane(
void cFinishGenSprinkleFoliage::GenFinish( void cFinishGenSprinkleFoliage::GenFinish(cChunkDesc & a_ChunkDesc)
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
)
{ {
// Generate small foliage (1-block): // Generate small foliage (1-block):
// TODO: Update heightmap with 1-block-tall foliage // TODO: Update heightmap with 1-block-tall foliage
cNoise Noise(m_Seed);
for (int z = 0; z < cChunkDef::Width; z++) for (int z = 0; z < cChunkDef::Width; z++)
{ {
int BlockZ = a_ChunkZ * cChunkDef::Width + z; int BlockZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width + z;
const float zz = (float)BlockZ; const float zz = (float)BlockZ;
for (int x = 0; x < cChunkDef::Width; x++) for (int x = 0; x < cChunkDef::Width; x++)
{ {
int BlockX = a_ChunkX * cChunkDef::Width + x; int BlockX = a_ChunkDesc.GetChunkX() * cChunkDef::Width + x;
if (((Noise.IntNoise2DInt(BlockX, BlockZ) / 8) % 128) < 124) if (((m_Noise.IntNoise2DInt(BlockX, BlockZ) / 8) % 128) < 124)
{ {
continue; continue;
} }
int Top = cChunkDef::GetHeight(a_HeightMap, x, z); int Top = a_ChunkDesc.GetHeight(x, z);
if (Top > 250) if (Top > 250)
{ {
// Nothing grows above Y=250 // Nothing grows above Y=250
continue; continue;
} }
if (cChunkDef::GetBlock(a_BlockTypes, x, Top + 1, z) != E_BLOCK_AIR) if (a_ChunkDesc.GetBlockType(x, Top + 1, z) != E_BLOCK_AIR)
{ {
// Space already taken by something else, don't grow here // Space already taken by something else, don't grow here
// WEIRD, since we're using heightmap, so there should NOT be anything above it // WEIRD, since we're using heightmap, so there should NOT be anything above it
@ -133,43 +119,41 @@ void cFinishGenSprinkleFoliage::GenFinish(
} }
const float xx = (float)BlockX; const float xx = (float)BlockX;
float val1 = Noise.CubicNoise2D(xx * 0.1f, zz * 0.1f ); float val1 = m_Noise.CubicNoise2D(xx * 0.1f, zz * 0.1f );
float val2 = Noise.CubicNoise2D(xx * 0.01f, zz * 0.01f ); float val2 = m_Noise.CubicNoise2D(xx * 0.01f, zz * 0.01f );
switch (cChunkDef::GetBlock(a_BlockTypes, x, Top, z)) switch (a_ChunkDesc.GetBlockType(x, Top, z))
{ {
case E_BLOCK_GRASS: case E_BLOCK_GRASS:
{ {
float val3 = Noise.CubicNoise2D(xx * 0.01f + 10, zz * 0.01f + 10 ); float val3 = m_Noise.CubicNoise2D(xx * 0.01f + 10, zz * 0.01f + 10 );
float val4 = Noise.CubicNoise2D(xx * 0.05f + 20, zz * 0.05f + 20 ); float val4 = m_Noise.CubicNoise2D(xx * 0.05f + 20, zz * 0.05f + 20 );
if (val1 + val2 > 0.2f) if (val1 + val2 > 0.2f)
{ {
cChunkDef::SetBlock(a_BlockTypes, x, ++Top, z, E_BLOCK_YELLOW_FLOWER); a_ChunkDesc.SetBlockType(x, ++Top, z, E_BLOCK_YELLOW_FLOWER);
} }
else if (val2 + val3 > 0.2f) else if (val2 + val3 > 0.2f)
{ {
cChunkDef::SetBlock(a_BlockTypes, x, ++Top, z, E_BLOCK_RED_ROSE); a_ChunkDesc.SetBlockType(x, ++Top, z, E_BLOCK_RED_ROSE);
} }
else if (val3 + val4 > 0.2f) else if (val3 + val4 > 0.2f)
{ {
cChunkDef::SetBlock(a_BlockTypes, x, ++Top, z, E_BLOCK_RED_MUSHROOM); a_ChunkDesc.SetBlockType(x, ++Top, z, E_BLOCK_RED_MUSHROOM);
} }
else if (val1 + val4 > 0.2f) else if (val1 + val4 > 0.2f)
{ {
cChunkDef::SetBlock(a_BlockTypes, x, ++Top, z, E_BLOCK_BROWN_MUSHROOM); a_ChunkDesc.SetBlockType(x, ++Top, z, E_BLOCK_BROWN_MUSHROOM);
} }
else if (val1 + val2 + val3 + val4 < -0.1) else if (val1 + val2 + val3 + val4 < -0.1)
{ {
cChunkDef::SetBlock (a_BlockTypes, x, ++Top, z, E_BLOCK_TALL_GRASS); a_ChunkDesc.SetBlockTypeMeta(x, ++Top, z, E_BLOCK_TALL_GRASS, E_META_TALL_GRASS_GRASS);
cChunkDef::SetNibble(a_BlockMeta, x, Top, z, E_META_TALL_GRASS_GRASS);
} }
else if (TryAddSugarcane(a_ChunkX, a_ChunkZ, x, Top, z, a_BlockTypes, a_BlockMeta)) else if (TryAddSugarcane(a_ChunkDesc, x, Top, z))
{ {
++Top; ++Top;
} }
else if ((val1 > 0.5) && (val2 < -0.5)) else if ((val1 > 0.5) && (val2 < -0.5))
{ {
cChunkDef::SetBlock (a_BlockTypes, x, ++Top, z, E_BLOCK_PUMPKIN); a_ChunkDesc.SetBlockTypeMeta(x, ++Top, z, E_BLOCK_PUMPKIN, (int)(val3 * 8) % 4);
cChunkDef::SetNibble(a_BlockMeta, x, Top, z, (int)(val3 * 8) % 4);
} }
break; break;
} // case E_BLOCK_GRASS } // case E_BLOCK_GRASS
@ -181,22 +165,22 @@ void cFinishGenSprinkleFoliage::GenFinish(
(x > 0) && (x < cChunkDef::Width - 1) && (x > 0) && (x < cChunkDef::Width - 1) &&
(z > 0) && (z < cChunkDef::Width - 1) && (z > 0) && (z < cChunkDef::Width - 1) &&
(val1 + val2 > 0.5f) && (val1 + val2 > 0.5f) &&
(cChunkDef::GetBlock(a_BlockTypes, x + 1, y, z) == E_BLOCK_AIR) && (a_ChunkDesc.GetBlockType(x + 1, y, z) == E_BLOCK_AIR) &&
(cChunkDef::GetBlock(a_BlockTypes, x - 1, y, z) == E_BLOCK_AIR) && (a_ChunkDesc.GetBlockType(x - 1, y, z) == E_BLOCK_AIR) &&
(cChunkDef::GetBlock(a_BlockTypes, x, y, z + 1) == E_BLOCK_AIR) && (a_ChunkDesc.GetBlockType(x, y, z + 1) == E_BLOCK_AIR) &&
(cChunkDef::GetBlock(a_BlockTypes, x, y, z - 1) == E_BLOCK_AIR) (a_ChunkDesc.GetBlockType(x, y, z - 1) == E_BLOCK_AIR)
) )
{ {
cChunkDef::SetBlock(a_BlockTypes, x, ++Top, z, E_BLOCK_CACTUS); a_ChunkDesc.SetBlockType(x, ++Top, z, E_BLOCK_CACTUS);
} }
else if (TryAddSugarcane(a_ChunkX, a_ChunkZ, x, Top, z, a_BlockTypes, a_BlockMeta)) else if (TryAddSugarcane(a_ChunkDesc, x, Top, z))
{ {
++Top; ++Top;
} }
break; break;
} }
} // switch (TopBlock) } // switch (TopBlock)
cChunkDef::SetHeight(a_HeightMap, x, z, Top); a_ChunkDesc.SetHeight(x, z, Top);
} // for y } // for y
} // for z } // for z
} }
@ -208,22 +192,14 @@ void cFinishGenSprinkleFoliage::GenFinish(
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cFinishGenSnow: // cFinishGenSnow:
void cFinishGenSnow::GenFinish( void cFinishGenSnow::GenFinish(cChunkDesc & a_ChunkDesc)
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
)
{ {
// Add a snow block in snowy biomes onto blocks that can be snowed over // Add a snow block in snowy biomes onto blocks that can be snowed over
for (int z = 0; z < cChunkDef::Width; z++) for (int z = 0; z < cChunkDef::Width; z++)
{ {
for (int x = 0; x < cChunkDef::Width; x++) for (int x = 0; x < cChunkDef::Width; x++)
{ {
switch (cChunkDef::GetBiome(a_BiomeMap, x, z)) switch (a_ChunkDesc.GetBiome(x, z))
{ {
case biIcePlains: case biIcePlains:
case biIceMountains: case biIceMountains:
@ -232,11 +208,11 @@ void cFinishGenSnow::GenFinish(
case biFrozenRiver: case biFrozenRiver:
case biFrozenOcean: case biFrozenOcean:
{ {
int Height = cChunkDef::GetHeight(a_HeightMap, x, z); int Height = a_ChunkDesc.GetHeight(x, z);
if (g_BlockIsSnowable[cChunkDef::GetBlock(a_BlockTypes, x, Height, z)]) if (g_BlockIsSnowable[a_ChunkDesc.GetBlockType(x, Height, z)])
{ {
cChunkDef::SetBlock(a_BlockTypes, x, Height + 1, z, E_BLOCK_SNOW); a_ChunkDesc.SetBlockType(x, Height + 1, z, E_BLOCK_SNOW);
cChunkDef::SetHeight(a_HeightMap, x, z, Height + 1); a_ChunkDesc.SetHeight(x, z, Height + 1);
} }
break; break;
} }
@ -252,22 +228,14 @@ void cFinishGenSnow::GenFinish(
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cFinishGenIce: // cFinishGenIce:
void cFinishGenIce::GenFinish( void cFinishGenIce::GenFinish(cChunkDesc & a_ChunkDesc)
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
)
{ {
// Turn surface water into ice in icy biomes // Turn surface water into ice in icy biomes
for (int z = 0; z < cChunkDef::Width; z++) for (int z = 0; z < cChunkDef::Width; z++)
{ {
for (int x = 0; x < cChunkDef::Width; x++) for (int x = 0; x < cChunkDef::Width; x++)
{ {
switch (cChunkDef::GetBiome(a_BiomeMap, x, z)) switch (a_ChunkDesc.GetBiome(x, z))
{ {
case biIcePlains: case biIcePlains:
case biIceMountains: case biIceMountains:
@ -276,13 +244,13 @@ void cFinishGenIce::GenFinish(
case biFrozenRiver: case biFrozenRiver:
case biFrozenOcean: case biFrozenOcean:
{ {
int Height = cChunkDef::GetHeight(a_HeightMap, x, z); int Height = a_ChunkDesc.GetHeight(x, z);
switch (cChunkDef::GetBlock(a_BlockTypes, x, Height, z)) switch (a_ChunkDesc.GetBlockType(x, Height, z))
{ {
case E_BLOCK_WATER: case E_BLOCK_WATER:
case E_BLOCK_STATIONARY_WATER: case E_BLOCK_STATIONARY_WATER:
{ {
cChunkDef::SetBlock(a_BlockTypes, x, Height, z, E_BLOCK_ICE); a_ChunkDesc.SetBlockType(x, Height, z, E_BLOCK_ICE);
break; break;
} }
} }
@ -300,68 +268,58 @@ void cFinishGenIce::GenFinish(
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cFinishGenLilypads: // cFinishGenLilypads:
int cFinishGenLilypads::GetNumLilypads(const cChunkDef::BiomeMap & a_BiomeMap) int cFinishGenSingleBiomeSingleTopBlock::GetNumToGen(const cChunkDef::BiomeMap & a_BiomeMap)
{ {
int res = 0; int res = 0;
for (int i = 0; i < ARRAYCOUNT(a_BiomeMap); i++) for (int i = 0; i < ARRAYCOUNT(a_BiomeMap); i++)
{ {
if (a_BiomeMap[i] == biSwampland) if (a_BiomeMap[i] == m_Biome)
{ {
res++; res++;
} }
} // for i - a_BiomeMap[] } // for i - a_BiomeMap[]
return res / 64; return m_Amount * res / 256;
} }
void cFinishGenLilypads::GenFinish( void cFinishGenSingleBiomeSingleTopBlock::GenFinish(cChunkDesc & a_ChunkDesc)
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
)
{ {
// Add Lilypads on top of water surface in Swampland // Add Lilypads on top of water surface in Swampland
int NumLilypads = GetNumLilypads(a_BiomeMap); int NumToGen = GetNumToGen(a_ChunkDesc.GetBiomeMap());
for (int i = 0; i < NumLilypads; i++) int ChunkX = a_ChunkDesc.GetChunkX();
int ChunkZ = a_ChunkDesc.GetChunkZ();
for (int i = 0; i < NumToGen; i++)
{ {
int x = (m_Noise.IntNoise3DInt(a_ChunkX + a_ChunkZ, a_ChunkZ, i) / 13) % cChunkDef::Width; int x = (m_Noise.IntNoise3DInt(ChunkX + ChunkZ, ChunkZ, i) / 13) % cChunkDef::Width;
int z = (m_Noise.IntNoise3DInt(a_ChunkX - a_ChunkZ, i, a_ChunkZ) / 11) % cChunkDef::Width; int z = (m_Noise.IntNoise3DInt(ChunkX - ChunkZ, i, ChunkZ) / 11) % cChunkDef::Width;
// Place a lily pad at {x, z} if possible (swampland, empty block, water below): // Place the block at {x, z} if possible:
if (cChunkDef::GetBiome(a_BiomeMap, x, z) != biSwampland) if (a_ChunkDesc.GetBiome(x, z) != m_Biome)
{ {
// not swampland // Incorrect biome
continue; continue;
} }
int Height = cChunkDef::GetHeight(a_HeightMap, x, z); int Height = a_ChunkDesc.GetHeight(x, z);
if (Height >= cChunkDef::Height) if (Height >= cChunkDef::Height)
{ {
// Too high up // Too high up
continue; continue;
} }
if (cChunkDef::GetBlock(a_BlockTypes, x, Height + 1, z) != E_BLOCK_AIR) if (a_ChunkDesc.GetBlockType(x, Height + 1, z) != E_BLOCK_AIR)
{ {
// not empty block // Not an empty block
continue; continue;
} }
switch (cChunkDef::GetBlock(a_BlockTypes, x, Height, z)) BLOCKTYPE BlockBelow = a_ChunkDesc.GetBlockType(x, Height, z);
if ((BlockBelow == m_AllowedBelow1) || (BlockBelow == m_AllowedBelow2))
{ {
case E_BLOCK_WATER: a_ChunkDesc.SetBlockType(x, Height + 1, z, m_BlockType);
case E_BLOCK_STATIONARY_WATER: a_ChunkDesc.SetHeight(x, z, Height + 1);
{
cChunkDef::SetBlock(a_BlockTypes, x, Height + 1, z, E_BLOCK_LILY_PAD);
cChunkDef::SetHeight(a_HeightMap, x, z, Height + 1);
break;
} }
} // switch (GetBlock)
} // for i } // for i
} }
@ -372,24 +330,17 @@ void cFinishGenLilypads::GenFinish(
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cFinishGenBottomLava: // cFinishGenBottomLava:
void cFinishGenBottomLava::GenFinish( void cFinishGenBottomLava::GenFinish(cChunkDesc & a_ChunkDesc)
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
)
{ {
cChunkDef::BlockTypes & BlockTypes = a_ChunkDesc.GetBlockTypes();
for (int y = m_Level; y > 0; y--) for (int y = m_Level; y > 0; y--)
{ {
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++)
{ {
int Index = cChunkDef::MakeIndexNoCheck(x, y, z); int Index = cChunkDef::MakeIndexNoCheck(x, y, z);
if (a_BlockTypes[Index] == E_BLOCK_AIR) if (BlockTypes[Index] == E_BLOCK_AIR)
{ {
a_BlockTypes[Index] = E_BLOCK_STATIONARY_LAVA; BlockTypes[Index] = E_BLOCK_STATIONARY_LAVA;
} }
} // for x, for z } // for x, for z
} // for y } // for y
@ -411,19 +362,11 @@ cFinishGenPreSimulator::cFinishGenPreSimulator(void)
void cFinishGenPreSimulator::GenFinish( void cFinishGenPreSimulator::GenFinish(cChunkDesc & a_ChunkDesc)
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
)
{ {
CollapseSandGravel(a_BlockTypes, a_HeightMap); CollapseSandGravel(a_ChunkDesc.GetBlockTypes(), a_ChunkDesc.GetHeightMap());
StationarizeFluid(a_BlockTypes, a_HeightMap, E_BLOCK_WATER, E_BLOCK_STATIONARY_WATER); StationarizeFluid(a_ChunkDesc.GetBlockTypes(), a_ChunkDesc.GetHeightMap(), E_BLOCK_WATER, E_BLOCK_STATIONARY_WATER);
StationarizeFluid(a_BlockTypes, a_HeightMap, E_BLOCK_LAVA, E_BLOCK_STATIONARY_LAVA); StationarizeFluid(a_ChunkDesc.GetBlockTypes(), a_ChunkDesc.GetHeightMap(), E_BLOCK_LAVA, E_BLOCK_STATIONARY_LAVA);
// TODO: other operations // TODO: other operations
} }
@ -574,77 +517,6 @@ void cFinishGenPreSimulator::StationarizeFluid(
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cFinishGenDeadBushes:
int cFinishGenDeadBushes::GetNumDeadBushes(const cChunkDef::BiomeMap & a_BiomeMap)
{
int res = 0;
for (int i = 0; i < ARRAYCOUNT(a_BiomeMap); i++)
{
if (a_BiomeMap[i] == biDesert)
{
res++;
}
} // for i - a_BiomeMap[]
return res / 128;
}
void cFinishGenDeadBushes::GenFinish(
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
)
{
// Add DeadBushes on top of sand surface in Desert
int NumDeadBushes = GetNumDeadBushes(a_BiomeMap);
for (int i = 0; i < NumDeadBushes; i++)
{
int x = (m_Noise.IntNoise3DInt(a_ChunkX + a_ChunkZ, a_ChunkZ, i) / 13) % cChunkDef::Width;
int z = (m_Noise.IntNoise3DInt(a_ChunkX - a_ChunkZ, i, a_ChunkZ) / 11) % cChunkDef::Width;
// Place a dead bush at {x, z} if possible (desert, empty block, sand below):
if (cChunkDef::GetBiome(a_BiomeMap, x, z) != biDesert)
{
// not swampland
continue;
}
int Height = cChunkDef::GetHeight(a_HeightMap, x, z);
if (Height >= cChunkDef::Height)
{
// Too high up
continue;
}
if (cChunkDef::GetBlock(a_BlockTypes, x, Height + 1, z) != E_BLOCK_AIR)
{
// not empty block
continue;
}
switch (cChunkDef::GetBlock(a_BlockTypes, x, Height, z))
{
case E_BLOCK_SAND:
{
cChunkDef::SetBlock(a_BlockTypes, x, Height + 1, z, E_BLOCK_DEAD_BUSH);
cChunkDef::SetHeight(a_HeightMap, x, z, Height + 1);
break;
}
} // switch (GetBlock)
} // for i
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cFinishGenFluidSprings: // cFinishGenFluidSprings:
@ -699,17 +571,9 @@ cFinishGenFluidSprings::cFinishGenFluidSprings(int a_Seed, BLOCKTYPE a_Fluid, cI
void cFinishGenFluidSprings::GenFinish( void cFinishGenFluidSprings::GenFinish(cChunkDesc & a_ChunkDesc)
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
)
{ {
int ChanceRnd = (m_Noise.IntNoise3DInt(128 * a_ChunkX, 512, 256 * a_ChunkZ) / 13) % 100; int ChanceRnd = (m_Noise.IntNoise3DInt(128 * a_ChunkDesc.GetChunkX(), 512, 256 * a_ChunkDesc.GetChunkZ()) / 13) % 100;
if (ChanceRnd > m_Chance) if (ChanceRnd > m_Chance)
{ {
// Not in this chunk // Not in this chunk
@ -717,7 +581,7 @@ void cFinishGenFluidSprings::GenFinish(
} }
// Get the height at which to try: // Get the height at which to try:
int Height = m_Noise.IntNoise3DInt(128 * a_ChunkX, 512, 256 * a_ChunkZ) / 11; int Height = m_Noise.IntNoise3DInt(128 * a_ChunkDesc.GetChunkX(), 1024, 256 * a_ChunkDesc.GetChunkZ()) / 11;
Height %= m_HeightDistribution.GetSum(); Height %= m_HeightDistribution.GetSum();
Height = m_HeightDistribution.MapValue(Height); Height = m_HeightDistribution.MapValue(Height);
@ -729,20 +593,12 @@ void cFinishGenFluidSprings::GenFinish(
{ {
for (int x = 1; x < cChunkDef::Width - 1; x++) for (int x = 1; x < cChunkDef::Width - 1; x++)
{ {
switch (cChunkDef::GetBlock(a_BlockTypes, x, y, z)) switch (a_ChunkDesc.GetBlockType(x, y, z))
{ {
case E_BLOCK_NETHERRACK: case E_BLOCK_NETHERRACK:
{
if (m_Fluid != E_BLOCK_LAVA)
{
// Only lava springs in the netherrack
continue;
}
// fallthrough:
}
case E_BLOCK_STONE: case E_BLOCK_STONE:
{ {
if (TryPlaceSpring(a_BlockTypes, a_BlockMeta, x, y, z)) if (TryPlaceSpring(a_ChunkDesc.GetBlockTypes(), a_ChunkDesc.GetBlockMetas(), x, y, z))
{ {
// Succeeded, bail out // Succeeded, bail out
return; return;

View File

@ -28,15 +28,7 @@ class cFinishGenSnow :
{ {
protected: protected:
// cFinishGen override: // cFinishGen override:
virtual void GenFinish( virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
) override;
} ; } ;
@ -48,15 +40,7 @@ class cFinishGenIce :
{ {
protected: protected:
// cFinishGen override: // cFinishGen override:
virtual void GenFinish( virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
) override;
} ; } ;
@ -67,59 +51,57 @@ class cFinishGenSprinkleFoliage :
public cFinishGen public cFinishGen
{ {
public: public:
cFinishGenSprinkleFoliage(int a_Seed) : m_Seed(a_Seed) {} cFinishGenSprinkleFoliage(int a_Seed) : m_Noise(a_Seed), m_Seed(a_Seed) {}
protected: protected:
cNoise m_Noise;
int m_Seed; int m_Seed;
/// Tries to place sugarcane at the coords specified, returns true if successful /// Tries to place sugarcane at the coords specified, returns true if successful
bool TryAddSugarcane( bool TryAddSugarcane(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelY, int a_RelZ);
int a_ChunkX, int a_ChunkZ,
int a_RelX, int a_RelY, int a_RelZ, // relative block coords of the sugarcane's base
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta // Block meta to read and change
);
// cFinishGen override: // cFinishGen override:
virtual void GenFinish( virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
) override;
} ; } ;
class cFinishGenLilypads : /** This class adds a single top block in random positions in the specified biome on top of specified allowed blocks.
Used for:
- Lilypads finisher
- DeadBushes finisher
*/
class cFinishGenSingleBiomeSingleTopBlock :
public cFinishGen public cFinishGen
{ {
public: public:
cFinishGenLilypads(int a_Seed) : cFinishGenSingleBiomeSingleTopBlock(
m_Noise(a_Seed) int a_Seed, BLOCKTYPE a_BlockType, EMCSBiome a_Biome, int a_Amount,
BLOCKTYPE a_AllowedBelow1, BLOCKTYPE a_AllowedBelow2
) :
m_Noise(a_Seed),
m_BlockType(a_BlockType),
m_Biome(a_Biome),
m_Amount(a_Amount),
m_AllowedBelow1(a_AllowedBelow1),
m_AllowedBelow2(a_AllowedBelow2)
{ {
} }
protected: protected:
cNoise m_Noise; cNoise m_Noise;
BLOCKTYPE m_BlockType;
EMCSBiome m_Biome;
int m_Amount; ///< Relative amount of blocks to try adding. 1 = one block per 256 biome columns.
BLOCKTYPE m_AllowedBelow1; ///< First of the two blocktypes that are allowed below m_BlockType
BLOCKTYPE m_AllowedBelow2; ///< Second of the two blocktypes that are allowed below m_BlockType
int GetNumLilypads(const cChunkDef::BiomeMap & a_BiomeMap); int GetNumToGen(const cChunkDef::BiomeMap & a_BiomeMap);
// cFinishGen override: // cFinishGen override:
virtual void GenFinish( virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
) override;
} ; } ;
@ -139,15 +121,7 @@ protected:
int m_Level; int m_Level;
// cFinishGen override: // cFinishGen override:
virtual void GenFinish( virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
) override;
} ; } ;
@ -179,52 +153,13 @@ protected:
); );
// cFinishGen override: // cFinishGen override:
virtual void GenFinish( virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
) override;
} ; } ;
class cFinishGenDeadBushes :
public cFinishGen
{
public:
cFinishGenDeadBushes(int a_Seed) :
m_Noise(a_Seed)
{
}
protected:
cNoise m_Noise;
int GetNumDeadBushes(const cChunkDef::BiomeMap & a_BiomeMap);
// cFinishGen override:
virtual void GenFinish(
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
) override;
} ;
class cFinishGenFluidSprings : class cFinishGenFluidSprings :
public cFinishGen public cFinishGen
{ {
@ -239,15 +174,7 @@ protected:
int m_Chance; ///< Chance, [0..100], that a spring will be generated in a chunk int m_Chance; ///< Chance, [0..100], that a spring will be generated in a chunk
// cFinishGen override: // cFinishGen override:
virtual void GenFinish( virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
) override;
/// Tries to place a spring at the specified coords, checks neighbors. Returns true if successful /// Tries to place a spring at the specified coords, checks neighbors. Returns true if successful
bool TryPlaceSpring( bool TryPlaceSpring(

View File

@ -117,20 +117,15 @@ void cStructGenRavines::ClearCache(void)
void cStructGenRavines::GenStructures( void cStructGenRavines::GenStructures(cChunkDesc & a_ChunkDesc)
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
)
{ {
int ChunkX = a_ChunkDesc.GetChunkX();
int ChunkZ = a_ChunkDesc.GetChunkZ();
cRavines Ravines; cRavines Ravines;
GetRavinesForChunk(a_ChunkX, a_ChunkZ, Ravines); GetRavinesForChunk(ChunkX, ChunkZ, Ravines);
for (cRavines::const_iterator itr = Ravines.begin(); itr != Ravines.end(); ++itr) for (cRavines::const_iterator itr = Ravines.begin(), end = Ravines.end(); itr != end; ++itr)
{ {
(*itr)->ProcessChunk(a_ChunkX, a_ChunkZ, a_BlockTypes, a_HeightMap); (*itr)->ProcessChunk(ChunkX, ChunkZ, a_ChunkDesc.GetBlockTypes(), a_ChunkDesc.GetHeightMap());
} // for itr - Ravines[] } // for itr - Ravines[]
} }

View File

@ -38,14 +38,7 @@ protected:
void GetRavinesForChunk(int a_ChunkX, int a_ChunkZ, cRavines & a_Ravines); void GetRavinesForChunk(int a_ChunkX, int a_ChunkZ, cRavines & a_Ravines);
// cStructureGen override: // cStructureGen override:
virtual void GenStructures( virtual void GenStructures(cChunkDesc & a_ChunkDesc) override;
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
) override;
} ; } ;

View File

@ -70,68 +70,62 @@ static bool SortTreeBlocks(const sSetBlock & a_First, const sSetBlock & a_Second
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cStructGenTrees: // cStructGenTrees:
void cStructGenTrees::GenStructures( void cStructGenTrees::GenStructures(cChunkDesc & a_ChunkDesc)
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMetas, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
)
{ {
cChunkDef::BlockTypes WorkerBlockTypes; int ChunkX = a_ChunkDesc.GetChunkX();
cChunkDef::BlockNibbles WorkerBlockMeta; int ChunkZ = a_ChunkDesc.GetChunkZ();
cChunkDef::HeightMap WorkerHeight;
cEntityList Entities; cChunkDesc WorkerDesc(ChunkX, ChunkZ);
cBlockEntityList BlockEntities;
// Generate trees: // Generate trees:
for (int x = 0; x <= 2; x++) for (int x = 0; x <= 2; x++)
{ {
int BaseX = a_ChunkX + x - 1; int BaseX = ChunkX + x - 1;
for (int z = 0; z <= 2; z++) for (int z = 0; z <= 2; z++)
{ {
int BaseZ = a_ChunkZ + z - 1; int BaseZ = ChunkZ + z - 1;
cChunkDef::BlockTypes * BlT; cChunkDef::BlockTypes * BlT;
cChunkDef::BlockNibbles * BlM; cChunkDef::BlockNibbles * BlM;
cChunkDef::HeightMap * Hei; cChunkDef::HeightMap * Hei;
cChunkDef::BiomeMap * Bio;
cChunkDef::BiomeMap Biomes;
m_BiomeGen->GenBiomes(BaseX, BaseZ, Biomes);
if ((x != 1) || (z != 1)) if ((x != 1) || (z != 1))
{ {
BlT = &WorkerBlockTypes; BlT = &(WorkerDesc.GetBlockTypes());
BlM = &WorkerBlockMeta; BlM = &(WorkerDesc.GetBlockMetas());
Hei = &WorkerHeight; Hei = &(WorkerDesc.GetHeightMap());
Bio = &(WorkerDesc.GetBiomeMap());
WorkerDesc.SetChunkCoords(BaseX, BaseZ);
m_HeightGen->GenHeightMap (BaseX, BaseZ, *Hei); m_BiomeGen->GenBiomes (BaseX, BaseZ, WorkerDesc.GetBiomeMap());
m_CompositionGen->ComposeTerrain(BaseX, BaseZ, *BlT, *BlM, *Hei, Biomes, Entities, BlockEntities); m_HeightGen->GenHeightMap (BaseX, BaseZ, WorkerDesc.GetHeightMap());
m_CompositionGen->ComposeTerrain(WorkerDesc);
// TODO: Free the entity lists // TODO: Free the entity lists
} }
else else
{ {
BlT = &a_BlockTypes; BlT = &(a_ChunkDesc.GetBlockTypes());
BlM = &a_BlockMetas; BlM = &(a_ChunkDesc.GetBlockMetas());
Hei = &a_HeightMap; Hei = &(a_ChunkDesc.GetHeightMap());
Bio = &(a_ChunkDesc.GetBiomeMap());
} }
int NumTrees = GetNumTrees(BaseX, BaseZ, Biomes); int NumTrees = GetNumTrees(BaseX, BaseZ, *Bio);
sSetBlockVector OutsideLogs, OutsideOther; sSetBlockVector OutsideLogs, OutsideOther;
for (int i = 0; i < NumTrees; i++) for (int i = 0; i < NumTrees; i++)
{ {
GenerateSingleTree(BaseX, BaseZ, i, *BlT, *BlM, *Hei, Biomes, OutsideLogs, OutsideOther); GenerateSingleTree(BaseX, BaseZ, i, *BlT, *BlM, *Hei, *Bio, OutsideLogs, OutsideOther);
} }
sSetBlockVector IgnoredOverflow; sSetBlockVector IgnoredOverflow;
IgnoredOverflow.reserve(OutsideOther.size()); IgnoredOverflow.reserve(OutsideOther.size());
ApplyTreeImage(a_ChunkX, a_ChunkZ, a_BlockTypes, a_BlockMetas, OutsideOther, IgnoredOverflow); ApplyTreeImage(ChunkX, ChunkZ, a_ChunkDesc.GetBlockTypes(), a_ChunkDesc.GetBlockMetas(), OutsideOther, IgnoredOverflow);
IgnoredOverflow.clear(); IgnoredOverflow.clear();
IgnoredOverflow.reserve(OutsideLogs.size()); IgnoredOverflow.reserve(OutsideLogs.size());
ApplyTreeImage(a_ChunkX, a_ChunkZ, a_BlockTypes, a_BlockMetas, OutsideLogs, IgnoredOverflow); ApplyTreeImage(ChunkX, ChunkZ, a_ChunkDesc.GetBlockTypes(), a_ChunkDesc.GetBlockMetas(), OutsideLogs, IgnoredOverflow);
} // for z } // for z
} // for x } // for x
@ -142,9 +136,9 @@ void cStructGenTrees::GenStructures(
{ {
for (int y = cChunkDef::Height - 1; y >= 0; y--) for (int y = cChunkDef::Height - 1; y >= 0; y--)
{ {
if (cChunkDef::GetBlock(a_BlockTypes, x, y, z) != E_BLOCK_AIR) if (cChunkDef::GetBlock(a_ChunkDesc.GetBlockTypes(), x, y, z) != E_BLOCK_AIR)
{ {
cChunkDef::SetHeight(a_HeightMap, x, z, y); cChunkDef::SetHeight(a_ChunkDesc.GetHeightMap(), x, z, y);
break; break;
} }
} // for y } // for y
@ -306,23 +300,19 @@ int cStructGenTrees::GetNumTrees(
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cStructGenOreNests: // cStructGenOreNests:
void cStructGenOreNests::GenStructures( void cStructGenOreNests::GenStructures(cChunkDesc & a_ChunkDesc)
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
)
{ {
GenerateOre(a_ChunkX, a_ChunkZ, E_BLOCK_COAL_ORE, MAX_HEIGHT_COAL, NUM_NESTS_COAL, NEST_SIZE_COAL, a_BlockTypes, 1); int ChunkX = a_ChunkDesc.GetChunkX();
GenerateOre(a_ChunkX, a_ChunkZ, E_BLOCK_IRON_ORE, MAX_HEIGHT_IRON, NUM_NESTS_IRON, NEST_SIZE_IRON, a_BlockTypes, 2); int ChunkZ = a_ChunkDesc.GetChunkZ();
GenerateOre(a_ChunkX, a_ChunkZ, E_BLOCK_REDSTONE_ORE, MAX_HEIGHT_REDSTONE, NUM_NESTS_REDSTONE, NEST_SIZE_REDSTONE, a_BlockTypes, 3); cChunkDef::BlockTypes & BlockTypes = a_ChunkDesc.GetBlockTypes();
GenerateOre(a_ChunkX, a_ChunkZ, E_BLOCK_GOLD_ORE, MAX_HEIGHT_GOLD, NUM_NESTS_GOLD, NEST_SIZE_GOLD, a_BlockTypes, 4); GenerateOre(ChunkX, ChunkZ, E_BLOCK_COAL_ORE, MAX_HEIGHT_COAL, NUM_NESTS_COAL, NEST_SIZE_COAL, BlockTypes, 1);
GenerateOre(a_ChunkX, a_ChunkZ, E_BLOCK_DIAMOND_ORE, MAX_HEIGHT_DIAMOND, NUM_NESTS_DIAMOND, NEST_SIZE_DIAMOND, a_BlockTypes, 5); GenerateOre(ChunkX, ChunkZ, E_BLOCK_IRON_ORE, MAX_HEIGHT_IRON, NUM_NESTS_IRON, NEST_SIZE_IRON, BlockTypes, 2);
GenerateOre(a_ChunkX, a_ChunkZ, E_BLOCK_LAPIS_ORE, MAX_HEIGHT_LAPIS, NUM_NESTS_LAPIS, NEST_SIZE_LAPIS, a_BlockTypes, 6); GenerateOre(ChunkX, ChunkZ, E_BLOCK_REDSTONE_ORE, MAX_HEIGHT_REDSTONE, NUM_NESTS_REDSTONE, NEST_SIZE_REDSTONE, BlockTypes, 3);
GenerateOre(a_ChunkX, a_ChunkZ, E_BLOCK_DIRT, MAX_HEIGHT_DIRT, NUM_NESTS_DIRT, NEST_SIZE_DIRT, a_BlockTypes, 10); GenerateOre(ChunkX, ChunkZ, E_BLOCK_GOLD_ORE, MAX_HEIGHT_GOLD, NUM_NESTS_GOLD, NEST_SIZE_GOLD, BlockTypes, 4);
GenerateOre(a_ChunkX, a_ChunkZ, E_BLOCK_GRAVEL, MAX_HEIGHT_GRAVEL, NUM_NESTS_GRAVEL, NEST_SIZE_GRAVEL, a_BlockTypes, 11); GenerateOre(ChunkX, ChunkZ, E_BLOCK_DIAMOND_ORE, MAX_HEIGHT_DIAMOND, NUM_NESTS_DIAMOND, NEST_SIZE_DIAMOND, BlockTypes, 5);
GenerateOre(ChunkX, ChunkZ, E_BLOCK_LAPIS_ORE, MAX_HEIGHT_LAPIS, NUM_NESTS_LAPIS, NEST_SIZE_LAPIS, BlockTypes, 6);
GenerateOre(ChunkX, ChunkZ, E_BLOCK_DIRT, MAX_HEIGHT_DIRT, NUM_NESTS_DIRT, NEST_SIZE_DIRT, BlockTypes, 10);
GenerateOre(ChunkX, ChunkZ, E_BLOCK_GRAVEL, MAX_HEIGHT_GRAVEL, NUM_NESTS_GRAVEL, NEST_SIZE_GRAVEL, BlockTypes, 11);
} }

View File

@ -69,14 +69,7 @@ protected:
); );
// cStructureGen override: // cStructureGen override:
virtual void GenStructures( virtual void GenStructures(cChunkDesc & a_ChunkDesc) override;
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMetas, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
) override;
} ; } ;
@ -94,14 +87,7 @@ protected:
int m_Seed; int m_Seed;
// cStructureGen override: // cStructureGen override:
virtual void GenStructures( virtual void GenStructures(cChunkDesc & a_ChunkDesc) override;
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change
cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data
cEntityList & a_Entities, // Entities may be added or deleted
cBlockEntityList & a_BlockEntities // Block entities may be added or deleted
) override;
void GenerateOre(int a_ChunkX, int a_ChunkZ, BLOCKTYPE a_OreType, int a_MaxHeight, int a_NumNests, int a_NestSize, cChunkDef::BlockTypes & a_BlockTypes, int a_Seq); void GenerateOre(int a_ChunkX, int a_ChunkZ, BLOCKTYPE a_OreType, int a_MaxHeight, int a_NumNests, int a_NestSize, cChunkDef::BlockTypes & a_BlockTypes, int a_Seq);
} ; } ;
@ -110,3 +96,22 @@ protected:
class cStructGenLakes :
public cStructureGen
{
public:
cStructGenLakes(int a_Seed, BLOCKTYPE a_Fluid) : m_Noise(a_Seed), m_Seed(a_Seed), m_Fluid(a_Fluid) {}
protected:
cNoise m_Noise;
int m_Seed;
BLOCKTYPE m_Fluid;
// cStructureGen override:
virtual void GenStructures(cChunkDesc & a_ChunkDesc) override;
} ;