Example #1
0
/*
=================
Com_Init
=================
*/
void Com_Init( char *commandLine ) {
	char	*s;

	Com_Printf( "%s %s %s\n", Q3_VERSION, CPUSTRING, __DATE__ );

	try {
		// prepare enough of the subsystems to handle
		// cvar and command buffer management
		Com_ParseCommandLine( commandLine );
		
		Swap_Init ();
		Cbuf_Init ();
		
		Com_InitZoneMemory();

		Cmd_Init ();
		Cvar_Init ();
		
		// get the commandline cvars set
		Com_StartupVariable( NULL );

		// done early so bind command exists
		CL_InitKeyCommands();
		
		FS_InitFilesystem ();	//uses z_malloc
		
		Com_InitJournaling();
		
		Cbuf_AddText ("exec default.cfg\n");

		// skip the jk2config.cfg if "safe" is on the command line
		if ( !Com_SafeMode() ) {
			Cbuf_AddText ("exec jk2config.cfg\n");
		}

		Cbuf_AddText ("exec autoexec.cfg\n");
		
		Cbuf_Execute ();
		
		// override anything from the config files with command line args
		Com_StartupVariable( NULL );
		
		// allocate the stack based hunk allocator
		Com_InitHunkMemory();

		// if any archived cvars are modified after this, we will trigger a writing
		// of the config file
		cvar_modifiedFlags &= ~CVAR_ARCHIVE;
		
		//
		// init commands and vars
		//
		Cmd_AddCommand ("quit", Com_Quit_f);
		Cmd_AddCommand ("writeconfig", Com_WriteConfig_f );
		
		com_maxfps = Cvar_Get ("com_maxfps", "85", CVAR_ARCHIVE);
		
		com_developer = Cvar_Get ("developer", "0", CVAR_TEMP );
		com_logfile = Cvar_Get ("logfile", "0", CVAR_TEMP );
		com_speedslog = Cvar_Get ("speedslog", "0", CVAR_TEMP );
		
		com_timescale = Cvar_Get ("timescale", "1", CVAR_CHEAT );
		com_fixedtime = Cvar_Get ("fixedtime", "0", CVAR_CHEAT);
		com_showtrace = Cvar_Get ("com_showtrace", "0", CVAR_CHEAT);
		com_viewlog = Cvar_Get( "viewlog", "0", CVAR_TEMP );
		com_speeds = Cvar_Get ("com_speeds", "0", 0);
		
		cl_paused	   = Cvar_Get ("cl_paused", "0", CVAR_ROM);
		sv_paused	   = Cvar_Get ("sv_paused", "0", CVAR_ROM);
		com_sv_running = Cvar_Get ("sv_running", "0", CVAR_ROM);
		com_cl_running = Cvar_Get ("cl_running", "0", CVAR_ROM);
		com_skippingcin = Cvar_Get ("skippingCinematic", "0", CVAR_ROM);
		com_buildScript = Cvar_Get( "com_buildScript", "0", 0 );
		
		com_FirstTime = Cvar_Get( "com_FirstTime", "0", CVAR_ARCHIVE);
		if ( com_developer && com_developer->integer ) {
			Cmd_AddCommand ("error", Com_Error_f);
			Cmd_AddCommand ("crash", Com_Crash_f );
			Cmd_AddCommand ("freeze", Com_Freeze_f);
		}
		
		s = va("%s %s %s", Q3_VERSION, CPUSTRING, __DATE__ );
		com_version = Cvar_Get ("version", s, CVAR_ROM | CVAR_SERVERINFO );

		SP_Init();	// Initialize StripEd
	
		Sys_Init();	// this also detects CPU type, so I can now do this CPU check below...

		if( !com_FirstTime->integer )	// special request to detect and use top-settings for Intel Williamette chip...	
		{
			Cvar_Set( "com_FirstTime", "1" );	// only do this once			
			//
			// ( make a local ptr only for quick test, since this is a common module )
			//
			cvar_t* s_CPUType = Cvar_Get("sys_cpuid","",0);
			if (s_CPUType->value == CPUID_INTEL_WILLIAMETTE)
			{
				Cbuf_AddText ("exec perfect.cfg\n");
//				Cbuf_Execute ();
			}
		}

		Netchan_Init( Com_Milliseconds() & 0xffff );	// pick a port value that should be nice and random
//	VM_Init();
		SV_Init();
		
		CL_Init();
		Sys_ShowConsole( com_viewlog->integer, qfalse );
		
		// set com_frameTime so that if a map is started on the
		// command line it will still be able to count on com_frameTime
		// being random enough for a serverid
		com_frameTime = Com_Milliseconds();

		// add + commands from command line
		if ( !Com_AddStartupCommands() ) {
#ifdef NDEBUG
			// if the user didn't give any commands, run default action
//			if ( !com_dedicated->integer ) 
			{
				Cbuf_AddText ("cinematic openinglogos\n");				
//				if( !com_introPlayed->integer ) {
//					Cvar_Set( com_introPlayed->name, "1" );
//					Cvar_Set( "nextmap", "cinematic intro" );
//				}
			}
#endif	
		}
		com_fullyInitialized = qtrue;
		Com_Printf ("--- Common Initialization Complete ---\n");
	}

	catch (const char* reason) {
		Sys_Error ("Error during initialization %s", reason);
	}

}
Example #2
0
void Com_Init( char *commandLine ) {
	char	*s;

	Com_Printf( "%s %s %s\n", Q3_VERSION, PLATFORM_STRING, __DATE__ );

	try {
		Cvar_Init ();

		// prepare enough of the subsystems to handle
		// cvar and command buffer management
		Com_ParseCommandLine( commandLine );

		//Swap_Init ();
		Cbuf_Init ();

		Com_InitZoneMemory();

		Cmd_Init ();

		// override anything from the config files with command line args
		Com_StartupVariable( NULL );

		// done early so bind command exists
		CL_InitKeyCommands();

		com_homepath = Cvar_Get("com_homepath", "", CVAR_INIT);

		FS_InitFilesystem ();	//uses z_malloc
		//re.R_InitWorldEffects();   // this doesn't do much but I want to be sure certain variables are intialized.
		
		Com_ExecuteCfg();

		// override anything from the config files with command line args
		Com_StartupVariable( NULL );
		
		// allocate the stack based hunk allocator
		Com_InitHunkMemory();

		// if any archived cvars are modified after this, we will trigger a writing
		// of the config file
		cvar_modifiedFlags &= ~CVAR_ARCHIVE;
		
		//
		// init commands and vars
		//
		Cmd_AddCommand ("quit", Com_Quit_f);
		Cmd_AddCommand ("writeconfig", Com_WriteConfig_f );
		
		com_maxfps = Cvar_Get ("com_maxfps", "125", CVAR_ARCHIVE);
		
		com_developer = Cvar_Get ("developer", "0", CVAR_TEMP );
		com_logfile = Cvar_Get ("logfile", "0", CVAR_TEMP );
		com_speedslog = Cvar_Get ("speedslog", "0", CVAR_TEMP );
		
		com_timescale = Cvar_Get ("timescale", "1", CVAR_CHEAT );
		com_fixedtime = Cvar_Get ("fixedtime", "0", CVAR_CHEAT);
		com_showtrace = Cvar_Get ("com_showtrace", "0", CVAR_CHEAT);
		com_speeds = Cvar_Get ("com_speeds", "0", 0);
		
#ifdef G2_PERFORMANCE_ANALYSIS
		com_G2Report = Cvar_Get("com_G2Report", "0", 0);
#endif

		cl_paused	   = Cvar_Get ("cl_paused", "0", CVAR_ROM);
		sv_paused	   = Cvar_Get ("sv_paused", "0", CVAR_ROM);
		com_sv_running = Cvar_Get ("sv_running", "0", CVAR_ROM);
		com_cl_running = Cvar_Get ("cl_running", "0", CVAR_ROM);
		com_skippingcin = Cvar_Get ("skippingCinematic", "0", CVAR_ROM);
		com_buildScript = Cvar_Get( "com_buildScript", "0", 0 );

		com_affinity = Cvar_Get( "com_affinity", "1", CVAR_ARCHIVE );

		com_bootlogo = Cvar_Get( "com_bootlogo", "1", CVAR_ARCHIVE );
		
		if ( com_developer && com_developer->integer ) {
			Cmd_AddCommand ("error", Com_Error_f);
			Cmd_AddCommand ("crash", Com_Crash_f );
			Cmd_AddCommand ("freeze", Com_Freeze_f);
		}
		
		s = va("%s %s %s", Q3_VERSION, PLATFORM_STRING, __DATE__ );
		com_version = Cvar_Get ("version", s, CVAR_ROM | CVAR_SERVERINFO );

#ifdef JK2_MODE
		JK2SP_Init();
		Com_Printf("Running Jedi Outcast Mode\n");
#else
		SE_Init();	// Initialize StringEd
		Com_Printf("Running Jedi Academy Mode\n");
#endif
	
		Sys_Init();	// this also detects CPU type, so I can now do this CPU check below...

		Sys_SetProcessorAffinity();

		Netchan_Init( Com_Milliseconds() & 0xffff );	// pick a port value that should be nice and random
//	VM_Init();
		SV_Init();
		
		CL_Init();
		
		// set com_frameTime so that if a map is started on the
		// command line it will still be able to count on com_frameTime
		// being random enough for a serverid
		com_frameTime = Com_Milliseconds();

		// add + commands from command line
		if ( !Com_AddStartupCommands() ) {
			// if the user didn't give any commands, run default action
			if ( com_bootlogo->integer )
			{
				Cbuf_AddText ("cinematic openinglogos\n");
			}
		}
		com_fullyInitialized = qtrue;
		Com_Printf ("--- Common Initialization Complete ---\n");

//HACKERY FOR THE DEUTSCH		
		//if ( (Cvar_VariableIntegerValue("ui_iscensored") == 1) 	//if this was on before, set it again so it gets its flags
		//	)
		//{
		//	Cvar_Get( "ui_iscensored",   "1", CVAR_ARCHIVE|CVAR_ROM|CVAR_INIT|CVAR_CHEAT|CVAR_NORESTART);
		//	Cvar_Set( "ui_iscensored",   "1");	//just in case it was archived
		//	// NOTE : I also create this in UI_Init()
		//	Cvar_Get( "g_dismemberment", "0", CVAR_ARCHIVE|CVAR_ROM|CVAR_INIT|CVAR_CHEAT);
		//	Cvar_Set( "g_dismemberment", "0");	//just in case it was archived
		//}
	}
	catch ( int code )
	{
		Com_CatchError (code);
		Sys_Error ("Error during initialization %s", Com_ErrorString (code));
	}
}
void *Z_Malloc(int iSize, memtag_t eTag, qboolean bZeroit, int iAlign)
{
//	assert(s_Initialized);
	// Zone now initializes on first use. (During static constructors)
	if (!s_Initialized)
		Com_InitZoneMemory();
	
	if (iSize == 0)
	{
#ifdef _DEBUG
		return (void*)(&s_EmptyBlock.start + 1);
#else
		return (void*)(&s_EmptyBlock.header + 1);
#endif
	}

	if (iSize < 0)
	{
		Z_MallocFail("Negative size", iSize, eTag);
		return NULL;
	}

#ifndef _GAMECUBE
	WaitForSingleObject(s_Mutex, INFINITE);
#endif
	
	// Make new/delete memory temporary if requested
	if (eTag == TAG_NEWDEL && s_IsNewDeleteTemp)
	{
		eTag = TAG_TEMP_WORKSPACE;
	}

	// Determine how much space we need with headers and footers
	int header_size = sizeof(ZoneHeader);
	int footer_size = 0;
	if (Z_IsTagLinked(eTag))
	{
		header_size += sizeof(ZoneLinkHeader);
	}
#ifdef _DEBUG
	header_size += sizeof(ZoneDebugHeader);
	footer_size += sizeof(ZoneDebugFooter);
#endif
	int real_size = iSize + header_size + footer_size;
	int align_pad = 0;

	// Get a bit of free memory.  Temporary memory is allocated
	// from the end.  More permanent allocations are done at the
	// begining of the pool.
	ZoneFreeBlock* fblock;
	if (Z_IsTagTemp(eTag))
	{
		fblock = Z_FindLastFree(real_size, header_size, footer_size, 
			iAlign, align_pad);
	}
	else
	{
		fblock = Z_FindFirstFree(real_size, header_size, footer_size, 
			iAlign, align_pad);
	}

	// Did we actually find some memory?
	if (!fblock)
	{
#ifndef _GAMECUBE
		ReleaseMutex(s_Mutex);
#endif
//		if(eTag == TAG_TEMP_SND_RAWDATA) {
		if(eTag == TAG_SND_RAWDATA) {
			return NULL;
		}

		Z_MallocFail("Out of memory", iSize, eTag);
		return NULL;
	}

	// Add any alignment bytes
	real_size += align_pad;

	// Split the free block and get a pointer to the start
	// allocated space.
	void* ablock;
	if (Z_IsTagTemp(eTag))
	{
		ablock = Z_SplitFree(fblock, real_size, false);
		
		// Append align pad to end of block
		Z_SetupAlignmentPad(
			(void*)((char*)ablock + real_size - align_pad), 
			align_pad, false);
	}
	else
	{
		ablock = Z_SplitFree(fblock, real_size, true);

		// Insert align pad at block start
		Z_SetupAlignmentPad(ablock, align_pad, true);
		ablock = (void*)((char*)ablock + align_pad);
	}

	if (!ablock)
	{
		Z_MallocFail("Failed to split", iSize, eTag);
	}

	// Add linking header if necessary
	if (Z_IsTagLinked(eTag))
	{
		ZoneLinkHeader* linked = (ZoneLinkHeader*)ablock;
		linked->m_Next = s_LinkBase;
		linked->m_Prev = NULL;
		if (s_LinkBase)
		{
			s_LinkBase->m_Prev = linked;
		}
		s_LinkBase = linked;

		assert(Z_ValidateLinks());

		// Next...
		ablock = (void*)((char*)ablock + sizeof(ZoneLinkHeader));
	}

	// Setup the header:
	//		31		- alignment flag
	//		25-30	- tag
	//		0-24	- size without headers/footers
	assert(iSize >= 0 && iSize < (1 << 25));
	assert(eTag >= 0 && eTag < 64);
	ZoneHeader* header = (ZoneHeader*)ablock;
	*header = 
		(((unsigned int)eTag) << 25) |
		((unsigned int)iSize);

	if (align_pad)
	{
		*header |= (1 << 31);
	}

	// Next...
	ablock = (void*)((char*)ablock + sizeof(ZoneHeader));

#ifdef _DEBUG
	{
		// Setup the debug markers
		ZoneDebugHeader* debug_header = (ZoneDebugHeader*)ablock;

		ZoneDebugFooter* debug_footer = (ZoneDebugFooter*)((char*)debug_header + 
			(sizeof(ZoneDebugHeader) + iSize));

		*debug_header = ZONE_MAGIC;
		*debug_footer = ZONE_MAGIC;

		// Next...
		ablock = (void*)((char*)ablock + sizeof(ZoneDebugHeader));
	}
#endif

	// Update the stats
	s_Stats.m_SizeAlloc += iSize;
	s_Stats.m_OverheadAlloc += header_size + footer_size + align_pad;
	s_Stats.m_SizesPerTag[eTag] += iSize;
	s_Stats.m_CountAlloc++;
	s_Stats.m_CountsPerTag[eTag]++;

	if (s_Stats.m_SizeAlloc + s_Stats.m_OverheadAlloc > s_Stats.m_PeakAlloc)
	{
		s_Stats.m_PeakAlloc = s_Stats.m_SizeAlloc + s_Stats.m_OverheadAlloc;
	}

	// Return a pointer to data memory
	if (bZeroit)
	{
		memset(ablock, 0, iSize);
	}

	assert(iAlign == 0 || (unsigned int)ablock % iAlign == 0);

	/*
	   This is useful for figuring out who's allocating a certain block of
	   memory.  Please don't remove it.
	if(eTag == TAG_NEWDEL && (unsigned int)ablock >= 0x806c0000 && 
			(unsigned int)ablock <= 0x806c1000 && iSize == 24) {
		int suck = 0;
	}
	if(eTag == TAG_SMALL && (iSize == 7 || iSize == 96)) {
		int suck = 0;
	}
	if(eTag == TAG_CLIENTS) {
		int suck = 0;
	}
	
	if ((unsigned)ablock >= 0x1eb0000 && (unsigned)ablock <= 0x1ec0000 && iSize == 48)
	{
		int suck = 0;
	}
	*/

#ifndef _GAMECUBE
	ReleaseMutex(s_Mutex);
#endif

	return ablock;
}