Skip to content

Commit

Permalink
Merge pull request ddnet#9267 from Robyt3/Client-MapImages-TextureSca…
Browse files Browse the repository at this point in the history
…le-Cleanup

Move texture scale initialization and conchain to `CMapImages`
  • Loading branch information
def- authored Nov 19, 2024
2 parents 4215bb4 + 7011113 commit 6f3cb5e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
21 changes: 14 additions & 7 deletions src/game/client/components/mapimages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,9 @@ const char *const gs_apModEntitiesNames[] = {
"f-ddrace",
};

CMapImages::CMapImages() :
CMapImages(100)
{
}

CMapImages::CMapImages(int TextureSize)
CMapImages::CMapImages()
{
m_Count = 0;
m_TextureScale = TextureSize;
mem_zero(m_aEntitiesIsLoaded, sizeof(m_aEntitiesIsLoaded));
m_SpeedupArrowIsLoaded = false;

Expand All @@ -44,6 +38,7 @@ CMapImages::CMapImages(int TextureSize)

void CMapImages::OnInit()
{
m_TextureScale = g_Config.m_ClTextEntitiesSize;
InitOverlayTextures();

if(str_comp(g_Config.m_ClAssetsEntities, "default") == 0)
Expand All @@ -52,6 +47,8 @@ void CMapImages::OnInit()
{
str_format(m_aEntitiesPath, sizeof(m_aEntitiesPath), "assets/entities/%s", g_Config.m_ClAssetsEntities);
}

Console()->Chain("cl_text_entities_size", ConchainClTextEntitiesSize, this);
}

void CMapImages::OnMapLoadImpl(class CLayers *pLayers, IMap *pMap)
Expand Down Expand Up @@ -381,6 +378,16 @@ void CMapImages::ChangeEntitiesPath(const char *pPath)
}
}

void CMapImages::ConchainClTextEntitiesSize(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
{
pfnCallback(pResult, pCallbackUserData);
if(pResult->NumArguments())
{
CMapImages *pThis = static_cast<CMapImages *>(pUserData);
pThis->SetTextureScale(g_Config.m_ClTextEntitiesSize);
}
}

void CMapImages::SetTextureScale(int Scale)
{
if(m_TextureScale == Scale)
Expand Down
3 changes: 2 additions & 1 deletion src/game/client/components/mapimages.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#ifndef GAME_CLIENT_COMPONENTS_MAPIMAGES_H
#define GAME_CLIENT_COMPONENTS_MAPIMAGES_H

#include <engine/console.h>
#include <engine/graphics.h>

#include <game/client/component.h>
Expand Down Expand Up @@ -43,7 +44,6 @@ class CMapImages : public CComponent

public:
CMapImages();
CMapImages(int TextureSize);
virtual int Sizeof() const override { return sizeof(*this); }

IGraphics::CTextureHandle Get(int Index) const { return m_aTextures[Index]; }
Expand Down Expand Up @@ -77,6 +77,7 @@ class CMapImages : public CComponent
IGraphics::CTextureHandle m_OverlayCenterTexture;
int m_TextureScale;

static void ConchainClTextEntitiesSize(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
void InitOverlayTextures();
IGraphics::CTextureHandle UploadEntityLayerText(int TextureSize, int MaxWidth, int YOffset);
void UpdateEntityLayerText(CImageInfo &TextImage, int TextureSize, int MaxWidth, int YOffset, int NumbersPower, int MaxNumber = -1);
Expand Down
14 changes: 0 additions & 14 deletions src/game/client/gameclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ void CGameClient::OnConsoleInit()
Console()->Chain("cl_vanilla_skins_only", ConchainRefreshSkins, this);

Console()->Chain("cl_dummy", ConchainSpecialDummy, this);
Console()->Chain("cl_text_entities_size", ConchainClTextEntitiesSize, this);

Console()->Chain("cl_menu_map", ConchainMenuMap, this);
}
Expand Down Expand Up @@ -407,8 +406,6 @@ void CGameClient::OnInit()
GenerateTimeoutCode(g_Config.m_ClTimeoutCode);
GenerateTimeoutCode(g_Config.m_ClDummyTimeoutCode);

m_MapImages.SetTextureScale(g_Config.m_ClTextEntitiesSize);

// Aggressively try to grab window again since some Windows users report
// window not being focused after starting client.
Graphics()->SetWindowGrab(true);
Expand Down Expand Up @@ -2780,17 +2777,6 @@ void CGameClient::ConchainSpecialDummy(IConsole::IResult *pResult, void *pUserDa
}
}

void CGameClient::ConchainClTextEntitiesSize(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
{
pfnCallback(pResult, pCallbackUserData);

if(pResult->NumArguments())
{
CGameClient *pGameClient = (CGameClient *)pUserData;
pGameClient->m_MapImages.SetTextureScale(g_Config.m_ClTextEntitiesSize);
}
}

IGameClient *CreateGameClient()
{
return new CGameClient();
Expand Down
1 change: 0 additions & 1 deletion src/game/client/gameclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ class CGameClient : public IGameClient
static void ConchainSpecialDummyInfoupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConchainRefreshSkins(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConchainSpecialDummy(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConchainClTextEntitiesSize(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);

static void ConTuneZone(IConsole::IResult *pResult, void *pUserData);

Expand Down

0 comments on commit 6f3cb5e

Please sign in to comment.