1
0

Always use relative coordinates in AddBlock

+ Pass block, use relatives
* Fixes everything immediately converting abs back to rel and getting block, when these data were already available
This commit is contained in:
Tiger Wang
2020-07-29 01:18:59 +01:00
parent 99856df686
commit 225c2fa9f6
21 changed files with 139 additions and 231 deletions

View File

@@ -79,14 +79,6 @@ cFireSimulator::cFireSimulator(cWorld & a_World, cIniFile & a_IniFile) :
cFireSimulator::~cFireSimulator()
{
}
void cFireSimulator::SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk)
{
cCoordWithIntList & Data = a_Chunk->GetFireSimulatorData();
@@ -241,28 +233,21 @@ bool cFireSimulator::DoesBurnForever(BLOCKTYPE a_BlockType)
void cFireSimulator::AddBlock(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block)
{
if ((a_Chunk == nullptr) || !a_Chunk->IsValid())
{
return;
}
const auto RelPos = cChunkDef::AbsoluteToRelative(a_Block, a_Chunk->GetPos());
BLOCKTYPE BlockType = a_Chunk->GetBlock(RelPos);
if (!IsAllowedBlock(BlockType))
if (!IsAllowedBlock(a_Block))
{
return;
}
// Check for duplicates:
cFireSimulatorChunkData & ChunkData = a_Chunk->GetFireSimulatorData();
cFireSimulatorChunkData & ChunkData = a_Chunk.GetFireSimulatorData();
for (cCoordWithIntList::iterator itr = ChunkData.begin(), end = ChunkData.end(); itr != end; ++itr)
{
const Vector3i ItrPos{itr->x, itr->y, itr->z};
if (ItrPos == RelPos)
if (ItrPos == a_Position)
{
// Block already present, check if burn step should decrease
// This means if fuel is removed, then the fire burns out sooner
const auto NewBurnStep = GetBurnStepTime(a_Chunk, RelPos);
const auto NewBurnStep = GetBurnStepTime(&a_Chunk, a_Position);
if (itr->Data > NewBurnStep)
{
FIRE_FLOG("FS: Block lost its fuel at {0}", a_Block);
@@ -274,7 +259,7 @@ void cFireSimulator::AddBlock(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a
} // for itr - ChunkData[]
FIRE_FLOG("FS: Adding block {0}", a_Block);
ChunkData.push_back(cCoordWithInt(RelPos.x, RelPos.y, RelPos.z, 100));
ChunkData.push_back(cCoordWithInt(a_Position.x, a_Position.y, a_Position.z, 100));
}