Browse Source

Switch to ankerl::unordered_dense

pull/7315/head
Gleb Mazovetskiy 2 years ago
parent
commit
e9c29fa806
  1. 7
      3rdParty/unordered_dense/CMakeLists.txt
  2. 4
      Source/debug.cpp
  3. 5
      Source/debug.h
  4. 7
      Source/dvlnet/zerotier_native.cpp
  5. 2
      Source/engine/render/dun_render.cpp
  6. 4
      Source/engine/render/dun_render.hpp
  7. 17
      Source/engine/render/scrollrt.cpp
  8. 4
      Source/engine/render/text_render.cpp
  9. 1
      Source/engine/trn.cpp
  10. 10
      Source/loadsave.cpp
  11. 6
      Source/lua/autocomplete.cpp
  12. 4
      Source/lua/lua.cpp
  13. 3
      Source/lua/modules/dev/towners.cpp
  14. 4
      Source/monstdat.cpp
  15. 18
      Source/msg.cpp
  16. 10
      Source/options.h
  17. 8
      Source/pfile.cpp
  18. 1
      Source/platform/vita/CMakeLists.txt
  19. 9
      Source/utils/language.cpp
  20. 6
      test/missiles_test.cpp

7
3rdParty/unordered_dense/CMakeLists.txt vendored

@ -1,21 +1,20 @@
include(functions/FetchContent_MakeAvailableExcludeFromAll) include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(FetchContent) include(FetchContent)
find_package(Patch REQUIRED)
set(unordered_dense_URL "https://github.com/martinus/unordered_dense/archive/refs/tags/v4.4.0.tar.gz") set(unordered_dense_URL "https://github.com/martinus/unordered_dense/archive/refs/tags/v4.4.0.tar.gz")
set(unordered_dense_HASH "f33c294a010540434b272754f937decf") set(unordered_dense_HASH "f33c294a010540434b272754f937decf")
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") if(MINGW_CROSS)
find_package(Patch REQUIRED)
FetchContent_Declare(unordered_dense FetchContent_Declare(unordered_dense
URL ${unordered_dense_URL} URL ${unordered_dense_URL}
URL_HASH MD5=${unordered_dense_HASH} URL_HASH MD5=${unordered_dense_HASH}
PATCH_COMMAND "${Patch_EXECUTABLE}" -p1 -N < "${CMAKE_CURRENT_LIST_DIR}/0001-Disable-PMR-support-for-mingw-std-threads-compat.patch" || true
) )
else() else()
FetchContent_Declare(unordered_dense FetchContent_Declare(unordered_dense
URL ${unordered_dense_URL} URL ${unordered_dense_URL}
URL_HASH MD5=${unordered_dense_HASH} URL_HASH MD5=${unordered_dense_HASH}
PATCH_COMMAND "${Patch_EXECUTABLE}" -p1 -N < "${CMAKE_CURRENT_LIST_DIR}/0001-Disable-PMR-support-for-mingw-std-threads-compat.patch" || true
) )
endif() endif()
FetchContent_MakeAvailableExcludeFromAll(unordered_dense) FetchContent_MakeAvailableExcludeFromAll(unordered_dense)

4
Source/debug.cpp

@ -10,6 +10,8 @@
#include <cstdint> #include <cstdint>
#include <cstdio> #include <cstdio>
#include <ankerl/unordered_dense.h>
#include "debug.h" #include "debug.h"
#include "automap.h" #include "automap.h"
@ -31,7 +33,7 @@ bool DebugGodMode = false;
bool DebugVision = false; bool DebugVision = false;
bool DebugPath = false; bool DebugPath = false;
bool DebugGrid = false; bool DebugGrid = false;
std::unordered_map<int, Point> DebugCoordsMap; ankerl::unordered_dense::map<int, Point> DebugCoordsMap;
bool DebugScrollViewEnabled = false; bool DebugScrollViewEnabled = false;
std::string debugTRN; std::string debugTRN;

5
Source/debug.h

@ -7,7 +7,8 @@
#include <cstdint> #include <cstdint>
#include <string_view> #include <string_view>
#include <unordered_map>
#include <ankerl/unordered_dense.h>
#include "diablo.h" #include "diablo.h"
#include "engine.h" #include "engine.h"
@ -22,7 +23,7 @@ extern bool DebugGodMode;
extern bool DebugVision; extern bool DebugVision;
extern bool DebugPath; extern bool DebugPath;
extern bool DebugGrid; extern bool DebugGrid;
extern std::unordered_map<int, Point> DebugCoordsMap; extern ankerl::unordered_dense::map<int, Point> DebugCoordsMap;
extern bool DebugScrollViewEnabled; extern bool DebugScrollViewEnabled;
extern std::string debugTRN; extern std::string debugTRN;
extern uint32_t glMid1Seed[NUMLEVELS]; extern uint32_t glMid1Seed[NUMLEVELS];

