mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-25 12:14:46 +02:00
code review + pause handling
This commit is contained in:
parent
a68522b370
commit
bb73a35412
@ -240,6 +240,18 @@ void CSoundHandler::stopSound(int handler)
|
|||||||
Mix_HaltChannel(handler);
|
Mix_HaltChannel(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSoundHandler::pauseSound(int handler)
|
||||||
|
{
|
||||||
|
if(isInitialized() && handler != -1)
|
||||||
|
Mix_Pause(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSoundHandler::resumeSound(int handler)
|
||||||
|
{
|
||||||
|
if(isInitialized() && handler != -1)
|
||||||
|
Mix_Resume(handler);
|
||||||
|
}
|
||||||
|
|
||||||
ui32 CSoundHandler::getVolume() const
|
ui32 CSoundHandler::getVolume() const
|
||||||
{
|
{
|
||||||
return volume;
|
return volume;
|
||||||
|
@ -67,6 +67,8 @@ public:
|
|||||||
int playSound(std::pair<std::unique_ptr<ui8[]>, si64> & data, int repeats = 0, bool cache = false) final;
|
int playSound(std::pair<std::unique_ptr<ui8[]>, si64> & data, int repeats = 0, bool cache = false) final;
|
||||||
int playSoundFromSet(std::vector<soundBase::soundID> & sound_vec) final;
|
int playSoundFromSet(std::vector<soundBase::soundID> & sound_vec) final;
|
||||||
void stopSound(int handler) final;
|
void stopSound(int handler) final;
|
||||||
|
void pauseSound(int handler) final;
|
||||||
|
void resumeSound(int handler) final;
|
||||||
|
|
||||||
void setCallback(int channel, std::function<void()> function) final;
|
void setCallback(int channel, std::function<void()> function) final;
|
||||||
void resetCallback(int channel) final;
|
void resetCallback(int channel) final;
|
||||||
|
@ -391,10 +391,10 @@ void CVideoInstance::tick(uint32_t msPassed)
|
|||||||
if(videoEnded())
|
if(videoEnded())
|
||||||
throw std::runtime_error("Video already ended!");
|
throw std::runtime_error("Video already ended!");
|
||||||
|
|
||||||
if(startTime == std::chrono::high_resolution_clock::time_point())
|
if(startTime == std::chrono::steady_clock::time_point())
|
||||||
startTime = std::chrono::high_resolution_clock::now();
|
startTime = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
auto nowTime = std::chrono::high_resolution_clock::now();
|
auto nowTime = std::chrono::steady_clock::now();
|
||||||
double difference = std::chrono::duration_cast<std::chrono::milliseconds>(nowTime - startTime).count() / 1000.0;
|
double difference = std::chrono::duration_cast<std::chrono::milliseconds>(nowTime - startTime).count() / 1000.0;
|
||||||
|
|
||||||
int frameskipCounter = 0;
|
int frameskipCounter = 0;
|
||||||
@ -407,6 +407,22 @@ void CVideoInstance::tick(uint32_t msPassed)
|
|||||||
loadNextFrame();
|
loadNextFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CVideoInstance::activate()
|
||||||
|
{
|
||||||
|
if(deactivationStartTime != std::chrono::steady_clock::time_point())
|
||||||
|
{
|
||||||
|
auto pauseDuration = std::chrono::steady_clock::now() - deactivationStartTime;
|
||||||
|
startTime += pauseDuration;
|
||||||
|
deactivationStartTime = std::chrono::steady_clock::time_point();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CVideoInstance::deactivate()
|
||||||
|
{
|
||||||
|
deactivationStartTime = std::chrono::steady_clock::now();
|
||||||
|
}
|
||||||
|
|
||||||
struct FFMpegFormatDescription
|
struct FFMpegFormatDescription
|
||||||
{
|
{
|
||||||
uint8_t sampleSizeBytes;
|
uint8_t sampleSizeBytes;
|
||||||
|
@ -78,7 +78,8 @@ class CVideoInstance final : public IVideoInstance, public FFMpegStream
|
|||||||
Point dimensions;
|
Point dimensions;
|
||||||
|
|
||||||
/// video playback start time point
|
/// video playback start time point
|
||||||
std::chrono::high_resolution_clock::time_point startTime;
|
std::chrono::steady_clock::time_point startTime;
|
||||||
|
std::chrono::steady_clock::time_point deactivationStartTime;
|
||||||
|
|
||||||
void prepareOutput(float scaleFactor, bool useTextureOutput);
|
void prepareOutput(float scaleFactor, bool useTextureOutput);
|
||||||
|
|
||||||
@ -96,6 +97,8 @@ public:
|
|||||||
|
|
||||||
void show(const Point & position, Canvas & canvas) final;
|
void show(const Point & position, Canvas & canvas) final;
|
||||||
void tick(uint32_t msPassed) final;
|
void tick(uint32_t msPassed) final;
|
||||||
|
void activate() final;
|
||||||
|
void deactivate() final;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CVideoPlayer final : public IVideoPlayer
|
class CVideoPlayer final : public IVideoPlayer
|
||||||
|
@ -22,6 +22,8 @@ public:
|
|||||||
virtual int playSound(std::pair<std::unique_ptr<ui8[]>, si64> & data, int repeats = 0, bool cache = false) = 0;
|
virtual int playSound(std::pair<std::unique_ptr<ui8[]>, si64> & data, int repeats = 0, bool cache = false) = 0;
|
||||||
virtual int playSoundFromSet(std::vector<soundBase::soundID> & sound_vec) = 0;
|
virtual int playSoundFromSet(std::vector<soundBase::soundID> & sound_vec) = 0;
|
||||||
virtual void stopSound(int handler) = 0;
|
virtual void stopSound(int handler) = 0;
|
||||||
|
virtual void pauseSound(int handler) = 0;
|
||||||
|
virtual void resumeSound(int handler) = 0;
|
||||||
|
|
||||||
virtual ui32 getVolume() const = 0;
|
virtual ui32 getVolume() const = 0;
|
||||||
virtual void setVolume(ui32 percent) = 0;
|
virtual void setVolume(ui32 percent) = 0;
|
||||||
|
@ -35,6 +35,10 @@ public:
|
|||||||
/// Advances video playback by specified duration
|
/// Advances video playback by specified duration
|
||||||
virtual void tick(uint32_t msPassed) = 0;
|
virtual void tick(uint32_t msPassed) = 0;
|
||||||
|
|
||||||
|
/// activate or deactivate video
|
||||||
|
virtual void activate() = 0;
|
||||||
|
virtual void deactivate() = 0;
|
||||||
|
|
||||||
virtual ~IVideoInstance() = default;
|
virtual ~IVideoInstance() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ void VideoWidgetBase::playVideo(const VideoPath & fileToPlay)
|
|||||||
{
|
{
|
||||||
pos.w = videoInstance->size().x;
|
pos.w = videoInstance->size().x;
|
||||||
pos.h = videoInstance->size().y;
|
pos.h = videoInstance->size().y;
|
||||||
|
if(!subTitleData.isNull())
|
||||||
subTitle = std::make_unique<CMultiLineLabel>(Rect(0, (pos.h / 5) * 4, pos.w, pos.h / 5), EFonts::FONT_HIGH_SCORE, ETextAlignment::CENTER, Colors::WHITE);
|
subTitle = std::make_unique<CMultiLineLabel>(Rect(0, (pos.h / 5) * 4, pos.w, pos.h / 5), EFonts::FONT_HIGH_SCORE, ETextAlignment::CENTER, Colors::WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,13 +122,20 @@ std::string VideoWidgetBase::getSubTitleLine(double timestamp)
|
|||||||
void VideoWidgetBase::activate()
|
void VideoWidgetBase::activate()
|
||||||
{
|
{
|
||||||
CIntObject::activate();
|
CIntObject::activate();
|
||||||
|
if(audioHandle != -1)
|
||||||
|
CCS->soundh->resumeSound(audioHandle);
|
||||||
|
else
|
||||||
startAudio();
|
startAudio();
|
||||||
|
if(videoInstance)
|
||||||
|
videoInstance->activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoWidgetBase::deactivate()
|
void VideoWidgetBase::deactivate()
|
||||||
{
|
{
|
||||||
CIntObject::deactivate();
|
CIntObject::deactivate();
|
||||||
stopAudio();
|
CCS->soundh->pauseSound(audioHandle);
|
||||||
|
if(videoInstance)
|
||||||
|
videoInstance->deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoWidgetBase::showAll(Canvas & to)
|
void VideoWidgetBase::showAll(Canvas & to)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user