Implement saving and restoring of event strings

Required for events with string arguments. On debug builds
an assert() is triggered when trying to save such an event,
while events could not be properly restored in any build.

This happens when going from map delta4 to hell1 and the
autosave feature kicks in. The trigger event 'selectWeapon'
with the string argument 'weapon_fists' is in the event queue.

With the binary from id a warning is issued:
WARNING: player1 is not carrying weapon ''
so the bug exists in there too, just that its a release build
and doesn't abort().

I also managed to trigger this while saving shortly after
activating an elevator switch.
This commit is contained in:
dhewg 2011-12-27 18:01:26 +01:00 committed by Daniel Gibson
parent 85a3a7089a
commit 92023f44ca
2 changed files with 26 additions and 0 deletions

View file

@ -755,6 +755,7 @@ void idEvent::Save( idSaveGame *savefile ) {
byte *dataPtr;
bool validTrace;
const char *format;
idStr s;
savefile->WriteInt( EventQueue.Num() );
@ -783,6 +784,12 @@ void idEvent::Save( idSaveGame *savefile ) {
savefile->WriteVec3( *reinterpret_cast<idVec3 *>( dataPtr ) );
size += sizeof( idVec3 );
break;
case D_EVENT_STRING :
s.Clear();
s.Append(reinterpret_cast<char *>(dataPtr), MAX_STRING_LEN);
savefile->WriteString(s);
size += MAX_STRING_LEN;
break;
case D_EVENT_TRACE :
validTrace = *reinterpret_cast<bool *>( dataPtr );
savefile->WriteBool( validTrace );
@ -836,6 +843,7 @@ void idEvent::Restore( idRestoreGame *savefile ) {
byte *dataPtr;
idEvent *event;
const char *format;
idStr s;
savefile->ReadInt( num );
@ -892,6 +900,11 @@ void idEvent::Restore( idRestoreGame *savefile ) {
savefile->ReadVec3( *reinterpret_cast<idVec3 *>( dataPtr ) );
size += sizeof( idVec3 );
break;
case D_EVENT_STRING :
savefile->ReadString(s);
idStr::Copynz(reinterpret_cast<char *>(dataPtr), s, MAX_STRING_LEN);
size += MAX_STRING_LEN;
break;
case D_EVENT_TRACE :
savefile->ReadBool( *reinterpret_cast<bool *>( dataPtr ) );
size += sizeof( bool );

View file

@ -621,6 +621,7 @@ void idEvent::Save( idSaveGame *savefile ) {
byte *dataPtr;
bool validTrace;
const char *format;
idStr s;
savefile->WriteInt( EventQueue.Num() );
@ -649,6 +650,12 @@ void idEvent::Save( idSaveGame *savefile ) {
savefile->WriteVec3( *reinterpret_cast<idVec3 *>( dataPtr ) );
size += sizeof( idVec3 );
break;
case D_EVENT_STRING :
s.Clear();
s.Append(reinterpret_cast<char *>(dataPtr), MAX_STRING_LEN);
savefile->WriteString(s);
size += MAX_STRING_LEN;
break;
case D_EVENT_TRACE :
validTrace = *reinterpret_cast<bool *>( dataPtr );
savefile->WriteBool( validTrace );
@ -685,6 +692,7 @@ void idEvent::Restore( idRestoreGame *savefile ) {
byte *dataPtr;
idEvent *event;
const char *format;
idStr s;
savefile->ReadInt( num );
@ -741,6 +749,11 @@ void idEvent::Restore( idRestoreGame *savefile ) {
savefile->ReadVec3( *reinterpret_cast<idVec3 *>( dataPtr ) );
size += sizeof( idVec3 );
break;
case D_EVENT_STRING :
savefile->ReadString(s);
idStr::Copynz(reinterpret_cast<char *>(dataPtr), s, MAX_STRING_LEN);
size += MAX_STRING_LEN;
break;
case D_EVENT_TRACE :
savefile->ReadBool( *reinterpret_cast<bool *>( dataPtr ) );
size += sizeof( bool );