1
0
This commit is contained in:
Tiger Wang 2014-10-20 19:01:53 +01:00
commit 2334c8dd9d
36 changed files with 281 additions and 234 deletions

View File

@ -4,12 +4,14 @@ BasedDoge (Donated AlchemistVillage prefabs)
bearbin (Alexander Harkness) bearbin (Alexander Harkness)
derouinw derouinw
Diusrex Diusrex
Duralex Duralex
FakeTruth (founder) FakeTruth (founder)
Howaner
keyboard keyboard
Lapayo Lapayo
Luksor Luksor
marmot21 marmot21
Masy98
mborland mborland
mgueydan mgueydan
MikeHunsinger MikeHunsinger
@ -18,6 +20,7 @@ nesco
rs2k rs2k
SamJBarney SamJBarney
Sofapriester Sofapriester
SphinxC0re
STR_Warrior STR_Warrior
structinf (xdot) structinf (xdot)
Sxw1212 Sxw1212
@ -25,11 +28,9 @@ Taugeshtu
tigerw (Tiger Wang) tigerw (Tiger Wang)
tonibm19 tonibm19
UltraCoderRU UltraCoderRU
WebFreak001
worktycho worktycho
xoft xoft
Yeeeeezus (Donated AlchemistVillage prefabs) Yeeeeezus (Donated AlchemistVillage prefabs)
Howaner
Masy98
WebFreak001
Please add yourself to this list if you contribute to MCServer. Please add yourself to this list if you contribute to MCServer.

View File

@ -43,7 +43,7 @@ void BioGenSource::reload()
int seed = m_IniFile->GetValueSetI("Seed", "Seed", 0); int seed = m_IniFile->GetValueSetI("Seed", "Seed", 0);
bool unused = false; bool unused = false;
QMutexLocker lock(&m_Mtx); QMutexLocker lock(&m_Mtx);
m_BiomeGen.reset(cBiomeGen::CreateBiomeGen(*m_IniFile, seed, unused)); m_BiomeGen = cBiomeGen::CreateBiomeGen(*m_IniFile, seed, unused);
} }

View File

@ -53,7 +53,7 @@ protected:
cIniFilePtr m_IniFile; cIniFilePtr m_IniFile;
/** The generator used for generating biomes. */ /** The generator used for generating biomes. */
std::unique_ptr<cBiomeGen> m_BiomeGen; cBiomeGenPtr m_BiomeGen;
/** Guards m_BiomeGen against multithreaded access. */ /** Guards m_BiomeGen against multithreaded access. */
QMutex m_Mtx; QMutex m_Mtx;

View File

@ -59,7 +59,7 @@ GeneratorSetup::GeneratorSetup(const AString & a_IniFileName, QWidget * a_Parent
m_IniFile->SetValue("Generator", "Generator", "Composable"); m_IniFile->SetValue("Generator", "Generator", "Composable");
m_IniFile->SetValue("Generator", "BiomeGen", m_cbGenerator->currentText().toStdString()); m_IniFile->SetValue("Generator", "BiomeGen", m_cbGenerator->currentText().toStdString());
bool dummy; bool dummy;
delete cBiomeGen::CreateBiomeGen(*m_IniFile, 0, dummy); cBiomeGen::CreateBiomeGen(*m_IniFile, 0, dummy);
} }
updateFromIni(); updateFromIni();
@ -91,7 +91,7 @@ void GeneratorSetup::generatorChanged(const QString & a_NewName)
// Create a dummy biome gen from the INI file, this will create the defaults in the INI file: // Create a dummy biome gen from the INI file, this will create the defaults in the INI file:
bool dummy; bool dummy;
delete cBiomeGen::CreateBiomeGen(*m_IniFile, m_Seed, dummy); cBiomeGen::CreateBiomeGen(*m_IniFile, m_Seed, dummy);
// Read all values from the INI file and put them into the form layout: // Read all values from the INI file and put them into the form layout:
updateFromIni(); updateFromIni();

View File

