From 605da124d47ed50397508a520e0a1a35ea94a7a9 Mon Sep 17 00:00:00 2001 From: sirius Date: Sat, 28 Sep 2019 12:18:38 +0800 Subject: [PATCH] add button to adjust render speed --- src/engine/client.h | 2 +- src/engine/client/client.cpp | 3 +- src/engine/client/client.h | 2 +- src/game/client/components/menus.cpp | 63 ++++++++++++++++++++++++++-- src/game/client/components/menus.h | 1 + 5 files changed, 64 insertions(+), 7 deletions(-) diff --git a/src/engine/client.h b/src/engine/client.h index 6df4e7851..7909c05b6 100644 --- a/src/engine/client.h +++ b/src/engine/client.h @@ -103,7 +103,7 @@ public: virtual void Quit() = 0; virtual const char *DemoPlayer_Play(const char *pFilename, int StorageType) = 0; #if defined(CONF_VIDEORECORDER) - virtual const char *DemoPlayer_Render(const char *pFilename, int StorageType, const char *pVideoName) = 0; + virtual const char *DemoPlayer_Render(const char *pFilename, int StorageType, const char *pVideoName, int SpeedIndex) = 0; #endif virtual void DemoRecorder_Start(const char *pFilename, bool WithTimestamp, int Recorder) = 0; virtual void DemoRecorder_HandleAutoStart() = 0; diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 24180c682..d9e4ac954 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -3531,7 +3531,7 @@ const char *CClient::DemoPlayer_Play(const char *pFilename, int StorageType) return 0; } #if defined(CONF_VIDEORECORDER) -const char *CClient::DemoPlayer_Render(const char *pFilename, int StorageType, const char *pVideoName) +const char *CClient::DemoPlayer_Render(const char *pFilename, int StorageType, const char *pVideoName, int SpeedIndex) { int Crc; const char *pError; @@ -3580,6 +3580,7 @@ const char *CClient::DemoPlayer_Render(const char *pFilename, int StorageType, c this->CClient::StartVideo(NULL, this, pVideoName); m_DemoPlayer.Play(); + m_DemoPlayer.SetSpeed(g_aSpeeds[SpeedIndex]); //m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "demo_recorder", "demo eof"); GameClient()->OnEnterGame(); diff --git a/src/engine/client/client.h b/src/engine/client/client.h index cf7f8aa5a..2e52dd436 100644 --- a/src/engine/client/client.h +++ b/src/engine/client/client.h @@ -365,7 +365,7 @@ public: static void StartVideo(IConsole::IResult *pResult, void *pUserData, const char *pVideName); static void Con_StartVideo(IConsole::IResult *pResult, void *pUserData); static void Con_StopVideo(IConsole::IResult *pResult, void *pUserData); - const char *DemoPlayer_Render(const char *pFilename, int StorageType, const char *pVideoName); + const char *DemoPlayer_Render(const char *pFilename, int StorageType, const char *pVideoName, int SpeedIndex); #endif static void Con_Rcon(IConsole::IResult *pResult, void *pUserData); diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 0087345f5..e455afb02 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -1542,7 +1542,7 @@ int CMenus::Render() #if defined(CONF_VIDEORECORDER) else if(m_Popup == POPUP_RENDER_DEMO) { - CUIRect Label, TextBox, Ok, Abort; + CUIRect Label, TextBox, Ok, Abort, IncSpeed, DecSpeed, Button; Box.HSplitBottom(20.f, &Box, &Part); #if defined(__ANDROID__) @@ -1586,15 +1586,69 @@ int CMenus::Render() } else { - const char *pError = Client()->DemoPlayer_Render(aBufOld, m_lDemos[m_DemolistSelectedIndex].m_StorageType, m_aCurrentDemoFile); + const char *pError = Client()->DemoPlayer_Render(aBufOld, m_lDemos[m_DemolistSelectedIndex].m_StorageType, m_aCurrentDemoFile, m_Speed); + m_Speed = 4; //Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "demo_render_path", aWholePath); if(pError) PopupMessage(Localize("Error"), str_comp(pError, "error loading demo") ? pError : Localize("Error loading demo"), Localize("Ok")); } } } - Box.HSplitBottom(60.f, &Box, &Part); + Box.HSplitBottom(20.f, &Box, &Part); + Part.VSplitLeft(60.0f, 0, &Part); + Part.VSplitLeft(60.0f, 0, &Label); + Part.VSplitMid(&IncSpeed, &DecSpeed); + + IncSpeed.VMargin(20.0f, &IncSpeed); + DecSpeed.VMargin(20.0f, &DecSpeed); + + Part.VSplitLeft(20.0f, &Button, &Part); + bool IncDemoSpeed = false, DecDemoSpeed = false; + // slowdown + Part.VSplitLeft(5.0f, 0, &Part); + Part.VSplitLeft(Button.h, &Button, &Part); + static int s_SlowDownButton = 0; + if(DoButton_Sprite(&s_SlowDownButton, IMAGE_DEMOBUTTONS, SPRITE_DEMOBUTTON_SLOWER, 0, &Button, CUI::CORNER_ALL)) + DecDemoSpeed = true; + + // fastforward + Part.VSplitLeft(5.0f, 0, &Part); + Part.VSplitLeft(Button.h, &Button, &Part); + static int s_FastForwardButton = 0; + if(DoButton_Sprite(&s_FastForwardButton, IMAGE_DEMOBUTTONS, SPRITE_DEMOBUTTON_FASTER, 0, &Button, CUI::CORNER_ALL)) + IncDemoSpeed = true; + + // speed meter + Part.VSplitLeft(15.0f, 0, &Part); + char aBuffer[64]; + str_format(aBuffer, sizeof(aBuffer), "Speed: ×%g", g_aSpeeds[m_Speed]); + //str_format(aBuffer, sizeof(aBuffer), "Speed: ×%g", Speed); + UI()->DoLabel(&Part, aBuffer, Button.h*0.7f, -1); + + if(IncDemoSpeed) + m_Speed = clamp(m_Speed + 1, 0, (int)(sizeof(g_aSpeeds)/sizeof(g_aSpeeds[0])-1)); + else if(DecDemoSpeed) + m_Speed = clamp(m_Speed - 1, 0, (int)(sizeof(g_aSpeeds)/sizeof(g_aSpeeds[0])-1)); + + /* + static int s_ButtonInc = 0; + if(DoButton_Menu(&s_ButtonInc, Localize("IncSpeed"), 0, &IncSpeed)) + m_Popup = POPUP_NONE; + + static int s_ButtonDec = 0; + if(DoButton_Menu(&s_ButtonDec, Localize("DecSpeed"), 0, &DecSpeed)) + m_Popup = POPUP_NONE; + */ + //Abort.VMargin(20.0f, &Abort); + //SpeedBox.VSplitLeft(40.0f, 0, &SpeedBox); + //SpeedBox.VSplitRight(80.0f, &SpeedBox, 0); + //UI()->DoLabel(&Label, Localize("Video speed:"), 18.0f, -1); + //static float Offset2 = 0.0f; + //char Speed[10] = "1"; + //DoEditBox(&Offset2, &SpeedBox, Speed, sizeof(Speed), 12.0f, &Offset2); + + Box.HSplitBottom(20.f, &Box, &Part); #if defined(__ANDROID__) Box.HSplitBottom(60.f, &Box, &Part); #else @@ -1636,7 +1690,8 @@ int CMenus::Render() // render video char aBuf[512]; str_format(aBuf, sizeof(aBuf), "%s/%s", m_aCurrentDemoFolder, m_lDemos[m_DemolistSelectedIndex].m_aFilename); - const char *pError = Client()->DemoPlayer_Render(aBuf, m_lDemos[m_DemolistSelectedIndex].m_StorageType, m_aCurrentDemoFile); + const char *pError = Client()->DemoPlayer_Render(aBuf, m_lDemos[m_DemolistSelectedIndex].m_StorageType, m_aCurrentDemoFile, m_Speed); + m_Speed = 4; if(pError) PopupMessage(Localize("Error"), str_comp(pError, "error loading demo") ? pError : Localize("Error loading demo"), Localize("Ok")); } diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index a47a39f85..091920b0c 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -227,6 +227,7 @@ class CMenus : public CComponent int m_DemolistSelectedIndex; bool m_DemolistSelectedIsDir; int m_DemolistStorageType; + int m_Speed = 4; void DemolistOnUpdate(bool Reset); //void DemolistPopulate();