2012-11-26 18:58:24 +00:00
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Doom 3 BFG Edition GPL Source Code
2012-11-28 15:47:07 +00:00
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
2012-11-28 15:47:07 +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 .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-12-22 15:18:19 +00:00
# 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 )
2012-11-28 15:47:07 +00:00
# define BUILD_DEBUG "-debug"
2012-11-26 18:58:24 +00:00
# else
2012-11-28 15:47:07 +00:00
# define BUILD_DEBUG ""
2012-11-26 18:58:24 +00:00
# endif
2012-11-28 15:47:07 +00:00
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 ;
2012-11-28 15:47:07 +00:00
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
2012-11-28 15:47:07 +00:00
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 " ) ;
2013-01-20 14:52:01 +00:00
// DG: support "com_showFPS 2" for fps-only view like in classic doom3 => make it CVAR_INTEGER
idCVar com_showFPS ( " com_showFPS " , " 0 " , CVAR_INTEGER | CVAR_SYSTEM | CVAR_ARCHIVE | CVAR_NOCHEAT , " show frames rendered per second. 0: off 1: default bfg values, 2: only show FPS (classic view) " ) ;
// DG end
2012-11-28 15:47:07 +00:00
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 " ) ;
2013-01-03 11:39:16 +00:00
// DG: add cvar for pause
2013-03-03 23:41:39 +00:00
idCVar com_pause ( " com_pause " , " 0 " , CVAR_BOOL | CVAR_SYSTEM | CVAR_NOCHEAT , " set to 1 to pause game, to 0 to unpause again " ) ;
2013-01-03 11:39:16 +00:00
// DG end
2012-11-26 18:58:24 +00:00
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__
2012-11-28 15:47:07 +00:00
idGame * game = NULL ;
idGameEdit * gameEdit = NULL ;
2012-11-26 18:58:24 +00:00
# endif
idCommonLocal commonLocal ;
2012-11-28 15:47:07 +00:00
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 ) ,
2012-11-28 15:47:07 +00:00
writeSnapshotIndex ( 0 ) ,
2012-12-11 22:48:55 +00:00
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-28 15:47:07 +00:00
{
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-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
logFile = NULL ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
strcpy ( errorMessage , " " ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
rd_buffer = NULL ;
rd_buffersize = 0 ;
rd_flush = NULL ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
gameDLL = 0 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
loadGUI = NULL ;
nextLoadTip = 0 ;
isHellMap = false ;
wipeForced = false ;
defaultLoadscreen = false ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
menuSoundWorld = NULL ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
insideUpdateScreen = false ;
insideExecuteMapChange = false ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
mapSpawnData . savegameFile = NULL ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
currentMapName . Clear ( ) ;
aviDemoShortName . Clear ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
renderWorld = NULL ;
soundWorld = NULL ;
menuSoundWorld = NULL ;
readDemo = NULL ;
writeDemo = NULL ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
gameFrame = 0 ;
gameTimeResidual = 0 ;
syncNextGameFrame = true ;
mapSpawned = false ;
aviCaptureMode = false ;
timeDemo = TD_NO ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
nextSnapshotSendTime = 0 ;
nextUsercmdSendTime = 0 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
clientPrediction = 0 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
saveFile = NULL ;
stringsFile = NULL ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
ClearWipe ( ) ;
}
/*
= = = = = = = = = = = = = = = = = =
idCommonLocal : : Quit
= = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idCommonLocal : : Quit ( )
{
2012-11-26 18:58:24 +00:00
// don't try to shutdown if we are in a recursive error
2012-11-28 15:47:07 +00:00
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
= = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idCommonLocal : : ParseCommandLine ( int argc , const char * const * argv )
{
2012-11-26 18:58:24 +00:00
int i , current_count ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
com_numConsoleLines = 0 ;
current_count = 0 ;
// API says no program path
2012-11-28 15:47:07 +00:00
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
2012-11-28 15:47:07 +00:00
}
else if ( argv [ i ] [ 0 ] = = ' + ' )
{
2012-11-26 18:58:24 +00:00
com_numConsoleLines + + ;
2012-11-28 15:47:07 +00:00
com_consoleLines [ com_numConsoleLines - 1 ] . AppendArg ( argv [ i ] + 1 ) ;
}
else
{
if ( ! com_numConsoleLines )
{
2012-11-26 18:58:24 +00:00
com_numConsoleLines + + ;
}
2012-11-28 15:47:07 +00:00
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 )
= = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
bool idCommonLocal : : SafeMode ( )
{
2012-11-26 18:58:24 +00:00
int i ;
2012-11-28 15:47:07 +00:00
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 .
= = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idCommonLocal : : StartupVariable ( const char * match )
{
2012-11-26 18:58:24 +00:00
int i = 0 ;
2012-11-28 15:47:07 +00:00
while ( i < com_numConsoleLines )
{
if ( strcmp ( com_consoleLines [ i ] . Argv ( 0 ) , " set " ) ! = 0 )
{
2012-11-26 18:58:24 +00:00
i + + ;
continue ;
}
2012-11-28 15:47:07 +00:00
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
= = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idCommonLocal : : AddStartupCommands ( )
{
2012-11-26 18:58:24 +00:00
// quote every token, so args with semicolons can work
2012-11-28 15:47:07 +00:00
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
= = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
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
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
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
2012-11-28 15:47:07 +00:00
if ( ! com_fullyInitialized )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
if ( ! ( cvarSystem - > GetModifiedFlags ( ) & CVAR_ARCHIVE ) )
{
2012-11-26 18:58:24 +00:00
return ;
}
cvarSystem - > ClearModifiedFlags ( CVAR_ARCHIVE ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// save to the profile
2012-11-28 15:47:07 +00:00
idLocalUser * user = session - > GetSignInManager ( ) . GetMasterLocalUser ( ) ;
if ( user ! = NULL )
{
2012-11-26 18:58:24 +00:00
user - > SaveProfileSettings ( ) ;
}
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
WriteConfigToFile ( CONFIG_FILE ) ;
2012-11-28 15:47:07 +00:00
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
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
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
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
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
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
int idCommonLocal : : ButtonState ( int key )
{
return usercmdGen - > ButtonState ( key ) ;
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = =
ButtonState ( )
Returns the state of the key
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
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
= = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
renderSystem - > PrintMemInfo ( & mi ) ; // textures and models
soundSystem - > PrintMemInfo ( & mi ) ; // sounds
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
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-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
common - > Printf ( " Used asset memory: %s bytes \n " , idStr : : FormatNumber ( mi . assetTotals ) . c_str ( ) ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// write overview file
2012-11-28 15:47:07 +00:00
idFile * f ;
2012-11-26 18:58:24 +00:00
f = fileSystem - > OpenFileAppend ( " maps/printmeminfo.txt " ) ;
2012-11-28 15:47:07 +00:00
if ( ! f )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
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 .
= = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
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 ;
}
2012-11-28 15:47:07 +00:00
if ( args . Argc ( ) > 1 )
{
2012-11-26 18:58:24 +00:00
commonLocal . FatalError ( " Testing fatal error " ) ;
2012-11-28 15:47:07 +00:00
}
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 .
= = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
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 ;
2012-11-28 15:47:07 +00:00
if ( args . Argc ( ) ! = 2 )
{
2012-11-26 18:58:24 +00:00
commonLocal . Printf ( " freeze <seconds> \n " ) ;
return ;
}
2012-11-28 15:47:07 +00:00
if ( ! com_developer . GetBool ( ) )
{
2012-11-26 18:58:24 +00:00
commonLocal . Printf ( " freeze may only be used in developer mode \n " ) ;
return ;
}
2012-11-28 15:47:07 +00:00
s = atof ( args . Argv ( 1 ) ) ;
2012-11-26 18:58:24 +00:00
start = eventLoop - > Milliseconds ( ) ;
2012-11-28 15:47:07 +00:00
while ( 1 )
{
2012-11-26 18:58:24 +00:00
now = eventLoop - > Milliseconds ( ) ;
2012-11-28 15:47:07 +00:00
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
= = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
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
2012-11-28 15:47:07 +00:00
* ( int * ) 0 = 0x12345678 ;
2012-12-22 05:15:50 +00:00
# endif
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = = =
Com_Quit_f
= = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
CONSOLE_COMMAND_SHIP ( quit , " quits the game " , NULL )
{
2012-11-26 18:58:24 +00:00
commonLocal . Quit ( ) ;
}
2012-11-28 15:47:07 +00:00
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
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
CONSOLE_COMMAND ( writeConfig , " writes a config file " , NULL )
{
2012-11-26 18:58:24 +00:00
idStr filename ;
2012-11-28 15:47:07 +00:00
if ( args . Argc ( ) ! = 2 )
{
2012-11-26 18:58:24 +00:00
commonLocal . Printf ( " Usage: writeconfig <filename> \n " ) ;
return ;
}
2012-11-28 15:47:07 +00:00
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
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idCommonLocal : : CheckStartupStorageRequirements ( )
{
2012-12-19 22:56:20 +00:00
// 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-12-19 22:56:20 +00:00
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.
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// Get the free space on the save path.
availableSpace = Sys_GetDriveFreeSpaceInBytes ( savepath ) ;
2012-11-28 15:47:07 +00:00
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)
2012-11-28 15:47:07 +00:00
if ( availableSpace < = 1 )
{
2012-11-26 18:58:24 +00:00
idStr savePath ( savepath ) ;
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
uint64 requiredSizeBytes = MIN_SAVE_STORAGE_SAVEGAME + MIN_SAVE_STORAGE_PROFILE ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
idLib : : Printf ( " requiredSizeBytes: %lld \n " , requiredSizeBytes ) ;
2012-11-28 15:47:07 +00:00
if ( ( int64 ) ( requiredSizeBytes - availableSpace ) > 0 )
{
class idSWFScriptFunction_Continue : public idSWFScriptFunction_RefCounted
{
2012-11-26 18:58:24 +00:00
public :
virtual ~ idSWFScriptFunction_Continue ( ) { }
2012-11-28 15:47:07 +00:00
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 ( ) ;
}
} ;
2012-11-28 15:47:07 +00:00
idStaticList < idSWFScriptFunction * , 4 > callbacks ;
2012-11-26 18:58:24 +00:00
idStaticList < idStrId , 4 > optionText ;
2012-11-28 15:47:07 +00:00
callbacks . Append ( new ( TAG_SWF ) idSWFScriptFunction_Continue ( ) ) ;
2012-11-26 18:58:24 +00:00
optionText . Append ( idStrId ( " #STR_SWF_ACCEPT " ) ) ;
2012-11-28 15:47:07 +00:00
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 ;
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
common - > Dialog ( ) . AddDynamicDialog ( GDM_INSUFFICENT_STORAGE_SPACE , callbacks , optionText , true , msg ) ;
}
2012-12-19 22:56:20 +00:00
# endif
// RB end
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
session - > GetAchievementSystem ( ) . Start ( ) ;
}
/*
= = = = = = = = = = = = = = =
idCommonLocal : : JapaneseCensorship
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
bool idCommonLocal : : JapaneseCensorship ( ) const
{
2012-11-26 18:58:24 +00:00
return com_japaneseCensorship . GetBool ( ) | | com_isJapaneseSKU ;
}
/*
= = = = = = = = = = = = = = =
idCommonLocal : : FilterLangList
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idCommonLocal : : FilterLangList ( idStrList * list , idStr lang )
{
2012-11-26 18:58:24 +00:00
idStr temp ;
2012-11-28 15:47:07 +00:00
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 ;
2012-11-28 15:47:07 +00:00
void idCommonLocal : : InitLanguageDict ( )
{
2012-11-26 18:58:24 +00:00
idStr fileName ;
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// Loop through the list and filter
idStrList currentLangList = langList ;
FilterLangList ( & currentLangList , sys_lang . GetString ( ) ) ;
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
idLocalization : : ClearDictionary ( ) ;
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < currentLangList . Num ( ) ; i + + )
{
2012-11-26 18:58:24 +00:00
//common->Printf("%s\n", currentLangList[i].c_str());
2012-11-28 15:47:07 +00:00
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 ] ) ;
2012-11-28 15:47:07 +00:00
fileSystem - > FreeFile ( ( void * ) buffer ) ;
2012-11-26 18:58:24 +00:00
}
2012-11-28 15:47:07 +00:00
fileSystem - > FreeFileList ( langFiles ) ;
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = = =
ReloadLanguage_f
= = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
CONSOLE_COMMAND ( reloadLanguage , " reload language dict " , NULL )
{
2012-11-26 18:58:24 +00:00
commonLocal . InitLanguageDict ( ) ;
}
# include "../renderer/Image.h"
/*
= = = = = = = = = = = = = = = = =
Com_StartBuild_f
= = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
CONSOLE_COMMAND ( startBuild , " prepares to make a build " , NULL )
{
2012-11-26 18:58:24 +00:00
globalImages - > StartBuild ( ) ;
}
/*
= = = = = = = = = = = = = = = = =
Com_FinishBuild_f
= = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
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
= = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
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 ;
2012-11-28 15:47:07 +00:00
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 ) ;
}
2012-11-28 15:47:07 +00:00
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 ) ;
2012-11-28 15:47:07 +00:00
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
= = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
idStr materialText ;
materialText . Format ( " { translucent { videoMap %s } } " , path ) ;
2012-11-28 15:47:07 +00:00
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 ( ) ) ;
2012-11-28 15:47:07 +00:00
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 ) ;
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
material - > MakeDefault ( ) ;
}
/*
= = = = = = = = = = = = = = = = =
idCommonLocal : : InitSIMD
= = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idCommonLocal : : InitSIMD ( )
{
2012-11-26 18:58:24 +00:00
idSIMD : : InitProcessor ( " doom " , com_forceGenericSIMD . GetBool ( ) ) ;
com_forceGenericSIMD . ClearModified ( ) ;
}
/*
= = = = = = = = = = = = = = = = =
idCommonLocal : : LoadGameDLL
= = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idCommonLocal : : LoadGameDLL ( )
{
2012-11-26 18:58:24 +00:00
# ifdef __DOOM_DLL__
char dllPath [ MAX_OSPATH ] ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
gameImport_t gameImport ;
gameExport_t gameExport ;
GetGameAPI_t GetGameAPI ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
fileSystem - > FindDLL ( " game " , dllPath , true ) ;
2012-11-28 15:47:07 +00:00
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 ) ;
2012-11-28 15:47:07 +00:00
if ( ! gameDLL )
{
2012-11-26 18:58:24 +00:00
common - > FatalError ( " couldn't load game dynamic library " ) ;
return ;
}
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
gameExport = * GetGameAPI ( & gameImport ) ;
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
game = gameExport . game ;
gameEdit = gameExport . gameEdit ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
# endif
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// initialize the game object
2012-11-28 15:47:07 +00:00
if ( game ! = NULL )
{
2012-11-26 18:58:24 +00:00
game - > Init ( ) ;
}
}
/*
= = = = = = = = = = = = = = = = =
idCommonLocal : : UnloadGameDLL
= = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idCommonLocal : : CleanupShell ( )
{
if ( game ! = NULL )
{
2012-11-26 18:58:24 +00:00
game - > Shell_Cleanup ( ) ;
}
}
/*
= = = = = = = = = = = = = = = = =
idCommonLocal : : UnloadGameDLL
= = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idCommonLocal : : UnloadGameDLL ( )
{
2012-11-26 18:58:24 +00:00
// shut down the game object
2012-11-28 15:47:07 +00:00
if ( game ! = NULL )
{
2012-11-26 18:58:24 +00:00
game - > Shutdown ( ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
# ifdef __DOOM_DLL__
2012-11-28 15:47:07 +00:00
if ( gameDLL )
{
2012-11-26 18:58:24 +00:00
Sys_DLL_Unload ( gameDLL ) ;
gameDLL = NULL ;
}
game = NULL ;
gameEdit = NULL ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
# endif
}
/*
= = = = = = = = = = = = = = = = =
idCommonLocal : : IsInitialized
= = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
bool idCommonLocal : : IsInitialized ( ) const
{
2012-11-26 18:58:24 +00:00
return com_fullyInitialized ;
}
//======================================================================================
/*
= = = = = = = = = = = = = = = = =
idCommonLocal : : Init
= = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// initialize idLib
idLib : : Init ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// clear warning buffer
ClearWarnings ( GAME_NAME " initialization " ) ;
2012-11-28 15:47:07 +00:00
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 ;
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// init console command system
cmdSystem - > Init ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// init CVar system
cvarSystem - > Init ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// register all static CVars
idCVar : : RegisterStaticVars ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
idLib : : Printf ( " QA Timing INIT: %06dms \n " , Sys_Milliseconds ( ) ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// print engine version
Printf ( " %s \n " , version . string ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// initialize key input/binding, done early so bind command exists
idKeyInput : : Init ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// init the console so we can take prints
console - > Init ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// get architecture info
Sys_Init ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// initialize networking
Sys_InitNetworking ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// override cvars from command line
StartupVariable ( NULL ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
consoleUsed = com_allowConsole . GetBool ( ) ;
2012-11-28 15:47:07 +00:00
if ( Sys_AlreadyRunning ( ) )
{
2012-11-26 18:58:24 +00:00
Sys_Quit ( ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// initialize processor specific SIMD implementation
InitSIMD ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// initialize the file system
fileSystem - > Init ( ) ;
2012-11-28 15:47:07 +00:00
const char * defaultLang = Sys_DefaultLanguage ( ) ;
2012-11-26 18:58:24 +00:00
com_isJapaneseSKU = ( idStr : : Icmp ( defaultLang , ID_LANG_JAPANESE ) = = 0 ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// Allow the system to set a default lanugage
Sys_SetLanguageFromSystem ( ) ;
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
saveFile . SetNameAndType ( SAVEGAME_CHECKPOINT_FILENAME , SAVEGAMEFILE_BINARY ) ;
saveFile . PreAllocate ( MIN_SAVEGAME_SIZE_BYTES ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
stringsFile . SetNameAndType ( SAVEGAME_STRINGS_FILENAME , SAVEGAMEFILE_BINARY ) ;
stringsFile . PreAllocate ( MAX_SAVEGAME_STRING_TABLE_SIZE ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
fileSystem - > BeginLevelLoad ( " _startup " , saveFile . GetDataPtr ( ) , saveFile . GetAllocated ( ) ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// initialize the declaration manager
declManager - > Init ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// init journalling, etc
eventLoop - > Init ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// init the parallel job manager
parallelJobManager - > Init ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// exec the startup scripts
cmdSystem - > BufferCommandText ( CMD_EXEC_APPEND , " exec default.cfg \n " ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
# ifdef CONFIG_FILE
// skip the config file if "safe" is on the command line
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
cmdSystem - > BufferCommandText ( CMD_EXEC_APPEND , " exec autoexec.cfg \n " ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// run cfg execution
cmdSystem - > ExecuteCommandBuffer ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// re-override anything from the config files with command line args
StartupVariable ( NULL ) ;
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// start the sound system, but don't do any hardware operations yet
soundSystem - > Init ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// initialize the renderSystem data structures
renderSystem - > Init ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
whiteMaterial = declManager - > FindMaterial ( " _white " ) ;
2012-11-28 15:47:07 +00:00
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 " ) ;
2012-11-28 15:47:07 +00:00
}
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 " ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
// Otherwise show it in english
splashScreen = declManager - > FindMaterial ( " guis/assets/splash/legal_english " ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
const int legalMinTime = 4000 ;
2012-11-28 15:47:07 +00:00
const bool showVideo = ( ! com_skipIntroVideos . GetBool ( ) & & fileSystem - > UsingResourceFiles ( ) ) ;
if ( showVideo )
{
2012-11-26 18:58:24 +00:00
RenderBink ( " video \\ loadvideo.bik " ) ;
RenderSplash ( ) ;
RenderSplash ( ) ;
2012-11-28 15:47:07 +00:00
}
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
int legalStartTime = Sys_Milliseconds ( ) ;
declManager - > Init2 ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// initialize string database so we can use it for loading messages
InitLanguageDict ( ) ;
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// init the user command input code
usercmdGen - > Init ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
Sys_SetRumble ( 0 , 0 , 0 ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// initialize the user interfaces
uiManager - > Init ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// startup the script debugger
// DebuggerServerInit();
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// load the game dll
LoadGameDLL ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// On the PC touch them all so they get included in the resource build
2012-11-28 15:47:07 +00:00
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
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
fileSystem - > UnloadResourceContainer ( " _ordered " ) ;
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
menuSoundWorld = soundSystem - > AllocSoundWorld ( NULL ) ;
menuSoundWorld - > PlaceListener ( vec3_origin , mat3_identity , 0 ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// init the session
session - > Initialize ( ) ;
session - > InitializeSoundRelatedSystems ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
InitializeMPMapsModes ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// leaderboards need to be initialized after InitializeMPMapsModes, which populates the MP Map list.
2012-11-28 15:47:07 +00:00
if ( game ! = NULL )
{
2012-11-26 18:58:24 +00:00
game - > Leaderboards_Init ( ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
CreateMainMenu ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
commonDialog . Init ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// load the console history file
consoleHistory . LoadHistoryFile ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
AddStartupCommands ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
StartMenu ( true ) ;
2012-11-28 15:47:07 +00:00
while ( Sys_Milliseconds ( ) - legalStartTime < legalMinTime )
{
2012-11-26 18:58:24 +00:00
RenderSplash ( ) ;
Sys_GenerateEvents ( ) ;
Sys_Sleep ( 10 ) ;
} ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// print all warnings queued during initialization
PrintWarnings ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// remove any prints from the notify lines
console - > ClearNotifyLines ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
CheckStartupStorageRequirements ( ) ;
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
fileSystem - > EndLevelLoad ( ) ;
2012-11-28 15:47:07 +00:00
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 " ) ;
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
com_fullyInitialized = true ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// No longer need the splash screen
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
Printf ( " --- Common Initialization Complete --- \n " ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
idLib : : Printf ( " QA Timing IIS: %06dms \n " , Sys_Milliseconds ( ) ) ;
2012-11-28 15:47:07 +00:00
}
catch ( idException & )
{
2012-11-26 18:58:24 +00:00
Sys_Error ( " Error during initialization " ) ;
}
}
/*
= = = = = = = = = = = = = = = = =
idCommonLocal : : Shutdown
= = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idCommonLocal : : Shutdown ( )
{
2012-11-26 18:58:24 +00:00
2012-11-28 15:47:07 +00:00
if ( com_shuttingDown )
{
2012-11-26 18:58:24 +00:00
return ;
}
com_shuttingDown = true ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// Kill any pending saves...
printf ( " session->GetSaveGameManager().CancelToTerminate(); \n " ) ;
session - > GetSaveGameManager ( ) . CancelToTerminate ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// kill sound first
printf ( " soundSystem->StopAllSounds(); \n " ) ;
soundSystem - > StopAllSounds ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// shutdown the script debugger
// DebuggerServerShutdown();
2012-11-28 15:47:07 +00:00
if ( aviCaptureMode )
{
2012-11-26 18:58:24 +00:00
printf ( " EndAVICapture(); \n " ) ;
EndAVICapture ( ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
printf ( " Stop(); \n " ) ;
Stop ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
printf ( " CleanupShell(); \n " ) ;
CleanupShell ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
printf ( " delete loadGUI; \n " ) ;
delete loadGUI ;
loadGUI = NULL ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
printf ( " delete renderWorld; \n " ) ;
delete renderWorld ;
renderWorld = NULL ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
printf ( " delete soundWorld; \n " ) ;
delete soundWorld ;
soundWorld = NULL ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
printf ( " delete menuSoundWorld; \n " ) ;
delete menuSoundWorld ;
menuSoundWorld = NULL ;
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// shutdown, deallocate leaderboard definitions.
2012-11-28 15:47:07 +00:00
if ( game ! = NULL )
{
2012-11-26 18:58:24 +00:00
printf ( " game->Leaderboards_Shutdown(); \n " ) ;
game - > Leaderboards_Shutdown ( ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// shut down the user interfaces
printf ( " uiManager->Shutdown(); \n " ) ;
uiManager - > Shutdown ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// shut down the sound system
printf ( " soundSystem->Shutdown(); \n " ) ;
soundSystem - > Shutdown ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// shut down the user command input code
printf ( " usercmdGen->Shutdown(); \n " ) ;
usercmdGen - > Shutdown ( ) ;
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// shut down the renderSystem
printf ( " renderSystem->Shutdown(); \n " ) ;
renderSystem - > Shutdown ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
printf ( " commonDialog.Shutdown(); \n " ) ;
commonDialog . Shutdown ( ) ;
// unload the game dll
printf ( " UnloadGameDLL(); \n " ) ;
UnloadGameDLL ( ) ;
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// shut down the file system
printf ( " fileSystem->Shutdown( false ); \n " ) ;
fileSystem - > Shutdown ( false ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// shut down non-portable system services
printf ( " Sys_Shutdown(); \n " ) ;
Sys_Shutdown ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// shut down the console
printf ( " console->Shutdown(); \n " ) ;
console - > Shutdown ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// shut down the key system
printf ( " idKeyInput::Shutdown(); \n " ) ;
idKeyInput : : Shutdown ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// shut down the cvar system
printf ( " cvarSystem->Shutdown(); \n " ) ;
cvarSystem - > Shutdown ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// shut down the console command system
printf ( " cmdSystem->Shutdown(); \n " ) ;
cmdSystem - > Shutdown ( ) ;
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// shutdown idLib
printf ( " idLib::ShutDown(); \n " ) ;
idLib : : ShutDown ( ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idCommonLocal : : CreateMainMenu
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
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
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idCommonLocal : : Stop ( bool resetSession )
{
2012-11-26 18:58:24 +00:00
ClearWipe ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// clear mapSpawned and demo playing flags
UnloadMap ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
soundSystem - > StopAllSounds ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
insideUpdateScreen = false ;
insideExecuteMapChange = false ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// drop all guis
ExitMenu ( ) ;
2012-11-28 15:47:07 +00:00
if ( resetSession )
{
2012-11-26 18:58:24 +00:00
session - > QuitMatchToTitle ( ) ;
}
}
/*
= = = = = = = = = = = = = = =
idCommonLocal : : BusyWait
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idCommonLocal : : BusyWait ( )
{
2012-11-26 18:58:24 +00:00
Sys_GenerateEvents ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
const bool captureToImage = false ;
UpdateScreen ( captureToImage ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
session - > UpdateSignInManager ( ) ;
session - > Pump ( ) ;
}
/*
= = = = = = = = = = = = = = =
idCommonLocal : : WaitForSessionState
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
bool idCommonLocal : : WaitForSessionState ( idSession : : sessionState_t desiredState )
{
if ( session - > GetState ( ) = = desiredState )
{
2012-11-26 18:58:24 +00:00
return true ;
}
2012-11-28 15:47:07 +00:00
while ( true )
{
2012-11-26 18:58:24 +00:00
BusyWait ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
idSession : : sessionState_t sessionState = session - > GetState ( ) ;
2012-11-28 15:47:07 +00:00
if ( sessionState = = desiredState )
{
2012-11-26 18:58:24 +00:00
return true ;
}
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
Sys_Sleep ( 10 ) ;
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idCommonLocal : : LeaveGame
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idCommonLocal : : LeaveGame ( )
{
2012-11-26 18:58:24 +00:00
const bool captureToImage = false ;
UpdateScreen ( captureToImage ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
ResetNetworkingState ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
Stop ( false ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
CreateMainMenu ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
StartMenu ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = =
idCommonLocal : : ProcessEvent
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
bool idCommonLocal : : ProcessEvent ( const sysEvent_t * event )
{
2012-11-26 18:58:24 +00:00
// hitting escape anywhere brings up the menu
2012-11-28 15:47:07 +00:00
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
2012-11-28 15:47:07 +00:00
if ( MenuEvent ( event ) )
{
2012-11-26 18:58:24 +00:00
return true ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
console - > Close ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
StartMenu ( ) ;
return true ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
console - > Close ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// menus / etc
2012-11-28 15:47:07 +00:00
if ( MenuEvent ( event ) )
{
2012-11-26 18:58:24 +00:00
return true ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
game - > Shell_ClosePause ( ) ;
}
2012-11-28 15:47:07 +00:00
}
2012-11-26 18:58:24 +00:00
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// let the pull-down console take it if desired
2012-11-28 15:47:07 +00:00
if ( console - > ProcessEvent ( event , false ) )
{
2012-11-26 18:58:24 +00:00
return true ;
}
2012-11-28 15:47:07 +00:00
if ( session - > ProcessInputEvent ( event ) )
{
2012-11-26 18:58:24 +00:00
return true ;
}
2012-11-28 15:47:07 +00:00
if ( Dialog ( ) . IsDialogActive ( ) )
{
2012-11-26 18:58:24 +00:00
Dialog ( ) . HandleDialogEvent ( event ) ;
return true ;
}
2012-11-28 15:47:07 +00:00
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.
2012-11-28 15:47:07 +00:00
if ( IsPlayingDoomClassic ( ) )
{
2012-11-26 18:58:24 +00:00
// Translate the event to Doom classic format.
event_t classicEvent ;
2012-11-28 15:47:07 +00:00
if ( event - > evType = = SE_KEY )
{
if ( event - > evValue2 = = 1 )
{
2012-11-26 18:58:24 +00:00
classicEvent . type = ev_keydown ;
2012-11-28 15:47:07 +00:00
}
else if ( event - > evValue2 = = 0 )
{
2012-11-26 18:58:24 +00:00
classicEvent . type = ev_keyup ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
DoomLib : : SetPlayer ( 0 ) ;
2012-11-28 15:47:07 +00:00
extern Globals * g ;
if ( g ! = NULL )
{
2012-11-26 18:58:24 +00:00
classicEvent . data1 = DoomLib : : RemapControl ( event - > GetKey ( ) ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
D_PostEvent ( & classicEvent ) ;
}
DoomLib : : SetPlayer ( - 1 ) ;
}
2012-11-28 15:47:07 +00:00
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-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// menus / etc
2012-11-28 15:47:07 +00:00
if ( MenuEvent ( event ) )
{
2012-11-26 18:58:24 +00:00
return true ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// if we aren't in a game, force the console to take it
2012-11-28 15:47:07 +00:00
if ( ! mapSpawned )
{
2012-11-26 18:58:24 +00:00
console - > ProcessEvent ( event , true ) ;
return true ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// in game, exec bindings for all key downs
2012-11-28 15:47:07 +00:00
if ( event - > evType = = SE_KEY & & event - > evValue2 = = 1 )
{
2012-11-26 18:58:24 +00:00
idKeyInput : : ExecKeyBinding ( event - > evValue ) ;
return true ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
return false ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idCommonLocal : : ResetPlayerInput
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
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
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idCommonLocal : : SwitchToGame ( currentGame_t newGame )
{
2012-11-26 18:58:24 +00:00
idealCurrentGame = newGame ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idCommonLocal : : PerformGameSwitch
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
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.
2012-11-28 15:47:07 +00:00
if ( session - > GetState ( ) > idSession : : IDLE )
{
2012-11-26 18:58:24 +00:00
idealCurrentGame = DOOM3_BFG ;
}
2012-11-28 15:47:07 +00:00
if ( currentGame = = idealCurrentGame )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
const int DOOM_CLASSIC_HZ = 35 ;
2012-11-28 15:47:07 +00:00
if ( idealCurrentGame = = DOOM_CLASSIC | | idealCurrentGame = = DOOM2_CLASSIC )
{
2012-11-26 18:58:24 +00:00
// Pause Doom 3 sound.
2012-11-28 15:47:07 +00:00
if ( menuSoundWorld ! = NULL )
{
2012-11-26 18:58:24 +00:00
menuSoundWorld - > Pause ( ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
DoomLib : : skipToNew = false ;
DoomLib : : skipToLoad = false ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// Reset match parameters for the classics.
DoomLib : : matchParms = idMatchParameters ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// The classics use the usercmd manager too, clear it.
userCmdMgr . SetDefaults ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// Classics need a local user too.
session - > UpdateSignInManager ( ) ;
session - > GetSignInManager ( ) . RegisterLocalUser ( 0 ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
com_engineHz_denominator = 100LL * DOOM_CLASSIC_HZ ;
com_engineHz_latched = DOOM_CLASSIC_HZ ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
DoomLib : : SetCurrentExpansion ( idealCurrentGame ) ;
2012-11-28 15:47:07 +00:00
}
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.
2012-11-28 15:47:07 +00:00
if ( session - > GetState ( ) < = idSession : : IDLE )
{
2012-11-26 18:58:24 +00:00
session - > MoveToPressStart ( ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// Unpause Doom 3 sound.
2012-11-28 15:47:07 +00:00
if ( menuSoundWorld ! = NULL )
{
2012-11-26 18:58:24 +00:00
menuSoundWorld - > UnPause ( ) ;
}
}
2012-11-28 15:47:07 +00:00
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
= = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
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 ;
}
2012-11-28 15:47:07 +00:00
idStr str = args . Argv ( 1 ) ;
2012-11-26 18:58:24 +00:00
str . DefaultFileExtension ( " .cfg " ) ;
2012-11-28 15:47:07 +00:00
idFile * f = fileSystem - > OpenFileWrite ( str ) ;
2012-11-26 18:58:24 +00:00
declManager - > WritePrecacheCommands ( f ) ;
renderModelManager - > WritePrecacheCommands ( f ) ;
uiManager - > WritePrecacheCommands ( f ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
fileSystem - > CloseFile ( f ) ;
}
/*
= = = = = = = = = = = = = = = =
Common_Disconnect_f
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
CONSOLE_COMMAND_SHIP ( disconnect , " disconnects from a game " , NULL )
{
2012-11-26 18:58:24 +00:00
session - > QuitMatch ( ) ;
}
/*
= = = = = = = = = = = = = = =
Common_Hitch_f
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
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 ) ;
}
}
2012-11-28 15:47:07 +00:00
CONSOLE_COMMAND ( showStringMemory , " shows memory used by strings " , NULL )
{
2012-11-26 18:58:24 +00:00
idStr : : ShowMemoryUsage_f ( args ) ;
}
2012-11-28 15:47:07 +00:00
CONSOLE_COMMAND ( showDictMemory , " shows memory used by dictionaries " , NULL )
{
2012-11-26 18:58:24 +00:00
idDict : : ShowMemoryUsage_f ( args ) ;
}
2012-11-28 15:47:07 +00:00
CONSOLE_COMMAND ( listDictKeys , " lists all keys used by dictionaries " , NULL )
{
2012-11-26 18:58:24 +00:00
idDict : : ListKeys_f ( args ) ;
}
2012-11-28 15:47:07 +00:00
CONSOLE_COMMAND ( listDictValues , " lists all values used by dictionaries " , NULL )
{
2012-11-26 18:58:24 +00:00
idDict : : ListValues_f ( args ) ;
}
2012-11-28 15:47:07 +00:00
CONSOLE_COMMAND ( testSIMD , " test SIMD code " , NULL )
{
2012-11-26 18:58:24 +00:00
idSIMD : : Test_f ( args ) ;
}