From 7b52d3d1acf5e7547e960f7f6722d871f007feef Mon Sep 17 00:00:00 2001 From: Teero888 Date: Fri, 22 Nov 2024 19:20:01 +0100 Subject: [PATCH 1/2] fix the rainbow component --- src/game/client/components/rainbow.cpp | 87 ++++++++++---------------- src/game/client/components/rainbow.h | 7 ++- 2 files changed, 36 insertions(+), 58 deletions(-) diff --git a/src/game/client/components/rainbow.cpp b/src/game/client/components/rainbow.cpp index 803df635d86..5d3b2f18248 100644 --- a/src/game/client/components/rainbow.cpp +++ b/src/game/client/components/rainbow.cpp @@ -8,77 +8,54 @@ #include +#include + +#include "base/color.h" #include "rainbow.h" -void CRainbow::TransformColor(unsigned char mode, int tick, CTeeRenderInfo *pinfo) +void CRainbow::TransformColor(unsigned char Mode, int Tick, CTeeRenderInfo *pInfo) { - if(!mode) + if(!Mode) return; - int deftick = tick % 255; - - const ColorHSLA playercolbody = ColorHSLA(g_Config.m_ClPlayerColorBody); - const ColorHSLA playercolfeet = ColorHSLA(g_Config.m_ClPlayerColorFeet); - - const ColorRGBA col = color_cast(ColorHSLA((float)deftick / 255.0f, 1.0f, 0.5f)); - if(mode == COLORMODE_RAINBOW) + int Deftick = Tick % 255 + 1; + if(Mode == COLORMODE_RAINBOW) { - pinfo->m_CustomColoredSkin = true; - pinfo->m_ColorBody = col; - pinfo->m_ColorFeet = col; - pinfo->m_BloodColor = col; + const ColorRGBA Col = color_cast(ColorHSLA((float)Deftick / 255.0f, 1.0f, 0.5f)); + pInfo->m_CustomColoredSkin = true; + pInfo->m_ColorBody = Col; + pInfo->m_ColorFeet = Col; + pInfo->m_BloodColor = Col; return; } - else if(mode == COLORMODE_PULSE) + else if(Mode == COLORMODE_PULSE) { - pinfo->m_CustomColoredSkin = true; - pinfo->m_ColorBody.s = 1.0f; - pinfo->m_ColorFeet.s = 1.0f; - pinfo->m_BloodColor.s = 1.0f; - pinfo->m_ColorBody.l = 0.5f + fabs(((float)deftick / 255.0f) - 0.5f); - pinfo->m_ColorFeet.l = 0.5f + fabs(((float)deftick / 255.0f) - 0.5f); - pinfo->m_BloodColor.l = 0.5f + fabs(((float)deftick / 255.0f) - 0.5f); - - pinfo->m_ColorBody.h = (float)deftick / 255.0f; - pinfo->m_ColorFeet.h = (float)deftick / 255.0f; - pinfo->m_BloodColor.h = (float)deftick / 255.0f; - + float Light = 0.5f + (std::sin(((float)Deftick / 255.0f) * 2 * pi) + 1.f) / 4.f; + pInfo->m_CustomColoredSkin = true; + ColorHSLA Body = color_cast(pInfo->m_ColorBody); + Body.l = Light; + pInfo->m_ColorBody = color_cast(Body); + pInfo->m_BloodColor = pInfo->m_ColorBody; + ColorHSLA Feet = color_cast(pInfo->m_ColorFeet); + Feet.l = Light; + pInfo->m_ColorFeet = color_cast(Feet); return; } - else if(mode == COLORMODE_DARKNESS) + else if(Mode == COLORMODE_DARKNESS) { - pinfo->m_CustomColoredSkin = true; - pinfo->m_ColorBody = ColorRGBA(0.0f, 0.0f, 0.0f); - pinfo->m_ColorFeet = ColorRGBA(0.0f, 0.0f, 0.0f); - pinfo->m_BloodColor = ColorRGBA(0.0f, 0.0f, 0.0f); - return; - } - else - { - pinfo->m_CustomColoredSkin = true; - pinfo->m_ColorBody = color_cast(playercolbody); - pinfo->m_ColorFeet = color_cast(playercolfeet); - pinfo->m_BloodColor = pinfo->m_BloodColor; + pInfo->m_CustomColoredSkin = true; + pInfo->m_ColorBody = ColorRGBA(0.0f, 0.0f, 0.0f); + pInfo->m_ColorFeet = ColorRGBA(0.0f, 0.0f, 0.0f); + pInfo->m_BloodColor = ColorRGBA(0.0f, 0.0f, 0.0f); return; } } void CRainbow::OnRender() { - for(int i = 0; i < MAX_CLIENTS; i++) - { - // check if local player - bool Local = m_pClient->m_Snap.m_LocalClientId == i; - - CTeeRenderInfo *RenderInfo = &m_pClient->m_aClients[i].m_RenderInfo; - // check if rainbow is enabled - if(g_Config.m_ClRainbow && Local) // rainbow is enabled and is own player - { - TransformColor(g_Config.m_ClRainbowMode, m_pClient->m_GameWorld.m_GameTick, RenderInfo); - } - else if(g_Config.m_ClRainbowOthers && !Local) // rainbow is enabled and is not own player - { - TransformColor(g_Config.m_ClRainbowMode, m_pClient->m_GameWorld.m_GameTick, RenderInfo); - } - } + if(g_Config.m_ClRainbowOthers) + for(auto &Client : m_pClient->m_aClients) + TransformColor(g_Config.m_ClRainbowMode, m_pClient->m_GameWorld.m_GameTick, &Client.m_RenderInfo); + else if(g_Config.m_ClRainbow) + TransformColor(g_Config.m_ClRainbowMode, m_pClient->m_GameWorld.m_GameTick, &m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientId].m_RenderInfo); } diff --git a/src/game/client/components/rainbow.h b/src/game/client/components/rainbow.h index f2c4958c1a3..0353aa86a9c 100644 --- a/src/game/client/components/rainbow.h +++ b/src/game/client/components/rainbow.h @@ -1,15 +1,16 @@ #ifndef GAME_CLIENT_COMPONENTS_RAINBOW_H #define GAME_CLIENT_COMPONENTS_RAINBOW_H +#include "game/client/render.h" #include class CRainbow : public CComponent { public: - virtual int Sizeof() const override { return sizeof(*this); } - virtual void OnRender() override; + int Sizeof() const override { return sizeof(*this); } + void OnRender() override; - void TransformColor(unsigned char mode, int tick, CTeeRenderInfo *pinfo); + void TransformColor(unsigned char Mode, int Tick, CTeeRenderInfo *pInfo); enum COLORMODE { COLORMODE_RAINBOW = 1, From 9d80d61c54cd44f89396db11f6477beda1a1ccc3 Mon Sep 17 00:00:00 2001 From: Teero888 Date: Fri, 22 Nov 2024 19:25:42 +0100 Subject: [PATCH 2/2] quick behaviour fix --- src/game/client/components/rainbow.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/game/client/components/rainbow.cpp b/src/game/client/components/rainbow.cpp index 5d3b2f18248..e3166483528 100644 --- a/src/game/client/components/rainbow.cpp +++ b/src/game/client/components/rainbow.cpp @@ -11,6 +11,7 @@ #include #include "base/color.h" +#include "engine/shared/protocol.h" #include "rainbow.h" void CRainbow::TransformColor(unsigned char Mode, int Tick, CTeeRenderInfo *pInfo) @@ -54,8 +55,9 @@ void CRainbow::TransformColor(unsigned char Mode, int Tick, CTeeRenderInfo *pInf void CRainbow::OnRender() { if(g_Config.m_ClRainbowOthers) - for(auto &Client : m_pClient->m_aClients) - TransformColor(g_Config.m_ClRainbowMode, m_pClient->m_GameWorld.m_GameTick, &Client.m_RenderInfo); - else if(g_Config.m_ClRainbow) + for(int i = 0; i < MAX_CLIENTS; ++i) + if(i != m_pClient->m_Snap.m_LocalClientId) + TransformColor(g_Config.m_ClRainbowMode, m_pClient->m_GameWorld.m_GameTick, &m_pClient->m_aClients[i].m_RenderInfo); + if(g_Config.m_ClRainbow) TransformColor(g_Config.m_ClRainbowMode, m_pClient->m_GameWorld.m_GameTick, &m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientId].m_RenderInfo); }