1
0
Fork 0

Fixed DelayedFluidSimulator.

Floody fluid simulator is now woken up properly across chunk borders.

git-svn-id: http://mc-server.googlecode.com/svn/trunk@966 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2012-10-15 20:16:43 +00:00
parent 164f0e7de9
commit f9dab57d8b
4 changed files with 22 additions and 12 deletions

View File

@ -955,7 +955,7 @@ void cChunk::CheckNeighbors(int a_RelX, int a_RelY, int a_RelZ)
{
int BlockX = m_PosX * cChunkDef::Width + a_RelX;
int BlockZ = m_PosZ * cChunkDef::Width + a_RelZ;
if (a_RelX < cChunkDef::Width)
if (a_RelX < cChunkDef::Width - 1)
{
m_ToTickBlocks.push_back(MakeIndexNoCheck(a_RelX + 1, a_RelY, a_RelZ));
}

View File

@ -17,7 +17,7 @@ cDelayedFluidSimulator::cDelayedFluidSimulator(cWorld * a_World, BLOCKTYPE a_Flu
super(a_World, a_Fluid, a_StationaryFluid),
m_TickDelay(a_TickDelay),
m_Slots(NULL),
m_CurrentSlotNum(a_TickDelay - 1)
m_CurrentSlotNum(0)
{
m_Slots = new CoordsArray[a_TickDelay];
}
@ -70,21 +70,22 @@ void cDelayedFluidSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ)
void cDelayedFluidSimulator::Simulate(float a_Dt)
{
CoordsArray & Blocks = m_Slots[m_CurrentSlotNum];
// First move to the next slot, so that simulated blocks can write another batch of scheduled blocks:
m_CurrentSlotNum += 1;
if (m_CurrentSlotNum >= m_TickDelay)
int SlotNum = m_CurrentSlotNum + 1;
if (SlotNum >= m_TickDelay)
{
m_CurrentSlotNum = 0;
SlotNum = 0;
}
CoordsArray & Blocks = m_Slots[SlotNum];
// Simulate the blocks in the scheduled slot:
for (CoordsArray::iterator itr = Blocks.begin(), end = Blocks.end(); itr != end; ++itr)
{
SimulateBlock(itr->x, itr->y, itr->z);
}
Blocks.clear();
m_CurrentSlotNum = SlotNum;
}

View File

@ -34,7 +34,13 @@ protected:
int m_TickDelay; // Count of the m_Slots array
CoordsArray * m_Slots; // Slots, one for each delay tick
int m_CurrentSlotNum; // Index into m_Slots[] where to insert new blocks
/*
Slots:
| 0 | 1 | ... | m_CurrentSlotNum | m_CurrentSlotNum + 1 | ... | m_TickDelay - 1 |
adding blocks here ^ | ^ simulating here
*/
/// Called from Simulate() to simulate each block in one slot of blocks. Descendants override this method to provide custom simulation.
virtual void SimulateBlock(int a_BlockX, int a_BlockY, int a_BlockZ) = 0;
} ;

View File

@ -287,15 +287,14 @@ cWorld::cWorld( const AString & a_WorldName )
m_BlockTickQueueCopy.reserve(1000);
// Simulators:
m_SimulatorManager = new cSimulatorManager();
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_SandSimulator = new cSandSimulator(this);
m_FireSimulator = new cFireSimulator(this);
m_RedstoneSimulator = new cRedstoneSimulator(this);
m_SimulatorManager = new cSimulatorManager();
m_SimulatorManager->RegisterSimulator(m_WaterSimulator, 6);
m_SimulatorManager->RegisterSimulator(m_LavaSimulator, 12);
// Water and Lava simulators get registered in InitializeFluidSimulator()
m_SimulatorManager->RegisterSimulator(m_SandSimulator, 1);
m_SimulatorManager->RegisterSimulator(m_FireSimulator, 10);
m_SimulatorManager->RegisterSimulator(m_RedstoneSimulator, 1);
@ -2172,6 +2171,7 @@ cFluidSimulator * cWorld::InitializeFluidSimulator(cIniFile & a_IniFile, const c
cFluidSimulator * res = NULL;
bool IsWater = (strcmp(a_FluidName, "Water") == 0); // Used for defaults
int Rate = 1;
if (NoCaseCompare(SimulatorName, "floody") == 0)
{
int DefaultFalloff = IsWater ? 1 : 2;
@ -2192,8 +2192,11 @@ cFluidSimulator * cWorld::InitializeFluidSimulator(cIniFile & a_IniFile, const c
int Falloff = a_IniFile.GetValueSetI(SimulatorSectionName, "Falloff", DefaultFalloff);
int MaxHeight = a_IniFile.GetValueSetI(SimulatorSectionName, "MaxHeight", DefaultMaxHeight);
res = new cClassicFluidSimulator(this, a_SimulateBlock, a_StationaryBlock, MaxHeight, Falloff);
Rate = IsWater ? 6 : 12;
}
m_SimulatorManager->RegisterSimulator(res, Rate);
return res;
}