Skip to content

Commit

Permalink
server: BlockRailTile move path release to TrainTracking
Browse files Browse the repository at this point in the history
- This effectively reverts commit 0b22d1f
- Logic from commit 0b22d1f is now in TrainTracking
- This fixes case when short train releases "enter"
  block before occupying "exit" block.
  • Loading branch information
gfgit committed Jul 29, 2024
1 parent cde858f commit fdd6d95
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
17 changes: 0 additions & 17 deletions server/src/board/tile/rail/blockrailtile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,30 +317,13 @@ void BlockRailTile::inputItemValueChanged(BlockInputMapItem& item)
{
const auto& blockStatus = trains.front();

const auto blockTrainDirection = blockStatus->direction.value();

// Train must be in at least two blocks, else we loose it.
// Release tailing block of train only. (When using current detection not all wagons might consume power.)
if(blockStatus->train &&
blockStatus->train->blocks.size() > 1 &&
blockStatus->train->blocks.back() == blockStatus)
{
TrainTracking::left(blockStatus);

const auto pathA = m_reservedPaths[0].lock();
const bool exitA = pathA && &pathA->fromBlock() == this;

const auto pathB = m_reservedPaths[1].lock();
const bool exitB = pathB && &pathB->fromBlock() == this;

if(blockTrainDirection == BlockTrainDirection::TowardsA && exitA)
{
pathA->delayedRelease(m_world.pathReleaseDelay);
}
else if(blockTrainDirection == BlockTrainDirection::TowardsB && exitB)
{
pathB->delayedRelease(m_world.pathReleaseDelay);
}
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions server/src/train/traintracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
#include "train.hpp"
#include "trainblockstatus.hpp"
#include "../board/tile/rail/blockrailtile.hpp"
#include "../board/map/blockpath.hpp"
#include "../core/objectproperty.tpp"
#include "../world/world.hpp"

void TrainTracking::reserve(const std::shared_ptr<Train>& train, const std::shared_ptr<BlockRailTile>& block, BlockTrainDirection direction)
{
Expand Down Expand Up @@ -90,6 +92,21 @@ void TrainTracking::left(std::shared_ptr<TrainBlockStatus> status)
train->fireBlockLeft(block, direction);
block->fireTrainLeft(train, direction);

const auto pathA = block->getReservedPath(BlockSide::A);
const bool exitA = pathA && &pathA->fromBlock() == block.get();

const auto pathB = block->getReservedPath(BlockSide::B);
const bool exitB = pathB && &pathB->fromBlock() == block.get();

if(direction == BlockTrainDirection::TowardsA && exitA)
{
pathA->delayedRelease(block->world().pathReleaseDelay);
}
else if(direction == BlockTrainDirection::TowardsB && exitB)
{
pathB->delayedRelease(block->world().pathReleaseDelay);
}

status->destroy();
#ifndef NDEBUG
std::weak_ptr<TrainBlockStatus> statusWeak = status;
Expand Down

0 comments on commit fdd6d95

Please sign in to comment.