some cleanup to the save/load code... I think some more wouldn't hurt :-)
svn-id: r4863
This commit is contained in:
parent
39422bd24a
commit
0cf920e040
2 changed files with 24 additions and 17 deletions
|
@ -686,7 +686,7 @@ void Scumm::saveLoadResource(Serializer *ser, int type, int idx)
|
||||||
size = ((MemBlkHeader *)ptr)->size;
|
size = ((MemBlkHeader *)ptr)->size;
|
||||||
|
|
||||||
ser->saveUint32(size);
|
ser->saveUint32(size);
|
||||||
ser->saveLoadBytes(ptr + sizeof(MemBlkHeader), size);
|
ser->saveBytes(ptr + sizeof(MemBlkHeader), size);
|
||||||
|
|
||||||
if (type == rtInventory) {
|
if (type == rtInventory) {
|
||||||
ser->saveWord(_inventory[idx]);
|
ser->saveWord(_inventory[idx]);
|
||||||
|
@ -695,7 +695,7 @@ void Scumm::saveLoadResource(Serializer *ser, int type, int idx)
|
||||||
size = ser->loadUint32();
|
size = ser->loadUint32();
|
||||||
if (size) {
|
if (size) {
|
||||||
createResource(type, idx, size);
|
createResource(type, idx, size);
|
||||||
ser->saveLoadBytes(getResourceAddress(type, idx), size);
|
ser->loadBytes(getResourceAddress(type, idx), size);
|
||||||
if (type == rtInventory) {
|
if (type == rtInventory) {
|
||||||
_inventory[idx] = ser->loadWord();
|
_inventory[idx] = ser->loadWord();
|
||||||
}
|
}
|
||||||
|
@ -703,11 +703,13 @@ 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);
|
_saveLoadStream.fwrite(b, 1, len);
|
||||||
else
|
}
|
||||||
|
|
||||||
|
void Serializer::loadBytes(void *b, int len)
|
||||||
|
{
|
||||||
_saveLoadStream.fread(b, 1, len);
|
_saveLoadStream.fread(b, 1, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -731,38 +733,38 @@ bool Serializer::checkEOFLoadStream()
|
||||||
void Serializer::saveUint32(uint32 d)
|
void Serializer::saveUint32(uint32 d)
|
||||||
{
|
{
|
||||||
uint32 e = FROM_LE_32(d);
|
uint32 e = FROM_LE_32(d);
|
||||||
saveLoadBytes(&e, 4);
|
saveBytes(&e, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Serializer::saveWord(uint16 d)
|
void Serializer::saveWord(uint16 d)
|
||||||
{
|
{
|
||||||
uint16 e = FROM_LE_16(d);
|
uint16 e = FROM_LE_16(d);
|
||||||
saveLoadBytes(&e, 2);
|
saveBytes(&e, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Serializer::saveByte(byte b)
|
void Serializer::saveByte(byte b)
|
||||||
{
|
{
|
||||||
saveLoadBytes(&b, 1);
|
saveBytes(&b, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 Serializer::loadUint32()
|
uint32 Serializer::loadUint32()
|
||||||
{
|
{
|
||||||
uint32 e;
|
uint32 e;
|
||||||
saveLoadBytes(&e, 4);
|
loadBytes(&e, 4);
|
||||||
return FROM_LE_32(e);
|
return FROM_LE_32(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16 Serializer::loadWord()
|
uint16 Serializer::loadWord()
|
||||||
{
|
{
|
||||||
uint16 e;
|
uint16 e;
|
||||||
saveLoadBytes(&e, 2);
|
loadBytes(&e, 2);
|
||||||
return FROM_LE_16(e);
|
return FROM_LE_16(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte Serializer::loadByte()
|
byte Serializer::loadByte()
|
||||||
{
|
{
|
||||||
byte e;
|
byte e;
|
||||||
saveLoadBytes(&e, 1);
|
loadBytes(&e, 1);
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -773,12 +775,15 @@ void Serializer::saveLoadArrayOf(void *b, int len, int datasize, byte filetype)
|
||||||
|
|
||||||
/* speed up byte arrays */
|
/* speed up byte arrays */
|
||||||
if (datasize == 1 && filetype == sleByte) {
|
if (datasize == 1 && filetype == sleByte) {
|
||||||
saveLoadBytes(b, len);
|
if (isSaving())
|
||||||
|
saveBytes(b, len);
|
||||||
|
else
|
||||||
|
loadBytes(b, len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (--len >= 0) {
|
while (--len >= 0) {
|
||||||
if (_saveOrLoad) {
|
if (isSaving()) {
|
||||||
/* saving */
|
/* saving */
|
||||||
if (datasize == 1) {
|
if (datasize == 1) {
|
||||||
data = *(byte *)at;
|
data = *(byte *)at;
|
||||||
|
@ -870,7 +875,7 @@ void Serializer::saveLoadEntries(void *d, const SaveLoadEntry *sle)
|
||||||
type = sle->type;
|
type = sle->type;
|
||||||
|
|
||||||
if (size == 0xFF) {
|
if (size == 0xFF) {
|
||||||
if (_saveOrLoad) {
|
if (isSaving()) {
|
||||||
/* save reference */
|
/* save reference */
|
||||||
ptr = *((void **)at);
|
ptr = *((void **)at);
|
||||||
saveWord(ptr ? ((*_save_ref) (_ref_me, type, ptr) + 1) : 0);
|
saveWord(ptr ? ((*_save_ref) (_ref_me, type, ptr) + 1) : 0);
|
||||||
|
|
|
@ -79,7 +79,9 @@ struct Serializer {
|
||||||
|
|
||||||
bool _saveOrLoad;
|
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 saveLoadArrayOf(void *b, int len, int datasize, byte filetype);
|
||||||
void saveLoadEntries(void *d, const SaveLoadEntry *sle);
|
void saveLoadEntries(void *d, const SaveLoadEntry *sle);
|
||||||
void saveLoadArrayOf(void *b, int num, int datasize, const SaveLoadEntry *sle);
|
void saveLoadArrayOf(void *b, int num, int datasize, const SaveLoadEntry *sle);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue