Performance improvement for collecting scripts, by reserving size in ScriptSource.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
3b1c0e84e1
commit
734d056449
|
@ -85,6 +85,7 @@ bool Battle::CreatureInField(const Creature* creature) const {
|
||||||
|
|
||||||
void Battle::ForceRecall(uint8_t side, uint8_t index) { _sides[side]->SetCreature(nullptr, index); }
|
void Battle::ForceRecall(uint8_t side, uint8_t index) { _sides[side]->SetCreature(nullptr, index); }
|
||||||
|
|
||||||
|
size_t Battle::ScriptCount() const { return 1; }
|
||||||
void Battle::GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) {
|
void Battle::GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) {
|
||||||
scripts.Append(ScriptWrapper::FromSet(&_volatile));
|
scripts.Append(ScriptWrapper::FromSet(&_volatile));
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,6 +81,7 @@ namespace CreatureLib::Battling {
|
||||||
void SwitchCreature(uint8_t side, uint8_t index, Creature* c);
|
void SwitchCreature(uint8_t side, uint8_t index, Creature* c);
|
||||||
bool CanSlotBeFilled(uint8_t side, uint8_t index) const;
|
bool CanSlotBeFilled(uint8_t side, uint8_t index) const;
|
||||||
|
|
||||||
|
size_t ScriptCount() const override;
|
||||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override;
|
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override;
|
||||||
|
|
||||||
void ValidateBattleState();
|
void ValidateBattleState();
|
||||||
|
|
|
@ -73,6 +73,8 @@ void BattleSide::GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& sc
|
||||||
scripts.Append(ScriptWrapper::FromSet(&_volatile));
|
scripts.Append(ScriptWrapper::FromSet(&_volatile));
|
||||||
_battle->GetActiveScripts(scripts);
|
_battle->GetActiveScripts(scripts);
|
||||||
}
|
}
|
||||||
|
size_t BattleSide::ScriptCount() const { return _battle->ScriptCount() + 1; }
|
||||||
|
|
||||||
uint8_t BattleSide::GetRandomCreatureIndex() {
|
uint8_t BattleSide::GetRandomCreatureIndex() {
|
||||||
// TODO: Consider adding parameter to only get index for available creatures.
|
// TODO: Consider adding parameter to only get index for available creatures.
|
||||||
AssertNotNull(_battle)
|
AssertNotNull(_battle)
|
||||||
|
|
|
@ -48,6 +48,7 @@ namespace CreatureLib::Battling {
|
||||||
Creature* GetCreature(uint8_t index) const;
|
Creature* GetCreature(uint8_t index) const;
|
||||||
bool CreatureOnSide(const Creature* creature) const;
|
bool CreatureOnSide(const Creature* creature) const;
|
||||||
|
|
||||||
|
size_t ScriptCount() const override;
|
||||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override;
|
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override;
|
||||||
|
|
||||||
const List<Creature*>& GetCreatures() { return _creatures; }
|
const List<Creature*>& GetCreatures() { return _creatures; }
|
||||||
|
|
|
@ -166,6 +166,14 @@ bool Battling::Creature::HasType(uint8_t type) const noexcept {
|
||||||
return std::find(t.begin(), t.end(), type) != t.end();
|
return std::find(t.begin(), t.end(), type) != t.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t Battling::Creature::ScriptCount() const {
|
||||||
|
auto c = 3;
|
||||||
|
if (_side != nullptr) {
|
||||||
|
c += _side->ScriptCount();
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
void Battling::Creature::GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) {
|
void Battling::Creature::GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) {
|
||||||
scripts.Append(ScriptWrapper::FromScript(&_activeTalent));
|
scripts.Append(ScriptWrapper::FromScript(&_activeTalent));
|
||||||
scripts.Append(ScriptWrapper::FromScript(&_status));
|
scripts.Append(ScriptWrapper::FromScript(&_status));
|
||||||
|
|
|
@ -122,6 +122,7 @@ namespace CreatureLib::Battling {
|
||||||
void MarkOpponentAsSeen(Creature* creature) { _seenOpponents.insert(creature); }
|
void MarkOpponentAsSeen(Creature* creature) { _seenOpponents.insert(creature); }
|
||||||
const std::unordered_set<Creature*>& GetSeenOpponents() const { return _seenOpponents; }
|
const std::unordered_set<Creature*>& GetSeenOpponents() const { return _seenOpponents; }
|
||||||
|
|
||||||
|
size_t ScriptCount() const override;
|
||||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override;
|
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override;
|
||||||
void ClearVolatileScripts();
|
void ClearVolatileScripts();
|
||||||
void AddVolatileScript(const ConstString& name);
|
void AddVolatileScript(const ConstString& name);
|
||||||
|
|
|
@ -80,6 +80,7 @@ namespace CreatureLib::Battling {
|
||||||
Creature* GetUser() noexcept { return _user; }
|
Creature* GetUser() noexcept { return _user; }
|
||||||
|
|
||||||
LearnedAttack* GetAttack() noexcept { return _attack; }
|
LearnedAttack* GetAttack() noexcept { return _attack; }
|
||||||
|
size_t ScriptCount() const override { return _user->ScriptCount() + 1; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
||||||
|
|
|
@ -18,6 +18,9 @@ namespace CreatureLib::Battling {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static constexpr size_t defaultCapacity = 8;
|
||||||
|
ScriptSet() : _scripts(defaultCapacity), _lookup(defaultCapacity){};
|
||||||
|
|
||||||
void Add(Script* script) {
|
void Add(Script* script) {
|
||||||
size_t v;
|
size_t v;
|
||||||
if (_lookup.TryGet(script->GetName(), v)) {
|
if (_lookup.TryGet(script->GetName(), v)) {
|
||||||
|
|
|
@ -16,8 +16,10 @@ namespace CreatureLib::Battling {
|
||||||
void ResetActiveScripts() { _areScriptsInitialized = false; }
|
void ResetActiveScripts() { _areScriptsInitialized = false; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
virtual size_t ScriptCount() const = 0;
|
||||||
const ScriptAggregator& GetScriptIterator() {
|
const ScriptAggregator& GetScriptIterator() {
|
||||||
if (!_areScriptsInitialized) {
|
if (!_areScriptsInitialized) {
|
||||||
|
_scripts.Reserve(ScriptCount());
|
||||||
GetActiveScripts(_scripts);
|
GetActiveScripts(_scripts);
|
||||||
_scriptsIterator = ScriptAggregator(_scripts);
|
_scriptsIterator = ScriptAggregator(_scripts);
|
||||||
_areScriptsInitialized = true;
|
_areScriptsInitialized = true;
|
||||||
|
|
|
@ -53,6 +53,7 @@ namespace CreatureLib::Battling {
|
||||||
const CreatureIndex& GetTarget() const noexcept { return _target; }
|
const CreatureIndex& GetTarget() const noexcept { return _target; }
|
||||||
|
|
||||||
Script* GetAttackScript() const noexcept { return _attackScript; }
|
Script* GetAttackScript() const noexcept { return _attackScript; }
|
||||||
|
size_t ScriptCount() const override { return 1 + GetUser()->ScriptCount(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
||||||
|
|
|
@ -10,6 +10,7 @@ namespace CreatureLib::Battling {
|
||||||
FleeTurnChoice(Creature* user) : BaseTurnChoice(user) {}
|
FleeTurnChoice(Creature* user) : BaseTurnChoice(user) {}
|
||||||
|
|
||||||
TurnChoiceKind GetKind() const noexcept override { return TurnChoiceKind ::Flee; }
|
TurnChoiceKind GetKind() const noexcept override { return TurnChoiceKind ::Flee; }
|
||||||
|
size_t ScriptCount() const override { return GetUser()->ScriptCount(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
||||||
|
|
|
@ -9,6 +9,7 @@ namespace CreatureLib::Battling {
|
||||||
PassTurnChoice(Creature* c) : BaseTurnChoice(c) {}
|
PassTurnChoice(Creature* c) : BaseTurnChoice(c) {}
|
||||||
|
|
||||||
TurnChoiceKind GetKind() const noexcept override { return TurnChoiceKind ::Pass; }
|
TurnChoiceKind GetKind() const noexcept override { return TurnChoiceKind ::Pass; }
|
||||||
|
size_t ScriptCount() const override { return GetUser()->ScriptCount(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
||||||
|
|
|
@ -13,6 +13,7 @@ namespace CreatureLib::Battling {
|
||||||
TurnChoiceKind GetKind() const noexcept final { return TurnChoiceKind::Switch; }
|
TurnChoiceKind GetKind() const noexcept final { return TurnChoiceKind::Switch; }
|
||||||
|
|
||||||
inline Creature* GetNewCreature() const noexcept { return _newCreature; }
|
inline Creature* GetNewCreature() const noexcept { return _newCreature; }
|
||||||
|
size_t ScriptCount() const override { return GetUser()->ScriptCount(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
||||||
|
|
|
@ -24,6 +24,7 @@ public:
|
||||||
Script* ScriptPtr = nullptr;
|
Script* ScriptPtr = nullptr;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
size_t ScriptCount() const override { return 1; }
|
||||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
||||||
scripts.Append(ScriptWrapper::FromScript(&ScriptPtr));
|
scripts.Append(ScriptWrapper::FromScript(&ScriptPtr));
|
||||||
}
|
}
|
||||||
|
@ -34,6 +35,7 @@ public:
|
||||||
ScriptSet Set;
|
ScriptSet Set;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
size_t ScriptCount() const override { return 1; }
|
||||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
||||||
scripts.Append(ScriptWrapper::FromSet(&Set));
|
scripts.Append(ScriptWrapper::FromSet(&Set));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue