mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-06 23:26:26 +02:00
use video player for spellbook animation
This commit is contained in:
parent
7fdddee503
commit
8808c9538c
@ -14,10 +14,6 @@
|
|||||||
class CEmptyVideoPlayer final : public IVideoPlayer
|
class CEmptyVideoPlayer final : public IVideoPlayer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void playSpellbookAnimation(const VideoPath & name, const Point & position) override
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Load video from specified path
|
/// Load video from specified path
|
||||||
std::unique_ptr<IVideoInstance> open(const VideoPath & name, float scaleFactor) override
|
std::unique_ptr<IVideoInstance> open(const VideoPath & name, float scaleFactor) override
|
||||||
{
|
{
|
||||||
|
@ -637,68 +637,6 @@ std::pair<std::unique_ptr<ui8 []>, si64> CAudioInstance::extractAudio(const Vide
|
|||||||
return dat;
|
return dat;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CVideoPlayer::openAndPlayVideoImpl(const VideoPath & name, const Point & position, bool useOverlay, bool stopOnKey)
|
|
||||||
{
|
|
||||||
CVideoInstance instance;
|
|
||||||
|
|
||||||
auto extractedAudio = getAudio(name);
|
|
||||||
int audioHandle = CCS->soundh->playSound(extractedAudio);
|
|
||||||
|
|
||||||
if (!instance.openInput(name))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
instance.openVideo();
|
|
||||||
instance.prepareOutput(1, true);
|
|
||||||
|
|
||||||
auto lastTimePoint = boost::chrono::steady_clock::now();
|
|
||||||
|
|
||||||
while(instance.loadNextFrame())
|
|
||||||
{
|
|
||||||
if(stopOnKey)
|
|
||||||
{
|
|
||||||
GH.input().fetchEvents();
|
|
||||||
if(GH.input().ignoreEventsUntilInput())
|
|
||||||
{
|
|
||||||
CCS->soundh->stopSound(audioHandle);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Rect rect;
|
|
||||||
rect.x = position.x;
|
|
||||||
rect.y = position.y;
|
|
||||||
rect.w = instance.dimensions.x;
|
|
||||||
rect.h = instance.dimensions.y;
|
|
||||||
|
|
||||||
SDL_RenderFillRect(mainRenderer, &rect);
|
|
||||||
|
|
||||||
if(instance.textureYUV)
|
|
||||||
SDL_RenderCopy(mainRenderer, instance.textureYUV, nullptr, &rect);
|
|
||||||
else
|
|
||||||
SDL_RenderCopy(mainRenderer, instance.textureRGB, nullptr, &rect);
|
|
||||||
|
|
||||||
SDL_RenderPresent(mainRenderer);
|
|
||||||
|
|
||||||
// Framerate delay
|
|
||||||
double targetFrameTimeSeconds = instance.getCurrentFrameDuration();
|
|
||||||
auto targetFrameTime = boost::chrono::milliseconds(static_cast<int>(1000 * targetFrameTimeSeconds));
|
|
||||||
|
|
||||||
auto timePointAfterPresent = boost::chrono::steady_clock::now();
|
|
||||||
auto timeSpentBusy = boost::chrono::duration_cast<boost::chrono::milliseconds>(timePointAfterPresent - lastTimePoint);
|
|
||||||
|
|
||||||
if(targetFrameTime > timeSpentBusy)
|
|
||||||
boost::this_thread::sleep_for(targetFrameTime - timeSpentBusy);
|
|
||||||
|
|
||||||
lastTimePoint = boost::chrono::steady_clock::now();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CVideoPlayer::playSpellbookAnimation(const VideoPath & name, const Point & position)
|
|
||||||
{
|
|
||||||
openAndPlayVideoImpl(name, position * GH.screenHandler().getScalingFactor(), false, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<IVideoInstance> CVideoPlayer::open(const VideoPath & name, float scaleFactor)
|
std::unique_ptr<IVideoInstance> CVideoPlayer::open(const VideoPath & name, float scaleFactor)
|
||||||
{
|
{
|
||||||
auto result = std::make_unique<CVideoInstance>();
|
auto result = std::make_unique<CVideoInstance>();
|
||||||
|
@ -103,11 +103,9 @@ public:
|
|||||||
|
|
||||||
class CVideoPlayer final : public IVideoPlayer
|
class CVideoPlayer final : public IVideoPlayer
|
||||||
{
|
{
|
||||||
bool openAndPlayVideoImpl(const VideoPath & name, const Point & position, bool useOverlay, bool stopOnKey);
|
|
||||||
void openVideoFile(CVideoInstance & state, const VideoPath & fname);
|
void openVideoFile(CVideoInstance & state, const VideoPath & fname);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void playSpellbookAnimation(const VideoPath & name, const Point & position) final;
|
|
||||||
std::unique_ptr<IVideoInstance> open(const VideoPath & name, float scaleFactor) final;
|
std::unique_ptr<IVideoInstance> open(const VideoPath & name, float scaleFactor) final;
|
||||||
std::pair<std::unique_ptr<ui8[]>, si64> getAudio(const VideoPath & videoToOpen) final;
|
std::pair<std::unique_ptr<ui8[]>, si64> getAudio(const VideoPath & videoToOpen) final;
|
||||||
};
|
};
|
||||||
|
@ -45,9 +45,6 @@ public:
|
|||||||
class IVideoPlayer : boost::noncopyable
|
class IVideoPlayer : boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// Plays video on top of the screen, returns only after playback is over
|
|
||||||
virtual void playSpellbookAnimation(const VideoPath & name, const Point & position) = 0;
|
|
||||||
|
|
||||||
/// Load video from specified path. Returns nullptr on failure
|
/// Load video from specified path. Returns nullptr on failure
|
||||||
virtual std::unique_ptr<IVideoInstance> open(const VideoPath & name, float scaleFactor) = 0;
|
virtual std::unique_ptr<IVideoInstance> open(const VideoPath & name, float scaleFactor) = 0;
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include "../widgets/CTextInput.h"
|
#include "../widgets/CTextInput.h"
|
||||||
#include "../widgets/TextControls.h"
|
#include "../widgets/TextControls.h"
|
||||||
#include "../widgets/Buttons.h"
|
#include "../widgets/Buttons.h"
|
||||||
|
#include "../widgets/VideoWidget.h"
|
||||||
#include "../adventureMap/AdventureMapInterface.h"
|
#include "../adventureMap/AdventureMapInterface.h"
|
||||||
#include "../render/AssetGenerator.h"
|
#include "../render/AssetGenerator.h"
|
||||||
|
|
||||||
@ -395,6 +396,8 @@ void CSpellWindow::fRcornerb()
|
|||||||
|
|
||||||
void CSpellWindow::show(Canvas & to)
|
void CSpellWindow::show(Canvas & to)
|
||||||
{
|
{
|
||||||
|
if(video)
|
||||||
|
video->show(to);
|
||||||
statusBar->show(to);
|
statusBar->show(to);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -493,14 +496,22 @@ void CSpellWindow::setCurrentPage(int value)
|
|||||||
|
|
||||||
void CSpellWindow::turnPageLeft()
|
void CSpellWindow::turnPageLeft()
|
||||||
{
|
{
|
||||||
|
OBJECT_CONSTRUCTION;
|
||||||
if(settings["video"]["spellbookAnimation"].Bool() && !isBigSpellbook)
|
if(settings["video"]["spellbookAnimation"].Bool() && !isBigSpellbook)
|
||||||
CCS->videoh->playSpellbookAnimation(VideoPath::builtin("PGTRNLFT.SMK"), pos.topLeft() + Point(13, 14));
|
video = std::make_shared<VideoWidgetOnce>(Point(13, 14), VideoPath::builtin("PGTRNLFT.SMK"), false, [this](){
|
||||||
|
video.reset();
|
||||||
|
redraw();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSpellWindow::turnPageRight()
|
void CSpellWindow::turnPageRight()
|
||||||
{
|
{
|
||||||
|
OBJECT_CONSTRUCTION;
|
||||||
if(settings["video"]["spellbookAnimation"].Bool() && !isBigSpellbook)
|
if(settings["video"]["spellbookAnimation"].Bool() && !isBigSpellbook)
|
||||||
CCS->videoh->playSpellbookAnimation(VideoPath::builtin("PGTRNRGH.SMK"), pos.topLeft() + Point(13, 14));
|
video = std::make_shared<VideoWidgetOnce>(Point(13, 14), VideoPath::builtin("PGTRNRGH.SMK"), false, [this](){
|
||||||
|
video.reset();
|
||||||
|
redraw();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSpellWindow::keyPressed(EShortcut key)
|
void CSpellWindow::keyPressed(EShortcut key)
|
||||||
|
@ -28,6 +28,7 @@ class CSpellWindow;
|
|||||||
class CTextInput;
|
class CTextInput;
|
||||||
class TransparentFilledRectangle;
|
class TransparentFilledRectangle;
|
||||||
class CToggleButton;
|
class CToggleButton;
|
||||||
|
class VideoWidgetOnce;
|
||||||
|
|
||||||
/// The spell window
|
/// The spell window
|
||||||
class CSpellWindow : public CWindowObject
|
class CSpellWindow : public CWindowObject
|
||||||
@ -86,6 +87,8 @@ class CSpellWindow : public CWindowObject
|
|||||||
std::shared_ptr<CToggleButton> showAllSpells;
|
std::shared_ptr<CToggleButton> showAllSpells;
|
||||||
std::shared_ptr<CLabel> showAllSpellsDescription;
|
std::shared_ptr<CLabel> showAllSpellsDescription;
|
||||||
|
|
||||||
|
std::shared_ptr<VideoWidgetOnce> video;
|
||||||
|
|
||||||
bool isBigSpellbook;
|
bool isBigSpellbook;
|
||||||
int spellsPerPage;
|
int spellsPerPage;
|
||||||
int offL;
|
int offL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user