now put skins in an array to save memory

This commit is contained in:
Choupom 2010-09-18 20:48:49 +02:00 committed by oy
parent 21d14b9704
commit aa46c22e10
3 changed files with 17 additions and 29 deletions

View file

@ -10,16 +10,11 @@
#include "skins.h" #include "skins.h"
CSkins::CSkins()
{
m_NumSkins = 0;
}
void CSkins::SkinScan(const char *pName, int IsDir, void *pUser) void CSkins::SkinScan(const char *pName, int IsDir, void *pUser)
{ {
CSkins *pSelf = (CSkins *)pUser; CSkins *pSelf = (CSkins *)pUser;
int l = str_length(pName); int l = str_length(pName);
if(l < 4 || IsDir || pSelf->m_NumSkins == MAX_SKINS) if(l < 4 || IsDir)
return; return;
if(str_comp(pName+l-4, ".png") != 0) if(str_comp(pName+l-4, ".png") != 0)
return; return;
@ -34,7 +29,8 @@ void CSkins::SkinScan(const char *pName, int IsDir, void *pUser)
return; 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 int BodySize = 96; // body size
unsigned char *d = (unsigned char *)Info.m_pData; 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 // 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); mem_free(Info.m_pData);
// set skin data // 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_copy(Skin.m_aName, pName, min((int)sizeof(Skin.m_aName),l-3));
str_format(aBuf, sizeof(aBuf), "load skin %s", pSelf->m_aSkins[pSelf->m_NumSkins].m_aName); str_format(aBuf, sizeof(aBuf), "load skin %s", Skin.m_aName);
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "game", aBuf); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "game", aBuf);
pSelf->m_NumSkins++; pSelf->m_aSkins.add(Skin);
} }
void CSkins::Init() void CSkins::Init()
{ {
// load skins // load skins
m_NumSkins = 0; m_aSkins.clear();
Storage()->ListDirectory(IStorage::TYPE_ALL, "skins", SkinScan, this); Storage()->ListDirectory(IStorage::TYPE_ALL, "skins", SkinScan, this);
} }
int CSkins::Num() int CSkins::Num()
{ {
return m_NumSkins; return m_aSkins.size();
} }
const CSkins::CSkin *CSkins::Get(int Index) 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) 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) if(str_comp(m_aSkins[i].m_aName, pName) == 0)
return i; return i;

View file

@ -1,6 +1,7 @@
#ifndef GAME_CLIENT_COMPONENTS_SKINS_H #ifndef GAME_CLIENT_COMPONENTS_SKINS_H
#define GAME_CLIENT_COMPONENTS_SKINS_H #define GAME_CLIENT_COMPONENTS_SKINS_H
#include <base/vmath.h> #include <base/vmath.h>
#include <base/tl/array.h>
#include <game/client/component.h> #include <game/client/component.h>
class CSkins : public CComponent class CSkins : public CComponent
@ -11,12 +12,9 @@ public:
{ {
int m_OrgTexture; int m_OrgTexture;
int m_ColorTexture; int m_ColorTexture;
char m_aName[31]; char m_aName[32];
char m_aTerm[1];
vec3 m_BloodColor; vec3 m_BloodColor;
} ; };
CSkins();
void Init(); void Init();
@ -26,13 +24,7 @@ public:
int Find(const char *pName); int Find(const char *pName);
private: private:
enum array<CSkin> m_aSkins;
{
MAX_SKINS=256,
};
CSkin m_aSkins[MAX_SKINS];
int m_NumSkins;
static void SkinScan(const char *pName, int IsDir, void *pUser); static void SkinScan(const char *pName, int IsDir, void *pUser);
}; };

View file

@ -34,7 +34,7 @@ MACRO_CONFIG_STR(ClLanguagefile, cl_languagefile, 255, "", CFGFLAG_CLIENT|CFGFLA
MACRO_CONFIG_INT(PlayerUseCustomColor, player_use_custom_color, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Toggles usage of custom colors") MACRO_CONFIG_INT(PlayerUseCustomColor, player_use_custom_color, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Toggles usage of custom colors")
MACRO_CONFIG_INT(PlayerColorBody, player_color_body, 65408, 0, 0xFFFFFF, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Player body color") MACRO_CONFIG_INT(PlayerColorBody, player_color_body, 65408, 0, 0xFFFFFF, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Player body color")
MACRO_CONFIG_INT(PlayerColorFeet, player_color_feet, 65408, 0, 0xFFFFFF, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Player feet color") MACRO_CONFIG_INT(PlayerColorFeet, player_color_feet, 65408, 0, 0xFFFFFF, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Player feet color")
MACRO_CONFIG_STR(PlayerSkin, player_skin, 64, "default", CFGFLAG_CLIENT|CFGFLAG_SAVE, "Player skin") MACRO_CONFIG_STR(PlayerSkin, player_skin, 32, "default", CFGFLAG_CLIENT|CFGFLAG_SAVE, "Player skin")
MACRO_CONFIG_INT(UiPage, ui_page, 5, 0, 9, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Interface page") MACRO_CONFIG_INT(UiPage, ui_page, 5, 0, 9, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Interface page")
MACRO_CONFIG_INT(UiToolboxPage, ui_toolbox_page, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Toolbox page") MACRO_CONFIG_INT(UiToolboxPage, ui_toolbox_page, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Toolbox page")