[Scummvm-cvs-logs] SF.net SVN: scummvm:[39180] scummvm/trunk/engines/cruise

dreammaster at users.sourceforge.net dreammaster at users.sourceforge.net
Sat Mar 7 08:12:14 CET 2009


Revision: 39180
          http://scummvm.svn.sourceforge.net/scummvm/?rev=39180&view=rev
Author:   dreammaster
Date:     2009-03-07 07:12:10 +0000 (Sat, 07 Mar 2009)

Log Message:
-----------
Fixed some method parameters, changed the main loop to a method of the engine class, and moved the frame delay code to the main loop to make the game more responsive to events

Modified Paths:
--------------
    scummvm/trunk/engines/cruise/backgroundIncrust.cpp
    scummvm/trunk/engines/cruise/cruise.cpp
    scummvm/trunk/engines/cruise/cruise.h
    scummvm/trunk/engines/cruise/cruise_main.cpp
    scummvm/trunk/engines/cruise/gfxModule.cpp
    scummvm/trunk/engines/cruise/mainDraw.cpp
    scummvm/trunk/engines/cruise/mainDraw.h

Modified: scummvm/trunk/engines/cruise/backgroundIncrust.cpp
===================================================================
--- scummvm/trunk/engines/cruise/backgroundIncrust.cpp	2009-03-07 06:57:59 UTC (rev 39179)
+++ scummvm/trunk/engines/cruise/backgroundIncrust.cpp	2009-03-07 07:12:10 UTC (rev 39180)
@@ -147,7 +147,7 @@
 			backupBackground(newElement, newElement->X, newElement->Y, width, height, backgroundPtr);
 		}
 
-		drawSprite(width, height, NULL, (char *)filesDatabase[params.fileIdx].subData.ptr, newElement->Y, newElement->X, (char *)backgroundPtr, (char *)filesDatabase[params.fileIdx].subData.ptrMask);
+		drawSprite(width, height, NULL, filesDatabase[params.fileIdx].subData.ptr, newElement->Y, newElement->X, backgroundPtr, filesDatabase[params.fileIdx].subData.ptrMask);
 	} else {			// poly
 		if (saveBuffer == 1) {
 			int newX;
@@ -202,7 +202,7 @@
 				int width = filesDatabase[frame].width;
 				int height = filesDatabase[frame].height;
 
-				drawSprite(width, height, NULL, (char *)filesDatabase[frame].subData.ptr, pl->Y, pl->X, (char*)backgroundPtrtable[pl->backgroundIdx], (char *)filesDatabase[frame].subData.ptrMask);
+				drawSprite(width, height, NULL, filesDatabase[frame].subData.ptr, pl->Y, pl->X, backgroundPtrtable[pl->backgroundIdx], filesDatabase[frame].subData.ptrMask);
 			} else {			// poly
 				addBackgroundIncrustSub1(frame, pl->X, pl->Y, NULL, pl->scale, (char*)backgroundPtrtable[pl->backgroundIdx], (char *)filesDatabase[frame].subData.ptr);
 			}

Modified: scummvm/trunk/engines/cruise/cruise.cpp
===================================================================
--- scummvm/trunk/engines/cruise/cruise.cpp	2009-03-07 06:57:59 UTC (rev 39179)
+++ scummvm/trunk/engines/cruise/cruise.cpp	2009-03-07 07:12:10 UTC (rev 39180)
@@ -83,8 +83,12 @@
 	Cruise::changeCursor(Cruise::CURSOR_NORMAL);
 	CursorMan.showMouse(true);
 
-	Cruise::mainLoop();
 
+	lastTick = 0;
+	lastTickDebug = 0;
+
+	mainLoop();
+
 	return Common::kNoError;
 }
 

Modified: scummvm/trunk/engines/cruise/cruise.h
===================================================================
--- scummvm/trunk/engines/cruise/cruise.h	2009-03-07 06:57:59 UTC (rev 39179)
+++ scummvm/trunk/engines/cruise/cruise.h	2009-03-07 07:12:10 UTC (rev 39180)
@@ -40,6 +40,8 @@
 	GType_CRUISE = 1
 };
 
