[Scummvm-cvs-logs] CVS: scummvm/sword2 anims.cpp,1.40,1.41 build_display.cpp,1.43,1.44 console.cpp,1.29,1.30 console.h,1.12,1.13 controls.cpp,1.47,1.48 controls.h,1.9,1.10 debug.cpp,1.25,1.26 events.cpp,1.17,1.18 events.h,1.10,1.11 function.cpp,1.36,1.37 icons.cpp,1.22,1.23 layers.cpp,1.19,1.20 logic.cpp,1.28,1.29 logic.h,1.17,1.18 maketext.cpp,1.27,1.28 maketext.h,1.7,1.8 mouse.cpp,1.37,1.38 resman.cpp,1.63,1.64 resman.h,1.13,1.14 router.cpp,1.28,1.29 router.h,1.10,1.11 save_rest.cpp,1.35,1.36 scroll.cpp,1.11,1.12 sound.cpp,1.32,1.33 speech.cpp,1.44,1.45 startup.cpp,1.29,1.30 sword2.cpp,1.77,1.78 sword2.h,1.33,1.34 sync.cpp,1.12,1.13 sync.h,1.7,1.8 tony_gsdk.cpp,1.15,1.16 tony_gsdk.h,1.6,1.7 walker.cpp,1.23,1.24

Torbj?rn Andersson eriktorbjorn at users.sourceforge.net
Sat Nov 8 07:50:28 CET 2003


Update of /cvsroot/scummvm/scummvm/sword2
In directory sc8-pr-cvs1:/tmp/cvs-serv22682

Modified Files:
	anims.cpp build_display.cpp console.cpp console.h controls.cpp 
	controls.h debug.cpp events.cpp events.h function.cpp 
	icons.cpp layers.cpp logic.cpp logic.h maketext.cpp maketext.h 
	mouse.cpp resman.cpp resman.h router.cpp router.h 
	save_rest.cpp scroll.cpp sound.cpp speech.cpp startup.cpp 
	sword2.cpp sword2.h sync.cpp sync.h tony_gsdk.cpp tony_gsdk.h 
	walker.cpp 
Log Message:
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.


Index: anims.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/anims.cpp,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- anims.cpp	3 Nov 2003 07:47:41 -0000	1.40
+++ anims.cpp	8 Nov 2003 15:47:51 -0000	1.41
@@ -161,7 +161,7 @@
 #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 @@
 			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 @@
 
 		// 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 @@
 #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 @@
 		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 @@
 
 		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 @@
 			// 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 @@
 
 	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);

Index: build_display.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/build_display.cpp,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- build_display.cpp	3 Nov 2003 07:47:41 -0000	1.43
+++ build_display.cpp	8 Nov 2003 15:47:51 -0000	1.44
@@ -160,7 +160,7 @@
 			// text blocks
 
 			// speech blocks and headup debug text
-			fontRenderer.printTextBlocs();
+			fontRenderer->printTextBlocs();
 
 			// menu bar & icons
 
@@ -218,7 +218,7 @@
 	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 @@
 	//		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 @@
 
 	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 @@
 	// 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 @@
 	// 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;

Index: console.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/console.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- console.cpp	4 Nov 2003 18:02:49 -0000	1.29
+++ console.cpp	8 Nov 2003 15:47:51 -0000	1.30
@@ -45,9 +45,9 @@
 	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 @@
 		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 @@
 	}
 
 	// 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 @@
 	}
 
 	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 @@
 	}
 
 	// 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 @@
 	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 @@
 	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_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_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;
 }

Index: console.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/console.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- console.h	2 Nov 2003 15:58:45 -0000	1.12
+++ console.h	8 Nov 2003 15:47:51 -0000	1.13
@@ -59,7 +59,7 @@
 	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;

Index: controls.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/controls.cpp,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- controls.cpp	4 Nov 2003 18:02:49 -0000	1.47
+++ controls.cpp	8 Nov 2003 15:47:51 -0000	1.48
@@ -1261,7 +1261,7 @@
 					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 @@
 	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 @@
 	}
 
 	// close engine systems down
-	Close_game();
-	exit(0);
+	_vm->closeGame();
 }
 
 void Gui::restartControl(void) {
@@ -1428,7 +1427,7 @@
 	}
 
 	// Stop music instantly!
-	g_sword2->killMusic();
+	_vm->killMusic();
 
 	//in case we were dead - well we're not anymore!
 	DEAD = 0;
@@ -1452,20 +1451,20 @@
 	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 @@
 	// - 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 @@
 	// 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) {

