[openjk] 34/130: Replace writing wrappers

Simon McVittie smcv at debian.org
Fri Oct 28 11:09:14 UTC 2016


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch debian/master
in repository openjk.

commit 0d153248e33d9f6788e524780b685de8a1bd39c9
Author: bibendovsky <bibendovsky at hotmail.com>
Date:   Mon Jul 11 21:27:31 2016 +0300

    Replace writing wrappers
---
 code/cgame/FxScheduler.cpp           |   9 ++-
 code/cgame/cg_main.cpp               |   9 ++-
 code/client/cl_main.cpp              |   3 +
 code/game/G_Timer.cpp                |  14 ++++-
 code/game/Q3_Interface.cpp           |  44 +++++++++++---
 code/game/g_main.cpp                 |   8 ++-
 code/game/g_objectives.cpp           |   4 +-
 code/game/g_roff.cpp                 |  15 ++++-
 code/game/g_savegame.cpp             |  32 +++++++---
 code/icarus/IcarusImplementation.cpp |  18 +++++-
 code/qcommon/cm_load.cpp             |   7 ++-
 code/rd-common/tr_public.h           |   2 +
 code/rd-vanilla/G2_misc.cpp          |  14 ++++-
 code/server/sv_savegame.cpp          | 110 ++++++++++++++++++++++++++++------
 codeJK2/cgame/cg_main.cpp            |   9 ++-
 codeJK2/game/G_Timer.cpp             |  19 ++++--
 codeJK2/game/Q3_Registers.cpp        |  44 +++++++++++---
 codeJK2/game/g_main.cpp              |   8 ++-
 codeJK2/game/g_objectives.cpp        |   4 +-
 codeJK2/game/g_roff.cpp              |  14 ++++-
 codeJK2/game/g_savegame.cpp          |  32 +++++++---
 codeJK2/icarus/Instance.cpp          |  45 +++++++++++---
 codeJK2/icarus/Sequence.cpp          |  67 ++++++++++++++++-----
 codeJK2/icarus/Sequencer.cpp         |  43 ++++++++++---
 codeJK2/icarus/TaskManager.cpp       | 113 ++++++++++++++++++++++++++++-------
 shared/qcommon/ojk_i_saved_game.h    |   2 +-
 26 files changed, 552 insertions(+), 137 deletions(-)

diff --git a/code/cgame/FxScheduler.cpp b/code/cgame/FxScheduler.cpp
index 34379ef..a2835b1 100644
--- a/code/cgame/FxScheduler.cpp
+++ b/code/cgame/FxScheduler.cpp
@@ -134,7 +134,10 @@ void CFxScheduler::LoadSave_Write()
 {
 	// bsave the data we need...
 	//
-	::sg_write_no_cast(::gi, INT_ID('F','X','L','E'), mLoopedEffectArray);
+    ::gi.saved_game->write_chunk(
+        INT_ID('F','X','L','E'),
+        mLoopedEffectArray);
+
 	//
 	// then cope with the fact that the mID field in each struct of the array we've just saved will not
 	//	necessarily point at the same thing when reloading, so save out the actual fx filename strings they
@@ -166,7 +169,9 @@ void CFxScheduler::LoadSave_Write()
 
 		// write out this string...
 		//
-		::sg_write_no_cast(::gi, INT_ID('F','X','F','N'), sFX_Filename);
+        ::gi.saved_game->write_chunk(
+            INT_ID('F','X','F','N'),
+            sFX_Filename);
 	}
 }
 
diff --git a/code/cgame/cg_main.cpp b/code/cgame/cg_main.cpp
index 96fa0f0..74aae7a 100644
--- a/code/cgame/cg_main.cpp
+++ b/code/cgame/cg_main.cpp
@@ -1908,8 +1908,13 @@ static void CG_GameStateReceived( void ) {
 
 void CG_WriteTheEvilCGHackStuff(void)
 {
-	::sg_write<int32_t>(::gi, INT_ID('F','P','S','L'), ::cg.forcepowerSelect);
-	::sg_write<int32_t>(::gi, INT_ID('I','V','S','L'), ::cg.inventorySelect);
+    ::gi.saved_game->write_chunk<int32_t>(
+        INT_ID('F','P','S','L'),
+        ::cg.forcepowerSelect);
+
+    ::gi.saved_game->write_chunk<int32_t>(
+        INT_ID('I','V','S','L'),
+        ::cg.inventorySelect);
 
 }
 void CG_ReadTheEvilCGHackStuff(void)
diff --git a/code/client/cl_main.cpp b/code/client/cl_main.cpp
index 6ab334d..b3ab567 100644
--- a/code/client/cl_main.cpp
+++ b/code/client/cl_main.cpp
@@ -32,6 +32,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
 #include "../ghoul2/G2.h"
 #include "qcommon/stringed_ingame.h"
 #include "sys/sys_loadlib.h"
+#include "qcommon/ojk_saved_game.h"
 
 #define	RETRANSMIT_TIMEOUT	3000	// time between connection packet retransmits
 
@@ -1181,6 +1182,8 @@ void CL_InitRef( void ) {
 
 	rit.SV_PointContents = SV_PointContents;
 
+    rit.saved_game = &ojk::SavedGame::get_instance();
+
 	ret = GetRefAPI( REF_API_VERSION, &rit );
 
 	if ( !ret ) {
diff --git a/code/game/G_Timer.cpp b/code/game/G_Timer.cpp
index 19d53b9..a35f13a 100644
--- a/code/game/G_Timer.cpp
+++ b/code/game/G_Timer.cpp
@@ -173,7 +173,9 @@ void TIMER_Save( void )
 		}
 
 		//Write out the timer information
-		::sg_write<uint8_t>(::gi, INT_ID('T','I','M','E'), numTimers);
+        ::gi.saved_game->write_chunk<uint8_t>(
+            INT_ID('T','I','M','E'),
+            numTimers);
 
 		gtimer_t *p = g_timers[j];
 		assert ((numTimers && p) || (!numTimers && !p));
@@ -187,10 +189,16 @@ void TIMER_Save( void )
 			assert( length < 1024 );//This will cause problems when loading the timer if longer
 
 			//Write out the id string
-			::sg_write_no_cast(::gi, INT_ID('T','M','I','D'), timerID, length);
+            ::gi.saved_game->write_chunk(
+                INT_ID('T','M','I','D'),
+                timerID,
+                length);
 
 			//Write out the timer data
-			::sg_write<int32_t>(::gi, INT_ID('T','D','T','A'), time);
+            ::gi.saved_game->write_chunk<int32_t>(
+                INT_ID('T','D','T','A'),
+                time);
+
 			p = p->next;
 		}
 	}
diff --git a/code/game/Q3_Interface.cpp b/code/game/Q3_Interface.cpp
index a013736..f109b10 100644
--- a/code/game/Q3_Interface.cpp
+++ b/code/game/Q3_Interface.cpp
@@ -7208,7 +7208,10 @@ VariableSaveFloats
 void CQuake3GameInterface::VariableSaveFloats( varFloat_m &fmap )
 {
 	int numFloats = fmap.size();
-	::sg_write<int32_t>(::gi, INT_ID('F','V','A','R'), numFloats);
+
+    ::gi.saved_game->write_chunk<int32_t>(
+        INT_ID('F','V','A','R'),
+        numFloats);
 
 	varFloat_m::iterator	vfi;
 	STL_ITERATE( vfi, fmap )
@@ -7217,11 +7220,19 @@ void CQuake3GameInterface::VariableSaveFloats( varFloat_m &fmap )
 		int	idSize = strlen( ((*vfi).first).c_str() );
 
 		//Save out the real data
-		::sg_write<int32_t>(::gi, INT_ID('F','I','D','L'), idSize);
-		::sg_write_no_cast(::gi, INT_ID('F','I','D','S'), ((*vfi).first).c_str(), idSize);
+        ::gi.saved_game->write_chunk<int32_t>(
+            INT_ID('F','I','D','L'),
+            idSize);
+
+        ::gi.saved_game->write_chunk(
+            INT_ID('F','I','D','S'),
+            ((*vfi).first).c_str(),
+            idSize);
 
 		//Save out the float value
-		::sg_write_no_cast(::gi, INT_ID('F','V','A','L'), (*vfi).second);
+        ::gi.saved_game->write_chunk<float>(
+            INT_ID('F','V','A','L'),
+            (*vfi).second);
 	}
 }
 