@ -558,7 +558,11 @@ void cLuaState::Push(cEntity * a_Entity)
{ {
ASSERT(IsValid()); ASSERT(IsValid());
if (a_Entity->IsMob()) if (a_Entity == nullptr)
{
lua_pushnil(m_LuaState);
}
else if (a_Entity->IsMob())
{ {
// Don't push specific mob types, as those are not exported in the API: // Don't push specific mob types, as those are not exported in the API:
tolua_pushusertype(m_LuaState, a_Entity, "cMonster"); tolua_pushusertype(m_LuaState, a_Entity, "cMonster");
@ -566,7 +570,7 @@ void cLuaState::Push(cEntity * a_Entity)
else else
{ {
// Push the specific class type: // Push the specific class type:
tolua_pushusertype(m_LuaState, a_Entity, (a_Entity == nullptr) ? "cEntity" : a_Entity->GetClass()); tolua_pushusertype(m_LuaState, a_Entity, a_Entity->GetClass());
} }
m_NumCurrentFunctionArgs += 1; m_NumCurrentFunctionArgs += 1;
} }

View File

@ -363,7 +363,7 @@ protected:
} }
/** Variadic template recursor: More params to push. Push them and recurse. */ /** Variadic template recursor: More params to push. Push them and recurse. */
template<typename T, typename... Args> template <typename T, typename... Args>
inline bool PushCallPop(T a_Param, Args &&... args) inline bool PushCallPop(T a_Param, Args &&... args)
{ {
Push(a_Param); Push(a_Param);

View File

@ -1828,6 +1828,7 @@ bool cPluginManager::DoWithPlugin(const AString & a_PluginName, cPluginCallback
bool cPluginManager::AddPlugin(cPlugin * a_Plugin) bool cPluginManager::AddPlugin(cPlugin * a_Plugin)
{ {
m_Plugins[a_Plugin->GetDirectory()] = a_Plugin; m_Plugins[a_Plugin->GetDirectory()] = a_Plugin;
if (a_Plugin->Initialize()) if (a_Plugin->Initialize())
{ {
// Initialization OK // Initialization OK

View File

@ -1,9 +1,9 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
#include "../Chunk.h"
#include "MetaRotator.h" #include "MetaRotator.h"
#include "BlockSlab.h"
class cBlockLeverHandler : class cBlockLeverHandler :
@ -93,13 +93,35 @@ public:
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{ {
NIBBLETYPE Meta; NIBBLETYPE Meta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ);
a_Chunk.UnboundedRelGetBlockMeta(a_RelX, a_RelY, a_RelZ, Meta);
eBlockFace Face = BlockMetaDataToBlockFace(Meta);
AddFaceDirection(a_RelX, a_RelY, a_RelZ, BlockMetaDataToBlockFace(Meta), true); AddFaceDirection(a_RelX, a_RelY, a_RelZ, Face, true);
BLOCKTYPE BlockIsOn; a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn);
return (a_RelY > 0) && cBlockInfo::FullyOccupiesVoxel(BlockIsOn); if ((a_RelY < 0) || (a_RelY >= cChunkDef::Height -1))
{
return false;
}
BLOCKTYPE BlockIsOn;
a_Chunk.UnboundedRelGetBlock(a_RelX, a_RelY, a_RelZ, BlockIsOn, Meta);
if (cBlockInfo::FullyOccupiesVoxel(BlockIsOn))
{
return true;
}
else if (cBlockSlabHandler::IsAnySlabType(BlockIsOn))
{
// Check if the slab is turned up side down
if (((Meta & 0x08) == 0x08) && (Face == BLOCK_FACE_TOP))
{
return true;
}
}
return false;
} }

View File

@ -3,6 +3,7 @@
#include "BlockHandler.h" #include "BlockHandler.h"
#include "../World.h" #include "../World.h"
#include "BlockSlab.h"
@ -16,11 +17,33 @@ public:
: cBlockHandler(a_BlockType) : cBlockHandler(a_BlockType)
{ {
} }
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{ {
return ((a_RelY > 0) && cBlockInfo::FullyOccupiesVoxel(a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ))); if (a_RelY <= 0)
{
return false;
}
BLOCKTYPE BelowBlock;
NIBBLETYPE BelowBlockMeta;
a_Chunk.GetBlockTypeMeta(a_RelX, a_RelY - 1, a_RelZ, BelowBlock, BelowBlockMeta);
if (cBlockInfo::FullyOccupiesVoxel(BelowBlock))
{
return true;
}
else if (cBlockSlabHandler::IsAnySlabType(BelowBlock))
{
// Check if the slab is turned up side down
if ((BelowBlockMeta & 0x08) == 0x08)
{
return true;
}
}
return false;
} }

View File

@ -5,6 +5,7 @@
#include "Chunk.h" #include "Chunk.h"
#include "MetaRotator.h" #include "MetaRotator.h"
#include "ChunkInterface.h" #include "ChunkInterface.h"
#include "BlockSlab.h"
@ -44,6 +45,7 @@ public:
} }
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{ {
// Reset meta to zero // Reset meta to zero
@ -59,7 +61,28 @@ public:
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{ {
return ((a_RelY > 0) && cBlockInfo::IsSolid(a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ))); if (a_RelY <= 0)
{
return false;
}
BLOCKTYPE BelowBlock;
NIBBLETYPE BelowBlockMeta;
a_Chunk.GetBlockTypeMeta(a_RelX, a_RelY - 1, a_RelZ, BelowBlock, BelowBlockMeta);
if (cBlockInfo::FullyOccupiesVoxel(BelowBlock))
{
return true;
}
else if (cBlockSlabHandler::IsAnySlabType(BelowBlock))
{
// Check if the slab is turned up side down
if ((BelowBlockMeta & 0x08) == 0x08)
{
return true;
}
}
return false;
} }

View File

@ -13,6 +13,7 @@
#include "../Items/ItemHandler.h" #include "../Items/ItemHandler.h"
#include "Root.h" #include "Root.h"
#include "ChunkInterface.h" #include "ChunkInterface.h"
#include "../Entities/Player.h"

View File

@ -2613,7 +2613,7 @@ BLOCKTYPE cChunk::GetBlock(int a_RelX, int a_RelY, int a_RelZ) const
void cChunk::GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) void cChunk::GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const
{ {
a_BlockType = GetBlock(a_RelX, a_RelY, a_RelZ); a_BlockType = GetBlock(a_RelX, a_RelY, a_RelZ);
a_BlockMeta = m_ChunkData.GetMeta(a_RelX, a_RelY, a_RelZ); a_BlockMeta = m_ChunkData.GetMeta(a_RelX, a_RelY, a_RelZ);

View File

@ -186,7 +186,7 @@ public:
void FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta, bool a_SendToClients = true); // Doesn't force block updates on neighbors, use for simple changes such as grass growing etc. void FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta, bool a_SendToClients = true); // Doesn't force block updates on neighbors, use for simple changes such as grass growing etc.
BLOCKTYPE GetBlock(int a_RelX, int a_RelY, int a_RelZ) const; BLOCKTYPE GetBlock(int a_RelX, int a_RelY, int a_RelZ) const;
BLOCKTYPE GetBlock(const Vector3i & a_RelCoords) const { return GetBlock(a_RelCoords.x, a_RelCoords.y, a_RelCoords.z); } BLOCKTYPE GetBlock(const Vector3i & a_RelCoords) const { return GetBlock(a_RelCoords.x, a_RelCoords.y, a_RelCoords.z); }
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) const;
void GetBlockInfo (int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight); void GetBlockInfo (int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight);
/** Returns the chunk into which the specified block belongs, by walking the neighbors. /** Returns the chunk into which the specified block belongs, by walking the neighbors.

View File

@ -343,7 +343,7 @@ private:
cCriticalSection m_CSChunkLists; cCriticalSection m_CSChunkLists;
cChunkCoordsList m_LoadedChunks; // Chunks that the player belongs to cChunkCoordsList m_LoadedChunks; // Chunks that the player belongs to
cChunkCoordsList m_ChunksToSend; // Chunks that need to be sent to the player (queued because they weren't generated yet or there's not enough time to send them) cChunkCoordsList m_ChunksToSend; // Chunks that need to be sent to the player (queued because they weren't generated yet or there's not enough time to send them)
cChunkCoordsList m_SentChunks; // Store the coordinates of the chunks that the client has loaded cChunkCoordsList m_SentChunks; // Chunks that are currently sent to the client
cProtocol * m_Protocol; cProtocol * m_Protocol;

View File

@ -45,7 +45,7 @@ void cBioGenConstant::InitializeBiomeGen(cIniFile & a_IniFile)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cBioGenCache: // cBioGenCache:
cBioGenCache::cBioGenCache(cBiomeGen * a_BioGenToCache, int a_CacheSize) : cBioGenCache::cBioGenCache(cBiomeGenPtr a_BioGenToCache, int a_CacheSize) :
m_BioGenToCache(a_BioGenToCache), m_BioGenToCache(a_BioGenToCache),
m_CacheSize(a_CacheSize), m_CacheSize(a_CacheSize),
m_CacheOrder(new int[a_CacheSize]), m_CacheOrder(new int[a_CacheSize]),
@ -145,25 +145,13 @@ void cBioGenCache::InitializeBiomeGen(cIniFile & a_IniFile)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cBioGenMulticache: // cBioGenMulticache:
cBioGenMulticache::cBioGenMulticache(cBiomeGen * a_BioGenToCache, size_t a_CacheSize, size_t a_CachesLength) : cBioGenMulticache::cBioGenMulticache(cBiomeGenPtr a_BioGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches) :
m_CachesLength(a_CachesLength) m_NumSubCaches(a_NumSubCaches)
{ {
m_Caches.reserve(a_CachesLength); m_Caches.reserve(a_NumSubCaches);
for (size_t i = 0; i < a_CachesLength; i++) for (size_t i = 0; i < a_NumSubCaches; i++)
{ {
m_Caches.push_back(new cBioGenCache(a_BioGenToCache, a_CacheSize)); m_Caches.push_back(cBiomeGenPtr(new cBioGenCache(a_BioGenToCache, a_SubCacheSize)));
}
}
cBioGenMulticache::~cBioGenMulticache()
{
for (cBiomeGens::iterator it = m_Caches.begin(); it != m_Caches.end(); it++)
{
delete *it;
} }
} }
@ -174,7 +162,7 @@ cBioGenMulticache::~cBioGenMulticache()
void cBioGenMulticache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) void cBioGenMulticache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap)
{ {
const size_t coefficient = 3; const size_t coefficient = 3;
const size_t cacheIdx = ((size_t)a_ChunkX + coefficient * (size_t)a_ChunkZ) % m_CachesLength; const size_t cacheIdx = ((size_t)a_ChunkX + coefficient * (size_t)a_ChunkZ) % m_NumSubCaches;
m_Caches[cacheIdx]->GenBiomes(a_ChunkX, a_ChunkZ, a_BiomeMap); m_Caches[cacheIdx]->GenBiomes(a_ChunkX, a_ChunkZ, a_BiomeMap);
} }
@ -185,10 +173,9 @@ void cBioGenMulticache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMa
void cBioGenMulticache::InitializeBiomeGen(cIniFile & a_IniFile) void cBioGenMulticache::InitializeBiomeGen(cIniFile & a_IniFile)
{ {
for (cBiomeGens::iterator it = m_Caches.begin(); it != m_Caches.end(); it++) for (auto itr : m_Caches)
{ {
cBiomeGen * tmp = *it; itr->InitializeBiomeGen(a_IniFile);
tmp->InitializeBiomeGen(a_IniFile);
} }
} }
@ -785,7 +772,7 @@ void cBioGenTwoLevel::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap
int BiomeGroup = m_VoronoiLarge.GetValueAt(DistortX[x][z], DistortZ[x][z], SeedX, SeedZ, MinDist2) / 7; int BiomeGroup = m_VoronoiLarge.GetValueAt(DistortX[x][z], DistortZ[x][z], SeedX, SeedZ, MinDist2) / 7;
int BiomeIdx = m_VoronoiSmall.GetValueAt(DistortX[x][z], DistortZ[x][z], SeedX, SeedZ, MinDist2) / 11; int BiomeIdx = m_VoronoiSmall.GetValueAt(DistortX[x][z], DistortZ[x][z], SeedX, SeedZ, MinDist2) / 11;
int MinDist1 = (DistortX[x][z] - SeedX) * (DistortX[x][z] - SeedX) + (DistortZ[x][z] - SeedZ) * (DistortZ[x][z] - SeedZ); int MinDist1 = (DistortX[x][z] - SeedX) * (DistortX[x][z] - SeedX) + (DistortZ[x][z] - SeedZ) * (DistortZ[x][z] - SeedZ);
cChunkDef::SetBiome(a_BiomeMap, x, z, SelectBiome(BiomeGroup, BiomeIdx, (MinDist1 < MinDist2 / 4) ? 0 : 1)); cChunkDef::SetBiome(a_BiomeMap, x, z, SelectBiome(BiomeGroup, BiomeIdx, (MinDist1 < MinDist2 / 4) ? 1 : 0));
} }
} }
} }
@ -932,7 +919,7 @@ void cBioGenTwoLevel::InitializeBiomeGen(cIniFile & a_IniFile)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cBiomeGen: // cBiomeGen:
cBiomeGen * cBiomeGen::CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool & a_CacheOffByDefault) cBiomeGenPtr cBiomeGen::CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool & a_CacheOffByDefault)
{ {
AString BiomeGenName = a_IniFile.GetValueSet("Generator", "BiomeGen", ""); AString BiomeGenName = a_IniFile.GetValueSet("Generator", "BiomeGen", "");
if (BiomeGenName.empty()) if (BiomeGenName.empty())
@ -988,7 +975,7 @@ cBiomeGen * cBiomeGen::CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool & a
} }
res->InitializeBiomeGen(a_IniFile); res->InitializeBiomeGen(a_IniFile);
return res; return cBiomeGenPtr(res);
} }

View File

@ -48,12 +48,12 @@ class cBioGenCache :
typedef cBiomeGen super; typedef cBiomeGen super;
public: public:
cBioGenCache(cBiomeGen * a_BioGenToCache, int a_CacheSize); // Doesn't take ownership of a_BioGenToCache cBioGenCache(cBiomeGenPtr a_BioGenToCache, int a_CacheSize);
~cBioGenCache(); virtual ~cBioGenCache();
protected: protected:
cBiomeGen * m_BioGenToCache; cBiomeGenPtr m_BioGenToCache;
struct sCacheData struct sCacheData
{ {
@ -87,19 +87,21 @@ class cBioGenMulticache :
typedef cBiomeGen super; typedef cBiomeGen super;
public: public:
/* /* Creates a new multicache - a cache that divides the caching into several sub-caches based on the chunk coords.
a_CacheSize defines the size of each singular cache This allows us to use shorter cache depths with faster lookups for more covered area. (#381)
a_CachesLength defines how many caches are used for the multicache a_SubCacheSize defines the size of each sub-cache
*/ a_NumSubCaches defines how many sub-caches are used for the multicache. */
cBioGenMulticache(cBiomeGen * a_BioGenToCache, size_t a_CacheSize, size_t a_CachesLength); // Doesn't take ownership of a_BioGenToCache cBioGenMulticache(cBiomeGenPtr a_BioGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches);
~cBioGenMulticache();
protected: protected:
typedef std::vector<cBiomeGen *> cBiomeGens; typedef std::vector<cBiomeGenPtr> cBiomeGenPtrs;
size_t m_CachesLength; /** Number of sub-caches. Pulled out of m_Caches.size() for faster access. */
cBiomeGens m_Caches; size_t m_NumSubCaches;
/** Individual sub-caches. */
cBiomeGenPtrs m_Caches;
virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override; virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;

View File

@ -269,10 +269,10 @@ void cChunkDesc::ReadBlockArea(cBlockArea & a_Dest, int a_MinRelX, int a_MaxRelX
LOGWARNING("%s: MaxRelX less than zero, adjusting to zero", __FUNCTION__); LOGWARNING("%s: MaxRelX less than zero, adjusting to zero", __FUNCTION__);
a_MaxRelX = 0; a_MaxRelX = 0;
} }
else if (a_MaxRelX >= cChunkDef::Width) else if (a_MaxRelX > cChunkDef::Width)
{ {
LOGWARNING("%s: MaxRelX more than chunk width, adjusting to chunk width", __FUNCTION__); LOGWARNING("%s: MaxRelX more than chunk width, adjusting to chunk width", __FUNCTION__);
a_MaxRelX = cChunkDef::Width - 1; a_MaxRelX = cChunkDef::Width;
} }
if (a_MinRelY < 0) if (a_MinRelY < 0)
@ -290,10 +290,10 @@ void cChunkDesc::ReadBlockArea(cBlockArea & a_Dest, int a_MinRelX, int a_MaxRelX
LOGWARNING("%s: MaxRelY less than zero, adjusting to zero", __FUNCTION__); LOGWARNING("%s: MaxRelY less than zero, adjusting to zero", __FUNCTION__);
a_MaxRelY = 0; a_MaxRelY = 0;
} }
else if (a_MaxRelY >= cChunkDef::Height) else if (a_MaxRelY > cChunkDef::Height)
{ {
LOGWARNING("%s: MaxRelY more than chunk height, adjusting to chunk height", __FUNCTION__); LOGWARNING("%s: MaxRelY more than chunk height, adjusting to chunk height", __FUNCTION__);
a_MaxRelY = cChunkDef::Height - 1; a_MaxRelY = cChunkDef::Height;
} }
if (a_MinRelZ < 0) if (a_MinRelZ < 0)
@ -311,10 +311,10 @@ void cChunkDesc::ReadBlockArea(cBlockArea & a_Dest, int a_MinRelX, int a_MaxRelX
LOGWARNING("%s: MaxRelZ less than zero, adjusting to zero", __FUNCTION__); LOGWARNING("%s: MaxRelZ less than zero, adjusting to zero", __FUNCTION__);
a_MaxRelZ = 0; a_MaxRelZ = 0;
} }
else if (a_MaxRelZ >= cChunkDef::Width) else if (a_MaxRelZ > cChunkDef::Width)
{ {
LOGWARNING("%s: MaxRelZ more than chunk width, adjusting to chunk width", __FUNCTION__); LOGWARNING("%s: MaxRelZ more than chunk width, adjusting to chunk width", __FUNCTION__);
a_MaxRelZ = cChunkDef::Width - 1; a_MaxRelZ = cChunkDef::Width;
} }
// Prepare the block area: // Prepare the block area:

