Another rework for scripthooks, for better performance.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This new version caches pointers to the pointers to scripts, so that we can build the data once and then simply iterate over it whenever we want to run a hook.
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
#include "TurnOrdering.hpp"
|
||||
#include "../TurnChoices/AttackTurnChoice.hpp"
|
||||
#include "../Models/Creature.hpp"
|
||||
#include "../Models/Battle.hpp"
|
||||
#include "../../Core/Exceptions/NotImplementedException.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@@ -15,8 +13,8 @@ bool ___ChoiceOrderFunc(const BaseTurnChoice* a, const BaseTurnChoice* b, Core::
|
||||
if (aKind != bKind)
|
||||
return aKind > bKind;
|
||||
if (aKind == TurnChoiceKind::Attack){
|
||||
auto aPriority = static_cast<const AttackTurnChoice*>(a)->GetPriority();
|
||||
auto bPriority = static_cast<const AttackTurnChoice*>(b)->GetPriority();
|
||||
auto aPriority = dynamic_cast<const AttackTurnChoice*>(a)->GetPriority();
|
||||
auto bPriority = dynamic_cast<const AttackTurnChoice*>(b)->GetPriority();
|
||||
if (aPriority != bPriority)
|
||||
return aPriority > bPriority;
|
||||
}
|
||||
@@ -29,7 +27,7 @@ bool ___ChoiceOrderFunc(const BaseTurnChoice* a, const BaseTurnChoice* b, Core::
|
||||
return randomValue == 0;
|
||||
}
|
||||
|
||||
void TurnOrdering::OrderChoices(std::vector<const BaseTurnChoice *> &vec, Core::Random& rand) {
|
||||
void TurnOrdering::OrderChoices(std::vector<BaseTurnChoice *> &vec, Core::Random& rand) {
|
||||
auto comp = [&](const BaseTurnChoice * a,const BaseTurnChoice * b)-> bool {
|
||||
return ___ChoiceOrderFunc(a,b,rand);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user