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

dreammaster at users.sourceforge.net dreammaster at users.sourceforge.net
Sun Mar 1 03:19:06 CET 2009


Revision: 38994
          http://scummvm.svn.sourceforge.net/scummvm/?rev=38994&view=rev
Author:   dreammaster
Date:     2009-03-01 02:19:06 +0000 (Sun, 01 Mar 2009)

Log Message:
-----------
Cleaned up parts of the font display system. Note: Cruise used two almost identical routines for text display - one which creates a draw structure, and the other draws directly to the screen. Since there don't seem to be any other differences, the immediate draw version has been changed to use the rendering version and then draw the results

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

Modified: scummvm/trunk/engines/cruise/font.cpp
===================================================================
--- scummvm/trunk/engines/cruise/font.cpp	2009-03-01 02:16:44 UTC (rev 38993)
+++ scummvm/trunk/engines/cruise/font.cpp	2009-03-01 02:19:06 UTC (rev 38994)
@@ -28,6 +28,7 @@
 #include "common/util.h"
 
 #include "cruise/cruise_main.h"
+#include "cruise/mouse.h"
 #include "cruise/staticres.h"
 
 namespace Cruise {
@@ -200,15 +201,13 @@
 	}
 }
 
-void renderWord(const uint8 *fontPtr_Data, uint8 *outBufferPtr,
-                int32 drawPosPixel_X, int32 heightOff, int32 height, int32 param4,
-                int32 stringRenderBufferSize, int32 width, int32 charWidth) {
+void renderWord(const uint8 *fontPtr_Data, uint8 *outBufferPtr, int xOffset, int yOffset,
+                int32 height, int32 param4, int32 stringRenderBufferSize, int32 width, int32 charWidth) {
 	int i;
 	int j;
 	const uint8 *fontPtr_Data2 = fontPtr_Data + height * 2;
 
-	outBufferPtr += heightOff * width * 2;	// param2 = height , param6 = width
-	outBufferPtr += drawPosPixel_X;	// param1 = drawPosPixel_X
+	outBufferPtr += yOffset * width * 2 + xOffset;
 
 	for (i = 0; i < height; i++) {	// y++
 		uint16 bitSet1 = READ_BE_UINT16(fontPtr_Data);
@@ -218,7 +217,7 @@
 		fontPtr_Data2 += sizeof(uint16);
 
 		for (j = 0; j < charWidth; j++) {
-			*outBufferPtr = ((bitSet1 >> 15) & 1) | ((bitSet2 >>14) & 2);
+			*outBufferPtr = ((bitSet1 >> 15) & 1) | ((bitSet2 >> 14) & 2);
 			outBufferPtr++;
 
 			bitSet1 <<= 1;
@@ -279,188 +278,17 @@
 	return counter;
 }
 
-void drawString(int32 x, int32 y, const char *string, uint8 *buffer, uint8 color,
-                int32 inRightBorder_X) {
-	const FontInfo *fontPtr;
-	const FontEntry *fontPtr_Desc;
-	const uint8 *fontPtr_Data;
-	int16 wordSpacingWidth;	// var1
-	int16 wordSpacingHeight;	// var2
-	int32 rightBorder_X;	// param2
-	int32 lineHeight;	// fontProc1result
-	int32 numLines;
-	int32 stringHeight;
-	int32 stringFinished;
-	int32 stringWidth;	// var_1C
-	int32 stringRenderBufferSize;
-	int32 useDynamicBuffer;
-	uint8 *currentStrRenderBuffer;
-	// int32 var_8;                                                         // don't need that on
-	int32 heightOffset;	// var_12
-	int32 renderBufferSize;	// var_1E
-	int needFlip;
+void drawString(int32 x, int32 y, const char *string, uint8 *buffer, uint8 fontColour, int32 rightBorder_X) {
 
-	if (!buffer || !string)
-		return;
+	// Get the rendered text to display
+	gfxEntryStruct *s = renderText(rightBorder_X, string);
 
-	if (fontFileIndex != -1) {
-		fontPtr = (const FontInfo *)filesDatabase[fontFileIndex].subData.ptr;
+	// Draw the message
+	drawMessage(s, x, y, rightBorder_X - x, fontColour, buffer);
 
-		if (!fontPtr) {
-			fontPtr = (const FontInfo *)_systemFNT;
-		}
-	} else {
-		fontPtr = (const FontInfo *)_systemFNT;
-	}
-
-	if (!fontPtr) {
-		return;
-	}
-
-	fontPtr_Desc = (const FontEntry *)((const uint8 *)fontPtr + sizeof(FontInfo));
-	fontPtr_Data = (const uint8 *)fontPtr + FROM_LE_32(fontPtr->offset);
-
-	lineHeight = getLineHeight(FROM_LE_16(fontPtr->numChars), fontPtr_Desc);
-
-	wordSpacingWidth = FROM_LE_16(fontPtr->hSpacing);
-	wordSpacingHeight = FROM_LE_16(fontPtr->vSpacing);
-
-	if (inRightBorder_X > 310) {
-		rightBorder_X = 310;
-	} else {
-		rightBorder_X = inRightBorder_X;
-	}
-	if (x + rightBorder_X > 319) {
-		x = 319 - rightBorder_X;
-	}
-	if (y < 0) {
-		y = 0;
-	}
-	if (x < 0) {
-		x = 0;
-	}
-	numLines = getTextLineCount(rightBorder_X, wordSpacingWidth, fontPtr_Desc, string);	// ok
-
-	if (!numLines) {
-		return;
-	}
-	stringHeight = ((wordSpacingHeight + lineHeight + 2) * numLines) + 1;
-
-	if (y + stringHeight > 199) {
-		y = 200 - stringHeight;
-	}
-	stringFinished = 0;
-	stringWidth = (rightBorder_X / 16) + 2;
-	stringRenderBufferSize = stringWidth * stringHeight * 4;
-	inRightBorder_X = rightBorder_X;
-
-	if (stringRenderBufferSize > 0x2000) {
-		currentStrRenderBuffer =
-		    (uint8 *) mallocAndZero(stringRenderBufferSize);
-
-		if (!currentStrRenderBuffer) {
-			return;
-		}
-		useDynamicBuffer = 1;
-	} else {
-		currentStrRenderBuffer = (uint8 *) workBuffer;
-		useDynamicBuffer = 0;
-	}
-
-	resetRaster(currentStrRenderBuffer, stringRenderBufferSize);
-
-	// var_8        = 0;
-	heightOffset = 0;
-	renderBufferSize = stringRenderBufferSize;
-
-	do {
-		int spacesCount = 0;	// si
-		char character = *(string);
-		short int strPixelLength;	// var_16;
-		const char *ptrStringEnd;	// var_4        //ok
-		int drawPosPixel_X;	// di
-
-		while (character == ' ') {
-			spacesCount++;
-			character = *(string + spacesCount);
-		}
-
-		string += spacesCount;
-		ptrStringEnd = string + prepareWordRender(inRightBorder_X, wordSpacingWidth, &strPixelLength, fontPtr_Desc, string);	//ok
-
-		if (inRightBorder_X > strPixelLength) {
-			drawPosPixel_X =
-			    (inRightBorder_X - strPixelLength) / 2;
-		} else {
-			drawPosPixel_X = 0;
-		}
-		// drawPosPixel_X = var_8;
-
-		do {
-			character = *(string++);
-
-			short int data = fontCharacterTable[(int)character];
-
-			if (character) {
-				if (character == ' ' || character == 0x7D) {
-					drawPosPixel_X += wordSpacingWidth + 5;
-				} else {
-					if (data) {
-						const FontEntry &fe = fontPtr_Desc[data];
-
-						renderWord((const uint8 *)fontPtr_Data + FROM_LE_32(fe.offset),
-						           currentStrRenderBuffer,
-						           drawPosPixel_X,
-								   FROM_LE_16(fe.height2) - FROM_LE_16(fe.charHeight) +
-						           lineHeight + heightOffset,
-								   FROM_LE_16(fe.charHeight),
-								   FROM_LE_16(fe.v1),
-						           renderBufferSize / 2,
-						           stringWidth * 2,
-								   FROM_LE_16(fe.charWidth));
-
-						drawPosPixel_X +=
-						    wordSpacingWidth + FROM_LE_16(fe.charWidth);
-					}
-				}
-			} else {
-				stringFinished = 1;
-			}
-
-			if (ptrStringEnd <= string) {
-				break;
-			}
-
-		} while (!stringFinished);
-
-		// var_8  = 0;
-		heightOffset = wordSpacingHeight + lineHeight;
-
-	} while (!stringFinished);
-
-	needFlip = 0;
-
-	if (buffer == gfxModuleData.pPage00) {
-		if (gfxModuleData.field_1 != 0) {
-			needFlip = 1;
-			gfxModuleData_field_90();
-		}
-
-		gfxModuleData_gfxWaitVSync();
-	}
-
-	gfxModuleData_field_64((char *)currentStrRenderBuffer, stringWidth,
-	                       stringHeight, (char *)buffer, x, y, 0);
-	gfxModuleData_field_64((char *)currentStrRenderBuffer, stringWidth,
-	                       stringHeight, (char *)buffer, x, y, color);
-
-	if (needFlip) {
-		gfxModuleData_flip();
-	}
-
-	if (useDynamicBuffer) {
-		free(currentStrRenderBuffer);
-	}
+	// Free the data
+	delete s->imagePtr;
+	delete s;
 }
 
 // calculates all necessary datas and renders text
@@ -531,7 +359,7 @@
 
 	currentStrRenderBuffer =
 	    (uint8 *) mallocAndZero(stringRenderBufferSize);
-	resetRaster(currentStrRenderBuffer, stringRenderBufferSize);
+	resetBitmap(currentStrRenderBuffer, stringRenderBufferSize);
 
 	generatedGfxEntry = (gfxEntryStruct *) malloc(sizeof(gfxEntryStruct));
 	generatedGfxEntry->imagePtr = currentStrRenderBuffer;

Modified: scummvm/trunk/engines/cruise/font.h
===================================================================
--- scummvm/trunk/engines/cruise/font.h	2009-03-01 02:16:44 UTC (rev 38993)
+++ scummvm/trunk/engines/cruise/font.h	2009-03-01 02:19:06 UTC (rev 38994)
@@ -68,7 +68,7 @@
                 int32 drawPosPixel_X, int32 heightOff, int32 height, int32 param4,
                 int32 stringRenderBufferSize, int32 width, int32 charWidth);
 gfxEntryStruct *renderText(int inRightBorder_X, const char *string);
-void drawString(int32 x, int32 y, const char *string, uint8 * buffer, uint8 color,
+void drawString(int32 x, int32 y, const char *string, uint8 * buffer, uint8 fontColour,
                 int32 inRightBorder_X);
 
 } // End of namespace Cruise

Modified: scummvm/trunk/engines/cruise/gfxModule.cpp
===================================================================
--- scummvm/trunk/engines/cruise/gfxModule.cpp	2009-03-01 02:16:44 UTC (rev 38993)
+++ scummvm/trunk/engines/cruise/gfxModule.cpp	2009-03-01 02:19:06 UTC (rev 38994)
@@ -42,7 +42,6 @@
 int palDirtyMax = -1;
 
 gfxModuleDataStruct gfxModuleData = {
-	0,			// field_1
 	0,			// use Tandy
 	0,			// use EGA
 	1,			// use VGA
@@ -193,25 +192,26 @@
 	*(pOutput++) = B;
 }
 
-void gfxModuleData_field_90(void) {
-}
-
 void gfxModuleData_gfxWaitVSync(void) {
 }
 
 void gfxModuleData_flip(void) {
 }
 
-void gfxModuleData_field_64(char *sourceBuffer, int width, int height, char *dest, int x, int y, int color) {
-	int i;
-	int j;
+void gfxCopyRect(const byte *sourceBuffer, int width, int height, byte *dest, int x, int y, int colour) {
+	int xp, yp;
 
-	x = 0;
-	y = 0;
+	for (yp = 0; yp < height; ++yp) {
+		const uint8 *srcP = &sourceBuffer[yp * width];
+		uint8 *destP = &dest[(y + yp) * 320 + x];
 
-	for (i = 0; i < height; i++) {
-		for (j = 0; j < width; j++) {
-			dest[(y + i) * 320 / 4 + x + j] = sourceBuffer[i * width + j];
+		for (xp = 0; xp < width; ++xp, ++srcP, ++destP) {
+			uint8 v = *srcP;
+			int xDest = x + xp;
+			int yDest = y + yp;
+
+			if ((v != 0) && (xDest >= 0) && (yDest >= 0) && (xDest < 320) && (yDest < 200))
+				*destP = (v == 1) ? 0 : colour;
 		}
 	}
 }
@@ -271,4 +271,10 @@
 	}
 }
 
+void resetBitmap(uint8 *dataPtr, int32 dataSize) {
+	memset(dataPtr, 0, dataSize);
+}
+
+
+
 } // End of namespace Cruise

Modified: scummvm/trunk/engines/cruise/gfxModule.h
===================================================================
--- scummvm/trunk/engines/cruise/gfxModule.h	2009-03-01 02:16:44 UTC (rev 38993)
+++ scummvm/trunk/engines/cruise/gfxModule.h	2009-03-01 02:19:06 UTC (rev 38994)
@@ -29,7 +29,6 @@
 namespace Cruise {
 
 struct gfxModuleDataStruct {
-	int field_1;
 	int useTandy;
 	int useEGA;
 	int useVGA;
@@ -53,7 +52,7 @@
 void gfxModuleData_field_90(void);
 void gfxModuleData_gfxWaitVSync(void);
 void gfxModuleData_flip(void);
-void gfxModuleData_field_64(char *sourceBuffer, int width, int height, char *dest, int x, int y, int color);
+void gfxCopyRect(const byte *sourceBuffer, int width, int height, byte *dest, int x, int y, int colour);
 void gfxModuleData_gfxCopyScreen(char *sourcePtr, char *destPtr);
 void convertGfxFromMode4(uint8 *sourcePtr, int width, int height, uint8 *destPtr);
 void convertGfxFromMode5(uint8 *sourcePtr, int width, int height, uint8 *destPtr);
@@ -63,6 +62,7 @@
 void gfxModuleData_setPal256(uint8 * ptr);
 void flip(void);
 void drawSolidBox(int32 x1, int32 y1, int32 x2, int32 y2, uint8 colour);
+void resetBitmap(uint8 *dataPtr, int32 dataSize);
 
 } // End of namespace Cruise
 

Modified: scummvm/trunk/engines/cruise/mainDraw.cpp
===================================================================
--- scummvm/trunk/engines/cruise/mainDraw.cpp	2009-03-01 02:16:44 UTC (rev 38993)
+++ scummvm/trunk/engines/cruise/mainDraw.cpp	2009-03-01 02:19:06 UTC (rev 38994)
@@ -1132,17 +1132,15 @@
 	buildPolyModel(newX, newY, newScale, (char*)polygonMask, destBuffer, newFrame);
 }
 
-void drawMessage(gfxEntryStruct *pGfxPtr, int globalX, int globalY, int width, int newColor, uint8 *ouputPtr) {
+void drawMessage(const gfxEntryStruct *pGfxPtr, int globalX, int globalY, int width, int newColor, uint8 *ouputPtr) {
 	// this is used for font only
 
 	if (pGfxPtr) {
 		uint8 *initialOuput;
 		uint8 *output;
-		int i;
-		int j;
-		int x;
-		int y;
-		uint8 *ptr = pGfxPtr->imagePtr;
+		int xp, yp;
+		int x, y;
+		const uint8 *ptr = pGfxPtr->imagePtr;
 		int height = pGfxPtr->height;
 
 		if (width > 310)
@@ -1160,13 +1158,12 @@
 
 		initialOuput = ouputPtr + (globalY * 320) + globalX;
 
-		y = globalY;
-		x = globalX;
+		for (yp = 0; yp < height; yp++) {
+			output = initialOuput + 320 * yp;
+			y = globalY + yp;
 
-		for (i = 0; i < height; i++) {
-			output = initialOuput + 320 * i;
-
-			for (j = 0; j < pGfxPtr->width; j++) {
+			for (xp = 0; xp < pGfxPtr->width; xp++) {
+				x = globalX + xp;
 				uint8 color = *(ptr++);
 
 				if (color) {

Modified: scummvm/trunk/engines/cruise/mainDraw.h
===================================================================
--- scummvm/trunk/engines/cruise/mainDraw.h	2009-03-01 02:16:44 UTC (rev 38993)
+++ scummvm/trunk/engines/cruise/mainDraw.h	2009-03-01 02:19:06 UTC (rev 38994)
@@ -45,6 +45,8 @@
 bool findPoly(char* dataPtr, int x, int y, int zoom, int mouseX, int mouseY);
 unsigned char *drawPolyMode2(unsigned char *dataPointer, int linesToDraw);
 void calcRGB(uint8* pColorSrc, uint8* pColorDst, int* offsetTable);
+void drawMessage(const gfxEntryStruct *pGfxPtr, int globalX, int globalY, int width, int newColor, uint8 *ouputPtr);
+
 } // End of namespace Cruise
 
 #endif


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