Implements ConstString in several core places in the library, improving performance.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-02-27 18:23:23 +01:00
parent 1d3a8da99e
commit 412e0a4d63
17 changed files with 161 additions and 148 deletions

View File

@@ -5,8 +5,8 @@
using namespace CreatureLib::Battling;
CreateCreature* CreateCreature::WithVariant(std::string variant) {
this->_variant = std::move(variant);
CreateCreature* CreateCreature::WithVariant(const Arbutils::CaseInsensitiveConstString& variant) {
this->_variant = variant;
return this;
}
@@ -20,18 +20,19 @@ CreateCreature* CreateCreature::WithGender(Library::Gender gender) {
return this;
}
CreateCreature* CreateCreature::WithAttack(const std::string& attackName, AttackLearnMethod learnMethod) {
CreateCreature* CreateCreature::WithAttack(const Arbutils::CaseInsensitiveConstString& attackName,
AttackLearnMethod learnMethod) {
if (_attacks.size() >= _library->GetSettings()->GetMaximalMoves())
throw CreatureException("You have already set the maximum amount of allowed moves.");
auto attackData = _library->GetAttackLibrary()->Get(attackName.c_str());
auto attackData = _library->GetAttackLibrary()->Get(attackName);
_attacks.emplace_back(attackData, learnMethod);
return this;
}
Creature* CreateCreature::Create() {
auto rand = Arbutils::Random();
auto species = this->_library->GetSpeciesLibrary()->Get(this->_species.c_str());
auto species = this->_library->GetSpeciesLibrary()->Get(this->_species);
auto variant = species->GetVariant(this->_variant);
int8_t talent;
if (this->_talent.empty()) {
@@ -48,8 +49,8 @@ Creature* CreateCreature::Create() {
gender = species->GetRandomGender(rand);
}
const Library::Item* heldItem = nullptr;
if (!this->_heldItem.empty()) {
if (!_library->GetItemLibrary()->TryGet(this->_heldItem.c_str(), heldItem)) {
if (!this->_heldItem.Empty()) {
if (!_library->GetItemLibrary()->TryGet(this->_heldItem, heldItem)) {
throw CreatureException("Invalid held item.");
}
}