[Scummvm-cvs-logs] scummvm master -> 6d55998b40f62518959f849922919b6b0562981e

clone2727 clone2727 at gmail.com
Mon Dec 29 05:15:17 CET 2014


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
6d55998b40 ZVISION: Make the rest of the controls properly use VideoDecoder timing


Commit: 6d55998b40f62518959f849922919b6b0562981e
    https://github.com/scummvm/scummvm/commit/6d55998b40f62518959f849922919b6b0562981e
Author: Matthew Hoops (clone2727 at gmail.com)
Date: 2014-12-28T21:27:56-05:00

Commit Message:
ZVISION: Make the rest of the controls properly use VideoDecoder timing

The hacky use of getDuration() to retrieve the framerate() is gone

Thanks to md5 for testing (and for filling in a few gaps since I was coding in the blind ;))

Changed paths:
    engines/zvision/scripting/controls/fist_control.cpp
    engines/zvision/scripting/controls/fist_control.h
    engines/zvision/scripting/controls/hotmov_control.cpp
    engines/zvision/scripting/controls/hotmov_control.h
    engines/zvision/scripting/controls/input_control.cpp
    engines/zvision/scripting/controls/safe_control.cpp
    engines/zvision/scripting/controls/safe_control.h



diff --git a/engines/zvision/scripting/controls/fist_control.cpp b/engines/zvision/scripting/controls/fist_control.cpp
index 34a64b4..4a8e8b1 100644
--- a/engines/zvision/scripting/controls/fist_control.cpp
+++ b/engines/zvision/scripting/controls/fist_control.cpp
@@ -46,10 +46,6 @@ FistControl::FistControl(ZVision *engine, uint32 key, Common::SeekableReadStream
 	_order = 0;
 	_fistnum = 0;
 
-	_frameCur = -1;
-	_frameEnd = -1;
-	_frameTime = 0;
-	_lastRenderedFrame = -1;
 	_animationId = 0;
 
 	clearFistArray(_fistsUp);
@@ -95,41 +91,23 @@ FistControl::~FistControl() {
 	_entries.clear();
 }
 
-void FistControl::renderFrame(uint frameNumber) {
-	if ((int32)frameNumber == _lastRenderedFrame)
-		return;
-
-	_lastRenderedFrame = frameNumber;
-
-	const Graphics::Surface *frameData;
-
-	if (_animation) {
-		_animation->seekToFrame(frameNumber);
-		frameData = _animation->decodeNextFrame();
-		if (frameData)
-			_engine->getRenderManager()->blitSurfaceToBkgScaled(*frameData, _anmRect);
-	}
-}
-
 bool FistControl::process(uint32 deltaTimeInMillis) {
 	if (_engine->getScriptManager()->getStateFlag(_key) & Puzzle::DISABLED)
 		return false;
 
-	if (_frameCur >= 0 && _frameEnd >= 0)
-		if (_frameCur <= _frameEnd) {
-			_frameTime -= deltaTimeInMillis;
-
-			if (_frameTime <= 0) {
-				_frameTime = 1000.0 / _animation->getDuration().framerate();
-
-				renderFrame(_frameCur);
-
-				_frameCur++;
+	if (_animation && _animation->isPlaying()) {
+		if (_animation->endOfVideo()) {
+			_animation->stop();
+			_engine->getScriptManager()->setStateValue(_animationId, 2);
+			return false;
+		}
 
-				if (_frameCur > _frameEnd)
-					_engine->getScriptManager()->setStateValue(_animationId, 2);
-			}
+		if (_animation->needsUpdate()) {
+			const Graphics::Surface *frameData = _animation->decodeNextFrame();
+			if (frameData)
+				_engine->getRenderManager()->blitSurfaceToBkgScaled(*frameData, _anmRect);
 		}
+	}
 
 	return false;
 }
@@ -160,9 +138,12 @@ bool FistControl::onMouseUp(const Common::Point &screenSpacePos, const Common::P
 
 		for (int i = 0; i < _numEntries; i++)
 			if (_entries[i]._bitsStrt == oldStatus && _entries[i]._bitsEnd == _fiststatus) {
-				_frameCur = _entries[i]._anmStrt;
-				_frameEnd = _entries[i]._anmEnd;
-				_frameTime = 0;
+				if (_animation) {
+					_animation->stop();
+					_animation->seekToFrame(_entries[i]._anmStrt);
+					_animation->setEndFrame(_entries[i]._anmEnd);
+					_animation->start();
+				}
 
 				_engine->getScriptManager()->setStateValue(_animationId, 1);
 				_engine->getScriptManager()->setStateValue(_soundKey, _entries[i]._sound);
diff --git a/engines/zvision/scripting/controls/fist_control.h b/engines/zvision/scripting/controls/fist_control.h
index 74e8f8d..d7cbcb1 100644
--- a/engines/zvision/scripting/controls/fist_control.h
+++ b/engines/zvision/scripting/controls/fist_control.h
@@ -64,10 +64,6 @@ private:
 	Video::VideoDecoder *_animation;
 	Common::Rect _anmRect;
 	int32   _soundKey;
-	int32   _frameCur;
-	int32   _frameEnd;
-	int32   _frameTime;
-	int32   _lastRenderedFrame;
 	int32   _animationId;
 
 public:
@@ -76,7 +72,6 @@ public:
 	bool process(uint32 deltaTimeInMillis);
 
 private:
-	void renderFrame(uint frameNumber);
 	void readDescFile(const Common::String &fileName);
 	void clearFistArray(Common::Array< Common::Array<Common::Rect> > &arr);
 	uint32 readBits(const char *str);
diff --git a/engines/zvision/scripting/controls/hotmov_control.cpp b/engines/zvision/scripting/controls/hotmov_control.cpp
index e77272e..182447a 100644
--- a/engines/zvision/scripting/controls/hotmov_control.cpp
+++ b/engines/zvision/scripting/controls/hotmov_control.cpp
@@ -41,10 +41,7 @@ HotMovControl::HotMovControl(ZVision *engine, uint32 key, Common::SeekableReadSt
 	: Control(engine, key, CONTROL_HOTMOV) {
 	_animation = NULL;
 	_cycle = 0;
-	_curFrame = -1;
-	_lastRenderedFrame = -1;
 	_frames.clear();
-	_frameTime = 0;
 	_cyclesCount = 0;
 	_framesCount = 0;
 
@@ -78,6 +75,7 @@ HotMovControl::HotMovControl(ZVision *engine, uint32 key, Common::SeekableReadSt
 			sscanf(values.c_str(), "%s", filename);
 			values = Common::String(filename);
 			_animation = _engine->loadAnimation(values);
+			_animation->start();
 		} else if (param.matchString("venus_id", true)) {
 			_venusId = atoi(values.c_str());
 		}
@@ -95,41 +93,26 @@ HotMovControl::~HotMovControl() {
 	_frames.clear();
 }
 
-void HotMovControl::renderFrame(uint frameNumber) {
-	if ((int)frameNumber == _lastRenderedFrame)
-		return;
-
-	_lastRenderedFrame = frameNumber;
-
-	const Graphics::Surface *frameData;
-
-	if (_animation) {
-		_animation->seekToFrame(frameNumber);
-		frameData = _animation->decodeNextFrame();
-		if (frameData)
-			_engine->getRenderManager()->blitSurfaceToBkgScaled(*frameData, _rectangle);
-	}
-}
-
 bool HotMovControl::process(uint32 deltaTimeInMillis) {
 	if (_engine->getScriptManager()->getStateFlag(_key) & Puzzle::DISABLED)
 		return false;
 
 	if (_cycle < _cyclesCount) {
-		_frameTime -= deltaTimeInMillis;
+		if (_animation && _animation->endOfVideo()) {
+			_cycle++;
 
-		if (_frameTime <= 0) {
-			_curFrame++;
-			if (_curFrame >= _framesCount) {
-				_curFrame = 0;
-				_cycle++;
-			}
-			if (_cycle != _cyclesCount)
-				renderFrame(_curFrame);
-			else
+			if (_cycle == _cyclesCount) {
 				_engine->getScriptManager()->setStateValue(_key, 2);
+				return false;
+			}
+
+			_animation->rewind();
+		}
 
-			_frameTime = 1000.0 / _animation->getDuration().framerate();
+		if (_animation && _animation->needsUpdate()) {
+			const Graphics::Surface *frameData = _animation->decodeNextFrame();
+			if (frameData)
+				_engine->getRenderManager()->blitSurfaceToBkgScaled(*frameData, _rectangle);
 		}
 	}
 
@@ -140,8 +123,11 @@ bool HotMovControl::onMouseMove(const Common::Point &screenSpacePos, const Commo
 	if (_engine->getScriptManager()->getStateFlag(_key) & Puzzle::DISABLED)
 		return false;
 
+	if (!_animation)
+		return false;
+
 	if (_cycle < _cyclesCount) {
-		if (_frames[_curFrame].contains(backgroundImageSpacePos)) {
+		if (_frames[_animation->getCurFrame()].contains(backgroundImageSpacePos)) {
 			_engine->getCursorManager()->changeCursor(CursorIndex_Active);
 			return true;
 		}
@@ -154,8 +140,11 @@ bool HotMovControl::onMouseUp(const Common::Point &screenSpacePos, const Common:
 	if (_engine->getScriptManager()->getStateFlag(_key) & Puzzle::DISABLED)
 		return false;
 
+	if (!_animation)
+		return false;
+
 	if (_cycle < _cyclesCount) {
-		if (_frames[_curFrame].contains(backgroundImageSpacePos)) {
+		if (_frames[_animation->getCurFrame()].contains(backgroundImageSpacePos)) {
 			setVenus();
 			_engine->getScriptManager()->setStateValue(_key, 1);
 			return true;
diff --git a/engines/zvision/scripting/controls/hotmov_control.h b/engines/zvision/scripting/controls/hotmov_control.h
index 01c83b5..99d1fd0 100644
--- a/engines/zvision/scripting/controls/hotmov_control.h
+++ b/engines/zvision/scripting/controls/hotmov_control.h
@@ -42,9 +42,6 @@ public:
 
 private:
 	int32  _framesCount;
-	int32  _frameTime;
-	int32  _curFrame;
-	int32  _lastRenderedFrame;
 	int32  _cycle;
 	int32  _cyclesCount;
 	Video::VideoDecoder *_animation;
@@ -56,7 +53,6 @@ public:
 	bool process(uint32 deltaTimeInMillis);
 
 private:
-	void renderFrame(uint frameNumber);
 	void readHsFile(const Common::String &fileName);
 };
 
diff --git a/engines/zvision/scripting/controls/input_control.cpp b/engines/zvision/scripting/controls/input_control.cpp
index 4abc0c9..47da27f 100644
--- a/engines/zvision/scripting/controls/input_control.cpp
+++ b/engines/zvision/scripting/controls/input_control.cpp
@@ -46,9 +46,7 @@ InputControl::InputControl(ZVision *engine, uint32 key, Common::SeekableReadStre
 	  _enterPressed(false),
 	  _readOnly(false),
 	  _txtWidth(0),
-	  _animation(NULL),
-	  _frameDelay(0),
-	  _frame(-1) {
+	  _animation(NULL) {
 	// Loop until we find the closing brace
 	Common::String line = stream.readLine();
 	_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
@@ -99,8 +97,7 @@ InputControl::InputControl(ZVision *engine, uint32 key, Common::SeekableReadStre
 			sscanf(values.c_str(), "%24s %*u", fileName);
 
 			_animation = _engine->loadAnimation(fileName);
-			_frame = -1;
-			_frameDelay = 0;
+			_animation->start();
 		} else if (param.matchString("focus", true)) {
 			_focused = true;
 			_engine->getScriptManager()->setFocusControlKey(_key);
@@ -212,16 +209,10 @@ bool InputControl::process(uint32 deltaTimeInMillis) {
 	}
 
 	if (_animation && !_readOnly && _focused) {
-		bool needDraw = true;// = _textChanged;
-		_frameDelay -= deltaTimeInMillis;
-		if (_frameDelay <= 0) {
-			_frame = (_frame + 1) % _animation->getFrameCount();
-			_frameDelay = 1000.0 / _animation->getDuration().framerate();
-			needDraw = true;
-		}
+		if (_animation->endOfVideo())
+			_animation->rewind();
 
-		if (needDraw) {
-			_animation->seekToFrame(_frame);
+		if (_animation->needsUpdate()) {
 			const Graphics::Surface *srf = _animation->decodeNextFrame();
 			int16 xx = _textRectangle.left + _txtWidth;
 			if (xx >= _textRectangle.left + (_textRectangle.width() - (int16)_animation->getWidth()))
diff --git a/engines/zvision/scripting/controls/safe_control.cpp b/engines/zvision/scripting/controls/safe_control.cpp
index 71be692..6ba3410 100644
--- a/engines/zvision/scripting/controls/safe_control.cpp
+++ b/engines/zvision/scripting/controls/safe_control.cpp
@@ -49,10 +49,7 @@ SafeControl::SafeControl(ZVision *engine, uint32 key, Common::SeekableReadStream
 	_outerRadiusSqr = 0;
 	_zeroPointer = 0;
 	_startPointer = 0;
-	_curFrame = -1;
 	_targetFrame = 0;
-	_frameTime = 0;
-	_lastRenderedFrame = -1;
 
 	// Loop until we find the closing brace
 	Common::String line = stream.readLine();
@@ -64,6 +61,7 @@ SafeControl::SafeControl(ZVision *engine, uint32 key, Common::SeekableReadStream
 	while (!stream.eos() && !line.contains('}')) {
 		if (param.matchString("animation", true)) {
 			_animation = _engine->loadAnimation(values);
+			_animation->start();
 		} else if (param.matchString("rectangle", true)) {
 			int x;
 			int y;
@@ -104,7 +102,9 @@ SafeControl::SafeControl(ZVision *engine, uint32 key, Common::SeekableReadStream
 		_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 		getParams(line, param, values);
 	}
-	renderFrame(_curState);
+
+	if (_animation)
+		_animation->seekToFrame(_curState);
 }
 
 SafeControl::~SafeControl() {
@@ -113,44 +113,20 @@ SafeControl::~SafeControl() {
 
 }
 
-void SafeControl::renderFrame(uint frameNumber) {
-	if (frameNumber == 0) {
-		_lastRenderedFrame = frameNumber;
-	} else if ((int16)frameNumber < _lastRenderedFrame) {
-		_lastRenderedFrame = frameNumber;
-		frameNumber = (_statesCount * 2) - frameNumber;
-	} else {
-		_lastRenderedFrame = frameNumber;
-	}
-
-	const Graphics::Surface *frameData;
-	int x = _rectangle.left;
-	int y = _rectangle.top;
-
-	_animation->seekToFrame(frameNumber);
-	frameData = _animation->decodeNextFrame();
-	if (frameData)
-		_engine->getRenderManager()->blitSurfaceToBkg(*frameData, x, y);
-}
-
 bool SafeControl::process(uint32 deltaTimeInMillis) {
 	if (_engine->getScriptManager()->getStateFlag(_key) & Puzzle::DISABLED)
 		return false;
 
-	if (_curFrame != _targetFrame) {
-		_frameTime -= deltaTimeInMillis;
-
-		if (_frameTime <= 0) {
-			if (_curFrame < _targetFrame) {
-				_curFrame++;
-				renderFrame(_curFrame);
-			} else if (_curFrame > _targetFrame) {
-				_curFrame--;
-				renderFrame(_curFrame);
-			}
-			_frameTime = 1000.0 / _animation->getDuration().framerate();
-		}
+	if (_animation && _animation->getCurFrame() != _targetFrame && _animation->needsUpdate()) {
+		// If we're past the target frame, move back one
+		if (_animation->getCurFrame() > _targetFrame)
+			_animation->seekToFrame(_animation->getCurFrame() - 1);
+
+		const Graphics::Surface *frameData = _animation->decodeNextFrame();
+		if (frameData)
+			_engine->getRenderManager()->blitSurfaceToBkg(*frameData, _rectangle.left, _rectangle.top);
 	}
+
 	return false;
 }
 
@@ -187,7 +163,8 @@ bool SafeControl::onMouseUp(const Common::Point &screenSpacePos, const Common::P
 
 			int16 tmp2 = (m_state + _curState - _zeroPointer + _statesCount - 1) % _statesCount;
 
-			_curFrame = (_curState + _statesCount - _startPointer) % _statesCount;
+			if (_animation)
+				_animation->seekToFrame((_curState + _statesCount - _startPointer) % _statesCount);
 
 			_curState = (_statesCount * 2 + tmp2) % _statesCount;
 
diff --git a/engines/zvision/scripting/controls/safe_control.h b/engines/zvision/scripting/controls/safe_control.h
index 2577ff4..3e8c176 100644
--- a/engines/zvision/scripting/controls/safe_control.h
+++ b/engines/zvision/scripting/controls/safe_control.h
@@ -52,19 +52,12 @@ private:
 	int32  _outerRadiusSqr;
 	int16  _zeroPointer;
 	int16  _startPointer;
-	int16  _curFrame;
 	int16  _targetFrame;
-	int32  _frameTime;
-
-	int16 _lastRenderedFrame;
 
 public:
 	bool onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos);
 	bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos);
 	bool process(uint32 deltaTimeInMillis);
-
-private:
-	void renderFrame(uint frameNumber);
 };
 
 } // End of namespace ZVision






More information about the Scummvm-git-logs mailing list