Index: controls.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/controls.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- controls.h	1 Nov 2003 17:08:23 -0000	1.9
+++ controls.h	8 Nov 2003 15:47:51 -0000	1.10
@@ -22,8 +22,12 @@
 
 namespace Sword2 {
 
+class Sword2Engine;
+
 class Gui {
 private:
+	Sword2Engine *_vm;
+
 	int _musicVolume[17];
 	int _soundVolume[15];
 
@@ -35,7 +39,7 @@
 	bool _stereoReversed;
 	bool _pointerTextSelected;
 
-	Gui();
+	Gui(Sword2Engine *vm);
 
 	uint32 restoreControl(void);
 	void saveControl(void);

Index: debug.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/debug.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- debug.cpp	4 Nov 2003 18:02:49 -0000	1.25
+++ debug.cpp	8 Nov 2003 15:47:51 -0000	1.26
@@ -41,7 +41,7 @@
 
 	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 @@
 
 	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 @@
 
 	// 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 @@
 		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 @@
 		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 @@
 
 		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 @@
 
  		// 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 @@
 	// 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::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

Index: events.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/events.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- events.cpp	7 Nov 2003 01:36:53 -0000	1.17
+++ events.cpp	8 Nov 2003 15:47:51 -0000	1.18
@@ -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 @@
 	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 @@
 	_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 @@
 	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 @@
 	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::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 @@
 	//		  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 @@
 
 	// 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 @@
 	// 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 @@
 
 	// params:	none
 
-	if (g_sword2->checkEventWaiting())
+	if (checkEventWaiting())
 		RESULT = 1;
 	else
 		RESULT = 0;
@@ -174,10 +170,10 @@
 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 @@
 
 	// 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::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;
 }
 

Index: events.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/events.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- events.h	2 Nov 2003 15:58:45 -0000	1.10
+++ events.h	8 Nov 2003 15:47:51 -0000	1.11
@@ -24,11 +24,6 @@
 
 namespace Sword2 {
 
-struct _event_unit {
-	uint32 id;
-	uint32 interact_id;
-};
-
 } // End of namespace Sword2
 
 #endif

Index: function.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/function.cpp,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- function.cpp	3 Nov 2003 07:47:41 -0000	1.36
+++ function.cpp	8 Nov 2003 15:47:51 -0000	1.37
@@ -139,7 +139,7 @@
 	// 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 @@
 
 	// 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 @@
 
 	// 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 @@
 	// +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 @@
 	// - 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 @@
 		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;

Index: icons.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/icons.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- icons.cpp	4 Nov 2003 18:02:49 -0000	1.22
+++ icons.cpp	8 Nov 2003 15:47:51 -0000	1.23
@@ -31,11 +31,11 @@
 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 @@
 
 	// 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;

Index: layers.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/layers.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- layers.cpp	3 Nov 2003 07:47:41 -0000	1.19
+++ layers.cpp	8 Nov 2003 15:47:51 -0000	1.20
@@ -44,7 +44,7 @@
 	// 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 @@
 
 			// 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);
 		}

