Esempio n. 1
0
void cNoise3DGenerator::DoGenerate(int a_ChunkX, int a_ChunkZ, cChunkDesc & a_ChunkDesc)
{
	NOISE_DATATYPE Noise[17 * 257 * 17];
	GenerateNoiseArray(a_ChunkX, a_ChunkZ, Noise);

	// Output noise into chunk:
	for (int z = 0; z < cChunkDef::Width; z++)
	{
		for (int y = 0; y < cChunkDef::Height; y++)
		{
			int idx = z * 17 * 257 + y * 17;
			for (int x = 0; x < cChunkDef::Width; x++)
			{
				NOISE_DATATYPE n = Noise[idx++];
				BLOCKTYPE BlockType;
				if (n > m_AirThreshold)
				{
					BlockType = (y > m_SeaLevel) ? E_BLOCK_AIR : E_BLOCK_STATIONARY_WATER;
				}
				else
				{
					BlockType = E_BLOCK_STONE;
				}
				a_ChunkDesc.SetBlockType(x, y, z, BlockType);
			}
		}
	}

	UpdateHeightmap(a_ChunkDesc);
	ComposeTerrain (a_ChunkDesc);
}
Esempio n. 2
0
/// Unless the LastChunk coords are equal to coords given, prepares the internal state (noise array)
void cEndGen::PrepareState(int a_ChunkX, int a_ChunkZ)
{
	ASSERT(!IsChunkOutsideRange(a_ChunkX, a_ChunkZ));  // Should be filtered before calling this function

	if ((m_LastChunkX == a_ChunkX) && (m_LastChunkZ == a_ChunkZ))
	{
		return;
	}

	m_LastChunkX = a_ChunkX;
	m_LastChunkZ = a_ChunkZ;

	GenerateNoiseArray();
}
Esempio n. 3
0
cNoise3DGenerator::cNoise3DGenerator(cChunkGenerator & a_ChunkGenerator) :
	super(a_ChunkGenerator),
	m_Perlin(1000),
	m_Cubic(1000)
{
	m_Perlin.AddOctave(1, (NOISE_DATATYPE)0.5);
	m_Perlin.AddOctave((NOISE_DATATYPE)0.5, 1);
	m_Perlin.AddOctave((NOISE_DATATYPE)0.5, 2);

	#if 0
	// DEBUG: Test the noise generation:
	// NOTE: In order to be able to run MCS with this code, you need to increase the default thread stack size
	// In MSVC, it is done in Project Settings -> Configuration Properties -> Linker -> System, set Stack reserve size to at least 64M
	m_SeaLevel            = 62;
	m_HeightAmplification = 0;
	m_MidPoint            = 75;
	m_FrequencyX          = 4;
	m_FrequencyY          = 4;
	m_FrequencyZ          = 4;
	m_AirThreshold        = 0.5;

	const int NumChunks = 4;
	NOISE_DATATYPE Noise[NumChunks][cChunkDef::Width * cChunkDef::Width * cChunkDef::Height];
	for (int x = 0; x < NumChunks; x++)
	{
		GenerateNoiseArray(x, 5, Noise[x]);
	}

	// Save in XY cuts:
	cFile f1;
	if (f1.Open("Test_XY.grab", cFile::fmWrite))
	{
		for (int z = 0; z < cChunkDef::Width; z++)
		{
			for (int y = 0; y < cChunkDef::Height; y++)
			{
				for (int i = 0; i < NumChunks; i++)
				{
					int idx = y * cChunkDef::Width + z * cChunkDef::Width * cChunkDef::Height;
					unsigned char buf[cChunkDef::Width];
					for (int x = 0; x < cChunkDef::Width; x++)
					{
						buf[x] = (unsigned char)(std::min(256, std::max(0, (int)(128 + 32 * Noise[i][idx++]))));
					}
					f1.Write(buf, cChunkDef::Width);
				}
			}  // for y
		}  // for z
	}  // if (XY file open)

	cFile f2;
	if (f2.Open("Test_XZ.grab", cFile::fmWrite))
	{
		for (int y = 0; y < cChunkDef::Height; y++)
		{
			for (int z = 0; z < cChunkDef::Width; z++)
			{
				for (int i = 0; i < NumChunks; i++)
				{
					int idx = y * cChunkDef::Width + z * cChunkDef::Width * cChunkDef::Height;
					unsigned char buf[cChunkDef::Width];
					for (int x = 0; x < cChunkDef::Width; x++)
					{
						buf[x] = (unsigned char)(std::min(256, std::max(0, (int)(128 + 32 * Noise[i][idx++]))));
					}
					f2.Write(buf, cChunkDef::Width);
				}
			}  // for z
		}  // for y
	}  // if (XZ file open)
	#endif  // 0
}