Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: task context is being sent empty #2871

Merged
merged 6 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/canary_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ int CanaryServer::run() {

loaderStatus.notify_one();
},
"CanaryServer::run"
__FUNCTION__
);

loaderStatus.wait(LoaderStatus::LOADING);
Expand Down
10 changes: 6 additions & 4 deletions src/creatures/combat/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2095,10 +2095,12 @@ bool ConditionFeared::executeCondition(std::shared_ptr<Creature> 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");
}
Expand Down
44 changes: 26 additions & 18 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,17 +251,23 @@
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<uint32_t>(ticks),
[creatureId = self->getID()] { g_game().checkCreatureWalk(creatureId); }, "Game::checkCreatureWalk"
);
});
self->eventWalk = g_dispatcher().scheduleEvent(
static_cast<uint32_t>(ticks),
[creatureId = self->getID()] {
g_game().checkCreatureWalk(creatureId);
},
"Game::checkCreatureWalk"
);
},
"Game::checkCreatureWalk"
);
}

void Creature::stopEventWalk() {
Expand Down Expand Up @@ -462,7 +468,7 @@

for (const auto &despawnCreature : despawnMonsterList) {
if (!despawnMonsterList.empty()) {
g_game().removeCreature(despawnCreature, true);

Check warning on line 471 in src/creatures/creature.cpp

View workflow job for this annotation

GitHub Actions / qodana

err33-c

the value returned by this function should not be disregarded; neglecting it may lead to errors
}
}
}
Expand Down Expand Up @@ -600,7 +606,7 @@
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())) {
Expand All @@ -615,7 +621,7 @@
} 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()) {
Expand Down Expand Up @@ -747,7 +753,7 @@
death(lastHitCreature);

if (droppedCorpse && !getPlayer()) {
g_game().removeCreature(static_self_cast<Creature>(), false);

Check warning on line 756 in src/creatures/creature.cpp

View workflow job for this annotation

GitHub Actions / qodana

err33-c

the value returned by this function should not be disregarded; neglecting it may lead to errors
}

if (getMaster()) {
Expand Down Expand Up @@ -825,10 +831,12 @@
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__
);
}
}
}
Expand Down Expand Up @@ -872,7 +880,7 @@
g_game().addCreatureHealth(static_self_cast<Creature>());
}
if (health <= 0) {
g_dispatcher().addEvent([creatureId = getID()] { g_game().executeDeath(creatureId); }, "Game::executeDeath");
g_dispatcher().addEvent([creatureId = getID()] { g_game().executeDeath(creatureId); }, __FUNCTION__);
}
}

Expand Down Expand Up @@ -1061,7 +1069,7 @@
});

if (onComplete) {
g_dispatcher().context().addEvent(std::move(onComplete));
g_dispatcher().context().addEvent(std::move(onComplete), __FUNCTION__);
}
}

Expand Down Expand Up @@ -1799,18 +1807,18 @@
if (teleportSummons) {
g_game().internalTeleport(static_self_cast<Creature>(), getMaster()->getPosition(), true);
} else {
g_game().removeCreature(static_self_cast<Creature>(), true);

Check warning on line 1810 in src/creatures/creature.cpp

View workflow job for this annotation

GitHub Actions / qodana

err33-c

the value returned by this function should not be disregarded; neglecting it may lead to errors
}
g_game().addMagicEffect(getPosition(), CONST_ME_POFF);
}

double_t Creature::getReflectPercent(CombatType_t combatType, bool useCharges /*= false*/) const {
try {
return reflectPercent.at(combatTypeToIndex(combatType));

Check warning on line 1817 in src/creatures/creature.cpp

View workflow job for this annotation

GitHub Actions / qodana

misra-cpp2008-5-0-5

MISRA 5-0-5: There shall be no implicit floating-integral conversions
} catch (const std::out_of_range &e) {
g_logger().error("Index is out of range in getReflectPercent: {}", e.what());
}
return 0;

Check warning on line 1821 in src/creatures/creature.cpp

View workflow job for this annotation

GitHub Actions / qodana

misra-cpp2008-5-0-5

MISRA 5-0-5: There shall be no implicit floating-integral conversions
}

void Creature::setReflectPercent(CombatType_t combatType, int32_t value) {
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/monsters/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ bool Monster::selectTarget(const std::shared_ptr<Creature> &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);
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/monsters/spawns/spawn_monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
14 changes: 7 additions & 7 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1946,7 +1946,7 @@ void Player::onCreatureMove(const std::shared_ptr<Creature> &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()) {
Expand Down Expand Up @@ -4283,7 +4283,7 @@ bool Player::updateSaleShopList(std::shared_ptr<Item> 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;
}
Expand Down Expand Up @@ -4354,7 +4354,7 @@ bool Player::setAttackedCreature(std::shared_ptr<Creature> 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;
}
Expand Down Expand Up @@ -4416,7 +4416,8 @@ void Player::doAttacking(uint32_t) {

const auto &task = createPlayerTask(
std::max<uint32_t>(SCHEDULER_MINTICKS, delay),
[playerId = getID()] { g_game().checkCreatureAttack(playerId); }, "Game::checkCreatureAttack"
[playerId = getID()] { g_game().checkCreatureAttack(playerId); },
__FUNCTION__
);

if (!classicSpeed) {
Expand Down Expand Up @@ -6785,7 +6786,7 @@ void Player::triggerTranscendance() {
player->sendBasicData();
}
},
"Player::triggerTranscendance"
__FUNCTION__
);
g_dispatcher().scheduleEvent(task);

Expand Down Expand Up @@ -7858,8 +7859,7 @@ bool Player::canAutoWalk(const Position &toPosition, const std::function<void()>
std::vector<Direction> 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> task = createPlayerTask(delay, function, __FUNCTION__);
const auto &task = createPlayerTask(delay, function, __FUNCTION__);
setNextWalkActionTask(task);
return true;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/database/databasetasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void DatabaseTasks::execute(const std::string &query, std::function<void(DBResul
threadPool.detach_task([this, query, callback]() {
bool success = db.executeQuery(query);
if (callback != nullptr) {
g_dispatcher().addEvent([callback, success]() { callback(nullptr, success); }, "DatabaseTasks::execute");
g_dispatcher().addEvent([callback, success]() { callback(nullptr, success); }, __FUNCTION__);
}
});
}
Expand All @@ -35,7 +35,7 @@ void DatabaseTasks::store(const std::string &query, std::function<void(DBResult_
threadPool.detach_task([this, query, callback]() {
DBResult_ptr result = db.storeQuery(query);
if (callback != nullptr) {
g_dispatcher().addEvent([callback, result]() { callback(result, true); }, "DatabaseTasks::store");
g_dispatcher().addEvent([callback, result]() { callback(result, true); }, __FUNCTION__);
}
});
}
Loading
Loading