Performance improvement for running turns by reducing the number of lookups for the hitdata.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-04-25 20:20:30 +02:00
parent f602ea9358
commit 94d9d4f3d2
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 11 additions and 1 deletions

View File

@ -130,6 +130,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
auto library = user->GetBattle()->GetLibrary(); auto library = user->GetBattle()->GetLibrary();
AssertNotNull(library) AssertNotNull(library)
auto dmgLibrary = library->GetDamageLibrary(); auto dmgLibrary = library->GetDamageLibrary();
auto hitIterator = attack->GetTargetIteratorBegin(target);
for (uint8_t hitIndex = 0; hitIndex < numberOfHits; hitIndex++) { for (uint8_t hitIndex = 0; hitIndex < numberOfHits; hitIndex++) {
if (user->IsFainted()) { if (user->IsFainted()) {
break; break;
@ -137,7 +138,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
if (target->IsFainted()) { if (target->IsFainted()) {
break; break;
} }
auto& hit = attack->GetHitData(target, hitIndex); auto& hit = *(hitIterator++);
auto hitType = hit.GetType(); auto hitType = hit.GetType();
HOOK(ChangeAttackType, targetSource, attack, target, hitIndex, &hitType); HOOK(ChangeAttackType, targetSource, attack, target, hitIndex, &hitType);
auto effectiveness = library->GetTypeLibrary()->GetEffectiveness(hitType, target->GetTypes()); auto effectiveness = library->GetTypeLibrary()->GetEffectiveness(hitType, target->GetTypes());

View File

@ -69,6 +69,15 @@ namespace CreatureLib::Battling {
throw CreatureException("Invalid target requested."); throw CreatureException("Invalid target requested.");
} }
std::vector<HitData>::iterator GetTargetIteratorBegin(Creature* creature) {
for (size_t i = 0; i < _targets.Count(); i++) {
if (_targets[i] == creature) {
return _hits.begin() + (i * _numberHits);
}
}
throw CreatureException("Invalid target requested.");
}
bool IsCreatureTarget(Creature* creature) noexcept { return _targets.IndexOf(creature) != (size_t)-1; } bool IsCreatureTarget(Creature* creature) noexcept { return _targets.IndexOf(creature) != (size_t)-1; }
const List<Creature*>& GetTargets() noexcept { return _targets; } const List<Creature*>& GetTargets() noexcept { return _targets; }
uint8_t GetNumberOfHits() const noexcept { return _numberHits; } uint8_t GetNumberOfHits() const noexcept { return _numberHits; }