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

476 lines
9.9 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
{
2010-10-09 22:00:00 +02:00
Msg( "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 )
{
2010-10-01 22:00:00 +02:00
Msg( "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;
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 );
2011-09-03 22:00:00 +02:00
if( !enabled && Q_stricmp( command, "on" )) return; // CD-player is disabled
2011-03-09 22:00:00 +01:00
if( !Q_stricmp( command, "play" ))
2010-11-19 22:00:00 +01:00
{
2011-03-09 22:00:00 +01:00
track = bound( 1, Q_atoi( Cmd_Argv( 2 )), MAX_CDTRACKS );
2012-05-14 22:00:00 +02:00
S_StartBackgroundTrack( clgame.cdtracks[track-1], NULL, 0 );
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
{
2011-03-09 22:00:00 +01:00
track = bound( 1, Q_atoi( Cmd_Argv( 2 )), MAX_CDTRACKS );
2012-05-14 22:00:00 +02:00
S_StartBackgroundTrack( clgame.cdtracks[track-1], clgame.cdtracks[track-1], 0 );
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
Msg( "%u tracks\n", maxTrack );
if( track )
{
if( paused ) Msg( "Paused %s track %u\n", looped ? "looping" : "playing", track );
else Msg( "Currently %s track %u\n", looped ? "looping" : "playing", track );
}
Msg( "Volume is %f\n", Cvar_VariableValue( "musicvolume" ));
return;
}
else Msg( "cd: unknown command %s\n", command );
}
2007-11-06 22:00:00 +01:00
/*
==================
CL_ScreenshotGetName
==================
*/
void CL_ScreenshotGetName( int lastnum, char *filename )
{
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
{
// bound
2011-03-09 22:00:00 +01:00
Q_sprintf( filename, "scrshots/%s/!error.bmp", clgame.mapname );
2007-11-06 22:00:00 +01:00
return;
}
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 );
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 )
{
MsgDev( D_ERROR, "unable to write snapshot\n" );
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
2011-08-21 22:00:00 +02:00
if( gl_overview->integer == 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++ )
{
CL_ScreenshotGetName( i, checkname );
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
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;
if( gl_overview->integer == 1 )
{
// 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
}
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
{
2009-07-03 22:00:00 +02:00
Msg( "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
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
{
2010-03-26 22:00:00 +01:00
Msg( "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
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;
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
2011-03-09 22:00:00 +01:00
Q_sprintf( cls.shotname, "levelshots/%s.bmp", clgame.mapname );
2011-10-14 22:00:00 +02:00
// make sure what entity patch is never than bsp
ft1 = FS_FileTime( cl.worldmodel->name, false );
ft2 = FS_FileTime( cls.shotname, true );
// 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 )
{
Msg( "Usage: saveshot <savename>\n" );
return;
}
2011-03-09 22:00:00 +01:00
Q_sprintf( cls.shotname, "save/%s.bmp", 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_DemoShot_f
mini-pic in playdemo menu
==================
*/
void CL_DemoShot_f( void )
{
if( Cmd_Argc() < 2 )
{
2010-03-26 22:00:00 +01:00
Msg( "Usage: demoshot <demoname>\n" );
2010-01-07 22:00:00 +01:00
return;
}
2011-03-09 22:00:00 +01:00
Q_sprintf( cls.shotname, "demos/%s.bmp", Cmd_Argv( 1 ));
2010-03-10 22:00:00 +01:00
cls.scrshot_action = scrshot_demoshot; // build new frame for demoshot
2010-01-07 22:00:00 +01:00
}
/*
==============
CL_DeleteDemo_f
==============
*/
void CL_DeleteDemo_f( void )
{
if( Cmd_Argc() != 2 )
{
2010-04-03 22:00:00 +02:00
Msg( "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
{
Msg( "Can't delete %s - recording\n", Cmd_Argv( 1 ));
return;
}
// delete save and saveshot
2010-03-27 22:00:00 +01:00
FS_Delete( va( "demos/%s.dem", Cmd_Argv( 1 )));
2011-02-15 22:00:00 +01:00
FS_Delete( va( "demos/%s.bmp", 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
{
2010-10-09 22:00:00 +02:00
Msg( "Usage: skyname <shadername>\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
2008-06-30 22:00:00 +02:00
if( Cmd_Argc() == 2 )
2007-11-13 22:00:00 +01:00
{
// run without page flipping
2010-12-02 22:00:00 +01:00
R_BeginFrame( false );
2008-06-30 22:00:00 +02:00
for( i = 0; i < 128; i++ )
2007-11-13 22:00:00 +01:00
{
2009-06-22 22:00:00 +02:00
cl.refdef.viewangles[1] = i / 128.0 * 360.0f;
2010-12-02 22:00:00 +01:00
R_RenderFrame( &cl.refdef, true );
2007-11-13 22:00:00 +01:00
}
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
{
2009-06-22 22:00:00 +02:00
cl.refdef.viewangles[1] = i / 128.0 * 360.0f;
2007-11-13 22:00:00 +01:00
2010-12-02 22:00:00 +01:00
R_BeginFrame( true );
R_RenderFrame( &cl.refdef, true );
R_EndFrame();
2007-11-13 22:00:00 +01:00
}
}
2009-06-22 22:00:00 +02:00
stop = Sys_DoubleTime ();
time = (stop - start);
2008-06-30 22:00:00 +02:00
Msg( "%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 )
{
2009-12-01 22:00:00 +01:00
Msg( "org ( %g %g %g )\n", cl.refdef.vieworg[0], cl.refdef.vieworg[1], cl.refdef.vieworg[2] );
Msg( "ang ( %g %g %g )\n", cl.refdef.viewangles[0], cl.refdef.viewangles[1], cl.refdef.viewangles[2] );
2007-11-06 22:00:00 +01:00
}