From 397a1c8199d7e33136cd0ad60ce904a6806117f2 Mon Sep 17 00:00:00 2001 From: Robert Müller Date: Fri, 13 Aug 2021 17:24:15 +0200 Subject: fix variable names --- src/game/client/components/skins.cpp | 48 ++++++++++++++++++------------------ src/game/client/components/skins.h | 2 +- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/game/client/components/skins.cpp b/src/game/client/components/skins.cpp index 9c00e1745..1863c5de1 100644 --- a/src/game/client/components/skins.cpp +++ b/src/game/client/components/skins.cpp @@ -45,7 +45,7 @@ int CSkins::SkinPartScan(const char *pName, int IsDir, int DirType, void *pUser) Part.m_OrgTexture = pSelf->Graphics()->LoadTextureRaw(Info.m_Width, Info.m_Height, Info.m_Format, Info.m_pData, Info.m_Format, 0); Part.m_BloodColor = vec3(1.0f, 1.0f, 1.0f); - unsigned char *d = (unsigned char *)Info.m_pData; + unsigned char *pData = (unsigned char *)Info.m_pData; int Pitch = Info.m_Width*4; // dig out blood color @@ -60,11 +60,11 @@ int CSkins::SkinPartScan(const char *pName, int IsDir, int DirType, void *pUser) for(int y = PartY; y < PartY+PartHeight; y++) for(int x = PartX; x < PartX+PartWidth; x++) { - if(d[y*Pitch+x*4+3] > 128) + if(pData[y*Pitch+x*4+3] > 128) { - aColors[0] += d[y*Pitch+x*4+0]; - aColors[1] += d[y*Pitch+x*4+1]; - aColors[2] += d[y*Pitch+x*4+2]; + aColors[0] += pData[y*Pitch+x*4+0]; + aColors[1] += pData[y*Pitch+x*4+1]; + aColors[2] += pData[y*Pitch+x*4+2]; } } @@ -77,10 +77,10 @@ int CSkins::SkinPartScan(const char *pName, int IsDir, int DirType, void *pUser) // make the texture gray scale for(int i = 0; i < Info.m_Width*Info.m_Height; i++) { - int v = (d[i*Step]+d[i*Step+1]+d[i*Step+2])/3; - d[i*Step] = v; - d[i*Step+1] = v; - d[i*Step+2] = v; + const int Average = (pData[i*Step]+pData[i*Step+1]+pData[i*Step+2])/3; + pData[i*Step] = Average; + pData[i*Step+1] = Average; + pData[i*Step+2] = Average; } Part.m_ColorTexture = pSelf->Graphics()->LoadTextureRaw(Info.m_Width, Info.m_Height, Info.m_Format, Info.m_pData, Info.m_Format, 0); @@ -470,34 +470,34 @@ int CSkins::GetTeamColor(int UseCustomColors, int PartColor, int Team, int Part) return ColorVal; } -bool CSkins::ValidateSkinParts(char* aPartNames[NUM_SKINPARTS], int* aUseCustomColors, int* aPartColors, int GameFlags) const +bool CSkins::ValidateSkinParts(char *apPartNames[NUM_SKINPARTS], int *pUseCustomColors, int *pPartColors, int GameFlags) const { // force standard (black) eyes on team skins if(GameFlags&GAMEFLAG_TEAMS) { // TODO: adjust eye color here as well? - if(str_comp(aPartNames[SKINPART_EYES], "colorable") == 0 || str_comp(aPartNames[SKINPART_EYES], "negative") == 0) + if(str_comp(apPartNames[SKINPART_EYES], "colorable") == 0 || str_comp(apPartNames[SKINPART_EYES], "negative") == 0) { - str_copy(aPartNames[SKINPART_EYES], "standard", MAX_SKIN_ARRAY_SIZE); + str_copy(apPartNames[SKINPART_EYES], "standard", MAX_SKIN_ARRAY_SIZE); return false; } } else { - const int BodyColor = aPartColors[SKINPART_BODY]; - const int EyeColor = aPartColors[SKINPART_EYES]; + const int BodyColor = pPartColors[SKINPART_BODY]; + const int EyeColor = pPartColors[SKINPART_EYES]; vec3 BodyHsl(((BodyColor>>16)&0xff)/255.0f, ((BodyColor>>8)&0xff)/255.0f, (BodyColor&0xff)/255.0f); vec3 EyeHsl(((EyeColor>>16)&0xff)/255.0f, ((EyeColor>>8)&0xff)/255.0f, (EyeColor&0xff)/255.0f); - if(!aUseCustomColors[SKINPART_BODY]) + if(!pUseCustomColors[SKINPART_BODY]) BodyHsl = vec3(0, 0, 1); const vec3 BodyLab = RgbToLab(HslToRgb(BodyHsl)); - if(str_comp(aPartNames[SKINPART_EYES], "negative") == 0) + if(str_comp(apPartNames[SKINPART_EYES], "negative") == 0) { - if(!aUseCustomColors[SKINPART_EYES]) + if(!pUseCustomColors[SKINPART_EYES]) EyeHsl = vec3(0, 0, 1); vec3 OrgEyeHsl = EyeHsl; @@ -510,19 +510,19 @@ bool CSkins::ValidateSkinParts(char* aPartNames[NUM_SKINPARTS], int* aUseCustomC // white eye can't go to black because of our DARKEST_COLOR_LGT restriction, so switch to standard (black) eyes if(OrgEyeHsl.l < DARKEST_COLOR_LGT/255.f) - str_copy(aPartNames[SKINPART_EYES], "standard", MAX_SKIN_ARRAY_SIZE); // black + str_copy(apPartNames[SKINPART_EYES], "standard", MAX_SKIN_ARRAY_SIZE); // black else { - aUseCustomColors[SKINPART_EYES] = 1; - aPartColors[SKINPART_EYES] = (int(OrgEyeHsl.h*255) << 16) | (int(OrgEyeHsl.s*255) << 8) | (int(OrgEyeHsl.l*255)); + pUseCustomColors[SKINPART_EYES] = 1; + pPartColors[SKINPART_EYES] = (int(OrgEyeHsl.h*255) << 16) | (int(OrgEyeHsl.s*255) << 8) | (int(OrgEyeHsl.l*255)); } return false; } } - else if(str_comp(aPartNames[SKINPART_EYES], "colorable") == 0) + else if(str_comp(apPartNames[SKINPART_EYES], "colorable") == 0) { - if(!aUseCustomColors[SKINPART_EYES]) + if(!pUseCustomColors[SKINPART_EYES]) EyeHsl = vec3(0, 0, 1); vec3 OrgEyeHsl = EyeHsl; @@ -534,8 +534,8 @@ bool CSkins::ValidateSkinParts(char* aPartNames[NUM_SKINPARTS], int* aUseCustomC OrgEyeHsl.l -= 0.6f; OrgEyeHsl.l = clamp(OrgEyeHsl.l, 0.f, 1.f); - aUseCustomColors[SKINPART_EYES] = 1; - aPartColors[SKINPART_EYES] = (int(OrgEyeHsl.h*255) << 16) | (int(OrgEyeHsl.s*255) << 8) | (int(OrgEyeHsl.l*255)); + pUseCustomColors[SKINPART_EYES] = 1; + pPartColors[SKINPART_EYES] = (int(OrgEyeHsl.h*255) << 16) | (int(OrgEyeHsl.s*255) << 8) | (int(OrgEyeHsl.l*255)); return false; } diff --git a/src/game/client/components/skins.h b/src/game/client/components/skins.h index 5b79caaf4..cd96ec29a 100644 --- a/src/game/client/components/skins.h +++ b/src/game/client/components/skins.h @@ -74,7 +74,7 @@ public: int GetTeamColor(int UseCustomColors, int PartColor, int Team, int Part) const; // returns true if everything was valid and nothing changed - bool ValidateSkinParts(char *aPartNames[NUM_SKINPARTS], int *aUseCustomColors, int* aPartColors, int GameFlags) const; + bool ValidateSkinParts(char *apPartNames[NUM_SKINPARTS], int *pUseCustomColors, int *pPartColors, int GameFlags) const; void SaveSkinfile(const char *pSaveSkinName); -- cgit v1.2.3 From 704f371e3fee6040772088ea710055b9772232f9 Mon Sep 17 00:00:00 2001 From: Robert Müller Date: Fri, 13 Aug 2021 17:38:57 +0200 Subject: do not load multiple skin parts with the same name --- src/game/client/components/skins.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/game/client/components/skins.cpp b/src/game/client/components/skins.cpp index 1863c5de1..c8e9fbdfd 100644 --- a/src/game/client/components/skins.cpp +++ b/src/game/client/components/skins.cpp @@ -31,6 +31,11 @@ int CSkins::SkinPartScan(const char *pName, int IsDir, int DirType, void *pUser) if(IsDir || !str_endswith(pName, ".png")) return 0; + CSkinPart Part; + str_utf8_copy_num(Part.m_aName, pName, minimum(str_length(pName) - 3, int(sizeof(Part.m_aName))), MAX_SKIN_LENGTH); + if(pSelf->FindSkinPart(pSelf->m_ScanningPart, Part.m_aName, true) != -1) + return 0; + char aBuf[IO_MAX_PATH_LENGTH]; str_format(aBuf, sizeof(aBuf), "skins/%s/%s", CSkins::ms_apSkinPartNames[pSelf->m_ScanningPart], pName); CImageInfo Info; @@ -41,7 +46,6 @@ int CSkins::SkinPartScan(const char *pName, int IsDir, int DirType, void *pUser) return 0; } - CSkinPart Part; Part.m_OrgTexture = pSelf->Graphics()->LoadTextureRaw(Info.m_Width, Info.m_Height, Info.m_Format, Info.m_pData, Info.m_Format, 0); Part.m_BloodColor = vec3(1.0f, 1.0f, 1.0f); @@ -92,7 +96,6 @@ int CSkins::SkinPartScan(const char *pName, int IsDir, int DirType, void *pUser) Part.m_Flags |= SKINFLAG_SPECIAL; if(DirType != IStorage::TYPE_SAVE) Part.m_Flags |= SKINFLAG_STANDARD; - str_utf8_copy_num(Part.m_aName, pName, minimum(str_length(pName) - 3, int(sizeof(Part.m_aName))), MAX_SKIN_LENGTH); if(pSelf->Config()->m_Debug) { str_format(aBuf, sizeof(aBuf), "load skin part %s", Part.m_aName); -- cgit v1.2.3 From 837b5043d591e2948f18b77eac9c64e5af2c6503 Mon Sep 17 00:00:00 2001 From: Robert Müller Date: Fri, 13 Aug 2021 17:42:06 +0200 Subject: organize includes --- src/game/client/components/skins.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/game/client/components/skins.cpp b/src/game/client/components/skins.cpp index c8e9fbdfd..0251ec2ce 100644 --- a/src/game/client/components/skins.cpp +++ b/src/game/client/components/skins.cpp @@ -1,10 +1,8 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ -#include - #include -#include #include +#include #include #include -- cgit v1.2.3