diff options
author | yinsimei | 2017-06-05 11:49:19 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2017-07-13 18:27:45 +0200 |
commit | 10ff6994ae8a8f6ba1f49d8cf1590762b1ae1be8 (patch) | |
tree | 88ccaea220791535dd3f5629424338c80b0c8a3a | |
parent | 414b3c47146ebcc684fb37bccbbb66ff2ac68e2d (diff) | |
download | scummvm-rg350-10ff6994ae8a8f6ba1f49d8cf1590762b1ae1be8.tar.gz scummvm-rg350-10ff6994ae8a8f6ba1f49d8cf1590762b1ae1be8.tar.bz2 scummvm-rg350-10ff6994ae8a8f6ba1f49d8cf1590762b1ae1be8.zip |
SLUDGE: format code and remove oneliners
31 files changed, 1468 insertions, 1416 deletions
diff --git a/engines/sludge/backdrop.cpp b/engines/sludge/backdrop.cpp index 1079b57d94..24185930a9 100644 --- a/engines/sludge/backdrop.cpp +++ b/engines/sludge/backdrop.cpp @@ -251,11 +251,11 @@ void killParallax() { bool reserveBackdrop() { cameraX = 0; cameraY = 0; - input.mouseX = (int) ((float) input.mouseX * cameraZoom); - input.mouseY = (int) ((float) input.mouseY * cameraZoom); + input.mouseX = (int)((float)input.mouseX * cameraZoom); + input.mouseY = (int)((float)input.mouseY * cameraZoom); cameraZoom = 1.0; - input.mouseX = (int) ((float) input.mouseX / cameraZoom); - input.mouseY = (int) ((float) input.mouseY / cameraZoom); + input.mouseX = (int)((float)input.mouseX / cameraZoom); + input.mouseY = (int)((float)input.mouseY / cameraZoom); setPixelCoords(false); int picWidth = sceneWidth; int picHeight = sceneHeight; @@ -317,9 +317,7 @@ void loadBackDrop(int fileNum, int x, int y) { if (!loadHSI(bigDataFile, x, y, false)) { char mess[200]; - sprintf(mess, - "Can't paste overlay image outside scene dimensions\n\nX = %i\nY = %i\nWidth = %i\nHeight = %i", - x, y, sceneWidth, sceneHeight); + sprintf(mess, "Can't paste overlay image outside scene dimensions\n\nX = %i\nY = %i\nWidth = %i\nHeight = %i", x, y, sceneWidth, sceneHeight); fatal(mess); } @@ -348,10 +346,10 @@ void blankScreen(int x1, int y1, int x2, int y2) { y1 = 0; if (x1 < 0) x1 = 0; - if (x2 > (int) sceneWidth) - x2 = (int) sceneWidth; - if (y2 > (int) sceneHeight) - y2 = (int) sceneHeight; + if (x2 > (int)sceneWidth) + x2 = (int)sceneWidth; + if (y2 > (int)sceneHeight) + y2 = (int)sceneHeight; int picWidth = x2 - x1; int picHeight = y2 - y1; @@ -467,13 +465,11 @@ void darkScreen() { int xoffset = 0; while (xoffset < sceneWidth) { - int w = (sceneWidth - xoffset < viewportWidth) ? - sceneWidth - xoffset : viewportWidth; + int w = (sceneWidth - xoffset < viewportWidth) ? sceneWidth - xoffset : viewportWidth; int yoffset = 0; while (yoffset < sceneHeight) { - int h = (sceneHeight - yoffset < viewportHeight) ? - sceneHeight - yoffset : viewportHeight; + int h = (sceneHeight - yoffset < viewportHeight) ? sceneHeight - yoffset : viewportHeight; // Render the scene - first the old backdrop #if 0 @@ -533,8 +529,7 @@ void darkScreen() { } inline int sortOutPCamera(int cX, int fX, int sceneMax, int boxMax) { - return (fX == 65535) ? - (sceneMax ? ((cX * boxMax) / sceneMax) : 0) : ((cX * fX) / 100); + return (fX == 65535) ? (sceneMax ? ((cX * boxMax) / sceneMax) : 0) : ((cX * fX) / 100); } void drawBackDrop() { @@ -624,7 +619,8 @@ void drawBackDrop() { bool loadLightMap(int v) { setResourceForFatal(v); - if (!openFileFromNum(v)) return fatal("Can't open light map."); + if (!openFileFromNum(v)) + return fatal("Can't open light map."); killLightMap(); lightMapNumber = v; @@ -714,10 +710,12 @@ void reloadParallaxTextures() { bool loadParallax(unsigned short v, unsigned short fracX, unsigned short fracY) { setResourceForFatal(v); - if (!openFileFromNum(v)) return fatal("Can't open parallax image"); + if (!openFileFromNum(v)) + return fatal("Can't open parallax image"); parallaxLayer *nP = new parallaxLayer; - if (!checkNew(nP)) return false; + if (!checkNew(nP)) + return false; nP->next = parallaxStuff; parallaxStuff = nP; @@ -924,15 +922,15 @@ bool loadHSI(Common::SeekableReadStream *stream, int x, int y, bool reserve) { int realPicHeight = backdropSurface.h; if (reserve) { // resize backdrop - if (!resizeBackdrop(realPicWidth, realPicHeight)) return false; + if (!resizeBackdrop(realPicWidth, realPicHeight)) + return false; } if (x == IN_THE_CENTRE) x = (sceneWidth - realPicWidth) >> 1; if (y == IN_THE_CENTRE) y = (sceneHeight - realPicHeight) >> 1; - if (x < 0 || x + realPicWidth > sceneWidth || y < 0 - || y + realPicHeight > sceneHeight) { + if (x < 0 || x + realPicWidth > sceneWidth || y < 0 || y + realPicHeight > sceneHeight) { debug(kSludgeDebugGraphics, "Illegal back drop size"); return false; } @@ -957,9 +955,12 @@ bool mixHSI(Common::SeekableReadStream *stream, int x, int y) { int realPicWidth = backdropSurface.w; int realPicHeight = backdropSurface.h; - if (x == IN_THE_CENTRE) x = (sceneWidth - realPicWidth) >> 1; - if (y == IN_THE_CENTRE) y = (sceneHeight - realPicHeight) >> 1; - if (x < 0 || x + realPicWidth > sceneWidth || y < 0 || y + realPicHeight > sceneHeight) return false; + if (x == IN_THE_CENTRE) + x = (sceneWidth - realPicWidth) >> 1; + if (y == IN_THE_CENTRE) + y = (sceneHeight - realPicHeight) >> 1; + if (x < 0 || x + realPicWidth > sceneWidth || y < 0 || y + realPicHeight > sceneHeight) + return false; #if 0 float btx1, tx1; float btx2, tx2; @@ -1160,27 +1161,22 @@ void saveCorePNG(Common::WriteStream *stream, GLuint texture, int w, int h) { #endif } #endif - #if 0 void saveCoreHSI(Common::WriteStream *stream, GLuint texture, int w, int h) { GLint tw, th; glBindTexture(GL_TEXTURE_2D, texture); getTextureDimensions(texture, &tw, &th); - GLushort *image = new GLushort [tw * th]; - if (!checkNew(image)) return; + GLushort *image = new GLushort[tw * th]; + if (!checkNew(image)) + return; glPixelStorei(GL_PACK_ALIGNMENT, 1); // glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, image); setPixelCoords(true); //glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - const GLfloat texCoords[] = { - 0.0f, 0.0f, - 1.0f, 0.0f, - 0.0f, 1.0f, - 1.0f, 1.0f - }; + const GLfloat texCoords[] = { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f }; int xoffset = 0; while (xoffset < tw) { @@ -1189,13 +1185,9 @@ void saveCoreHSI(Common::WriteStream *stream, GLuint texture, int w, int h) { int yoffset = 0; while (yoffset < th) { int h = (th - yoffset < viewportHeight) ? th - yoffset : viewportHeight; - glClear(GL_COLOR_BUFFER_BIT); // Clear The Screen - const GLfloat vertices[] = { - (GLfloat) - xoffset, (GLfloat) - yoffset, 0., - (GLfloat)w - xoffset, (GLfloat) - yoffset, 0., - (GLfloat) - xoffset, (GLfloat) - yoffset + h, 0., - (GLfloat)w - xoffset, (GLfloat) - yoffset + h, 0. - }; + glClear (GL_COLOR_BUFFER_BIT); // Clear The Screen + const GLfloat vertices[] = { (GLfloat)-xoffset, (GLfloat)-yoffset, 0., (GLfloat)w - xoffset, (GLfloat)-yoffset, 0., (GLfloat)-xoffset, (GLfloat)-yoffset + h, 0., (GLfloat)w - xoffset, + (GLfloat)-yoffset + h, 0. }; glUseProgram(shader.texture); setPMVMatrix(shader.texture); @@ -1203,7 +1195,7 @@ void saveCoreHSI(Common::WriteStream *stream, GLuint texture, int w, int h) { glUseProgram(0); for (int i = 0; i < h; i++) { - glReadPixels(viewportOffsetX, viewportOffsetY + i, w, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, image + xoffset + (yoffset + i)*tw); + glReadPixels(viewportOffsetX, viewportOffsetY + i, w, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, image + xoffset + (yoffset + i) * tw); } yoffset += viewportHeight; } @@ -1214,32 +1206,34 @@ void saveCoreHSI(Common::WriteStream *stream, GLuint texture, int w, int h) { setPixelCoords(false); int x, y, lookAhead; - unsigned short int *fromHere, * lookPointer; + unsigned short int *fromHere, *lookPointer; stream->writeUint16BE(w); stream->writeUint16BE(h); - for (y = 0; y < h; y ++) { + for (y = 0; y < h; y++) { fromHere = image + (y * tw); x = 0; while (x < w) { lookPointer = fromHere + 1; - for (lookAhead = x + 1; lookAhead < w; lookAhead ++) { - if (lookAhead - x == 256) break; - if (* fromHere != * lookPointer) break; - lookPointer ++; + for (lookAhead = x + 1; lookAhead < w; lookAhead++) { + if (lookAhead - x == 256) + break; + if (*fromHere != *lookPointer) + break; + lookPointer++; } if (lookAhead == x + 1) { - put2bytes((* fromHere) & 65503, stream); + put2bytes((*fromHere) & 65503, stream); } else { - stream->writeUint16BE(* fromHere | 32); + stream->writeUint16BE(*fromHere | 32); stream->writeByte(lookAhead - x - 1); } fromHere = lookPointer; x = lookAhead; } } - delete [] image; + delete[] image; image = NULL; } #endif diff --git a/engines/sludge/bg_effects.cpp b/engines/sludge/bg_effects.cpp index 9c8bcb304b..3692026452 100644 --- a/engines/sludge/bg_effects.cpp +++ b/engines/sludge/bg_effects.cpp @@ -64,14 +64,14 @@ static int s_matrixEffectBase = 15; static int s_matrixEffectDivide = 4; static int s_matrixEffectWidth = 3; static int s_matrixEffectHeight = 3; -static int s_matrixEffectData[9] = { -2, -1, 0, -1, 1, 1, 0, 1, 2}; +static int s_matrixEffectData[9] = {-2, -1, 0, -1, 1, 1, 0, 1, 2}; static int s_matrixEffectBase = 16; #elif 0 // Standard emboss static int s_matrixEffectDivide = 2; static int s_matrixEffectWidth = 3; static int s_matrixEffectHeight = 3; -static int s_matrixEffectData[9] = { -1, 0, 0, 0, 0, 0, 0, 0, 1}; +static int s_matrixEffectData[9] = {-1, 0, 0, 0, 0, 0, 0, 0, 1}; static int s_matrixEffectBase = 128; #elif 0 // Horizontal blur @@ -92,7 +92,7 @@ static int s_matrixEffectBase = 0; static int s_matrixEffectDivide = 1; static int s_matrixEffectWidth = 1; static int s_matrixEffectHeight = 1; -static int s_matrixEffectData[9] = { -1}; +static int s_matrixEffectData[9] = {-1}; static int s_matrixEffectBase = 255; #elif 0 // Fog @@ -136,7 +136,7 @@ static int *blur_allocateMemoryForEffect() { s_matrixEffectData = NULL; if (s_matrixEffectWidth && s_matrixEffectHeight) { - s_matrixEffectData = (int *) malloc(sizeof(int) * s_matrixEffectHeight * s_matrixEffectWidth); + s_matrixEffectData = (int *)malloc(sizeof(int) * s_matrixEffectHeight * s_matrixEffectWidth); checkNew(s_matrixEffectData); } return s_matrixEffectData; @@ -169,7 +169,7 @@ bool blur_createSettings(int numParams, variableStack *&stack) { int width = 0; variableStack *justToCheckSizes = stack; - for (int a = 0; a < height; a ++) { + for (int a = 0; a < height; a++) { if (justToCheckSizes->thisVar.varType != SVT_STACK) { error = "Third and subsequent parameters in setBackgroundEffect should be arrays"; break; @@ -189,19 +189,19 @@ bool blur_createSettings(int numParams, variableStack *&stack) { } } - if (width == 0 && ! error) { + if (width == 0 && !error) { error = "Empty arrays found in setBackgroundEffect parameters"; } - if (! error) { + if (!error) { s_matrixEffectWidth = width; s_matrixEffectHeight = height; if (blur_allocateMemoryForEffect()) { - for (int y = height - 1; y >= 0; y --) { + for (int y = height - 1; y >= 0; y--) { variableStack *eachNumber = stack->thisVar.varData.theStack->first; - if (! error) { - for (int x = 0; x < width; x ++) { + if (!error) { + for (int x = 0; x < width; x++) { int arraySlot = x + (y * width); // s_matrixEffectData[arraySlot] = (rand() % 4); if (!getValueType(s_matrixEffectData[arraySlot], SVT_INT, eachNumber->thisVar)) { @@ -213,13 +213,13 @@ bool blur_createSettings(int numParams, variableStack *&stack) { trimStack(stack); } } - if (! error && !getValueType(s_matrixEffectDivide, SVT_INT, stack -> thisVar)) + if (!error && !getValueType(s_matrixEffectDivide, SVT_INT, stack->thisVar)) error = ""; trimStack(stack); - if (! error && !getValueType(s_matrixEffectBase, SVT_INT, stack -> thisVar)) + if (!error && !getValueType(s_matrixEffectBase, SVT_INT, stack->thisVar)) error = ""; trimStack(stack); - if (! error) { + if (!error) { if (s_matrixEffectDivide) { createNullThing = false; } else { @@ -249,7 +249,7 @@ bool blur_createSettings(int numParams, variableStack *&stack) { fatal(error); } - return ! createNullThing; + return !createNullThing; } static inline int clampi(int i, int min, int max) { @@ -260,13 +260,13 @@ static inline void blur_createSourceLine(unsigned char *createLine, unsigned cha int miniX; memcpy(createLine + overlapOnLeft * 4, fromLine, width * 4); - for (miniX = 0; miniX < overlapOnLeft; miniX ++) { + for (miniX = 0; miniX < overlapOnLeft; miniX++) { createLine[miniX * 4] = fromLine[0]; createLine[miniX * 4 + 1] = fromLine[1]; createLine[miniX * 4 + 2] = fromLine[2]; } - for (miniX = width + overlapOnLeft; miniX < width + s_matrixEffectWidth - 1; miniX ++) { + for (miniX = width + overlapOnLeft; miniX < width + s_matrixEffectWidth - 1; miniX++) { createLine[miniX * 4] = fromLine[width * 4 - 4]; createLine[miniX * 4 + 1] = fromLine[width * 4 - 3]; createLine[miniX * 4 + 2] = fromLine[width * 4 - 2]; @@ -280,15 +280,16 @@ bool blurScreen() { int y, x; bool ok = true; int overlapOnLeft = s_matrixEffectWidth / 2; - int overlapAbove = s_matrixEffectHeight / 2; + int overlapAbove = s_matrixEffectHeight / 2; unsigned char **sourceLine = new unsigned char *[s_matrixEffectHeight]; - if (! checkNew(sourceLine)) return false; + if (!checkNew(sourceLine)) + return false; int picWidth = sceneWidth; int picHeight = sceneHeight; - if (! NPOT_textures) { + if (!NPOT_textures) { picWidth = getNextPOT(sceneWidth); picHeight = getNextPOT(sceneHeight); } @@ -296,26 +297,26 @@ bool blurScreen() { // Retrieve the texture saveTexture(backdropTextureName, backdropTexture); - for (y = 0; y < s_matrixEffectHeight; y ++) { + for (y = 0; y < s_matrixEffectHeight; y++) { sourceLine[y] = new unsigned char[(s_matrixEffectWidth - 1 + picWidth) * 4]; ok &= (sourceLine[y] != NULL); } if (ok) { - for (y = 0; y < s_matrixEffectHeight; y ++) { + for (y = 0; y < s_matrixEffectHeight; y++) { int miniY = clampi(y - overlapAbove - 1, 0, sceneHeight - 1); blur_createSourceLine(sourceLine[y], backdropTexture + miniY * picWidth * 4, overlapOnLeft, picWidth); } - for (y = 0; y < sceneHeight; y ++) { + for (y = 0; y < sceneHeight; y++) { thisLine = backdropTexture + y * picWidth * 4; //------------------------- // Scroll source lines //------------------------- unsigned char *tempLine = sourceLine[0]; - for (int miniY = 0; miniY < s_matrixEffectHeight - 1; miniY ++) { + for (int miniY = 0; miniY < s_matrixEffectHeight - 1; miniY++) { sourceLine[miniY] = sourceLine[miniY + 1]; } sourceLine[s_matrixEffectHeight - 1] = tempLine; @@ -325,19 +326,19 @@ bool blurScreen() { blur_createSourceLine(sourceLine[h], backdropTexture + miniY * picWidth * 4, overlapOnLeft, picWidth); } - for (x = 0; x < sceneWidth; x ++) { + for (x = 0; x < sceneWidth; x++) { int totalRed = 0; int totalGreen = 0; int totalBlue = 0; int *matrixElement = s_matrixEffectData; - for (int miniY = 0; miniY < s_matrixEffectHeight; ++ miniY) { - unsigned char *pixel = & sourceLine[miniY][x * 4]; - for (int miniX = 0; miniX < s_matrixEffectWidth; ++ miniX) { - - totalRed += pixel[0] * * matrixElement; - totalGreen += pixel[1] * * matrixElement; - totalBlue += pixel[2] * * matrixElement; - ++ matrixElement; + for (int miniY = 0; miniY < s_matrixEffectHeight; ++miniY) { + unsigned char *pixel = &sourceLine[miniY][x * 4]; + for (int miniX = 0; miniX < s_matrixEffectWidth; ++miniX) { + + totalRed += pixel[0] * *matrixElement; + totalGreen += pixel[1] * *matrixElement; + totalBlue += pixel[2] * *matrixElement; + ++matrixElement; pixel += 4; } } @@ -350,19 +351,19 @@ bool blurScreen() { totalBlue = (totalBlue + s_matrixEffectDivide / 2) / s_matrixEffectDivide + s_matrixEffectBase; totalBlue = (totalBlue < 0) ? 0 : ((totalBlue > 255) ? 255 : totalBlue); - * thisLine = totalRed; - ++ thisLine; - * thisLine = totalGreen; - ++ thisLine; - * thisLine = totalBlue; - ++ thisLine; -// * thisLine = totalAlpha; - ++ thisLine; + *thisLine = totalRed; + ++thisLine; + *thisLine = totalGreen; + ++thisLine; + *thisLine = totalBlue; + ++thisLine; +// *thisLine = totalAlpha; + ++thisLine; } } } - for (y = 0; y < s_matrixEffectHeight; y ++) { + for (y = 0; y < s_matrixEffectHeight; y++) { delete sourceLine[y]; } delete sourceLine; diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp index 5eb52f9d07..58926b20d6 100644 --- a/engines/sludge/builtin.cpp +++ b/engines/sludge/builtin.cpp @@ -125,37 +125,38 @@ int paramNum[] = { -1, 0, 1, 1, -1, -1, 1, 3, 4, 1, 0, 0, 8, -1, // SAY->MOVE }; bool failSecurityCheck(char *fn) { - if (fn == NULL) return true; + if (fn == NULL) + return true; int a = 0; while (fn[a]) { switch (fn[a]) { - case ':': - case '\\': - case '/': - case '*': - case '?': - case '"': - case '<': - case '>': - case '|': - fatal("Filenames may not contain the following characters: \n\n\\ / : \" < > | ? *\n\nConsequently, the following filename is not allowed:", fn); - return true; + case ':': + case '\\': + case '/': + case '*': + case '?': + case '"': + case '<': + case '>': + case '|': + fatal("Filenames may not contain the following characters: \n\n\\ / : \" < > | ? *\n\nConsequently, the following filename is not allowed:", fn); + return true; } - a ++; + a++; } return false; } loadedFunction *saverFunc; -typedef builtReturn(* builtInSludgeFunc)(int numParams, loadedFunction *fun); +typedef builtReturn (*builtInSludgeFunc)(int numParams, loadedFunction *fun); struct builtInFunctionData { builtInSludgeFunc func; }; -#define builtIn(a) static builtReturn builtIn_ ## a (int numParams, loadedFunction * fun) +#define builtIn(a) static builtReturn builtIn_ ## a (int numParams, loadedFunction *fun) #define UNUSEDALL (void) (0 && sizeof(numParams) && sizeof (fun)); static builtReturn sayCore(int numParams, loadedFunction *fun, bool sayIt) { @@ -165,24 +166,27 @@ static builtReturn sayCore(int numParams, loadedFunction *fun, bool sayIt) { killSpeechTimers(); switch (numParams) { - case 3: - if (!getValueType(fileNum, SVT_FILE, fun->stack->thisVar)) return BR_ERROR; - trimStack(fun->stack); - // No break; here + case 3: + if (!getValueType(fileNum, SVT_FILE, fun->stack->thisVar)) + return BR_ERROR; + trimStack(fun->stack); + // No break; here - case 2: - newText = getTextFromAnyVar(fun->stack->thisVar); - if (!newText) return BR_ERROR; - trimStack(fun->stack); - if (!getValueType(objT, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; - trimStack(fun->stack); - p = wrapSpeech(newText, objT, fileNum, sayIt); - fun->timeLeft = p; - //debugOut ("BUILTIN: sayCore: %s (%i)\n", newText, p); - fun->isSpeech = true; - delete newText; - newText = NULL; - return BR_KEEP_AND_PAUSE; + case 2: + newText = getTextFromAnyVar(fun->stack->thisVar); + if (!newText) + return BR_ERROR; + trimStack(fun->stack); + if (!getValueType(objT, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; + trimStack(fun->stack); + p = wrapSpeech(newText, objT, fileNum, sayIt); + fun->timeLeft = p; + //debugOut ("BUILTIN: sayCore: %s (%i)\n", newText, p); + fun->isSpeech = true; + delete newText; + newText = NULL; + return BR_KEEP_AND_PAUSE; } fatal("Function should have either 2 or 3 parameters"); @@ -264,18 +268,21 @@ builtIn(getStatusText) { builtIn(getMatchingFiles) { UNUSEDALL char *newText = getTextFromAnyVar(fun->stack->thisVar); - if (!newText) return BR_ERROR; + if (!newText) + return BR_ERROR; trimStack(fun->stack); unlinkVar(fun->reg); // Return value fun->reg.varType = SVT_STACK; fun->reg.varData.theStack = new stackHandler; - if (!checkNew(fun->reg.varData.theStack)) return BR_ERROR; + if (!checkNew(fun->reg.varData.theStack)) + return BR_ERROR; fun->reg.varData.theStack->first = NULL; fun->reg.varData.theStack->last = NULL; fun->reg.varData.theStack->timesUsed = 1; - if (!getSavedGamesStack(fun->reg.varData.theStack, newText)) return BR_ERROR; + if (!getSavedGamesStack(fun->reg.varData.theStack, newText)) + return BR_ERROR; delete newText; newText = NULL; return BR_CONTINUE; @@ -293,7 +300,8 @@ builtIn(saveGame) { char *aaaaa = encodeFilename(loadNow); delete[] loadNow; - if (failSecurityCheck(aaaaa)) return BR_ERROR; // Won't fail if encoded, how cool is that? OK, not very. + if (failSecurityCheck(aaaaa)) + return BR_ERROR; // Won't fail if encoded, how cool is that? OK, not very. loadNow = joinStrings(":", aaaaa); delete[] aaaaa; @@ -309,7 +317,8 @@ builtIn(fileExists) { trimStack(fun->stack); char *aaaaa = encodeFilename(loadNow); delete loadNow; - if (failSecurityCheck(aaaaa)) return BR_ERROR; + if (failSecurityCheck(aaaaa)) + return BR_ERROR; #if 0 FILE *fp = fopen(aaaaa, "rb"); if (!fp) { @@ -328,11 +337,11 @@ builtIn(fileExists) { } #endif // Return value - setVariable(fun->reg, SVT_INT, 0/*(fp != NULL)*/);//TODO:false value + setVariable(fun->reg, SVT_INT, 0/*(fp != NULL)*/); //TODO:false value #if 0 - if (fp) fclose(fp); - delete[] aaaaa; - loadNow = NULL; + if (fp) fclose(fp); + delete[] aaaaa; + loadNow = NULL; #endif return BR_CONTINUE; } @@ -347,7 +356,8 @@ builtIn(loadGame) { if (frozenStuff) { fatal("Can't load a saved game while the engine is frozen"); } - if (failSecurityCheck(loadNow)) return BR_ERROR; + if (failSecurityCheck(loadNow)) + return BR_ERROR; Common::File fd; if (fd.open(loadNow)) { fd.close(); @@ -372,13 +382,17 @@ builtIn(blankScreen) { builtIn(blankArea) { UNUSEDALL int x1, y1, x2, y2; - if (!getValueType(y2, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(y2, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(x2, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(x2, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(y1, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(y1, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(x1, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(x1, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); blankScreen(x1, y1, x2, y2); return BR_CONTINUE; @@ -393,11 +407,14 @@ builtIn(darkBackground) { builtIn(addOverlay) { UNUSEDALL int fileNumber, xPos, yPos; - if (!getValueType(yPos, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(yPos, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(xPos, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(xPos, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); loadBackDrop(fileNumber, xPos, yPos); return BR_CONTINUE; @@ -406,11 +423,14 @@ builtIn(addOverlay) { builtIn(mixOverlay) { UNUSEDALL int fileNumber, xPos, yPos; - if (!getValueType(yPos, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(yPos, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(xPos, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(xPos, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); mixBackDrop(fileNumber, xPos, yPos); return BR_CONTINUE; @@ -419,13 +439,16 @@ builtIn(mixOverlay) { builtIn(pasteImage) { UNUSEDALL int x, y; - if (!getValueType(y, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(y, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(x, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(x, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); personaAnimation *pp = getAnimationFromVar(fun->stack->thisVar); trimStack(fun->stack); - if (pp == NULL) return BR_CONTINUE; + if (pp == NULL) + return BR_CONTINUE; pasteCursor(x, y, pp); return BR_CONTINUE; @@ -437,9 +460,11 @@ builtIn(pasteImage) { builtIn(setSceneDimensions) { UNUSEDALL int x, y; - if (!getValueType(y, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(y, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(x, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(x, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); if (killResizeBackdrop(x, y)) { blankScreen(0, 0, x, y); @@ -451,35 +476,42 @@ builtIn(setSceneDimensions) { builtIn(aimCamera) { UNUSEDALL - if (!getValueType(cameraY, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(cameraY, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(cameraX, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(cameraX, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); cameraX -= (float)(winWidth >> 1) / cameraZoom; cameraY -= (float)(winHeight >> 1) / cameraZoom; - if (cameraX < 0) cameraX = 0; - else if (cameraX > sceneWidth - (float)winWidth / cameraZoom) cameraX = sceneWidth - (float)winWidth / cameraZoom; - if (cameraY < 0) cameraY = 0; - else if (cameraY > sceneHeight - (float)winHeight / cameraZoom) cameraY = sceneHeight - (float)winHeight / cameraZoom; + if (cameraX < 0) + cameraX = 0; + else if (cameraX > sceneWidth - (float)winWidth / cameraZoom) + cameraX = sceneWidth - (float)winWidth / cameraZoom; + if (cameraY < 0) + cameraY = 0; + else if (cameraY > sceneHeight - (float)winHeight / cameraZoom) + cameraY = sceneHeight - (float)winHeight / cameraZoom; return BR_CONTINUE; } - builtIn(zoomCamera) { UNUSEDALL int z; - if (!getValueType(z, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(z, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); input.mouseX = input.mouseX * cameraZoom; input.mouseY = input.mouseY * cameraZoom; - - cameraZoom = (float) z * 0.01; - if ((float) winWidth / cameraZoom > sceneWidth) cameraZoom = (float)winWidth / sceneWidth; - if ((float) winHeight / cameraZoom > sceneHeight) cameraZoom = (float)winHeight / sceneHeight; + cameraZoom = (float)z * 0.01; + if ((float)winWidth / cameraZoom > sceneWidth) + cameraZoom = (float)winWidth / sceneWidth; + if ((float)winHeight / cameraZoom > sceneHeight) + cameraZoom = (float)winHeight / sceneHeight; setPixelCoords(false); input.mouseX = input.mouseX / cameraZoom; @@ -491,7 +523,6 @@ builtIn(zoomCamera) { #pragma mark - #pragma mark Variables - builtIn(pickOne) { UNUSEDALL if (!numParams) { @@ -505,8 +536,9 @@ builtIn(pickOne) { #endif // Return value - while (numParams --) { - if (i == numParams) copyVariable(fun->stack->thisVar, fun->reg); + while (numParams--) { + if (i == numParams) + copyVariable(fun->stack->thisVar, fun->reg); trimStack(fun->stack); } return BR_CONTINUE; @@ -520,9 +552,11 @@ builtIn(substring) { //debugOut ("BUILTIN: substring\n"); - if (!getValueType(length, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(length, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(start, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(start, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); wholeString = getTextFromAnyVar(fun->stack->thisVar); trimStack(fun->stack); @@ -569,12 +603,14 @@ builtIn(newStack) { // Return value fun->reg.varType = SVT_STACK; fun->reg.varData.theStack = new stackHandler; - if (!checkNew(fun->reg.varData.theStack)) return BR_ERROR; + if (!checkNew(fun->reg.varData.theStack)) + return BR_ERROR; fun->reg.varData.theStack->first = NULL; fun->reg.varData.theStack->last = NULL; fun->reg.varData.theStack->timesUsed = 1; - while (numParams --) { - if (!addVarToStack(fun->stack->thisVar, fun->reg.varData.theStack->first)) return BR_ERROR; + while (numParams--) { + if (!addVarToStack(fun->stack->thisVar, fun->reg.varData.theStack->first)) + return BR_ERROR; if (fun->reg.varData.theStack->last == NULL) { fun->reg.varData.theStack->last = fun->reg.varData.theStack->first; } @@ -589,20 +625,20 @@ builtIn(newStack) { builtIn(stackSize) { UNUSEDALL switch (fun->stack->thisVar.varType) { - case SVT_STACK: - // Return value - setVariable(fun->reg, SVT_INT, stackSize(fun->stack->thisVar.varData.theStack)); - trimStack(fun->stack); - return BR_CONTINUE; + case SVT_STACK: + // Return value + setVariable(fun->reg, SVT_INT, stackSize(fun->stack->thisVar.varData.theStack)); + trimStack(fun->stack); + return BR_CONTINUE; - case SVT_FASTARRAY: - // Return value - setVariable(fun->reg, SVT_INT, fun->stack->thisVar.varData.fastArray->size); - trimStack(fun->stack); - return BR_CONTINUE; + case SVT_FASTARRAY: + // Return value + setVariable(fun->reg, SVT_INT, fun->stack->thisVar.varData.fastArray->size); + trimStack(fun->stack); + return BR_CONTINUE; - default: - break; + default: + break; } fatal("Parameter isn't a stack or a fast array."); return BR_ERROR; @@ -615,7 +651,8 @@ builtIn(copyStack) { return BR_ERROR; } // Return value - if (!copyStack(fun->stack->thisVar, fun->reg)) return BR_ERROR; + if (!copyStack(fun->stack->thisVar, fun->reg)) + return BR_ERROR; trimStack(fun->stack); return BR_CONTINUE; } @@ -651,8 +688,7 @@ builtIn(enqueue) { fun->stack->next->thisVar.varData.theStack->last = fun->stack->next->thisVar.varData.theStack->first; } else { - if (!addVarToStack(fun->stack->thisVar, - fun->stack->next->thisVar.varData.theStack->last->next)) + if (!addVarToStack(fun->stack->thisVar, fun->stack->next->thisVar.varData.theStack->last->next)) return BR_ERROR; fun->stack->next->thisVar.varData.theStack->last = fun->stack->next->thisVar.varData.theStack->last->next; } @@ -670,9 +706,7 @@ builtIn(deleteFromStack) { } // Return value - setVariable(fun->reg, SVT_INT, - deleteVarFromStack(fun->stack->thisVar, - fun->stack->next->thisVar.varData.theStack->first, false)); + setVariable(fun->reg, SVT_INT, deleteVarFromStack(fun->stack->thisVar, fun->stack->next->thisVar.varData.theStack->first, false)); // Horrible hacking because 'last' value might now be wrong! fun->stack->next->thisVar.varData.theStack->last = stackFindLast(fun->stack->next->thisVar.varData.theStack->first); @@ -690,9 +724,7 @@ builtIn(deleteAllFromStack) { } // Return value - setVariable(fun->reg, SVT_INT, - deleteVarFromStack(fun->stack->thisVar, - fun->stack->next->thisVar.varData.theStack->first, true)); + setVariable(fun->reg, SVT_INT, deleteVarFromStack(fun->stack->thisVar, fun->stack->next->thisVar.varData.theStack->first, true)); // Horrible hacking because 'last' value might now be wrong! fun->stack->next->thisVar.varData.theStack->last = stackFindLast(fun->stack->next->thisVar.varData.theStack->first); @@ -762,17 +794,21 @@ builtIn(random) { return BR_ERROR; trimStack(fun->stack); - if (num <= 0) num = 1; + if (num <= 0) + num = 1; setVariable(fun->reg, SVT_INT, 0 /*rand() % num*/); //TODO:false value return BR_CONTINUE; } static bool getRGBParams(int &red, int &green, int &blue, loadedFunction *fun) { - if (!getValueType(blue, SVT_INT, fun->stack->thisVar)) return false; + if (!getValueType(blue, SVT_INT, fun->stack->thisVar)) + return false; trimStack(fun->stack); - if (!getValueType(green, SVT_INT, fun->stack->thisVar)) return false; + if (!getValueType(green, SVT_INT, fun->stack->thisVar)) + return false; trimStack(fun->stack); - if (!getValueType(red, SVT_INT, fun->stack->thisVar)) return false; + if (!getValueType(red, SVT_INT, fun->stack->thisVar)) + return false; trimStack(fun->stack); return true; } @@ -784,7 +820,7 @@ builtIn(setStatusColour) { if (!getRGBParams(red, green, blue, fun)) return BR_ERROR; - statusBarColour((byte) red, (byte) green, (byte) blue); + statusBarColour((byte)red, (byte)green, (byte)blue); return BR_CONTINUE; } @@ -795,7 +831,7 @@ builtIn(setLitStatusColour) { if (!getRGBParams(red, green, blue, fun)) return BR_ERROR; - statusBarLitColour((byte) red, (byte) green, (byte) blue); + statusBarLitColour((byte)red, (byte)green, (byte)blue); return BR_CONTINUE; } @@ -806,7 +842,7 @@ builtIn(setPasteColour) { if (!getRGBParams(red, green, blue, fun)) return BR_ERROR; - setFontColour(pastePalette, (byte) red, (byte) green, (byte) blue); + setFontColour(pastePalette, (byte)red, (byte)green, (byte)blue); return BR_CONTINUE; } @@ -836,21 +872,24 @@ builtIn(setBurnColour) { return BR_CONTINUE; } - builtIn(setFont) { UNUSEDALL int fileNumber, newHeight; - if (!getValueType(newHeight, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(newHeight, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; // newDebug (" Height:", newHeight); trimStack(fun->stack); char *newText = getTextFromAnyVar(fun->stack->thisVar); - if (!newText) return BR_ERROR; + if (!newText) + return BR_ERROR; // newDebug (" Character supported:", newText); trimStack(fun->stack); - if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) + return BR_ERROR; // newDebug (" File:", fileNumber); trimStack(fun->stack); - if (!loadFont(fileNumber, newText, newHeight)) return BR_ERROR; + if (!loadFont(fileNumber, newText, newHeight)) + return BR_ERROR; // newDebug (" Done!"); delete newText; @@ -860,7 +899,8 @@ builtIn(setFont) { builtIn(inFont) { UNUSEDALL char *newText = getTextFromAnyVar(fun->stack->thisVar); - if (!newText) return BR_ERROR; + if (!newText) + return BR_ERROR; trimStack(fun->stack); // Return value @@ -874,11 +914,14 @@ builtIn(pasteString) { char *newText = getTextFromAnyVar(fun->stack->thisVar); trimStack(fun->stack); int y, x; - if (!getValueType(y, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(y, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(x, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(x, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (x == IN_THE_CENTRE) x = (winWidth - stringWidth(newText)) >> 1; + if (x == IN_THE_CENTRE) + x = (winWidth - stringWidth(newText)) >> 1; fixFont(pastePalette); pasteStringToBackdrop(newText, x, y, pastePalette); delete[] newText; @@ -897,12 +940,14 @@ builtIn(anim) { // Only remaining paramter is the file number int fileNumber; - if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); // Load the required sprite bank loadedSpriteBank *sprBanky = loadBankForAnim(fileNumber); - if (!sprBanky) return BR_ERROR; // File not found, fatal done already + if (!sprBanky) + return BR_ERROR; // File not found, fatal done already setBankFile(ba, sprBanky); // Return value @@ -914,16 +959,18 @@ builtIn(anim) { builtIn(costume) { UNUSEDALL persona *newPersona = new persona; - if (!checkNew(newPersona)) return BR_ERROR; + if (!checkNew(newPersona)) + return BR_ERROR; newPersona->numDirections = numParams / 3; if (numParams == 0 || newPersona->numDirections * 3 != numParams) { fatal("Illegal number of parameters (should be greater than 0 and divisible by 3)"); return BR_ERROR; } int iii; - newPersona->animation = new personaAnimation * [numParams]; - if (!checkNew(newPersona->animation)) return BR_ERROR; - for (iii = numParams - 1; iii >= 0; iii --) { + newPersona->animation = new personaAnimation *[numParams]; + if (!checkNew(newPersona->animation)) + return BR_ERROR; + for (iii = numParams - 1; iii >= 0; iii--) { newPersona->animation[iii] = getAnimationFromVar(fun->stack->thisVar); trimStack(fun->stack); } @@ -936,16 +983,13 @@ builtIn(costume) { builtIn(launch) { UNUSEDALL char *newTextA = getTextFromAnyVar(fun->stack->thisVar); - if (!newTextA) return BR_ERROR; + if (!newTextA) + return BR_ERROR; char *newText = encodeFilename(newTextA); trimStack(fun->stack); - if (newTextA[0] == 'h' && - newTextA[1] == 't' && - newTextA[2] == 't' && - newTextA[3] == 'p' && - (newTextA[4] == ':' || (newTextA[4] == 's' && newTextA[5] == ':'))) { + if (newTextA[0] == 'h' && newTextA[1] == 't' && newTextA[2] == 't' && newTextA[3] == 'p' && (newTextA[4] == ':' || (newTextA[4] == 's' && newTextA[5] == ':'))) { // IT'S A WEBSITE! launchMe = copyString(newTextA); @@ -958,7 +1002,8 @@ builtIn(launch) { #endif launchMe = joinStrings(gameDir, newText); delete newText; - if (!launchMe) return BR_ERROR; + if (!launchMe) + return BR_ERROR; } delete newTextA; setGraphicsWindow(false); @@ -971,7 +1016,8 @@ builtIn(launch) { builtIn(pause) { UNUSEDALL int theTime; - if (!getValueType(theTime, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(theTime, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); if (theTime > 0) { fun->timeLeft = theTime - 1; @@ -990,9 +1036,11 @@ builtIn(completeTimers) { builtIn(callEvent) { UNUSEDALL int obj1, obj2; - if (!getValueType(obj2, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(obj2, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(obj1, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(obj1, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); int fNum = getCombinationFunction(obj1, obj2); @@ -1022,7 +1070,6 @@ builtIn(quitGame) { return BR_CONTINUE; } - #pragma mark - #pragma mark Movie functions @@ -1049,9 +1096,11 @@ builtIn(playMovie) { UNUSEDALL int fileNumber, r; - if (movieIsPlaying) return BR_PAUSE; + if (movieIsPlaying) + return BR_PAUSE; - if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); r = playMovie(fileNumber); @@ -1085,27 +1134,31 @@ builtIn(pauseMovie) { return BR_CONTINUE; } - #pragma mark - #pragma mark Audio functions builtIn(startMusic) { UNUSEDALL int fromTrack, musChan, fileNumber; - if (!getValueType(fromTrack, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(fromTrack, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(musChan, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(musChan, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!playMOD(fileNumber, musChan, fromTrack)) return BR_CONTINUE; //BR_ERROR; + if (!playMOD(fileNumber, musChan, fromTrack)) + return BR_CONTINUE; //BR_ERROR; return BR_CONTINUE; } builtIn(stopMusic) { UNUSEDALL int v; - if (!getValueType(v, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(v, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); stopMOD(v); return BR_CONTINUE; @@ -1114,9 +1167,11 @@ builtIn(stopMusic) { builtIn(setMusicVolume) { UNUSEDALL int musChan, v; - if (!getValueType(v, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(v, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(musChan, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(musChan, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); setMusicVolume(musChan, v); return BR_CONTINUE; @@ -1125,7 +1180,8 @@ builtIn(setMusicVolume) { builtIn(setDefaultMusicVolume) { UNUSEDALL int v; - if (!getValueType(v, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(v, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); setDefaultMusicVolume(v); return BR_CONTINUE; @@ -1134,9 +1190,11 @@ builtIn(setDefaultMusicVolume) { builtIn(playSound) { UNUSEDALL int fileNumber; - if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!startSound(fileNumber, false)) return BR_CONTINUE; // Was BR_ERROR + if (!startSound(fileNumber, false)) + return BR_CONTINUE; // Was BR_ERROR return BR_CONTINUE; } builtIn(loopSound) { @@ -1148,9 +1206,11 @@ builtIn(loopSound) { return BR_ERROR; } else if (numParams < 2) { - if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!startSound(fileNumber, true)) return BR_CONTINUE; // Was BR_ERROR + if (!startSound(fileNumber, true)) + return BR_CONTINUE; // Was BR_ERROR return BR_CONTINUE; } else { // We have more than one sound to play! @@ -1171,17 +1231,19 @@ builtIn(loopSound) { return BR_ERROR; } s = new soundList; - if (!checkNew(s)) return BR_ERROR; + if (!checkNew(s)) + return BR_ERROR; - s-> next = old; - s-> prev = NULL; - s-> sound = fileNumber; + s->next = old; + s->prev = NULL; + s->sound = fileNumber; old = s; trimStack(fun->stack); numParams--; } - while (s->next) s = s-> next; + while (s->next) + s = s->next; if (doLoop > 1) { s->next = old; old->prev = s; @@ -1197,7 +1259,8 @@ builtIn(loopSound) { builtIn(stopSound) { UNUSEDALL int v; - if (!getValueType(v, SVT_FILE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(v, SVT_FILE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); huntKillSound(v); return BR_CONTINUE; @@ -1206,7 +1269,8 @@ builtIn(stopSound) { builtIn(setDefaultSoundVolume) { UNUSEDALL int v; - if (!getValueType(v, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(v, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); setDefaultSoundVolume(v); return BR_CONTINUE; @@ -1215,23 +1279,27 @@ builtIn(setDefaultSoundVolume) { builtIn(setSoundVolume) { UNUSEDALL int musChan, v; - if (!getValueType(v, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(v, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(musChan, SVT_FILE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(musChan, SVT_FILE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); setSoundVolume(musChan, v); return BR_CONTINUE; } - builtIn(setSoundLoopPoints) { UNUSEDALL int musChan, theEnd, theStart; - if (!getValueType(theEnd, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(theEnd, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(theStart, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(theStart, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(musChan, SVT_FILE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(musChan, SVT_FILE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); setSoundLoop(musChan, theStart, theEnd); return BR_CONTINUE; @@ -1246,7 +1314,8 @@ builtIn(setFloor) { int v; getValueType(v, SVT_FILE, fun->stack->thisVar); trimStack(fun->stack); - if (!setFloor(v)) return BR_ERROR; + if (!setFloor(v)) + return BR_ERROR; } else { trimStack(fun->stack); setFloorNull(); @@ -1266,7 +1335,8 @@ builtIn(setZBuffer) { int v; getValueType(v, SVT_FILE, fun->stack->thisVar); trimStack(fun->stack); - if (!setZBuffer(v)) return BR_ERROR; + if (!setZBuffer(v)) + return BR_ERROR; } else { trimStack(fun->stack); killZBuffer(); @@ -1277,40 +1347,42 @@ builtIn(setZBuffer) { builtIn(setLightMap) { UNUSEDALL switch (numParams) { - case 2: - if (!getValueType(lightMapMode, SVT_INT, fun->stack->thisVar)) return BR_ERROR; - trimStack(fun->stack); - lightMapMode %= LIGHTMAPMODE_NUM; - // No break; - - case 1: - if (fun->stack->thisVar.varType == SVT_FILE) { - int v; - getValueType(v, SVT_FILE, fun->stack->thisVar); - trimStack(fun->stack); - if (!loadLightMap(v)) return BR_ERROR; - setVariable(fun->reg, SVT_INT, 1); - } else { + case 2: + if (!getValueType(lightMapMode, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - killLightMap(); - setVariable(fun->reg, SVT_INT, 0); - } - break; + lightMapMode %= LIGHTMAPMODE_NUM; + // No break; + + case 1: + if (fun->stack->thisVar.varType == SVT_FILE) { + int v; + getValueType(v, SVT_FILE, fun->stack->thisVar); + trimStack(fun->stack); + if (!loadLightMap(v)) + return BR_ERROR; + setVariable(fun->reg, SVT_INT, 1); + } else { + trimStack(fun->stack); + killLightMap(); + setVariable(fun->reg, SVT_INT, 0); + } + break; - default: - fatal("Function should have either 2 or 3 parameters"); - return BR_ERROR; + default: + fatal("Function should have either 2 or 3 parameters"); + return BR_ERROR; } return BR_CONTINUE; } - #pragma mark - #pragma mark Objects builtIn(setSpeechMode) { UNUSEDALL - if (!getValueType(speechMode, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(speechMode, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); if (speechMode < 0 || speechMode > 2) { fatal("Valid parameters are be SPEECHANDTEXT, SPEECHONLY or TEXTONLY"); @@ -1351,9 +1423,11 @@ builtIn(rename) { UNUSEDALL char *newText = getTextFromAnyVar(fun->stack->thisVar); int objT; - if (!newText) return BR_ERROR; + if (!newText) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(objT, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(objT, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); objectType *o = findObjectType(objT); delete o->screenName; @@ -1364,7 +1438,8 @@ builtIn(rename) { builtIn(getObjectX) { UNUSEDALL int objectNumber; - if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); onScreenPerson *pers = findPerson(objectNumber); @@ -1384,7 +1459,8 @@ builtIn(getObjectX) { builtIn(getObjectY) { UNUSEDALL int objectNumber; - if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); onScreenPerson *pers = findPerson(objectNumber); @@ -1401,27 +1477,35 @@ builtIn(getObjectY) { return BR_CONTINUE; } - builtIn(addScreenRegion) { UNUSEDALL int sX, sY, x1, y1, x2, y2, di, objectNumber; - if (!getValueType(di, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(di, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(sY, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(sY, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(sX, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(sX, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(y2, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(y2, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(x2, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(x2, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(y1, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(y1, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(x1, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(x1, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (addScreenRegion(x1, y1, x2, y2, sX, sY, di, objectNumber)) return BR_CONTINUE; + if (addScreenRegion(x1, y1, x2, y2, sX, sY, di, objectNumber)) + return BR_CONTINUE; return BR_ERROR; } @@ -1429,7 +1513,8 @@ builtIn(addScreenRegion) { builtIn(removeScreenRegion) { UNUSEDALL int objectNumber; - if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); removeScreenRegion(objectNumber); return BR_CONTINUE; @@ -1453,23 +1538,29 @@ builtIn(addCharacter) { int x, y, objectNumber; p = getCostumeFromVar(fun->stack->thisVar); - if (p == NULL) return BR_ERROR; + if (p == NULL) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(y, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(y, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(x, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(x, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (addPerson(x, y, objectNumber, p)) return BR_CONTINUE; + if (addPerson(x, y, objectNumber, p)) + return BR_CONTINUE; return BR_ERROR; } builtIn(hideCharacter) { UNUSEDALL int objectNumber; - if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); setShown(false, objectNumber); return BR_CONTINUE; @@ -1478,7 +1569,8 @@ builtIn(hideCharacter) { builtIn(showCharacter) { UNUSEDALL int objectNumber; - if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); setShown(true, objectNumber); return BR_CONTINUE; @@ -1494,9 +1586,11 @@ builtIn(removeAllCharacters) { builtIn(setCharacterDrawMode) { UNUSEDALL int obj, di; - if (!getValueType(di, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(di, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); setDrawMode(di, obj); return BR_CONTINUE; @@ -1504,9 +1598,11 @@ builtIn(setCharacterDrawMode) { builtIn(setCharacterTransparency) { UNUSEDALL int obj, x; - if (!getValueType(x, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(x, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); setPersonTransparency(obj, x); return BR_CONTINUE; @@ -1514,15 +1610,20 @@ builtIn(setCharacterTransparency) { builtIn(setCharacterColourise) { UNUSEDALL int obj, r, g, b, mix; - if (!getValueType(mix, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(mix, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(b, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(b, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(g, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(g, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(r, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(r, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); setPersonColourise(obj, r, g, b, mix); return BR_CONTINUE; @@ -1531,18 +1632,21 @@ builtIn(setCharacterColourise) { builtIn(setScale) { UNUSEDALL int val1, val2; - if (!getValueType(val2, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(val2, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(val1, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(val1, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - setScale((short int) val1, (short int) val2); + setScale((short int)val1, (short int)val2); return BR_CONTINUE; } builtIn(stopCharacter) { UNUSEDALL int obj; - if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); // Return value @@ -1553,7 +1657,8 @@ builtIn(stopCharacter) { builtIn(pasteCharacter) { UNUSEDALL int obj; - if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); onScreenPerson *thisPerson = findPerson(obj); @@ -1579,9 +1684,11 @@ builtIn(animate) { UNUSEDALL int obj; personaAnimation *pp = getAnimationFromVar(fun->stack->thisVar); - if (pp == NULL) return BR_ERROR; + if (pp == NULL) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); animatePerson(obj, pp); setVariable(fun->reg, SVT_INT, timeForAnim(pp)); @@ -1592,9 +1699,11 @@ builtIn(setCostume) { UNUSEDALL int obj; persona *pp = getCostumeFromVar(fun->stack->thisVar); - if (pp == NULL) return BR_ERROR; + if (pp == NULL) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); animatePerson(obj, pp); return BR_CONTINUE; @@ -1603,9 +1712,11 @@ builtIn(setCostume) { builtIn(floatCharacter) { UNUSEDALL int obj, di; - if (!getValueType(di, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(di, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); setVariable(fun->reg, SVT_INT, floatCharacter(di, obj)); return BR_CONTINUE; @@ -1614,9 +1725,11 @@ builtIn(floatCharacter) { builtIn(setCharacterWalkSpeed) { UNUSEDALL int obj, di; - if (!getValueType(di, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(di, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); setVariable(fun->reg, SVT_INT, setCharacterWalkSpeed(di, obj)); return BR_CONTINUE; @@ -1625,9 +1738,11 @@ builtIn(setCharacterWalkSpeed) { builtIn(turnCharacter) { UNUSEDALL int obj, di; - if (!getValueType(di, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(di, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); setVariable(fun->reg, SVT_INT, turnPersonToFace(obj, di)); return BR_CONTINUE; @@ -1636,9 +1751,11 @@ builtIn(turnCharacter) { builtIn(setCharacterExtra) { UNUSEDALL int obj, di; - if (!getValueType(di, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(di, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); setVariable(fun->reg, SVT_INT, setPersonExtra(obj, di)); return BR_CONTINUE; @@ -1647,7 +1764,8 @@ builtIn(setCharacterExtra) { builtIn(removeCharacter) { UNUSEDALL int objectNumber; - if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); removeOneCharacter(objectNumber); return BR_CONTINUE; @@ -1655,50 +1773,60 @@ builtIn(removeCharacter) { static builtReturn moveChr(int numParams, loadedFunction *fun, bool force, bool immediate) { switch (numParams) { - case 3: { - int x, y, objectNumber; + case 3: { + int x, y, objectNumber; - if (!getValueType(y, SVT_INT, fun->stack->thisVar)) return BR_ERROR; - trimStack(fun->stack); - if (!getValueType(x, SVT_INT, fun->stack->thisVar)) return BR_ERROR; - trimStack(fun->stack); - if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; - trimStack(fun->stack); + if (!getValueType(y, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; + trimStack(fun->stack); + if (!getValueType(x, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; + trimStack(fun->stack); + if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; + trimStack(fun->stack); - if (force) { - if (forceWalkingPerson(x, y, objectNumber, fun, -1)) return BR_PAUSE; - } else if (immediate) { - jumpPerson(x, y, objectNumber); - } else { - if (makeWalkingPerson(x, y, objectNumber, fun, -1)) return BR_PAUSE; + if (force) { + if (forceWalkingPerson(x, y, objectNumber, fun, -1)) + return BR_PAUSE; + } else if (immediate) { + jumpPerson(x, y, objectNumber); + } else { + if (makeWalkingPerson(x, y, objectNumber, fun, -1)) + return BR_PAUSE; + } + return BR_CONTINUE; } - return BR_CONTINUE; - } - - case 2: { - int toObj, objectNumber; - screenRegion *reggie; - if (!getValueType(toObj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; - trimStack(fun->stack); - if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; - trimStack(fun->stack); - reggie = getRegionForObject(toObj); - if (reggie == NULL) return BR_CONTINUE; + case 2: { + int toObj, objectNumber; + screenRegion *reggie; - if (force) { - if (forceWalkingPerson(reggie->sX, reggie->sY, objectNumber, fun, reggie->di)) return BR_PAUSE; - } else if (immediate) { - jumpPerson(reggie->sX, reggie->sY, objectNumber); - } else { - if (makeWalkingPerson(reggie->sX, reggie->sY, objectNumber, fun, reggie->di)) return BR_PAUSE; + if (!getValueType(toObj, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; + trimStack(fun->stack); + if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; + trimStack(fun->stack); + reggie = getRegionForObject(toObj); + if (reggie == NULL) + return BR_CONTINUE; + + if (force) { + if (forceWalkingPerson(reggie->sX, reggie->sY, objectNumber, fun, reggie->di)) + return BR_PAUSE; + } else if (immediate) { + jumpPerson(reggie->sX, reggie->sY, objectNumber); + } else { + if (makeWalkingPerson(reggie->sX, reggie->sY, objectNumber, fun, reggie->di)) + return BR_PAUSE; + } + return BR_CONTINUE; } - return BR_CONTINUE; - } - default: - fatal("Built-in function must have either 2 or 3 parameters."); - return BR_ERROR; + default: + fatal("Built-in function must have either 2 or 3 parameters."); + return BR_ERROR; } } @@ -1738,7 +1866,8 @@ builtIn(addStatus) { builtIn(statusText) { UNUSEDALL char *newText = getTextFromAnyVar(fun->stack->thisVar); - if (!newText) return BR_ERROR; + if (!newText) + return BR_ERROR; trimStack(fun->stack); setStatusBar(newText); delete newText; @@ -1748,7 +1877,8 @@ builtIn(statusText) { builtIn(lightStatus) { UNUSEDALL int val; - if (!getValueType(val, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(val, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); setLitStatus(val); return BR_CONTINUE; @@ -1757,9 +1887,11 @@ builtIn(lightStatus) { builtIn(positionStatus) { UNUSEDALL int x, y; - if (!getValueType(y, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(y, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(x, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(x, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); positionStatus(x, y); return BR_CONTINUE; @@ -1768,26 +1900,28 @@ builtIn(positionStatus) { builtIn(alignStatus) { UNUSEDALL int val; - if (!getValueType(val, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(val, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - nowStatus->alignStatus = (short) val; + nowStatus->alignStatus = (short)val; return BR_CONTINUE; } static bool getFuncNumForCallback(int numParams, loadedFunction *fun, int &functionNum) { switch (numParams) { - case 0: - functionNum = 0; - break; + case 0: + functionNum = 0; + break; - case 1: - if (!getValueType(functionNum, SVT_FUNC, fun->stack->thisVar)) return false; - trimStack(fun->stack); - break; + case 1: + if (!getValueType(functionNum, SVT_FUNC, fun->stack->thisVar)) + return false; + trimStack(fun->stack); + break; - default: - fatal("Too many parameters."); - return false; + default: + fatal("Too many parameters."); + return false; } return true; } @@ -1866,7 +2000,8 @@ builtIn(spawnSub) { UNUSEDALL int functionNum; if (getFuncNumForCallback(numParams, fun, functionNum)) { - if (!startNewFunctionNum(functionNum, 0, NULL, noStack)) return BR_ERROR; + if (!startNewFunctionNum(functionNum, 0, NULL, noStack)) + return BR_ERROR; return BR_CONTINUE; } return BR_ERROR; @@ -1890,7 +2025,8 @@ builtIn(cancelSub) { builtIn(stringWidth) { UNUSEDALL char *theText = getTextFromAnyVar(fun->stack->thisVar); - if (!theText) return BR_ERROR; + if (!theText) + return BR_ERROR; trimStack(fun->stack); // Return value @@ -1902,17 +2038,18 @@ builtIn(stringWidth) { builtIn(hardScroll) { UNUSEDALL int v; - if (!getValueType(v, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(v, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); hardScroll(v); return BR_CONTINUE; } - builtIn(isScreenRegion) { UNUSEDALL int objectNumber; - if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); setVariable(fun->reg, SVT_INT, getRegionForObject(objectNumber) != NULL); return BR_CONTINUE; @@ -1921,7 +2058,8 @@ builtIn(isScreenRegion) { builtIn(setSpeechSpeed) { UNUSEDALL int number; - if (!getValueType(number, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(number, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); speechSpeed = number * 0.01; setVariable(fun->reg, SVT_INT, 1); @@ -1931,7 +2069,8 @@ builtIn(setSpeechSpeed) { builtIn(setFontSpacing) { UNUSEDALL int fontSpaceI; - if (!getValueType(fontSpaceI, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(fontSpaceI, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; fontSpace = fontSpaceI; trimStack(fun->stack); setVariable(fun->reg, SVT_INT, 1); @@ -1941,7 +2080,8 @@ builtIn(setFontSpacing) { builtIn(transitionLevel) { UNUSEDALL int number; - if (!getValueType(number, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(number, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); if (number < 0) @@ -1963,13 +2103,14 @@ builtIn(captureAllKeys) { return BR_CONTINUE; } - builtIn(spinCharacter) { UNUSEDALL int number, objectNumber; - if (!getValueType(number, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(number, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); onScreenPerson *thisPerson = findPerson(objectNumber); @@ -1988,7 +2129,8 @@ builtIn(spinCharacter) { builtIn(getCharacterDirection) { UNUSEDALL int objectNumber; - if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); onScreenPerson *thisPerson = findPerson(objectNumber); if (thisPerson) { @@ -2002,7 +2144,8 @@ builtIn(getCharacterDirection) { builtIn(isCharacter) { UNUSEDALL int objectNumber; - if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); onScreenPerson *thisPerson = findPerson(objectNumber); setVariable(fun->reg, SVT_INT, thisPerson != NULL); @@ -2012,7 +2155,8 @@ builtIn(isCharacter) { builtIn(normalCharacter) { UNUSEDALL int objectNumber; - if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); onScreenPerson *thisPerson = findPerson(objectNumber); if (thisPerson) { @@ -2027,7 +2171,8 @@ builtIn(normalCharacter) { builtIn(isMoving) { UNUSEDALL int objectNumber; - if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); onScreenPerson *thisPerson = findPerson(objectNumber); if (thisPerson) { @@ -2041,9 +2186,11 @@ builtIn(isMoving) { builtIn(fetchEvent) { UNUSEDALL int obj1, obj2; - if (!getValueType(obj2, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(obj2, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(obj1, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(obj1, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); int fNum = getCombinationFunction(obj1, obj2); @@ -2064,7 +2211,8 @@ builtIn(deleteFile) { trimStack(fun->stack); char *nam = encodeFilename(namNormal); delete namNormal; - if (failSecurityCheck(nam)) return BR_ERROR; + if (failSecurityCheck(nam)) + return BR_ERROR; setVariable(fun->reg, SVT_INT, remove(nam)); delete nam; @@ -2078,29 +2226,32 @@ builtIn(renameFile) { temp = getTextFromAnyVar(fun->stack->thisVar); char *newnam = encodeFilename(temp); trimStack(fun->stack); - if (failSecurityCheck(newnam)) return BR_ERROR; + if (failSecurityCheck(newnam)) + return BR_ERROR; delete temp; temp = getTextFromAnyVar(fun->stack->thisVar); char *nam = encodeFilename(temp); trimStack(fun->stack); - if (failSecurityCheck(nam)) return BR_ERROR; + if (failSecurityCheck(nam)) + return BR_ERROR; delete temp; setVariable(fun->reg, SVT_INT, rename(nam, newnam)); delete nam; delete newnam; - return BR_CONTINUE; } builtIn(cacheSound) { UNUSEDALL int fileNumber; - if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (cacheSound(fileNumber) == -1) return BR_ERROR; + if (cacheSound(fileNumber) == -1) + return BR_ERROR; return BR_CONTINUE; } @@ -2109,11 +2260,14 @@ builtIn(burnString) { char *newText = getTextFromAnyVar(fun->stack->thisVar); trimStack(fun->stack); int y, x; - if (!getValueType(y, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(y, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(x, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(x, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (x == IN_THE_CENTRE) x = (winWidth - stringWidth(newText)) >> 1; + if (x == IN_THE_CENTRE) + x = (winWidth - stringWidth(newText)) >> 1; fixFont(pastePalette); burnStringToBackdrop(newText, x, y, pastePalette); delete[] newText; @@ -2123,9 +2277,11 @@ builtIn(burnString) { builtIn(setCharacterSpinSpeed) { UNUSEDALL int speed, who; - if (!getValueType(speed, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(speed, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(who, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(who, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); onScreenPerson *thisPerson = findPerson(who); @@ -2142,9 +2298,11 @@ builtIn(setCharacterSpinSpeed) { builtIn(setCharacterAngleOffset) { UNUSEDALL int angle, who; - if (!getValueType(angle, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(angle, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(who, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(who, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); onScreenPerson *thisPerson = findPerson(who); @@ -2158,18 +2316,17 @@ builtIn(setCharacterAngleOffset) { return BR_CONTINUE; } - builtIn(transitionMode) { UNUSEDALL int n; - if (!getValueType(n, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(n, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; fadeMode = n; trimStack(fun->stack); setVariable(fun->reg, SVT_INT, 1); return BR_CONTINUE; } - // Removed function - does nothing builtIn(_rem_updateDisplay) { UNUSEDALL @@ -2182,11 +2339,13 @@ builtIn(getSoundCache) { UNUSEDALL fun->reg.varType = SVT_STACK; fun->reg.varData.theStack = new stackHandler; - if (!checkNew(fun->reg.varData.theStack)) return BR_ERROR; + if (!checkNew(fun->reg.varData.theStack)) + return BR_ERROR; fun->reg.varData.theStack->first = NULL; fun->reg.varData.theStack->last = NULL; fun->reg.varData.theStack->timesUsed = 1; - if (!getSoundCacheStack(fun->reg.varData.theStack)) return BR_ERROR; + if (!getSoundCacheStack(fun->reg.varData.theStack)) + return BR_ERROR; return BR_CONTINUE; } @@ -2194,19 +2353,22 @@ builtIn(saveCustomData) { UNUSEDALL // saveCustomData (thisStack, fileName); char *fileNameB = getTextFromAnyVar(fun->stack->thisVar); - if (!checkNew(fileNameB)) return BR_ERROR; + if (!checkNew(fileNameB)) + return BR_ERROR; char *fileName = encodeFilename(fileNameB); delete fileNameB; - if (failSecurityCheck(fileName)) return BR_ERROR; + if (failSecurityCheck(fileName)) + return BR_ERROR; trimStack(fun->stack); if (fun->stack->thisVar.varType != SVT_STACK) { fatal("First parameter isn't a stack"); return BR_ERROR; } - if (!stackToFile(fileName, fun->stack->thisVar)) return BR_ERROR; + if (!stackToFile(fileName, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); delete fileName; return BR_CONTINUE; @@ -2216,22 +2378,26 @@ builtIn(loadCustomData) { UNUSEDALL char *newTextA = getTextFromAnyVar(fun->stack->thisVar); - if (!checkNew(newTextA)) return BR_ERROR; + if (!checkNew(newTextA)) + return BR_ERROR; char *newText = encodeFilename(newTextA); delete newTextA; - if (failSecurityCheck(newText)) return BR_ERROR; + if (failSecurityCheck(newText)) + return BR_ERROR; trimStack(fun->stack); unlinkVar(fun->reg); fun->reg.varType = SVT_STACK; fun->reg.varData.theStack = new stackHandler; - if (!checkNew(fun->reg.varData.theStack)) return BR_ERROR; + if (!checkNew(fun->reg.varData.theStack)) + return BR_ERROR; fun->reg.varData.theStack->first = NULL; fun->reg.varData.theStack->last = NULL; fun->reg.varData.theStack->timesUsed = 1; - if (!fileToStack(newText, fun->reg.varData.theStack)) return BR_ERROR; + if (!fileToStack(newText, fun->reg.varData.theStack)) + return BR_ERROR; delete newText; return BR_CONTINUE; } @@ -2239,7 +2405,8 @@ builtIn(loadCustomData) { builtIn(setCustomEncoding) { UNUSEDALL int n; - if (!getValueType(n, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(n, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; saveEncoding = n; trimStack(fun->stack); setVariable(fun->reg, SVT_INT, 1); @@ -2249,7 +2416,8 @@ builtIn(setCustomEncoding) { builtIn(freeSound) { UNUSEDALL int v; - if (!getValueType(v, SVT_FILE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(v, SVT_FILE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); huntKillFreeSound(v); return BR_CONTINUE; @@ -2262,14 +2430,18 @@ builtIn(parallaxAdd) { return BR_ERROR; } else { int wrapX, wrapY, v; - if (!getValueType(wrapY, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(wrapY, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(wrapX, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(wrapX, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(v, SVT_FILE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(v, SVT_FILE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!loadParallax(v, wrapX, wrapY)) return BR_ERROR; + if (!loadParallax(v, wrapX, wrapY)) + return BR_ERROR; setVariable(fun->reg, SVT_INT, 1); } return BR_CONTINUE; @@ -2285,19 +2457,23 @@ builtIn(parallaxClear) { builtIn(getPixelColour) { UNUSEDALL int x, y; - if (!getValueType(y, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(y, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(x, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(x, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); unlinkVar(fun->reg); fun->reg.varType = SVT_STACK; fun->reg.varData.theStack = new stackHandler; - if (!checkNew(fun->reg.varData.theStack)) return BR_ERROR; + if (!checkNew(fun->reg.varData.theStack)) + return BR_ERROR; fun->reg.varData.theStack->first = NULL; fun->reg.varData.theStack->last = NULL; fun->reg.varData.theStack->timesUsed = 1; - if (!getRGBIntoStack(x, y, fun->reg.varData.theStack)) return BR_ERROR; + if (!getRGBIntoStack(x, y, fun->reg.varData.theStack)) + return BR_ERROR; return BR_CONTINUE; } @@ -2305,22 +2481,22 @@ builtIn(getPixelColour) { builtIn(makeFastArray) { UNUSEDALL switch (fun->stack->thisVar.varType) { - case SVT_STACK: { - bool success = makeFastArrayFromStack(fun->reg, fun->stack->thisVar.varData.theStack); - trimStack(fun->stack); - return success ? BR_CONTINUE : BR_ERROR; - } - break; + case SVT_STACK: { + bool success = makeFastArrayFromStack(fun->reg, fun->stack->thisVar.varData.theStack); + trimStack(fun->stack); + return success ? BR_CONTINUE : BR_ERROR; + } + break; - case SVT_INT: { - int i = fun->stack->thisVar.varData.intValue; - trimStack(fun->stack); - return makeFastArraySize(fun->reg, i) ? BR_CONTINUE : BR_ERROR; - } - break; + case SVT_INT: { + int i = fun->stack->thisVar.varData.intValue; + trimStack(fun->stack); + return makeFastArraySize(fun->reg, i) ? BR_CONTINUE : BR_ERROR; + } + break; - default: - break; + default: + break; } fatal("Parameter must be a number or a stack."); return BR_ERROR; @@ -2329,7 +2505,8 @@ builtIn(makeFastArray) { builtIn(getCharacterScale) { UNUSEDALL int objectNumber; - if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); onScreenPerson *pers = findPerson(objectNumber); @@ -2368,9 +2545,11 @@ builtIn(getFramesPerSecond) { builtIn(showThumbnail) { UNUSEDALL int x, y; - if (!getValueType(y, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(y, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(x, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(x, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); // Encode the name!Encode the name! @@ -2390,9 +2569,11 @@ builtIn(showThumbnail) { builtIn(setThumbnailSize) { UNUSEDALL - if (!getValueType(thumbHeight, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(thumbHeight, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(thumbWidth, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(thumbWidth, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); if (thumbWidth < 0 || thumbHeight < 0 || thumbWidth > winWidth || thumbHeight > winHeight) { char buff[50]; @@ -2406,12 +2587,15 @@ builtIn(setThumbnailSize) { builtIn(hasFlag) { UNUSEDALL int objNum, flagIndex; - if (!getValueType(flagIndex, SVT_INT, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(flagIndex, SVT_INT, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); - if (!getValueType(objNum, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; + if (!getValueType(objNum, SVT_OBJTYPE, fun->stack->thisVar)) + return BR_ERROR; trimStack(fun->stack); objectType *objT = findObjectType(objNum); - if (!objT) return BR_ERROR; + if (!objT) + return BR_ERROR; setVariable(fun->reg, SVT_INT, objT->flags & (1 << flagIndex)); return BR_CONTINUE; } @@ -2498,19 +2682,17 @@ builtIn(doBackgroundEffect) { #define FUNC(special,name) {builtIn_ ## name}, static builtInFunctionData builtInFunctionArray[] = { #include "CommonCode/functionlist.h" -}; + }; #undef FUNC #define FUNC(special,name) {#name}, char builtInFunctionNames[][25] = { #include "CommonCode/functionlist.h" -}; + }; #undef FUNC #define NUM_FUNCS (sizeof (builtInFunctionArray) / sizeof (builtInFunctionArray[0])) - - builtReturn callBuiltIn(int whichFunc, int numParams, loadedFunction *fun) { // fprintf (stderr, "Calling function %d: %s\n", whichFunc, builtInFunctionNames[whichFunc]); fflush (stderr); if (numBIFNames) { @@ -2518,18 +2700,15 @@ builtReturn callBuiltIn(int whichFunc, int numParams, loadedFunction *fun) { // deb ("IN:", (fun->originalNumber < numUserFunc) ? allUserFunc[fun->originalNumber] : "Unknown user function"); // deb ("GO:", (whichFunc < numBIFNames) ? allBIFNames[whichFunc] : "Unknown built-in function"); - setFatalInfo( - (fun->originalNumber < numUserFunc) ? allUserFunc[fun->originalNumber] : "Unknown user function", - (whichFunc < numBIFNames) ? allBIFNames[whichFunc] : "Unknown built-in function"); + setFatalInfo((fun->originalNumber < numUserFunc) ? allUserFunc[fun->originalNumber] : "Unknown user function", + (whichFunc < numBIFNames) ? allBIFNames[whichFunc] : "Unknown built-in function"); } if (whichFunc < NUM_FUNCS) { if (paramNum[whichFunc] != -1) { if (paramNum[whichFunc] != numParams) { char buff[100]; - sprintf(buff, "Built in function must have %i parameter%s", - paramNum[whichFunc], - (paramNum[whichFunc] == 1) ? "" : "s"); + sprintf(buff, "Built in function must have %i parameter%s", paramNum[whichFunc], (paramNum[whichFunc] == 1) ? "" : "s"); fatal(copyString(buff)); return BR_ERROR; diff --git a/engines/sludge/errors.h b/engines/sludge/errors.h index f706bad83f..388d4a0694 100644 --- a/engines/sludge/errors.h +++ b/engines/sludge/errors.h @@ -56,9 +56,9 @@ namespace Sludge { #define ERROR_MUSIC_MEMORY_LOW "Your computer doesn't have enough memory available to load a music resource that needs playing." _NO_MEMORY_GENERAL_
#define ERROR_SOUND_MEMORY_LOW "Your computer doesn't have enough memory available to load a sound resource that needs playing." _NO_MEMORY_GENERAL_
#define ERROR_MUSIC_UNKNOWN "I can't understand a piece of music which I've been told to play!\n\n" \
- "Maybe it's stored in a format that SLUDGE doesn't know about... " \
- "make sure you've got a recent version of the SLUDGE engine from http://opensludge.github.io/. " \
- "Failing that, maybe the resource in question isn't a valid music format at all... in which case, contact the game's author and tell them what's happened."
+ "Maybe it's stored in a format that SLUDGE doesn't know about... " \
+ "make sure you've got a recent version of the SLUDGE engine from http://opensludge.github.io/. " \
+ "Failing that, maybe the resource in question isn't a valid music format at all... in which case, contact the game's author and tell them what's happened."
#define ERROR_SOUND_UNKNOWN "I can't understand a sample which I've been told to play!\nMake sure you've got the latest SLUDGE engine from http://opensludge.github.io/. Failing that, maybe the resource in question isn't a valid sound at all... in which case, contact the game's author and tell them what's happened."
#define ERROR_MUSIC_ODDNESS "I can't load a music resource I've been told to play. Sorry."
#define ERROR_SOUND_ODDNESS "I can't load a sound resource I've been told to play. Sorry."
diff --git a/engines/sludge/fileset.cpp b/engines/sludge/fileset.cpp index d6ecdef2bb..cf858149ef 100644 --- a/engines/sludge/fileset.cpp +++ b/engines/sludge/fileset.cpp @@ -44,8 +44,7 @@ bool sliceBusy = true; Common::File *bigDataFile = NULL; -uint32_t startOfDataIndex, startOfTextIndex, startOfSubIndex, - startOfObjectIndex; +uint32_t startOfDataIndex, startOfTextIndex, startOfSubIndex, startOfObjectIndex; bool openSubSlice(int num) { // FILE * dbug = fopen ("debuggy.txt", "at"); @@ -199,8 +198,7 @@ void finishAccess() { int32_t startIndex; -void setFileIndices(Common::File *fp, int numLanguages, - unsigned int skipBefore) { +void setFileIndices(Common::File *fp, int numLanguages, unsigned int skipBefore) { if (fp) { // Keep hold of the file handle, and let things get at it bigDataFile = fp; diff --git a/engines/sludge/floor.cpp b/engines/sludge/floor.cpp index cfb64d5b4a..29038b3125 100644 --- a/engines/sludge/floor.cpp +++ b/engines/sludge/floor.cpp @@ -42,17 +42,14 @@ bool pointInFloorPolygon(floorPolygon &floorPoly, int x, int y) { xp_j = currentFloor->vertex[floorPoly.vertexID[j]].x; yp_j = currentFloor->vertex[floorPoly.vertexID[j]].y; - if ((((yp_i <= y) && (y < yp_j)) || ((yp_j <= y) && (y < yp_i))) - && (x < (xp_j - xp_i) * (y - yp_i) / (yp_j - yp_i) + xp_i)) { - + if ((((yp_i <= y) && (y < yp_j)) || ((yp_j <= y) && (y < yp_i))) && (x < (xp_j - xp_i) * (y - yp_i) / (yp_j - yp_i) + xp_i)) { c = !c; } } return c; } -bool getMatchingCorners(floorPolygon &a, floorPolygon &b, int &cornerA, - int &cornerB) { +bool getMatchingCorners(floorPolygon &a, floorPolygon &b, int &cornerA, int &cornerB) { int sharedVertices = 0; int i, j; @@ -147,8 +144,7 @@ bool setFloor(int fileNum) { // Find out how many vertex IDs there are and reserve memory currentFloor->polygon[i].numVertices = bigDataFile->readByte(); - currentFloor->polygon[i].vertexID = - new int[currentFloor->polygon[i].numVertices]; + currentFloor->polygon[i].vertexID = new int[currentFloor->polygon[i].numVertices]; if (!checkNew(currentFloor->polygon[i].vertexID)) return false; @@ -196,8 +192,7 @@ bool setFloor(int fileNum) { for (i = 0; i < currentFloor->numPolygons; i++) { for (j = 0; j < currentFloor->numPolygons; j++) { if (i != j) { - if (polysShareSide(currentFloor->polygon[i], - currentFloor->polygon[j])) { + if (polysShareSide(currentFloor->polygon[i], currentFloor->polygon[j])) { currentFloor->matrix[i][j] = j; distanceMatrix[i][j] = 1; } @@ -222,11 +217,7 @@ bool setFloor(int fileNum) { // OK, so we don't know how to get from i to j... for (int d = 0; d < currentFloor->numPolygons; d++) { if (d != i && d != j) { - if (currentFloor->matrix[i][d] == d - && currentFloor->matrix[d][j] >= 0 - && distanceMatrix[d][j] - <= lookForDistance) { - + if (currentFloor->matrix[i][d] == d && currentFloor->matrix[d][j] >= 0 && distanceMatrix[d][j] <= lookForDistance) { currentFloor->matrix[i][j] = d; distanceMatrix[i][j] = lookForDistance + 1; madeChange = true; @@ -257,21 +248,11 @@ void drawFloor() { nV = currentFloor->polygon[i].numVertices; if (nV > 1) { for (j = 1; j < nV; j++) { - drawLine( - currentFloor->vertex[currentFloor->polygon[i].vertexID[j - - 1]].x, - currentFloor->vertex[currentFloor->polygon[i].vertexID[j - - 1]].y, - currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].x, - currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].y); + drawLine(currentFloor->vertex[currentFloor->polygon[i].vertexID[j - 1]].x, currentFloor->vertex[currentFloor->polygon[i].vertexID[j - 1]].y, + currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].x, currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].y); } - drawLine( - currentFloor->vertex[currentFloor->polygon[i].vertexID[0]].x, - currentFloor->vertex[currentFloor->polygon[i].vertexID[0]].y, - currentFloor->vertex[currentFloor->polygon[i].vertexID[nV - - 1]].x, - currentFloor->vertex[currentFloor->polygon[i].vertexID[nV - - 1]].y); + drawLine(currentFloor->vertex[currentFloor->polygon[i].vertexID[0]].x, currentFloor->vertex[currentFloor->polygon[i].vertexID[0]].y, + currentFloor->vertex[currentFloor->polygon[i].vertexID[nV - 1]].x, currentFloor->vertex[currentFloor->polygon[i].vertexID[nV - 1]].y); } } } @@ -286,8 +267,7 @@ int inFloor(int x, int y) { return r; } -bool closestPointOnLine(int &closestX, int &closestY, int x1, int y1, int x2, - int y2, int xP, int yP) { +bool closestPointOnLine(int &closestX, int &closestY, int x1, int y1, int x2, int y2, int xP, int yP) { int xDiff = x2 - x1; int yDiff = y2 - y1; diff --git a/engines/sludge/floor.h b/engines/sludge/floor.h index 50fe56e87c..193b6d19bf 100644 --- a/engines/sludge/floor.h +++ b/engines/sludge/floor.h @@ -54,8 +54,7 @@ bool setFloor(int fileNum); void drawFloor(); int inFloor(int x, int y); bool getMatchingCorners(floorPolygon &, floorPolygon &, int &, int &); -bool closestPointOnLine(int &closestX, int &closestY, int x1, int y1, int x2, - int y2, int xP, int yP); +bool closestPointOnLine(int &closestX, int &closestY, int x1, int y1, int x2, int y2, int xP, int yP); } // End of namespace Sludge diff --git a/engines/sludge/fonttext.cpp b/engines/sludge/fonttext.cpp index 505078d155..4dfdd1093e 100644 --- a/engines/sludge/fonttext.cpp +++ b/engines/sludge/fonttext.cpp @@ -94,17 +94,16 @@ void pasteString(char *theText, int xOff, int y, spritePalette &thePal) { if (!fontTableSize) return; - xOff += (int) ((float) (fontSpace >> 1) / cameraZoom); + xOff += (int)((float)(fontSpace >> 1) / cameraZoom); while (theText[a]) { c = u8_nextchar(theText, &a); mySprite = &theFont.sprites[fontInTable(c)]; fontSprite(xOff, y, *mySprite, thePal); - xOff += (int) ((double) (mySprite->surface.w + fontSpace) / cameraZoom); + xOff += (int)((double)(mySprite->surface.w + fontSpace) / cameraZoom); } } -void pasteStringToBackdrop(char *theText, int xOff, int y, - spritePalette &thePal) { +void pasteStringToBackdrop(char *theText, int xOff, int y, spritePalette &thePal) { sprite *mySprite; int a = 0; uint32_t c; @@ -121,8 +120,7 @@ void pasteStringToBackdrop(char *theText, int xOff, int y, } } -void burnStringToBackdrop(char *theText, int xOff, int y, - spritePalette &thePal) { +void burnStringToBackdrop(char *theText, int xOff, int y, spritePalette &thePal) { sprite *mySprite; int a = 0; uint32_t c; diff --git a/engines/sludge/freeze.cpp b/engines/sludge/freeze.cpp index 0d797b27d9..d5aa29d9d0 100644 --- a/engines/sludge/freeze.cpp +++ b/engines/sludge/freeze.cpp @@ -156,7 +156,7 @@ bool freeze() { // Grab a copy of the current scene freezeGraphics(); #if 0 - newFreezer -> backdropTextureName = backdropTextureName; + newFreezer->backdropTextureName = backdropTextureName; #endif int picWidth = sceneWidth; int picHeight = sceneHeight; @@ -165,8 +165,9 @@ bool freeze() { picHeight = getNextPOT(picHeight); } #if 0 - newFreezer -> backdropTexture = new GLubyte [picHeight * picWidth * 4]; - if (! checkNew(newFreezer -> backdropTexture)) return false; + newFreezer->backdropTexture = new GLubyte[picHeight * picWidth * 4]; + if (!checkNew(newFreezer->backdropTexture)) + return false; saveTexture(backdropTextureName, newFreezer->backdropTexture); @@ -178,16 +179,16 @@ bool freeze() { newFreezer->cameraY = cameraY; newFreezer->cameraZoom = cameraZoom; #if 0 - newFreezer -> lightMapTexture = lightMap.data; - newFreezer -> lightMapTextureName = lightMap.name; - newFreezer -> lightMapNumber = lightMapNumber; + newFreezer->lightMapTexture = lightMap.data; + newFreezer->lightMapTextureName = lightMap.name; + newFreezer->lightMapNumber = lightMapNumber; lightMap.data = NULL; lightMap.name = 0; - newFreezer -> parallaxStuff = parallaxStuff; + newFreezer->parallaxStuff = parallaxStuff; parallaxStuff = NULL; - newFreezer -> zBufferImage = zBuffer.tex; - newFreezer -> zBufferNumber = zBuffer.originalNum; - newFreezer -> zPanels = zBuffer.numPanels; + newFreezer->zBufferImage = zBuffer.tex; + newFreezer->zBufferNumber = zBuffer.originalNum; + newFreezer->zPanels = zBuffer.numPanels; zBuffer.tex = NULL; #endif // resizeBackdrop kills parallax stuff, light map, z-buffer... @@ -198,8 +199,8 @@ bool freeze() { picWidth = getNextPOT(sceneWidth); picHeight = getNextPOT(sceneHeight); #if 0 - backdropTexW = (double) sceneWidth / picWidth; - backdropTexH = (double) sceneHeight / picHeight; + backdropTexW = (double)sceneWidth / picWidth; + backdropTexH = (double)sceneHeight / picHeight; #endif } @@ -210,19 +211,19 @@ bool freeze() { backdropExists = true; // Free texture memory used by old stuff - parallaxStuff = newFreezer -> parallaxStuff; + parallaxStuff = newFreezer->parallaxStuff; while (parallaxStuff) { - deleteTextures(1, ¶llaxStuff -> textureName); - parallaxStuff = parallaxStuff -> next; + deleteTextures(1, ¶llaxStuff->textureName); + parallaxStuff = parallaxStuff->next; } - if (newFreezer -> zBufferImage) { + if (newFreezer->zBufferImage) { deleteTextures(1, &zBuffer.texName); } - if (newFreezer -> lightMapTextureName) { - deleteTextures(1, &newFreezer -> lightMapTextureName); + if (newFreezer->lightMapTextureName) { + deleteTextures(1, &newFreezer->lightMapTextureName); } - if (newFreezer -> backdropTextureName) { - deleteTextures(1, &newFreezer -> backdropTextureName); + if (newFreezer->backdropTextureName) { + deleteTextures(1, &newFreezer->backdropTextureName); } #endif newFreezer->allPeople = allPeople; @@ -282,11 +283,11 @@ void unfreeze(bool killImage) { cameraX = frozenStuff->cameraX; cameraY = frozenStuff->cameraY; - input.mouseX = (int) (input.mouseX * cameraZoom); - input.mouseY = (int) (input.mouseY * cameraZoom); + input.mouseX = (int)(input.mouseX * cameraZoom); + input.mouseY = (int)(input.mouseY * cameraZoom); cameraZoom = frozenStuff->cameraZoom; - input.mouseX = (int) (input.mouseX / cameraZoom); - input.mouseY = (int) (input.mouseY / cameraZoom); + input.mouseX = (int)(input.mouseX / cameraZoom); + input.mouseY = (int)(input.mouseY / cameraZoom); setPixelCoords(false); killAllPeople(); @@ -297,31 +298,33 @@ void unfreeze(bool killImage) { killLightMap(); #if 0 - lightMap.data = frozenStuff -> lightMapTexture; - lightMap.name = frozenStuff -> lightMapTextureName; - lightMapNumber = frozenStuff -> lightMapNumber; + lightMap.data = frozenStuff->lightMapTexture; + lightMap.name = frozenStuff->lightMapTextureName; + lightMapNumber = frozenStuff->lightMapNumber; if (lightMapNumber) { lightMap.name = 0; loadLightMap(lightMapNumber); } killZBuffer(); - zBuffer.tex = frozenStuff -> zBufferImage; - zBuffer.originalNum = frozenStuff -> zBufferNumber; - zBuffer.numPanels = frozenStuff -> zPanels; + zBuffer.tex = frozenStuff->zBufferImage; + zBuffer.originalNum = frozenStuff->zBufferNumber; + zBuffer.numPanels = frozenStuff->zPanels; if (zBuffer.numPanels) { zBuffer.texName = 0; setZBuffer(zBuffer.originalNum); } killParallax(); - parallaxStuff = frozenStuff -> parallaxStuff; + parallaxStuff = frozenStuff->parallaxStuff; reloadParallaxTextures(); - if (killImage) killBackDrop(); - backdropTextureName = frozenStuff -> backdropTextureName; - if (backdropTexture) delete[] backdropTexture; - backdropTexture = frozenStuff -> backdropTexture; + if (killImage) + killBackDrop(); + backdropTextureName = frozenStuff->backdropTextureName; + if (backdropTexture) + delete[] backdropTexture; + backdropTexture = frozenStuff->backdropTexture; backdropExists = true; if (backdropTextureName) { backdropTextureName = 0; @@ -340,12 +343,12 @@ void unfreeze(bool killImage) { int picWidth = sceneWidth; int picHeight = sceneHeight; - if (! NPOT_textures) { + if (!NPOT_textures) { picWidth = getNextPOT(picWidth); picHeight = getNextPOT(picHeight); } // Restore the backdrop - texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, picWidth, picHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, frozenStuff -> backdropTexture, backdropTextureName); + texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, picWidth, picHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, frozenStuff->backdropTexture, backdropTextureName); } #endif deleteAnim(mouseCursorAnim); diff --git a/engines/sludge/language.cpp b/engines/sludge/language.cpp index b6a7ab62d2..8d795a0d48 100644 --- a/engines/sludge/language.cpp +++ b/engines/sludge/language.cpp @@ -91,8 +91,7 @@ void readIniFile(char *filename) { Common::File fd; if (!fd.open(langName)) { - debug(kSludgeDebugDataLoad, "Fail to open language file : %s", - langName); + debug(kSludgeDebugDataLoad, "Fail to open language file : %s", langName); return; } @@ -121,45 +120,45 @@ void readIniFile(char *filename) { keepGoing = false; } switch (readChar) { - case '\n': - case '\r': - if (doingSecond) { - if (strcmp(lineSoFar, "LANGUAGE") == 0) { - gameSettings.languageID = stringToInt(secondSoFar); - } else if (strcmp(lineSoFar, "WINDOW") == 0) { - gameSettings.userFullScreen = !stringToInt(secondSoFar); - } else if (strcmp(lineSoFar, "REFRESH") == 0) { - gameSettings.refreshRate = stringToInt(secondSoFar); - } else if (strcmp(lineSoFar, "ANTIALIAS") == 0) { - gameSettings.antiAlias = stringToInt(secondSoFar); - } else if (strcmp(lineSoFar, "FIXEDPIXELS") == 0) { - gameSettings.fixedPixels = stringToInt(secondSoFar); - } else if (strcmp(lineSoFar, "NOSTARTWINDOW") == 0) { - gameSettings.noStartWindow = stringToInt(secondSoFar); - } else if (strcmp(lineSoFar, "DEBUGMODE") == 0) { - gameSettings.debugMode = stringToInt(secondSoFar); + case '\n': + case '\r': + if (doingSecond) { + if (strcmp(lineSoFar, "LANGUAGE") == 0) { + gameSettings.languageID = stringToInt(secondSoFar); + } else if (strcmp(lineSoFar, "WINDOW") == 0) { + gameSettings.userFullScreen = !stringToInt(secondSoFar); + } else if (strcmp(lineSoFar, "REFRESH") == 0) { + gameSettings.refreshRate = stringToInt(secondSoFar); + } else if (strcmp(lineSoFar, "ANTIALIAS") == 0) { + gameSettings.antiAlias = stringToInt(secondSoFar); + } else if (strcmp(lineSoFar, "FIXEDPIXELS") == 0) { + gameSettings.fixedPixels = stringToInt(secondSoFar); + } else if (strcmp(lineSoFar, "NOSTARTWINDOW") == 0) { + gameSettings.noStartWindow = stringToInt(secondSoFar); + } else if (strcmp(lineSoFar, "DEBUGMODE") == 0) { + gameSettings.debugMode = stringToInt(secondSoFar); + } } - } - here = 0; - doingSecond = false; - lineSoFar[0] = 0; - secondSoFar[0] = 0; - break; - - case '=': - doingSecond = true; - here = 0; - break; - - default: - if (doingSecond) { - secondSoFar[here++] = readChar; - secondSoFar[here] = 0; - } else { - lineSoFar[here++] = readChar; - lineSoFar[here] = 0; - } - break; + here = 0; + doingSecond = false; + lineSoFar[0] = 0; + secondSoFar[0] = 0; + break; + + case '=': + doingSecond = true; + here = 0; + break; + + default: + if (doingSecond) { + secondSoFar[here++] = readChar; + secondSoFar[here] = 0; + } else { + lineSoFar[here++] = readChar; + lineSoFar[here] = 0; + } + break; } } while (keepGoing); @@ -194,14 +193,12 @@ void makeLanguageTable(Common::File *table) { for (unsigned int i = 0; i <= gameSettings.numLanguages; i++) { languageTable[i] = i ? table->readUint16BE() : 0; - debug(kSludgeDebugDataLoad, "languageTable %i: %i", i, - languageTable[i]); + debug(kSludgeDebugDataLoad, "languageTable %i: %i", i, languageTable[i]); languageName[i] = 0; if (gameVersion >= VERSION(2, 0)) { if (gameSettings.numLanguages) { languageName[i] = readString(table); - debug(kSludgeDebugDataLoad, "languageName %i: %s\n", i, - languageName[i]); + debug(kSludgeDebugDataLoad, "languageName %i: %s\n", i, languageName[i]); } } } diff --git a/engines/sludge/line.cpp b/engines/sludge/line.cpp index 1feba03756..0067163415 100644 --- a/engines/sludge/line.cpp +++ b/engines/sludge/line.cpp @@ -37,35 +37,47 @@ void drawLine(int x1, int y1, int x2, int y2) { int x, y; bool backwards = false; #if 0 - if (x1 < 0) x1 = 0; - if (y1 < 0) y1 = 0; - if (x2 < 0) x2 = 0; - if (y2 < 0) y2 = 0; - if (x1 > sceneWidth) x1 = sceneWidth - 1; - if (x2 > sceneWidth) x2 = sceneWidth - 1; - if (y1 > sceneHeight) y1 = sceneHeight - 1; - if (y2 > sceneHeight) y2 = sceneHeight - 1; + if (x1 < 0) + x1 = 0; + if (y1 < 0) + y1 = 0; + if (x2 < 0) + x2 = 0; + if (y2 < 0) + y2 = 0; + if (x1 > sceneWidth) + x1 = sceneWidth - 1; + if (x2 > sceneWidth) + x2 = sceneWidth - 1; + if (y1 > sceneHeight) + y1 = sceneHeight - 1; + if (y2 > sceneHeight) + y2 = sceneHeight - 1; if (x1 > x2) { x = x2; backwards = !backwards; - } else x = x1; + } else + x = x1; if (y1 > y2) { y = y2; backwards = !backwards; - } else y = y1; + } else + y = y1; int diffX = abs(x2 - x1); int diffY = abs(y2 - y1); - if (! diffX) { + if (!diffX) { diffX = 1; - if (x == sceneWidth - 1) x = sceneWidth - 2; + if (x == sceneWidth - 1) + x = sceneWidth - 2; } - if (! diffY) { + if (!diffY) { diffY = 1; - if (y == sceneHeight - 1) y = sceneHeight - 2; + if (y == sceneHeight - 1) + y = sceneHeight - 2; } setPixelCoords(true); @@ -82,19 +94,10 @@ void drawLine(int x1, int y1, int x2, int y2) { // Render the scene - first the old backdrop glBindTexture(GL_TEXTURE_2D, backdropTextureName); //glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - const GLfloat vertices[] = { - (GLfloat) - x - xoffset, (GLfloat)1 - y - yoffset, 0., - (GLfloat)sceneWidth - x - xoffset, (GLfloat)1 - y - yoffset, 0., - (GLfloat) - x - xoffset, (GLfloat)sceneHeight - y - yoffset, 0., - (GLfloat)sceneWidth - x - xoffset, (GLfloat)sceneHeight - y - yoffset, 0. - }; - - const GLfloat texCoords[] = { - 0.0f, 0.0f, - backdropTexW, 0.0f, - 0.0f, backdropTexH, - backdropTexW, backdropTexH - }; + const GLfloat vertices[] = { (GLfloat)-x - xoffset, (GLfloat)1 - y - yoffset, 0., (GLfloat)sceneWidth - x - xoffset, (GLfloat)1 - y - yoffset, 0., (GLfloat)-x - xoffset, + (GLfloat)sceneHeight - y - yoffset, 0., (GLfloat)sceneWidth - x - xoffset, (GLfloat)sceneHeight - y - yoffset, 0. }; + + const GLfloat texCoords[] = { 0.0f, 0.0f, backdropTexW, 0.0f, 0.0f, backdropTexH, backdropTexW, backdropTexH }; glUseProgram(shader.texture); @@ -105,15 +108,12 @@ void drawLine(int x1, int y1, int x2, int y2) { //FIXME:Removing the lines doesn't work, but also didn't work properly before. GLint xo1 = -xoffset, xo2 = -xoffset; - if (! backwards) { + if (!backwards) { xo2 += diffX; } else { xo1 += diffX; } - const GLint lineVertices[] = { - xo1, -yoffset, 0, - xo2, -yoffset + diffY, 0, - }; + const GLint lineVertices[] = { xo1, -yoffset, 0, xo2, -yoffset + diffY, 0, }; glUseProgram(shader.color); diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp index f3eb93f1bb..50ef4cc6f2 100644 --- a/engines/sludge/loadsave.cpp +++ b/engines/sludge/loadsave.cpp @@ -113,14 +113,13 @@ void saveStack(variableStack *vs, Common::WriteStream *stream) { } } -variableStack *loadStack(Common::SeekableReadStream *stream, - variableStack **last) { +variableStack *loadStack(Common::SeekableReadStream *stream, variableStack **last) { int elements = stream->readUint16BE(); int a; variableStack *first = NULL; variableStack * * changeMe = &first; - for (a = 0; a < elements; ++a) { + for (a = 0; a < elements; a++) { variableStack *nS = new variableStack; if (!checkNew(nS)) return NULL; @@ -147,7 +146,7 @@ bool saveStackRef(stackHandler *vs, Common::WriteStream *stream) { return true; } s = s->next; - ++a; + a++; } stream->writeByte(0); saveStack(vs->first, stream); @@ -233,36 +232,34 @@ bool saveVariable(variable *from, Common::WriteStream *stream) { stream->writeByte(from->varType); switch (from->varType) { - case SVT_INT: - case SVT_FUNC: - case SVT_BUILT: - case SVT_FILE: - case SVT_OBJTYPE: - stream->writeUint32LE(from->varData.intValue); - return true; - - case SVT_STRING: - writeString(from->varData.theString, stream); - return true; - - case SVT_STACK: - return saveStackRef(from->varData.theStack, stream); - - case SVT_COSTUME: - saveCostume(from->varData.costumeHandler, stream); - return false; + case SVT_INT: + case SVT_FUNC: + case SVT_BUILT: + case SVT_FILE: + case SVT_OBJTYPE: + stream->writeUint32LE(from->varData.intValue); + return true; - case SVT_ANIM: - saveAnim(from->varData.animHandler, stream); - return false; + case SVT_STRING: + writeString(from->varData.theString, stream); + return true; - case SVT_NULL: - return false; + case SVT_STACK: + return saveStackRef(from->varData.theStack, stream); + + case SVT_COSTUME: + saveCostume(from->varData.costumeHandler, stream); + return false; + + case SVT_ANIM: + saveAnim(from->varData.animHandler, stream); + return false; + + case SVT_NULL: + return false; - default: - fatal("Can't save variables of this type:", - (from->varType < SVT_NUM_TYPES) ? - typeName[from->varType] : "bad ID"); + default: + fatal("Can't save variables of this type:", (from->varType < SVT_NUM_TYPES) ? typeName[from->varType] : "bad ID"); } return true; } @@ -270,45 +267,45 @@ bool saveVariable(variable *from, Common::WriteStream *stream) { bool loadVariable(variable *to, Common::SeekableReadStream *stream) { to->varType = (variableType)stream->readByte(); switch (to->varType) { - case SVT_INT: - case SVT_FUNC: - case SVT_BUILT: - case SVT_FILE: - case SVT_OBJTYPE: - to->varData.intValue = stream->readUint32LE(); - return true; - - case SVT_STRING: - to->varData.theString = readString(stream); - return true; - - case SVT_STACK: - to->varData.theStack = loadStackRef(stream); + case SVT_INT: + case SVT_FUNC: + case SVT_BUILT: + case SVT_FILE: + case SVT_OBJTYPE: + to->varData.intValue = stream->readUint32LE(); + return true; + + case SVT_STRING: + to->varData.theString = readString(stream); + return true; + + case SVT_STACK: + to->varData.theStack = loadStackRef(stream); #if DEBUG_STACKINESS - { - char *str = getTextFromAnyVar(*to); - stackDebug((stackfp, "just loaded %s\n", str)); - delete str; - } + { + char *str = getTextFromAnyVar(*to); + stackDebug((stackfp, "just loaded %s\n", str)); + delete str; + } #endif - return true; + return true; - case SVT_COSTUME: - to->varData.costumeHandler = new persona; - if (!checkNew(to->varData.costumeHandler)) - return false; - loadCostume(to->varData.costumeHandler, stream); - return true; + case SVT_COSTUME: + to->varData.costumeHandler = new persona; + if (!checkNew(to->varData.costumeHandler)) + return false; + loadCostume(to->varData.costumeHandler, stream); + return true; - case SVT_ANIM: - to->varData.animHandler = new personaAnimation; - if (!checkNew(to->varData.animHandler)) - return false; - loadAnim(to->varData.animHandler, stream); - return true; + case SVT_ANIM: + to->varData.animHandler = new personaAnimation; + if (!checkNew(to->varData.animHandler)) + return false; + loadAnim(to->varData.animHandler, stream); + return true; - default: - break; + default: + break; } return true; } diff --git a/engines/sludge/moreio.cpp b/engines/sludge/moreio.cpp index ed3a7ecdc7..da86553cda 100644 --- a/engines/sludge/moreio.cpp +++ b/engines/sludge/moreio.cpp @@ -136,50 +136,50 @@ char *encodeFilename(char *nameIn) { int i = 0; while (*nameIn) { switch (*nameIn) { - case '<': - newName[i++] = '_'; - newName[i++] = 'L'; - break; - case '>': - newName[i++] = '_'; - newName[i++] = 'G'; - break; - case '|': - newName[i++] = '_'; - newName[i++] = 'P'; - break; - case '_': - newName[i++] = '_'; - newName[i++] = 'U'; - break; - case '\"': - newName[i++] = '_'; - newName[i++] = 'S'; - break; - case '\\': - newName[i++] = '_'; - newName[i++] = 'B'; - break; - case '/': - newName[i++] = '_'; - newName[i++] = 'F'; - break; - case ':': - newName[i++] = '_'; - newName[i++] = 'C'; - break; - case '*': - newName[i++] = '_'; - newName[i++] = 'A'; - break; - case '?': - newName[i++] = '_'; - newName[i++] = 'Q'; - break; + case '<': + newName[i++] = '_'; + newName[i++] = 'L'; + break; + case '>': + newName[i++] = '_'; + newName[i++] = 'G'; + break; + case '|': + newName[i++] = '_'; + newName[i++] = 'P'; + break; + case '_': + newName[i++] = '_'; + newName[i++] = 'U'; + break; + case '\"': + newName[i++] = '_'; + newName[i++] = 'S'; + break; + case '\\': + newName[i++] = '_'; + newName[i++] = 'B'; + break; + case '/': + newName[i++] = '_'; + newName[i++] = 'F'; + break; + case ':': + newName[i++] = '_'; + newName[i++] = 'C'; + break; + case '*': + newName[i++] = '_'; + newName[i++] = 'A'; + break; + case '?': + newName[i++] = '_'; + newName[i++] = 'Q'; + break; - default: - newName[i++] = *nameIn; - break; + default: + newName[i++] = *nameIn; + break; } newName[i] = 0; nameIn++; @@ -211,48 +211,48 @@ char *decodeFilename(char *nameIn) { if (*nameIn == '_') { nameIn++; switch (*nameIn) { - case 'L': - newName[i] = '<'; - nameIn++; - break; - case 'G': - newName[i] = '>'; - nameIn++; - break; - case 'P': - newName[i] = '|'; - nameIn++; - break; - case 'U': - newName[i] = '_'; - nameIn++; - break; - case 'S': - newName[i] = '\"'; - nameIn++; - break; - case 'B': - newName[i] = '\\'; - nameIn++; - break; - case 'F': - newName[i] = '/'; - nameIn++; - break; - case 'C': - newName[i] = ':'; - nameIn++; - break; - case 'A': - newName[i] = '*'; - nameIn++; - break; - case 'Q': - newName[i] = '?'; - nameIn++; - break; - default: - newName[i] = '_'; + case 'L': + newName[i] = '<'; + nameIn++; + break; + case 'G': + newName[i] = '>'; + nameIn++; + break; + case 'P': + newName[i] = '|'; + nameIn++; + break; + case 'U': + newName[i] = '_'; + nameIn++; + break; + case 'S': + newName[i] = '\"'; + nameIn++; + break; + case 'B': + newName[i] = '\\'; + nameIn++; + break; + case 'F': + newName[i] = '/'; + nameIn++; + break; + case 'C': + newName[i] = ':'; + nameIn++; + break; + case 'A': + newName[i] = '*'; + nameIn++; + break; + case 'Q': + newName[i] = '?'; + nameIn++; + break; + default: + newName[i] = '_'; } } else { newName[i] = *nameIn; diff --git a/engines/sludge/newfatal.cpp b/engines/sludge/newfatal.cpp index 9441569559..a6887d4165 100644 --- a/engines/sludge/newfatal.cpp +++ b/engines/sludge/newfatal.cpp @@ -42,9 +42,7 @@ namespace Sludge { const char emergencyMemoryMessage[] = "Out of memory displaying error message!"; static char *fatalMessage = NULL; -static char *fatalInfo = - joinStrings("Initialisation error! Something went wrong before we even got started!", - ""); +static char *fatalInfo = joinStrings("Initialisation error! Something went wrong before we even got started!", ""); extern int numResourceNames /* = 0*/; extern char * *allResourceNames /*= NULL*/; @@ -85,9 +83,7 @@ void warning(const char *l) { void registerWindowForFatal() { delete fatalInfo; fatalInfo = - joinStrings( - "There's an error with this SLUDGE game! If you're designing this game, please turn on verbose error messages in the project manager and recompile. If not, please contact the author saying where and how this problem occured.", - ""); + joinStrings("There's an error with this SLUDGE game! If you're designing this game, please turn on verbose error messages in the project manager and recompile. If not, please contact the author saying where and how this problem occured.", ""); } #if 0 @@ -132,8 +128,7 @@ void setFatalInfo(const char *userFunc, const char *BIF) { delete fatalInfo; fatalInfo = new char[strlen(userFunc) + strlen(BIF) + 38]; if (fatalInfo) - sprintf(fatalInfo, "Currently in this sub: %s\nCalling: %s", userFunc, - BIF); + sprintf(fatalInfo, "Currently in this sub: %s\nCalling: %s", userFunc, BIF); debug(kSludgeDebugFatal, "%s", fatalInfo); } @@ -144,8 +139,7 @@ void setResourceForFatal(int n) { int fatal(const char *str1) { if (numResourceNames && resourceForFatal != -1) { const char *r = resourceNameFromNum(resourceForFatal); - char *newStr = new char[strlen(str1) + strlen(r) + strlen(fatalInfo) - + 14]; + char *newStr = new char[strlen(str1) + strlen(r) + strlen(fatalInfo) + 14]; if (checkNew(newStr)) { sprintf(newStr, "%s\nResource: %s\n\n%s", fatalInfo, r, str1); inFatal(newStr); diff --git a/engines/sludge/objtypes.cpp b/engines/sludge/objtypes.cpp index 3c79374e8c..a765f3f852 100644 --- a/engines/sludge/objtypes.cpp +++ b/engines/sludge/objtypes.cpp @@ -79,8 +79,7 @@ objectType *loadObjectType(int i) { } newType->numCom = bigDataFile->readUint16BE(); - newType->allCombis = - (newType->numCom) ? new combination[newType->numCom] : NULL; + newType->allCombis = (newType->numCom) ? new combination[newType->numCom] : NULL; #if DEBUG_COMBINATIONS FILE *callEventLog = fopen("callEventLog.txt", "at"); diff --git a/engines/sludge/people.cpp b/engines/sludge/people.cpp index 9b19bbf847..fb21037b3d 100644 --- a/engines/sludge/people.cpp +++ b/engines/sludge/people.cpp @@ -71,8 +71,7 @@ inline int TF_abs(int a) { } void setFrames(onScreenPerson &m, int a) { - m.myAnim = m.myPersona->animation[(a * m.myPersona->numDirections) - + m.direction]; + m.myAnim = m.myPersona->animation[(a * m.myPersona->numDirections) + m.direction]; } personaAnimation *createPersonaAnim(int num, variableStack *&stacky) { @@ -93,10 +92,8 @@ personaAnimation *createPersonaAnim(int num, variableStack *&stacky) { } else if (stacky->thisVar.varType == SVT_FUNC) { newP->frames[a].noise = -stacky->thisVar.varData.intValue; } else if (stacky->thisVar.varType == SVT_STACK) { - getValueType(frameNum, SVT_INT, - stacky->thisVar.varData.theStack->first->thisVar); - getValueType(howMany, SVT_INT, - stacky->thisVar.varData.theStack->first->next->thisVar); + getValueType(frameNum, SVT_INT, stacky->thisVar.varData.theStack->first->thisVar); + getValueType(howMany, SVT_INT, stacky->thisVar.varData.theStack->first->next->thisVar); } else { getValueType(frameNum, SVT_INT, stacky->thisVar); howMany = 1; @@ -182,10 +179,7 @@ bool initPeople() { void spinStep(onScreenPerson *thisPerson) { int diff = (thisPerson->angle + 360) - thisPerson->wantAngle; - int eachSlice = - thisPerson->spinSpeed ? - thisPerson->spinSpeed : - (360 / thisPerson->myPersona->numDirections); + int eachSlice = thisPerson->spinSpeed ? thisPerson->spinSpeed : (360 / thisPerson->myPersona->numDirections); while (diff > 180) { diff -= 360; } @@ -217,8 +211,7 @@ bool turnPersonToFace(int thisNum, int direc) { thisPerson->walking = false; thisPerson->spinning = false; turnMeAngle(thisPerson, direc); - setFrames(*thisPerson, - (thisPerson == speech->currentTalker) ? ANI_TALK : ANI_STAND); + setFrames(*thisPerson, (thisPerson == speech->currentTalker) ? ANI_TALK : ANI_STAND); return true; } return false; @@ -295,106 +288,106 @@ enum drawModes { void setMyDrawMode(onScreenPerson *moveMe, int h) { switch (h) { - case drawModeTransparent3: - moveMe->r = moveMe->g = moveMe->b = 0; - moveMe->colourmix = 0; - moveMe->transparency = 64; - break; - case drawModeTransparent2: - moveMe->r = moveMe->g = moveMe->b = 0; - moveMe->colourmix = 0; - moveMe->transparency = 128; - break; - case drawModeTransparent1: - moveMe->r = moveMe->g = moveMe->b = 0; - moveMe->colourmix = 0; - moveMe->transparency = 192; - break; - case drawModeInvisible: - moveMe->r = moveMe->g = moveMe->b = 0; - moveMe->colourmix = 0; - moveMe->transparency = 254; - break; - case drawModeDark1: - moveMe->r = moveMe->g = moveMe->b = 0; - moveMe->colourmix = 192; - moveMe->transparency = 0; - break; - case drawModeDark2: - moveMe->r = moveMe->g = moveMe->b = 0; - moveMe->colourmix = 128; - moveMe->transparency = 0; - break; - case drawModeDark3: - moveMe->r = moveMe->g = moveMe->b = 0; - moveMe->colourmix = 64; - moveMe->transparency = 0; - break; - case drawModeBlack: - moveMe->r = moveMe->g = moveMe->b = 0; - moveMe->colourmix = 255; - moveMe->transparency = 0; - break; - case drawModeShadow1: - moveMe->r = moveMe->g = moveMe->b = 0; - moveMe->colourmix = 255; - moveMe->transparency = 64; - break; - case drawModeShadow2: - moveMe->r = moveMe->g = moveMe->b = 0; - moveMe->colourmix = 255; - moveMe->transparency = 128; - break; - case drawModeShadow3: - moveMe->r = moveMe->g = moveMe->b = 0; - moveMe->colourmix = 255; - moveMe->transparency = 192; - break; - case drawModeFoggy3: - moveMe->r = moveMe->g = moveMe->b = 128; - moveMe->colourmix = 192; - moveMe->transparency = 0; - break; - case drawModeFoggy2: - moveMe->r = moveMe->g = moveMe->b = 128; - moveMe->colourmix = 128; - moveMe->transparency = 0; - break; - case drawModeFoggy1: - moveMe->r = moveMe->g = moveMe->b = 128; - moveMe->colourmix = 64; - moveMe->transparency = 0; - break; - case drawModeFoggy4: - moveMe->r = moveMe->g = moveMe->b = 128; - moveMe->colourmix = 255; - moveMe->transparency = 0; - break; - case drawModeGlow3: - moveMe->r = moveMe->g = moveMe->b = 255; - moveMe->colourmix = 192; - moveMe->transparency = 0; - break; - case drawModeGlow2: - moveMe->r = moveMe->g = moveMe->b = 255; - moveMe->colourmix = 128; - moveMe->transparency = 0; - break; - case drawModeGlow1: - moveMe->r = moveMe->g = moveMe->b = 255; - moveMe->colourmix = 64; - moveMe->transparency = 0; - break; - case drawModeGlow4: - moveMe->r = moveMe->g = moveMe->b = 255; - moveMe->colourmix = 255; - moveMe->transparency = 0; - break; - default: - moveMe->r = moveMe->g = moveMe->b = 0; - moveMe->colourmix = 0; - moveMe->transparency = 0; - break; + case drawModeTransparent3: + moveMe->r = moveMe->g = moveMe->b = 0; + moveMe->colourmix = 0; + moveMe->transparency = 64; + break; + case drawModeTransparent2: + moveMe->r = moveMe->g = moveMe->b = 0; + moveMe->colourmix = 0; + moveMe->transparency = 128; + break; + case drawModeTransparent1: + moveMe->r = moveMe->g = moveMe->b = 0; + moveMe->colourmix = 0; + moveMe->transparency = 192; + break; + case drawModeInvisible: + moveMe->r = moveMe->g = moveMe->b = 0; + moveMe->colourmix = 0; + moveMe->transparency = 254; + break; + case drawModeDark1: + moveMe->r = moveMe->g = moveMe->b = 0; + moveMe->colourmix = 192; + moveMe->transparency = 0; + break; + case drawModeDark2: + moveMe->r = moveMe->g = moveMe->b = 0; + moveMe->colourmix = 128; + moveMe->transparency = 0; + break; + case drawModeDark3: + moveMe->r = moveMe->g = moveMe->b = 0; + moveMe->colourmix = 64; + moveMe->transparency = 0; + break; + case drawModeBlack: + moveMe->r = moveMe->g = moveMe->b = 0; + moveMe->colourmix = 255; + moveMe->transparency = 0; + break; + case drawModeShadow1: + moveMe->r = moveMe->g = moveMe->b = 0; + moveMe->colourmix = 255; + moveMe->transparency = 64; + break; + case drawModeShadow2: + moveMe->r = moveMe->g = moveMe->b = 0; + moveMe->colourmix = 255; + moveMe->transparency = 128; + break; + case drawModeShadow3: + moveMe->r = moveMe->g = moveMe->b = 0; + moveMe->colourmix = 255; + moveMe->transparency = 192; + break; + case drawModeFoggy3: + moveMe->r = moveMe->g = moveMe->b = 128; + moveMe->colourmix = 192; + moveMe->transparency = 0; + break; + case drawModeFoggy2: + moveMe->r = moveMe->g = moveMe->b = 128; + moveMe->colourmix = 128; + moveMe->transparency = 0; + break; + case drawModeFoggy1: + moveMe->r = moveMe->g = moveMe->b = 128; + moveMe->colourmix = 64; + moveMe->transparency = 0; + break; + case drawModeFoggy4: + moveMe->r = moveMe->g = moveMe->b = 128; + moveMe->colourmix = 255; + moveMe->transparency = 0; + break; + case drawModeGlow3: + moveMe->r = moveMe->g = moveMe->b = 255; + moveMe->colourmix = 192; + moveMe->transparency = 0; + break; + case drawModeGlow2: + moveMe->r = moveMe->g = moveMe->b = 255; + moveMe->colourmix = 128; + moveMe->transparency = 0; + break; + case drawModeGlow1: + moveMe->r = moveMe->g = moveMe->b = 255; + moveMe->colourmix = 64; + moveMe->transparency = 0; + break; + case drawModeGlow4: + moveMe->r = moveMe->g = moveMe->b = 255; + moveMe->colourmix = 255; + moveMe->transparency = 0; + break; + default: + moveMe->r = moveMe->g = moveMe->b = 0; + moveMe->colourmix = 0; + moveMe->transparency = 0; + break; } } @@ -417,8 +410,7 @@ void setPersonTransparency(int ob, unsigned char x) { moveMe->transparency = x; } -void setPersonColourise(int ob, unsigned char r, unsigned char g, - unsigned char b, unsigned char colourmix) { +void setPersonColourise(int ob, unsigned char r, unsigned char g, unsigned char b, unsigned char colourmix) { onScreenPerson *moveMe = findPerson(ob); if (!moveMe) return; @@ -474,20 +466,16 @@ void drawPeople() { thisPerson->frameNum = 0; thisPerson->frameTick = myAnim->frames[0].howMany; if (myAnim->frames[thisPerson->frameNum].noise > 0) { - startSound(myAnim->frames[thisPerson->frameNum].noise, - false); + startSound(myAnim->frames[thisPerson->frameNum].noise, false); thisPerson->frameNum++; thisPerson->frameNum %= thisPerson->myAnim->numFrames; - thisPerson->frameTick = - thisPerson->myAnim->frames[thisPerson->frameNum].howMany; + thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany; } else if (myAnim->frames[thisPerson->frameNum].noise) { - startNewFunctionNum( - -myAnim->frames[thisPerson->frameNum].noise, 0, - NULL, noStack); + startNewFunctionNum(-myAnim->frames[thisPerson->frameNum].noise, 0, + NULL, noStack); thisPerson->frameNum++; thisPerson->frameNum %= thisPerson->myAnim->numFrames; - thisPerson->frameTick = - thisPerson->myAnim->frames[thisPerson->frameNum].howMany; + thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany; } } int fNumSign = myAnim->frames[thisPerson->frameNum].frameNum; @@ -499,8 +487,7 @@ void drawPeople() { } if (m != 2) { bool r = false; - r = scaleSprite(myAnim->theSprites->bank.sprites[fNum], - myAnim->theSprites->bank.myPalette, thisPerson, m); + r = scaleSprite(myAnim->theSprites->bank.sprites[fNum], myAnim->theSprites->bank.myPalette, thisPerson, m); if (r) { if (thisPerson->thisType->screenName[0]) { if (personRegion.thisType != thisPerson->thisType) @@ -514,24 +501,19 @@ void drawPeople() { if (!--thisPerson->frameTick) { thisPerson->frameNum++; thisPerson->frameNum %= thisPerson->myAnim->numFrames; - thisPerson->frameTick = - thisPerson->myAnim->frames[thisPerson->frameNum].howMany; + thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany; if (thisPerson->show && myAnim && myAnim->frames) { if (myAnim->frames[thisPerson->frameNum].noise > 0) { - startSound(myAnim->frames[thisPerson->frameNum].noise, - false); + startSound(myAnim->frames[thisPerson->frameNum].noise, false); thisPerson->frameNum++; thisPerson->frameNum %= thisPerson->myAnim->numFrames; - thisPerson->frameTick = - thisPerson->myAnim->frames[thisPerson->frameNum].howMany; + thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany; } else if (myAnim->frames[thisPerson->frameNum].noise) { - startNewFunctionNum( - -myAnim->frames[thisPerson->frameNum].noise, 0, - NULL, noStack); + startNewFunctionNum(-myAnim->frames[thisPerson->frameNum].noise, 0, + NULL, noStack); thisPerson->frameNum++; thisPerson->frameNum %= thisPerson->myAnim->numFrames; - thisPerson->frameTick = - thisPerson->myAnim->frames[thisPerson->frameNum].howMany; + thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany; } } } @@ -548,9 +530,7 @@ void makeSilent(onScreenPerson &me) { } bool handleClosestPoint(int &setX, int &setY, int &setPoly) { - int gotX = 320, gotY = 200, gotPoly = -1, i, j, xTest1, yTest1, xTest2, - yTest2, closestX, closestY, oldJ, currentDistance = 0xFFFFF, - thisDistance; + int gotX = 320, gotY = 200, gotPoly = -1, i, j, xTest1, yTest1, xTest2, yTest2, closestX, closestY, oldJ, currentDistance = 0xFFFFF, thisDistance; // FILE * dbug = fopen ("debug_closest.txt", "at"); // fprintf (dbug, "\nGetting closest point to %i, %i\n", setX, setY); @@ -559,16 +539,11 @@ bool handleClosestPoint(int &setX, int &setY, int &setPoly) { oldJ = currentFloor->polygon[i].numVertices - 1; for (j = 0; j < currentFloor->polygon[i].numVertices; j++) { // fprintf (dbug, "Polygon %i, line %i... ", i, j); - xTest1 = - currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].x; - yTest1 = - currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].y; - xTest2 = - currentFloor->vertex[currentFloor->polygon[i].vertexID[oldJ]].x; - yTest2 = - currentFloor->vertex[currentFloor->polygon[i].vertexID[oldJ]].y; - closestPointOnLine(closestX, closestY, xTest1, yTest1, xTest2, - yTest2, setX, setY); + xTest1 = currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].x; + yTest1 = currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].y; + xTest2 = currentFloor->vertex[currentFloor->polygon[i].vertexID[oldJ]].x; + yTest2 = currentFloor->vertex[currentFloor->polygon[i].vertexID[oldJ]].y; + closestPointOnLine(closestX, closestY, xTest1, yTest1, xTest2, yTest2, setX, setY); // fprintf (dbug, "closest point is %i, %i... ", closestX, closestY); xTest1 = setX - closestX; yTest1 = setY - closestY; @@ -610,8 +585,7 @@ bool doBorderStuff(onScreenPerson *moveMe) { // Grab the index of the second matching corner... int ID, ID2; - if (!getMatchingCorners(currentFloor->polygon[moveMe->inPoly], - currentFloor->polygon[newPoly], ID, ID2)) + if (!getMatchingCorners(currentFloor->polygon[moveMe->inPoly], currentFloor->polygon[newPoly], ID, ID2)) return fatal("Not a valid floor plan!"); // Remember that we're walking to the new polygon... @@ -647,8 +621,7 @@ bool doBorderStuff(onScreenPerson *moveMe) { dy23 *= dy23; dy24 *= dy24; - if (sqrt((double) dx13 + dy13) + sqrt((double) dx23 + dy23) - < sqrt((double) dx14 + dy14) + sqrt((double) dx24 + dy24)) { + if (sqrt((double)dx13 + dy13) + sqrt((double)dx23 + dy23) < sqrt((double)dx14 + dy14) + sqrt((double)dx24 + dy24)) { moveMe->thisStepX = x3; moveMe->thisStepY = y3; } else { @@ -679,9 +652,7 @@ bool walkMe(onScreenPerson *thisPerson, bool move = true) { if (s < 0.2) s = 0.2; - maxDiff = - (TF_abs(xDiff) >= TF_abs(yDiff)) ? - TF_abs(xDiff) : TF_abs(yDiff); + maxDiff = (TF_abs(xDiff) >= TF_abs(yDiff)) ? TF_abs(xDiff) : TF_abs(yDiff); if (TF_abs(maxDiff) > s) { if (thisPerson->spinning) { @@ -690,8 +661,7 @@ bool walkMe(onScreenPerson *thisPerson, bool move = true) { } s = maxDiff / s; if (move) - moveAndScale(*thisPerson, thisPerson->x + xDiff / s, - thisPerson->y + yDiff / (s * 2)); + moveAndScale(*thisPerson, thisPerson->x + xDiff / s, thisPerson->y + yDiff / (s * 2)); return true; } @@ -732,8 +702,7 @@ bool makeWalkingPerson(int x, int y, int objNum, loadedFunction *func, int di) { moveMe->walkToY = y; moveMe->walkToPoly = inFloor(x, y); if (moveMe->walkToPoly == -1) { - if (!handleClosestPoint(moveMe->walkToX, moveMe->walkToY, - moveMe->walkToPoly)) + if (!handleClosestPoint(moveMe->walkToX, moveMe->walkToY, moveMe->walkToPoly)) return false; } @@ -767,8 +736,7 @@ bool stopPerson(int o) { return false; } -bool forceWalkingPerson(int x, int y, int objNum, loadedFunction *func, - int di) { +bool forceWalkingPerson(int x, int y, int objNum, loadedFunction *func, int di) { if (x == 0 && y == 0) return false; onScreenPerson *moveMe = findPerson(objNum); @@ -840,8 +808,7 @@ void walkAllPeople() { spinStep(thisPerson); setFrames(*thisPerson, ANI_STAND); } - if ((!thisPerson->walking) && (!thisPerson->spinning) - && thisPerson->continueAfterWalking) { + if ((!thisPerson->walking) && (!thisPerson->spinning) && thisPerson->continueAfterWalking) { restartFunction(thisPerson->continueAfterWalking); thisPerson->continueAfterWalking = NULL; } @@ -890,12 +857,10 @@ bool addPerson(int x, int y, int objNum, persona *p) { if (fNumSigned < 0) { newPerson->height = 5; } else { - newPerson->height = - p->animation[0]->theSprites->bank.sprites[0].yhot + 5; + newPerson->height = p->animation[0]->theSprites->bank.sprites[0].yhot + 5; } } else { - newPerson->height = p->animation[0]->theSprites->bank.sprites[fNum].yhot - + 5; + newPerson->height = p->animation[0]->theSprites->bank.sprites[fNum].yhot + 5; } // NOW ADD IT IN THE RIGHT PLACE @@ -907,7 +872,7 @@ bool addPerson(int x, int y, int objNum, persona *p) { newPerson->next = (*changethat); (*changethat) = newPerson; - return (bool) (newPerson->thisType != NULL); + return (bool)(newPerson->thisType != NULL); } int timeForAnim(personaAnimation *fram) { @@ -987,8 +952,7 @@ void removeOneCharacter(int i) { onScreenPerson *p = findPerson(i); if (p) { - if (overRegion == &personRegion - && overRegion->thisType == p->thisType) { + if (overRegion == &personRegion && overRegion->thisType == p->thisType) { overRegion = NULL; } @@ -997,8 +961,7 @@ void removeOneCharacter(int i) { p->continueAfterWalking = NULL; onScreenPerson * * killPeople; - for (killPeople = &allPeople; *killPeople != p; killPeople = - &((*killPeople)->next)) { + for (killPeople = &allPeople; *killPeople != p; killPeople = &((*killPeople)->next)) { ; } diff --git a/engines/sludge/people.h b/engines/sludge/people.h index f6d87847e3..442cb925ca 100644 --- a/engines/sludge/people.h +++ b/engines/sludge/people.h @@ -69,43 +69,34 @@ struct onScreenPerson { };
// Initialisation and creation
-
bool initPeople();
bool addPerson(int x, int y, int objNum, persona *p);
// Draw to screen and to backdrop
-
void drawPeople();
void freezePeople(int, int);
// Removalisationisms
-
void killAllPeople();
void killMostPeople();
void removeOneCharacter(int i);
// Things which affect or use all characters
-
onScreenPerson *findPerson(int v);
void setScale(short int h, short int d);
// Things which affect one character
-
void makeTalker(onScreenPerson &me);
void makeSilent(onScreenPerson &me);
void setShown(bool h, int ob);
void setDrawMode(int h, int ob);
void setPersonTransparency(int ob, unsigned char x);
-void setPersonColourise(int ob, unsigned char r, unsigned char g,
- unsigned char b, unsigned char colourmix);
+void setPersonColourise(int ob, unsigned char r, unsigned char g, unsigned char b, unsigned char colourmix);
// Moving 'em
-
void movePerson(int x, int y, int objNum);
-bool makeWalkingPerson(int x, int y, int objNum, struct loadedFunction *func,
- int di);
-bool forceWalkingPerson(int x, int y, int objNum, struct loadedFunction *func,
- int di);
+bool makeWalkingPerson(int x, int y, int objNum, struct loadedFunction *func, int di);
+bool forceWalkingPerson(int x, int y, int objNum, struct loadedFunction *func, int di);
void jumpPerson(int x, int y, int objNum);
void walkAllPeople();
bool turnPersonToFace(int thisNum, int direc);
@@ -114,7 +105,6 @@ bool floatCharacter(int f, int objNum); bool setCharacterWalkSpeed(int f, int objNum);
// Animating 'em
-
void animatePerson(int obj, personaAnimation *);
void animatePerson(int obj, persona *per);
personaAnimation *createPersonaAnim(int num, struct variableStack *&stacky);
diff --git a/engines/sludge/region.cpp b/engines/sludge/region.cpp index efc6908b1b..9c565a3ce0 100644 --- a/engines/sludge/region.cpp +++ b/engines/sludge/region.cpp @@ -47,7 +47,7 @@ void showBoxes() { } void removeScreenRegion(int objectNum) { - screenRegion * * huntRegion = &allScreenRegions; + screenRegion ** huntRegion = &allScreenRegions; screenRegion *killMe; while (*huntRegion) { diff --git a/engines/sludge/savedata.cpp b/engines/sludge/savedata.cpp index e387b92bfb..bb1315299e 100644 --- a/engines/sludge/savedata.cpp +++ b/engines/sludge/savedata.cpp @@ -77,7 +77,7 @@ char *readStringEncoded(Common::File *fp) { if (!checkNew(s)) return NULL; for (a = 0; a < len; a++) { - s[a] = (char) (fp->readByte() ^ encode1); + s[a] = (char)(fp->readByte() ^ encode1); encode1 += encode2; } s[len] = 0; @@ -95,7 +95,7 @@ char *readTextPlain(Common::File *fp) { startPos = fp->pos(); while (keepGoing) { - gotChar = (char) fp->readByte(); + gotChar = (char)fp->readByte(); if ((gotChar == '\n') || (fp->eos())) { keepGoing = false; } else { @@ -125,9 +125,7 @@ bool fileToStack(char *filename, stackHandler *sH) { variable stringVar; stringVar.varType = SVT_NULL; - const char *checker = - saveEncoding ? - "[Custom data (encoded)]\r\n" : "[Custom data (ASCII)]\n"; + const char *checker = saveEncoding ? "[Custom data (encoded)]\r\n" : "[Custom data (ASCII)]\n"; Common::File fd; @@ -153,14 +151,13 @@ bool fileToStack(char *filename, stackHandler *sH) { return fatal("No such file", filename); //TODO: false value } - encode1 = (unsigned char) saveEncoding & 255; - encode2 = (unsigned char) (saveEncoding >> 8); + encode1 = (unsigned char)saveEncoding & 255; + encode2 = (unsigned char)(saveEncoding >> 8); while (*checker) { if (fd.readByte() != *checker) { fd.close(); - return fatal(LOAD_ERROR "This isn't a SLUDGE custom data file:", - filename); + return fatal(LOAD_ERROR "This isn't a SLUDGE custom data file:", filename); } checker++; } @@ -170,8 +167,7 @@ bool fileToStack(char *filename, stackHandler *sH) { if (strcmp(checker, "UN�LO�CKED")) { fd.close(); return fatal( - LOAD_ERROR "The current file encoding setting does not match the encoding setting used when this file was created:", - filename); + LOAD_ERROR "The current file encoding setting does not match the encoding setting used when this file was created:", filename); } delete checker; checker = NULL; @@ -184,25 +180,25 @@ bool fileToStack(char *filename, stackHandler *sH) { if (fd.eos()) break; switch (i) { - case 0: { - char *g = readStringEncoded(&fd); - makeTextVar(stringVar, g); - delete g; - } - break; + case 0: { + char *g = readStringEncoded(&fd); + makeTextVar(stringVar, g); + delete g; + } + break; - case 1: - setVariable(stringVar, SVT_INT, fd.readUint32LE()); - break; + case 1: + setVariable(stringVar, SVT_INT, fd.readUint32LE()); + break; - case 2: - setVariable(stringVar, SVT_INT, fd.readByte()); - break; + case 2: + setVariable(stringVar, SVT_INT, fd.readByte()); + break; - default: - fatal(LOAD_ERROR "Corrupt custom data file:", filename); - fd.close(); - return false; + default: + fatal(LOAD_ERROR "Corrupt custom data file:", filename); + fd.close(); + return false; } } else { char *line = readTextPlain(&fd); diff --git a/engines/sludge/sludge.cpp b/engines/sludge/sludge.cpp index b679a0994f..85775f07cd 100644 --- a/engines/sludge/sludge.cpp +++ b/engines/sludge/sludge.cpp @@ -20,7 +20,7 @@ * */ #include "common/scummsys.h" - + #include "common/config-manager.h" #include "common/debug.h" #include "common/debug-channels.h" @@ -32,10 +32,10 @@ #include "main_loop.h" namespace Sludge { - -SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc) - : Engine(syst), _gameDescription(gameDesc), _console(nullptr) { - + +SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc) : + Engine(syst), _gameDescription(gameDesc), _console(nullptr) { + // register your random source _rnd = new Common::RandomSource("sludge"); @@ -49,19 +49,19 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc) // check init debug("SludgeEngine::SludgeEngine"); } - + SludgeEngine::~SludgeEngine() { // Dispose resources delete _rnd; - + // Remove debug levels DebugMan.clearAllDebugChannels(); - + // Dispose console delete _console; } - + Common::Error SludgeEngine::run() { // init graphics Graphics::PixelFormat format = Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0); @@ -69,12 +69,12 @@ Common::Error SludgeEngine::run() { // create console _console = new SludgeConsole(this); - + // debug log main_loop("Welcome.slg"); - + return Common::kNoError; } - + } // End of namespace Sludge diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp index 9f802283dd..a018d744b5 100644 --- a/engines/sludge/sludger.cpp +++ b/engines/sludge/sludger.cpp @@ -1672,8 +1672,7 @@ bool handleInput() { delete tempString; tempString = NULL; tempStack->next = NULL; - if (!startNewFunctionNum(currentEvents->spaceFunction, 1, NULL, - tempStack)) + if (!startNewFunctionNum(currentEvents->spaceFunction, 1, NULL, tempStack)) return false; } } diff --git a/engines/sludge/sludger.h b/engines/sludge/sludger.h index ef319dbda1..f5030ef732 100644 --- a/engines/sludge/sludger.h +++ b/engines/sludge/sludger.h @@ -82,8 +82,7 @@ extern int iconW, iconH; bool initSludge(char *);
void sludgeDisplay();
-int startNewFunctionNum(unsigned int, unsigned int, loadedFunction *,
- variableStack*&, bool = true);
+int startNewFunctionNum(unsigned int, unsigned int, loadedFunction *, variableStack*&, bool = true);
bool handleInput();
void restartFunction(loadedFunction *fun);
bool loadFunctionCode(loadedFunction *newFunc);
@@ -92,8 +91,7 @@ void saveHandlers(Common::WriteStream *stream); void finishFunction(loadedFunction *fun);
void abortFunction(loadedFunction *fun);
-Common::File *openAndVerify(char *filename, char extra1, char extra2,
- const char *er, int &fileVersion);
+Common::File *openAndVerify(char *filename, char extra1, char extra2, const char *er, int &fileVersion);
void freezeSubs();
void unfreezeSubs();
diff --git a/engines/sludge/sound_bass.cpp b/engines/sludge/sound_bass.cpp index c2fa56d9da..b285b968c9 100644 --- a/engines/sludge/sound_bass.cpp +++ b/engines/sludge/sound_bass.cpp @@ -49,8 +49,7 @@ soundThing soundCache[MAX_SAMPLES]; int defVol = 128; int defSoundVol = 255; -char *loadEntireFileToMemory(Common::SeekableReadStream *inputFile, - uint32_t size) { +char *loadEntireFileToMemory(Common::SeekableReadStream *inputFile, uint32_t size) { char *allData = new char[size]; if (!allData) return NULL; @@ -147,11 +146,7 @@ bool playMOD(int f, int a, int fromTrack) { if (!memImage) return fatal(ERROR_MUSIC_MEMORY_LOW); - mod[a] = - BASS_MusicLoad(true, memImage, 0, length, - BASS_MUSIC_LOOP - | BASS_MUSIC_RAMP/*|BASS_MUSIC_PRESCAN needed too if we're going to set the position in bytes*/, - 0); + mod[a] = BASS_MusicLoad(true, memImage, 0, length, BASS_MUSIC_LOOP | BASS_MUSIC_RAMP/*|BASS_MUSIC_PRESCAN needed too if we're going to set the position in bytes*/, 0); delete memImage; if (!mod[a]) { @@ -162,10 +157,8 @@ bool playMOD(int f, int a, int fromTrack) { if (!BASS_ChannelPlay(mod[a], true)) debugOut("playMOD: Error %d!\n", BASS_ErrorGetCode()); - BASS_ChannelSetPosition(mod[a], MAKELONG(fromTrack, 0), - BASS_POS_MUSIC_ORDER); - BASS_ChannelFlags(mod[a], BASS_SAMPLE_LOOP | BASS_MUSIC_RAMP, - BASS_SAMPLE_LOOP | BASS_MUSIC_RAMP); + BASS_ChannelSetPosition(mod[a], MAKELONG(fromTrack, 0), BASS_POS_MUSIC_ORDER); + BASS_ChannelFlags(mod[a], BASS_SAMPLE_LOOP | BASS_MUSIC_RAMP, BASS_SAMPLE_LOOP | BASS_MUSIC_RAMP); } setResourceForFatal(-1); } @@ -175,8 +168,7 @@ bool playMOD(int f, int a, int fromTrack) { void setMusicVolume(int a, int v) { int ret; if (soundOK && mod[a]) { - ret = BASS_ChannelSetAttribute(mod[a], BASS_ATTRIB_VOL, - (float) v / 256); + ret = BASS_ChannelSetAttribute(mod[a], BASS_ATTRIB_VOL, (float)v / 256); if (!ret) { debugOut("setMusicVolume: Error %d\n", BASS_ErrorGetCode()); } @@ -192,8 +184,7 @@ void setSoundVolume(int a, int v) { int ch = findInSoundCache(a); if (ch != -1) { if (BASS_ChannelIsActive(soundCache[ch].mostRecentChannel)) { - BASS_ChannelSetAttribute(soundCache[ch].mostRecentChannel, - BASS_ATTRIB_VOL, (float) v / 256); + BASS_ChannelSetAttribute(soundCache[ch].mostRecentChannel, BASS_ATTRIB_VOL, (float)v / 256); } } } @@ -203,8 +194,7 @@ bool stillPlayingSound(int ch) { if (soundOK) if (ch != -1) if (soundCache[ch].fileLoaded != -1) - if (BASS_ChannelIsActive(soundCache[ch].mostRecentChannel) - != BASS_ACTIVE_STOPPED) + if (BASS_ChannelIsActive(soundCache[ch].mostRecentChannel) != BASS_ACTIVE_STOPPED) return true; return false; } @@ -318,8 +308,7 @@ int cacheSound(int f) { for (;;) { // soundWarning (" Trying to load sound into slot", a); - soundCache[a].sample = BASS_SampleLoad(true, memImage, 0, length, 65535, - 0); + soundCache[a].sample = BASS_SampleLoad(true, memImage, 0, length, 65535, 0); if (soundCache[a].sample) { soundCache[a].fileLoaded = f; @@ -345,15 +334,12 @@ bool startSound(int f, bool loopy) { soundCache[a].looping = loopy; soundCache[a].vol = defSoundVol; - soundCache[a].mostRecentChannel = BASS_SampleGetChannel( - soundCache[a].sample, false); + soundCache[a].mostRecentChannel = BASS_SampleGetChannel(soundCache[a].sample, false); if (soundCache[a].mostRecentChannel) { BASS_ChannelPlay(soundCache[a].mostRecentChannel, true); - BASS_ChannelSetAttribute(soundCache[a].mostRecentChannel, - BASS_ATTRIB_VOL, defSoundVol); + BASS_ChannelSetAttribute(soundCache[a].mostRecentChannel, BASS_ATTRIB_VOL, defSoundVol); if (loopy) { - BASS_ChannelFlags(soundCache[a].mostRecentChannel, - BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP); // set LOOP flag + BASS_ChannelFlags(soundCache[a].mostRecentChannel, BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP); // set LOOP flag } } diff --git a/engines/sludge/sprbanks.cpp b/engines/sludge/sprbanks.cpp index 8598cb51ac..1ae7774716 100644 --- a/engines/sludge/sprbanks.cpp +++ b/engines/sludge/sprbanks.cpp @@ -52,8 +52,7 @@ loadedSpriteBank *loadBankForAnim(int ID) { debugOut("loadBankForAnim: New sprite bank created OK\n"); return returnMe; } else { - debugOut( - "loadBankForAnim: I guess I couldn't load the sprites...\n"); + debugOut("loadBankForAnim: I guess I couldn't load the sprites...\n"); return NULL; } } else diff --git a/engines/sludge/sprites.h b/engines/sludge/sprites.h index c09ae39d02..f3ec22dc25 100644 --- a/engines/sludge/sprites.h +++ b/engines/sludge/sprites.h @@ -67,19 +67,13 @@ bool loadSpriteBank(char *filename, spriteBank &loadhere); bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont); void fontSprite(int x1, int y1, sprite &single, const spritePalette &fontPal); -void flipFontSprite(int x1, int y1, sprite &single, - const spritePalette &fontPal); +void flipFontSprite(int x1, int y1, sprite &single, const spritePalette &fontPal); -bool scaleSprite(sprite &single, const spritePalette &fontPal, - onScreenPerson *thisPerson, bool mirror); -void pasteSpriteToBackDrop(int x1, int y1, sprite &single, - const spritePalette &fontPal); +bool scaleSprite(sprite &single, const spritePalette &fontPal, onScreenPerson *thisPerson, bool mirror); +void pasteSpriteToBackDrop(int x1, int y1, sprite &single, const spritePalette &fontPal); bool reserveSpritePal(spritePalette &sP, int n); -void fixScaleSprite(int x1, int y1, sprite &single, - const spritePalette &fontPal, onScreenPerson *thisPerson, - const int camX, const int camY, bool); -void burnSpriteToBackDrop(int x1, int y1, sprite &single, - const spritePalette &fontPal); +void fixScaleSprite(int x1, int y1, sprite &single, const spritePalette &fontPal, onScreenPerson *thisPerson, const int camX, const int camY, bool); +void burnSpriteToBackDrop(int x1, int y1, sprite &single, const spritePalette &fontPal); } // End of namespace Sludge diff --git a/engines/sludge/statusba.cpp b/engines/sludge/statusba.cpp index da9d655022..52aeb5da03 100644 --- a/engines/sludge/statusba.cpp +++ b/engines/sludge/statusba.cpp @@ -223,8 +223,8 @@ bool loadStatusBars(Common::SeekableReadStream *stream) { if (! checkNew(newOne)) return false; newOne->text = readString(stream); newOne->next = NULL; - (* viewLine) = newOne; - viewLine = & (newOne->next); + (*viewLine) = newOne; + viewLine = &(newOne->next); } return true; } diff --git a/engines/sludge/thumbnail.cpp b/engines/sludge/thumbnail.cpp index 5e77936fb6..63c7544fff 100644 --- a/engines/sludge/thumbnail.cpp +++ b/engines/sludge/thumbnail.cpp @@ -104,8 +104,8 @@ bool saveThumbnail(Common::WriteStream *stream) { GLuint *tmp = new GLuint [thumbWidth * thumbHeight]; if (! checkNew(image)) return false; glReadPixels(viewportOffsetX, viewportOffsetY, thumbWidth, thumbHeight, GL_RGBA, GL_UNSIGNED_BYTE, tmp); - for (int y = 0; y < thumbHeight; y ++) { - for (int x = 0; x < thumbWidth; x ++) { + for (int y = 0; y < thumbHeight; y++) { + for (int x = 0; x < thumbWidth; x++) { const GLuint a = tmp[y * thumbWidth + x]; image[y * thumbWidth + x] = ((a & 0x00f80000) >> (16 + 3)) | ((a & 0x0000fc00) >> (8 + 2 - 5)) | ((a & 0x000000f8) << (11 - 3)); } @@ -122,8 +122,8 @@ bool saveThumbnail(Common::WriteStream *stream) { #endif setPixelCoords(false); - for (int y = 0; y < thumbHeight; y ++) { - for (int x = 0; x < thumbWidth; x ++) { + for (int y = 0; y < thumbHeight; y++) { + for (int x = 0; x < thumbWidth; x++) { put2bytes((*(image + y * thumbWidth + x)), fp); } } @@ -167,7 +167,7 @@ void showThumbnail(char *filename, int atX, int atY) { int t1, t2; unsigned short c; GLubyte *target; - for (t2 = 0; t2 < fileHeight; t2 ++) { + for (t2 = 0; t2 < fileHeight; t2++) { t1 = 0; while (t1 < fileWidth) { c = (unsigned short) fp->readUint16BE(); diff --git a/engines/sludge/transition.cpp b/engines/sludge/transition.cpp index 73ac73736b..100cc9cc38 100644 --- a/engines/sludge/transition.cpp +++ b/engines/sludge/transition.cpp @@ -380,27 +380,27 @@ void transitionBlinds() { void fixBrightness() { switch (fadeMode) { - case 0: - transitionFader(); - break; - case 1: - resetRandW(); - // Fall through! - case 2: - transitionDisolve(); - break; - case 3: - transitionTV(); - break; - case 4: - transitionBlinds(); - break; - case 5: - transitionCrossFader(); - break; - case 6: - transitionSnapshotBox(); - break; + case 0: + transitionFader(); + break; + case 1: + resetRandW(); + // Fall through! + case 2: + transitionDisolve(); + break; + case 3: + transitionTV(); + break; + case 4: + transitionBlinds(); + break; + case 5: + transitionCrossFader(); + break; + case 6: + transitionSnapshotBox(); + break; } } diff --git a/engines/sludge/variable.cpp b/engines/sludge/variable.cpp index 8d6beb2536..96473cc423 100644 --- a/engines/sludge/variable.cpp +++ b/engines/sludge/variable.cpp @@ -49,36 +49,36 @@ extern char *outputDir; void unlinkVar(variable &thisVar) { switch (thisVar.varType) { - case SVT_STRING: - delete[] thisVar.varData.theString; - thisVar.varData.theString = NULL; - break; - - case SVT_STACK: - thisVar.varData.theStack->timesUsed--; - if (thisVar.varData.theStack->timesUsed <= 0) { - while (thisVar.varData.theStack->first) - trimStack(thisVar.varData.theStack->first); - delete thisVar.varData.theStack; - thisVar.varData.theStack = NULL; - } - break; - - case SVT_FASTARRAY: - thisVar.varData.fastArray->timesUsed--; - if (thisVar.varData.theStack->timesUsed <= 0) { - delete thisVar.varData.fastArray->fastVariables; - delete[] thisVar.varData.fastArray; - thisVar.varData.fastArray = NULL; - } - break; + case SVT_STRING: + delete[] thisVar.varData.theString; + thisVar.varData.theString = NULL; + break; + + case SVT_STACK: + thisVar.varData.theStack->timesUsed--; + if (thisVar.varData.theStack->timesUsed <= 0) { + while (thisVar.varData.theStack->first) + trimStack(thisVar.varData.theStack->first); + delete thisVar.varData.theStack; + thisVar.varData.theStack = NULL; + } + break; + + case SVT_FASTARRAY: + thisVar.varData.fastArray->timesUsed--; + if (thisVar.varData.theStack->timesUsed <= 0) { + delete thisVar.varData.fastArray->fastVariables; + delete[] thisVar.varData.fastArray; + thisVar.varData.fastArray = NULL; + } + break; - case SVT_ANIM: - deleteAnim(thisVar.varData.animHandler); - break; + case SVT_ANIM: + deleteAnim(thisVar.varData.animHandler); + break; - default: - break; + default: + break; } } @@ -101,8 +101,7 @@ personaAnimation *getAnimationFromVar(variable &thisVar) { if (thisVar.varType == SVT_INT && thisVar.varData.intValue == 0) return makeNullAnim(); - fatal("Expecting an animation variable; found variable of type", - typeName[thisVar.varType]); + fatal("Expecting an animation variable; found variable of type", typeName[thisVar.varType]); return NULL; } @@ -116,27 +115,26 @@ persona *getCostumeFromVar(variable &thisVar) { persona *p = NULL; switch (thisVar.varType) { - case SVT_ANIM: - p = new persona; - if (!checkNew(p)) - return NULL; - p->numDirections = 1; - p->animation = new personaAnimation *[3]; - if (!checkNew(p->animation)) - return NULL; + case SVT_ANIM: + p = new persona; + if (!checkNew(p)) + return NULL; + p->numDirections = 1; + p->animation = new personaAnimation *[3]; + if (!checkNew(p->animation)) + return NULL; - for (int iii = 0; iii < 3; iii++) - p->animation[iii] = copyAnim(thisVar.varData.animHandler); + for (int iii = 0; iii < 3; iii++) + p->animation[iii] = copyAnim(thisVar.varData.animHandler); - break; + break; - case SVT_COSTUME: - return thisVar.varData.costumeHandler; - break; + case SVT_COSTUME: + return thisVar.varData.costumeHandler; + break; - default: - fatal("Expecting an animation variable; found variable of type", - typeName[thisVar.varType]); + default: + fatal("Expecting an animation variable; found variable of type", typeName[thisVar.varType]); } return p; @@ -297,29 +295,29 @@ int compareVars(const variable &var1, const variable &var2) { int re = 0; if (var1.varType == var2.varType) { switch (var1.varType) { - case SVT_NULL: - re = 1; - break; + case SVT_NULL: + re = 1; + break; - case SVT_COSTUME: - re = (var1.varData.costumeHandler == var2.varData.costumeHandler); - break; + case SVT_COSTUME: + re = (var1.varData.costumeHandler == var2.varData.costumeHandler); + break; - case SVT_ANIM: - re = (var1.varData.animHandler == var2.varData.animHandler); - break; + case SVT_ANIM: + re = (var1.varData.animHandler == var2.varData.animHandler); + break; - case SVT_STRING: + case SVT_STRING: - re = (strcmp(var1.varData.theString, var2.varData.theString) == 0); - break; + re = (strcmp(var1.varData.theString, var2.varData.theString) == 0); + break; - case SVT_STACK: - re = (var1.varData.theStack == var2.varData.theStack); - break; + case SVT_STACK: + re = (var1.varData.theStack == var2.varData.theStack); + break; - default: - re = (var1.varData.intValue == var2.varData.intValue); + default: + re = (var1.varData.intValue == var2.varData.intValue); } } return re; @@ -338,93 +336,92 @@ void makeTextVar(variable &thisVar, const char *txt) { bool loadStringToVar(variable &thisVar, int value) { makeTextVar(thisVar, getNumberedString(value)); - return (bool) (thisVar.varData.theString != NULL); + return (bool)(thisVar.varData.theString != NULL); } char *getTextFromAnyVar(const variable &from) { switch (from.varType) { - case SVT_STRING: - return copyString(from.varData.theString); - - case SVT_FASTARRAY: { - char *builder = copyString("FAST:"); - char *builder2; - char *grabText; - - for (int i = 0; i < from.varData.fastArray->size; i++) { - builder2 = joinStrings(builder, " "); - if (!builder2) - return NULL; - delete builder; - grabText = getTextFromAnyVar( - from.varData.fastArray->fastVariables[i]); - builder = joinStrings(builder2, grabText); - if (!builder) - return NULL; - delete grabText; - grabText = NULL; - delete builder2; - builder2 = NULL; + case SVT_STRING: + return copyString(from.varData.theString); + + case SVT_FASTARRAY: { + char *builder = copyString("FAST:"); + char *builder2; + char *grabText; + + for (int i = 0; i < from.varData.fastArray->size; i++) { + builder2 = joinStrings(builder, " "); + if (!builder2) + return NULL; + delete builder; + grabText = getTextFromAnyVar(from.varData.fastArray->fastVariables[i]); + builder = joinStrings(builder2, grabText); + if (!builder) + return NULL; + delete grabText; + grabText = NULL; + delete builder2; + builder2 = NULL; + } + return builder; } - return builder; - } - case SVT_STACK: { - char *builder = copyString("ARRAY:"); - char *builder2; - char *grabText; - - variableStack *stacky = from.varData.theStack->first; + case SVT_STACK: { + char *builder = copyString("ARRAY:"); + char *builder2; + char *grabText; + + variableStack *stacky = from.varData.theStack->first; + + while (stacky) { + builder2 = joinStrings(builder, " "); + if (!builder2) + return NULL; + delete builder; + grabText = getTextFromAnyVar(stacky->thisVar); + builder = joinStrings(builder2, grabText); + if (!builder) + return NULL; + delete grabText; + grabText = NULL; + delete builder2; + builder2 = NULL; + stacky = stacky->next; + } + return builder; + } - while (stacky) { - builder2 = joinStrings(builder, " "); - if (!builder2) + case SVT_INT: { + char *buff = new char[10]; + if (!checkNew(buff)) return NULL; - delete builder; - grabText = getTextFromAnyVar(stacky->thisVar); - builder = joinStrings(builder2, grabText); - if (!builder) - return NULL; - delete grabText; - grabText = NULL; - delete builder2; - builder2 = NULL; - stacky = stacky->next; + sprintf(buff, "%i", from.varData.intValue); + return buff; } - return builder; - } - - case SVT_INT: { - char *buff = new char[10]; - if (!checkNew(buff)) - return NULL; - sprintf(buff, "%i", from.varData.intValue); - return buff; - } - case SVT_FILE: { + case SVT_FILE: { // char * buff = new char[15]; // if (! checkNew (buff)) return NULL; // sprintf (buff, "FILE %i", from.varData.intValue); - return joinStrings("", resourceNameFromNum(from.varData.intValue)); - } + return joinStrings("", resourceNameFromNum(from.varData.intValue)); + } - /* case SVT_ANIM: - { - char * buff = new char[20]; - if (! checkNew (buff)) return NULL; - sprintf (buff, "%p", from.varData.animHandler); - return buff; - }*/ - - case SVT_OBJTYPE: { - objectType *thisType = findObjectType(from.varData.intValue); - if (thisType) - return copyString(thisType->screenName); - } + /* case SVT_ANIM: + { + char * buff = new char[20]; + if (! checkNew (buff)) return NULL; + sprintf (buff, "%p", from.varData.animHandler); + return buff; + }*/ + + case SVT_OBJTYPE: { + objectType *thisType = findObjectType(from.varData.intValue); + if (thisType) + return copyString(thisType->screenName); + } - default: - break; + default: + break; } return copyString(typeName[from.varType]); @@ -432,23 +429,23 @@ char *getTextFromAnyVar(const variable &from) { bool getBoolean(const variable &from) { switch (from.varType) { - case SVT_NULL: - return false; + case SVT_NULL: + return false; - case SVT_INT: - return (bool) (from.varData.intValue != 0); + case SVT_INT: + return (bool)(from.varData.intValue != 0); - case SVT_STACK: - return (bool) (from.varData.theStack->first != NULL); + case SVT_STACK: + return (bool)(from.varData.theStack->first != NULL); - case SVT_STRING: - return (bool) (from.varData.theString[0] != 0); + case SVT_STRING: + return (bool)(from.varData.theString[0] != 0); - case SVT_FASTARRAY: - return (bool) (from.varData.fastArray->size != 0); + case SVT_FASTARRAY: + return (bool)(from.varData.fastArray->size != 0); - default: - break; + default: + break; } return true; } @@ -456,41 +453,41 @@ bool getBoolean(const variable &from) { bool copyMain(const variable &from, variable &to) { to.varType = from.varType; switch (to.varType) { - case SVT_INT: - case SVT_FUNC: - case SVT_BUILT: - case SVT_FILE: - case SVT_OBJTYPE: - to.varData.intValue = from.varData.intValue; - return true; - - case SVT_FASTARRAY: - to.varData.fastArray = from.varData.fastArray; - to.varData.fastArray->timesUsed++; - return true; - - case SVT_STRING: - to.varData.theString = copyString(from.varData.theString); - return to.varData.theString ? true : false; - - case SVT_STACK: - to.varData.theStack = from.varData.theStack; - to.varData.theStack->timesUsed++; - return true; - - case SVT_COSTUME: - to.varData.costumeHandler = from.varData.costumeHandler; - return true; - - case SVT_ANIM: - to.varData.animHandler = copyAnim(from.varData.animHandler); - return true; - - case SVT_NULL: - return true; - - default: - break; + case SVT_INT: + case SVT_FUNC: + case SVT_BUILT: + case SVT_FILE: + case SVT_OBJTYPE: + to.varData.intValue = from.varData.intValue; + return true; + + case SVT_FASTARRAY: + to.varData.fastArray = from.varData.fastArray; + to.varData.fastArray->timesUsed++; + return true; + + case SVT_STRING: + to.varData.theString = copyString(from.varData.theString); + return to.varData.theString ? true : false; + + case SVT_STACK: + to.varData.theStack = from.varData.theStack; + to.varData.theStack->timesUsed++; + return true; + + case SVT_COSTUME: + to.varData.costumeHandler = from.varData.costumeHandler; + return true; + + case SVT_ANIM: + to.varData.animHandler = copyAnim(from.varData.animHandler); + return true; + + case SVT_NULL: + return true; + + default: + break; } fatal("Unknown value type"); return false; @@ -509,8 +506,7 @@ variable *fastArrayGetByIndex(fastArrayHandler *vS, unsigned int theIndex) { bool makeFastArraySize(variable &to, int size) { if (size < 0) - return fatal( - "Can't create a fast array with a negative number of elements!"); + return fatal("Can't create a fast array with a negative number of elements!"); unlinkVar(to); to.varType = SVT_FASTARRAY; to.varData.fastArray = new fastArrayHandler; @@ -561,8 +557,7 @@ bool addVarToStack(const variable &va, variableStack *&thisStack) { return false; newStack->next = thisStack; thisStack = newStack; - debug(kSludgeDebugStackMachine, "Variable %s was added to stack", - getTextFromAnyVar(va)); + debug(kSludgeDebugStackMachine, "Variable %s was added to stack", getTextFromAnyVar(va)); return true; } @@ -578,13 +573,11 @@ bool addVarToStackQuick(variable &va, variableStack *&thisStack) { newStack->next = thisStack; thisStack = newStack; - debug(kSludgeDebugStackMachine, "Variable %s was added to stack quick", - getTextFromAnyVar(va)); + debug(kSludgeDebugStackMachine, "Variable %s was added to stack quick", getTextFromAnyVar(va)); return true; } -bool stackSetByIndex(variableStack *vS, unsigned int theIndex, - const variable &va) { +bool stackSetByIndex(variableStack *vS, unsigned int theIndex, const variable &va) { while (theIndex--) { vS = vS->next; if (!vS) @@ -603,8 +596,7 @@ variable *stackGetByIndex(variableStack *vS, unsigned int theIndex) { return &(vS->thisVar); } -int deleteVarFromStack(const variable &va, variableStack *&thisStack, - bool allOfEm) { +int deleteVarFromStack(const variable &va, variableStack *&thisStack, bool allOfEm) { variableStack * * huntVar = &thisStack; variableStack *killMe; int reply = 0; @@ -640,12 +632,8 @@ variableStack *stackFindLast(variableStack *hunt) { bool getValueType(int &toHere, variableType vT, const variable &v) { //if (! v) return false; if (v.varType != vT) { - char *e1 = - joinStrings( - "Can only perform specified operation on a value which is of type ", - typeName[vT]); - char *e2 = joinStrings("... value supplied was of type ", - typeName[v.varType]); + char *e1 = joinStrings("Can only perform specified operation on a value which is of type ", typeName[vT]); + char *e2 = joinStrings("... value supplied was of type ", typeName[v.varType]); fatal(e1, e2); return false; @@ -658,8 +646,7 @@ void trimStack(variableStack *&stack) { variableStack *killMe = stack; stack = stack->next; - debug(kSludgeDebugStackMachine, "Variable %s was removed from stack", - getTextFromAnyVar(killMe->thisVar)); + debug(kSludgeDebugStackMachine, "Variable %s was removed from stack", getTextFromAnyVar(killMe->thisVar)); // When calling this, we've ALWAYS checked that stack != NULL unlinkVar(killMe->thisVar); diff --git a/engines/sludge/vid.cpp b/engines/sludge/vid.cpp index 00e2063938..0aab819b92 100644 --- a/engines/sludge/vid.cpp +++ b/engines/sludge/vid.cpp @@ -74,8 +74,7 @@ bool getStream(DWORD type, timStream &intoHere) { if (AVIFileGetStream(pAviFile, &intoHere.got, type, 0)) {
intoHere.got = NULL;
return true;
- } else if (AVIStreamInfo(intoHere.got, &intoHere.info,
- sizeof(AVISTREAMINFO))) {
+ } else if (AVIStreamInfo(intoHere.got, &intoHere.info, sizeof(AVISTREAMINFO))) {
return fatal("Can't get stream info");
} else if (AVIStreamReadFormat(intoHere.got, AVIStreamStart(intoHere.got),
NULL, &intoHere.chunkSize)) {
@@ -87,9 +86,7 @@ bool getStream(DWORD type, timStream &intoHere) { if (!intoHere.chunk) {
return fatal("Out of memory");
- } else if (AVIStreamReadFormat(intoHere.got,
- AVIStreamStart(intoHere.got), intoHere.chunk,
- &intoHere.chunkSize)) {
+ } else if (AVIStreamReadFormat(intoHere.got, AVIStreamStart(intoHere.got), intoHere.chunk, &intoHere.chunkSize)) {
return fatal("Couldn't read stream format");
}
}
@@ -231,14 +228,13 @@ return true; }
bool nextVideoFrame() {
-LPBITMAPINFOHEADER lpbi = (LPBITMAPINFOHEADER) AVIStreamGetFrame(pgf,
- videoFrameNum);
+LPBITMAPINFOHEADER lpbi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(pgf, videoFrameNum);
if (!lpbi) {
finishVideo();
return false;
}
-BYTE *pData = (((BYTE *) lpbi) + lpbi->biSize);
+BYTE *pData = (((BYTE *)lpbi) + lpbi->biSize);
int xOff = (winWidth - vidWidth) >> 1;
int yOff = (winHeight + vidHeight) >> 1;
@@ -249,22 +245,20 @@ for (int y = 0; y < vidHeight; y++) { unsigned short int *toHere = startingPoint;
for (int x = 0; x < vidWidth; x++) {
switch (vidBytesPerPixel) {
- case 1:
- (*toHere) = makeGrey(*pData);
- break;
-
- case 3:
- case 4:
- (*toHere) = makeColour(*(pData + 2), *(pData + 1), *pData);
- break;
-
- default: {
- WORD Pixel16 = *((WORD *) pData);
- (*toHere) = makeColour((((UINT)(Pixel16) >> 10) & 0x1F) << 3,
- (((UINT)(Pixel16) >> 5) & 0x1F) << 3,
- (((UINT)(Pixel16) >> 0) & 0x1F) << 3);
- }
- break;
+ case 1:
+ (*toHere) = makeGrey(*pData);
+ break;
+
+ case 3:
+ case 4:
+ (*toHere) = makeColour(*(pData + 2), *(pData + 1), *pData);
+ break;
+
+ default: {
+ WORD Pixel16 = *((WORD *)pData);
+ (*toHere) = makeColour((((UINT)(Pixel16) >> 10) & 0x1F) << 3, (((UINT)(Pixel16) >> 5) & 0x1F) << 3, (((UINT)(Pixel16) >> 0) & 0x1F) << 3);
+ }
+ break;
}
pData += vidBytesPerPixel;
toHere++;
diff --git a/engines/sludge/zbuffer.cpp b/engines/sludge/zbuffer.cpp index d81fde6dd5..865a62e6a2 100644 --- a/engines/sludge/zbuffer.cpp +++ b/engines/sludge/zbuffer.cpp @@ -75,133 +75,140 @@ bool setZBuffer(int y) { setResourceForFatal(y); zBuffer.originalNum = y; - if (! openFileFromNum(y)) return false; - if (fgetc(bigDataFile) != 'S') return fatal("Not a Z-buffer file"); - if (fgetc(bigDataFile) != 'z') return fatal("Not a Z-buffer file"); - if (fgetc(bigDataFile) != 'b') return fatal("Not a Z-buffer file"); - - switch (fgetc(bigDataFile)) { - case 0: - zBuffer.width = 640; - zBuffer.height = 480; - break; - - case 1: - zBuffer.width = bigDataFile->readUint16BE(); - zBuffer.height = bigDataFile->readUint16BE(); - break; - - default: - return fatal("Extended Z-buffer format not supported in this version of the SLUDGE engine"); - } - if (zBuffer.width != sceneWidth || zBuffer.height != sceneHeight) { - char tmp[256]; - sprintf(tmp, "Z-w: %d Z-h:%d w: %d, h:%d", zBuffer.width, zBuffer.height, sceneWidth, sceneHeight); - return fatal("Z-buffer width and height don't match scene width and height", tmp); - } + if (!openFileFromNum(y)) + return false; + if (bigDataFile->readByte() != 'S') + return fatal("Not a Z-buffer file"); + if (bigDataFile->readByte() != 'z') + return fatal("Not a Z-buffer file"); + if (bigDataFile->readByte() != 'b') + return fatal("Not a Z-buffer file"); + + switch (bigDataFile->readByte()) { + case 0: + zBuffer.width = 640; + zBuffer.height = 480; + break; + + case 1: + zBuffer.width = bigDataFile->readUint16BE(); + zBuffer.height = bigDataFile->readUint16BE(); + break; + + default: + return fatal("Extended Z-buffer format not supported in this version of the SLUDGE engine"); + } + if (zBuffer.width != sceneWidth || zBuffer.height != sceneHeight) { + char tmp[256]; + sprintf(tmp, "Z-w: %d Z-h:%d w: %d, h:%d", zBuffer.width, zBuffer.height, sceneWidth, sceneHeight); + return fatal("Z-buffer width and height don't match scene width and height", tmp); + } - zBuffer.numPanels = fgetc(bigDataFile); - for (y = 0; y < zBuffer.numPanels; y ++) { - yPalette[y] = bigDataFile->readUint16BE(); - } - sortZPal(yPalette, sorted, zBuffer.numPanels); - for (y = 0; y < zBuffer.numPanels; y ++) { - zBuffer.panel[y] = yPalette[sorted[y]]; - sortback[sorted[y]] = y; - } + zBuffer.numPanels = bigDataFile->readByte(); + for (y = 0; y < zBuffer.numPanels; y++) { + yPalette[y] = bigDataFile->readUint16BE(); + } + sortZPal(yPalette, sorted, zBuffer.numPanels); + for (y = 0; y < zBuffer.numPanels; y++) { + zBuffer.panel[y] = yPalette[sorted[y]]; + sortback[sorted[y]] = y; + } - int picWidth = sceneWidth; - int picHeight = sceneHeight; - if (! NPOT_textures) { - picWidth = getNextPOT(picWidth); - picHeight = getNextPOT(picHeight); - } - zBuffer.tex = new GLubyte [picHeight * picWidth]; - if (! checkNew(zBuffer.tex)) return false; - - for (y = 0; y < sceneHeight; y ++) { - for (x = 0; x < sceneWidth; x ++) { - if (stillToGo == 0) { - n = fgetc(bigDataFile); - stillToGo = n >> 4; - if (stillToGo == 15) stillToGo = bigDataFile->readUint16BE() + 16l; - else stillToGo ++; - n &= 15; + int picWidth = sceneWidth; + int picHeight = sceneHeight; + if (!NPOT_textures) { + picWidth = getNextPOT(picWidth); + picHeight = getNextPOT(picHeight); + } + zBuffer.tex = new GLubyte[picHeight * picWidth]; + if (!checkNew(zBuffer.tex)) + return false; + + for (y = 0; y < sceneHeight; y++) { + for (x = 0; x < sceneWidth; x++) { + if (stillToGo == 0) { + n = bigDataFile->readByte(); + stillToGo = n >> 4; + if (stillToGo == 15) + stillToGo = bigDataFile->readUint16BE() + 16l; + else + stillToGo++; + n &= 15; + } + zBuffer.tex[y * picWidth + x] = sortback[n] * 16; + stillToGo--; } - zBuffer.tex[y * picWidth + x] = sortback[n] * 16; - stillToGo --; } - } - finishAccess(); + finishAccess(); #endif - setResourceForFatal(-1); + setResourceForFatal(-1); #if 0 - if (! zBuffer.texName) glGenTextures(1, &zBuffer.texName); - glBindTexture(GL_TEXTURE_2D, zBuffer.texName); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - - texImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, picWidth, picHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, zBuffer.tex, zBuffer.texName); + if (! zBuffer.texName) glGenTextures(1, &zBuffer.texName); + glBindTexture(GL_TEXTURE_2D, zBuffer.texName); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + + texImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, picWidth, picHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, zBuffer.tex, zBuffer.texName); #endif - return true; -} + return true; + } -void drawZBuffer(int x, int y, bool upsidedown) { - int i; + void drawZBuffer(int x, int y, bool upsidedown) { + int i; #if 0 - if (! zBuffer.tex) return; + if (! zBuffer.tex) return; - glEnable(GL_DEPTH_TEST); - glEnable(GL_BLEND); - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); - glDepthMask(GL_TRUE); + glEnable(GL_DEPTH_TEST); + glEnable(GL_BLEND); + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + glDepthMask(GL_TRUE); - glUseProgram(shader.texture); + glUseProgram(shader.texture); - setPMVMatrix(shader.texture); + setPMVMatrix(shader.texture); - //glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - glBindTexture(GL_TEXTURE_2D, zBuffer.texName); + //glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glBindTexture(GL_TEXTURE_2D, zBuffer.texName); - setPrimaryColor(1.0, 1.0, 1.0, 1.0); + setPrimaryColor(1.0, 1.0, 1.0, 1.0); - for (i = 1; i < zBuffer.numPanels; i++) { - GLfloat z = 1.0 - (double) i * (1.0 / 128.0); + for (i = 1; i < zBuffer.numPanels; i++) { + GLfloat z = 1.0 - (double) i * (1.0 / 128.0); - GLfloat vy1 = -y, vy2 = zBuffer.height - y; - if (upsidedown) { - vy1 += zBuffer.height; - vy2 -= zBuffer.height; - } + GLfloat vy1 = -y, vy2 = zBuffer.height - y; + if (upsidedown) { + vy1 += zBuffer.height; + vy2 -= zBuffer.height; + } - const GLfloat vertices[] = { - (GLfloat) - x, vy1, z, - (GLfloat)zBuffer.width - x, vy1, z, - (GLfloat) - x, vy2, z, - (GLfloat)zBuffer.width - x, vy2, z - }; - - const GLfloat texCoords[] = { - 0.0f, 0.0f, - backdropTexW, 0.0f, - 0.0f, backdropTexH, - backdropTexW, backdropTexH - }; - - glUniform1i(glGetUniformLocation(shader.texture, "zBuffer"), 1); - glUniform1f(glGetUniformLocation(shader.texture, "zBufferLayer"), i); - - drawQuad(shader.texture, vertices, 1, texCoords); - glUniform1i(glGetUniformLocation(shader.texture, "zBuffer"), 0); - } + const GLfloat vertices[] = { + (GLfloat) - x, vy1, z, + (GLfloat)zBuffer.width - x, vy1, z, + (GLfloat) - x, vy2, z, + (GLfloat)zBuffer.width - x, vy2, z + }; + + const GLfloat texCoords[] = { + 0.0f, 0.0f, + backdropTexW, 0.0f, + 0.0f, backdropTexH, + backdropTexW, backdropTexH + }; + + glUniform1i(glGetUniformLocation(shader.texture, "zBuffer"), 1); + glUniform1f(glGetUniformLocation(shader.texture, "zBufferLayer"), i); + + drawQuad(shader.texture, vertices, 1, texCoords); + glUniform1i(glGetUniformLocation(shader.texture, "zBuffer"), 0); + } - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glDepthMask(GL_FALSE); - glDisable(GL_BLEND); - glUseProgram(0); + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glDepthMask(GL_FALSE); + glDisable(GL_BLEND); + glUseProgram(0); #endif -} + } -} // End of namespace Sludge + } // End of namespace Sludge |