diff --git a/SPID/CMakeLists.txt b/SPID/CMakeLists.txt index fa562a9..df6aa8a 100644 --- a/SPID/CMakeLists.txt +++ b/SPID/CMakeLists.txt @@ -134,6 +134,7 @@ else () endif() find_package(frozen CONFIG REQUIRED) +find_package(robin_hood CONFIG REQUIRED) find_path(SIMPLEINI_INCLUDE_DIRS "ConvertUTF.c") find_path(SRELL_INCLUDE_DIRS "srell.hpp") @@ -202,6 +203,7 @@ target_link_libraries( PRIVATE ${CommonLibName}::${CommonLibName} frozen::frozen + robin_hood::robin_hood ) target_precompile_headers( diff --git a/SPID/include/Defs.h b/SPID/include/Defs.h index f3c7148..8f044e8 100644 --- a/SPID/include/Defs.h +++ b/SPID/include/Defs.h @@ -73,25 +73,12 @@ namespace DATA }; } -/// Trait that is used to infer default sorter for Forms. -template -struct form_sorter -{ - using Sorter = std::less; -}; - /// Custom ordering for keywords that ensures that dependent keywords are disitrbuted after the keywords that they depend on. struct KeywordDependencySorter { static bool sort(RE::BGSKeyword* a, RE::BGSKeyword* b); }; -template <> -struct form_sorter -{ - using Sorter = KeywordDependencySorter; -}; - using EventResult = RE::BSEventNotifyControl; using FormIDPair = std::pair,std::optional>; @@ -128,6 +115,11 @@ using StringFilters = std::array; using FormFilters = std::array; using LevelFilters = std::pair>; +template +using Map = robin_hood::unordered_flat_map; +template +using Set = robin_hood::unordered_flat_set; + template struct FormData { diff --git a/SPID/include/PCH.h b/SPID/include/PCH.h index c360f7e..5b7ebb7 100644 --- a/SPID/include/PCH.h +++ b/SPID/include/PCH.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/SPID/include/PCLevelMultManager.h b/SPID/include/PCLevelMultManager.h index 94a9e19..fe849b3 100644 --- a/SPID/include/PCLevelMultManager.h +++ b/SPID/include/PCLevelMultManager.h @@ -32,7 +32,7 @@ namespace PCLevelMult void DumpRejectedEntries(); [[nodiscard]] bool FindDistributedEntry(const Input& a_input); - bool InsertDistributedEntry(const Input& a_input, RE::FormID a_distributedFormID, IdxOrCount a_idx); + void InsertDistributedEntry(const Input& a_input, RE::FormID a_distributedFormID, IdxOrCount a_idx); void ForEachDistributedEntry(const Input& a_input, std::function a_fn) const; void DumpDistributedEntries(); @@ -48,7 +48,7 @@ namespace PCLevelMult static std::uint64_t get_game_playerID(); void remap_player_ids(std::uint64_t a_oldID, std::uint64_t a_newID); - EventResult ProcessEvent(const RE::MenuOpenCloseEvent* a_event, RE::BSTEventSource*) override; + EventResult ProcessEvent(const RE::MenuOpenCloseEvent* a_event, RE::BSTEventSource*) override; private: Manager() = default; @@ -70,20 +70,20 @@ namespace PCLevelMult { struct Entries { - std::unordered_map> rejectedEntries{}; // Distributed formID, FormData vector index - std::set> distributedEntries{}; // Distributed formID, distributed count/idx + Map> rejectedEntries{}; // Distributed formID, FormData vector index + std::vector> distributedEntries{}; // Distributed formID, distributed count/idx }; - LEVEL_CAP_STATE levelCapState{}; - std::map entries{}; // Actor Level, Entries + LEVEL_CAP_STATE levelCapState{}; + Map entries{}; // Actor Level, Entries }; - std::unordered_map> // NPC formID, Data + Map> // NPC formID, Data cache{}; std::uint64_t currentPlayerID{ 0 }; - std::uint64_t oldPlayerID{ 0 }; + std::uint64_t oldPlayerID{ 0 }; bool newGameStarted{ false }; }; diff --git a/SPID/src/PCLevelMultManager.cpp b/SPID/src/PCLevelMultManager.cpp index 1828037..6afd8df 100644 --- a/SPID/src/PCLevelMultManager.cpp +++ b/SPID/src/PCLevelMultManager.cpp @@ -123,13 +123,13 @@ namespace PCLevelMult return false; } - bool Manager::InsertDistributedEntry(const Input& a_input, RE::FormID a_distributedFormID, IdxOrCount a_idx) + void Manager::InsertDistributedEntry(const Input& a_input, RE::FormID a_distributedFormID, IdxOrCount a_idx) { if (a_input.noPlayerLevelDistribution) { - return false; + return; } - return cache[a_input.playerID][a_input.npcFormID].entries[a_input.npcLevel].distributedEntries.insert({ a_distributedFormID, a_idx }).second; + cache[a_input.playerID][a_input.npcFormID].entries[a_input.npcLevel].distributedEntries.push_back({ a_distributedFormID, a_idx }); } void Manager::ForEachDistributedEntry(const Input& a_input, std::function a_fn) const diff --git a/vcpkg.json b/vcpkg.json index 222ba36..4210170 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -6,6 +6,7 @@ "clib-util", "frozen", "mergemapper", + "robin-hood-hashing", "rsm-binary-io", "simpleini", "srell",