From 4f17362aeb80e5339c58a5d3b0fbaeb88d9e701c Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Mon, 13 Feb 2012 21:47:03 +0000 Subject: Rewritten most of the code for multithreading; still not 100%, but getting there. If this commit proves to be too problematic, we can always undo it. git-svn-id: http://mc-server.googlecode.com/svn/trunk@251 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cWorldGenerator.cpp | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) (limited to 'source/cWorldGenerator.cpp') diff --git a/source/cWorldGenerator.cpp b/source/cWorldGenerator.cpp index c54be8899..5d087014b 100644 --- a/source/cWorldGenerator.cpp +++ b/source/cWorldGenerator.cpp @@ -6,7 +6,6 @@ #include "cWorld.h" #include "cChunk.h" #include "cGenSettings.h" -#include "MersenneTwister.h" #include "BlockID.h" #include "Vector3i.h" @@ -19,17 +18,33 @@ cWorldGenerator::cWorldGenerator() { } + + + + cWorldGenerator::~cWorldGenerator() { } -void cWorldGenerator::GenerateChunk( cChunk* a_Chunk ) + + + +void cWorldGenerator::GenerateChunk( cChunkPtr a_Chunk ) { + assert(!a_Chunk->IsValid()); + + memset(a_Chunk->pGetBlockData(), 0, cChunk::c_BlockDataSize); GenerateTerrain( a_Chunk ); GenerateFoliage( a_Chunk ); + a_Chunk->CalculateHeightmap(); + a_Chunk->CalculateLighting(); } + + + + static float GetNoise( float x, float y, cNoise & a_Noise ) { float oct1 = a_Noise.CubicNoise2D( x*cGenSettings::HeightFreq1, y*cGenSettings::HeightFreq1 )*cGenSettings::HeightAmp1; @@ -44,6 +59,10 @@ static float GetNoise( float x, float y, cNoise & a_Noise ) return (oct1 + oct2 + oct3) * flatness + height; } + + + + #define PI_2 (1.57079633f) static float GetMarbleNoise( float x, float y, float z, cNoise & a_Noise ) { @@ -56,6 +75,10 @@ static float GetMarbleNoise( float x, float y, float z, cNoise & a_Noise ) return oct1; } + + + + static float GetOreNoise( float x, float y, float z, cNoise & a_Noise ) { float oct1 = a_Noise.CubicNoise3D( x*0.1f, y*0.1f, z*0.1f ); @@ -69,7 +92,11 @@ static float GetOreNoise( float x, float y, float z, cNoise & a_Noise ) return oct1; } -void cWorldGenerator::GenerateTerrain( cChunk* a_Chunk ) + + + + +void cWorldGenerator::GenerateTerrain( cChunkPtr a_Chunk ) { Vector3i ChunkPos( a_Chunk->GetPosX(), a_Chunk->GetPosY(), a_Chunk->GetPosZ() ); char* BlockType = a_Chunk->pGetType(); @@ -154,7 +181,9 @@ void cWorldGenerator::GenerateTerrain( cChunk* a_Chunk ) -void cWorldGenerator::GenerateFoliage( cChunk* a_Chunk ) + + +void cWorldGenerator::GenerateFoliage( cChunkPtr a_Chunk ) { const ENUM_BLOCK_ID GrassID = E_BLOCK_GRASS; const ENUM_BLOCK_ID DirtID = E_BLOCK_DIRT; @@ -213,7 +242,6 @@ void cWorldGenerator::GenerateFoliage( cChunk* a_Chunk ) BlockType[ index ] = (char)GrassID; } - MTRand r1; // Plant sum trees { int xx = x + PosX*16; @@ -253,3 +281,7 @@ void cWorldGenerator::GenerateFoliage( cChunk* a_Chunk ) } } } + + + + -- cgit v1.2.3