@@ -7234,7 +7245,10 @@ VariableSaveStrings
 void CQuake3GameInterface::VariableSaveStrings( varString_m &smap )
 {
 	int numStrings = smap.size();
-	::sg_write<int32_t>(::gi, INT_ID('S','V','A','R'), numStrings);
+
+    ::gi.saved_game->write_chunk<int32_t>(
+        INT_ID('S','V','A','R'),
+        numStrings);
 
 	varString_m::iterator	vsi;
 	STL_ITERATE( vsi, smap )
@@ -7243,14 +7257,26 @@ void CQuake3GameInterface::VariableSaveStrings( varString_m &smap )
 		int	idSize = strlen( ((*vsi).first).c_str() );
 
 		//Save out the real data
-		::sg_write<int32_t>(::gi, INT_ID('S','I','D','L'), idSize);
-		::sg_write_no_cast(::gi, INT_ID('S','I','D','S'), ((*vsi).first).c_str(), idSize);
+        ::gi.saved_game->write_chunk<int32_t>(
+            INT_ID('S','I','D','L'),
+            idSize);
+
+        ::gi.saved_game->write_chunk(
+            INT_ID('S','I','D','S'),
+            ((*vsi).first).c_str(),
+            idSize);
 
 		//Save out the string value
 		idSize = strlen( ((*vsi).second).c_str() );
 
-		::sg_write<int32_t>(::gi, INT_ID('S','V','S','Z'), idSize);
-		::sg_write_no_cast(::gi, INT_ID('S','V','A','L'), ((*vsi).second).c_str(), idSize);
+        ::gi.saved_game->write_chunk<int32_t>(
+            INT_ID('S','V','S','Z'),
+            idSize);
+
+        ::gi.saved_game->write_chunk(
+            INT_ID('S','V','A','L'),
+            ((*vsi).second).c_str(),
+            idSize);
 	}
 }
 
diff --git a/code/game/g_main.cpp b/code/game/g_main.cpp
index 288be0c..9d29aba 100644
--- a/code/game/g_main.cpp
+++ b/code/game/g_main.cpp
@@ -108,7 +108,9 @@ qboolean PInUse(unsigned int entNum)
 
 void WriteInUseBits(void)
 {
-	::sg_write<uint32_t>(::gi, INT_ID('I','N','U','S'), ::g_entityInUseBits);
+    ::gi.saved_game->write_chunk<uint32_t>(
+        INT_ID('I','N','U','S'),
+        ::g_entityInUseBits);
 }
 
 void ReadInUseBits(void)
@@ -2114,7 +2116,9 @@ extern qboolean player_locked;
 
 void G_LoadSave_WriteMiscData(void)
 {
-	::sg_write<int32_t>(::gi, INT_ID('L','C','K','D'), player_locked);
+    ::gi.saved_game->write_chunk<int32_t>(
+        INT_ID('L','C','K','D'),
+        ::player_locked);
 }
 
 
diff --git a/code/game/g_objectives.cpp b/code/game/g_objectives.cpp
index 92afb43..ae3e45a 100644
--- a/code/game/g_objectives.cpp
+++ b/code/game/g_objectives.cpp
@@ -61,7 +61,9 @@ OBJ_SaveMissionObjectives
 */
 void OBJ_SaveMissionObjectives( gclient_t *client )
 {
-	::sg_write_no_cast(::gi, INT_ID('O','B','J','T'), client->sess.mission_objectives);
+    ::gi.saved_game->write_chunk(
+        INT_ID('O','B','J','T'),
+        client->sess.mission_objectives);
 }
 
 
diff --git a/code/game/g_roff.cpp b/code/game/g_roff.cpp
index 5f3176e..95b8494 100644
--- a/code/game/g_roff.cpp
+++ b/code/game/g_roff.cpp
@@ -653,15 +653,24 @@ void G_SaveCachedRoffs()
 	int i, len;
 
 	// Write out the number of cached ROFFs
-	::sg_write<int32_t>(::gi, INT_ID('R','O','F','F'), num_roffs);
+    ::gi.saved_game->write_chunk<int32_t>(
+        INT_ID('R','O','F','F'),
+        ::num_roffs);
 
 	// Now dump out the cached ROFF file names in order so they can be loaded on the other end
 	for ( i = 0; i < num_roffs; i++ )
 	{
 		// Dump out the string length to make things a bit easier on the other end...heh heh.
 		len = strlen( roffs[i].fileName ) + 1;
-		::sg_write<int32_t>(::gi, INT_ID('S','L','E','N'), len);
-		::sg_write_no_cast(::gi, INT_ID('R','S','T','R'), roffs[i].fileName, len);
+
+        ::gi.saved_game->write_chunk<int32_t>(
+            INT_ID('S','L','E','N'),
+            len);
+
+        ::gi.saved_game->write_chunk(
+            INT_ID('R','S','T','R'),
+            roffs[i].fileName,
+            len);
 	}
 }
 
diff --git a/code/game/g_savegame.cpp b/code/game/g_savegame.cpp
index 54e2d02..f3941c1 100644
--- a/code/game/g_savegame.cpp
+++ b/code/game/g_savegame.cpp
@@ -536,13 +536,19 @@ static void EnumerateFields(const save_field_t *pFields, const T* src_instance,
 
     ::sg_export(*src_instance, *dst_instance);
 
-	::sg_write_no_cast(::gi, ulChid, dst_buffer.data(), dst_size);
+    ::gi.saved_game->write_chunk(
+        ulChid,
+        dst_buffer.data(),
+        dst_size);
 
 	// save out any associated strings..
 	//
 	for (const auto& it : strList)
 	{
-		::sg_write_no_cast(::gi, INT_ID('S','T','R','G'), it.c_str(), static_cast<int>(it.length() + 1));
+        ::gi.saved_game->write_chunk(
+            INT_ID('S','T','R','G'),
+            it.c_str(),
+            static_cast<int>(it.length() + 1));
 	}
 }
 
@@ -849,7 +855,9 @@ static void WriteGEntities(qboolean qbAutosave)
 		}
 	}
 
-	::sg_write<int32_t>(::gi, INT_ID('N','M','E','D'), iCount);
+    ::gi.saved_game->write_chunk<int32_t>(
+        INT_ID('N','M','E','D'),
+        iCount);
 
 	for (i=0; i<(qbAutosave?1:globals.num_entities); i++)
 	{
@@ -857,7 +865,9 @@ static void WriteGEntities(qboolean qbAutosave)
 
 		if ( ent->inuse)
 		{
-			::sg_write<int32_t>(::gi, INT_ID('E','D','N','M'), i);
+            ::gi.saved_game->write_chunk<int32_t>(
+                INT_ID('E','D','N','M'),
+                i);
 
 			qboolean qbLinked = ent->linked;
 			gi.unlinkentity( ent );
@@ -888,7 +898,9 @@ static void WriteGEntities(qboolean qbAutosave)
 
 			if (tempEnt.parms)
 			{
-				::sg_write_no_cast(::gi, INT_ID('P','A','R','M'), *ent->parms);
+                ::gi.saved_game->write_chunk(
+                    INT_ID('P','A','R','M'),
+                    *ent->parms);
 			}
 
 			if (tempEnt.m_pVehicle)
@@ -917,7 +929,10 @@ static void WriteGEntities(qboolean qbAutosave)
 		//	This saves time debugging, and makes things easier to track.
 		//
 		static int iBlah = 1234;
-		::sg_write<int32_t>(::gi, INT_ID('I','C','O','K'), iBlah);
+
+        ::gi.saved_game->write_chunk<int32_t>(
+            INT_ID('I','C','O','K'),
+            iBlah);
 	}
 	if (!qbAutosave )//really shouldn't need to write these bits at all, just restore them from the ents...
 	{
@@ -1216,7 +1231,10 @@ void WriteLevel(qboolean qbAutosave)
 	// put out an end-marker so that the load code can check everything was read in...
 	//
 	static int iDONE = 1234;
-	::sg_write<int32_t>(::gi, INT_ID('D','O','N','E'), iDONE);
+
+    ::gi.saved_game->write_chunk<int32_t>(
+        INT_ID('D','O','N','E'),
+        iDONE);
 }
 
 void ReadLevel(qboolean qbAutosave, qboolean qbLoadTransition)
diff --git a/code/icarus/IcarusImplementation.cpp b/code/icarus/IcarusImplementation.cpp
index 6b0385b..77d7ce8 100644
--- a/code/icarus/IcarusImplementation.cpp
+++ b/code/icarus/IcarusImplementation.cpp
@@ -539,10 +539,14 @@ int CIcarus::Save()
 	CreateBuffer();
 
 	IGameInterface* game = IGameInterface::GetGame(m_flavor);
+    auto saved_game = game->get_saved_game();
 
 	//Save out a ICARUS save block header with the ICARUS version
 	double	version = ICARUS_VERSION;
-	::sg_write_no_cast(game, INT_ID('I','C','A','R'), version);
+
+    saved_game->read_chunk<double>(
+        INT_ID('I','C','A','R'),
+        version);
 
 	//Save out the signals
 	if ( SaveSignals() == false )
@@ -566,7 +570,10 @@ int CIcarus::Save()
 	}
 
 	// Write out the buffer with all our collected data.
