doom3-bfg/neo/framework/Common.cpp

1926 lines
45 KiB
C++
Raw Normal View History

2012-11-26 18:58:24 +00:00
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
2012-12-06 23:09:53 +00:00
Copyright (C) 2012 Robert Beckebans
2012-11-26 18:58:24 +00:00
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
2012-11-26 18:58:24 +00:00
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "precompiled.h"
2012-11-26 18:58:24 +00:00
#pragma hdrstop
#include "Common_local.h"
#include "ConsoleHistory.h"
#include "../renderer/AutoRenderBink.h"
#include "../sound/sound.h"
2012-12-06 23:09:53 +00:00
// RB begin
#if defined(USE_DOOMCLASSIC)
2012-11-26 18:58:24 +00:00
#include "../../doomclassic/doom/doomlib.h"
#include "../../doomclassic/doom/d_event.h"
#include "../../doomclassic/doom/d_main.h"
2012-12-06 23:09:53 +00:00
#endif
// RB end
2012-11-26 18:58:24 +00:00
#include "../sys/sys_savegame.h"
#if defined( _DEBUG )
#define BUILD_DEBUG "-debug"
2012-11-26 18:58:24 +00:00
#else
#define BUILD_DEBUG ""
2012-11-26 18:58:24 +00:00
#endif
struct version_s
{
version_s()
{
sprintf( string, "%s.%d%s %s %s %s", ENGINE_VERSION, BUILD_NUMBER, BUILD_DEBUG, BUILD_STRING, __DATE__, __TIME__ );
}
2012-11-26 18:58:24 +00:00
char string[256];
} version;
idCVar com_version( "si_version", version.string, CVAR_SYSTEM | CVAR_ROM | CVAR_SERVERINFO, "engine version" );
2012-11-26 18:58:24 +00:00
idCVar com_forceGenericSIMD( "com_forceGenericSIMD", "0", CVAR_BOOL | CVAR_SYSTEM | CVAR_NOCHEAT, "force generic platform independent SIMD" );
#ifdef ID_RETAIL
idCVar com_allowConsole( "com_allowConsole", "0", CVAR_BOOL | CVAR_SYSTEM | CVAR_INIT, "allow toggling console with the tilde key" );
#else
idCVar com_allowConsole( "com_allowConsole", "1", CVAR_BOOL | CVAR_SYSTEM | CVAR_INIT, "allow toggling console with the tilde key" );
#endif
idCVar com_developer( "developer", "0", CVAR_BOOL | CVAR_SYSTEM | CVAR_NOCHEAT, "developer mode" );
idCVar com_speeds( "com_speeds", "0", CVAR_BOOL | CVAR_SYSTEM | CVAR_NOCHEAT, "show engine timings" );
idCVar com_showFPS( "com_showFPS", "0", CVAR_BOOL | CVAR_SYSTEM | CVAR_ARCHIVE | CVAR_NOCHEAT, "show frames rendered per second" );
idCVar com_showMemoryUsage( "com_showMemoryUsage", "0", CVAR_BOOL | CVAR_SYSTEM | CVAR_NOCHEAT, "show total and per frame memory usage" );
2012-11-26 18:58:24 +00:00
idCVar com_updateLoadSize( "com_updateLoadSize", "0", CVAR_BOOL | CVAR_SYSTEM | CVAR_NOCHEAT, "update the load size after loading a map" );
idCVar com_productionMode( "com_productionMode", "0", CVAR_SYSTEM | CVAR_BOOL, "0 - no special behavior, 1 - building a production build, 2 - running a production build" );
idCVar com_japaneseCensorship( "com_japaneseCensorship", "0", CVAR_NOCHEAT, "Enable Japanese censorship" );
idCVar preload_CommonAssets( "preload_CommonAssets", "1", CVAR_SYSTEM | CVAR_BOOL, "preload common assets" );
idCVar net_inviteOnly( "net_inviteOnly", "1", CVAR_BOOL | CVAR_ARCHIVE, "whether or not the private server you create allows friends to join or invite only" );
extern idCVar g_demoMode;
idCVar com_engineHz( "com_engineHz", "60", CVAR_FLOAT | CVAR_ARCHIVE, "Frames per second the engine runs at", 10.0f, 1024.0f );
float com_engineHz_latched = 60.0f; // Latched version of cvar, updated between map loads
int64 com_engineHz_numerator = 100LL * 1000LL;
int64 com_engineHz_denominator = 100LL * 60LL;
2012-12-06 23:09:53 +00:00
// RB begin
#if defined(_WIN32)
2012-11-26 18:58:24 +00:00
HWND com_hwndMsg = NULL;
2012-12-06 23:09:53 +00:00
#endif
// RB end
2012-11-26 18:58:24 +00:00
#ifdef __DOOM_DLL__
idGame* game = NULL;
idGameEdit* gameEdit = NULL;
2012-11-26 18:58:24 +00:00
#endif
idCommonLocal commonLocal;
idCommon* common = &commonLocal;
2012-11-26 18:58:24 +00:00
idCVar com_skipIntroVideos( "com_skipIntroVideos", "0", CVAR_BOOL , "skips intro videos" );
// For doom classic
struct Globals;
/*
==================
idCommonLocal::idCommonLocal
==================
*/
idCommonLocal::idCommonLocal() :
readSnapshotIndex( 0 ),
writeSnapshotIndex( 0 ),
optimalPCTBuffer( 0.5f ),
2012-11-26 18:58:24 +00:00
optimalTimeBuffered( 0.0f ),
optimalTimeBufferedWindow( 0.0f ),
lastPacifierSessionTime( 0 ),
lastPacifierGuiTime( 0 ),
lastPacifierDialogState( false ),
2012-12-06 23:23:27 +00:00
showShellRequested( false )
2012-12-06 23:09:53 +00:00
// RB begin
#if defined(USE_DOOMCLASSIC)
2012-12-06 23:23:27 +00:00
,
2012-11-26 18:58:24 +00:00
currentGame( DOOM3_BFG ),
idealCurrentGame( DOOM3_BFG ),
doomClassicMaterial( NULL )
2012-12-06 23:09:53 +00:00
#endif
2012-12-06 23:23:27 +00:00
// RB end
{
2012-11-26 18:58:24 +00:00
snapCurrent.localTime = -1;
snapPrevious.localTime = -1;
snapCurrent.serverTime = -1;
snapPrevious.serverTime = -1;
snapTimeBuffered = 0.0f;
effectiveSnapRate = 0.0f;
totalBufferedTime = 0;
totalRecvTime = 0;
2012-11-26 18:58:24 +00:00
com_fullyInitialized = false;
com_refreshOnPrint = false;
com_errorEntered = ERP_NONE;
com_shuttingDown = false;
com_isJapaneseSKU = false;
2012-11-26 18:58:24 +00:00
logFile = NULL;
2012-11-26 18:58:24 +00:00
strcpy( errorMessage, "" );
2012-11-26 18:58:24 +00:00
rd_buffer = NULL;
rd_buffersize = 0;
rd_flush = NULL;
2012-11-26 18:58:24 +00:00
gameDLL = 0;
2012-11-26 18:58:24 +00:00
loadGUI = NULL;
nextLoadTip = 0;
isHellMap = false;
wipeForced = false;
defaultLoadscreen = false;
2012-11-26 18:58:24 +00:00
menuSoundWorld = NULL;
2012-11-26 18:58:24 +00:00
insideUpdateScreen = false;
insideExecuteMapChange = false;
2012-11-26 18:58:24 +00:00
mapSpawnData.savegameFile = NULL;
2012-11-26 18:58:24 +00:00
currentMapName.Clear();
aviDemoShortName.Clear();
2012-11-26 18:58:24 +00:00
renderWorld = NULL;
soundWorld = NULL;
menuSoundWorld = NULL;
readDemo = NULL;
writeDemo = NULL;
2012-11-26 18:58:24 +00:00
gameFrame = 0;
gameTimeResidual = 0;
syncNextGameFrame = true;
mapSpawned = false;
aviCaptureMode = false;
timeDemo = TD_NO;
2012-11-26 18:58:24 +00:00
nextSnapshotSendTime = 0;
nextUsercmdSendTime = 0;
2012-11-26 18:58:24 +00:00
clientPrediction = 0;
2012-11-26 18:58:24 +00:00
saveFile = NULL;
stringsFile = NULL;
2012-11-26 18:58:24 +00:00
ClearWipe();
}
/*
==================
idCommonLocal::Quit
==================
*/
void idCommonLocal::Quit()
{
2012-11-26 18:58:24 +00:00
// don't try to shutdown if we are in a recursive error
if( !com_errorEntered )
{
2012-11-26 18:58:24 +00:00
Shutdown();
}
Sys_Quit();
}
/*
============================================================================
COMMAND LINE FUNCTIONS
+ characters separate the commandLine string into multiple console
command lines.
All of these are valid:
doom +set test blah +map test
doom set test blah+map test
doom set test blah + map test
============================================================================
*/
#define MAX_CONSOLE_LINES 32
int com_numConsoleLines;
idCmdArgs com_consoleLines[MAX_CONSOLE_LINES];
/*
==================
idCommonLocal::ParseCommandLine
==================
*/
void idCommonLocal::ParseCommandLine( int argc, const char* const* argv )
{
2012-11-26 18:58:24 +00:00
int i, current_count;
2012-11-26 18:58:24 +00:00
com_numConsoleLines = 0;
current_count = 0;
// API says no program path
for( i = 0; i < argc; i++ )
{
if( idStr::Icmp( argv[ i ], "+connect_lobby" ) == 0 )
{
2012-11-26 18:58:24 +00:00
// Handle Steam bootable invites.
2012-12-08 17:20:13 +00:00
2012-12-06 23:09:53 +00:00
// RB begin
#if defined(_WIN32)
2012-11-26 18:58:24 +00:00
session->HandleBootableInvite( _atoi64( argv[ i + 1 ] ) );
2012-12-06 23:09:53 +00:00
#else
session->HandleBootableInvite( atol( argv[ i + 1 ] ) );
#endif
// RB end
}
else if( argv[ i ][ 0 ] == '+' )
{
2012-11-26 18:58:24 +00:00
com_numConsoleLines++;
com_consoleLines[ com_numConsoleLines - 1 ].AppendArg( argv[ i ] + 1 );
}
else
{
if( !com_numConsoleLines )
{
2012-11-26 18:58:24 +00:00
com_numConsoleLines++;
}
com_consoleLines[ com_numConsoleLines - 1 ].AppendArg( argv[ i ] );
2012-11-26 18:58:24 +00:00
}
}
}
/*
==================
idCommonLocal::SafeMode
Check for "safe" on the command line, which will
skip loading of config file (DoomConfig.cfg)
==================
*/
bool idCommonLocal::SafeMode()
{
2012-11-26 18:58:24 +00:00
int i;
for( i = 0 ; i < com_numConsoleLines ; i++ )
{
if( !idStr::Icmp( com_consoleLines[ i ].Argv( 0 ), "safe" )
|| !idStr::Icmp( com_consoleLines[ i ].Argv( 0 ), "cvar_restart" ) )
{
2012-11-26 18:58:24 +00:00
com_consoleLines[ i ].Clear();
return true;
}
}
return false;
}
/*
==================
idCommonLocal::StartupVariable
Searches for command line parameters that are set commands.
If match is not NULL, only that cvar will be looked for.
That is necessary because cddir and basedir need to be set
before the filesystem is started, but all other sets should
be after execing the config and default.
==================
*/
void idCommonLocal::StartupVariable( const char* match )
{
2012-11-26 18:58:24 +00:00
int i = 0;
while( i < com_numConsoleLines )
{
if( strcmp( com_consoleLines[ i ].Argv( 0 ), "set" ) != 0 )
{
2012-11-26 18:58:24 +00:00
i++;
continue;
}
const char* s = com_consoleLines[ i ].Argv( 1 );
if( !match || !idStr::Icmp( s, match ) )
{
2012-11-26 18:58:24 +00:00
cvarSystem->SetCVarString( s, com_consoleLines[ i ].Argv( 2 ) );
}
i++;
}
}
/*
==================
idCommonLocal::AddStartupCommands
Adds command line parameters as script statements
Commands are separated by + signs
Returns true if any late commands were added, which
will keep the demoloop from immediately starting
==================
*/
void idCommonLocal::AddStartupCommands()
{
2012-11-26 18:58:24 +00:00
// quote every token, so args with semicolons can work
for( int i = 0; i < com_numConsoleLines; i++ )
{
if( !com_consoleLines[i].Argc() )
{
2012-11-26 18:58:24 +00:00
continue;
}
// directly as tokenized so nothing gets screwed
cmdSystem->BufferCommandArgs( CMD_EXEC_APPEND, com_consoleLines[i] );
}
}
/*
==================
idCommonLocal::WriteConfigToFile
==================
*/
void idCommonLocal::WriteConfigToFile( const char* filename )
{
idFile* f = fileSystem->OpenFileWrite( filename );
if( !f )
{
Printf( "Couldn't write %s.\n", filename );
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
idKeyInput::WriteBindings( f );
cvarSystem->WriteFlaggedVariables( CVAR_ARCHIVE, "set", f );
fileSystem->CloseFile( f );
}
/*
===============
idCommonLocal::WriteConfiguration
Writes key bindings and archived cvars to config file if modified
===============
*/
void idCommonLocal::WriteConfiguration()
{
2012-11-26 18:58:24 +00:00
// if we are quiting without fully initializing, make sure
// we don't write out anything
if( !com_fullyInitialized )
{
2012-11-26 18:58:24 +00:00
return;
}
if( !( cvarSystem->GetModifiedFlags() & CVAR_ARCHIVE ) )
{
2012-11-26 18:58:24 +00:00
return;
}
cvarSystem->ClearModifiedFlags( CVAR_ARCHIVE );
2012-11-26 18:58:24 +00:00
// save to the profile
idLocalUser* user = session->GetSignInManager().GetMasterLocalUser();
if( user != NULL )
{
2012-11-26 18:58:24 +00:00
user->SaveProfileSettings();
}
2012-11-26 18:58:24 +00:00
#ifdef CONFIG_FILE
// disable printing out the "Writing to:" message
bool developer = com_developer.GetBool();
com_developer.SetBool( false );
2012-11-26 18:58:24 +00:00
WriteConfigToFile( CONFIG_FILE );
2012-11-26 18:58:24 +00:00
// restore the developer cvar
com_developer.SetBool( developer );
#endif
}
/*
===============
KeysFromBinding()
Returns the key bound to the command
===============
*/
const char* idCommonLocal::KeysFromBinding( const char* bind )
{
2012-11-26 18:58:24 +00:00
return idKeyInput::KeysFromBinding( bind );
}
/*
===============
BindingFromKey()
Returns the binding bound to key
===============
*/
const char* idCommonLocal::BindingFromKey( const char* key )
{
2012-11-26 18:58:24 +00:00
return idKeyInput::BindingFromKey( key );
}
/*
===============
ButtonState()
Returns the state of the button
===============
*/
int idCommonLocal::ButtonState( int key )
{
return usercmdGen->ButtonState( key );
2012-11-26 18:58:24 +00:00
}
/*
===============
ButtonState()
Returns the state of the key
===============
*/
int idCommonLocal::KeyState( int key )
{
return usercmdGen->KeyState( key );
2012-11-26 18:58:24 +00:00
}
/*
============
idCmdSystemLocal::PrintMemInfo_f
This prints out memory debugging data
============
*/
CONSOLE_COMMAND( printMemInfo, "prints memory debugging data", NULL )
{
2012-11-26 18:58:24 +00:00
MemInfo_t mi;
memset( &mi, 0, sizeof( mi ) );
mi.filebase = commonLocal.GetCurrentMapName();
2012-11-26 18:58:24 +00:00
renderSystem->PrintMemInfo( &mi ); // textures and models
soundSystem->PrintMemInfo( &mi ); // sounds
2012-11-26 18:58:24 +00:00
common->Printf( " Used image memory: %s bytes\n", idStr::FormatNumber( mi.imageAssetsTotal ).c_str() );
mi.assetTotals += mi.imageAssetsTotal;
2012-11-26 18:58:24 +00:00
common->Printf( " Used model memory: %s bytes\n", idStr::FormatNumber( mi.modelAssetsTotal ).c_str() );
mi.assetTotals += mi.modelAssetsTotal;
2012-11-26 18:58:24 +00:00
common->Printf( " Used sound memory: %s bytes\n", idStr::FormatNumber( mi.soundAssetsTotal ).c_str() );
mi.assetTotals += mi.soundAssetsTotal;
2012-11-26 18:58:24 +00:00
common->Printf( " Used asset memory: %s bytes\n", idStr::FormatNumber( mi.assetTotals ).c_str() );
2012-11-26 18:58:24 +00:00
// write overview file
idFile* f;
2012-11-26 18:58:24 +00:00
f = fileSystem->OpenFileAppend( "maps/printmeminfo.txt" );
if( !f )
{
2012-11-26 18:58:24 +00:00
return;
}
f->Printf( "total(%s ) image(%s ) model(%s ) sound(%s ): %s\n", idStr::FormatNumber( mi.assetTotals ).c_str(), idStr::FormatNumber( mi.imageAssetsTotal ).c_str(),
idStr::FormatNumber( mi.modelAssetsTotal ).c_str(), idStr::FormatNumber( mi.soundAssetsTotal ).c_str(), mi.filebase.c_str() );
2012-11-26 18:58:24 +00:00
fileSystem->CloseFile( f );
}
/*
==================
Com_Error_f
Just throw a fatal error to test error shutdown procedures.
==================
*/
CONSOLE_COMMAND( error, "causes an error", NULL )
{
if( !com_developer.GetBool() )
{
2012-11-26 18:58:24 +00:00
commonLocal.Printf( "error may only be used in developer mode\n" );
return;
}
if( args.Argc() > 1 )
{
2012-11-26 18:58:24 +00:00
commonLocal.FatalError( "Testing fatal error" );
}
else
{
2012-11-26 18:58:24 +00:00
commonLocal.Error( "Testing drop error" );
}
}
/*
==================
Com_Freeze_f
Just freeze in place for a given number of seconds to test error recovery.
==================
*/
CONSOLE_COMMAND( freeze, "freezes the game for a number of seconds", NULL )
{
2012-11-26 18:58:24 +00:00
float s;
int start, now;
if( args.Argc() != 2 )
{
2012-11-26 18:58:24 +00:00
commonLocal.Printf( "freeze <seconds>\n" );
return;
}
if( !com_developer.GetBool() )
{
2012-11-26 18:58:24 +00:00
commonLocal.Printf( "freeze may only be used in developer mode\n" );
return;
}
s = atof( args.Argv( 1 ) );
2012-11-26 18:58:24 +00:00
start = eventLoop->Milliseconds();
while( 1 )
{
2012-11-26 18:58:24 +00:00
now = eventLoop->Milliseconds();
if( ( now - start ) * 0.001f > s )
{
2012-11-26 18:58:24 +00:00
break;
}
}
}
/*
=================
Com_Crash_f
A way to force a bus error for development reasons
=================
*/
CONSOLE_COMMAND( crash, "causes a crash", NULL )
{
if( !com_developer.GetBool() )
{
2012-11-26 18:58:24 +00:00
commonLocal.Printf( "crash may only be used in developer mode\n" );
return;
}
2012-12-22 05:15:50 +00:00
#ifdef __GNUC__
__builtin_trap();
#else
* ( int* ) 0 = 0x12345678;
2012-12-22 05:15:50 +00:00
#endif
2012-11-26 18:58:24 +00:00
}
/*
=================
Com_Quit_f
=================
*/
CONSOLE_COMMAND_SHIP( quit, "quits the game", NULL )
{
2012-11-26 18:58:24 +00:00
commonLocal.Quit();
}
CONSOLE_COMMAND_SHIP( exit, "exits the game", NULL )
{
2012-11-26 18:58:24 +00:00
commonLocal.Quit();
}
/*
===============
Com_WriteConfig_f
Write the config file to a specific name
===============
*/
CONSOLE_COMMAND( writeConfig, "writes a config file", NULL )
{
2012-11-26 18:58:24 +00:00
idStr filename;
if( args.Argc() != 2 )
{
2012-11-26 18:58:24 +00:00
commonLocal.Printf( "Usage: writeconfig <filename>\n" );
return;
}
filename = args.Argv( 1 );
2012-11-26 18:58:24 +00:00
filename.DefaultFileExtension( ".cfg" );
commonLocal.Printf( "Writing %s.\n", filename.c_str() );
commonLocal.WriteConfigToFile( filename );
}
/*
========================
idCommonLocal::CheckStartupStorageRequirements
========================
*/
void idCommonLocal::CheckStartupStorageRequirements()
{
// RB: disabled savegame and profile storage checks, because it fails sometimes without any clear reason
#if 0
2012-11-26 18:58:24 +00:00
int64 availableSpace = 0;
2012-11-26 18:58:24 +00:00
// ------------------------------------------------------------------------
// Savegame and Profile required storage
// ------------------------------------------------------------------------
{
// Make sure the save path exists in case it was deleted.
// If the path cannot be created we can safely assume there is no
// free space because in that case nothing can be saved anyway.
const char* savepath = cvarSystem->GetCVarString( "fs_savepath" );
2012-11-26 18:58:24 +00:00
idStr directory = savepath;
//idStr directory = fs_savepath.GetString();
directory += "\\"; // so it doesn't think the last part is a file and ignores in the directory creation
fileSystem->CreateOSPath( directory );
2012-11-26 18:58:24 +00:00
// Get the free space on the save path.
availableSpace = Sys_GetDriveFreeSpaceInBytes( savepath );
2012-11-26 18:58:24 +00:00
// If free space fails then get space on drive as a fall back
// (the directory will be created later anyway)
if( availableSpace <= 1 )
{
2012-11-26 18:58:24 +00:00
idStr savePath( savepath );
if( savePath.Length() >= 3 )
{
if( savePath[ 1 ] == ':' && savePath[ 2 ] == '\\' &&
( ( savePath[ 0 ] >= 'A' && savePath[ 0 ] <= 'Z' ) ||
( savePath[ 0 ] >= 'a' && savePath[ 0 ] <= 'z' ) ) )
{
savePath = savePath.Left( 3 );
availableSpace = Sys_GetDriveFreeSpaceInBytes( savePath );
2012-11-26 18:58:24 +00:00
}
}
}
}
2012-11-26 18:58:24 +00:00
const int MIN_SAVE_STORAGE_PROFILE = 1024 * 1024;
const int MIN_SAVE_STORAGE_SAVEGAME = MIN_SAVEGAME_SIZE_BYTES;
2012-11-26 18:58:24 +00:00
uint64 requiredSizeBytes = MIN_SAVE_STORAGE_SAVEGAME + MIN_SAVE_STORAGE_PROFILE;
2012-11-26 18:58:24 +00:00
idLib::Printf( "requiredSizeBytes: %lld\n", requiredSizeBytes );
if( ( int64 )( requiredSizeBytes - availableSpace ) > 0 )
{
class idSWFScriptFunction_Continue : public idSWFScriptFunction_RefCounted
{
2012-11-26 18:58:24 +00:00
public:
virtual ~idSWFScriptFunction_Continue() {}
idSWFScriptVar Call( idSWFScriptObject* thisObject, const idSWFParmList& parms )
{
2012-11-26 18:58:24 +00:00
common->Dialog().ClearDialog( GDM_INSUFFICENT_STORAGE_SPACE );
common->Quit();
return idSWFScriptVar();
}
};
idStaticList< idSWFScriptFunction*, 4 > callbacks;
2012-11-26 18:58:24 +00:00
idStaticList< idStrId, 4 > optionText;
callbacks.Append( new( TAG_SWF ) idSWFScriptFunction_Continue() );
2012-11-26 18:58:24 +00:00
optionText.Append( idStrId( "#STR_SWF_ACCEPT" ) );
2012-11-26 18:58:24 +00:00
// build custom space required string
// #str_dlg_space_required ~= "There is insufficient storage available. Please free %s and try again."
idStr format = idStrId( "#str_dlg_startup_insufficient_storage" ).GetLocalizedString();
idStr size;
if( requiredSizeBytes > ( 1024 * 1024 ) )
{
size = va( "%.1f MB", ( float )requiredSizeBytes / ( 1024.0f * 1024.0f ) + 0.1f ); // +0.1 to avoid truncation
}
else
{
size = va( "%.1f KB", ( float )requiredSizeBytes / 1024.0f + 0.1f );
2012-11-26 18:58:24 +00:00
}
idStr msg = va( format.c_str(), size.c_str() );
2012-11-26 18:58:24 +00:00
common->Dialog().AddDynamicDialog( GDM_INSUFFICENT_STORAGE_SPACE, callbacks, optionText, true, msg );
}
#endif
// RB end
2012-11-26 18:58:24 +00:00
session->GetAchievementSystem().Start();
}
/*
===============
idCommonLocal::JapaneseCensorship
===============
*/
bool idCommonLocal::JapaneseCensorship() const
{
2012-11-26 18:58:24 +00:00
return com_japaneseCensorship.GetBool() || com_isJapaneseSKU;
}
/*
===============
idCommonLocal::FilterLangList
===============
*/
void idCommonLocal::FilterLangList( idStrList* list, idStr lang )
{
2012-11-26 18:58:24 +00:00
idStr temp;
for( int i = 0; i < list->Num(); i++ )
{
temp = ( *list )[i];
temp = temp.Right( temp.Length() - strlen( "strings/" ) );
temp = temp.Left( lang.Length() );
if( idStr::Icmp( temp, lang ) != 0 )
{
list->RemoveIndex( i );
2012-11-26 18:58:24 +00:00
i--;
}
}
}
/*
===============
idCommonLocal::InitLanguageDict
===============
*/
extern idCVar sys_lang;
void idCommonLocal::InitLanguageDict()
{
2012-11-26 18:58:24 +00:00
idStr fileName;
2012-11-26 18:58:24 +00:00
//D3XP: Instead of just loading a single lang file for each language
//we are going to load all files that begin with the language name
//similar to the way pak files work. So you can place english001.lang
//to add new strings to the english language dictionary
idFileList* langFiles;
langFiles = fileSystem->ListFilesTree( "strings", ".lang", true );
idStrList langList = langFiles->GetList();
2012-11-26 18:58:24 +00:00
// Loop through the list and filter
idStrList currentLangList = langList;
FilterLangList( &currentLangList, sys_lang.GetString() );
if( currentLangList.Num() == 0 )
{
2012-11-26 18:58:24 +00:00
// reset to english and try to load again
sys_lang.SetString( ID_LANG_ENGLISH );
currentLangList = langList;
FilterLangList( &currentLangList, sys_lang.GetString() );
}
2012-11-26 18:58:24 +00:00
idLocalization::ClearDictionary();
for( int i = 0; i < currentLangList.Num(); i++ )
{
2012-11-26 18:58:24 +00:00
//common->Printf("%s\n", currentLangList[i].c_str());
const byte* buffer = NULL;
int len = fileSystem->ReadFile( currentLangList[i], ( void** )&buffer );
if( len <= 0 )
{
2012-11-26 18:58:24 +00:00
assert( false && "couldn't read the language dict file" );
break;
}
idLocalization::LoadDictionary( buffer, len, currentLangList[i] );
fileSystem->FreeFile( ( void* )buffer );
2012-11-26 18:58:24 +00:00
}
fileSystem->FreeFileList( langFiles );
2012-11-26 18:58:24 +00:00
}
/*
=================
ReloadLanguage_f
=================
*/
CONSOLE_COMMAND( reloadLanguage, "reload language dict", NULL )
{
2012-11-26 18:58:24 +00:00
commonLocal.InitLanguageDict();
}
#include "../renderer/Image.h"
/*
=================
Com_StartBuild_f
=================
*/
CONSOLE_COMMAND( startBuild, "prepares to make a build", NULL )
{
2012-11-26 18:58:24 +00:00
globalImages->StartBuild();
}
/*
=================
Com_FinishBuild_f
=================
*/
CONSOLE_COMMAND( finishBuild, "finishes the build process", NULL )
{
if( game )
{
2012-11-26 18:58:24 +00:00
game->CacheDictionaryMedia( NULL );
}
globalImages->FinishBuild( ( args.Argc() > 1 ) );
}
/*
=================
idCommonLocal::RenderSplash
=================
*/
void idCommonLocal::RenderSplash()
{
2012-11-26 18:58:24 +00:00
const float sysWidth = renderSystem->GetWidth() * renderSystem->GetPixelAspect();
const float sysHeight = renderSystem->GetHeight();
const float sysAspect = sysWidth / sysHeight;
const float splashAspect = 16.0f / 9.0f;
const float adjustment = sysAspect / splashAspect;
const float barHeight = ( adjustment >= 1.0f ) ? 0.0f : ( 1.0f - adjustment ) * ( float )SCREEN_HEIGHT * 0.25f;
const float barWidth = ( adjustment <= 1.0f ) ? 0.0f : ( adjustment - 1.0f ) * ( float )SCREEN_WIDTH * 0.25f;
if( barHeight > 0.0f )
{
2012-11-26 18:58:24 +00:00
renderSystem->SetColor( colorBlack );
renderSystem->DrawStretchPic( 0, 0, SCREEN_WIDTH, barHeight, 0, 0, 1, 1, whiteMaterial );
renderSystem->DrawStretchPic( 0, SCREEN_HEIGHT - barHeight, SCREEN_WIDTH, barHeight, 0, 0, 1, 1, whiteMaterial );
}
if( barWidth > 0.0f )
{
2012-11-26 18:58:24 +00:00
renderSystem->SetColor( colorBlack );
renderSystem->DrawStretchPic( 0, 0, barWidth, SCREEN_HEIGHT, 0, 0, 1, 1, whiteMaterial );
renderSystem->DrawStretchPic( SCREEN_WIDTH - barWidth, 0, barWidth, SCREEN_HEIGHT, 0, 0, 1, 1, whiteMaterial );
}
renderSystem->SetColor4( 1, 1, 1, 1 );
renderSystem->DrawStretchPic( barWidth, barHeight, SCREEN_WIDTH - barWidth * 2.0f, SCREEN_HEIGHT - barHeight * 2.0f, 0, 0, 1, 1, splashScreen );
const emptyCommand_t* cmd = renderSystem->SwapCommandBuffers( &time_frontend, &time_backend, &time_shadows, &time_gpu );
2012-11-26 18:58:24 +00:00
renderSystem->RenderCommandBuffers( cmd );
}
/*
=================
idCommonLocal::RenderBink
=================
*/
void idCommonLocal::RenderBink( const char* path )
{
2012-11-26 18:58:24 +00:00
const float sysWidth = renderSystem->GetWidth() * renderSystem->GetPixelAspect();
const float sysHeight = renderSystem->GetHeight();
const float sysAspect = sysWidth / sysHeight;
const float movieAspect = ( 16.0f / 9.0f );
const float imageWidth = SCREEN_WIDTH * movieAspect / sysAspect;
const float chop = 0.5f * ( SCREEN_WIDTH - imageWidth );
2012-11-26 18:58:24 +00:00
idStr materialText;
materialText.Format( "{ translucent { videoMap %s } }", path );
idMaterial* material = const_cast<idMaterial*>( declManager->FindMaterial( "splashbink" ) );
2012-11-26 18:58:24 +00:00
material->Parse( materialText.c_str(), materialText.Length(), false );
material->ResetCinematicTime( Sys_Milliseconds() );
while( Sys_Milliseconds() <= material->GetCinematicStartTime() + material->CinematicLength() )
{
2012-11-26 18:58:24 +00:00
renderSystem->DrawStretchPic( chop, 0, imageWidth, SCREEN_HEIGHT, 0, 0, 1, 1, material );
const emptyCommand_t* cmd = renderSystem->SwapCommandBuffers( &time_frontend, &time_backend, &time_shadows, &time_gpu );
2012-11-26 18:58:24 +00:00
renderSystem->RenderCommandBuffers( cmd );
Sys_GenerateEvents();
Sys_Sleep( 10 );
}
2012-11-26 18:58:24 +00:00
material->MakeDefault();
}
/*
=================
idCommonLocal::InitSIMD
=================
*/
void idCommonLocal::InitSIMD()
{
2012-11-26 18:58:24 +00:00
idSIMD::InitProcessor( "doom", com_forceGenericSIMD.GetBool() );
com_forceGenericSIMD.ClearModified();
}
/*
=================
idCommonLocal::LoadGameDLL
=================
*/
void idCommonLocal::LoadGameDLL()
{
2012-11-26 18:58:24 +00:00
#ifdef __DOOM_DLL__
char dllPath[ MAX_OSPATH ];
2012-11-26 18:58:24 +00:00
gameImport_t gameImport;
gameExport_t gameExport;
GetGameAPI_t GetGameAPI;
2012-11-26 18:58:24 +00:00
fileSystem->FindDLL( "game", dllPath, true );
if( !dllPath[ 0 ] )
{
2012-11-26 18:58:24 +00:00
common->FatalError( "couldn't find game dynamic library" );
return;
}
common->DPrintf( "Loading game DLL: '%s'\n", dllPath );
gameDLL = sys->DLL_Load( dllPath );
if( !gameDLL )
{
2012-11-26 18:58:24 +00:00
common->FatalError( "couldn't load game dynamic library" );
return;
}
const char* functionName = "GetGameAPI";
GetGameAPI = ( GetGameAPI_t ) Sys_DLL_GetProcAddress( gameDLL, functionName );
if( !GetGameAPI )
{
2012-11-26 18:58:24 +00:00
Sys_DLL_Unload( gameDLL );
gameDLL = NULL;
common->FatalError( "couldn't find game DLL API" );
return;
}
2012-11-26 18:58:24 +00:00
gameImport.version = GAME_API_VERSION;
gameImport.sys = ::sys;
gameImport.common = ::common;
gameImport.cmdSystem = ::cmdSystem;
gameImport.cvarSystem = ::cvarSystem;
gameImport.fileSystem = ::fileSystem;
gameImport.renderSystem = ::renderSystem;
gameImport.soundSystem = ::soundSystem;
gameImport.renderModelManager = ::renderModelManager;
gameImport.uiManager = ::uiManager;
gameImport.declManager = ::declManager;
gameImport.AASFileManager = ::AASFileManager;
gameImport.collisionModelManager = ::collisionModelManager;
2012-11-26 18:58:24 +00:00
gameExport = *GetGameAPI( &gameImport );
if( gameExport.version != GAME_API_VERSION )
{
2012-11-26 18:58:24 +00:00
Sys_DLL_Unload( gameDLL );
gameDLL = NULL;
common->FatalError( "wrong game DLL API version" );
return;
}
2012-11-26 18:58:24 +00:00
game = gameExport.game;
gameEdit = gameExport.gameEdit;
2012-11-26 18:58:24 +00:00
#endif
2012-11-26 18:58:24 +00:00
// initialize the game object
if( game != NULL )
{
2012-11-26 18:58:24 +00:00
game->Init();
}
}
/*
=================
idCommonLocal::UnloadGameDLL
=================
*/
void idCommonLocal::CleanupShell()
{
if( game != NULL )
{
2012-11-26 18:58:24 +00:00
game->Shell_Cleanup();
}
}
/*
=================
idCommonLocal::UnloadGameDLL
=================
*/
void idCommonLocal::UnloadGameDLL()
{
2012-11-26 18:58:24 +00:00
// shut down the game object
if( game != NULL )
{
2012-11-26 18:58:24 +00:00
game->Shutdown();
}
2012-11-26 18:58:24 +00:00
#ifdef __DOOM_DLL__
if( gameDLL )
{
2012-11-26 18:58:24 +00:00
Sys_DLL_Unload( gameDLL );
gameDLL = NULL;
}
game = NULL;
gameEdit = NULL;
2012-11-26 18:58:24 +00:00
#endif
}
/*
=================
idCommonLocal::IsInitialized
=================
*/
bool idCommonLocal::IsInitialized() const
{
2012-11-26 18:58:24 +00:00
return com_fullyInitialized;
}
//======================================================================================
/*
=================
idCommonLocal::Init
=================
*/
void idCommonLocal::Init( int argc, const char* const* argv, const char* cmdline )
{
try
{
2012-11-26 18:58:24 +00:00
// set interface pointers used by idLib
idLib::sys = sys;
idLib::common = common;
idLib::cvarSystem = cvarSystem;
idLib::fileSystem = fileSystem;
2012-11-26 18:58:24 +00:00
// initialize idLib
idLib::Init();
2012-11-26 18:58:24 +00:00
// clear warning buffer
ClearWarnings( GAME_NAME " initialization" );
2012-11-26 18:58:24 +00:00
idLib::Printf( va( "Command line: %s\n", cmdline ) );
//::MessageBox( NULL, cmdline, "blah", MB_OK );
// parse command line options
idCmdArgs args;
if( cmdline )
{
2012-11-26 18:58:24 +00:00
// tokenize if the OS doesn't do it for us
args.TokenizeString( cmdline, true );
argv = args.GetArgs( &argc );
}
ParseCommandLine( argc, argv );
2012-11-26 18:58:24 +00:00
// init console command system
cmdSystem->Init();
2012-11-26 18:58:24 +00:00
// init CVar system
cvarSystem->Init();
2012-11-26 18:58:24 +00:00
// register all static CVars
idCVar::RegisterStaticVars();
2012-11-26 18:58:24 +00:00
idLib::Printf( "QA Timing INIT: %06dms\n", Sys_Milliseconds() );
2012-11-26 18:58:24 +00:00
// print engine version
Printf( "%s\n", version.string );
2012-11-26 18:58:24 +00:00
// initialize key input/binding, done early so bind command exists
idKeyInput::Init();
2012-11-26 18:58:24 +00:00
// init the console so we can take prints
console->Init();
2012-11-26 18:58:24 +00:00
// get architecture info
Sys_Init();
2012-11-26 18:58:24 +00:00
// initialize networking
Sys_InitNetworking();
2012-11-26 18:58:24 +00:00
// override cvars from command line
StartupVariable( NULL );
2012-11-26 18:58:24 +00:00
consoleUsed = com_allowConsole.GetBool();
if( Sys_AlreadyRunning() )
{
2012-11-26 18:58:24 +00:00
Sys_Quit();
}
2012-11-26 18:58:24 +00:00
// initialize processor specific SIMD implementation
InitSIMD();
2012-11-26 18:58:24 +00:00
// initialize the file system
fileSystem->Init();
const char* defaultLang = Sys_DefaultLanguage();
2012-11-26 18:58:24 +00:00
com_isJapaneseSKU = ( idStr::Icmp( defaultLang, ID_LANG_JAPANESE ) == 0 );
2012-11-26 18:58:24 +00:00
// Allow the system to set a default lanugage
Sys_SetLanguageFromSystem();
2012-11-26 18:58:24 +00:00
// Pre-allocate our 20 MB save buffer here on time, instead of on-demand for each save....
2012-11-26 18:58:24 +00:00
saveFile.SetNameAndType( SAVEGAME_CHECKPOINT_FILENAME, SAVEGAMEFILE_BINARY );
saveFile.PreAllocate( MIN_SAVEGAME_SIZE_BYTES );
2012-11-26 18:58:24 +00:00
stringsFile.SetNameAndType( SAVEGAME_STRINGS_FILENAME, SAVEGAMEFILE_BINARY );
stringsFile.PreAllocate( MAX_SAVEGAME_STRING_TABLE_SIZE );
2012-11-26 18:58:24 +00:00
fileSystem->BeginLevelLoad( "_startup", saveFile.GetDataPtr(), saveFile.GetAllocated() );
2012-11-26 18:58:24 +00:00
// initialize the declaration manager
declManager->Init();
2012-11-26 18:58:24 +00:00
// init journalling, etc
eventLoop->Init();
2012-11-26 18:58:24 +00:00
// init the parallel job manager
parallelJobManager->Init();
2012-11-26 18:58:24 +00:00
// exec the startup scripts
cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "exec default.cfg\n" );
2012-11-26 18:58:24 +00:00
#ifdef CONFIG_FILE
// skip the config file if "safe" is on the command line
if( !SafeMode() && !g_demoMode.GetBool() )
{
2012-11-26 18:58:24 +00:00
cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "exec " CONFIG_FILE "\n" );
}
#endif
2012-11-26 18:58:24 +00:00
cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "exec autoexec.cfg\n" );
2012-11-26 18:58:24 +00:00
// run cfg execution
cmdSystem->ExecuteCommandBuffer();
2012-11-26 18:58:24 +00:00
// re-override anything from the config files with command line args
StartupVariable( NULL );
2012-11-26 18:58:24 +00:00
// if any archived cvars are modified after this, we will trigger a writing of the config file
cvarSystem->ClearModifiedFlags( CVAR_ARCHIVE );
// init OpenGL, which will open a window and connect sound and input hardware
renderSystem->InitOpenGL();
2012-11-26 18:58:24 +00:00
// Support up to 2 digits after the decimal point
com_engineHz_denominator = 100LL * com_engineHz.GetFloat();
com_engineHz_latched = com_engineHz.GetFloat();
2012-11-26 18:58:24 +00:00
// start the sound system, but don't do any hardware operations yet
soundSystem->Init();
2012-11-26 18:58:24 +00:00
// initialize the renderSystem data structures
renderSystem->Init();
2012-11-26 18:58:24 +00:00
whiteMaterial = declManager->FindMaterial( "_white" );
if( idStr::Icmp( sys_lang.GetString(), ID_LANG_FRENCH ) == 0 )
{
2012-11-26 18:58:24 +00:00
// If the user specified french, we show french no matter what SKU
splashScreen = declManager->FindMaterial( "guis/assets/splash/legal_french" );
}
else if( idStr::Icmp( defaultLang, ID_LANG_FRENCH ) == 0 )
{
2012-11-26 18:58:24 +00:00
// If the lead sku is french (ie: europe), display figs
splashScreen = declManager->FindMaterial( "guis/assets/splash/legal_figs" );
}
else
{
2012-11-26 18:58:24 +00:00
// Otherwise show it in english
splashScreen = declManager->FindMaterial( "guis/assets/splash/legal_english" );
}
2012-11-26 18:58:24 +00:00
const int legalMinTime = 4000;
const bool showVideo = ( !com_skipIntroVideos.GetBool() && fileSystem->UsingResourceFiles() );
if( showVideo )
{
2012-11-26 18:58:24 +00:00
RenderBink( "video\\loadvideo.bik" );
RenderSplash();
RenderSplash();
}
else
{
2012-11-26 18:58:24 +00:00
idLib::Printf( "Skipping Intro Videos!\n" );
// display the legal splash screen
// No clue why we have to render this twice to show up...
RenderSplash();
RenderSplash();
}
2012-11-26 18:58:24 +00:00
int legalStartTime = Sys_Milliseconds();
declManager->Init2();
2012-11-26 18:58:24 +00:00
// initialize string database so we can use it for loading messages
InitLanguageDict();
2012-11-26 18:58:24 +00:00
// spawn the game thread, even if we are going to run without SMP
// one meg stack, because it can parse decls from gui surfaces (unfortunately)
// use a lower priority so job threads can run on the same core
gameThread.StartWorkerThread( "Game/Draw", CORE_1B, THREAD_BELOW_NORMAL, 0x100000 );
// boost this thread's priority, so it will prevent job threads from running while
// the render back end still has work to do
2012-11-26 18:58:24 +00:00
// init the user command input code
usercmdGen->Init();
2012-11-26 18:58:24 +00:00
Sys_SetRumble( 0, 0, 0 );
2012-11-26 18:58:24 +00:00
// initialize the user interfaces
uiManager->Init();
2012-11-26 18:58:24 +00:00
// startup the script debugger
// DebuggerServerInit();
2012-11-26 18:58:24 +00:00
// load the game dll
LoadGameDLL();
2012-11-26 18:58:24 +00:00
// On the PC touch them all so they get included in the resource build
if( !fileSystem->UsingResourceFiles() )
{
2012-11-26 18:58:24 +00:00
declManager->FindMaterial( "guis/assets/splash/legal_english" );
declManager->FindMaterial( "guis/assets/splash/legal_french" );
declManager->FindMaterial( "guis/assets/splash/legal_figs" );
// register the japanese font so it gets included
renderSystem->RegisterFont( "DFPHeiseiGothicW7" );
// Make sure all videos get touched because you can bring videos from one map to another, they need to be included in all maps
for( int i = 0; i < declManager->GetNumDecls( DECL_VIDEO ); i++ )
{
2012-11-26 18:58:24 +00:00
declManager->DeclByIndex( DECL_VIDEO, i );
}
}
2012-11-26 18:58:24 +00:00
fileSystem->UnloadResourceContainer( "_ordered" );
2012-11-26 18:58:24 +00:00
// the same idRenderWorld will be used for all games
// and demos, insuring that level specific models
// will be freed
renderWorld = renderSystem->AllocRenderWorld();
soundWorld = soundSystem->AllocSoundWorld( renderWorld );
2012-11-26 18:58:24 +00:00
menuSoundWorld = soundSystem->AllocSoundWorld( NULL );
menuSoundWorld->PlaceListener( vec3_origin, mat3_identity, 0 );
2012-11-26 18:58:24 +00:00
// init the session
session->Initialize();
session->InitializeSoundRelatedSystems();
2012-11-26 18:58:24 +00:00
InitializeMPMapsModes();
2012-11-26 18:58:24 +00:00
// leaderboards need to be initialized after InitializeMPMapsModes, which populates the MP Map list.
if( game != NULL )
{
2012-11-26 18:58:24 +00:00
game->Leaderboards_Init();
}
2012-11-26 18:58:24 +00:00
CreateMainMenu();
2012-11-26 18:58:24 +00:00
commonDialog.Init();
2012-11-26 18:58:24 +00:00
// load the console history file
consoleHistory.LoadHistoryFile();
2012-11-26 18:58:24 +00:00
AddStartupCommands();
2012-11-26 18:58:24 +00:00
StartMenu( true );
while( Sys_Milliseconds() - legalStartTime < legalMinTime )
{
2012-11-26 18:58:24 +00:00
RenderSplash();
Sys_GenerateEvents();
Sys_Sleep( 10 );
};
2012-11-26 18:58:24 +00:00
// print all warnings queued during initialization
PrintWarnings();
2012-11-26 18:58:24 +00:00
// remove any prints from the notify lines
console->ClearNotifyLines();
2012-11-26 18:58:24 +00:00
CheckStartupStorageRequirements();
if( preload_CommonAssets.GetBool() && fileSystem->UsingResourceFiles() )
{
2012-11-26 18:58:24 +00:00
idPreloadManifest manifest;
manifest.LoadManifest( "_common.preload" );
globalImages->Preload( manifest, false );
soundSystem->Preload( manifest );
}
2012-11-26 18:58:24 +00:00
fileSystem->EndLevelLoad();
2012-12-06 23:09:53 +00:00
// RB begin
#if defined(USE_DOOMCLASSIC)
2012-11-26 18:58:24 +00:00
// Initialize support for Doom classic.
doomClassicMaterial = declManager->FindMaterial( "_doomClassic" );
idImage* image = globalImages->GetImage( "_doomClassic" );
if( image != NULL )
{
2012-11-26 18:58:24 +00:00
idImageOpts opts;
opts.format = FMT_RGBA8;
opts.colorFormat = CFM_DEFAULT;
opts.width = DOOMCLASSIC_RENDERWIDTH;
opts.height = DOOMCLASSIC_RENDERHEIGHT;
opts.numLevels = 1;
image->AllocImage( opts, TF_LINEAR, TR_REPEAT );
}
2012-12-06 23:09:53 +00:00
#endif
// RB end
2012-11-26 18:58:24 +00:00
com_fullyInitialized = true;
2012-11-26 18:58:24 +00:00
// No longer need the splash screen
if( splashScreen != NULL )
{
for( int i = 0; i < splashScreen->GetNumStages(); i++ )
{
idImage* image = splashScreen->GetStage( i )->texture.image;
if( image != NULL )
{
2012-11-26 18:58:24 +00:00
image->PurgeImage();
}
}
}
2012-11-26 18:58:24 +00:00
Printf( "--- Common Initialization Complete ---\n" );
2012-11-26 18:58:24 +00:00
idLib::Printf( "QA Timing IIS: %06dms\n", Sys_Milliseconds() );
}
catch( idException& )
{
2012-11-26 18:58:24 +00:00
Sys_Error( "Error during initialization" );
}
}
/*
=================
idCommonLocal::Shutdown
=================
*/
void idCommonLocal::Shutdown()
{
2012-11-26 18:58:24 +00:00
if( com_shuttingDown )
{
2012-11-26 18:58:24 +00:00
return;
}
com_shuttingDown = true;
2012-11-26 18:58:24 +00:00
// Kill any pending saves...
printf( "session->GetSaveGameManager().CancelToTerminate();\n" );
session->GetSaveGameManager().CancelToTerminate();
2012-11-26 18:58:24 +00:00
// kill sound first
printf( "soundSystem->StopAllSounds();\n" );
soundSystem->StopAllSounds();
2012-11-26 18:58:24 +00:00
// shutdown the script debugger
// DebuggerServerShutdown();
if( aviCaptureMode )
{
2012-11-26 18:58:24 +00:00
printf( "EndAVICapture();\n" );
EndAVICapture();
}
2012-11-26 18:58:24 +00:00
printf( "Stop();\n" );
Stop();
2012-11-26 18:58:24 +00:00
printf( "CleanupShell();\n" );
CleanupShell();
2012-11-26 18:58:24 +00:00
printf( "delete loadGUI;\n" );
delete loadGUI;
loadGUI = NULL;
2012-11-26 18:58:24 +00:00
printf( "delete renderWorld;\n" );
delete renderWorld;
renderWorld = NULL;
2012-11-26 18:58:24 +00:00
printf( "delete soundWorld;\n" );
delete soundWorld;
soundWorld = NULL;
2012-11-26 18:58:24 +00:00
printf( "delete menuSoundWorld;\n" );
delete menuSoundWorld;
menuSoundWorld = NULL;
2012-11-26 18:58:24 +00:00
// shut down the session
printf( "session->ShutdownSoundRelatedSystems();\n" );
session->ShutdownSoundRelatedSystems();
printf( "session->Shutdown();\n" );
session->Shutdown();
2012-11-26 18:58:24 +00:00
// shutdown, deallocate leaderboard definitions.
if( game != NULL )
{
2012-11-26 18:58:24 +00:00
printf( "game->Leaderboards_Shutdown();\n" );
game->Leaderboards_Shutdown();
}
2012-11-26 18:58:24 +00:00
// shut down the user interfaces
printf( "uiManager->Shutdown();\n" );
uiManager->Shutdown();
2012-11-26 18:58:24 +00:00
// shut down the sound system
printf( "soundSystem->Shutdown();\n" );
soundSystem->Shutdown();
2012-11-26 18:58:24 +00:00
// shut down the user command input code
printf( "usercmdGen->Shutdown();\n" );
usercmdGen->Shutdown();
2012-11-26 18:58:24 +00:00
// shut down the event loop
printf( "eventLoop->Shutdown();\n" );
eventLoop->Shutdown();
// shutdown the decl manager
printf( "declManager->Shutdown();\n" );
declManager->Shutdown();
2012-11-26 18:58:24 +00:00
// shut down the renderSystem
printf( "renderSystem->Shutdown();\n" );
renderSystem->Shutdown();
2012-11-26 18:58:24 +00:00
printf( "commonDialog.Shutdown();\n" );
commonDialog.Shutdown();
// unload the game dll
printf( "UnloadGameDLL();\n" );
UnloadGameDLL();
2012-11-26 18:58:24 +00:00
printf( "saveFile.Clear( true );\n" );
saveFile.Clear( true );
printf( "stringsFile.Clear( true );\n" );
stringsFile.Clear( true );
2012-11-26 18:58:24 +00:00
// only shut down the log file after all output is done
printf( "CloseLogFile();\n" );
CloseLogFile();
2012-11-26 18:58:24 +00:00
// shut down the file system
printf( "fileSystem->Shutdown( false );\n" );
fileSystem->Shutdown( false );
2012-11-26 18:58:24 +00:00
// shut down non-portable system services
printf( "Sys_Shutdown();\n" );
Sys_Shutdown();
2012-11-26 18:58:24 +00:00
// shut down the console
printf( "console->Shutdown();\n" );
console->Shutdown();
2012-11-26 18:58:24 +00:00
// shut down the key system
printf( "idKeyInput::Shutdown();\n" );
idKeyInput::Shutdown();
2012-11-26 18:58:24 +00:00
// shut down the cvar system
printf( "cvarSystem->Shutdown();\n" );
cvarSystem->Shutdown();
2012-11-26 18:58:24 +00:00
// shut down the console command system
printf( "cmdSystem->Shutdown();\n" );
cmdSystem->Shutdown();
2012-11-26 18:58:24 +00:00
// free any buffered warning messages
printf( "ClearWarnings( GAME_NAME \" shutdown\" );\n" );
ClearWarnings( GAME_NAME " shutdown" );
printf( "warningCaption.Clear();\n" );
warningCaption.Clear();
printf( "errorList.Clear();\n" );
errorList.Clear();
2012-11-26 18:58:24 +00:00
// shutdown idLib
printf( "idLib::ShutDown();\n" );
idLib::ShutDown();
}
/*
========================
idCommonLocal::CreateMainMenu
========================
*/
void idCommonLocal::CreateMainMenu()
{
if( game != NULL )
{
2012-11-26 18:58:24 +00:00
// note which media we are going to need to load
declManager->BeginLevelLoad();
renderSystem->BeginLevelLoad();
soundSystem->BeginLevelLoad();
uiManager->BeginLevelLoad();
// create main inside an "empty" game level load - so assets get
// purged automagically when we transition to a "real" map
game->Shell_CreateMenu( false );
game->Shell_Show( true );
game->Shell_SyncWithSession();
2012-11-26 18:58:24 +00:00
// load
renderSystem->EndLevelLoad();
soundSystem->EndLevelLoad();
declManager->EndLevelLoad();
uiManager->EndLevelLoad( "" );
}
}
/*
===============
idCommonLocal::Stop
called on errors and game exits
===============
*/
void idCommonLocal::Stop( bool resetSession )
{
2012-11-26 18:58:24 +00:00
ClearWipe();
2012-11-26 18:58:24 +00:00
// clear mapSpawned and demo playing flags
UnloadMap();
2012-11-26 18:58:24 +00:00
soundSystem->StopAllSounds();
2012-11-26 18:58:24 +00:00
insideUpdateScreen = false;
insideExecuteMapChange = false;
2012-11-26 18:58:24 +00:00
// drop all guis
ExitMenu();
if( resetSession )
{
2012-11-26 18:58:24 +00:00
session->QuitMatchToTitle();
}
}
/*
===============
idCommonLocal::BusyWait
===============
*/
void idCommonLocal::BusyWait()
{
2012-11-26 18:58:24 +00:00
Sys_GenerateEvents();
2012-11-26 18:58:24 +00:00
const bool captureToImage = false;
UpdateScreen( captureToImage );
2012-11-26 18:58:24 +00:00
session->UpdateSignInManager();
session->Pump();
}
/*
===============
idCommonLocal::WaitForSessionState
===============
*/
bool idCommonLocal::WaitForSessionState( idSession::sessionState_t desiredState )
{
if( session->GetState() == desiredState )
{
2012-11-26 18:58:24 +00:00
return true;
}
while( true )
{
2012-11-26 18:58:24 +00:00
BusyWait();
2012-11-26 18:58:24 +00:00
idSession::sessionState_t sessionState = session->GetState();
if( sessionState == desiredState )
{
2012-11-26 18:58:24 +00:00
return true;
}
if( sessionState != idSession::LOADING &&
sessionState != idSession::SEARCHING &&
sessionState != idSession::CONNECTING &&
sessionState != idSession::BUSY &&
sessionState != desiredState )
{
return false;
2012-11-26 18:58:24 +00:00
}
2012-11-26 18:58:24 +00:00
Sys_Sleep( 10 );
}
}
/*
========================
idCommonLocal::LeaveGame
========================
*/
void idCommonLocal::LeaveGame()
{
2012-11-26 18:58:24 +00:00
const bool captureToImage = false;
UpdateScreen( captureToImage );
2012-11-26 18:58:24 +00:00
ResetNetworkingState();
2012-11-26 18:58:24 +00:00
Stop( false );
2012-11-26 18:58:24 +00:00
CreateMainMenu();
2012-11-26 18:58:24 +00:00
StartMenu();
2012-11-26 18:58:24 +00:00
}
/*
===============
idCommonLocal::ProcessEvent
===============
*/
bool idCommonLocal::ProcessEvent( const sysEvent_t* event )
{
2012-11-26 18:58:24 +00:00
// hitting escape anywhere brings up the menu
if( game && game->IsInGame() )
{
if( event->evType == SE_KEY && event->evValue2 == 1 && ( event->evValue == K_ESCAPE || event->evValue == K_JOY9 ) )
{
if( !game->Shell_IsActive() )
{
2012-11-26 18:58:24 +00:00
// menus / etc
if( MenuEvent( event ) )
{
2012-11-26 18:58:24 +00:00
return true;
}
2012-11-26 18:58:24 +00:00
console->Close();
2012-11-26 18:58:24 +00:00
StartMenu();
return true;
}
else
{
2012-11-26 18:58:24 +00:00
console->Close();
2012-11-26 18:58:24 +00:00
// menus / etc
if( MenuEvent( event ) )
{
2012-11-26 18:58:24 +00:00
return true;
}
2012-11-26 18:58:24 +00:00
game->Shell_ClosePause();
}
}
2012-11-26 18:58:24 +00:00
}
2012-11-26 18:58:24 +00:00
// let the pull-down console take it if desired
if( console->ProcessEvent( event, false ) )
{
2012-11-26 18:58:24 +00:00
return true;
}
if( session->ProcessInputEvent( event ) )
{
2012-11-26 18:58:24 +00:00
return true;
}
if( Dialog().IsDialogActive() )
{
2012-11-26 18:58:24 +00:00
Dialog().HandleDialogEvent( event );
return true;
}
2012-12-06 23:09:53 +00:00
// RB begin
#if defined(USE_DOOMCLASSIC)
2012-12-08 17:20:13 +00:00
2012-11-26 18:58:24 +00:00
// Let Doom classic run events.
if( IsPlayingDoomClassic() )
{
2012-11-26 18:58:24 +00:00
// Translate the event to Doom classic format.
event_t classicEvent;
if( event->evType == SE_KEY )
{
if( event->evValue2 == 1 )
{
2012-11-26 18:58:24 +00:00
classicEvent.type = ev_keydown;
}
else if( event->evValue2 == 0 )
{
2012-11-26 18:58:24 +00:00
classicEvent.type = ev_keyup;
}
2012-11-26 18:58:24 +00:00
DoomLib::SetPlayer( 0 );
extern Globals* g;
if( g != NULL )
{
2012-11-26 18:58:24 +00:00
classicEvent.data1 = DoomLib::RemapControl( event->GetKey() );
2012-11-26 18:58:24 +00:00
D_PostEvent( &classicEvent );
}
DoomLib::SetPlayer( -1 );
}
2012-11-26 18:58:24 +00:00
// Let the classics eat all events.
return true;
}
2012-12-06 23:09:53 +00:00
#endif
// RB end
2012-11-26 18:58:24 +00:00
// menus / etc
if( MenuEvent( event ) )
{
2012-11-26 18:58:24 +00:00
return true;
}
2012-11-26 18:58:24 +00:00
// if we aren't in a game, force the console to take it
if( !mapSpawned )
{
2012-11-26 18:58:24 +00:00
console->ProcessEvent( event, true );
return true;
}
2012-11-26 18:58:24 +00:00
// in game, exec bindings for all key downs
if( event->evType == SE_KEY && event->evValue2 == 1 )
{
2012-11-26 18:58:24 +00:00
idKeyInput::ExecKeyBinding( event->evValue );
return true;
}
2012-11-26 18:58:24 +00:00
return false;
}
/*
========================
idCommonLocal::ResetPlayerInput
========================
*/
void idCommonLocal::ResetPlayerInput( int playerIndex )
{
userCmdMgr.ResetPlayer( playerIndex );
2012-11-26 18:58:24 +00:00
}
2012-12-06 23:09:53 +00:00
// RB begin
#if defined(USE_DOOMCLASSIC)
2012-11-26 18:58:24 +00:00
/*
========================
idCommonLocal::SwitchToGame
========================
*/
void idCommonLocal::SwitchToGame( currentGame_t newGame )
{
2012-11-26 18:58:24 +00:00
idealCurrentGame = newGame;
}
/*
========================
idCommonLocal::PerformGameSwitch
========================
*/
void idCommonLocal::PerformGameSwitch()
{
2012-11-26 18:58:24 +00:00
// If the session state is past the menu, we should be in Doom 3.
// This will happen if, for example, we accept an invite while playing
// Doom or Doom 2.
if( session->GetState() > idSession::IDLE )
{
2012-11-26 18:58:24 +00:00
idealCurrentGame = DOOM3_BFG;
}
if( currentGame == idealCurrentGame )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
const int DOOM_CLASSIC_HZ = 35;
if( idealCurrentGame == DOOM_CLASSIC || idealCurrentGame == DOOM2_CLASSIC )
{
2012-11-26 18:58:24 +00:00
// Pause Doom 3 sound.
if( menuSoundWorld != NULL )
{
2012-11-26 18:58:24 +00:00
menuSoundWorld->Pause();
}
2012-11-26 18:58:24 +00:00
DoomLib::skipToNew = false;
DoomLib::skipToLoad = false;
2012-11-26 18:58:24 +00:00
// Reset match parameters for the classics.
DoomLib::matchParms = idMatchParameters();
2012-11-26 18:58:24 +00:00
// The classics use the usercmd manager too, clear it.
userCmdMgr.SetDefaults();
2012-11-26 18:58:24 +00:00
// Classics need a local user too.
session->UpdateSignInManager();
session->GetSignInManager().RegisterLocalUser( 0 );
2012-11-26 18:58:24 +00:00
com_engineHz_denominator = 100LL * DOOM_CLASSIC_HZ;
com_engineHz_latched = DOOM_CLASSIC_HZ;
2012-11-26 18:58:24 +00:00
DoomLib::SetCurrentExpansion( idealCurrentGame );
}
else if( idealCurrentGame == DOOM3_BFG )
{
2012-11-26 18:58:24 +00:00
DoomLib::Interface.Shutdown();
com_engineHz_denominator = 100LL * com_engineHz.GetFloat();
com_engineHz_latched = com_engineHz.GetFloat();
// Don't MoveToPressStart if we have an invite, we need to go
// directly to the lobby.
if( session->GetState() <= idSession::IDLE )
{
2012-11-26 18:58:24 +00:00
session->MoveToPressStart();
}
2012-11-26 18:58:24 +00:00
// Unpause Doom 3 sound.
if( menuSoundWorld != NULL )
{
2012-11-26 18:58:24 +00:00
menuSoundWorld->UnPause();
}
}
2012-11-26 18:58:24 +00:00
currentGame = idealCurrentGame;
}
2012-12-06 23:09:53 +00:00
#endif // #if defined(USE_DOOMCLASSIC)
// RB end
2012-11-26 18:58:24 +00:00
/*
==================
Common_WritePrecache_f
==================
*/
CONSOLE_COMMAND( writePrecache, "writes precache commands", NULL )
{
if( args.Argc() != 2 )
{
2012-11-26 18:58:24 +00:00
common->Printf( "USAGE: writePrecache <execFile>\n" );
return;
}
idStr str = args.Argv( 1 );
2012-11-26 18:58:24 +00:00
str.DefaultFileExtension( ".cfg" );
idFile* f = fileSystem->OpenFileWrite( str );
2012-11-26 18:58:24 +00:00
declManager->WritePrecacheCommands( f );
renderModelManager->WritePrecacheCommands( f );
uiManager->WritePrecacheCommands( f );
2012-11-26 18:58:24 +00:00
fileSystem->CloseFile( f );
}
/*
================
Common_Disconnect_f
================
*/
CONSOLE_COMMAND_SHIP( disconnect, "disconnects from a game", NULL )
{
2012-11-26 18:58:24 +00:00
session->QuitMatch();
}
/*
===============
Common_Hitch_f
===============
*/
CONSOLE_COMMAND( hitch, "hitches the game", NULL )
{
if( args.Argc() == 2 )
{
Sys_Sleep( atoi( args.Argv( 1 ) ) );
}
else
{
2012-11-26 18:58:24 +00:00
Sys_Sleep( 100 );
}
}
CONSOLE_COMMAND( showStringMemory, "shows memory used by strings", NULL )
{
2012-11-26 18:58:24 +00:00
idStr::ShowMemoryUsage_f( args );
}
CONSOLE_COMMAND( showDictMemory, "shows memory used by dictionaries", NULL )
{
2012-11-26 18:58:24 +00:00
idDict::ShowMemoryUsage_f( args );
}
CONSOLE_COMMAND( listDictKeys, "lists all keys used by dictionaries", NULL )
{
2012-11-26 18:58:24 +00:00
idDict::ListKeys_f( args );
}
CONSOLE_COMMAND( listDictValues, "lists all values used by dictionaries", NULL )
{
2012-11-26 18:58:24 +00:00
idDict::ListValues_f( args );
}
CONSOLE_COMMAND( testSIMD, "test SIMD code", NULL )
{
2012-11-26 18:58:24 +00:00
idSIMD::Test_f( args );
}