Make typelibrary be based around the hash value instead of conststring value.

This commit is contained in:
Deukhoofd 2020-02-29 15:54:02 +01:00
parent 4341efb54c
commit 671077259e
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 4 additions and 2 deletions

View File

@ -16,6 +16,7 @@ float TypeLibrary::GetSingleEffectiveness(uint8_t attacking, uint8_t defensive)
}
uint8_t TypeLibrary::GetTypeId(const ConstString& key) const { return _types.at(key); }
uint8_t TypeLibrary::GetTypeId(uint32_t s) const { return _types.at(s); }
uint8_t TypeLibrary::RegisterType(const ConstString& key) {
_types.insert({key, _types.size()});

View File

@ -8,13 +8,14 @@ using ConstString = Arbutils::CaseInsensitiveConstString;
namespace CreatureLib::Library {
class TypeLibrary {
std::unordered_map<ConstString, uint8_t> _types;
std::unordered_map<uint32_t, uint8_t> _types;
std::vector<std::vector<float>> _effectiveness;
public:
TypeLibrary(size_t initialCapacity = 20) : _types(std::unordered_map<ConstString, uint8_t>(initialCapacity)) {}
TypeLibrary(size_t initialCapacity = 20) : _types(std::unordered_map<uint32_t, uint8_t>(initialCapacity)) {}
uint8_t GetTypeId(const ConstString& s) const;
uint8_t GetTypeId(uint32_t s) const;
float GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const;
float GetEffectiveness(uint8_t attacking, const std::vector<uint8_t>& defensive) const;