diff options
author | Marcus Comstedt | 2002-02-27 01:02:16 +0000 |
---|---|---|
committer | Marcus Comstedt | 2002-02-27 01:02:16 +0000 |
commit | 2b99e57578c34125e61bc24ee8e6fa553fb6e73a (patch) | |
tree | 7d1da0d8d7cb6618bc02fabb8226acb1ebff0a59 /dc | |
parent | 038cd2a3c2396613cdca92aa8ecb4a78e6694a6a (diff) | |
download | scummvm-rg350-2b99e57578c34125e61bc24ee8e6fa553fb6e73a.tar.gz scummvm-rg350-2b99e57578c34125e61bc24ee8e6fa553fb6e73a.tar.bz2 scummvm-rg350-2b99e57578c34125e61bc24ee8e6fa553fb6e73a.zip |
Compressed savegames.
svn-id: r3633
Diffstat (limited to 'dc')
-rw-r--r-- | dc/Makefile | 6 | ||||
-rw-r--r-- | dc/vmsave.cpp | 31 |
2 files changed, 32 insertions, 5 deletions
diff --git a/dc/Makefile b/dc/Makefile index 0336ad08da..18092baeb8 100644 --- a/dc/Makefile +++ b/dc/Makefile @@ -10,7 +10,7 @@ DEFINES = -D__DC__ -DNONSTANDARD_PORT -DUSE_ADLIB -DNONSTANDARD_SAVE LDFLAGS := -Wl,-Ttext,0x8c010000 -nostartfiles ronin/crt0.o INCLUDES:= -I./ -I../ -I../sound CPPFLAGS= $(DEFINES) $(INCLUDES) -LIBS = ronin/libronin.a -lm +LIBS = ronin/libronin.a ronin/libz.a -lm INCS = scumm.h scummsys.h stdafx.h portdefs.h dc.h @@ -18,8 +18,8 @@ OBJS = actor.o boxes.o costume.o gfx.o object.o resource.o \ saveload.o script.o scummvm.o sound.o string.o \ sys.o verbs.o script_v1.o script_v2.o debug.o gui.o \ sound/imuse.o sound/fmopl.o sound/adlib.o sound/gmidi.o debugrl.o \ - akos.o dcmain.o display.o audio.o input.o selector.o icon.o label.o \ - vmsave.o + akos.o vars.o dcmain.o display.o audio.o input.o selector.o icon.o \ + label.o vmsave.o .cpp.o: $(CC) $(CFLAGS) $(CPPFLAGS) -c $(<) -o $*.o diff --git a/dc/vmsave.cpp b/dc/vmsave.cpp index 2823459625..b9a122b98a 100644 --- a/dc/vmsave.cpp +++ b/dc/vmsave.cpp @@ -25,6 +25,12 @@ #include "dc.h" #include "icon.h" +#include <ronin/zlib.h> + + +// Savegame can not be bigger than this, even before compression +#define MAX_SAVE_SIZE (128*1024) + enum vmsaveResult { VMSAVE_OK, @@ -169,9 +175,19 @@ bool SerializerStream::fopen(const char *filename, const char *mode) c->issave = true; strncpy(c->filename, filename, 16); c->pos = 0; - c->buffer = new char[c->size = 128*1024]; + c->buffer = new char[c->size = MAX_SAVE_SIZE]; return true; } else if(readSaveGame(c->buffer, c->size, filename)) { + if(c->size > 0 && c->buffer[0] != 'S') { + // Data does not start with "SCVM". Maybe compressed? + char *expbuf = new char[MAX_SAVE_SIZE]; + unsigned long destlen = MAX_SAVE_SIZE; + if(!uncompress((Bytef*)expbuf, &destlen, (Bytef*)c->buffer, c->size)) { + delete(c->buffer); + c->buffer = expbuf; + c->size = destlen; + } else delete expbuf; + } c->issave = false; c->pos = 0; return true; @@ -189,9 +205,20 @@ void SerializerStream::fclose() if(context) { vmStreamContext *c = (vmStreamContext *)context; - if(c->issave) + if(c->issave) { + if(c->pos) { + // Try compression + char *compbuf = new char[c->pos]; + unsigned long destlen = c->pos; + if(!compress((Bytef*)compbuf, &destlen, (Bytef*)c->buffer, c->pos)) { + delete c->buffer; + c->buffer = compbuf; + c->pos = destlen; + } else delete compbuf; + } writeSaveGame(&scumm, c->buffer, c->pos, c->filename, icon); + } delete c->buffer; delete c; context = NULL; |