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

dreammaster at users.sourceforge.net dreammaster at users.sourceforge.net
Fri Apr 30 13:27:42 CEST 2010


Revision: 48875
          http://scummvm.svn.sourceforge.net/scummvm/?rev=48875&view=rev
Author:   dreammaster
Date:     2010-04-30 11:27:42 +0000 (Fri, 30 Apr 2010)

Log Message:
-----------
Added proper names for some of the previous unknown timer fields, and bugfixes for the sequence list methods

Modified Paths:
--------------
    scummvm/trunk/engines/m4/assets.cpp
    scummvm/trunk/engines/m4/m4.cpp
    scummvm/trunk/engines/m4/m4.h
    scummvm/trunk/engines/m4/mads_logic.cpp
    scummvm/trunk/engines/m4/mads_logic.h
    scummvm/trunk/engines/m4/mads_menus.cpp
    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-04-29 22:11:22 UTC (rev 48874)
+++ scummvm/trunk/engines/m4/assets.cpp	2010-04-30 11:27:42 UTC (rev 48875)
@@ -227,7 +227,7 @@
 		frame.w = spriteStream->readUint16LE();
 		frame.h = spriteStream->readUint16LE();
 		if (curFrame == 0)
-			printf("%i frames, x = %i, y = %i, w = %i, h = %i\n", _frameCount, frame.x, frame.y, frame.w, frame.h);
+			debugC(1, kDebugGraphics, "%i frames, x = %i, y = %i, w = %i, h = %i\n", _frameCount, frame.x, frame.y, frame.w, frame.h);
 
 		frame.frame = new M4Sprite(spriteDataStream, frame.x, frame.y, frame.w, frame.h, false);
 		_frames.push_back(frame);

Modified: scummvm/trunk/engines/m4/m4.cpp
===================================================================
--- scummvm/trunk/engines/m4/m4.cpp	2010-04-29 22:11:22 UTC (rev 48874)
+++ scummvm/trunk/engines/m4/m4.cpp	2010-04-30 11:27:42 UTC (rev 48875)
@@ -115,6 +115,7 @@
 	SearchMan.addSubDirectoryMatching(_gameDataDir, "resource");
 
 	DebugMan.addDebugChannel(kDebugScript, "script", "Script debug level");
+	DebugMan.addDebugChannel(kDebugGraphics, "graphics", "Graphics debug level");
 	DebugMan.addDebugChannel(kDebugConversations, "conversations", "Conversations debugging");
 
 	_resourceManager = NULL;

Modified: scummvm/trunk/engines/m4/m4.h
===================================================================
--- scummvm/trunk/engines/m4/m4.h	2010-04-29 22:11:22 UTC (rev 48874)
+++ scummvm/trunk/engines/m4/m4.h	2010-04-30 11:27:42 UTC (rev 48875)
@@ -113,7 +113,8 @@
 
 enum {
 	kDebugScript = 1 << 0,
-	kDebugConversations = 2 << 0
+	kDebugConversations = 1 << 1,
+	kDebugGraphics = 1 << 2
 };
 
 #define MESSAGE_BASIC 1

Modified: scummvm/trunk/engines/m4/mads_logic.cpp
===================================================================
--- scummvm/trunk/engines/m4/mads_logic.cpp	2010-04-29 22:11:22 UTC (rev 48874)
+++ scummvm/trunk/engines/m4/mads_logic.cpp	2010-04-30 11:27:42 UTC (rev 48875)
@@ -83,16 +83,16 @@
 		spriteFrame->y + (spriteFrame->height() / 2));
 
 	return _madsVm->scene()->_sequenceList.add(srcSpriteIdx, v0, 1, fld24, timeoutTicks, extraTicks, numTicks, 0, 0, 
-		-1, 100, (int)pixel - 1, 1, 1, 0, 0);
+		-1, 100, (int)pixel - 1, 1, ANIMTYPE_SINGLE_DIRECTION, 0, 0);
 }
 
