[Scummvm-cvs-logs] SF.net SVN: scummvm:[50723] scummvm/trunk/engines/m4

dreammaster at users.sourceforge.net dreammaster at users.sourceforge.net
Tue Jul 6 13:33:09 CEST 2010


Revision: 50723
          http://scummvm.svn.sourceforge.net/scummvm/?rev=50723&view=rev
Author:   dreammaster
Date:     2010-07-06 11:33:09 +0000 (Tue, 06 Jul 2010)

Log Message:
-----------
Added support for idle character animations

Modified Paths:
--------------
    scummvm/trunk/engines/m4/assets.cpp
    scummvm/trunk/engines/m4/assets.h
    scummvm/trunk/engines/m4/m4.cpp
    scummvm/trunk/engines/m4/mads_player.cpp
    scummvm/trunk/engines/m4/mads_player.h
    scummvm/trunk/engines/m4/mads_scene.cpp
    scummvm/trunk/engines/m4/mads_views.cpp
    scummvm/trunk/engines/m4/mads_views.h

Modified: scummvm/trunk/engines/m4/assets.cpp
===================================================================
--- scummvm/trunk/engines/m4/assets.cpp	2010-07-06 11:32:10 UTC (rev 50722)
+++ scummvm/trunk/engines/m4/assets.cpp	2010-07-06 11:33:09 UTC (rev 50723)
@@ -632,9 +632,9 @@
 //--------------------------------------------------------------------------
 
 MadsSpriteSetCharInfo::MadsSpriteSetCharInfo(Common::SeekableReadStream *s) {
-	_frameNumber = s->readByte();
+	_totalFrames = s->readByte();
 	s->skip(1);
-	_hasIdling = s->readUint16LE() != 0;
+	_numEntries = s->readUint16LE();
 	
 	for (int i = 0; i < 16; ++i)
 		_frameList[i] = s->readUint16LE();

Modified: scummvm/trunk/engines/m4/assets.h
===================================================================
--- scummvm/trunk/engines/m4/assets.h	2010-07-06 11:32:10 UTC (rev 50722)
+++ scummvm/trunk/engines/m4/assets.h	2010-07-06 11:33:09 UTC (rev 50723)
@@ -106,8 +106,8 @@
 public:
 	MadsSpriteSetCharInfo(Common::SeekableReadStream *s);
 
-	int _frameNumber;
-	int _hasIdling;
+	int _totalFrames;
+	int _numEntries;
 	int _frameList2[16];
 	int _frameList[16];
 	int _ticksList[16];

Modified: scummvm/trunk/engines/m4/m4.cpp
===================================================================
--- scummvm/trunk/engines/m4/m4.cpp	2010-07-06 11:32:10 UTC (rev 50722)
+++ scummvm/trunk/engines/m4/m4.cpp	2010-07-06 11:33:09 UTC (rev 50723)
@@ -538,6 +538,8 @@
 	//printf("%s\n----------\n", _globals->loadMessage(i));
 
 	if (getGameType() == GType_RexNebular) {
+		MadsGameLogic::initialiseGlobals();
+
 		_scene = NULL;
 		loadMenu(MAIN_MENU);
 	} else {

Modified: scummvm/trunk/engines/m4/mads_player.cpp
===================================================================
--- scummvm/trunk/engines/m4/mads_player.cpp	2010-07-06 11:32:10 UTC (rev 50722)
+++ scummvm/trunk/engines/m4/mads_player.cpp	2010-07-06 11:33:09 UTC (rev 50723)
@@ -38,6 +38,9 @@
 	_direction = 0;
 	_direction2 = 0;
 	_forceRefresh = true;
+	_stepEnabled = true;
+	_ticksAmount = 3;
+	_priorTimer = 0;
 	_visible = true;
 	_priorVisible = false;
 	_visible3 = false;
@@ -53,7 +56,7 @@
 	_frameNum = 0;
 	_frameOffset = 0;
 	_unk1 = 0;
-	_newFrame = 0;
+	_frameCount = 0;
 	_frameListIndex = 0;
 	_actionIndex = 0;
 	resetActionList();
@@ -154,7 +157,7 @@
 
 				if (equal)
 					// Undo the prior expiry of the player sprite
-					slot.spriteType = SPRITE_ZERO;
+					s2.spriteType = SPRITE_ZERO;
 				else
 					slotIndex = -1;
 			}
@@ -175,13 +178,13 @@
 }
 
 /**
- * Idling animation for player
+ * Updates the animation frame for the player
  */
