Make ExecutingAttack have raw pointer array HitData, instead of a List. This is a very hot segment of code, and removing surrounding abstractions can give us a decent amount of performance.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2020-05-27 18:26:09 +02:00
parent 90e7a699bc
commit fcc6f2214e
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
3 changed files with 12 additions and 8 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/cmake-build-debug/
/cmake-build-release/
/build-release-windows/
/.idea/

View File

@ -138,9 +138,10 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
if (target->IsFainted()) {
break;
}
auto& hit = *(hitIterator++);
auto hitType = hit.GetType();
auto& hit = hitIterator[hitIndex];
uint8_t hitType = hit.GetType();
HOOK(ChangeAttackType, targetSource, attack, target, hitIndex, &hitType);
hit.SetType(hitType);
auto effectiveness = library->GetTypeLibrary()->GetEffectiveness(hitType, target->GetTypes());
HOOK(ChangeEffectiveness, attack, attack, target, hitIndex, &effectiveness)
hit.SetEffectiveness(effectiveness);

View File

@ -38,7 +38,7 @@ namespace CreatureLib::Battling {
private:
ArbUt::List<Creature*> _targets;
uint8_t _numberHits;
ArbUt::List<HitData> _hits;
HitData* _hits;
Creature* _user;
LearnedAttack* _attack;
Script* _script;
@ -46,15 +46,16 @@ namespace CreatureLib::Battling {
public:
ExecutingAttack(const ArbUt::List<Creature*>& targets, uint8_t numberHits, Creature* user,
LearnedAttack* attack, Script* script)
: _targets(targets.Count()), _numberHits(numberHits), _hits(targets.Count() * numberHits), _user(user),
_attack(attack), _script(script) {
: _targets(targets.Count()), _numberHits(numberHits), _hits(new HitData[targets.Count() * numberHits]),
_user(user), _attack(attack), _script(script) {
AssertNotNull(user)
AssertNotNull(attack)
for (auto target : targets) {
_targets.Append(target);
_hits.Resize(numberHits);
}
}
ExecutingAttack(const ExecutingAttack&) = delete;
ExecutingAttack& operator=(const ExecutingAttack&) = delete;
virtual ~ExecutingAttack() noexcept { delete _script; };
@ -67,10 +68,11 @@ namespace CreatureLib::Battling {
throw CreatureException("Invalid target requested.");
}
std::vector<HitData>::iterator GetTargetIteratorBegin(Creature* creature) {
HitData* GetTargetIteratorBegin(Creature* creature) {
for (size_t i = 0; i < _targets.Count(); i++) {
if (_targets[i] == creature) {
return _hits.begin() + (i * _numberHits);
auto v = _hits + (i * _numberHits * sizeof(HitData));
return v;
}
}
throw CreatureException("Invalid target requested.");