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_scrn.c

764 lines
19 KiB
C
Raw Normal View History

2011-05-09 22:00:00 +02:00
/*
cl_scrn.c - refresh screen
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-06-21 22:00:00 +02:00
2008-06-09 22:00:00 +02:00
#include "common.h"
2007-06-21 22:00:00 +02:00
#include "client.h"
2011-04-06 22:00:00 +02:00
#include "gl_local.h"
2011-04-08 22:00:00 +02:00
#include "vgui_draw.h"
2010-09-10 22:00:00 +02:00
#include "qfont.h"
2018-03-20 22:00:00 +01:00
#include "input.h"
2007-06-21 22:00:00 +02:00
2010-10-22 22:00:00 +02:00
convar_t *scr_centertime;
convar_t *scr_loading;
convar_t *scr_download;
2011-04-10 22:00:00 +02:00
convar_t *scr_viewsize;
2010-10-22 22:00:00 +02:00
convar_t *cl_testlights;
convar_t *cl_allow_levelshots;
convar_t *cl_levelshot_name;
convar_t *cl_envshot_size;
2018-03-04 22:00:00 +01:00
convar_t *v_dark;
2007-11-06 22:00:00 +01:00
2011-09-19 22:00:00 +02:00
typedef struct
{
int x1, y1, x2, y2;
} dirty_t;
static dirty_t scr_dirty, scr_old_dirty[2];
2011-04-09 22:00:00 +02:00
static qboolean scr_init = false;
2007-11-04 22:00:00 +01:00
2008-12-26 22:00:00 +01:00
/*
==============
SCR_DrawFPS
==============
*/
2016-11-17 22:00:00 +01:00
void SCR_DrawFPS( int height )
2008-12-26 22:00:00 +01:00
{
float calc;
2010-07-20 22:00:00 +02:00
rgba_t color;
2016-11-17 22:00:00 +01:00
double newtime;
2008-12-26 22:00:00 +01:00
static double nexttime = 0, lasttime = 0;
static double framerate = 0;
static int framecount = 0;
2015-04-25 23:00:00 +02:00
static int minfps = 9999;
static int maxfps = 0;
char fpsstring[64];
2011-07-07 22:00:00 +02:00
int offset;
2008-12-26 22:00:00 +01:00
2017-02-12 22:00:00 +01:00
if( cls.state != ca_active || !cl_showfps->value || cl.background )
2016-11-17 22:00:00 +01:00
return;
2011-09-19 22:00:00 +02:00
switch( cls.scrshot_action )
{
case scrshot_normal:
case scrshot_snapshot:
case scrshot_inactive:
break;
default: return;
}
2008-12-26 22:00:00 +01:00
newtime = Sys_DoubleTime();
2009-09-17 22:00:00 +02:00
if( newtime >= nexttime )
2008-12-26 22:00:00 +01:00
{
framerate = framecount / (newtime - lasttime);
lasttime = newtime;
2016-11-17 22:00:00 +01:00
nexttime = Q_max( nexttime + 1.0, lasttime - 1.0 );
2008-12-26 22:00:00 +01:00
framecount = 0;
}
2010-07-20 22:00:00 +02:00
2008-12-26 22:00:00 +01:00
calc = framerate;
2016-11-17 22:00:00 +01:00
framecount++;
2008-12-26 22:00:00 +01:00
2010-07-20 22:00:00 +02:00
if( calc < 1.0f )
2008-12-26 22:00:00 +01:00
{
2015-04-25 23:00:00 +02:00
Q_snprintf( fpsstring, sizeof( fpsstring ), "%4i spf", (int)(1.0f / calc + 0.5f));
2010-07-20 22:00:00 +02:00
MakeRGBA( color, 255, 0, 0, 255 );
2008-12-26 22:00:00 +01:00
}
else
{
2015-04-25 23:00:00 +02:00
int curfps = (int)(calc + 0.5f);
if( curfps < minfps ) minfps = curfps;
if( curfps > maxfps ) maxfps = curfps;
2017-02-12 22:00:00 +01:00
if( cl_showfps->value == 2 )
2015-04-25 23:00:00 +02:00
Q_snprintf( fpsstring, sizeof( fpsstring ), "fps: ^1%4i min, ^3%4i cur, ^2%4i max", minfps, curfps, maxfps );
else Q_snprintf( fpsstring, sizeof( fpsstring ), "%4i fps", curfps );
2010-07-20 22:00:00 +02:00
MakeRGBA( color, 255, 255, 255, 255 );
2008-12-26 22:00:00 +01:00
}
2011-07-07 22:00:00 +02:00
Con_DrawStringLen( fpsstring, &offset, NULL );
2017-02-15 22:00:00 +01:00
Con_DrawString( glState.width - offset - 4, height, fpsstring, color );
2008-12-26 22:00:00 +01:00
}
2011-04-09 22:00:00 +02:00
/*
==============
SCR_NetSpeeds
same as r_speeds but for network channel
==============
*/
2010-07-26 22:00:00 +02:00
void SCR_NetSpeeds( void )
{
static char msg[MAX_SYSPATH];
int x, y, height;
char *p, *start, *end;
2011-04-08 22:00:00 +02:00
float time = cl.mtime[0];
2016-11-14 22:00:00 +01:00
static int min_svfps = 100;
static int max_svfps = 0;
int cur_svfps = 0;
2016-11-22 22:00:00 +01:00
static int min_clfps = 100;
static int max_clfps = 0;
int cur_clfps = 0;
2010-07-26 22:00:00 +02:00
rgba_t color;
2018-03-03 22:00:00 +01:00
if( !host.allow_console )
2017-02-21 22:00:00 +01:00
return;
2018-04-25 23:00:00 +02:00
if( !net_speeds->value || cls.state != ca_active )
2016-11-14 22:00:00 +01:00
return;
2010-07-26 22:00:00 +02:00
2017-02-21 22:00:00 +01:00
// prevent to get too big values at max
if( cl_serverframetime() > 0.0001f )
2010-07-26 22:00:00 +02:00
{
2016-11-14 22:00:00 +01:00
cur_svfps = Q_rint( 1.0f / cl_serverframetime( ));
if( cur_svfps < min_svfps ) min_svfps = cur_svfps;
if( cur_svfps > max_svfps ) max_svfps = cur_svfps;
2010-07-26 22:00:00 +02:00
}
2017-02-21 22:00:00 +01:00
// prevent to get too big values at max
if( cl_clientframetime() > 0.0001f )
2016-11-22 22:00:00 +01:00
{
cur_clfps = Q_rint( 1.0f / cl_clientframetime( ));
if( cur_clfps < min_clfps ) min_clfps = cur_clfps;
if( cur_clfps > max_clfps ) max_clfps = cur_clfps;
}
2017-08-21 23:00:00 +02:00
Q_snprintf( msg, sizeof( msg ), "sv fps: ^1%4i min, ^3%4i cur, ^2%4i max\ncl fps: ^1%4i min, ^3%4i cur, ^2%4i max\nGame Time: %02d:%02d\nTotal received from server: %s\nTotal sent to server: %s\n",
2017-02-21 22:00:00 +01:00
min_svfps, cur_svfps, max_svfps, min_clfps, cur_clfps, max_clfps, (int)(time / 60.0f ), (int)fmod( time, 60.0f ), Q_memprint( cls.netchan.total_received ), Q_memprint( cls.netchan.total_sended ));
2016-11-14 22:00:00 +01:00
2017-02-15 22:00:00 +01:00
x = glState.width - 320;
2016-11-14 22:00:00 +01:00
y = 384;
2010-07-26 22:00:00 +02:00
Con_DrawStringLen( NULL, NULL, &height );
MakeRGBA( color, 255, 255, 255, 255 );
p = start = msg;
2011-04-09 22:00:00 +02:00
2010-07-26 22:00:00 +02:00
do
{
2011-03-09 22:00:00 +01:00
end = Q_strchr( p, '\n' );
2010-07-26 22:00:00 +02:00
if( end ) msg[end-start] = '\0';
Con_DrawString( x, y, p, color );
y += height;
if( end ) p = end + 1;
else break;
} while( 1 );
}
2009-09-01 22:00:00 +02:00
/*
================
SCR_RSpeeds
================
*/
void SCR_RSpeeds( void )
{
2018-06-07 23:00:00 +02:00
char msg[2048];
2009-09-01 22:00:00 +02:00
2018-03-03 22:00:00 +01:00
if( !host.allow_console )
2017-02-21 22:00:00 +01:00
return;
2010-12-02 22:00:00 +01:00
if( R_SpeedsMessage( msg, sizeof( msg )))
2009-09-01 22:00:00 +02:00
{
int x, y, height;
char *p, *start, *end;
2009-09-10 22:00:00 +02:00
rgba_t color;
2009-09-01 22:00:00 +02:00
2017-02-15 22:00:00 +01:00
x = glState.width - 340;
2009-09-01 22:00:00 +02:00
y = 64;
2010-07-20 22:00:00 +02:00
Con_DrawStringLen( NULL, NULL, &height );
2009-09-10 22:00:00 +02:00
MakeRGBA( color, 255, 255, 255, 255 );
2009-09-01 22:00:00 +02:00
p = start = msg;
do
{
2011-03-09 22:00:00 +01:00
end = Q_strchr( p, '\n' );
2009-09-01 22:00:00 +02:00
if( end ) msg[end-start] = '\0';
2010-07-20 22:00:00 +02:00
Con_DrawString( x, y, p, color );
2009-09-01 22:00:00 +02:00
y += height;
2018-05-20 23:00:00 +02:00
// handle '\n\n'
if( *p == '\n' )
y += height;
2009-09-01 22:00:00 +02:00
if( end ) p = end + 1;
else break;
} while( 1 );
}
}
2017-01-14 22:00:00 +01:00
/*
================
SCR_MakeLevelShot
creates levelshot at next frame
================
*/
2009-10-18 22:00:00 +02:00
void SCR_MakeLevelShot( void )
{
if( cls.scrshot_request != scrshot_plaque )
return;
// make levelshot at nextframe()
2010-12-09 22:00:00 +01:00
Cbuf_AddText( "levelshot\n" );
2009-10-18 22:00:00 +02:00
}
2017-01-14 22:00:00 +01:00
/*
================
SCR_MakeScreenShot
create a requested screenshot type
================
*/
2009-09-23 22:00:00 +02:00
void SCR_MakeScreenShot( void )
{
2010-10-26 22:00:00 +02:00
qboolean iRet = false;
2014-05-08 22:00:00 +02:00
int viewsize;
if( cls.envshot_viewsize > 0 )
viewsize = cls.envshot_viewsize;
2017-02-12 22:00:00 +01:00
else viewsize = cl_envshot_size->value;
2010-03-26 22:00:00 +01:00
2009-09-23 22:00:00 +02:00
switch( cls.scrshot_action )
{
2011-03-31 22:00:00 +02:00
case scrshot_normal:
iRet = VID_ScreenShot( cls.shotname, VID_SCREENSHOT );
break;
2011-09-03 22:00:00 +02:00
case scrshot_snapshot:
iRet = VID_ScreenShot( cls.shotname, VID_SNAPSHOT );
break;
2009-09-23 22:00:00 +02:00
case scrshot_plaque:
2010-12-02 22:00:00 +01:00
iRet = VID_ScreenShot( cls.shotname, VID_LEVELSHOT );
2009-09-23 22:00:00 +02:00
break;
case scrshot_savegame:
2010-12-02 22:00:00 +01:00
iRet = VID_ScreenShot( cls.shotname, VID_MINISHOT );
2010-03-26 22:00:00 +01:00
break;
case scrshot_envshot:
2014-05-08 22:00:00 +02:00
iRet = VID_CubemapShot( cls.shotname, viewsize, cls.envshot_vieworg, false );
2009-09-23 22:00:00 +02:00
break;
2010-03-26 22:00:00 +01:00
case scrshot_skyshot:
2014-05-08 22:00:00 +02:00
iRet = VID_CubemapShot( cls.shotname, viewsize, cls.envshot_vieworg, true );
2010-03-26 22:00:00 +01:00
break;
2011-08-21 22:00:00 +02:00
case scrshot_mapshot:
iRet = VID_ScreenShot( cls.shotname, VID_MAPSHOT );
break;
case scrshot_inactive:
return;
2009-09-23 22:00:00 +02:00
}
2010-03-26 22:00:00 +01:00
// report
2011-09-03 22:00:00 +02:00
if( iRet )
{
// snapshots don't writes message about image
if( cls.scrshot_action != scrshot_snapshot )
2018-09-10 23:00:00 +02:00
Con_Reportf( "Write %s\n", cls.shotname );
2011-09-03 22:00:00 +02:00
}
2018-09-10 23:00:00 +02:00
else Con_Printf( S_ERROR "Unable to write %s\n", cls.shotname );
2010-03-26 22:00:00 +01:00
cls.envshot_vieworg = NULL;
2009-09-23 22:00:00 +02:00
cls.scrshot_action = scrshot_inactive;
2014-05-08 22:00:00 +02:00
cls.envshot_disable_vis = false;
cls.envshot_viewsize = 0;
2009-09-23 22:00:00 +02:00
cls.shotname[0] = '\0';
}
2017-01-14 22:00:00 +01:00
/*
================
SCR_DrawPlaque
================
*/
2009-10-18 22:00:00 +02:00
void SCR_DrawPlaque( void )
{
2017-02-12 22:00:00 +01:00
if(( cl_allow_levelshots->value && !cls.changelevel ) || cl.background )
2010-07-17 22:00:00 +02:00
{
2018-10-17 23:00:00 +02:00
int levelshot = GL_LoadTexture( cl_levelshot_name->string, NULL, 0, TF_IMAGE );
2010-12-02 22:00:00 +01:00
GL_SetRenderMode( kRenderNormal );
2017-02-15 22:00:00 +01:00
R_DrawStretchPic( 0, 0, glState.width, glState.height, 0, 0, 1, 1, levelshot );
2014-05-09 22:00:00 +02:00
if( !cl.background ) CL_DrawHUD( CL_LOADING );
2010-07-17 22:00:00 +02:00
}
2009-10-18 22:00:00 +02:00
}
2010-12-09 22:00:00 +01:00
/*
================
SCR_BeginLoadingPlaque
================
*/
2011-04-05 22:00:00 +02:00
void SCR_BeginLoadingPlaque( qboolean is_background )
2010-12-09 22:00:00 +01:00
{
2019-06-11 23:00:00 +02:00
float oldclear;
2017-06-23 23:00:00 +02:00
S_StopAllSounds( true );
2011-04-09 22:00:00 +02:00
cl.audio_prepped = false; // don't play ambients
2019-06-08 23:00:00 +02:00
cl.video_prepped = false;
2019-06-11 23:00:00 +02:00
oldclear = gl_clear->value;
2010-12-09 22:00:00 +01:00
2017-08-14 23:00:00 +02:00
if( CL_IsInMenu( ) && !cls.changedemo && !is_background )
{
UI_SetActiveMenu( false );
if( cls.state == ca_disconnected )
SCR_UpdateScreen();
}
2018-03-05 22:00:00 +01:00
if( cls.state == ca_disconnected || cls.disable_screen )
return; // already set
2010-12-09 22:00:00 +01:00
2018-03-09 22:00:00 +01:00
if( cls.key_dest == key_console )
return;
2019-06-11 23:00:00 +02:00
gl_clear->value = 0.0f;
2018-03-20 22:00:00 +01:00
if( is_background ) IN_MouseSavePos( );
2018-03-08 22:00:00 +01:00
cls.draw_changelevel = !is_background;
2010-12-09 22:00:00 +01:00
SCR_UpdateScreen();
cls.disable_screen = host.realtime;
cls.disable_servercount = cl.servercount;
2011-04-09 22:00:00 +02:00
cl.background = is_background; // set right state before svc_serverdata is came
2019-06-11 23:00:00 +02:00
gl_clear->value = oldclear;
2018-03-14 22:00:00 +01:00
// SNDDMA_LockSound();
2010-12-09 22:00:00 +01:00
}
/*
================
SCR_EndLoadingPlaque
================
*/
void SCR_EndLoadingPlaque( void )
{
2014-04-23 22:00:00 +02:00
cls.disable_screen = 0.0f;
2010-12-09 22:00:00 +01:00
Con_ClearNotify();
2018-03-14 22:00:00 +01:00
// SNDDMA_UnlockSound();
2010-12-09 22:00:00 +01:00
}
2011-09-19 22:00:00 +02:00
/*
=================
SCR_AddDirtyPoint
=================
*/
void SCR_AddDirtyPoint( int x, int y )
{
2012-12-23 21:00:00 +01:00
if( x < scr_dirty.x1 ) scr_dirty.x1 = x;
if( x > scr_dirty.x2 ) scr_dirty.x2 = x;
if( y < scr_dirty.y1 ) scr_dirty.y1 = y;
if( y > scr_dirty.y2 ) scr_dirty.y2 = y;
2011-09-19 22:00:00 +02:00
}
/*
================
SCR_DirtyScreen
================
*/
void SCR_DirtyScreen( void )
{
SCR_AddDirtyPoint( 0, 0 );
2017-02-15 22:00:00 +01:00
SCR_AddDirtyPoint( glState.width - 1, glState.height - 1 );
2011-09-19 22:00:00 +02:00
}
/*
================
SCR_TileClear
================
*/
void SCR_TileClear( void )
{
int i, top, bottom, left, right;
dirty_t clear;
2017-02-12 22:00:00 +01:00
if( scr_viewsize->value >= 120 )
2011-09-19 22:00:00 +02:00
return; // full screen rendering
// erase rect will be the union of the past three frames
// so tripple buffering works properly
clear = scr_dirty;
2012-11-18 21:00:00 +01:00
2011-09-19 22:00:00 +02:00
for( i = 0; i < 2; i++ )
{
if( scr_old_dirty[i].x1 < clear.x1 )
clear.x1 = scr_old_dirty[i].x1;
if( scr_old_dirty[i].x2 > clear.x2 )
clear.x2 = scr_old_dirty[i].x2;
if( scr_old_dirty[i].y1 < clear.y1 )
clear.y1 = scr_old_dirty[i].y1;
if( scr_old_dirty[i].y2 > clear.y2 )
clear.y2 = scr_old_dirty[i].y2;
}
scr_old_dirty[1] = scr_old_dirty[0];
scr_old_dirty[0] = scr_dirty;
scr_dirty.x1 = 9999;
scr_dirty.x2 = -9999;
scr_dirty.y1 = 9999;
scr_dirty.y2 = -9999;
if( clear.y2 <= clear.y1 )
return; // nothing disturbed
2018-09-08 23:00:00 +02:00
top = clgame.viewport[1];
bottom = top + clgame.viewport[3] - 1;
left = clgame.viewport[0];
right = left + clgame.viewport[2] - 1;
2011-09-19 22:00:00 +02:00
if( clear.y1 < top )
{
// clear above view screen
i = clear.y2 < top-1 ? clear.y2 : top - 1;
R_DrawTileClear( clear.x1, clear.y1, clear.x2 - clear.x1 + 1, i - clear.y1 + 1 );
clear.y1 = top;
}
if( clear.y2 > bottom )
{
// clear below view screen
i = clear.y1 > bottom + 1 ? clear.y1 : bottom + 1;
R_DrawTileClear( clear.x1, i, clear.x2 - clear.x1 + 1, clear.y2 - i + 1 );
clear.y2 = bottom;
}
if( clear.x1 < left )
{
// clear left of view screen
i = clear.x2 < left - 1 ? clear.x2 : left - 1;
R_DrawTileClear( clear.x1, clear.y1, i - clear.x1 + 1, clear.y2 - clear.y1 + 1 );
clear.x1 = left;
}
if( clear.x2 > right )
{
// clear left of view screen
i = clear.x1 > right + 1 ? clear.x1 : right + 1;
R_DrawTileClear( i, clear.y1, clear.x2 - i + 1, clear.y2 - clear.y1 + 1 );
clear.x2 = right;
}
}
2007-06-21 22:00:00 +02:00
/*
==================
2007-11-06 22:00:00 +01:00
SCR_UpdateScreen
2007-06-21 22:00:00 +02:00
2007-11-06 22:00:00 +01:00
This is called every frame, and can also be called explicitly to flush
text to the screen.
2007-06-21 22:00:00 +02:00
==================
*/
2007-11-06 22:00:00 +01:00
void SCR_UpdateScreen( void )
2007-06-21 22:00:00 +02:00
{
2011-04-09 22:00:00 +02:00
if( !V_PreRender( )) return;
switch( cls.state )
2007-06-21 22:00:00 +02:00
{
2011-04-09 22:00:00 +02:00
case ca_disconnected:
2018-03-08 22:00:00 +01:00
Con_RunConsole ();
2011-04-09 22:00:00 +02:00
break;
case ca_connecting:
case ca_connected:
2018-02-20 22:00:00 +01:00
case ca_validate:
2011-04-09 22:00:00 +02:00
SCR_DrawPlaque();
break;
case ca_active:
2018-03-08 22:00:00 +01:00
Con_RunConsole ();
2011-04-09 22:00:00 +02:00
V_RenderView();
break;
case ca_cinematic:
SCR_DrawCinematic();
break;
default:
Host_Error( "SCR_UpdateScreen: bad cls.state\n" );
break;
}
V_PostRender();
2007-11-05 22:00:00 +01:00
}
2007-06-21 22:00:00 +02:00
2017-07-05 23:00:00 +02:00
qboolean SCR_LoadFixedWidthFont( const char *fontname )
2010-07-08 22:00:00 +02:00
{
2017-07-05 23:00:00 +02:00
int i, fontWidth;
if( cls.creditsFont.valid )
return true; // already loaded
2011-04-09 22:00:00 +02:00
2017-07-05 23:00:00 +02:00
if( !FS_FileExists( fontname, false ))
return false;
2011-04-09 22:00:00 +02:00
2018-10-17 23:00:00 +02:00
cls.creditsFont.hFontTexture = GL_LoadTexture( fontname, NULL, 0, TF_IMAGE|TF_KEEP_SOURCE );
2011-04-09 22:00:00 +02:00
R_GetTextureParms( &fontWidth, NULL, cls.creditsFont.hFontTexture );
2017-07-05 23:00:00 +02:00
cls.creditsFont.charHeight = clgame.scrInfo.iCharHeight = fontWidth / 16;
2017-07-16 23:00:00 +02:00
cls.creditsFont.type = FONT_FIXED;
2017-07-05 23:00:00 +02:00
cls.creditsFont.valid = true;
2011-09-28 22:00:00 +02:00
2017-07-05 23:00:00 +02:00
// build fixed rectangles
for( i = 0; i < 256; i++ )
2011-04-09 22:00:00 +02:00
{
2017-07-05 23:00:00 +02:00
cls.creditsFont.fontRc[i].left = (i * (fontWidth / 16)) % fontWidth;
cls.creditsFont.fontRc[i].right = cls.creditsFont.fontRc[i].left + fontWidth / 16;
cls.creditsFont.fontRc[i].top = (i / 16) * (fontWidth / 16);
cls.creditsFont.fontRc[i].bottom = cls.creditsFont.fontRc[i].top + fontWidth / 16;
cls.creditsFont.charWidths[i] = clgame.scrInfo.charWidths[i] = fontWidth / 16;
}
2011-04-09 22:00:00 +02:00
2017-07-05 23:00:00 +02:00
return true;
}
qboolean SCR_LoadVariableWidthFont( const char *fontname )
{
int i, fontWidth;
byte *buffer;
size_t length;
qfont_t *src;
if( cls.creditsFont.valid )
return true; // already loaded
if( !FS_FileExists( fontname, false ))
return false;
2018-10-17 23:00:00 +02:00
cls.creditsFont.hFontTexture = GL_LoadTexture( fontname, NULL, 0, TF_IMAGE );
2017-07-05 23:00:00 +02:00
R_GetTextureParms( &fontWidth, NULL, cls.creditsFont.hFontTexture );
// half-life font with variable chars witdh
buffer = FS_LoadFile( fontname, &length, false );
// setup creditsfont
if( buffer && length >= sizeof( qfont_t ))
{
src = (qfont_t *)buffer;
cls.creditsFont.charHeight = clgame.scrInfo.iCharHeight = src->rowheight;
2017-07-16 23:00:00 +02:00
cls.creditsFont.type = FONT_VARIABLE;
2017-07-05 23:00:00 +02:00
// build rectangles
for( i = 0; i < 256; i++ )
2010-07-08 22:00:00 +02:00
{
2017-07-05 23:00:00 +02:00
cls.creditsFont.fontRc[i].left = (word)src->fontinfo[i].startoffset % fontWidth;
cls.creditsFont.fontRc[i].right = cls.creditsFont.fontRc[i].left + src->fontinfo[i].charwidth;
cls.creditsFont.fontRc[i].top = (word)src->fontinfo[i].startoffset / fontWidth;
cls.creditsFont.fontRc[i].bottom = cls.creditsFont.fontRc[i].top + src->rowheight;
cls.creditsFont.charWidths[i] = clgame.scrInfo.charWidths[i] = src->fontinfo[i].charwidth;
2010-07-08 22:00:00 +02:00
}
2017-07-05 23:00:00 +02:00
cls.creditsFont.valid = true;
}
if( buffer ) Mem_Free( buffer );
return true;
}
2018-01-02 22:00:00 +01:00
/*
================
SCR_LoadCreditsFont
2017-07-05 23:00:00 +02:00
2018-02-07 22:00:00 +01:00
INTERNAL RESOURCE
2018-01-02 22:00:00 +01:00
================
*/
2017-07-05 23:00:00 +02:00
void SCR_LoadCreditsFont( void )
{
if( !SCR_LoadVariableWidthFont( "gfx.wad/creditsfont.fnt" ))
{
if( !SCR_LoadFixedWidthFont( "gfx/conchars" ))
2018-09-10 23:00:00 +02:00
Con_DPrintf( S_ERROR "failed to load HUD font\n" );
2010-07-08 22:00:00 +02:00
}
}
2018-01-02 22:00:00 +01:00
/*
================
SCR_InstallParticlePalette
2018-02-07 22:00:00 +01:00
INTERNAL RESOURCE
2018-01-02 22:00:00 +01:00
================
*/
2012-12-23 21:00:00 +01:00
void SCR_InstallParticlePalette( void )
2010-07-13 22:00:00 +02:00
{
rgbdata_t *pic;
int i;
2011-04-18 22:00:00 +02:00
// first check 'palette.lmp' then 'palette.pal'
2018-06-10 23:00:00 +02:00
pic = FS_LoadImage( DEFAULT_INTERNAL_PALETTE, NULL, 0 );
if( !pic ) pic = FS_LoadImage( DEFAULT_EXTERNAL_PALETTE, NULL, 0 );
2011-04-09 22:00:00 +02:00
2010-07-13 22:00:00 +02:00
// NOTE: imagelib required this fakebuffer for loading internal palette
2017-03-14 22:00:00 +01:00
if( !pic ) pic = FS_LoadImage( "#valve.pal", (byte *)&i, 768 );
2010-07-13 22:00:00 +02:00
if( pic )
{
for( i = 0; i < 256; i++ )
{
2017-02-21 22:00:00 +01:00
clgame.palette[i].r = pic->palette[i*4+0];
clgame.palette[i].g = pic->palette[i*4+1];
clgame.palette[i].b = pic->palette[i*4+2];
2010-07-13 22:00:00 +02:00
}
FS_FreeImage( pic );
}
else
{
2018-06-10 23:00:00 +02:00
// someone deleted internal palette from code...
2010-07-13 22:00:00 +02:00
for( i = 0; i < 256; i++ )
{
2017-02-21 22:00:00 +01:00
clgame.palette[i].r = i;
clgame.palette[i].g = i;
clgame.palette[i].b = i;
2010-07-13 22:00:00 +02:00
}
}
}
2018-01-02 22:00:00 +01:00
/*
================
SCR_RegisterTextures
2018-02-07 22:00:00 +01:00
INTERNAL RESOURCE
2018-01-02 22:00:00 +01:00
================
*/
2012-12-23 21:00:00 +01:00
void SCR_RegisterTextures( void )
2008-11-15 22:00:00 +01:00
{
2010-11-22 22:00:00 +01:00
// register gfx.wad images
2017-07-03 23:00:00 +02:00
if( FS_FileExists( "gfx/paused.lmp", false ))
2018-10-17 23:00:00 +02:00
cls.pauseIcon = GL_LoadTexture( "gfx/paused.lmp", NULL, 0, TF_IMAGE );
2017-07-03 23:00:00 +02:00
else if( FS_FileExists( "gfx/pause.lmp", false ))
2018-10-17 23:00:00 +02:00
cls.pauseIcon = GL_LoadTexture( "gfx/pause.lmp", NULL, 0, TF_IMAGE );
2017-07-03 23:00:00 +02:00
if( FS_FileExists( "gfx/lambda.lmp", false ))
{
if( cl_allow_levelshots->value )
2018-10-17 23:00:00 +02:00
cls.loadingBar = GL_LoadTexture( "gfx/lambda.lmp", NULL, 0, TF_IMAGE|TF_LUMINANCE );
else cls.loadingBar = GL_LoadTexture( "gfx/lambda.lmp", NULL, 0, TF_IMAGE );
2017-07-03 23:00:00 +02:00
}
else if( FS_FileExists( "gfx/loading.lmp", false ))
{
if( cl_allow_levelshots->value )
2018-10-17 23:00:00 +02:00
cls.loadingBar = GL_LoadTexture( "gfx/loading.lmp", NULL, 0, TF_IMAGE|TF_LUMINANCE );
else cls.loadingBar = GL_LoadTexture( "gfx/loading.lmp", NULL, 0, TF_IMAGE );
2017-07-03 23:00:00 +02:00
}
2018-10-17 23:00:00 +02:00
cls.tileImage = GL_LoadTexture( "gfx/backtile.lmp", NULL, 0, TF_NOMIPMAP );
2011-03-15 22:00:00 +01:00
}
2010-11-22 22:00:00 +01:00
2011-09-19 22:00:00 +02:00
/*
=================
SCR_SizeUp_f
Keybinding command
=================
*/
void SCR_SizeUp_f( void )
{
2017-02-12 22:00:00 +01:00
Cvar_SetValue( "viewsize", Q_min( scr_viewsize->value + 10, 120 ));
2011-09-19 22:00:00 +02:00
}
/*
=================
SCR_SizeDown_f
Keybinding command
=================
*/
void SCR_SizeDown_f( void )
{
2017-02-12 22:00:00 +01:00
Cvar_SetValue( "viewsize", Q_max( scr_viewsize->value - 10, 30 ));
2011-09-19 22:00:00 +02:00
}
2010-11-22 22:00:00 +01:00
/*
==================
SCR_VidInit
==================
*/
void SCR_VidInit( void )
{
2016-11-17 22:00:00 +01:00
memset( &clgame.ds, 0, sizeof( clgame.ds )); // reset a draw state
memset( &gameui.ds, 0, sizeof( gameui.ds )); // reset a draw state
memset( &clgame.centerPrint, 0, sizeof( clgame.centerPrint ));
2009-12-05 22:00:00 +01:00
2010-07-20 22:00:00 +02:00
// update screen sizes for menu
2017-02-15 22:00:00 +01:00
gameui.globals->scrWidth = glState.width;
gameui.globals->scrHeight = glState.height;
2008-12-28 22:00:00 +01:00
2010-11-16 22:00:00 +01:00
VGui_Startup ();
2018-03-07 22:00:00 +01:00
CL_ClearSpriteTextures(); // now all hud sprites are invalid
2010-12-21 22:00:00 +01:00
2008-12-28 22:00:00 +01:00
// vid_state has changed
2016-11-17 22:00:00 +01:00
if( gameui.hInstance ) gameui.dllFuncs.pfnVidInit();
2010-12-21 22:00:00 +01:00
if( clgame.hInstance ) clgame.dllFuncs.pfnVidInit();
2010-07-19 22:00:00 +02:00
// restart console size
Con_VidInit ();
2008-11-15 22:00:00 +01:00
}
2007-11-05 22:00:00 +01:00
/*
==================
2007-11-06 22:00:00 +01:00
SCR_Init
2007-11-05 22:00:00 +01:00
==================
*/
2008-11-15 22:00:00 +01:00
void SCR_Init( void )
2007-11-05 22:00:00 +01:00
{
2009-10-02 22:00:00 +02:00
if( scr_init ) return;
2009-09-19 22:00:00 +02:00
scr_centertime = Cvar_Get( "scr_centertime", "2.5", 0, "centerprint hold time" );
2010-12-09 22:00:00 +01:00
cl_levelshot_name = Cvar_Get( "cl_levelshot_name", "*black", 0, "contains path to current levelshot" );
2017-02-12 22:00:00 +01:00
cl_allow_levelshots = Cvar_Get( "allow_levelshots", "0", FCVAR_ARCHIVE, "allow engine to use indivdual levelshots instead of 'loading' image" );
2010-07-20 22:00:00 +02:00
scr_loading = Cvar_Get( "scr_loading", "0", 0, "loading bar progress" );
2018-03-07 22:00:00 +01:00
scr_download = Cvar_Get( "scr_download", "-1", 0, "downloading bar progress" );
2010-07-20 22:00:00 +02:00
cl_testlights = Cvar_Get( "cl_testlights", "0", 0, "test dynamic lights" );
2017-02-12 22:00:00 +01:00
cl_envshot_size = Cvar_Get( "cl_envshot_size", "256", FCVAR_ARCHIVE, "envshot size of cube side" );
2018-03-04 22:00:00 +01:00
v_dark = Cvar_Get( "v_dark", "0", 0, "starts level from dark screen" );
2017-02-12 22:00:00 +01:00
scr_viewsize = Cvar_Get( "viewsize", "120", FCVAR_ARCHIVE, "screen size" );
2008-11-15 22:00:00 +01:00
2007-11-06 22:00:00 +01:00
// register our commands
2008-01-20 22:00:00 +01:00
Cmd_AddCommand( "timerefresh", SCR_TimeRefresh_f, "turn quickly and print rendering statistcs" );
Cmd_AddCommand( "skyname", CL_SetSky_f, "set new skybox by basename" );
2018-06-13 23:00:00 +02:00
Cmd_AddCommand( "loadsky", CL_SetSky_f, "set new skybox by basename" );
2008-08-04 22:00:00 +02:00
Cmd_AddCommand( "viewpos", SCR_Viewpos_f, "prints current player origin" );
2011-09-19 22:00:00 +02:00
Cmd_AddCommand( "sizeup", SCR_SizeUp_f, "screen size up to 10 points" );
Cmd_AddCommand( "sizedown", SCR_SizeDown_f, "screen size down to 10 points" );
2008-11-09 22:00:00 +01:00
2016-11-19 22:00:00 +01:00
if( !UI_LoadProgs( ))
2010-07-21 22:00:00 +02:00
{
2018-03-01 22:00:00 +01:00
Con_Printf( S_ERROR "can't initialize gameui.dll\n" ); // there is non fatal for us
2018-03-03 22:00:00 +01:00
host.allow_console = true; // we need console, because menu is missing
2010-07-21 22:00:00 +02:00
}
2010-07-18 22:00:00 +02:00
2018-06-10 23:00:00 +02:00
SCR_VidInit();
2011-09-28 22:00:00 +02:00
SCR_LoadCreditsFont ();
2012-12-23 21:00:00 +01:00
SCR_RegisterTextures ();
2018-06-10 23:00:00 +02:00
SCR_InstallParticlePalette ();
2010-10-01 22:00:00 +02:00
SCR_InitCinematic();
2016-11-14 22:00:00 +01:00
CL_InitNetgraph();
2010-07-08 22:00:00 +02:00
2018-03-03 22:00:00 +01:00
if( host.allow_console && Sys_CheckParm( "-toconsole" ))
2016-11-19 22:00:00 +01:00
Cbuf_AddText( "toggleconsole\n" );
else UI_SetActiveMenu( true );
2009-10-02 22:00:00 +02:00
scr_init = true;
2008-08-04 22:00:00 +02:00
}
void SCR_Shutdown( void )
{
2009-10-02 22:00:00 +02:00
if( !scr_init ) return;
Cmd_RemoveCommand( "timerefresh" );
Cmd_RemoveCommand( "skyname" );
Cmd_RemoveCommand( "viewpos" );
2010-07-18 22:00:00 +02:00
UI_SetActiveMenu( false );
2016-11-19 22:00:00 +01:00
UI_UnloadProgs();
2010-12-21 22:00:00 +01:00
2009-10-02 22:00:00 +02:00
scr_init = false;
2007-11-06 22:00:00 +01:00
}