View File

@ -663,7 +663,7 @@ void cCompoGenNether::InitializeCompoGen(cIniFile & a_IniFile)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cCompoGenCache: // cCompoGenCache:
cCompoGenCache::cCompoGenCache(cTerrainCompositionGen & a_Underlying, int a_CacheSize) : cCompoGenCache::cCompoGenCache(cTerrainCompositionGenPtr a_Underlying, int a_CacheSize) :
m_Underlying(a_Underlying), m_Underlying(a_Underlying),
m_CacheSize(a_CacheSize), m_CacheSize(a_CacheSize),
m_CacheOrder(new int[a_CacheSize]), m_CacheOrder(new int[a_CacheSize]),
@ -739,7 +739,7 @@ void cCompoGenCache::ComposeTerrain(cChunkDesc & a_ChunkDesc)
// Not in the cache: // Not in the cache:
m_NumMisses++; m_NumMisses++;
m_Underlying.ComposeTerrain(a_ChunkDesc); m_Underlying->ComposeTerrain(a_ChunkDesc);
// Insert it as the first item in the MRU order: // Insert it as the first item in the MRU order:
int Idx = m_CacheOrder[m_CacheSize - 1]; int Idx = m_CacheOrder[m_CacheSize - 1];
@ -760,7 +760,7 @@ void cCompoGenCache::ComposeTerrain(cChunkDesc & a_ChunkDesc)
void cCompoGenCache::InitializeCompoGen(cIniFile & a_IniFile) void cCompoGenCache::InitializeCompoGen(cIniFile & a_IniFile)
{ {
m_Underlying.InitializeCompoGen(a_IniFile); m_Underlying->InitializeCompoGen(a_IniFile);
} }

View File

