diff options
| -rw-r--r-- | sword2/anims.cpp | 105 | ||||
| -rw-r--r-- | sword2/function.cpp | 56 | ||||
| -rw-r--r-- | sword2/logic.h | 6 | ||||
| -rw-r--r-- | sword2/router.h | 8 | 
4 files changed, 82 insertions, 93 deletions
| diff --git a/sword2/anims.cpp b/sword2/anims.cpp index d4badbf640..c60a5a3e06 100644 --- a/sword2/anims.cpp +++ b/sword2/anims.cpp @@ -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 @@ int32 Logic::animate(int32 *params, bool reverse) {  		// '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 @@ int32 Logic::animate(int32 *params, bool reverse) {  		// 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 @@ int32 Logic::animate(int32 *params, bool reverse) {  		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 @@ int32 Logic::animate(int32 *params, bool reverse) {  	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[]) { diff --git a/sword2/function.cpp b/sword2/function.cpp index da921ba4a4..eb10e46557 100644 --- a/sword2/function.cpp +++ b/sword2/function.cpp @@ -81,19 +81,19 @@ int32 Logic::fnSetSession(int32 *params) {  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 @@ int32 Logic::fnRegisterMouse(int32 *params) {  	// 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 @@ int32 Logic::fnAnim(int32 *params) {  	//		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 @@ int32 Logic::fnMegaTableAnim(int32 *params) {  	//		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::fnRegisterFrame(int32 *params) {  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 @@ int32 Logic::fnReverseMegaTableAnim(int32 *params) {  	//		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 @@ int32 Logic::fnReverseAnim(int32 *params) {  	//		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::fnSetStandbyCoords(int32 *params) {  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::fnPlaySequence(int32 *params) {  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;  } diff --git a/sword2/logic.h b/sword2/logic.h index e770e162df..ebb58f3e9e 100644 --- a/sword2/logic.h +++ b/sword2/logic.h @@ -77,12 +77,6 @@ private:  	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; diff --git a/sword2/router.h b/sword2/router.h index a016579fa6..27c2c0bb35 100644 --- a/sword2/router.h +++ b/sword2/router.h @@ -231,6 +231,14 @@ public:  	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); | 