7
Source/dvlnet/zerotier_native.cpp

@ -1,8 +1,9 @@
#include "dvlnet/zerotier_native.h" #include "dvlnet/zerotier_native.h"
#include <SDL.h>
#include <atomic> #include <atomic>
#include <unordered_map>
#include <SDL.h>
#include <ankerl/unordered_dense.h>
#ifdef USE_SDL1 #ifdef USE_SDL1
#include "utils/sdl2_to_1_2_backports.h" #include "utils/sdl2_to_1_2_backports.h"
@ -46,7 +47,7 @@ std::atomic_bool zt_network_ready(false);
std::atomic_bool zt_node_online(false); std::atomic_bool zt_node_online(false);
std::atomic_bool zt_joined(false); std::atomic_bool zt_joined(false);
std::unordered_map<uint64_t, zts_event_t> ztPeerEvents; ankerl::unordered_dense::map<uint64_t, zts_event_t> ztPeerEvents;
#ifdef DVL_ZT_SYMLINK #ifdef DVL_ZT_SYMLINK
bool HasMultiByteChars(std::string_view path) bool HasMultiByteChars(std::string_view path)

2
Source/engine/render/dun_render.cpp

@ -1101,7 +1101,7 @@ void RenderBlackTileFull(uint8_t *DVL_RESTRICT dst, uint16_t dstPitch)
} // namespace } // namespace
#ifdef DUN_RENDER_STATS #ifdef DUN_RENDER_STATS
std::unordered_map<DunRenderType, size_t, DunRenderTypeHash> DunRenderStats; ankerl::unordered_dense::map<DunRenderType, size_t, DunRenderTypeHash> DunRenderStats;
std::string_view TileTypeToString(TileType tileType) std::string_view TileTypeToString(TileType tileType)
{ {

4
Source/engine/render/dun_render.hpp

@ -15,7 +15,7 @@
// #define DUN_RENDER_STATS // #define DUN_RENDER_STATS
#ifdef DUN_RENDER_STATS #ifdef DUN_RENDER_STATS
#include <unordered_map> #include <ankerl/unordered_dense.h>
#endif #endif
namespace devilution { namespace devilution {
@ -156,7 +156,7 @@ struct DunRenderTypeHash {
return std::hash<uint32_t> {}((1 < static_cast<uint8_t>(t.tileType)) | static_cast<uint8_t>(t.maskType)); return std::hash<uint32_t> {}((1 < static_cast<uint8_t>(t.tileType)) | static_cast<uint8_t>(t.maskType));
} }
}; };
extern std::unordered_map<DunRenderType, size_t, DunRenderTypeHash> DunRenderStats; extern ankerl::unordered_dense::map<DunRenderType, size_t, DunRenderTypeHash> DunRenderStats;
std::string_view TileTypeToString(TileType tileType); std::string_view TileTypeToString(TileType tileType);

17
Source/engine/render/scrollrt.cpp

@ -8,6 +8,8 @@
#include <cmath> #include <cmath>
#include <cstdint> #include <cstdint>
#include <ankerl/unordered_dense.h>
#include "DiabloUI/ui_flags.hpp" #include "DiabloUI/ui_flags.hpp"
#include "automap.h" #include "automap.h"
#include "controls/plrctrls.h" #include "controls/plrctrls.h"
@ -83,7 +85,7 @@ namespace {
/** /**
* @brief Contains all Missile at rendering position * @brief Contains all Missile at rendering position
*/ */
std::unordered_multimap<WorldTilePosition, Missile *> MissilesAtRenderingTile; ankerl::unordered_dense::map<WorldTilePosition, std::vector<Missile *>> MissilesAtRenderingTile;
/** /**
* @brief Could the missile (at the next game tick) collide? This method is a simplified version of CheckMissileCol (for example without random). * @brief Could the missile (at the next game tick) collide? This method is a simplified version of CheckMissileCol (for example without random).
@ -163,7 +165,7 @@ void UpdateMissilesRendererData()
for (auto &m : Missiles) { for (auto &m : Missiles) {
UpdateMissileRendererData(m); UpdateMissileRendererData(m);
MissilesAtRenderingTile.insert(std::make_pair(m.position.tileForRendering, &m)); MissilesAtRenderingTile[m.position.tileForRendering].push_back(&m);
} }
} }
@ -289,9 +291,10 @@ void DrawMissilePrivate(const Surface &out, const Missile &missile, Point target
*/ */
void DrawMissile(const Surface &out, WorldTilePosition tilePosition, Point targetBufferPosition, bool pre) void DrawMissile(const Surface &out, WorldTilePosition tilePosition, Point targetBufferPosition, bool pre)
{ {
const auto [begin, end] = MissilesAtRenderingTile.equal_range(tilePosition); const auto it = MissilesAtRenderingTile.find(tilePosition);
for (auto it = begin; it != end; ++it) { if (it == MissilesAtRenderingTile.end()) return;
DrawMissilePrivate(out, *it->second, targetBufferPosition, pre); for (Missile *missile : it->second) {
DrawMissilePrivate(out, *missile, targetBufferPosition, pre);
} }
} }
@ -900,6 +903,10 @@ void DrawTileContent(const Surface &out, Point tilePosition, Point targetBufferP
// Keep evaluating until MicroTiles can't affect screen // Keep evaluating until MicroTiles can't affect screen
rows += MicroTileLen; rows += MicroTileLen;
#ifdef _DEBUG
DebugCoordsMap.reserve(rows * columns);
#endif
for (int i = 0; i < rows; i++) { for (int i = 0; i < rows; i++) {
bool skip = false; bool skip = false;
for (int j = 0; j < columns; j++) { for (int j = 0; j < columns; j++) {

4
Source/engine/render/text_render.cpp

@ -9,10 +9,10 @@
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include <optional> #include <optional>
#include <unordered_map>
#include <utility> #include <utility>
#include <variant> #include <variant>
#include <ankerl/unordered_dense.h>
#include <fmt/core.h> #include <fmt/core.h>
#include "DiabloUI/diabloui.h" #include "DiabloUI/diabloui.h"
@ -39,7 +39,7 @@ namespace {
constexpr char32_t ZWSP = U'\u200B'; // Zero-width space constexpr char32_t ZWSP = U'\u200B'; // Zero-width space
std::unordered_map<uint32_t, OptionalOwnedClxSpriteList> Fonts; ankerl::unordered_dense::map<uint32_t, OptionalOwnedClxSpriteList> Fonts;
std::array<int, 6> FontSizes = { 12, 24, 30, 42, 46, 22 }; std::array<int, 6> FontSizes = { 12, 24, 30, 42, 46, 22 };
constexpr std::array<int, 6> LineHeights = { 12, 26, 38, 42, 50, 22 }; constexpr std::array<int, 6> LineHeights = { 12, 26, 38, 42, 50, 22 };

1
Source/engine/trn.cpp

@ -1,7 +1,6 @@
#include "engine/trn.hpp" #include "engine/trn.hpp"
#include <cstdint> #include <cstdint>
#include <unordered_map>
#include <fmt/format.h> #include <fmt/format.h>

10
Source/loadsave.cpp

@ -9,9 +9,9 @@
#include <cstdint> #include <cstdint>
#include <cstring> #include <cstring>
#include <numeric> #include <numeric>
#include <unordered_map>
#include <SDL.h> #include <SDL.h>
#include <ankerl/unordered_dense.h>
#include <fmt/core.h> #include <fmt/core.h>
#include "automap.h" #include "automap.h"
@ -1733,7 +1733,7 @@ void SavePortal(SaveHelper *file, int i)
* @return a map converting from runtime item indexes to the relative position in the save file, used by SaveDroppedItemLocations * @return a map converting from runtime item indexes to the relative position in the save file, used by SaveDroppedItemLocations
* @see SaveDroppedItemLocations * @see SaveDroppedItemLocations
*/ */
std::unordered_map<uint8_t, uint8_t> SaveDroppedItems(SaveHelper &file) ankerl::unordered_dense::map<uint8_t, uint8_t> SaveDroppedItems(SaveHelper &file)
{ {
// Vanilla Diablo/Hellfire initialise the ActiveItems and AvailableItems arrays based on saved data, so write valid values for compatibility // Vanilla Diablo/Hellfire initialise the ActiveItems and AvailableItems arrays based on saved data, so write valid values for compatibility
for (uint8_t i = 0; i < MAXITEMS; i++) for (uint8_t i = 0; i < MAXITEMS; i++)
@ -1741,7 +1741,9 @@ std::unordered_map<uint8_t, uint8_t> SaveDroppedItems(SaveHelper &file)
for (uint8_t i = 0; i < MAXITEMS; i++) for (uint8_t i = 0; i < MAXITEMS; i++)
file.WriteLE<uint8_t>((i + ActiveItemCount) % MAXITEMS); file.WriteLE<uint8_t>((i + ActiveItemCount) % MAXITEMS);
std::unordered_map<uint8_t, uint8_t> itemIndexes = { { 0, 0 } }; ankerl::unordered_dense::map<uint8_t, uint8_t> itemIndexes;
itemIndexes.reserve(ActiveItemCount + 1);
itemIndexes.emplace(0, 0);
for (uint8_t i = 0; i < ActiveItemCount; i++) { for (uint8_t i = 0; i < ActiveItemCount; i++) {
itemIndexes[ActiveItems[i] + 1] = i + 1; itemIndexes[ActiveItems[i] + 1] = i + 1;
SaveItem(file, Items[ActiveItems[i]]); SaveItem(file, Items[ActiveItems[i]]);
@ -1754,7 +1756,7 @@ std::unordered_map<uint8_t, uint8_t> SaveDroppedItems(SaveHelper &file)
* @param file interface to the save file * @param file interface to the save file
* @param itemIndexes a map converting from runtime item indexes to the relative position in the save file * @param itemIndexes a map converting from runtime item indexes to the relative position in the save file
*/ */
void SaveDroppedItemLocations(SaveHelper &file, const std::unordered_map<uint8_t, uint8_t> &itemIndexes) void SaveDroppedItemLocations(SaveHelper &file, const ankerl::unordered_dense::map<uint8_t, uint8_t> &itemIndexes)
{ {
for (int j = 0; j < MAXDUNY; j++) { for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) // NOLINT(modernize-loop-convert) for (int i = 0; i < MAXDUNX; i++) // NOLINT(modernize-loop-convert)

6
Source/lua/autocomplete.cpp

@ -5,9 +5,9 @@
#include <cstddef> #include <cstddef>
#include <string> #include <string>
#include <string_view> #include <string_view>
#include <unordered_set>
#include <vector> #include <vector>
#include <ankerl/unordered_dense.h>
#include <sol/sol.hpp> #include <sol/sol.hpp>
#include <sol/utility/to_string.hpp> #include <sol/utility/to_string.hpp>
@ -122,7 +122,7 @@ ValueInfo GetValueInfo(const sol::table &table, std::string_view key, const sol:
} }
void SuggestionsFromTable(const sol::table &table, std::string_view prefix, void SuggestionsFromTable(const sol::table &table, std::string_view prefix,
size_t maxSuggestions, std::unordered_set<LuaAutocompleteSuggestion> &out) size_t maxSuggestions, ankerl::unordered_dense::set<LuaAutocompleteSuggestion> &out)
{ {
for (const auto &[key, value] : table) { for (const auto &[key, value] : table) {
if (key.get_type() == sol::type::string) { if (key.get_type() == sol::type::string) {
@ -178,7 +178,7 @@ void GetLuaAutocompleteSuggestions(std::string_view text, const sol::environment
const std::string_view prefix = token.substr(dotPos + 1); const std::string_view prefix = token.substr(dotPos + 1);
token.remove_suffix(token.size() - (dotPos == std::string_view::npos ? 0 : dotPos)); token.remove_suffix(token.size() - (dotPos == std::string_view::npos ? 0 : dotPos));
std::unordered_set<LuaAutocompleteSuggestion> suggestions; ankerl::unordered_dense::set<LuaAutocompleteSuggestion> suggestions;
const auto addSuggestions = [&](const sol::table &table) { const auto addSuggestions = [&](const sol::table &table) {
SuggestionsFromTable(table, prefix, maxSuggestions, suggestions); SuggestionsFromTable(table, prefix, maxSuggestions, suggestions);
}; };

4
Source/lua/lua.cpp

@ -2,8 +2,8 @@
#include <optional> #include <optional>
#include <string_view> #include <string_view>
#include <unordered_map>
#include <ankerl/unordered_dense.h>
#include <sol/sol.hpp> #include <sol/sol.hpp>
#include <config.h> #include <config.h>
@ -30,7 +30,7 @@ namespace {
struct LuaState { struct LuaState {
sol::state sol = {}; sol::state sol = {};
sol::table commonPackages = {}; sol::table commonPackages = {};
std::unordered_map<std::string, sol::bytecode> compiledScripts = {}; ankerl::unordered_dense::segmented_map<std::string, sol::bytecode> compiledScripts = {};
sol::environment sandbox = {}; sol::environment sandbox = {};
sol::table events = {}; sol::table events = {};
}; };

3
Source/lua/modules/dev/towners.cpp

@ -3,6 +3,7 @@
#include <string> #include <string>
#include <ankerl/unordered_dense.h>
#include <sol/sol.hpp> #include <sol/sol.hpp>
#include "lua/metadoc.hpp" #include "lua/metadoc.hpp"
@ -14,7 +15,7 @@
namespace devilution { namespace devilution {
namespace { namespace {
std::unordered_map<std::string_view, _talker_id> TownerShortNameToTownerId = { ankerl::unordered_dense::map<std::string_view, _talker_id> TownerShortNameToTownerId = {
{ "griswold", _talker_id::TOWN_SMITH }, { "griswold", _talker_id::TOWN_SMITH },
{ "smith", _talker_id::TOWN_SMITH }, { "smith", _talker_id::TOWN_SMITH },
{ "pepin", _talker_id::TOWN_HEALER }, { "pepin", _talker_id::TOWN_HEALER },

4
Source/monstdat.cpp

@ -6,8 +6,8 @@
#include "monstdat.h" #include "monstdat.h"
#include <cstdint> #include <cstdint>
#include <unordered_map>
#include <ankerl/unordered_dense.h>
#include <expected.hpp> #include <expected.hpp>
#include "data/file.hpp" #include "data/file.hpp"
@ -475,7 +475,7 @@ void LoadMonstDat()
MonstersData.clear(); MonstersData.clear();
MonstersData.reserve(dataFile.numRecords()); MonstersData.reserve(dataFile.numRecords());
std::unordered_map<std::string, size_t> spritePathToId; ankerl::unordered_dense::map<std::string, size_t> spritePathToId;
for (DataFileRecord record : dataFile) { for (DataFileRecord record : dataFile) {
RecordReader reader { record, filename }; RecordReader reader { record, filename };
MonsterData &monster = MonstersData.emplace_back(); MonsterData &monster = MonstersData.emplace_back();

18
Source/msg.cpp

@ -8,8 +8,8 @@
#include <cstdint> #include <cstdint>
#include <list> #include <list>
#include <memory> #include <memory>
#include <unordered_map>
#include <ankerl/unordered_dense.h>
#include <fmt/format.h> #include <fmt/format.h>
#if !defined(UNPACKED_MPQS) || !defined(UNPACKED_SAVES) || !defined(NONET) #if !defined(UNPACKED_MPQS) || !defined(UNPACKED_SAVES) || !defined(NONET)
@ -218,8 +218,8 @@ struct DSpawnedMonster {
struct DLevel { struct DLevel {
TCmdPItem item[MAXITEMS]; TCmdPItem item[MAXITEMS];
std::unordered_map<WorldTilePosition, DObjectStr> object; ankerl::unordered_dense::map<WorldTilePosition, DObjectStr> object;
std::unordered_map<size_t, DSpawnedMonster> spawnedMonsters; ankerl::unordered_dense::map<size_t, DSpawnedMonster> spawnedMonsters;
DMonsterStr monster[MaxMonsters]; DMonsterStr monster[MaxMonsters];
}; };
@ -260,14 +260,14 @@ constexpr size_t MAX_CHUNKS = MAX_MULTIPLAYERLEVELS + 4;
uint32_t sgdwOwnerWait; uint32_t sgdwOwnerWait;
uint32_t sgdwRecvOffset; uint32_t sgdwRecvOffset;
int sgnCurrMegaPlayer; int sgnCurrMegaPlayer;
std::unordered_map<uint8_t, DLevel> DeltaLevels; ankerl::unordered_dense::map<uint8_t, DLevel> DeltaLevels;
uint8_t sbLastCmd; uint8_t sbLastCmd;
/** /**
* @brief buffer used to receive level deltas, size is the worst expected case assuming every object on a level was touched * @brief buffer used to receive level deltas, size is the worst expected case assuming every object on a level was touched
*/ */
std::byte sgRecvBuf[1U + sizeof(DLevel::item) + sizeof(uint8_t) + (sizeof(WorldTilePosition) + sizeof(_cmd_id)) * MAXOBJECTS + sizeof(DLevel::monster)]; std::byte sgRecvBuf[1U + sizeof(DLevel::item) + sizeof(uint8_t) + (sizeof(WorldTilePosition) + sizeof(_cmd_id)) * MAXOBJECTS + sizeof(DLevel::monster)];
_cmd_id sgbRecvCmd; _cmd_id sgbRecvCmd;
std::unordered_map<uint8_t, LocalLevel> LocalLevels; ankerl::unordered_dense::map<uint8_t, LocalLevel> LocalLevels;
DJunk sgJunk; DJunk sgJunk;
uint8_t sgbDeltaChunks; uint8_t sgbDeltaChunks;
std::list<TMegaPkt> MegaPktList; std::list<TMegaPkt> MegaPktList;
@ -504,7 +504,7 @@ size_t DeltaImportItem(const std::byte *src, TCmdPItem *dst)
return size; return size;
} }
std::byte *DeltaExportObject(std::byte *dst, const std::unordered_map<WorldTilePosition, DObjectStr> &src) std::byte *DeltaExportObject(std::byte *dst, const ankerl::unordered_dense::map<WorldTilePosition, DObjectStr> &src)
{ {
*dst++ = static_cast<std::byte>(src.size()); *dst++ = static_cast<std::byte>(src.size());
for (const auto &[position, obj] : src) { for (const auto &[position, obj] : src) {
@ -516,7 +516,7 @@ std::byte *DeltaExportObject(std::byte *dst, const std::unordered_map<WorldTileP
return dst; return dst;
} }
const std::byte *DeltaImportObjects(const std::byte *src, std::unordered_map<WorldTilePosition, DObjectStr> &dst) const std::byte *DeltaImportObjects(const std::byte *src, ankerl::unordered_dense::map<WorldTilePosition, DObjectStr> &dst)
{ {
dst.clear(); dst.clear();
@ -562,7 +562,7 @@ size_t DeltaImportMonster(const std::byte *src, DMonsterStr *dst)
return size; return size;
} }
std::byte *DeltaExportSpawnedMonsters(std::byte *dst, const std::unordered_map<size_t, DSpawnedMonster> &spawnedMonsters) std::byte *DeltaExportSpawnedMonsters(std::byte *dst, const ankerl::unordered_dense::map<size_t, DSpawnedMonster> &spawnedMonsters)
{ {
auto &size = *reinterpret_cast<uint16_t *>(dst); auto &size = *reinterpret_cast<uint16_t *>(dst);
size = static_cast<uint16_t>(spawnedMonsters.size()); size = static_cast<uint16_t>(spawnedMonsters.size());
@ -580,7 +580,7 @@ std::byte *DeltaExportSpawnedMonsters(std::byte *dst, const std::unordered_map<s
return dst; return dst;
} }
const std::byte *DeltaImportSpawnedMonsters(const std::byte *src, std::unordered_map<size_t, DSpawnedMonster> &spawnedMonsters) const std::byte *DeltaImportSpawnedMonsters(const std::byte *src, ankerl::unordered_dense::map<size_t, DSpawnedMonster> &spawnedMonsters)
{ {
uint16_t size = *reinterpret_cast<const uint16_t *>(src); uint16_t size = *reinterpret_cast<const uint16_t *>(src);
src += sizeof(uint16_t); src += sizeof(uint16_t);

10
Source/options.h

@ -6,9 +6,9 @@
#include <forward_list> #include <forward_list>
#include <optional> #include <optional>
#include <string_view> #include <string_view>
#include <unordered_map>
#include <SDL_version.h> #include <SDL_version.h>
#include <ankerl/unordered_dense.h>
#include "controls/controller.h" #include "controls/controller.h"
#include "controls/controller_buttons.h" #include "controls/controller_buttons.h"
@ -708,9 +708,9 @@ struct KeymapperOptions : OptionCategoryBase {
private: private:
std::forward_list<Action> actions; std::forward_list<Action> actions;
std::unordered_map<uint32_t, std::reference_wrapper<Action>> keyIDToAction; ankerl::unordered_dense::segmented_map<uint32_t, std::reference_wrapper<Action>> keyIDToAction;
std::unordered_map<uint32_t, std::string> keyIDToKeyName; ankerl::unordered_dense::segmented_map<uint32_t, std::string> keyIDToKeyName;
std::unordered_map<std::string, uint32_t> keyNameToKeyID; ankerl::unordered_dense::segmented_map<std::string, uint32_t> keyNameToKeyID;
}; };
/** The Padmapper maps gamepad buttons to actions. */ /** The Padmapper maps gamepad buttons to actions. */
@ -782,7 +782,7 @@ private:
std::forward_list<Action> actions; std::forward_list<Action> actions;
std::array<const Action *, enum_size<ControllerButton>::value> buttonToReleaseAction; std::array<const Action *, enum_size<ControllerButton>::value> buttonToReleaseAction;
std::array<std::string, enum_size<ControllerButton>::value> buttonToButtonName; std::array<std::string, enum_size<ControllerButton>::value> buttonToButtonName;
std::unordered_map<std::string, ControllerButton> buttonNameToButton; ankerl::unordered_dense::segmented_map<std::string, ControllerButton> buttonNameToButton;
bool committed = false; bool committed = false;
const Action *FindAction(ControllerButton button) const; const Action *FindAction(ControllerButton button) const;

8
Source/pfile.cpp

@ -8,8 +8,8 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <string_view> #include <string_view>
#include <unordered_map>
#include <ankerl/unordered_dense.h>
#include <fmt/core.h> #include <fmt/core.h>
#include "codec.h" #include "codec.h"
@ -273,7 +273,7 @@ inline bool string_ends_with(std::string_view value, std::string_view suffix)
return std::equal(suffix.rbegin(), suffix.rend(), value.rbegin()); return std::equal(suffix.rbegin(), suffix.rend(), value.rbegin());
} }
void CreateDetailDiffs(std::string_view prefix, std::string_view memoryMapFile, CompareInfo &compareInfoReference, CompareInfo &compareInfoActual, std::unordered_map<std::string, size_t> &foundDiffs) void CreateDetailDiffs(std::string_view prefix, std::string_view memoryMapFile, CompareInfo &compareInfoReference, CompareInfo &compareInfoActual, ankerl::unordered_dense::segmented_map<std::string, size_t> &foundDiffs)
{ {
// Note: Detail diffs are currently only supported in unit tests // Note: Detail diffs are currently only supported in unit tests
std::string memoryMapFileAssetName = StrCat(paths::BasePath(), "/test/fixtures/memory_map/", memoryMapFile, ".txt"); std::string memoryMapFileAssetName = StrCat(paths::BasePath(), "/test/fixtures/memory_map/", memoryMapFile, ".txt");
@ -295,7 +295,7 @@ void CreateDetailDiffs(std::string_view prefix, std::string_view memoryMapFile,
const std::string_view buffer(reinterpret_cast<const char *>(memoryMapFileData.get()), readBytes); const std::string_view buffer(reinterpret_cast<const char *>(memoryMapFileData.get()), readBytes);
std::unordered_map<std::string, CompareCounter> counter; ankerl::unordered_dense::segmented_map<std::string, CompareCounter> counter;
auto getCounter = [&](const std::string &counterAsString) { auto getCounter = [&](const std::string &counterAsString) {
auto it = counter.find(counterAsString); auto it = counter.find(counterAsString);
@ -482,7 +482,7 @@ HeroCompareResult CompareSaves(const std::string &actualSavePath, const std::str
StrAppend(message, "file \"", compareTarget.fileName, "\" has different content."); StrAppend(message, "file \"", compareTarget.fileName, "\" has different content.");
if (!logDetails) if (!logDetails)
continue; continue;
std::unordered_map<std::string, size_t> foundDiffs; ankerl::unordered_dense::segmented_map<std::string, size_t> foundDiffs;
CompareInfo compareInfoReference = { fileDataReference, 0, fileSizeReference, compareTarget.isTownLevel, fileSizeReference != 0 }; CompareInfo compareInfoReference = { fileDataReference, 0, fileSizeReference, compareTarget.isTownLevel, fileSizeReference != 0 };
CompareInfo compareInfoActual = { fileDataActual, 0, fileSizeActual, compareTarget.isTownLevel, fileSizeActual != 0 }; CompareInfo compareInfoActual = { fileDataActual, 0, fileSizeActual, compareTarget.isTownLevel, fileSizeActual != 0 };
CreateDetailDiffs(compareTarget.fileName, compareTarget.memoryMapFileName, compareInfoReference, compareInfoActual, foundDiffs); CreateDetailDiffs(compareTarget.fileName, compareTarget.memoryMapFileName, compareInfoReference, compareInfoActual, foundDiffs);

1
Source/platform/vita/CMakeLists.txt

@ -24,4 +24,5 @@ target_link_libraries(libdevilutionx_vita PUBLIC
SceNet_stub SceNet_stub
SceNetCtl_stub SceNetCtl_stub
tl tl
unordered_dense::unordered_dense
) )

9
Source/utils/language.cpp

@ -3,9 +3,9 @@
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
#include <string_view> #include <string_view>
#include <unordered_map>
#include <vector> #include <vector>
#include <ankerl/unordered_dense.h>
#include <function_ref.hpp> #include <function_ref.hpp>
#include "engine/assets.hpp" #include "engine/assets.hpp"
@ -38,9 +38,11 @@ std::unique_ptr<char[]> translationValues;
using TranslationRef = uint32_t; using TranslationRef = uint32_t;
struct StringHash { struct StringHash {
using is_avalanching = void;
size_t operator()(const char *str) const noexcept size_t operator()(const char *str) const noexcept
{ {
return std::hash<std::string_view> {}(str); return ankerl::unordered_dense::detail::wyhash::hash(str, std::string_view { str }.size());
} }
}; };
@ -51,7 +53,7 @@ struct StringEq {
} }
}; };
std::vector<std::unordered_map<const char *, TranslationRef, StringHash, StringEq>> translation = { {}, {} }; std::vector<ankerl::unordered_dense::map<const char *, TranslationRef, StringHash, StringEq>> translation = { {}, {} };
constexpr uint32_t TranslationRefOffsetBits = 19; constexpr uint32_t TranslationRefOffsetBits = 19;
constexpr uint32_t TranslationRefSizeBits = 32 - TranslationRefOffsetBits; // 13 constexpr uint32_t TranslationRefSizeBits = 32 - TranslationRefOffsetBits; // 13
@ -481,6 +483,7 @@ void LanguageInitialize()
char *keyPtr = &translationKeys[0]; char *keyPtr = &translationKeys[0];
char *valuePtr = &translationValues[0]; char *valuePtr = &translationValues[0];
translation[0].reserve(head.nbMappings - 1);
for (uint32_t i = 1; i < head.nbMappings; i++) { for (uint32_t i = 1; i < head.nbMappings; i++) {
if (readWholeFile if (readWholeFile
? ReadEntry(data.get(), fileSize, src[i], keyPtr) && ReadEntry(data.get(), fileSize, dst[i], valuePtr) ? ReadEntry(data.get(), fileSize, src[i], keyPtr) && ReadEntry(data.get(), fileSize, dst[i], valuePtr)

6
test/missiles_test.cpp

@ -1,6 +1,8 @@
#include <gmock/gmock.h> #include <gmock/gmock.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <ankerl/unordered_dense.h>
#include "engine/random.hpp" #include "engine/random.hpp"
#include "missiles.h" #include "missiles.h"
@ -13,7 +15,7 @@ using ::testing::UnorderedElementsAre;
void TestArrowRotatesUniformly(Missile &missile, int startingFrame, int leftFrame, int rightFrame) void TestArrowRotatesUniformly(Missile &missile, int startingFrame, int leftFrame, int rightFrame)
{ {
std::unordered_map<int, unsigned> observed {}; ankerl::unordered_dense::map<int, unsigned> observed {};
for (auto i = 0; i < 100; i++) { for (auto i = 0; i < 100; i++) {
missile._miAnimFrame = startingFrame; missile._miAnimFrame = startingFrame;
TestRotateBlockedMissile(missile); TestRotateBlockedMissile(missile);
@ -25,7 +27,7 @@ void TestArrowRotatesUniformly(Missile &missile, int startingFrame, int leftFram
void TestAnimatedMissileRotatesUniformly(Missile &missile, int startingDir, int leftDir, int rightDir) void TestAnimatedMissileRotatesUniformly(Missile &missile, int startingDir, int leftDir, int rightDir)
{ {
std::unordered_map<int, unsigned> observed {}; ankerl::unordered_dense::map<int, unsigned> observed {};
for (auto i = 0; i < 100; i++) { for (auto i = 0; i < 100; i++) {
missile._mimfnum = startingDir; missile._mimfnum = startingDir;
TestRotateBlockedMissile(missile); TestRotateBlockedMissile(missile);

Loading…
Cancel
Save