Merge pull request #7027 from Robyt3/Client-OnWindowResize-Editor-Fix

Move `OnWindowResize` listener to engine, handle editor
This commit is contained in:
Dennis Felsing 2023-08-15 21:07:30 +00:00 committed by GitHub
commit 26cf933e9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 51 additions and 47 deletions

View file

@ -181,6 +181,7 @@ public:
virtual void SetWindowParams(int FullscreenMode, bool IsBorderless, bool AllowResizing) = 0; virtual void SetWindowParams(int FullscreenMode, bool IsBorderless, bool AllowResizing) = 0;
virtual void ToggleWindowVSync() = 0; virtual void ToggleWindowVSync() = 0;
virtual void Notify(const char *pTitle, const char *pMessage) = 0; virtual void Notify(const char *pTitle, const char *pMessage) = 0;
virtual void OnWindowResize() = 0;
virtual void UpdateAndSwap() = 0; virtual void UpdateAndSwap() = 0;
@ -316,6 +317,7 @@ public:
virtual void OnMessage(int MsgID, CUnpacker *pUnpacker, int Conn, bool Dummy) = 0; virtual void OnMessage(int MsgID, CUnpacker *pUnpacker, int Conn, bool Dummy) = 0;
virtual void OnPredict() = 0; virtual void OnPredict() = 0;
virtual void OnActivateEditor() = 0; virtual void OnActivateEditor() = 0;
virtual void OnWindowResize() = 0;
virtual int OnSnapInput(int *pData, bool Dummy, bool Force) = 0; virtual int OnSnapInput(int *pData, bool Dummy, bool Force) = 0;
virtual void OnDummySwap() = 0; virtual void OnDummySwap() = 0;

View file

