diff options
| author | Torbjörn Andersson | 2004-04-27 08:59:58 +0000 | 
|---|---|---|
| committer | Torbjörn Andersson | 2004-04-27 08:59:58 +0000 | 
| commit | 49fc62b4d0a3d905195fa70e34dd33b10a49c62f (patch) | |
| tree | 8f940da0ae42873a9cf5007967d8c36a4c0b3255 | |
| parent | aaf508d4da5ac68a4d7d4fdae9b64983a7177654 (diff) | |
| download | scummvm-rg350-49fc62b4d0a3d905195fa70e34dd33b10a49c62f.tar.gz scummvm-rg350-49fc62b4d0a3d905195fa70e34dd33b10a49c62f.tar.bz2 scummvm-rg350-49fc62b4d0a3d905195fa70e34dd33b10a49c62f.zip  | |
Cleanup
svn-id: r13649
| -rw-r--r-- | sword2/logic.h | 2 | ||||
| -rw-r--r-- | sword2/scroll.cpp | 168 | ||||
| -rw-r--r-- | sword2/startup.cpp | 191 | 
3 files changed, 166 insertions, 195 deletions
diff --git a/sword2/logic.h b/sword2/logic.h index 3d7586b5c3..c1d9f3e41c 100644 --- a/sword2/logic.h +++ b/sword2/logic.h @@ -152,7 +152,7 @@ private:  	StartUp _startList[MAX_starts]; -	uint32 initStartMenu(void); +	bool initStartMenu(void);  	int16 _standbyX;	// see fnSetStandbyCoords()  	int16 _standbyY; diff --git a/sword2/scroll.cpp b/sword2/scroll.cpp index 45be9a939a..82d2bdcd22 100644 --- a/sword2/scroll.cpp +++ b/sword2/scroll.cpp @@ -22,134 +22,136 @@  #include "sword2/defs.h"  #include "sword2/interpreter.h"  #include "sword2/logic.h" -#include "sword2/resman.h"  namespace Sword2 { -// max no of pixel allowed to scroll per cycle +// Max no of pixel allowed to scroll per cycle  #define MAX_SCROLL_DISTANCE 8 +/** + * If the room is larger than the physical screen, this function is called + * every game cycle to update the scroll offsets. + */ +  void Sword2Engine::setScrolling(void) { -	// normally we aim to get George's feet at (320,250) from top left +	// Normally we aim to get George's feet at (320,250) from top left  	// of screen window  	// feet_x = 128 + 320  	// feet_y = 128 + 250 -	// set scroll offsets according to the player's coords +	// Set scroll offsets according to the player's coords -	int16 offset_x; -	int16 offset_y; -	int16 dx, dy; -	uint16 scroll_distance_x;	// how much we want to scroll -	uint16 scroll_distance_y; +	// If the scroll offsets are being forced in script, ensure that they +	// are neither too far to the right nor too far down. -	// if the scroll offsets are being forced in script  	if (Logic::_scriptVars[SCROLL_X] || Logic::_scriptVars[SCROLL_Y]) { -		// ensure not too far right or too far down  		_thisScreen.scroll_offset_x = MIN((uint16) Logic::_scriptVars[SCROLL_X], _thisScreen.max_scroll_offset_x);  		_thisScreen.scroll_offset_y = MIN((uint16) Logic::_scriptVars[SCROLL_Y], _thisScreen.max_scroll_offset_y); -	} else { -		// George's offset from the centre - the desired position -		// for him - -		offset_x = _thisScreen.player_feet_x - _thisScreen.feet_x; -		offset_y = _thisScreen.player_feet_y - _thisScreen.feet_y; +		return; +	} -		// prevent scrolling too far left/right/up/down +	// George's offset from the centre - the desired position for him -		if (offset_x < 0) -			offset_x = 0; -		else if ((uint32) offset_x > _thisScreen.max_scroll_offset_x) -			offset_x = _thisScreen.max_scroll_offset_x; +	int16 offset_x = _thisScreen.player_feet_x - _thisScreen.feet_x; +	int16 offset_y = _thisScreen.player_feet_y - _thisScreen.feet_y; -		if (offset_y < 0) -			offset_y = 0; -		else if ((uint32) offset_y > _thisScreen.max_scroll_offset_y) -			offset_y = _thisScreen.max_scroll_offset_y; +	// Prevent scrolling too far left/right/up/down -		// first time on this screen - need absolute scroll -		// immediately! +	if (offset_x < 0) +		offset_x = 0; +	else if (offset_x > _thisScreen.max_scroll_offset_x) +		offset_x = _thisScreen.max_scroll_offset_x; -		if (_thisScreen.scroll_flag == 2) { -			debug(5, "init scroll"); -			_thisScreen.scroll_offset_x = offset_x; -			_thisScreen.scroll_offset_y = offset_y; -			_thisScreen.scroll_flag = 1; -		} else { -			// catch up with required scroll offsets - speed -			// depending on distance to catch up (dx and dy) & -			// 'SCROLL_FRACTION' used, but limit to certain -			// number of pixels per cycle (MAX_SCROLL_DISTANCE) +	if (offset_y < 0) +		offset_y = 0; +	else if (offset_y > _thisScreen.max_scroll_offset_y) +		offset_y = _thisScreen.max_scroll_offset_y; -			dx = _thisScreen.scroll_offset_x - offset_x; -			dy = _thisScreen.scroll_offset_y - offset_y; +	// First time on this screen - need absolute scroll immediately! -			// current scroll_offset_x is less than the required -			// value +	if (_thisScreen.scroll_flag == 2) { +		debug(5, "init scroll"); +		_thisScreen.scroll_offset_x = offset_x; +		_thisScreen.scroll_offset_y = offset_y; +		_thisScreen.scroll_flag = 1; +		return; +	} -			// NB. I'm adding 1 to the result of -			// dx / SCROLL_FRACTION, because it would otherwise -			// not scroll at all when dx < SCROLL_FRACTION +	// Catch up with required scroll offsets - speed depending on distance +	// to catch up (dx and dy) and _scrollFraction used, but limit to +	// certain number of pixels per cycle (MAX_SCROLL_DISTANCE) -			if (dx < 0) { -				// => inc by (fraction of the differnce) -				// NB. dx is -ve, so we subtract -				// dx / SCROLL_FRACTION +	int16 dx = _thisScreen.scroll_offset_x - offset_x; +	int16 dy = _thisScreen.scroll_offset_y - offset_y; -				scroll_distance_x = 1 - dx / _scrollFraction; +	uint16 scroll_distance_x;	// how much we want to scroll +	uint16 scroll_distance_y; -				if (scroll_distance_x > MAX_SCROLL_DISTANCE) -					scroll_distance_x = MAX_SCROLL_DISTANCE; +	if (dx < 0) { +		// Current scroll_offset_x is less than the required value -				_thisScreen.scroll_offset_x += scroll_distance_x; -			} else if (dx > 0) { -				// current scroll_offset_x is greater than -				// the required value -				// => dec by (fraction of the differnce) +		// NB. I'm adding 1 to the result of dx / SCROLL_FRACTION, +		// because it would otherwise not scroll at all when +		// dx < SCROLL_FRACTION -				scroll_distance_x = 1 + dx / _scrollFraction; +		// => inc by (fraction of the differnce) NB. dx is -ve, so we +		// subtract dx / SCROLL_FRACTION -				if (scroll_distance_x > MAX_SCROLL_DISTANCE) -					scroll_distance_x = MAX_SCROLL_DISTANCE; +		scroll_distance_x = 1 - dx / _scrollFraction; -				_thisScreen.scroll_offset_x -= scroll_distance_x; -			} +		if (scroll_distance_x > MAX_SCROLL_DISTANCE) +			scroll_distance_x = MAX_SCROLL_DISTANCE; -			if (dy < 0) { -				scroll_distance_y = 1 - dy / _scrollFraction; +		_thisScreen.scroll_offset_x += scroll_distance_x; +	} else if (dx > 0) { +		// Current scroll_offset_x is greater than +		// the required value -				if (scroll_distance_y > MAX_SCROLL_DISTANCE) -					scroll_distance_y = MAX_SCROLL_DISTANCE; +		// => dec by (fraction of the differnce) -				_thisScreen.scroll_offset_y += scroll_distance_y; -			} else if (dy > 0) { -				scroll_distance_y = 1 + dy / _scrollFraction; +		scroll_distance_x = 1 + dx / _scrollFraction; -				if (scroll_distance_y > MAX_SCROLL_DISTANCE) -					scroll_distance_y = MAX_SCROLL_DISTANCE; +		if (scroll_distance_x > MAX_SCROLL_DISTANCE) +			scroll_distance_x = MAX_SCROLL_DISTANCE; -				_thisScreen.scroll_offset_y -= scroll_distance_y; -			} -		} +		_thisScreen.scroll_offset_x -= scroll_distance_x;  	} -} -int32 Logic::fnSetScrollCoordinate(int32 *params) { -	// set the special scroll offset variables +	if (dy < 0) { +		scroll_distance_y = 1 - dy / _scrollFraction; -	// call when starting screens and to change the camera within screens +		if (scroll_distance_y > MAX_SCROLL_DISTANCE) +			scroll_distance_y = MAX_SCROLL_DISTANCE; -	// call AFTER fnInitBackground() to override the defaults +		_thisScreen.scroll_offset_y += scroll_distance_y; +	} else if (dy > 0) { +		scroll_distance_y = 1 + dy / _scrollFraction; -	// called feet_x and feet_y to retain intelectual compatibility with -	// Sword1 ! +		if (scroll_distance_y > MAX_SCROLL_DISTANCE) +			scroll_distance_y = MAX_SCROLL_DISTANCE; -	// feet_x & feet_y refer to the physical screen coords where the -	// system will try to maintain George's feet +		_thisScreen.scroll_offset_y -= scroll_distance_y; +	} +} +/** + * Set the special scroll offset variables + * + * Call when starting screens and to change the camera within screens + * + * call AFTER fnInitBackground() to override the defaults + */ + +int32 Logic::fnSetScrollCoordinate(int32 *params) {  	// params:	0 feet_x value  	// 		1 feet_y value +  	// Called feet_x and feet_y to retain intellectual compatibility with +	// Sword1! +	// +	// feet_x & feet_y refer to the physical screen coords where the +	// system will try to maintain George's feet +  	_vm->_thisScreen.feet_x = params[0];  	_vm->_thisScreen.feet_y = params[1];  	return IR_CONT; diff --git a/sword2/startup.cpp b/sword2/startup.cpp index 661d702b1b..f5899c1dc9 100644 --- a/sword2/startup.cpp +++ b/sword2/startup.cpp @@ -21,6 +21,7 @@  #include "common/file.h"  #include "sword2/sword2.h"  #include "sword2/console.h" +#include "sword2/interpreter.h"  #include "sword2/logic.h"  #include "sword2/maketext.h"  #include "sword2/resman.h" @@ -30,7 +31,7 @@  namespace Sword2 { -uint32 Logic::initStartMenu(void) { +bool Logic::initStartMenu(void) {  	// Print out a list of all the start points available.  	// There should be a linc produced file called startup.txt.  	// This file should contain ascii numbers of all the resource game @@ -40,72 +41,60 @@ uint32 Logic::initStartMenu(void) {  	File fp; -	uint32 pos = 0; -	char *raw_script; -	uint32 null_pc; - -	char ascii_start_ids[MAX_starts][7]; -  	// ok, load in the master screen manager file -	_totalStartups = 0;	// no starts - -	debug(5, "initialising start menu"); +	_totalStartups = 0;  	if (!fp.open("startup.inf")) { -		warning("initStartMenu: cannot open startup.inf - the debugger won't have a start menu"); -		return 0; +		warning("Cannot open startup.inf - the debugger won't have a start menu"); +		return false;  	}  	// The startup.inf file which contains a list of all the files. Now  	// extract the filenames +	int start_ids[MAX_starts]; +  	while (1) {  		bool done = false; -		while (1) { -			byte b = fp.readByte(); +		start_ids[_totalScreenManagers] = 0; + +		// Scan the string until the LF in CRLF + +		int b; + +		do { +			b = fp.readByte();  			if (fp.ioFailed()) {  				done = true;  				break;  			} -			// Each item ends with CRLF -			if (b == 13) { -				fp.readByte(); -				break; +			if (isdigit(b)) { +				start_ids[_totalScreenManagers] *= 10; +				start_ids[_totalScreenManagers] += (b - '0');  			} - -			if (pos < 7) -				ascii_start_ids[_totalScreenManagers][pos] = b; -			pos++; -		} +		} while (b != 10);  		if (done)  			break; -		// NULL terminate our extracted string -		ascii_start_ids[_totalScreenManagers][pos] = 0; - -		// reset position in current slot between entries -		pos = 0; - -		// done another  		_totalScreenManagers++;  		if (_totalScreenManagers == MAX_starts) { -			debug(5, "WARNING MAX_starts exceeded!"); +			warning("MAX_starts exceeded");  			break;  		}  	}  	fp.close(); -	// using this method the Gode generated resource.inf must have #0d0a +	// Using this method the Gode generated resource.inf must have #0d0a  	// on the last entry -	debug(5, "%d screen manager objects", _totalScreenManagers); +	debug(1, "%d screen manager objects", _totalScreenManagers);  	// Open each object and make a query call. The object must fill in a  	// startup structure. It may fill in several if it wishes - for @@ -113,12 +102,12 @@ uint32 Logic::initStartMenu(void) {  	// specific vars are set  	for (uint i = 0; i < _totalScreenManagers; i++) { -		_startRes = atoi(ascii_start_ids[i]); +		_startRes = start_ids[i]; -		debug(5, "+querying screen manager %d", _startRes); +		debug(2, "Querying screen manager %d", _startRes); -		// resopen each one and run through the interpretter -		// script 0 is the query request script +		// Open each one and run through the interpreter. Script 0 is +		// the query request script  		// if the resource number is within range & it's not a null  		// resource @@ -126,13 +115,13 @@ uint32 Logic::initStartMenu(void) {  		// start list  		if (_vm->_resman->checkValid(_startRes)) { -			debug(5, "- resource %d ok", _startRes); -			raw_script = (char *) _vm->_resman->openResource(_startRes); -			null_pc = 0; +			char *raw_script = (char *) _vm->_resman->openResource(_startRes); +			uint32 null_pc = 0; +  			runScript(raw_script, raw_script, &null_pc);  			_vm->_resman->closeResource(_startRes);  		} else -			debug(5, "- resource %d invalid", _startRes); +			warning("Start menu resource %d invalid", _startRes);  	}  	return 1; @@ -142,34 +131,26 @@ int32 Logic::fnRegisterStartPoint(int32 *params) {  	// params:	0 id of startup script to call - key  	// 		1 pointer to ascii message -#ifdef _SWORD2_DEBUG -	if (_totalStartups == MAX_starts) -		error("ERROR: _startList full"); +	assert(_totalStartups < MAX_starts); -	// +1 to allow for NULL terminator -	if (strlen((const char *) _vm->_memory->decodePtr(params[1])) + 1 > MAX_description) -		error("ERROR: startup description too long"); -#endif +	char *name = (char *) _vm->_memory->decodePtr(params[1]); -	// this objects id  	_startList[_totalStartups].start_res_id	= _startRes; - -	// a key code to be passed to a script via a script var to SWITCH in -	// the correct start  	_startList[_totalStartups].key = params[0]; -	strcpy(_startList[_totalStartups].description, (const char *) _vm->_memory->decodePtr(params[1])); +	strncpy(_startList[_totalStartups].description, name, MAX_description); +	_startList[_totalStartups].description[MAX_description - 1] = 0; -	// point to next  	_totalStartups++; - -	return 1; +	return IR_CONT;  } -void Logic::conPrintStartMenu(void) { -	// the console 'starts' (or 's') command which lists out all the -	// registered start points in the game +/** + * The console 'starts' (or 's') command which lists out all the registered + * start points in the game. + */ +void Logic::conPrintStartMenu(void) {  	if (!_totalStartups) {  		Debug_Printf("Sorry - no startup positions registered?\n"); @@ -177,76 +158,64 @@ void Logic::conPrintStartMenu(void) {  			Debug_Printf("There is a problem with startup.inf\n");  		else  			Debug_Printf(" (%d screen managers found in startup.inf)\n", _totalScreenManagers); -	} else { -		for (uint i = 0; i < _totalStartups; i++) -			Debug_Printf("%d  (%s)\n", i, _startList[i].description); +		return;  	} + +	for (uint i = 0; i < _totalStartups; i++) +		Debug_Printf("%d  (%s)\n", i, _startList[i].description);  }  void Logic::conStart(int start) { -	char *raw_script; -	char *raw_data_ad; -	uint32 null_pc; - -	if (!_totalStartups) +	if (!_totalStartups) {  		Debug_Printf("Sorry - there are no startups!\n"); -	else if (start >= 0 && start < (int) _totalStartups) { -		// do the startup as we've specified a legal start - -		// restarting - stop sfx, music & speech! - -		_vm->clearFxQueue(); - -		// fade out any music that is currently playing -		fnStopMusic(NULL); - -		// halt the sample prematurely -		_vm->_sound->unpauseSpeech(); -		_vm->_sound->stopSpeech(); +		return; +	} -		// clean out all resources & flags, ready for a total -		// restart +	if (start < 0 || start >= (int) _totalStartups) { +		Debug_Printf("Not a legal start position\n"); +		return; +	} -		// remove all resources from memory, including player -		// object & global variables +	// Restarting - stop sfx, music & speech! -		_vm->_resman->removeAll(); +	_vm->clearFxQueue(); +	fnStopMusic(NULL); +	_vm->_sound->unpauseSpeech(); +	_vm->_sound->stopSpeech(); -		// reopen global variables resource & send address to -		// interpreter - it won't be moving -		_vm->_logic->resetScriptVars(); +	// Remove all resources from memory, including player object and global +	// variables -		// free all the route memory blocks from previous game -		_router->freeAllRouteMem(); +	_vm->_resman->removeAll(); -		// if there was speech text, kill the text block -		if (_speechTextBlocNo) { -			_vm->_fontRenderer->killTextBloc(_speechTextBlocNo); -			_speechTextBlocNo = 0; -		} +	// Reopen global variables resource and send address to interpreter +	_vm->_logic->resetScriptVars(); -		// set the key +	// Free all the route memory blocks from previous game +	_router->freeAllRouteMem(); -		// Open George -		raw_data_ad = (char *) _vm->_resman->openResource(8); -		raw_script = (char *) _vm->_resman->openResource(_startList[start].start_res_id); +	// If there was speech text, kill the text block +	if (_speechTextBlocNo) { +		_vm->_fontRenderer->killTextBloc(_speechTextBlocNo); +		_speechTextBlocNo = 0; +	} -		// denotes script to run -		null_pc = _startList[start].key & 0xffff; +	// Open George +	char *raw_data_ad = (char *) _vm->_resman->openResource(8); +	char *raw_script = (char *) _vm->_resman->openResource(_startList[start].start_res_id); -		Debug_Printf("Running start %d\n", start); -		runScript(raw_script, raw_data_ad, &null_pc); +	// Denotes script to run +	uint32 null_pc = _startList[start].key & 0xffff; -		_vm->_resman->closeResource(_startList[start].start_res_id); +	Debug_Printf("Running start %d\n", start); +	runScript(raw_script, raw_data_ad, &null_pc); -		// Close George -		_vm->_resman->closeResource(8); +	_vm->_resman->closeResource(_startList[start].start_res_id); +	_vm->_resman->closeResource(8); -		// make sure thre's a mouse, in case restarting while -		// mouse not available -		fnAddHuman(NULL); -	} else -		Debug_Printf("Not a legal start position\n"); +	// Make sure there's a mouse, in case restarting while mouse not +	// available +	fnAddHuman(NULL);  }  } // End of namespace Sword2  | 
