From ac090883ac2e48cd18d611a3a0c5341d3515c368 Mon Sep 17 00:00:00 2001 From: dhewg Date: Thu, 12 Jan 2012 23:47:56 +0100 Subject: [PATCH] More fixes regarding event saving and restoring Fix silly issue from 3d692b58 (sizeof(E_EVENT_SIZEOF_VEC)). Align entity values of events to the native pointer size, which is noticeably faster on x86_64 and fixes another assert() in debug builds. Past savegames with entities in events are not compatible. --- d3xp/gamesys/Event.cpp | 24 ++++++++++++------------ game/gamesys/Event.cpp | 24 ++++++++++++------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/d3xp/gamesys/Event.cpp b/d3xp/gamesys/Event.cpp index 83c5e6e..59aa884 100644 --- a/d3xp/gamesys/Event.cpp +++ b/d3xp/gamesys/Event.cpp @@ -99,6 +99,8 @@ idEventDef::idEventDef( const char *command, const char *formatspec, char return break; case D_EVENT_INTEGER : + case D_EVENT_ENTITY : + case D_EVENT_ENTITY_NULL : argsize += sizeof( intptr_t ); break; @@ -110,14 +112,6 @@ idEventDef::idEventDef( const char *command, const char *formatspec, char return argsize += MAX_STRING_LEN; break; - case D_EVENT_ENTITY : - argsize += sizeof( idEntityPtr ); - break; - - case D_EVENT_ENTITY_NULL : - argsize += sizeof( idEntityPtr ); - break; - case D_EVENT_TRACE : argsize += sizeof( trace_t ) + MAX_STRING_LEN + sizeof( bool ); break; @@ -775,14 +769,17 @@ void idEvent::Save( idSaveGame *savefile ) { size += sizeof( intptr_t ); break; case D_EVENT_INTEGER : + savefile->WriteInt( *reinterpret_cast( dataPtr ) ); + size += sizeof( intptr_t ); + break; case D_EVENT_ENTITY : case D_EVENT_ENTITY_NULL : - savefile->WriteInt( *reinterpret_cast( dataPtr ) ); + reinterpret_cast< idEntityPtr * >( dataPtr )->Save(savefile); size += sizeof( intptr_t ); break; case D_EVENT_VECTOR : savefile->WriteVec3( *reinterpret_cast( dataPtr ) ); - size += sizeof( E_EVENT_SIZEOF_VEC ); + size += E_EVENT_SIZEOF_VEC; break; case D_EVENT_STRING : s.Clear(); @@ -891,14 +888,17 @@ void idEvent::Restore( idRestoreGame *savefile ) { size += sizeof( intptr_t ); break; case D_EVENT_INTEGER : + savefile->ReadInt( *reinterpret_cast( dataPtr ) ); + size += sizeof( intptr_t ); + break; case D_EVENT_ENTITY : case D_EVENT_ENTITY_NULL : - savefile->ReadInt( *reinterpret_cast( dataPtr ) ); + reinterpret_cast< idEntityPtr * >( dataPtr )->Restore(savefile); size += sizeof( intptr_t ); break; case D_EVENT_VECTOR : savefile->ReadVec3( *reinterpret_cast( dataPtr ) ); - size += sizeof( E_EVENT_SIZEOF_VEC ); + size += E_EVENT_SIZEOF_VEC; break; case D_EVENT_STRING : savefile->ReadString(s); diff --git a/game/gamesys/Event.cpp b/game/gamesys/Event.cpp index 3d38978..86fdf0f 100644 --- a/game/gamesys/Event.cpp +++ b/game/gamesys/Event.cpp @@ -99,6 +99,8 @@ idEventDef::idEventDef( const char *command, const char *formatspec, char return break; case D_EVENT_INTEGER : + case D_EVENT_ENTITY : + case D_EVENT_ENTITY_NULL : argsize += sizeof( intptr_t ); break; @@ -110,14 +112,6 @@ idEventDef::idEventDef( const char *command, const char *formatspec, char return argsize += MAX_STRING_LEN; break; - case D_EVENT_ENTITY : - argsize += sizeof( idEntityPtr ); - break; - - case D_EVENT_ENTITY_NULL : - argsize += sizeof( idEntityPtr ); - break; - case D_EVENT_TRACE : argsize += sizeof( trace_t ) + MAX_STRING_LEN + sizeof( bool ); break; @@ -641,14 +635,17 @@ void idEvent::Save( idSaveGame *savefile ) { size += sizeof( intptr_t ); break; case D_EVENT_INTEGER : + savefile->WriteInt( *reinterpret_cast( dataPtr ) ); + size += sizeof( intptr_t ); + break; case D_EVENT_ENTITY : case D_EVENT_ENTITY_NULL : - savefile->WriteInt( *reinterpret_cast( dataPtr ) ); + reinterpret_cast< idEntityPtr * >( dataPtr )->Save(savefile); size += sizeof( intptr_t ); break; case D_EVENT_VECTOR : savefile->WriteVec3( *reinterpret_cast( dataPtr ) ); - size += sizeof( E_EVENT_SIZEOF_VEC ); + size += E_EVENT_SIZEOF_VEC; break; case D_EVENT_STRING : s.Clear(); @@ -740,14 +737,17 @@ void idEvent::Restore( idRestoreGame *savefile ) { size += sizeof( intptr_t ); break; case D_EVENT_INTEGER : + savefile->ReadInt( *reinterpret_cast( dataPtr ) ); + size += sizeof( intptr_t ); + break; case D_EVENT_ENTITY : case D_EVENT_ENTITY_NULL : - savefile->ReadInt( *reinterpret_cast( dataPtr ) ); + reinterpret_cast< idEntityPtr * >( dataPtr )->Restore(savefile); size += sizeof( intptr_t ); break; case D_EVENT_VECTOR : savefile->ReadVec3( *reinterpret_cast( dataPtr ) ); - size += sizeof( E_EVENT_SIZEOF_VEC ); + size += E_EVENT_SIZEOF_VEC; break; case D_EVENT_STRING : savefile->ReadString(s);