@ -292,16 +292,6 @@ CClient::CClient() :
for(auto &DemoRecorder : m_aDemoRecorder) for(auto &DemoRecorder : m_aDemoRecorder)
DemoRecorder = CDemoRecorder(&m_SnapshotDelta); DemoRecorder = CDemoRecorder(&m_SnapshotDelta);
m_pEditor = 0;
m_pInput = 0;
m_pGraphics = 0;
m_pSound = 0;
m_pGameClient = 0;
m_pMap = 0;
m_pConfigManager = 0;
m_pConfig = 0;
m_pConsole = 0;
m_RenderFrameTime = 0.0001f; m_RenderFrameTime = 0.0001f;
m_RenderFrameTimeLow = 1.0f; m_RenderFrameTimeLow = 1.0f;
m_RenderFrameTimeHigh = 0.0f; m_RenderFrameTimeHigh = 0.0f;
@ -1132,13 +1122,12 @@ void CClient::DebugRender()
float sp = Graphics()->ScreenWidth() / 100.0f; float sp = Graphics()->ScreenWidth() / 100.0f;
float x = Graphics()->ScreenWidth() - w - sp; float x = Graphics()->ScreenWidth() - w - sp;
ITextRender *pTextRender = Kernel()->RequestInterface<ITextRender>();
m_FpsGraph.Scale(); m_FpsGraph.Scale();
m_FpsGraph.Render(Graphics(), pTextRender, x, sp * 5, w, h, "FPS"); m_FpsGraph.Render(Graphics(), TextRender(), x, sp * 5, w, h, "FPS");
m_InputtimeMarginGraph.Scale(); m_InputtimeMarginGraph.Scale();
m_InputtimeMarginGraph.Render(Graphics(), pTextRender, x, sp * 6 + h, w, h, "Prediction Margin"); m_InputtimeMarginGraph.Render(Graphics(), TextRender(), x, sp * 6 + h, w, h, "Prediction Margin");
m_GametimeMarginGraph.Scale(); m_GametimeMarginGraph.Scale();
m_GametimeMarginGraph.Render(Graphics(), pTextRender, x, sp * 7 + h * 2, w, h, "Gametime Margin"); m_GametimeMarginGraph.Render(Graphics(), TextRender(), x, sp * 7 + h * 2, w, h, "Gametime Margin");
} }
} }
@ -3048,8 +3037,8 @@ void CClient::Run()
#endif #endif
// init text render // init text render
IEngineTextRender *pTextRender = Kernel()->RequestInterface<IEngineTextRender>(); m_pTextRender = Kernel()->RequestInterface<IEngineTextRender>();
pTextRender->Init(); m_pTextRender->Init();
// init the input // init the input
Input()->Init(); Input()->Init();
@ -3068,6 +3057,8 @@ void CClient::Run()
str_copy(g_Config.m_SteamName, Steam()->GetPlayerName()); str_copy(g_Config.m_SteamName, Steam()->GetPlayerName());
} }
Graphics()->AddWindowResizeListener([this] { OnWindowResize(); });
GameClient()->OnInit(); GameClient()->OnInit();
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", "version " GAME_RELEASE_VERSION " on " CONF_PLATFORM_STRING " " CONF_ARCH_STRING, ColorRGBA(0.7f, 0.7f, 1.0f, 1.0f)); m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", "version " GAME_RELEASE_VERSION " on " CONF_PLATFORM_STRING " " CONF_ARCH_STRING, ColorRGBA(0.7f, 0.7f, 1.0f, 1.0f));
@ -3408,7 +3399,7 @@ void CClient::Run()
delete m_pEditor; delete m_pEditor;
// shutdown text render while graphics are still available // shutdown text render while graphics are still available
pTextRender->Shutdown(); m_pTextRender->Shutdown();
} }
bool CClient::InitNetworkClient(char *pError, size_t ErrorSize) bool CClient::InitNetworkClient(char *pError, size_t ErrorSize)
@ -4297,6 +4288,14 @@ void CClient::Notify(const char *pTitle, const char *pMessage)
Graphics()->NotifyWindow(); Graphics()->NotifyWindow();
} }
void CClient::OnWindowResize()
{
TextRender()->OnPreWindowResize();
GameClient()->OnWindowResize();
m_pEditor->OnWindowResize();
TextRender()->OnWindowResize();
}
void CClient::ConchainWindowVSync(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData) void CClient::ConchainWindowVSync(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
{ {
CClient *pSelf = (CClient *)pUserData; CClient *pSelf = (CClient *)pUserData;

View file

@ -107,21 +107,22 @@ public:
class CClient : public IClient, public CDemoPlayer::IListener class CClient : public IClient, public CDemoPlayer::IListener
{ {
// needed interfaces // needed interfaces
IEngine *m_pEngine; IConfigManager *m_pConfigManager = nullptr;
IEditor *m_pEditor; CConfig *m_pConfig = nullptr;
IEngineInput *m_pInput; IConsole *m_pConsole = nullptr;
IEngineGraphics *m_pGraphics; IDiscord *m_pDiscord = nullptr;
IEngineSound *m_pSound; IEditor *m_pEditor = nullptr;
IFavorites *m_pFavorites; IEngine *m_pEngine = nullptr;
IGameClient *m_pGameClient; IFavorites *m_pFavorites = nullptr;
IEngineMap *m_pMap; IGameClient *m_pGameClient = nullptr;
IConfigManager *m_pConfigManager; IEngineGraphics *m_pGraphics = nullptr;
CConfig *m_pConfig; IEngineInput *m_pInput = nullptr;
IConsole *m_pConsole; IEngineMap *m_pMap = nullptr;
IStorage *m_pStorage; IEngineSound *m_pSound = nullptr;
IUpdater *m_pUpdater; ISteam *m_pSteam = nullptr;
IDiscord *m_pDiscord; IStorage *m_pStorage = nullptr;
ISteam *m_pSteam; IEngineTextRender *m_pTextRender = nullptr;
IUpdater *m_pUpdater = nullptr;
CNetClient m_aNetClient[NUM_CONNS]; CNetClient m_aNetClient[NUM_CONNS];
CDemoPlayer m_DemoPlayer; CDemoPlayer m_DemoPlayer;
@ -146,7 +147,6 @@ class CClient : public IClient, public CDemoPlayer::IListener
int64_t m_GlobalStartTime; int64_t m_GlobalStartTime;
IGraphics::CTextureHandle m_DebugFont; IGraphics::CTextureHandle m_DebugFont;
int m_DebugSoundIndex = 0;
int64_t m_LastRenderTime; int64_t m_LastRenderTime;
float m_RenderFrameTimeLow; float m_RenderFrameTimeLow;
@ -302,17 +302,18 @@ class CClient : public IClient, public CDemoPlayer::IListener
std::shared_ptr<ILogger> m_pStdoutLogger = nullptr; std::shared_ptr<ILogger> m_pStdoutLogger = nullptr;
public: public:
IConfigManager *ConfigManager() { return m_pConfigManager; }
CConfig *Config() { return m_pConfig; }
IDiscord *Discord() { return m_pDiscord; }
IEngine *Engine() { return m_pEngine; } IEngine *Engine() { return m_pEngine; }
IGameClient *GameClient() { return m_pGameClient; }
IEngineGraphics *Graphics() { return m_pGraphics; } IEngineGraphics *Graphics() { return m_pGraphics; }
IEngineInput *Input() { return m_pInput; } IEngineInput *Input() { return m_pInput; }
IEngineSound *Sound() { return m_pSound; } IEngineSound *Sound() { return m_pSound; }
IGameClient *GameClient() { return m_pGameClient; }
IConfigManager *ConfigManager() { return m_pConfigManager; }
CConfig *Config() { return m_pConfig; }
IStorage *Storage() { return m_pStorage; }
IUpdater *Updater() { return m_pUpdater; }
IDiscord *Discord() { return m_pDiscord; }
ISteam *Steam() { return m_pSteam; } ISteam *Steam() { return m_pSteam; }
IStorage *Storage() { return m_pStorage; }
IEngineTextRender *TextRender() { return m_pTextRender; }
IUpdater *Updater() { return m_pUpdater; }
CClient(); CClient();
@ -511,6 +512,7 @@ public:
void SetWindowParams(int FullscreenMode, bool IsBorderless, bool AllowResizing) override; void SetWindowParams(int FullscreenMode, bool IsBorderless, bool AllowResizing) override;
void ToggleWindowVSync() override; void ToggleWindowVSync() override;
void Notify(const char *pTitle, const char *pMessage) override; void Notify(const char *pTitle, const char *pMessage) override;
void OnWindowResize() override;
void BenchmarkQuit(int Seconds, const char *pFilename); void BenchmarkQuit(int Seconds, const char *pFilename);
void UpdateAndSwap() override; void UpdateAndSwap() override;

View file

@ -13,6 +13,7 @@ public:
virtual void OnUpdate() = 0; virtual void OnUpdate() = 0;
virtual void OnRender() = 0; virtual void OnRender() = 0;
virtual void OnActivate() = 0; virtual void OnActivate() = 0;
virtual void OnWindowResize() = 0;
virtual bool HasUnsavedData() const = 0; virtual bool HasUnsavedData() const = 0;
virtual bool Load(const char *pFilename, int StorageType) = 0; virtual bool Load(const char *pFilename, int StorageType) = 0;
virtual bool Save(const char *pFilename) = 0; virtual bool Save(const char *pFilename) = 0;

View file

@ -227,8 +227,6 @@ void CGameClient::OnInit()
m_pGraphics = Kernel()->RequestInterface<IGraphics>(); m_pGraphics = Kernel()->RequestInterface<IGraphics>();
m_pGraphics->AddWindowResizeListener([this] { OnWindowResize(); });
// propagate pointers // propagate pointers
m_UI.Init(Kernel()); m_UI.Init(Kernel());
m_RenderTools.Init(Graphics(), TextRender()); m_RenderTools.Init(Graphics(), TextRender());
@ -964,13 +962,10 @@ void CGameClient::OnFlagGrab(int TeamID)
void CGameClient::OnWindowResize() void CGameClient::OnWindowResize()
{ {
TextRender()->OnPreWindowResize();
for(auto &pComponent : m_vpAll) for(auto &pComponent : m_vpAll)
pComponent->OnWindowResize(); pComponent->OnWindowResize();
UI()->OnWindowResize(); UI()->OnWindowResize();
TextRender()->OnWindowResize();
} }
void CGameClient::OnLanguageChange() void CGameClient::OnLanguageChange()
@ -991,7 +986,7 @@ void CGameClient::HandleLanguageChanged()
TextRender()->SetFontLanguageVariant(g_Config.m_ClLanguagefile); TextRender()->SetFontLanguageVariant(g_Config.m_ClLanguagefile);
// Clear all text containers // Clear all text containers
OnWindowResize(); Client()->OnWindowResize();
} }
void CGameClient::RenderShutdownMessage() void CGameClient::RenderShutdownMessage()

View file

@ -485,8 +485,7 @@ public:
virtual void OnStartGame(); virtual void OnStartGame();
virtual void OnStartRound(); virtual void OnStartRound();
virtual void OnFlagGrab(int TeamID); virtual void OnFlagGrab(int TeamID);
void OnWindowResize() override;
void OnWindowResize();
bool m_LanguageChanged = false; bool m_LanguageChanged = false;
void OnLanguageChange(); void OnLanguageChange();

View file

@ -8292,6 +8292,11 @@ void CEditor::OnActivate()
ResetIngameMoved(); ResetIngameMoved();
} }
void CEditor::OnWindowResize()
{
UI()->OnWindowResize();
}
void CEditor::LoadCurrentMap() void CEditor::LoadCurrentMap()
{ {
if(Load(m_pClient->GetCurrentMapPath(), IStorage::TYPE_SAVE)) if(Load(m_pClient->GetCurrentMapPath(), IStorage::TYPE_SAVE))

View file

@ -950,6 +950,7 @@ public:
void OnUpdate() override; void OnUpdate() override;
void OnRender() override; void OnRender() override;
void OnActivate() override; void OnActivate() override;
void OnWindowResize() override;
bool HasUnsavedData() const override { return m_Map.m_Modified; } bool HasUnsavedData() const override { return m_Map.m_Modified; }
void UpdateMentions() override { m_Mentions++; } void UpdateMentions() override { m_Mentions++; }
void ResetMentions() override { m_Mentions = 0; } void ResetMentions() override { m_Mentions = 0; }