1
0

Unified the chunk data to use the BLOCKDATA datatype.

git-svn-id: http://mc-server.googlecode.com/svn/trunk@413 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2012-03-14 21:21:03 +00:00
parent 0aefed3e22
commit b974b1ea59
16 changed files with 52 additions and 33 deletions

View File

@ -43,6 +43,7 @@ typedef std::list<cBlockEntity *> cBlockEntityList;
/// The datatype used by blockdata, metadata, blocklight and skylight
typedef char BLOCKTYPE;
typedef char BIOMETYPE;

View File

@ -102,7 +102,7 @@ protected:
// Data about the chunk that is being sent:
// NOTE that m_BlockData[] is inherited from the cChunkDataCollector
BLOCKTYPE m_BiomeData[cChunkDef::Width * cChunkDef::Width];
BIOMETYPE m_BiomeData[cChunkDef::Width * cChunkDef::Width];
PacketList m_Packets; // Accumulator for the entity-packets to send
// cIsThread override:

View File

@ -33,7 +33,7 @@ cWGFlat::cWGFlat(cWorld * a_World) :
void cWGFlat::GenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, char * a_BlockData, cEntityList & a_Entities, cBlockEntityList & a_BlockEntities)
void cWGFlat::GenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, BLOCKTYPE * a_BlockData, cEntityList & a_Entities, cBlockEntityList & a_BlockEntities)
{
int SliceSize = cChunkDef::Width * cChunkDef::Width;
memset(a_BlockData, E_BLOCK_BEDROCK, SliceSize);
@ -76,14 +76,14 @@ void cWGFlat::GenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, char * a_B
memset(a_BlockData + SliceSize * m_Height, E_BLOCK_AIR, cChunkDef::NumBlocks - SliceSize * m_Height);
SliceSize /= 2; // Nibbles from now on
char * Meta = a_BlockData + cChunkDef::NumBlocks;
BLOCKTYPE * Meta = a_BlockData + cChunkDef::NumBlocks;
memset(Meta, 0, cChunkDef::NumBlocks / 2);
char * SkyLight = Meta + cChunkDef::NumBlocks / 2;
BLOCKTYPE * SkyLight = Meta + cChunkDef::NumBlocks / 2;
memset(SkyLight, 0, m_Height * SliceSize);
memset(SkyLight + m_Height * SliceSize, 0xff, cChunkDef::NumBlocks / 2 - m_Height * SliceSize);
char * BlockLight = SkyLight + cChunkDef::NumBlocks / 2;
BLOCKTYPE * BlockLight = SkyLight + cChunkDef::NumBlocks / 2;
memset(BlockLight, 0, cChunkDef::NumBlocks / 2);
}

View File

@ -23,7 +23,7 @@ class cWGFlat :
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 GenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, BLOCKTYPE * a_BlockData, cEntityList & a_Entities, cBlockEntityList & a_BlockEntities) override;
virtual void PostGenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) override;
public:

View File

