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

350 lines
8.5 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
2017-02-15 22:00:00 +01:00
/*
===============
V_CalcViewRect
calc frame rectangle (Quake1 style)
===============
*/
void V_CalcViewRect( void )
{
int size, sb_lines;
if( scr_viewsize->value >= 120.0f )
sb_lines = 0; // no status bar at all
else if( scr_viewsize->value >= 110.0f )
sb_lines = 24; // no inventory
else sb_lines = 48;
size = Q_min( scr_viewsize->value, 100 );
clgame.viewport[2] = glState.width * size / 100;
clgame.viewport[3] = glState.height * size / 100;
if( clgame.viewport[3] > glState.height - sb_lines )
clgame.viewport[3] = glState.height - sb_lines;
if( clgame.viewport[3] > glState.height )
clgame.viewport[3] = glState.height;
clgame.viewport[0] = ( glState.width - clgame.viewport[2] ) / 2;
clgame.viewport[1] = ( glState.height - sb_lines - clgame.viewport[3] ) / 2;
}
/*
===============
V_SetupViewModel
===============
*/
void V_SetupViewModel( void )
{
cl_entity_t *view = &clgame.viewent;
// setup the viewent variables
view->model = Mod_Handle( cl.local.viewmodel );
view->curstate.modelindex = cl.local.viewmodel;
view->curstate.number = cl.playernum + 1;
view->index = cl.playernum + 1;
view->curstate.colormap = 0;
view->curstate.frame = 0;
}
/*
===============
V_SetRefParams
===============
*/
void V_SetRefParams( ref_params_t *fd )
{
memset( fd, 0, sizeof( ref_params_t ));
// probably this is not needs
VectorCopy( RI.vieworg, fd->vieworg );
VectorCopy( RI.viewangles, fd->viewangles );
fd->frametime = host.frametime;
fd->time = cl.time;
fd->intermission = cl.intermission; // Quake Remake compatibility
fd->paused = (cl.paused != 0);
fd->spectator = (cls.spectator != 0);
fd->onground = (cl.local.onground != -1);
fd->waterlevel = cl.local.waterlevel;
VectorCopy( cl.simvel, fd->simvel );
VectorCopy( cl.simorg, fd->simorg );
VectorCopy( cl.viewheight, fd->viewheight );
fd->idealpitch = cl.local.idealpitch;
VectorCopy( cl.viewangles, fd->cl_viewangles );
fd->health = cl.local.health;
VectorCopy( cl.crosshairangle, fd->crosshairangle );
fd->viewsize = scr_viewsize->value;
VectorCopy( cl.punchangle, fd->punchangle );
fd->maxclients = cl.maxclients;
fd->viewentity = cl.viewentity;
fd->playernum = cl.playernum;
fd->max_entities = clgame.maxEntities;
fd->demoplayback = cls.demoplayback;
fd->hardware = 1; // OpenGL
if( cl.first_frame ) fd->smoothing = true; // NOTE: currently this used to prevent ugly un-duck effect while level is changed
else fd->smoothing = cl.local.pushmsec; // enable smoothing in multiplayer by server request (AMX uses)
// get pointers to movement vars and user cmd
fd->movevars = &clgame.movevars;
fd->cmd = cl.cmd;
// setup viewport
fd->viewport[0] = clgame.viewport[0];
fd->viewport[1] = clgame.viewport[1];
fd->viewport[2] = clgame.viewport[2];
fd->viewport[3] = clgame.viewport[3];
fd->onlyClientDraw = 0; // reset clientdraw
fd->nextView = 0; // reset nextview
// Xash3D extension. FIXME: it's needs to be removed...
// calc FOV
fd->fov_x = bound( 1.0f, cl.local.scr_fov, 179.0f ); // this is a final fov value
fd->fov_y = V_CalcFov( &fd->fov_x, clgame.viewport[2], clgame.viewport[3] );
// adjust FOV for widescreen
if( glState.wideScreen && r_adjust_fov->value )
V_AdjustFov( &fd->fov_x, &fd->fov_y, clgame.viewport[2], clgame.viewport[3], false );
}
2011-08-21 22:00:00 +02:00
/*
===============
V_MergeOverviewRefdef
merge refdef with overview settings
===============
*/
2017-02-15 22:00:00 +01:00
void V_RefParamsApplyOverview( ref_params_t *fd )
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-15 22:00:00 +01:00
if( !CL_IsDevOverviewMode( ))
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 );
}
2017-02-15 22:00:00 +01:00
VectorCopy( ov->origin, fd->vieworg );
fd->vieworg[2] = ov->zFar + ov->zNear;
Vector2Copy( fd->vieworg, mins );
Vector2Copy( fd->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;
2017-02-15 22:00:00 +01:00
fd->viewangles[0] = 90.0f;
fd->viewangles[1] = 90.0f;
fd->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
/*
2017-02-15 22:00:00 +01:00
=============
V_GetRefParams
=============
2012-12-23 21:00:00 +01:00
*/
2017-02-15 22:00:00 +01:00
void V_GetRefParams( ref_params_t *fd )
2012-12-23 21:00:00 +01:00
{
2017-02-15 22:00:00 +01:00
// part1: deniable updates
VectorCopy( fd->simvel, cl.simvel );
VectorCopy( fd->simorg, cl.simorg );
VectorCopy( fd->punchangle, cl.punchangle );
VectorCopy( fd->viewheight, cl.viewheight );
// part2: really used updates
VectorCopy( fd->crosshairangle, cl.crosshairangle );
VectorCopy( fd->cl_viewangles, cl.viewangles );
cl.intermission = fd->intermission; // Quake Remake compatibility
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
2017-02-15 22:00:00 +01:00
R_BeginFrame( !cl.paused );
2010-12-09 22:00:00 +01:00
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 )
{
2017-02-15 22:00:00 +01:00
ref_params_t rp;
int viewnum = 0;
2016-11-14 22:00:00 +01:00
if( !cl.video_prepped || ( UI_IsVisible() && !cl.background ))
return; // still loading
2017-02-15 22:00:00 +01:00
if( cl.frame.valid && ( cl.force_refdef || !cl.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 ();
2016-11-14 22:00:00 +01:00
}
2017-02-15 22:00:00 +01:00
V_CalcViewRect (); // compute viewport rectangle
V_SetRefParams( &rp );
V_SetupViewModel ();
2016-11-14 22:00:00 +01:00
R_Set2DMode( false );
2017-02-15 22:00:00 +01:00
SCR_AddDirtyPoint( 0, 0 );
SCR_AddDirtyPoint( clgame.viewport[2] - 1, clgame.viewport[3] - 1 );
GL_BackendStartFrame ();
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-15 22:00:00 +01:00
clgame.dllFuncs.pfnCalcRefdef( &rp );
V_RefParamsApplyOverview( &rp );
V_GetRefParams( &rp );
if ( viewnum == 0 && rp.onlyClientDraw )
{
pglClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
pglClear( GL_COLOR_BUFFER_BIT );
}
R_RenderFrame( &rp, true, cl.local.scr_fov );
viewnum++;
} while( rp.nextView );
2016-11-14 22:00:00 +01:00
// draw debug triangles on a server
SV_DrawDebugTriangles ();
2017-02-15 22:00:00 +01:00
GL_BackendEndFrame ();
2016-11-14 22:00:00 +01:00
}
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
}