[Scummvm-cvs-logs] CVS: scummvm saveload.cpp,1.23,1.24 scumm.h,1.39,1.40

Marcus Comstedt marcus_c at users.sourceforge.net
Sat Feb 2 15:28:03 CET 2002


Update of /cvsroot/scummvm/scummvm
In directory usw-pr-cvs1:/tmp/cvs-serv9198

Modified Files:
	saveload.cpp scumm.h 
Log Message:
Added support for non-FILE* based savegames.

Index: saveload.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saveload.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** saveload.cpp	2002/01/02 11:50:28	1.23
--- saveload.cpp	2002/02/02 23:27:06	1.24
***************
*** 35,39 ****
  bool Scumm::saveState(int slot, bool compat) {
  	char filename[256];
! 	FILE *out;
  	SaveGameHeader hdr;
  	Serializer ser;
--- 35,39 ----
  bool Scumm::saveState(int slot, bool compat) {
  	char filename[256];
! 	SerializerStream out;
  	SaveGameHeader hdr;
  	Serializer ser;
***************
*** 41,46 ****
  	makeSavegameName(filename, slot, compat);
  	
! 	out = fopen(filename,"wb");
! 	if (out==NULL)
  		return false;
  
--- 41,45 ----
  	makeSavegameName(filename, slot, compat);
  	
! 	if (!out.fopen(filename,"wb"))
  		return false;
  
***************
*** 51,55 ****
  	hdr.ver = CURRENT_VER;
  	
! 	fwrite(&hdr, sizeof(hdr), 1, out);
  
  	ser._saveLoadStream = out;
--- 50,54 ----
  	hdr.ver = CURRENT_VER;
  	
! 	out.fwrite(&hdr, sizeof(hdr), 1);
  
  	ser._saveLoadStream = out;
***************
*** 57,61 ****
  	saveOrLoad(&ser);
  
! 	fclose(out);
  	debug(1,"State saved as '%s'", filename);
  	return true;
--- 56,60 ----
  	saveOrLoad(&ser);
  
! 	out.fclose();
  	debug(1,"State saved as '%s'", filename);
  	return true;
***************
*** 64,68 ****
  bool Scumm::loadState(int slot, bool compat) {
  	char filename[256];
!  	FILE *out;
  	int i,j;
  	SaveGameHeader hdr;
--- 63,67 ----
  bool Scumm::loadState(int slot, bool compat) {
  	char filename[256];
!  	SerializerStream out;
  	int i,j;
  	SaveGameHeader hdr;
***************
*** 72,84 ****
  
  	makeSavegameName(filename, slot, compat);
! 	out = fopen(filename,"rb");
! 
! 	if (out==NULL)
  		return false;
  
! 	fread(&hdr, sizeof(hdr), 1, out);
  	if (hdr.type != MKID('SCVM')) {
  		warning("Invalid savegame '%s'", filename);
! 		fclose(out);
  		return false;
  	}
--- 71,81 ----
  
  	makeSavegameName(filename, slot, compat);
! 	if (!out.fopen(filename,"rb"))
  		return false;
  
! 	out.fread(&hdr, sizeof(hdr), 1);
  	if (hdr.type != MKID('SCVM')) {
  		warning("Invalid savegame '%s'", filename);
! 		out.fclose();
  		return false;
  	}
***************
*** 86,90 ****
  	if (hdr.ver != CURRENT_VER) {
  		warning("Invalid version of '%s'", filename);
! 		fclose(out);
  		return false;
  	}
--- 83,87 ----
  	if (hdr.ver != CURRENT_VER) {
  		warning("Invalid version of '%s'", filename);
! 		out.fclose();
  		return false;
  	}
***************
*** 112,116 ****
  	ser._saveOrLoad = false;
  	saveOrLoad(&ser);
! 	fclose(out);
  
  	sb = _screenB;
--- 109,113 ----
  	ser._saveOrLoad = false;
  	saveOrLoad(&ser);
! 	out.fclose();
  
  	sb = _screenB;
***************
*** 155,159 ****
  bool Scumm::getSavegameName(int slot, char *desc) {
  	char filename[256];
! 	FILE *out;
  	SaveGameHeader hdr;
  	bool result;
--- 152,156 ----
  bool Scumm::getSavegameName(int slot, char *desc) {
  	char filename[256];
! 	SerializerStream out;
  	SaveGameHeader hdr;
  	bool result;
***************
*** 161,171 ****
  
  	makeSavegameName(filename, slot, false);
! 	out = fopen(filename,"rb");	
! 	if (out==NULL) {
  		strcpy(desc,"");
  		return false;
  	}
! 	len = fread(&hdr, sizeof(hdr), 1, out);
! 	fclose(out);
  
  	if (len!=1 || hdr.type != MKID('SCVM')) {
--- 158,167 ----
  
  	makeSavegameName(filename, slot, false);
! 	if (!out.fopen(filename,"rb")) {
  		strcpy(desc,"");
  		return false;
  	}
! 	len = out.fread(&hdr, sizeof(hdr), 1);
! 	out.fclose();
  
  	if (len!=1 || hdr.type != MKID('SCVM')) {
***************
*** 562,568 ****
  void Serializer::saveLoadBytes(void *b, int len) {
  	if (_saveOrLoad)
! 		fwrite(b, 1, len, _saveLoadStream);
  	else
! 		fread(b, 1, len, _saveLoadStream);
  }
  
--- 558,564 ----
  void Serializer::saveLoadBytes(void *b, int len) {
  	if (_saveOrLoad)
! 		_saveLoadStream.fwrite(b, 1, len);
  	else
! 		_saveLoadStream.fread(b, 1, len);
  }
  

Index: scumm.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm.h,v
retrieving revision 1.39
retrieving revision 1.40
diff -C2 -d -r1.39 -r1.40
*** scumm.h	2002/02/02 19:07:10	1.39
--- scumm.h	2002/02/02 23:27:06	1.40
***************
*** 2147,2152 ****
  
  
  struct Serializer {
! 	FILE *_saveLoadStream;
  
  	union {
--- 2147,2178 ----
  
  
+ struct SerializerStream {
+ #ifdef NONSTANDARD_SAVE
+ 	void *context;
+ 
+ 	bool fopen(const char *filename, const char *mode);
+ 	void fclose();
+ 	int fread(void *buf, int size, int cnt);
+ 	int fwrite(void *buf, int size, int cnt);
+ #else
+ 	FILE *out;
+ 
+ 	FILE *fopen(const char *filename, const char *mode) {
+ 		return out = ::fopen(filename, mode);
+ 	}
+ 	void fclose() {
+ 		::fclose(out);
+ 	}
+ 	int fread(void *buf, int size, int cnt) {
+ 		return ::fread(buf, size, cnt, out);
+ 	}
+ 	int fwrite(void *buf, int size, int cnt) {
+ 		return ::fwrite(buf, size, cnt, out);
+ 	}
+ #endif
+ };
+ 
  struct Serializer {
! 	SerializerStream _saveLoadStream;
  
  	union {





More information about the Scummvm-git-logs mailing list