-uint16 MadsSceneLogic::startSpriteSequence2(uint16 srcSpriteIdx, int v0, int numTicks, int fld24, int timeoutTicks, int extraTicks) {
+uint16 MadsSceneLogic::startCycledSpriteSequence(uint16 srcSpriteIdx, int v0, int numTicks, int fld24, int timeoutTicks, int extraTicks) {
 	M4Sprite *spriteFrame = _madsVm->scene()->_spriteSlots.getSprite(srcSpriteIdx).getFrame(1);
 	uint8 pixel = *_madsVm->scene()->getWalkSurface()->getBasePtr(spriteFrame->x + (spriteFrame->width() / 2),
 		spriteFrame->y + (spriteFrame->height() / 2));
 
 	return _madsVm->scene()->_sequenceList.add(srcSpriteIdx, v0, 1, fld24, timeoutTicks, extraTicks, numTicks, 0, 0, 
-		-1, 100, (int)pixel - 1, 1, 2, 0, 0);
+		-1, 100, (int)pixel - 1, 1, ANIMTYPE_CYCLED, 0, 0);
 }
 
 uint16 MadsSceneLogic::startSpriteSequence3(uint16 srcSpriteIdx, int v0, int numTicks, int fld24, int timeoutTicks, int extraTicks) {
@@ -101,7 +101,7 @@
 		spriteFrame->y + (spriteFrame->height() / 2));
 
 	return _madsVm->scene()->_sequenceList.add(srcSpriteIdx, v0, 1, fld24, timeoutTicks, extraTicks, numTicks, 0, 0, 
-		-1, 100, (int)pixel - 1, -1, 1, 0, 0);
+		-1, 100, (int)pixel - 1, -1, ANIMTYPE_SINGLE_DIRECTION, 0, 0);
 }
 
 void MadsSceneLogic::activateHotspot(int idx, bool active) {
@@ -165,7 +165,7 @@
 void MadsSceneLogic::setupScene() {
 	// FIXME: This is the hardcoded logic for Rex scene 101 only
 	const char *animName = formAnimName('A', -1);
-warning("anim - %s\n", animName);	
+
 //	sub_1e754(animName, 3);
 
 	getSceneSpriteSet();
@@ -189,7 +189,7 @@
 
 	_madsVm->scene()->_sequenceList.unk2(0, 2, 7, 0x46);
 
-	_spriteIndexes[18] = startSpriteSequence2(_spriteIndexes[3], 0, 10, 0, 0, 60);
+	_spriteIndexes[18] = startCycledSpriteSequence(_spriteIndexes[3], 0, 10, 0, 0, 60);
 	_spriteIndexes[19] = startSpriteSequence(_spriteIndexes[4], 0, 5, 0, 1, 0);
 	_spriteIndexes[20] = startSpriteSequence(_spriteIndexes[5], 0, 10, 0, 2, 0);
 	_spriteIndexes[21] = startSpriteSequence(_spriteIndexes[6], 0, 6, 0, 0, 0);

Modified: scummvm/trunk/engines/m4/mads_logic.h
===================================================================
--- scummvm/trunk/engines/m4/mads_logic.h	2010-04-29 22:11:22 UTC (rev 48874)
+++ scummvm/trunk/engines/m4/mads_logic.h	2010-04-30 11:27:42 UTC (rev 48875)
@@ -36,7 +36,7 @@
 	// Library interface methods
 	uint16 loadSpriteSet(uint16 suffixNum, uint16 sepChar);
 	uint16 startSpriteSequence(uint16 srcSpriteIdx, int v0, int numTicks, int fld24, int timeoutTicks, int extraTicks);
-	uint16 startSpriteSequence2(uint16 srcSpriteIdx, int v0, int numTicks, int fld24, int timeoutTicks, int extraTicks);
+	uint16 startCycledSpriteSequence(uint16 srcSpriteIdx, int v0, int numTicks, int fld24, int timeoutTicks, int extraTicks);
 	uint16 startSpriteSequence3(uint16 srcSpriteIdx, int v0, int numTicks, int fld24, int timeoutTicks, int extraTicks);
 	void activateHotspot(int idx, bool active);
 	void lowRoomsEntrySound();

Modified: scummvm/trunk/engines/m4/mads_menus.cpp
===================================================================
--- scummvm/trunk/engines/m4/mads_menus.cpp	2010-04-29 22:11:22 UTC (rev 48874)
+++ scummvm/trunk/engines/m4/mads_menus.cpp	2010-04-30 11:27:42 UTC (rev 48875)
@@ -697,7 +697,7 @@
 	refreshText();
 
 	// Handle the drawing of the various Mads elements
-	refresh(rects);
+	refresh();
 
 	View::onRefresh(rects, destSurface);
 }

Modified: scummvm/trunk/engines/m4/mads_scene.cpp
===================================================================
--- scummvm/trunk/engines/m4/mads_scene.cpp	2010-04-29 22:11:22 UTC (rev 48874)
+++ scummvm/trunk/engines/m4/mads_scene.cpp	2010-04-30 11:27:42 UTC (rev 48875)
@@ -263,26 +263,10 @@
  * Draws all the elements of the scene
  */
 void MadsScene::drawElements() {
-	// Display animations
-	_spriteSlots.draw(this);
+	refresh();
 
-	// Text display 
-	_textDisplay.draw(this);
-
 	// Copy the user interface surface onto the surface
 	_interfaceSurface->copyTo(this, 0, this->height() - _interfaceSurface->height());
-
-/*
-	// Some kind of copying over of slot entries
-	for (int idx = 0, idx2 = 0; idx < _spriteSlotsStart; ++idx) {
-		if (_spriteSlots[idx].spriteId >= 0) {
-			if (idx != idx2) {
-				// Copy over the slot entry
-				_spriteSlots[idx2] = _spriteSlots[idx];
-			}
-			++idx2;
-		}
-	}*/
 }
 
 

Modified: scummvm/trunk/engines/m4/mads_views.cpp
===================================================================
--- scummvm/trunk/engines/m4/mads_views.cpp	2010-04-29 22:11:22 UTC (rev 48874)
+++ scummvm/trunk/engines/m4/mads_views.cpp	2010-04-30 11:27:42 UTC (rev 48875)
@@ -36,14 +36,26 @@
 
 namespace M4 {
 
-static const int INV_ANIM_FRAME_SPEED = 8;
+static const int INV_ANIM_FRAME_SPEED = 2;
 static const int INVENTORY_X = 160;
 static const int INVENTORY_Y = 159;
 static const int SCROLLER_DELAY = 200;
 
 //--------------------------------------------------------------------------
 
+MadsSpriteSlots::MadsSpriteSlots() {
+	for (int i = 0; i < SPRITE_SLOTS_SIZE; ++i) {
+		MadsSpriteSlot rec;
+		_entries.push_back(rec);
+	}
+
+	startIndex = 0;
+}
+
 int MadsSpriteSlots::getIndex() {
+	if (startIndex == SPRITE_SLOTS_SIZE)
+		error("Run out of sprite slots");
+
 	return startIndex++;
 }
 
@@ -97,7 +109,7 @@
 	// Sort the list in order of the depth
 	Common::sort(depthList.begin(), depthList.end(), sortHelper);
 
-	// Loop through each of the objectes
+	// Loop through each of the objects
 	DepthList::iterator i;
 	for (i = depthList.begin(); i != depthList.end(); ++i) {
 		DepthEntry &de = *i;
@@ -131,6 +143,29 @@
 	}
 }
 
+/**
+ * Removes any sprite slots that are no longer needed
+ */
+void MadsSpriteSlots::cleanUp() {
+	// Delete any entries that aren't needed
+	int idx = 0;
+	while (idx < startIndex) {
+		if (_entries[idx].spriteId >= 0) {
+			_entries.remove_at(idx);
+			--startIndex;
+		} else {
+			++idx;
+		}
+	}
+
+	// Original engine sprite slot list was a fixed array, so to keep the engine similiar, for
+	// now I'm adding in new entries to make up the original fixed total again
+	while (_entries.size() < SPRITE_SLOTS_SIZE) {
+		MadsSpriteSlot rec;
+		_entries.push_back(rec);
+	}
+}
+
 //--------------------------------------------------------------------------
 
 MadsTextDisplay::MadsTextDisplay() {
@@ -191,6 +226,18 @@
 	}
 }
 