-void MadsPlayer::idle() {
+void MadsPlayer::updateFrame() {
 	SpriteAsset &spriteSet = _madsVm->scene()->_spriteSlots.getSprite(_spriteListIdx + _spriteListIdx2);
 	assert(spriteSet._charInfo);
 
-	if (!spriteSet._charInfo->_hasIdling) {
+	if (!spriteSet._charInfo->_numEntries) {
 		_frameNum = 1;
 	} else {
 		_frameListIndex = _actionList[_actionIndex];
@@ -204,7 +207,7 @@
 		if (frameIndex == 0)
 			setTicksAmount();
 		else
-			_madsVm->scene()->_ticksAmount = spriteSet._charInfo->_ticksList[frameIndex];
+			_madsVm->_player._ticksAmount = spriteSet._charInfo->_ticksList[frameIndex];
 	}
 }
 
@@ -223,21 +226,105 @@
 	_unk1 = MAX(spriteSet._charInfo->_unk1, 100);
 	setTicksAmount();
 
-	_newFrame = spriteSet._charInfo->_frameNumber;
-	if (_newFrame == 0)
-		_newFrame = spriteSet.getCount();
+	_frameCount = spriteSet._charInfo->_totalFrames;
+	if (_frameCount == 0)
+		_frameCount = spriteSet.getCount();
 
 	_yScale = spriteSet._charInfo->_yScale;
 	
-	if ((_frameNum <= 0) || (_frameNum > _newFrame))
+	if ((_frameNum <= 0) || (_frameNum > _frameCount))
 		_frameNum = 1;
 	_forceRefresh = true;
 }
 
 void MadsPlayer::step() {
+	if (_visible && _stepEnabled && !_moving && (_direction == _direction2) && (_madsVm->_currentTimer >= GET_GLOBAL32(2))) {
+		if (_actionIndex == 0) {
+			int randVal = _vm->_random->getRandomNumber(29999);
 
+			if (GET_GLOBAL(0) == SEX_MALE) {
+				switch (_direction) {
+				case 1:
+				case 3:
+				case 7:
+				case 9:
+					if (randVal < 200) {
+						queueAction(-1, 0);
+						queueAction(1, 0);
+					}
+					break;
+
+				case 2:
+					if (randVal < 500) {
+						for (int i = 0; i < 10; ++i)
+							queueAction((randVal < 250) ? 1 : 2, 0);
+					} else if (randVal < 750) {
+						for (int i = 0; i < 5; ++i)
+							queueAction(1, 0);
+						queueAction(0, 0);
+						for (int i = 0; i < 5; ++i)
+							queueAction(2, 0);
+					}
+					break;
+
+				case 4:
+				case 6:
+					if (randVal < 500) {
+						for (int i = 0; i < 10; ++i)
+							queueAction(1, 0);
+					}
+					break;
+
+				case 5:
+				case 8:
+					if (randVal < 200) {
+						queueAction(-1, 0);
+						queueAction(1, 0);
+					}
+					break;
+				}
+			}
+		}
+
+		SET_GLOBAL32(2, GET_GLOBAL32(2) + 6);
+	}
+
+	if (GET_GLOBAL(138) == 1) {
+		uint32 diff = _madsVm->_currentTimer - GET_GLOBAL32(142);
+		if (diff > 60) {
+			SET_GLOBAL32(144, GET_GLOBAL32(144) + 1);
+		} else {
+			SET_GLOBAL32(144, GET_GLOBAL32(144) + diff);
+		}
+
+		SET_GLOBAL32(142, _madsVm->_currentTimer);
+	}
 }
 
+void MadsPlayer::nextFrame() {
+	if (_madsVm->_currentTimer >= (_priorTimer + _ticksAmount)) {
+		_priorTimer = _madsVm->_currentTimer;
+
+		if (_moving)
+			move();
+		else
+			idle();
+
+		// Post update logic
+		if (_moving) {
+			++_frameNum;
+			if (_frameNum > _frameCount)
+				_frameNum = 1;
+			_forceRefresh = true;
+		} else if (!_forceRefresh) {
+			idle();
+		}
+
+		// Final update
+		update();
+	}
+}
+
 int MadsPlayer::getScale(int yp) {
 	MadsSceneResources &r = _madsVm->scene()->getSceneResources();
 
@@ -262,9 +349,9 @@
 void MadsPlayer::setTicksAmount() {
 	SpriteAsset &spriteSet = _madsVm->scene()->_spriteSlots.getSprite(_spriteListIdx + _spriteListIdx2);
 	assert(spriteSet._charInfo);
-	_madsVm->scene()->_ticksAmount = spriteSet._charInfo->_ticksAmount;
-	if (_madsVm->scene()->_ticksAmount == 0)
-		_madsVm->scene()->_ticksAmount = 6;
+	_madsVm->_player._ticksAmount = spriteSet._charInfo->_ticksAmount;
+	if (_madsVm->_player._ticksAmount == 0)
+		_madsVm->_player._ticksAmount = 6;
 }
 
 void MadsPlayer::resetActionList() {
@@ -279,7 +366,7 @@
 	SpriteAsset &spriteSet = _madsVm->scene()->_spriteSlots.getSprite(_spriteListIdx + _spriteListIdx2);
 	assert(spriteSet._charInfo);
 
-	if ((spriteSet._charInfo->_hasIdling) && (_actionIndex < 11)) {
+	if ((action1 < spriteSet._charInfo->_numEntries) && (_actionIndex < 11)) {
 		++_actionIndex;
 		_actionList[_actionIndex] = action1;
 		_actionList2[_actionIndex] = action2;
@@ -289,4 +376,79 @@
 	return true;
 }
 
+void MadsPlayer::idle() {
+	if (_direction != _direction2) {
+		// The direction has changed, so reset for new direction
+		dirChanged();
+		return;
+	}
+
+	SpriteAsset &spriteSet = _madsVm->scene()->_spriteSlots.getSprite(_spriteListIdx + _spriteListIdx2);
+	assert(spriteSet._charInfo);
+	if (spriteSet._charInfo->_numEntries == 0)
+		// No entries, so exit immediately
+		return;
+
+	int frameIndex = ABS(_frameListIndex);
+	int direction = (_frameListIndex < 0) ? -1 : 1;
+
+	if (frameIndex >= spriteSet._charInfo->_numEntries)
+		// Reset back to the start of the list
+		_frameListIndex = 0;
+	else {
+		_frameNum += direction;
+		_forceRefresh = true;
+
+		if (spriteSet._charInfo->_frameList2[frameIndex] < _frameNum) {
+			_unk3 = _unk2;
+			updateFrame();
+		}
+		if (spriteSet._charInfo->_frameList[frameIndex] < _frameNum) {
+			_unk3 = _unk2;
+			updateFrame();
+		}
+	}
+}
+
+void MadsPlayer::move() {
+	// TODO: Handle player movement
+}
+
+void MadsPlayer::dirChanged() {
+	int dirIndex = 0, dirIndex2 = 0;
+	int newDir = 0, newDir2 = 0;
+
+	if (_direction != _direction2) {
+		// Find the index for the given direction in the player direction list
+		int tempDir = _direction;
+		do {
+			++dirIndex;
+			newDir += tempDir;
+			tempDir = _directionListIndexes[tempDir + 10];
+		} while (tempDir != _direction2);
+	}
+
+
+	if (_direction != _direction2) {
+		// Find the index for the given direction in the player direction list
+		int tempDir = _direction;
+		do {
+			++dirIndex2;
+			newDir2 += tempDir;
+			tempDir = _directionListIndexes[tempDir + 10];
+		} while (tempDir != _direction2);
+	}
+
+	int diff = dirIndex - dirIndex2;
+	if (diff == 0)
+		diff = newDir - newDir2;
+
+	_direction = (diff >= 0) ? _directionListIndexes[_direction] : _directionListIndexes[_direction + 10];
+	setupFrame();
+	if ((_direction == _direction2) && !_moving)
+		updateFrame();
+
+	_priorTimer += 1;
+}
+
 } // End of namespace M4

Modified: scummvm/trunk/engines/m4/mads_player.h
===================================================================
--- scummvm/trunk/engines/m4/mads_player.h	2010-07-06 11:32:10 UTC (rev 50722)
+++ scummvm/trunk/engines/m4/mads_player.h	2010-07-06 11:33:09 UTC (rev 50723)
@@ -39,13 +39,19 @@
 	void setTicksAmount();
 	void resetActionList();
 	int queueAction(int v0, int v1);
+	void idle();
+	void move();
+	void dirChanged();
 public:
 	char _spritesPrefix[16];
 	int _spriteSetCount;
 	bool _spriteSetsPresent[8];
 	Common::Point _playerPos;
 	Common::Point _destPos;
+	uint32 _priorTimer;
+	uint _ticksAmount;
 	int16 _direction, _direction2;
+	bool _stepEnabled;
 	bool _visible, _priorVisible;
 	bool _visible3;
 	bool _forceRefresh;
@@ -57,7 +63,7 @@
 	uint16 _frameOffset, _frameNum;
 	bool _moving;
 	int _unk1;
-	int _newFrame;
+	int _frameCount;
 	int _frameListIndex;
 	int _actionIndex;
 	int _actionList[12];
@@ -71,9 +77,10 @@
 
 	bool loadSprites(const char *prefix);
 	void update();
-	void idle();
+	void updateFrame();
 	void setupFrame();
 	void step();
+	void nextFrame();
 };
 
 } // End of namespace M4

Modified: scummvm/trunk/engines/m4/mads_scene.cpp
===================================================================
--- scummvm/trunk/engines/m4/mads_scene.cpp	2010-07-06 11:32:10 UTC (rev 50722)
+++ scummvm/trunk/engines/m4/mads_scene.cpp	2010-07-06 11:33:09 UTC (rev 50723)
@@ -167,7 +167,7 @@
 	_madsVm->_player._destPos = _madsVm->_player._destPos;
 	_madsVm->_player._direction2 = _madsVm->_player._direction;
 	_madsVm->_player.setupFrame();
-	_madsVm->_player.idle();
+	_madsVm->_player.updateFrame();
 
 	// Purge resources
 	_vm->res()->purge();
@@ -337,9 +337,15 @@
 	// Step through the scene
 	_sceneLogic.sceneStep();
 
+	_madsVm->_player.step();
+	_madsVm->_player._unk3 = 0;
+
 	if (_abortTimersMode == ABORTMODE_1)
 		_abortTimers = 0;
 
+	// Handle updating the player frame
+	_madsVm->_player.nextFrame();
+	
 	if ((_activeAnimation) && !_abortTimers) {
 		_activeAnimation->update();
 		if (((MadsAnimation *) _activeAnimation)->freeFlag()) {

Modified: scummvm/trunk/engines/m4/mads_views.cpp
===================================================================
--- scummvm/trunk/engines/m4/mads_views.cpp	2010-07-06 11:32:10 UTC (rev 50722)
+++ scummvm/trunk/engines/m4/mads_views.cpp	2010-07-06 11:33:09 UTC (rev 50723)
@@ -426,15 +426,15 @@
 	for (int i = 0; i < 3; ++i)
 		rec.actionNouns[i] = _madsVm->globals()->actionNouns[i];
 
-	if (flags & KMSG_OWNER_TIMEOUT)
-		rec.frameTimer = _owner._ticksAmount + _owner._newTimeout;
+	if (flags & KMSG_PLAYER_TIMEOUT)
+		rec.frameTimer = _madsVm->_player._ticksAmount + _madsVm->_player._priorTimer;
 
 	return idx;
 }
 
 int MadsKernelMessageList::addQuote(int quoteId, int abortTimers, uint32 timeout) {
 	const char *quoteStr = _madsVm->globals()->getQuote(quoteId);
-	return add(Common::Point(0, 0), 0x1110, KMSG_OWNER_TIMEOUT | KMSG_CENTER_ALIGN, abortTimers, timeout, quoteStr);
+	return add(Common::Point(0, 0), 0x1110, KMSG_PLAYER_TIMEOUT | KMSG_CENTER_ALIGN, abortTimers, timeout, quoteStr);
 }
 
 void MadsKernelMessageList::scrollMessage(int msgIndex, int numTicks, bool quoted) {
@@ -450,8 +450,8 @@
 	_entries[msgIndex].asciiChar = *msgP;
 	_entries[msgIndex].asciiChar2 = *(msgP + 1);
 
-	if (_entries[msgIndex].flags & KMSG_OWNER_TIMEOUT)
-		_entries[msgIndex].frameTimer2 = _owner._ticksAmount + _owner._newTimeout;
+	if (_entries[msgIndex].flags & KMSG_PLAYER_TIMEOUT)
+		_entries[msgIndex].frameTimer2 = _madsVm->_player._ticksAmount + _madsVm->_player._priorTimer;
 
 	_entries[msgIndex].frameTimer = _entries[msgIndex].frameTimer2;
 }
@@ -545,7 +545,7 @@
 		}
 	}
 	
