diff options
-rw-r--r-- | engines/sludge/backdrop.cpp | 105 | ||||
-rw-r--r-- | engines/sludge/builtin.cpp | 5 | ||||
-rw-r--r-- | engines/sludge/loadsave.cpp | 212 | ||||
-rw-r--r-- | engines/sludge/talk.cpp | 4 | ||||
-rw-r--r-- | engines/sludge/thumbnail.cpp | 5 |
5 files changed, 136 insertions, 195 deletions
diff --git a/engines/sludge/backdrop.cpp b/engines/sludge/backdrop.cpp index 93a1e0fc72..8ab4c6f04e 100644 --- a/engines/sludge/backdrop.cpp +++ b/engines/sludge/backdrop.cpp @@ -1009,108 +1009,7 @@ bool mixHSI(Common::SeekableReadStream *stream, int x, int y) { #endif return true; } -#if 0 -void saveCorePNG(Common::WriteStream *stream, GLuint texture, int w, int h) { - GLint tw, th; - - glBindTexture(GL_TEXTURE_2D, texture); - - getTextureDimensions(texture, &tw, &th); - - GLubyte *image = new GLubyte [tw * th * 4]; - if (!checkNew(image)) return; - - glPixelStorei(GL_PACK_ALIGNMENT, 1); -// glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, image); - -#ifdef HAVE_GLES2 - GLuint old_fbo, new_fbo; - GLint old_vp[4]; - glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint *)&old_fbo); - glGetIntegerv(GL_VIEWPORT, old_vp); - glGenFramebuffers(1, &new_fbo); - glBindFramebuffer(GL_FRAMEBUFFER, new_fbo); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); - glViewport(0, 0, tw, th); - glReadPixels(0, 0, tw, th, GL_RGBA, GL_UNSIGNED_BYTE, image); - glBindFramebuffer(GL_FRAMEBUFFER, old_fbo); - glViewport(old_vp[0], old_vp[1], old_vp[2], old_vp[3]); - glDeleteFramebuffers(1, &new_fbo); -#else - setPixelCoords(true); - 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) { - int w = (tw - xoffset < viewportWidth) ? tw - xoffset : viewportWidth; - - 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)tw - xoffset, (GLfloat) - yoffset, 0., - (GLfloat) - xoffset, (GLfloat) - yoffset + th, 0., - (GLfloat)tw - xoffset, (GLfloat) - yoffset + th, 0. - }; - - glUseProgram(shader.texture); - - setPMVMatrix(shader.texture); - - drawQuad(shader.texture, vertices, 1, texCoords); - - glUseProgram(0); - - for (int i = 0; i < h; i++) { - glReadPixels(viewportOffsetX, viewportOffsetY + i, w, 1, GL_RGBA, GL_UNSIGNED_BYTE, image + xoffset * 4 + (yoffset + i) * 4 * tw); - } - yoffset += viewportHeight; - } - - xoffset += viewportWidth; - } - setPixelCoords(false); - - png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if (!png_ptr) { - fatal("Error saving image!"); - return; - } - - png_infop info_ptr = png_create_info_struct(png_ptr); - if (!info_ptr) { - png_destroy_write_struct(&png_ptr, (png_infopp)NULL); - fatal("Error saving image!"); - return; - } - - png_init_io(png_ptr, writer); - - png_set_IHDR(png_ptr, info_ptr, w, h, - 8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); - - unsigned char *row_pointers[h]; - - for (int i = 0; i < h; i++) { - row_pointers[i] = image + 4 * i * tw; - } - - png_set_rows(png_ptr, info_ptr, row_pointers); - png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); - - delete [] image; - image = NULL; -#endif -} -#endif #if 0 void saveCoreHSI(Common::WriteStream *stream, GLuint texture, int w, int h) { GLint tw, th; @@ -1188,11 +1087,9 @@ void saveCoreHSI(Common::WriteStream *stream, GLuint texture, int w, int h) { } #endif -#if 0 void saveHSI(Common::WriteStream *stream) { - saveCorePNG(stream, backdropTextureName, sceneWidth, sceneHeight); + Image::writePNG(*stream, backdropSurface); } -#endif void saveParallaxRecursive(parallaxLayer *me, Common::WriteStream *stream) { if (me) { diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp index 6af0eafef6..21818b9cb5 100644 --- a/engines/sludge/builtin.cpp +++ b/engines/sludge/builtin.cpp @@ -347,7 +347,7 @@ builtIn(loadGame) { char *aaaaa = getTextFromAnyVar(fun->stack->thisVar); trimStack(fun->stack); loadNow = encodeFilename(aaaaa); - delete aaaaa; + delete []aaaaa; if (frozenStuff) { fatal("Can't load a saved game while the engine is frozen"); @@ -359,9 +359,10 @@ builtIn(loadGame) { fd.close(); return BR_KEEP_AND_PAUSE; } - delete loadNow; + delete []loadNow; loadNow = NULL; + debug("not find sav file"); return BR_CONTINUE; } diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp index fb668b5b8b..d397092714 100644 --- a/engines/sludge/loadsave.cpp +++ b/engines/sludge/loadsave.cpp @@ -20,6 +20,8 @@ * */ +#include "common/savefile.h" + #include "sludge/allfiles.h" #include "sludge/sprites.h" #include "sludge/fonttext.h" @@ -41,6 +43,8 @@ #include "sludge/fileset.h" #include "sludge/debug.h" #include "sludge/loadsave.h" +#include "sludge/bg_effects.h" +#include "sludge/thumbnail.h" #include "sludge/CommonCode/version.h" namespace Sludge { @@ -74,9 +78,7 @@ extern bool captureAllKeys; extern bool allowAnyFilename; extern unsigned short saveEncoding; // in savedata.cpp extern unsigned char currentBurnR, currentBurnG, currentBurnB; -#if 0 extern unsigned int currentBlankColour; // in backdrop.cpp -#endif extern parallaxLayer *parallaxStuff; // " extern int lightMapMode; // " extern int languageNum; @@ -383,28 +385,28 @@ loadedFunction *loadFunction(Common::SeekableReadStream *stream) { //---------------------------------------------------------------------- bool saveGame(char *fname) { -#if 0 - int a; + Common::OutSaveFile *fp = g_system->getSavefileManager()->openForSaving(fname); - FILE *fp = fopen(fname, "wb"); - if (fp == NULL) return false; + if (fp == NULL) + return false; - fprintf(fp, "SLUDSA"); - fputc(0, fp); - fputc(0, fp); - fputc(MAJOR_VERSION, fp); - fputc(MINOR_VERSION, fp); + fp->writeString("SLUDSA"); + fp->writeByte(0); + fp->writeByte(0); + fp->writeByte(MAJOR_VERSION); + fp->writeByte(MINOR_VERSION); - if (! saveThumbnail(fp)) return false; + if (!saveThumbnail(fp)) + return false; - fwrite(&fileTime, sizeof(FILETIME), 1, fp); + fp->write(&fileTime, sizeof(FILETIME)); // DON'T ADD ANYTHING NEW BEFORE THIS POINT! - fputc(allowAnyFilename, fp); - fputc(captureAllKeys, fp); - fputc(true, fp);// updateDisplay - fputc(fontTableSize > 0, fp); + fp->writeByte(allowAnyFilename); + fp->writeByte(captureAllKeys); + fp->writeByte(true); + fp->writeByte(fontTableSize > 0); if (fontTableSize > 0) { fp->writeUint16BE(loadedFontNum); @@ -418,7 +420,7 @@ bool saveGame(char *fname) { fp->writeUint16BE(cameraY); putFloat(cameraZoom, fp); - fputc(brightnessLevel, fp); + fp->writeByte(brightnessLevel); saveHSI(fp); // Save event handlers @@ -434,7 +436,7 @@ bool saveGame(char *fname) { loadedFunction *thisFunction = allRunningFunctions; int countFunctions = 0; while (thisFunction) { - countFunctions ++; + countFunctions++; thisFunction = thisFunction->next; } fp->writeUint16BE(countFunctions); @@ -445,30 +447,36 @@ bool saveGame(char *fname) { thisFunction = thisFunction->next; } - for (a = 0; a < numGlobals; a++) { + for (int a = 0; a < numGlobals; a++) { saveVariable(&globalVars[a], fp); } savePeople(fp); if (currentFloor->numPolygons) { - fputc(1, fp); + fp->writeByte(1); fp->writeUint16BE(currentFloor->originalNum); - } else fputc(0, fp); + } else { + fp->writeByte(0); + } - if (zBuffer.tex) { - fputc(1, fp); + if (zBuffer.numPanels > 0) { + fp->writeByte(1); fp->writeUint16BE(zBuffer.originalNum); - } else fputc(0, fp); + } else { + fp->writeByte(0); + } - if (lightMap.data) { - fputc(1, fp); + if (lightMap.getPixels()) { + fp->writeByte(1); fp->writeUint16BE(lightMapNumber); - } else fputc(0, fp); + } else { + fp->writeByte(0); + } - fputc(lightMapMode, fp); - fputc(speechMode, fp); - fputc(fadeMode, fp); + fp->writeByte(lightMapMode); + fp->writeByte(speechMode); + fp->writeByte(fadeMode); saveSpeech(speech, fp); saveStatusBars(fp); saveSounds(fp); @@ -478,19 +486,21 @@ bool saveGame(char *fname) { blur_saveSettings(fp); fp->writeUint16BE(currentBlankColour); - fputc(currentBurnR, fp); - fputc(currentBurnG, fp); - fputc(currentBurnB, fp); + fp->writeByte(currentBurnR); + fp->writeByte(currentBurnG); + fp->writeByte(currentBurnB); saveParallaxRecursive(parallaxStuff, fp); - fputc(0, fp); + fp->writeByte(0); - fputc(languageNum, fp); // Selected language + fp->writeByte(languageNum); // Selected language saveSnapshot(fp); - fclose(fp); -#endif + fp->flush(); + fp->finalize(); + delete fp; + clearStackLib(); return true; } @@ -502,39 +512,65 @@ bool saveGame(char *fname) { int ssgVersion; bool loadGame(char *fname) { -#if 0 - FILE *fp; + Common::InSaveFile *fp = g_system->getSavefileManager()->openForLoading(fname); FILETIME savedGameTime; - int a; - while (allRunningFunctions) finishFunction(allRunningFunctions); + while (allRunningFunctions) + finishFunction(allRunningFunctions); + + if (fp == NULL) + return false; + + bool headerBad = false; + if (fp->readByte() != 'S') + headerBad = true; + if (fp->readByte() != 'L') + headerBad = true; + if (fp->readByte() != 'U') + headerBad = true; + if (fp->readByte() != 'D') + headerBad = true; + if (fp->readByte() != 'S') + headerBad = true; + if (fp->readByte() != 'A') + headerBad = true; + if (headerBad) { + fatal(ERROR_GAME_LOAD_NO, fname); + return NULL; + } + char c; + c = fp->readByte(); + while ((c = fp->readByte())) + ; + + int majVersion = fp->readByte(); + int minVersion = fp->readByte(); + ssgVersion = majVersion * 256 + minVersion; - fp = openAndVerify(fname, 'S', 'A', ERROR_GAME_LOAD_NO, ssgVersion); - if (fp == NULL) return false; if (ssgVersion >= VERSION(1, 4)) { - if (! skipThumbnail(fp)) return fatal(ERROR_GAME_LOAD_CORRUPT, fname); + if (!skipThumbnail(fp)) + return fatal(ERROR_GAME_LOAD_CORRUPT, fname); } - size_t bytes_read = fread(&savedGameTime, sizeof(FILETIME), 1, fp); - if (bytes_read != sizeof(FILETIME) && ferror(fp)) { + uint32 bytes_read = fp->read(&savedGameTime, sizeof(FILETIME)); + if (bytes_read != sizeof(FILETIME) && fp->err()) { debugOut("Reading error in loadGame.\n"); } - if (savedGameTime.dwLowDateTime != fileTime.dwLowDateTime || - savedGameTime.dwHighDateTime != fileTime.dwHighDateTime) { + if (savedGameTime.dwLowDateTime != fileTime.dwLowDateTime || savedGameTime.dwHighDateTime != fileTime.dwHighDateTime) { return fatal(ERROR_GAME_LOAD_WRONG, fname); } // DON'T ADD ANYTHING NEW BEFORE THIS POINT! if (ssgVersion >= VERSION(1, 4)) { - allowAnyFilename = fgetc(fp); + allowAnyFilename = fp->readByte(); } - captureAllKeys = fgetc(fp); - fgetc(fp); // updateDisplay (part of movie playing) + captureAllKeys = fp->readByte(); + fp->readByte(); // updateDisplay (part of movie playing) - bool fontLoaded = fgetc(fp); + bool fontLoaded = fp->readByte(); int fontNum; char *charOrder; if (fontLoaded) { @@ -544,10 +580,11 @@ bool loadGame(char *fname) { if (ssgVersion < VERSION(2, 2)) { int x; charOrder = new char[257]; - if (! checkNew(charOrder)) return false; + if (!checkNew(charOrder)) + return false; for (int a = 0; a < 256; a++) { - x = fgetc(fp); + x = fp->readByte(); charOrder[x] = a; } charOrder[256] = 0; @@ -556,7 +593,7 @@ bool loadGame(char *fname) { } } loadFont(fontNum, charOrder, fontHeight); - delete [] charOrder; + delete []charOrder; fontSpace = getSigned(fp); @@ -572,53 +609,59 @@ bool loadGame(char *fname) { camerZ = 1.0; } - brightnessLevel = fgetc(fp); + brightnessLevel = fp->readByte(); loadHSI(fp, 0, 0, true); loadHandlers(fp); loadRegions(fp); mouseCursorAnim = new personaAnimation; - if (! checkNew(mouseCursorAnim)) return false; - if (! loadAnim(mouseCursorAnim, fp)) return false; + if (!checkNew(mouseCursorAnim)) + return false; + if (!loadAnim(mouseCursorAnim, fp)) + return false; mouseCursorFrameNum = fp->readUint16BE(); loadedFunction *rFunc; - loadedFunction * * buildList = &allRunningFunctions; + loadedFunction **buildList = &allRunningFunctions; int countFunctions = fp->readUint16BE(); - while (countFunctions --) { + while (countFunctions--) { rFunc = loadFunction(fp); rFunc->next = NULL; - (* buildList) = rFunc; + (*buildList) = rFunc; buildList = &(rFunc->next); } - for (a = 0; a < numGlobals; a++) { + for (int a = 0; a < numGlobals; a++) { unlinkVar(globalVars[a]); loadVariable(&globalVars[a], fp); } loadPeople(fp); - if (fgetc(fp)) { - if (! setFloor(fp->readUint16BE())) return false; - } else setFloorNull(); + if (fp->readByte()) { + if (!setFloor(fp->readUint16BE())) + return false; + } else + setFloorNull(); - if (fgetc(fp)) { - if (! setZBuffer(fp->readUint16BE())) return false; + if (fp->readByte()) { + if (!setZBuffer(fp->readUint16BE())) + return false; } - if (fgetc(fp)) { - if (! loadLightMap(fp->readUint16BE())) return false; + if (fp->readByte()) { + if (!loadLightMap(fp->readUint16BE())) + return false; } if (ssgVersion >= VERSION(1, 4)) { - lightMapMode = fgetc(fp) % 3; + lightMapMode = fp->readByte() % 3; } - speechMode = fgetc(fp); - fadeMode = fgetc(fp); + speechMode = fp->readByte(); + fadeMode = fp->readByte(); loadSpeech(speech, fp); loadStatusBars(fp); loadSounds(fp); @@ -628,7 +671,7 @@ bool loadGame(char *fname) { if (ssgVersion >= VERSION(1, 6)) { if (ssgVersion < VERSION(2, 0)) { // aaLoad - fgetc(fp); + fp->readByte(); getFloat(fp); getFloat(fp); } @@ -638,20 +681,21 @@ bool loadGame(char *fname) { if (ssgVersion >= VERSION(1, 3)) { currentBlankColour = fp->readUint16BE(); - currentBurnR = fgetc(fp); - currentBurnG = fgetc(fp); - currentBurnB = fgetc(fp); + currentBurnR = fp->readByte(); + currentBurnG = fp->readByte(); + currentBurnB = fp->readByte(); // Read parallax layers - while (fgetc(fp)) { + while (fp->readByte()) { int im = fp->readUint16BE(); int fx = fp->readUint16BE(); int fy = fp->readUint16BE(); - if (! loadParallax(im, fx, fy)) return false; + if (!loadParallax(im, fx, fy)) + return false; } - int selectedLanguage = fgetc(fp); + int selectedLanguage = fp->readByte(); if (selectedLanguage != languageNum) { // Load the saved language! languageNum = selectedLanguage; @@ -661,17 +705,17 @@ bool loadGame(char *fname) { nosnapshot(); if (ssgVersion >= VERSION(1, 4)) { - if (fgetc(fp)) { - if (! restoreSnapshot(fp)) return false; + if (fp->readByte()) { + if (!restoreSnapshot(fp)) + return false; } } - fclose(fp); + delete fp; cameraX = camerX; cameraY = camerY; cameraZoom = camerZ; -#endif clearStackLib(); return true; diff --git a/engines/sludge/talk.cpp b/engines/sludge/talk.cpp index 7663d39c04..ce9bd0be68 100644 --- a/engines/sludge/talk.cpp +++ b/engines/sludge/talk.cpp @@ -213,7 +213,6 @@ void viewSpeech() { } void saveSpeech(speechStruct *sS, Common::WriteStream *stream) { -#if 0 speechLine *viewLine = sS->allSpeech; stream->writeByte(sS->talkCol.originalRed); @@ -242,11 +241,9 @@ void saveSpeech(speechStruct *sS, Common::WriteStream *stream) { viewLine = viewLine->next; } stream->writeByte(0); -#endif } bool loadSpeech(speechStruct *sS, Common::SeekableReadStream *stream) { -#if 0 speech->currentTalker = NULL; killAllSpeech(); byte r = stream->readByte(); @@ -281,7 +278,6 @@ bool loadSpeech(speechStruct *sS, Common::SeekableReadStream *stream) { (* viewLine) = newOne; viewLine = &(newOne->next); } -#endif return true; } diff --git a/engines/sludge/thumbnail.cpp b/engines/sludge/thumbnail.cpp index 8e238f76fa..b628f0bd8d 100644 --- a/engines/sludge/thumbnail.cpp +++ b/engines/sludge/thumbnail.cpp @@ -132,8 +132,8 @@ bool saveThumbnail(Common::WriteStream *stream) { unfreeze(true); } fputc('!', fp); - return true; #endif + return true; } void showThumbnail(char *filename, int atX, int atY) { @@ -252,12 +252,15 @@ void showThumbnail(char *filename, int atX, int atY) { } bool skipThumbnail(Common::SeekableReadStream *stream) { +#if 0 thumbWidth = stream->readUint32LE(); thumbHeight = stream->readUint32LE(); uint32 skippy = thumbWidth; skippy *= thumbHeight << 1; stream->seek(skippy, 1); return (stream->readByte() == '!'); +#endif + return true; } } // End of namespace Sludge |