diff --git a/src/canary_server.cpp b/src/canary_server.cpp index cca280b69fa..f71fc71ba9a 100644 --- a/src/canary_server.cpp +++ b/src/canary_server.cpp @@ -123,7 +123,7 @@ int CanaryServer::run() { loaderStatus.notify_one(); }, - "CanaryServer::run" + __FUNCTION__ ); loaderStatus.wait(LoaderStatus::LOADING); diff --git a/src/creatures/combat/condition.cpp b/src/creatures/combat/condition.cpp index 6784e8786f3..b308c05a5bc 100644 --- a/src/creatures/combat/condition.cpp +++ b/src/creatures/combat/condition.cpp @@ -2095,10 +2095,12 @@ bool ConditionFeared::executeCondition(std::shared_ptr creature, int32 } if (getFleePath(creature, currentPos, listDir)) { - g_dispatcher().addEvent([id = creature->getID(), listDir] { - g_game().forcePlayerAutoWalk(id, listDir); - }, - "ConditionFeared::executeCondition"); + g_dispatcher().addEvent( + [id = creature->getID(), listDir] { + g_game().forcePlayerAutoWalk(id, listDir); + }, + __FUNCTION__ + ); g_logger().debug("[ConditionFeared::executeCondition] Walking Scheduled"); } diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index a5cd66a629f..56ed1770039 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -251,17 +251,23 @@ void Creature::addEventWalk(bool firstStep) { return; } - g_dispatcher().context().tryAddEvent([ticks, self = getCreature()]() { - // Take first step right away, but still queue the next - if (ticks == 1) { - g_game().checkCreatureWalk(self->getID()); - } + g_dispatcher().context().tryAddEvent( + [ticks, self = getCreature()]() { + // Take first step right away, but still queue the next + if (ticks == 1) { + g_game().checkCreatureWalk(self->getID()); + } - self->eventWalk = g_dispatcher().scheduleEvent( - static_cast(ticks), - [creatureId = self->getID()] { g_game().checkCreatureWalk(creatureId); }, "Game::checkCreatureWalk" - ); - }); + self->eventWalk = g_dispatcher().scheduleEvent( + static_cast(ticks), + [creatureId = self->getID()] { + g_game().checkCreatureWalk(creatureId); + }, + "Game::checkCreatureWalk" + ); + }, + "Game::checkCreatureWalk" + ); } void Creature::stopEventWalk() { @@ -600,7 +606,7 @@ void Creature::onCreatureMove(const std::shared_ptr &creature, const s if (followCreature && (creature == getCreature() || creature == followCreature)) { if (hasFollowPath) { isUpdatingPath = true; - g_dispatcher().addEvent([creatureId = getID()] { g_game().updateCreatureWalk(creatureId); }, "Game::updateCreatureWalk"); + g_dispatcher().addEvent([creatureId = getID()] { g_game().updateCreatureWalk(creatureId); }, __FUNCTION__); } if (newPos.z != oldPos.z || !canSee(followCreature->getPosition())) { @@ -615,7 +621,7 @@ void Creature::onCreatureMove(const std::shared_ptr &creature, const s } else { if (hasExtraSwing()) { // our target is moving lets see if we can get in hit - g_dispatcher().addEvent([creatureId = getID()] { g_game().checkCreatureAttack(creatureId); }, "Game::checkCreatureAttack"); + g_dispatcher().addEvent([creatureId = getID()] { g_game().checkCreatureAttack(creatureId); }, __FUNCTION__); } if (newTile->getZoneType() != oldTile->getZoneType()) { @@ -825,10 +831,12 @@ bool Creature::dropCorpse(std::shared_ptr lastHitCreature, std::shared auto isReachable = g_game().map.getPathMatching(player->getPosition(), dirList, FrozenPathingConditionCall(corpse->getPosition()), fpp); if (player->checkAutoLoot(monster->isRewardBoss()) && isReachable) { - g_dispatcher().addEvent([player, corpseContainer, corpsePosition = corpse->getPosition()] { - g_game().playerQuickLootCorpse(player, corpseContainer, corpsePosition); - }, - "Game::playerQuickLootCorpse"); + g_dispatcher().addEvent( + [player, corpseContainer, corpsePosition = corpse->getPosition()] { + g_game().playerQuickLootCorpse(player, corpseContainer, corpsePosition); + }, + __FUNCTION__ + ); } } } @@ -872,7 +880,7 @@ void Creature::changeHealth(int32_t healthChange, bool sendHealthChange /* = tru g_game().addCreatureHealth(static_self_cast()); } if (health <= 0) { - g_dispatcher().addEvent([creatureId = getID()] { g_game().executeDeath(creatureId); }, "Game::executeDeath"); + g_dispatcher().addEvent([creatureId = getID()] { g_game().executeDeath(creatureId); }, __FUNCTION__); } } @@ -1061,7 +1069,7 @@ void Creature::goToFollowCreature_async(std::function &&onComplete) { }); if (onComplete) { - g_dispatcher().context().addEvent(std::move(onComplete)); + g_dispatcher().context().addEvent(std::move(onComplete), __FUNCTION__); } } diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index 1a364ece2ba..4a6d07fe8d7 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -792,7 +792,7 @@ bool Monster::selectTarget(const std::shared_ptr &creature) { if (isHostile() || isSummon()) { if (setAttackedCreature(creature)) { - g_dispatcher().addEvent([creatureId = getID()] { g_game().checkCreatureAttack(creatureId); }, "Game::checkCreatureAttack"); + g_dispatcher().addEvent([creatureId = getID()] { g_game().checkCreatureAttack(creatureId); }, __FUNCTION__); } } return setFollowCreature(creature); diff --git a/src/creatures/monsters/spawns/spawn_monster.cpp b/src/creatures/monsters/spawns/spawn_monster.cpp index 846068e67b7..93b381da061 100644 --- a/src/creatures/monsters/spawns/spawn_monster.cpp +++ b/src/creatures/monsters/spawns/spawn_monster.cpp @@ -226,7 +226,7 @@ void SpawnMonster::startup(bool delayed) { continue; } if (delayed) { - g_dispatcher().addEvent([this, spawnMonsterId, &sb, mType] { scheduleSpawn(spawnMonsterId, sb, mType, 0, true); }, "SpawnMonster::startup"); + g_dispatcher().addEvent([this, spawnMonsterId, &sb, mType] { scheduleSpawn(spawnMonsterId, sb, mType, 0, true); }, __FUNCTION__); } else { scheduleSpawn(spawnMonsterId, sb, mType, 0, true); } diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 6f7e33eb7f9..8c49226b621 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -1946,7 +1946,7 @@ void Player::onCreatureMove(const std::shared_ptr &creature, const std const auto &followCreature = getFollowCreature(); if (hasFollowPath && (creature == followCreature || (creature.get() == this && followCreature))) { isUpdatingPath = false; - g_dispatcher().addEvent([creatureId = getID()] { g_game().updateCreatureWalk(creatureId); }, "Game::updateCreatureWalk"); + g_dispatcher().addEvent([creatureId = getID()] { g_game().updateCreatureWalk(creatureId); }, __FUNCTION__); } if (creature != getPlayer()) { @@ -4283,7 +4283,7 @@ bool Player::updateSaleShopList(std::shared_ptr item) { return true; } - g_dispatcher().addEvent([creatureId = getID()] { g_game().updatePlayerSaleItems(creatureId); }, "Game::updatePlayerSaleItems"); + g_dispatcher().addEvent([creatureId = getID()] { g_game().updatePlayerSaleItems(creatureId); }, __FUNCTION__); scheduledSaleUpdate = true; return true; } @@ -4354,7 +4354,7 @@ bool Player::setAttackedCreature(std::shared_ptr creature) { } if (creature) { - g_dispatcher().addEvent([creatureId = getID()] { g_game().checkCreatureAttack(creatureId); }, "Game::checkCreatureAttack"); + g_dispatcher().addEvent([creatureId = getID()] { g_game().checkCreatureAttack(creatureId); }, __FUNCTION__); } return true; } @@ -4416,7 +4416,8 @@ void Player::doAttacking(uint32_t) { const auto &task = createPlayerTask( std::max(SCHEDULER_MINTICKS, delay), - [playerId = getID()] { g_game().checkCreatureAttack(playerId); }, "Game::checkCreatureAttack" + [playerId = getID()] { g_game().checkCreatureAttack(playerId); }, + __FUNCTION__ ); if (!classicSpeed) { @@ -6785,7 +6786,7 @@ void Player::triggerTranscendance() { player->sendBasicData(); } }, - "Player::triggerTranscendance" + __FUNCTION__ ); g_dispatcher().scheduleEvent(task); @@ -7858,8 +7859,7 @@ bool Player::canAutoWalk(const Position &toPosition, const std::function std::vector listDir; if (getPathTo(toPosition, listDir, 0, 1, true, true)) { g_dispatcher().addEvent([creatureId = getID(), listDir] { g_game().playerAutoWalk(creatureId, listDir); }, __FUNCTION__); - - std::shared_ptr task = createPlayerTask(delay, function, __FUNCTION__); + const auto &task = createPlayerTask(delay, function, __FUNCTION__); setNextWalkActionTask(task); return true; } else { diff --git a/src/database/databasetasks.cpp b/src/database/databasetasks.cpp index 06cfda93fc0..8a660f1c031 100644 --- a/src/database/databasetasks.cpp +++ b/src/database/databasetasks.cpp @@ -26,7 +26,7 @@ void DatabaseTasks::execute(const std::string &query, std::functiongetID(), movingCreature->getID(), movingCreature->getPosition(), tile->getPosition()); }, - "Game::playerMoveCreatureByID" + __FUNCTION__ ); player->setNextActionPushTask(task); } else { @@ -1385,7 +1385,11 @@ void Game::playerMoveCreature(std::shared_ptr player, std::shared_ptrcanDoAction()) { const auto &task = createPlayerTask( - 600, [this, player, movingCreature, toTile, movingCreatureOrigPos] { playerMoveCreatureByID(player->getID(), movingCreature->getID(), movingCreatureOrigPos, toTile->getPosition()); }, "Game::playerMoveCreatureByID" + 600, + [this, player, movingCreature, toTile, movingCreatureOrigPos] { + playerMoveCreatureByID(player->getID(), movingCreature->getID(), movingCreatureOrigPos, toTile->getPosition()); + }, + __FUNCTION__ ); player->setNextActionPushTask(task); @@ -1398,9 +1402,13 @@ void Game::playerMoveCreature(std::shared_ptr player, std::shared_ptr listDir; if (player->getPathTo(movingCreatureOrigPos, listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); const auto &task = createPlayerTask( - 600, [this, player, movingCreature, toTile, movingCreatureOrigPos] { playerMoveCreatureByID(player->getID(), movingCreature->getID(), movingCreatureOrigPos, toTile->getPosition()); }, "Game::playerMoveCreatureByID" + 600, + [this, player, movingCreature, toTile, movingCreatureOrigPos] { + playerMoveCreatureByID(player->getID(), movingCreature->getID(), movingCreatureOrigPos, toTile->getPosition()); + }, + __FUNCTION__ ); player->pushEvent(true); player->setNextActionPushTask(task); @@ -1601,11 +1609,12 @@ void Game::playerMoveItemByPlayerID(uint32_t playerId, const Position &fromPos, void Game::playerMoveItem(std::shared_ptr player, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count, std::shared_ptr item, std::shared_ptr toCylinder) { if (!player->canDoAction()) { uint32_t delay = player->getNextActionTime(); - std::shared_ptr task = createPlayerTask( - delay, [this, playerId = player->getID(), fromPos, itemId, fromStackPos, toPos, count] { + const auto &task = createPlayerTask( + delay, + [this, playerId = player->getID(), fromPos, itemId, fromStackPos, toPos, count] { playerMoveItemByPlayerID(playerId, fromPos, itemId, fromStackPos, toPos, count); }, - "Game::playerMoveItemByPlayerID" + __FUNCTION__ ); player->setNextActionTask(task); return; @@ -1691,13 +1700,13 @@ void Game::playerMoveItem(std::shared_ptr player, const Position &fromPo // need to walk to the item first before using it std::vector listDir; if (player->getPathTo(item->getPosition(), listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - - std::shared_ptr task = createPlayerTask( - 400, [this, playerId = player->getID(), fromPos, itemId, fromStackPos, toPos, count] { + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); + const auto &task = createPlayerTask( + 400, + [this, playerId = player->getID(), fromPos, itemId, fromStackPos, toPos, count] { playerMoveItemByPlayerID(playerId, fromPos, itemId, fromStackPos, toPos, count); }, - "Game::playerMoveItemByPlayerID" + __FUNCTION__ ); player->setNextWalkActionTask(task); } else { @@ -1753,13 +1762,13 @@ void Game::playerMoveItem(std::shared_ptr player, const Position &fromPo std::vector listDir; if (player->getPathTo(walkPos, listDir, 0, 0, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - - std::shared_ptr task = createPlayerTask( - 400, [this, playerId = player->getID(), itemPos, itemId, itemStackPos, toPos, count] { + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); + const auto &task = createPlayerTask( + 400, + [this, playerId = player->getID(), itemPos, itemId, itemStackPos, toPos, count] { playerMoveItemByPlayerID(playerId, itemPos, itemId, itemStackPos, toPos, count); }, - "Game::playerMoveItemByPlayerID" + __FUNCTION__ ); player->setNextWalkActionTask(task); } else { @@ -3678,10 +3687,13 @@ void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t f std::vector listDir; if (player->getPathTo(walkToPos, listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - - std::shared_ptr task = createPlayerTask( - 400, [this, playerId, itemPos, itemStackPos, fromItemId, toPos, toStackPos, toItemId] { playerUseItemEx(playerId, itemPos, itemStackPos, fromItemId, toPos, toStackPos, toItemId); }, "Game::playerUseItemEx" + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); + const auto &task = createPlayerTask( + 400, + [this, playerId, itemPos, itemStackPos, fromItemId, toPos, toStackPos, toItemId] { + playerUseItemEx(playerId, itemPos, itemStackPos, fromItemId, toPos, toStackPos, toItemId); + }, + __FUNCTION__ ); if (it.isRune() || it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); @@ -3708,8 +3720,12 @@ void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t f if (it.isRune() || it.type == ITEM_TYPE_POTION) { delay = player->getNextPotionActionTime(); } - std::shared_ptr task = createPlayerTask( - delay, [this, playerId, fromPos, fromStackPos, fromItemId, toPos, toStackPos, toItemId] { playerUseItemEx(playerId, fromPos, fromStackPos, fromItemId, toPos, toStackPos, toItemId); }, "Game::playerUseItemEx" + const auto &task = createPlayerTask( + delay, + [this, playerId, fromPos, fromStackPos, fromItemId, toPos, toStackPos, toItemId] { + playerUseItemEx(playerId, fromPos, fromStackPos, fromItemId, toPos, toStackPos, toItemId); + }, + __FUNCTION__ ); if (it.isRune() || it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); @@ -3792,10 +3808,13 @@ void Game::playerUseItem(uint32_t playerId, const Position &pos, uint8_t stackPo if (ret == RETURNVALUE_TOOFARAWAY) { std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - - std::shared_ptr task = createPlayerTask( - 400, [this, playerId, pos, stackPos, index, itemId] { playerUseItem(playerId, pos, stackPos, index, itemId); }, "Game::playerUseItem" + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); + const auto &task = createPlayerTask( + 400, + [this, playerId, pos, stackPos, index, itemId] { + playerUseItem(playerId, pos, stackPos, index, itemId); + }, + __FUNCTION__ ); if (it.isRune() || it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); @@ -3822,8 +3841,12 @@ void Game::playerUseItem(uint32_t playerId, const Position &pos, uint8_t stackPo if (it.isRune() || it.type == ITEM_TYPE_POTION) { delay = player->getNextPotionActionTime(); } - std::shared_ptr task = createPlayerTask( - delay, [this, playerId, pos, stackPos, index, itemId] { playerUseItem(playerId, pos, stackPos, index, itemId); }, "Game::playerUseItem" + const auto &task = createPlayerTask( + delay, + [this, playerId, pos, stackPos, index, itemId] { + playerUseItem(playerId, pos, stackPos, index, itemId); + }, + __FUNCTION__ ); if (it.isRune() || it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); @@ -3949,13 +3972,13 @@ void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uin std::vector listDir; if (player->getPathTo(walkToPos, listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - - std::shared_ptr task = createPlayerTask( - 400, [this, playerId, itemPos, itemStackPos, creatureId, itemId] { + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); + const auto &task = createPlayerTask( + 400, + [this, playerId, itemPos, itemStackPos, creatureId, itemId] { playerUseWithCreature(playerId, itemPos, itemStackPos, creatureId, itemId); }, - "Game::playerUseWithCreature" + __FUNCTION__ ); if (it.isRune() || it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); @@ -3982,10 +4005,13 @@ void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uin if (it.isRune() || it.type == ITEM_TYPE_POTION) { delay = player->getNextPotionActionTime(); } - std::shared_ptr task = createPlayerTask( - delay, [this, playerId, fromPos, fromStackPos, creatureId, itemId] { playerUseWithCreature(playerId, fromPos, fromStackPos, creatureId, itemId); }, "Game::playerUseWithCreature" + const auto &task = createPlayerTask( + delay, + [this, playerId, fromPos, fromStackPos, creatureId, itemId] { + playerUseWithCreature(playerId, fromPos, fromStackPos, creatureId, itemId); + }, + __FUNCTION__ ); - if (it.isRune() || it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); } else { @@ -4110,13 +4136,13 @@ void Game::playerRotateItem(uint32_t playerId, const Position &pos, uint8_t stac if (pos.x != 0xFFFF && !Position::areInRange<1, 1, 0>(pos, player->getPosition())) { std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - - std::shared_ptr task = createPlayerTask( - 400, [this, playerId, pos, stackPos, itemId] { + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); + const auto &task = createPlayerTask( + 400, + [this, playerId, pos, stackPos, itemId] { playerRotateItem(playerId, pos, stackPos, itemId); }, - "Game::playerRotateItem" + __FUNCTION__ ); player->setNextWalkActionTask(task); } else { @@ -4166,18 +4192,26 @@ void Game::playerConfigureShowOffSocket(uint32_t playerId, const Position &pos, if (!Position::areInRange<1, 1, 0>(pos, player->getPosition())) { std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, false)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - std::shared_ptr task; + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); if (isPodiumOfRenown) { - task = createPlayerTask( - 400, [player, item, pos, itemId, stackPos] { player->sendPodiumWindow(item, pos, itemId, stackPos); }, "Game::playerConfigureShowOffSocket" + const auto &task = createPlayerTask( + 400, + [player, item, pos, itemId, stackPos] { + player->sendPodiumWindow(item, pos, itemId, stackPos); + }, + __FUNCTION__ ); + player->setNextWalkActionTask(task); } else { - task = createPlayerTask( - 400, [player, item, pos, itemId, stackPos] { player->sendMonsterPodiumWindow(item, pos, itemId, stackPos); }, "Game::playerConfigureShowOffSocket" + const auto &task = createPlayerTask( + 400, + [player, item, pos, itemId, stackPos] { + player->sendMonsterPodiumWindow(item, pos, itemId, stackPos); + }, + __FUNCTION__ ); + player->setNextWalkActionTask(task); } - player->setNextWalkActionTask(task); } else { player->sendCancelMessage(RETURNVALUE_THEREISNOWAY); } @@ -4227,9 +4261,13 @@ void Game::playerSetShowOffSocket(uint32_t playerId, Outfit_t &outfit, const Pos if (!Position::areInRange<1, 1, 0>(pos, player->getPosition())) { std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, false)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - std::shared_ptr task = createPlayerTask( - 400, [this, playerId, pos] { playerBrowseField(playerId, pos); }, "Game::playerBrowseField" + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); + const auto &task = createPlayerTask( + 400, + [this, playerId, pos] { + playerBrowseField(playerId, pos); + }, + __FUNCTION__ ); player->setNextWalkActionTask(task); } else { @@ -4368,10 +4406,13 @@ void Game::playerWrapableItem(uint32_t playerId, const Position &pos, uint8_t st if (pos.x != 0xFFFF && !Position::areInRange<1, 1, 0>(pos, player->getPosition())) { std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - - std::shared_ptr task = createPlayerTask( - 400, [this, playerId, pos, stackPos, itemId] { playerWrapableItem(playerId, pos, stackPos, itemId); }, "Game::playerWrapableItem" + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); + const auto &task = createPlayerTask( + 400, + [this, playerId, pos, stackPos, itemId] { + playerWrapableItem(playerId, pos, stackPos, itemId); + }, + __FUNCTION__ ); player->setNextWalkActionTask(task); } else { @@ -4549,9 +4590,13 @@ void Game::playerBrowseField(uint32_t playerId, const Position &pos) { if (!Position::areInRange<1, 1>(playerPos, pos)) { std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - std::shared_ptr task = createPlayerTask( - 400, [this, playerId, pos] { playerBrowseField(playerId, pos); }, "Game::playerBrowseField" + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); + const auto &task = createPlayerTask( + 400, + [this, playerId, pos] { + playerBrowseField(playerId, pos); + }, + __FUNCTION__ ); player->setNextWalkActionTask(task); } else { @@ -4812,10 +4857,13 @@ void Game::playerRequestTrade(uint32_t playerId, const Position &pos, uint8_t st if (!Position::areInRange<1, 1>(tradeItemPosition, playerPosition)) { std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - - std::shared_ptr task = createPlayerTask( - 400, [this, playerId, pos, stackPos, tradePlayerId, itemId] { playerRequestTrade(playerId, pos, stackPos, tradePlayerId, itemId); }, "Game::playerRequestTrade" + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); + const auto &task = createPlayerTask( + 400, + [this, playerId, pos, stackPos, tradePlayerId, itemId] { + playerRequestTrade(playerId, pos, stackPos, tradePlayerId, itemId); + }, + __FUNCTION__ ); player->setNextWalkActionTask(task); } else { @@ -5375,12 +5423,13 @@ void Game::playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t item } if (!autoLoot && !player->canDoAction()) { - uint32_t delay = player->getNextActionTime(); - std::shared_ptr task = createPlayerTask( - delay, [this, playerId = player->getID(), pos, itemId, stackPos, defaultItem, lootAllCorpses, autoLoot] { + const uint32_t delay = player->getNextActionTime(); + const auto &task = createPlayerTask( + delay, + [this, playerId = player->getID(), pos, itemId, stackPos, defaultItem, lootAllCorpses, autoLoot] { playerQuickLoot(playerId, pos, itemId, stackPos, defaultItem, lootAllCorpses, autoLoot); }, - "Game::playerQuickLoot" + __FUNCTION__ ); player->setNextActionTask(task); return; @@ -5391,12 +5440,13 @@ void Game::playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t item // need to walk to the corpse first before looting it std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - std::shared_ptr task = createPlayerTask( - 0, [this, playerId = player->getID(), pos, itemId, stackPos, defaultItem, lootAllCorpses, autoLoot] { + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); + const auto &task = createPlayerTask( + 300, + [this, playerId = player->getID(), pos, itemId, stackPos, defaultItem, lootAllCorpses, autoLoot] { playerQuickLoot(playerId, pos, itemId, stackPos, defaultItem, lootAllCorpses, autoLoot); }, - "Game::playerQuickLoot" + __FUNCTION__ ); player->setNextWalkActionTask(task); } else { @@ -5765,7 +5815,7 @@ void Game::playerSetAttackedCreature(uint32_t playerId, uint32_t creatureId) { } player->setAttackedCreature(attackCreature); - g_dispatcher().addEvent([this, plyerId = player->getID()] { updateCreatureWalk(plyerId); }, "Game::updateCreatureWalk"); + g_dispatcher().addEvent([this, plyerId = player->getID()] { updateCreatureWalk(plyerId); }, __FUNCTION__); } void Game::playerFollowCreature(uint32_t playerId, uint32_t creatureId) { @@ -5775,7 +5825,7 @@ void Game::playerFollowCreature(uint32_t playerId, uint32_t creatureId) { } player->setAttackedCreature(nullptr); - g_dispatcher().addEvent([this, plyerId = player->getID()] { updateCreatureWalk(plyerId); }, "Game::updateCreatureWalk"); + g_dispatcher().addEvent([this, plyerId = player->getID()] { updateCreatureWalk(plyerId); }, __FUNCTION__); player->setFollowCreature(getCreatureByID(creatureId)); } @@ -9483,9 +9533,13 @@ void Game::playerSetMonsterPodium(uint32_t playerId, uint32_t monsterRaceId, con if (!Position::areInRange<1, 1, 0>(pos, player->getPosition())) { if (std::vector listDir; player->getPathTo(pos, listDir, 0, 1, true, false)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - std::shared_ptr task = createPlayerTask( - 400, [this, playerId, pos] { playerBrowseField(playerId, pos); }, "Game::playerBrowseField" + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); + const auto &task = createPlayerTask( + 400, + [this, playerId, pos] { + playerBrowseField(playerId, pos); + }, + __FUNCTION__ ); player->setNextWalkActionTask(task); } else { @@ -9583,12 +9637,13 @@ void Game::playerRotatePodium(uint32_t playerId, const Position &pos, uint8_t st if (pos.x != 0xFFFF && !Position::areInRange<1, 1, 0>(pos, player->getPosition())) { if (std::vector listDir; player->getPathTo(pos, listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - std::shared_ptr task = createPlayerTask( - 400, [this, playerId, pos, stackPos, itemId] { + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); + const auto &task = createPlayerTask( + 400, + [this, playerId, pos, stackPos, itemId] { playerRotatePodium(playerId, pos, stackPos, itemId); }, - "Game::playerRotatePodium" + __FUNCTION__ ); player->setNextWalkActionTask(task); } else { @@ -10107,7 +10162,7 @@ uint32_t Game::makeFiendishMonster(uint32_t forgeableMonsterId /* = 0*/, bool cr auto schedulerTask = createPlayerTask( finalTime, [this, monster] { updateFiendishMonsterStatus(monster->getID(), monster->getName()); }, - "Game::updateFiendishMonsterStatus" + __FUNCTION__ ); forgeMonsterEventIds[monster->getID()] = g_dispatcher().scheduleEvent(schedulerTask); return monster->getID(); diff --git a/src/game/scheduling/dispatcher.cpp b/src/game/scheduling/dispatcher.cpp index dbbfc020be5..eaedaa86ac5 100644 --- a/src/game/scheduling/dispatcher.cpp +++ b/src/game/scheduling/dispatcher.cpp @@ -236,17 +236,17 @@ void Dispatcher::stopEvent(uint64_t eventId) { } } -void DispatcherContext::addEvent(std::function &&f) const { - g_dispatcher().addEvent(std::move(f), taskName); +void DispatcherContext::addEvent(std::function &&f, std::string_view context) const { + g_dispatcher().addEvent(std::move(f), context); } -void DispatcherContext::tryAddEvent(std::function &&f) const { +void DispatcherContext::tryAddEvent(std::function &&f, std::string_view context) const { if (!f) { return; } if (isAsync()) { - g_dispatcher().addEvent(std::move(f), taskName); + g_dispatcher().addEvent(std::move(f), context); } else { f(); } diff --git a/src/game/scheduling/dispatcher.hpp b/src/game/scheduling/dispatcher.hpp index 94b284c9316..b50346e4895 100644 --- a/src/game/scheduling/dispatcher.hpp +++ b/src/game/scheduling/dispatcher.hpp @@ -56,10 +56,10 @@ struct DispatcherContext { } // postpone the event - void addEvent(std::function &&f) const; + void addEvent(std::function &&f, std::string_view context) const; // if the context is async, the event will be postponed, if not, it will be executed immediately. - void tryAddEvent(std::function &&f) const; + void tryAddEvent(std::function &&f, std::string_view context) const; private: void reset() { @@ -70,7 +70,7 @@ struct DispatcherContext { DispatcherType type = DispatcherType::None; TaskGroup group = TaskGroup::ThreadPool; - std::string_view taskName = ""; + std::string_view taskName; friend class Dispatcher; }; diff --git a/src/lua/functions/core/game/game_functions.cpp b/src/lua/functions/core/game/game_functions.cpp index 10a6379781a..83544ded535 100644 --- a/src/lua/functions/core/game/game_functions.cpp +++ b/src/lua/functions/core/game/game_functions.cpp @@ -180,7 +180,7 @@ int GameFunctions::luaGameGetPlayers(lua_State* L) { int GameFunctions::luaGameLoadMap(lua_State* L) { // Game.loadMap(path) const std::string &path = getString(L, 1); - g_dispatcher().addEvent([path]() { g_game().loadMap(path); }, "GameFunctions::luaGameLoadMap"); + g_dispatcher().addEvent([path]() { g_game().loadMap(path); }, __FUNCTION__); return 0; } @@ -188,7 +188,7 @@ int GameFunctions::luaGameloadMapChunk(lua_State* L) { // Game.loadMapChunk(path, position, remove) const std::string &path = getString(L, 1); const Position &position = getPosition(L, 2); - g_dispatcher().addEvent([path, position]() { g_game().loadMap(path, position); }, "GameFunctions::luaGameloadMapChunk"); + g_dispatcher().addEvent([path, position]() { g_game().loadMap(path, position); }, __FUNCTION__); return 0; } diff --git a/src/map/mapcache.cpp b/src/map/mapcache.cpp index f4cdb524ec9..ad3c909a8bf 100644 --- a/src/map/mapcache.cpp +++ b/src/map/mapcache.cpp @@ -152,11 +152,14 @@ std::shared_ptr MapCache::getOrCreateTileFromCache(const std::unique_ptrsetFlag(static_cast(cachedTile->flags)); // add zone synchronously - g_dispatcher().context().tryAddEvent([tile, pos] { - for (const auto &zone : Zone::getZones(pos)) { - tile->addZone(zone); - } - }); + g_dispatcher().context().tryAddEvent( + [tile, pos] { + for (const auto &zone : Zone::getZones(pos)) { + tile->addZone(zone); + } + }, + "Zone::getZones" + ); floor->setTile(x, y, tile); diff --git a/src/server/network/connection/connection.cpp b/src/server/network/connection/connection.cpp index 3072384420d..a3782d56cba 100644 --- a/src/server/network/connection/connection.cpp +++ b/src/server/network/connection/connection.cpp @@ -62,7 +62,7 @@ void Connection::close(bool force) { connectionState = CONNECTION_STATE_CLOSED; if (protocol) { - g_dispatcher().addEvent([protocol = protocol] { protocol->release(); }, "Protocol::release", std::chrono::milliseconds(CONNECTION_WRITE_TIMEOUT * 1000).count()); + g_dispatcher().addEvent([protocol = protocol] { protocol->release(); }, __FUNCTION__, std::chrono::milliseconds(CONNECTION_WRITE_TIMEOUT * 1000).count()); } if (messageQueue.empty() || force) { @@ -98,7 +98,7 @@ void Connection::closeSocket() { void Connection::accept(Protocol_ptr protocolPtr) { connectionState = CONNECTION_STATE_IDENTIFYING; protocol = std::move(protocolPtr); - g_dispatcher().addEvent([protocol = protocol] { protocol->onConnect(); }, "Protocol::onConnect", std::chrono::milliseconds(CONNECTION_WRITE_TIMEOUT * 1000).count()); + g_dispatcher().addEvent([protocol = protocol] { protocol->onConnect(); }, __FUNCTION__, std::chrono::milliseconds(CONNECTION_WRITE_TIMEOUT * 1000).count()); acceptInternal(false); } diff --git a/src/server/network/protocol/protocol.cpp b/src/server/network/protocol/protocol.cpp index 255899f2f99..c40ead17ab0 100644 --- a/src/server/network/protocol/protocol.cpp +++ b/src/server/network/protocol/protocol.cpp @@ -44,13 +44,17 @@ bool Protocol::sendRecvMessageCallback(NetworkMessage &msg) { return false; } - g_dispatcher().addEvent([&msg, protocolWeak = std::weak_ptr(shared_from_this())]() { - if (auto protocol = protocolWeak.lock()) { - if (auto protocolConnection = protocol->getConnection()) { - protocol->parsePacket(msg); - protocolConnection->resumeWork(); + g_dispatcher().addEvent( + [&msg, protocolWeak = std::weak_ptr(shared_from_this())]() { + if (auto protocol = protocolWeak.lock()) { + if (auto protocolConnection = protocol->getConnection()) { + protocol->parsePacket(msg); + protocolConnection->resumeWork(); + } } - } }, "Protocol::sendRecvMessageCallback"); + }, + __FUNCTION__ + ); return true; } diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index aab3f88bd47..909eef1e92e 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -859,7 +859,7 @@ void ProtocolGame::onRecvFirstMessage(NetworkMessage &msg) { return; } - g_dispatcher().addEvent([self = getThis(), characterName, accountId, operatingSystem] { self->login(characterName, accountId, operatingSystem); }, "ProtocolGame::login"); + g_dispatcher().addEvent([self = getThis(), characterName, accountId, operatingSystem] { self->login(characterName, accountId, operatingSystem); }, __FUNCTION__); } void ProtocolGame::onConnect() { @@ -5040,18 +5040,20 @@ void ProtocolGame::updateCoinBalance() { return; } - g_dispatcher().addEvent([playerId = player->getID()] { - const auto &threadPlayer = g_game().getPlayerByID(playerId); - if (threadPlayer && threadPlayer->getAccount()) { - const auto [coins, errCoin] = threadPlayer->getAccount()->getCoins(enumToValue(CoinType::Normal)); - const auto [transferCoins, errTCoin] = threadPlayer->getAccount()->getCoins(enumToValue(CoinType::Transferable)); + g_dispatcher().addEvent( + [playerId = player->getID()] { + const auto &threadPlayer = g_game().getPlayerByID(playerId); + if (threadPlayer && threadPlayer->getAccount()) { + const auto [coins, errCoin] = threadPlayer->getAccount()->getCoins(enumToValue(CoinType::Normal)); + const auto [transferCoins, errTCoin] = threadPlayer->getAccount()->getCoins(enumToValue(CoinType::Transferable)); - threadPlayer->coinBalance = coins; - threadPlayer->coinTransferableBalance = transferCoins; - threadPlayer->sendCoinBalance(); - } - }, - "ProtocolGame::updateCoinBalance"); + threadPlayer->coinBalance = coins; + threadPlayer->coinTransferableBalance = transferCoins; + threadPlayer->sendCoinBalance(); + } + }, + __FUNCTION__ + ); } void ProtocolGame::sendMarketLeave() { diff --git a/src/server/network/protocol/protocollogin.cpp b/src/server/network/protocol/protocollogin.cpp index d6e9e3cb9f1..f8c68634f64 100644 --- a/src/server/network/protocol/protocollogin.cpp +++ b/src/server/network/protocol/protocollogin.cpp @@ -174,8 +174,10 @@ void ProtocolLogin::onRecvFirstMessage(NetworkMessage &msg) { return; } - g_dispatcher().addEvent([self = std::static_pointer_cast(shared_from_this()), accountDescriptor, password] { - self->getCharacterList(accountDescriptor, password); - }, - "ProtocolLogin::getCharacterList"); + g_dispatcher().addEvent( + [self = std::static_pointer_cast(shared_from_this()), accountDescriptor, password] { + self->getCharacterList(accountDescriptor, password); + }, + __FUNCTION__ + ); } diff --git a/src/server/network/protocol/protocolstatus.cpp b/src/server/network/protocol/protocolstatus.cpp index 15a3f74be07..f9ec878eda9 100644 --- a/src/server/network/protocol/protocolstatus.cpp +++ b/src/server/network/protocol/protocolstatus.cpp @@ -44,10 +44,12 @@ void ProtocolStatus::onRecvFirstMessage(NetworkMessage &msg) { // XML info protocol case 0xFF: { if (msg.getString(4) == "info") { - g_dispatcher().addEvent([self = std::static_pointer_cast(shared_from_this())] { - self->sendStatusString(); - }, - "ProtocolStatus::sendStatusString"); + g_dispatcher().addEvent( + [self = std::static_pointer_cast(shared_from_this())] { + self->sendStatusString(); + }, + __FUNCTION__ + ); return; } break; @@ -60,10 +62,12 @@ void ProtocolStatus::onRecvFirstMessage(NetworkMessage &msg) { if (requestedInfo & REQUEST_PLAYER_STATUS_INFO) { characterName = msg.getString(); } - g_dispatcher().addEvent([self = std::static_pointer_cast(shared_from_this()), requestedInfo, characterName] { - self->sendInfo(requestedInfo, characterName); - }, - "ProtocolStatus::sendInfo"); + g_dispatcher().addEvent( + [self = std::static_pointer_cast(shared_from_this()), requestedInfo, characterName] { + self->sendInfo(requestedInfo, characterName); + }, + __FUNCTION__ + ); return; } diff --git a/src/server/signals.cpp b/src/server/signals.cpp index 626a918f677..ae71d833c93 100644 --- a/src/server/signals.cpp +++ b/src/server/signals.cpp @@ -54,21 +54,21 @@ void Signals::asyncWait() { void Signals::dispatchSignalHandler(int signal) { switch (signal) { case SIGINT: // Shuts the server down - g_dispatcher().addEvent(sigintHandler, "sigintHandler"); + g_dispatcher().addEvent(sigintHandler, __FUNCTION__); break; case SIGTERM: // Shuts the server down - g_dispatcher().addEvent(sigtermHandler, "sigtermHandler"); + g_dispatcher().addEvent(sigtermHandler, __FUNCTION__); break; #ifndef _WIN32 case SIGHUP: // Reload config/data - g_dispatcher().addEvent(sighupHandler, "sighupHandler"); + g_dispatcher().addEvent(sighupHandler, __FUNCTION__); break; case SIGUSR1: // Saves game state - g_dispatcher().addEvent(sigusr1Handler, "sigusr1Handler"); + g_dispatcher().addEvent(sigusr1Handler, __FUNCTION__); break; #else case SIGBREAK: // Shuts the server down - g_dispatcher().addEvent(sigbreakHandler, "sigbreakHandler"); + g_dispatcher().addEvent(sigbreakHandler, __FUNCTION__); // hold the thread until other threads end inject().shutdown(); break;