Exemplo n.º 1
0
static char *Cvar_BitInfo( int bit )
{
	static char info[MAX_INFO_STRING];
	struct trie_dump_s *dump;
	unsigned int i;

	info[0] = 0;

	assert( cvar_trie );
	Trie_DumpIf( cvar_trie, "", TRIE_DUMP_VALUES, Cvar_HasFlags, &bit, &dump );

	// make sure versioncvar comes first
	for( i = dump->size; i > 0; --i )
	{
		cvar_t *const var = dump->key_value_vector[i-1].value;
		if( var == versioncvar )
		{
			Info_SetValueForKey( info, var->name, var->string );
			break;
		}
	}

	// dump other cvars
	for( i = 0; i < dump->size; ++i )
	{
		cvar_t *const var = dump->key_value_vector[i].value;
		if( var != versioncvar )
			Info_SetValueForKey( info, var->name, var->string );
	}

	Trie_FreeDump( dump );

	return info;
}
Exemplo n.º 2
0
/*
* Cvar_WriteVariables
* 
* Appends lines containing "set variable value" for all variables
* with the archive flag set to true.
*/
void Cvar_WriteVariables( int file )
{
	char buffer[MAX_PRINTMSG];
	struct trie_dump_s *dump;
	unsigned int i;
	cvar_flag_t cvar_archive = CVAR_ARCHIVE;

	assert( cvar_trie );
	Trie_DumpIf( cvar_trie, "", TRIE_DUMP_VALUES, Cvar_HasFlags, &cvar_archive, &dump );
	for( i = 0; i < dump->size; ++i )
	{
		cvar_t *const var = dump->key_value_vector[i].value;
		const char *cmd;

		if( Cvar_FlagIsSet( var->flags, CVAR_USERINFO ) )
			cmd = "setau";
		else if( Cvar_FlagIsSet( var->flags, CVAR_SERVERINFO ) )
			cmd = "setas";
		else
			cmd = "seta";

		if( Cvar_FlagIsSet( var->flags, CVAR_LATCH ) || Cvar_FlagIsSet( var->flags, CVAR_LATCH_VIDEO ) ||
			Cvar_FlagIsSet( var->flags, CVAR_LATCH_SOUND ) )
		{
			if( var->latched_string )
				Q_snprintfz( buffer, sizeof( buffer ), "%s %s \"%s\"\r\n", cmd, var->name, var->latched_string );
			else
				Q_snprintfz( buffer, sizeof( buffer ), "%s %s \"%s\"\r\n", cmd, var->name, var->string );
		}
		else
			Q_snprintfz( buffer, sizeof( buffer ), "%s %s \"%s\"\r\n", cmd, var->name, var->string );
		FS_Printf( file, "%s", buffer );
	}
	Trie_FreeDump( dump );
}
Exemplo n.º 3
0
/*
* Cvar_GetLatchedVars
* 
* Any variables with CVAR_LATCHED will now be updated
*/
void Cvar_GetLatchedVars( cvar_flag_t flags )
{
	unsigned int i;
	struct trie_dump_s *dump;
	cvar_flag_t latchFlags;

	Cvar_FlagsClear( &latchFlags );
	Cvar_FlagSet( &latchFlags, CVAR_LATCH );
	Cvar_FlagSet( &latchFlags, CVAR_LATCH_VIDEO );
	Cvar_FlagSet( &latchFlags, CVAR_LATCH_SOUND );
	Cvar_FlagUnset( &flags, ~latchFlags );
	if( !flags )
		return;

	assert( cvar_trie );
	Trie_DumpIf( cvar_trie, "", TRIE_DUMP_VALUES, Cvar_IsLatched, &flags, &dump );
	for( i = 0; i < dump->size; ++i )
	{
		cvar_t *const var = (cvar_t *) dump->key_value_vector[i].value;
		if( !strcmp( var->name, "fs_game" ) )
		{
			FS_SetGameDirectory( var->latched_string, qfalse );
			return;
		}
		Mem_ZoneFree( var->string );
		var->string = var->latched_string;
		var->latched_string = NULL;
		var->value = atof( var->string );
		var->integer = Q_rint( var->value );
	}
	Trie_FreeDump( dump );
}
Exemplo n.º 4
0
void Dynvar_List_f( void )
{
	struct trie_dump_s *dump;
	unsigned int i, size;
	char *pattern;

	Trie_GetSize( dynvar_trie, &size );
	if( !size )
	{
		Com_Printf( "No dynvars\n" );
		return;
	}

	if( Cmd_Argc() == 1 )
		pattern = NULL; // no wildcard
	else
		pattern = Cmd_Args();

	Com_Printf( "\nDynvars:\n" );
	assert( dynvar_trie );
	Trie_DumpIf( dynvar_trie, "", TRIE_DUMP_VALUES, Dynvar_Console, pattern, &dump );
	for( i = 0; i < dump->size; ++i )
	{
		dynvar_t *const dynvar = (dynvar_t *) dump->key_value_vector[i].value;
		Com_Printf( "%s\n", Dynvar_GetName( dynvar ) );
	}
	Trie_FreeDump( dump );
	Com_Printf( "%i dynvars\n", i );
}
Exemplo n.º 5
0
void Dynvar_Shutdown( void )
{
	if( dynvar_initialized )
	{
		struct trie_dump_s *dump;
		unsigned int i;

		assert( dynvar_trie );

		Cmd_RemoveCommand( "dynvarlist" );
		Cmd_RemoveCommand( "setdyn" );

		Trie_Dump( dynvar_trie, "", TRIE_DUMP_VALUES, &dump );
		for( i = 0; i < dump->size; i++ )
		{
			Dynvar_Destroy( (dynvar_t *)dump->key_value_vector[i].value );
		}
		Trie_FreeDump( dump );

		dynvar_initialized = qfalse;
	}

	if( dynvar_preinitialized )
	{
		assert( dynvar_trie );

		Trie_Destroy( dynvar_trie );
		dynvar_trie = NULL;

		dynvar_preinitialized = qfalse;
	}
}
Exemplo n.º 6
0
/*
* Cvar_List_f
*/
static void Cvar_List_f( void )
{
	struct trie_dump_s *dump;
	unsigned int i;
	char *pattern;

	if( Cmd_Argc() == 1 )
		pattern = NULL;
	else
		pattern = Cmd_Args();

	assert( cvar_trie );
	Trie_DumpIf( cvar_trie, "", TRIE_DUMP_VALUES, Cvar_PatternMatches, pattern, &dump );

	Com_Printf( "\nConsole variables:\n" );
	for( i = 0; i < dump->size; ++i )
	{
		cvar_t *const var = dump->key_value_vector[i].value;
#ifdef PUBLIC_BUILD
		if( Cvar_FlagIsSet( var->flags, CVAR_DEVELOPER ) )
			continue;
#endif
		if( Cvar_FlagIsSet( var->flags, CVAR_ARCHIVE ) )
			Com_Printf( "*" );
		else
			Com_Printf( " " );
		if( Cvar_FlagIsSet( var->flags, CVAR_USERINFO ) )
			Com_Printf( "U" );
		else
			Com_Printf( " " );
		if( Cvar_FlagIsSet( var->flags, CVAR_SERVERINFO ) )
			Com_Printf( "S" );
		else
			Com_Printf( " " );
		if( Cvar_FlagIsSet( var->flags, CVAR_NOSET ) || Cvar_FlagIsSet( var->flags, CVAR_READONLY ) )
			Com_Printf( "-" );
		else if( Cvar_FlagIsSet( var->flags, CVAR_LATCH ) || Cvar_FlagIsSet( var->flags, CVAR_LATCH_VIDEO ) ||
			Cvar_FlagIsSet( var->flags, CVAR_LATCH_SOUND ) )
			Com_Printf( "L" );
		else
			Com_Printf( " " );
		if( Cvar_FlagIsSet( var->flags, CVAR_CHEAT ) )
			Com_Printf( "C" );
		else
			Com_Printf( " " );
		Com_Printf( " %s \"%s%s\", default: \"%s%s\"\n", var->name, 
			var->string, Q_ColorStringTerminator( var->string, ColorIndex(COLOR_WHITE) ),
			var->dvalue, Q_ColorStringTerminator( var->dvalue, ColorIndex(COLOR_WHITE) ) );
	}
	Com_Printf( "%i variables\n", i );

	Trie_FreeDump( dump );
}
Exemplo n.º 7
0
/*
* ML_MapListCmd
* Handler for console command "maplist"
*/
static void ML_MapListCmd( void )
{
	char *pattern;
	mapinfo_t *map;
	int argc = Cmd_Argc();
	unsigned int i;
	struct trie_dump_s *dump = NULL;

	if( argc > 2 )
	{
		Com_Printf( "Usage: %s [rebuild]\n", Cmd_Argv(0) );
		return;
	}

	pattern = (argc == 2 ? Cmd_Argv( 1 ) : NULL);
	if( pattern && !*pattern )
		pattern = NULL;

	if( pattern )
	{
		if( !strcmp( pattern, "rebuild" ) )
		{
			Com_Printf( "Rebuilding map list...\n" );
			ML_Restart( true );
			return;
		}

		if( !strcmp( pattern, "update" ) )
		{
			Com_Printf( "Updating map list...\n" );
			ML_Update();
			return;
		}
	}

	Trie_DumpIf( mlist_filenames_trie, "", TRIE_DUMP_VALUES, ML_PatternMatchesMap, pattern, &dump );
	for( i = 0; i < dump->size; i++ )
	{
		map = ( mapinfo_t * )( dump->key_value_vector[i].value );
		Com_Printf( "%s: %s\n", map->filename, map->fullname );
	}
	Trie_FreeDump( dump );

	Com_Printf( "%d map(s) %s\n", i, pattern ? "matching" : "total" );
}
Exemplo n.º 8
0
/*
* ML_GetMapByNum
* Prints map infostring in "mapname\0fullname" format into "out" string,
* returns fullsize (so that out can be reallocated if there's not enough space)
*/
size_t ML_GetMapByNum( int num, char *out, size_t size )
{
	static int i = 0;
	static struct trie_dump_s *dump = NULL;
	size_t fsize;
	mapinfo_t *map;

	if( !ml_initialized )
		return 0;

	if( ml_flush || i > num )
	{
		if( dump )
		{
			Trie_FreeDump( dump );
			dump = NULL;
		}
		ml_flush = false;
	}

	if( !dump )
	{
		i = 0;
		Trie_Dump( mlist_filenames_trie, "", TRIE_DUMP_VALUES, &dump );
	}

	for( ; i < num && i < (int)dump->size; i++ )
		;
	if( i == (int)dump->size )
		return 0;

	map = ( mapinfo_t * )( dump->key_value_vector[i].value );
	fsize = strlen( map->filename ) + 1 + strlen( map->fullname ) + 1;
	if( out && (fsize <= size) )
	{
		Q_strncpyz( out, map->filename, size );
		Q_strncpyz( out + strlen( out ) + 1,
			strcmp( map->fullname, MLIST_UNKNOWN_MAPNAME ) ? map->fullname : map->filename, size - (strlen( out ) + 1) );
	}

	return fsize;
}
Exemplo n.º 9
0
/*
* Cvar_ArchiveList_f
*/
static void Cvar_ArchiveList_f( void )
{
	struct trie_dump_s *dump;
	unsigned int i;

	assert( cvar_trie );
	Trie_Dump( cvar_trie, "", TRIE_DUMP_VALUES, &dump );

	for( i = 0; i < dump->size; ++i )
	{
		cvar_t *const var = dump->key_value_vector[i].value;
		if( Cvar_FlagIsSet( var->flags, CVAR_DEVELOPER ) )
			continue;
		if( !Cvar_FlagIsSet( var->flags, CVAR_ARCHIVE ) )
			continue;
		Com_Printf( "set %s \"%s\"\n", var->name, var->dvalue );
	}

	Trie_FreeDump( dump );
}
Exemplo n.º 10
0
/*
* Cvar_FixCheatVars
* 
* All cheat variables with be reset to default unless cheats are allowed
*/
void Cvar_FixCheatVars( void )
{
	struct trie_dump_s *dump;
	unsigned int i;
	cvar_flag_t flags = CVAR_CHEAT;

	if( Cvar_CheatsAllowed() )
		return;

	assert( cvar_trie );
	Trie_DumpIf( cvar_trie, "", TRIE_DUMP_VALUES, Cvar_HasFlags, &flags, &dump );
	for( i = 0; i < dump->size; ++i )
	{
		cvar_t *const var = (cvar_t *) dump->key_value_vector[i].value;
		Mem_ZoneFree( var->string );
		var->string = ZoneCopyString( var->dvalue );
		var->value = atof( var->string );
		var->integer = Q_rint( var->value );
	}
	Trie_FreeDump( dump );
}
Exemplo n.º 11
0
/*
* ML_BuildCache
* Write the map data to a cache file
*/
static void ML_BuildCache( void )
{
	int filenum;
	mapinfo_t *map;
	struct trie_dump_s *dump;

	if( !ml_initialized )
		return;

	if( FS_FOpenFile( MLIST_CACHE, &filenum, FS_WRITE|FS_CACHE ) != -1 )
	{
		unsigned int i;

		Trie_Dump( mlist_filenames_trie, "", TRIE_DUMP_VALUES, &dump );
		for( i = 0; i < dump->size; ++i )
		{
			map = ( mapinfo_t * )( dump->key_value_vector[i].value );
			FS_Printf( filenum, "%s\r\n%s\r\n", map->filename, map->fullname );
		}
		Trie_FreeDump( dump );

		FS_FCloseFile( filenum );
	}
}
Exemplo n.º 12
0
/*
* Cvar_Shutdown
* 
* Reads in all archived cvars
*/
void Cvar_Shutdown( void )
{
	if( cvar_initialized )
	{
		unsigned int i;
		struct trie_dump_s *dump;
		extern cvar_t *developer, *developerMemory;
#ifndef DEDICATED_ONLY
		extern cvar_t *con_printText;
#endif

		assert( cvar_trie );

		// NULL out some console variables so that we won't try to read from
		// the memory pointers after the data has already been freed but before we
		// reset the pointers to NULL
		developer = NULL;
		developerMemory = NULL;
		dedicated = NULL;
#ifndef DEDICATED_ONLY
		con_printText = NULL;
#endif

		Cmd_RemoveCommand( "set" );
		Cmd_RemoveCommand( "seta" );
		Cmd_RemoveCommand( "setau" );
		Cmd_RemoveCommand( "setas" );
		Cmd_RemoveCommand( "setu" );
		Cmd_RemoveCommand( "sets" );
		Cmd_RemoveCommand( "reset" );
		Cmd_RemoveCommand( "toggle" );
		Cmd_RemoveCommand( "cvarlist" );
#ifndef PUBLIC_BUILD
		Cmd_RemoveCommand( "cvararchivelist" );
#endif

		Trie_Dump( cvar_trie, "", TRIE_DUMP_VALUES, &dump );
		for( i = 0; i < dump->size; ++i )
		{
			cvar_t *const var = dump->key_value_vector[i].value;

			if( var->string )
				Mem_ZoneFree( var->string );
			if( var->dvalue )
				Mem_ZoneFree( var->dvalue );
			Mem_ZoneFree( var );
		}
		Trie_FreeDump( dump );

		cvar_initialized = qfalse;
	}

	if( cvar_preinitialized )
	{
		assert( cvar_trie );

		Trie_Destroy( cvar_trie );
		cvar_trie = NULL;

		cvar_preinitialized = qfalse;
	}
}