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:
@@ -33,10 +33,10 @@ void Battle::CheckChoicesSetAndRun() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
auto choices = std::vector<const BaseTurnChoice*>(_numberOfSides * _creaturesPerSide);
|
||||
auto choices = std::vector<BaseTurnChoice*>(_numberOfSides * _creaturesPerSide);
|
||||
auto i = 0;
|
||||
for (auto side: _sides){
|
||||
for (const BaseTurnChoice* choice: side->GetChoices()){
|
||||
for (BaseTurnChoice* choice: side->GetChoices()){
|
||||
if (choice->GetKind() == TurnChoiceKind::Attack){
|
||||
auto attack = dynamic_cast<const AttackTurnChoice*>(choice)->GetAttack();
|
||||
uint8_t uses = 1;
|
||||
@@ -93,6 +93,6 @@ void Battle::FillRecall(uint8_t side, uint8_t, Creature *c) {
|
||||
}
|
||||
}
|
||||
|
||||
void Battle::GetActiveScripts(ScriptAggregator &aggr) const {
|
||||
aggr.Add(&_volatile);
|
||||
void Battle::GetActiveScripts(std::vector<ScriptWrapper> &scripts) {
|
||||
scripts.emplace_back(&_volatile);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace CreatureLib::Battling {
|
||||
|
||||
void FillRecall(uint8_t side, uint8_t, Creature* c);
|
||||
|
||||
void GetActiveScripts(ScriptAggregator &aggr) const override;
|
||||
void GetActiveScripts(std::vector<ScriptWrapper> &scripts) override;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,11 @@ void BattleSide::ResetChoices() {
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<const BaseTurnChoice *>& BattleSide::GetChoices() const{
|
||||
const std::vector<BaseTurnChoice *>& BattleSide::GetChoices() const{
|
||||
return _choices;
|
||||
}
|
||||
|
||||
void BattleSide::SetChoice(const BaseTurnChoice *choice) {
|
||||
void BattleSide::SetChoice(BaseTurnChoice *choice) {
|
||||
auto find = std::find(_creatures.begin(), _creatures.end(), choice->GetUser());
|
||||
if (find ==_creatures.end())
|
||||
throw CreatureException("User not found");
|
||||
@@ -41,7 +41,7 @@ Creature *BattleSide::GetCreature(uint8_t index) const {
|
||||
return _creatures[index];
|
||||
}
|
||||
|
||||
void BattleSide::GetActiveScripts(ScriptAggregator &aggr) const {
|
||||
aggr.Add(&_volatile);
|
||||
_battle->GetActiveScripts(aggr);
|
||||
void BattleSide::GetActiveScripts(std::vector<ScriptWrapper> &scripts) {
|
||||
scripts.emplace_back(&_volatile);
|
||||
_battle->GetActiveScripts(scripts);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace CreatureLib::Battling{
|
||||
class BattleSide : public ScriptSource{
|
||||
uint8_t _creaturesPerSide;
|
||||
std::vector<Creature*> _creatures;
|
||||
std::vector<const BaseTurnChoice*> _choices;
|
||||
std::vector<BaseTurnChoice*> _choices;
|
||||
uint8_t _choicesSet = 0;
|
||||
ScriptSet _volatile;
|
||||
Battle* _battle;
|
||||
@@ -21,9 +21,9 @@ namespace CreatureLib::Battling{
|
||||
}
|
||||
|
||||
[[nodiscard]] bool AllChoicesSet() const;
|
||||
[[nodiscard]] const std::vector<const BaseTurnChoice*>& GetChoices() const;
|
||||
[[nodiscard]] const std::vector<BaseTurnChoice*>& GetChoices() const;
|
||||
|
||||
void SetChoice(const BaseTurnChoice* choice);
|
||||
void SetChoice(BaseTurnChoice* choice);
|
||||
void ResetChoices();
|
||||
|
||||
void SetCreature(Creature* creature, uint8_t index);
|
||||
@@ -31,7 +31,7 @@ namespace CreatureLib::Battling{
|
||||
Creature* GetCreature(uint8_t index) const;
|
||||
bool CreatureOnSide(const Creature* creature) const;
|
||||
|
||||
void GetActiveScripts(ScriptAggregator &aggr) const override;
|
||||
void GetActiveScripts(std::vector<ScriptWrapper> &scripts) override;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include "Creature.hpp"
|
||||
#include "../Models/Battle.hpp"
|
||||
|
||||
@@ -20,9 +21,9 @@ Battling::Creature::Creature(const Library::CreatureSpecies* species, const Libr
|
||||
__Gender(gender),
|
||||
__Coloring(coloring),
|
||||
__HeldItem(heldItem),
|
||||
_nickname(nickname),
|
||||
_nickname(std::move(nickname)),
|
||||
_talentIndex(talent),
|
||||
_attacks(attacks)
|
||||
_attacks(std::move(attacks))
|
||||
{}
|
||||
|
||||
|
||||
@@ -140,8 +141,8 @@ bool Battling::Creature::HasType(uint8_t type) const {
|
||||
return std::find(t.begin(), t.end(), type) != t.end();
|
||||
}
|
||||
|
||||
void Battling::Creature::GetActiveScripts(Battling::ScriptAggregator &aggr) const {
|
||||
aggr.Add(_status);
|
||||
aggr.Add(&_volatile);
|
||||
_side->GetActiveScripts(aggr);
|
||||
void Battling::Creature::GetActiveScripts(std::vector<ScriptWrapper> &scripts) {
|
||||
scripts.emplace_back(&_status);
|
||||
scripts.emplace_back(&_volatile);
|
||||
_side->GetActiveScripts(scripts);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,8 @@ namespace CreatureLib::Battling{
|
||||
|
||||
class Creature : public ScriptSource{
|
||||
GetProperty(const Library::CreatureSpecies*, Species);
|
||||
GetProperty(const Library::SpeciesVariant*, Variant);
|
||||
GetProperty(const Library::SpeciesVariant*, Variant)
|
||||
|
||||
GetProperty(uint8_t, Level);
|
||||
GetProperty(uint32_t, Experience);
|
||||
GetProperty(Core::StatisticSet<uint8_t >, StatExperience);
|
||||
@@ -67,7 +68,7 @@ namespace CreatureLib::Battling{
|
||||
[[nodiscard]] const std::vector<uint8_t>& GetTypes() const;
|
||||
[[nodiscard]] bool HasType(uint8_t type) const;
|
||||
|
||||
void GetActiveScripts(ScriptAggregator& aggr) const override;
|
||||
void GetActiveScripts(std::vector<ScriptWrapper> &scripts) override;
|
||||
|
||||
//region Stat APIs
|
||||
|
||||
@@ -85,6 +86,7 @@ namespace CreatureLib::Battling{
|
||||
void RecalculateBoostedStats();
|
||||
void RecalculateFlatStat(Core::Statistic);
|
||||
void RecalculateBoostedStat(Core::Statistic);
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
|
||||
@@ -89,8 +89,10 @@ namespace CreatureLib::Battling {
|
||||
return _attack;
|
||||
}
|
||||
|
||||
void GetActiveScripts(ScriptAggregator &aggr) const override {
|
||||
aggr.Add(_script);
|
||||
protected:
|
||||
void GetActiveScripts(std::vector<ScriptWrapper> &scripts) override {
|
||||
scripts.emplace_back(&_script);
|
||||
GetUser()->GetActiveScripts(scripts);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user