+/**
+ * Deactivates any text display entries that are finished
+ */
+void MadsTextDisplay::cleanUp() {
+	for (uint idx = 0; idx < _entries.size(); ++idx) {
+		if (_entries[idx].expire < 0) {
+			_entries[idx].active = false;
+			_entries[idx].expire = 0;
+		}
+	}
+}
+
 //--------------------------------------------------------------------------
 
 /**
@@ -341,8 +388,8 @@
 }
 
 int MadsSequenceList::add(int spriteListIndex, int v0, int frameIndex, char field_24, int timeoutTicks, int extraTicks, int numTicks, 
-		int height, int width, char field_12, char scale, char depth, int frameStart, int field_A, int numSprites, 
-		int spriteNum) {
+		int height, int width, char field_12, char scale, char depth, int frameInc, SpriteAnimType animType, int numSprites, 
+		int frameStart) {
 
 	// Find a free slot
 	uint timerIndex = 0;
@@ -351,22 +398,22 @@
 	if (timerIndex == _entries.size())
 		error("TimerList full");
 
-	if (spriteNum <= 0)
-		spriteNum = 1;
+	if (frameStart <= 0)
+		frameStart = 1;
 	if (numSprites == 0)
 		numSprites = _madsVm->scene()->_spriteSlots.getSprite(spriteListIndex).getCount();
-	if (spriteNum == numSprites)
-		frameStart = 0;
+	if (frameStart == numSprites)
+		frameInc = 0;
 
 	// Set the list entry fields
 	_entries[timerIndex].active = true;
 	_entries[timerIndex].spriteListIndex = spriteListIndex;
 	_entries[timerIndex].field_2 = v0;
 	_entries[timerIndex].frameIndex = frameIndex;
-	_entries[timerIndex].spriteNum = spriteNum;
+	_entries[timerIndex].frameStart = frameStart;
 	_entries[timerIndex].numSprites = numSprites;
-	_entries[timerIndex].field_A = field_A;
-	_entries[timerIndex].frameStart = frameStart;
+	_entries[timerIndex].animType = animType;
+	_entries[timerIndex].frameInc = frameInc;
 	_entries[timerIndex].depth = depth;
 	_entries[timerIndex].scale = scale;
 	_entries[timerIndex].field_12 = field_12;
@@ -405,7 +452,7 @@
 	SpriteAsset &sprite = _owner._spriteSlots.getSprite(timerEntry.spriteListIndex);
 
 	// TODO: Figure out logic for spriteId value based on SPRITE_SLOT.field_0
-	spriteSlot.spriteId = (0 /*field 0*/ == 1) ? 0xFFFC : 1;
+	spriteSlot.spriteId = (0 /*field 0*/ == 1) ? -4 : 1;
 	spriteSlot.timerIndex = timerIndex;
 	spriteSlot.spriteListIndex = timerEntry.spriteListIndex;
 	spriteSlot.frameNumber = ((timerEntry.field_2 == 1) ? 0x8000 : 0) | timerEntry.frameIndex;