@ -734,12 +734,14 @@ bool cWSSCompact::LoadChunkFromData(const cChunkCoords & a_Chunk, int & a_Uncomp
}
}
BLOCKTYPE * BlockData = (BLOCKTYPE *)UncompressedData.data();
a_World->ChunkDataLoaded(
a_Chunk.m_ChunkX, a_Chunk.m_ChunkY, a_Chunk.m_ChunkZ,
UncompressedData.data(),
UncompressedData.data() + cChunkDef::MetaOffset,
UncompressedData.data() + cChunkDef::LightOffset,
UncompressedData.data() + cChunkDef::SkyLightOffset,
BlockData,
BlockData + cChunkDef::MetaOffset,
BlockData + cChunkDef::LightOffset,
BlockData + cChunkDef::SkyLightOffset,
NULL,
Entities,
BlockEntities
@ -788,7 +790,7 @@ bool cWSSCompact::cPAKFile::SaveChunkToData(const cChunkCoords & a_Chunk, cWorld
}
AString Data;
Data.assign(Serializer.GetBlockData(), cChunkDef::BlockDataSize);
Data.assign((const char *)Serializer.GetBlockData(), cChunkDef::BlockDataSize);
if (Serializer.HasJsonData())
{
AString JsonData;

View File

@ -735,7 +735,7 @@ void cChunk::CalculateLighting()
void cChunk::SpreadLight(char* a_LightBuffer)
void cChunk::SpreadLight(BLOCKTYPE * a_LightBuffer)
{
// Spread the light
for(int x = 0; x < Width; x++) for(int z = 0; z < Width; z++) for(int y = 0; y < Height; y++)
@ -762,7 +762,7 @@ void cChunk::SpreadLight(char* a_LightBuffer)
// Spread to neighbour chunks X-axis
cChunkPtr LeftChunk = m_ChunkMap->GetChunkNoGen( m_PosX - 1, m_PosY, m_PosZ );
cChunkPtr RightChunk = m_ChunkMap->GetChunkNoGen( m_PosX + 1, m_PosY, m_PosZ );
char * LeftSky = NULL, *RightSky = NULL;
BLOCKTYPE * LeftSky = NULL, *RightSky = NULL;
if (LeftChunk->IsValid())
{
LeftSky = (a_LightBuffer == m_BlockSkyLight) ? LeftChunk->m_BlockSkyLight : LeftChunk->m_BlockLight;
@ -779,8 +779,8 @@ void cChunk::SpreadLight(char* a_LightBuffer)
int index = MakeIndexNoCheck( 0, y, z );
if( g_BlockSpreadLightFalloff[ m_BlockTypes[index] ] > 0 )
{
char CurrentLight = GetNibble( a_LightBuffer, 0, y, z );
char LeftLight = GetNibble( LeftSky, Width-1, y, z );
BLOCKTYPE CurrentLight = GetNibble( a_LightBuffer, 0, y, z );
BLOCKTYPE LeftLight = GetNibble( LeftSky, Width-1, y, z );
if( LeftLight < CurrentLight-g_BlockSpreadLightFalloff[ m_BlockTypes[index] ] )
{
SetNibble( LeftSky, Width - 1, y, z, MAX(0, CurrentLight-g_BlockSpreadLightFalloff[ m_BlockTypes[index] ]) );
@ -793,8 +793,8 @@ void cChunk::SpreadLight(char* a_LightBuffer)
int index = MakeIndexNoCheck( Width - 1, y, z );
if( g_BlockSpreadLightFalloff[ m_BlockTypes[index] ] > 0 )
{
char CurrentLight = GetNibble( a_LightBuffer, Width-1, y, z );
char RightLight = GetNibble( RightSky, 0, y, z );
BLOCKTYPE CurrentLight = GetNibble( a_LightBuffer, Width-1, y, z );
BLOCKTYPE RightLight = GetNibble( RightSky, 0, y, z );
if( RightLight < CurrentLight-g_BlockSpreadLightFalloff[ m_BlockTypes[index] ] )
{
SetNibble( RightSky, 0, y, z, MAX(0, CurrentLight-g_BlockSpreadLightFalloff[ m_BlockTypes[index] ]) );
@ -807,7 +807,7 @@ void cChunk::SpreadLight(char* a_LightBuffer)
// Spread to neighbour chunks Z-axis
cChunkPtr FrontChunk = m_ChunkMap->GetChunkNoGen( m_PosX, m_PosY, m_PosZ - 1 );
cChunkPtr BackChunk = m_ChunkMap->GetChunkNoGen( m_PosX, m_PosY, m_PosZ + 1 );
char * FrontSky = NULL, * BackSky = NULL;
BLOCKTYPE * FrontSky = NULL, * BackSky = NULL;
if (FrontChunk->IsValid())
{
FrontSky = (a_LightBuffer == m_BlockSkyLight) ? FrontChunk->m_BlockSkyLight : FrontChunk->m_BlockLight;

View File

@ -211,7 +211,7 @@ private:
cBlockEntity * GetBlockEntity( int a_X, int a_Y, int a_Z );
cBlockEntity * GetBlockEntity( const Vector3i & a_BlockPos ) { return GetBlockEntity( a_BlockPos.x, a_BlockPos.y, a_BlockPos.z ); }
void SpreadLightOfBlock(char* a_LightBuffer, int a_X, int a_Y, int a_Z, char a_Falloff);
void SpreadLightOfBlock(BLOCKTYPE * a_LightBuffer, int a_X, int a_Y, int a_Z, BLOCKTYPE a_Falloff);
void CreateBlockEntities(void);

View File

@ -180,7 +180,7 @@ void cChunkGenerator::Execute(void)
void cChunkGenerator::DoGenerate(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
{
char BlockData[cChunkDef::BlockDataSize];
BLOCKTYPE BlockData[cChunkDef::BlockDataSize];
cEntityList Entities;
cBlockEntityList BlockEntities;
m_pWorldGenerator->GenerateChunk(a_ChunkX, a_ChunkY, a_ChunkZ, BlockData, Entities, BlockEntities);

View File

@ -521,7 +521,7 @@ void cChunkMap::CollectPickupsByPlayer(cPlayer * a_Player)
char cChunkMap::GetBlock(int a_X, int a_Y, int a_Z)
BLOCKTYPE cChunkMap::GetBlock(int a_X, int a_Y, int a_Z)
{
int ChunkX, ChunkZ;
cChunkDef::AbsoluteToRelative( a_X, a_Y, a_Z, ChunkX, ChunkZ );
@ -539,7 +539,7 @@ char cChunkMap::GetBlock(int a_X, int a_Y, int a_Z)
char cChunkMap::GetBlockMeta(int a_X, int a_Y, int a_Z)
BLOCKTYPE cChunkMap::GetBlockMeta(int a_X, int a_Y, int a_Z)
{
int ChunkX, ChunkZ;
cChunkDef::AbsoluteToRelative( a_X, a_Y, a_Z, ChunkX, ChunkZ );
@ -557,7 +557,7 @@ char cChunkMap::GetBlockMeta(int a_X, int a_Y, int a_Z)
void cChunkMap::SetBlockMeta(int a_X, int a_Y, int a_Z, char a_BlockMeta)
void cChunkMap::SetBlockMeta(int a_X, int a_Y, int a_Z, BLOCKTYPE a_BlockMeta)
{
int ChunkX, ChunkZ;
cChunkDef::AbsoluteToRelative( a_X, a_Y, a_Z, ChunkX, ChunkZ );
@ -576,7 +576,7 @@ void cChunkMap::SetBlockMeta(int a_X, int a_Y, int a_Z, char a_BlockMeta)
void cChunkMap::SetBlock(int a_X, int a_Y, int a_Z, char a_BlockType, char a_BlockMeta)
void cChunkMap::SetBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta)
{
int ChunkX, ChunkZ, X = a_X, Y = a_Y, Z = a_Z;
cChunkDef::AbsoluteToRelative( X, Y, Z, ChunkX, ChunkZ );

View File

@ -182,6 +182,21 @@ cWorld::cWorld( const AString & a_WorldName )
, m_RSList ( 0 )
, m_Weather ( eWeather_Sunny )
{
/*
// DEBUG:
DWORD Tick = GetTickCount();
for (int i = 0; i < 3000; i++)
{
BLOCKTYPE Playground[cChunkDef::NumBlocks / 2];
for (int x = 0; x < 16; x++) for (int z = 0; z < 16; z++) for (int y = 0; y < 256; y++)
{
cChunkDef::SetNibble(Playground, x, y, z, x);
} // for x, y, z
} // for i
Tick = GetTickCount() - Tick;
LOGINFO("3000 chunkfulls of SetNibble() took %d ticks", Tick);
//*/
LOG("cWorld::cWorld(%s)", a_WorldName.c_str());
m_WorldName = a_WorldName;
m_IniFileName = m_WorldName + "/world.ini";

View File

@ -81,7 +81,7 @@ cWorldGenerator::~cWorldGenerator()
void cWorldGenerator::GenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, char * a_BlockData, cEntityList & a_Entities, cBlockEntityList & a_BlockEntities)
void cWorldGenerator::GenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, BLOCKTYPE * a_BlockData, cEntityList & a_Entities, cBlockEntityList & a_BlockEntities)
{
GenerateTerrain(a_ChunkX, a_ChunkY, a_ChunkZ, a_BlockData);
}
@ -190,7 +190,7 @@ unsigned int cWorldGenerator::MakeIndex(int x, int y, int z )
void cWorldGenerator::GenerateTerrain(int a_ChunkX, int a_ChunkY, int a_ChunkZ, char * a_BlockData)
void cWorldGenerator::GenerateTerrain(int a_ChunkX, int a_ChunkY, int a_ChunkZ, BLOCKTYPE * a_BlockData)
{
const int WATER_LEVEL = 60;
const int SAND_LEVEL = 3;
@ -327,7 +327,7 @@ void cWorldGenerator::GenerateTerrain(int a_ChunkX, int a_ChunkY, int a_ChunkZ,
void cWorldGenerator::GenerateOre(char a_OreType, int a_MaxHeight, int a_NumNests, int a_NestSize, char * a_BlockData)
void cWorldGenerator::GenerateOre(char a_OreType, int a_MaxHeight, int a_NumNests, int a_NestSize, BLOCKTYPE * a_BlockData)
{
// This function generates several "nests" of ore, each nest consisting of number of ore blocks relatively adjacent to each other.
// It does so by making a random XYZ walk and adding ore along the way in cuboids of different (random) sizes
@ -397,7 +397,7 @@ void cWorldGenerator::GenerateOre(char a_OreType, int a_MaxHeight, int a_NumNest
void cWorldGenerator::GenerateFoliage(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
{
char BlockType[cChunkDef::NumBlocks];
BLOCKTYPE BlockType[cChunkDef::NumBlocks];
if (!m_World->GetChunkBlockTypes(a_ChunkX, a_ChunkY, a_ChunkZ, BlockType))
{

View File

@ -25,7 +25,7 @@ public:
cWorldGenerator(cWorld * a_World);
~cWorldGenerator();
virtual void GenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, char * a_BlockData, cEntityList & a_Entities, cBlockEntityList & a_BlockEntities);
virtual void GenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, BLOCKTYPE * a_BlockData, cEntityList & a_Entities, cBlockEntityList & a_BlockEntities);
virtual void PostGenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Called when the chunk has been already generated and set valid

View File

@ -8,7 +8,7 @@
void cWorldGenerator_Test::GenerateTerrain(int a_ChunkX, int a_ChunkY, int a_ChunkZ, char * a_BlockData)
void cWorldGenerator_Test::GenerateTerrain(int a_ChunkX, int a_ChunkY, int a_ChunkZ, BLOCKTYPE * a_BlockData)
{
memset(a_BlockData, E_BLOCK_DIRT, cChunkDef::NumBlocks);
for(int x = 0; x < cChunkDef::Width; x++)

View File

@ -16,7 +16,7 @@ public:
protected:
virtual void GenerateTerrain(int a_ChunkX, int a_ChunkY, int a_ChunkZ, char * a_BlockData) override;
virtual void GenerateTerrain(int a_ChunkX, int a_ChunkY, int a_ChunkZ, BLOCKTYPE * a_BlockData) override;
virtual void GenerateFoliage(int a_ChunkX, int a_ChunkY, int a_ChunkZ) override;
};

View File

@ -19,7 +19,7 @@ cPacket_MapChunk::~cPacket_MapChunk()
cPacket_MapChunk::cPacket_MapChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, const char * a_BlockData, const char * a_BiomeData)
cPacket_MapChunk::cPacket_MapChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, const BLOCKTYPE * a_BlockData, const BIOMETYPE * a_BiomeData)
{
m_PacketID = E_MAP_CHUNK;

View File

@ -2,6 +2,7 @@
#pragma once
#include "cPacket.h"
#include "../ChunkDef.h"
@ -33,7 +34,7 @@ public:
{ m_PacketID = E_MAP_CHUNK; m_CompressedData = 0; }
cPacket_MapChunk( const cPacket_MapChunk & a_Copy );
cPacket_MapChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, const char * a_BlockData, const char * a_BiomeData);
cPacket_MapChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, const BLOCKTYPE * a_BlockData, const BIOMETYPE * a_BiomeData);
~cPacket_MapChunk();
virtual cPacket* Clone() const { return new cPacket_MapChunk(*this); }