diff options
| author | Max Horn | 2002-08-26 16:47:14 +0000 | 
|---|---|---|
| committer | Max Horn | 2002-08-26 16:47:14 +0000 | 
| commit | 0cf920e0403408b3e01787ed8d3ac9a6dd7a5a9c (patch) | |
| tree | 5bdadd8cb59d83ead2149f28af489b834bba33eb /scumm | |
| parent | 39422bd24ad0e7a9ec40f28d23e5fc8c4402cbf4 (diff) | |
| download | scummvm-rg350-0cf920e0403408b3e01787ed8d3ac9a6dd7a5a9c.tar.gz scummvm-rg350-0cf920e0403408b3e01787ed8d3ac9a6dd7a5a9c.tar.bz2 scummvm-rg350-0cf920e0403408b3e01787ed8d3ac9a6dd7a5a9c.zip  | |
some cleanup to the save/load code... I think some more wouldn't hurt :-)
svn-id: r4863
Diffstat (limited to 'scumm')
| -rw-r--r-- | scumm/saveload.cpp | 37 | ||||
| -rw-r--r-- | scumm/saveload.h | 4 | 
2 files changed, 24 insertions, 17 deletions
diff --git a/scumm/saveload.cpp b/scumm/saveload.cpp index 383419a789..6ac7bdd0df 100644 --- a/scumm/saveload.cpp +++ b/scumm/saveload.cpp @@ -686,7 +686,7 @@ void Scumm::saveLoadResource(Serializer *ser, int type, int idx)  		size = ((MemBlkHeader *)ptr)->size;  		ser->saveUint32(size); -		ser->saveLoadBytes(ptr + sizeof(MemBlkHeader), size); +		ser->saveBytes(ptr + sizeof(MemBlkHeader), size);  		if (type == rtInventory) {  			ser->saveWord(_inventory[idx]); @@ -695,7 +695,7 @@ void Scumm::saveLoadResource(Serializer *ser, int type, int idx)  		size = ser->loadUint32();  		if (size) {  			createResource(type, idx, size); -			ser->saveLoadBytes(getResourceAddress(type, idx), size); +			ser->loadBytes(getResourceAddress(type, idx), size);  			if (type == rtInventory) {  				_inventory[idx] = ser->loadWord();  			} @@ -703,12 +703,14 @@ void Scumm::saveLoadResource(Serializer *ser, int type, int idx)  	}  } -void Serializer::saveLoadBytes(void *b, int len) +void Serializer::saveBytes(void *b, int len)  { -	if (_saveOrLoad) -		_saveLoadStream.fwrite(b, 1, len); -	else -		_saveLoadStream.fread(b, 1, len); +	_saveLoadStream.fwrite(b, 1, len); +} + +void Serializer::loadBytes(void *b, int len) +{ +	_saveLoadStream.fread(b, 1, len);  }  #ifdef _WIN32_WCE @@ -731,38 +733,38 @@ bool Serializer::checkEOFLoadStream()  void Serializer::saveUint32(uint32 d)  {  	uint32 e = FROM_LE_32(d); -	saveLoadBytes(&e, 4); +	saveBytes(&e, 4);  }  void Serializer::saveWord(uint16 d)  {  	uint16 e = FROM_LE_16(d); -	saveLoadBytes(&e, 2); +	saveBytes(&e, 2);  }  void Serializer::saveByte(byte b)  { -	saveLoadBytes(&b, 1); +	saveBytes(&b, 1);  }  uint32 Serializer::loadUint32()  {  	uint32 e; -	saveLoadBytes(&e, 4); +	loadBytes(&e, 4);  	return FROM_LE_32(e);  }  uint16 Serializer::loadWord()  {  	uint16 e; -	saveLoadBytes(&e, 2); +	loadBytes(&e, 2);  	return FROM_LE_16(e);  }  byte Serializer::loadByte()  {  	byte e; -	saveLoadBytes(&e, 1); +	loadBytes(&e, 1);  	return e;  } @@ -773,12 +775,15 @@ void Serializer::saveLoadArrayOf(void *b, int len, int datasize, byte filetype)  	/* speed up byte arrays */  	if (datasize == 1 && filetype == sleByte) { -		saveLoadBytes(b, len); +		if (isSaving()) +			saveBytes(b, len); +		else +			loadBytes(b, len);  		return;  	}  	while (--len >= 0) { -		if (_saveOrLoad) { +		if (isSaving()) {  			/* saving */  			if (datasize == 1) {  				data = *(byte *)at; @@ -870,7 +875,7 @@ void Serializer::saveLoadEntries(void *d, const SaveLoadEntry *sle)  		type = sle->type;  		if (size == 0xFF) { -			if (_saveOrLoad) { +			if (isSaving()) {  				/* save reference */  				ptr = *((void **)at);  				saveWord(ptr ? ((*_save_ref) (_ref_me, type, ptr) + 1) : 0); diff --git a/scumm/saveload.h b/scumm/saveload.h index 8b715de3f6..68e003ba7a 100644 --- a/scumm/saveload.h +++ b/scumm/saveload.h @@ -79,7 +79,9 @@ struct Serializer {  	bool _saveOrLoad; -	void saveLoadBytes(void *b, int len); +	void saveBytes(void *b, int len); +	void loadBytes(void *b, int len); +	  	void saveLoadArrayOf(void *b, int len, int datasize, byte filetype);  	void saveLoadEntries(void *d, const SaveLoadEntry *sle);  	void saveLoadArrayOf(void *b, int num, int datasize, const SaveLoadEntry *sle);  | 