@ -144,12 +144,12 @@ protected:
/// Caches most-recently-used chunk composition of another composition generator. Caches only the types and metas /** Caches most-recently-used chunk composition of another composition generator. Caches only the types and metas */
class cCompoGenCache : class cCompoGenCache :
public cTerrainCompositionGen public cTerrainCompositionGen
{ {
public: public:
cCompoGenCache(cTerrainCompositionGen & a_Underlying, int a_CacheSize); // Doesn't take ownership of a_Underlying cCompoGenCache(cTerrainCompositionGenPtr a_Underlying, int a_CacheSize); // Doesn't take ownership of a_Underlying
~cCompoGenCache(); ~cCompoGenCache();
// cTerrainCompositionGen override: // cTerrainCompositionGen override:
@ -158,7 +158,7 @@ public:
protected: protected:
cTerrainCompositionGen & m_Underlying; cTerrainCompositionGenPtr m_Underlying;
struct sCacheData struct sCacheData
{ {

View File

@ -39,7 +39,7 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cTerrainCompositionGen: // cTerrainCompositionGen:
cTerrainCompositionGen * cTerrainCompositionGen::CreateCompositionGen(cIniFile & a_IniFile, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen, int a_Seed) cTerrainCompositionGenPtr cTerrainCompositionGen::CreateCompositionGen(cIniFile & a_IniFile, cBiomeGenPtr a_BiomeGen, cTerrainHeightGen & a_HeightGen, int a_Seed)
{ {
AString CompoGenName = a_IniFile.GetValueSet("Generator", "CompositionGen", ""); AString CompoGenName = a_IniFile.GetValueSet("Generator", "CompositionGen", "");
if (CompoGenName.empty()) if (CompoGenName.empty())
@ -107,7 +107,7 @@ cTerrainCompositionGen * cTerrainCompositionGen::CreateCompositionGen(cIniFile &
// Read the settings from the ini file: // Read the settings from the ini file:
res->InitializeCompoGen(a_IniFile); res->InitializeCompoGen(a_IniFile);
return res; return cTerrainCompositionGenPtr(res);
} }
@ -119,12 +119,9 @@ cTerrainCompositionGen * cTerrainCompositionGen::CreateCompositionGen(cIniFile &
cComposableGenerator::cComposableGenerator(cChunkGenerator & a_ChunkGenerator) : cComposableGenerator::cComposableGenerator(cChunkGenerator & a_ChunkGenerator) :
super(a_ChunkGenerator), super(a_ChunkGenerator),
m_BiomeGen(NULL), m_BiomeGen(nullptr),
m_HeightGen(NULL), m_HeightGen(nullptr),
m_CompositionGen(NULL), m_CompositionGen(nullptr)
m_UnderlyingBiomeGen(NULL),
m_UnderlyingHeightGen(NULL),
m_UnderlyingCompositionGen(NULL)
{ {
} }
@ -132,33 +129,6 @@ cComposableGenerator::cComposableGenerator(cChunkGenerator & a_ChunkGenerator) :
cComposableGenerator::~cComposableGenerator()
{
// Delete the generating composition:
for (cFinishGenList::const_iterator itr = m_FinishGens.begin(); itr != m_FinishGens.end(); ++itr)
{
delete *itr;
}
m_FinishGens.clear();
delete m_CompositionGen;
m_CompositionGen = NULL;
delete m_HeightGen;
m_HeightGen = NULL;
delete m_BiomeGen;
m_BiomeGen = NULL;
delete m_UnderlyingCompositionGen;
m_UnderlyingCompositionGen = NULL;
delete m_UnderlyingHeightGen;
m_UnderlyingHeightGen = NULL;
delete m_UnderlyingBiomeGen;
m_UnderlyingBiomeGen = NULL;
}
void cComposableGenerator::Initialize(cIniFile & a_IniFile) void cComposableGenerator::Initialize(cIniFile & a_IniFile)
{ {
super::Initialize(a_IniFile); super::Initialize(a_IniFile);
@ -245,15 +215,14 @@ void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile)
CacheSize = 4; CacheSize = 4;
} }
LOGD("Using a cache for biomegen of size %d.", CacheSize); LOGD("Using a cache for biomegen of size %d.", CacheSize);
m_UnderlyingBiomeGen = m_BiomeGen;
if (MultiCacheLength > 0) if (MultiCacheLength > 0)
{ {
LOGD("Enabling multicache for biomegen of length %d.", MultiCacheLength); LOGD("Enabling multicache for biomegen of length %d.", MultiCacheLength);
m_BiomeGen = new cBioGenMulticache(m_UnderlyingBiomeGen, CacheSize, MultiCacheLength); m_BiomeGen = cBiomeGenPtr(new cBioGenMulticache(m_BiomeGen, CacheSize, MultiCacheLength));
} }
else else
{ {
m_BiomeGen = new cBioGenCache(m_UnderlyingBiomeGen, CacheSize); m_BiomeGen = cBiomeGenPtr(new cBioGenCache(m_BiomeGen, CacheSize));
} }
} }
@ -264,7 +233,7 @@ void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile)
void cComposableGenerator::InitHeightGen(cIniFile & a_IniFile) void cComposableGenerator::InitHeightGen(cIniFile & a_IniFile)
{ {
bool CacheOffByDefault = false; bool CacheOffByDefault = false;
m_HeightGen = cTerrainHeightGen::CreateHeightGen(a_IniFile, *m_BiomeGen, m_ChunkGenerator.GetSeed(), CacheOffByDefault); m_HeightGen = cTerrainHeightGen::CreateHeightGen(a_IniFile, m_BiomeGen, m_ChunkGenerator.GetSeed(), CacheOffByDefault);
// Add a cache, if requested: // Add a cache, if requested:
int CacheSize = a_IniFile.GetValueSetI("Generator", "HeightGenCacheSize", CacheOffByDefault ? 0 : 64); int CacheSize = a_IniFile.GetValueSetI("Generator", "HeightGenCacheSize", CacheOffByDefault ? 0 : 64);
@ -278,8 +247,7 @@ void cComposableGenerator::InitHeightGen(cIniFile & a_IniFile)
CacheSize = 4; CacheSize = 4;
} }
LOGD("Using a cache for Heightgen of size %d.", CacheSize); LOGD("Using a cache for Heightgen of size %d.", CacheSize);
m_UnderlyingHeightGen = m_HeightGen; m_HeightGen = cTerrainHeightGenPtr(new cHeiGenCache(m_HeightGen, CacheSize));
m_HeightGen = new cHeiGenCache(*m_UnderlyingHeightGen, CacheSize);
} }
} }
@ -289,13 +257,12 @@ void cComposableGenerator::InitHeightGen(cIniFile & a_IniFile)
void cComposableGenerator::InitCompositionGen(cIniFile & a_IniFile) void cComposableGenerator::InitCompositionGen(cIniFile & a_IniFile)
{ {
m_CompositionGen = cTerrainCompositionGen::CreateCompositionGen(a_IniFile, *m_BiomeGen, *m_HeightGen, m_ChunkGenerator.GetSeed()); m_CompositionGen = cTerrainCompositionGen::CreateCompositionGen(a_IniFile, m_BiomeGen, *m_HeightGen, m_ChunkGenerator.GetSeed());
int CompoGenCacheSize = a_IniFile.GetValueSetI("Generator", "CompositionGenCacheSize", 64); int CompoGenCacheSize = a_IniFile.GetValueSetI("Generator", "CompositionGenCacheSize", 64);
if (CompoGenCacheSize > 1) if (CompoGenCacheSize > 1)
{ {
m_UnderlyingCompositionGen = m_CompositionGen; m_CompositionGen = cTerrainCompositionGenPtr(new cCompoGenCache(m_CompositionGen, 32));
m_CompositionGen = new cCompoGenCache(*m_UnderlyingCompositionGen, 32);
} }
} }
@ -319,7 +286,7 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
{ {
int DefaultBottomLavaLevel = (Dimension == dimNether) ? 30 : 10; int DefaultBottomLavaLevel = (Dimension == dimNether) ? 30 : 10;
int BottomLavaLevel = a_IniFile.GetValueSetI("Generator", "BottomLavaLevel", DefaultBottomLavaLevel); int BottomLavaLevel = a_IniFile.GetValueSetI("Generator", "BottomLavaLevel", DefaultBottomLavaLevel);
m_FinishGens.push_back(new cFinishGenBottomLava(BottomLavaLevel)); m_FinishGens.push_back(cFinishGenPtr(new cFinishGenBottomLava(BottomLavaLevel)));
} }
else if (NoCaseCompare(*itr, "DeadBushes") == 0) else if (NoCaseCompare(*itr, "DeadBushes") == 0)
{ {
@ -341,20 +308,20 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
AllowedBlocks.push_back(E_BLOCK_HARDENED_CLAY); AllowedBlocks.push_back(E_BLOCK_HARDENED_CLAY);
AllowedBlocks.push_back(E_BLOCK_STAINED_CLAY); AllowedBlocks.push_back(E_BLOCK_STAINED_CLAY);
m_FinishGens.push_back(new cFinishGenSingleTopBlock(Seed, E_BLOCK_DEAD_BUSH, AllowedBiomes, 2, AllowedBlocks)); m_FinishGens.push_back(cFinishGenPtr(new cFinishGenSingleTopBlock(Seed, E_BLOCK_DEAD_BUSH, AllowedBiomes, 2, AllowedBlocks)));
} }
else if (NoCaseCompare(*itr, "DirectOverhangs") == 0) else if (NoCaseCompare(*itr, "DirectOverhangs") == 0)
{ {
m_FinishGens.push_back(new cStructGenDirectOverhangs(Seed)); m_FinishGens.push_back(cFinishGenPtr(new cStructGenDirectOverhangs(Seed)));
} }
else if (NoCaseCompare(*itr, "DistortedMembraneOverhangs") == 0) else if (NoCaseCompare(*itr, "DistortedMembraneOverhangs") == 0)
{ {
m_FinishGens.push_back(new cStructGenDistortedMembraneOverhangs(Seed)); m_FinishGens.push_back(cFinishGenPtr(new cStructGenDistortedMembraneOverhangs(Seed)));
} }
else if (NoCaseCompare(*itr, "DualRidgeCaves") == 0) else if (NoCaseCompare(*itr, "DualRidgeCaves") == 0)
{ {
float Threshold = (float)a_IniFile.GetValueSetF("Generator", "DualRidgeCavesThreshold", 0.3); float Threshold = (float)a_IniFile.GetValueSetF("Generator", "DualRidgeCavesThreshold", 0.3);
m_FinishGens.push_back(new cStructGenDualRidgeCaves(Seed, Threshold)); m_FinishGens.push_back(cFinishGenPtr(new cStructGenDualRidgeCaves(Seed, Threshold)));
} }
else if (NoCaseCompare(*itr, "DungeonRooms") == 0) else if (NoCaseCompare(*itr, "DungeonRooms") == 0)
{ {
@ -362,24 +329,24 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
int MaxSize = a_IniFile.GetValueSetI("Generator", "DungeonRoomsMaxSize", 7); int MaxSize = a_IniFile.GetValueSetI("Generator", "DungeonRoomsMaxSize", 7);
int MinSize = a_IniFile.GetValueSetI("Generator", "DungeonRoomsMinSize", 5); int MinSize = a_IniFile.GetValueSetI("Generator", "DungeonRoomsMinSize", 5);
AString HeightDistrib = a_IniFile.GetValueSet ("Generator", "DungeonRoomsHeightDistrib", "0, 0; 10, 10; 11, 500; 40, 500; 60, 40; 90, 1"); AString HeightDistrib = a_IniFile.GetValueSet ("Generator", "DungeonRoomsHeightDistrib", "0, 0; 10, 10; 11, 500; 40, 500; 60, 40; 90, 1");
m_FinishGens.push_back(new cDungeonRoomsFinisher(*m_HeightGen, Seed, GridSize, MaxSize, MinSize, HeightDistrib)); m_FinishGens.push_back(cFinishGenPtr(new cDungeonRoomsFinisher(m_HeightGen, Seed, GridSize, MaxSize, MinSize, HeightDistrib)));
} }
else if (NoCaseCompare(*itr, "Ice") == 0) else if (NoCaseCompare(*itr, "Ice") == 0)
{ {
m_FinishGens.push_back(new cFinishGenIce); m_FinishGens.push_back(cFinishGenPtr(new cFinishGenIce));
} }
else if (NoCaseCompare(*itr, "LavaLakes") == 0) else if (NoCaseCompare(*itr, "LavaLakes") == 0)
{ {
int Probability = a_IniFile.GetValueSetI("Generator", "LavaLakesProbability", 10); int Probability = a_IniFile.GetValueSetI("Generator", "LavaLakesProbability", 10);
m_FinishGens.push_back(new cStructGenLakes(Seed * 5 + 16873, E_BLOCK_STATIONARY_LAVA, *m_HeightGen, Probability)); m_FinishGens.push_back(cFinishGenPtr(new cStructGenLakes(Seed * 5 + 16873, E_BLOCK_STATIONARY_LAVA, m_HeightGen, Probability)));
} }
else if (NoCaseCompare(*itr, "LavaSprings") == 0) else if (NoCaseCompare(*itr, "LavaSprings") == 0)
{ {
m_FinishGens.push_back(new cFinishGenFluidSprings(Seed, E_BLOCK_LAVA, a_IniFile, Dimension)); m_FinishGens.push_back(cFinishGenPtr(new cFinishGenFluidSprings(Seed, E_BLOCK_LAVA, a_IniFile, Dimension)));
} }
else if (NoCaseCompare(*itr, "MarbleCaves") == 0) else if (NoCaseCompare(*itr, "MarbleCaves") == 0)
{ {
m_FinishGens.push_back(new cStructGenMarbleCaves(Seed)); m_FinishGens.push_back(cFinishGenPtr(new cStructGenMarbleCaves(Seed)));
} }
else if (NoCaseCompare(*itr, "MineShafts") == 0) else if (NoCaseCompare(*itr, "MineShafts") == 0)
{ {
@ -389,10 +356,10 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
int ChanceCorridor = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceCorridor", 600); int ChanceCorridor = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceCorridor", 600);
int ChanceCrossing = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceCrossing", 200); int ChanceCrossing = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceCrossing", 200);
int ChanceStaircase = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceStaircase", 200); int ChanceStaircase = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceStaircase", 200);
m_FinishGens.push_back(new cStructGenMineShafts( m_FinishGens.push_back(cFinishGenPtr(new cStructGenMineShafts(
Seed, GridSize, MaxOffset, MaxSystemSize, Seed, GridSize, MaxOffset, MaxSystemSize,
ChanceCorridor, ChanceCrossing, ChanceStaircase ChanceCorridor, ChanceCrossing, ChanceStaircase
)); )));
} }
else if (NoCaseCompare(*itr, "Lilypads") == 0) else if (NoCaseCompare(*itr, "Lilypads") == 0)
{ {
@ -406,7 +373,7 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
AllowedBlocks.push_back(E_BLOCK_WATER); AllowedBlocks.push_back(E_BLOCK_WATER);
AllowedBlocks.push_back(E_BLOCK_STATIONARY_WATER); AllowedBlocks.push_back(E_BLOCK_STATIONARY_WATER);
m_FinishGens.push_back(new cFinishGenSingleTopBlock(Seed, E_BLOCK_LILY_PAD, AllowedBiomes, 4, AllowedBlocks)); m_FinishGens.push_back(cFinishGenPtr(new cFinishGenSingleTopBlock(Seed, E_BLOCK_LILY_PAD, AllowedBiomes, 4, AllowedBlocks)));
} }
else if (NoCaseCompare(*itr, "NaturalPatches") == 0) else if (NoCaseCompare(*itr, "NaturalPatches") == 0)
{ {
@ -455,18 +422,18 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
AndesiteVein.NestSize = 32; AndesiteVein.NestSize = 32;
Ores.push_back(AndesiteVein); Ores.push_back(AndesiteVein);
m_FinishGens.push_back(new cStructGenOreNests(Seed, Ores, E_BLOCK_STONE)); m_FinishGens.push_back(cFinishGenPtr(new cStructGenOreNests(Seed, Ores, E_BLOCK_STONE)));
} }
else if (NoCaseCompare(*itr, "NetherClumpFoliage") == 0) else if (NoCaseCompare(*itr, "NetherClumpFoliage") == 0)
{ {
m_FinishGens.push_back(new cFinishGenNetherClumpFoliage(Seed)); m_FinishGens.push_back(cFinishGenPtr(new cFinishGenNetherClumpFoliage(Seed)));
} }
else if (NoCaseCompare(*itr, "NetherForts") == 0) else if (NoCaseCompare(*itr, "NetherForts") == 0)
{ {
int GridSize = a_IniFile.GetValueSetI("Generator", "NetherFortsGridSize", 512); int GridSize = a_IniFile.GetValueSetI("Generator", "NetherFortsGridSize", 512);
int MaxOffset = a_IniFile.GetValueSetI("Generator", "NetherFortMaxOffset", 128); int MaxOffset = a_IniFile.GetValueSetI("Generator", "NetherFortMaxOffset", 128);
int MaxDepth = a_IniFile.GetValueSetI("Generator", "NetherFortsMaxDepth", 12); int MaxDepth = a_IniFile.GetValueSetI("Generator", "NetherFortsMaxDepth", 12);
m_FinishGens.push_back(new cNetherFortGen(Seed, GridSize, MaxOffset, MaxDepth)); m_FinishGens.push_back(cFinishGenPtr(new cNetherFortGen(Seed, GridSize, MaxOffset, MaxDepth)));
} }
else if (NoCaseCompare(*itr, "NetherOreNests") == 0) else if (NoCaseCompare(*itr, "NetherOreNests") == 0)
{ {
@ -480,7 +447,7 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
QuartzVein.NestSize = 8; QuartzVein.NestSize = 8;
Ores.push_back(QuartzVein); Ores.push_back(QuartzVein);
m_FinishGens.push_back(new cStructGenOreNests(Seed, Ores, E_BLOCK_NETHERRACK)); m_FinishGens.push_back(cFinishGenPtr(new cStructGenOreNests(Seed, Ores, E_BLOCK_NETHERRACK)));
} }
else if (NoCaseCompare(*itr, "OreNests") == 0) else if (NoCaseCompare(*itr, "OreNests") == 0)
@ -535,11 +502,11 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
DiamondVein.NestSize = 4; DiamondVein.NestSize = 4;
Ores.push_back(DiamondVein); Ores.push_back(DiamondVein);
m_FinishGens.push_back(new cStructGenOreNests(Seed, Ores, E_BLOCK_STONE)); m_FinishGens.push_back(cFinishGenPtr(new cStructGenOreNests(Seed, Ores, E_BLOCK_STONE)));
} }
else if (NoCaseCompare(*itr, "POCPieces") == 0) else if (NoCaseCompare(*itr, "POCPieces") == 0)
{ {
m_FinishGens.push_back(new cPOCPieceGenerator(Seed)); m_FinishGens.push_back(cFinishGenPtr(new cPOCPieceGenerator(Seed)));
} }
else if (NoCaseCompare(*itr, "PreSimulator") == 0) else if (NoCaseCompare(*itr, "PreSimulator") == 0)
{ {
@ -548,7 +515,7 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
bool PreSimulateWater = a_IniFile.GetValueSetB("Generator", "PreSimulatorWater", true); bool PreSimulateWater = a_IniFile.GetValueSetB("Generator", "PreSimulatorWater", true);
bool PreSimulateLava = a_IniFile.GetValueSetB("Generator", "PreSimulatorLava", true); bool PreSimulateLava = a_IniFile.GetValueSetB("Generator", "PreSimulatorLava", true);
m_FinishGens.push_back(new cFinishGenPreSimulator(PreSimulateFallingBlocks, PreSimulateWater, PreSimulateLava)); m_FinishGens.push_back(cFinishGenPtr(new cFinishGenPreSimulator(PreSimulateFallingBlocks, PreSimulateWater, PreSimulateLava)));
} }
else if (NoCaseCompare(*itr, "RainbowRoads") == 0) else if (NoCaseCompare(*itr, "RainbowRoads") == 0)
{ {
@ -556,11 +523,11 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
int MaxOffset = a_IniFile.GetValueSetI("Generator", "RainbowRoadsMaxOffset", 128); int MaxOffset = a_IniFile.GetValueSetI("Generator", "RainbowRoadsMaxOffset", 128);
int MaxDepth = a_IniFile.GetValueSetI("Generator", "RainbowRoadsMaxDepth", 30); int MaxDepth = a_IniFile.GetValueSetI("Generator", "RainbowRoadsMaxDepth", 30);
int MaxSize = a_IniFile.GetValueSetI("Generator", "RainbowRoadsMaxSize", 260); int MaxSize = a_IniFile.GetValueSetI("Generator", "RainbowRoadsMaxSize", 260);
m_FinishGens.push_back(new cRainbowRoadsGen(Seed, GridSize, MaxOffset, MaxDepth, MaxSize)); m_FinishGens.push_back(cFinishGenPtr(new cRainbowRoadsGen(Seed, GridSize, MaxOffset, MaxDepth, MaxSize)));
} }
else if (NoCaseCompare(*itr, "Ravines") == 0) else if (NoCaseCompare(*itr, "Ravines") == 0)
{ {
m_FinishGens.push_back(new cStructGenRavines(Seed, 128)); m_FinishGens.push_back(cFinishGenPtr(new cStructGenRavines(Seed, 128)));
} }
else if (NoCaseCompare(*itr, "RoughRavines") == 0) else if (NoCaseCompare(*itr, "RoughRavines") == 0)
{ {
@ -580,7 +547,7 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
double MinCeilingHeightEdge = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinCeilingHeightEdge", 38); double MinCeilingHeightEdge = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinCeilingHeightEdge", 38);
double MaxCeilingHeightCenter = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxCeilingHeightCenter", 58); double MaxCeilingHeightCenter = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxCeilingHeightCenter", 58);
double MinCeilingHeightCenter = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinCeilingHeightCenter", 36); double MinCeilingHeightCenter = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinCeilingHeightCenter", 36);
m_FinishGens.push_back(new cRoughRavines( m_FinishGens.push_back(cFinishGenPtr(new cRoughRavines(
Seed, MaxSize, MinSize, Seed, MaxSize, MinSize,
(float)MaxCenterWidth, (float)MinCenterWidth, (float)MaxCenterWidth, (float)MinCenterWidth,
(float)MaxRoughness, (float)MinRoughness, (float)MaxRoughness, (float)MinRoughness,
@ -589,27 +556,27 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
(float)MaxCeilingHeightEdge, (float)MinCeilingHeightEdge, (float)MaxCeilingHeightEdge, (float)MinCeilingHeightEdge,
(float)MaxCeilingHeightCenter, (float)MinCeilingHeightCenter, (float)MaxCeilingHeightCenter, (float)MinCeilingHeightCenter,
GridSize, MaxOffset GridSize, MaxOffset
)); )));
} }
else if (NoCaseCompare(*itr, "Snow") == 0) else if (NoCaseCompare(*itr, "Snow") == 0)
{ {
m_FinishGens.push_back(new cFinishGenSnow); m_FinishGens.push_back(cFinishGenPtr(new cFinishGenSnow));
} }
else if (NoCaseCompare(*itr, "SprinkleFoliage") == 0) else if (NoCaseCompare(*itr, "SprinkleFoliage") == 0)
{ {
m_FinishGens.push_back(new cFinishGenSprinkleFoliage(Seed)); m_FinishGens.push_back(cFinishGenPtr(new cFinishGenSprinkleFoliage(Seed)));
} }
else if (NoCaseCompare(*itr, "TallGrass") == 0) else if (NoCaseCompare(*itr, "TallGrass") == 0)
{ {
m_FinishGens.push_back(new cFinishGenTallGrass(Seed)); m_FinishGens.push_back(cFinishGenPtr(new cFinishGenTallGrass(Seed)));
} }
else if (NoCaseCompare(*itr, "TestRails") == 0) else if (NoCaseCompare(*itr, "TestRails") == 0)
{ {
m_FinishGens.push_back(new cTestRailsGen(Seed, 100, 1, 7, 50)); m_FinishGens.push_back(cFinishGenPtr(new cTestRailsGen(Seed, 100, 1, 7, 50)));
} }
else if (NoCaseCompare(*itr, "Trees") == 0) else if (NoCaseCompare(*itr, "Trees") == 0)
{ {
m_FinishGens.push_back(new cStructGenTrees(Seed, m_BiomeGen, m_HeightGen, m_CompositionGen)); m_FinishGens.push_back(cFinishGenPtr(new cStructGenTrees(Seed, m_BiomeGen, m_HeightGen, m_CompositionGen)));
} }
else if (NoCaseCompare(*itr, "UnderwaterBases") == 0) else if (NoCaseCompare(*itr, "UnderwaterBases") == 0)
{ {
@ -617,7 +584,7 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
int MaxOffset = a_IniFile.GetValueSetI("Generator", "UnderwaterBaseMaxOffset", 128); int MaxOffset = a_IniFile.GetValueSetI("Generator", "UnderwaterBaseMaxOffset", 128);
int MaxDepth = a_IniFile.GetValueSetI("Generator", "UnderwaterBaseMaxDepth", 7); int MaxDepth = a_IniFile.GetValueSetI("Generator", "UnderwaterBaseMaxDepth", 7);
int MaxSize = a_IniFile.GetValueSetI("Generator", "UnderwaterBaseMaxSize", 128); int MaxSize = a_IniFile.GetValueSetI("Generator", "UnderwaterBaseMaxSize", 128);
m_FinishGens.push_back(new cUnderwaterBaseGen(Seed, GridSize, MaxOffset, MaxDepth, MaxSize, *m_BiomeGen)); m_FinishGens.push_back(cFinishGenPtr(new cUnderwaterBaseGen(Seed, GridSize, MaxOffset, MaxDepth, MaxSize, m_BiomeGen)));
} }
else if (NoCaseCompare(*itr, "Villages") == 0) else if (NoCaseCompare(*itr, "Villages") == 0)
{ {
@ -627,23 +594,23 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
int MaxSize = a_IniFile.GetValueSetI("Generator", "VillageMaxSize", 128); int MaxSize = a_IniFile.GetValueSetI("Generator", "VillageMaxSize", 128);
int MinDensity = a_IniFile.GetValueSetI("Generator", "VillageMinDensity", 50); int MinDensity = a_IniFile.GetValueSetI("Generator", "VillageMinDensity", 50);
int MaxDensity = a_IniFile.GetValueSetI("Generator", "VillageMaxDensity", 80); int MaxDensity = a_IniFile.GetValueSetI("Generator", "VillageMaxDensity", 80);
m_FinishGens.push_back(new cVillageGen(Seed, GridSize, MaxOffset, MaxDepth, MaxSize, MinDensity, MaxDensity, *m_BiomeGen, *m_HeightGen)); m_FinishGens.push_back(cFinishGenPtr(new cVillageGen(Seed, GridSize, MaxOffset, MaxDepth, MaxSize, MinDensity, MaxDensity, m_BiomeGen, m_HeightGen)));
} }
else if (NoCaseCompare(*itr, "WaterLakes") == 0) else if (NoCaseCompare(*itr, "WaterLakes") == 0)
{ {
int Probability = a_IniFile.GetValueSetI("Generator", "WaterLakesProbability", 25); int Probability = a_IniFile.GetValueSetI("Generator", "WaterLakesProbability", 25);
m_FinishGens.push_back(new cStructGenLakes(Seed * 3 + 652, E_BLOCK_STATIONARY_WATER, *m_HeightGen, Probability)); m_FinishGens.push_back(cFinishGenPtr(new cStructGenLakes(Seed * 3 + 652, E_BLOCK_STATIONARY_WATER, m_HeightGen, Probability)));
} }
else if (NoCaseCompare(*itr, "WaterSprings") == 0) else if (NoCaseCompare(*itr, "WaterSprings") == 0)
{ {
m_FinishGens.push_back(new cFinishGenFluidSprings(Seed, E_BLOCK_WATER, a_IniFile, Dimension)); m_FinishGens.push_back(cFinishGenPtr(new cFinishGenFluidSprings(Seed, E_BLOCK_WATER, a_IniFile, Dimension)));
} }
else if (NoCaseCompare(*itr, "WormNestCaves") == 0) else if (NoCaseCompare(*itr, "WormNestCaves") == 0)
{ {
int Size = a_IniFile.GetValueSetI("Generator", "WormNestCavesSize", 64); int Size = a_IniFile.GetValueSetI("Generator", "WormNestCavesSize", 64);
int Grid = a_IniFile.GetValueSetI("Generator", "WormNestCavesGrid", 96); int Grid = a_IniFile.GetValueSetI("Generator", "WormNestCavesGrid", 96);
int MaxOffset = a_IniFile.GetValueSetI("Generator", "WormNestMaxOffset", 32); int MaxOffset = a_IniFile.GetValueSetI("Generator", "WormNestMaxOffset", 32);
m_FinishGens.push_back(new cStructGenWormNestCaves(Seed, Size, Grid, MaxOffset)); m_FinishGens.push_back(cFinishGenPtr(new cStructGenWormNestCaves(Seed, Size, Grid, MaxOffset)));
} }
else else
{ {

View File

@ -24,6 +24,16 @@ See http://forum.mc-server.org/showthread.php?tid=409 for details.
// Forward-declare the shared pointers to subgenerator classes:
class cBiomeGen;
class cTerrainHeightGen;
class cTerrainCompositionGen;
class cFinishGen;
typedef SharedPtr<cBiomeGen> cBiomeGenPtr;
typedef SharedPtr<cTerrainHeightGen> cTerrainHeightGenPtr;
typedef SharedPtr<cTerrainCompositionGen> cTerrainCompositionGenPtr;
typedef SharedPtr<cFinishGen> cFinishGenPtr;
// fwd: Noise3DGenerator.h // fwd: Noise3DGenerator.h
class cNoise3DComposable; class cNoise3DComposable;
@ -53,8 +63,7 @@ public:
a_CacheOffByDefault gets set to whether the cache should be disabled by default. a_CacheOffByDefault gets set to whether the cache should be disabled by default.
Used in BiomeVisualiser, too. Used in BiomeVisualiser, too.
Implemented in BioGen.cpp! */ Implemented in BioGen.cpp! */
static cBiomeGen * CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool & a_CacheOffByDefault); static cBiomeGenPtr CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool & a_CacheOffByDefault);
} ; } ;
@ -83,7 +92,7 @@ public:
a_CacheOffByDefault gets set to whether the cache should be disabled by default a_CacheOffByDefault gets set to whether the cache should be disabled by default
Implemented in HeiGen.cpp! Implemented in HeiGen.cpp!
*/ */
static cTerrainHeightGen * CreateHeightGen(cIniFile & a_IniFile, cBiomeGen & a_BiomeGen, int a_Seed, bool & a_CacheOffByDefault); static cTerrainHeightGenPtr CreateHeightGen(cIniFile & a_IniFile, cBiomeGenPtr a_BiomeGen, int a_Seed, bool & a_CacheOffByDefault);
} ; } ;
@ -109,7 +118,7 @@ public:
a_BiomeGen is the underlying biome generator, some composition generators may depend on it to generate more biomes a_BiomeGen is the underlying biome generator, some composition generators may depend on it to generate more biomes
a_HeightGen is the underlying height generator, some composition generators may depend on it providing additional values a_HeightGen is the underlying height generator, some composition generators may depend on it providing additional values
*/ */
static cTerrainCompositionGen * CreateCompositionGen(cIniFile & a_IniFile, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen, int a_Seed); static cTerrainCompositionGenPtr CreateCompositionGen(cIniFile & a_IniFile, cBiomeGenPtr a_BiomeGen, cTerrainHeightGen & a_HeightGen, int a_Seed);
} ; } ;
@ -131,7 +140,7 @@ public:
virtual void GenFinish(cChunkDesc & a_ChunkDesc) = 0; virtual void GenFinish(cChunkDesc & a_ChunkDesc) = 0;
} ; } ;
typedef std::list<cFinishGen *> cFinishGenList; typedef std::list<cFinishGenPtr> cFinishGenList;
@ -144,7 +153,6 @@ class cComposableGenerator :
public: public:
cComposableGenerator(cChunkGenerator & a_ChunkGenerator); cComposableGenerator(cChunkGenerator & a_ChunkGenerator);
virtual ~cComposableGenerator();
virtual void Initialize(cIniFile & a_IniFile) override; virtual void Initialize(cIniFile & a_IniFile) override;
virtual void GenerateBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override; virtual void GenerateBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;
@ -152,15 +160,10 @@ public:
protected: protected:
// The generation composition: // The generation composition:
cBiomeGen * m_BiomeGen; cBiomeGenPtr m_BiomeGen;
cTerrainHeightGen * m_HeightGen; cTerrainHeightGenPtr m_HeightGen;
cTerrainCompositionGen * m_CompositionGen; cTerrainCompositionGenPtr m_CompositionGen;
cFinishGenList m_FinishGens; cFinishGenList m_FinishGens;
// Generators underlying the caches:
cBiomeGen * m_UnderlyingBiomeGen;
cTerrainHeightGen * m_UnderlyingHeightGen;
cTerrainCompositionGen * m_UnderlyingCompositionGen;
/** Reads the biome gen settings from the ini and initializes m_BiomeGen accordingly */ /** Reads the biome gen settings from the ini and initializes m_BiomeGen accordingly */

