mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-14 10:12:59 +02:00
video: use global timer; implement frameskip
This commit is contained in:
parent
8b427c3989
commit
f0b7d007a0
@ -173,6 +173,7 @@ void CVideoInstance::openVideo()
|
||||
{
|
||||
openContext();
|
||||
openCodec(findVideoStream());
|
||||
startTime = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
void CVideoInstance::prepareOutput(float scaleFactor, bool useTextureOutput)
|
||||
@ -391,9 +392,16 @@ void CVideoInstance::tick(uint32_t msPassed)
|
||||
if(videoEnded())
|
||||
throw std::runtime_error("Video already ended!");
|
||||
|
||||
frameTime += msPassed / 1000.0;
|
||||
auto nowTime = std::chrono::high_resolution_clock::now();
|
||||
double difference = std::chrono::duration_cast<std::chrono::milliseconds>(nowTime - startTime).count() / 1000.0;
|
||||
|
||||
if(frameTime >= getCurrentFrameEndTime())
|
||||
int frameskipCounter = 0;
|
||||
while(!videoEnded() && difference >= getCurrentFrameEndTime() + getCurrentFrameDuration() && frameskipCounter < MAX_FRAMESKIP) // Frameskip
|
||||
{
|
||||
decodeNextFrame();
|
||||
frameskipCounter++;
|
||||
}
|
||||
if(!videoEnded() && difference >= getCurrentFrameEndTime())
|
||||
loadNextFrame();
|
||||
}
|
||||
|
||||
|
@ -77,10 +77,12 @@ class CVideoInstance final : public IVideoInstance, public FFMpegStream
|
||||
SDL_Surface * surface = nullptr;
|
||||
Point dimensions;
|
||||
|
||||
/// video playback current progress, in seconds
|
||||
double frameTime = 0.0;
|
||||
/// video playback start time point
|
||||
std::chrono::high_resolution_clock::time_point startTime;
|
||||
|
||||
void prepareOutput(float scaleFactor, bool useTextureOutput);
|
||||
|
||||
const int MAX_FRAMESKIP = 5;
|
||||
|
||||
public:
|
||||
~CVideoInstance();
|
||||
|
Loading…
Reference in New Issue
Block a user