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

299 lines
7.8 KiB
C
Raw Normal View History

2011-05-09 22:00:00 +02:00
/*
cl_view.c - player rendering positioning
Copyright (C) 2009 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"
2008-11-25 22:00:00 +01:00
#include "const.h"
2010-08-15 22:00:00 +02:00
#include "entity_types.h"
2010-12-02 22:00:00 +01:00
#include "gl_local.h"
2011-04-08 22:00:00 +02:00
#include "vgui_draw.h"
2007-06-21 22:00:00 +02:00
2011-08-21 22:00:00 +02:00
/*
===============
V_MergeOverviewRefdef
merge refdef with overview settings
===============
*/
2016-11-14 22:00:00 +01:00
void V_MergeOverviewRefdef( void )
2011-08-21 22:00:00 +02:00
{
ref_overview_t *ov = &clgame.overView;
float aspect;
float size_x, size_y;
vec2_t mins, maxs;
2017-02-12 22:00:00 +01:00
if( !gl_overview->value ) return;
2011-08-21 22:00:00 +02:00
// NOTE: Xash3D may use 16:9 or 16:10 aspects
aspect = (float)glState.width / (float)glState.height;
size_x = fabs( 8192.0f / ov->flZoom );
size_y = fabs( 8192.0f / (ov->flZoom * aspect ));
// compute rectangle
ov->xLeft = -(size_x / 2);
ov->xRight = (size_x / 2);
ov->xTop = -(size_y / 2);
ov->xBottom = (size_y / 2);
2017-02-12 22:00:00 +01:00
if( gl_overview->value == 1 )
2011-08-21 22:00:00 +02:00
{
Con_NPrintf( 0, " Overview: Zoom %.2f, Map Origin (%.2f, %.2f, %.2f), Z Min %.2f, Z Max %.2f, Rotated %i\n",
ov->flZoom, ov->origin[0], ov->origin[1], ov->origin[2], ov->zNear, ov->zFar, ov->rotated );
}
2016-11-14 22:00:00 +01:00
VectorCopy( ov->origin, cl.refdef.vieworg );
cl.refdef.vieworg[2] = ov->zFar + ov->zNear;
Vector2Copy( cl.refdef.vieworg, mins );
Vector2Copy( cl.refdef.vieworg, maxs );
2011-08-21 22:00:00 +02:00
mins[!ov->rotated] += ov->xLeft;
maxs[!ov->rotated] += ov->xRight;
mins[ov->rotated] += ov->xTop;
maxs[ov->rotated] += ov->xBottom;
2016-11-14 22:00:00 +01:00
cl.refdef.viewangles[0] = 90.0f;
cl.refdef.viewangles[1] = 90.0f;
cl.refdef.viewangles[2] = (ov->rotated) ? (ov->flZoom < 0.0f) ? 180.0f : 0.0f : (ov->flZoom < 0.0f) ? -90.0f : 90.0f;
2011-08-21 22:00:00 +02:00
Mod_SetOrthoBounds( mins, maxs );
}
2012-12-23 21:00:00 +01:00
/*
===============
2016-11-14 22:00:00 +01:00
V_CalcViewRect
2012-12-23 21:00:00 +01:00
2016-11-14 22:00:00 +01:00
calc frame rectangle (Quake1 style)
2012-12-23 21:00:00 +01:00
===============
*/
2016-11-14 22:00:00 +01:00
void V_CalcViewRect( void )
2012-12-23 21:00:00 +01:00
{
2016-11-14 22:00:00 +01:00
int size, sb_lines;
2017-02-12 22:00:00 +01:00
if( scr_viewsize->value >= 120 )
2016-11-14 22:00:00 +01:00
sb_lines = 0; // no status bar at all
2017-02-12 22:00:00 +01:00
else if( scr_viewsize->value >= 110 )
2016-11-14 22:00:00 +01:00
sb_lines = 24; // no inventory
else sb_lines = 48;
2012-12-23 21:00:00 +01:00
2017-02-12 22:00:00 +01:00
size = Q_min( scr_viewsize->value, 100 );
2016-11-14 22:00:00 +01:00
2017-02-12 22:00:00 +01:00
cl.refdef.viewport[2] = scr_width->value * size / 100;
cl.refdef.viewport[3] = scr_height->value * size / 100;
2016-11-14 22:00:00 +01:00
2017-02-12 22:00:00 +01:00
if( cl.refdef.viewport[3] > scr_height->value - sb_lines )
cl.refdef.viewport[3] = scr_height->value - sb_lines;
if( cl.refdef.viewport[3] > scr_height->value )
cl.refdef.viewport[3] = scr_height->value;
2012-12-23 21:00:00 +01:00
2017-02-12 22:00:00 +01:00
cl.refdef.viewport[0] = ( scr_width->value - cl.refdef.viewport[2] ) / 2;
cl.refdef.viewport[1] = ( scr_height->value - sb_lines - cl.refdef.viewport[3] ) / 2;
2012-12-23 21:00:00 +01:00
}
2007-06-21 22:00:00 +02:00
/*
2009-01-22 22:00:00 +01:00
===============
2016-11-14 22:00:00 +01:00
V_SetupRefDef
2009-01-22 22:00:00 +01:00
2016-11-14 22:00:00 +01:00
update refdef values each frame
2009-01-22 22:00:00 +01:00
===============
2007-06-21 22:00:00 +02:00
*/
2016-11-14 22:00:00 +01:00
void V_SetupRefDef( void )
2007-06-21 22:00:00 +02:00
{
2016-11-14 22:00:00 +01:00
cl_entity_t *clent;
2011-08-14 22:00:00 +02:00
2016-11-14 22:00:00 +01:00
// compute viewport rectangle
V_CalcViewRect();
2011-08-14 22:00:00 +02:00
2016-11-14 22:00:00 +01:00
clent = CL_GetLocalPlayer ();
2012-05-28 22:00:00 +02:00
2016-11-14 22:00:00 +01:00
clgame.entities->curstate.scale = clgame.movevars.waveHeight;
2007-06-21 22:00:00 +02:00
2016-11-14 22:00:00 +01:00
cl.refdef.movevars = &clgame.movevars;
cl.refdef.health = cl.frame.client.health;
cl.refdef.playernum = cl.playernum;
cl.refdef.max_entities = clgame.maxEntities;
cl.refdef.maxclients = cl.maxclients;
cl.refdef.time = cl.time;
cl.refdef.frametime = cl.time - cl.oldtime;
cl.refdef.demoplayback = cls.demoplayback;
2017-02-12 22:00:00 +01:00
cl.refdef.viewsize = scr_viewsize->value;
2016-11-14 22:00:00 +01:00
cl.refdef.onlyClientDraw = 0; // reset clientdraw
cl.refdef.hardware = true; // always true
2017-02-12 22:00:00 +01:00
cl.refdef.spectator = (cls.spectator != 0);
2016-11-14 22:00:00 +01:00
cl.refdef.smoothing = cl.first_frame; // NOTE: currently this used to prevent ugly un-duck effect while level is changed
cl.scr_fov = bound( 1.0f, cl.scr_fov, 179.0f );
cl.refdef.nextView = 0;
2007-06-21 22:00:00 +02:00
2016-11-14 22:00:00 +01:00
// calc FOV
cl.refdef.fov_x = cl.scr_fov; // this is a final fov value
cl.refdef.fov_y = V_CalcFov( &cl.refdef.fov_x, cl.refdef.viewport[2], cl.refdef.viewport[3] );
2007-06-21 22:00:00 +02:00
2016-11-14 22:00:00 +01:00
// adjust FOV for widescreen
2017-02-12 22:00:00 +01:00
if( glState.wideScreen && r_adjust_fov->value )
2016-11-14 22:00:00 +01:00
V_AdjustFov( &cl.refdef.fov_x, &cl.refdef.fov_y, cl.refdef.viewport[2], cl.refdef.viewport[3], false );
2007-06-21 22:00:00 +02:00
2016-11-14 22:00:00 +01:00
if( CL_IsPredicted( ) && !cl.first_frame )
2007-06-21 22:00:00 +02:00
{
2016-11-14 22:00:00 +01:00
VectorCopy( cl.predicted.origin, cl.refdef.simorg );
VectorCopy( cl.predicted.velocity, cl.refdef.simvel );
VectorCopy( cl.predicted.viewofs, cl.refdef.viewheight );
VectorCopy( cl.predicted.punchangle, cl.refdef.punchangle );
cl.refdef.onground = ( cl.predicted.onground == -1 ) ? false : true;
cl.refdef.waterlevel = cl.predicted.waterlevel;
}
else
{
VectorCopy( cl.frame.client.origin, cl.refdef.simorg );
VectorCopy( cl.frame.client.view_ofs, cl.refdef.viewheight );
VectorCopy( cl.frame.client.velocity, cl.refdef.simvel );
VectorCopy( cl.frame.client.punchangle, cl.refdef.punchangle );
cl.refdef.onground = (cl.frame.client.flags & FL_ONGROUND) ? 1 : 0;
cl.refdef.waterlevel = cl.frame.client.waterlevel;
}
// setup the viewent variables
if( cl_lw->value ) clgame.viewent.curstate.modelindex = cl.predicted.viewmodel;
else clgame.viewent.curstate.modelindex = cl.frame.client.viewmodel;
clgame.viewent.model = Mod_Handle( clgame.viewent.curstate.modelindex );
clgame.viewent.curstate.number = cl.playernum + 1;
clgame.viewent.curstate.entityType = ET_NORMAL;
clgame.viewent.index = cl.playernum + 1;
2007-06-21 22:00:00 +02:00
}
2007-11-06 22:00:00 +01:00
/*
==================
V_PreRender
==================
*/
2010-10-26 22:00:00 +02:00
qboolean V_PreRender( void )
2007-11-06 22:00:00 +01:00
{
2008-05-18 22:00:00 +02:00
// too early
2010-12-02 22:00:00 +01:00
if( !glw_state.initialized )
return false;
2009-07-17 22:00:00 +02:00
2010-02-07 22:00:00 +01:00
if( host.state == HOST_NOFOCUS )
return false;
2010-12-09 22:00:00 +01:00
2010-02-07 22:00:00 +01:00
if( host.state == HOST_SLEEP )
return false;
2010-12-09 22:00:00 +01:00
// if the screen is disabled (loading plaque is up)
if( cls.disable_screen )
2010-04-12 22:00:00 +02:00
{
2011-04-09 22:00:00 +02:00
if(( host.realtime - cls.disable_screen ) > cl_timeout->value )
2010-12-09 22:00:00 +01:00
{
2016-11-14 22:00:00 +01:00
MsgDev( D_ERROR, "V_PreRender: loading plaque timed out\n" );
2010-12-09 22:00:00 +01:00
cls.disable_screen = 0.0f;
}
return false;
2010-04-12 22:00:00 +02:00
}
2011-02-22 22:00:00 +01:00
2010-12-09 22:00:00 +01:00
R_BeginFrame( !cl.refdef.paused );
2010-07-17 22:00:00 +02:00
return true;
2007-11-06 22:00:00 +01:00
}
2016-11-14 22:00:00 +01:00
//============================================================================
/*
==================
V_RenderView
==================
*/
void V_RenderView( void )
{
if( !cl.video_prepped || ( UI_IsVisible() && !cl.background ))
return; // still loading
2017-02-13 22:00:00 +01:00
if( cl.frame.valid && ( cl.force_refdef || !cl.refdef.paused ))
2016-11-14 22:00:00 +01:00
{
2017-02-13 22:00:00 +01:00
cl.force_refdef = false;
2016-11-14 22:00:00 +01:00
2017-02-13 22:00:00 +01:00
R_ClearScene ();
CL_AddEntities ();
V_SetupRefDef ();
2016-11-14 22:00:00 +01:00
}
R_Set2DMode( false );
SCR_AddDirtyPoint( 0, 0 );
2017-02-12 22:00:00 +01:00
SCR_AddDirtyPoint( scr_width->value - 1, scr_height->value - 1 );
2016-11-14 22:00:00 +01:00
tr.framecount++; // g-cont. keep actual frame for all viewpasses
2017-02-13 22:00:00 +01:00
do
2016-11-14 22:00:00 +01:00
{
2017-02-13 22:00:00 +01:00
clgame.dllFuncs.pfnCalcRefdef( &cl.refdef );
V_MergeOverviewRefdef();
R_RenderFrame( &cl.refdef, true );
cl.refdef.onlyClientDraw = false;
} while( cl.refdef.nextView );
2016-11-14 22:00:00 +01:00
// draw debug triangles on a server
SV_DrawDebugTriangles ();
}
2007-11-06 22:00:00 +01:00
/*
==================
V_PostRender
==================
*/
void V_PostRender( void )
{
2016-11-14 22:00:00 +01:00
static double oldtime;
qboolean draw_2d = false;
2011-09-03 22:00:00 +02:00
2010-12-12 22:00:00 +01:00
R_Set2DMode( true );
2016-11-14 22:00:00 +01:00
if( cls.state == ca_active && cls.scrshot_action != scrshot_mapshot )
2010-12-12 22:00:00 +01:00
{
2011-09-19 22:00:00 +02:00
SCR_TileClear();
2010-12-12 22:00:00 +01:00
CL_DrawHUD( CL_ACTIVE );
2011-03-18 22:00:00 +01:00
VGui_Paint();
2010-12-12 22:00:00 +01:00
}
2011-09-03 22:00:00 +02:00
switch( cls.scrshot_action )
{
case scrshot_inactive:
case scrshot_normal:
case scrshot_snapshot:
draw_2d = true;
break;
}
if( draw_2d )
2009-09-23 22:00:00 +02:00
{
SCR_RSpeeds();
2010-07-26 22:00:00 +02:00
SCR_NetSpeeds();
2016-11-14 22:00:00 +01:00
SCR_DrawNetGraph();
2012-06-25 22:00:00 +02:00
SV_DrawOrthoTriangles();
2010-12-12 22:00:00 +01:00
CL_DrawDemoRecording();
2010-12-09 22:00:00 +01:00
CL_DrawHUD( CL_CHANGELEVEL );
2016-11-14 22:00:00 +01:00
R_ShowTextures();
2009-09-23 22:00:00 +02:00
Con_DrawConsole();
2010-12-27 22:00:00 +01:00
UI_UpdateMenu( host.realtime );
2011-07-07 22:00:00 +02:00
Con_DrawVersion();
2011-04-08 22:00:00 +02:00
Con_DrawDebug(); // must be last
2016-11-14 22:00:00 +01:00
2017-02-13 22:00:00 +01:00
S_ExtraUpdate();
2009-09-23 22:00:00 +02:00
}
2010-07-23 22:00:00 +02:00
2009-12-11 22:00:00 +01:00
SCR_MakeScreenShot();
2010-12-02 22:00:00 +01:00
R_EndFrame();
2008-07-17 22:00:00 +02:00
}