예제 #1
0
파일: g_session.c 프로젝트: dpadgett/pugmod
/*
==================
G_InitWorldSession

==================
*/
void G_InitWorldSession( void ) {
	char	s[MAX_STRING_CHARS];
	int			gt;
    fileHandle_t tmpfile;

	trap_Cvar_VariableStringBuffer( "session", s, sizeof(s) );
	gt = atoi( s );
	
	// if the gametype changed since the last session, don't use any
	// client sessions
	if ( g_gametype.integer != gt ) {
		level.newSession = qtrue;
		G_Printf( "Gametype changed, clearing session data.\n" );
	}
	char      gsessptr[MAX_STRING_CHARS];

   // bani - allocate client persistent session data
   trap_TrueMalloc( &g_sess, g_maxclients.integer * sizeof( clientSession_t ) );
   trap_Cvar_VariableStringBuffer( "gsess", gsessptr, sizeof( gsessptr ) );
   if( !Q_stricmp( gsessptr, "" ) ) {
      trap_Cvar_Set( "gsess", "1" );
      memset( g_sess, 0, g_maxclients.integer * sizeof( clientSession_t ) );
   } else {
      //PLS 2 LOAD FROM FILE
	  trap_FS_FOpenFile( "sess.dat", &tmpfile, FS_READ );
	  trap_FS_Read( g_sess, g_maxclients.integer * sizeof( clientSession_t ), tmpfile );
	  trap_FS_FCloseFile( tmpfile );
	  //KTHXBAI
   }
}
예제 #2
0
static JKGMemBlock_t *JKG_Mem_AddBlock(int size) {
	int idx;
	// Add new entry in the MemBlocks dynamic array
	idx = JKG_Arrays_AddArrayElement((void **)&MemBlocks, sizeof(JKGMemBlock_t), &BlockCount);

	// Since these allocs are static, we'll use trap_TrueMalloc for it
	// This will make the alloc in the engine's zone memory

	// Allocs are fitted with a marker, so we can quickly determine if an alloc is made by this (in G_Free)
	trap_TrueMalloc(&MemBlocks[idx].ptr, size+4);
	MemBlocks[idx].size = size;
	if (!MemBlocks[idx].ptr) {
		G_Error("G_Alloc: Failed to allocate %i bytes of memory\n", size);
	}
	memset(MemBlocks[idx].ptr,0,size);
	*(int *)MemBlocks[idx].ptr = ALLOCMARKER;
        #ifndef __linux__
		(int)MemBlocks[idx].ptr += 4;
        #else
        { // linux doesnt like += 4 on pointers >.>
            int tmp = (int)MemBlocks[idx].ptr;
            tmp += 4;
            MemBlocks[idx].ptr = (void *)tmp;
        }
        #endif
	return &MemBlocks[idx];
}
예제 #3
0
파일: g_strap.c 프로젝트: jwginge/ojpa
void strap_TrueMalloc(void **ptr, int size)
{
	trap_TrueMalloc(ptr, size);
}