From 33e170d5621e13b0ac2692b6ad7b54526a65e15b Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Sun, 28 Jan 2024 22:53:51 +0100 Subject: [PATCH 1/3] CVideoHandler: Call SDL_RenderClear() when playing intro, call SDL_RenderFillRect() for spellbook animation --- client/CMT.cpp | 6 +++--- client/CVideoHandler.cpp | 12 ++++++++++-- client/CVideoHandler.h | 5 +++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/client/CMT.cpp b/client/CMT.cpp index a35d245f2..68cdd9b39 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -430,15 +430,15 @@ void playIntro() { auto audioData = CCS->videoh->getAudio(VideoPath::builtin("3DOLOGO.SMK")); int sound = CCS->soundh->playSound(audioData); - if(CCS->videoh->openAndPlayVideo(VideoPath::builtin("3DOLOGO.SMK"), 0, 1, true, true)) + if(CCS->videoh->openAndPlayVideo(VideoPath::builtin("3DOLOGO.SMK"), 0, 1, true, true, false)) { audioData = CCS->videoh->getAudio(VideoPath::builtin("NWCLOGO.SMK")); sound = CCS->soundh->playSound(audioData); - if (CCS->videoh->openAndPlayVideo(VideoPath::builtin("NWCLOGO.SMK"), 0, 1, true, true)) + if (CCS->videoh->openAndPlayVideo(VideoPath::builtin("NWCLOGO.SMK"), 0, 1, true, true, false)) { audioData = CCS->videoh->getAudio(VideoPath::builtin("H3INTRO.SMK")); sound = CCS->soundh->playSound(audioData); - CCS->videoh->openAndPlayVideo(VideoPath::builtin("H3INTRO.SMK"), 0, 1, true, true); + CCS->videoh->openAndPlayVideo(VideoPath::builtin("H3INTRO.SMK"), 0, 1, true, true, false); } } CCS->soundh->stopSound(sound); diff --git a/client/CVideoHandler.cpp b/client/CVideoHandler.cpp index 9f5129898..946dc2cb1 100644 --- a/client/CVideoHandler.cpp +++ b/client/CVideoHandler.cpp @@ -647,7 +647,14 @@ bool CVideoPlayer::playVideo(int x, int y, bool stopOnKey) SDL_Rect rect = CSDL_Ext::toSDL(pos); - SDL_RenderFillRect(mainRenderer, &rect); + if(overlayVideo) + { + SDL_RenderFillRect(mainRenderer, &rect); + } + else + { + SDL_RenderClear(mainRenderer); + } SDL_RenderCopy(mainRenderer, texture, nullptr, &rect); SDL_RenderPresent(mainRenderer); @@ -672,8 +679,9 @@ bool CVideoPlayer::playVideo(int x, int y, bool stopOnKey) return true; } -bool CVideoPlayer::openAndPlayVideo(const VideoPath & name, int x, int y, bool stopOnKey, bool scale) +bool CVideoPlayer::openAndPlayVideo(const VideoPath & name, int x, int y, bool stopOnKey, bool scale, bool overlay) { + overlayVideo = overlay; open(name, false, true, scale); bool ret = playVideo(x, y, stopOnKey); close(); diff --git a/client/CVideoHandler.h b/client/CVideoHandler.h index 38499bede..0ac743b1c 100644 --- a/client/CVideoHandler.h +++ b/client/CVideoHandler.h @@ -33,7 +33,7 @@ class IMainVideoPlayer : public IVideoPlayer public: virtual ~IMainVideoPlayer() = default; virtual void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update = true, std::function restart = nullptr){} - virtual bool openAndPlayVideo(const VideoPath & name, int x, int y, bool stopOnKey = false, bool scale = false) + virtual bool openAndPlayVideo(const VideoPath & name, int x, int y, bool stopOnKey = false, bool scale = false, bool overlay = true) { return false; } @@ -89,6 +89,7 @@ class CVideoPlayer final : public IMainVideoPlayer /// video playback currnet progress, in seconds double frameTime; bool doLoop; // loop through video + bool overlayVideo; bool playVideo(int x, int y, bool stopOnKey); bool open(const VideoPath & fname, bool loop, bool useOverlay = false, bool scale = false); @@ -106,7 +107,7 @@ public: void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update = true, std::function onVideoRestart = nullptr) override; //moves to next frame if appropriate, and blits it or blits only if redraw parameter is set true // Opens video, calls playVideo, closes video; returns playVideo result (if whole video has been played) - bool openAndPlayVideo(const VideoPath & name, int x, int y, bool stopOnKey = false, bool scale = false) override; + bool openAndPlayVideo(const VideoPath & name, int x, int y, bool stopOnKey = false, bool scale = false, bool overlay = true) override; std::pair, si64> getAudio(const VideoPath & videoToOpen) override; From 70ce090bc4a4f2776e82598f978b57f6b2de7e0f Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Mon, 29 Jan 2024 15:20:22 +0100 Subject: [PATCH 2/3] CVideoHandler: Use EVideoType::INTRO and EVideoType::SPELLBOOK --- client/CMT.cpp | 6 +++--- client/CVideoHandler.cpp | 21 ++++++++++++++++++--- client/CVideoHandler.h | 12 +++++++++--- client/windows/CSpellWindow.cpp | 4 ++-- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/client/CMT.cpp b/client/CMT.cpp index 68cdd9b39..64b85c69c 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -430,15 +430,15 @@ void playIntro() { auto audioData = CCS->videoh->getAudio(VideoPath::builtin("3DOLOGO.SMK")); int sound = CCS->soundh->playSound(audioData); - if(CCS->videoh->openAndPlayVideo(VideoPath::builtin("3DOLOGO.SMK"), 0, 1, true, true, false)) + if(CCS->videoh->openAndPlayVideo(VideoPath::builtin("3DOLOGO.SMK"), 0, 1, EVideoType::INTRO)) { audioData = CCS->videoh->getAudio(VideoPath::builtin("NWCLOGO.SMK")); sound = CCS->soundh->playSound(audioData); - if (CCS->videoh->openAndPlayVideo(VideoPath::builtin("NWCLOGO.SMK"), 0, 1, true, true, false)) + if (CCS->videoh->openAndPlayVideo(VideoPath::builtin("NWCLOGO.SMK"), 0, 1, EVideoType::INTRO)) { audioData = CCS->videoh->getAudio(VideoPath::builtin("H3INTRO.SMK")); sound = CCS->soundh->playSound(audioData); - CCS->videoh->openAndPlayVideo(VideoPath::builtin("H3INTRO.SMK"), 0, 1, true, true, false); + CCS->videoh->openAndPlayVideo(VideoPath::builtin("H3INTRO.SMK"), 0, 1, EVideoType::INTRO); } } CCS->soundh->stopSound(sound); diff --git a/client/CVideoHandler.cpp b/client/CVideoHandler.cpp index 946dc2cb1..4cdb42ce9 100644 --- a/client/CVideoHandler.cpp +++ b/client/CVideoHandler.cpp @@ -647,7 +647,7 @@ bool CVideoPlayer::playVideo(int x, int y, bool stopOnKey) SDL_Rect rect = CSDL_Ext::toSDL(pos); - if(overlayVideo) + if(overlay) { SDL_RenderFillRect(mainRenderer, &rect); } @@ -679,9 +679,24 @@ bool CVideoPlayer::playVideo(int x, int y, bool stopOnKey) return true; } -bool CVideoPlayer::openAndPlayVideo(const VideoPath & name, int x, int y, bool stopOnKey, bool scale, bool overlay) +bool CVideoPlayer::openAndPlayVideo(const VideoPath & name, int x, int y, EVideoType videoType) { - overlayVideo = overlay; + bool scale; + bool stopOnKey; + + switch(videoType) + { + case EVideoType::INTRO: + stopOnKey = true; + scale = true; + overlay = false; + break; + case EVideoType::SPELLBOOK: + default: + stopOnKey = false; + scale = false; + overlay = true; + } open(name, false, true, scale); bool ret = playVideo(x, y, stopOnKey); close(); diff --git a/client/CVideoHandler.h b/client/CVideoHandler.h index 0ac743b1c..e112966fc 100644 --- a/client/CVideoHandler.h +++ b/client/CVideoHandler.h @@ -15,6 +15,12 @@ struct SDL_Surface; struct SDL_Texture; +enum class EVideoType : ui8 +{ + INTRO = 0, // use entire window: stopOnKey = true, scale = true, overlay = false + SPELLBOOK // overlay video: stopOnKey = false, scale = false, overlay = true +}; + class IVideoPlayer : boost::noncopyable { public: @@ -33,7 +39,7 @@ class IMainVideoPlayer : public IVideoPlayer public: virtual ~IMainVideoPlayer() = default; virtual void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update = true, std::function restart = nullptr){} - virtual bool openAndPlayVideo(const VideoPath & name, int x, int y, bool stopOnKey = false, bool scale = false, bool overlay = true) + virtual bool openAndPlayVideo(const VideoPath & name, int x, int y, EVideoType videoType) { return false; } @@ -89,7 +95,7 @@ class CVideoPlayer final : public IMainVideoPlayer /// video playback currnet progress, in seconds double frameTime; bool doLoop; // loop through video - bool overlayVideo; + bool overlay; bool playVideo(int x, int y, bool stopOnKey); bool open(const VideoPath & fname, bool loop, bool useOverlay = false, bool scale = false); @@ -107,7 +113,7 @@ public: void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update = true, std::function onVideoRestart = nullptr) override; //moves to next frame if appropriate, and blits it or blits only if redraw parameter is set true // Opens video, calls playVideo, closes video; returns playVideo result (if whole video has been played) - bool openAndPlayVideo(const VideoPath & name, int x, int y, bool stopOnKey = false, bool scale = false, bool overlay = true) override; + bool openAndPlayVideo(const VideoPath & name, int x, int y, EVideoType videoType) override; std::pair, si64> getAudio(const VideoPath & videoToOpen) override; diff --git a/client/windows/CSpellWindow.cpp b/client/windows/CSpellWindow.cpp index fbbc8f5e3..a09670c5e 100644 --- a/client/windows/CSpellWindow.cpp +++ b/client/windows/CSpellWindow.cpp @@ -519,13 +519,13 @@ void CSpellWindow::setCurrentPage(int value) void CSpellWindow::turnPageLeft() { if(settings["video"]["spellbookAnimation"].Bool() && !isBigSpellbook) - CCS->videoh->openAndPlayVideo(VideoPath::builtin("PGTRNLFT.SMK"), pos.x+13, pos.y+15); + CCS->videoh->openAndPlayVideo(VideoPath::builtin("PGTRNLFT.SMK"), pos.x+13, pos.y+15, EVideoType::SPELLBOOK); } void CSpellWindow::turnPageRight() { if(settings["video"]["spellbookAnimation"].Bool() && !isBigSpellbook) - CCS->videoh->openAndPlayVideo(VideoPath::builtin("PGTRNRGH.SMK"), pos.x+13, pos.y+15); + CCS->videoh->openAndPlayVideo(VideoPath::builtin("PGTRNRGH.SMK"), pos.x+13, pos.y+15, EVideoType::SPELLBOOK); } void CSpellWindow::keyPressed(EShortcut key) From 6085893c0db1d1102c3ef0bb5d8faa14a9e7245a Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Mon, 29 Jan 2024 20:20:31 +0100 Subject: [PATCH 3/3] CVideoPlayer: Make overlay an argument of playVideo() instead of an attribute --- client/CVideoHandler.cpp | 11 ++++++----- client/CVideoHandler.h | 3 +-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/client/CVideoHandler.cpp b/client/CVideoHandler.cpp index 4cdb42ce9..4595e5977 100644 --- a/client/CVideoHandler.cpp +++ b/client/CVideoHandler.cpp @@ -101,8 +101,8 @@ bool CVideoPlayer::open(const VideoPath & fname, bool scale) } // loop = to loop through the video -// useOverlay = directly write to the screen. -bool CVideoPlayer::open(const VideoPath & videoToOpen, bool loop, bool useOverlay, bool scale) +// overlay = directly write to the screen. +bool CVideoPlayer::open(const VideoPath & videoToOpen, bool loop, bool overlay, bool scale) { close(); @@ -199,7 +199,7 @@ bool CVideoPlayer::open(const VideoPath & videoToOpen, bool loop, bool useOverla } // Allocate a place to put our YUV image on that screen - if (useOverlay) + if (overlay) { texture = SDL_CreateTexture( mainRenderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STATIC, pos.w, pos.h); } @@ -624,7 +624,7 @@ Point CVideoPlayer::size() } // Plays a video. Only works for overlays. -bool CVideoPlayer::playVideo(int x, int y, bool stopOnKey) +bool CVideoPlayer::playVideo(int x, int y, bool stopOnKey, bool overlay) { // Note: either the windows player or the linux player is // broken. Compensate here until the bug is found. @@ -683,6 +683,7 @@ bool CVideoPlayer::openAndPlayVideo(const VideoPath & name, int x, int y, EVideo { bool scale; bool stopOnKey; + bool overlay; switch(videoType) { @@ -698,7 +699,7 @@ bool CVideoPlayer::openAndPlayVideo(const VideoPath & name, int x, int y, EVideo overlay = true; } open(name, false, true, scale); - bool ret = playVideo(x, y, stopOnKey); + bool ret = playVideo(x, y, stopOnKey, overlay); close(); return ret; } diff --git a/client/CVideoHandler.h b/client/CVideoHandler.h index e112966fc..89f8016a2 100644 --- a/client/CVideoHandler.h +++ b/client/CVideoHandler.h @@ -95,9 +95,8 @@ class CVideoPlayer final : public IMainVideoPlayer /// video playback currnet progress, in seconds double frameTime; bool doLoop; // loop through video - bool overlay; - bool playVideo(int x, int y, bool stopOnKey); + bool playVideo(int x, int y, bool stopOnKey, bool overlay); bool open(const VideoPath & fname, bool loop, bool useOverlay = false, bool scale = false); public: CVideoPlayer();