diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-06-07 21:06:27 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-06-07 21:06:27 +0200 |
commit | 73a30d302bb6c62a0161a8a2f742b1e752f20871 (patch) | |
tree | 547abbcc4972790a7f02f654683a5148c2691315 | |
parent | Repeaters' delays can be set by rclk (diff) | |
download | cuberite-73a30d302bb6c62a0161a8a2f742b1e752f20871.tar cuberite-73a30d302bb6c62a0161a8a2f742b1e752f20871.tar.gz cuberite-73a30d302bb6c62a0161a8a2f742b1e752f20871.tar.bz2 cuberite-73a30d302bb6c62a0161a8a2f742b1e752f20871.tar.lz cuberite-73a30d302bb6c62a0161a8a2f742b1e752f20871.tar.xz cuberite-73a30d302bb6c62a0161a8a2f742b1e752f20871.tar.zst cuberite-73a30d302bb6c62a0161a8a2f742b1e752f20871.zip |
Diffstat (limited to '')
-rw-r--r-- | source/cChunk.cpp | 187 | ||||
-rw-r--r-- | source/cChunk.h | 5 |
2 files changed, 98 insertions, 94 deletions
diff --git a/source/cChunk.cpp b/source/cChunk.cpp index 0cdebc503..eba434ed1 100644 --- a/source/cChunk.cpp +++ b/source/cChunk.cpp @@ -402,124 +402,125 @@ 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)
{
- Lock2.Lock();
- std::deque< unsigned int > ToTickBlocks = m_ToTickBlocks;
- m_ToTickBlocks.clear();
- Lock2.Unlock();
+ return;
+ }
- bool isRedstone = false;
- for ( std::deque< unsigned int >::iterator itr = ToTickBlocks.begin(); itr != ToTickBlocks.end(); ++itr )
- {
- unsigned int index = (*itr);
- Vector3i BlockPos = IndexToCoordinate( index );
+ Lock2.Lock();
+ std::deque< unsigned int > ToTickBlocks = m_ToTickBlocks;
+ m_ToTickBlocks.clear();
+ Lock2.Unlock();
+
+ 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 );
- NIBBLETYPE BlockMeta = GetMeta(index);
- switch ( BlockID )
+ BLOCKTYPE BlockType = GetBlock(index);
+ NIBBLETYPE BlockMeta = GetMeta (index);
+ switch (BlockType)
+ {
+ case E_BLOCK_REDSTONE_REPEATER_OFF:
+ case E_BLOCK_REDSTONE_REPEATER_ON:
+ case E_BLOCK_REDSTONE_WIRE:
+ case E_BLOCK_CACTUS:
+ case E_BLOCK_REEDS:
+ case E_BLOCK_WOODEN_PRESSURE_PLATE:
+ case E_BLOCK_STONE_PRESSURE_PLATE:
+ case E_BLOCK_MINECART_TRACKS:
+ case E_BLOCK_SIGN_POST:
+ case E_BLOCK_CROPS:
+ case E_BLOCK_SAPLING:
+ case E_BLOCK_YELLOW_FLOWER:
+ case E_BLOCK_RED_ROSE:
+ case E_BLOCK_RED_MUSHROOM:
+ case E_BLOCK_BROWN_MUSHROOM: // Stuff that drops when block below is destroyed
{
- case E_BLOCK_REDSTONE_REPEATER_OFF:
- case E_BLOCK_REDSTONE_REPEATER_ON:
- case E_BLOCK_REDSTONE_WIRE:
+ if (GetBlock(BlockPos.x, BlockPos.y - 1, BlockPos.z) == E_BLOCK_AIR)
{
- isRedstone = true;
- // fallthrough
- }
-
- case E_BLOCK_CACTUS:
- case E_BLOCK_REEDS:
- case E_BLOCK_WOODEN_PRESSURE_PLATE:
- case E_BLOCK_STONE_PRESSURE_PLATE:
- case E_BLOCK_MINECART_TRACKS:
- case E_BLOCK_SIGN_POST:
- case E_BLOCK_CROPS:
- case E_BLOCK_SAPLING:
- case E_BLOCK_YELLOW_FLOWER:
- case E_BLOCK_RED_ROSE:
- case E_BLOCK_RED_MUSHROOM:
- case E_BLOCK_BROWN_MUSHROOM: // Stuff that drops when block below is destroyed
- {
- if (GetBlock(BlockPos.x, BlockPos.y - 1, BlockPos.z) == E_BLOCK_AIR)
- {
- SetBlock( BlockPos, E_BLOCK_AIR, 0 );
+ SetBlock( BlockPos, E_BLOCK_AIR, 0 );
- Vector3i WorldPos = PositionToWorldPosition( BlockPos );
+ Vector3i WorldPos = PositionToWorldPosition( BlockPos );
- m_World->GetSimulatorManager()->WakeUp(WorldPos.x, WorldPos.y, WorldPos.z);
-
- cItems Pickups;
- cBlockToPickup::ToPickup(BlockID, BlockMeta, E_ITEM_EMPTY, Pickups);
- m_World->SpawnItemPickups(Pickups, WorldPos.x, WorldPos.y, WorldPos.z);
- }
- break;
+ m_World->GetSimulatorManager()->WakeUp(WorldPos.x, WorldPos.y, WorldPos.z);
+
+ cItems Pickups;
+ cBlockToPickup::ToPickup(BlockType, BlockMeta, E_ITEM_EMPTY, Pickups);
+ m_World->SpawnItemPickups(Pickups, WorldPos.x, WorldPos.y, WorldPos.z);
}
+ break;
+ }
- 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 ) );
- Vector3i WorldPos = PositionToWorldPosition( BlockPos );
+ case E_BLOCK_REDSTONE_TORCH_OFF:
+ case E_BLOCK_REDSTONE_TORCH_ON:
+ case E_BLOCK_TORCH:
+ {
+ char Dir = cTorch::MetaDataToDirection( GetNibble( m_BlockMeta, BlockPos ) );
+ Vector3i WorldPos = PositionToWorldPosition( BlockPos );
- Vector3i AttachedTo = WorldPos;
- AddDirection( AttachedTo.x, AttachedTo.y, AttachedTo.z, Dir, true );
- if( m_World->GetBlock( AttachedTo ) == E_BLOCK_AIR )
- {
- SetBlock( BlockPos, E_BLOCK_AIR, 0 );
+ Vector3i AttachedTo = WorldPos;
+ AddDirection( AttachedTo.x, AttachedTo.y, AttachedTo.z, Dir, true );
+ if( m_World->GetBlock( AttachedTo ) == E_BLOCK_AIR )
+ {
+ SetBlock( BlockPos, E_BLOCK_AIR, 0 );
- m_World->GetSimulatorManager()->WakeUp(WorldPos.x, WorldPos.y, WorldPos.z);
+ m_World->GetSimulatorManager()->WakeUp(WorldPos.x, WorldPos.y, WorldPos.z);
- cItems Pickups;
- cBlockToPickup::ToPickup(BlockID, BlockMeta, E_ITEM_EMPTY, Pickups);
- m_World->SpawnItemPickups(Pickups, WorldPos.x, WorldPos.y, WorldPos.z);
- }
- break;
+ cItems Pickups;
+ cBlockToPickup::ToPickup(BlockType, BlockMeta, E_ITEM_EMPTY, Pickups);
+ m_World->SpawnItemPickups(Pickups, WorldPos.x, WorldPos.y, WorldPos.z);
}
+ break;
+ }
- case E_BLOCK_LADDER:
+ case E_BLOCK_LADDER:
+ {
+ char Dir = cLadder::MetaDataToDirection( GetNibble( m_BlockMeta, BlockPos ) );
+ Vector3i WorldPos = PositionToWorldPosition( BlockPos );
+ Vector3i AttachedTo = WorldPos;
+ AddDirection( AttachedTo.x, AttachedTo.y, AttachedTo.z, Dir, true );
+ if( m_World->GetBlock( AttachedTo ) == E_BLOCK_AIR )
{
- char Dir = cLadder::MetaDataToDirection( GetNibble( m_BlockMeta, BlockPos ) );
- Vector3i WorldPos = PositionToWorldPosition( BlockPos );
- Vector3i AttachedTo = WorldPos;
- AddDirection( AttachedTo.x, AttachedTo.y, AttachedTo.z, Dir, true );
- if( m_World->GetBlock( AttachedTo ) == E_BLOCK_AIR )
- {
- SetBlock( BlockPos, E_BLOCK_AIR, 0 );
- cItems Pickups;
- cBlockToPickup::ToPickup(BlockID, BlockMeta, E_ITEM_EMPTY, Pickups);
- m_World->SpawnItemPickups(Pickups, WorldPos.x, WorldPos.y, WorldPos.z);
- }
- break;
+ SetBlock( BlockPos, E_BLOCK_AIR, 0 );
+ cItems Pickups;
+ cBlockToPickup::ToPickup(BlockType, BlockMeta, E_ITEM_EMPTY, Pickups);
+ m_World->SpawnItemPickups(Pickups, WorldPos.x, WorldPos.y, WorldPos.z);
}
- } // switch (BlockType)
- } // 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;
- }
- }
+ break;
+ }
+ } // switch (BlockType)
+ } // for itr - ToTickBlocks[]
}
+
void cChunk::TickBlocks(MTRand & a_TickRandom)
{
// Tick dem blocks
diff --git a/source/cChunk.h b/source/cChunk.h index 415205b33..6fe4e77f7 100644 --- a/source/cChunk.h +++ b/source/cChunk.h @@ -227,7 +227,10 @@ private: // Makes a copy of the list
cClientHandleList GetAllClients(void) const {return m_LoadedByClient; }
- void TickBlocks(MTRand & a_TickRandom);
+ /// 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);
void TickFarmland (int a_RelX, int a_RelY, int a_RelZ);
|