Performance improvements for battle and creature AddVolatileScript methods when passing a string as parameter.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Instead of loading a script, then passing it to the ScriptSet class and checking if it already exists before invoking stack, we now check whether the ScriptSet has that script. If one already exists we just invoke stack on it, if not we continue to the process of creating a new script instance.
This commit is contained in:
parent
142889ad8a
commit
645ba95bbc
|
@ -77,7 +77,12 @@ namespace CreatureLib::Battling {
|
||||||
const std::vector<BattleSide*>& GetSides() const { return _sides; }
|
const std::vector<BattleSide*>& GetSides() const { return _sides; }
|
||||||
Script* GetVolatileScript(const std::string& key) const { return _volatile.Get(key); }
|
Script* GetVolatileScript(const std::string& key) const { return _volatile.Get(key); }
|
||||||
void AddVolatileScript(const std::string& key) {
|
void AddVolatileScript(const std::string& key) {
|
||||||
auto script = _library->LoadScript(ScriptCategory::Battle, key);
|
auto script = _volatile.Get(key);
|
||||||
|
if (script != nullptr) {
|
||||||
|
script->Stack();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
script = _library->LoadScript(ScriptCategory::Battle, key);
|
||||||
return _volatile.Add(script);
|
return _volatile.Add(script);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -186,7 +186,12 @@ void Battling::Creature::SetHeldItem(const std::string& itemName) {
|
||||||
_heldItem = item;
|
_heldItem = item;
|
||||||
}
|
}
|
||||||
void Battling::Creature::AddVolatileScript(const std::string& name) {
|
void Battling::Creature::AddVolatileScript(const std::string& name) {
|
||||||
auto script = this->_library->LoadScript(ScriptCategory::Creature, name);
|
auto script = _volatile.Get(name);
|
||||||
|
if (script != nullptr) {
|
||||||
|
script->Stack();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
script = this->_library->LoadScript(ScriptCategory::Creature, name);
|
||||||
_volatile.Add(script);
|
_volatile.Add(script);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue