1
0

Added a flat terrain generator with settable terrain height

git-svn-id: http://mc-server.googlecode.com/svn/trunk@404 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2012-03-12 19:39:41 +00:00
parent cb1edaf6df
commit 10c8c75bb7
8 changed files with 160 additions and 10 deletions

View File

@ -1698,6 +1698,14 @@
RelativePath="..\source\cWorldGenerator_Test.h" RelativePath="..\source\cWorldGenerator_Test.h"
> >
</File> </File>
<File
RelativePath="..\source\WGFlat.cpp"
>
</File>
<File
RelativePath="..\source\WGFlat.h"
>
</File>
</Filter> </Filter>
</Filter> </Filter>
<File <File

View File

@ -485,6 +485,7 @@
<ClCompile Include="..\source\Vector3d.cpp" /> <ClCompile Include="..\source\Vector3d.cpp" />
<ClCompile Include="..\source\Vector3f.cpp" /> <ClCompile Include="..\source\Vector3f.cpp" />
<ClCompile Include="..\source\Vector3i.cpp" /> <ClCompile Include="..\source\Vector3i.cpp" />
<ClCompile Include="..\source\WGFlat.cpp" />
<ClCompile Include="..\source\WorldStorage.cpp" /> <ClCompile Include="..\source\WorldStorage.cpp" />
<ClCompile Include="..\source\WSSAnvil.cpp" /> <ClCompile Include="..\source\WSSAnvil.cpp" />
<ClCompile Include="..\source\WSSCompact.cpp" /> <ClCompile Include="..\source\WSSCompact.cpp" />
@ -666,6 +667,7 @@
<ClInclude Include="..\source\Vector3d.h" /> <ClInclude Include="..\source\Vector3d.h" />
<ClInclude Include="..\source\Vector3f.h" /> <ClInclude Include="..\source\Vector3f.h" />
<ClInclude Include="..\source\Vector3i.h" /> <ClInclude Include="..\source\Vector3i.h" />
<ClInclude Include="..\source\WGFlat.h" />
<ClInclude Include="..\source\WorldStorage.h" /> <ClInclude Include="..\source\WorldStorage.h" />
<ClInclude Include="..\source\WSSAnvil.h" /> <ClInclude Include="..\source\WSSAnvil.h" />
<ClInclude Include="..\source\WSSCompact.h" /> <ClInclude Include="..\source\WSSCompact.h" />

View File

@ -921,6 +921,7 @@
<ClCompile Include="..\source\ChunkSender.cpp" /> <ClCompile Include="..\source\ChunkSender.cpp" />
<ClCompile Include="..\source\WSSAnvil.cpp" /> <ClCompile Include="..\source\WSSAnvil.cpp" />
<ClCompile Include="..\source\NBT.cpp" /> <ClCompile Include="..\source\NBT.cpp" />
<ClCompile Include="..\source\WGFlat.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\source\cServer.h"> <ClInclude Include="..\source\cServer.h">
@ -1423,6 +1424,7 @@
<ClInclude Include="..\source\ChunkSender.h" /> <ClInclude Include="..\source\ChunkSender.h" />
<ClInclude Include="..\source\WSSAnvil.h" /> <ClInclude Include="..\source\WSSAnvil.h" />
<ClInclude Include="..\source\NBT.h" /> <ClInclude Include="..\source\NBT.h" />
<ClInclude Include="..\source\WGFlat.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="..\source\AllToLua.pkg"> <None Include="..\source\AllToLua.pkg">

101
source/WGFlat.cpp Normal file
View File

