1
0

BlockChecking split into a separate function

git-svn-id: http://mc-server.googlecode.com/svn/trunk@571 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2012-06-07 19:06:27 +00:00
parent c0a73ef89d
commit 73a30d302b
2 changed files with 107 additions and 103 deletions

View File

@ -402,35 +402,52 @@ void cChunk::Tick(float a_Dt, MTRand & a_TickRandom)
m_UnloadQuery.remove( *m_UnloadQuery.begin() );
}
CheckBlocks();
TickBlocks(a_TickRandom);
// Tick block entities (furnaces)
for (cBlockEntityList::iterator itr = m_BlockEntities.begin(); itr != m_BlockEntities.end(); ++itr)
{
if ((*itr)->GetBlockType() == E_BLOCK_FURNACE)
{
m_IsDirty = ((cFurnaceEntity *)(*itr))->Tick( a_Dt ) | m_IsDirty;
}
}
}
void cChunk::CheckBlocks(void)
{
cCSLock Lock2(m_CSBlockLists);
unsigned int NumTickBlocks = m_ToTickBlocks.size();
Lock2.Unlock();
if ( NumTickBlocks > 0 )
if (NumTickBlocks == 0)
{
return;
}
Lock2.Lock();
std::deque< unsigned int > ToTickBlocks = m_ToTickBlocks;
m_ToTickBlocks.clear();
Lock2.Unlock();
bool isRedstone = false;
for ( std::deque< unsigned int >::iterator itr = ToTickBlocks.begin(); itr != ToTickBlocks.end(); ++itr )
for (std::deque< unsigned int >::const_iterator itr = ToTickBlocks.begin(); itr != ToTickBlocks.end(); ++itr)
{
unsigned int index = (*itr);
Vector3i BlockPos = IndexToCoordinate(index);
BLOCKTYPE BlockID = GetBlock( index );
BLOCKTYPE BlockType = GetBlock(index);
NIBBLETYPE BlockMeta = GetMeta (index);
switch ( BlockID )
switch (BlockType)
{
case E_BLOCK_REDSTONE_REPEATER_OFF:
case E_BLOCK_REDSTONE_REPEATER_ON:
case E_BLOCK_REDSTONE_WIRE:
{
isRedstone = true;
// fallthrough
}
case E_BLOCK_CACTUS:
case E_BLOCK_REEDS:
case E_BLOCK_WOODEN_PRESSURE_PLATE:
@ -453,7 +470,7 @@ void cChunk::Tick(float a_Dt, MTRand & a_TickRandom)
m_World->GetSimulatorManager()->WakeUp(WorldPos.x, WorldPos.y, WorldPos.z);
cItems Pickups;
cBlockToPickup::ToPickup(BlockID, BlockMeta, E_ITEM_EMPTY, Pickups);
cBlockToPickup::ToPickup(BlockType, BlockMeta, E_ITEM_EMPTY, Pickups);
m_World->SpawnItemPickups(Pickups, WorldPos.x, WorldPos.y, WorldPos.z);
}
break;
@ -461,11 +478,6 @@ void cChunk::Tick(float a_Dt, MTRand & a_TickRandom)
case E_BLOCK_REDSTONE_TORCH_OFF:
case E_BLOCK_REDSTONE_TORCH_ON:
{
isRedstone = true;
// fallthrough
}
case E_BLOCK_TORCH:
{
char Dir = cTorch::MetaDataToDirection( GetNibble( m_BlockMeta, BlockPos ) );
@ -480,7 +492,7 @@ void cChunk::Tick(float a_Dt, MTRand & a_TickRandom)
m_World->GetSimulatorManager()->WakeUp(WorldPos.x, WorldPos.y, WorldPos.z);
cItems Pickups;
cBlockToPickup::ToPickup(BlockID, BlockMeta, E_ITEM_EMPTY, Pickups);
cBlockToPickup::ToPickup(BlockType, BlockMeta, E_ITEM_EMPTY, Pickups);
m_World->SpawnItemPickups(Pickups, WorldPos.x, WorldPos.y, WorldPos.z);
}
break;
@ -496,7 +508,7 @@ void cChunk::Tick(float a_Dt, MTRand & a_TickRandom)
{
SetBlock( BlockPos, E_BLOCK_AIR, 0 );
cItems Pickups;
cBlockToPickup::ToPickup(BlockID, BlockMeta, E_ITEM_EMPTY, Pickups);
cBlockToPickup::ToPickup(BlockType, BlockMeta, E_ITEM_EMPTY, Pickups);
m_World->SpawnItemPickups(Pickups, WorldPos.x, WorldPos.y, WorldPos.z);
}
break;
@ -505,17 +517,6 @@ void cChunk::Tick(float a_Dt, MTRand & a_TickRandom)
} // for itr - ToTickBlocks[]
}
TickBlocks(a_TickRandom);
// Tick block entities (furnaces)
for (cBlockEntityList::iterator itr = m_BlockEntities.begin(); itr != m_BlockEntities.end(); ++itr)
{
if ((*itr)->GetBlockType() == E_BLOCK_FURNACE)
{
m_IsDirty = ((cFurnaceEntity *)(*itr))->Tick( a_Dt ) | m_IsDirty;
}
}
}

View File

@ -227,6 +227,9 @@ private:
// Makes a copy of the list
cClientHandleList GetAllClients(void) const {return m_LoadedByClient; }
/// Checks the block scheduled for checking in m_ToTickBlocks[]
void CheckBlocks(void);
void TickBlocks (MTRand & a_TickRandom);
void TickGrass (int a_RelX, int a_RelY, int a_RelZ, MTRand & a_TickRandom);
void TickMelonPumpkin(int a_RelX, int a_RelY, int a_RelZ, int a_BlockIdx, BLOCKTYPE a_BlockType, MTRand & a_TickRandom);