From d75e5627f9c5d14dd25f2eae7cebe9ca6ff3f9b4 Mon Sep 17 00:00:00 2001 From: Asuro Date: Sun, 13 Apr 2025 01:46:36 +0200 Subject: [PATCH] stuff --- src/game/data/static/puzzle.dat | Bin 7030 -> 7432 bytes src/game/data/static/uiconfig.dat | Bin 6671 -> 6689 bytes src/game/util/HashMap.h | 91 ++++++++++++++++++++++++++++++ tools/minidef.exe | 2 +- 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 src/game/util/HashMap.h diff --git a/src/game/data/static/puzzle.dat b/src/game/data/static/puzzle.dat index bab034a5a17f48f908427bd9f37e1fed256c5766..41bdabf1bc13f42675b1d0b713214d6e24944fac 100644 GIT binary patch delta 581 zcmexn)?uX(91t4C$iTp$6_M}Ez`(;WL6m`E2_pl84Ld|^qQW8e)eNi*8yMIpPh|bg zA;ZAH(9V(-KKTu!13L=?GXo0)>tsWw>dEVvc$hO8geHFcJb452DgHVJUWRT49){@* zEDW<51SWp`yt#(8S%AkkKP5FMB(5i`u||S#K6p%qRPO)%*@U3V73(# zSnxk9!=5M~GiC;6W=@9O>yIKJqAU#jjA0hc3=9lh3^9B$Cm^EC44>LBoM2#NVBlkz z7G1FhBFfHCmf5qIfeGX{$$5YGK}6XYey-u%$j;2b%puKi{lVjZ5Mf4!`XWXb1_lNO z2!HZAahb_m#Kndyc7k|wNpYmziq*zo4Dx)NhOE8r_98nF2Jw+`*$s1h7zT+004F}x Ai2wiq delta 503 zcmeCM`evpO91t4C$iTp`aqq_K3=BLB6GRypCNVNF*swyxCMq0apUJ?=Fpq(K@dEVvcqUI`{Wf_6^C|uu2403r1|Ei11{Q`+ z27!qmKX0yKZ5G%pDCWwTz{J4JnWDC?7Ls24-eXhTQ9qB3Kys z8N)1?85kJ27-INhPB1fkYQJ!TfsuiMk6~JL#Ts^ovdo^v3``)$O3wSckB#By8qSR% zr*JS_fAIL<FOLXW?*1oFmo2MXLp@p2f`peGJdjF-+s;& MNqb4(G<%RZ09o0rH2?qr diff --git a/src/game/data/static/uiconfig.dat b/src/game/data/static/uiconfig.dat index db36b0735d54266e87e1cd5e293b54fbf61b488c..f62b36f98fda58d15802cd8aab0b935593c145e8 100644 GIT binary patch delta 108 zcmeA-S!gmrgmKA4(X-M8jGPRWjC>63j7$ujj2sLT8QB?TFtRetWn`axkm>p6CyXJ%)QXbQqSVbt#ci2*nHZQk OQ&ia*R<8{TVFUo379bS> delta 92 zcmZ2z(r+?BgmKbD(X-NVjGPSVjC>5Gj7$vWj2sO0jO+|;jI0dZjO>#SGCkk?gmDJ* uWC0--c18vUhD<}V%^$gTGfoU(+w8&KEU@{mxH%K=e=uNYSiLqVgb@I2cO0$& diff --git a/src/game/util/HashMap.h b/src/game/util/HashMap.h new file mode 100644 index 0000000..0c58670 --- /dev/null +++ b/src/game/util/HashMap.h @@ -0,0 +1,91 @@ +#include "bx/hash.h" +#include +#include + +template struct HashMapInsertResult +{ + T& Obj = nullptr; + bool ElementExists = false; +}; + +template struct HashMapInsertResultConst +{ + const T& Obj = nullptr; + bool ElementExists = false; +}; + +// BitSize 16 will make the HashTable ~200kb with 65k entries +template struct HashMapCore +{ + static constexpr uint32_t SlotCount = (1 << BitSize); + static constexpr uint32_t RequiredDataSize = SlotCount * sizeof(T); + + T* Data = nullptr; + uint32_t HashTable[SlotCount]{0}; + + // External array that should be RequiredDataSize bytes big + void Init(T* data, uint64_t dataSize) + { + Data = data; + assert(data != nullptr); + assert(dataSize == RequiredDataSize); + } + + bool Has(uint32_t hash) const + { + return HashTable[FindIdx(hash)] == hash; + } + + HashMapInsertResult Get(uint32_t hash) + { + uint16_t idx = FindIdx(hash); + return {Data[idx], HashTable[idx] == hash}; + } + + const T& Get(uint32_t hash) const + { + uint16_t idx = FindIdx(hash); + return {Data[idx], HashTable[idx] == hash}; + } + + bool Remove(uint32_t hash); // TODO: requires tombstones so later entries survive + + private: + uint16_t FindIdx(uint32_t hash) const + { + uint32_t mask = SlotCount - 1; + uint32_t idx = hash & mask; + uint32_t tableEntry = HashTable[idx]; + uint32_t stepCount = 0; + while (tableEntry != hash && tableEntry != 0 && stepCount < UINT16_MAX) + { + idx = (idx + 1) % SlotCount; + tableEntry = HashTable[idx]; + ++stepCount; + } + assert(stepCount < UINT16_MAX); + return idx; + } +}; + +namespace HashMapTests +{ + struct AAA + { + int X = 3; + int Y = 42; + }; + + inline void Test() + { + HashMapCore testMap; + AAA* backingData = new AAA[testMap.RequiredDataSize](); + testMap.Init(backingData, testMap.RequiredDataSize); + AAA test{}; + AAA test2{5, 6}; + testMap.Get(bx::hash(test)).Obj = test; + testMap.Get(bx::hash(test2)).Obj = test2; + delete[] backingData; + } + +} // namespace HashMapTests diff --git a/tools/minidef.exe b/tools/minidef.exe index 757f646..a6156c2 100644 --- a/tools/minidef.exe +++ b/tools/minidef.exe @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6e101b18da1ba1e37156b03bc19ba3ee488d6eb02acbf491063f1d1f56dddaad +oid sha256:8f183d74c5423fd3920916186d2065ea9b7373b6c4a0843f1802a35ed97fc8a1 size 167424