Converted simulators to take cWorld reference instead of a pointer
git-svn-id: http://mc-server.googlecode.com/svn/trunk@1228 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
2588f5a605
commit
619ec8b247
@ -32,7 +32,7 @@
|
|||||||
class cClassicFluidSimulator::FluidData
|
class cClassicFluidSimulator::FluidData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FluidData(cWorld * a_World, cClassicFluidSimulator * a_Simulator )
|
FluidData(cWorld & a_World, cClassicFluidSimulator * a_Simulator )
|
||||||
: m_ActiveFluid( new std::set < Vector3i >() )
|
: m_ActiveFluid( new std::set < Vector3i >() )
|
||||||
, m_Simulator (a_Simulator)
|
, m_Simulator (a_Simulator)
|
||||||
, m_Buffer( new std::set< Vector3i >() )
|
, m_Buffer( new std::set< Vector3i >() )
|
||||||
@ -109,8 +109,8 @@ public:
|
|||||||
{
|
{
|
||||||
for (int z = 0; z < AREA_WIDTH; z++)
|
for (int z = 0; z < AREA_WIDTH; z++)
|
||||||
{
|
{
|
||||||
char UpperBlock = m_World->GetBlock(CornerGlobal.x + x, CornerGlobal.y, CornerGlobal.z + z);
|
BLOCKTYPE UpperBlock = m_World.GetBlock(CornerGlobal.x + x, CornerGlobal.y, CornerGlobal.z + z);
|
||||||
char DownBlock = m_World->GetBlock(CornerGlobal.x + x, CornerGlobal.y - 1, CornerGlobal.z + z);
|
BLOCKTYPE DownBlock = m_World.GetBlock(CornerGlobal.x + x, CornerGlobal.y - 1, CornerGlobal.z + z);
|
||||||
|
|
||||||
if (m_Simulator->IsSolidBlock(UpperBlock) || (m_Simulator->IsStationaryFluidBlock(UpperBlock)))
|
if (m_Simulator->IsSolidBlock(UpperBlock) || (m_Simulator->IsStationaryFluidBlock(UpperBlock)))
|
||||||
{
|
{
|
||||||
@ -214,7 +214,7 @@ public:
|
|||||||
};
|
};
|
||||||
for (int i = 0; i < 4; ++i)
|
for (int i = 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
char Block = m_World->GetBlock(LevelPoints[i].x, a_BlockY, LevelPoints[i].z);
|
char Block = m_World.GetBlock(LevelPoints[i].x, a_BlockY, LevelPoints[i].z);
|
||||||
if (m_Simulator->IsPassableForFluid(Block))
|
if (m_Simulator->IsPassableForFluid(Block))
|
||||||
{
|
{
|
||||||
Points.push_back(LevelPoints[i]);
|
Points.push_back(LevelPoints[i]);
|
||||||
@ -227,7 +227,7 @@ public:
|
|||||||
|
|
||||||
std::set< Vector3i > * m_ActiveFluid;
|
std::set< Vector3i > * m_ActiveFluid;
|
||||||
std::set< Vector3i > * m_Buffer;
|
std::set< Vector3i > * m_Buffer;
|
||||||
cWorld * m_World;
|
cWorld & m_World;
|
||||||
cClassicFluidSimulator * m_Simulator;
|
cClassicFluidSimulator * m_Simulator;
|
||||||
|
|
||||||
const static int AREA_WIDTH = 11;
|
const static int AREA_WIDTH = 11;
|
||||||
@ -262,7 +262,7 @@ public:
|
|||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// cClassicFluidSimulator:
|
// cClassicFluidSimulator:
|
||||||
|
|
||||||
cClassicFluidSimulator::cClassicFluidSimulator(cWorld * a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, NIBBLETYPE a_MaxHeight, NIBBLETYPE a_Falloff) :
|
cClassicFluidSimulator::cClassicFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, NIBBLETYPE a_MaxHeight, NIBBLETYPE a_Falloff) :
|
||||||
cFluidSimulator(a_World, a_Fluid, a_StationaryFluid),
|
cFluidSimulator(a_World, a_Fluid, a_StationaryFluid),
|
||||||
m_Data(NULL),
|
m_Data(NULL),
|
||||||
m_MaxHeight(a_MaxHeight),
|
m_MaxHeight(a_MaxHeight),
|
||||||
@ -287,7 +287,7 @@ cClassicFluidSimulator::~cClassicFluidSimulator()
|
|||||||
void cClassicFluidSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk)
|
void cClassicFluidSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk)
|
||||||
{
|
{
|
||||||
// TODO: This can be optimized
|
// TODO: This can be optimized
|
||||||
BLOCKTYPE BlockType = m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
|
BLOCKTYPE BlockType = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ);
|
||||||
if (!IsAllowedBlock(BlockType)) // This should save very much time because it doesn´t have to iterate through all blocks
|
if (!IsAllowedBlock(BlockType)) // This should save very much time because it doesn´t have to iterate through all blocks
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -306,10 +306,10 @@ NIBBLETYPE cClassicFluidSimulator::GetHighestLevelAround(int a_BlockX, int a_Blo
|
|||||||
NIBBLETYPE Max = m_MaxHeight + m_Falloff;
|
NIBBLETYPE Max = m_MaxHeight + m_Falloff;
|
||||||
|
|
||||||
#define __HIGHLEVEL_CHECK__( x, y, z ) \
|
#define __HIGHLEVEL_CHECK__( x, y, z ) \
|
||||||
if (IsAllowedBlock(m_World->GetBlock( x, y, z ) ) ) \
|
if (IsAllowedBlock(m_World.GetBlock( x, y, z ) ) ) \
|
||||||
{ \
|
{ \
|
||||||
NIBBLETYPE Meta; \
|
NIBBLETYPE Meta; \
|
||||||
if ((Meta = m_World->GetBlockMeta( x, y, z ) ) < Max ) Max = Meta; \
|
if ((Meta = m_World.GetBlockMeta( x, y, z ) ) < Max ) Max = Meta; \
|
||||||
else if (Meta == m_MaxHeight + m_Falloff) Max = 0; \
|
else if (Meta == m_MaxHeight + m_Falloff) Max = 0; \
|
||||||
if (Max == 0) return 0; \
|
if (Max == 0) return 0; \
|
||||||
}
|
}
|
||||||
@ -348,16 +348,16 @@ void cClassicFluidSimulator::Simulate(float a_Dt)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
char BlockID = m_World->GetBlock( pos.x, pos.y, pos.z );
|
char BlockID = m_World.GetBlock( pos.x, pos.y, pos.z );
|
||||||
if( IsAllowedBlock( BlockID ) ) // only care about own fluid
|
if( IsAllowedBlock( BlockID ) ) // only care about own fluid
|
||||||
{
|
{
|
||||||
bool bIsFed = false;
|
bool bIsFed = false;
|
||||||
NIBBLETYPE Meta = m_World->GetBlockMeta( pos.x, pos.y, pos.z );
|
NIBBLETYPE Meta = m_World.GetBlockMeta( pos.x, pos.y, pos.z );
|
||||||
NIBBLETYPE Feed = Meta;
|
NIBBLETYPE Feed = Meta;
|
||||||
if (BlockID == m_StationaryFluidBlock) Meta = 0;
|
if (BlockID == m_StationaryFluidBlock) Meta = 0;
|
||||||
if (Meta == 8 ) // Falling fluid
|
if (Meta == 8 ) // Falling fluid
|
||||||
{
|
{
|
||||||
if (IsAllowedBlock( m_World->GetBlock(pos.x, pos.y+1, pos.z) ) ) // Block above is fluid
|
if (IsAllowedBlock( m_World.GetBlock(pos.x, pos.y+1, pos.z) ) ) // Block above is fluid
|
||||||
{
|
{
|
||||||
bIsFed = true;
|
bIsFed = true;
|
||||||
Meta = 0; // Make it a full block
|
Meta = 0; // Make it a full block
|
||||||
@ -376,7 +376,7 @@ void cClassicFluidSimulator::Simulate(float a_Dt)
|
|||||||
|
|
||||||
if( bIsFed )
|
if( bIsFed )
|
||||||
{
|
{
|
||||||
char DownID = m_World->GetBlock(pos.x, pos.y - 1, pos.z);
|
char DownID = m_World.GetBlock(pos.x, pos.y - 1, pos.z);
|
||||||
bool bWashedAwayItem = CanWashAway(DownID);
|
bool bWashedAwayItem = CanWashAway(DownID);
|
||||||
if ((IsPassableForFluid(DownID) || bWashedAwayItem) && !IsStationaryFluidBlock(DownID) ) // free for fluid
|
if ((IsPassableForFluid(DownID) || bWashedAwayItem) && !IsStationaryFluidBlock(DownID) ) // free for fluid
|
||||||
{
|
{
|
||||||
@ -385,12 +385,12 @@ void cClassicFluidSimulator::Simulate(float a_Dt)
|
|||||||
cBlockHandler * Handler = BlockHandler(DownID);
|
cBlockHandler * Handler = BlockHandler(DownID);
|
||||||
if (Handler->DoesDropOnUnsuitable())
|
if (Handler->DoesDropOnUnsuitable())
|
||||||
{
|
{
|
||||||
Handler->DropBlock(m_World, NULL, pos.x, pos.y - 1, pos.z);
|
Handler->DropBlock(&m_World, NULL, pos.x, pos.y - 1, pos.z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pos.y > 0)
|
if (pos.y > 0)
|
||||||
{
|
{
|
||||||
m_World->SetBlock(pos.x, pos.y - 1, pos.z, m_FluidBlock, 8); // falling
|
m_World.SetBlock(pos.x, pos.y - 1, pos.z, m_FluidBlock, 8); // falling
|
||||||
ApplyUniqueToNearest(pos - Vector3i(0, 1, 0));
|
ApplyUniqueToNearest(pos - Vector3i(0, 1, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -398,7 +398,7 @@ void cClassicFluidSimulator::Simulate(float a_Dt)
|
|||||||
{
|
{
|
||||||
if (Feed + m_Falloff < Meta)
|
if (Feed + m_Falloff < Meta)
|
||||||
{
|
{
|
||||||
m_World->SetBlock(pos.x, pos.y, pos.z, m_FluidBlock, Feed + m_Falloff);
|
m_World.SetBlock(pos.x, pos.y, pos.z, m_FluidBlock, Feed + m_Falloff);
|
||||||
ApplyUniqueToNearest(pos);
|
ApplyUniqueToNearest(pos);
|
||||||
}
|
}
|
||||||
else if ((Meta < m_MaxHeight ) || (BlockID == m_StationaryFluidBlock)) // max is the lowest, so it cannot spread
|
else if ((Meta < m_MaxHeight ) || (BlockID == m_StationaryFluidBlock)) // max is the lowest, so it cannot spread
|
||||||
@ -407,7 +407,7 @@ void cClassicFluidSimulator::Simulate(float a_Dt)
|
|||||||
for( std::vector< Vector3i >::iterator itr = Points.begin(); itr != Points.end(); ++itr )
|
for( std::vector< Vector3i >::iterator itr = Points.begin(); itr != Points.end(); ++itr )
|
||||||
{
|
{
|
||||||
Vector3i & p = *itr;
|
Vector3i & p = *itr;
|
||||||
char BlockID = m_World->GetBlock( p.x, p.y, p.z );
|
char BlockID = m_World.GetBlock( p.x, p.y, p.z );
|
||||||
bool bWashedAwayItem = CanWashAway( BlockID );
|
bool bWashedAwayItem = CanWashAway( BlockID );
|
||||||
|
|
||||||
if (!IsPassableForFluid(BlockID)) continue;
|
if (!IsPassableForFluid(BlockID)) continue;
|
||||||
@ -419,23 +419,23 @@ void cClassicFluidSimulator::Simulate(float a_Dt)
|
|||||||
cBlockHandler * Handler = BlockHandler(DownID);
|
cBlockHandler * Handler = BlockHandler(DownID);
|
||||||
if (Handler->DoesDropOnUnsuitable())
|
if (Handler->DoesDropOnUnsuitable())
|
||||||
{
|
{
|
||||||
Handler->DropBlock(m_World, NULL, p.x, p.y, p.z);
|
Handler->DropBlock(&m_World, NULL, p.x, p.y, p.z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.y == pos.y)
|
if (p.y == pos.y)
|
||||||
{
|
{
|
||||||
m_World->SetBlock(p.x, p.y, p.z, m_FluidBlock, Meta + m_Falloff);
|
m_World.SetBlock(p.x, p.y, p.z, m_FluidBlock, Meta + m_Falloff);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_World->SetBlock(p.x, p.y, p.z, m_FluidBlock, 8);
|
m_World.SetBlock(p.x, p.y, p.z, m_FluidBlock, 8);
|
||||||
}
|
}
|
||||||
ApplyUniqueToNearest(p);
|
ApplyUniqueToNearest(p);
|
||||||
}
|
}
|
||||||
else // it's fluid
|
else // it's fluid
|
||||||
{
|
{
|
||||||
NIBBLETYPE PointMeta = m_World->GetBlockMeta(p.x, p.y, p.z);
|
NIBBLETYPE PointMeta = m_World.GetBlockMeta(p.x, p.y, p.z);
|
||||||
if (PointMeta > Meta + m_Falloff)
|
if (PointMeta > Meta + m_Falloff)
|
||||||
{
|
{
|
||||||
// TODO: AddBlock(p.x, p.y, p.z);
|
// TODO: AddBlock(p.x, p.y, p.z);
|
||||||
@ -448,7 +448,7 @@ void cClassicFluidSimulator::Simulate(float a_Dt)
|
|||||||
}
|
}
|
||||||
else // not fed
|
else // not fed
|
||||||
{
|
{
|
||||||
m_World->SetBlock(pos.x, pos.y, pos.z, E_BLOCK_AIR, 0);
|
m_World.SetBlock(pos.x, pos.y, pos.z, E_BLOCK_AIR, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -462,22 +462,22 @@ bool cClassicFluidSimulator::UniqueSituation(Vector3i a_Pos)
|
|||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
char BlockId = m_World->GetBlock( a_Pos.x, a_Pos.y, a_Pos.z );
|
char BlockId = m_World.GetBlock( a_Pos.x, a_Pos.y, a_Pos.z );
|
||||||
char Meta = m_World->GetBlockMeta( a_Pos.x, a_Pos.y, a_Pos.z );
|
char Meta = m_World.GetBlockMeta( a_Pos.x, a_Pos.y, a_Pos.z );
|
||||||
|
|
||||||
if(IsBlockWater(BlockId))
|
if(IsBlockWater(BlockId))
|
||||||
{
|
{
|
||||||
|
|
||||||
char UpperBlock = m_World->GetBlock( a_Pos.x, a_Pos.y + 1, a_Pos.z );
|
char UpperBlock = m_World.GetBlock( a_Pos.x, a_Pos.y + 1, a_Pos.z );
|
||||||
if(IsBlockLava(UpperBlock))
|
if(IsBlockLava(UpperBlock))
|
||||||
{
|
{
|
||||||
m_World->SetBlock(a_Pos.x, a_Pos.y, a_Pos.z, E_BLOCK_STONE, 0);
|
m_World.SetBlock(a_Pos.x, a_Pos.y, a_Pos.z, E_BLOCK_STONE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(BlockId != E_BLOCK_STATIONARY_WATER)
|
if(BlockId != E_BLOCK_STATIONARY_WATER)
|
||||||
{
|
{
|
||||||
char DownBlockId = m_World->GetBlock( a_Pos.x, a_Pos.y-1, a_Pos.z );
|
char DownBlockId = m_World.GetBlock( a_Pos.x, a_Pos.y-1, a_Pos.z );
|
||||||
if(IsSolidBlock(DownBlockId))
|
if(IsSolidBlock(DownBlockId))
|
||||||
{
|
{
|
||||||
Vector3i LevelPoints [] = {
|
Vector3i LevelPoints [] = {
|
||||||
@ -489,14 +489,14 @@ bool cClassicFluidSimulator::UniqueSituation(Vector3i a_Pos)
|
|||||||
int SourceBlocksCount = 0;
|
int SourceBlocksCount = 0;
|
||||||
for(int i=0; i<4; i++)
|
for(int i=0; i<4; i++)
|
||||||
{
|
{
|
||||||
if (m_World->GetBlock(LevelPoints[i].x, LevelPoints[i].y, LevelPoints[i].z)==E_BLOCK_STATIONARY_WATER)
|
if (m_World.GetBlock(LevelPoints[i].x, LevelPoints[i].y, LevelPoints[i].z)==E_BLOCK_STATIONARY_WATER)
|
||||||
{
|
{
|
||||||
SourceBlocksCount++;
|
SourceBlocksCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(SourceBlocksCount>=2)
|
if(SourceBlocksCount>=2)
|
||||||
{
|
{
|
||||||
m_World->SetBlock(a_Pos.x, a_Pos.y, a_Pos.z, E_BLOCK_STATIONARY_WATER, 0);
|
m_World.SetBlock(a_Pos.x, a_Pos.y, a_Pos.z, E_BLOCK_STATIONARY_WATER, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -507,7 +507,7 @@ bool cClassicFluidSimulator::UniqueSituation(Vector3i a_Pos)
|
|||||||
{
|
{
|
||||||
bool bWater = false;
|
bool bWater = false;
|
||||||
|
|
||||||
char UpperBlock = m_World->GetBlock( a_Pos.x, a_Pos.y + 1, a_Pos.z );
|
char UpperBlock = m_World.GetBlock( a_Pos.x, a_Pos.y + 1, a_Pos.z );
|
||||||
if (IsBlockWater(UpperBlock))
|
if (IsBlockWater(UpperBlock))
|
||||||
{
|
{
|
||||||
bWater = true;
|
bWater = true;
|
||||||
@ -523,7 +523,7 @@ bool cClassicFluidSimulator::UniqueSituation(Vector3i a_Pos)
|
|||||||
|
|
||||||
for(int i=0; i<4; i++)
|
for(int i=0; i<4; i++)
|
||||||
{
|
{
|
||||||
if (IsBlockWater(m_World->GetBlock(LevelPoints[i].x, LevelPoints[i].y, LevelPoints[i].z)))
|
if (IsBlockWater(m_World.GetBlock(LevelPoints[i].x, LevelPoints[i].y, LevelPoints[i].z)))
|
||||||
{
|
{
|
||||||
bWater = true;
|
bWater = true;
|
||||||
}
|
}
|
||||||
@ -535,11 +535,11 @@ bool cClassicFluidSimulator::UniqueSituation(Vector3i a_Pos)
|
|||||||
{
|
{
|
||||||
if (BlockId == E_BLOCK_STATIONARY_LAVA)
|
if (BlockId == E_BLOCK_STATIONARY_LAVA)
|
||||||
{
|
{
|
||||||
m_World->SetBlock(a_Pos.x, a_Pos.y, a_Pos.z, E_BLOCK_OBSIDIAN, 0);
|
m_World.SetBlock(a_Pos.x, a_Pos.y, a_Pos.z, E_BLOCK_OBSIDIAN, 0);
|
||||||
}
|
}
|
||||||
else if (Meta<m_MaxHeight)
|
else if (Meta<m_MaxHeight)
|
||||||
{
|
{
|
||||||
m_World->SetBlock(a_Pos.x, a_Pos.y, a_Pos.z, E_BLOCK_COBBLESTONE, 0);
|
m_World.SetBlock(a_Pos.x, a_Pos.y, a_Pos.z, E_BLOCK_COBBLESTONE, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ class cClassicFluidSimulator :
|
|||||||
public cFluidSimulator
|
public cFluidSimulator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cClassicFluidSimulator(cWorld * a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, NIBBLETYPE a_MaxHeight, NIBBLETYPE a_Falloff);
|
cClassicFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, NIBBLETYPE a_MaxHeight, NIBBLETYPE a_Falloff);
|
||||||
~cClassicFluidSimulator();
|
~cClassicFluidSimulator();
|
||||||
|
|
||||||
// cSimulator overrides:
|
// cSimulator overrides:
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
cDelayedFluidSimulator::cDelayedFluidSimulator(cWorld * a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, int a_TickDelay) :
|
cDelayedFluidSimulator::cDelayedFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, int a_TickDelay) :
|
||||||
super(a_World, a_Fluid, a_StationaryFluid),
|
super(a_World, a_Fluid, a_StationaryFluid),
|
||||||
m_TickDelay(a_TickDelay),
|
m_TickDelay(a_TickDelay),
|
||||||
m_Slots(NULL),
|
m_Slots(NULL),
|
||||||
@ -45,7 +45,7 @@ void cDelayedFluidSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This can be optimized:
|
// TODO: This can be optimized:
|
||||||
BLOCKTYPE BlockType = m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
|
BLOCKTYPE BlockType = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ);
|
||||||
if (BlockType != m_FluidBlock)
|
if (BlockType != m_FluidBlock)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -21,7 +21,7 @@ class cDelayedFluidSimulator :
|
|||||||
typedef cFluidSimulator super;
|
typedef cFluidSimulator super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
cDelayedFluidSimulator(cWorld * a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, int a_TickDelay);
|
cDelayedFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, int a_TickDelay);
|
||||||
virtual ~cDelayedFluidSimulator();
|
virtual ~cDelayedFluidSimulator();
|
||||||
|
|
||||||
// cSimulator overrides:
|
// cSimulator overrides:
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
cFireSimulator::cFireSimulator( cWorld* a_World )
|
cFireSimulator::cFireSimulator(cWorld & a_World)
|
||||||
: cSimulator(a_World)
|
: cSimulator(a_World)
|
||||||
, m_Blocks(new BlockList)
|
, m_Blocks(new BlockList)
|
||||||
, m_Buffer(new BlockList)
|
, m_Buffer(new BlockList)
|
||||||
@ -33,30 +33,34 @@ cFireSimulator::~cFireSimulator()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cFireSimulator::Simulate( float a_Dt )
|
void cFireSimulator::Simulate(float a_Dt)
|
||||||
{
|
{
|
||||||
m_Buffer->clear();
|
m_Buffer->clear();
|
||||||
std::swap( m_Blocks, m_Buffer );
|
std::swap(m_Blocks, m_Buffer);
|
||||||
|
|
||||||
for( BlockList::iterator itr = m_Buffer->begin(); itr != m_Buffer->end(); ++itr )
|
for (BlockList::iterator itr = m_Buffer->begin(); itr != m_Buffer->end(); ++itr)
|
||||||
{
|
{
|
||||||
Vector3i Pos = *itr;
|
Vector3i Pos = *itr;
|
||||||
|
|
||||||
char BlockID = m_World->GetBlock(Pos.x, Pos.y, Pos.z);
|
BLOCKTYPE BlockID = m_World.GetBlock(Pos.x, Pos.y, Pos.z);
|
||||||
|
|
||||||
if(!IsAllowedBlock(BlockID)) //Check wheather the block is still burning
|
if (!IsAllowedBlock(BlockID)) // Check wheather the block is still burning
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (BurnBlockAround(Pos.x, Pos.y, Pos.z)) //Burn single block and if there was one -> next time again
|
if (BurnBlockAround(Pos.x, Pos.y, Pos.z)) //Burn single block and if there was one -> next time again
|
||||||
{
|
{
|
||||||
m_Blocks->push_back(Pos);
|
m_Blocks->push_back(Pos);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if(!IsForeverBurnable(m_World->GetBlock(Pos.x, Pos.y - 1, Pos.z)) && !FiresForever(BlockID))
|
{
|
||||||
m_World->SetBlock(Pos.x, Pos.y, Pos.z, E_BLOCK_AIR, 0);
|
if (!IsForeverBurnable(m_World.GetBlock(Pos.x, Pos.y - 1, Pos.z)) && !FiresForever(BlockID))
|
||||||
|
{
|
||||||
}
|
m_World.SetBlock(Pos.x, Pos.y, Pos.z, E_BLOCK_AIR, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // for itr - m_Buffer[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -75,7 +79,7 @@ bool cFireSimulator::IsAllowedBlock(BLOCKTYPE a_BlockType)
|
|||||||
void cFireSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk)
|
void cFireSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk)
|
||||||
{
|
{
|
||||||
// TODO: This can be optimized
|
// TODO: This can be optimized
|
||||||
BLOCKTYPE BlockType = m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
|
BLOCKTYPE BlockType = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ);
|
||||||
if (!IsAllowedBlock(BlockType))
|
if (!IsAllowedBlock(BlockType))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -148,18 +152,18 @@ bool cFireSimulator::BurnBlockAround(int a_X, int a_Y, int a_Z)
|
|||||||
|
|
||||||
bool cFireSimulator::BurnBlock(int a_X, int a_Y, int a_Z)
|
bool cFireSimulator::BurnBlock(int a_X, int a_Y, int a_Z)
|
||||||
{
|
{
|
||||||
char BlockID = m_World->GetBlock(a_X, a_Y, a_Z);
|
BLOCKTYPE BlockID = m_World.GetBlock(a_X, a_Y, a_Z);
|
||||||
if(IsBurnable(BlockID))
|
if (IsBurnable(BlockID))
|
||||||
{
|
{
|
||||||
m_World->SetBlock(a_X, a_Y, a_Z, E_BLOCK_FIRE, 0);
|
m_World.SetBlock(a_X, a_Y, a_Z, E_BLOCK_FIRE, 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(IsForeverBurnable(BlockID))
|
if (IsForeverBurnable(BlockID))
|
||||||
{
|
{
|
||||||
char BlockAbove = m_World->GetBlock(a_X, a_Y + 1, a_Z);
|
BLOCKTYPE BlockAbove = m_World.GetBlock(a_X, a_Y + 1, a_Z);
|
||||||
if(BlockAbove == E_BLOCK_AIR)
|
if (BlockAbove == E_BLOCK_AIR)
|
||||||
{
|
{
|
||||||
m_World->SetBlock(a_X, a_Y + 1, a_Z, E_BLOCK_FIRE, 0); //Doesn´t notify the simulator so it won´t go off
|
m_World.SetBlock(a_X, a_Y + 1, a_Z, E_BLOCK_FIRE, 0); //Doesn´t notify the simulator so it won´t go off
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
class cFireSimulator : public cSimulator
|
class cFireSimulator : public cSimulator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cFireSimulator( cWorld* a_World );
|
cFireSimulator(cWorld & a_World);
|
||||||
~cFireSimulator();
|
~cFireSimulator();
|
||||||
|
|
||||||
virtual void Simulate( float a_Dt ) override;
|
virtual void Simulate( float a_Dt ) override;
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
|
|
||||||
cFloodyFluidSimulator::cFloodyFluidSimulator(
|
cFloodyFluidSimulator::cFloodyFluidSimulator(
|
||||||
cWorld * a_World,
|
cWorld & a_World,
|
||||||
BLOCKTYPE a_Fluid,
|
BLOCKTYPE a_Fluid,
|
||||||
BLOCKTYPE a_StationaryFluid,
|
BLOCKTYPE a_StationaryFluid,
|
||||||
NIBBLETYPE a_Falloff,
|
NIBBLETYPE a_Falloff,
|
||||||
@ -51,7 +51,7 @@ void cFloodyFluidSimulator::SimulateBlock(int a_BlockX, int a_BlockY, int a_Bloc
|
|||||||
cBlockArea Area;
|
cBlockArea Area;
|
||||||
int MinBlockY = std::max(0, a_BlockY - 1);
|
int MinBlockY = std::max(0, a_BlockY - 1);
|
||||||
int MaxBlockY = std::min(+cChunkDef::Height, a_BlockY + 1);
|
int MaxBlockY = std::min(+cChunkDef::Height, a_BlockY + 1);
|
||||||
if (!Area.Read(m_World, a_BlockX - 1, a_BlockX + 1, MinBlockY, MaxBlockY, a_BlockZ - 1, a_BlockZ + 1))
|
if (!Area.Read(&m_World, a_BlockX - 1, a_BlockX + 1, MinBlockY, MaxBlockY, a_BlockZ - 1, a_BlockZ + 1))
|
||||||
{
|
{
|
||||||
// Cannot read the immediate neighborhood, probably too close to an unloaded chunk. Bail out.
|
// Cannot read the immediate neighborhood, probably too close to an unloaded chunk. Bail out.
|
||||||
// TODO: Shouldn't we re-schedule?
|
// TODO: Shouldn't we re-schedule?
|
||||||
@ -112,7 +112,7 @@ void cFloodyFluidSimulator::SimulateBlock(int a_BlockX, int a_BlockY, int a_Bloc
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mark as processed:
|
// Mark as processed:
|
||||||
m_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_StationaryFluidBlock, MyMeta);
|
m_World.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_StationaryFluidBlock, MyMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ bool cFloodyFluidSimulator::CheckTributaries(int a_BlockX, int a_BlockY, int a_B
|
|||||||
if (a_MyMeta >= 8)
|
if (a_MyMeta >= 8)
|
||||||
{
|
{
|
||||||
FLOG(" Not fed and downwards, turning into non-downwards meta %d", m_Falloff);
|
FLOG(" Not fed and downwards, turning into non-downwards meta %d", m_Falloff);
|
||||||
m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_StationaryFluidBlock, m_Falloff);
|
m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_StationaryFluidBlock, m_Falloff);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -155,12 +155,12 @@ bool cFloodyFluidSimulator::CheckTributaries(int a_BlockX, int a_BlockY, int a_B
|
|||||||
if (a_MyMeta < 8)
|
if (a_MyMeta < 8)
|
||||||
{
|
{
|
||||||
FLOG(" Not fed, decreasing from %d to %d", a_MyMeta, a_MyMeta + m_Falloff);
|
FLOG(" Not fed, decreasing from %d to %d", a_MyMeta, a_MyMeta + m_Falloff);
|
||||||
m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_StationaryFluidBlock, a_MyMeta);
|
m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_StationaryFluidBlock, a_MyMeta);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FLOG(" Not fed, meta %d, erasing altogether", a_MyMeta);
|
FLOG(" Not fed, meta %d, erasing altogether", a_MyMeta);
|
||||||
m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
|
m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -200,7 +200,7 @@ void cFloodyFluidSimulator::SpreadToNeighbor(int a_BlockX, int a_BlockY, int a_B
|
|||||||
a_BlockX, a_BlockY, a_BlockZ,
|
a_BlockX, a_BlockY, a_BlockZ,
|
||||||
ItemTypeToString(NewBlock).c_str()
|
ItemTypeToString(NewBlock).c_str()
|
||||||
);
|
);
|
||||||
m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, NewBlock, 0);
|
m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, NewBlock, 0);
|
||||||
|
|
||||||
// TODO: Sound effect
|
// TODO: Sound effect
|
||||||
|
|
||||||
@ -216,7 +216,7 @@ void cFloodyFluidSimulator::SpreadToNeighbor(int a_BlockX, int a_BlockY, int a_B
|
|||||||
FLOG(" Water flowing into lava, turning lava at {%d, %d, %d} into %s",
|
FLOG(" Water flowing into lava, turning lava at {%d, %d, %d} into %s",
|
||||||
a_BlockX, a_BlockY, a_BlockZ, ItemTypeToString(NewBlock).c_str()
|
a_BlockX, a_BlockY, a_BlockZ, ItemTypeToString(NewBlock).c_str()
|
||||||
);
|
);
|
||||||
m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, NewBlock, 0);
|
m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, NewBlock, 0);
|
||||||
|
|
||||||
// TODO: Sound effect
|
// TODO: Sound effect
|
||||||
|
|
||||||
@ -240,13 +240,13 @@ void cFloodyFluidSimulator::SpreadToNeighbor(int a_BlockX, int a_BlockY, int a_B
|
|||||||
cBlockHandler * Handler = BlockHandler(Block);
|
cBlockHandler * Handler = BlockHandler(Block);
|
||||||
if (Handler->DoesDropOnUnsuitable())
|
if (Handler->DoesDropOnUnsuitable())
|
||||||
{
|
{
|
||||||
Handler->DropBlock(m_World, NULL, a_BlockX, a_BlockY, a_BlockZ);
|
Handler->DropBlock(&m_World, NULL, a_BlockX, a_BlockY, a_BlockZ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spread:
|
// Spread:
|
||||||
FLOG(" Spreading to {%d, %d, %d} with meta %d", a_BlockX, a_BlockY, a_BlockZ, a_NewMeta);
|
FLOG(" Spreading to {%d, %d, %d} with meta %d", a_BlockX, a_BlockY, a_BlockZ, a_NewMeta);
|
||||||
m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_FluidBlock, a_NewMeta);
|
m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_FluidBlock, a_NewMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -283,7 +283,7 @@ bool cFloodyFluidSimulator::CheckNeighborsForSource(int a_BlockX, int a_BlockY,
|
|||||||
{
|
{
|
||||||
// Found enough, turn into a source and bail out
|
// Found enough, turn into a source and bail out
|
||||||
FLOG(" Found enough neighbor sources, turning into a source");
|
FLOG(" Found enough neighbor sources, turning into a source");
|
||||||
m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_FluidBlock, 0);
|
m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_FluidBlock, 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ class cFloodyFluidSimulator :
|
|||||||
typedef cDelayedFluidSimulator super;
|
typedef cDelayedFluidSimulator super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
cFloodyFluidSimulator(cWorld * a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, NIBBLETYPE a_Falloff, int a_TickDelay, int a_NumNeighborsForSource);
|
cFloodyFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, NIBBLETYPE a_Falloff, int a_TickDelay, int a_NumNeighborsForSource);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NIBBLETYPE m_Falloff;
|
NIBBLETYPE m_Falloff;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
cFluidSimulator::cFluidSimulator(cWorld * a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid) :
|
cFluidSimulator::cFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid) :
|
||||||
super(a_World),
|
super(a_World),
|
||||||
m_FluidBlock(a_Fluid),
|
m_FluidBlock(a_Fluid),
|
||||||
m_StationaryFluidBlock(a_StationaryFluid)
|
m_StationaryFluidBlock(a_StationaryFluid)
|
||||||
@ -119,7 +119,7 @@ bool cFluidSimulator::IsHigherMeta(NIBBLETYPE a_Meta1, NIBBLETYPE a_Meta2)
|
|||||||
// TODO Not working very well yet :s
|
// TODO Not working very well yet :s
|
||||||
Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a_Over)
|
Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a_Over)
|
||||||
{
|
{
|
||||||
char BlockID = m_World->GetBlock(a_X, a_Y, a_Z);
|
char BlockID = m_World.GetBlock(a_X, a_Y, a_Z);
|
||||||
if (!IsAllowedBlock(BlockID)) // No Fluid -> No Flowing direction :D
|
if (!IsAllowedBlock(BlockID)) // No Fluid -> No Flowing direction :D
|
||||||
{
|
{
|
||||||
return NONE;
|
return NONE;
|
||||||
@ -128,15 +128,15 @@ Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Disabled because of causing problems and being useless atm
|
Disabled because of causing problems and being useless atm
|
||||||
char BlockBelow = m_World->GetBlock(a_X, a_Y - 1, a_Z); //If there is nothing or fluid below it -> dominating flow is down :D
|
char BlockBelow = m_World.GetBlock(a_X, a_Y - 1, a_Z); //If there is nothing or fluid below it -> dominating flow is down :D
|
||||||
if (BlockBelow == E_BLOCK_AIR || IsAllowedBlock(BlockBelow))
|
if (BlockBelow == E_BLOCK_AIR || IsAllowedBlock(BlockBelow))
|
||||||
return Y_MINUS;
|
return Y_MINUS;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
NIBBLETYPE LowestPoint = m_World->GetBlockMeta(a_X, a_Y, a_Z); //Current Block Meta so only lower points will be counted
|
NIBBLETYPE LowestPoint = m_World.GetBlockMeta(a_X, a_Y, a_Z); //Current Block Meta so only lower points will be counted
|
||||||
int X = 0, Y = 0, Z = 0; //Lowest Pos will be stored here
|
int X = 0, Y = 0, Z = 0; //Lowest Pos will be stored here
|
||||||
|
|
||||||
if (IsAllowedBlock(m_World->GetBlock(a_X, a_Y + 1, a_Z)) && a_Over) //check for upper block to flow because this also affects the flowing direction
|
if (IsAllowedBlock(m_World.GetBlock(a_X, a_Y + 1, a_Z)) && a_Over) //check for upper block to flow because this also affects the flowing direction
|
||||||
{
|
{
|
||||||
return GetFlowingDirection(a_X, a_Y + 1, a_Z, false);
|
return GetFlowingDirection(a_X, a_Y + 1, a_Z, false);
|
||||||
}
|
}
|
||||||
@ -154,10 +154,10 @@ Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a
|
|||||||
for (std::vector<Vector3i *>::iterator it = Points.begin(); it < Points.end(); it++)
|
for (std::vector<Vector3i *>::iterator it = Points.begin(); it < Points.end(); it++)
|
||||||
{
|
{
|
||||||
Vector3i *Pos = (*it);
|
Vector3i *Pos = (*it);
|
||||||
char BlockID = m_World->GetBlock(Pos->x, Pos->y, Pos->z);
|
char BlockID = m_World.GetBlock(Pos->x, Pos->y, Pos->z);
|
||||||
if(IsAllowedBlock(BlockID))
|
if(IsAllowedBlock(BlockID))
|
||||||
{
|
{
|
||||||
char Meta = m_World->GetBlockMeta(Pos->x, Pos->y, Pos->z);
|
char Meta = m_World.GetBlockMeta(Pos->x, Pos->y, Pos->z);
|
||||||
|
|
||||||
if(Meta > LowestPoint)
|
if(Meta > LowestPoint)
|
||||||
{
|
{
|
||||||
@ -177,7 +177,7 @@ Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a
|
|||||||
delete Pos;
|
delete Pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LowestPoint == m_World->GetBlockMeta(a_X, a_Y, a_Z))
|
if (LowestPoint == m_World.GetBlockMeta(a_X, a_Y, a_Z))
|
||||||
return NONE;
|
return NONE;
|
||||||
|
|
||||||
if (a_X - X > 0)
|
if (a_X - X > 0)
|
||||||
|
@ -28,7 +28,7 @@ class cFluidSimulator :
|
|||||||
typedef cSimulator super;
|
typedef cSimulator super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
cFluidSimulator(cWorld * a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid);
|
cFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid);
|
||||||
|
|
||||||
// cSimulator overrides:
|
// cSimulator overrides:
|
||||||
virtual bool IsAllowedBlock(BLOCKTYPE a_BlockType) override;
|
virtual bool IsAllowedBlock(BLOCKTYPE a_BlockType) override;
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
cRedstoneSimulator::cRedstoneSimulator( cWorld* a_World )
|
cRedstoneSimulator::cRedstoneSimulator(cWorld & a_World )
|
||||||
: super(a_World)
|
: super(a_World)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -60,15 +60,15 @@ void cRedstoneSimulator::Simulate( float a_Dt )
|
|||||||
}
|
}
|
||||||
BLOCKTYPE BlockType;
|
BLOCKTYPE BlockType;
|
||||||
NIBBLETYPE BlockMeta;
|
NIBBLETYPE BlockMeta;
|
||||||
m_World->GetBlockTypeMeta(itr->Position.x, itr->Position.y, itr->Position.z, BlockType, BlockMeta);
|
m_World.GetBlockTypeMeta(itr->Position.x, itr->Position.y, itr->Position.z, BlockType, BlockMeta);
|
||||||
if (itr->bPowerOn && (BlockType == E_BLOCK_REDSTONE_REPEATER_OFF))
|
if (itr->bPowerOn && (BlockType == E_BLOCK_REDSTONE_REPEATER_OFF))
|
||||||
{
|
{
|
||||||
m_World->FastSetBlock(itr->Position.x, itr->Position.y, itr->Position.z, E_BLOCK_REDSTONE_REPEATER_ON, BlockMeta);
|
m_World.FastSetBlock(itr->Position.x, itr->Position.y, itr->Position.z, E_BLOCK_REDSTONE_REPEATER_ON, BlockMeta);
|
||||||
m_Blocks.push_back(itr->Position);
|
m_Blocks.push_back(itr->Position);
|
||||||
}
|
}
|
||||||
else if (!itr->bPowerOn && (BlockType == E_BLOCK_REDSTONE_REPEATER_ON))
|
else if (!itr->bPowerOn && (BlockType == E_BLOCK_REDSTONE_REPEATER_ON))
|
||||||
{
|
{
|
||||||
m_World->FastSetBlock(itr->Position.x, itr->Position.y, itr->Position.z, E_BLOCK_REDSTONE_REPEATER_OFF, BlockMeta);
|
m_World.FastSetBlock(itr->Position.x, itr->Position.y, itr->Position.z, E_BLOCK_REDSTONE_REPEATER_OFF, BlockMeta);
|
||||||
m_Blocks.push_back(itr->Position);
|
m_Blocks.push_back(itr->Position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,16 +116,16 @@ void cRedstoneSimulator::RefreshTorchesAround( const Vector3i & a_BlockPos )
|
|||||||
{
|
{
|
||||||
TargetBlockType = E_BLOCK_REDSTONE_TORCH_OFF;
|
TargetBlockType = E_BLOCK_REDSTONE_TORCH_OFF;
|
||||||
TargetRepeaterType = E_BLOCK_REDSTONE_REPEATER_ON;
|
TargetRepeaterType = E_BLOCK_REDSTONE_REPEATER_ON;
|
||||||
//if( m_World->GetBlock( a_BlockPos ) == E_BLOCK_DIRT )
|
//if( m_World.GetBlock( a_BlockPos ) == E_BLOCK_DIRT )
|
||||||
//{
|
//{
|
||||||
// m_World->FastSetBlock( a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, E_BLOCK_STONE, 0 );
|
// m_World.FastSetBlock( a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, E_BLOCK_STONE, 0 );
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//if( m_World->GetBlock( a_BlockPos ) == E_BLOCK_STONE )
|
//if( m_World.GetBlock( a_BlockPos ) == E_BLOCK_STONE )
|
||||||
//{
|
//{
|
||||||
// m_World->FastSetBlock( a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, E_BLOCK_DIRT, 0 );
|
// m_World.FastSetBlock( a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, E_BLOCK_DIRT, 0 );
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ void cRedstoneSimulator::RefreshTorchesAround( const Vector3i & a_BlockPos )
|
|||||||
Vector3i TorchPos = a_BlockPos + Surroundings[i];
|
Vector3i TorchPos = a_BlockPos + Surroundings[i];
|
||||||
BLOCKTYPE BlockType;
|
BLOCKTYPE BlockType;
|
||||||
NIBBLETYPE BlockMeta;
|
NIBBLETYPE BlockMeta;
|
||||||
m_World->GetBlockTypeMeta(TorchPos.x, TorchPos.y, TorchPos.z, BlockType, BlockMeta);
|
m_World.GetBlockTypeMeta(TorchPos.x, TorchPos.y, TorchPos.z, BlockType, BlockMeta);
|
||||||
switch (BlockType)
|
switch (BlockType)
|
||||||
{
|
{
|
||||||
case E_BLOCK_REDSTONE_TORCH_ON:
|
case E_BLOCK_REDSTONE_TORCH_ON:
|
||||||
@ -144,7 +144,7 @@ void cRedstoneSimulator::RefreshTorchesAround( const Vector3i & a_BlockPos )
|
|||||||
{
|
{
|
||||||
if (cTorch::IsAttachedTo(TorchPos, BlockMeta, a_BlockPos))
|
if (cTorch::IsAttachedTo(TorchPos, BlockMeta, a_BlockPos))
|
||||||
{
|
{
|
||||||
m_World->FastSetBlock(TorchPos.x, TorchPos.y, TorchPos.z, TargetBlockType, BlockMeta);
|
m_World.FastSetBlock(TorchPos.x, TorchPos.y, TorchPos.z, TargetBlockType, BlockMeta);
|
||||||
m_Blocks.push_back(TorchPos);
|
m_Blocks.push_back(TorchPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -189,7 +189,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos )
|
|||||||
|
|
||||||
BLOCKTYPE BlockType;
|
BLOCKTYPE BlockType;
|
||||||
NIBBLETYPE BlockMeta;
|
NIBBLETYPE BlockMeta;
|
||||||
m_World->GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta);
|
m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta);
|
||||||
|
|
||||||
// First check whether torch should be on or off
|
// First check whether torch should be on or off
|
||||||
switch (BlockType)
|
switch (BlockType)
|
||||||
@ -207,7 +207,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos )
|
|||||||
for( unsigned int i = 0; i < ARRAYCOUNT( Surroundings ); ++i )
|
for( unsigned int i = 0; i < ARRAYCOUNT( Surroundings ); ++i )
|
||||||
{
|
{
|
||||||
Vector3i pos = a_BlockPos + Surroundings[i];
|
Vector3i pos = a_BlockPos + Surroundings[i];
|
||||||
BLOCKTYPE OtherBlock = m_World->GetBlock( pos );
|
BLOCKTYPE OtherBlock = m_World.GetBlock( pos );
|
||||||
if (
|
if (
|
||||||
(OtherBlock != E_BLOCK_AIR) &&
|
(OtherBlock != E_BLOCK_AIR) &&
|
||||||
(OtherBlock != E_BLOCK_REDSTONE_TORCH_ON) &&
|
(OtherBlock != E_BLOCK_REDSTONE_TORCH_ON) &&
|
||||||
@ -217,7 +217,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos )
|
|||||||
RefreshTorchesAround( pos );
|
RefreshTorchesAround( pos );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_World->GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta);
|
m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta);
|
||||||
break;
|
break;
|
||||||
} // case "torches"
|
} // case "torches"
|
||||||
|
|
||||||
@ -227,7 +227,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos )
|
|||||||
// Check if repeater is powered by a 'powered block' (not wires/torch)
|
// Check if repeater is powered by a 'powered block' (not wires/torch)
|
||||||
Vector3i Direction = GetRepeaterDirection(BlockMeta);
|
Vector3i Direction = GetRepeaterDirection(BlockMeta);
|
||||||
Vector3i pos = a_BlockPos - Direction; // NOTE: It's minus Direction
|
Vector3i pos = a_BlockPos - Direction; // NOTE: It's minus Direction
|
||||||
BLOCKTYPE OtherBlock = m_World->GetBlock(pos);
|
BLOCKTYPE OtherBlock = m_World.GetBlock(pos);
|
||||||
if (
|
if (
|
||||||
(OtherBlock != E_BLOCK_AIR) &&
|
(OtherBlock != E_BLOCK_AIR) &&
|
||||||
(OtherBlock != E_BLOCK_REDSTONE_TORCH_ON) &&
|
(OtherBlock != E_BLOCK_REDSTONE_TORCH_ON) &&
|
||||||
@ -241,7 +241,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos )
|
|||||||
{
|
{
|
||||||
SetRepeater(a_BlockPos, 10, IsPowered(a_BlockPos, false));
|
SetRepeater(a_BlockPos, 10, IsPowered(a_BlockPos, false));
|
||||||
}
|
}
|
||||||
m_World->GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta);
|
m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} // switch (BlockType)
|
} // switch (BlockType)
|
||||||
@ -298,7 +298,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos )
|
|||||||
|
|
||||||
BLOCKTYPE BlockType;
|
BLOCKTYPE BlockType;
|
||||||
NIBBLETYPE BlockMeta;
|
NIBBLETYPE BlockMeta;
|
||||||
m_World->GetBlockTypeMeta(SourcePos.x, SourcePos.y, SourcePos.z, BlockType, BlockMeta);
|
m_World.GetBlockTypeMeta(SourcePos.x, SourcePos.y, SourcePos.z, BlockType, BlockMeta);
|
||||||
switch (BlockType)
|
switch (BlockType)
|
||||||
{
|
{
|
||||||
case E_BLOCK_LEVER: // Treating lever as a torch
|
case E_BLOCK_LEVER: // Treating lever as a torch
|
||||||
@ -349,7 +349,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos )
|
|||||||
{
|
{
|
||||||
Vector3i pos = SpreadStack.back();
|
Vector3i pos = SpreadStack.back();
|
||||||
SpreadStack.pop_back();
|
SpreadStack.pop_back();
|
||||||
NIBBLETYPE Meta = m_World->GetBlockMeta(pos);
|
NIBBLETYPE Meta = m_World.GetBlockMeta(pos);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < ARRAYCOUNT(Surroundings); ++i)
|
for (unsigned int i = 0; i < ARRAYCOUNT(Surroundings); ++i)
|
||||||
{
|
{
|
||||||
@ -367,7 +367,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos )
|
|||||||
Vector3i pos = m_RefreshPistons.back();
|
Vector3i pos = m_RefreshPistons.back();
|
||||||
m_RefreshPistons.pop_back();
|
m_RefreshPistons.pop_back();
|
||||||
|
|
||||||
BLOCKTYPE BlockType = m_World->GetBlock(pos);
|
BLOCKTYPE BlockType = m_World.GetBlock(pos);
|
||||||
switch (BlockType)
|
switch (BlockType)
|
||||||
{
|
{
|
||||||
case E_BLOCK_PISTON:
|
case E_BLOCK_PISTON:
|
||||||
@ -375,12 +375,12 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos )
|
|||||||
{
|
{
|
||||||
if (IsPowered(pos))
|
if (IsPowered(pos))
|
||||||
{
|
{
|
||||||
cPiston Piston(m_World);
|
cPiston Piston(&m_World);
|
||||||
Piston.ExtendPiston(pos.x, pos.y, pos.z);
|
Piston.ExtendPiston(pos.x, pos.y, pos.z);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cPiston Piston(m_World);
|
cPiston Piston(&m_World);
|
||||||
Piston.RetractPiston(pos.x, pos.y, pos.z);
|
Piston.RetractPiston(pos.x, pos.y, pos.z);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -393,7 +393,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos )
|
|||||||
Vector3i pos = m_RefreshDispensers.back();
|
Vector3i pos = m_RefreshDispensers.back();
|
||||||
m_RefreshDispensers.pop_back();
|
m_RefreshDispensers.pop_back();
|
||||||
|
|
||||||
BLOCKTYPE BlockType = m_World->GetBlock(pos);
|
BLOCKTYPE BlockType = m_World.GetBlock(pos);
|
||||||
if (BlockType == E_BLOCK_DISPENSER)
|
if (BlockType == E_BLOCK_DISPENSER)
|
||||||
{
|
{
|
||||||
if (IsPowered(pos))
|
if (IsPowered(pos))
|
||||||
@ -413,7 +413,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos )
|
|||||||
}
|
}
|
||||||
} ;
|
} ;
|
||||||
cActivateDispenser DispAct;
|
cActivateDispenser DispAct;
|
||||||
m_World->DoWithDispenserAt(pos.x, pos.y, pos.z, DispAct);
|
m_World.DoWithDispenserAt(pos.x, pos.y, pos.z, DispAct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -427,14 +427,14 @@ bool cRedstoneSimulator::PowerBlock(const Vector3i & a_BlockPos, const Vector3i
|
|||||||
{
|
{
|
||||||
BLOCKTYPE BlockType;
|
BLOCKTYPE BlockType;
|
||||||
NIBBLETYPE BlockMeta;
|
NIBBLETYPE BlockMeta;
|
||||||
m_World->GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta);
|
m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta);
|
||||||
switch (BlockType)
|
switch (BlockType)
|
||||||
{
|
{
|
||||||
case E_BLOCK_REDSTONE_WIRE:
|
case E_BLOCK_REDSTONE_WIRE:
|
||||||
{
|
{
|
||||||
if (BlockMeta < a_Power)
|
if (BlockMeta < a_Power)
|
||||||
{
|
{
|
||||||
m_World->SetBlockMeta(a_BlockPos, a_Power);
|
m_World.SetBlockMeta(a_BlockPos, a_Power);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -496,14 +496,14 @@ int cRedstoneSimulator::UnPowerBlock( const Vector3i & a_BlockPos, const Vector3
|
|||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
m_World->GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta);
|
m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta);
|
||||||
switch (BlockType)
|
switch (BlockType)
|
||||||
{
|
{
|
||||||
case E_BLOCK_REDSTONE_WIRE:
|
case E_BLOCK_REDSTONE_WIRE:
|
||||||
{
|
{
|
||||||
if (BlockMeta > 0 )
|
if (BlockMeta > 0 )
|
||||||
{
|
{
|
||||||
m_World->SetBlockMeta(a_BlockPos, 0);
|
m_World.SetBlockMeta(a_BlockPos, 0);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -609,7 +609,7 @@ cRedstoneSimulator::BlockList cRedstoneSimulator::RemoveCurrent( const Vector3i
|
|||||||
|
|
||||||
BLOCKTYPE BlockType;
|
BLOCKTYPE BlockType;
|
||||||
NIBBLETYPE BlockMeta;
|
NIBBLETYPE BlockMeta;
|
||||||
m_World->GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta);
|
m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta);
|
||||||
switch (BlockType)
|
switch (BlockType)
|
||||||
{
|
{
|
||||||
case E_BLOCK_REDSTONE_REPEATER_ON:
|
case E_BLOCK_REDSTONE_REPEATER_ON:
|
||||||
@ -704,7 +704,7 @@ bool cRedstoneSimulator::IsPowering(const Vector3i & a_PowerPos, const Vector3i
|
|||||||
{
|
{
|
||||||
BLOCKTYPE PowerBlock;
|
BLOCKTYPE PowerBlock;
|
||||||
NIBBLETYPE PowerMeta;
|
NIBBLETYPE PowerMeta;
|
||||||
m_World->GetBlockTypeMeta(a_PowerPos.x, a_PowerPos.y, a_PowerPos.z, PowerBlock, PowerMeta);
|
m_World.GetBlockTypeMeta(a_PowerPos.x, a_PowerPos.y, a_PowerPos.z, PowerBlock, PowerMeta);
|
||||||
|
|
||||||
// Filter out powering blocks for a_bOnlyByWire
|
// Filter out powering blocks for a_bOnlyByWire
|
||||||
if (
|
if (
|
||||||
@ -753,13 +753,13 @@ bool cRedstoneSimulator::IsPowered( const Vector3i & a_BlockPos, bool a_bOnlyByW
|
|||||||
{
|
{
|
||||||
BLOCKTYPE BlockType;
|
BLOCKTYPE BlockType;
|
||||||
NIBBLETYPE BlockMeta;
|
NIBBLETYPE BlockMeta;
|
||||||
m_World->GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta);
|
m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta);
|
||||||
if ((BlockType == E_BLOCK_REDSTONE_REPEATER_OFF) || (BlockType == E_BLOCK_REDSTONE_REPEATER_ON))
|
if ((BlockType == E_BLOCK_REDSTONE_REPEATER_OFF) || (BlockType == E_BLOCK_REDSTONE_REPEATER_ON))
|
||||||
{
|
{
|
||||||
Vector3i Behind = a_BlockPos - GetRepeaterDirection(BlockMeta);
|
Vector3i Behind = a_BlockPos - GetRepeaterDirection(BlockMeta);
|
||||||
BLOCKTYPE BehindBlock;
|
BLOCKTYPE BehindBlock;
|
||||||
NIBBLETYPE BehindMeta;
|
NIBBLETYPE BehindMeta;
|
||||||
m_World->GetBlockTypeMeta(Behind.x, Behind.y, Behind.z, BehindBlock, BehindMeta);
|
m_World.GetBlockTypeMeta(Behind.x, Behind.y, Behind.z, BehindBlock, BehindMeta);
|
||||||
switch (BehindBlock)
|
switch (BehindBlock)
|
||||||
{
|
{
|
||||||
case E_BLOCK_REDSTONE_TORCH_ON:
|
case E_BLOCK_REDSTONE_TORCH_ON:
|
||||||
@ -800,7 +800,7 @@ bool cRedstoneSimulator::IsPowered( const Vector3i & a_BlockPos, bool a_bOnlyByW
|
|||||||
// Only wires can power the bottom block
|
// Only wires can power the bottom block
|
||||||
BLOCKTYPE PosYType;
|
BLOCKTYPE PosYType;
|
||||||
NIBBLETYPE PosYMeta;
|
NIBBLETYPE PosYMeta;
|
||||||
m_World->GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y + 1, a_BlockPos.z, PosYType, PosYMeta);
|
m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y + 1, a_BlockPos.z, PosYType, PosYMeta);
|
||||||
if (PosYType == E_BLOCK_REDSTONE_WIRE)
|
if (PosYType == E_BLOCK_REDSTONE_WIRE)
|
||||||
{
|
{
|
||||||
return (PosYMeta > 0);
|
return (PosYMeta > 0);
|
||||||
@ -817,7 +817,7 @@ cRedstoneSimulator::eRedstoneDirection cRedstoneSimulator::GetWireDirection(int
|
|||||||
{
|
{
|
||||||
int Dir = REDSTONE_NONE;
|
int Dir = REDSTONE_NONE;
|
||||||
|
|
||||||
BLOCKTYPE NegX = m_World->GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ);
|
BLOCKTYPE NegX = m_World.GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ);
|
||||||
if (
|
if (
|
||||||
(NegX == E_BLOCK_REDSTONE_WIRE) ||
|
(NegX == E_BLOCK_REDSTONE_WIRE) ||
|
||||||
(NegX == E_BLOCK_REDSTONE_TORCH_ON) ||
|
(NegX == E_BLOCK_REDSTONE_TORCH_ON) ||
|
||||||
@ -827,7 +827,7 @@ cRedstoneSimulator::eRedstoneDirection cRedstoneSimulator::GetWireDirection(int
|
|||||||
Dir |= (REDSTONE_X_POS);
|
Dir |= (REDSTONE_X_POS);
|
||||||
}
|
}
|
||||||
|
|
||||||
BLOCKTYPE PosX = m_World->GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ);
|
BLOCKTYPE PosX = m_World.GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ);
|
||||||
if (
|
if (
|
||||||
(PosX == E_BLOCK_REDSTONE_WIRE) ||
|
(PosX == E_BLOCK_REDSTONE_WIRE) ||
|
||||||
(PosX == E_BLOCK_REDSTONE_TORCH_ON) ||
|
(PosX == E_BLOCK_REDSTONE_TORCH_ON) ||
|
||||||
@ -837,7 +837,7 @@ cRedstoneSimulator::eRedstoneDirection cRedstoneSimulator::GetWireDirection(int
|
|||||||
Dir |= (REDSTONE_X_NEG);
|
Dir |= (REDSTONE_X_NEG);
|
||||||
}
|
}
|
||||||
|
|
||||||
BLOCKTYPE NegZ = m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ - 1);
|
BLOCKTYPE NegZ = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ - 1);
|
||||||
if (
|
if (
|
||||||
(NegZ == E_BLOCK_REDSTONE_WIRE) ||
|
(NegZ == E_BLOCK_REDSTONE_WIRE) ||
|
||||||
(NegZ == E_BLOCK_REDSTONE_TORCH_ON) ||
|
(NegZ == E_BLOCK_REDSTONE_TORCH_ON) ||
|
||||||
@ -857,7 +857,7 @@ cRedstoneSimulator::eRedstoneDirection cRedstoneSimulator::GetWireDirection(int
|
|||||||
Dir |= REDSTONE_Z_POS;
|
Dir |= REDSTONE_Z_POS;
|
||||||
}
|
}
|
||||||
|
|
||||||
BLOCKTYPE PosZ = m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1);
|
BLOCKTYPE PosZ = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1);
|
||||||
if (
|
if (
|
||||||
(PosZ == E_BLOCK_REDSTONE_WIRE) ||
|
(PosZ == E_BLOCK_REDSTONE_WIRE) ||
|
||||||
(PosZ == E_BLOCK_REDSTONE_TORCH_ON) ||
|
(PosZ == E_BLOCK_REDSTONE_TORCH_ON) ||
|
||||||
|
@ -12,7 +12,7 @@ class cRedstoneSimulator :
|
|||||||
{
|
{
|
||||||
typedef cSimulator super;
|
typedef cSimulator super;
|
||||||
public:
|
public:
|
||||||
cRedstoneSimulator( cWorld* a_World );
|
cRedstoneSimulator(cWorld & a_World);
|
||||||
~cRedstoneSimulator();
|
~cRedstoneSimulator();
|
||||||
|
|
||||||
virtual void Simulate( float a_Dt ) override;
|
virtual void Simulate( float a_Dt ) override;
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
cSandSimulator::cSandSimulator( cWorld* a_World )
|
cSandSimulator::cSandSimulator(cWorld & a_World)
|
||||||
: cSimulator(a_World)
|
: cSimulator(a_World)
|
||||||
, m_Blocks(new BlockList)
|
, m_Blocks(new BlockList)
|
||||||
, m_Buffer(new BlockList)
|
, m_Buffer(new BlockList)
|
||||||
@ -34,7 +34,7 @@ cSandSimulator::~cSandSimulator()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cSandSimulator::Simulate( float a_Dt )
|
void cSandSimulator::Simulate(float a_Dt)
|
||||||
{
|
{
|
||||||
m_Buffer->clear();
|
m_Buffer->clear();
|
||||||
std::swap( m_Blocks, m_Buffer );
|
std::swap( m_Blocks, m_Buffer );
|
||||||
@ -42,17 +42,17 @@ void cSandSimulator::Simulate( float a_Dt )
|
|||||||
for( BlockList::iterator itr = m_Buffer->begin(); itr != m_Buffer->end(); ++itr )
|
for( BlockList::iterator itr = m_Buffer->begin(); itr != m_Buffer->end(); ++itr )
|
||||||
{
|
{
|
||||||
Vector3i Pos = *itr;
|
Vector3i Pos = *itr;
|
||||||
BLOCKTYPE BlockID = m_World->GetBlock(Pos.x, Pos.y, Pos.z);
|
BLOCKTYPE BlockID = m_World.GetBlock(Pos.x, Pos.y, Pos.z);
|
||||||
if(!IsAllowedBlock(BlockID))
|
if(!IsAllowedBlock(BlockID))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
BLOCKTYPE BottomBlock = m_World->GetBlock( Pos.x, Pos.y - 1, Pos.z );
|
BLOCKTYPE BottomBlock = m_World.GetBlock( Pos.x, Pos.y - 1, Pos.z );
|
||||||
|
|
||||||
if( IsPassable(BottomBlock) )
|
if( IsPassable(BottomBlock) )
|
||||||
{
|
{
|
||||||
cFallingBlock * FallingBlock = new cFallingBlock( Pos, BlockID );
|
cFallingBlock * FallingBlock = new cFallingBlock(Pos, BlockID);
|
||||||
FallingBlock->Initialize( m_World );
|
FallingBlock->Initialize(&m_World);
|
||||||
m_World->SetBlock( Pos.x, Pos.y, Pos.z, E_BLOCK_AIR, 0 );
|
m_World.SetBlock( Pos.x, Pos.y, Pos.z, E_BLOCK_AIR, 0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
class cSandSimulator : public cSimulator
|
class cSandSimulator : public cSimulator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cSandSimulator( cWorld* a_World );
|
cSandSimulator(cWorld & a_World);
|
||||||
~cSandSimulator();
|
~cSandSimulator();
|
||||||
|
|
||||||
virtual void Simulate( float a_Dt ) override;
|
virtual void Simulate( float a_Dt ) override;
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
cSimulator::cSimulator( cWorld* a_World )
|
cSimulator::cSimulator(cWorld & a_World)
|
||||||
: m_World(a_World)
|
: m_World(a_World)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,15 @@ class cChunk;
|
|||||||
class cSimulator
|
class cSimulator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cSimulator(cWorld * a_World);
|
cSimulator(cWorld & a_World);
|
||||||
virtual ~cSimulator();
|
virtual ~cSimulator();
|
||||||
|
|
||||||
/// Called in each tick, a_Dt is the time passed since the last tick, in msec
|
/// Called in each tick, a_Dt is the time passed since the last tick, in msec
|
||||||
virtual void Simulate(float a_Dt) = 0;
|
virtual void Simulate(float a_Dt) = 0;
|
||||||
|
|
||||||
|
/// Called in each tick for each chunk, a_Dt is the time passed since the last tick, in msec; direct access to chunk data available
|
||||||
|
virtual void SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) {};
|
||||||
|
|
||||||
/// Called when a block changes
|
/// Called when a block changes
|
||||||
virtual void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk);
|
virtual void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk);
|
||||||
|
|
||||||
@ -32,7 +35,7 @@ protected:
|
|||||||
/// Called to simulate a new block
|
/// Called to simulate a new block
|
||||||
virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) = 0;
|
virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) = 0;
|
||||||
|
|
||||||
cWorld * m_World;
|
cWorld & m_World;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,12 +2,14 @@
|
|||||||
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
||||||
|
|
||||||
#include "SimulatorManager.h"
|
#include "SimulatorManager.h"
|
||||||
|
#include "../World.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cSimulatorManager::cSimulatorManager(void) :
|
cSimulatorManager::cSimulatorManager(cWorld & a_World) :
|
||||||
|
m_World(a_World),
|
||||||
m_Ticks(0)
|
m_Ticks(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -24,7 +26,7 @@ cSimulatorManager::~cSimulatorManager()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cSimulatorManager::Simulate( float a_Dt )
|
void cSimulatorManager::Simulate(float a_Dt)
|
||||||
{
|
{
|
||||||
m_Ticks++;
|
m_Ticks++;
|
||||||
for (cSimulators::iterator itr = m_Simulators.begin(); itr != m_Simulators.end(); ++itr )
|
for (cSimulators::iterator itr = m_Simulators.begin(); itr != m_Simulators.end(); ++itr )
|
||||||
@ -40,6 +42,22 @@ void cSimulatorManager::Simulate( float a_Dt )
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cSimulatorManager::SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk)
|
||||||
|
{
|
||||||
|
// m_Ticks has already been increased in Simulate()
|
||||||
|
for (cSimulators::iterator itr = m_Simulators.begin(); itr != m_Simulators.end(); ++itr )
|
||||||
|
{
|
||||||
|
if ((m_Ticks % itr->second) == 0)
|
||||||
|
{
|
||||||
|
itr->first->SimulateChunk(a_Dt, a_ChunkX, a_ChunkZ, a_Chunk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cSimulatorManager::WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk)
|
void cSimulatorManager::WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk)
|
||||||
{
|
{
|
||||||
for (cSimulators::iterator itr = m_Simulators.begin(); itr != m_Simulators.end(); ++itr )
|
for (cSimulators::iterator itr = m_Simulators.begin(); itr != m_Simulators.end(); ++itr )
|
||||||
|
@ -18,6 +18,9 @@
|
|||||||
// fwd: Chunk.h
|
// fwd: Chunk.h
|
||||||
class cChunk;
|
class cChunk;
|
||||||
|
|
||||||
|
// fwd: World.h
|
||||||
|
class cWorld;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -25,18 +28,21 @@ class cChunk;
|
|||||||
class cSimulatorManager
|
class cSimulatorManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cSimulatorManager(void);
|
cSimulatorManager(cWorld & a_World);
|
||||||
~cSimulatorManager();
|
~cSimulatorManager();
|
||||||
|
|
||||||
void Simulate(float a_Dt);
|
void Simulate(float a_Dt);
|
||||||
|
|
||||||
|
void SimulateChunk(float a_DT, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk);
|
||||||
|
|
||||||
void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk);
|
void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk);
|
||||||
|
|
||||||
void RegisterSimulator(cSimulator * a_Simulator, int a_Rate); // Takes ownership of the simulator object!
|
void RegisterSimulator(cSimulator * a_Simulator, int a_Rate); // Takes ownership of the simulator object!
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
typedef std::vector <std::pair<cSimulator *, int> > cSimulators;
|
typedef std::vector <std::pair<cSimulator *, int> > cSimulators;
|
||||||
|
|
||||||
|
cWorld & m_World;
|
||||||
cSimulators m_Simulators;
|
cSimulators m_Simulators;
|
||||||
long long m_Ticks;
|
long long m_Ticks;
|
||||||
};
|
};
|
||||||
|
@ -250,12 +250,12 @@ cWorld::cWorld(const AString & a_WorldName) :
|
|||||||
m_BlockTickQueueCopy.reserve(1000);
|
m_BlockTickQueueCopy.reserve(1000);
|
||||||
|
|
||||||
// Simulators:
|
// Simulators:
|
||||||
m_SimulatorManager = new cSimulatorManager();
|
m_SimulatorManager = new cSimulatorManager(*this);
|
||||||
m_WaterSimulator = InitializeFluidSimulator(IniFile, "Water", E_BLOCK_WATER, E_BLOCK_STATIONARY_WATER);
|
m_WaterSimulator = InitializeFluidSimulator(IniFile, "Water", E_BLOCK_WATER, E_BLOCK_STATIONARY_WATER);
|
||||||
m_LavaSimulator = InitializeFluidSimulator(IniFile, "Lava", E_BLOCK_LAVA, E_BLOCK_STATIONARY_LAVA);
|
m_LavaSimulator = InitializeFluidSimulator(IniFile, "Lava", E_BLOCK_LAVA, E_BLOCK_STATIONARY_LAVA);
|
||||||
m_SandSimulator = new cSandSimulator(this);
|
m_SandSimulator = new cSandSimulator(*this);
|
||||||
m_FireSimulator = new cFireSimulator(this);
|
m_FireSimulator = new cFireSimulator(*this);
|
||||||
m_RedstoneSimulator = new cRedstoneSimulator(this);
|
m_RedstoneSimulator = new cRedstoneSimulator(*this);
|
||||||
|
|
||||||
// Water and Lava simulators get registered in InitializeFluidSimulator()
|
// Water and Lava simulators get registered in InitializeFluidSimulator()
|
||||||
m_SimulatorManager->RegisterSimulator(m_SandSimulator, 1);
|
m_SimulatorManager->RegisterSimulator(m_SandSimulator, 1);
|
||||||
@ -2217,7 +2217,7 @@ cFluidSimulator * cWorld::InitializeFluidSimulator(cIniFile & a_IniFile, const c
|
|||||||
int Falloff = a_IniFile.GetValueSetI(SimulatorSectionName, "Falloff", IsWater ? 1 : 2);
|
int Falloff = a_IniFile.GetValueSetI(SimulatorSectionName, "Falloff", IsWater ? 1 : 2);
|
||||||
int TickDelay = a_IniFile.GetValueSetI(SimulatorSectionName, "TickDelay", IsWater ? 5 : 30);
|
int TickDelay = a_IniFile.GetValueSetI(SimulatorSectionName, "TickDelay", IsWater ? 5 : 30);
|
||||||
int NumNeighborsForSource = a_IniFile.GetValueSetI(SimulatorSectionName, "NumNeighborsForSource", IsWater ? 2 : -1);
|
int NumNeighborsForSource = a_IniFile.GetValueSetI(SimulatorSectionName, "NumNeighborsForSource", IsWater ? 2 : -1);
|
||||||
res = new cFloodyFluidSimulator(this, a_SimulateBlock, a_StationaryBlock, Falloff, TickDelay, NumNeighborsForSource);
|
res = new cFloodyFluidSimulator(*this, a_SimulateBlock, a_StationaryBlock, Falloff, TickDelay, NumNeighborsForSource);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2230,7 +2230,7 @@ cFluidSimulator * cWorld::InitializeFluidSimulator(cIniFile & a_IniFile, const c
|
|||||||
int DefaultMaxHeight = IsWater ? 7 : 6;
|
int DefaultMaxHeight = IsWater ? 7 : 6;
|
||||||
int Falloff = a_IniFile.GetValueSetI(SimulatorSectionName, "Falloff", DefaultFalloff);
|
int Falloff = a_IniFile.GetValueSetI(SimulatorSectionName, "Falloff", DefaultFalloff);
|
||||||
int MaxHeight = a_IniFile.GetValueSetI(SimulatorSectionName, "MaxHeight", DefaultMaxHeight);
|
int MaxHeight = a_IniFile.GetValueSetI(SimulatorSectionName, "MaxHeight", DefaultMaxHeight);
|
||||||
res = new cClassicFluidSimulator(this, a_SimulateBlock, a_StationaryBlock, MaxHeight, Falloff);
|
res = new cClassicFluidSimulator(*this, a_SimulateBlock, a_StationaryBlock, MaxHeight, Falloff);
|
||||||
Rate = IsWater ? 6 : 12;
|
Rate = IsWater ? 6 : 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user