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:
@@ -7,12 +7,12 @@
|
||||
|
||||
namespace CreatureLib::Battling{
|
||||
class ChoiceQueue {
|
||||
std::vector<const BaseTurnChoice*> _queue;
|
||||
std::vector<BaseTurnChoice*> _queue;
|
||||
size_t _current = 0;
|
||||
public:
|
||||
bool HasCompletedQueue = false;
|
||||
|
||||
explicit ChoiceQueue(std::vector<const BaseTurnChoice*> queue)
|
||||
explicit ChoiceQueue(std::vector<BaseTurnChoice*> queue)
|
||||
:_queue(std::move(queue)){}
|
||||
|
||||
const BaseTurnChoice* Dequeue(){
|
||||
@@ -25,7 +25,7 @@ namespace CreatureLib::Battling{
|
||||
return _current < _queue.size();
|
||||
}
|
||||
|
||||
std::vector<const BaseTurnChoice*>& GetInnerQueue(){
|
||||
std::vector<BaseTurnChoice*>& GetInnerQueue(){
|
||||
return _queue;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
namespace CreatureLib::Battling {
|
||||
class TurnOrdering {
|
||||
public:
|
||||
static void OrderChoices(std::vector<const BaseTurnChoice*>& vec, CreatureLib::Core::Random& rand);
|
||||
static void OrderChoices(std::vector<BaseTurnChoice*>& vec, CreatureLib::Core::Random& rand);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user