[Scummvm-cvs-logs] SF.net SVN: scummvm: [23525] scummvm/trunk/engines/sword2

eriktorbjorn at users.sourceforge.net eriktorbjorn at users.sourceforge.net
Thu Jul 20 22:52:03 CEST 2006


Revision: 23525
          http://svn.sourceforge.net/scummvm/?rev=23525&view=rev
Author:   eriktorbjorn
Date:     2006-07-15 16:44:44 -0700 (Sat, 15 Jul 2006)

Log Message:
-----------
Some cleanups and restructuring. The clearScreen() function has been renamed
clearFrame(), and is only responsible for clearing the frame buffer. Frame
syncing and frame drawing are now separate from each other.

Modified Paths:
--------------
    scummvm/trunk/engines/sword2/animation.cpp
    scummvm/trunk/engines/sword2/animation.h

Modified: scummvm/trunk/engines/sword2/animation.cpp
===================================================================
--- scummvm/trunk/engines/sword2/animation.cpp	2006-07-15 23:18:11 UTC (rev 23524)
+++ scummvm/trunk/engines/sword2/animation.cpp	2006-07-15 23:44:44 UTC (rev 23525)
@@ -143,9 +143,8 @@
 	_vm->_screen->setPalette(0, 256, _originalPalette, RDPAL_INSTANT);
 }
 
