about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChoupom <andycootlapin@hotmail.fr>2010-09-18 20:48:49 +0200
committeroy <Tom_Adams@web.de>2010-09-24 13:13:46 +0200
commitaa46c22e10f85285dae87454724d9b6ed161c9c3 (patch)
tree92e85d4048a9d3cd072e10a63e451cc803451d24
parent21d14b9704f9ede9877d7b7861a897f55bf70fdc (diff)
downloadzcatch-aa46c22e10f85285dae87454724d9b6ed161c9c3.tar.gz
zcatch-aa46c22e10f85285dae87454724d9b6ed161c9c3.zip
now put skins in an array to save memory
-rw-r--r--src/game/client/components/skins.cpp28
-rw-r--r--src/game/client/components/skins.h16
-rw-r--r--src/game/variables.h2
3 files changed, 17 insertions, 29 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);
 };
diff --git a/src/game/variables.h b/src/game/variables.h
index 6a247671..0b3cb014 100644
--- a/src/game/variables.h
+++ b/src/game/variables.h
@@ -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(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_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(UiToolboxPage, ui_toolbox_page, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Toolbox page")