Make components member of CGameClient

This commit is contained in:
Jupeyy 2021-07-12 11:29:59 +02:00
parent dbc05f6bb0
commit 8451775821
31 changed files with 263 additions and 107 deletions

View file

@ -1750,6 +1750,7 @@ if(CLIENT)
set_src(GAME_CLIENT GLOB_RECURSE src/game/client
animstate.cpp
animstate.h
component.cpp
component.h
components/background.cpp
components/background.h

View file

@ -0,0 +1,39 @@
#include "component.h"
#include "gameclient.h"
class IKernel *CComponent::Kernel() const { return m_pClient->Kernel(); }
class IGraphics *CComponent::Graphics() const { return m_pClient->Graphics(); }
class ITextRender *CComponent::TextRender() const { return m_pClient->TextRender(); }
class IInput *CComponent::Input() const { return m_pClient->Input(); }
class IStorage *CComponent::Storage() const { return m_pClient->Storage(); }
class CUI *CComponent::UI() const { return m_pClient->UI(); }
class ISound *CComponent::Sound() const { return m_pClient->Sound(); }
class CRenderTools *CComponent::RenderTools() const { return m_pClient->RenderTools(); }
class CConfig *CComponent::Config() const { return m_pClient->Config(); }
class IConsole *CComponent::Console() const { return m_pClient->Console(); }
class IDemoPlayer *CComponent::DemoPlayer() const { return m_pClient->DemoPlayer(); }
class IDemoRecorder *CComponent::DemoRecorder(int Recorder) const { return m_pClient->DemoRecorder(Recorder); }
class IServerBrowser *CComponent::ServerBrowser() const { return m_pClient->ServerBrowser(); }
class CLayers *CComponent::Layers() const { return m_pClient->Layers(); }
class CCollision *CComponent::Collision() const { return m_pClient->Collision(); }
#if defined(CONF_AUTOUPDATE)
class IUpdater *CComponent::Updater() const
{
return m_pClient->Updater();
}
#endif
float CComponent::LocalTime() const
{
#if defined(CONF_VIDEORECORDER)
return IVideo::Current() ? IVideo::LocalTime() : Client()->LocalTime();
#else
return Client()->LocalTime();
#endif
}
class IClient *CComponent::Client() const
{
return m_pClient->Client();
}

View file

@ -7,9 +7,17 @@
#include <engine/shared/video.h>
#endif
#include "gameclient.h"
#include <base/color.h>
#include <engine/input.h>
#include <engine/client.h>
#include <engine/console.h>
#include <game/localization.h>
#include <engine/config.h>
class CGameClient;
class CComponent
{
protected:
@ -18,26 +26,23 @@ protected:
CGameClient *m_pClient;
// perhaps propagte pointers for these as well
class IKernel *Kernel() const { return m_pClient->Kernel(); }
class IGraphics *Graphics() const { return m_pClient->Graphics(); }
class ITextRender *TextRender() const { return m_pClient->TextRender(); }
class IInput *Input() const { return m_pClient->Input(); }
class IStorage *Storage() const { return m_pClient->Storage(); }
class CUI *UI() const { return m_pClient->UI(); }
class ISound *Sound() const { return m_pClient->Sound(); }
class CRenderTools *RenderTools() const { return m_pClient->RenderTools(); }
class CConfig *Config() const { return m_pClient->Config(); }
class IConsole *Console() const { return m_pClient->Console(); }
class IDemoPlayer *DemoPlayer() const { return m_pClient->DemoPlayer(); }
class IDemoRecorder *DemoRecorder(int Recorder) const { return m_pClient->DemoRecorder(Recorder); }
class IServerBrowser *ServerBrowser() const { return m_pClient->ServerBrowser(); }
class CLayers *Layers() const { return m_pClient->Layers(); }
class CCollision *Collision() const { return m_pClient->Collision(); }
class IKernel *Kernel() const;
class IGraphics *Graphics() const;
class ITextRender *TextRender() const;
class IInput *Input() const;
class IStorage *Storage() const;
class CUI *UI() const;
class ISound *Sound() const;
class CRenderTools *RenderTools() const;
class CConfig *Config() const;
class IConsole *Console() const;
class IDemoPlayer *DemoPlayer() const;
class IDemoRecorder *DemoRecorder(int Recorder) const;
class IServerBrowser *ServerBrowser() const;
class CLayers *Layers() const;
class CCollision *Collision() const;
#if defined(CONF_AUTOUPDATE)
class IUpdater *Updater() const
{
return m_pClient->Updater();
}
class IUpdater *Updater() const;
#endif
#if defined(CONF_VIDEORECORDER)
@ -45,19 +50,18 @@ protected:
{
return IVideo::Current() ? IVideo::Time() : time_get();
}
float LocalTime() const { return IVideo::Current() ? IVideo::LocalTime() : Client()->LocalTime(); }
#else
int64_t time() const
{
return time_get();
}
float LocalTime() const { return Client()->LocalTime(); }
#endif
float LocalTime() const;
public:
virtual ~CComponent() {}
class CGameClient *GameClient() const { return m_pClient; }
class IClient *Client() const { return m_pClient->Client(); }
class IClient *Client() const;
virtual void OnStateChange(int NewState, int OldState){};
virtual void OnConsoleInit(){};

View file

@ -8,6 +8,9 @@
#include <game/client/components/mapimages.h>
#include <game/client/components/maplayers.h>
#include <game/client/gameclient.h>
#include <game/layers.h>
#include "background.h"
CBackground::CBackground(int MapType, bool OnlineOnly) :

View file

@ -5,6 +5,10 @@
#include <engine/keys.h>
#include <game/client/component.h>
#include "console.h"
class IConfigManager;
class CBinds : public CComponent
{
int GetKeyID(const char *pKeyName);

View file

@ -7,6 +7,8 @@
#include <game/client/component.h>
#include <game/client/lineinput.h>
#include <game/client/skin.h>
class CChat : public CComponent
{
CLineInput m_Input;

View file

@ -31,6 +31,8 @@
#include <game/client/lineinput.h>
#include <game/client/render.h>
#include <game/client/gameclient.h>
#include "console.h"
CGameConsole::CInstance::CInstance(int Type)

View file

@ -6,6 +6,8 @@
#include <game/client/component.h>
#include <game/client/lineinput.h>
#include <engine/console.h>
enum
{
CONSOLE_CLOSED,

View file

@ -7,6 +7,8 @@
#include <base/vmath.h>
#include <game/client/component.h>
#include <game/generated/protocol.h>
class CControls : public CComponent
{
public:

View file

@ -9,6 +9,8 @@
#include <game/client/render.h>
#include <game/client/ui.h>
#include <game/client/gameclient.h>
CDamageInd::CDamageInd()
{
m_Lastupdate = 0;

View file

@ -13,6 +13,8 @@
#include <game/client/ui.h>
#include <game/gamecore.h> // get_angle
#include <game/client/gameclient.h>
CEmoticon::CEmoticon()
{
OnReset();

View file

@ -12,6 +12,8 @@
#include "players.h"
#include "skins.h"
#include <game/client/gameclient.h>
const char *CGhost::ms_pGhostDir = "ghosts";
CGhost::CGhost() :

View file

@ -6,6 +6,10 @@
#include <game/client/component.h>
#include <game/client/components/menus.h>
#include <game/client/render.h>
struct CNetObj_Character;
enum
{
GHOSTDATA_TYPE_SKIN = 0,

View file

@ -4,6 +4,8 @@
#define GAME_CLIENT_COMPONENTS_KILLMESSAGES_H
#include <game/client/component.h>
#include <game/client/render.h>
class CKillMessages : public CComponent
{
int m_SpriteQuadContainerIndex;

View file

@ -8,8 +8,12 @@
#include <game/client/component.h>
#include <game/mapitems.h>
#include <game/layers.h>
#include "mapimages.h"
#include <game/client/gameclient.h>
CMapImages::CMapImages() :
CMapImages(100)
{

View file

@ -4,6 +4,8 @@
#define GAME_CLIENT_COMPONENTS_MAPLAYERS_H
#include <game/client/component.h>
#include <base/color.h>
#include <cstdint>
#include <vector>
@ -15,6 +17,10 @@ typedef char *offset_ptr_size;
typedef uintptr_t offset_ptr;
typedef unsigned int offset_ptr32;
struct CMapItemGroup;
struct CMapItemLayerTilemap;
struct CMapItemLayerQuads;
class CMapLayers : public CComponent
{
friend class CBackground;

View file

@ -6,6 +6,10 @@
#include <game/client/components/maplayers.h> // envelope
#include <game/client/components/sounds.h>
#include <game/client/gameclient.h>
#include <game/layers.h>
#include "mapsounds.h"
CMapSounds::CMapSounds()

View file

@ -7,6 +7,8 @@
#include <game/client/component.h>
struct CSoundSource;
class CMapSounds : public CComponent
{
int m_aSounds[64];

View file

@ -10,6 +10,10 @@
#include <game/client/components/mapimages.h>
#include <game/client/components/maplayers.h>
#include <game/layers.h>
#include <game/client/render.h>
#include "menu_background.h"
CMenuBackground::CMenuBackground() :

View file

@ -18,6 +18,8 @@
#include <game/client/ui_ex.h>
#include <game/voting.h>
#include <game/client/render.h>
struct CServerProcess
{
PROCESS Process;

View file

@ -19,6 +19,8 @@
#include <game/localization.h>
#include <game/version.h>
#include <game/client/gameclient.h>
#include "menus.h"
static const int g_OffsetColFlagLock = 2;

View file

@ -13,6 +13,10 @@
#include <game/editor/editor.h>
#include <game/version.h>
#include <game/generated/client_data.h>
#include <game/client/gameclient.h>
#include "menus.h"
void CMenus::RenderStartMenu(CUIRect MainView)

View file

@ -3,6 +3,11 @@
#ifndef GAME_CLIENT_COMPONENTS_NAMEPLATES_H
#define GAME_CLIENT_COMPONENTS_NAMEPLATES_H
#include <game/client/component.h>
struct CNetObj_Character;
struct CNetObj_PlayerInfo;
struct CMapItemGroup;
struct SPlayerNamePlate
{
SPlayerNamePlate()

View file

@ -9,6 +9,8 @@
#include <game/gamecore.h>
#include <game/generated/client_data.h>
#include <game/client/gameclient.h>
CParticles::CParticles()
{
OnReset();

View file

@ -4,6 +4,9 @@
#define GAME_CLIENT_COMPONENTS_PLAYERS_H
#include <game/client/component.h>
#include <game/client/render.h>
#include <game/generated/protocol.h>
class CPlayers : public CComponent
{
friend class CGhost;

View file

@ -11,6 +11,8 @@
#include "race_demo.h"
#include <game/client/gameclient.h>
const char *CRaceDemo::ms_pRaceDemoDir = "demos/auto/race";
struct CDemoItem

View file

@ -11,6 +11,10 @@
#include <engine/shared/config.h>
#include <engine/storage.h>
#include <game/generated/client_data.h>
#include <game/client/gameclient.h>
#include "skins.h"
static const char *VANILLA_SKINS[] = {"bluekitty", "bluestripe", "brownbear",

View file

@ -17,6 +17,8 @@
#include "camera.h"
#include "spectator.h"
#include <game/client/gameclient.h>
bool CSpectator::CanChangeSpectator()
{
// Don't change SpectatorID when not spectating

View file

@ -8,6 +8,8 @@
#include <game/client/render.h>
#include <game/generated/protocol.h>
#include <game/client/gameclient.h>
void CVoting::ConCallvote(IConsole::IResult *pResult, void *pUserData)
{
CVoting *pSelf = (CVoting *)pUserData;

View file

@ -69,46 +69,6 @@
CGameClient g_GameClient;
// instantiate all systems
static CKillMessages gs_KillMessages;
static CCamera gs_Camera;
static CChat gs_Chat;
static CMotd gs_Motd;
static CBroadcast gs_Broadcast;
static CGameConsole gs_GameConsole;
static CBinds gs_Binds;
static CParticles gs_Particles;
static CMenus gs_Menus;
static CSkins gs_Skins;
static CCountryFlags gs_CountryFlags;
static CFlow gs_Flow;
static CHud gs_Hud;
static CDebugHud gs_DebugHud;
static CControls gs_Controls;
static CEffects gs_Effects;
static CScoreboard gs_Scoreboard;
static CStatboard gs_Statboard;
static CSounds gs_Sounds;
static CEmoticon gs_Emoticon;
static CDamageInd gsDamageInd;
static CVoting gs_Voting;
static CSpectator gs_Spectator;
static CPlayers gs_Players;
static CNamePlates gs_NamePlates;
static CItems gs_Items;
static CMapImages gs_MapImages;
static CMapLayers gs_MapLayersBackGround(CMapLayers::TYPE_BACKGROUND);
static CMapLayers gs_MapLayersForeGround(CMapLayers::TYPE_FOREGROUND);
static CBackground gs_BackGround;
static CMenuBackground gs_MenuBackground;
static CMapSounds gs_MapSounds;
static CRaceDemo gs_RaceDemo;
static CGhost gs_Ghost;
CGameClient::CStack::CStack() { m_Num = 0; }
void CGameClient::CStack::Add(class CComponent *pComponent) { m_paComponents[m_Num++] = pComponent; }
@ -137,39 +97,39 @@ void CGameClient::OnConsoleInit()
#endif
// setup pointers
m_pMenuBackground = &::gs_MenuBackground;
m_pBinds = &::gs_Binds;
m_pGameConsole = &::gs_GameConsole;
m_pParticles = &::gs_Particles;
m_pMenus = &::gs_Menus;
m_pSkins = &::gs_Skins;
m_pCountryFlags = &::gs_CountryFlags;
m_pChat = &::gs_Chat;
m_pFlow = &::gs_Flow;
m_pCamera = &::gs_Camera;
m_pControls = &::gs_Controls;
m_pEffects = &::gs_Effects;
m_pSounds = &::gs_Sounds;
m_pMotd = &::gs_Motd;
m_pDamageind = &::gsDamageInd;
m_pMapimages = &::gs_MapImages;
m_pVoting = &::gs_Voting;
m_pScoreboard = &::gs_Scoreboard;
m_pStatboard = &::gs_Statboard;
m_pItems = &::gs_Items;
m_pMapLayersBackGround = &::gs_MapLayersBackGround;
m_pMapLayersForeGround = &::gs_MapLayersForeGround;
m_pBackGround = &::gs_BackGround;
m_pMenuBackground = &m_MenuBackground;
m_pBinds = &m_Binds;
m_pGameConsole = &m_GameConsole;
m_pParticles = &m_Particles;
m_pMenus = &m_Menus;
m_pSkins = &m_Skins;
m_pCountryFlags = &m_CountryFlags;
m_pChat = &m_Chat;
m_pFlow = &m_Flow;
m_pCamera = &m_Camera;
m_pControls = &m_Controls;
m_pEffects = &m_Effects;
m_pSounds = &m_Sounds;
m_pMotd = &m_Motd;
m_pDamageind = &m_DamageInd;
m_pMapimages = &m_MapImages;
m_pVoting = &m_Voting;
m_pScoreboard = &m_Scoreboard;
m_pStatboard = &m_Statboard;
m_pItems = &m_Items;
m_pMapLayersBackGround = &m_MapLayersBackGround;
m_pMapLayersForeGround = &m_MapLayersForeGround;
m_pBackGround = &m_BackGround;
m_pMapSounds = &::gs_MapSounds;
m_pPlayers = &::gs_Players;
m_pMapSounds = &m_MapSounds;
m_pPlayers = &m_Players;
m_pRaceDemo = &::gs_RaceDemo;
m_pGhost = &::gs_Ghost;
m_pRaceDemo = &m_RaceDemo;
m_pGhost = &m_Ghost;
m_pMenus->SetMenuBackground(m_pMenuBackground);
gs_NamePlates.SetPlayers(m_pPlayers);
m_NamePlates.SetPlayers(m_pPlayers);
// make a list of all the systems, make sure to add them in the correct render order
m_All.Add(m_pSkins);
@ -186,26 +146,26 @@ void CGameClient::OnConsoleInit()
m_All.Add(m_pRaceDemo);
m_All.Add(m_pMapSounds);
m_All.Add(&gs_BackGround); //render instead of gs_MapLayersBackGround when g_Config.m_ClOverlayEntities == 100
m_All.Add(&gs_MapLayersBackGround); // first to render
m_All.Add(&m_BackGround); //render instead of m_MapLayersBackGround when g_Config.m_ClOverlayEntities == 100
m_All.Add(&m_MapLayersBackGround); // first to render
m_All.Add(&m_pParticles->m_RenderTrail);
m_All.Add(m_pItems);
m_All.Add(m_pPlayers);
m_All.Add(m_pGhost);
m_All.Add(&gs_MapLayersForeGround);
m_All.Add(&m_MapLayersForeGround);
m_All.Add(&m_pParticles->m_RenderExplosions);
m_All.Add(&gs_NamePlates);
m_All.Add(&m_NamePlates);
m_All.Add(&m_pParticles->m_RenderGeneral);
m_All.Add(m_pDamageind);
m_All.Add(&gs_Hud);
m_All.Add(&gs_Spectator);
m_All.Add(&gs_Emoticon);
m_All.Add(&gs_KillMessages);
m_All.Add(&m_Hud);
m_All.Add(&m_Spectator);
m_All.Add(&m_Emoticon);
m_All.Add(&m_KillMessages);
m_All.Add(m_pChat);
m_All.Add(&gs_Broadcast);
m_All.Add(&gs_DebugHud);
m_All.Add(&gs_Scoreboard);
m_All.Add(&gs_Statboard);
m_All.Add(&m_Broadcast);
m_All.Add(&m_DebugHud);
m_All.Add(&m_Scoreboard);
m_All.Add(&m_Statboard);
m_All.Add(m_pMotd);
m_All.Add(m_pMenus);
m_All.Add(&m_pMenus->m_Binder);
@ -220,8 +180,8 @@ void CGameClient::OnConsoleInit()
m_Input.Add(m_pChat); // chat has higher prio due to tha you can quit it by pressing esc
m_Input.Add(m_pMotd); // for pressing esc to remove it
m_Input.Add(m_pMenus);
m_Input.Add(&gs_Spectator);
m_Input.Add(&gs_Emoticon);
m_Input.Add(&m_Spectator);
m_Input.Add(&m_Emoticon);
m_Input.Add(m_pControls);
m_Input.Add(m_pBinds);
@ -355,7 +315,7 @@ void CGameClient::OnInit()
m_LastDummyConnected = false;
// Set free binds to DDRace binds if it's active
gs_Binds.SetDDRaceBinds(true);
m_Binds.SetDDRaceBinds(true);
if(g_Config.m_ClTimeoutCode[0] == '\0' || str_comp(g_Config.m_ClTimeoutCode, "hGuEYnfxicsXGwFq") == 0)
{
@ -2991,7 +2951,7 @@ void CGameClient::RefindSkins()
}
m_pGhost->RefindSkin();
m_pChat->RefindSkins();
gs_KillMessages.RefindSkins();
m_KillMessages.RefindSkins();
}
void CGameClient::LoadMapSettings()

View file

@ -20,6 +20,41 @@
#include <game/client/prediction/entities/pickup.h>
#include <game/client/prediction/gameworld.h>
// components
#include "components/background.h"
#include "components/binds.h"
#include "components/broadcast.h"
#include "components/camera.h"
#include "components/chat.h"
#include "components/console.h"
#include "components/controls.h"
#include "components/countryflags.h"
#include "components/damageind.h"
#include "components/debughud.h"
#include "components/effects.h"
#include "components/emoticon.h"
#include "components/flow.h"
#include "components/ghost.h"
#include "components/hud.h"
#include "components/items.h"
#include "components/killmessages.h"
#include "components/mapimages.h"
#include "components/maplayers.h"
#include "components/mapsounds.h"
#include "components/menu_background.h"
#include "components/menus.h"
#include "components/motd.h"
#include "components/nameplates.h"
#include "components/particles.h"
#include "components/players.h"
#include "components/race_demo.h"
#include "components/scoreboard.h"
#include "components/skins.h"
#include "components/sounds.h"
#include "components/spectator.h"
#include "components/statboard.h"
#include "components/voting.h"
class CGameInfo
{
public:
@ -59,6 +94,48 @@ public:
class CGameClient : public IGameClient
{
public:
// all components
CKillMessages m_KillMessages;
CCamera m_Camera;
CChat m_Chat;
CMotd m_Motd;
CBroadcast m_Broadcast;
CGameConsole m_GameConsole;
CBinds m_Binds;
CParticles m_Particles;
CMenus m_Menus;
CSkins m_Skins;
CCountryFlags m_CountryFlags;
CFlow m_Flow;
CHud m_Hud;
CDebugHud m_DebugHud;
CControls m_Controls;
CEffects m_Effects;
CScoreboard m_Scoreboard;
CStatboard m_Statboard;
CSounds m_Sounds;
CEmoticon m_Emoticon;
CDamageInd m_DamageInd;
CVoting m_Voting;
CSpectator m_Spectator;
CPlayers m_Players;
CNamePlates m_NamePlates;
CItems m_Items;
CMapImages m_MapImages;
CMapLayers m_MapLayersBackGround = CMapLayers{CMapLayers::TYPE_BACKGROUND};
CMapLayers m_MapLayersForeGround = CMapLayers{CMapLayers::TYPE_FOREGROUND};
CBackground m_BackGround;
CMenuBackground m_MenuBackground;
CMapSounds m_MapSounds;
CRaceDemo m_RaceDemo;
CGhost m_Ghost;
private:
class CStack
{
public: