diff options
| author | Torbjörn Andersson | 2003-11-08 15:47:51 +0000 | 
|---|---|---|
| committer | Torbjörn Andersson | 2003-11-08 15:47:51 +0000 | 
| commit | 688c80b0620ae5765355a4048864bb3de84ebf74 (patch) | |
| tree | 497d8efc73b08f5a4d58c45c52b7a6bafa1975ff | |
| parent | b04ddef7506bfa08527da9e79040c583fb765b2e (diff) | |
| download | scummvm-rg350-688c80b0620ae5765355a4048864bb3de84ebf74.tar.gz scummvm-rg350-688c80b0620ae5765355a4048864bb3de84ebf74.tar.bz2 scummvm-rg350-688c80b0620ae5765355a4048864bb3de84ebf74.zip | |
Moved more stuff into classes, changed some static allocation to dynamic,
and removed some of the references to global variables.
At this point I believe everything in the main game engine has been moved
into classes - not necessarily the correct ones, but still... However,
there is some stuff in the driver directory that need to be taken care of
as well.
svn-id: r11207
36 files changed, 455 insertions, 454 deletions
| diff --git a/sword2/anims.cpp b/sword2/anims.cpp index 1b14ca409a..00797a7300 100644 --- a/sword2/anims.cpp +++ b/sword2/anims.cpp @@ -161,7 +161,7 @@ int32 Logic::animate(int32 *params, bool reverse) {  #endif  		// point to anim header -		anim_head = g_sword2->fetchAnimHeader(anim_file); +		anim_head = _vm->fetchAnimHeader(anim_file);  /* #ifdef _SWORD2_DEBUG  		// check there's at least one frame @@ -177,7 +177,7 @@ int32 Logic::animate(int32 *params, bool reverse) {  			ob_graphic->anim_pc = anim_head->noAnimFrames - 1;  		else  			ob_graphic->anim_pc = 0; - 	} else if (Get_sync()) { + 	} else if (g_logic->getSync()) {  		// We've received a sync - return to script immediately  		debug(5, "**sync stopped %d**", ID); @@ -191,7 +191,7 @@ int32 Logic::animate(int32 *params, bool reverse) {  		// open anim file and point to anim header  		anim_file = res_man->openResource(ob_graphic->anim_resource); -		anim_head = g_sword2->fetchAnimHeader(anim_file); +		anim_head = _vm->fetchAnimHeader(anim_file);  		if (reverse)  			ob_graphic->anim_pc--; @@ -284,7 +284,7 @@ int32 Logic::fnSetFrame(int32 *params) {  #endif  	// set up pointer to the animation header -	anim_head = g_sword2->fetchAnimHeader(anim_file); +	anim_head = _vm->fetchAnimHeader(anim_file);  /* #ifdef _SWORD2_DEBUG  	// check there's at least one frame @@ -497,7 +497,7 @@ void Logic::createSequenceSpeech(_movieTextObject *sequenceText[]) {  		local_text = _sequenceTextList[line].textNumber & 0xffff;  		// open text resource & get the line -		text = g_sword2->fetchTextLine(res_man->openResource(text_res), local_text); +		text = _vm->fetchTextLine(res_man->openResource(text_res), local_text);  		wavId = (int32) READ_LE_UINT16(text);  		// now ok to close the text file @@ -540,7 +540,7 @@ void Logic::createSequenceSpeech(_movieTextObject *sequenceText[]) {  		if (gui->_subtitles || !speechRunning) {  			// open text resource & get the line -			text = g_sword2->fetchTextLine(res_man->openResource(text_res), local_text); +			text = _vm->fetchTextLine(res_man->openResource(text_res), local_text);  			// make the sprite  			// 'text+2' to skip the first 2 bytes which form the  			// line reference number @@ -551,7 +551,7 @@ void Logic::createSequenceSpeech(_movieTextObject *sequenceText[]) {  			// When rendering text over a sequence we need a  			// different colour for the border. -			_sequenceTextList[line].text_mem = fontRenderer.makeTextSprite(text + 2, 600, 255, g_sword2->_speechFontId, 1); +			_sequenceTextList[line].text_mem = fontRenderer->makeTextSprite(text + 2, 600, 255, _vm->_speechFontId, 1);  			// ok to close the text resource now  			res_man->closeResource(text_res); @@ -727,7 +727,7 @@ int32 Logic::fnPlaySequence(int32 *params) {  	MoviePlayer player;  -	if (_sequenceTextLines && !(g_sword2->_features & GF_DEMO)) +	if (_sequenceTextLines && !(_vm->_features & GF_DEMO))  		rv = player.play(filename, sequenceSpeechArray, leadOut);  	else  		rv = player.play(filename, NULL, leadOut); diff --git a/sword2/build_display.cpp b/sword2/build_display.cpp index aa734d71e6..82f098719a 100644 --- a/sword2/build_display.cpp +++ b/sword2/build_display.cpp @@ -160,7 +160,7 @@ void Sword2Engine::buildDisplay(void) {  			// text blocks  			// speech blocks and headup debug text -			fontRenderer.printTextBlocs(); +			fontRenderer->printTextBlocs();  			// menu bar & icons @@ -218,7 +218,7 @@ void Sword2Engine::displayMsg(uint8 *text, int time) {  	g_display->closeMenuImmediately();  	g_display->clearScene(); -	text_spr = fontRenderer.makeTextSprite(text, 640, 187, g_sword2->_speechFontId); +	text_spr = fontRenderer->makeTextSprite(text, 640, 187, _speechFontId);  	frame = (_frameHeader *) text_spr->ad; @@ -702,7 +702,7 @@ int32 Logic::fnRegisterFrame(int32 *params) {  	//		1 pointer to graphic structure  	//		2 pointer to mega structure or NULL if not a mega -	return g_sword2->registerFrame(params); +	return _vm->registerFrame(params);  }  int32 Sword2Engine::registerFrame(int32 *params) { @@ -790,15 +790,15 @@ int32 Logic::fnUpdatePlayerStats(int32 *params) {  	Object_mega *ob_mega = (Object_mega *) params[0]; -	g_sword2->_thisScreen.player_feet_x = ob_mega->feet_x; -	g_sword2->_thisScreen.player_feet_y = ob_mega->feet_y; +	_vm->_thisScreen.player_feet_x = ob_mega->feet_x; +	_vm->_thisScreen.player_feet_y = ob_mega->feet_y;  	// for the script  	PLAYER_FEET_X = ob_mega->feet_x;  	PLAYER_FEET_Y = ob_mega->feet_y;  	PLAYER_CUR_DIR = ob_mega->current_dir; -	SCROLL_OFFSET_X = g_sword2->_thisScreen.scroll_offset_x; +	SCROLL_OFFSET_X = _vm->_thisScreen.scroll_offset_x;  	debug(5, "fnUpdatePlayerStats: %d %d", ob_mega->feet_x, ob_mega->feet_y); @@ -832,7 +832,7 @@ int32 Logic::fnSetPalette(int32 *params) {  	// params:	0 resource number of palette file, or 0 if it's to be  	//		  the palette from the current screen -	g_sword2->setFullPalette(params[0]); +	_vm->setFullPalette(params[0]);  	return IR_CONT;  } @@ -927,13 +927,13 @@ int32 Logic::fnChangeShadows(int32 *params) {  	// params:	none  	// if last screen was using a shading mask (see below) -	if (g_sword2->_thisScreen.mask_flag) { +	if (_vm->_thisScreen.mask_flag) {  		uint32 rv = g_display->closeLightMask();  		if (rv)  			error("Driver Error %.8x [%s line %u]", rv); -		g_sword2->_thisScreen.mask_flag = 0; +		_vm->_thisScreen.mask_flag = 0;  	}  	return IR_CONT; diff --git a/sword2/console.cpp b/sword2/console.cpp index 387a6a7824..d31f77335e 100644 --- a/sword2/console.cpp +++ b/sword2/console.cpp @@ -45,9 +45,9 @@ void Debugger::varSet(int var, int val) {  	Debug_Printf("now %d\n", VAR(var));  } -Debugger::Debugger(Sword2Engine *s) +Debugger::Debugger(Sword2Engine *vm)  	: Common::Debugger<Debugger>() { -	_vm = s; +	_vm = vm;  	memset(_debugTextBlocks, 0, sizeof(_debugTextBlocks));  	memset(_showVar, 0, sizeof(_showVar)); @@ -361,7 +361,7 @@ bool Debugger::Cmd_ListSaveGames(int argc, const char **argv) {  		uint8 description[SAVE_DESCRIPTION_LEN];  		// if there is a save game print the name -		if (g_sword2->getSaveDescription(i, description) == SR_OK) +		if (_vm->getSaveDescription(i, description) == SR_OK)  			DebugPrintf("%d: \"%s\"\n", i, description);  	} @@ -380,7 +380,7 @@ bool Debugger::Cmd_SaveGame(int argc, const char **argv) {  	}  	// if mouse if off, or system menu is locked off -	if (g_sword2->_mouseStatus || g_sword2->_mouseModeLocked) { +	if (_vm->_mouseStatus || _vm->_mouseModeLocked) {  		DebugPrintf("WARNING: Cannot save game while control menu unavailable!\n");  		return true;  	} @@ -405,7 +405,7 @@ bool Debugger::Cmd_SaveGame(int argc, const char **argv) {  	}  	slotNo = atoi(argv[1]); -	rv = g_sword2->saveGame(slotNo, (uint8 *) description); +	rv = _vm->saveGame(slotNo, (uint8 *) description);  	if (rv == SR_OK)  		DebugPrintf("Saved game \"%s\" to file \"savegame.%.3d\"\n", description, slotNo); @@ -428,16 +428,16 @@ bool Debugger::Cmd_RestoreGame(int argc, const char **argv) {  	}  	// if mouse if off, or system menu is locked off -	if (g_sword2->_mouseStatus || g_sword2->_mouseModeLocked) { +	if (_vm->_mouseStatus || _vm->_mouseModeLocked) {  		DebugPrintf("WARNING: Cannot restore game while control menu unavailable!\n");  		return true;  	}  	slotNo = atoi(argv[1]); -	rv = g_sword2->restoreGame(slotNo); +	rv = _vm->restoreGame(slotNo);  	if (rv == SR_OK) { -		g_sword2->getSaveDescription(slotNo, description); +		_vm->getSaveDescription(slotNo, description);  		DebugPrintf("Restored game \"%s\" from file \"savegame.%.3d\"\n", description, slotNo);  	} else if (rv == SR_ERR_FILEOPEN)  		DebugPrintf("ERROR: Cannot open file \"savegame.%.3d\"\n", slotNo); @@ -667,9 +667,9 @@ bool Debugger::Cmd_Grab(int argc, const char **argv) {  	DebugPrintf("FIXME: Continuous screen-grabbing not implemented\n");  #if 0 -	g_sword2->_grabbingSequences = !g_sword2->_grabbingSequences; +	_vm->_grabbingSequences = !_vm->_grabbingSequences; -	if (g_sword2->_grabbingSequences) +	if (_vm->_grabbingSequences)  		DebugPrintf("PCX-grabbing enabled\n");  	else  		DebugPrintf("PCX-grabbing disabled\n"); @@ -682,12 +682,12 @@ bool Debugger::Cmd_Events(int argc, const char **argv) {  	DebugPrintf("EVENT LIST:\n");  	for (uint32 i = 0; i < MAX_events; i++) { -		if (g_sword2->_eventList[i].id) { -			uint32 target = g_sword2->_eventList[i].id; -			uint32 script = g_sword2->_eventList[i].interact_id; +		if (g_logic->_eventList[i].id) { +			uint32 target = g_logic->_eventList[i].id; +			uint32 script = g_logic->_eventList[i].interact_id; -			DebugPrintf("slot %d: id = %s (%d)\n", i, g_sword2->fetchObjectName(target), target); -			DebugPrintf("         script = %s (%d) pos %d\n", g_sword2->fetchObjectName(script / 65536), script / 65536, script % 65536); +			DebugPrintf("slot %d: id = %s (%d)\n", i, _vm->fetchObjectName(target), target); +			DebugPrintf("         script = %s (%d) pos %d\n", _vm->fetchObjectName(script / 65536), script / 65536, script % 65536);  		}  	} @@ -695,9 +695,9 @@ bool Debugger::Cmd_Events(int argc, const char **argv) {  }  bool Debugger::Cmd_Sfx(int argc, const char **argv) { -	g_sword2->_wantSfxDebug = !g_sword2->_wantSfxDebug; +	_vm->_wantSfxDebug = !_vm->_wantSfxDebug; -	if (g_sword2->_wantSfxDebug) +	if (_vm->_wantSfxDebug)  		DebugPrintf("SFX logging activated\n");  	else  		DebugPrintf("SFX logging deactivated\n"); @@ -706,19 +706,19 @@ bool Debugger::Cmd_Sfx(int argc, const char **argv) {  }  bool Debugger::Cmd_English(int argc, const char **argv) { -	g_sword2->initialiseFontResourceFlags(DEFAULT_TEXT); +	_vm->initialiseFontResourceFlags(DEFAULT_TEXT);  	DebugPrintf("Default fonts selected\n");  	return true;  }  bool Debugger::Cmd_Finnish(int argc, const char **argv) { -	g_sword2->initialiseFontResourceFlags(FINNISH_TEXT); +	_vm->initialiseFontResourceFlags(FINNISH_TEXT);  	DebugPrintf("Finnish fonts selected\n");  	return true;  }  bool Debugger::Cmd_Polish(int argc, const char **argv) { -	g_sword2->initialiseFontResourceFlags(POLISH_TEXT); +	_vm->initialiseFontResourceFlags(POLISH_TEXT);  	DebugPrintf("Polish fonts selected\n");  	return true;  } diff --git a/sword2/console.h b/sword2/console.h index 047bc0cba6..b7189fb327 100644 --- a/sword2/console.h +++ b/sword2/console.h @@ -59,7 +59,7 @@ private:  	void drawRect(int16 x, int16 y, int16 x2, int16 y2, uint8 pen);  public: -	Debugger(Sword2Engine *s); +	Debugger(Sword2Engine *vm);  	int16 _rectX1, _rectY1;  	int16 _rectX2, _rectY2; diff --git a/sword2/controls.cpp b/sword2/controls.cpp index cc224871ab..740ade618b 100644 --- a/sword2/controls.cpp +++ b/sword2/controls.cpp @@ -1261,7 +1261,7 @@ public:  					break;  				} -				saveLoadError((char*) (g_sword2->fetchTextLine(res_man->openResource(textId / SIZE), textId & 0xffff) + 2)); +				saveLoadError((char *) (g_sword2->fetchTextLine(res_man->openResource(textId / SIZE), textId & 0xffff) + 2));  				result = 0;  			}  		} else { @@ -1333,7 +1333,7 @@ void SaveLoadDialog::saveLoadError(char* text) {  	g_sword2->removeMsg();  } -Gui::Gui() : _baseSlot(0) { +Gui::Gui(Sword2Engine *vm) : _vm(vm), _baseSlot(0) {  	int i;  	for (i = 0; i < ARRAYSIZE(_musicVolume); i++) { @@ -1413,8 +1413,7 @@ void Gui::quitControl(void) {  	}  	// close engine systems down -	Close_game(); -	exit(0); +	_vm->closeGame();  }  void Gui::restartControl(void) { @@ -1428,7 +1427,7 @@ void Gui::restartControl(void) {  	}  	// Stop music instantly! -	g_sword2->killMusic(); +	_vm->killMusic();  	//in case we were dead - well we're not anymore!  	DEAD = 0; @@ -1452,20 +1451,20 @@ void Gui::restartControl(void) {  	DEMO = temp_demo_flag;  	// free all the route memory blocks from previous game -	router.freeAllRouteMem(); +	g_logic->_router->freeAllRouteMem();  	// call the same function that first started us up -	g_sword2->Start_game(); +	_vm->startGame();  	// prime system with a game cycle  	// reset the graphic 'buildit' list before a new logic list  	// (see fnRegisterFrame) -	g_sword2->resetRenderLists(); +	_vm->resetRenderLists();  	// reset the mouse hot-spot list (see fnRegisterMouse and  	// fnRegisterFrame) -	g_sword2->resetMouseList(); +	_vm->resetMouseList();  	g_display->closeMenuImmediately(); @@ -1473,7 +1472,7 @@ void Gui::restartControl(void) {  	// - this is taken from fnInitBackground  	// switch on scrolling (2 means first time on screen) -	g_sword2->_thisScreen.scroll_flag = 2; +	_vm->_thisScreen.scroll_flag = 2;  	if (g_logic->processSession())  		error("restart 1st cycle failed??"); @@ -1481,7 +1480,7 @@ void Gui::restartControl(void) {  	// So palette not restored immediately after control panel - we want  	// to fade up instead! -	g_sword2->_thisScreen.new_palette = 99; +	_vm->_thisScreen.new_palette = 99;  }  void Gui::optionControl(void) { diff --git a/sword2/controls.h b/sword2/controls.h index d85adbf66b..169667cbbb 100644 --- a/sword2/controls.h +++ b/sword2/controls.h @@ -22,8 +22,12 @@  namespace Sword2 { +class Sword2Engine; +  class Gui {  private: +	Sword2Engine *_vm; +  	int _musicVolume[17];  	int _soundVolume[15]; @@ -35,7 +39,7 @@ public:  	bool _stereoReversed;  	bool _pointerTextSelected; -	Gui(); +	Gui(Sword2Engine *vm);  	uint32 restoreControl(void);  	void saveControl(void); diff --git a/sword2/debug.cpp b/sword2/debug.cpp index 8d5861eaaa..3efe37747d 100644 --- a/sword2/debug.cpp +++ b/sword2/debug.cpp @@ -41,7 +41,7 @@ void Debugger::clearDebugTextBlocks(void) {  	while (blockNo < MAX_DEBUG_TEXT_BLOCKS && _debugTextBlocks[blockNo] > 0) {  		// kill the system text block -		fontRenderer.killTextBloc(_debugTextBlocks[blockNo]); +		fontRenderer->killTextBloc(_debugTextBlocks[blockNo]);  		// clear this element of our array of block numbers  		_debugTextBlocks[blockNo] = 0; @@ -58,7 +58,7 @@ void Debugger::makeDebugTextBlock(char *text, int16 x, int16 y) {  	assert(blockNo < MAX_DEBUG_TEXT_BLOCKS); -	_debugTextBlocks[blockNo] = fontRenderer.buildNewBloc((uint8 *) text, x, y, 640 - x, 0, RDSPR_DISPLAYALIGN, CONSOLE_FONT_ID, NO_JUSTIFICATION); +	_debugTextBlocks[blockNo] = fontRenderer->buildNewBloc((uint8 *) text, x, y, 640 - x, 0, RDSPR_DISPLAYALIGN, CONSOLE_FONT_ID, NO_JUSTIFICATION);  }  void Debugger::buildDebugText(void) { @@ -113,7 +113,7 @@ void Debugger::buildDebugText(void) {  	// speed-up indicator -	if (g_sword2->_renderSkip) {		// see sword.cpp +	if (_vm->_renderSkip) {		// see sword.cpp  		sprintf(buf, "SKIPPING FRAMES FOR SPEED-UP!");  		makeDebugTextBlock(buf, 0, 120);  	} @@ -129,7 +129,7 @@ void Debugger::buildDebugText(void) {  		time -= _startTime;  		sprintf(buf, "Time %.2d:%.2d:%.2d.%.3d", (time / 3600000) % 60, (time / 60000) % 60, (time / 1000) % 60, time % 1000);  		makeDebugTextBlock(buf, 500, 360); -		sprintf(buf, "Game %d", g_sword2->_gameCycle); +		sprintf(buf, "Game %d", _vm->_gameCycle);  		makeDebugTextBlock(buf, 500, 380);  	} @@ -178,23 +178,23 @@ void Debugger::buildDebugText(void) {  		if (CLICKED_ID)  			sprintf(buf, "last click at %d,%d (id %d: %s)",  				MOUSE_X, MOUSE_Y, CLICKED_ID, -				g_sword2->fetchObjectName(CLICKED_ID)); +				_vm->fetchObjectName(CLICKED_ID));  		else  			sprintf(buf, "last click at %d,%d (---)",  				MOUSE_X, MOUSE_Y);   		makeDebugTextBlock(buf, 0, 15); -		if (g_sword2->_mouseTouching) +		if (_vm->_mouseTouching)  			sprintf(buf, "mouse %d,%d (id %d: %s)", -				g_display->_mouseX + g_sword2->_thisScreen.scroll_offset_x, -				g_display->_mouseY + g_sword2->_thisScreen.scroll_offset_y, -				g_sword2->_mouseTouching, -				g_sword2->fetchObjectName(g_sword2->_mouseTouching)); +				g_display->_mouseX + _vm->_thisScreen.scroll_offset_x, +				g_display->_mouseY + _vm->_thisScreen.scroll_offset_y, +				_vm->_mouseTouching, +				_vm->fetchObjectName(_vm->_mouseTouching));  		else  			sprintf(buf, "mouse %d,%d (not touching)", -				g_display->_mouseX + g_sword2->_thisScreen.scroll_offset_x, -				g_display->_mouseY + g_sword2->_thisScreen.scroll_offset_y); +				g_display->_mouseX + _vm->_thisScreen.scroll_offset_x, +				g_display->_mouseY + _vm->_thisScreen.scroll_offset_y);  		makeDebugTextBlock(buf, 0, 30); @@ -203,23 +203,23 @@ void Debugger::buildDebugText(void) {  		if (_playerGraphic.anim_resource)  			sprintf(buf, "player %d,%d %s (%d) #%d/%d", -				g_sword2->_thisScreen.player_feet_x, -				g_sword2->_thisScreen.player_feet_y, -				g_sword2->fetchObjectName(_playerGraphic.anim_resource), +				_vm->_thisScreen.player_feet_x, +				_vm->_thisScreen.player_feet_y, +				_vm->fetchObjectName(_playerGraphic.anim_resource),  				_playerGraphic.anim_resource,  				_playerGraphic.anim_pc,  				_playerGraphicNoFrames);  		else  			sprintf(buf, "player %d,%d --- %d", -				g_sword2->_thisScreen.player_feet_x, -				g_sword2->_thisScreen.player_feet_y, +				_vm->_thisScreen.player_feet_x, +				_vm->_thisScreen.player_feet_y,  				_playerGraphic.anim_pc);  		makeDebugTextBlock(buf, 0, 45);   		// frames-per-second counter -		sprintf(buf, "fps %d", g_sword2->_fps); +		sprintf(buf, "fps %d", _vm->_fps);  		makeDebugTextBlock(buf, 440, 0);   		// location number @@ -234,44 +234,44 @@ void Debugger::buildDebugText(void) {   		// no. of events in event list -		sprintf(buf, "events=%d", g_sword2->countEvents()); +		sprintf(buf, "events=%d", g_logic->countEvents());  		makeDebugTextBlock(buf, 440, 45);  		// sprite list usage -		sprintf(buf, "bgp0: %d/%d", g_sword2->_curBgp0, MAX_bgp0_sprites); +		sprintf(buf, "bgp0: %d/%d", _vm->_curBgp0, MAX_bgp0_sprites);  		makeDebugTextBlock(buf, 560, 0); -		sprintf(buf, "bgp1: %d/%d", g_sword2->_curBgp1, MAX_bgp1_sprites); +		sprintf(buf, "bgp1: %d/%d", _vm->_curBgp1, MAX_bgp1_sprites);  		makeDebugTextBlock(buf, 560, 15); -		sprintf(buf, "back: %d/%d", g_sword2->_curBack, MAX_back_sprites); +		sprintf(buf, "back: %d/%d", _vm->_curBack, MAX_back_sprites);  		makeDebugTextBlock(buf, 560, 30); -		sprintf(buf, "sort: %d/%d", g_sword2->_curSort, MAX_sort_sprites); +		sprintf(buf, "sort: %d/%d", _vm->_curSort, MAX_sort_sprites);  		makeDebugTextBlock(buf, 560, 45); -		sprintf(buf, "fore: %d/%d", g_sword2->_curFore, MAX_fore_sprites); +		sprintf(buf, "fore: %d/%d", _vm->_curFore, MAX_fore_sprites);  		makeDebugTextBlock(buf, 560, 60); -		sprintf(buf, "fgp0: %d/%d", g_sword2->_curFgp0, MAX_fgp0_sprites); +		sprintf(buf, "fgp0: %d/%d", _vm->_curFgp0, MAX_fgp0_sprites);  		makeDebugTextBlock(buf, 560, 75); -		sprintf(buf, "fgp1: %d/%d", g_sword2->_curFgp1, MAX_fgp1_sprites); +		sprintf(buf, "fgp1: %d/%d", _vm->_curFgp1, MAX_fgp1_sprites);  		makeDebugTextBlock(buf, 560, 90);  		// largest layer & sprite  		// NB. Strings already constructed in Build_display.cpp -		makeDebugTextBlock(g_sword2->_largestLayerInfo, 0, 60); -		makeDebugTextBlock(g_sword2->_largestSpriteInfo, 0, 75); +		makeDebugTextBlock(_vm->_largestLayerInfo, 0, 60); +		makeDebugTextBlock(_vm->_largestSpriteInfo, 0, 75);  		// "waiting for person" indicator - set form fnTheyDo and  		// fnTheyDoWeWait  		if (g_logic->_speechScriptWaiting) {  			sprintf(buf, "script waiting for %s (%d)", -				g_sword2->fetchObjectName(g_logic->_speechScriptWaiting), +				_vm->fetchObjectName(g_logic->_speechScriptWaiting),  				g_logic->_speechScriptWaiting);  			makeDebugTextBlock(buf, 0, 90);  		} @@ -310,17 +310,17 @@ void Debugger::drawDebugGraphics(void) {  	// walk-grid  	if (_displayWalkGrid) -		router.plotWalkGrid();  +		g_logic->_router->plotWalkGrid();   	// player feet coord marker  	if (_displayPlayerMarker) -		plotCrossHair(g_sword2->_thisScreen.player_feet_x, g_sword2->_thisScreen.player_feet_y, 215); +		plotCrossHair(_vm->_thisScreen.player_feet_x, _vm->_thisScreen.player_feet_y, 215);  	// mouse marker & coords  	if (_displayMouseMarker) -		plotCrossHair(g_display->_mouseX + g_sword2->_thisScreen.scroll_offset_x, g_display->_mouseY + g_sword2->_thisScreen.scroll_offset_y, 215); +		plotCrossHair(g_display->_mouseX + _vm->_thisScreen.scroll_offset_x, g_display->_mouseY + _vm->_thisScreen.scroll_offset_y, 215);     	// mouse area rectangle / sprite box rectangle when testing anims @@ -355,10 +355,10 @@ void Debugger::drawRect(int16 x1, int16 y1, int16 x2, int16 y2, uint8 pen) {  void Debugger::printCurrentInfo(void) {  	// prints general stuff about the screen, etc. -	if (g_sword2->_thisScreen.background_layer_id) { -		Debug_Printf("background layer id %d\n", g_sword2->_thisScreen.background_layer_id); -		Debug_Printf("%d wide, %d high\n", g_sword2->_thisScreen.screen_wide, g_sword2->_thisScreen.screen_deep); -		Debug_Printf("%d normal layers\n", g_sword2->_thisScreen.number_of_layers); +	if (_vm->_thisScreen.background_layer_id) { +		Debug_Printf("background layer id %d\n", _vm->_thisScreen.background_layer_id); +		Debug_Printf("%d wide, %d high\n", _vm->_thisScreen.screen_wide, _vm->_thisScreen.screen_deep); +		Debug_Printf("%d normal layers\n", _vm->_thisScreen.number_of_layers);  		g_logic->examineRunList();  	} else diff --git a/sword2/driver/d_draw.cpp b/sword2/driver/d_draw.cpp index 407697439a..4b94388b9a 100644 --- a/sword2/driver/d_draw.cpp +++ b/sword2/driver/d_draw.cpp @@ -143,7 +143,7 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu  		memset(g_display->_buffer, 0, g_display->_screenWide * MENUDEEP);  		uint8 msg[] = "Cutscene - Press ESC to exit"; -		mem *data = fontRenderer.makeTextSprite(msg, 640, 255, g_sword2->_speechFontId); +		mem *data = fontRenderer->makeTextSprite(msg, 640, 255, g_sword2->_speechFontId);  		_frameHeader *frame = (_frameHeader *) data->ad;  		_spriteInfo msgSprite;  		uint8 *msgSurface; diff --git a/sword2/driver/rdwin.cpp b/sword2/driver/rdwin.cpp index 674ac960bf..42cc6e96de 100644 --- a/sword2/driver/rdwin.cpp +++ b/sword2/driver/rdwin.cpp @@ -60,7 +60,7 @@ void Sword2Engine::parseEvents() {  			LogMouseEvent(RD_RIGHTBUTTONUP);  			break;  		case OSystem::EVENT_QUIT: -			Close_game(); +			g_sword2->closeGame();  			break;  		default:  			break; diff --git a/sword2/driver/render.cpp b/sword2/driver/render.cpp index e844294c43..0b01468ac9 100644 --- a/sword2/driver/render.cpp +++ b/sword2/driver/render.cpp @@ -641,7 +641,7 @@ bool Display::endRenderCycle(void) {  	if (_scrollXTarget == _scrollX && _scrollYTarget == _scrollY) {  		// If we have already reached the scroll target sleep for the  		// rest of the render cycle. -		sleepUntil(_totalTime); +		g_sword2->sleepUntil(_totalTime);  		_initialTime = SVM_timeGetTime();  		_totalTime += MILLISECSPERCYCLE;  		return true; diff --git a/sword2/events.cpp b/sword2/events.cpp index e721e4655f..90757fb374 100644 --- a/sword2/events.cpp +++ b/sword2/events.cpp @@ -29,11 +29,7 @@  namespace Sword2 { -void Sword2Engine::initEventSystem(void) { -	memset(_eventList, 0, sizeof(_eventList)); -} - -uint32 Sword2Engine::countEvents(void) { +uint32 Logic::countEvents(void) {  	uint32 count = 0;  	for (int i = 0; i < MAX_events; i++) { @@ -44,7 +40,7 @@ uint32 Sword2Engine::countEvents(void) {  	return count;  } -void Sword2Engine::sendEvent(uint32 id, uint32 interact_id) { +void Logic::sendEvent(uint32 id, uint32 interact_id) {  	int i;  	for (i = 0; i < MAX_events; i++) { @@ -66,12 +62,12 @@ void Sword2Engine::sendEvent(uint32 id, uint32 interact_id) {  	_eventList[i].interact_id = interact_id;  } -void Sword2Engine::setPlayerActionEvent(uint32 id, uint32 interact_id) { +void Logic::setPlayerActionEvent(uint32 id, uint32 interact_id) {  	// Full script id of action script number 2  	sendEvent(id, (interact_id << 16) | 2);  } -bool Sword2Engine::checkEventWaiting(void) { +bool Logic::checkEventWaiting(void) {  	for (int i = 0; i < MAX_events; i++) {  		if (_eventList[i].id == ID)  			return true; @@ -80,7 +76,7 @@ bool Sword2Engine::checkEventWaiting(void) {  	return false;  } -void Sword2Engine::startEvent(void) { +void Logic::startEvent(void) {  	// call this from stuff like fnWalk  	// you must follow with a return IR_TERMINATE @@ -99,7 +95,7 @@ void Sword2Engine::startEvent(void) {  	error("Start_event can't find event for id %d", ID);  } -void Sword2Engine::clearEvent(uint32 id) { +void Logic::clearEvent(uint32 id) {  	for (int i = 0; i < MAX_events; i++) {  		if (_eventList[i].id == id) {  			// clear the slot @@ -109,7 +105,7 @@ void Sword2Engine::clearEvent(uint32 id) {  	}  } -void Sword2Engine::killAllIdsEvents(uint32 id) { +void Logic::killAllIdsEvents(uint32 id) {  	for (int i = 0; i < MAX_events; i++) {  		if (_eventList[i].id == id) {  			// clear the slot @@ -126,7 +122,7 @@ int32 Logic::fnRequestSpeech(int32 *params) {  	//		  servicing  	// Full script id to interact with - megas run their own 7th script -	g_sword2->sendEvent(params[0], (params[0] << 16) | 6); +	sendEvent(params[0], (params[0] << 16) | 6);  	return IR_CONT;  } @@ -140,7 +136,7 @@ int32 Logic::fnSetPlayerActionEvent(int32 *params) {  	// params:	0 id to interact with -	g_sword2->setPlayerActionEvent(CUR_PLAYER_ID, params[0]); +	setPlayerActionEvent(CUR_PLAYER_ID, params[0]);  	return IR_CONT;  } @@ -151,7 +147,7 @@ int32 Logic::fnSendEvent(int32 *params) {  	// params:	0 id to receive event  	//		1 script to run -	g_sword2->sendEvent(params[0], params[1]); +	sendEvent(params[0], params[1]);  	return IR_CONT;  } @@ -160,7 +156,7 @@ int32 Logic::fnCheckEventWaiting(int32 *params) {  	// params:	none -	if (g_sword2->checkEventWaiting()) +	if (checkEventWaiting())  		RESULT = 1;  	else  		RESULT = 0; @@ -174,10 +170,10 @@ int32 Logic::fnCheckEventWaiting(int32 *params) {  int32 Logic::fnCheckForEvent(int32 *params) {  	// params:	none -	if (!g_sword2->checkEventWaiting()) +	if (!checkEventWaiting())  		return IR_CONT; -	g_sword2->startEvent(); +	startEvent();  	return IR_TERMINATE;  } @@ -194,12 +190,12 @@ int32 Logic::fnPauseForEvent(int32 *params) {  	// first, check for an event -	if (g_sword2->checkEventWaiting()) { +	if (checkEventWaiting()) {  		// reset the 'looping' flag  		ob_logic->looping = 0;  		// start the event - run 3rd script of target object on level 1 -		g_sword2->startEvent(); +		startEvent();  		return IR_TERMINATE;  	} @@ -231,14 +227,14 @@ int32 Logic::fnPauseForEvent(int32 *params) {  int32 Logic::fnClearEvent(int32 *params) {  	// params:	none -	g_sword2->clearEvent(ID); +	clearEvent(ID);  	return IR_CONT;  }  int32 Logic::fnStartEvent(int32 *params) {  	// params:	none -	g_sword2->startEvent(); +	startEvent();  	return IR_TERMINATE;  } diff --git a/sword2/events.h b/sword2/events.h index 0f24302080..a1d358bf22 100644 --- a/sword2/events.h +++ b/sword2/events.h @@ -24,11 +24,6 @@  namespace Sword2 { -struct _event_unit { -	uint32 id; -	uint32 interact_id; -}; -  } // End of namespace Sword2  #endif diff --git a/sword2/function.cpp b/sword2/function.cpp index c4699398ce..681ac8d469 100644 --- a/sword2/function.cpp +++ b/sword2/function.cpp @@ -139,7 +139,7 @@ int32 Logic::fnRandom(int32 *params) {  	// params:	0 min  	//		1 max -	RESULT = g_sword2->_rnd.getRandomNumberRng(params[0], params[1]); +	RESULT = _vm->_rnd.getRandomNumberRng(params[0], params[1]);  	return IR_CONT;  } @@ -204,7 +204,7 @@ int32 Logic::fnPassGraph(int32 *params) {  	// params:	0 pointer to a graphic structure (might not need this?) -	memcpy(&g_sword2->_engineGraph, (uint8 *) params[0], sizeof(Object_graphic)); +	memcpy(&_vm->_engineGraph, (uint8 *) params[0], sizeof(Object_graphic));  	// makes no odds  	return IR_CONT; @@ -220,7 +220,7 @@ int32 Logic::fnPassMega(int32 *params) {  	// params: 	0 pointer to a mega structure -	memcpy(&g_sword2->_engineMega, (uint8 *) params[0], sizeof(Object_mega)); +	memcpy(&_vm->_engineMega, (uint8 *) params[0], sizeof(Object_mega));  	// makes no odds  	return IR_CONT; @@ -337,9 +337,9 @@ int32 Logic::fnDisplayMsg(int32 *params) {  	// +2 to skip the encoded text number in the first 2 chars; 3 is  	// duration in seconds -	g_sword2->displayMsg(g_sword2->fetchTextLine(res_man->openResource(text_res), local_text) + 2, 3); +	_vm->displayMsg(_vm->fetchTextLine(res_man->openResource(text_res), local_text) + 2, 3);  	res_man->closeResource(text_res); -	g_sword2->removeMsg(); +	_vm->removeMsg();  	return IR_CONT;  } @@ -372,7 +372,7 @@ int32 Logic::fnResetGlobals(int32 *params) {  	// - this is taken from fnInitBackground  	// switch on scrolling (2 means first time on screen) -	g_sword2->_thisScreen.scroll_flag = 2; +	_vm->_thisScreen.scroll_flag = 2;  	return IR_CONT;  } @@ -444,19 +444,15 @@ int32 Logic::fnPlayCredits(int32 *params) {  		g_display->setPalette(0, 256, oldPal, RDPAL_FADE);  		g_display->fadeUp();  		g_display->updateDisplay(); -		g_sword2->buildDisplay(); +		_vm->buildDisplay();  		g_display->waitForFade();  		g_sound->muteFx(false);  		g_sound->muteSpeech(false);  	} -	// FIXME: This probably isn't the correct way of shutting down ScummVM -	// Anyway, I don't know if we ever call this from the demo. - -	if (g_sword2->_features & GF_DEMO) { -		Close_game();		// close engine systems down -		exit(0);		// quit the game +	if (_vm->_features & GF_DEMO) { +		_vm->closeGame();  	}  	return IR_CONT; diff --git a/sword2/icons.cpp b/sword2/icons.cpp index 6771bef83c..32766383f8 100644 --- a/sword2/icons.cpp +++ b/sword2/icons.cpp @@ -31,11 +31,11 @@ namespace Sword2 {  int32 Logic::fnAddMenuObject(int32 *params) {  	// params:	0 pointer to a menu_object structure to copy down -	assert(g_sword2->_totalTemp < TOTAL_engine_pockets); +	assert(_vm->_totalTemp < TOTAL_engine_pockets);  	// copy the structure to our in-the-engine list -	memcpy(&g_sword2->_tempList[g_sword2->_totalTemp], (uint8 *) params[0], sizeof(menu_object)); -	g_sword2->_totalTemp++; +	memcpy(&_vm->_tempList[_vm->_totalTemp], (uint8 *) params[0], sizeof(menu_object)); +	_vm->_totalTemp++;  	// script continue  	return IR_CONT; @@ -54,9 +54,9 @@ int32 Logic::fnRefreshInventory(int32 *params) {  	// so that the icon in 'object_held' is coloured while the rest are  	// grey -	g_sword2->_examiningMenuIcon = true; -	g_sword2->buildMenu(); -	g_sword2->_examiningMenuIcon = false; +	_vm->_examiningMenuIcon = true; +	_vm->buildMenu(); +	_vm->_examiningMenuIcon = false;  	// script continue  	return IR_CONT; diff --git a/sword2/layers.cpp b/sword2/layers.cpp index 3130825d18..7bbcd09bb5 100644 --- a/sword2/layers.cpp +++ b/sword2/layers.cpp @@ -44,7 +44,7 @@ int32 Logic::fnInitBackground(int32 *params) {  	// params:	0 res id of normal background layer - cannot be 0  	//		1 1 yes 0 no for a new palette -	return g_sword2->initBackground(params[0], params[1]); +	return _vm->initBackground(params[0], params[1]);  }  int32 Sword2Engine::initBackground(int32 res, int32 new_palette) { @@ -115,9 +115,9 @@ int32 Sword2Engine::initBackground(int32 res, int32 new_palette) {  			// need this for sorting - but leave the rest blank,  			// we'll take from the header at print time -			g_sword2->_sortList[i].sort_y = layer->y + layer->height; +			_sortList[i].sort_y = layer->y + layer->height;  			// signifies a layer -			g_sword2->_sortList[i].layer_number = i + 1; +			_sortList[i].layer_number = i + 1;  			debug(5, "init layer %d", i);  		} diff --git a/sword2/logic.cpp b/sword2/logic.cpp index 3dd94a7af6..0e39af8b72 100644 --- a/sword2/logic.cpp +++ b/sword2/logic.cpp @@ -185,7 +185,7 @@ int Logic::processSession(void) {  		// clear any syncs that were waiting for this character - it  		// has used them or now looses them -		Clear_syncs(ID); +		clearSyncs(ID);  		if (_pc != 0xffffffff) {  			// the session is still valid so run the service script @@ -232,16 +232,16 @@ void Logic::expressChangeSession(uint32 sesh_id) {  	// in theory sync waiting in the list could be left behind and never  	// removed - so we trash the lot -	Init_sync_system(); +	memset(_syncList, 0, sizeof(_syncList));  	// reset walkgrid list (see fnRegisterWalkGrid) -	router.clearWalkGridList(); +	_router->clearWalkGridList();  	// stops all fx & clears the queue -	g_sword2->clearFxQueue(); +	_vm->clearFxQueue();  	// free all the route memory blocks from previous game -	router.freeAllRouteMem(); +	_router->freeAllRouteMem();  }  /** diff --git a/sword2/logic.h b/sword2/logic.h index 8892329c9d..7d3e64bc5c 100644 --- a/sword2/logic.h +++ b/sword2/logic.h @@ -22,10 +22,13 @@  #ifndef _LOGIC  #define _LOGIC +#include "sword2/events.h"  #include "sword2/header.h"  #include "sword2/memory.h" +#include "sword2/router.h"  #include "sword2/speech.h"  #include "sword2/startup.h" +#include "sword2/sync.h"  #include "sword2/driver/driver96.h"  namespace Sword2 { @@ -37,8 +40,12 @@ namespace Sword2 {  #define MAX_SEQUENCE_TEXT_LINES 15 +class Sword2Engine; +  class Logic {  private: +	Sword2Engine *_vm; +  	// Point to the global variable data  	int32 *_globals; @@ -161,8 +168,15 @@ private:  	uint32 initStartMenu(void); +	int16 _standbyX;	// see fnSetStandbyCoords() +	int16 _standbyY; +	int16 _standbyDir; + +	int whatTarget(int startX, int startY, int destX, int destY); +  public: -	Logic() : _globals(NULL), _kills(0), _debugFlag(false), +	Logic(Sword2Engine *vm) : +		  _vm(vm), _globals(NULL), _kills(0), _debugFlag(false),  		  _smackerLeadOut(0), _sequenceTextLines(0), _speechTime(0),  		  _animId(0), _leftClickDelay(0), _rightClickDelay(0),  		  _defaultResponseId(0), _totalStartups(0), @@ -170,6 +184,9 @@ public:  		  _speechScriptWaiting(0), _speechTextBlocNo(0),  		  _choosing(false), _unpauseZone(0) {  		memset(_subjectList, 0, sizeof(_subjectList)); +		memset(_eventList, 0, sizeof(_eventList)); +		memset(_syncList, 0, sizeof(_syncList)); +		_router = new Router();  		setupOpcodes();  		initStartMenu();  	} @@ -202,6 +219,34 @@ public:  	int32 executeOpcode(int op, int32 *params); +	struct _event_unit { +		uint32 id; +		uint32 interact_id; +	}; + +	_event_unit _eventList[MAX_events]; + +	void sendEvent(uint32 id, uint32 interact_id); +	void setPlayerActionEvent(uint32 id, uint32 interact_id); +	void startEvent(void); +	bool checkEventWaiting(void); +	void clearEvent(uint32 id); +	void killAllIdsEvents(uint32 id); + +	uint32 countEvents(void); + +	struct _sync_unit { +		uint32 id; +		uint32 sync; +	}; + +	_sync_unit _syncList[MAX_syncs]; + +	void clearSyncs(uint32 id); +	bool getSync(void); + +	Router *_router; +  	int32 fnTestFunction(int32 *params);  	int32 fnTestFlags(int32 *params);  	int32 fnRegisterStartPoint(int32 *params); diff --git a/sword2/maketext.cpp b/sword2/maketext.cpp index 5ebb58eb62..a8466610ff 100644 --- a/sword2/maketext.cpp +++ b/sword2/maketext.cpp @@ -60,7 +60,7 @@  namespace Sword2 { -FontRenderer fontRenderer; +FontRenderer *fontRenderer;  // info for each line of words in the output text sprite diff --git a/sword2/maketext.h b/sword2/maketext.h index c0ca30383a..41d0151810 100644 --- a/sword2/maketext.h +++ b/sword2/maketext.h @@ -141,7 +141,7 @@ public:  	uint32 buildNewBloc(uint8 *ascii, int16 x, int16 y, uint16 width, uint8 pen, uint32 type, uint32 fontRes, uint8 justification);  }; -extern FontRenderer fontRenderer; +extern FontRenderer *fontRenderer;  } // End of namespace Sword2 diff --git a/sword2/mouse.cpp b/sword2/mouse.cpp index 7957c433b0..80f80e72a4 100644 --- a/sword2/mouse.cpp +++ b/sword2/mouse.cpp @@ -321,7 +321,7 @@ void Sword2Engine::dragMouse(void) {  			CLICKED_ID = _mouseTouching; -			setPlayerActionEvent(CUR_PLAYER_ID, _mouseTouching); +			g_logic->setPlayerActionEvent(CUR_PLAYER_ID, _mouseTouching);  			debug(5, "USED \"%s\" ICON ON %s", fetchObjectName(OBJECT_HELD), fetchObjectName(CLICKED_ID)); @@ -359,7 +359,7 @@ void Sword2Engine::dragMouse(void) {  						// we're dragging  						COMBINE_BASE = _masterMenuList[pos].icon_resource; -						setPlayerActionEvent(CUR_PLAYER_ID, MENU_MASTER_OBJECT); +						g_logic->setPlayerActionEvent(CUR_PLAYER_ID, MENU_MASTER_OBJECT);  						// turn off mouse now, to  						// prevent player trying to @@ -422,7 +422,7 @@ void Sword2Engine::menuMouse(void) {  					debug(5, "RIGHT-CLICKED ON \"%s\" ICON", fetchObjectName(OBJECT_HELD)); -					setPlayerActionEvent(CUR_PLAYER_ID, MENU_MASTER_OBJECT); +					g_logic->setPlayerActionEvent(CUR_PLAYER_ID, MENU_MASTER_OBJECT);  					// refresh the menu  					buildMenu(); @@ -626,7 +626,7 @@ void Sword2Engine::normalMouse(void) {  				EXIT_CLICK_ID = 0;  				EXIT_FADING = 0; -				setPlayerActionEvent(CUR_PLAYER_ID, _mouseTouching); +				g_logic->setPlayerActionEvent(CUR_PLAYER_ID, _mouseTouching);  				if (OBJECT_HELD)  					debug(5, "USED \"%s\" ICON ON %s", fetchObjectName(OBJECT_HELD), fetchObjectName(CLICKED_ID)); @@ -965,7 +965,7 @@ void Sword2Engine::createPointerText(uint32 text_id, uint32 pointer_res) {  			// 'text+2' to skip the first 2 bytes which form the  			// line reference number -			_pointerTextBlocNo = fontRenderer.buildNewBloc( +			_pointerTextBlocNo = fontRenderer->buildNewBloc(  				text + 2, g_display->_mouseX + xOffset,  				g_display->_mouseY + yOffset,  				POINTER_TEXT_WIDTH, POINTER_TEXT_PEN, @@ -980,7 +980,7 @@ void Sword2Engine::createPointerText(uint32 text_id, uint32 pointer_res) {  void Sword2Engine::clearPointerText(void) {  	if (_pointerTextBlocNo) { -		fontRenderer.killTextBloc(_pointerTextBlocNo); +		fontRenderer->killTextBloc(_pointerTextBlocNo);  		_pointerTextBlocNo = 0;  	}  } @@ -1055,8 +1055,8 @@ void Sword2Engine::monitorPlayerActivity(void) {  int32 Logic::fnNoHuman(int32 *params) {  	// params:	none -	g_sword2->noHuman(); -	g_sword2->clearPointerText(); +	_vm->noHuman(); +	_vm->clearPointerText();  	// must be normal mouse situation or a largely neutral situation -  	// special menus use noHuman @@ -1065,9 +1065,9 @@ int32 Logic::fnNoHuman(int32 *params) {  	if (TALK_FLAG == 0)  		g_display->hideMenu(RDMENU_BOTTOM); -	if (g_sword2->_mouseMode == MOUSE_system_menu) { +	if (_vm->_mouseMode == MOUSE_system_menu) {  		// close menu -		g_sword2->_mouseMode = MOUSE_normal; +		_vm->_mouseMode = MOUSE_normal;  		g_display->hideMenu(RDMENU_TOP);  	} @@ -1082,9 +1082,9 @@ int32 Logic::fnAddHuman(int32 *params) {  	MOUSE_AVAILABLE = 1;  	// off -	if (g_sword2->_mouseStatus) { -		g_sword2->_mouseStatus = false;	// on -		g_sword2->_mouseTouching = 1;	// forces engine to choose a cursor +	if (_vm->_mouseStatus) { +		_vm->_mouseStatus = false;	// on +		_vm->_mouseTouching = 1;	// forces engine to choose a cursor  	}  	//clear this to reset no-second-click system @@ -1096,7 +1096,7 @@ int32 Logic::fnAddHuman(int32 *params) {  	// unlock the mouse from possible large object lock situtations - see  	// syphon in rm 3 -	g_sword2->_mouseModeLocked = false; +	_vm->_mouseModeLocked = false;  	if (OBJECT_HELD) {  		// was dragging something around @@ -1104,26 +1104,26 @@ int32 Logic::fnAddHuman(int32 *params) {  		OBJECT_HELD = 0;  		// and these may also need clearing, just in case -		g_sword2->_examiningMenuIcon = false; +		_vm->_examiningMenuIcon = false;  		COMBINE_BASE = 0; -		g_sword2->setLuggage(0); +		_vm->setLuggage(0);  	}  	// if mouse is over menu area  	if (g_display->_mouseY > 399) { -		if (g_sword2->_mouseMode != MOUSE_holding) { +		if (_vm->_mouseMode != MOUSE_holding) {  			// VITAL - reset things & rebuild the menu -			g_sword2->_mouseMode = MOUSE_normal; -			g_sword2->setMouse(NORMAL_MOUSE_ID); +			_vm->_mouseMode = MOUSE_normal; +			_vm->setMouse(NORMAL_MOUSE_ID);  		} else -			g_sword2->setMouse(NORMAL_MOUSE_ID); +			_vm->setMouse(NORMAL_MOUSE_ID);  	}  	// enabled/disabled from console; status printed with on-screen debug  	// info -	if (g_sword2->_debugger->_testingSnR) { +	if (_vm->_debugger->_testingSnR) {  		uint8 black[4] = {   0,  0,    0,   0 };  		uint8 white[4] = { 255, 255, 255,   0 }; @@ -1135,7 +1135,7 @@ int32 Logic::fnAddHuman(int32 *params) {  		// stops all fx & clears the queue - eg. when leaving a  		// location -		g_sword2->clearFxQueue(); +		_vm->clearFxQueue();  		// Trash all object resources so they load in fresh & restart  		// their logic scripts @@ -1157,7 +1157,7 @@ int32 Logic::fnRegisterMouse(int32 *params) {  	// params:	0 pointer to Object_mouse or 0 for no write to mouse  	//		  list -	g_sword2->registerMouse((Object_mouse *) params[0]); +	_vm->registerMouse((Object_mouse *) params[0]);  	return IR_CONT;  } @@ -1168,13 +1168,13 @@ int32 Logic::fnRegisterMouse(int32 *params) {  int32 Logic::fnRegisterPointerText(int32 *params) {  	// params:	0 local id of text line to use as pointer text -	assert(g_sword2->_curMouse < TOTAL_mouse_list); +	assert(_vm->_curMouse < TOTAL_mouse_list);  	// current object id - used for checking pointer_text when mouse area  	// registered (in fnRegisterMouse and fnRegisterFrame) -	g_sword2->_mouseList[g_sword2->_curMouse].id = ID; -	g_sword2->_mouseList[g_sword2->_curMouse].pointer_text = params[0]; +	_vm->_mouseList[_vm->_curMouse].id = ID; +	_vm->_mouseList[_vm->_curMouse].pointer_text = params[0];  	return IR_CONT;  } @@ -1188,8 +1188,8 @@ int32 Logic::fnInitFloorMouse(int32 *params) {  	ob_mouse->x1 = 0;  	ob_mouse->y1 = 0; -	ob_mouse->x2 = g_sword2->_thisScreen.screen_wide - 1; -	ob_mouse->y2 = g_sword2->_thisScreen.screen_deep - 1; +	ob_mouse->x2 = _vm->_thisScreen.screen_wide - 1; +	ob_mouse->y2 = _vm->_thisScreen.screen_deep - 1;  	ob_mouse->priority = 9;  	ob_mouse->pointer = NORMAL_MOUSE_ID; @@ -1207,11 +1207,11 @@ int32 Logic::fnSetScrollLeftMouse(int32 *params) {  	ob_mouse->x1 = 0;  	ob_mouse->y1 = 0; -	ob_mouse->x2 = g_sword2->_thisScreen.scroll_offset_x + SCROLL_MOUSE_WIDTH; -	ob_mouse->y2 = g_sword2->_thisScreen.screen_deep - 1; +	ob_mouse->x2 = _vm->_thisScreen.scroll_offset_x + SCROLL_MOUSE_WIDTH; +	ob_mouse->y2 = _vm->_thisScreen.screen_deep - 1;  	ob_mouse->priority = 0; -	if (g_sword2->_thisScreen.scroll_offset_x > 0) { +	if (_vm->_thisScreen.scroll_offset_x > 0) {  		// not fully scrolled to the left  		ob_mouse->pointer = SCROLL_LEFT_MOUSE_ID;  	} else { @@ -1229,13 +1229,13 @@ int32 Logic::fnSetScrollRightMouse(int32 *params) {  	// Highest priority -	ob_mouse->x1 = g_sword2->_thisScreen.scroll_offset_x + g_display->_screenWide - SCROLL_MOUSE_WIDTH; +	ob_mouse->x1 = _vm->_thisScreen.scroll_offset_x + g_display->_screenWide - SCROLL_MOUSE_WIDTH;  	ob_mouse->y1 = 0; -	ob_mouse->x2 = g_sword2->_thisScreen.screen_wide - 1; -	ob_mouse->y2 = g_sword2->_thisScreen.screen_deep - 1; +	ob_mouse->x2 = _vm->_thisScreen.screen_wide - 1; +	ob_mouse->y2 = _vm->_thisScreen.screen_deep - 1;  	ob_mouse->priority = 0; -	if (g_sword2->_thisScreen.scroll_offset_x < g_sword2->_thisScreen.max_scroll_offset_x) { +	if (_vm->_thisScreen.scroll_offset_x < _vm->_thisScreen.max_scroll_offset_x) {  		// not fully scrolled to the right  		ob_mouse->pointer = SCROLL_RIGHT_MOUSE_ID;  	} else { @@ -1249,13 +1249,13 @@ int32 Logic::fnSetScrollRightMouse(int32 *params) {  int32 Logic::fnSetObjectHeld(int32 *params) {  	// params:	0 luggage icon to set -	g_sword2->setLuggage(params[0]); +	_vm->setLuggage(params[0]);  	OBJECT_HELD = params[0]; -	g_sword2->_currentLuggageResource = params[0]; +	_vm->_currentLuggageResource = params[0];  	// mode locked - no menu available -	g_sword2->_mouseModeLocked = true; +	_vm->_mouseModeLocked = true;  	return IR_CONT;  } @@ -1280,11 +1280,11 @@ int32 Logic::fnCheckPlayerActivity(int32 *params) {  	uint32 threshold = params[0] * 12;	// in game cycles  	// if the actual delay is at or above the given threshold -	if (g_sword2->_playerActivityDelay >= threshold) { +	if (_vm->_playerActivityDelay >= threshold) {  		// reset activity delay counter, now that we've got a  		// positive check -		g_sword2->_playerActivityDelay = 0; +		_vm->_playerActivityDelay = 0;  		RESULT = 1;  	} else  		RESULT = 0; @@ -1298,7 +1298,7 @@ int32 Logic::fnResetPlayerActivityDelay(int32 *params) {  	// params:	none -	g_sword2->_playerActivityDelay = 0; +	_vm->_playerActivityDelay = 0;  	return IR_CONT;  } diff --git a/sword2/resman.cpp b/sword2/resman.cpp index cec6bf1df7..8a47bf9d03 100644 --- a/sword2/resman.cpp +++ b/sword2/resman.cpp @@ -85,7 +85,9 @@ struct _cd_inf {  	#pragma END_PACK_STRUCTS  #endif -ResourceManager::ResourceManager(void) { +ResourceManager::ResourceManager(Sword2Engine *vm) { +	_vm = vm; +  	// We read in the resource info which tells us the names of the  	// resource cluster files ultimately, although there might be groups  	// within the clusters at this point it makes no difference. We only @@ -981,7 +983,7 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {  	g_logic->fnStopMusic(NULL); -	g_sword2->clearFxQueue();	// stops all fx & clears the queue (James22july97) +	_vm->clearFxQueue();	// stops all fx & clears the queue (James22july97)  	getCd(_cdTab[newCluster] & 3);  	// Kick out old cached cluster and load the new one. @@ -1027,19 +1029,19 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {  	g_display->clearScene(); -	g_sword2->setMouse(0); -	g_sword2->setLuggage(0); +	_vm->setMouse(0); +	_vm->setLuggage(0);  	uint8 *bgfile;  	bgfile = openResource(2950);	// open the screen resource  	g_display->initialiseBackgroundLayer(NULL);  	g_display->initialiseBackgroundLayer(NULL); -	g_display->initialiseBackgroundLayer(g_sword2->fetchBackgroundLayer(bgfile)); +	g_display->initialiseBackgroundLayer(_vm->fetchBackgroundLayer(bgfile));  	g_display->initialiseBackgroundLayer(NULL);  	g_display->initialiseBackgroundLayer(NULL); -	g_display->setPalette(0, 256, g_sword2->fetchPalette(bgfile), RDPAL_FADE); +	g_display->setPalette(0, 256, _vm->fetchPalette(bgfile), RDPAL_FADE); -	g_display->renderParallax(g_sword2->fetchBackgroundLayer(bgfile), 2); +	g_display->renderParallax(_vm->fetchBackgroundLayer(bgfile), 2);  	closeResource(2950);		// release the screen resource  	// Git rid of read-only status, if it is set. @@ -1061,7 +1063,7 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {  	uint8 *loadingBar;  	_cdtEntry *cdt; -	text_spr = fontRenderer.makeTextSprite(g_sword2->fetchTextLine(openResource(2283), 8) + 2, 640, 187, g_sword2->_speechFontId); +	text_spr = fontRenderer->makeTextSprite(_vm->fetchTextLine(openResource(2283), 8) + 2, 640, 187, _vm->_speechFontId);  	frame = (_frameHeader*) text_spr->ad; @@ -1080,8 +1082,8 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {  	loadingBar = openResource(2951); -	frame = g_sword2->fetchFrameHeader(loadingBar, 0); -	cdt   = g_sword2->fetchCdtEntry(loadingBar, 0); +	frame = _vm->fetchFrameHeader(loadingBar, 0); +	cdt   = _vm->fetchCdtEntry(loadingBar, 0);  	barSprite.x = cdt->x;  	barSprite.y = cdt->y; @@ -1097,7 +1099,7 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {  	closeResource(2951);  	loadingBar = openResource(2951); -	frame = g_sword2->fetchFrameHeader(loadingBar, 0); +	frame = _vm->fetchFrameHeader(loadingBar, 0);  	barSprite.data = (uint8 *) (frame + 1);  	closeResource(2951); @@ -1138,11 +1140,11 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {  			step = 0;  			// open the screen resource  			bgfile = openResource(2950); -			g_display->renderParallax(g_sword2->fetchBackgroundLayer(bgfile), 2); +			g_display->renderParallax(_vm->fetchBackgroundLayer(bgfile), 2);  			// release the screen resource  			closeResource(2950);  			loadingBar = openResource(2951); -			frame = g_sword2->fetchFrameHeader(loadingBar, fr); +			frame = _vm->fetchFrameHeader(loadingBar, fr);  			barSprite.data = (uint8 *) (frame + 1);  			closeResource(2951);  			g_display->drawSprite(&barSprite); @@ -1222,7 +1224,7 @@ void ResourceManager::getCd(int cd) {  	// don't ask for CD's in the playable demo downloaded from our  	// web-site! -	if (g_sword2->_features & GF_DEMO) +	if (_vm->_features & GF_DEMO)  		return;  #ifdef _PCGUIDE @@ -1285,8 +1287,8 @@ void ResourceManager::getCd(int cd) {  	g_logic->fnStopMusic(NULL);  	textRes = openResource(2283); -	g_sword2->displayMsg(g_sword2->fetchTextLine(textRes, 5 + cd) + 2, 0); -	text_spr = fontRenderer.makeTextSprite(g_sword2->fetchTextLine(textRes, 5 + cd) + 2, 640, 187, g_sword2->_speechFontId); +	_vm->displayMsg(_vm->fetchTextLine(textRes, 5 + cd) + 2, 0); +	text_spr = fontRenderer->makeTextSprite(_vm->fetchTextLine(textRes, 5 + cd) + 2, 640, 187, _vm->_speechFontId);  	frame = (_frameHeader*) text_spr->ad; @@ -1338,7 +1340,7 @@ void ResourceManager::getCd(int cd) {  	} while (!done);  	memory->freeMemory(text_spr); -	g_sword2->removeMsg(); +	_vm->removeMsg();  }  } // End of namespace Sword2 diff --git a/sword2/resman.h b/sword2/resman.h index 510f22ba5b..85d334e644 100644 --- a/sword2/resman.h +++ b/sword2/resman.h @@ -26,9 +26,11 @@ namespace Sword2 {  #define	MAX_res_files	20 +class Sword2Engine; +  class ResourceManager {  public: -	ResourceManager(void);		// read in the config file +	ResourceManager(Sword2Engine *vm);	// read in the config file  	~ResourceManager(void);  	// Returns ad of resource. Loads if not in memory. Retains a count. @@ -77,6 +79,8 @@ public:  	mem **_resList;  private: +	Sword2Engine *_vm; +  	int _curCd;  	uint32 _totalResFiles;  	uint32 _totalClusters; diff --git a/sword2/router.cpp b/sword2/router.cpp index d15b590587..9be82d80ff 100644 --- a/sword2/router.cpp +++ b/sword2/router.cpp @@ -88,8 +88,6 @@  namespace Sword2 { -Router router; -  uint8 Router::returnSlotNo(uint32 megaId) {  	if (ID == CUR_PLAYER_ID) {  		// George (8) diff --git a/sword2/router.h b/sword2/router.h index 87e3dbcc75..f75d82bdba 100644 --- a/sword2/router.h +++ b/sword2/router.h @@ -216,7 +216,24 @@ private:  public:  	Router() :  		_nExtraBars(0), _nExtraNodes(0), _diagonalx(0), -		_diagonaly(0) {} +		_diagonaly(0) { +		memset(_routeSlots, 0, sizeof(_routeSlots)); +		memset(_bars, 0, sizeof(_bars)); +		memset(_node, 0, sizeof(_node)); +		memset(_walkGridList, 0, sizeof(_walkGridList)); +		memset(_extraBars, 0, sizeof(_extraBars)); +		memset(_extraNode, 0, sizeof(_extraNode)); +		memset(_route, 0, sizeof(_route)); +		memset(_smoothPath, 0, sizeof(_smoothPath)); +		memset(_modularPath, 0, sizeof(_modularPath)); +		memset(_dx, 0, sizeof(_dx)); +		memset(_dy, 0, sizeof(_dy)); +		memset(_modX, 0, sizeof(_modX)); +		memset(_modY, 0, sizeof(_modY)); +		memset(_firstSlowInFrame, 0, sizeof(_firstSlowInFrame)); +		memset(_numberOfSlowInFrames, 0, sizeof(_numberOfSlowInFrames)); +		memset(_leadingLeg, 0, sizeof(_leadingLeg)); +	}  	int32 routeFinder(Object_mega *ob_mega, Object_walkdata *ob_walkdata, int32 x, int32 y, int32 dir); @@ -234,8 +251,6 @@ public:  	void plotWalkGrid(void);  }; -extern Router router; -  } // End of namespace Sword2  #endif diff --git a/sword2/save_rest.cpp b/sword2/save_rest.cpp index 169d5af1a9..9760658bc8 100644 --- a/sword2/save_rest.cpp +++ b/sword2/save_rest.cpp @@ -560,9 +560,9 @@ int32 Logic::fnPassPlayerSaveData(int32 *params) {  	// copy from player object to savegame header -	memcpy(&g_sword2->g_header.logic, (uint8 *) params[0], sizeof(Object_logic)); -	memcpy(&g_sword2->g_header.graphic, (uint8 *) params[1], sizeof(Object_graphic)); -	memcpy(&g_sword2->g_header.mega, (uint8 *) params[2], sizeof(Object_mega)); +	memcpy(&_vm->g_header.logic, (uint8 *) params[0], sizeof(Object_logic)); +	memcpy(&_vm->g_header.graphic, (uint8 *) params[1], sizeof(Object_graphic)); +	memcpy(&_vm->g_header.mega, (uint8 *) params[2], sizeof(Object_mega));  	// makes no odds  	return IR_CONT; @@ -584,9 +584,9 @@ int32 Logic::fnGetPlayerSaveData(int32 *params) {  	// copy from savegame header to player object -	memcpy((uint8 *) ob_logic, &g_sword2->g_header.logic, sizeof(Object_logic)); -	memcpy((uint8 *) ob_graphic, &g_sword2->g_header.graphic, sizeof(Object_graphic)); -	memcpy((uint8 *) ob_mega, &g_sword2->g_header.mega, sizeof(Object_mega)); +	memcpy((uint8 *) ob_logic, &_vm->g_header.logic, sizeof(Object_logic)); +	memcpy((uint8 *) ob_graphic, &_vm->g_header.graphic, sizeof(Object_graphic)); +	memcpy((uint8 *) ob_mega, &_vm->g_header.mega, sizeof(Object_mega));   	// any walk-data must be cleared - the player will be set to stand if  	// he was walking when saved diff --git a/sword2/scroll.cpp b/sword2/scroll.cpp index ec64ca2361..1c64d08057 100644 --- a/sword2/scroll.cpp +++ b/sword2/scroll.cpp @@ -162,22 +162,22 @@ int32 Logic::fnSetScrollCoordinate(int32 *params) {  	// params:	0 feet_x value  	// 		1 feet_y value -	g_sword2->_thisScreen.feet_x = params[0]; -	g_sword2->_thisScreen.feet_y = params[1]; +	_vm->_thisScreen.feet_x = params[0]; +	_vm->_thisScreen.feet_y = params[1];  	return IR_CONT;  }  int32 Logic::fnSetScrollSpeedNormal(int32 *params) {  	// params:	none -	g_sword2->_scrollFraction = 16; +	_vm->_scrollFraction = 16;  	return IR_CONT;  }  int32 Logic::fnSetScrollSpeedSlow(int32 *params) {  	// params:	none -	g_sword2->_scrollFraction = 32; +	_vm->_scrollFraction = 32;  	return IR_CONT;  } diff --git a/sword2/sound.cpp b/sword2/sound.cpp index a1437d4191..d21671622f 100644 --- a/sword2/sound.cpp +++ b/sword2/sound.cpp @@ -168,10 +168,10 @@ int32 Logic::fnPlayFx(int32 *params) {  	_standardHeader *header;  #endif -	if (g_sword2->_wantSfxDebug) { +	if (_vm->_wantSfxDebug) {  		char type[10]; -		switch (params[1]) {	// 'type' +		switch (params[1]) {  		case FX_SPOT:  			strcpy(type, "SPOT");  			break; @@ -185,34 +185,34 @@ int32 Logic::fnPlayFx(int32 *params) {  			strcpy(type, "INVALID");  		} -		debug(0, "SFX (sample=\"%s\", vol=%d, pan=%d, delay=%d, type=%s)", g_sword2->fetchObjectName(params[0]), params[3], params[4], params[2], type); +		debug(0, "SFX (sample=\"%s\", vol=%d, pan=%d, delay=%d, type=%s)", _vm->fetchObjectName(params[0]), params[3], params[4], params[2], type);  	} -	while (j < FXQ_LENGTH && g_sword2->_fxQueue[j].resource != 0) +	while (j < FXQ_LENGTH && _vm->_fxQueue[j].resource != 0)  		j++;  	if (j == FXQ_LENGTH)  		return IR_CONT; -	g_sword2->_fxQueue[j].resource	= params[0];	// wav resource id -	g_sword2->_fxQueue[j].type = params[1];	// FX_SPOT, FX_LOOP or FX_RANDOM +	_vm->_fxQueue[j].resource = params[0];	// wav resource id +	_vm->_fxQueue[j].type = params[1];	// FX_SPOT, FX_LOOP or FX_RANDOM -	if (g_sword2->_fxQueue[j].type == FX_RANDOM) { +	if (_vm->_fxQueue[j].type == FX_RANDOM) {  		// 'delay' param is the intended average no. seconds between  		// playing this effect -		g_sword2->_fxQueue[j].delay = params[2] * 12; +		_vm->_fxQueue[j].delay = params[2] * 12;  	} else {  		// FX_SPOT or FX_LOOP:  		//  'delay' is no. frames to wait before playing -		g_sword2->_fxQueue[j].delay = params[2]; +		_vm->_fxQueue[j].delay = params[2];  	} -	g_sword2->_fxQueue[j].volume = params[3];	// 0..16 -	g_sword2->_fxQueue[j].pan = params[4];		// -16..16 +	_vm->_fxQueue[j].volume = params[3];	// 0..16 +	_vm->_fxQueue[j].pan = params[4];	// -16..16 -	if (g_sword2->_fxQueue[j].type == FX_SPOT) { +	if (_vm->_fxQueue[j].type == FX_SPOT) {  		// "pre-load" the sample; this gets it into memory -		data = res_man->openResource(g_sword2->_fxQueue[j].resource); +		data = res_man->openResource(_vm->_fxQueue[j].resource);  #ifdef _SWORD2_DEBUG  		header = (_standardHeader*) data; @@ -221,14 +221,14 @@ int32 Logic::fnPlayFx(int32 *params) {  #endif  		// but then releases it to "age" out if the space is needed -		res_man->closeResource(g_sword2->_fxQueue[j].resource); +		res_man->closeResource(_vm->_fxQueue[j].resource);  	} else {  		// random & looped fx  		id = (uint32) j + 1;	// because 0 is not a valid id  		// load in the sample -		data = res_man->openResource(g_sword2->_fxQueue[j].resource); +		data = res_man->openResource(_vm->_fxQueue[j].resource);  #ifdef _SWORD2_DEBUG  		header = (_standardHeader*)data; @@ -245,13 +245,13 @@ int32 Logic::fnPlayFx(int32 *params) {  			debug(5, "SFX ERROR: openFx() returned %.8x", rv);  		// release the sample -		res_man->closeResource(g_sword2->_fxQueue[j].resource); +		res_man->closeResource(_vm->_fxQueue[j].resource);  	} -	if (g_sword2->_fxQueue[j].type == FX_LOOP) { +	if (_vm->_fxQueue[j].type == FX_LOOP) {  		// play now, rather than in Process_fx_queue where it was  		// getting played again & again! -		g_sword2->triggerFx(j); +		_vm->triggerFx(j);  	}  	// in case we want to call fnStopFx() later, to kill this fx @@ -307,7 +307,7 @@ int32 Logic::fnStopFx(int32 *params) {  	uint32 id;  	uint32 rv; -	if (g_sword2->_fxQueue[j].type == FX_RANDOM || g_sword2->_fxQueue[j].type == FX_LOOP) { +	if (_vm->_fxQueue[j].type == FX_RANDOM || _vm->_fxQueue[j].type == FX_LOOP) {  		id = (uint32) j + 1;		// because 0 is not a valid id  		// stop fx & remove sample from sound memory @@ -318,7 +318,7 @@ int32 Logic::fnStopFx(int32 *params) {  	}  	// remove from queue -	g_sword2->_fxQueue[j].resource = 0; +	_vm->_fxQueue[j].resource = 0;  	return IR_CONT;  } @@ -330,7 +330,7 @@ int32 Logic::fnStopAllFx(int32 *params) {  	// params:	none -	g_sword2->clearFxQueue(); +	_vm->clearFxQueue();  	return IR_CONT;  } @@ -355,18 +355,18 @@ int32 Logic::fnPlayMusic(int32 *params) {  		// keep a note of the id, for restarting after an  		// interruption to gameplay -		g_sword2->_loopingMusicId = params[0]; +		_vm->_loopingMusicId = params[0];  	} else {   		loopFlag = false;  		// don't need to restart this tune after control panel or  		// restore -		g_sword2->_loopingMusicId = 0; +		_vm->_loopingMusicId = 0;  	}  	// add the appropriate file extension & play it -	if (g_sword2->_features & GF_DEMO) { +	if (_vm->_features & GF_DEMO) {  		// The demo I found didn't come with any music file, but you  		// could use the music from the first CD of the complete game,  		// I suppose... @@ -394,7 +394,7 @@ int32 Logic::fnPlayMusic(int32 *params) {  int32 Logic::fnStopMusic(int32 *params) {  	// params:	none -	g_sword2->_loopingMusicId = 0;		// clear the 'looping' flag +	_vm->_loopingMusicId = 0;		// clear the 'looping' flag  	g_sound->stopMusic();  	return IR_CONT;  } diff --git a/sword2/speech.cpp b/sword2/speech.cpp index 42d68f5226..e3a5f17697 100644 --- a/sword2/speech.cpp +++ b/sword2/speech.cpp @@ -189,7 +189,7 @@ int32 Logic::fnChoose(int32 *params) {  		g_display->showMenu(RDMENU_BOTTOM);  		// lets have the mouse pointer back -		g_sword2->setMouse(NORMAL_MOUSE_ID); +		_vm->setMouse(NORMAL_MOUSE_ID);  		_choosing = true; @@ -219,7 +219,7 @@ int32 Logic::fnChoose(int32 *params) {  					// change icons  					for (j = 0; j < IN_SUBJECT; j++) { -						debug(5, "%s", g_sword2->fetchObjectName(_subjectList[j].res)); +						debug(5, "%s", _vm->fetchObjectName(_subjectList[j].res));  						// change all others to grey  						if (j != hit) { @@ -230,7 +230,7 @@ int32 Logic::fnChoose(int32 *params) {  					} -					debug(5, "Selected: %s", g_sword2->fetchObjectName(_subjectList[hit].res)); +					debug(5, "Selected: %s", _vm->fetchObjectName(_subjectList[hit].res));  					// this is our looping flag  					_choosing = false; @@ -238,7 +238,7 @@ int32 Logic::fnChoose(int32 *params) {  					IN_SUBJECT = 0;  					// blank mouse again -					g_sword2->setMouse(0); +					_vm->setMouse(0);  					debug(5, "hit %d - ref %d  ref*8 %d", hit, _subjectList[hit].ref, _subjectList[hit].ref * 8); @@ -287,7 +287,7 @@ int32 Logic::fnEndConversation(int32 *params) {  	if (g_display->_mouseY > 399) {  		// will wait for cursor to move off the bottom menu -		g_sword2->_mouseMode = MOUSE_holding; +		_vm->_mouseMode = MOUSE_holding;  		debug(5, "   holding");  	} @@ -543,7 +543,7 @@ int32 Logic::fnTimedWait(int32 *params) {  		// clear the event that hasn't been picked up - in theory,  		// none of this should ever happen -		g_sword2->killAllIdsEvents(target); +		killAllIdsEvents(target);  		debug(5, "EVENT timed out"); @@ -931,7 +931,7 @@ int32 Logic::fnISpeak(int32 *params) {  		} else  			cycle_skip = 0; -		g_sword2->_debugger->_textNumber = params[S_TEXT];	// for debug info +		_vm->_debugger->_textNumber = params[S_TEXT];	// for debug info  		// For testing all text & speech!  		// A script loop can send any text number to fnISpeak and it @@ -958,7 +958,7 @@ int32 Logic::fnISpeak(int32 *params) {  				if (head->fileType == TEXT_FILE) {  					// if it's not an animation file  					// if line number is out of range -					if (g_sword2->checkTextLine((uint8*) head, local_text) == 0) { +					if (_vm->checkTextLine((uint8*) head, local_text) == 0) {  						// line number out of range  						RESULT = 2;  					} @@ -988,7 +988,7 @@ int32 Logic::fnISpeak(int32 *params) {  		local_text = params[S_TEXT] & 0xffff;  		// open text file & get the line -		text = g_sword2->fetchTextLine(res_man->openResource(text_res), local_text); +		text = _vm->fetchTextLine(res_man->openResource(text_res), local_text);  		_officialTextNumber = READ_LE_UINT16(text);  		// now ok to close the text file @@ -1023,7 +1023,7 @@ int32 Logic::fnISpeak(int32 *params) {  		if (PLAYER_ID != CUR_PLAYER_ID)  			debug(5, "(%d) Nico: %s", _officialTextNumber, text + 2);  		else -			debug(5, "(%d) %s: %s", _officialTextNumber, g_sword2->fetchObjectName(ID), text + 2); +			debug(5, "(%d) %s: %s", _officialTextNumber, _vm->fetchObjectName(ID), text + 2);  		// Set up the speech animation @@ -1171,7 +1171,7 @@ int32 Logic::fnISpeak(int32 *params) {  		// open the anim file  		anim_file = res_man->openResource(ob_graphic->anim_resource); -		anim_head = g_sword2->fetchAnimHeader(anim_file); +		anim_head = _vm->fetchAnimHeader(anim_file);  		if (!_speechAnimType) {  			// ANIM IS TO BE LIP-SYNC'ED & REPEATING @@ -1284,7 +1284,7 @@ int32 Logic::fnISpeak(int32 *params) {  		// if there is text  		if (_speechTextBlocNo) {  			// kill the text block -			fontRenderer.killTextBloc(_speechTextBlocNo); +			fontRenderer->killTextBloc(_speechTextBlocNo);  			_speechTextBlocNo = 0;  		} @@ -1302,7 +1302,7 @@ int32 Logic::fnISpeak(int32 *params) {  		ob_logic->looping = 0;  		// reset for debug info -		g_sword2->_debugger->_textNumber = 0; +		_vm->_debugger->_textNumber = 0;  		// reset to zero, in case text line not even extracted (since  		// this number comes from the text line) @@ -1364,13 +1364,13 @@ void Logic::locateTalker(int32 *params) {  		// open animation file & set up the necessary pointers  		file = res_man->openResource(_animId); -		anim_head = g_sword2->fetchAnimHeader(file); +		anim_head = _vm->fetchAnimHeader(file);  		// '0' means 1st frame -		cdt_entry = g_sword2->fetchCdtEntry(file, 0); +		cdt_entry = _vm->fetchCdtEntry(file, 0);  		// '0' means 1st frame -		frame_head = g_sword2->fetchFrameHeader(file, 0); +		frame_head = _vm->fetchFrameHeader(file, 0);  		// check if this frame has offsets ie. this is a scalable  		// mega frame @@ -1410,8 +1410,8 @@ void Logic::locateTalker(int32 *params) {  		// adjust the text coords for RDSPR_DISPLAYALIGN -		_textX -= g_sword2->_thisScreen.scroll_offset_x; -		_textY -= g_sword2->_thisScreen.scroll_offset_y; +		_textX -= _vm->_thisScreen.scroll_offset_x; +		_textY -= _vm->_thisScreen.scroll_offset_y;  		// release the anim resource  		res_man->closeResource(_animId); @@ -1468,16 +1468,16 @@ void Logic::formText(int32 *params) {  		local_text = params[S_TEXT] & 0xffff;  		// open text file & get the line -		text = g_sword2->fetchTextLine(res_man->openResource(text_res), local_text); +		text = _vm->fetchTextLine(res_man->openResource(text_res), local_text);  		// 'text + 2' to skip the first 2 bytes which form the line  		// reference number -		_speechTextBlocNo = fontRenderer.buildNewBloc( +		_speechTextBlocNo = fontRenderer->buildNewBloc(  			text + 2, _textX, _textY,  			textWidth, ob_speech->pen,  			RDSPR_TRANS | RDSPR_DISPLAYALIGN, -			g_sword2->_speechFontId, POSITION_AT_CENTRE_OF_BASE); +			_vm->_speechFontId, POSITION_AT_CENTRE_OF_BASE);  		// now ok to close the text file  		res_man->closeResource(text_res); diff --git a/sword2/startup.cpp b/sword2/startup.cpp index 19cb2838dd..0ec0768911 100644 --- a/sword2/startup.cpp +++ b/sword2/startup.cpp @@ -63,7 +63,7 @@ uint32 Logic::initStartMenu(void) {  	debug(5, "initialising start menu"); -	if (!(end = Read_file("startup.inf", &temp, UID_temp))) { +	if (!(end = _vm->readFile("startup.inf", &temp, UID_temp))) {  		debug(5, "Init_start_menu cannot open startup.inf");  		return 0;	// meaning no start menu available  	} @@ -191,7 +191,7 @@ void Logic::conStart(int start) {  		// restarting - stop sfx, music & speech! -		g_sword2->clearFxQueue(); +		_vm->clearFxQueue();  		// fade out any music that is currently playing  		fnStopMusic(NULL); @@ -214,11 +214,11 @@ void Logic::conStart(int start) {  		res_man->closeResource(1);  		// free all the route memory blocks from previous game -		router.freeAllRouteMem(); +		g_logic->_router->freeAllRouteMem();  		// if there was speech text, kill the text block  		if (_speechTextBlocNo) { -			fontRenderer.killTextBloc(_speechTextBlocNo); +			fontRenderer->killTextBloc(_speechTextBlocNo);  			_speechTextBlocNo = 0;  		} diff --git a/sword2/sword2.cpp b/sword2/sword2.cpp index d3909b8024..20fcad672b 100644 --- a/sword2/sword2.cpp +++ b/sword2/sword2.cpp @@ -75,7 +75,7 @@ GameList Engine_SWORD2_detectGames(const FSList &fslist) {  	const GameSettings *g;  	// TODO: It would be nice if we had code here which distinguishes between -	// the 'sword2' and Ôsword2demoÔ targets. The current code can't do that +	// the 'sword2' and 'sword2demo' targets. The current code can't do that  	// since they use the same detectname.  	for (g = sword2_settings; g->gameName; ++g) { @@ -101,12 +101,6 @@ REGISTER_PLUGIN("Broken Sword II", Engine_SWORD2_gameList, Engine_SWORD2_create,  namespace Sword2 { -uint8 quitGame = 0; - -uint8 gamePaused = 0; -uint8 graphics_level_fudged = 0; -uint8 stepOneCycle = 0;			// for use while game paused -  Sword2Engine *g_sword2 = NULL;  Sound *g_sound = NULL;  Display *g_display = NULL; @@ -137,12 +131,12 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst)  	// away  	memory = new MemoryManager(); -	res_man = new ResourceManager(); -	g_logic = new Logic(); +	res_man = new ResourceManager(this); +	g_logic = new Logic(this); +	fontRenderer = new FontRenderer(); +	gui = new Gui(this);  	g_sound = _sound = new Sound(_mixer);  	g_display = _display = new Display(640, 480); -	gui = new Gui(); -  	_debugger = new Debugger(this);  	_lastPaletteRes = 0; @@ -189,14 +183,19 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst)  	// used to be a define, but now it's flexible  	_scrollFraction = 16; + +	_gamePaused = false; +	_stepOneCycle = false; +	_graphicsLevelFudged = false;  }  Sword2Engine::~Sword2Engine() {  	free(_targetName); -	delete _sound; -	delete _display;  	delete _debugger; +	delete _display; +	delete _sound;  	delete gui; +	delete fontRenderer;  	delete g_logic;  	delete res_man;  	delete memory; @@ -243,12 +242,6 @@ int32 Sword2Engine::InitialiseGame(void) {  	debug(5, "CALLING: initialiseFontResourceFlags");  	initialiseFontResourceFlags(); -	debug(5, "CALLING: Init_sync_system"); -	Init_sync_system(); - -	debug(5, "CALLING: Init_event_system"); -	initEventSystem(); -	  	// initialise the sound fx queue  	debug(5, "CALLING: Init_fx_queue"); @@ -263,16 +256,13 @@ int32 Sword2Engine::InitialiseGame(void) {  	return 0;  } -void Close_game() { -	debug(5, "Close_game() STARTING:"); - +void Sword2Engine::closeGame(void) {  	// Stop music instantly! -	g_sword2->killMusic(); - +	killMusic();  	g_system->quit();  } -int32 GameCycle(void) { +void Sword2Engine::gameCycle(void) {  	// do one game cycle  	// got a screen to run? @@ -281,34 +271,29 @@ int32 GameCycle(void) {  		do {  			// reset the graphic 'buildit' list before a new  			// logic list (see fnRegisterFrame) -			g_sword2->resetRenderLists(); +			resetRenderLists();  			// reset the mouse hot-spot list (see fnRegisterMouse  			// and fnRegisterFrame) -			g_sword2->resetMouseList(); +			resetMouseList();  			// keep going as long as new lists keep getting put in  			// - i.e. screen changes  		} while (g_logic->processSession());  	} else {  		// start the console and print the start options perhaps? -		g_sword2->_debugger->attach("AWAITING START COMMAND: (Enter 's 1' then 'q' to start from beginning)"); +		_debugger->attach("AWAITING START COMMAND: (Enter 's 1' then 'q' to start from beginning)");  	}  	// if this screen is wide, recompute the scroll offsets every cycle -	if (g_sword2->_thisScreen.scroll_flag) -		g_sword2->setScrolling(); +	if (_thisScreen.scroll_flag) +		setScrolling(); -	g_sword2->mouseEngine(); -	g_sword2->processFxQueue(); +	mouseEngine(); +	processFxQueue();  	// update age and calculate previous cycle memory usage  	res_man->nextCycle(); - -	if (quitGame) -		return 1; - -	return 0;  }  void Sword2Engine::go() { @@ -327,7 +312,7 @@ void Sword2Engine::go() {  	debug(5, "CALLING: InitialiseGame");  	if (InitialiseGame()) { -		Close_game(); +		closeGame();  		return;  	} @@ -337,10 +322,10 @@ void Sword2Engine::go() {  		else { // show restore menu  			setMouse(NORMAL_MOUSE_ID);  			if (!gui->restoreControl()) -				Start_game(); +				startGame();  		}  	} else -		Start_game(); +		startGame();  	debug(5, "CALLING: initialiseRenderCycle");  	g_display->initialiseRenderCycle(); @@ -370,9 +355,9 @@ void Sword2Engine::go() {  		// if we've just stepped forward one cycle while the  		// game was paused -		if (stepOneCycle) { -			PauseGame(); -			stepOneCycle = 0; +		if (_stepOneCycle) { +			pauseGame(); +			_stepOneCycle = false;  		}  #endif @@ -390,10 +375,10 @@ void Sword2Engine::go() {  			if (c == '~' || c == '#')  				_debugger->attach(); -			if (gamePaused) {	// if currently paused +			if (_gamePaused) {	// if currently paused  				if (c == 'P') {  					// 'P' while paused = unpause! -					UnpauseGame(); +					unpauseGame();  				}  #ifdef _SWORD2_DEBUG  				// frame-skipping only allowed on @@ -402,13 +387,13 @@ void Sword2Engine::go() {  				else if (c == ' ') {  					// SPACE bar while paused =  					// step one frame! -					stepOneCycle = 1; -					UnpauseGame(); +					_stepOneCycle = true; +					unpauseGame();  				}  #endif  			} else if (c == 'P') {  				// 'P' while not paused = pause! -				PauseGame(); +				pauseGame();  			} else if (c == 'C' && !(_features & GF_DEMO)) {  				g_logic->fnPlayCredits(NULL);  			} @@ -422,15 +407,11 @@ void Sword2Engine::go() {  		}  		// skip GameCycle if we're paused -		if (gamePaused == 0) { +		if (!_gamePaused) {  #ifdef _SWORD2_DEBUG  			_gameCycle++;  #endif - -			if (GameCycle()) { -				// break out of main game loop -				break; -			} +			gameCycle();  		}  		// creates the debug text blocks @@ -441,24 +422,22 @@ void Sword2Engine::go() {  		// display once every 4 game-cycles  		if (console_status || !_renderSkip || (_gameCycle % 4) == 0) -			g_sword2->buildDisplay();	// create and flip the screen +			buildDisplay();	// create and flip the screen  #else  		// create and flip the screen -		g_sword2->buildDisplay(); +		buildDisplay();  #endif  	} -	Close_game();		//close engine systems down - -	return;			//quit the game +	closeGame();		// close engine systems down  } -void Sword2Engine::Start_game(void) { +void Sword2Engine::startGame(void) {  	// boot the game straight into a start script  	int screen_manager_id; -	debug(5, "Start_game() STARTING:"); +	debug(5, "startGame() STARTING:");  	// all demos not just web  	if (_features & GF_DEMO) @@ -495,14 +474,14 @@ void Sword2Engine::Start_game(void) {  	// close george  	res_man->closeResource(8); -	debug(5, "Start_game() DONE."); +	debug(5, "startGame() DONE.");  }  // FIXME: Move this to some better place? -void sleepUntil(int32 time) { +void Sword2Engine::sleepUntil(int32 time) {  	while ((int32) SVM_timeGetTime() < time) { -		g_sword2->parseEvents(); +		parseEvents();  		// Make sure menu animations and fades don't suffer  		g_display->processMenu(); @@ -512,7 +491,7 @@ void sleepUntil(int32 time) {  	}  } -void PauseGame(void) { +void Sword2Engine::pauseGame(void) {  	// uint8 *text;  	// open text file & get the line "PAUSED" @@ -525,10 +504,10 @@ void PauseGame(void) {  	if (g_display->getFadeStatus() != RDFADE_NONE)  		return; -	g_sword2->pauseAllSound(); +	pauseAllSound();  	// make a normal mouse -	g_sword2->clearPointerText(); +	clearPointerText();  	// mouse_mode=MOUSE_normal; @@ -536,52 +515,52 @@ void PauseGame(void) {  	g_display->setLuggageAnim(NULL, 0);  	// blank cursor -	g_sword2->setMouse(0); +	setMouse(0);  	// forces engine to choose a cursor -	g_sword2->_mouseTouching = 1; +	_mouseTouching = 1;  	// if level at max, turn down because palette-matching won't work  	// when dimmed  	if (gui->_currentGraphicsLevel == 3) {  		gui->updateGraphicsLevel(2); -		graphics_level_fudged = 1; +		_graphicsLevelFudged = true;  	}  	// don't dim it if we're single-stepping through frames  	// dim the palette during the pause -	if (stepOneCycle == 0) +	if (!_stepOneCycle)  		g_display->dimPalette(); -	gamePaused = 1; +	_gamePaused = true;  } -void UnpauseGame(void) { +void Sword2Engine::unpauseGame(void) {  	// removed "PAUSED" from screen  	// Kill_text_bloc(pause_text_bloc_no); -	if (OBJECT_HELD && g_sword2->_realLuggageItem) -		g_sword2->setLuggage(g_sword2->_realLuggageItem); +	if (OBJECT_HELD && _realLuggageItem) +		setLuggage(_realLuggageItem); -	g_sword2->unpauseAllSound(); +	unpauseAllSound();  	// put back game screen palette; see Build_display.cpp -	g_sword2->setFullPalette(0xffffffff); +	setFullPalette(0xffffffff);  	// If graphics level at max, turn up again - 	if (graphics_level_fudged) { + 	if (_graphicsLevelFudged) {  		gui->updateGraphicsLevel(3); -		graphics_level_fudged = 0; +		_graphicsLevelFudged = false;  	} -	gamePaused = 0; +	_gamePaused = false;  	g_logic->_unpauseZone = 2;  	// if mouse is about or we're in a chooser menu -	if (!g_sword2->_mouseStatus || g_logic->_choosing) -		g_sword2->setMouse(NORMAL_MOUSE_ID); +	if (!_mouseStatus || g_logic->_choosing) +		setMouse(NORMAL_MOUSE_ID);  }  } // End of namespace Sword2 diff --git a/sword2/sword2.h b/sword2/sword2.h index 8abc60d0c7..9d218ffb02 100644 --- a/sword2/sword2.h +++ b/sword2/sword2.h @@ -55,13 +55,6 @@ namespace Sword2 {  #define	CD2_LABEL		"RBSII2" -void Close_game(); - -void PauseGame(void); -void UnpauseGame(void); - -void sleepUntil(int32 time); -  // TODO move stuff into class  class Sword2Engine : public Engine { @@ -140,12 +133,14 @@ private:  	uint32 calcChecksum(uint8 *buffer, uint32 size); +	void pauseGame(void); +	void unpauseGame(void); +  public:  	Sword2Engine(GameDetector *detector, OSystem *syst);  	~Sword2Engine();  	void go(void);  	void parseEvents(void); -	void Start_game(void);  	int32 InitialiseGame(void);  	GameDetector *_detector;  	uint32 _features; @@ -202,18 +197,6 @@ public:  	int32 initBackground(int32 res, int32 new_palette); -	_event_unit _eventList[MAX_events]; - -	void initEventSystem(void); -	void sendEvent(uint32 id, uint32 interact_id); -	void setPlayerActionEvent(uint32 id, uint32 interact_id); -	void startEvent(void); -	bool checkEventWaiting(void); -	void clearEvent(uint32 id); -	void killAllIdsEvents(uint32 id); - -	uint32 countEvents(void); -  	// These two are set by fnPassGraph() and fnPassMega().  	// FIXME: _engineGraph isn't used at all, is it? @@ -372,6 +355,18 @@ public:  	void triggerFx(uint8 j); +	bool _gamePaused; +	bool _graphicsLevelFudged; +	bool _stepOneCycle;		// for use while game paused + +	void startGame(void); +	void gameCycle(void); +	void closeGame(void); + +	void sleepUntil(int32 time); + +	uint32 readFile(const char *name, mem **membloc, uint32 uid); +  	void errorString(const char *buf_input, char *buf_output);  	void initialiseFontResourceFlags(void);  	void initialiseFontResourceFlags(uint8 language); diff --git a/sword2/sync.cpp b/sword2/sync.cpp index 659cf4a6ff..3e24fcc741 100644 --- a/sword2/sync.cpp +++ b/sword2/sync.cpp @@ -27,31 +27,15 @@  namespace Sword2 { -typedef	struct { -	uint32 id; -	uint32 sync; -} _sync_unit; - -// there wont be many will there. probably 2 at most i reckon -#define	MAX_syncs 10 - -static _sync_unit sync_list[MAX_syncs]; - -void Init_sync_system(void) { -	// set list to 0's -	for (int j = 0; j < MAX_syncs; j++) -		sync_list[j].id = 0; -} -  int32 Logic::fnSendSync(int32 *params) {  	// params:	0 sync's recipient  	//		1 sync value  	for (int i = 0; i < MAX_syncs; i++) { -		if (sync_list[i].id == 0) { +		if (_syncList[i].id == 0) {  			debug(5, " %d sending sync %d to %d", ID, params[1], params[0]); -			sync_list[i].id = params[0]; -			sync_list[i].sync = params[1]; +			_syncList[i].id = params[0]; +			_syncList[i].sync = params[1];  			return IR_CONT;  		}  	} @@ -63,27 +47,27 @@ int32 Logic::fnSendSync(int32 *params) {  	return IR_CONT;  } -void Clear_syncs(uint32	id) { +void Logic::clearSyncs(uint32 id) {  	// clear any syncs registered for this id  	// call this just after the id has been processed  	// there could in theory be more than one sync waiting for us so  	// clear the lot  	for (int i = 0; i < MAX_syncs; i++) { -		if (sync_list[i].id == id) { +		if (_syncList[i].id == id) {  			debug(5, "removing sync %d for %d", i, id); -			sync_list[i].id = 0; +			_syncList[i].id = 0;  		}  	}  } -bool Get_sync(void) { +bool Logic::getSync(void) {  	// check for a sync waiting for this character  	// - called from system code eg. from inside fnAnim(), to see if  	// animation to be quit  	for (int i = 0; i < MAX_syncs; i++) { -		if (sync_list[i].id == ID) { +		if (_syncList[i].id == ID) {  			// means sync found  			return true;  		} @@ -100,9 +84,9 @@ int32 Logic::fnGetSync(int32 *params) {  	// params:	none  	for (int i = 0; i < MAX_syncs; i++) { -		if (sync_list[i].id == ID) { +		if (_syncList[i].id == ID) {  			// return sync value waiting -			RESULT = sync_list[i].sync; +			RESULT = _syncList[i].sync;  			return IR_CONT;  		}  	} @@ -120,10 +104,10 @@ int32 Logic::fnWaitSync(int32 *params) {  	debug(5, "fnWaitSync: %d waits", ID);  	for (int i = 0; i < MAX_syncs; i++) { -		if (sync_list[i].id == ID) { +		if (_syncList[i].id == ID) {  			// return sync value waiting  			debug(5, "fnWaitSync: go"); -			RESULT = sync_list[i].sync; +			RESULT = _syncList[i].sync;  			return IR_CONT;  		}  	} diff --git a/sword2/sync.h b/sword2/sync.h index 229297e875..fb3fdef03f 100644 --- a/sword2/sync.h +++ b/sword2/sync.h @@ -20,14 +20,11 @@  #ifndef	_SYNC  #define	_SYNC -#include "sword2/object.h" +// There won't be many, will there? Probably 2 at most i reckon +#define	MAX_syncs 10  namespace Sword2 { -void Init_sync_system(void); -void Clear_syncs(uint32	id); -bool Get_sync(void); -  } // End of namespace Sword2  #endif diff --git a/sword2/tony_gsdk.cpp b/sword2/tony_gsdk.cpp index ef1f52a0df..7dd6c68a59 100644 --- a/sword2/tony_gsdk.cpp +++ b/sword2/tony_gsdk.cpp @@ -28,7 +28,7 @@  namespace Sword2 { -uint32 Read_file(const char *name, mem **membloc, uint32 uid) { +uint32 Sword2Engine::readFile(const char *name, mem **membloc, uint32 uid) {  	// read the file in and place into an allocated MEM_float block  	File fh; diff --git a/sword2/tony_gsdk.h b/sword2/tony_gsdk.h index 16a6d001ed..bfbd06ef84 100644 --- a/sword2/tony_gsdk.h +++ b/sword2/tony_gsdk.h @@ -20,12 +20,8 @@  #ifndef	TONY_GSDK  #define	TONY_GSDK -#include "sword2/memory.h" -  namespace Sword2 { -uint32 Read_file(const char *name, mem **membloc, uint32 uid); -  } // End of namespace Sword2  #endif diff --git a/sword2/walker.cpp b/sword2/walker.cpp index 21718b5088..b12f5966ed 100644 --- a/sword2/walker.cpp +++ b/sword2/walker.cpp @@ -37,10 +37,6 @@  namespace Sword2 { -int16 standby_x;		// see fnSetStandbyCoords -int16 standby_y; -uint8 standby_dir; -  /**   * Walk mega to (x,y,dir)   */ @@ -102,9 +98,9 @@ int32 Logic::fnWalk(int32 *params) {  		// set up mem for _walkData in route_slots[] & set mega's  		// 'route_slot_id' accordingly -		router.allocateRouteMem(); +		_router->allocateRouteMem(); -		route = (int8) router.routeFinder(ob_mega, ob_walkdata, target_x, target_y, target_dir); +		route = (int8) _router->routeFinder(ob_mega, ob_walkdata, target_x, target_y, target_dir);  		// 0 = can't make route to target  		// 1 = created route @@ -125,7 +121,7 @@ int32 Logic::fnWalk(int32 *params) {  			// (see fnGetPlayerSaveData() in save_rest.cpp  		} else {  			// free up the walkdata mem block -			router.freeRouteMem(); +			_router->freeRouteMem();  			// 1 means error, no walk created  			RESULT = 1; @@ -144,7 +140,7 @@ int32 Logic::fnWalk(int32 *params) {  		// ok, thats it - back to script and change screen  		ob_logic->looping = 0;	// so script loop stops -		router.freeRouteMem();	// free up the walkdata mem block +		_router->freeRouteMem();	// free up the walkdata mem block  		// must clear in-case on the new screen there's a walk  		// instruction (which would get cut short) @@ -168,17 +164,17 @@ int32 Logic::fnWalk(int32 *params) {  	// get pointer to walkanim & current frame position  	// lock the _walkData array -	walkAnim = router.lockRouteMem(); +	walkAnim = _router->lockRouteMem();  	walk_pc = ob_mega->walk_pc;  	// if stopping the walk early, overwrite the next step with a  	// slow-out, then finish -	if (g_sword2->checkEventWaiting()) { +	if (checkEventWaiting()) {  		if (walkAnim[walk_pc].step == 0 && walkAnim[walk_pc + 1].step == 1) {  			// at the beginning of a step  			ob_walkdata = (Object_walkdata *) params[3]; -			router.earlySlowOut(ob_mega, ob_walkdata); +			_router->earlySlowOut(ob_mega, ob_walkdata);  		}  	} @@ -197,7 +193,7 @@ int32 Logic::fnWalk(int32 *params) {  	// '512' is end-marker  	if (walkAnim[walk_pc + 1].frame == 512) {  		ob_logic->looping = 0;	// so script loop stops -		router.freeRouteMem();	// free up the walkdata mem block +		_router->freeRouteMem();	// free up the walkdata mem block  		// finished walk  		ob_mega->currently_walking = 0; @@ -213,8 +209,8 @@ int32 Logic::fnWalk(int32 *params) {  		// was only run if a function that always returned zero  		// returned non-zero. -		if (g_sword2->checkEventWaiting()) { -			g_sword2->startEvent(); +		if (checkEventWaiting()) { +			startEvent();  			RESULT = 1;		// 1 means didn't finish walk  			return IR_TERMINATE;  		} else { @@ -238,7 +234,7 @@ int32 Logic::fnWalk(int32 *params) {  	ob_mega->walk_pc++;  	// allow _walkData array to float about memory again -	router.floatRouteMem(); +	_router->floatRouteMem();  	// stop the script, but repeat this call next cycle  	return IR_REPEAT; @@ -269,7 +265,7 @@ int32 Logic::fnWalkToAnim(int32 *params) {  		anim_file = res_man->openResource(params[4]);  		// point to animation header -		anim_head = g_sword2->fetchAnimHeader( anim_file ); +		anim_head = _vm->fetchAnimHeader( anim_file );  		pars[4] = anim_head->feetStartX;	// target_x  		pars[5] = anim_head->feetStartY;	// target_y @@ -282,11 +278,11 @@ int32 Logic::fnWalkToAnim(int32 *params) {  		// coords (which should be set beforehand in the script)  		if (pars[4] == 0 && pars[5] == 0) { -			pars[4] = standby_x; -			pars[5] = standby_y; -			pars[6] = standby_dir; +			pars[4] = _standbyX; +			pars[5] = _standbyY; +			pars[6] = _standbyDir; -			debug(5, "WARNING: fnWalkToAnim(%s) used standby coords", g_sword2->fetchObjectName(params[4])); +			debug(5, "WARNING: fnWalkToAnim(%s) used standby coords", _vm->fetchObjectName(params[4]));  		}  		if (pars[6] < 0 || pars[6] > 7) @@ -431,7 +427,7 @@ int32 Logic::fnStandAfterAnim(int32 *params) {  	// open anim file  	anim_file = res_man->openResource(params[2]); -	anim_head = g_sword2->fetchAnimHeader(anim_file); +	anim_head = _vm->fetchAnimHeader(anim_file);  	// set up the parameter list for fnWalkTo() @@ -446,11 +442,11 @@ int32 Logic::fnStandAfterAnim(int32 *params) {  	// should be set beforehand in the script)  	if (pars[2] == 0 && pars[3] == 0) { -		pars[2] = standby_x; -		pars[3] = standby_y; -		pars[4] = standby_dir; +		pars[2] = _standbyX; +		pars[3] = _standbyY; +		pars[4] = _standbyDir; -		debug(5, "WARNING: fnStandAfterAnim(%s) used standby coords", g_sword2->fetchObjectName(params[2])); +		debug(5, "WARNING: fnStandAfterAnim(%s) used standby coords", _vm->fetchObjectName(params[2]));  	}  	if (pars[4] < 0 || pars[4] > 7) @@ -478,7 +474,7 @@ int32 Logic::fnStandAtAnim(int32 *params) {  	// open anim file  	anim_file = res_man->openResource(params[2]); -	anim_head = g_sword2->fetchAnimHeader(anim_file); +	anim_head = _vm->fetchAnimHeader(anim_file);  	// set up the parameter list for fnWalkTo() @@ -492,12 +488,12 @@ int32 Logic::fnStandAtAnim(int32 *params) {  	// if start coords not available use the standby coords (which should  	// be set beforehand in the script) -	if (pars[2] == 0 && pars[3]==0) { -		pars[2] = standby_x; -		pars[3] = standby_y; -		pars[4] = standby_dir; +	if (pars[2] == 0 && pars[3] == 0) { +		pars[2] = _standbyX; +		pars[3] = _standbyY; +		pars[4] = _standbyDir; -		debug(5, "WARNING: fnStandAtAnim(%s) used standby coords", g_sword2->fetchObjectName(params[2])); +		debug(5, "WARNING: fnStandAtAnim(%s) used standby coords", _vm->fetchObjectName(params[2]));  	}  	if (pars[4] < 0 || pars[4] > 7) @@ -516,7 +512,7 @@ int32 Logic::fnStandAtAnim(int32 *params) {  #define	diagonalx 36  #define	diagonaly 8 -int What_target(int startX, int startY, int destX, int destY) { +int Logic::whatTarget(int startX, int startY, int destX, int destY) {  	int deltaX = destX - startX;  	int deltaY = destY - startY; @@ -545,7 +541,7 @@ int What_target(int startX, int startY, int destX, int destY) {  /**   * turn mega to face point (x,y) on the floor   * just needs to call fnWalk() with current feet coords & direction computed - * by What_target() + * by whatTarget()   */  int32 Logic::fnFaceXY(int32 *params) { @@ -570,7 +566,7 @@ int32 Logic::fnFaceXY(int32 *params) {  		pars[4] = ob_mega->feet_x;  		pars[5] = ob_mega->feet_y; -		pars[6] = What_target(ob_mega->feet_x, ob_mega->feet_y, params[4], params[5]); +		pars[6] = whatTarget(ob_mega->feet_x, ob_mega->feet_y, params[4], params[5]);  	}  	// set up the rest of the parameters for fnWalk() @@ -621,7 +617,7 @@ int32 Logic::fnFaceMega(int32 *params) {  		pars[3] = params[3];  		pars[4] = ob_mega->feet_x;  		pars[5] = ob_mega->feet_y; -		pars[6] = What_target(ob_mega->feet_x, ob_mega->feet_y, g_sword2->_engineMega.feet_x, g_sword2->_engineMega.feet_y); +		pars[6] = whatTarget(ob_mega->feet_x, ob_mega->feet_y, _vm->_engineMega.feet_x, _vm->_engineMega.feet_y);  	}  	pars[0] = params[0]; @@ -682,7 +678,7 @@ int32 Logic::fnWalkToTalkToMega(int32 *params) {  		// route to  		// stand exactly beside the mega, ie. at same y-coord -		pars[5] = g_sword2->_engineMega.feet_y; +		pars[5] = _vm->_engineMega.feet_y;  		// apply scale factor to walk distance  		// Ay+B gives 256 * scale ie. 256 * 256 * true_scale for even @@ -693,20 +689,20 @@ int32 Logic::fnWalkToTalkToMega(int32 *params) {  		mega_separation= (mega_separation * scale) / 256;  		debug(5, "separation %d", mega_separation); -		debug(5, " target x %d, y %d", g_sword2->_engineMega.feet_x, g_sword2->_engineMega.feet_y); +		debug(5, " target x %d, y %d", _vm->_engineMega.feet_x, _vm->_engineMega.feet_y); -		if (g_sword2->_engineMega.feet_x < ob_mega->feet_x) +		if (_vm->_engineMega.feet_x < ob_mega->feet_x)  		{  			// Target is left of us, so aim to stand to their  			// right. Face down_left -			pars[4] = g_sword2->_engineMega.feet_x + mega_separation; +			pars[4] = _vm->_engineMega.feet_x + mega_separation;  			pars[6] = 5;  		} else {  			// Ok, must be right of us so aim to stand to their  			// left. Face down_right. -			pars[4] = g_sword2->_engineMega.feet_x - mega_separation; +			pars[4] = _vm->_engineMega.feet_x - mega_separation;  			pars[6] = 3;  		}  	} @@ -741,7 +737,7 @@ int32 Logic::fnAddWalkGrid(int32 *params) {  		fnAddToKillList(params);  	} -	router.addWalkGrid(params[0]); +	_router->addWalkGrid(params[0]);  	// Touch the grid, getting it into memory.  	res_man->openResource(params[0]); @@ -757,7 +753,7 @@ int32 Logic::fnAddWalkGrid(int32 *params) {  int32 Logic::fnRemoveWalkGrid(int32 *params) {  	// params:	0 id of walkgrid resource -	router.removeWalkGrid(params[0]); +	_router->removeWalkGrid(params[0]);  	return IR_CONT;  } @@ -799,9 +795,9 @@ int32 Logic::fnSetStandbyCoords(int32 *params) {  	if (params[2] < 0 || params[2] > 7)  		error("Invalid direction (%d) in fnSetStandbyCoords", params[2]); -	standby_x = (int16) params[0]; -	standby_y = (int16) params[1]; -	standby_dir = (uint8) params[2]; +	_standbyX = (int16) params[0]; +	_standbyY = (int16) params[1]; +	_standbyDir = (uint8) params[2];  	return IR_CONT;  } | 
