From 61d04ba28a84b7cc56289f46d4f2e370f9f5a140 Mon Sep 17 00:00:00 2001 From: koldo Date: Fri, 12 Sep 2014 20:57:45 +0000 Subject: [PATCH] .RasterPlayer: Small update git-svn-id: svn://ultimatepp.org/upp/trunk@7670 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/RasterPlayer/RasterPlayer.cpp | 41 ++++++++++++++++------------ uppsrc/RasterPlayer/RasterPlayer.h | 1 + 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/uppsrc/RasterPlayer/RasterPlayer.cpp b/uppsrc/RasterPlayer/RasterPlayer.cpp index 9fe2b0d2d..ffd4d2cd4 100644 --- a/uppsrc/RasterPlayer/RasterPlayer.cpp +++ b/uppsrc/RasterPlayer/RasterPlayer.cpp @@ -103,35 +103,42 @@ bool RasterPlayer::Load(const String &fileName) { return LoadBuffer(LoadStream(in)); } +bool RasterPlayer::IsKilled() { + bool ret; + INTERLOCKED_(mutex) {ret = kill;} + return ret; +} + #ifdef _MULTITHREADED void RasterPlayerThread(RasterPlayer *animatedClip) { TimeStop t; dword tFrame = 0; - while (!animatedClip->kill) { + while (!animatedClip->IsKilled()) { INTERLOCKED_(mutex) { - int ind = animatedClip->ind+1; - if (ind > animatedClip->GetPageCount()-1) + int ind = animatedClip->ind + 1; + if (ind > animatedClip->GetPageCount() - 1) ind = 0; tFrame += dword(animatedClip->delays[ind]/animatedClip->speed); } - while (t.Elapsed() < tFrame && !animatedClip->kill) + while (t.Elapsed() < tFrame && !animatedClip->IsKilled()) Sleep(10); PostCallback(callback(animatedClip, &RasterPlayer::NextFrame)); } - INTERLOCKED_(mutex) { - animatedClip->running = false; - } +INTERLOCKED_(mutex) { + animatedClip->running = false; +} } #endif void RasterPlayer::TimerFun() { +INTERLOCKED_(mutex) { if (kill || !running) return; - +} if (tTime.Elapsed() < tFrame) return; - int iFrame = ind+1; - if (iFrame > GetPageCount()-1) + int iFrame = ind + 1; + if (iFrame > GetPageCount() - 1) iFrame = 0; tFrame += dword(delays[iFrame]/speed); NextFrame(); @@ -140,10 +147,10 @@ void RasterPlayer::TimerFun() { void RasterPlayer::Play() { if (images.GetCount() <= 1) return; - INTERLOCKED_(mutex) { - running = true; - kill = false; - } +INTERLOCKED_(mutex) { + running = true; + kill = false; +} #ifdef _MULTITHREADED if (mt) Thread().Run(callback1(RasterPlayerThread, this)); @@ -157,9 +164,7 @@ void RasterPlayer::Play() { } void RasterPlayer::Stop() { - INTERLOCKED_(mutex) { - kill = true; - } +INTERLOCKED_(mutex) {kill = true;} #ifdef _MULTITHREADED if (mt) { while (running) @@ -168,7 +173,7 @@ void RasterPlayer::Stop() { #endif { KillTimeCallback(1); - running = false; + INTERLOCKED_(mutex) {running = false;} } } diff --git a/uppsrc/RasterPlayer/RasterPlayer.h b/uppsrc/RasterPlayer/RasterPlayer.h index 2c57fc3f0..1da71395a 100644 --- a/uppsrc/RasterPlayer/RasterPlayer.h +++ b/uppsrc/RasterPlayer/RasterPlayer.h @@ -8,6 +8,7 @@ using namespace Upp; class RasterPlayer : public Ctrl { private: virtual void Paint(Draw& w); + bool IsKilled(); Array images; Array delays;