Changed int parameters to vector parameters in cCuboid and simulators (#3874)

This commit is contained in:
Lane Kolbly
2017-08-17 15:48:38 +02:00
committed by Mattes D
parent 09e94bd947
commit 7bdbfad1bb
39 changed files with 283 additions and 215 deletions
+6 -6
View File
@@ -78,9 +78,9 @@ cDelayedFluidSimulator::cDelayedFluidSimulator(cWorld & a_World, BLOCKTYPE a_Flu
void cDelayedFluidSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk)
void cDelayedFluidSimulator::AddBlock(Vector3i a_Block, cChunk * a_Chunk)
{
if ((a_BlockY < 0) || (a_BlockY >= cChunkDef::Height))
if ((a_Block.y < 0) || (a_Block.y >= cChunkDef::Height))
{
// Not inside the world (may happen when rclk with a full bucket - the client sends Y = -1)
return;
@@ -91,9 +91,9 @@ void cDelayedFluidSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ,
return;
}
int RelX = a_BlockX - a_Chunk->GetPosX() * cChunkDef::Width;
int RelZ = a_BlockZ - a_Chunk->GetPosZ() * cChunkDef::Width;
BLOCKTYPE BlockType = a_Chunk->GetBlock(RelX, a_BlockY, RelZ);
int RelX = a_Block.x - a_Chunk->GetPosX() * cChunkDef::Width;
int RelZ = a_Block.z - a_Chunk->GetPosZ() * cChunkDef::Width;
BLOCKTYPE BlockType = a_Chunk->GetBlock(RelX, a_Block.y, RelZ);
if (BlockType != m_FluidBlock)
{
return;
@@ -104,7 +104,7 @@ void cDelayedFluidSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ,
cDelayedFluidSimulatorChunkData::cSlot & Slot = ChunkData->m_Slots[m_AddSlotNum];
// Add, if not already present:
if (!Slot.Add(RelX, a_BlockY, RelZ))
if (!Slot.Add(RelX, a_Block.y, RelZ))
{
return;
}
+1 -1
View File
@@ -54,7 +54,7 @@ public:
cDelayedFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, int a_TickDelay);
// cSimulator overrides:
virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override;
virtual void AddBlock(Vector3i a_Block, cChunk * a_Chunk) override;
virtual void Simulate(float a_Dt) override;
virtual void SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) override;
virtual cFluidSimulatorData * CreateChunkData(void) override { return new cDelayedFluidSimulatorChunkData(m_TickDelay); }
+7 -7
View File
@@ -218,16 +218,16 @@ bool cFireSimulator::DoesBurnForever(BLOCKTYPE a_BlockType)
void cFireSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk)
void cFireSimulator::AddBlock(Vector3i a_Block, cChunk * a_Chunk)
{
if ((a_Chunk == nullptr) || !a_Chunk->IsValid())
{
return;
}
int RelX = a_BlockX - a_Chunk->GetPosX() * cChunkDef::Width;
int RelZ = a_BlockZ - a_Chunk->GetPosZ() * cChunkDef::Width;
BLOCKTYPE BlockType = a_Chunk->GetBlock(RelX, a_BlockY, RelZ);
int RelX = a_Block.x - a_Chunk->GetPosX() * cChunkDef::Width;
int RelZ = a_Block.z - a_Chunk->GetPosZ() * cChunkDef::Width;
BLOCKTYPE BlockType = a_Chunk->GetBlock(RelX, a_Block.y, RelZ);
if (!IsAllowedBlock(BlockType))
{
return;
@@ -237,15 +237,15 @@ void cFireSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk *
cFireSimulatorChunkData & ChunkData = a_Chunk->GetFireSimulatorData();
for (cCoordWithIntList::iterator itr = ChunkData.begin(), end = ChunkData.end(); itr != end; ++itr)
{
if ((itr->x == RelX) && (itr->y == a_BlockY) && (itr->z == RelZ))
if ((itr->x == RelX) && (itr->y == a_Block.y) && (itr->z == RelZ))
{
// Already present, skip adding
return;
}
} // for itr - ChunkData[]
FLOG("FS: Adding block {%d, %d, %d}", a_BlockX, a_BlockY, a_BlockZ);
ChunkData.push_back(cCoordWithInt(RelX, a_BlockY, RelZ, 100));
FLOG("FS: Adding block {%d, %d, %d}", a_Block.x, a_Block.y, a_Block.z);
ChunkData.push_back(cCoordWithInt(RelX, a_Block.y, RelZ, 100));
}
+1 -1
View File
@@ -43,7 +43,7 @@ protected:
int m_ReplaceFuelChance;
virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override;
virtual void AddBlock(Vector3i a_Block, cChunk * a_Chunk) override;
/** Returns the time [msec] after which the specified fire block is stepped again; based on surrounding fuels */
int GetBurnStepTime(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ);
+1 -1
View File
@@ -325,7 +325,7 @@ void cFloodyFluidSimulator::SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, i
// Spread:
FLOG(" Spreading to {%d, %d, %d} with meta %d", BlockX, a_RelY, BlockZ, a_NewMeta);
a_NearChunk->SetBlock(a_RelX, a_RelY, a_RelZ, m_FluidBlock, a_NewMeta);
m_World.GetSimulatorManager()->WakeUp(BlockX, a_RelY, BlockZ, a_NearChunk);
m_World.GetSimulatorManager()->WakeUp({BlockX, a_RelY, BlockZ}, a_NearChunk);
HardenBlock(a_NearChunk, a_RelX, a_RelY, a_RelZ, m_FluidBlock, a_NewMeta);
}
@@ -31,9 +31,9 @@ public:
return IsRedstone(a_BlockType);
}
virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override
virtual void AddBlock(Vector3i a_Block, cChunk * a_Chunk) override
{
m_Data.WakeUp({ a_BlockX, a_BlockY, a_BlockZ });
m_Data.WakeUp(a_Block);
}
/** Returns if a block is a mechanism (something that accepts power and does something)
+2 -4
View File
@@ -27,11 +27,9 @@ public:
}
// cSimulator overrides:
virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override
virtual void AddBlock(Vector3i a_Block, cChunk * a_Chunk) override
{
UNUSED(a_BlockX);
UNUSED(a_BlockY);
UNUSED(a_BlockZ);
UNUSED(a_Block);
UNUSED(a_Chunk);
}
virtual void Simulate(float a_Dt) override { UNUSED(a_Dt);}
+2 -4
View File
@@ -27,11 +27,9 @@ public:
UNUSED(a_Chunk);
}
virtual bool IsAllowedBlock( BLOCKTYPE a_BlockType) override { return false; }
virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override
virtual void AddBlock(Vector3i a_Block, cChunk * a_Chunk) override
{
UNUSED(a_BlockX);
UNUSED(a_BlockY);
UNUSED(a_BlockZ);
UNUSED(a_Block);
UNUSED(a_Chunk);
}
+1 -1
View File
@@ -33,7 +33,7 @@ public:
virtual void Simulate(float a_Dt) = 0;
virtual void SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) = 0;
virtual bool IsAllowedBlock(BLOCKTYPE a_BlockType) = 0;
virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) = 0;
virtual void AddBlock(Vector3i a_Block, cChunk * a_Chunk) = 0;
virtual cRedstoneSimulatorChunkData * CreateChunkData() = 0;
+6 -6
View File
@@ -101,15 +101,15 @@ bool cSandSimulator::IsAllowedBlock(BLOCKTYPE a_BlockType)
void cSandSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk)
void cSandSimulator::AddBlock(Vector3i a_Block, cChunk * a_Chunk)
{
if ((a_Chunk == nullptr) || !a_Chunk->IsValid())
{
return;
}
int RelX = a_BlockX - a_Chunk->GetPosX() * cChunkDef::Width;
int RelZ = a_BlockZ - a_Chunk->GetPosZ() * cChunkDef::Width;
if (!IsAllowedBlock(a_Chunk->GetBlock(RelX, a_BlockY, RelZ)))
int RelX = a_Block.x - a_Chunk->GetPosX() * cChunkDef::Width;
int RelZ = a_Block.z - a_Chunk->GetPosZ() * cChunkDef::Width;
if (!IsAllowedBlock(a_Chunk->GetBlock(RelX, a_Block.y, RelZ)))
{
return;
}
@@ -118,14 +118,14 @@ void cSandSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk *
cSandSimulatorChunkData & ChunkData = a_Chunk->GetSandSimulatorData();
for (cSandSimulatorChunkData::iterator itr = ChunkData.begin(); itr != ChunkData.end(); ++itr)
{
if ((itr->x == RelX) && (itr->y == a_BlockY) && (itr->z == RelZ))
if ((itr->x == RelX) && (itr->y == a_Block.y) && (itr->z == RelZ))
{
return;
}
}
m_TotalBlocks += 1;
ChunkData.push_back(cCoordWithInt(RelX, a_BlockY, RelZ));
ChunkData.push_back(cCoordWithInt(RelX, a_Block.y, RelZ));
}
+1 -1
View File
@@ -59,7 +59,7 @@ protected:
int m_TotalBlocks; // Total number of blocks currently in the queue for simulating
virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override;
virtual void AddBlock(Vector3i a_Block, cChunk * a_Chunk) override;
/** Performs the instant fall of the block - removes it from top, Finishes it at the bottom */
void DoInstantFall(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ);
+15 -16
View File
@@ -18,20 +18,20 @@
void cSimulator::WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk)
void cSimulator::WakeUp(Vector3i a_Block, cChunk * a_Chunk)
{
AddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk);
AddBlock(a_BlockX - 1, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX - 1, a_BlockZ));
AddBlock(a_BlockX + 1, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX + 1, a_BlockZ));
AddBlock(a_BlockX, a_BlockY, a_BlockZ - 1, a_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ - 1));
AddBlock(a_BlockX, a_BlockY, a_BlockZ + 1, a_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ + 1));
if (a_BlockY > 0)
AddBlock(a_Block, a_Chunk);
AddBlock(a_Block + Vector3i(-1, 0, 0), a_Chunk->GetNeighborChunk(a_Block.x - 1, a_Block.z));
AddBlock(a_Block + Vector3i( 1, 0, 0), a_Chunk->GetNeighborChunk(a_Block.x + 1, a_Block.z));
AddBlock(a_Block + Vector3i(0, 0, -1), a_Chunk->GetNeighborChunk(a_Block.x, a_Block.z - 1));
AddBlock(a_Block + Vector3i(0, 0, 1), a_Chunk->GetNeighborChunk(a_Block.x, a_Block.z + 1));
if (a_Block.y > 0)
{
AddBlock(a_BlockX, a_BlockY - 1, a_BlockZ, a_Chunk);
AddBlock(a_Block + Vector3i(0, -1, 0), a_Chunk);
}
if (a_BlockY < cChunkDef::Height - 1)
if (a_Block.y < cChunkDef::Height - 1)
{
AddBlock(a_BlockX, a_BlockY + 1, a_BlockZ, a_Chunk);
AddBlock(a_Block + Vector3i(0, 1, 0), a_Chunk);
}
}
@@ -47,12 +47,11 @@ void cSimulator::WakeUpArea(const cCuboid & a_Area)
area.ClampY(0, cChunkDef::Height - 1);
// Add all blocks, in a per-chunk manner:
int chunkStartX, chunkStartZ, chunkEndX, chunkEndZ;
cChunkDef::BlockToChunk(area.p1.x, area.p1.z, chunkStartX, chunkStartZ);
cChunkDef::BlockToChunk(area.p2.x, area.p2.z, chunkEndX, chunkEndZ);
for (int cz = chunkStartZ; cz <= chunkEndZ; ++cz)
cChunkCoords ChunkStart = cChunkDef::BlockToChunk(area.p1);
cChunkCoords ChunkEnd = cChunkDef::BlockToChunk(area.p2);
for (int cz = ChunkStart.m_ChunkZ; cz <= ChunkEnd.m_ChunkZ; ++cz)
{
for (int cx = chunkStartX; cx <= chunkEndX; ++cx)
for (int cx = ChunkStart.m_ChunkX; cx <= ChunkEnd.m_ChunkX; ++cx)
{
m_World.DoWithChunk(cx, cz, [this, &area](cChunk & a_CBChunk) -> bool
{
@@ -73,7 +72,7 @@ void cSimulator::WakeUpArea(const cCuboid & a_Area)
{
for (int x = startX; x <= endX; ++x)
{
AddBlock(x, y, z, &a_CBChunk);
AddBlock({x, y, z}, &a_CBChunk);
} // for x
} // for z
} // for y
+2 -2
View File
@@ -39,7 +39,7 @@ public:
}
/** Called when a block changes */
void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk);
void WakeUp(Vector3i a_Block, cChunk * a_Chunk);
/** Does the same processing as WakeUp, but for all blocks within the specified area.
Has better performance than calling WakeUp for each block individually, due to neighbor-checking.
@@ -55,7 +55,7 @@ protected:
friend class cChunk; // Calls AddBlock() in its WakeUpSimulators() function, to speed things up
/** 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(Vector3i a_Block, cChunk * a_Chunk) = 0;
cWorld & m_World;
} ;
+2 -2
View File
@@ -58,11 +58,11 @@ void cSimulatorManager::SimulateChunk(std::chrono::milliseconds a_Dt, int a_Chun
void cSimulatorManager::WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk)
void cSimulatorManager::WakeUp(Vector3i a_Block, cChunk * a_Chunk)
{
for (cSimulators::iterator itr = m_Simulators.begin(); itr != m_Simulators.end(); ++itr)
{
itr->first->WakeUp(a_BlockX, a_BlockY, a_BlockZ, a_Chunk);
itr->first->WakeUp(a_Block, a_Chunk);
}
}
+1 -1
View File
@@ -36,7 +36,7 @@ public:
void SimulateChunk(std::chrono::milliseconds a_DT, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk);
/* Called when a single block changes, wakes all simulators up for the block and its face-neighbors. */
void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk);
void WakeUp(Vector3i a_Block, cChunk * a_Chunk);
/** Does the same processing as WakeUp, but for all blocks within the specified area.
Has better performance than calling WakeUp for each block individually, due to neighbor-checking.
+8 -8
View File
@@ -20,26 +20,26 @@ cVaporizeFluidSimulator::cVaporizeFluidSimulator(cWorld & a_World, BLOCKTYPE a_F
void cVaporizeFluidSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk)
void cVaporizeFluidSimulator::AddBlock(Vector3i a_Block, cChunk * a_Chunk)
{
if (a_Chunk == nullptr)
{
return;
}
int RelX = a_BlockX - a_Chunk->GetPosX() * cChunkDef::Width;
int RelZ = a_BlockZ - a_Chunk->GetPosZ() * cChunkDef::Width;
BLOCKTYPE BlockType = a_Chunk->GetBlock(RelX, a_BlockY, RelZ);
int RelX = a_Block.x - a_Chunk->GetPosX() * cChunkDef::Width;
int RelZ = a_Block.z - a_Chunk->GetPosZ() * cChunkDef::Width;
BLOCKTYPE BlockType = a_Chunk->GetBlock(RelX, a_Block.y, RelZ);
if (
(BlockType == m_FluidBlock) ||
(BlockType == m_StationaryFluidBlock)
)
{
a_Chunk->SetBlock(RelX, a_BlockY, RelZ, E_BLOCK_AIR, 0);
a_Chunk->SetBlock(RelX, a_Block.y, RelZ, E_BLOCK_AIR, 0);
a_Chunk->BroadcastSoundEffect(
"block.fire.extinguish",
static_cast<double>(a_BlockX),
static_cast<double>(a_BlockY),
static_cast<double>(a_BlockZ),
static_cast<double>(a_Block.x),
static_cast<double>(a_Block.y),
static_cast<double>(a_Block.z),
1.0f,
0.6f
);
+1 -1
View File
@@ -25,7 +25,7 @@ public:
cVaporizeFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid);
// cSimulator overrides:
virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override;
virtual void AddBlock(Vector3i a_Block, cChunk * a_Chunk) override;
virtual void Simulate(float a_Dt) override;
} ;