-	::sg_write_no_cast(game, INT_ID('I','S','E','Q'), m_byBuffer, static_cast<int>(m_ulBufferCurPos));
+    saved_game->read_chunk(
+        INT_ID('I','S','E','Q'),
+        m_byBuffer,
+        static_cast<int>(m_ulBufferCurPos));
 
 	// De-allocate the temporary buffer.
 	DestroyBuffer();
@@ -796,7 +803,12 @@ void CIcarus::BufferWrite( void *pSrcData, unsigned long ulNumBytesToWrite )
 	if ( MAX_BUFFER_SIZE - m_ulBufferCurPos < ulNumBytesToWrite )
 	{	// Write out the buffer with all our collected data so far...
 		IGameInterface::GetGame()->DebugPrint( IGameInterface::WL_ERROR, "BufferWrite: Out of buffer space, Flushing." );
-		::sg_write_no_cast(IGameInterface::GetGame(), INT_ID('I','S','E','Q'), m_byBuffer, static_cast<int>(m_ulBufferCurPos));
+
+        IGameInterface::GetGame()->get_saved_game()->write_chunk(
+            INT_ID('I','S','E','Q'),
+            m_byBuffer,
+            static_cast<int>(m_ulBufferCurPos));
+
 		m_ulBufferCurPos = 0;	//reset buffer
 	}
 
