Skip to content

Commit

Permalink
switch to robin-hood-map
Browse files Browse the repository at this point in the history
  • Loading branch information
powerof3 committed Nov 11, 2022
1 parent d7822f5 commit e76afed
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 25 deletions.
2 changes: 2 additions & 0 deletions SPID/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -202,6 +203,7 @@ target_link_libraries(
PRIVATE
${CommonLibName}::${CommonLibName}
frozen::frozen
robin_hood::robin_hood
)

target_precompile_headers(
Expand Down
18 changes: 5 additions & 13 deletions SPID/include/Defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,12 @@ namespace DATA
};
}

/// Trait that is used to infer default sorter for Forms.
template <class TForm>
struct form_sorter
{
using Sorter = std::less<TForm*>;
};

/// 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<RE::BGSKeyword>
{
using Sorter = KeywordDependencySorter;
};

using EventResult = RE::BSEventNotifyControl;

using FormIDPair = std::pair<std::optional<RE::FormID>,std::optional<std::string>>;
Expand Down Expand Up @@ -128,6 +115,11 @@ using StringFilters = std::array<StringVec, 4>;
using FormFilters = std::array<FormVec, 3>;
using LevelFilters = std::pair<ActorLevel, std::vector<SkillLevel>>;

template <class K, class D>
using Map = robin_hood::unordered_flat_map<K, D>;
template <class K>
using Set = robin_hood::unordered_flat_set<K>;

template <class Form>
struct FormData
{
Expand Down
1 change: 1 addition & 0 deletions SPID/include/PCH.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <ClibUtil/utils.hpp>
#include <SimpleIni.h>
#include <frozen/set.h>
#include <robin_hood.h>
#include <spdlog/sinks/basic_file_sink.h>
#include <srell.hpp>
#include <xbyak/xbyak.h>
Expand Down
18 changes: 9 additions & 9 deletions SPID/include/PCLevelMultManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(RE::TESForm&, IdxOrCount a_idx, bool)> a_fn) const;
void DumpDistributedEntries();

Expand All @@ -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<RE::MenuOpenCloseEvent>*) override;
EventResult ProcessEvent(const RE::MenuOpenCloseEvent* a_event, RE::BSTEventSource<RE::MenuOpenCloseEvent>*) override;

private:
Manager() = default;
Expand All @@ -70,20 +70,20 @@ namespace PCLevelMult
{
struct Entries
{
std::unordered_map<RE::FormID, std::set<std::uint32_t>> rejectedEntries{}; // Distributed formID, FormData vector index
std::set<std::pair<RE::FormID, IdxOrCount>> distributedEntries{}; // Distributed formID, distributed count/idx
Map<RE::FormID, Set<std::uint32_t>> rejectedEntries{}; // Distributed formID, FormData vector index
std::vector<std::pair<RE::FormID, IdxOrCount>> distributedEntries{}; // Distributed formID, distributed count/idx
};

LEVEL_CAP_STATE levelCapState{};
std::map<std::uint16_t, Entries> entries{}; // Actor Level, Entries
LEVEL_CAP_STATE levelCapState{};
Map<std::uint16_t, Entries> entries{}; // Actor Level, Entries
};

std::unordered_map<std::uint64_t, // PlayerID
std::unordered_map<RE::FormID, Data>> // NPC formID, Data
Map<std::uint64_t, // PlayerID
Map<RE::FormID, Data>> // NPC formID, Data
cache{};

std::uint64_t currentPlayerID{ 0 };
std::uint64_t oldPlayerID{ 0 };
std::uint64_t oldPlayerID{ 0 };

bool newGameStarted{ false };
};
Expand Down
6 changes: 3 additions & 3 deletions SPID/src/PCLevelMultManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(RE::TESForm&, IdxOrCount a_idx, bool)> a_fn) const
Expand Down
1 change: 1 addition & 0 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"clib-util",
"frozen",
"mergemapper",
"robin-hood-hashing",
"rsm-binary-io",
"simpleini",
"srell",
Expand Down

0 comments on commit e76afed

Please sign in to comment.