mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-16 10:19:47 +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();
|
openContext();
|
||||||
openCodec(findVideoStream());
|
openCodec(findVideoStream());
|
||||||
|
startTime = std::chrono::high_resolution_clock::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CVideoInstance::prepareOutput(float scaleFactor, bool useTextureOutput)
|
void CVideoInstance::prepareOutput(float scaleFactor, bool useTextureOutput)
|
||||||
@ -391,9 +392,16 @@ void CVideoInstance::tick(uint32_t msPassed)
|
|||||||
if(videoEnded())
|
if(videoEnded())
|
||||||
throw std::runtime_error("Video already ended!");
|
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();
|
loadNextFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,11 +77,13 @@ class CVideoInstance final : public IVideoInstance, public FFMpegStream
|
|||||||
SDL_Surface * surface = nullptr;
|
SDL_Surface * surface = nullptr;
|
||||||
Point dimensions;
|
Point dimensions;
|
||||||
|
|
||||||
/// video playback current progress, in seconds
|
/// video playback start time point
|
||||||
double frameTime = 0.0;
|
std::chrono::high_resolution_clock::time_point startTime;
|
||||||
|
|
||||||
void prepareOutput(float scaleFactor, bool useTextureOutput);
|
void prepareOutput(float scaleFactor, bool useTextureOutput);
|
||||||
|
|
||||||
|
const int MAX_FRAMESKIP = 5;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~CVideoInstance();
|
~CVideoInstance();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user