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
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
90e7a699bc
commit
fcc6f2214e
|
@ -1,3 +1,4 @@
|
||||||
/cmake-build-debug/
|
/cmake-build-debug/
|
||||||
/cmake-build-release/
|
/cmake-build-release/
|
||||||
|
/build-release-windows/
|
||||||
/.idea/
|
/.idea/
|
|
@ -138,9 +138,10 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
|
||||||
if (target->IsFainted()) {
|
if (target->IsFainted()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
auto& hit = *(hitIterator++);
|
auto& hit = hitIterator[hitIndex];
|
||||||
auto hitType = hit.GetType();
|
uint8_t hitType = hit.GetType();
|
||||||
HOOK(ChangeAttackType, targetSource, attack, target, hitIndex, &hitType);
|
HOOK(ChangeAttackType, targetSource, attack, target, hitIndex, &hitType);
|
||||||
|
hit.SetType(hitType);
|
||||||
auto effectiveness = library->GetTypeLibrary()->GetEffectiveness(hitType, target->GetTypes());
|
auto effectiveness = library->GetTypeLibrary()->GetEffectiveness(hitType, target->GetTypes());
|
||||||
HOOK(ChangeEffectiveness, attack, attack, target, hitIndex, &effectiveness)
|
HOOK(ChangeEffectiveness, attack, attack, target, hitIndex, &effectiveness)
|
||||||
hit.SetEffectiveness(effectiveness);
|
hit.SetEffectiveness(effectiveness);
|
||||||
|
|
|
@ -38,7 +38,7 @@ namespace CreatureLib::Battling {
|
||||||
private:
|
private:
|
||||||
ArbUt::List<Creature*> _targets;
|
ArbUt::List<Creature*> _targets;
|
||||||
uint8_t _numberHits;
|
uint8_t _numberHits;
|
||||||
ArbUt::List<HitData> _hits;
|
HitData* _hits;
|
||||||
Creature* _user;
|
Creature* _user;
|
||||||
LearnedAttack* _attack;
|
LearnedAttack* _attack;
|
||||||
Script* _script;
|
Script* _script;
|
||||||
|
@ -46,15 +46,16 @@ namespace CreatureLib::Battling {
|
||||||
public:
|
public:
|
||||||
ExecutingAttack(const ArbUt::List<Creature*>& targets, uint8_t numberHits, Creature* user,
|
ExecutingAttack(const ArbUt::List<Creature*>& targets, uint8_t numberHits, Creature* user,
|
||||||
LearnedAttack* attack, Script* script)
|
LearnedAttack* attack, Script* script)
|
||||||
: _targets(targets.Count()), _numberHits(numberHits), _hits(targets.Count() * numberHits), _user(user),
|
: _targets(targets.Count()), _numberHits(numberHits), _hits(new HitData[targets.Count() * numberHits]),
|
||||||
_attack(attack), _script(script) {
|
_user(user), _attack(attack), _script(script) {
|
||||||
AssertNotNull(user)
|
AssertNotNull(user)
|
||||||
AssertNotNull(attack)
|
AssertNotNull(attack)
|
||||||
for (auto target : targets) {
|
for (auto target : targets) {
|
||||||
_targets.Append(target);
|
_targets.Append(target);
|
||||||
_hits.Resize(numberHits);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ExecutingAttack(const ExecutingAttack&) = delete;
|
||||||
|
ExecutingAttack& operator=(const ExecutingAttack&) = delete;
|
||||||
|
|
||||||
virtual ~ExecutingAttack() noexcept { delete _script; };
|
virtual ~ExecutingAttack() noexcept { delete _script; };
|
||||||
|
|
||||||
|
@ -67,10 +68,11 @@ namespace CreatureLib::Battling {
|
||||||
throw CreatureException("Invalid target requested.");
|
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++) {
|
for (size_t i = 0; i < _targets.Count(); i++) {
|
||||||
if (_targets[i] == creature) {
|
if (_targets[i] == creature) {
|
||||||
return _hits.begin() + (i * _numberHits);
|
auto v = _hits + (i * _numberHits * sizeof(HitData));
|
||||||
|
return v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw CreatureException("Invalid target requested.");
|
throw CreatureException("Invalid target requested.");
|
||||||
|
|
Loading…
Reference in New Issue