This repository has been archived on 2022-06-27. You can view files and clone it, but cannot push or open issues or pull requests.
Xash3DArchive/engine/client/cl_cmds.c

487 lines
10 KiB
C
Raw Normal View History

2011-05-09 22:00:00 +02:00
/*
cl_cmds.c - client console commnds
Copyright (C) 2007 Uncle Mike
This program 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.
This program 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.
*/
2007-11-06 22:00:00 +01:00
2008-06-09 22:00:00 +02:00
#include "common.h"
2007-11-06 22:00:00 +01:00
#include "client.h"
2011-04-06 22:00:00 +02:00
#include "gl_local.h"
2007-11-06 22:00:00 +01:00
2008-08-04 22:00:00 +02:00
/*
====================
CL_PlayVideo_f
movie <moviename>
====================
*/
void CL_PlayVideo_f( void )
{
2010-10-09 22:00:00 +02:00
string path;
if( Cmd_Argc() != 2 && Cmd_Argc() != 3 )
2008-08-04 22:00:00 +02:00
{
2018-03-01 22:00:00 +01:00
Con_Printf( S_USAGE "movie <moviename> [full]\n" );
2008-08-04 22:00:00 +02:00
return;
}
2010-08-12 22:00:00 +02:00
2008-08-04 22:00:00 +02:00
if( cls.state == ca_active )
{
2018-03-01 22:00:00 +01:00
Con_Printf( "Can't play movie while connected to a server.\nPlease disconnect first.\n" );
2008-08-04 22:00:00 +02:00
return;
}
2010-08-12 22:00:00 +02:00
2010-10-09 22:00:00 +02:00
switch( Cmd_Argc( ))
{
case 2: // simple user version
2011-03-09 22:00:00 +01:00
Q_snprintf( path, sizeof( path ), "media/%s.avi", Cmd_Argv( 1 ));
2010-10-09 22:00:00 +02:00
SCR_PlayCinematic( path );
break;
case 3: // sequenced cinematics used this
SCR_PlayCinematic( Cmd_Argv( 1 ));
break;
}
2008-08-04 22:00:00 +02:00
}
2008-08-02 22:00:00 +02:00
/*
===============
2010-11-19 22:00:00 +01:00
CL_PlayCDTrack_f
2011-04-08 22:00:00 +02:00
Emulate audio-cd system
2010-11-19 22:00:00 +01:00
===============
*/
void CL_PlayCDTrack_f( void )
{
const char *command;
2018-02-12 22:00:00 +01:00
const char *pszTrack;
2010-11-19 22:00:00 +01:00
static int track = 0;
static qboolean paused = false;
static qboolean looped = false;
2011-09-03 22:00:00 +02:00
static qboolean enabled = true;
2010-11-19 22:00:00 +01:00
if( Cmd_Argc() < 2 ) return;
command = Cmd_Argv( 1 );
2018-02-12 22:00:00 +01:00
pszTrack = Cmd_Argv( 2 );
2010-11-19 22:00:00 +01:00
2016-11-17 22:00:00 +01:00
if( !enabled && Q_stricmp( command, "on" ))
return; // CD-player is disabled
2011-09-03 22:00:00 +02:00
2011-03-09 22:00:00 +01:00
if( !Q_stricmp( command, "play" ))
2010-11-19 22:00:00 +01:00
{
2018-02-12 22:00:00 +01:00
if( Q_isdigit( pszTrack ))
{
track = bound( 1, Q_atoi( Cmd_Argv( 2 )), MAX_CDTRACKS );
2018-02-15 22:00:00 +01:00
S_StartBackgroundTrack( clgame.cdtracks[track-1], NULL, 0, false );
2018-02-12 22:00:00 +01:00
}
2018-02-15 22:00:00 +01:00
else S_StartBackgroundTrack( pszTrack, NULL, 0, true );
2010-11-19 22:00:00 +01:00
paused = false;
looped = false;
}
2011-03-09 22:00:00 +01:00
else if( !Q_stricmp( command, "loop" ))
2010-11-19 22:00:00 +01:00
{
2018-02-12 22:00:00 +01:00
if( Q_isdigit( pszTrack ))
{
track = bound( 1, Q_atoi( Cmd_Argv( 2 )), MAX_CDTRACKS );
2018-02-15 22:00:00 +01:00
S_StartBackgroundTrack( clgame.cdtracks[track-1], clgame.cdtracks[track-1], 0, false );
2018-02-12 22:00:00 +01:00
}
2018-02-15 22:00:00 +01:00
else S_StartBackgroundTrack( pszTrack, pszTrack, 0, true );
2010-11-19 22:00:00 +01:00
paused = false;
looped = true;
}
2011-03-09 22:00:00 +01:00
else if( !Q_stricmp( command, "pause" ))
2010-11-19 22:00:00 +01:00
{
S_StreamSetPause( true );
paused = true;
}
2011-03-09 22:00:00 +01:00
else if( !Q_stricmp( command, "resume" ))
2010-11-19 22:00:00 +01:00
{
S_StreamSetPause( false );
paused = false;
}
2011-03-09 22:00:00 +01:00
else if( !Q_stricmp( command, "stop" ))
2010-11-19 22:00:00 +01:00
{
S_StopBackgroundTrack();
paused = false;
looped = false;
track = 0;
}
2011-09-03 22:00:00 +02:00
else if( !Q_stricmp( command, "on" ))
{
enabled = true;
}
else if( !Q_stricmp( command, "off" ))
{
enabled = false;
}
2011-03-09 22:00:00 +01:00
else if( !Q_stricmp( command, "info" ))
2010-11-19 22:00:00 +01:00
{
int i, maxTrack;
for( maxTrack = i = 0; i < MAX_CDTRACKS; i++ )
2011-03-09 22:00:00 +01:00
if( Q_strlen( clgame.cdtracks[i] )) maxTrack++;
2010-11-19 22:00:00 +01:00
2018-03-01 22:00:00 +01:00
Con_Printf( "%u tracks\n", maxTrack );
2010-11-19 22:00:00 +01:00
if( track )
{
2018-03-01 22:00:00 +01:00
if( paused ) Con_Printf( "Paused %s track %u\n", looped ? "looping" : "playing", track );
else Con_Printf( "Currently %s track %u\n", looped ? "looping" : "playing", track );
2010-11-19 22:00:00 +01:00
}
2018-03-01 22:00:00 +01:00
Con_Printf( "Volume is %f\n", Cvar_VariableValue( "MP3Volume" ));
2010-11-19 22:00:00 +01:00
return;
}
2018-03-01 22:00:00 +01:00
else Con_Printf( "%s: unknown command %s\n", Cmd_Argv( 0 ), command );
2010-11-19 22:00:00 +01:00
}
2007-11-06 22:00:00 +01:00
/*
==================
CL_ScreenshotGetName
==================
*/
2016-11-06 22:00:00 +01:00
qboolean CL_ScreenshotGetName( int lastnum, char *filename )
2007-11-06 22:00:00 +01:00
{
int a, b, c, d;
2009-07-03 22:00:00 +02:00
if( lastnum < 0 || lastnum > 9999 )
2007-11-06 22:00:00 +01:00
{
2018-09-10 23:00:00 +02:00
Con_Printf( S_ERROR "unable to write screenshot\n" );
2016-11-06 22:00:00 +01:00
return false;
2007-11-06 22:00:00 +01:00
}
a = lastnum / 1000;
lastnum -= a * 1000;
b = lastnum / 100;
lastnum -= b * 100;
c = lastnum / 10;
lastnum -= c * 10;
d = lastnum;
2013-02-19 21:00:00 +01:00
Q_sprintf( filename, "scrshots/%s_shot%i%i%i%i.bmp", clgame.mapname, a, b, c, d );
2016-11-06 22:00:00 +01:00
return true;
2007-11-06 22:00:00 +01:00
}
2011-09-03 22:00:00 +02:00
/*
==================
CL_SnapshotGetName
==================
*/
qboolean CL_SnapshotGetName( int lastnum, char *filename )
{
int a, b, c, d;
if( lastnum < 0 || lastnum > 9999 )
{
2018-09-10 23:00:00 +02:00
Con_Printf( S_ERROR "unable to write snapshot\n" );
2011-09-03 22:00:00 +02:00
FS_AllowDirectPaths( false );
return false;
}
a = lastnum / 1000;
lastnum -= a * 1000;
b = lastnum / 100;
lastnum -= b * 100;
c = lastnum / 10;
lastnum -= c * 10;
d = lastnum;
2012-06-25 22:00:00 +02:00
Q_sprintf( filename, "../%s_%i%i%i%i.bmp", clgame.mapname, a, b, c, d );
2011-09-03 22:00:00 +02:00
return true;
}
2007-11-06 22:00:00 +01:00
/*
==============================================================================
2011-04-08 22:00:00 +02:00
SCREEN SHOTS
2007-11-06 22:00:00 +01:00
==============================================================================
*/
/*
==================
CL_ScreenShot_f
normal screenshot
==================
2011-04-08 22:00:00 +02:00
*/
2007-11-06 22:00:00 +01:00
void CL_ScreenShot_f( void )
{
2008-07-23 22:00:00 +02:00
int i;
string checkname;
2007-11-06 22:00:00 +01:00
2017-02-21 22:00:00 +01:00
if( CL_IsDevOverviewMode() == 1 )
2007-11-06 22:00:00 +01:00
{
2011-08-21 22:00:00 +02:00
// special case for write overview image and script file
Q_snprintf( cls.shotname, sizeof( cls.shotname ), "overviews/%s.bmp", clgame.mapname );
cls.scrshot_action = scrshot_mapshot; // build new frame for mapshot
}
else
{
// scan for a free filename
for( i = 0; i < 9999; i++ )
{
2016-11-06 22:00:00 +01:00
if( !CL_ScreenshotGetName( i, checkname ))
return; // no namespace
2011-08-21 22:00:00 +02:00
if( !FS_FileExists( checkname, false ))
break;
}
Q_strncpy( cls.shotname, checkname, sizeof( cls.shotname ));
cls.scrshot_action = scrshot_normal; // build new frame for screenshot
2007-11-06 22:00:00 +01:00
}
2011-03-31 22:00:00 +02:00
cls.envshot_vieworg = NULL; // no custom view
2014-05-08 22:00:00 +02:00
cls.envshot_viewsize = 0;
2007-11-06 22:00:00 +01:00
}
2011-09-03 22:00:00 +02:00
/*
==================
CL_SnapShot_f
save screenshots into root dir
==================
*/
void CL_SnapShot_f( void )
{
int i;
string checkname;
2017-02-21 22:00:00 +01:00
if( CL_IsDevOverviewMode() == 1 )
2011-09-03 22:00:00 +02:00
{
// special case for write overview image and script file
Q_snprintf( cls.shotname, sizeof( cls.shotname ), "overviews/%s.bmp", clgame.mapname );
cls.scrshot_action = scrshot_mapshot; // build new frame for mapshot
}
else
{
FS_AllowDirectPaths( true );
// scan for a free filename
for( i = 0; i < 9999; i++ )
{
if( !CL_SnapshotGetName( i, checkname ))
return; // no namespace
if( !FS_FileExists( checkname, false ))
break;
}
FS_AllowDirectPaths( false );
Q_strncpy( cls.shotname, checkname, sizeof( cls.shotname ));
cls.scrshot_action = scrshot_snapshot; // build new frame for screenshot
}
cls.envshot_vieworg = NULL; // no custom view
2014-05-08 22:00:00 +02:00
cls.envshot_viewsize = 0;
2011-09-03 22:00:00 +02:00
}
2011-04-08 22:00:00 +02:00
/*
==================
CL_EnvShot_f
cubemap view
==================
*/
2008-11-09 22:00:00 +01:00
void CL_EnvShot_f( void )
{
2009-07-03 22:00:00 +02:00
if( Cmd_Argc() < 2 )
2008-11-09 22:00:00 +01:00
{
2018-03-01 22:00:00 +01:00
Con_Printf( S_USAGE "envshot <shotname>\n" );
2008-11-09 22:00:00 +01:00
return;
}
2011-03-09 22:00:00 +01:00
Q_sprintf( cls.shotname, "gfx/env/%s", Cmd_Argv( 1 ));
2010-03-26 22:00:00 +01:00
cls.scrshot_action = scrshot_envshot; // build new frame for envshot
cls.envshot_vieworg = NULL; // no custom view
2014-05-08 22:00:00 +02:00
cls.envshot_viewsize = 0;
2008-11-09 22:00:00 +01:00
}
2011-04-08 22:00:00 +02:00
/*
==================
CL_SkyShot_f
skybox view
==================
*/
2008-11-09 22:00:00 +01:00
void CL_SkyShot_f( void )
{
2009-07-03 22:00:00 +02:00
if( Cmd_Argc() < 2 )
2008-11-09 22:00:00 +01:00
{
2018-03-01 22:00:00 +01:00
Con_Printf( S_USAGE "skyshot <shotname>\n" );
2008-11-09 22:00:00 +01:00
return;
}
2011-03-09 22:00:00 +01:00
Q_sprintf( cls.shotname, "gfx/env/%s", Cmd_Argv( 1 ));
2010-03-26 22:00:00 +01:00
cls.scrshot_action = scrshot_skyshot; // build new frame for skyshot
cls.envshot_vieworg = NULL; // no custom view
2014-05-08 22:00:00 +02:00
cls.envshot_viewsize = 0;
2008-11-09 22:00:00 +01:00
}
2007-11-06 22:00:00 +01:00
/*
==================
CL_LevelShot_f
splash logo while map is loading
==================
*/
void CL_LevelShot_f( void )
{
2011-10-14 22:00:00 +02:00
size_t ft1, ft2;
2014-05-09 22:00:00 +02:00
string filename;
2011-10-14 22:00:00 +02:00
2009-09-23 22:00:00 +02:00
if( cls.scrshot_request != scrshot_plaque ) return;
cls.scrshot_request = scrshot_inactive;
2007-11-06 22:00:00 +01:00
// check for exist
2014-05-09 22:00:00 +02:00
if( cls.demoplayback && ( cls.demonum != -1 ))
{
Q_sprintf( cls.shotname, "levelshots/%s_%s.bmp", cls.demoname, glState.wideScreen ? "16x9" : "4x3" );
2018-11-02 22:00:00 +01:00
Q_snprintf( filename, sizeof( filename ), "%s.dem", cls.demoname );
2014-05-09 22:00:00 +02:00
// make sure what levelshot is newer than demo
ft1 = FS_FileTime( filename, false );
ft2 = FS_FileTime( cls.shotname, true );
}
else
{
Q_sprintf( cls.shotname, "levelshots/%s_%s.bmp", clgame.mapname, glState.wideScreen ? "16x9" : "4x3" );
2011-10-14 22:00:00 +02:00
2014-05-09 22:00:00 +02:00
// make sure what levelshot is newer than bsp
ft1 = FS_FileTime( cl.worldmodel->name, false );
ft2 = FS_FileTime( cls.shotname, true );
}
2011-10-14 22:00:00 +02:00
// missing levelshot or level never than levelshot
if( ft2 == -1 || ft1 > ft2 )
2009-09-23 22:00:00 +02:00
cls.scrshot_action = scrshot_plaque; // build new frame for levelshot
else cls.scrshot_action = scrshot_inactive; // disable - not needs
2007-11-13 22:00:00 +01:00
}
2009-09-10 22:00:00 +02:00
/*
==================
CL_SaveShot_f
mini-pic in loadgame menu
==================
*/
void CL_SaveShot_f( void )
{
if( Cmd_Argc() < 2 )
{
2018-03-01 22:00:00 +01:00
Con_Printf( S_USAGE "saveshot <savename>\n" );
2009-09-10 22:00:00 +02:00
return;
}
2018-03-23 22:00:00 +01:00
Q_sprintf( cls.shotname, "%s%s.bmp", DEFAULT_SAVE_DIRECTORY, Cmd_Argv( 1 ));
2010-03-10 22:00:00 +01:00
cls.scrshot_action = scrshot_savegame; // build new frame for saveshot
2009-09-10 22:00:00 +02:00
}
2010-01-07 22:00:00 +01:00
/*
==============
CL_DeleteDemo_f
==============
*/
void CL_DeleteDemo_f( void )
{
if( Cmd_Argc() != 2 )
{
2018-03-01 22:00:00 +01:00
Con_Printf( S_USAGE "killdemo <name>\n" );
2010-01-07 22:00:00 +01:00
return;
}
2011-03-09 22:00:00 +01:00
if( cls.demorecording && !Q_stricmp( cls.demoname, Cmd_Argv( 1 )))
2010-01-07 22:00:00 +01:00
{
2018-03-01 22:00:00 +01:00
Con_Printf( "Can't delete %s - recording\n", Cmd_Argv( 1 ));
2010-01-07 22:00:00 +01:00
return;
}
2018-11-02 22:00:00 +01:00
// delete demo
FS_Delete( va( "%s.dem", Cmd_Argv( 1 )));
2010-01-07 22:00:00 +01:00
}
2007-11-13 22:00:00 +01:00
/*
=================
CL_SetSky_f
2011-04-08 22:00:00 +02:00
Set a specified skybox (only for local clients)
2007-11-13 22:00:00 +01:00
=================
*/
void CL_SetSky_f( void )
{
2009-08-07 22:00:00 +02:00
if( Cmd_Argc() < 2 )
2007-11-13 22:00:00 +01:00
{
2018-03-01 22:00:00 +01:00
Con_Printf( S_USAGE "skyname <skybox>\n" );
2007-11-13 22:00:00 +01:00
return;
}
2010-12-02 22:00:00 +01:00
R_SetupSky( Cmd_Argv( 1 ));
2007-11-13 22:00:00 +01:00
}
/*
================
SCR_TimeRefresh_f
2008-08-04 22:00:00 +02:00
2010-10-09 22:00:00 +02:00
timerefresh [noflip]
2007-11-13 22:00:00 +01:00
================
*/
2008-06-30 22:00:00 +02:00
void SCR_TimeRefresh_f( void )
2007-11-13 22:00:00 +01:00
{
2010-10-09 22:00:00 +02:00
int i;
double start, stop;
double time;
2007-11-13 22:00:00 +01:00
2009-09-17 22:00:00 +02:00
if( cls.state != ca_active )
2007-11-13 22:00:00 +01:00
return;
2009-06-22 22:00:00 +02:00
start = Sys_DoubleTime();
2007-11-13 22:00:00 +01:00
2017-02-21 22:00:00 +01:00
// run without page flipping like GoldSrc
if( Cmd_Argc() == 1 )
2007-11-13 22:00:00 +01:00
{
2017-02-21 22:00:00 +01:00
pglDrawBuffer( GL_FRONT );
2008-06-30 22:00:00 +02:00
for( i = 0; i < 128; i++ )
2007-11-13 22:00:00 +01:00
{
2017-02-15 22:00:00 +01:00
RI.viewangles[1] = i / 128.0 * 360.0f;
R_RenderScene();
2007-11-13 22:00:00 +01:00
}
2017-02-21 22:00:00 +01:00
pglFinish();
2010-12-02 22:00:00 +01:00
R_EndFrame();
2007-11-13 22:00:00 +01:00
}
else
{
2008-06-30 22:00:00 +02:00
for( i = 0; i < 128; i++ )
2007-11-13 22:00:00 +01:00
{
2010-12-02 22:00:00 +01:00
R_BeginFrame( true );
2017-02-21 22:00:00 +01:00
RI.viewangles[1] = i / 128.0 * 360.0f;
2017-02-15 22:00:00 +01:00
R_RenderScene();
2010-12-02 22:00:00 +01:00
R_EndFrame();
2007-11-13 22:00:00 +01:00
}
}
2009-06-22 22:00:00 +02:00
stop = Sys_DoubleTime ();
time = (stop - start);
2018-03-01 22:00:00 +01:00
Con_Printf( "%f seconds (%f fps)\n", time, 128 / time );
2008-08-04 22:00:00 +02:00
}
/*
=============
SCR_Viewpos_f
2011-04-08 22:00:00 +02:00
viewpos (level-designer helper)
2008-08-04 22:00:00 +02:00
=============
*/
void SCR_Viewpos_f( void )
{
2018-03-01 22:00:00 +01:00
Con_Printf( "org ( %g %g %g )\n", RI.vieworg[0], RI.vieworg[1], RI.vieworg[2] );
Con_Printf( "ang ( %g %g %g )\n", RI.viewangles[0], RI.viewangles[1], RI.viewangles[2] );
2007-11-06 22:00:00 +01:00
}