Index: logic.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/logic.cpp,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- logic.cpp	4 Nov 2003 18:02:49 -0000	1.28
+++ logic.cpp	8 Nov 2003 15:47:51 -0000	1.29
@@ -185,7 +185,7 @@
 		// 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 @@
 	// 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();
 }
 
 /**

Index: logic.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/logic.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- logic.h	7 Nov 2003 01:36:53 -0000	1.17
+++ logic.h	8 Nov 2003 15:47:51 -0000	1.18
@@ -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 @@
 
 #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 @@
 
 	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 @@
 		  _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();
 	}
@@ -201,6 +218,34 @@
 	int runScript(char *scriptData, char *objectData, uint32 *offset);
 
 	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);

Index: maketext.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/maketext.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- maketext.cpp	3 Nov 2003 07:47:41 -0000	1.27
+++ maketext.cpp	8 Nov 2003 15:47:51 -0000	1.28
@@ -60,7 +60,7 @@
 
 namespace Sword2 {
 
-FontRenderer fontRenderer;
+FontRenderer *fontRenderer;
 
 // info for each line of words in the output text sprite
 

Index: maketext.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/maketext.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- maketext.h	28 Oct 2003 19:51:29 -0000	1.7
+++ maketext.h	8 Nov 2003 15:47:51 -0000	1.8
@@ -141,7 +141,7 @@
 	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
 

Index: mouse.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/mouse.cpp,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- mouse.cpp	4 Nov 2003 18:02:49 -0000	1.37
+++ mouse.cpp	8 Nov 2003 15:47:51 -0000	1.38
@@ -321,7 +321,7 @@
 
 			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 @@
 						// 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 @@
 
 					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 @@
 				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 @@
 			// '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::clearPointerText(void) {
 	if (_pointerTextBlocNo) {
-		fontRenderer.killTextBloc(_pointerTextBlocNo);
+		fontRenderer->killTextBloc(_pointerTextBlocNo);
 		_pointerTextBlocNo = 0;
 	}
 }
@@ -1055,8 +1055,8 @@
 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 @@
 	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 @@
 	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 @@
 	// 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 @@
 		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 @@
 		// 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 @@
 	// 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::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 @@
 
 	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 @@
 
 	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 @@
 
 	// 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::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 @@
 	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 @@
 
 	// params:	none
 
-	g_sword2->_playerActivityDelay = 0;
+	_vm->_playerActivityDelay = 0;
 	return IR_CONT;
 }
 

Index: resman.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/resman.cpp,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -d -r1.63 -r1.64
--- resman.cpp	7 Nov 2003 01:36:53 -0000	1.63
+++ resman.cpp	8 Nov 2003 15:47:51 -0000	1.64
@@ -85,7 +85,9 @@
 	#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 @@
 
 	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 @@
 
 	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 @@
 	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 @@
 
 	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 @@
 	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 @@
 			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 @@
 
 	// 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 @@
 	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 @@
 	} while (!done);
 
 	memory->freeMemory(text_spr);
-	g_sword2->removeMsg();
+	_vm->removeMsg();
 }
 
 } // End of namespace Sword2

Index: resman.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/resman.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- resman.h	3 Nov 2003 07:47:41 -0000	1.13
+++ resman.h	8 Nov 2003 15:47:51 -0000	1.14
@@ -26,9 +26,11 @@
 
 #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 @@
 	mem **_resList;
 
 private:
+	Sword2Engine *_vm;
+
 	int _curCd;
 	uint32 _totalResFiles;
 	uint32 _totalClusters;

Index: router.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/router.cpp,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- router.cpp	7 Nov 2003 01:36:53 -0000	1.28
+++ router.cpp	8 Nov 2003 15:47:51 -0000	1.29
@@ -88,8 +88,6 @@
 
 namespace Sword2 {
 
-Router router;
-
 uint8 Router::returnSlotNo(uint32 megaId) {
 	if (ID == CUR_PLAYER_ID) {
 		// George (8)

Index: router.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/router.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- router.h	28 Oct 2003 19:51:29 -0000	1.10
+++ router.h	8 Nov 2003 15:47:51 -0000	1.11
@@ -216,7 +216,24 @@
 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);
 
@@ -233,8 +250,6 @@
 
 	void plotWalkGrid(void);
 };
-
-extern Router router;
 
 } // End of namespace Sword2
 

Index: save_rest.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/save_rest.cpp,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- save_rest.cpp	4 Nov 2003 18:02:49 -0000	1.35
+++ save_rest.cpp	8 Nov 2003 15:47:51 -0000	1.36
@@ -560,9 +560,9 @@
 
 	// 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 @@
 
 	// 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

Index: scroll.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/scroll.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- scroll.cpp	3 Nov 2003 07:47:41 -0000	1.11
+++ scroll.cpp	8 Nov 2003 15:47:51 -0000	1.12
@@ -162,22 +162,22 @@
 	// 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;
 }
 

Index: sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/sound.cpp,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- sound.cpp	3 Nov 2003 07:47:41 -0000	1.32
+++ sound.cpp	8 Nov 2003 15:47:51 -0000	1.33
@@ -168,10 +168,10 @@
 	_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 @@
 			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 @@
 #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 @@
 			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 @@
 	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 @@
 	}
 
 	// remove from queue
-	g_sword2->_fxQueue[j].resource = 0;
+	_vm->_fxQueue[j].resource = 0;
 
 	return IR_CONT;
 }
@@ -330,7 +330,7 @@
 
 	// params:	none
 
-	g_sword2->clearFxQueue();
+	_vm->clearFxQueue();
 	return IR_CONT;
 }
 
@@ -355,18 +355,18 @@
 
 		// 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::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;
 }

Index: speech.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/speech.cpp,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- speech.cpp	7 Nov 2003 02:14:56 -0000	1.44
+++ speech.cpp	8 Nov 2003 15:47:51 -0000	1.45
@@ -189,7 +189,7 @@
 		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 @@
 
 					// 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 @@
 					}
 
 
-					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 @@
 					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 @@
 
 	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 @@
 
 		// 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 @@
 		} 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 @@
 				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 @@
 		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 @@
 		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 @@
 
 		// 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 @@
 		// if there is text
 		if (_speechTextBlocNo) {
 			// kill the text block
-			fontRenderer.killTextBloc(_speechTextBlocNo);
+			fontRenderer->killTextBloc(_speechTextBlocNo);
 			_speechTextBlocNo = 0;
 		}
 
@@ -1302,7 +1302,7 @@
 		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 @@
 		// 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 @@
 			
 		// 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 @@
 		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);

Index: startup.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/startup.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- startup.cpp	4 Nov 2003 18:02:49 -0000	1.29
+++ startup.cpp	8 Nov 2003 15:47:51 -0000	1.30
@@ -63,7 +63,7 @@
 
 	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 @@
 
 		// restarting - stop sfx, music & speech!
 
-		g_sword2->clearFxQueue();
+		_vm->clearFxQueue();
 
 		// fade out any music that is currently playing
 		fnStopMusic(NULL);
@@ -214,11 +214,11 @@
 		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;
 		}
 

Index: sword2.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/sword2.cpp,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -d -r1.77 -r1.78
--- sword2.cpp	4 Nov 2003 18:02:49 -0000	1.77
+++ sword2.cpp	8 Nov 2003 15:47:51 -0000	1.78
@@ -75,7 +75,7 @@
 	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 @@
 
 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 @@
 	// 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 @@
 
 	// 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 @@
 	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 @@
 	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 @@
 		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 @@
 
 	debug(5, "CALLING: InitialiseGame");
 	if (InitialiseGame()) {
-		Close_game();
+		closeGame();
 		return;
 	}
 
@@ -337,10 +322,10 @@
 		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 @@
 		// 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 @@
 			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 @@
 				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 @@
 		}
 
 		// 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 @@
 		// 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 @@
 	// 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 PauseGame(void) {
+void Sword2Engine::pauseGame(void) {
 	// uint8 *text;
 
 	// open text file & get the line "PAUSED"
@@ -525,10 +504,10 @@
 	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 @@
 	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

Index: sword2.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/sword2.h,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- sword2.h	3 Nov 2003 07:47:42 -0000	1.33
+++ sword2.h	8 Nov 2003 15:47:51 -0000	1.34
@@ -55,13 +55,6 @@
 
 #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 @@
 
 	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 @@
 
 	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?
 
@@ -371,6 +354,18 @@
 	void killMusic(void);
 
 	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);

Index: sync.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/sync.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- sync.cpp	7 Nov 2003 01:36:53 -0000	1.12
+++ sync.cpp	8 Nov 2003 15:47:51 -0000	1.13
@@ -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 @@
 	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 @@
 	// 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 @@
 	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;
 		}
 	}

Index: sync.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/sync.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- sync.h	28 Oct 2003 19:51:30 -0000	1.7
+++ sync.h	8 Nov 2003 15:47:51 -0000	1.8
@@ -20,13 +20,10 @@
 #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
 

Index: tony_gsdk.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/tony_gsdk.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- tony_gsdk.cpp	3 Nov 2003 07:47:42 -0000	1.15
+++ tony_gsdk.cpp	8 Nov 2003 15:47:51 -0000	1.16
@@ -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;

Index: tony_gsdk.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/tony_gsdk.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- tony_gsdk.h	28 Oct 2003 19:51:30 -0000	1.6
+++ tony_gsdk.h	8 Nov 2003 15:47:51 -0000	1.7
@@ -20,11 +20,7 @@
 #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
 

Index: walker.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/walker.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- walker.cpp	7 Nov 2003 01:36:53 -0000	1.23
+++ walker.cpp	8 Nov 2003 15:47:51 -0000	1.24
@@ -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 @@
 		// 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 @@
 			// (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 @@
 		// 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 @@
 	// 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 @@
 	// '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 @@
 		// 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 @@
 	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 @@
 		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 @@
 		// 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 @@
 
 	// 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 @@
 	// 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 @@
 
 	// 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 @@
 	// 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 @@
 #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 @@
 /**
  * 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 @@
 	
 		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 @@
 		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 @@
 		// 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 @@
 		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 @@
 		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::fnRemoveWalkGrid(int32 *params) {
 	// params:	0 id of walkgrid resource
 
-	router.removeWalkGrid(params[0]);
+	_router->removeWalkGrid(params[0]);
 	return IR_CONT;
 }
 
@@ -799,9 +795,9 @@
 	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;
 }





More information about the Scummvm-git-logs mailing list