@ -0,0 +1,101 @@
// WGFlat.cpp
// Implements the cWGFlat class representing the flat world generator
#include "Globals.h"
#include "WGFlat.h"
#include "../iniFile/iniFile.h"
#include "cWorld.h"
cWGFlat::cWGFlat(cWorld * a_World) :
super(a_World)
{
// Load the settings from the INI file:
cIniFile INI(a_World->GetIniFileName());
INI.ReadFile();
m_Height = INI.GetValueI("flat", "height", 5);
if (m_Height < 1)
{
m_Height = 1;
}
if (m_Height > 250)
{
m_Height = 250;
}
}
void cWGFlat::GenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, char * a_BlockData, cEntityList & a_Entities, cBlockEntityList & a_BlockEntities)
{
int SliceSize = cChunk::c_ChunkWidth * cChunk::c_ChunkWidth;
memset(a_BlockData, E_BLOCK_BEDROCK, SliceSize);
switch (m_Height)
{
case 1:
{
// Just the bedrock layer
break;
}
case 2:
{
// Bedrock + 1 dirt layer:
memset(a_BlockData + SliceSize, E_BLOCK_GRASS, SliceSize);
break;
}
case 3:
{
// Bedrock + 2 dirt layers:
memset(a_BlockData + SliceSize, E_BLOCK_DIRT, SliceSize);
memset(a_BlockData + 2 * SliceSize, E_BLOCK_GRASS, SliceSize);
break;
}
case 4:
{
// Bedrock + 3 dirt layers:
memset(a_BlockData + SliceSize, E_BLOCK_DIRT, 2 * SliceSize);
memset(a_BlockData + 3 * SliceSize, E_BLOCK_GRASS, SliceSize);
break;
}
default:
{
// Bedrock + stone layers + 3 dirt layers:
memset(a_BlockData + SliceSize, E_BLOCK_STONE, SliceSize * (m_Height - 4));
memset(a_BlockData + SliceSize * (m_Height - 3), E_BLOCK_DIRT, SliceSize * 2);
memset(a_BlockData + SliceSize * (m_Height - 1), E_BLOCK_GRASS, SliceSize);
break;
}
}
memset(a_BlockData + SliceSize * m_Height, E_BLOCK_AIR, cChunk::c_NumBlocks - SliceSize * m_Height);
SliceSize /= 2; // Nibbles from now on
char * Meta = a_BlockData + cChunk::c_NumBlocks;
memset(Meta, 0, cChunk::c_NumBlocks / 2);
char * SkyLight = Meta + cChunk::c_NumBlocks / 2;
memset(SkyLight, 0, m_Height * SliceSize);
memset(SkyLight + m_Height * SliceSize, 0xff, cChunk::c_NumBlocks / 2 - m_Height * SliceSize);
char * BlockLight = SkyLight + cChunk::c_NumBlocks / 2;
memset(BlockLight, 0, cChunk::c_NumBlocks / 2);
}
void cWGFlat::PostGenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
{
// Nothing needed yet, just don't call the parent
}

35
source/WGFlat.h Normal file
View File

@ -0,0 +1,35 @@
// WGFlat.h
// Interfaces to the cWGFlat class representing the flat world generator
#pragma once
#include "cWorldGenerator.h"
class cWGFlat :
public cWorldGenerator
{
typedef cWorldGenerator super;
protected:
int m_Height;
virtual void GenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, char * a_BlockData, cEntityList & a_Entities, cBlockEntityList & a_BlockEntities) override;
virtual void PostGenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) override;
public:
cWGFlat(cWorld * a_World);
} ;

View File