diff --git a/code/qcommon/cm_load.cpp b/code/qcommon/cm_load.cpp
index a7250ca..bfe4975 100644
--- a/code/qcommon/cm_load.cpp
+++ b/code/qcommon/cm_load.cpp
@@ -1217,7 +1217,12 @@ int SG_Read(unsigned int chid, void *pvAddress, int iLength, void **ppvAddressPt
 
 void CM_WritePortalState ()
 {
-	::sg_write<int32_t>(::SG_Append, INT_ID('P','R','T','S'), ::cmg.areaPortals, ::cmg.numAreas * ::cmg.numAreas);
+    auto saved_game = &ojk::SavedGame::get_instance();
+
+    saved_game->write_chunk<int32_t>(
+        INT_ID('P','R','T','S'),
+        ::cmg.areaPortals,
+        ::cmg.numAreas * ::cmg.numAreas);
 }
 
 /*
diff --git a/code/rd-common/tr_public.h b/code/rd-common/tr_public.h
index 3db7b66..9b4e2f2 100644
--- a/code/rd-common/tr_public.h
+++ b/code/rd-common/tr_public.h
@@ -114,6 +114,8 @@ typedef struct {
 
 	qboolean			(*SG_Append)						( unsigned int chid, const void *pvData, int iLength );
 
+    ojk::ISavedGame* saved_game;
+
 	int					(*SV_PointContents)					( const vec3_t p, clipHandle_t model );
 
 	qboolean			(*CM_DeleteCachedMap)				( qboolean bGuaranteedOkToDelete );	// NOT IN MP
diff --git a/code/rd-vanilla/G2_misc.cpp b/code/rd-vanilla/G2_misc.cpp
index 4ad50ac..676ae4d 100644
--- a/code/rd-vanilla/G2_misc.cpp
+++ b/code/rd-vanilla/G2_misc.cpp
@@ -51,7 +51,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
 #ifdef _G2_GORE
 #include "../ghoul2/ghoul2_gore.h"
 #include "qcommon/ojk_sg_wrappers.h"
-#include "qcommon/ojk_i_saved_game_fwd.h"
+#include "qcommon/ojk_i_saved_game.h"
 
 #define GORE_TAG_UPPER (256)
 #define GORE_TAG_MASK (~255)
@@ -1781,7 +1781,11 @@ void G2_SaveGhoul2Models(CGhoul2Info_v &ghoul2)
 	if (!ghoul2.IsValid()||!ghoul2.size())
 	{
         uint32_t empty_value = 0;
-		::sg_write_no_cast(::ri, INT_ID('G','H','L','2'), empty_value);	//write out a zero buffer
+
+        ::ri.saved_game->write_chunk<uint32_t>(
+            INT_ID('G','H','L','2'),
+            empty_value); //write out a zero buffer
+
 		return;
 	}
 
@@ -1880,7 +1884,11 @@ void G2_SaveGhoul2Models(CGhoul2Info_v &ghoul2)
 		}
 	}
 
-	::sg_write_no_cast(::ri, INT_ID('G','H','L','2'), pGhoul2Data, iGhoul2Size);
+    ::ri.saved_game->write_chunk(
+        INT_ID('G','H','L','2'),
+        pGhoul2Data,
+        iGhoul2Size);
+
 	R_Free(pGhoul2Data);
 }
 
diff --git a/code/server/sv_savegame.cpp b/code/server/sv_savegame.cpp
index bc8d173..52d7084 100644
--- a/code/server/sv_savegame.cpp
+++ b/code/server/sv_savegame.cpp
@@ -180,8 +180,13 @@ static qboolean SG_Create( const char *psPathlessBaseName )
 		return qfalse;
 	}
 
+    auto saved_game = &ojk::SavedGame::get_instance();
+
 	giSaveGameVersion = iSAVEGAME_VERSION;
-	::sg_write<int32_t>(::SG_Append, INT_ID('_','V','E','R'), ::giSaveGameVersion);
+
+    saved_game->write_chunk<int32_t>(
+        INT_ID('_','V','E','R'),
+        ::giSaveGameVersion);
 
 	return qtrue;
 }
@@ -548,7 +553,11 @@ void SV_SaveGame_f(void)
 //---------------
 static void WriteGame(qboolean autosave)
 {
-	::sg_write<int32_t>(::SG_Append, INT_ID('G','A','M','E'), autosave);
+    auto saved_game = &ojk::SavedGame::get_instance();
+
+    saved_game->write_chunk<int32_t>(
+        INT_ID('G','A','M','E'),
+        autosave);
 
 	if (autosave)
 	{
@@ -563,25 +572,37 @@ static void WriteGame(qboolean autosave)
 		//
 		memset(s,0,sizeof(s));
 		Cvar_VariableStringBuffer( sCVARNAME_PLAYERSAVE, s, sizeof(s) );
-		::sg_write_no_cast(::SG_Append, INT_ID('C','V','S','V'), s);
+
+        saved_game->write_chunk(
+            INT_ID('C','V','S','V'),
+            s);
 
 		// write ammo...
 		//
 		memset(s,0,sizeof(s));
 		Cvar_VariableStringBuffer( "playerammo", s, sizeof(s) );
-		::sg_write_no_cast(::SG_Append, INT_ID('A','M','M','O'), s);
+
+        saved_game->write_chunk(
+            INT_ID('A','M','M','O'),
+            s);
 
 		// write inventory...
 		//
 		memset(s,0,sizeof(s));
 		Cvar_VariableStringBuffer( "playerinv", s, sizeof(s) );
-		::sg_write_no_cast(::SG_Append, INT_ID('I','V','T','Y'), s);
+
+        saved_game->write_chunk(
+            INT_ID('I','V','T','Y'),
+            s);
 
 		// the new JK2 stuff - force powers, etc...
 		//
 		memset(s,0,sizeof(s));
 		Cvar_VariableStringBuffer( "playerfplvl", s, sizeof(s) );
-		::sg_write_no_cast(::SG_Append, INT_ID('F','P','L','V'), s);
+
+        saved_game->write_chunk(
+            INT_ID('F','P','L','V'),
+            s);
 	}
 }
 
@@ -656,6 +677,8 @@ void SG_WriteCvars(void)
 	cvar_t	*var;
 	int		iCount = 0;
 
+    auto saved_game = &ojk::SavedGame::get_instance();
+
 	// count the cvars...
 	//
 	for (var = cvar_vars; var; var = var->next)
@@ -673,7 +696,9 @@ void SG_WriteCvars(void)
 
 	// store count...
 	//
-	::sg_write<int32_t>(::SG_Append, INT_ID('C','V','C','N'), iCount);
+    saved_game->write_chunk<int32_t>(
+        INT_ID('C','V','C','N'),
+        iCount);
 
 	// write 'em...
 	//
@@ -687,8 +712,16 @@ void SG_WriteCvars(void)
 		{
 			continue;
 		}
-		::sg_write_no_cast(::SG_Append, INT_ID('C','V','A','R'), var->name, static_cast<int>(strlen(var->name) + 1));
-		::sg_write_no_cast(::SG_Append, INT_ID('V','A','L','U'), var->string, static_cast<int>(strlen(var->string) + 1));
+
+        saved_game->write_chunk(
+            INT_ID('C','V','A','R'),
+            var->name,
+            static_cast<int>(strlen(var->name) + 1));
+
+        saved_game->write_chunk(
+            INT_ID('V','A','L','U'),
+            var->string,
+            static_cast<int>(strlen(var->string) + 1));
 	}
 }
 
@@ -726,6 +759,8 @@ void SG_ReadCvars(void)
 
 void SG_WriteServerConfigStrings( void )
 {
+    auto saved_game = &ojk::SavedGame::get_instance();
+
 	int iCount = 0;
 	int i;	// not in FOR statement in case compiler goes weird by reg-optimising it then failing to get the address later
 
@@ -742,7 +777,9 @@ void SG_WriteServerConfigStrings( void )
 		}
 	}
 
-	::sg_write<int32_t>(::SG_Append, INT_ID('C','S','C','N'), iCount);
+    saved_game->write_chunk<int32_t>(
+        INT_ID('C','S','C','N'),
+        iCount);
 
 	// now write 'em...
 	//
@@ -752,8 +789,14 @@ void SG_WriteServerConfigStrings( void )
 		{
 			if (sv.configstrings[i]	&& strlen(sv.configstrings[i]))
 			{
-				::sg_write<int32_t>(::SG_Append, INT_ID('C','S','I','N'), i);
-				::sg_write_no_cast(::SG_Append, INT_ID('C','S','D','A'), ::sv.configstrings[i], static_cast<int>(strlen(::sv.configstrings[i])+1));
+                saved_game->write_chunk<int32_t>(
+                    INT_ID('C','S','I','N'),
+                    i);
+
+                saved_game->write_chunk(
+                    INT_ID('C','S','D','A'),
+                    ::sv.configstrings[i],
+                    static_cast<int>(strlen(::sv.configstrings[i])+1));
 			}
 		}
 	}
@@ -816,6 +859,8 @@ static unsigned int SG_UnixTimestamp ( const time_t& t )
 
 static void SG_WriteComment(qboolean qbAutosave, const char *psMapName)
 {
+    auto saved_game = &ojk::SavedGame::get_instance();
+
 	char	sComment[iSG_COMMENT_SIZE];
 
 	if ( qbAutosave || !*saveGameComment)
@@ -827,11 +872,16 @@ static void SG_WriteComment(qboolean qbAutosave, const char *psMapName)
 		Q_strncpyz(sComment,saveGameComment, sizeof(sComment));
 	}
 
-	::sg_write_no_cast(::SG_Append, INT_ID('C','O','M','M'), sComment);
+    saved_game->write_chunk(
+        INT_ID('C','O','M','M'),
+        sComment);
 
 	// Add Date/Time/Map stamp
 	unsigned int timestamp = SG_UnixTimestamp (time (NULL));
-	::sg_write<uint32_t>(::SG_Append, INT_ID('C','M','T','M'), timestamp);
+
+    saved_game->write_chunk<uint32_t>(
+        INT_ID('C','M','T','M'),
+        timestamp);
 
 	Com_DPrintf("Saving: current (%s)\n", sComment);
 }
@@ -1010,6 +1060,8 @@ qboolean SG_GetSaveImage( const char *psPathlessBaseName, void *pvAddress )
 
 static void SG_WriteScreenshot(qboolean qbAutosave, const char *psMapName)
 {
+    auto saved_game = &ojk::SavedGame::get_instance();
+
 	byte *pbRawScreenShot = NULL;
 	byte *byBlank = NULL;
 
@@ -1053,8 +1105,16 @@ static void SG_WriteScreenshot(qboolean qbAutosave, const char *psMapName)
 	iJPGDataSize = re.SaveJPGToBuffer(pJPGData, bufSize, JPEG_IMAGE_QUALITY, SG_SCR_WIDTH, SG_SCR_HEIGHT, pbRawScreenShot, 0 );
 	if ( qbAutosave )
 		delete[] byBlank;
-	::sg_write<uint32_t>(::SG_Append, INT_ID('S','H','L','N'), iJPGDataSize);
-	::sg_write_no_cast(::SG_Append, INT_ID('S','H','O','T'), pJPGData, static_cast<int>(iJPGDataSize));
+
+    saved_game->write_chunk<uint32_t>(
+        INT_ID('S','H','L','N'),
+        iJPGDataSize);
+
+    saved_game->write_chunk(
+        INT_ID('S','H','O','T'),
+        pJPGData,
+        static_cast<int>(iJPGDataSize));
+
 	Z_Free(pJPGData);
 	SCR_TempRawImage_CleanUp();
 }
@@ -1134,7 +1194,13 @@ qboolean SG_WriteSavegame(const char *psPathlessBaseName, qboolean qbAutosave)
 #ifdef JK2_MODE
 	SG_WriteScreenshot(qbAutosave, sMapCmd);
 #endif
-	::sg_write_no_cast(::SG_Append, INT_ID('M','P','C','M'), sMapCmd);
+
+    auto saved_game = &ojk::SavedGame::get_instance();
+
+    saved_game->write_chunk(
+        INT_ID('M','P','C','M'),
+        sMapCmd);
+
 	SG_WriteCvars();
 
 	WriteGame (qbAutosave);
@@ -1143,8 +1209,14 @@ qboolean SG_WriteSavegame(const char *psPathlessBaseName, qboolean qbAutosave)
 	//
 	if (!qbAutosave)
 	{
-		::sg_write<int32_t>(::SG_Append, INT_ID('T','I','M','E'), ::sv.time);
-		::sg_write<int32_t>(::SG_Append, INT_ID('T','I','M','R'), ::sv.timeResidual);
+        saved_game->write_chunk<int32_t>(
+            INT_ID('T','I','M','E'),
+            ::sv.time);
+
+        saved_game->write_chunk<int32_t>(
+            INT_ID('T','I','M','R'),
+            ::sv.timeResidual);
+
 		CM_WritePortalState();
 		SG_WriteServerConfigStrings();
 	}
diff --git a/codeJK2/cgame/cg_main.cpp b/codeJK2/cgame/cg_main.cpp
index 1f2b761..2804a04 100644
--- a/codeJK2/cgame/cg_main.cpp
+++ b/codeJK2/cgame/cg_main.cpp
@@ -1641,10 +1641,15 @@ Ghoul2 Insert End
 
 void CG_WriteTheEvilCGHackStuff(void)
 {
-	::sg_write<int32_t>(::gi, INT_ID('F','P','S','L'), ::cg.forcepowerSelect);
-	::sg_write<int32_t>(::gi, INT_ID('I','V','S','L'), ::cg.inventorySelect);
+    ::gi.saved_game->write_chunk<int32_t>(
+        INT_ID('F','P','S','L'),
+        ::cg.forcepowerSelect);
 
+    ::gi.saved_game->write_chunk<int32_t>(
+        INT_ID('I','V','S','L'),
+        ::cg.inventorySelect);
 }
+
 void CG_ReadTheEvilCGHackStuff(void)
 {
     ::gi.saved_game->read_chunk<int32_t>(
diff --git a/codeJK2/game/G_Timer.cpp b/codeJK2/game/G_Timer.cpp
index b767a6d..c67eda9 100644
--- a/codeJK2/game/G_Timer.cpp
+++ b/codeJK2/game/G_Timer.cpp
@@ -179,7 +179,9 @@ void TIMER_Save( void )
 		}
 
 		//Write out the timer information
-		::sg_write<int32_t>(::gi, INT_ID('T','I','M','E'), numTimers);
+        ::gi.saved_game->write_chunk<int32_t>(
+            INT_ID('T','I','M','E'),
+            numTimers);
 	
 		gtimer_t *p = g_timers[j];
 		assert ((numTimers && p) || (!numTimers && !p));
@@ -193,11 +195,20 @@ void TIMER_Save( void )
 			assert( length < 1024 );//This will cause problems when loading the timer if longer
 
 			//Write out the string size and data
-			::sg_write<int32_t>(::gi, INT_ID('T','S','L','N'), length);
-			::sg_write_no_cast(::gi, INT_ID('T','S','N','M'), timerID, length);
+            ::gi.saved_game->write_chunk<int32_t>(
+                INT_ID('T','S','L','N'),
+                length);
+
+            ::gi.saved_game->write_chunk(
+                INT_ID('T','S','N','M'),
+                timerID,
+                length);
 
 			//Write out the timer data
-			::sg_write<int32_t>(::gi, INT_ID('T','D','T','A'), time);
+            ::gi.saved_game->write_chunk<int32_t>(
+                INT_ID('T','D','T','A'),
+                time);
+
 			p = p->next;
 		}
 	}
diff --git a/codeJK2/game/Q3_Registers.cpp b/codeJK2/game/Q3_Registers.cpp
index debb294..3fb2e65 100644
--- a/codeJK2/game/Q3_Registers.cpp
+++ b/codeJK2/game/Q3_Registers.cpp
@@ -290,7 +290,10 @@ Q3_VariableSaveFloats
 void Q3_VariableSaveFloats( varFloat_m &fmap )
 {
 	int numFloats = fmap.size();
-	::sg_write<int32_t>(::gi, INT_ID('F','V','A','R'), numFloats);
+
+    ::gi.saved_game->write_chunk<int32_t>(
+        INT_ID('F','V','A','R'),
+        numFloats);
 
 	varFloat_m::iterator	vfi;
 	STL_ITERATE( vfi, fmap )
@@ -299,11 +302,19 @@ void Q3_VariableSaveFloats( varFloat_m &fmap )
 		int	idSize = strlen( ((*vfi).first).c_str() );
 		
 		//Save out the real data
-		::sg_write<int32_t>(::gi, INT_ID('F','I','D','L'), idSize);
-		::sg_write_no_cast(::gi, INT_ID('F','I','D','S'), ((*vfi).first).c_str(), idSize);
+        ::gi.saved_game->write_chunk<int32_t>(
+            INT_ID('F','I','D','L'),
+            idSize);
+
+        ::gi.saved_game->write_chunk(
+            INT_ID('F','I','D','S'),
+            ((*vfi).first).c_str(),
+            idSize);
 
 		//Save out the float value
-		::sg_write_no_cast(::gi, INT_ID('F','V','A','L'), (*vfi).second);
+        ::gi.saved_game->write_chunk<float>(
+            INT_ID('F','V','A','L'),
+            (*vfi).second);
 	}
 }
 
@@ -316,7 +327,10 @@ Q3_VariableSaveStrings
 void Q3_VariableSaveStrings( varString_m &smap )
 {
 	int numStrings = smap.size();
-	::sg_write<int32_t>(::gi, INT_ID('S','V','A','R'), numStrings);
+
+    ::gi.saved_game->write_chunk<int32_t>(
+        INT_ID('S','V','A','R'),
+        numStrings);
 
 	varString_m::iterator	vsi;
 	STL_ITERATE( vsi, smap )
@@ -325,14 +339,26 @@ void Q3_VariableSaveStrings( varString_m &smap )
 		int	idSize = strlen( ((*vsi).first).c_str() );
 		
 		//Save out the real data
-		::sg_write<int32_t>(::gi, INT_ID('S','I','D','L'), idSize);
-		::sg_write_no_cast(::gi, INT_ID('S','I','D','S'), ((*vsi).first).c_str(), idSize);
+        ::gi.saved_game->write_chunk<int32_t>(
+            INT_ID('S','I','D','L'),
+            idSize);
+
+        ::gi.saved_game->write_chunk(
+            INT_ID('S','I','D','S'),
+            ((*vsi).first).c_str(),
+            idSize);
 
 		//Save out the string value
 		idSize = strlen( ((*vsi).second).c_str() );
 
-		::sg_write<int32_t>(::gi, INT_ID('S','V','S','Z'), idSize);
-		::sg_write_no_cast(::gi, INT_ID('S','V','A','L'), ((*vsi).second).c_str(), idSize);
+        ::gi.saved_game->write_chunk<int32_t>(
+            INT_ID('S','V','S','Z'),
+            idSize);
+
+        ::gi.saved_game->write_chunk(
+            INT_ID('S','V','A','L'),
+            ((*vsi).second).c_str(),
+            idSize);
 	}
 }
 
diff --git a/codeJK2/game/g_main.cpp b/codeJK2/game/g_main.cpp
index dd435f6..18b0355 100644
--- a/codeJK2/game/g_main.cpp
+++ b/codeJK2/game/g_main.cpp
@@ -91,7 +91,9 @@ qboolean PInUse2(gentity_t *ent)
 
 void WriteInUseBits(void)
 {
-	::sg_write<uint32_t>(::gi, INT_ID('I','N','U','S'), ::g_entityInUseBits);
+    ::gi.saved_game->write_chunk<uint32_t>(
+        INT_ID('I','N','U','S'),
+        ::g_entityInUseBits);
 }
 
 void ReadInUseBits(void)
@@ -1482,7 +1484,9 @@ extern qboolean player_locked;
 
 void G_LoadSave_WriteMiscData(void)
 {
-	::sg_write<int32_t>(::gi, INT_ID('L','C','K','D'), player_locked);
+    ::gi.saved_game->write_chunk<int32_t>(
+        INT_ID('L','C','K','D'),
+        ::player_locked);
 }
 
 
diff --git a/codeJK2/game/g_objectives.cpp b/codeJK2/game/g_objectives.cpp
index 3f35a57..11c2b7f 100644
--- a/codeJK2/game/g_objectives.cpp
+++ b/codeJK2/game/g_objectives.cpp
@@ -63,7 +63,9 @@ OBJ_SaveMissionObjectives
 */
 void OBJ_SaveMissionObjectives( gclient_t *client )
 {
-	::sg_write_no_cast(::gi, INT_ID('O','B','J','T'), client->sess.mission_objectives);
+    ::gi.saved_game->write_chunk(
+        INT_ID('O','B','J','T'),
+        client->sess.mission_objectives);
 }
 
 
diff --git a/codeJK2/game/g_roff.cpp b/codeJK2/game/g_roff.cpp
index 97d8e65..8d3f388 100644
--- a/codeJK2/game/g_roff.cpp
+++ b/codeJK2/game/g_roff.cpp
@@ -628,15 +628,23 @@ void G_SaveCachedRoffs()
 	int i, len;
 
 	// Write out the number of cached ROFFs
-	::sg_write<int32_t>(::gi, INT_ID('R','O','F','F'), num_roffs);
+    ::gi.saved_game->write_chunk<int32_t>(
+        INT_ID('R','O','F','F'),
+        ::num_roffs);
 
 	// Now dump out the cached ROFF file names in order so they can be loaded on the other end
 	for ( i = 0; i < num_roffs; i++ )
 	{
 		// Dump out the string length to make things a bit easier on the other end...heh heh.
 		len = strlen( roffs[i].fileName ) + 1;
-		::sg_write<int32_t>(::gi, INT_ID('S','L','E','N'), len);
-		::sg_write_no_cast(::gi, INT_ID('R','S','T','R'), roffs[i].fileName, len);
+        ::gi.saved_game->write_chunk<int32_t>(
+            INT_ID('S','L','E','N'),
+            len);
+
+        ::gi.saved_game->write_chunk(
+            INT_ID('R','S','T','R'),
+            ::roffs[i].fileName,
+            len);
 	}
 }
 
