DelayedFluidSimulator: optimized block storage for large amounts of blocks.
Speeds up chunk generation by 15 %. Expected to speed up fluid simulation, unmeasured. git-svn-id: http://mc-server.googlecode.com/svn/trunk@1293 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
f8ae3e6f62
commit
e8aa03f8df
@ -14,11 +14,37 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// cDelayedFluidSimulatorChunkData::cSlot
|
||||||
|
|
||||||
|
bool cDelayedFluidSimulatorChunkData::cSlot::Add(int a_RelX, int a_RelY, int a_RelZ)
|
||||||
|
{
|
||||||
|
ASSERT(a_RelZ >= 0);
|
||||||
|
ASSERT(a_RelZ < ARRAYCOUNT(m_Blocks));
|
||||||
|
|
||||||
|
cCoordWithIntVector & Blocks = m_Blocks[a_RelZ];
|
||||||
|
int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY, a_RelZ);
|
||||||
|
for (cCoordWithIntVector::const_iterator itr = Blocks.begin(), end = Blocks.end(); itr != end; ++itr)
|
||||||
|
{
|
||||||
|
if (itr->Data == Index)
|
||||||
|
{
|
||||||
|
// Already present
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} // for itr - Blocks[]
|
||||||
|
Blocks.push_back(cCoordWithInt(a_RelX, a_RelY, a_RelZ, Index));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// cDelayedFluidSimulatorChunkData:
|
// cDelayedFluidSimulatorChunkData:
|
||||||
|
|
||||||
cDelayedFluidSimulatorChunkData::cDelayedFluidSimulatorChunkData(int a_TickDelay) :
|
cDelayedFluidSimulatorChunkData::cDelayedFluidSimulatorChunkData(int a_TickDelay) :
|
||||||
m_Slots(new cCoordWithIntVector[a_TickDelay])
|
m_Slots(new cSlot[a_TickDelay])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,20 +101,15 @@ void cDelayedFluidSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ,
|
|||||||
|
|
||||||
void * ChunkDataRaw = (m_FluidBlock == E_BLOCK_WATER) ? a_Chunk->GetWaterSimulatorData() : a_Chunk->GetLavaSimulatorData();
|
void * ChunkDataRaw = (m_FluidBlock == E_BLOCK_WATER) ? a_Chunk->GetWaterSimulatorData() : a_Chunk->GetLavaSimulatorData();
|
||||||
cDelayedFluidSimulatorChunkData * ChunkData = (cDelayedFluidSimulatorChunkData *)ChunkDataRaw;
|
cDelayedFluidSimulatorChunkData * ChunkData = (cDelayedFluidSimulatorChunkData *)ChunkDataRaw;
|
||||||
cCoordWithIntVector & Blocks = ChunkData->m_Slots[m_AddSlotNum];
|
cDelayedFluidSimulatorChunkData::cSlot & Slot = ChunkData->m_Slots[m_AddSlotNum];
|
||||||
|
|
||||||
// Check for duplicates:
|
// Add, if not already present:
|
||||||
int Index = cChunkDef::MakeIndexNoCheck(RelX, a_BlockY, RelZ);
|
if (!Slot.Add(RelX, a_BlockY, RelZ))
|
||||||
for (cCoordWithIntVector::iterator itr = Blocks.begin(), end = Blocks.end(); itr != end; ++itr)
|
|
||||||
{
|
|
||||||
if ((itr->Data == Index))
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
++m_TotalBlocks;
|
++m_TotalBlocks;
|
||||||
Blocks.push_back(cCoordWithInt(RelX, a_BlockY, RelZ, Index));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -113,15 +134,23 @@ void cDelayedFluidSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int a_Chunk
|
|||||||
{
|
{
|
||||||
void * ChunkDataRaw = (m_FluidBlock == E_BLOCK_WATER) ? a_Chunk->GetWaterSimulatorData() : a_Chunk->GetLavaSimulatorData();
|
void * ChunkDataRaw = (m_FluidBlock == E_BLOCK_WATER) ? a_Chunk->GetWaterSimulatorData() : a_Chunk->GetLavaSimulatorData();
|
||||||
cDelayedFluidSimulatorChunkData * ChunkData = (cDelayedFluidSimulatorChunkData *)ChunkDataRaw;
|
cDelayedFluidSimulatorChunkData * ChunkData = (cDelayedFluidSimulatorChunkData *)ChunkDataRaw;
|
||||||
cCoordWithIntVector & Blocks = ChunkData->m_Slots[m_SimSlotNum];
|
cDelayedFluidSimulatorChunkData::cSlot & Slot = ChunkData->m_Slots[m_SimSlotNum];
|
||||||
|
|
||||||
// Simulate the blocks in the scheduled slot:
|
// Simulate all the blocks in the scheduled slot:
|
||||||
|
for (int i = 0; i < ARRAYCOUNT(Slot.m_Blocks); i++)
|
||||||
|
{
|
||||||
|
cCoordWithIntVector & Blocks = Slot.m_Blocks[i];
|
||||||
|
if (Blocks.empty())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
for (cCoordWithIntVector::iterator itr = Blocks.begin(), end = Blocks.end(); itr != end; ++itr)
|
for (cCoordWithIntVector::iterator itr = Blocks.begin(), end = Blocks.end(); itr != end; ++itr)
|
||||||
{
|
{
|
||||||
SimulateBlock(a_Chunk, itr->x, itr->y, itr->z);
|
SimulateBlock(a_Chunk, itr->x, itr->y, itr->z);
|
||||||
}
|
}
|
||||||
m_TotalBlocks -= Blocks.size();
|
m_TotalBlocks -= Blocks.size();
|
||||||
Blocks.clear();
|
Blocks.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,13 +19,26 @@ class cDelayedFluidSimulatorChunkData :
|
|||||||
public cFluidSimulatorData
|
public cFluidSimulatorData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
class cSlot
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/// Returns true if the specified block is stored
|
||||||
|
bool HasBlock(int a_RelX, int a_RelY, int a_RelZ);
|
||||||
|
|
||||||
|
/// Adds the specified block unless already present; returns true if added, false if the block was already present
|
||||||
|
bool Add(int a_RelX, int a_RelY, int a_RelZ);
|
||||||
|
|
||||||
|
/** Array of block containers, each item stores blocks for one Z coord
|
||||||
|
Int param is the block index (for faster duplicate comparison in Add())
|
||||||
|
*/
|
||||||
|
cCoordWithIntVector m_Blocks[16];
|
||||||
|
} ;
|
||||||
|
|
||||||
cDelayedFluidSimulatorChunkData(int a_TickDelay);
|
cDelayedFluidSimulatorChunkData(int a_TickDelay);
|
||||||
virtual ~cDelayedFluidSimulatorChunkData();
|
virtual ~cDelayedFluidSimulatorChunkData();
|
||||||
|
|
||||||
/** Slots, one for each delay tick, each containing the blocks to simulate; relative coords.
|
/// Slots, one for each delay tick, each containing the blocks to simulate
|
||||||
Int param is the block index (for faster duplicate comparison in cDelayedFluidSimulator::AddBlock())
|
cSlot * m_Slots;
|
||||||
*/
|
|
||||||
cCoordWithIntVector * m_Slots;
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user