From 929bf57bf60ea1d5c2beaac611d0482d1feb7d87 Mon Sep 17 00:00:00 2001 From: archimede67 Date: Wed, 5 Jun 2019 19:17:55 +0200 Subject: [PATCH] infinite length and a lot of changes including notifications are now chat messages --- src/engine/client.h | 14 +---- src/engine/client/client.cpp | 63 ++++++++++--------- src/engine/client/client.h | 5 +- src/engine/shared/config_variables.h | 5 +- src/game/client/components/chat.cpp | 7 ++- src/game/client/components/chat.h | 1 + src/game/client/components/hud.cpp | 31 --------- src/game/client/components/hud.h | 1 - src/game/client/components/menus_settings.cpp | 20 +++--- src/game/client/gameclient.cpp | 5 ++ src/game/client/gameclient.h | 2 + 11 files changed, 60 insertions(+), 94 deletions(-) diff --git a/src/engine/client.h b/src/engine/client.h index be0f14f44..61824fd27 100644 --- a/src/engine/client.h +++ b/src/engine/client.h @@ -19,14 +19,6 @@ enum typedef bool (*CLIENTFUNC_FILTER)(const void *pData, int DataSize, void *pUser); -class CHudNotification -{ -public: - const char *m_pTitle; - const char *m_pMessage; - int64 m_ExpireTime; -}; - class IClient : public IInterface { MACRO_INTERFACE("client", 0) @@ -34,8 +26,6 @@ protected: // quick access to state of the client int m_State; - CHudNotification m_CurrentNotification; - // quick access to time variables int m_PrevGameTick[2]; int m_CurGameTick[2]; @@ -82,9 +72,6 @@ public: STATE_QUITING, }; - CHudNotification *CurrentNotification() { return &m_CurrentNotification; }; - bool HasNotification() { return m_CurrentNotification.m_pTitle; }; - // inline int State() const { return m_State; } @@ -250,6 +237,7 @@ public: virtual const char *NetVersion() = 0; virtual void OnDummyDisconnect() = 0; + virtual void Echo(const char *pString) = 0; }; extern IGameClient *CreateGameClient(); diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 46b8d9e14..e32f77eb3 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -781,7 +781,7 @@ void CClient::Disconnect() DisconnectWithReason(0); // make sure to remove replay tmp demo - if(g_Config.m_ClRaceReplays) + if(g_Config.m_ClReplays) { Storage()->RemoveFile((&m_DemoRecorder[RECORDER_REPLAYS])->GetCurrentFilename(), IStorage::TYPE_SAVE); } @@ -1077,15 +1077,6 @@ void CClient::Render() int64 Now = time_get(); g_Config.m_ClAntiPing = (m_PredictedTime.Get(Now)-m_GameTime[g_Config.m_ClDummy].Get(Now))*1000/(float)time_freq() > g_Config.m_ClAntiPingLimit; } - - if(HasNotification()) - { - int64 Now = time_get(); - if(CurrentNotification()->m_ExpireTime < Now) - { - EndNotification(); - } - } } const char *CClient::LoadMap(const char *pName, const char *pFilename, SHA256_DIGEST *pWantedSha256, unsigned WantedCrc) @@ -2676,12 +2667,12 @@ void CClient::Update() std::shared_ptr e = m_EditJobs.front(); if(e->Status() == IJob::STATE_DONE) { - // Notify the player via console and a hud notification char aBuf[256]; str_format(aBuf, sizeof(aBuf), "Successfully saved the replay to %s!", e->Destination()); m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "replay", aBuf); - Notify(Localize("Replay"), Localize("Successfully saved the replay!")); + GameClient()->Echo(Localize("Successfully saved the replay!")); + m_EditJobs.pop_front(); } } @@ -3330,17 +3321,18 @@ void CClient::Con_SaveReplay(IConsole::IResult *pResult, void *pUserData) void CClient::SaveReplay(const int Length) { - if(!g_Config.m_ClRaceReplays) + if(!g_Config.m_ClReplays) { m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "replay", "Feature is disabled. Please enable it via configuration."); - Notify(Localize("Replay"), Localize("Replay feature is disabled!")); + char aBuf[64]; + GameClient()->Echo(Localize("Replay feature is disabled!")); } else { if(!DemoRecorder(RECORDER_REPLAYS)->IsRecording()) - { m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "replay", "Error: demorecorder isn't recording. Try to rejoin to fix that."); - } + else if(DemoRecorder(RECORDER_REPLAYS)->Length() < 1) + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "replay", "Error: demorecorder isn't recording for at least 1 second."); else { // First we stop the recorder to slice correctly the demo after @@ -3357,6 +3349,8 @@ void CClient::SaveReplay(const int Length) const int EndTick = GameTick(); const int StartTick = EndTick - Length * GameTickSpeed(); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "replay", "Saving replay..."); + // Create a job to do this slicing in background because it can be a bit long depending on the file size std::shared_ptr pDemoEditTask = std::make_shared(GameClient()->NetVersion(), &m_SnapshotDelta, m_pStorage, pSrc, aFilename, StartTick, EndTick); Engine()->AddJob(pDemoEditTask); @@ -3368,20 +3362,6 @@ void CClient::SaveReplay(const int Length) } } -void CClient::Notify(const char *pTitle, const char *pMessage) -{ - EndNotification(); - new CHudNotification(m_CurrentNotification); - m_CurrentNotification.m_pTitle = pTitle; - m_CurrentNotification.m_pMessage = pMessage; - m_CurrentNotification.m_ExpireTime = time_get() + g_Config.m_ClNotificationTime * time_freq(); -} - -void CClient::EndNotification() -{ - mem_zero(&m_CurrentNotification, sizeof(m_CurrentNotification)); -} - void CClient::DemoSlice(const char *pDstPath, CLIENTFUNC_FILTER pfnFilter, void *pUser) { if(m_DemoPlayer.IsPlaying()) @@ -3513,7 +3493,7 @@ void CClient::DemoRecorder_HandleAutoStart() void CClient::DemoRecorder_StartReplayRecorder() { - if(g_Config.m_ClRaceReplays) + if(g_Config.m_ClReplays) { DemoRecorder_Stop(RECORDER_REPLAYS); char aBuf[512]; @@ -3699,6 +3679,26 @@ void CClient::ConchainPassword(IConsole::IResult *pResult, void *pUserData, ICon pSelf->m_SendPassword = true; } +void CClient::ConchainReplays(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData) +{ + CClient *pSelf = (CClient *)pUserData; + pfnCallback(pResult, pCallbackUserData); + if(pResult->NumArguments()) + { + int Status = pResult->GetInteger(0); + if(Status == 0) + { + // stop recording and remove the tmp demo file + pSelf->DemoRecorder_Stop(RECORDER_REPLAYS, true); + } + else + { + // start recording + pSelf->DemoRecorder_HandleAutoStart(); + } + } +} + void CClient::RegisterCommands() { m_pConsole = Kernel()->RequestInterface(); @@ -3740,6 +3740,7 @@ void CClient::RegisterCommands() m_pConsole->Register("save_replay", "?i[length]", CFGFLAG_CLIENT, Con_SaveReplay, this, "Save a replay of the last defined amount of seconds"); m_pConsole->Chain("cl_timeout_seed", ConchainTimeoutSeed, this); + m_pConsole->Chain("cl_replays", ConchainReplays, this); m_pConsole->Chain("password", ConchainPassword, this); diff --git a/src/engine/client/client.h b/src/engine/client/client.h index 644b30fbb..800179364 100644 --- a/src/engine/client/client.h +++ b/src/engine/client/client.h @@ -93,6 +93,7 @@ class CClient : public IClient, public CDemoPlayer::IListener int64 m_LocalStartTime; int m_DebugFont; + int m_DebugSoundIndex = 0; int64 m_LastRenderTime; float m_RenderFrameTimeLow; @@ -361,6 +362,7 @@ public: static void ConchainWindowVSync(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData); static void ConchainTimeoutSeed(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData); static void ConchainPassword(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData); + static void ConchainReplays(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData); static void Con_DemoSlice(IConsole::IResult *pResult, void *pUserData); static void Con_DemoSliceBegin(IConsole::IResult *pResult, void *pUserData); @@ -417,12 +419,9 @@ public: virtual void DemoSlice(const char *pDstPath, CLIENTFUNC_FILTER pfnFilter, void *pUser); virtual void SaveReplay(const int Length); - virtual void Notify(const char * pTitle, const char * pMessage); - bool EditorHasUnsavedData() { return m_pEditor->HasUnsavedData(); } virtual IFriends* Foes() {return &m_Foes; } - virtual void EndNotification(); void GetSmoothTick(int *pSmoothTick, float *pSmoothIntraTick, float MixAmount); }; diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index aad8e03b5..67f2a64be 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -264,9 +264,8 @@ MACRO_CONFIG_INT(ConnTimeoutProtection, conn_timeout_protection, 1000, 5, 10000, MACRO_CONFIG_INT(ClShowIDs, cl_show_ids, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Whether to show client ids in scoreboard") MACRO_CONFIG_INT(ClScoreboardOnDeath, cl_scoreboard_on_death, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Whether to show scoreboard after death or not") MACRO_CONFIG_INT(ClAutoRaceRecord, cl_auto_race_record, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Save the best demo of each race") -MACRO_CONFIG_INT(ClRaceReplays, cl_race_replays, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Enable replays") -MACRO_CONFIG_INT(ClReplayLength, cl_replay_length, 10, 5, 60, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Set the length of the replays") -MACRO_CONFIG_INT(ClNotificationTime, cl_notification_time, 3, 1, 10, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Set the duration of the notifications (how many seconds they should stay on the screen)") +MACRO_CONFIG_INT(ClReplays, cl_replays, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Enable/disable replays") +MACRO_CONFIG_INT(ClReplayLength, cl_replay_length, 30, 10, 0, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Set the default length of the replays") MACRO_CONFIG_INT(ClRaceRecordServerControl, cl_race_record_server_control, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Let the server start the race recorder") MACRO_CONFIG_INT(ClDemoName, cl_demo_name, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Save the player name within the demo") MACRO_CONFIG_INT(ClDemoAssumeRace, cl_demo_assume_race, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Assume that demos are race demos") diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index 6dca90a8e..3db3c8104 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -138,7 +138,12 @@ void CChat::ConShowChat(IConsole::IResult *pResult, void *pUserData) void CChat::ConEcho(IConsole::IResult *pResult, void *pUserData) { - ((CChat *)pUserData)->AddLine(-2, 0, pResult->GetString(0)); + ((CChat *)pUserData)->Echo(pResult->GetString(0)); +} + +void CChat::Echo(const char *pString) +{ + AddLine(-2, 0, pString); } void CChat::OnConsoleInit() diff --git a/src/game/client/components/chat.h b/src/game/client/components/chat.h index 1f51ef442..daf004a00 100644 --- a/src/game/client/components/chat.h +++ b/src/game/client/components/chat.h @@ -101,6 +101,7 @@ public: void Say(int Team, const char *pLine); void SayChat(const char *pLine); void RegisterCommand(const char *pName, const char *pParams, int flags, const char *pHelp); + void Echo(const char *pString); virtual void OnWindowResize(); virtual void OnReset(); diff --git a/src/game/client/components/hud.cpp b/src/game/client/components/hud.cpp index 3dc7c9dbe..8d4c26c0e 100644 --- a/src/game/client/components/hud.cpp +++ b/src/game/client/components/hud.cpp @@ -807,41 +807,10 @@ void CHud::OnRender() if(g_Config.m_ClShowRecord) RenderRecord(); - RenderNotification(); } RenderCursor(); } -void CHud::RenderNotification() -{ - - if (Client()->State() == IClient::STATE_DEMOPLAYBACK || !Client()->HasNotification()) - return; - - const CHudNotification *pNotif = Client()->CurrentNotification(); - const char *pTitle = pNotif->m_pTitle; - const char *pMessage = pNotif->m_pMessage; - - float TextWidth = 120.0f; - float Height = 40.0f; - - Graphics()->TextureSet(-1); - Graphics()->QuadsBegin(); - Graphics()->SetColor(0, 0, 0, 0.40f); - RenderTools()->DrawRoundRect(150.0f*Graphics()->ScreenAspect() - TextWidth / 2.0f, 40, TextWidth, Height, 5.0f); - Graphics()->QuadsEnd(); - - TextRender()->TextColor(1, 1, 1, 1); - - float FontSize = 9.0f; - float w = TextRender()->TextWidth(0, FontSize, pTitle, -1); - TextRender()->Text(0, 150.0f*Graphics()->ScreenAspect() - w/2.0f, 50.0f, FontSize, pTitle, TextWidth - 20); - - FontSize = 6.0f; - w = TextRender()->TextWidth(0, FontSize, pMessage, strlen(pMessage)); - TextRender()->Text(0, 150.0f*Graphics()->ScreenAspect() - w/2.0f, 62.0f, FontSize, pMessage, TextWidth - 20); -} - void CHud::OnMessage(int MsgType, void *pRawMsg) { if(MsgType == NETMSGTYPE_SV_DDRACETIME) diff --git a/src/game/client/components/hud.h b/src/game/client/components/hud.h index a4f7aa408..9797dd923 100644 --- a/src/game/client/components/hud.h +++ b/src/game/client/components/hud.h @@ -68,7 +68,6 @@ public: virtual void OnWindowResize(); virtual void OnReset(); virtual void OnRender(); - virtual void RenderNotification(); virtual void OnInit(); // DDRace diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index 844f0c706..d43453498 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -2000,24 +2000,22 @@ void CMenus::RenderSettingsDDNet(CUIRect MainView) { CUIRect Button, Label; Left.HSplitTop(20.0f, &Button, &Left); - Button.VSplitMid(&LeftLeft, &Button); + Button.VSplitLeft(160.0f, &LeftLeft, &Button); - Button.VSplitLeft(80.0f, &Label, &Button); + Button.VSplitLeft(140.0f, &Label, &Button); Button.HMargin(2.0f, &Button); char aBuf[256]; - str_format(aBuf, sizeof(aBuf), Localize("Length: %d"), g_Config.m_ClReplayLength); + str_format(aBuf, sizeof(aBuf), Localize("Default length: %d"), g_Config.m_ClReplayLength); UI()->DoLabelScaled(&Label, aBuf, 14.0f, -1); - int FakeLength = g_Config.m_ClReplayLength - 5; // minimum length is 5 not 0 + int NewValue = (int)(DoScrollbarH(&g_Config.m_ClReplayLength, &Button, (minimum(g_Config.m_ClReplayLength, 600) - 10) / 590.0f)*590.0f) + 10; + if(g_Config.m_ClReplayLength < 600 || NewValue < 600) + g_Config.m_ClReplayLength = minimum(NewValue, 600); - FakeLength = (int)(DoScrollbarH(&FakeLength, &Button, FakeLength / 55.0f)*55.0f); - - g_Config.m_ClReplayLength = FakeLength + 5; - - if(DoButton_CheckBox(&g_Config.m_ClRaceReplays, Localize("Enable replays"), g_Config.m_ClRaceReplays, &LeftLeft)) + if(DoButton_CheckBox(&g_Config.m_ClReplays, Localize("Enable replays"), g_Config.m_ClReplays, &LeftLeft)) { - g_Config.m_ClRaceReplays ^= 1; - if(!g_Config.m_ClRaceReplays) + g_Config.m_ClReplays ^= 1; + if(!g_Config.m_ClReplays) { // stop recording and remove the tmp demo file Client()->DemoRecorder_Stop(RECORDER_REPLAYS, true); diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 25e7cb539..96c9b4810 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -2134,3 +2134,8 @@ vec2 CGameClient::GetSmoothPos(int ClientID) } return Pos; } + +void CGameClient::Echo(const char *pString) +{ + m_pChat->Echo(pString); +} diff --git a/src/game/client/gameclient.h b/src/game/client/gameclient.h index 22cf6381a..073439eea 100644 --- a/src/game/client/gameclient.h +++ b/src/game/client/gameclient.h @@ -417,6 +417,8 @@ public: CGameWorld m_PredictedWorld; CGameWorld m_PrevPredictedWorld; + void Echo(const char *pString); + private: bool m_DDRaceMsgSent[2]; int m_ShowOthers[2];