diff --git a/codeJK2/game/g_savegame.cpp b/codeJK2/game/g_savegame.cpp
index 2d4f6e4..9634913 100644
--- a/codeJK2/game/g_savegame.cpp
+++ b/codeJK2/game/g_savegame.cpp
@@ -477,13 +477,19 @@ static void EnumerateFields(const field_t *pFields, T* src_instance, unsigned in
 
     ::sg_export(*src_instance, *dst_instance);
 
-	::sg_write_no_cast(::gi, ulChid, dst_buffer.data(), dst_size);
+    ::gi.saved_game->write_chunk(
+        ulChid,
+        dst_buffer.data(),
+        dst_size);
 
 	// save out any associated strings..
 	//
 	for (const auto& it : strList)
 	{
-		::sg_write_no_cast(::gi, INT_ID('S','T','R','G'), it.c_str(), static_cast<int>(it.length()+1));
+        ::gi.saved_game->write_chunk(
+            INT_ID('S','T','R','G'),
+            it.c_str(),
+            static_cast<int>(it.length() + 1));
 	}
 }
 
@@ -686,7 +692,9 @@ static void WriteGEntities(qboolean qbAutosave)
 		}
 	}
 
-	::sg_write<int32_t>(::gi, INT_ID('N','M','E','D'), iCount);
+    ::gi.saved_game->write_chunk<int32_t>(
+        INT_ID('N','M','E','D'),
+        iCount);
 
 	for (i=0; i<(qbAutosave?1:globals.num_entities); i++)
 	{
@@ -694,7 +702,9 @@ static void WriteGEntities(qboolean qbAutosave)
 
 		if ( ent->inuse)
 		{
-			::sg_write<int32_t>(::gi, INT_ID('E','D','N','M'), i);
+            ::gi.saved_game->write_chunk<int32_t>(
+                INT_ID('E','D','N','M'),
+                i);
 
 			qboolean qbLinked = ent->linked;
 			gi.unlinkentity( ent );
@@ -725,7 +735,9 @@ static void WriteGEntities(qboolean qbAutosave)
 
 			if (tempEnt.parms)
 			{
-				::sg_write_no_cast(::gi, INT_ID('P','A','R','M'), *ent->parms);
+                ::gi.saved_game->write_chunk(
+                    INT_ID('P','A','R','M'),
+                    *ent->parms);
 			}
 
 			// the scary ghoul2 saver stuff...  (fingers crossed)
@@ -748,7 +760,10 @@ static void WriteGEntities(qboolean qbAutosave)
 		//	This saves time debugging, and makes things easier to track.
 		//
 		static int iBlah = 1234;
-		::sg_write<int32_t>(::gi, INT_ID('I','C','O','K'), iBlah);
+
+        ::gi.saved_game->write_chunk<int32_t>(
+            INT_ID('I','C','O','K'),
+            iBlah);
 	}
 	if (!qbAutosave )//really shouldn't need to write these bits at all, just restore them from the ents...
 	{
@@ -1004,7 +1019,10 @@ void WriteLevel(qboolean qbAutosave)
 	// put out an end-marker so that the load code can check everything was read in...
 	//
 	static int iDONE = 1234;
-	::sg_write<int32_t>(::gi, INT_ID('D','O','N','E'), iDONE);
+
+    ::gi.saved_game->write_chunk<int32_t>(
+        INT_ID('D','O','N','E'),
+        iDONE);
 }
 
 void ReadLevel(qboolean qbAutosave, qboolean qbLoadTransition)
diff --git a/codeJK2/icarus/Instance.cpp b/codeJK2/icarus/Instance.cpp
index 3e31873..78e4f94 100644
--- a/codeJK2/icarus/Instance.cpp
+++ b/codeJK2/icarus/Instance.cpp
@@ -304,7 +304,12 @@ int ICARUS_Instance::SaveSequenceIDTable( void )
 {
 	//Save out the number of sequences to follow
 	int		numSequences = m_sequences.size();
-	::sg_write<int32_t>(m_interface, INT_ID('#','S','E','Q'), numSequences);
+
+    auto saved_game = m_interface->saved_game;
+
+    saved_game->write_chunk<int32_t>(
+        INT_ID('#','S','E','Q'),
+        numSequences);
 
 	//Sequences are saved first, by ID and information
 	sequence_l::iterator	sqi;
@@ -321,7 +326,10 @@ int ICARUS_Instance::SaveSequenceIDTable( void )
 		idTable[itr++] = (*sqi)->GetID();
 	}
 
-	::sg_write<int32_t>(m_interface, INT_ID('S','Q','T','B'), idTable, numSequences);
+    saved_game->write_chunk<int32_t>(
+        INT_ID('S','Q','T','B'),
+        idTable,
+        numSequences);
 
 	delete[] idTable;
 
@@ -359,7 +367,12 @@ int ICARUS_Instance::SaveSequencers( void )
 {
 	//Save out the number of sequences to follow
 	int		numSequencers = m_sequencers.size();
-	::sg_write<int32_t>(m_interface, INT_ID('#','S','Q','R'), numSequencers);
+
+    auto saved_game = m_interface->saved_game;
+
+    saved_game->write_chunk<int32_t>(
+        INT_ID('#','S','Q','R'),
+        numSequencers);
 
 	//The sequencers are then saved
 	sequencer_l::iterator	si;
@@ -381,7 +394,11 @@ int ICARUS_Instance::SaveSignals( void )
 {
 	int	numSignals = m_signals.size();
 
-	::sg_write<int32_t>(m_interface, INT_ID('I','S','I','G'), numSignals);
+    auto saved_game = m_interface->saved_game;
+
+    saved_game->write_chunk<int32_t>(
+        INT_ID('I','S','I','G'),
+        numSignals);
 
 	signal_m::iterator	si;
 	STL_ITERATE( si, m_signals )
@@ -395,10 +412,15 @@ int ICARUS_Instance::SaveSignals( void )
 		int length = strlen( name ) + 1;
 
 		//Save out the string size
-		::sg_write<int32_t>(m_interface, INT_ID('S','I','G','#'), length);
+        saved_game->write_chunk<int32_t>(
+            INT_ID('S','I','G','#'),
+            length);
 
 		//Write out the string
-		::sg_write_no_cast(m_interface, INT_ID('S','I','G','N'), name, length );
+        saved_game->write_chunk(
+            INT_ID('S','I','G','N'),
+            name,
+            length );
 	}
 
 	return true;
@@ -414,7 +436,12 @@ int ICARUS_Instance::Save( void )
 {	
 	//Save out a ICARUS save block header with the ICARUS version
 	double	version = ICARUS_VERSION;
-	::sg_write_no_cast(m_interface, INT_ID('I','C','A','R'), version);
+
+    auto saved_game = m_interface->saved_game;
+
+    saved_game->write_chunk<double>(
+        INT_ID('I','C','A','R'),
+        version);
 
 	//Save out the signals
 	if ( SaveSignals() == false )
@@ -428,7 +455,9 @@ int ICARUS_Instance::Save( void )
 	if ( SaveSequencers() == false )
 		return false;
 
-	::sg_write_no_cast(m_interface, INT_ID('I','E','N','D'), version);
+    saved_game->write_chunk<double>(
+        INT_ID('I','E','N','D'),
+        version);
 
 	return true;
 }
diff --git a/codeJK2/icarus/Sequence.cpp b/codeJK2/icarus/Sequence.cpp
index 721c145..0d6a1e8 100644
--- a/codeJK2/icarus/Sequence.cpp
+++ b/codeJK2/icarus/Sequence.cpp
@@ -343,18 +343,27 @@ int CSequence::SaveCommand( CBlock *block )
 	unsigned char	flags;
 	int				numMembers, bID, size;
 	CBlockMember	*bm;
-	
+
+    auto saved_game = m_owner->GetInterface()->saved_game;
+
 	//Save out the block ID
 	bID = block->GetBlockID();
-	::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('B','L','I','D'), bID);
+    saved_game->write_chunk<int32_t>(
+        INT_ID('B','L','I','D'),
+        bID);
 
 	//Save out the block's flags
 	flags = block->GetFlags();
-	::sg_write<uint8_t>(m_owner->GetInterface(), INT_ID('B','F','L','G'), flags);
+    saved_game->write_chunk<uint8_t>(
+        INT_ID('B','F','L','G'),
+        flags);
 
 	//Save out the number of members to read
 	numMembers = block->GetNumMembers();
-	::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('B','N','U','M'), numMembers);
+
+    saved_game->write_chunk<int32_t>(
+        INT_ID('B','N','U','M'),
+        numMembers);
 
 	for ( int i = 0; i < numMembers; i++ )
 	{
@@ -362,14 +371,25 @@ int CSequence::SaveCommand( CBlock *block )
 
 		//Save the block id
 		bID = bm->GetID();
-		::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('B','M','I','D'), bID);
+
+        saved_game->write_chunk<int32_t>(
+            INT_ID('B','M','I','D'),
+            bID);
 		
 		//Save out the data size
 		size = bm->GetSize();
