Tweaks and fixes for TypeLibrary

This commit is contained in:
Deukhoofd 2020-02-29 16:06:36 +01:00
parent 671077259e
commit 70ad3eb838
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
3 changed files with 19 additions and 8 deletions

View File

@ -47,16 +47,18 @@ namespace CreatureLib::Library {
return true; return true;
} }
inline const T* Get(const Arbutils::CaseInsensitiveConstString& name) const { [[nodiscard]] inline const T* Get(const Arbutils::CaseInsensitiveConstString& name) const {
return _values.at(name.GetHash()); return _values.at(name.GetHash());
} }
inline const T* Get(uint32_t hashedKey) const { return _values.at(hashedKey); } [[nodiscard]] inline const T* Get(uint32_t hashedKey) const { return _values.at(hashedKey); }
inline const T* operator[](const Arbutils::CaseInsensitiveConstString& name) const { return Get(name); } [[nodiscard]] inline const T* operator[](const Arbutils::CaseInsensitiveConstString& name) const {
inline const T* operator[](uint32_t hashedKey) const { return Get(hashedKey); } return Get(name);
inline const std::unordered_map<uint32_t, const T*>& GetIterator() const { return _values; } }
[[nodiscard]] inline const T* operator[](uint32_t hashedKey) const { return Get(hashedKey); }
[[nodiscard]] inline const std::unordered_map<uint32_t, const T*>& GetIterator() const { return _values; }
size_t GetCount() const { return _values.size(); } [[nodiscard]] size_t GetCount() const { return _values.size(); }
}; };
} }

View File

@ -26,6 +26,14 @@ uint8_t TypeLibrary::RegisterType(const ConstString& key) {
} }
return _types.size() - 1; return _types.size() - 1;
} }
uint8_t TypeLibrary::RegisterType(uint32_t key) {
_types.insert({key, _types.size()});
_effectiveness.resize(_types.size());
for (auto& eff : _effectiveness) {
eff.resize(_types.size(), 1);
}
return _types.size() - 1;
}
void TypeLibrary::SetEffectiveness(uint8_t attacking, uint8_t defensive, float effectiveness) { void TypeLibrary::SetEffectiveness(uint8_t attacking, uint8_t defensive, float effectiveness) {
_effectiveness[attacking][defensive] = effectiveness; _effectiveness[attacking][defensive] = effectiveness;

View File

@ -16,10 +16,11 @@ namespace CreatureLib::Library {
uint8_t GetTypeId(const ConstString& s) const; uint8_t GetTypeId(const ConstString& s) const;
uint8_t GetTypeId(uint32_t s) const; uint8_t GetTypeId(uint32_t s) const;
float GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const; [[nodiscard]] float GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const;
float GetEffectiveness(uint8_t attacking, const std::vector<uint8_t>& defensive) const; [[nodiscard]] float GetEffectiveness(uint8_t attacking, const std::vector<uint8_t>& defensive) const;
uint8_t RegisterType(const ConstString& typeName); uint8_t RegisterType(const ConstString& typeName);
uint8_t RegisterType(uint32_t typeHash);
void SetEffectiveness(uint8_t attacking, uint8_t defensive, float effectiveness); void SetEffectiveness(uint8_t attacking, uint8_t defensive, float effectiveness);
}; };
} }