+#define GAME_FRAME_DELAY 70
+
 #define MAX_LANGUAGE_STRINGS 25
 
 enum LangStringId { ID_PAUSED = 0, ID_INVENTORY = 5, ID_PLAYER_MENU = 7,
@@ -49,16 +51,17 @@
 
 class CruiseEngine: public Engine {
 private:
-	void initialize(void);
-	bool loadLanguageStrings();
-	bool makeLoad(char *saveName);
-	void mainLoop(int bootScriptIdx);
-
 	bool _preLoad;
 	Debugger *_debugger;
 	Common::StringList _langStrings;
 	CursorType _savedCursor;
+	uint32 lastTick, lastTickDebug;
 
+	void initialize(void);
+	bool loadLanguageStrings();
+	bool makeLoad(char *saveName);
+	void mainLoop();
+
 protected:
 	// Engine APIs
 	virtual Common::Error run();

Modified: scummvm/trunk/engines/cruise/cruise_main.cpp
===================================================================
--- scummvm/trunk/engines/cruise/cruise_main.cpp	2009-03-07 06:57:59 UTC (rev 39179)
+++ scummvm/trunk/engines/cruise/cruise_main.cpp	2009-03-07 07:12:10 UTC (rev 39180)
@@ -1700,8 +1700,8 @@
 	*pMouseButton = currentMouseButton;
 }
 
-void mainLoop(void) {
-	int frames = 0;		/* Number of frames displayed */
+
+void CruiseEngine::mainLoop(void) {
 	//int32 t_start,t_left;
 	//uint32 t_end;
 	//int32 q=0;                     /* Dummy */
@@ -1722,201 +1722,176 @@
 
 	initAllData();
 
-	{
-		int playerDontAskQuit = 1;
-		int quitValue2 = 1;
-		int quitValue = 0;
+	int playerDontAskQuit = 1;
+	int quitValue2 = 1;
+	int quitValue = 0;
 
-		do {
-			frames++;
-//      t_start=Osystem_GetTicks();
+	do {
+		// Handle frame delay
+		uint32 currentTick = g_system->getMillis();
 
-//      readKeyboard();
-			playerDontAskQuit = processInput();
+		if (!bFastMode) {
+			// Delay for the specified amount of time, but still respond to events
+			while (currentTick < lastTick + GAME_FRAME_DELAY) {
+				g_system->delayMillis(10);
+				currentTick = g_system->getMillis();
 
-			if (enableUser) {
-				userEnabled = 1;
-				enableUser = 0;
-			}
+				manageEvents();
 
-			manageScripts(&relHead);
-			manageScripts(&procHead);
-
-			removeFinishedScripts(&relHead);
-			removeFinishedScripts(&procHead);
-
-			processAnimation();
-
-			if (remdo) {
-				// ASSERT(0);
-				/*    main3 = 0;
-				 * var24 = 0;
-				 * var23 = 0;
-				 *
-				 * freeStuff2(); */
+				if (_vm->getDebugger()->isAttached())
+					_vm->getDebugger()->onFrame();
 			}
+		} else {
+			manageEvents();
 
-			if (cmdLine[0]) {
-				ASSERT(0);
-				/*        redrawStrings(0,&cmdLine,8);
+			if (currentTick >= (lastTickDebug + 10)) {
+				lastTickDebug = currentTick;
 
-				        waitForPlayerInput();
-
-				        cmdLine = 0; */
+				if (_vm->getDebugger()->isAttached())
+					_vm->getDebugger()->onFrame();
 			}
+		}
 
-			if (displayOn) {
-				if (doFade)
-					PCFadeFlag = 0;
+		lastTick = g_system->getMillis();
 
-				/*if (!PCFadeFlag)*/
-				{
-					mainDraw(0);
-					flipScreen();
-				}
+		// Handle the next frame
 
-				if (userEnabled && !userWait && !autoTrack) {
-					if (currentActiveMenu == -1) {
-						int16 mouseX;
-						int16 mouseY;
-						int16 mouseButton;
+//		frames++;
+//      t_start=Osystem_GetTicks();
 
-						static int16 oldMouseX = -1;
-						static int16 oldMouseY = -1;
+//      readKeyboard();
+		playerDontAskQuit = processInput();
 
-						getMouseStatus(&main10, &mouseX, &mouseButton, &mouseY);
+		if (enableUser) {
+			userEnabled = 1;
+			enableUser = 0;
+		}
 
-						if (mouseX != oldMouseX && mouseY != oldMouseY) {
-							int objectType;
-							int newCursor1;
-							int newCursor2;
+		manageScripts(&relHead);
+		manageScripts(&procHead);
 
-							oldMouseX = mouseX;
-							oldMouseY = mouseY;
+		removeFinishedScripts(&relHead);
+		removeFinishedScripts(&procHead);
 
-							objectType = findObject(mouseX, mouseY, &newCursor1, &newCursor2);
+		processAnimation();
 
-							if (objectType == 9) {
-								changeCursor(CURSOR_EXIT);
-							} else if (objectType != -1) {
-								changeCursor(CURSOR_MAGNIFYING_GLASS);
-							} else {
-								changeCursor(CURSOR_WALK);
-							}
-						}
-					} else {
-						changeCursor(CURSOR_NORMAL);
-					}
-				} else {
-					changeCursor(CURSOR_NORMAL);
-				}
+		if (remdo) {
+			// ASSERT(0);
+			/*    main3 = 0;
+			 * var24 = 0;
+			 * var23 = 0;
+			 *
+			 * freeStuff2(); */
+		}
 
-				if (userWait) {
-					int16 mouseButton = 0;
-					checkInput(&mouseButton);
+		if (cmdLine[0]) {
+			ASSERT(0);
+			/*        redrawStrings(0,&cmdLine,8);
 
-					while (!mouseButton) {
-						manageScripts(&relHead);
-						manageScripts(&procHead);
+			        waitForPlayerInput();
 
-						removeFinishedScripts(&relHead);
-						removeFinishedScripts(&procHead);
+			        cmdLine = 0; */
+		}
 
-						processAnimation();
+		if (displayOn) {
+			if (doFade)
+				PCFadeFlag = 0;
 
-						flip();
+			/*if (!PCFadeFlag)*/
+			{
+				mainDraw(0);
+				flipScreen();
+			}
 
-						// not exactly this
-						manageEvents();
+			if (userEnabled && !userWait && !autoTrack) {
+				if (currentActiveMenu == -1) {
+					int16 mouseX;
+					int16 mouseY;
+					int16 mouseButton;
 
-						checkInput(&mouseButton);
-					}
+					static int16 oldMouseX = -1;
+					static int16 oldMouseY = -1;
 
-					changeScriptParamInList(-1, -1, &procHead, 9999, 0);
-					changeScriptParamInList(-1, -1, &relHead, 9999, 0);
-					userWait = 0;
-				}
+					getMouseStatus(&main10, &mouseX, &mouseButton, &mouseY);
 
-				// wait for character to finish auto track
-				if (autoTrack) {
-					if (isAnimFinished(narratorOvl, narratorIdx, &actorHead, ATP_MOUSE)) {
-						if (autoMsg != -1) {
-							freezeCell(&cellHead, autoOvl, autoMsg, 5, -1, 9998, 0);
+					if (mouseX != oldMouseX && mouseY != oldMouseY) {
+						int objectType;
+						int newCursor1;
+						int newCursor2;
 
-							char* pText = getText(autoMsg, autoOvl);
+						oldMouseX = mouseX;
+						oldMouseY = mouseY;
 
-							if (strlen(pText))
-								userWait = 1;
-						}
+						objectType = findObject(mouseX, mouseY, &newCursor1, &newCursor2);
 
-						changeScriptParamInList(-1, -1, &relHead, 9998, 0);
-						autoTrack = false;
-						enableUser = 1;
-					} else {
-						userEnabled = false;
+						if (objectType == 9) {
+							changeCursor(CURSOR_EXIT);
+						} else if (objectType != -1) {
+							changeCursor(CURSOR_MAGNIFYING_GLASS);
+						} else {
+							changeCursor(CURSOR_WALK);
+						}
 					}
-				} else if (autoMsg != -1) {
-					removeCell(&cellHead, autoOvl, autoMsg, 5, masterScreen);
-					autoMsg = -1;
+				} else {
+					changeCursor(CURSOR_NORMAL);
 				}
+			} else {
+				changeCursor(CURSOR_NORMAL);
 			}
-			// t_end = t_start+SPEED;
-//      t_left=t_start-Osystem_GetTicks()+SPEED;
-#ifndef FASTDEBUG
-			/*    if (t_left>0)
-			 * if (t_left>SLEEP_MIN)
-			 * Osystem_Delay(t_left-SLEEP_GRAN);
-			 * while (Osystem_GetTicks()<t_end){q++;}; */
-#endif
-			manageEvents();
 
-		} while (!playerDontAskQuit && quitValue2 && quitValue != 7);
-	}
+			if (userWait) {
+				int16 mouseButton = 0;
+				checkInput(&mouseButton);
 
-}
+				while (!mouseButton) {
+					manageScripts(&relHead);
+					manageScripts(&procHead);
 
-int oldmain(int argc, char *argv[]) {
-	printf("Cruise for a corpse recode\n");
+					removeFinishedScripts(&relHead);
+					removeFinishedScripts(&procHead);
 
-//  OSystemInit();
-//  osystem = new OSystem;
+					processAnimation();
 
-	printf("Osystem Initialized\n");
+					flip();
 
-	printf("Initializing engine...\n");
+					// not exactly this
+					manageEvents();
 
-	PCFadeFlag = 0;
+					checkInput(&mouseButton);
+				}
 
-	//lowLevelInit();
+				changeScriptParamInList(-1, -1, &procHead, 9999, 0);
+				changeScriptParamInList(-1, -1, &relHead, 9999, 0);
+				userWait = 0;
+			}
 
-	// arg parser stuff
+			// wait for character to finish auto track
+			if (autoTrack) {
+				if (isAnimFinished(narratorOvl, narratorIdx, &actorHead, ATP_MOUSE)) {
+					if (autoMsg != -1) {
+						freezeCell(&cellHead, autoOvl, autoMsg, 5, -1, 9998, 0);
 
-	workBuffer = (uint8 *) mallocAndZero(8192);
+						char* pText = getText(autoMsg, autoOvl);
 
-	/*volVar1 = 0;
-	 * fileData1 = 0; */
+						if (strlen(pText))
+							userWait = 1;
+					}
 
-	/*PAL_fileHandle = -1; */
+					changeScriptParamInList(-1, -1, &relHead, 9998, 0);
+					autoTrack = false;
+					enableUser = 1;
+				} else {
+					userEnabled = false;
+				}
+			} else if (autoMsg != -1) {
+				removeCell(&cellHead, autoOvl, autoMsg, 5, masterScreen);
+				autoMsg = -1;
+			}
+		}
 
-	// video init stuff
+		manageEvents();
 
-	initSystem();
-
-	// another bit of video init
-
-	if (!readVolCnf()) {
-		printf("Fatal: unable to load vol.cnf !\n");
-		return (-1);
-	}
-
-	printf("Entering main loop...\n");
-	mainLoop();
-
-	//freeStuff();
-
-	//freePtr(workBuffer);
-
-	return (0);
+	} while (!playerDontAskQuit && quitValue2 && quitValue != 7);
 }
 
 void *mallocAndZero(int32 size) {

Modified: scummvm/trunk/engines/cruise/gfxModule.cpp
===================================================================
--- scummvm/trunk/engines/cruise/gfxModule.cpp	2009-03-07 06:57:59 UTC (rev 39179)
+++ scummvm/trunk/engines/cruise/gfxModule.cpp	2009-03-07 07:12:10 UTC (rev 39180)
@@ -222,10 +222,6 @@
 	flip();
 }
 
-extern bool bFastMode;
-
-static uint32 lastTick = 0, lastTickDebug = 0;
-
 void flip() {
 	int i;
 	byte paletteRGBA[256 * 4];
@@ -244,24 +240,6 @@
 
 	g_system->copyRectToScreen(globalScreen, 320, 0, 0, 320, 200);
 	g_system->updateScreen();
-
-	uint32 currentTick = g_system->getMillis();
-
-	if (currentTick >= (lastTickDebug + 10)) {
-		lastTickDebug = currentTick;
-
-		if (_vm->getDebugger()->isAttached())
-			_vm->getDebugger()->onFrame();
-	}
-
-	if (!bFastMode) {
-		uint32 speed = 50;
-		if (lastTick + speed > currentTick) {
-			g_system->delayMillis(lastTick + speed - currentTick);
-		}
-	}
-
-	lastTick = g_system->getMillis();
 }
 
 void drawSolidBox(int32 x1, int32 y1, int32 x2, int32 y2, uint8 colour) {

Modified: scummvm/trunk/engines/cruise/mainDraw.cpp
===================================================================
--- scummvm/trunk/engines/cruise/mainDraw.cpp	2009-03-07 06:57:59 UTC (rev 39179)
+++ scummvm/trunk/engines/cruise/mainDraw.cpp	2009-03-07 07:12:10 UTC (rev 39180)
@@ -1181,12 +1181,12 @@
 	}
 }
 
-void drawSprite(int objX1, int var_6, cellStruct *currentObjPtr, char *data1, int objY2, int objX2, char *output, char *data2) {
+void drawSprite(int objX1, int height, cellStruct *currentObjPtr, uint8 *data1, int objY2, int objX2, uint8 *output, uint8 *data2) {
 	int x = 0;
 	int y = 0;
 
 	cellStruct* plWork = currentObjPtr;
-	int workBufferSize = var_6 * (objX1 / 8);
+	int workBufferSize = height * (objX1 / 8);
 
 	unsigned char* workBuf = (unsigned char*)malloc(workBufferSize);
 	memcpy(workBuf, data2, workBufferSize);
@@ -1204,10 +1204,10 @@
 			int maskFrame = params.fileIdx;
 
 			if (filesDatabase[maskFrame].subData.resourceType == OBJ_TYPE_BGMK && filesDatabase[maskFrame].subData.ptrMask) {
-				drawMask(workBuf, objX1 / 8, var_6, filesDatabase[maskFrame].subData.ptrMask, filesDatabase[maskFrame].width / 8, filesDatabase[maskFrame].height, maskX - objX2, maskY - objY2, numPasses++);
+				drawMask(workBuf, objX1 / 8, height, filesDatabase[maskFrame].subData.ptrMask, filesDatabase[maskFrame].width / 8, filesDatabase[maskFrame].height, maskX - objX2, maskY - objY2, numPasses++);
 			} else
 				if (filesDatabase[maskFrame].subData.resourceType == OBJ_TYPE_SPRITE && filesDatabase[maskFrame].subData.ptrMask) {
-					drawMask(workBuf, objX1 / 8, var_6, filesDatabase[maskFrame].subData.ptrMask, filesDatabase[maskFrame].width / 8, filesDatabase[maskFrame].height, maskX - objX2, maskY - objY2, numPasses++);
+					drawMask(workBuf, objX1 / 8, height, filesDatabase[maskFrame].subData.ptrMask, filesDatabase[maskFrame].width / 8, filesDatabase[maskFrame].height, maskX - objX2, maskY - objY2, numPasses++);
 				}
 
 		}
@@ -1215,7 +1215,7 @@
 		plWork = plWork->next;
 	}
 
-	for (y = 0; y < var_6; y++) {
+	for (y = 0; y < height; y++) {
 		for (x = 0; x < (objX1); x++) {
 			uint8 color = (data1[0]);
 			data1++;
@@ -1440,7 +1440,7 @@
 					spriteHeight = filesDatabase[objZ2].height;	// height
 
 					if (filesDatabase[objZ2].subData.ptr) {
-						drawSprite(objX1, spriteHeight, currentObjPtr, (char *)filesDatabase[objZ2].subData.ptr, objY2, objX2, (char *)gfxModuleData.pPage10, (char *)filesDatabase[objZ2].subData.ptrMask);
+						drawSprite(objX1, spriteHeight, currentObjPtr, filesDatabase[objZ2].subData.ptr, objY2, objX2, gfxModuleData.pPage10, filesDatabase[objZ2].subData.ptrMask);
 					}
 				}
 			}

Modified: scummvm/trunk/engines/cruise/mainDraw.h
===================================================================
--- scummvm/trunk/engines/cruise/mainDraw.h	2009-03-07 06:57:59 UTC (rev 39179)
+++ scummvm/trunk/engines/cruise/mainDraw.h	2009-03-07 07:12:10 UTC (rev 39180)
@@ -39,7 +39,7 @@
 void mainDraw(int16 param);
 void flipScreen(void);
 void buildPolyModel(int X, int Y, int scale, char *ptr2, char *destBuffer, char *dataPtr);
-void drawSprite(int objX1, int var_6, cellStruct * currentObjPtr, char *data1, int objY2, int objX2, char *output, char *data2);
+void drawSprite(int objX1, int height, cellStruct *currentObjPtr, uint8 *data1, int objY2, int objX2, uint8 *output, uint8 *data2);
 void flipPoly(int fileId, int16 *dataPtr, int scale, char** newFrame, int X, int Y, int *outX, int *outY, int *outScale);
 void getPolySize(int positionX, int positionY, int scale, int sizeTable[4], unsigned char *dataPtr);
 bool findPoly(char* dataPtr, int x, int y, int zoom, int mouseX, int mouseY);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list