-	if (msg.flags & KMSG_OWNER_TIMEOUT) {
+	if (msg.flags & KMSG_PLAYER_TIMEOUT) {
 		if (word_8469E != 0) {
 			// TODO: Figure out various flags
 		} else {
@@ -1211,7 +1211,6 @@
 		_kernelMessages(*this), _spriteSlots(*this), _dirtyAreas(*this), _textDisplay(*this) {
 		
 	_textSpacing = -1;
-	_ticksAmount = 3;
 	_newTimeout = 0;
 	_abortTimers = 0;
 	_abortTimers2 = 0;

Modified: scummvm/trunk/engines/m4/mads_views.h
===================================================================
--- scummvm/trunk/engines/m4/mads_views.h	2010-07-06 11:32:10 UTC (rev 50722)
+++ scummvm/trunk/engines/m4/mads_views.h	2010-07-06 11:33:09 UTC (rev 50723)
@@ -149,7 +149,7 @@
 #define TIMED_TEXT_SIZE 10
 #define INDEFINITE_TIMEOUT 9999999
 
-enum KernelMessageFlags {KMSG_QUOTED = 1, KMSG_OWNER_TIMEOUT = 2, KMSG_SEQ_ENTRY = 4, KMSG_SCROLL = 8, KMSG_RIGHT_ALIGN = 0x10, 
+enum KernelMessageFlags {KMSG_QUOTED = 1, KMSG_PLAYER_TIMEOUT = 2, KMSG_SEQ_ENTRY = 4, KMSG_SCROLL = 8, KMSG_RIGHT_ALIGN = 0x10, 
 	KMSG_CENTER_ALIGN = 0x20, KMSG_EXPIRE = 0x40, KMSG_ACTIVE = 0x80};
 
 class MadsKernelMessageEntry {
@@ -395,7 +395,6 @@
 	MadsDirtyAreas _dirtyAreas;
 
 	int _textSpacing;
-	int _ticksAmount;
 	uint32 _newTimeout;
 	int _abortTimers;
 	int8 _abortTimers2;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list