@@ -416,8 +463,8 @@
 		spriteSlot.xp = timerEntry.width;
 		spriteSlot.yp = timerEntry.height;
 	} else {
-		spriteSlot.xp = sprite.getFrame(timerEntry.frameIndex)->x;
-		spriteSlot.yp = sprite.getFrame(timerEntry.frameIndex)->y;
+		spriteSlot.xp = sprite.getFrame(timerEntry.frameIndex - 1)->x;
+		spriteSlot.yp = sprite.getFrame(timerEntry.frameIndex - 1)->y;
 	}
 }
 
@@ -443,7 +490,7 @@
 
 		if ((timerEntry.field_13 != 0) || (timerEntry.dynamicHotspotIndex >= 0)) {
 			SpriteAsset &spriteSet = _owner._spriteSlots.getSprite(timerEntry.spriteListIndex);
-			M4Sprite *frame = spriteSet.getFrame(timerEntry.frameIndex);
+			M4Sprite *frame = spriteSet.getFrame(timerEntry.frameIndex - 1);
 			int width = frame->width() * timerEntry.scale / 200;
 			int height = frame->height() * timerEntry.scale / 100;
 
@@ -464,26 +511,32 @@
 		}
 
 		// Frame adjustments
-		if (timerEntry.numSprites != timerEntry.spriteNum) 
-			timerEntry.frameIndex += timerEntry.frameStart;
+		if (timerEntry.frameStart != timerEntry.numSprites)
+			timerEntry.frameIndex += timerEntry.frameInc;
 
