From bc5f3fc8396c7521bd261bc4ef69e52f6d91af12 Mon Sep 17 00:00:00 2001 From: oy Date: Wed, 24 Nov 2010 01:08:51 +0100 Subject: [PATCH 1/3] fixed client crash when there are lots of particles. Closes #105 --- src/game/client/components/particles.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/game/client/components/particles.cpp b/src/game/client/components/particles.cpp index 7aa8771c3..ba6b13c7f 100644 --- a/src/game/client/components/particles.cpp +++ b/src/game/client/components/particles.cpp @@ -50,7 +50,8 @@ void CParticles::Add(int Group, CParticle *pPart) // remove from the free list int Id = m_FirstFree; m_FirstFree = m_aParticles[Id].m_NextPart; - m_aParticles[m_FirstFree].m_PrevPart = -1; + if(m_FirstFree != -1) + m_aParticles[m_FirstFree].m_PrevPart = -1; // copy data m_aParticles[Id] = *pPart; From e6698b111873e5c8584343eb511aa40c7052f99b Mon Sep 17 00:00:00 2001 From: oy Date: Wed, 24 Nov 2010 01:11:56 +0100 Subject: [PATCH 2/3] apply custom colour to blood colour. Closes #314 --- src/game/client/components/effects.cpp | 12 +++++++++--- src/game/client/components/menus_settings.cpp | 11 ++++++----- src/game/client/components/skins.cpp | 7 ++++++- src/game/client/components/skins.h | 3 ++- src/game/client/gameclient.cpp | 8 ++++---- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/game/client/components/effects.cpp b/src/game/client/components/effects.cpp index 79117d30a..45dd856e0 100644 --- a/src/game/client/components/effects.cpp +++ b/src/game/client/components/effects.cpp @@ -1,6 +1,7 @@ /* (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 @@ -153,9 +154,14 @@ void CEffects::PlayerDeath(vec2 Pos, int Cid) if(Cid >= 0) { - const CSkins::CSkin *s = m_pClient->m_pSkins->Get(m_pClient->m_aClients[Cid].m_SkinId); - if(s) - BloodColor = s->m_BloodColor; + if(g_Config.m_PlayerUseCustomColor) + BloodColor = m_pClient->m_pSkins->GetColorV3(g_Config.m_PlayerColorBody); + else + { + const CSkins::CSkin *s = m_pClient->m_pSkins->Get(m_pClient->m_aClients[Cid].m_SkinId); + if(s) + BloodColor = s->m_BloodColor; + } } for(int i = 0; i < 64; i++) diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index 3c134cce3..119dc2f58 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -116,8 +116,8 @@ void CMenus::RenderSettingsPlayer(CUIRect MainView) if(g_Config.m_PlayerUseCustomColor) { - OwnSkinInfo.m_ColorBody = m_pClient->m_pSkins->GetColor(g_Config.m_PlayerColorBody); - OwnSkinInfo.m_ColorFeet = m_pClient->m_pSkins->GetColor(g_Config.m_PlayerColorFeet); + OwnSkinInfo.m_ColorBody = m_pClient->m_pSkins->GetColorV4(g_Config.m_PlayerColorBody); + OwnSkinInfo.m_ColorFeet = m_pClient->m_pSkins->GetColorV4(g_Config.m_PlayerColorFeet); OwnSkinInfo.m_Texture = pOwnSkin->m_ColorTexture; } @@ -250,8 +250,8 @@ void CMenus::RenderSettingsPlayer(CUIRect MainView) if(g_Config.m_PlayerUseCustomColor) { - Info.m_ColorBody = m_pClient->m_pSkins->GetColor(g_Config.m_PlayerColorBody); - Info.m_ColorFeet = m_pClient->m_pSkins->GetColor(g_Config.m_PlayerColorFeet); + Info.m_ColorBody = m_pClient->m_pSkins->GetColorV4(g_Config.m_PlayerColorBody); + Info.m_ColorFeet = m_pClient->m_pSkins->GetColorV4(g_Config.m_PlayerColorFeet); Info.m_Texture = s->m_ColorTexture; } @@ -261,9 +261,10 @@ void CMenus::RenderSettingsPlayer(CUIRect MainView) if(g_Config.m_Debug) { + vec3 BloodColor = g_Config.m_PlayerUseCustomColor ? m_pClient->m_pSkins->GetColorV3(g_Config.m_PlayerColorBody) : s->m_BloodColor; Graphics()->TextureSet(-1); Graphics()->QuadsBegin(); - Graphics()->SetColor(s->m_BloodColor.r, s->m_BloodColor.g, s->m_BloodColor.b, 1.0f); + Graphics()->SetColor(BloodColor.r, BloodColor.g, BloodColor.b, 1.0f); IGraphics::CQuadItem QuadItem(Item.m_Rect.x, Item.m_Rect.y, 12, 12); Graphics()->QuadsDrawTL(&QuadItem, 1); Graphics()->QuadsEnd(); diff --git a/src/game/client/components/skins.cpp b/src/game/client/components/skins.cpp index 638baeae8..9c39e9ad7 100644 --- a/src/game/client/components/skins.cpp +++ b/src/game/client/components/skins.cpp @@ -179,7 +179,12 @@ static vec3 HslToRgb(vec3 in) return Out; } -vec4 CSkins::GetColor(int v) +vec3 CSkins::GetColorV3(int v) +{ + return HslToRgb(vec3(((v>>16)&0xff)/255.0f, ((v>>8)&0xff)/255.0f, 0.5f+(v&0xff)/255.0f*0.5f)); +} + +vec4 CSkins::GetColorV4(int v) { vec3 r = HslToRgb(vec3(((v>>16)&0xff)/255.0f, ((v>>8)&0xff)/255.0f, 0.5f+(v&0xff)/255.0f*0.5f)); return vec4(r.r, r.g, r.b, 1.0f); diff --git a/src/game/client/components/skins.h b/src/game/client/components/skins.h index 519f2e732..9e20ba37b 100644 --- a/src/game/client/components/skins.h +++ b/src/game/client/components/skins.h @@ -22,7 +22,8 @@ public: void Init(); - vec4 GetColor(int v); + vec3 GetColorV3(int v); + vec4 GetColorV4(int v); int Num(); const CSkin *Get(int Index); int Find(const char *pName); diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 5dea08761..2b94b10bc 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -708,8 +708,8 @@ void CGameClient::OnNewSnapshot() if(m_aClients[Cid].m_aSkinName[0] == 'x' || m_aClients[Cid].m_aSkinName[1] == '_') str_copy(m_aClients[Cid].m_aSkinName, "default", 64); - m_aClients[Cid].m_SkinInfo.m_ColorBody = m_pSkins->GetColor(m_aClients[Cid].m_ColorBody); - m_aClients[Cid].m_SkinInfo.m_ColorFeet = m_pSkins->GetColor(m_aClients[Cid].m_ColorFeet); + m_aClients[Cid].m_SkinInfo.m_ColorBody = m_pSkins->GetColorV4(m_aClients[Cid].m_ColorBody); + m_aClients[Cid].m_SkinInfo.m_ColorFeet = m_pSkins->GetColorV4(m_aClients[Cid].m_ColorFeet); m_aClients[Cid].m_SkinInfo.m_Size = 64; // find new skin @@ -948,8 +948,8 @@ void CGameClient::CClientData::UpdateRenderInfo() if(m_Team >= 0 && m_Team <= 1) { m_RenderInfo.m_Texture = g_GameClient.m_pSkins->Get(m_SkinId)->m_ColorTexture; - m_RenderInfo.m_ColorBody = g_GameClient.m_pSkins->GetColor(TeamColors[m_Team]); - m_RenderInfo.m_ColorFeet = g_GameClient.m_pSkins->GetColor(TeamColors[m_Team]); + m_RenderInfo.m_ColorBody = g_GameClient.m_pSkins->GetColorV4(TeamColors[m_Team]); + m_RenderInfo.m_ColorFeet = g_GameClient.m_pSkins->GetColorV4(TeamColors[m_Team]); } } } From c3966413e9f9c612fb26cfb2d0a20d85aa136df9 Mon Sep 17 00:00:00 2001 From: Batchyx Date: Mon, 1 Nov 2010 16:35:15 +0100 Subject: [PATCH 3/3] Storage: fix RemoveFile and CreateFolder ret value Removefile returns remove() and CreateFolder returns fs_makedir(), but they returns 0 on success and non-zero on error. Fix that, RemoveFile and CreateFolder should return true on success. (they return false when the type argument is invalid). note: bug has remained unoticed because noone uses CreateFolder, and the user of RemoveFile (the demo browser's remove button) doesn't check the return value. --- src/engine/shared/storage.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/shared/storage.cpp b/src/engine/shared/storage.cpp index ec43847fb..e43cd539b 100644 --- a/src/engine/shared/storage.cpp +++ b/src/engine/shared/storage.cpp @@ -280,7 +280,7 @@ public: return false; char aBuffer[MAX_PATH_LENGTH]; - return remove(GetPath(Type, pFilename, aBuffer, sizeof(aBuffer))); + return !remove(GetPath(Type, pFilename, aBuffer, sizeof(aBuffer))); } virtual bool CreateFolder(const char *pFoldername, int Type) @@ -289,7 +289,7 @@ public: return false; char aBuffer[MAX_PATH_LENGTH]; - return fs_makedir(GetPath(Type, pFoldername, aBuffer, sizeof(aBuffer))); + return !fs_makedir(GetPath(Type, pFoldername, aBuffer, sizeof(aBuffer))); } static IStorage *Create(const char *pApplicationName, int NumArgs, const char **ppArguments)