added another overload of fireEvent for less verbose calling

Dieser Commit ist enthalten in:
Reinder Feenstra 2023-12-29 23:04:13 +01:00
Ursprung 2c2ab529ed
Commit 19e8ae44b5
2 geänderte Dateien mit 11 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -111,7 +111,7 @@ BlockRailTile::BlockRailTile(World& world, std::string_view _id) :
} }
} }
fireEvent<const std::shared_ptr<Train>&, const std::shared_ptr<BlockRailTile>&>(onTrainAssigned, newTrain, self); fireEvent(onTrainAssigned, newTrain, self);
} }
}} }}
, removeTrain{*this, "remove_train", , removeTrain{*this, "remove_train",
@ -154,7 +154,7 @@ BlockRailTile::BlockRailTile(World& world, std::string_view _id) :
} }
} }
fireEvent<const std::shared_ptr<Train>&, const std::shared_ptr<BlockRailTile>&>(onTrainRemoved, oldTrain, self); fireEvent(onTrainRemoved, oldTrain, self);
} }
}} }}
, flipTrain{*this, "flip_train", , flipTrain{*this, "flip_train",
@ -280,7 +280,7 @@ void BlockRailTile::inputItemValueChanged(BlockInputMapItem& item)
trains.appendInternal(blockStatus); trains.appendInternal(blockStatus);
updateTrainMethodEnabled(); updateTrainMethodEnabled();
fireEvent<const std::shared_ptr<Train>&, const std::shared_ptr<BlockRailTile>&>( fireEvent(
onTrainEntered, onTrainEntered,
blockStatus->train.value(), blockStatus->train.value(),
shared_ptr<BlockRailTile>(), shared_ptr<BlockRailTile>(),
@ -327,7 +327,7 @@ void BlockRailTile::inputItemValueChanged(BlockInputMapItem& item)
updateState(); updateState();
fireEvent<const std::shared_ptr<Train>&, const std::shared_ptr<BlockRailTile>&>( fireEvent(
onTrainLeft, onTrainLeft,
blockStatus->train.value(), blockStatus->train.value(),
shared_ptr<BlockRailTile>(), shared_ptr<BlockRailTile>(),
@ -445,7 +445,7 @@ bool BlockRailTile::reserve(const std::shared_ptr<BlockPath>& blockPath, const s
{ {
const auto direction = side == BlockSide::A ? BlockTrainDirection::TowardsB : BlockTrainDirection::TowardsA; const auto direction = side == BlockSide::A ? BlockTrainDirection::TowardsB : BlockTrainDirection::TowardsA;
trains.appendInternal(TrainBlockStatus::create(*this, *train, direction)); trains.appendInternal(TrainBlockStatus::create(*this, *train, direction));
fireEvent<const std::shared_ptr<Train>&, const std::shared_ptr<BlockRailTile>&>(onTrainReserved, train, shared_ptr<BlockRailTile>(), direction); fireEvent(onTrainReserved, train, shared_ptr<BlockRailTile>(), direction);
} }
updateState(); updateState();
} }

Datei anzeigen

@ -74,6 +74,12 @@ class Object : public std::enable_shared_from_this<Object>
event.fire(object, std::forward<Args>(args)...); event.fire(object, std::forward<Args>(args)...);
} }
template<class T1, class T2, class... Args>
inline void fireEvent(Event<const std::shared_ptr<T1>&, const std::shared_ptr<T2>&, Args...>& event, const std::shared_ptr<T1>& object1, const std::shared_ptr<T2>& object2, Args... args)
{
event.fire(object1, object2, std::forward<Args>(args)...);
}
virtual void destroying() {} virtual void destroying() {}
virtual void load(WorldLoader& loader, const nlohmann::json& data); virtual void load(WorldLoader& loader, const nlohmann::json& data);
virtual void save(WorldSaver& saver, nlohmann::json& data, nlohmann::json& state) const; virtual void save(WorldSaver& saver, nlohmann::json& data, nlohmann::json& state) const;