@ -5,13 +5,7 @@
#include "cWorld.h" #include "cWorld.h"
#include "cWorldGenerator.h" #include "cWorldGenerator.h"
#include "cWorldGenerator_Test.h" #include "cWorldGenerator_Test.h"
#include "WGFlat.h"
typedef std::pair<int, int> ChunkCoord;
typedef std::list< ChunkCoord > ChunkCoordList;
@ -51,10 +45,14 @@ bool cChunkGenerator::Start(cWorld * a_World, const AString & a_WorldGeneratorNa
{ {
m_World = a_World; m_World = a_World;
if (a_WorldGeneratorName.compare("Test") == 0 ) if (NoCaseCompare(a_WorldGeneratorName, "Test") == 0 )
{ {
m_pWorldGenerator = new cWorldGenerator_Test(a_World); m_pWorldGenerator = new cWorldGenerator_Test(a_World);
} }
else if (NoCaseCompare(a_WorldGeneratorName, "flat") == 0)
{
m_pWorldGenerator = new cWGFlat(a_World);
}
else // Default else // Default
{ {
m_pWorldGenerator = new cWorldGenerator(a_World); m_pWorldGenerator = new cWorldGenerator(a_World);

View File

@ -184,6 +184,7 @@ cWorld::cWorld( const AString & a_WorldName )
{ {
LOG("cWorld::cWorld(%s)", a_WorldName.c_str()); LOG("cWorld::cWorld(%s)", a_WorldName.c_str());
m_WorldName = a_WorldName; m_WorldName = a_WorldName;
m_IniFileName = m_WorldName + "/world.ini";
cMakeDir::MakeDir(m_WorldName.c_str()); cMakeDir::MakeDir(m_WorldName.c_str());
@ -197,7 +198,7 @@ cWorld::cWorld( const AString & a_WorldName )
AString GeneratorName; AString GeneratorName;
AString StorageSchema("Default"); AString StorageSchema("Default");
cIniFile IniFile( m_WorldName + "/world.ini"); cIniFile IniFile(m_IniFileName);
if( IniFile.ReadFile() ) if( IniFile.ReadFile() )
{ {
m_SpawnX = IniFile.GetValueF("SpawnPosition", "X", m_SpawnX ); m_SpawnX = IniFile.GetValueF("SpawnPosition", "X", m_SpawnX );
@ -219,7 +220,7 @@ cWorld::cWorld( const AString & a_WorldName )
IniFile.SetValue("Storage", "Schema", StorageSchema); IniFile.SetValue("Storage", "Schema", StorageSchema);
if( !IniFile.WriteFile() ) if( !IniFile.WriteFile() )
{ {
LOG("WARNING: Could not write to %s/world.ini", a_WorldName.c_str()); LOG("WARNING: Could not write to %s", m_IniFileName.c_str());
} }
} }
LOGINFO("Seed: %i", m_WorldSeed ); LOGINFO("Seed: %i", m_WorldSeed );
@ -302,6 +303,7 @@ cWorld::cWorld( const AString & a_WorldName )
g_BlockTransparent[ E_BLOCK_RED_ROSE ] = true; g_BlockTransparent[ E_BLOCK_RED_ROSE ] = true;
g_BlockTransparent[ E_BLOCK_RED_MUSHROOM ] = true; g_BlockTransparent[ E_BLOCK_RED_MUSHROOM ] = true;
g_BlockTransparent[ E_BLOCK_BROWN_MUSHROOM ] = true; g_BlockTransparent[ E_BLOCK_BROWN_MUSHROOM ] = true;
g_BlockTransparent[ E_BLOCK_SNOW ] = true;
// TODO: Any other transparent blocks? // TODO: Any other transparent blocks?

View File

@ -187,6 +187,7 @@ public:
unsigned int GetWorldSeed(void) const { return m_WorldSeed; } //tolua_export unsigned int GetWorldSeed(void) const { return m_WorldSeed; } //tolua_export
const AString & GetName(void) const { return m_WorldName; } //tolua_export const AString & GetName(void) const { return m_WorldName; } //tolua_export
const AString & GetIniFileName(void) const {return m_IniFileName; }
inline static void AbsoluteToRelative( int & a_X, int & a_Y, int & a_Z, int & a_ChunkX, int & a_ChunkY, int & a_ChunkZ ) inline static void AbsoluteToRelative( int & a_X, int & a_Y, int & a_Z, int & a_ChunkX, int & a_ChunkY, int & a_ChunkZ )
{ {
@ -299,6 +300,7 @@ private:
cChunkSender m_ChunkSender; cChunkSender m_ChunkSender;
AString m_WorldName; AString m_WorldName;
AString m_IniFileName;
cWorld(const AString & a_WorldName); cWorld(const AString & a_WorldName);
~cWorld(); ~cWorld();