Improved redstone speed and fixed a wire bug
The redstone simulator no longer goes through the Powered and LinkedPowered blocks lists for EVERY item in the chunk data, instead, only at every tick. Also, wires powering each other that had the same data value is now fixed.
This commit is contained in:
parent
4741e5e794
commit
8d88c8f26f
@ -76,15 +76,6 @@ void cRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, c
|
||||
int BaseX = a_Chunk->GetPosX() * cChunkDef::Width;
|
||||
int BaseZ = a_Chunk->GetPosZ() * cChunkDef::Width;
|
||||
|
||||
for (cRedstoneSimulatorChunkData::iterator dataitr = ChunkData.begin(), end = ChunkData.end(); dataitr != end;)
|
||||
{
|
||||
BLOCKTYPE BlockType = a_Chunk->GetBlock(dataitr->x, dataitr->y, dataitr->z);
|
||||
if (!IsAllowedBlock(BlockType))
|
||||
{
|
||||
dataitr = ChunkData.erase(dataitr);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check to see if PoweredBlocks have invalid items (source is air or unpowered)
|
||||
for (PoweredBlocksList::iterator itr = m_PoweredBlocks.begin(); itr != m_PoweredBlocks.end();)
|
||||
{
|
||||
@ -95,7 +86,10 @@ void cRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, c
|
||||
|
||||
BLOCKTYPE SourceBlockType;
|
||||
NIBBLETYPE SourceBlockMeta;
|
||||
a_Chunk->UnboundedRelGetBlock(RelX, Change.a_SourcePos.y, RelZ, SourceBlockType, SourceBlockMeta);
|
||||
if (!a_Chunk->UnboundedRelGetBlock(RelX, Change.a_SourcePos.y, RelZ, SourceBlockType, SourceBlockMeta))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (SourceBlockType != Change.a_SourceBlock)
|
||||
{
|
||||
@ -132,8 +126,13 @@ void cRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, c
|
||||
BLOCKTYPE SourceBlockType;
|
||||
NIBBLETYPE SourceBlockMeta;
|
||||
BLOCKTYPE MiddleBlockType;
|
||||
a_Chunk->UnboundedRelGetBlock(RelX, Change.a_SourcePos.y, RelZ, SourceBlockType, SourceBlockMeta);
|
||||
a_Chunk->UnboundedRelGetBlockType(MidRelX, Change.a_MiddlePos.y, MidRelZ, MiddleBlockType);
|
||||
if (
|
||||
!a_Chunk->UnboundedRelGetBlock(RelX, Change.a_SourcePos.y, RelZ, SourceBlockType, SourceBlockMeta) ||
|
||||
!a_Chunk->UnboundedRelGetBlockType(MidRelX, Change.a_MiddlePos.y, MidRelZ, MiddleBlockType)
|
||||
)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (SourceBlockType != Change.a_SourceBlock)
|
||||
{
|
||||
@ -161,7 +160,16 @@ void cRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, c
|
||||
}
|
||||
}
|
||||
|
||||
// PoweredBlock list was fine, now to the actual handling
|
||||
for (cRedstoneSimulatorChunkData::iterator dataitr = ChunkData.begin(), end = ChunkData.end(); dataitr != end;)
|
||||
{
|
||||
BLOCKTYPE BlockType = a_Chunk->GetBlock(dataitr->x, dataitr->y, dataitr->z);
|
||||
if (!IsAllowedBlock(BlockType))
|
||||
{
|
||||
dataitr = ChunkData.erase(dataitr);
|
||||
continue;
|
||||
}
|
||||
|
||||
// PoweredBlock and LinkedPoweredBlock list was fine, now to the actual handling
|
||||
int a_X = BaseX + dataitr->x;
|
||||
int a_Z = BaseZ + dataitr->z;
|
||||
switch (BlockType)
|
||||
@ -407,7 +415,9 @@ void cRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_BlockY, int a_Bl
|
||||
|
||||
if (SurroundMeta > 1) // Wires of power 1 or 0 cannot transfer power TO ME, don't bother checking
|
||||
{
|
||||
if (SurroundMeta > MyMeta) // Does surrounding wire have a higher power level than self?
|
||||
// Does surrounding wire have a higher power level than self?
|
||||
// >= to fix a bug where wires bordering each other with the same power level will appear (in terms of meta) to power each other, when they aren't actually in the powered list
|
||||
if (SurroundMeta >= MyMeta)
|
||||
{
|
||||
m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, SurroundMeta - 1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user