-void MoviePlayer::clearScreen() {
-	_vm->_screen->clearScene();
-	_system->copyRectToScreen(_vm->_screen->getScreen(), _vm->_screen->getScreenWide(), 0, 0, _vm->_screen->getScreenWide(), _vm->_screen->getScreenDeep());
+void MoviePlayer::clearFrame() {
+	memset(_frameBuffer, 0, _vm->_screen->getScreenWide() * _vm->_screen->getScreenDeep());
 }
 
 void MoviePlayer::updateScreen() {
@@ -176,7 +175,14 @@
 	return true;
 }
 
-void MoviePlayer::waitForFrame() {
+void MoviePlayer::syncFrame() {
+	_ticks += 83;
+
+	if (checkSkipFrame()) {
+		warning("Skipped frame %d", _currentFrame);
+		return;
+	}
+
 	if (_bgSoundStream) {
 		while (_mixer->isSoundHandleActive(_bgSoundHandle) && (_mixer->getSoundElapsedTime(_bgSoundHandle) * 12) / 1000 < _currentFrame) {
 			_system->delayMillis(10);
@@ -195,19 +201,9 @@
 }
 
 void MoviePlayer::drawFrame() {
-	_ticks += 83;
-
-	if (checkSkipFrame()) {
-		warning("Skipped frame %d", _currentFrame);
-		return;
-	}
-
-	waitForFrame();
-
 	int screenWidth = _vm->_screen->getScreenWide();
 
 	_system->copyRectToScreen(_frameBuffer + _frameY * screenWidth + _frameX, screenWidth, _frameX, _frameY, _frameWidth, _frameHeight);
-	_vm->_screen->setNeedFullRedraw();
 }
 
 void MoviePlayer::openTextObject(MovieTextObject *t) {
@@ -360,6 +356,7 @@
 			_vm->_sound->playFx(&leadOutHandle, data, len, Audio::Mixer::kMaxChannelVolume, 0, false, Audio::Mixer::kMusicSoundType);
 		}
 
+		syncFrame();
 		drawFrame();
 		updateScreen();
 
@@ -388,7 +385,7 @@
 		// Most cutscenes fade to black on their own, but not all of
 		// them. I think it looks better if they do.
 
-		clearScreen();
+		clearFrame();
 
 		// If the sound is still playing, draw the subtitles one final
 		// time. This happens in the "carib" cutscene.
@@ -397,6 +394,7 @@
 			drawTextObject(_textList[_currentText]);
 		}
 
+		drawFrame();
 		updateScreen();
 	}
 
@@ -406,25 +404,22 @@
 	}
 
 	if (!terminate) {
-		// Wait for the voice to stop playing. This is to make sure
-		// that we don't cut off the speech in mid-sentence, and - even
-		// more importantly - that we don't free the sound buffer while
-		// it's still in use.
+		// Wait for the voice and sound track to stop playing. This is
+		// to make sure that we don't cut off the speech in
+		// mid-sentence, and - even more importantly - that we don't
+		// free the sound buffer while it's still in use.
 
-		while (_mixer->isSoundHandleActive(_speechHandle)) {
+		while (_mixer->isSoundHandleActive(_speechHandle) || _mixer->isSoundHandleActive(_bgSoundHandle)) {
 			_system->delayMillis(100);
 		}
-
-		while (_mixer->isSoundHandleActive(_bgSoundHandle)) {
-			_system->delayMillis(100);
-		}
 	} else {
 		_mixer->stopHandle(_speechHandle);
 		_mixer->stopHandle(_bgSoundHandle);
 	}
 
 	if (!_seamless) {
-		clearScreen();
+		clearFrame();
+		drawFrame();
 		updateScreen();
 	}
 
@@ -525,13 +520,6 @@
 	return true;
 }
 
-bool MoviePlayerMPEG::checkSkipFrame() {
-	return false;
-}
-
-void MoviePlayerMPEG::waitForFrame() {
-}
-
 bool MoviePlayerMPEG::decodeFrame() {
 	bool result = _anim->decodeFrame();
 
@@ -546,6 +534,9 @@
 	return result;
 }
 
+void MoviePlayerMPEG::syncFrame() {
+}
+
 AnimationState::AnimationState(Sword2Engine *vm, MoviePlayer *player)
 	: BaseAnimationState(vm->_mixer, vm->_system, 640, 480) {
 	_vm = vm;
@@ -567,8 +558,8 @@
 	_anim->handleScreenChanged();
 }
 
-void MoviePlayerMPEG::clearScreen() {
-	_anim->clearScreen();
+void MoviePlayerMPEG::clearFrame() {
+	_anim->clearFrame();
 }
 
 void MoviePlayerMPEG::drawFrame() {
@@ -635,7 +626,7 @@
 }
 #endif
 
-void AnimationState::clearScreen() {
+void AnimationState::clearFrame() {
 #ifdef BACKEND_8BIT
 	memset(_vm->_screen->getScreen(), 0, _movieWidth * _movieHeight);
 #else
@@ -768,22 +759,16 @@
 	return true;
 }
 
-bool MoviePlayerDummy::checkSkipFrame() {
-	return false;
-}
-
-void MoviePlayerDummy::waitForFrame() {
+void MoviePlayerDummy::syncFrame() {
 	if (!_textList || _currentFrame < _textList[0]->startFrame) {
 		_ticks = _system->getMillis();
 		return;
 	}
 
-	MoviePlayer::waitForFrame();
+	MoviePlayer::syncFrame();
 }
 
 void MoviePlayerDummy::drawFrame() {
-	_ticks += 83;
-	waitForFrame();
 }
 
 void MoviePlayerDummy::drawTextObject(MovieTextObject *t) {

Modified: scummvm/trunk/engines/sword2/animation.h
===================================================================
--- scummvm/trunk/engines/sword2/animation.h	2006-07-15 23:18:11 UTC (rev 23524)
+++ scummvm/trunk/engines/sword2/animation.h	2006-07-15 23:44:44 UTC (rev 23525)
@@ -49,6 +49,9 @@
 };
 
 class MoviePlayer {
+private:
+	bool checkSkipFrame();
+
 protected:
 	Sword2Engine *_vm;
 	Audio::Mixer *_mixer;
@@ -91,11 +94,10 @@
 
 	virtual void handleScreenChanged() {}
 
-	virtual void clearScreen();
+	virtual void clearFrame();
 	virtual void updateScreen();
 	virtual bool decodeFrame() = 0;
-	virtual bool checkSkipFrame();
-	virtual void waitForFrame();
+	virtual void syncFrame();
 	virtual void drawFrame();
 	virtual void drawTextObject(MovieTextObject *t);
 	virtual void undrawTextObject(MovieTextObject *t);
@@ -112,8 +114,7 @@
 class MoviePlayerDummy : public MoviePlayer {
 protected:
 	virtual bool decodeFrame();
-	virtual bool checkSkipFrame();
-	virtual void waitForFrame();
+	virtual void syncFrame();
 	virtual void drawFrame();
 	virtual void drawTextObject(MovieTextObject *t);
 	virtual void undrawTextObject(MovieTextObject *t);
@@ -139,7 +140,7 @@
 	void drawTextObject(SpriteInfo *s, byte *src);
 #endif
 
-	void clearScreen();
+	void clearFrame();
 
 private:
 	void drawYUV(int width, int height, byte *const *dat);
@@ -153,13 +154,12 @@
 protected:
 	AnimationState *_anim;
 
-	virtual bool checkSkipFrame();
-	virtual void waitForFrame();
 	virtual bool decodeFrame();
+	virtual void syncFrame();
 
 #ifndef BACKEND_8BIT
 	virtual void handleScreenChanged();
-	virtual void clearScreen();
+	virtual void clearFrame();
 	virtual void drawFrame();
 	virtual void updateScreen();
 	virtual void drawTextObject(MovieTextObject *t);






More information about the Scummvm-git-logs mailing list