-		::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('B','S','I','Z'), size);
+
+        saved_game->write_chunk<int32_t>(
+            INT_ID('B','S','I','Z'),
+            size);
 		
 		//Save out the raw data
-		::sg_write_no_cast(m_owner->GetInterface(), INT_ID('B','M','E','M'), bm->GetData(), size);
+        auto raw_data = static_cast<const uint8_t*>(bm->GetData());
+
+        saved_game->write_chunk(
+            INT_ID('B','M','E','M'),
+            raw_data,
+            size);
 	}
 
 	return true;
@@ -387,32 +407,51 @@ int CSequence::Save( void )
 	block_l::iterator		bi;
 	int						id;
 
+    auto saved_game = m_owner->GetInterface()->saved_game;
+
 	//Save the parent (by GUID)
 	id = ( m_parent != NULL ) ? m_parent->GetID() : -1;
-	::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('S','P','I','D'), id);
+
+    saved_game->write_chunk<int32_t>(
+        INT_ID('S','P','I','D'),
+        id);
 
 	//Save the return (by GUID)
 	id = ( m_return != NULL ) ? m_return->GetID() : -1;
-	::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('S','R','I','D'), id);
+
+    saved_game->write_chunk<int32_t>(
+        INT_ID('S','R','I','D'),
+        id);
 	
 	//Save the number of children