View File

@ -276,13 +276,13 @@ const cDistortedHeightmap::sGenParam cDistortedHeightmap::m_GenParam[256] =
cDistortedHeightmap::cDistortedHeightmap(int a_Seed, cBiomeGen & a_BiomeGen) : cDistortedHeightmap::cDistortedHeightmap(int a_Seed, cBiomeGenPtr a_BiomeGen) :
m_NoiseDistortX(a_Seed + 1000), m_NoiseDistortX(a_Seed + 1000),
m_NoiseDistortZ(a_Seed + 2000), m_NoiseDistortZ(a_Seed + 2000),
m_OceanFloorSelect(a_Seed + 3000), m_OceanFloorSelect(a_Seed + 3000),
m_MesaFloor(a_Seed + 4000), m_MesaFloor(a_Seed + 4000),
m_BiomeGen(a_BiomeGen), m_BiomeGen(a_BiomeGen),
m_UnderlyingHeiGen(a_Seed, a_BiomeGen), m_UnderlyingHeiGen(new cHeiGenBiomal(a_Seed, a_BiomeGen)),
m_HeightGen(m_UnderlyingHeiGen, 64), m_HeightGen(m_UnderlyingHeiGen, 64),
m_IsInitialized(false) m_IsInitialized(false)
{ {
@ -577,7 +577,7 @@ void cDistortedHeightmap::UpdateDistortAmps(void)
{ {
for (int x = -1; x <= 1; x++) for (int x = -1; x <= 1; x++)
{ {
m_BiomeGen.GenBiomes(m_CurChunkX + x, m_CurChunkZ + z, Biomes[x + 1][z + 1]); m_BiomeGen->GenBiomes(m_CurChunkX + x, m_CurChunkZ + z, Biomes[x + 1][z + 1]);
} // for x } // for x
} // for z } // for z

View File

@ -35,7 +35,7 @@ public:
NIBBLETYPE BlockMeta; NIBBLETYPE BlockMeta;
} ; } ;
cDistortedHeightmap(int a_Seed, cBiomeGen & a_BiomeGen); cDistortedHeightmap(int a_Seed, cBiomeGenPtr a_BiomeGen);
protected: protected:
typedef cChunkDef::BiomeMap BiomeNeighbors[3][3]; typedef cChunkDef::BiomeMap BiomeNeighbors[3][3];
@ -64,9 +64,14 @@ protected:
int m_CurChunkZ; int m_CurChunkZ;
NOISE_DATATYPE m_DistortedHeightmap[17 * 257 * 17]; NOISE_DATATYPE m_DistortedHeightmap[17 * 257 * 17];
cBiomeGen & m_BiomeGen; /** The bime generator to query for biomes. */
cHeiGenBiomal m_UnderlyingHeiGen; // This generator provides us with base heightmap (before distortion) cBiomeGenPtr m_BiomeGen;
cHeiGenCache m_HeightGen; // Cache above m_UnderlyingHeiGen
/** The generator that provides the base heightmap (before distortion). */
cTerrainHeightGenPtr m_UnderlyingHeiGen;
/** Cache for m_UnderlyingHeiGen. */
cHeiGenCache m_HeightGen;
/// Heightmap for the current chunk, before distortion (from m_HeightGen). Used for optimization. /// Heightmap for the current chunk, before distortion (from m_HeightGen). Used for optimization.
cChunkDef::HeightMap m_CurChunkHeights; cChunkDef::HeightMap m_CurChunkHeights;

View File

@ -258,7 +258,7 @@ protected:
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cDungeonRoomsFinisher: // cDungeonRoomsFinisher:
cDungeonRoomsFinisher::cDungeonRoomsFinisher(cTerrainHeightGen & a_HeightGen, int a_Seed, int a_GridSize, int a_MaxSize, int a_MinSize, const AString & a_HeightDistrib) : cDungeonRoomsFinisher::cDungeonRoomsFinisher(cTerrainHeightGenPtr a_HeightGen, int a_Seed, int a_GridSize, int a_MaxSize, int a_MinSize, const AString & a_HeightDistrib) :
super(a_Seed + 100, a_GridSize, a_GridSize, a_GridSize, a_GridSize, a_MaxSize, a_MaxSize, 1024), super(a_Seed + 100, a_GridSize, a_GridSize, a_GridSize, a_GridSize, a_MaxSize, a_MaxSize, 1024),
m_HeightGen(a_HeightGen), m_HeightGen(a_HeightGen),
m_MaxHalfSize((a_MaxSize + 1) / 2), m_MaxHalfSize((a_MaxSize + 1) / 2),
@ -294,7 +294,7 @@ cDungeonRoomsFinisher::cStructurePtr cDungeonRoomsFinisher::CreateStructure(int
int RelX = a_OriginX, RelY = 0, RelZ = a_OriginZ; int RelX = a_OriginX, RelY = 0, RelZ = a_OriginZ;
cChunkDef::AbsoluteToRelative(RelX, RelY, RelZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(RelX, RelY, RelZ, ChunkX, ChunkZ);
cChunkDef::HeightMap HeightMap; cChunkDef::HeightMap HeightMap;
m_HeightGen.GenHeightMap(ChunkX, ChunkZ, HeightMap); m_HeightGen->GenHeightMap(ChunkX, ChunkZ, HeightMap);
int Height = cChunkDef::GetHeight(HeightMap, RelX, RelZ); // Max room height at {a_OriginX, a_OriginZ} int Height = cChunkDef::GetHeight(HeightMap, RelX, RelZ); // Max room height at {a_OriginX, a_OriginZ}
Height = Clamp(m_HeightProbability.MapValue(rnd % m_HeightProbability.GetSum()), 10, Height - 5); Height = Clamp(m_HeightProbability.MapValue(rnd % m_HeightProbability.GetSum()), 10, Height - 5);

View File

@ -26,12 +26,12 @@ public:
a_HeightGen is the underlying height generator, so that the rooms can always be placed under the terrain. a_HeightGen is the underlying height generator, so that the rooms can always be placed under the terrain.
a_MaxSize and a_MinSize are the maximum and minimum sizes of the room's internal (air) area, in blocks across. a_MaxSize and a_MinSize are the maximum and minimum sizes of the room's internal (air) area, in blocks across.
a_HeightDistrib is the string defining the height distribution for the rooms (cProbabDistrib format). */ a_HeightDistrib is the string defining the height distribution for the rooms (cProbabDistrib format). */
cDungeonRoomsFinisher(cTerrainHeightGen & a_HeightGen, int a_Seed, int a_GridSize, int a_MaxSize, int a_MinSize, const AString & a_HeightDistrib); cDungeonRoomsFinisher(cTerrainHeightGenPtr a_HeightGen, int a_Seed, int a_GridSize, int a_MaxSize, int a_MinSize, const AString & a_HeightDistrib);
protected: protected:
/** The height gen that is used for limiting the rooms' Y coords */ /** The height gen that is used for limiting the rooms' Y coords */
cTerrainHeightGen & m_HeightGen; cTerrainHeightGenPtr m_HeightGen;
/** Maximum half-size (from center to wall) of the dungeon room's inner (air) area. Default is 3 (vanilla). */ /** Maximum half-size (from center to wall) of the dungeon room's inner (air) area. Default is 3 (vanilla). */
int m_MaxHalfSize; int m_MaxHalfSize;

View File

@ -19,7 +19,7 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cTerrainHeightGen: // cTerrainHeightGen:
cTerrainHeightGen * cTerrainHeightGen::CreateHeightGen(cIniFile &a_IniFile, cBiomeGen & a_BiomeGen, int a_Seed, bool & a_CacheOffByDefault) cTerrainHeightGenPtr cTerrainHeightGen::CreateHeightGen(cIniFile & a_IniFile, cBiomeGenPtr a_BiomeGen, int a_Seed, bool & a_CacheOffByDefault)
{ {
AString HeightGenName = a_IniFile.GetValueSet("Generator", "HeightGen", ""); AString HeightGenName = a_IniFile.GetValueSet("Generator", "HeightGen", "");
if (HeightGenName.empty()) if (HeightGenName.empty())
@ -84,7 +84,7 @@ cTerrainHeightGen * cTerrainHeightGen::CreateHeightGen(cIniFile &a_IniFile, cBio
// Read the settings: // Read the settings:
res->InitializeHeightGen(a_IniFile); res->InitializeHeightGen(a_IniFile);
return res; return cTerrainHeightGenPtr(res);
} }
@ -118,7 +118,7 @@ void cHeiGenFlat::InitializeHeightGen(cIniFile & a_IniFile)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cHeiGenCache: // cHeiGenCache:
cHeiGenCache::cHeiGenCache(cTerrainHeightGen & a_HeiGenToCache, int a_CacheSize) : cHeiGenCache::cHeiGenCache(cTerrainHeightGenPtr a_HeiGenToCache, int a_CacheSize) :
m_HeiGenToCache(a_HeiGenToCache), m_HeiGenToCache(a_HeiGenToCache),
m_CacheSize(a_CacheSize), m_CacheSize(a_CacheSize),
m_CacheOrder(new int[a_CacheSize]), m_CacheOrder(new int[a_CacheSize]),
@ -190,7 +190,7 @@ void cHeiGenCache::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap
// Not in the cache: // Not in the cache:
m_NumMisses++; m_NumMisses++;
m_HeiGenToCache.GenHeightMap(a_ChunkX, a_ChunkZ, a_HeightMap); m_HeiGenToCache->GenHeightMap(a_ChunkX, a_ChunkZ, a_HeightMap);
// Insert it as the first item in the MRU order: // Insert it as the first item in the MRU order:
int Idx = m_CacheOrder[m_CacheSize - 1]; int Idx = m_CacheOrder[m_CacheSize - 1];
@ -210,7 +210,7 @@ void cHeiGenCache::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap
void cHeiGenCache::InitializeHeightGen(cIniFile & a_IniFile) void cHeiGenCache::InitializeHeightGen(cIniFile & a_IniFile)
{ {
m_HeiGenToCache.InitializeHeightGen(a_IniFile); m_HeiGenToCache->InitializeHeightGen(a_IniFile);
} }
@ -317,7 +317,9 @@ void cHeiGenClassic::InitializeHeightGen(cIniFile & a_IniFile)
cHeiGenMountains::cHeiGenMountains(int a_Seed) : cHeiGenMountains::cHeiGenMountains(int a_Seed) :
m_Seed(a_Seed), m_Seed(a_Seed),
m_Noise(a_Seed) m_MountainNoise(a_Seed + 100),
m_DitchNoise(a_Seed + 200),
m_Perlin(a_Seed + 300)
{ {
} }
@ -332,9 +334,11 @@ void cHeiGenMountains::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::Heigh
NOISE_DATATYPE StartZ = (NOISE_DATATYPE)(a_ChunkZ * cChunkDef::Width); NOISE_DATATYPE StartZ = (NOISE_DATATYPE)(a_ChunkZ * cChunkDef::Width);
NOISE_DATATYPE EndZ = (NOISE_DATATYPE)(a_ChunkZ * cChunkDef::Width + cChunkDef::Width - 1); NOISE_DATATYPE EndZ = (NOISE_DATATYPE)(a_ChunkZ * cChunkDef::Width + cChunkDef::Width - 1);
NOISE_DATATYPE Workspace[16 * 16]; NOISE_DATATYPE Workspace[16 * 16];
NOISE_DATATYPE Noise[16 * 16]; NOISE_DATATYPE MountainNoise[16 * 16];
NOISE_DATATYPE DitchNoise[16 * 16];
NOISE_DATATYPE PerlinNoise[16 * 16]; NOISE_DATATYPE PerlinNoise[16 * 16];
m_Noise.Generate2D(Noise, 16, 16, StartX, EndX, StartZ, EndZ, Workspace); m_MountainNoise.Generate2D(MountainNoise, 16, 16, StartX, EndX, StartZ, EndZ, Workspace);
m_DitchNoise.Generate2D(DitchNoise, 16, 16, StartX, EndX, StartZ, EndZ, Workspace);
m_Perlin.Generate2D(PerlinNoise, 16, 16, StartX, EndX, StartZ, EndZ, Workspace); m_Perlin.Generate2D(PerlinNoise, 16, 16, StartX, EndX, StartZ, EndZ, Workspace);
for (int z = 0; z < cChunkDef::Width; z++) for (int z = 0; z < cChunkDef::Width; z++)
{ {
@ -342,7 +346,7 @@ void cHeiGenMountains::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::Heigh
for (int x = 0; x < cChunkDef::Width; x++) for (int x = 0; x < cChunkDef::Width; x++)
{ {
int idx = IdxZ + x; int idx = IdxZ + x;
int hei = 100 - (int)((Noise[idx] + PerlinNoise[idx]) * 15); int hei = 100 - (int)((MountainNoise[idx] - DitchNoise[idx] + PerlinNoise[idx]) * 15);
if (hei < 10) if (hei < 10)
{ {
hei = 10; hei = 10;
@ -363,9 +367,12 @@ void cHeiGenMountains::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::Heigh
void cHeiGenMountains::InitializeHeightGen(cIniFile & a_IniFile) void cHeiGenMountains::InitializeHeightGen(cIniFile & a_IniFile)
{ {
// TODO: Read the params from an INI file // TODO: Read the params from an INI file
m_Noise.AddOctave(0.1f, 0.1f); m_MountainNoise.AddOctave(0.1f, 0.2f);
m_Noise.AddOctave(0.05f, 0.5f); m_MountainNoise.AddOctave(0.05f, 0.4f);
m_Noise.AddOctave(0.02f, 1.5f); m_MountainNoise.AddOctave(0.02f, 1.0f);
m_DitchNoise.AddOctave(0.1f, 0.2f);
m_DitchNoise.AddOctave(0.05f, 0.4f);
m_DitchNoise.AddOctave(0.02f, 1.0f);
m_Perlin.AddOctave(0.01f, 1.5f); m_Perlin.AddOctave(0.01f, 1.5f);
} }
@ -479,7 +486,7 @@ void cHeiGenBiomal::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMa
{ {
for (int x = -1; x <= 1; x++) for (int x = -1; x <= 1; x++)
{ {
m_BiomeGen.GenBiomes(a_ChunkX + x, a_ChunkZ + z, Biomes[x + 1][z + 1]); m_BiomeGen->GenBiomes(a_ChunkX + x, a_ChunkZ + z, Biomes[x + 1][z + 1]);
} // for x } // for x
} // for z } // for z

View File

@ -45,7 +45,7 @@ class cHeiGenCache :
public cTerrainHeightGen public cTerrainHeightGen
{ {
public: public:
cHeiGenCache(cTerrainHeightGen & a_HeiGenToCache, int a_CacheSize); // Doesn't take ownership of a_HeiGenToCache cHeiGenCache(cTerrainHeightGenPtr a_HeiGenToCache, int a_CacheSize);
~cHeiGenCache(); ~cHeiGenCache();
// cTerrainHeightGen overrides: // cTerrainHeightGen overrides:
@ -57,7 +57,7 @@ public:
protected: protected:
cTerrainHeightGen & m_HeiGenToCache; cTerrainHeightGenPtr m_HeiGenToCache;
struct sCacheData struct sCacheData
{ {
@ -115,7 +115,8 @@ public:
protected: protected:
int m_Seed; int m_Seed;
cRidgedMultiNoise m_Noise; cRidgedMultiNoise m_MountainNoise;
cRidgedMultiNoise m_DitchNoise;
cPerlinNoise m_Perlin; cPerlinNoise m_Perlin;
// cTerrainHeightGen overrides: // cTerrainHeightGen overrides:
@ -131,7 +132,7 @@ class cHeiGenBiomal :
public cTerrainHeightGen public cTerrainHeightGen
{ {
public: public:
cHeiGenBiomal(int a_Seed, cBiomeGen & a_BiomeGen) : cHeiGenBiomal(int a_Seed, cBiomeGenPtr a_BiomeGen) :
m_Noise(a_Seed), m_Noise(a_Seed),
m_BiomeGen(a_BiomeGen) m_BiomeGen(a_BiomeGen)
{ {
@ -141,8 +142,8 @@ protected:
typedef cChunkDef::BiomeMap BiomeNeighbors[3][3]; typedef cChunkDef::BiomeMap BiomeNeighbors[3][3];
cNoise m_Noise; cNoise m_Noise;
cBiomeGen & m_BiomeGen; cBiomeGenPtr m_BiomeGen;
// Per-biome terrain generator parameters: // Per-biome terrain generator parameters:
struct sGenParam struct sGenParam

View File

@ -411,7 +411,7 @@ void cStructGenLakes::CreateLakeImage(int a_ChunkX, int a_ChunkZ, cBlockArea & a
// Find the minimum height in this chunk: // Find the minimum height in this chunk:
cChunkDef::HeightMap HeightMap; cChunkDef::HeightMap HeightMap;
m_HeiGen.GenHeightMap(a_ChunkX, a_ChunkZ, HeightMap); m_HeiGen->GenHeightMap(a_ChunkX, a_ChunkZ, HeightMap);
HEIGHTTYPE MinHeight = HeightMap[0]; HEIGHTTYPE MinHeight = HeightMap[0];
for (size_t i = 1; i < ARRAYCOUNT(HeightMap); i++) for (size_t i = 1; i < ARRAYCOUNT(HeightMap); i++)
{ {

View File

@ -24,7 +24,7 @@ class cStructGenTrees :
public cFinishGen public cFinishGen
{ {
public: public:
cStructGenTrees(int a_Seed, cBiomeGen * a_BiomeGen, cTerrainHeightGen * a_HeightGen, cTerrainCompositionGen * a_CompositionGen) : cStructGenTrees(int a_Seed, cBiomeGenPtr a_BiomeGen, cTerrainHeightGenPtr a_HeightGen, cTerrainCompositionGenPtr a_CompositionGen) :
m_Seed(a_Seed), m_Seed(a_Seed),
m_Noise(a_Seed), m_Noise(a_Seed),
m_BiomeGen(a_BiomeGen), m_BiomeGen(a_BiomeGen),
@ -36,9 +36,9 @@ protected:
int m_Seed; int m_Seed;
cNoise m_Noise; cNoise m_Noise;
cBiomeGen * m_BiomeGen; cBiomeGenPtr m_BiomeGen;
cTerrainHeightGen * m_HeightGen; cTerrainHeightGenPtr m_HeightGen;
cTerrainCompositionGen * m_CompositionGen; cTerrainCompositionGenPtr m_CompositionGen;
/** Generates and applies an image of a single tree. /** Generates and applies an image of a single tree.
Parts of the tree inside the chunk are applied to a_BlockX. Parts of the tree inside the chunk are applied to a_BlockX.
@ -124,7 +124,7 @@ class cStructGenLakes :
public cFinishGen public cFinishGen
{ {
public: public:
cStructGenLakes(int a_Seed, BLOCKTYPE a_Fluid, cTerrainHeightGen & a_HeiGen, int a_Probability) : cStructGenLakes(int a_Seed, BLOCKTYPE a_Fluid, cTerrainHeightGenPtr a_HeiGen, int a_Probability) :
m_Noise(a_Seed), m_Noise(a_Seed),
m_Seed(a_Seed), m_Seed(a_Seed),
m_Fluid(a_Fluid), m_Fluid(a_Fluid),
@ -134,11 +134,11 @@ public:
} }
protected: protected:
cNoise m_Noise; cNoise m_Noise;
int m_Seed; int m_Seed;
BLOCKTYPE m_Fluid; BLOCKTYPE m_Fluid;
cTerrainHeightGen & m_HeiGen; cTerrainHeightGenPtr m_HeiGen;
int m_Probability; ///< Chance, 0 .. 100, of a chunk having the lake int m_Probability; ///< Chance, 0 .. 100, of a chunk having the lake
// cFinishGen override: // cFinishGen override:
virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;

View File

@ -93,7 +93,7 @@ protected:
cUnderwaterBaseGen::cUnderwaterBaseGen(int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxDepth, int a_MaxSize, cBiomeGen & a_BiomeGen) : cUnderwaterBaseGen::cUnderwaterBaseGen(int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxDepth, int a_MaxSize, cBiomeGenPtr a_BiomeGen) :
super(a_Seed, a_GridSize, a_GridSize, a_MaxOffset, a_MaxOffset, a_MaxSize, a_MaxSize, 100), super(a_Seed, a_GridSize, a_GridSize, a_MaxOffset, a_MaxOffset, a_MaxSize, a_MaxSize, 100),
m_Noise(a_Seed + 1000), m_Noise(a_Seed + 1000),
m_MaxDepth(a_MaxDepth), m_MaxDepth(a_MaxDepth),
@ -112,7 +112,7 @@ cGridStructGen::cStructurePtr cUnderwaterBaseGen::CreateStructure(int a_GridX, i
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_OriginX, a_OriginZ, ChunkX, ChunkZ); cChunkDef::BlockToChunk(a_OriginX, a_OriginZ, ChunkX, ChunkZ);
cChunkDef::BiomeMap Biomes; cChunkDef::BiomeMap Biomes;
m_BiomeGen.GenBiomes(ChunkX, ChunkZ, Biomes); m_BiomeGen->GenBiomes(ChunkX, ChunkZ, Biomes);
// Check if all the biomes are ocean: // Check if all the biomes are ocean:
// If just one is not, no base is created, because it's likely that an unfriendly biome is too close // If just one is not, no base is created, because it's likely that an unfriendly biome is too close

View File

@ -22,7 +22,7 @@ class cUnderwaterBaseGen :
typedef cGridStructGen super; typedef cGridStructGen super;
public: public:
cUnderwaterBaseGen(int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxDepth, int a_MaxSize, cBiomeGen & a_BiomeGen); cUnderwaterBaseGen(int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxDepth, int a_MaxSize, cBiomeGenPtr a_BiomeGen);
protected: protected:
class cUnderwaterBase; // fwd: UnderwaterBaseGen.cpp class cUnderwaterBase; // fwd: UnderwaterBaseGen.cpp
@ -38,7 +38,7 @@ protected:
int m_MaxSize; int m_MaxSize;
/** The underlying biome generator that defines whether the base is created or not */ /** The underlying biome generator that defines whether the base is created or not */
cBiomeGen & m_BiomeGen; cBiomeGenPtr m_BiomeGen;
// cGridStructGen overrides: // cGridStructGen overrides:

View File

@ -116,7 +116,7 @@ public:
int a_MaxSize, int a_MaxSize,
int a_Density, int a_Density,
cPiecePool & a_Prefabs, cPiecePool & a_Prefabs,
cTerrainHeightGen & a_HeightGen, cTerrainHeightGenPtr a_HeightGen,
BLOCKTYPE a_RoadBlock, BLOCKTYPE a_RoadBlock,
BLOCKTYPE a_WaterRoadBlock BLOCKTYPE a_WaterRoadBlock
) : ) :
@ -175,7 +175,7 @@ protected:
cPiecePool & m_Prefabs; cPiecePool & m_Prefabs;
/** The underlying height generator, used for placing the structures on top of the terrain. */ /** The underlying height generator, used for placing the structures on top of the terrain. */
cTerrainHeightGen & m_HeightGen; cTerrainHeightGenPtr m_HeightGen;
/** The village pieces, placed by the generator. */ /** The village pieces, placed by the generator. */
cPlacedPieces m_Pieces; cPlacedPieces m_Pieces;
@ -194,7 +194,7 @@ protected:
// Each intersecting prefab is placed on ground, then drawn // Each intersecting prefab is placed on ground, then drawn
// Each intersecting road is drawn by replacing top soil blocks with gravel / sandstone blocks // Each intersecting road is drawn by replacing top soil blocks with gravel / sandstone blocks
cChunkDef::HeightMap HeightMap; // Heightmap for this chunk, used by roads cChunkDef::HeightMap HeightMap; // Heightmap for this chunk, used by roads
m_HeightGen.GenHeightMap(a_Chunk.GetChunkX(), a_Chunk.GetChunkZ(), HeightMap); m_HeightGen->GenHeightMap(a_Chunk.GetChunkX(), a_Chunk.GetChunkZ(), HeightMap);
for (cPlacedPieces::iterator itr = m_Pieces.begin(), end = m_Pieces.end(); itr != end; ++itr) for (cPlacedPieces::iterator itr = m_Pieces.begin(), end = m_Pieces.end(); itr != end; ++itr)
{ {
cPrefab & Prefab = (cPrefab &)((*itr)->GetPiece()); cPrefab & Prefab = (cPrefab &)((*itr)->GetPiece());
@ -224,7 +224,7 @@ protected:
int BlockY; int BlockY;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cChunkDef::HeightMap HeightMap; cChunkDef::HeightMap HeightMap;
m_HeightGen.GenHeightMap(ChunkX, ChunkZ, HeightMap); m_HeightGen->GenHeightMap(ChunkX, ChunkZ, HeightMap);
int TerrainHeight = cChunkDef::GetHeight(HeightMap, BlockX, BlockZ); int TerrainHeight = cChunkDef::GetHeight(HeightMap, BlockX, BlockZ);
a_Piece.MoveToGroundBy(TerrainHeight - FirstConnector.m_Pos.y + 1); a_Piece.MoveToGroundBy(TerrainHeight - FirstConnector.m_Pos.y + 1);
} }
@ -359,7 +359,7 @@ static cVillagePiecePool * g_PlainsVillagePools[] =
cVillageGen::cVillageGen(int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxDepth, int a_MaxSize, int a_MinDensity, int a_MaxDensity, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen) : cVillageGen::cVillageGen(int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxDepth, int a_MaxSize, int a_MinDensity, int a_MaxDensity, cBiomeGenPtr a_BiomeGen, cTerrainHeightGenPtr a_HeightGen) :
super(a_Seed, a_GridSize, a_GridSize, a_MaxOffset, a_MaxOffset, a_MaxSize, a_MaxSize, 100), super(a_Seed, a_GridSize, a_GridSize, a_MaxOffset, a_MaxOffset, a_MaxSize, a_MaxSize, 100),
m_Noise(a_Seed + 1000), m_Noise(a_Seed + 1000),
m_MaxDepth(a_MaxDepth), m_MaxDepth(a_MaxDepth),
@ -381,7 +381,7 @@ cGridStructGen::cStructurePtr cVillageGen::CreateStructure(int a_GridX, int a_Gr
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_OriginX, a_OriginZ, ChunkX, ChunkZ); cChunkDef::BlockToChunk(a_OriginX, a_OriginZ, ChunkX, ChunkZ);
cChunkDef::BiomeMap Biomes; cChunkDef::BiomeMap Biomes;
m_BiomeGen.GenBiomes(ChunkX, ChunkZ, Biomes); m_BiomeGen->GenBiomes(ChunkX, ChunkZ, Biomes);
// Check if all the biomes are village-friendly: // Check if all the biomes are village-friendly:
// If just one is not, no village is created, because it's likely that an unfriendly biome is too close // If just one is not, no village is created, because it's likely that an unfriendly biome is too close

View File

@ -21,7 +21,7 @@ class cVillageGen :
{ {
typedef cGridStructGen super; typedef cGridStructGen super;
public: public:
cVillageGen(int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxDepth, int a_MaxSize, int a_MinDensity, int a_MaxDensity, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen); cVillageGen(int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxDepth, int a_MaxSize, int a_MinDensity, int a_MaxDensity, cBiomeGenPtr a_BiomeGen, cTerrainHeightGenPtr a_HeightGen);
protected: protected:
class cVillage; // fwd: VillageGen.cpp class cVillage; // fwd: VillageGen.cpp
@ -42,10 +42,10 @@ protected:
int m_MaxDensity; int m_MaxDensity;
/** The underlying biome generator that defines whether the village is created or not */ /** The underlying biome generator that defines whether the village is created or not */
cBiomeGen & m_BiomeGen; cBiomeGenPtr m_BiomeGen;
/** The underlying height generator, used to position the prefabs crossing chunk borders */ /** The underlying height generator, used to position the prefabs crossing chunk borders */
cTerrainHeightGen & m_HeightGen; cTerrainHeightGenPtr m_HeightGen;
// cGridStructGen overrides: // cGridStructGen overrides:

View File

@ -361,19 +361,8 @@ void inline LOGD(const char* a_Format, ...)
#define assert_test(x) ( !!(x) || (assert(!#x), exit(1), 0)) #define assert_test(x) ( !!(x) || (assert(!#x), exit(1), 0))
#endif #endif
// Allow both Older versions of MSVC and newer versions of everything use a shared_ptr: // Unified shared ptr from before C++11. Also no silly undercores.
// Note that we cannot typedef, because C++ doesn't allow (partial) templates to be typedeffed. #define SharedPtr std::shared_ptr
#if (defined(_MSC_VER) && (_MSC_VER < 1600))
// MSVC before 2010 doesn't have std::shared_ptr, but has std::tr1::shared_ptr, defined in <memory> included earlier
#define SharedPtr std::tr1::shared_ptr
#elif (defined(_MSC_VER) || (__cplusplus >= 201103L))
// C++11 has std::shared_ptr in <memory>, included earlier
#define SharedPtr std::shared_ptr
#else
// C++03 has std::tr1::shared_ptr in <tr1/memory>
#include <tr1/memory>
#define SharedPtr std::tr1::shared_ptr
#endif

View File

@ -642,7 +642,7 @@ void cItemGrid::GenerateRandomLootWithBooks(const cLootProbab * a_LootProbabs, s
// Choose the enchantments // Choose the enchantments
cWeightedEnchantments Enchantments; cWeightedEnchantments Enchantments;
cEnchantments::AddItemEnchantmentWeights(Enchantments, E_ITEM_BOOK, 24 + Noise.IntNoise2DInt(a_Seed, TotalProbab) % 7); cEnchantments::AddItemEnchantmentWeights(Enchantments, E_ITEM_BOOK, 24 + Noise.IntNoise2DInt(a_Seed, TotalProbab) % 7);
int NumEnchantments = Noise.IntNoise3DInt(TotalProbab, Rnd, a_Seed) % 5; // The number of enchantments this book wil get. int NumEnchantments = Noise.IntNoise3DInt(TotalProbab, Rnd, a_Seed) % 5; // The number of enchantments this book wil get.
for (int j = 0; j <= NumEnchantments; j++) for (int j = 0; j <= NumEnchantments; j++)
{ {

View File

@ -485,6 +485,17 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac
{ {
if (split.size() > 1) if (split.size() > 1)
{ {
cPluginManager::PluginMap map = cPluginManager::Get()->GetAllPlugins();
for (auto plugin_entry : map)
{
if (plugin_entry.first == split[1])
{
a_Output.Out("Error! Plugin is already loaded!");
a_Output.Finished();
return;
}
}
a_Output.Out(cPluginManager::Get()->LoadPlugin(split[1]) ? "Plugin loaded" : "Error occurred loading plugin"); a_Output.Out(cPluginManager::Get()->LoadPlugin(split[1]) ? "Plugin loaded" : "Error occurred loading plugin");
} }
else else