2007-06-21 22:00:00 +02:00
|
|
|
|
//=======================================================================
|
|
|
|
|
// Copyright XashXT Group 2007 <20>
|
|
|
|
|
// host.c - dedicated and shared host
|
|
|
|
|
//=======================================================================
|
|
|
|
|
|
2008-06-09 22:00:00 +02:00
|
|
|
|
#include "common.h"
|
2008-08-04 22:00:00 +02:00
|
|
|
|
#include "input.h"
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2009-11-23 22:00:00 +01:00
|
|
|
|
#define MAX_SYSEVENTS 1024 // system events
|
2009-10-02 22:00:00 +02:00
|
|
|
|
|
2007-11-24 22:00:00 +01:00
|
|
|
|
physic_exp_t *pe;
|
2007-11-17 22:00:00 +01:00
|
|
|
|
render_exp_t *re;
|
2008-06-12 22:00:00 +02:00
|
|
|
|
vsound_exp_t *se;
|
2007-09-03 22:00:00 +02:00
|
|
|
|
host_parm_t host; // host parms
|
2007-11-30 22:00:00 +01:00
|
|
|
|
stdlib_api_t com, newcom;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2009-10-02 22:00:00 +02:00
|
|
|
|
char *buildstring = __TIME__ " " __DATE__;
|
2007-09-02 22:00:00 +02:00
|
|
|
|
|
2009-10-02 22:00:00 +02:00
|
|
|
|
dll_info_t render_dll = { "", NULL, "CreateAPI", NULL, NULL, 0, sizeof(render_exp_t), sizeof(stdlib_api_t) };
|
|
|
|
|
dll_info_t vsound_dll = { "", NULL, "CreateAPI", NULL, NULL, 0, sizeof(vsound_exp_t), sizeof(stdlib_api_t) };
|
2010-06-17 22:00:00 +02:00
|
|
|
|
dll_info_t physic_dll = { "physic.dll", NULL, "CreateAPI", NULL, NULL, 0, sizeof(physic_exp_t), sizeof(stdlib_api_t) };
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2010-03-30 22:00:00 +02:00
|
|
|
|
cvar_t *sys_sharedstrings;
|
2007-11-14 22:00:00 +01:00
|
|
|
|
cvar_t *host_serverstate;
|
2007-11-25 22:00:00 +01:00
|
|
|
|
cvar_t *host_cheats;
|
2009-09-16 22:00:00 +02:00
|
|
|
|
cvar_t *host_maxfps;
|
2010-04-20 22:00:00 +02:00
|
|
|
|
cvar_t *host_nosound;
|
2009-02-03 22:00:00 +01:00
|
|
|
|
cvar_t *host_framerate;
|
2008-08-01 22:00:00 +02:00
|
|
|
|
cvar_t *host_registered;
|
2009-10-02 22:00:00 +02:00
|
|
|
|
cvar_t *host_video;
|
2009-11-03 22:00:00 +01:00
|
|
|
|
cvar_t *host_audio;
|
2007-11-17 22:00:00 +01:00
|
|
|
|
|
2008-07-31 22:00:00 +02:00
|
|
|
|
// these cvars will be duplicated on each client across network
|
2009-09-25 22:00:00 +02:00
|
|
|
|
int Host_ServerState( void ) { return Cvar_VariableInteger( "host_serverstate" ); }
|
2008-07-06 22:00:00 +02:00
|
|
|
|
|
2009-09-28 22:00:00 +02:00
|
|
|
|
int Host_CompareFileTime( long ft1, long ft2 )
|
|
|
|
|
{
|
|
|
|
|
if( ft1 < ft2 )
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
else if( ft1 > ft2 )
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-13 22:00:00 +02:00
|
|
|
|
void Host_ShutdownServer( void )
|
|
|
|
|
{
|
|
|
|
|
if( !SV_Active()) return;
|
|
|
|
|
com.strncpy( host.finalmsg, "Server was killed\n", MAX_STRING );
|
|
|
|
|
SV_Shutdown( false );
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-25 22:00:00 +01:00
|
|
|
|
/*
|
|
|
|
|
================
|
|
|
|
|
Host_NewGame
|
|
|
|
|
================
|
|
|
|
|
*/
|
|
|
|
|
bool Host_NewGame( const char *mapName, bool loadGame )
|
|
|
|
|
{
|
|
|
|
|
bool iRet;
|
|
|
|
|
|
|
|
|
|
iRet = SV_NewGame( mapName, loadGame );
|
|
|
|
|
|
|
|
|
|
return iRet;
|
|
|
|
|
}
|
2009-10-13 22:00:00 +02:00
|
|
|
|
/*
|
|
|
|
|
================
|
|
|
|
|
Host_EndGame
|
|
|
|
|
================
|
|
|
|
|
*/
|
|
|
|
|
void Host_EndGame( const char *message, ... )
|
|
|
|
|
{
|
|
|
|
|
va_list argptr;
|
|
|
|
|
static char string[MAX_MSGLEN];
|
|
|
|
|
|
|
|
|
|
va_start( argptr, message );
|
|
|
|
|
vsprintf( string, message, argptr );
|
|
|
|
|
va_end( argptr );
|
|
|
|
|
|
|
|
|
|
MsgDev( D_INFO, "Host_EndGame: %s\n", string );
|
|
|
|
|
|
|
|
|
|
if( SV_Active())
|
|
|
|
|
{
|
2010-03-25 22:00:00 +01:00
|
|
|
|
com.snprintf( host.finalmsg, sizeof( host.finalmsg ), "Host_EndGame: %s\n", string );
|
2009-10-13 22:00:00 +02:00
|
|
|
|
SV_Shutdown( false );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( host.type == HOST_DEDICATED )
|
|
|
|
|
Sys_Break( "Host_EndGame: %s\n", string ); // dedicated servers exit
|
|
|
|
|
|
2009-11-03 22:00:00 +01:00
|
|
|
|
if( CL_NextDemo( ));
|
|
|
|
|
else CL_Disconnect();
|
2009-10-13 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
Host_AbortCurrentFrame ();
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-03 22:00:00 +01:00
|
|
|
|
static void Host_DrawDebug( cmdraw_t callback )
|
2007-10-22 22:00:00 +02:00
|
|
|
|
{
|
2009-11-03 22:00:00 +01:00
|
|
|
|
if( pe ) pe->DrawCollision( callback );
|
2007-10-22 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Host_FreePhysic( void )
|
|
|
|
|
{
|
2009-11-03 22:00:00 +01:00
|
|
|
|
if( physic_dll.link )
|
2007-10-22 22:00:00 +02:00
|
|
|
|
{
|
2007-11-24 22:00:00 +01:00
|
|
|
|
pe->Shutdown();
|
2009-11-03 22:00:00 +01:00
|
|
|
|
Mem_Set( &pe, 0, sizeof( pe ));
|
2007-10-22 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
Sys_FreeLibrary( &physic_dll );
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-03 22:00:00 +01:00
|
|
|
|
bool Host_InitPhysic( void )
|
|
|
|
|
{
|
|
|
|
|
static physic_imp_t pi;
|
|
|
|
|
launch_t CreatePhysic;
|
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
|
|
// phys callback
|
|
|
|
|
pi.api_size = sizeof( physic_imp_t );
|
|
|
|
|
|
2010-06-18 22:00:00 +02:00
|
|
|
|
Sys_LoadLibrary( NULL, &physic_dll );
|
2009-11-03 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
if( physic_dll.link )
|
|
|
|
|
{
|
|
|
|
|
CreatePhysic = (void *)physic_dll.main;
|
|
|
|
|
pe = CreatePhysic( &newcom, &pi );
|
|
|
|
|
|
|
|
|
|
if( pe->Init( )) result = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// video system not started, shutdown refresh subsystem
|
|
|
|
|
if( !result ) Host_FreePhysic();
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-02 22:00:00 +02:00
|
|
|
|
void Host_FreeRender( void )
|
|
|
|
|
{
|
|
|
|
|
if( render_dll.link )
|
|
|
|
|
{
|
|
|
|
|
SCR_Shutdown ();
|
|
|
|
|
re->Shutdown( true );
|
|
|
|
|
Mem_Set( &re, 0, sizeof( re ));
|
|
|
|
|
}
|
|
|
|
|
Sys_FreeLibrary( &render_dll );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Host_InitRender( void )
|
|
|
|
|
{
|
|
|
|
|
static render_imp_t ri;
|
|
|
|
|
launch_t CreateRender;
|
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
|
|
ri.api_size = sizeof( render_imp_t );
|
2007-11-17 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
// studio callbacks
|
2008-11-08 22:00:00 +01:00
|
|
|
|
ri.UpdateScreen = SCR_UpdateScreen;
|
2007-11-17 22:00:00 +01:00
|
|
|
|
ri.StudioEvent = CL_StudioEvent;
|
2009-09-03 22:00:00 +02:00
|
|
|
|
ri.StudioFxTransform = CL_StudioFxTransform;
|
2009-11-03 22:00:00 +01:00
|
|
|
|
ri.ShowCollision = Host_DrawDebug;
|
2009-10-15 22:00:00 +02:00
|
|
|
|
ri.GetAttachment = CL_GetAttachment;
|
|
|
|
|
ri.SetAttachment = CL_SetAttachment;
|
2008-08-05 22:00:00 +02:00
|
|
|
|
ri.GetClientEdict = CL_GetEdictByIndex;
|
2010-04-04 22:00:00 +02:00
|
|
|
|
ri.GetLerpFrame = CL_GetLerpFrame;
|
2009-10-15 22:00:00 +02:00
|
|
|
|
ri.GetMouthOpen = CL_GetMouthOpen;
|
2008-08-05 22:00:00 +02:00
|
|
|
|
ri.GetLocalPlayer = CL_GetLocalPlayer;
|
|
|
|
|
ri.GetMaxClients = CL_GetMaxClients;
|
2009-09-18 22:00:00 +02:00
|
|
|
|
ri.GetLerpFrac = CL_GetLerpFrac;
|
2009-12-07 22:00:00 +01:00
|
|
|
|
ri.DrawTriangles = Tri_DrawTriangles;
|
2009-11-23 22:00:00 +01:00
|
|
|
|
ri.RoQ_ReadChunk = CIN_ReadChunk;
|
|
|
|
|
ri.RoQ_ReadNextFrame = CIN_ReadNextFrame;
|
2009-10-15 22:00:00 +02:00
|
|
|
|
ri.WndProc = IN_WndProc;
|
|
|
|
|
|
2009-10-02 22:00:00 +02:00
|
|
|
|
Sys_LoadLibrary( host_video->string, &render_dll );
|
2007-11-17 22:00:00 +01:00
|
|
|
|
|
2008-08-04 22:00:00 +02:00
|
|
|
|
if( render_dll.link )
|
|
|
|
|
{
|
|
|
|
|
CreateRender = (void *)render_dll.main;
|
|
|
|
|
re = CreateRender( &newcom, &ri );
|
|
|
|
|
|
2008-11-15 22:00:00 +01:00
|
|
|
|
if( re->Init( true )) result = true;
|
2008-08-04 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2009-10-02 22:00:00 +02:00
|
|
|
|
// video system not started, shutdown refresh subsystem
|
|
|
|
|
if( !result ) Host_FreeRender();
|
2007-11-17 22:00:00 +01:00
|
|
|
|
|
2009-10-02 22:00:00 +02:00
|
|
|
|
return result;
|
2008-06-04 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-12-03 22:00:00 +01:00
|
|
|
|
void Host_FreeSound( void )
|
|
|
|
|
{
|
|
|
|
|
if( vsound_dll.link )
|
|
|
|
|
{
|
|
|
|
|
se->Shutdown();
|
|
|
|
|
Mem_Set( &se, 0, sizeof( se ));
|
|
|
|
|
}
|
|
|
|
|
Sys_FreeLibrary( &vsound_dll );
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-02 22:00:00 +02:00
|
|
|
|
bool Host_InitSound( void )
|
2008-06-12 22:00:00 +02:00
|
|
|
|
{
|
2009-10-02 22:00:00 +02:00
|
|
|
|
static vsound_imp_t si;
|
|
|
|
|
launch_t CreateSound;
|
|
|
|
|
bool result = false;
|
2008-06-12 22:00:00 +02:00
|
|
|
|
|
2010-04-20 22:00:00 +02:00
|
|
|
|
if( host_nosound->integer )
|
|
|
|
|
return result;
|
|
|
|
|
|
2009-10-02 22:00:00 +02:00
|
|
|
|
si.api_size = sizeof( vsound_imp_t );
|
2010-04-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
// sound callbacks
|
|
|
|
|
si.GetEntitySpatialization = CL_GetEntitySpatialization;
|
|
|
|
|
si.TraceLine = CL_TraceLine;
|
2010-06-24 22:00:00 +02:00
|
|
|
|
si.AmbientLevels = CL_AmbientLevels;
|
2009-10-10 22:00:00 +02:00
|
|
|
|
si.GetClientEdict = CL_GetEdictByIndex;
|
2010-04-21 22:00:00 +02:00
|
|
|
|
si.GetEntityMouth = CL_GetEntityMouth;
|
2009-10-02 22:00:00 +02:00
|
|
|
|
si.GetServerTime = CL_GetServerTime;
|
2010-07-01 22:00:00 +02:00
|
|
|
|
si.IsInMenu = CL_IsInMenu;
|
2010-04-21 22:00:00 +02:00
|
|
|
|
si.IsActive = CL_Active;
|
2008-06-12 22:00:00 +02:00
|
|
|
|
|
2009-10-02 22:00:00 +02:00
|
|
|
|
Sys_LoadLibrary( host_audio->string, &vsound_dll );
|
2008-06-12 22:00:00 +02:00
|
|
|
|
|
2008-12-03 22:00:00 +01:00
|
|
|
|
if( vsound_dll.link )
|
2008-06-12 22:00:00 +02:00
|
|
|
|
{
|
2008-12-03 22:00:00 +01:00
|
|
|
|
CreateSound = (void *)vsound_dll.main;
|
|
|
|
|
se = CreateSound( &newcom, &si );
|
|
|
|
|
|
|
|
|
|
if( se->Init( host.hWnd )) result = true;
|
2008-06-12 22:00:00 +02:00
|
|
|
|
}
|
2008-12-03 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
// audio system not started, shutdown sound subsystem
|
|
|
|
|
if( !result ) Host_FreeSound();
|
2009-10-02 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Host_CheckChanges( void )
|
|
|
|
|
{
|
|
|
|
|
int num_changes;
|
2010-04-20 22:00:00 +02:00
|
|
|
|
bool audio_disabled = false;
|
|
|
|
|
|
|
|
|
|
if( host_nosound->integer )
|
|
|
|
|
{
|
|
|
|
|
if( host.state == HOST_INIT )
|
|
|
|
|
audio_disabled = true;
|
|
|
|
|
host_audio->modified = false;
|
|
|
|
|
}
|
2009-10-02 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
if( host_video->modified || host_audio->modified )
|
|
|
|
|
{
|
2009-11-16 22:00:00 +01:00
|
|
|
|
S_StopAllSounds(); // don't let them loop during the restart
|
2009-10-02 22:00:00 +02:00
|
|
|
|
|
2009-11-03 22:00:00 +01:00
|
|
|
|
if( host_video->modified ) CL_ForceVid();
|
|
|
|
|
if( host_audio->modified ) CL_ForceSnd();
|
2009-10-02 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
else return;
|
|
|
|
|
|
|
|
|
|
num_changes = 0;
|
|
|
|
|
|
2010-07-01 22:00:00 +02:00
|
|
|
|
if( host_video->modified && CL_Active( ))
|
|
|
|
|
{
|
|
|
|
|
// we're in game and want keep decals when renderer is changed
|
|
|
|
|
host.decalList = (decallist_t *)Z_Malloc(sizeof( decallist_t ) * MAX_DECALS );
|
|
|
|
|
host.numdecals = CL_CreateDecalList( host.decalList, false );
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-02 22:00:00 +02:00
|
|
|
|
// restart or change renderer
|
|
|
|
|
while( host_video->modified )
|
|
|
|
|
{
|
2010-03-25 22:00:00 +01:00
|
|
|
|
host_video->modified = false; // predict state
|
2009-10-02 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
Host_FreeRender(); // release render.dll
|
|
|
|
|
if( !Host_InitRender( )) // load it again
|
|
|
|
|
{
|
2010-07-18 22:00:00 +02:00
|
|
|
|
if( num_changes > host.num_video_dlls )
|
2009-10-02 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
Sys_NewInstance( va("#%s", GI->gamefolder ), "fallback to dedicated mode\n" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-07-18 22:00:00 +02:00
|
|
|
|
if( !com.strcmp( host.video_dlls[num_changes], host_video->string ))
|
2009-10-02 22:00:00 +02:00
|
|
|
|
num_changes++; // already trying - failed
|
2010-07-18 22:00:00 +02:00
|
|
|
|
Cvar_FullSet( "host_video", host.video_dlls[num_changes], CVAR_SYSTEMINFO );
|
2009-10-02 22:00:00 +02:00
|
|
|
|
num_changes++;
|
|
|
|
|
}
|
|
|
|
|
else SCR_Init ();
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-20 22:00:00 +02:00
|
|
|
|
if( audio_disabled ) MsgDev( D_INFO, "Audio: Disabled\n" );
|
|
|
|
|
|
2009-10-02 22:00:00 +02:00
|
|
|
|
num_changes = 0;
|
|
|
|
|
|
|
|
|
|
// restart or change sound engine
|
|
|
|
|
while( host_audio->modified )
|
|
|
|
|
{
|
2010-03-25 22:00:00 +01:00
|
|
|
|
host_audio->modified = false; // predict state
|
2009-10-02 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
Host_FreeSound(); // release sound.dll
|
|
|
|
|
if( !Host_InitSound( )) // load it again
|
|
|
|
|
{
|
2010-07-18 22:00:00 +02:00
|
|
|
|
if( num_changes > host.num_audio_dlls )
|
2009-10-02 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
MsgDev( D_ERROR, "couldn't initialize sound system\n" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-07-18 22:00:00 +02:00
|
|
|
|
if( !com.strcmp( host.audio_dlls[num_changes], host_audio->string ))
|
2009-10-02 22:00:00 +02:00
|
|
|
|
num_changes++; // already trying - failed
|
2010-07-18 22:00:00 +02:00
|
|
|
|
Cvar_FullSet( "host_audio", host.audio_dlls[num_changes], CVAR_SYSTEMINFO );
|
2009-10-02 22:00:00 +02:00
|
|
|
|
num_changes++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-06-12 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-10 22:00:00 +02:00
|
|
|
|
/*
|
|
|
|
|
================
|
|
|
|
|
Host_AbortCurrentFrame
|
|
|
|
|
|
|
|
|
|
aborts the current host frame and goes on with the next one
|
|
|
|
|
================
|
|
|
|
|
*/
|
|
|
|
|
void Host_AbortCurrentFrame( void )
|
|
|
|
|
{
|
2008-05-18 22:00:00 +02:00
|
|
|
|
longjmp( host.abortframe, 1 );
|
2007-09-10 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-14 22:00:00 +01:00
|
|
|
|
/*
|
|
|
|
|
==================
|
|
|
|
|
Host_SetServerState
|
|
|
|
|
==================
|
|
|
|
|
*/
|
|
|
|
|
void Host_SetServerState( int state )
|
|
|
|
|
{
|
2008-07-31 22:00:00 +02:00
|
|
|
|
Cvar_SetValue( "host_serverstate", state );
|
2007-11-14 22:00:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
2007-06-21 22:00:00 +02:00
|
|
|
|
/*
|
|
|
|
|
=================
|
2007-11-17 22:00:00 +01:00
|
|
|
|
Host_VidRestart_f
|
|
|
|
|
|
|
|
|
|
Restart the video subsystem
|
2007-06-21 22:00:00 +02:00
|
|
|
|
=================
|
|
|
|
|
*/
|
2007-11-17 22:00:00 +01:00
|
|
|
|
void Host_VidRestart_f( void )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2009-10-02 22:00:00 +02:00
|
|
|
|
host_video->modified = true;
|
2007-11-17 22:00:00 +01:00
|
|
|
|
}
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2008-06-12 22:00:00 +02:00
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
Host_SndRestart_f
|
|
|
|
|
|
|
|
|
|
Restart the audio subsystem
|
|
|
|
|
=================
|
|
|
|
|
*/
|
|
|
|
|
void Host_SndRestart_f( void )
|
|
|
|
|
{
|
2009-10-02 22:00:00 +02:00
|
|
|
|
host_audio->modified = true;
|
2008-06-12 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-03-25 22:00:00 +01:00
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
Host_ChangeGame_f
|
|
|
|
|
|
|
|
|
|
Change game modification
|
|
|
|
|
=================
|
|
|
|
|
*/
|
2008-08-04 22:00:00 +02:00
|
|
|
|
void Host_ChangeGame_f( void )
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if( Cmd_Argc() != 2 )
|
|
|
|
|
{
|
2009-09-10 22:00:00 +02:00
|
|
|
|
Msg( "Usage: game <directory>\n" );
|
2008-08-04 22:00:00 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// validate gamedir
|
2009-09-10 22:00:00 +02:00
|
|
|
|
for( i = 0; i < SI->numgames; i++ )
|
2008-08-04 22:00:00 +02:00
|
|
|
|
{
|
2009-09-10 22:00:00 +02:00
|
|
|
|
if( !com.stricmp( SI->games[i]->gamefolder, Cmd_Argv( 1 )))
|
2008-08-04 22:00:00 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-10 22:00:00 +02:00
|
|
|
|
if( i == SI->numgames ) Msg( "%s not exist\n", Cmd_Argv( 1 ));
|
|
|
|
|
else if( !com.stricmp( GI->gamefolder, Cmd_Argv( 1 )))
|
|
|
|
|
Msg( "%s already active\n", Cmd_Argv( 1 ));
|
|
|
|
|
else Sys_NewInstance( Cmd_Argv( 1 ), "Host_ChangeGame\n" );
|
2008-08-04 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-08-10 22:00:00 +02:00
|
|
|
|
void Host_Minimize_f( void )
|
|
|
|
|
{
|
|
|
|
|
if( host.hWnd ) ShowWindow( host.hWnd, SW_MINIMIZE );
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-20 22:00:00 +02:00
|
|
|
|
bool Host_IsLocalGame( void )
|
|
|
|
|
{
|
|
|
|
|
if( CL_Active() && SV_Active() && CL_GetMaxClients() == 1 )
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-20 22:00:00 +02:00
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
Host_InitEvents
|
|
|
|
|
=================
|
|
|
|
|
*/
|
|
|
|
|
void Host_InitEvents( void )
|
|
|
|
|
{
|
|
|
|
|
Mem_Set( host.events, 0, sizeof( host.events ));
|
|
|
|
|
host.events_head = 0;
|
|
|
|
|
host.events_tail = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
Host_PushEvent
|
|
|
|
|
=================
|
|
|
|
|
*/
|
|
|
|
|
void Host_PushEvent( sys_event_t *event )
|
|
|
|
|
{
|
|
|
|
|
sys_event_t *ev;
|
|
|
|
|
static bool overflow = false;
|
|
|
|
|
|
2009-11-23 22:00:00 +01:00
|
|
|
|
ev = &host.events[host.events_head & (MAX_SYSEVENTS-1)];
|
2009-09-20 22:00:00 +02:00
|
|
|
|
|
2009-11-23 22:00:00 +01:00
|
|
|
|
if( host.events_head - host.events_tail >= MAX_SYSEVENTS )
|
2009-09-20 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
if( !overflow )
|
|
|
|
|
{
|
|
|
|
|
MsgDev( D_WARN, "Host_PushEvent overflow\n" );
|
|
|
|
|
overflow = true;
|
|
|
|
|
}
|
|
|
|
|
if( ev->data ) Mem_Free( ev->data );
|
|
|
|
|
host.events_tail++;
|
|
|
|
|
}
|
|
|
|
|
else overflow = false;
|
|
|
|
|
|
|
|
|
|
*ev = *event;
|
|
|
|
|
host.events_head++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
Host_GetEvent
|
|
|
|
|
=================
|
|
|
|
|
*/
|
|
|
|
|
sys_event_t Host_GetEvent( void )
|
|
|
|
|
{
|
|
|
|
|
if( host.events_head > host.events_tail )
|
|
|
|
|
{
|
|
|
|
|
host.events_tail++;
|
2009-11-23 22:00:00 +01:00
|
|
|
|
return host.events[(host.events_tail - 1) & (MAX_SYSEVENTS-1)];
|
2009-09-20 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
return Sys_GetEvent();
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-06 22:00:00 +02:00
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
Host_EventLoop
|
|
|
|
|
|
|
|
|
|
Returns last event time
|
|
|
|
|
=================
|
|
|
|
|
*/
|
2010-06-20 22:00:00 +02:00
|
|
|
|
bool Host_EventLoop( void )
|
2008-07-06 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
sys_event_t ev;
|
|
|
|
|
|
|
|
|
|
while( 1 )
|
|
|
|
|
{
|
2009-02-03 22:00:00 +01:00
|
|
|
|
ev = Sys_GetEvent();
|
|
|
|
|
switch( ev.type )
|
2008-07-06 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
case SE_NONE:
|
2010-06-20 22:00:00 +02:00
|
|
|
|
// done
|
|
|
|
|
Cbuf_Execute();
|
|
|
|
|
return true;
|
2008-07-06 22:00:00 +02:00
|
|
|
|
case SE_KEY:
|
2010-06-20 22:00:00 +02:00
|
|
|
|
Key_Event( ev.value[0], ev.value[1] );
|
2008-07-06 22:00:00 +02:00
|
|
|
|
break;
|
|
|
|
|
case SE_CHAR:
|
|
|
|
|
CL_CharEvent( ev.value[0] );
|
|
|
|
|
break;
|
|
|
|
|
case SE_MOUSE:
|
2009-02-03 22:00:00 +01:00
|
|
|
|
CL_MouseEvent( ev.value[0], ev.value[1] );
|
2008-07-06 22:00:00 +02:00
|
|
|
|
break;
|
|
|
|
|
case SE_CONSOLE:
|
2009-06-22 22:00:00 +02:00
|
|
|
|
Cbuf_AddText( va( "%s\n", ev.data ));
|
2008-07-12 22:00:00 +02:00
|
|
|
|
break;
|
2008-07-06 22:00:00 +02:00
|
|
|
|
default:
|
2010-06-20 22:00:00 +02:00
|
|
|
|
MsgDev( D_ERROR, "Host_EventLoop: bad event type %i", ev.type );
|
|
|
|
|
return false;
|
2008-07-06 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
if( ev.data ) Mem_Free( ev.data );
|
|
|
|
|
}
|
2010-06-20 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
// shut up the compiler
|
|
|
|
|
return false;
|
2008-07-06 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-16 22:00:00 +02:00
|
|
|
|
/*
|
2010-06-20 22:00:00 +02:00
|
|
|
|
===================
|
|
|
|
|
Host_FilterTime
|
2009-09-16 22:00:00 +02:00
|
|
|
|
|
2010-06-20 22:00:00 +02:00
|
|
|
|
Returns false if the time is too short to run a frame
|
|
|
|
|
===================
|
2009-09-16 22:00:00 +02:00
|
|
|
|
*/
|
2010-06-20 22:00:00 +02:00
|
|
|
|
bool Host_FilterTime( float time )
|
2009-09-16 22:00:00 +02:00
|
|
|
|
{
|
2010-06-20 22:00:00 +02:00
|
|
|
|
static double oldtime;
|
|
|
|
|
float fps;
|
2009-09-16 22:00:00 +02:00
|
|
|
|
|
2010-06-20 22:00:00 +02:00
|
|
|
|
host.realtime += time;
|
2009-09-16 22:00:00 +02:00
|
|
|
|
|
2010-06-20 22:00:00 +02:00
|
|
|
|
// dedicated's tic_rate regulates server frame rate. Don't apply fps filter here.
|
|
|
|
|
fps = host_maxfps->value;
|
2009-09-16 22:00:00 +02:00
|
|
|
|
|
2010-06-20 22:00:00 +02:00
|
|
|
|
if( fps != 0 )
|
2009-09-20 22:00:00 +02:00
|
|
|
|
{
|
2010-06-20 22:00:00 +02:00
|
|
|
|
float minframetime;
|
|
|
|
|
|
|
|
|
|
// limit fps to withing tolerable range
|
|
|
|
|
fps = bound( MIN_FPS, fps, MAX_FPS );
|
|
|
|
|
|
|
|
|
|
minframetime = 1.0f / fps;
|
|
|
|
|
|
|
|
|
|
if(( host.realtime - oldtime ) < minframetime )
|
|
|
|
|
{
|
|
|
|
|
// framerate is too high
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2009-09-20 22:00:00 +02:00
|
|
|
|
}
|
2010-06-20 22:00:00 +02:00
|
|
|
|
|
2010-07-17 22:00:00 +02:00
|
|
|
|
host.frametime = host.realtime - oldtime;
|
|
|
|
|
host.realframetime = bound( MIN_FRAMETIME, host.frametime, MAX_FRAMETIME );
|
2010-06-20 22:00:00 +02:00
|
|
|
|
oldtime = host.realtime;
|
|
|
|
|
|
|
|
|
|
if( host_framerate->value > 0 && ( Host_IsLocalGame() || CL_IsPlaybackDemo() ))
|
2009-09-20 22:00:00 +02:00
|
|
|
|
{
|
2010-06-20 22:00:00 +02:00
|
|
|
|
float fps = host_framerate->value;
|
|
|
|
|
if( fps > 1 ) fps = 1.0f / fps;
|
|
|
|
|
host.frametime = fps;
|
2009-09-20 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
2010-06-20 22:00:00 +02:00
|
|
|
|
{ // don't allow really long or short frames
|
|
|
|
|
host.frametime = bound( MIN_FRAMETIME, host.frametime, MAX_FRAMETIME );
|
2009-09-20 22:00:00 +02:00
|
|
|
|
}
|
2010-06-20 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
return true;
|
2009-09-16 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2007-06-21 22:00:00 +02:00
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
Host_Frame
|
|
|
|
|
=================
|
|
|
|
|
*/
|
2010-06-20 22:00:00 +02:00
|
|
|
|
void Host_Frame( float time )
|
2008-07-06 22:00:00 +02:00
|
|
|
|
{
|
2008-12-20 22:00:00 +01:00
|
|
|
|
if( setjmp( host.abortframe ))
|
2008-07-06 22:00:00 +02:00
|
|
|
|
return;
|
|
|
|
|
|
2010-06-20 22:00:00 +02:00
|
|
|
|
// decide the simulation time
|
|
|
|
|
if( !Host_FilterTime( time ))
|
|
|
|
|
return;
|
2009-09-20 22:00:00 +02:00
|
|
|
|
|
2010-06-20 22:00:00 +02:00
|
|
|
|
Host_EventLoop();
|
2009-09-14 22:00:00 +02:00
|
|
|
|
|
2010-06-20 22:00:00 +02:00
|
|
|
|
rand (); // keep the random time dependent
|
2009-09-14 22:00:00 +02:00
|
|
|
|
|
2010-06-20 22:00:00 +02:00
|
|
|
|
Host_ServerFrame (); // server frame
|
|
|
|
|
Host_ClientFrame (); // client frame
|
2008-07-06 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
host.framecount++;
|
|
|
|
|
}
|
2007-11-14 22:00:00 +01:00
|
|
|
|
/*
|
|
|
|
|
================
|
|
|
|
|
Host_Print
|
|
|
|
|
|
|
|
|
|
Handles cursor positioning, line wrapping, etc
|
|
|
|
|
All console printing must go through this in order to be logged to disk
|
|
|
|
|
If no console is visible, the text will appear at the top of the game window
|
|
|
|
|
================
|
|
|
|
|
*/
|
|
|
|
|
void Host_Print( const char *txt )
|
|
|
|
|
{
|
2008-07-12 22:00:00 +02:00
|
|
|
|
if( host.rd.target )
|
2007-11-14 22:00:00 +01:00
|
|
|
|
{
|
2009-12-04 22:00:00 +01:00
|
|
|
|
if(( com.strlen( txt ) + com.strlen( host.rd.buffer )) > ( host.rd.buffersize - 1 ))
|
2007-11-14 22:00:00 +01:00
|
|
|
|
{
|
2008-07-12 22:00:00 +02:00
|
|
|
|
if( host.rd.flush )
|
2007-11-14 22:00:00 +01:00
|
|
|
|
{
|
2008-07-12 22:00:00 +02:00
|
|
|
|
host.rd.flush( host.rd.address, host.rd.target, host.rd.buffer );
|
2007-11-14 22:00:00 +01:00
|
|
|
|
*host.rd.buffer = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-07-12 22:00:00 +02:00
|
|
|
|
com.strcat( host.rd.buffer, txt );
|
2007-11-14 22:00:00 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Con_Print( txt ); // echo to client console
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-10 22:00:00 +02:00
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
Host_Error
|
|
|
|
|
=================
|
|
|
|
|
*/
|
|
|
|
|
void Host_Error( const char *error, ... )
|
|
|
|
|
{
|
2008-07-23 22:00:00 +02:00
|
|
|
|
static char hosterror1[MAX_MSGLEN];
|
|
|
|
|
static char hosterror2[MAX_MSGLEN];
|
2007-09-10 22:00:00 +02:00
|
|
|
|
static bool recursive = false;
|
|
|
|
|
va_list argptr;
|
|
|
|
|
|
|
|
|
|
va_start( argptr, error );
|
2008-06-09 22:00:00 +02:00
|
|
|
|
com.vsprintf( hosterror1, error, argptr );
|
2007-09-10 22:00:00 +02:00
|
|
|
|
va_end( argptr );
|
|
|
|
|
|
2010-03-27 22:00:00 +01:00
|
|
|
|
CL_WriteMessageHistory (); // before com.error call
|
|
|
|
|
|
2008-11-05 22:00:00 +01:00
|
|
|
|
if( host.framecount < 3 || host.state == HOST_SHUTDOWN )
|
2008-11-04 22:00:00 +01:00
|
|
|
|
{
|
2008-12-25 22:00:00 +01:00
|
|
|
|
Msg( "Host_InitError: " );
|
2008-08-04 22:00:00 +02:00
|
|
|
|
com.error( hosterror1 );
|
2008-11-04 22:00:00 +01:00
|
|
|
|
}
|
2008-11-05 22:00:00 +01:00
|
|
|
|
else if( host.framecount == host.errorframe )
|
|
|
|
|
{
|
|
|
|
|
com.error( "Host_MultiError: %s", hosterror2 );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-08-04 22:00:00 +02:00
|
|
|
|
else Msg( "Host_Error: %s", hosterror1 );
|
2007-09-10 22:00:00 +02:00
|
|
|
|
|
2008-08-04 22:00:00 +02:00
|
|
|
|
if( recursive )
|
2007-09-10 22:00:00 +02:00
|
|
|
|
{
|
2008-11-06 22:00:00 +01:00
|
|
|
|
Msg( "Host_RecursiveError: %s", hosterror2 );
|
2008-08-08 22:00:00 +02:00
|
|
|
|
com.error( va( "%s", hosterror1 ));
|
2007-11-21 22:00:00 +01:00
|
|
|
|
return; // don't multiple executes
|
2007-09-10 22:00:00 +02:00
|
|
|
|
}
|
2007-11-21 22:00:00 +01:00
|
|
|
|
|
2007-09-10 22:00:00 +02:00
|
|
|
|
recursive = true;
|
2008-11-04 22:00:00 +01:00
|
|
|
|
com.strncpy( hosterror2, hosterror1, MAX_MSGLEN );
|
2008-11-06 22:00:00 +01:00
|
|
|
|
host.errorframe = host.framecount; // to avoid multply calls per frame
|
2008-05-18 22:00:00 +02:00
|
|
|
|
com.sprintf( host.finalmsg, "Server crashed: %s\n", hosterror1 );
|
2007-09-10 22:00:00 +02:00
|
|
|
|
|
2007-11-21 22:00:00 +01:00
|
|
|
|
SV_Shutdown( false );
|
2007-09-10 22:00:00 +02:00
|
|
|
|
CL_Drop(); // drop clients
|
|
|
|
|
|
|
|
|
|
recursive = false;
|
|
|
|
|
Host_AbortCurrentFrame();
|
2007-09-22 22:00:00 +02:00
|
|
|
|
host.state = HOST_ERROR;
|
2007-09-10 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Host_Error_f( void )
|
|
|
|
|
{
|
2010-02-18 22:00:00 +01:00
|
|
|
|
const char *error = Cmd_Argv( 1 );
|
|
|
|
|
|
|
|
|
|
if( !*error ) error = "Invoked host error";
|
|
|
|
|
Host_Error( "%s\n", error );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Sys_Error_f( void )
|
|
|
|
|
{
|
|
|
|
|
const char *error = Cmd_Argv( 1 );
|
|
|
|
|
|
|
|
|
|
if( !*error ) error = "Invoked sys error";
|
|
|
|
|
com.error( "%s\n", error );
|
2007-11-17 22:00:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-03-27 22:00:00 +01:00
|
|
|
|
void Net_Error_f( void )
|
|
|
|
|
{
|
|
|
|
|
com.strncpy( host.finalmsg, Cmd_Argv( 1 ), sizeof( host.finalmsg ));
|
|
|
|
|
SV_ForceError();
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-17 22:00:00 +01:00
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
Host_Crash_f
|
|
|
|
|
=================
|
|
|
|
|
*/
|
2009-10-02 22:00:00 +02:00
|
|
|
|
static void Host_Crash_f( void )
|
2007-11-17 22:00:00 +01:00
|
|
|
|
{
|
|
|
|
|
*(int *)0 = 0xffffffff;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-18 22:00:00 +02:00
|
|
|
|
void Host_InitCommon( const int argc, const char **argv )
|
2008-07-06 22:00:00 +02:00
|
|
|
|
{
|
2010-07-18 22:00:00 +02:00
|
|
|
|
dll_info_t check_vid, check_snd;
|
2009-10-02 22:00:00 +02:00
|
|
|
|
search_t *dlls;
|
|
|
|
|
int i;
|
2008-07-06 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
newcom = com;
|
|
|
|
|
|
|
|
|
|
// overload some funcs
|
|
|
|
|
newcom.error = Host_Error;
|
|
|
|
|
|
2010-07-21 22:00:00 +02:00
|
|
|
|
// get developer mode
|
|
|
|
|
host.developer = SI->developer;
|
2008-07-06 22:00:00 +02:00
|
|
|
|
|
2009-09-20 22:00:00 +02:00
|
|
|
|
Host_InitEvents();
|
|
|
|
|
|
2009-09-13 22:00:00 +02:00
|
|
|
|
FS_LoadGameInfo( NULL );
|
2010-04-20 22:00:00 +02:00
|
|
|
|
Image_Init( GI->gameHint, -1 );
|
|
|
|
|
Sound_Init( GI->gameHint, -1 );
|
2009-09-10 22:00:00 +02:00
|
|
|
|
|
2009-11-03 22:00:00 +01:00
|
|
|
|
host.mempool = Mem_AllocPool( "Zone Engine" );
|
2008-07-06 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
IN_Init();
|
2009-10-02 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
// initialize audio\video multi-dlls system
|
2010-07-18 22:00:00 +02:00
|
|
|
|
host.num_video_dlls = host.num_audio_dlls = 0;
|
2009-10-02 22:00:00 +02:00
|
|
|
|
host_video = Cvar_Get( "host_video", "vid_gl.dll", CVAR_SYSTEMINFO, "name of video rendering library" );
|
|
|
|
|
host_audio = Cvar_Get( "host_audio", "snd_al.dll", CVAR_SYSTEMINFO, "name of sound rendering library" );
|
|
|
|
|
|
|
|
|
|
// make sure what global copy has no changed with any dll checking
|
|
|
|
|
Mem_Copy( &check_vid, &render_dll, sizeof( dll_info_t ));
|
|
|
|
|
Mem_Copy( &check_snd, &vsound_dll, sizeof( dll_info_t ));
|
|
|
|
|
|
|
|
|
|
// checking dlls don't invoke crash!
|
|
|
|
|
check_vid.crash = false;
|
|
|
|
|
check_snd.crash = false;
|
|
|
|
|
|
|
|
|
|
dlls = FS_Search( "*.dll", true );
|
|
|
|
|
|
|
|
|
|
// couldn't find any dlls, render is missing (but i'm don't know how laucnher find engine :)
|
|
|
|
|
// probably this should never happen
|
|
|
|
|
if( !dlls ) Sys_NewInstance( "<EFBFBD>", "" );
|
|
|
|
|
|
|
|
|
|
for( i = 0; i < dlls->numfilenames; i++ )
|
|
|
|
|
{
|
|
|
|
|
if(!com.strnicmp( "vid_", dlls->filenames[i], 4 ))
|
|
|
|
|
{
|
|
|
|
|
// make sure what found library is valid
|
|
|
|
|
if( Sys_LoadLibrary( dlls->filenames[i], &check_vid ))
|
|
|
|
|
{
|
2010-07-18 22:00:00 +02:00
|
|
|
|
MsgDev( D_NOTE, "VideoLibrary[%i]: %s\n", host.num_video_dlls, dlls->filenames[i] );
|
|
|
|
|
host.video_dlls[host.num_video_dlls] = copystring( dlls->filenames[i] );
|
2009-10-02 22:00:00 +02:00
|
|
|
|
Sys_FreeLibrary( &check_vid );
|
2010-07-18 22:00:00 +02:00
|
|
|
|
host.num_video_dlls++;
|
2009-10-02 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(!com.strnicmp( "snd_", dlls->filenames[i], 4 ))
|
|
|
|
|
{
|
|
|
|
|
// make sure what found library is valid
|
|
|
|
|
if( Sys_LoadLibrary( dlls->filenames[i], &check_snd ))
|
|
|
|
|
{
|
2010-07-18 22:00:00 +02:00
|
|
|
|
MsgDev( D_NOTE, "AudioLibrary[%i]: %s\n", host.num_audio_dlls, dlls->filenames[i] );
|
|
|
|
|
host.audio_dlls[host.num_audio_dlls] = copystring( dlls->filenames[i] );
|
2009-10-02 22:00:00 +02:00
|
|
|
|
Sys_FreeLibrary( &check_snd );
|
2010-07-18 22:00:00 +02:00
|
|
|
|
host.num_audio_dlls++;
|
2009-10-02 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Mem_Free( dlls );
|
2008-07-06 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Host_FreeCommon( void )
|
|
|
|
|
{
|
|
|
|
|
IN_Shutdown();
|
2009-11-03 22:00:00 +01:00
|
|
|
|
Mem_FreePool( &host.mempool );
|
2008-07-06 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-17 22:00:00 +01:00
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
Host_Init
|
|
|
|
|
=================
|
|
|
|
|
*/
|
2009-08-18 22:00:00 +02:00
|
|
|
|
void Host_Init( const int argc, const char **argv )
|
2007-11-17 22:00:00 +01:00
|
|
|
|
{
|
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
|
|
host.state = HOST_INIT; // initialzation started
|
2009-09-10 22:00:00 +02:00
|
|
|
|
host.type = g_Instance();
|
2007-11-17 22:00:00 +01:00
|
|
|
|
|
2009-01-11 22:00:00 +01:00
|
|
|
|
Host_InitCommon( argc, argv );
|
2007-11-17 22:00:00 +01:00
|
|
|
|
Key_Init();
|
|
|
|
|
|
2010-02-18 22:00:00 +01:00
|
|
|
|
if( host.type != HOST_DEDICATED )
|
|
|
|
|
{
|
|
|
|
|
// get user configuration
|
|
|
|
|
Cbuf_AddText( "exec keys.rc\n" );
|
|
|
|
|
Cbuf_AddText( "exec vars.rc\n" );
|
|
|
|
|
Cbuf_Execute();
|
|
|
|
|
}
|
2007-11-17 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
// init commands and vars
|
2010-03-25 22:00:00 +01:00
|
|
|
|
if( host.developer >= 3 )
|
2007-11-17 22:00:00 +01:00
|
|
|
|
{
|
2010-02-18 22:00:00 +01:00
|
|
|
|
Cmd_AddCommand ( "sys_error", Sys_Error_f, "just throw a fatal error to test shutdown procedures");
|
|
|
|
|
Cmd_AddCommand ( "host_error", Host_Error_f, "just throw a host error to test shutdown procedures");
|
|
|
|
|
Cmd_AddCommand ( "crash", Host_Crash_f, "a way to force a bus error for development reasons");
|
2010-03-27 22:00:00 +01:00
|
|
|
|
Cmd_AddCommand ( "net_error", Net_Error_f, "send network bad message from random place");
|
2007-11-17 22:00:00 +01:00
|
|
|
|
}
|
2008-07-17 22:00:00 +02:00
|
|
|
|
|
2010-04-05 22:00:00 +02:00
|
|
|
|
sys_sharedstrings = Cvar_Get( "sys_sharedstrings", "0", CVAR_INIT|CVAR_ARCHIVE, "hl1 compatible strings" );
|
2009-02-03 22:00:00 +01:00
|
|
|
|
host_cheats = Cvar_Get( "sv_cheats", "1", CVAR_SYSTEMINFO, "allow cheat variables to enable" );
|
2010-06-20 22:00:00 +02:00
|
|
|
|
host_maxfps = Cvar_Get( "fps_max", "72", CVAR_ARCHIVE, "host fps upper limit" );
|
2009-02-03 22:00:00 +01:00
|
|
|
|
host_framerate = Cvar_Get( "host_framerate", "0", 0, "locks frame timing to this value in seconds" );
|
2009-09-20 22:00:00 +02:00
|
|
|
|
host_serverstate = Cvar_Get( "host_serverstate", "0", CVAR_SERVERINFO, "displays current server state" );
|
2008-08-01 22:00:00 +02:00
|
|
|
|
host_registered = Cvar_Get( "registered", "1", CVAR_SYSTEMINFO, "indicate shareware version of game" );
|
2010-04-20 22:00:00 +02:00
|
|
|
|
host_nosound = Cvar_Get( "host_nosound", "0", CVAR_SYSTEMINFO, "disable sound system" );
|
2007-11-17 22:00:00 +01:00
|
|
|
|
|
2010-05-04 22:00:00 +02:00
|
|
|
|
s = va( "^1Xash %g ^3%s", SI->version, buildstring );
|
2010-01-31 22:00:00 +01:00
|
|
|
|
Cvar_Get( "version", s, CVAR_INIT, "engine current version" );
|
2008-07-11 22:00:00 +02:00
|
|
|
|
|
2010-04-17 22:00:00 +02:00
|
|
|
|
// content control
|
|
|
|
|
Cvar_Get( "violence_hgibs", "1", CVAR_SYSTEMINFO, "content control disables human gibs" );
|
|
|
|
|
Cvar_Get( "violence_agibs", "1", CVAR_SYSTEMINFO, "content control disables alien gibs" );
|
|
|
|
|
Cvar_Get( "violence_hblood", "1", CVAR_SYSTEMINFO, "content control disables human blood" );
|
|
|
|
|
Cvar_Get( "violence_ablood", "1", CVAR_SYSTEMINFO, "content control disables alien blood" );
|
|
|
|
|
|
2007-11-17 22:00:00 +01:00
|
|
|
|
NET_Init();
|
|
|
|
|
Netchan_Init();
|
2010-06-18 22:00:00 +02:00
|
|
|
|
Host_InitPhysic();
|
2008-07-11 22:00:00 +02:00
|
|
|
|
|
2007-11-17 22:00:00 +01:00
|
|
|
|
SV_Init();
|
|
|
|
|
CL_Init();
|
2008-07-06 22:00:00 +02:00
|
|
|
|
|
2009-09-10 22:00:00 +02:00
|
|
|
|
Host_WriteDefaultConfig ();
|
|
|
|
|
|
2009-07-12 22:00:00 +02:00
|
|
|
|
if( host.type == HOST_DEDICATED )
|
|
|
|
|
{
|
2009-09-10 22:00:00 +02:00
|
|
|
|
Cmd_AddCommand( "quit", Sys_Quit, "quit the game" );
|
|
|
|
|
Cmd_AddCommand( "exit", Sys_Quit, "quit the game" );
|
2010-01-30 22:00:00 +01:00
|
|
|
|
Cbuf_AddText( "exec server.rc\n" ); // dedicated servers using settings from server.rc file
|
2009-07-12 22:00:00 +02:00
|
|
|
|
}
|
2009-10-02 22:00:00 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Cmd_AddCommand( "minimize", Host_Minimize_f, "minimize main window to tray" );
|
|
|
|
|
Cmd_AddCommand( "vid_restart", Host_VidRestart_f, "restarts video system" );
|
|
|
|
|
Cmd_AddCommand( "snd_restart", Host_SndRestart_f, "restarts audio system" );
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-18 22:00:00 +02:00
|
|
|
|
// allow to change game from the console
|
|
|
|
|
Cmd_AddCommand( "game", Host_ChangeGame_f, "change game" );
|
|
|
|
|
|
2008-11-04 22:00:00 +01:00
|
|
|
|
host.errorframe = 0;
|
2010-01-30 22:00:00 +01:00
|
|
|
|
Cbuf_Execute();
|
2007-11-17 22:00:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
Host_Main
|
|
|
|
|
=================
|
|
|
|
|
*/
|
|
|
|
|
void Host_Main( void )
|
|
|
|
|
{
|
2010-06-20 22:00:00 +02:00
|
|
|
|
static double oldtime, newtime;
|
|
|
|
|
|
|
|
|
|
oldtime = Sys_DoubleTime();
|
|
|
|
|
|
2007-11-17 22:00:00 +01:00
|
|
|
|
// main window message loop
|
2010-06-30 22:00:00 +02:00
|
|
|
|
while( host.type != HOST_OFFLINE )
|
2007-11-17 22:00:00 +01:00
|
|
|
|
{
|
2008-07-06 22:00:00 +02:00
|
|
|
|
IN_Frame();
|
2010-06-20 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
newtime = Sys_DoubleTime ();
|
|
|
|
|
Host_Frame( newtime - oldtime );
|
|
|
|
|
oldtime = newtime;
|
2007-11-17 22:00:00 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
Host_Shutdown
|
|
|
|
|
=================
|
|
|
|
|
*/
|
|
|
|
|
void Host_Free( void )
|
|
|
|
|
{
|
2009-09-28 22:00:00 +02:00
|
|
|
|
if( host.state == HOST_SHUTDOWN )
|
|
|
|
|
return;
|
|
|
|
|
|
2008-06-06 22:00:00 +02:00
|
|
|
|
host.state = HOST_SHUTDOWN; // prepare host to normal shutdown
|
|
|
|
|
com.strncpy( host.finalmsg, "Server shutdown\n", MAX_STRING );
|
|
|
|
|
|
2007-11-17 22:00:00 +01:00
|
|
|
|
Host_FreeRender();
|
2010-02-28 22:00:00 +01:00
|
|
|
|
Host_FreeSound();
|
2007-11-17 22:00:00 +01:00
|
|
|
|
Host_FreePhysic();
|
2010-06-16 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
SV_Shutdown( false );
|
|
|
|
|
CL_Shutdown();
|
2010-02-28 22:00:00 +01:00
|
|
|
|
NET_Shutdown();
|
2007-11-17 22:00:00 +01:00
|
|
|
|
Host_FreeCommon();
|
2009-11-23 22:00:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
Engine entry point
|
|
|
|
|
=================
|
|
|
|
|
*/
|
|
|
|
|
launch_exp_t DLLEXPORT *CreateAPI( stdlib_api_t *input, void *unused )
|
|
|
|
|
{
|
|
|
|
|
static launch_exp_t Host;
|
|
|
|
|
|
|
|
|
|
com = *input;
|
|
|
|
|
Host.api_size = sizeof( launch_exp_t );
|
|
|
|
|
Host.com_size = sizeof( stdlib_api_t );
|
|
|
|
|
|
|
|
|
|
Host.Init = Host_Init;
|
|
|
|
|
Host.Main = Host_Main;
|
|
|
|
|
Host.Free = Host_Free;
|
|
|
|
|
Host.CPrint = Host_Print;
|
2010-02-02 22:00:00 +01:00
|
|
|
|
Host.CmdForward = Cmd_ForwardToServer;
|
2010-02-18 22:00:00 +01:00
|
|
|
|
Host.CmdComplete = Cmd_AutoComplete;
|
2009-11-23 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
return &Host;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|