From 0859da7e6a7befe50f319470ca2bee2f3cdc4844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Mon, 23 May 2022 22:20:10 +0200 Subject: [PATCH] Use std::vector instead of sorted_array --- src/game/client/components/skins.cpp | 45 +++++++++++++++------------- src/game/client/components/skins.h | 3 +- src/game/client/skin.h | 4 +-- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/game/client/components/skins.cpp b/src/game/client/components/skins.cpp index 0b3936d44..067750c13 100644 --- a/src/game/client/components/skins.cpp +++ b/src/game/client/components/skins.cpp @@ -295,7 +295,7 @@ int CSkins::LoadSkin(const char *pName, CImageInfo &Info) Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "game", aBuf); } - m_aSkins.add(Skin); + m_aSkins.insert(std::lower_bound(m_aSkins.begin(), m_aSkins.end(), Skin), Skin); return 0; } @@ -324,24 +324,24 @@ void CSkins::OnInit() void CSkins::Refresh(TSkinLoadedCBFunc &&SkinLoadedFunc) { - for(int i = 0; i < m_aSkins.size(); ++i) + for(auto &Skin : m_aSkins) { - Graphics()->UnloadTexture(&m_aSkins[i].m_OriginalSkin.m_Body); - Graphics()->UnloadTexture(&m_aSkins[i].m_OriginalSkin.m_BodyOutline); - Graphics()->UnloadTexture(&m_aSkins[i].m_OriginalSkin.m_Feet); - Graphics()->UnloadTexture(&m_aSkins[i].m_OriginalSkin.m_FeetOutline); - Graphics()->UnloadTexture(&m_aSkins[i].m_OriginalSkin.m_Hands); - Graphics()->UnloadTexture(&m_aSkins[i].m_OriginalSkin.m_HandsOutline); - for(auto &Eye : m_aSkins[i].m_OriginalSkin.m_Eyes) + Graphics()->UnloadTexture(&Skin.m_OriginalSkin.m_Body); + Graphics()->UnloadTexture(&Skin.m_OriginalSkin.m_BodyOutline); + Graphics()->UnloadTexture(&Skin.m_OriginalSkin.m_Feet); + Graphics()->UnloadTexture(&Skin.m_OriginalSkin.m_FeetOutline); + Graphics()->UnloadTexture(&Skin.m_OriginalSkin.m_Hands); + Graphics()->UnloadTexture(&Skin.m_OriginalSkin.m_HandsOutline); + for(auto &Eye : Skin.m_OriginalSkin.m_Eyes) Graphics()->UnloadTexture(&Eye); - Graphics()->UnloadTexture(&m_aSkins[i].m_ColorableSkin.m_Body); - Graphics()->UnloadTexture(&m_aSkins[i].m_ColorableSkin.m_BodyOutline); - Graphics()->UnloadTexture(&m_aSkins[i].m_ColorableSkin.m_Feet); - Graphics()->UnloadTexture(&m_aSkins[i].m_ColorableSkin.m_FeetOutline); - Graphics()->UnloadTexture(&m_aSkins[i].m_ColorableSkin.m_Hands); - Graphics()->UnloadTexture(&m_aSkins[i].m_ColorableSkin.m_HandsOutline); - for(auto &Eye : m_aSkins[i].m_ColorableSkin.m_Eyes) + Graphics()->UnloadTexture(&Skin.m_ColorableSkin.m_Body); + Graphics()->UnloadTexture(&Skin.m_ColorableSkin.m_BodyOutline); + Graphics()->UnloadTexture(&Skin.m_ColorableSkin.m_Feet); + Graphics()->UnloadTexture(&Skin.m_ColorableSkin.m_FeetOutline); + Graphics()->UnloadTexture(&Skin.m_ColorableSkin.m_Hands); + Graphics()->UnloadTexture(&Skin.m_ColorableSkin.m_HandsOutline); + for(auto &Eye : Skin.m_ColorableSkin.m_Eyes) Graphics()->UnloadTexture(&Eye); } @@ -351,14 +351,14 @@ void CSkins::Refresh(TSkinLoadedCBFunc &&SkinLoadedFunc) SkinScanUser.m_pThis = this; SkinScanUser.m_SkinLoadedFunc = SkinLoadedFunc; Storage()->ListDirectory(IStorage::TYPE_ALL, "skins", SkinScan, &SkinScanUser); - if(!m_aSkins.size()) + if(m_aSkins.empty()) { Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "gameclient", "failed to load skins. folder='skins/'"); CSkin DummySkin; DummySkin.m_IsVanilla = true; str_copy(DummySkin.m_aName, "dummy", sizeof(DummySkin.m_aName)); DummySkin.m_BloodColor = ColorRGBA(1.0f, 1.0f, 1.0f); - m_aSkins.add(DummySkin); + m_aSkins.push_back(DummySkin); } } @@ -402,9 +402,12 @@ int CSkins::Find(const char *pName) int CSkins::FindImpl(const char *pName) { - auto r = ::find_binary(m_aSkins.all(), pName); - if(!r.empty()) - return &r.front() - m_aSkins.base_ptr(); + CSkin Needle; + mem_zero(&Needle, sizeof(Needle)); + str_copy(Needle.m_aName, pName, sizeof(Needle.m_aName)); + auto Range = std::equal_range(m_aSkins.begin(), m_aSkins.end(), Needle); + if(std::distance(Range.first, Range.second) == 1) + return Range.first - m_aSkins.begin(); if(str_comp(pName, "default") == 0) return -1; diff --git a/src/game/client/components/skins.h b/src/game/client/components/skins.h index e5b445243..22b85fbe0 100644 --- a/src/game/client/components/skins.h +++ b/src/game/client/components/skins.h @@ -8,6 +8,7 @@ #include #include #include +#include class CSkins : public CComponent { @@ -46,7 +47,7 @@ public: int Find(const char *pName); private: - sorted_array m_aSkins; + std::vector m_aSkins; sorted_array m_aDownloadSkins; char m_EventSkinPrefix[24]; diff --git a/src/game/client/skin.h b/src/game/client/skin.h index 9bdd366eb..e51ca71e8 100644 --- a/src/game/client/skin.h +++ b/src/game/client/skin.h @@ -130,9 +130,7 @@ struct CSkin SSkinMetrics m_Metrics; bool operator<(const CSkin &Other) const { return str_comp(m_aName, Other.m_aName) < 0; } - - bool operator<(const char *pOther) const { return str_comp(m_aName, pOther) < 0; } - bool operator==(const char *pOther) const { return !str_comp(m_aName, pOther); } + bool operator==(const CSkin &Other) const { return !str_comp(m_aName, Other.m_aName); } }; #endif