[Scummvm-cvs-logs] CVS: scummvm/sword2 anims.cpp,1.70,1.71 function.cpp,1.83,1.84 logic.h,1.45,1.46 router.h,1.21,1.22

Torbjörn Andersson eriktorbjorn at users.sourceforge.net
Wed May 11 23:31:37 CEST 2005


Update of /cvsroot/scummvm/scummvm/sword2
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10857

Modified Files:
	anims.cpp function.cpp logic.h router.h 
Log Message:
Moved some more animation stuff out of the Logic class and into the
increasingly misnamed Router class. (I'll fix the naming later. Probably.)


Index: anims.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/anims.cpp,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- anims.cpp	3 May 2005 09:00:04 -0000	1.70
+++ anims.cpp	12 May 2005 06:30:15 -0000	1.71
@@ -34,21 +34,15 @@
 #include "sword2/logic.h"
 #include "sword2/maketext.h"
 #include "sword2/resman.h"
+#include "sword2/router.h"
 #include "sword2/sound.h"
 #include "sword2/driver/animation.h"
 
 namespace Sword2 {
 
-int32 Logic::animate(int32 *params, bool reverse) {
-	// params:	0 pointer to object's logic structure
-	//		1 pointer to object's graphic structure
-	//		2 resource id of animation file
-
- 	ObjectLogic *ob_logic = (ObjectLogic *) decodePtr(params[0]);
- 	ObjectGraphic *ob_graphic = (ObjectGraphic *) decodePtr(params[1]);
+int Router::doAnimate(ObjectLogic *ob_logic, ObjectGraphic *ob_graphic, int32 animRes, bool reverse) {
 	byte *anim_file;
 	AnimHeader *anim_head;
- 	int32 res = params[2];
 
 	if (ob_logic->looping == 0) {
 		StandardHeader *head;
@@ -61,40 +55,38 @@
 		// 'testing_routines' object in George's Player Character
 		// section of linc
 
-		if (_scriptVars[SYSTEM_TESTING_ANIMS]) {
-			// if the resource number is within range & it's not
-			// a null resource
-
-			if (_vm->_resman->checkValid(res)) {
-				// Open the resource. Can close it immediately.
-				// We've got a pointer to the header.
-				head = (StandardHeader *) _vm->_resman->openResource(res);
-				_vm->_resman->closeResource(res);
-
-				// if it's not an animation file
-				if (head->fileType != ANIMATION_FILE) {
-					// switch off the sprite
-					// don't animate - just continue
-					// script next cycle
-					fnNoSprite(params + 1);
-					return IR_STOP;
-				}
-			} else {
+		if (Logic::_scriptVars[SYSTEM_TESTING_ANIMS]) {
+			if (!_vm->_resman->checkValid(animRes)) {
 				// Not a valid resource number. Switch off
 				// the sprite. Don't animate - just continue
 				// script next cycle.
-				fnNoSprite(params + 1);
+				setSpriteStatus(ob_graphic, NO_SPRITE);
+				return IR_STOP;
+			}
+
+			head = (StandardHeader *) _vm->_resman->openResource(animRes);
+
+			// if it's not an animation file
+			if (head->fileType != ANIMATION_FILE) {
+				_vm->_resman->closeResource(animRes);
+
+				// switch off the sprite
+				// don't animate - just continue
+				// script next cycle
+				setSpriteStatus(ob_graphic, NO_SPRITE);
 				return IR_STOP;
 			}
 
+			_vm->_resman->closeResource(animRes);
+
 			// switch on the sprite
-			fnSortSprite(params + 1);
+			setSpriteStatus(ob_graphic, SORT_SPRITE);
 		}
 
-		assert(res);
+		assert(animRes);
 
 		// open anim file
-		anim_file = _vm->_resman->openResource(res);
+		anim_file = _vm->_resman->openResource(animRes);
 
 		head = (StandardHeader *) anim_file;
 		assert(head->fileType == ANIMATION_FILE);
@@ -102,17 +94,17 @@
 		// point to anim header
 		anim_head = _vm->fetchAnimHeader(anim_file);
 
-		// now running an anim, looping back to this 'FN' call again
+		// now running an anim, looping back to this call again
 		ob_logic->looping = 1;
-		ob_graphic->anim_resource = res;
+		ob_graphic->anim_resource = animRes;
 
 		if (reverse)
 			ob_graphic->anim_pc = anim_head->noAnimFrames - 1;
 		else
 			ob_graphic->anim_pc = 0;
- 	} else if (getSync() != -1) {
+	} else if (_vm->_logic->getSync() != -1) {
 		// We've received a sync - return to script immediately
-		debug(5, "**sync stopped %d**", _scriptVars[ID]);
+		debug(5, "**sync stopped %d**", Logic::_scriptVars[ID]);
 
 		// If sync received, anim finishes right now (remaining on
 		// last frame). Quit animation, but continue script.
@@ -138,7 +130,7 @@
 		if (ob_graphic->anim_pc == 0)
 			ob_logic->looping = 0;
 	} else {
-		if (ob_graphic->anim_pc == (int32) (anim_head->noAnimFrames - 1))
+		if (ob_graphic->anim_pc == anim_head->noAnimFrames - 1)
 			ob_logic->looping = 0;
 	}
 
@@ -149,49 +141,30 @@
 	return ob_logic->looping ? IR_REPEAT : IR_STOP;
 }
 
-int32 Logic::megaTableAnimate(int32 *params, bool reverse) {
-	// params:	0 pointer to object's logic structure
-	//		1 pointer to object's graphic structure
-	//		2 pointer to object's mega structure
-	//		3 pointer to animation table
-
-	int32 pars[3];
-
-	// Set up the parameters for animate().
-
-	pars[0] = params[0];
-	pars[1] = params[1];
+int Router::megaTableAnimate(ObjectLogic *ob_logic, ObjectGraphic *ob_graph, ObjectMega *ob_mega, uint32 *animTable, bool reverse) {
+	int32 animRes = 0;
 
 	// If this is the start of the anim, read the anim table to get the
 	// appropriate anim resource
 
- 	ObjectLogic *ob_logic = (ObjectLogic *) decodePtr(params[0]);
-
 	if (ob_logic->looping == 0) {
-	 	ObjectMega *ob_mega = (ObjectMega *) decodePtr(params[2]);
-		uint32 *anim_table = (uint32 *) decodePtr(params[3]);
-
-		// appropriate anim resource is in 'table[direction]'
-		pars[2] = anim_table[ob_mega->current_dir];
+		// Appropriate anim resource is in 'table[direction]'
+		animRes = animTable[ob_mega->current_dir];
 	}
 
-	return animate(pars, reverse);
+	return doAnimate(ob_logic, ob_graph, animRes, reverse);
 }
 
-void Logic::setSpriteStatus(uint32 sprite, uint32 type) {
-	ObjectGraphic *ob_graphic = (ObjectGraphic *) decodePtr(sprite);
-
+void Router::setSpriteStatus(ObjectGraphic *ob_graph, uint32 type) {
 	// Remove the previous status, but don't affect the shading upper-word
-	ob_graphic->type = (ob_graphic->type & 0xffff0000) | type;
+	ob_graph->type = (ob_graph->type & 0xffff0000) | type;
 }
 
-void Logic::setSpriteShading(uint32 sprite, uint32 type) {
-	ObjectGraphic *ob_graphic = (ObjectGraphic *) decodePtr(sprite);
-
+void Router::setSpriteShading(ObjectGraphic *ob_graph, uint32 type) {
 	// Remove the previous shading, but don't affect the status lower-word.
-	// Note that drivers may still shade mega frames automatically, even
-	// when not sent 'RDSPR_SHADOW'.
-	ob_graphic->type = (ob_graphic->type & 0x0000ffff) | type;
+	// Note that mega frames may still be shaded automatically, even when
+	// not sent 'RDSPR_SHADOW'.
+	ob_graph->type = (ob_graph->type & 0x0000ffff) | type;
 }
 
 void Logic::createSequenceSpeech(MovieTextObject *sequenceText[]) {

Index: function.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/function.cpp,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -d -r1.83 -r1.84
--- function.cpp	3 May 2005 09:00:05 -0000	1.83
+++ function.cpp	12 May 2005 06:30:15 -0000	1.84
@@ -81,19 +81,19 @@
 
 int32 Logic::fnBackSprite(int32 *params) {
 	// params:	0 pointer to object's graphic structure
-	setSpriteStatus(params[0], BACK_SPRITE);
+	_router->setSpriteStatus((ObjectGraphic *) decodePtr(params[0]), BACK_SPRITE);
 	return IR_CONT;
 }
 
 int32 Logic::fnSortSprite(int32 *params) {
 	// params:	0 pointer to object's graphic structure
-	setSpriteStatus(params[0], SORT_SPRITE);
+	_router->setSpriteStatus((ObjectGraphic *) decodePtr(params[0]), SORT_SPRITE);
 	return IR_CONT;
 }
 
 int32 Logic::fnForeSprite(int32 *params) {
 	// params:	0 pointer to object's graphic structure
-	setSpriteStatus(params[0], FORE_SPRITE);
+	_router->setSpriteStatus((ObjectGraphic *) decodePtr(params[0]), FORE_SPRITE);
 	return IR_CONT;
 }
 
@@ -106,9 +106,7 @@
 	// params:	0 pointer to ObjectMouse or 0 for no write to mouse
 	//		  list
 
-	ObjectMouse *ob_mouse = (ObjectMouse *) decodePtr(params[0]);
-
-	_vm->_mouse->registerMouse(ob_mouse, NULL);
+	_vm->_mouse->registerMouse((ObjectMouse *) decodePtr(params[0]), NULL);
 	return IR_CONT;
 }
 
@@ -117,8 +115,11 @@
 	//		1 pointer to object's graphic structure
 	//		2 resource id of animation file
 
-	// 0 means normal forward anim
-	return animate(params, false);
+	// Normal forward animation
+	return _router->doAnimate(
+		(ObjectLogic *) decodePtr(params[0]),
+		(ObjectGraphic *) decodePtr(params[1]),
+		params[2], false);
 }
 
 int32 Logic::fnRandom(int32 *params) {
@@ -324,8 +325,13 @@
 	//		2 pointer to object's mega structure
 	//		3 pointer to animation table
 
-	// 0 means normal forward anim
-	return megaTableAnimate(params, false);
+	// Normal forward anim
+	return _router->megaTableAnimate(
+		(ObjectLogic *) decodePtr(params[0]),
+		(ObjectGraphic *) decodePtr(params[1]),
+		(ObjectMega *) decodePtr(params[2]),
+		(uint32 *) decodePtr(params[3]),
+		false);
 }
 
 int32 Logic::fnAddMenuObject(int32 *params) {
@@ -428,7 +434,7 @@
 
 int32 Logic::fnNoSprite(int32 *params) {
 	// params:	0 pointer to object's graphic structure
-	setSpriteStatus(params[0], NO_SPRITE);
+	_router->setSpriteStatus((ObjectGraphic *) decodePtr(params[0]), NO_SPRITE);
 	return IR_CONT;
 }
 
@@ -1663,8 +1669,13 @@
 	//		2 pointer to object's mega structure
 	//		3 pointer to animation table
 
-	// 1 means reverse anim
-	return megaTableAnimate(params, true);
+	// Reverse anim
+	return _router->megaTableAnimate(
+		(ObjectLogic *) decodePtr(params[0]),
+		(ObjectGraphic *) decodePtr(params[1]),
+		(ObjectMega *) decodePtr(params[2]),
+		(uint32 *) decodePtr(params[3]),
+		true);
 }
 
 int32 Logic::fnReverseAnim(int32 *params) {
@@ -1672,8 +1683,11 @@
 	//		1 pointer to object's graphic structure
 	//		2 resource id of animation file
 
-	// 1 means reverse anim
-	return animate(params, true);
+	// Reverse anim
+	return _router->doAnimate(
+		(ObjectLogic *) decodePtr(params[0]),
+		(ObjectGraphic *) decodePtr(params[1]),
+		params[2], true);
 }
 
 /**
@@ -1731,25 +1745,25 @@
 
 int32 Logic::fnBackPar0Sprite(int32 *params) {
 	// params:	0 pointer to object's graphic structure
-	setSpriteStatus(params[0], BGP0_SPRITE);
+	_router->setSpriteStatus((ObjectGraphic *) decodePtr(params[0]), BGP0_SPRITE);
 	return IR_CONT;
 }
 
 int32 Logic::fnBackPar1Sprite(int32 *params) {
 	// params:	0 pointer to object's graphic structure
-	setSpriteStatus(params[0], BGP1_SPRITE);
+	_router->setSpriteStatus((ObjectGraphic *) decodePtr(params[0]), BGP1_SPRITE);
 	return IR_CONT;
 }
 
 int32 Logic::fnForePar0Sprite(int32 *params) {
 	// params:	0 pointer to object's graphic structure
-	setSpriteStatus(params[0], FGP0_SPRITE);
+	_router->setSpriteStatus((ObjectGraphic *) decodePtr(params[0]), FGP0_SPRITE);
 	return IR_CONT;
 }
 
 int32 Logic::fnForePar1Sprite(int32 *params) {
 	// params:	0 pointer to object's graphic structure
-	setSpriteStatus(params[0], FGP1_SPRITE);
+	_router->setSpriteStatus((ObjectGraphic *) decodePtr(params[0]), FGP1_SPRITE);
 	return IR_CONT;
 }
 
@@ -2187,13 +2201,13 @@
 
 int32 Logic::fnShadedSprite(int32 *params) {
 	// params:	0 pointer to object's graphic structure
-	setSpriteShading(params[0], SHADED_SPRITE);
+	_router->setSpriteShading((ObjectGraphic *) decodePtr(params[0]), SHADED_SPRITE);
 	return IR_CONT;
 }
 
 int32 Logic::fnUnshadedSprite(int32 *params) {
 	// params:	0 pointer to object's graphic structure
-	setSpriteShading(params[0], UNSHADED_SPRITE);
+	_router->setSpriteShading((ObjectGraphic *) decodePtr(params[0]), UNSHADED_SPRITE);
 	return IR_CONT;
 }
 

Index: logic.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/logic.h,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- logic.h	3 May 2005 09:00:05 -0000	1.45
+++ logic.h	12 May 2005 06:30:16 -0000	1.46
@@ -77,12 +77,6 @@
 	uint32 _smackerLeadIn;
 	uint32 _smackerLeadOut;
 
-	int32 animate(int32 *params, bool reverse);
-	int32 megaTableAnimate(int32 *params, bool reverse);
-
-	void setSpriteStatus(uint32 sprite, uint32 type);
-	void setSpriteShading(uint32 sprite, uint32 type);
-
 	// keeps count of number of text lines to disaply during the sequence
 	uint32 _sequenceTextLines;
 

Index: router.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/router.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- router.h	3 May 2005 09:00:05 -0000	1.21
+++ router.h	12 May 2005 06:30:16 -0000	1.22
@@ -231,6 +231,14 @@
 	void setStandbyCoords(int16 x, int16 y, uint8 dir);
 	int whatTarget(int startX, int startY, int destX, int destY);
 
+	// Sprites
+	void setSpriteStatus(ObjectGraphic *ob_graph, uint32 type);
+	void setSpriteShading(ObjectGraphic *ob_graph, uint32 type);
+
+	// Animation
+	int doAnimate(ObjectLogic *ob_logic, ObjectGraphic *ob_graph, int32 animRes, bool reverse);
+	int megaTableAnimate(ObjectLogic *ob_logic, ObjectGraphic *ob_graph, ObjectMega *ob_mega, uint32 *animTable, bool reverse);
+
 	// Walking
 	int doWalk(ObjectLogic *ob_logic, ObjectGraphic *ob_graph, ObjectMega *ob_mega, ObjectWalkdata *ob_walkdata, int16 target_x, int16 target_y, uint8 target_dir);
 	int walkToAnim(ObjectLogic *ob_logic, ObjectGraphic *ob_graph, ObjectMega *ob_mega, ObjectWalkdata *ob_walkdata, uint32 animRes);





More information about the Scummvm-git-logs mailing list