-	::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('S','N','C','H'), m_numChildren);
+    saved_game->write_chunk<int32_t>(
+        INT_ID('S','N','C','H'),
+        m_numChildren);
 
 	//Save out the children (only by GUID)
 	STL_ITERATE( ci, m_children )
 	{
 		id = (*ci)->GetID();
-		::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('S','C','H','D'), id);
+
+        saved_game->write_chunk<int32_t>(
+            INT_ID('S','C','H','D'),
+            id);
 	}
 
 	//Save flags
-	::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('S','F','L','G'), m_flags);
+    saved_game->write_chunk<int32_t>(
+        INT_ID('S','F','L','G'),
+        m_flags);
 
 	//Save iterations
-	::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('S','I','T','R'), m_iterations);
+    saved_game->write_chunk<int32_t>(
+        INT_ID('S','I','T','R'),
+        m_iterations);
 
 	//Save the number of commands
-	::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('S','N','M','C'), m_numCommands);
+    saved_game->write_chunk<int32_t>(
+        INT_ID('S','N','M','C'),
+        m_numCommands);
 
 	//Save the commands
 	STL_ITERATE( bi, m_commands )
diff --git a/codeJK2/icarus/Sequencer.cpp b/codeJK2/icarus/Sequencer.cpp
index 457a12d..c41b06c 100644
--- a/codeJK2/icarus/Sequencer.cpp
+++ b/codeJK2/icarus/Sequencer.cpp
@@ -2328,20 +2328,29 @@ int	CSequencer::Save( void )
 	taskSequence_m::iterator	ti;
 	int							numSequences = 0, id, numTasks;
 
+    auto saved_game = m_ie->saved_game;
+
 	//Get the number of sequences to save out
 	numSequences = m_sequences.size();
 
 	//Save out the owner sequence
-	::sg_write<int32_t>(m_ie, INT_ID('S','Q','R','E'), m_ownerID);
+    saved_game->write_chunk<int32_t>(
+        INT_ID('S','Q','R','E'),
+        m_ownerID);
 
 	//Write out the number of sequences we need to read
-	::sg_write<int32_t>(m_ie, INT_ID('S','Q','R','#'), numSequences);
+    saved_game->write_chunk<int32_t>(
+        INT_ID('S','Q','R','#'),
+        numSequences);
 
 	//Second pass, save out all sequences, in order
 	STL_ITERATE( si, m_sequences )
 	{
 		id = (*si)->GetID();
-		::sg_write<int32_t>(m_ie, INT_ID('S','Q','R','I'), id);
+
+        saved_game->write_chunk<int32_t>(
+            INT_ID('S','Q','R','I'),
+            id);
 	}
 
 	//Save out the taskManager
@@ -2349,29 +2358,45 @@ int	CSequencer::Save( void )
 
 	//Save out the task sequences mapping the name to the GUIDs
 	numTasks = m_taskSequences.size();
-	::sg_write<int32_t>(m_ie, INT_ID('S','Q','T','#'), numTasks);
+
+    saved_game->write_chunk<int32_t>(
+        INT_ID('S','Q','T','#'),
+        numTasks);
 
 	STL_ITERATE( ti, m_taskSequences )
 	{	
 		//Save the task group's ID
 		id = ((*ti).first)->GetGUID();
-		::sg_write<int32_t>(m_ie, INT_ID('S','T','I','D'), id);
+
+        saved_game->write_chunk<int32_t>(
+            INT_ID('S','T','I','D'),
+            id);
 
 		//Save the sequence's ID
 		id = ((*ti).second)->GetID();
-		::sg_write<int32_t>(m_ie, INT_ID('S','S','I','D'), id);
+
+        saved_game->write_chunk<int32_t>(
+            INT_ID('S','S','I','D'),
+            id);
 	}
 
 	int	curGroupID = ( m_curGroup == NULL ) ? -1 : m_curGroup->GetGUID();
 
-	::sg_write<int32_t>(m_ie, INT_ID('S','Q','C','T'), curGroupID);
+    saved_game->write_chunk<int32_t>(
+        INT_ID('S','Q','C','T'),
+        curGroupID);
 
 	//Output the number of commands
-	::sg_write<int32_t>(m_ie, INT_ID('S','Q','#','C'), m_numCommands);	//FIXME: This can be reconstructed
+    saved_game->write_chunk<int32_t>(
+        INT_ID('S','Q','#','C'),
+        m_numCommands);	//FIXME: This can be reconstructed
 
 	//Output the ID of the current sequence
 	id = ( m_curSequence != NULL ) ? m_curSequence->GetID() : -1;
-	::sg_write<int32_t>(m_ie, INT_ID('S','Q','C','S'), id);
+
+    saved_game->write_chunk<int32_t>(
+        INT_ID('S','Q','C','S'),
+        id);
 
 	return true;
 }
diff --git a/codeJK2/icarus/TaskManager.cpp b/codeJK2/icarus/TaskManager.cpp
index bd386f6..3310505 100644
--- a/codeJK2/icarus/TaskManager.cpp
+++ b/codeJK2/icarus/TaskManager.cpp
@@ -1640,18 +1640,29 @@ int CTaskManager::SaveCommand( CBlock *block )
 	unsigned char	flags;
 	int				numMembers, bID, size;
 	CBlockMember	*bm;
