I have been trying this for a few days but still cannot find a fix, so in the meantime, I am trying myself. I decided to post this here in case someone has a solution.
CPU is going up to 80% by just one function, using TFS 1.4.2 with many commits of 1.5.
I have
Here's the
and here's the
That is the full log at the exact same time as the single-function log above.
CPU is going up to 80% by just one function, using TFS 1.4.2 with many commits of 1.5.
I have
classicAttackSpeed = true
in my config.lua
Code:
[17/08/2023 19:30:40]
Thread: 1 Cpu usage: 71.1587% Idle: 28.7749% Other: 0.066461% Players online: 46
Time (ms) Calls Rel usage % Real usage % Description
16767 314 78.54636% 55.89254% std::bind(&Game::checkCreatures, this, (index + 1) % EVENT_CREATURECOUNT)
Here's the
checkCreatures
function.
C++:
void Game::checkCreatures(size_t index)
{
g_scheduler.addEvent(createSchedulerTask(EVENT_CHECK_CREATURE_INTERVAL, std::bind(&Game::checkCreatures, this, (index + 1) % EVENT_CREATURECOUNT)));
auto& checkCreatureList = checkCreatureLists[index];
auto it = checkCreatureList.begin(), end = checkCreatureList.end();
while (it != end) {
Creature* creature = *it;
if (creature->creatureCheck) {
if (creature->getHealth() > 0) {
creature->onThink(EVENT_CREATURE_THINK_INTERVAL);
creature->onAttacking(EVENT_CREATURE_THINK_INTERVAL);
creature->executeConditions(EVENT_CREATURE_THINK_INTERVAL);
}
++it;
} else {
creature->inCheckCreaturesVector = false;
it = checkCreatureList.erase(it);
ReleaseCreature(creature);
}
}
cleanup();
#ifdef STATS_ENABLED
g_stats.playersOnline = getPlayersOnline();
#endif
}
doAttacking
function.
C++:
void Player::doAttacking(uint32_t)
{
if (lastAttack == 0) {
lastAttack = OTSYS_TIME() - getAttackSpeed() - 1;
}
if (hasCondition(CONDITION_PACIFIED)) {
return;
}
if ((OTSYS_TIME() - lastAttack) >= getAttackSpeed()) {
bool result = false;
Item* tool = getWeapon();
const Weapon* weapon = g_weapons->getWeapon(tool);
uint32_t delay = getAttackSpeed();
bool classicSpeed = g_config.getBoolean(ConfigManager::CLASSIC_ATTACK_SPEED);
if (weapon) {
if (!weapon->interruptSwing()) {
result = weapon->useWeapon(this, tool, attackedCreature);
} else if (!classicSpeed && !canDoAction()) {
delay = getNextActionTime();
} else {
result = weapon->useWeapon(this, tool, attackedCreature);
}
} else {
result = Weapon::useFist(this, attackedCreature);
}
SchedulerTask* task = createSchedulerTask(std::max<uint32_t>(SCHEDULER_MINTICKS, delay), std::bind(&Game::checkCreatureAttack, &g_game, getID()));
if (!classicSpeed) {
setNextActionTask(task, false);
} else {
g_scheduler.addEvent(task);
}
if (result) {
lastAttack = OTSYS_TIME();
}
}
}
Code:
[17/08/2023 19:30:40]
Thread: 1 Cpu usage: 71.1587% Idle: 28.7749% Other: 0.066461% Players online: 46
Time (ms) Calls Rel usage % Real usage % Description
16767 314 78.54636% 55.89254% std::bind(&Game::checkCreatures, this, (index + 1) % EVENT_CREATURECOUNT)
1063 6211 4.98369% 3.54632% std::bind(&Game::checkCreatureAttack, &g_game, getID())
805 2373 3.77382% 2.68540% &Game::playerSay
573 77 2.68796% 1.91272% std::bind(&Game::checkDecay, this)
547 588 2.56446% 1.82484% std::bind(&LuaEnvironment::executeTimerEvent, &g_luaEnvironment, lastTimerEventId)
468 6377 2.19267% 1.56028% std::bind(&Game::checkCreatureWalk, &g_game, getID())
437 1150 2.05126% 1.45965% [&]() { sendAll(bufferedProtocols); }
191 247 0.89923% 0.63988% std::bind(&Game::executeDeath, &g_game, getID())
76 730 0.36022% 0.25633% std::bind(&Game::updateCreatureWalk, &g_game, getID())
74 660 0.34983% 0.24893% &Game::playerUseWithCreature
72 256 0.34151% 0.24302% std::bind(&Game::playerUseWithCreature, this, playerId, fromPos, fromStackPos, creatureId, spriteId)
60 142808 0.28539% 0.20308% std::bind(&ProtocolGame::writeToSpectatorsOutputBuffer, this, msg)
53 352 0.24831% 0.17669% std::bind(&Spawn::checkSpawn, this)
37 399 0.17724% 0.12612% &Game::playerMove
26 1096 0.12200% 0.08682% &Game::playerReceivePingBack
23 318 0.10789% 0.07677% &Game::playerSetAttackedCreature