diff options
| author | Choupom <andycootlapin@hotmail.fr> | 2010-09-18 20:48:49 +0200 |
|---|---|---|
| committer | oy <Tom_Adams@web.de> | 2010-09-24 13:13:46 +0200 |
| commit | aa46c22e10f85285dae87454724d9b6ed161c9c3 (patch) | |
| tree | 92e85d4048a9d3cd072e10a63e451cc803451d24 /src/game/client/components | |
| parent | 21d14b9704f9ede9877d7b7861a897f55bf70fdc (diff) | |
| download | zcatch-aa46c22e10f85285dae87454724d9b6ed161c9c3.tar.gz zcatch-aa46c22e10f85285dae87454724d9b6ed161c9c3.zip | |
now put skins in an array to save memory
Diffstat (limited to 'src/game/client/components')
| -rw-r--r-- | src/game/client/components/skins.cpp | 28 | ||||
| -rw-r--r-- | src/game/client/components/skins.h | 16 |
2 files changed, 16 insertions, 28 deletions
diff --git a/src/game/client/components/skins.cpp b/src/game/client/components/skins.cpp index 73cf954d..b5cb8239 100644 --- a/src/game/client/components/skins.cpp +++ b/src/game/client/components/skins.cpp @@ -10,16 +10,11 @@ #include "skins.h" -CSkins::CSkins() -{ - m_NumSkins = 0; -} - void CSkins::SkinScan(const char *pName, int IsDir, void *pUser) { CSkins *pSelf = (CSkins *)pUser; int l = str_length(pName); - if(l < 4 || IsDir || pSelf->m_NumSkins == MAX_SKINS) + if(l < 4 || IsDir) return; if(str_comp(pName+l-4, ".png") != 0) return; @@ -34,7 +29,8 @@ void CSkins::SkinScan(const char *pName, int IsDir, void *pUser) return; } - pSelf->m_aSkins[pSelf->m_NumSkins].m_OrgTexture = pSelf->Graphics()->LoadTextureRaw(Info.m_Width, Info.m_Height, Info.m_Format, Info.m_pData, Info.m_Format, 0); + CSkin Skin; + Skin.m_OrgTexture = pSelf->Graphics()->LoadTextureRaw(Info.m_Width, Info.m_Height, Info.m_Format, Info.m_pData, Info.m_Format, 0); int BodySize = 96; // body size unsigned char *d = (unsigned char *)Info.m_pData; @@ -54,7 +50,7 @@ void CSkins::SkinScan(const char *pName, int IsDir, void *pUser) } } - pSelf->m_aSkins[pSelf->m_NumSkins].m_BloodColor = normalize(vec3(aColors[0], aColors[1], aColors[2])); + Skin.m_BloodColor = normalize(vec3(aColors[0], aColors[1], aColors[2])); } // create colorless version @@ -107,37 +103,37 @@ void CSkins::SkinScan(const char *pName, int IsDir, void *pUser) } } - pSelf->m_aSkins[pSelf->m_NumSkins].m_ColorTexture = pSelf->Graphics()->LoadTextureRaw(Info.m_Width, Info.m_Height, Info.m_Format, Info.m_pData, Info.m_Format, 0); + Skin.m_ColorTexture = pSelf->Graphics()->LoadTextureRaw(Info.m_Width, Info.m_Height, Info.m_Format, Info.m_pData, Info.m_Format, 0); mem_free(Info.m_pData); // set skin data - str_copy(pSelf->m_aSkins[pSelf->m_NumSkins].m_aName, pName, min((int)sizeof(pSelf->m_aSkins[pSelf->m_NumSkins].m_aName),l-3)); - str_format(aBuf, sizeof(aBuf), "load skin %s", pSelf->m_aSkins[pSelf->m_NumSkins].m_aName); + str_copy(Skin.m_aName, pName, min((int)sizeof(Skin.m_aName),l-3)); + str_format(aBuf, sizeof(aBuf), "load skin %s", Skin.m_aName); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "game", aBuf); - pSelf->m_NumSkins++; + pSelf->m_aSkins.add(Skin); } void CSkins::Init() { // load skins - m_NumSkins = 0; + m_aSkins.clear(); Storage()->ListDirectory(IStorage::TYPE_ALL, "skins", SkinScan, this); } int CSkins::Num() { - return m_NumSkins; + return m_aSkins.size(); } const CSkins::CSkin *CSkins::Get(int Index) { - return &m_aSkins[Index%m_NumSkins]; + return &m_aSkins[Index%m_aSkins.size()]; } int CSkins::Find(const char *pName) { - for(int i = 0; i < m_NumSkins; i++) + for(int i = 0; i < m_aSkins.size(); i++) { if(str_comp(m_aSkins[i].m_aName, pName) == 0) return i; diff --git a/src/game/client/components/skins.h b/src/game/client/components/skins.h index f733140f..08e8c5e0 100644 --- a/src/game/client/components/skins.h +++ b/src/game/client/components/skins.h @@ -1,6 +1,7 @@ #ifndef GAME_CLIENT_COMPONENTS_SKINS_H #define GAME_CLIENT_COMPONENTS_SKINS_H #include <base/vmath.h> +#include <base/tl/array.h> #include <game/client/component.h> class CSkins : public CComponent @@ -11,12 +12,9 @@ public: { int m_OrgTexture; int m_ColorTexture; - char m_aName[31]; - char m_aTerm[1]; + char m_aName[32]; vec3 m_BloodColor; - } ; - - CSkins(); + }; void Init(); @@ -26,13 +24,7 @@ public: int Find(const char *pName); private: - enum - { - MAX_SKINS=256, - }; - - CSkin m_aSkins[MAX_SKINS]; - int m_NumSkins; + array<CSkin> m_aSkins; static void SkinScan(const char *pName, int IsDir, void *pUser); }; |