-	
+
+    auto saved_game = m_owner->GetInterface()->saved_game;
+
 	//Save out the block ID
 	bID = block->GetBlockID();
-	::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('B','L','I','D'), bID);
+
+    saved_game->write_chunk<int32_t>(
+        INT_ID('B','L','I','D'),
+        bID);
 
 	//Save out the block's flags
 	flags = block->GetFlags();
-	::sg_write<uint8_t>(m_owner->GetInterface(), INT_ID('B','F','L','G'), flags);
+
+    saved_game->write_chunk<uint8_t>(
+        INT_ID('B','F','L','G'),
+        flags);
 
 	//Save out the number of members to read
 	numMembers = block->GetNumMembers();
-	::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('B','N','U','M'), numMembers);
+
+    saved_game->write_chunk<int32_t>(
+        INT_ID('B','N','U','M'),
+        numMembers);
 
 	for ( int i = 0; i < numMembers; i++ )
 	{
@@ -1659,14 +1670,25 @@ int CTaskManager::SaveCommand( CBlock *block )
 
 		//Save the block id
 		bID = bm->GetID();
-		::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('B','M','I','D'), bID);
+
+        saved_game->write_chunk<int32_t>(
+            INT_ID('B','M','I','D'),
+            bID);
 		
 		//Save out the data size
 		size = bm->GetSize();
-		::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('B','S','I','Z'), size);
+
+        saved_game->write_chunk<int32_t>(
+            INT_ID('B','S','I','Z'),
+            size);
 		
 		//Save out the raw data
-		::sg_write_no_cast(m_owner->GetInterface(), INT_ID('B','M','E','M'), bm->GetData(), size);
+        auto raw_data = static_cast<const uint8_t*>(bm->GetData());
+
+        saved_game->write_chunk(
+            INT_ID('B','M','E','M'),
+            raw_data,
+            size);
 	}
 
 	return true;
@@ -1688,12 +1710,19 @@ void CTaskManager::Save( void )
 	int			id, numCommands;
 	int			numWritten;
 
+    auto saved_game = m_owner->GetInterface()->saved_game;
+
 	//Save the taskmanager's GUID
-	::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('T','M','I','D'), m_GUID);	//FIXME: This can be reconstructed
+    saved_game->write_chunk<int32_t>(
+        INT_ID('T','M','I','D'),
+        m_GUID); //FIXME: This can be reconstructed
 
 	//Save out the number of tasks that will follow
 	int iNumTasks = m_tasks.size();
-	::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('T','S','K','#'), iNumTasks);
+
+    saved_game->write_chunk<int32_t>(
+        INT_ID('T','S','K','#'),
+        iNumTasks);
 
 	//Save out all the tasks
 	tasks_l::iterator	ti;
@@ -1702,11 +1731,17 @@ void CTaskManager::Save( void )
 	{
 		//Save the GUID
 		id = (*ti)->GetGUID();
-		::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('T','K','I','D'), id);
+
+        saved_game->write_chunk<int32_t>(
+            INT_ID('T','K','I','D'),
+            id);
 
 		//Save the timeStamp (FIXME: Although, this is going to be worthless if time is not consistent...)
 		timeStamp = (*ti)->GetTimeStamp();
-		::sg_write<uint32_t>(m_owner->GetInterface(), INT_ID('T','K','T','S'), timeStamp);
+
+        saved_game->write_chunk<uint32_t>(
+            INT_ID('T','K','T','S'),
+            timeStamp);
 
 		//Save out the block
 		block = (*ti)->GetBlock();
@@ -1715,14 +1750,22 @@ void CTaskManager::Save( void )
 
 	//Save out the number of task groups
 	int numTaskGroups = m_taskGroups.size();
-	::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('T','G','#','G'), numTaskGroups);
+
+    saved_game->write_chunk<int32_t>(
+        INT_ID('T','G','#','G'),
+        numTaskGroups);
+
 	//Save out the IDs of all the task groups
 	numWritten = 0;
 	taskGroup_v::iterator	tgi;
 	STL_ITERATE( tgi, m_taskGroups )
 	{
 		id = (*tgi)->GetGUID();
-		::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('T','K','G','#'), id);		
+
+        saved_game->write_chunk<int32_t>(
+            INT_ID('T','K','G','#'),
+            id);
+
 		numWritten++;
 	}
 	assert (numWritten == numTaskGroups);
@@ -1733,11 +1776,17 @@ void CTaskManager::Save( void )
 	{
 		//Save out the parent
 		id = ( (*tgi)->GetParent() == NULL ) ? -1 : ((*tgi)->GetParent())->GetGUID();
-		::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('T','K','G','P'), id);
+
+        saved_game->write_chunk<int32_t>(
+            INT_ID('T','K','G','P'),
+            id);
 
 		//Save out the number of commands
 		numCommands = (*tgi)->m_completedTasks.size();
-		::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('T','G','N','C'), numCommands);
+
+        saved_game->write_chunk<int32_t>(
+            INT_ID('T','G','N','C'),
+            numCommands);
 
 		//Save out the command map
 		CTaskGroup::taskCallback_m::iterator	tci;
@@ -1746,16 +1795,25 @@ void CTaskManager::Save( void )
 		{
 			//Write out the ID
 			id = (*tci).first;
-			::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('G','M','I','D'), id);
+
+            saved_game->write_chunk<int32_t>(
+                INT_ID('G','M','I','D'),
+                id);
 
 			//Write out the state of completion
 			completed = (*tci).second;
-			::sg_write<uint8_t>(m_owner->GetInterface(), INT_ID('G','M','D','N'), completed);
+
+            saved_game->write_chunk<uint8_t>(
+                INT_ID('G','M','D','N'),
+                completed);
 		}
 
 		//Save out the number of completed commands
 		id = (*tgi)->m_numCompleted;
-		::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('T','G','D','N'), id);	//FIXME: This can be reconstructed
+
+        saved_game->write_chunk<int32_t>(
+            INT_ID('T','G','D','N'),
+            id); //FIXME: This can be reconstructed
 		numWritten++;
 	}
 	assert (numWritten == numTaskGroups);
@@ -1765,7 +1823,10 @@ void CTaskManager::Save( void )
 	{
 		//Save out the currently active group
 		int	curGroupID = ( m_curGroup == NULL ) ? -1 : m_curGroup->GetGUID();
-		::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('T','G','C','G'), curGroupID);
+
+        saved_game->write_chunk<int32_t>(
+            INT_ID('T','G','C','G'),
+            curGroupID);
 	}
 
 	//Save out the task group name maps
@@ -1781,17 +1842,25 @@ void CTaskManager::Save( void )
 		int length = strlen( name ) + 1;
 
 		//Save out the string size
-		::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('T','G','N','L'), length);
+        saved_game->write_chunk<int32_t>(
+            INT_ID('T','G','N','L'),
+            length);
 
 		//Write out the string
-		::sg_write_no_cast(m_owner->GetInterface(), INT_ID('T','G','N','S'), name, length);
+        saved_game->write_chunk(
+            INT_ID('T','G','N','S'),
+            name,
+            length);
 
 		taskGroup = (*tmi).second;
 
 		id = taskGroup->GetGUID();
 
 		//Write out the ID
-		::sg_write<int32_t>(m_owner->GetInterface(), INT_ID('T','G','N','I'), id);
+        saved_game->write_chunk<int32_t>(
+            INT_ID('T','G','N','I'),
+            id);
+
 		numWritten++;
 	}
 	assert (numWritten == numTaskGroups);
diff --git a/shared/qcommon/ojk_i_saved_game.h b/shared/qcommon/ojk_i_saved_game.h
index f7970f3..b100fc5 100644
--- a/shared/qcommon/ojk_i_saved_game.h
+++ b/shared/qcommon/ojk_i_saved_game.h
@@ -497,7 +497,7 @@ void ISavedGame::write(
     int src_count,
     InplaceTag)
 {
-    constexpr auto src_size = src_count * static_cast<int>(sizeof(TSrc));
+    const auto src_size = src_count * static_cast<int>(sizeof(TSrc));
 
     raw_write(
         src_values,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/openjk.git



More information about the Pkg-games-commits mailing list