-		if (timerEntry.frameIndex >= timerEntry.spriteNum) {
+		if (timerEntry.frameIndex >= timerEntry.frameStart) {
 			if (timerEntry.frameIndex > timerEntry.numSprites) {
 				result = true;
-				if (timerEntry.field_A != 2) {
-					timerEntry.frameIndex = timerEntry.spriteNum;
+				if (timerEntry.animType != ANIMTYPE_CYCLED) {
+					// Keep index from exceeding maximum allowed
+					timerEntry.frameIndex = timerEntry.frameStart;
 				} else {
+					// Switch into reverse
 					timerEntry.frameIndex = timerEntry.numSprites - 1;
-					timerEntry.frameStart = -1;
+					timerEntry.frameInc = -1;
 				}
 			}
 		} else {
+			// Currently in reverse mode
 			result = true;
 
-			if (timerEntry.field_A == 2) {
-				timerEntry.frameIndex = timerEntry.spriteNum + 1;
-				timerEntry.frameStart = 1;
+			if (timerEntry.animType == ANIMTYPE_CYCLED)
+			{
+				// Switch back to forward direction again
+				timerEntry.frameIndex = timerEntry.frameStart + 1;
+				timerEntry.frameInc = 1;
 			} else {
+				// Otherwise reset back to last sprite for further reverse animating
 				timerEntry.frameIndex = timerEntry.numSprites;		
 			}
 		}
@@ -511,7 +564,7 @@
 	}
 
 	if (idx >= 0) {
-		_owner._abortTimers = timerEntry.fld36[idx];
+		//_owner._abortTimers = timerEntry.fld36[idx];
 		
 		// TODO: Figure out word_84208, timerEntry.field_3B[]
 	}
@@ -558,12 +611,18 @@
 	_abortTimers2 = 0;
 }
 
-void MadsView::refresh(RectList *rects) {
+void MadsView::refresh() {
 	// Draw any sprites
 	_spriteSlots.draw(_view);
 
 	// Draw text elements onto the view
 	_textDisplay.draw(_view);
+
+	// Remove any sprite slots that are no longer needed
+	_spriteSlots.cleanUp();
+
+	// Deactivate any text display entries that are no longer needed
+	_textDisplay.cleanUp();
 }
 
 /*--------------------------------------------------------------------------

Modified: scummvm/trunk/engines/m4/mads_views.h
===================================================================
--- scummvm/trunk/engines/m4/mads_views.h	2010-04-29 22:11:22 UTC (rev 48874)
+++ scummvm/trunk/engines/m4/mads_views.h	2010-04-30 11:27:42 UTC (rev 48875)
@@ -60,12 +60,12 @@
 
 class MadsSpriteSlots {
 private:
-	MadsSpriteSlot _entries[SPRITE_SLOTS_SIZE];
+	Common::Array<MadsSpriteSlot> _entries;
 	SpriteList _sprites;
 public:
 	int startIndex;
 
-	MadsSpriteSlots() { startIndex = 0; }
+	MadsSpriteSlots();
 
 	MadsSpriteSlot &operator[](int idx) {
 		assert(idx < SPRITE_SLOTS_SIZE);
@@ -85,6 +85,7 @@
 	void deleteTimer(int timerIndex);
 
 	void draw(View *view);
+	void cleanUp();
 };
 
 class MadsTextDisplayEntry {
@@ -122,6 +123,7 @@
 	int add(int xp, int yp, uint fontColour, int charSpacing, const char *msg, Font *font);
 	void clear();
 	void draw(View *view);
+	void cleanUp();
 };
 
 class ScreenObjectEntry {
@@ -191,6 +193,8 @@
 
 #define TIMER_ENTRY_SUBSET_MAX 5
 
+enum SpriteAnimType {ANIMTYPE_SINGLE_DIRECTION = 1, ANIMTYPE_CYCLED = 2};
+
 struct MadsSequenceEntry {
 	int8 active;
 	int8 spriteListIndex;
@@ -198,12 +202,12 @@
 	int field_2;
 	
 	int frameIndex;
-	int spriteNum;
+	int frameStart;
 	int numSprites;
-	
-	int field_A;
-	int frameStart;
 
+	SpriteAnimType animType;
+	int frameInc;
+
 	int depth;
 	int scale;
 	int dynamicHotspotIndex;
@@ -240,8 +244,8 @@
 	MadsSequenceEntry &operator[](int index) { return _entries[index]; }	
 	bool unk2(int index, int v1, int v2, int v3);
 	int add(int spriteListIndex, int v0, int v1, char field_24, int timeoutTicks, int extraTicks, int numTicks, 
-		int height, int width, char field_12, char scale, char depth, int frameStart, int field_A, 
-		int numSprites, int spriteNum);
+		int height, int width, char field_12, char scale, char depth, int frameInc, SpriteAnimType animType, 
+		int numSprites, int frameStart);
 	void remove(int timerIndex);
 	void setSpriteSlot(int timerIndex, MadsSpriteSlot &spriteSlot);
 	bool loadSprites(int timerIndex);
@@ -264,7 +268,7 @@
 public:
 	MadsView(View *view);
 
-	void refresh(RectList *rects);
+	void refresh();
 };
 
 #define CHEAT_SEQUENCE_MAX 8


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