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

425 lines
11 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
/*
2009-01-22 22:00:00 +01:00
===============
V_SetupRefDef
2007-06-21 22:00:00 +02:00
2009-01-22 22:00:00 +01:00
update refdef values each frame
===============
2007-06-21 22:00:00 +02:00
*/
2009-01-22 22:00:00 +01:00
void V_SetupRefDef( void )
2007-06-21 22:00:00 +02:00
{
2010-08-07 22:00:00 +02:00
cl_entity_t *clent;
2011-09-19 22:00:00 +02:00
int size;
int sb_lines;
2009-01-22 22:00:00 +01:00
2009-11-26 22:00:00 +01:00
clent = CL_GetLocalPlayer ();
2009-01-23 22:00:00 +01:00
2011-02-26 22:00:00 +01:00
clgame.entities->curstate.scale = clgame.movevars.waveHeight;
2016-08-13 23:00:00 +02:00
if( cl_lw->value ) clgame.viewent.curstate.modelindex = cl.predicted.viewmodel;
else clgame.viewent.curstate.modelindex = cl.frame.client.viewmodel;
2011-02-20 22:00:00 +01:00
clgame.viewent.model = Mod_Handle( clgame.viewent.curstate.modelindex );
2011-07-22 22:00:00 +02:00
clgame.viewent.curstate.number = cl.playernum + 1;
2010-12-19 22:00:00 +01:00
clgame.viewent.curstate.entityType = ET_NORMAL;
clgame.viewent.index = cl.playernum + 1;
2010-08-20 22:00:00 +02:00
2009-01-22 22:00:00 +01:00
cl.refdef.movevars = &clgame.movevars;
2016-03-17 22:00:00 +01:00
cl.refdef.health = cl.frame.client.health;
2010-11-15 22:00:00 +01:00
cl.refdef.playernum = cl.playernum;
2010-08-20 22:00:00 +02:00
cl.refdef.max_entities = clgame.maxEntities;
cl.refdef.maxclients = cl.maxclients;
2011-04-08 22:00:00 +02:00
cl.refdef.time = cl.time;
2010-10-09 22:00:00 +02:00
cl.refdef.frametime = cl.time - cl.oldtime;
2009-01-22 22:00:00 +01:00
cl.refdef.demoplayback = cls.demoplayback;
2011-09-19 22:00:00 +02:00
cl.refdef.viewsize = scr_viewsize->integer;
2010-12-14 22:00:00 +01:00
cl.refdef.onlyClientDraw = 0; // reset clientdraw
2010-11-15 22:00:00 +01:00
cl.refdef.hardware = true; // always true
2012-03-24 21:00:00 +01:00
cl.refdef.spectator = (clent->curstate.spectator != 0);
2016-08-13 23:00:00 +02:00
cl.refdef.smoothing = false; // old stuff to smooth multiplayer view
2009-01-23 22:00:00 +01:00
cl.refdef.nextView = 0;
2009-01-22 22:00:00 +01:00
2011-09-19 22:00:00 +02:00
SCR_AddDirtyPoint( 0, 0 );
SCR_AddDirtyPoint( scr_width->integer - 1, scr_height->integer - 1 );
if( cl.refdef.viewsize >= 120 )
sb_lines = 0; // no status bar at all
else if( cl.refdef.viewsize >= 110 )
sb_lines = 24; // no inventory
else sb_lines = 48;
size = min( scr_viewsize->integer, 100 );
cl.refdef.viewport[2] = scr_width->integer * size / 100;
cl.refdef.viewport[3] = scr_height->integer * size / 100;
if( cl.refdef.viewport[3] > scr_height->integer - sb_lines )
cl.refdef.viewport[3] = scr_height->integer - sb_lines;
if( cl.refdef.viewport[3] > scr_height->integer )
cl.refdef.viewport[3] = scr_height->integer;
2012-12-23 21:00:00 +01:00
2011-09-19 22:00:00 +02:00
cl.refdef.viewport[0] = (scr_width->integer - cl.refdef.viewport[2]) / 2;
cl.refdef.viewport[1] = (scr_height->integer - sb_lines - cl.refdef.viewport[3]) / 2;
2010-08-20 22:00:00 +02:00
2016-08-13 23:00:00 +02:00
cl.scr_fov = bound( 1.0f, cl.scr_fov, 179.0f );
2016-08-12 23:00:00 +02:00
2010-11-15 22:00:00 +01:00
// calc FOV
2016-08-12 23:00:00 +02:00
cl.refdef.fov_x = cl.scr_fov; // this is a final fov value
2010-12-06 22:00:00 +01:00
cl.refdef.fov_y = V_CalcFov( &cl.refdef.fov_x, cl.refdef.viewport[2], cl.refdef.viewport[3] );
2010-11-15 22:00:00 +01:00
2011-12-04 21:00:00 +01:00
// adjust FOV for widescreen
if( glState.wideScreen && r_adjust_fov->integer )
V_AdjustFov( &cl.refdef.fov_x, &cl.refdef.fov_y, cl.refdef.viewport[2], cl.refdef.viewport[3], false );
2010-03-14 22:00:00 +01:00
if( CL_IsPredicted( ) && !cl.refdef.demoplayback )
2015-09-16 23:00:00 +02:00
{
2016-08-13 23:00:00 +02: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;
2009-12-05 22:00:00 +01:00
}
else
{
2016-03-17 22:00:00 +01:00
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 );
2016-08-13 23:00:00 +02:00
cl.refdef.onground = (cl.frame.client.flags & FL_ONGROUND) ? 1 : 0;
cl.refdef.waterlevel = cl.frame.client.waterlevel;
2007-06-21 22:00:00 +02:00
}
}
2011-08-21 22:00:00 +02:00
/*
===============
V_SetupOverviewState
Get initial overview values
===============
*/
void V_SetupOverviewState( void )
{
ref_overview_t *ov = &clgame.overView;
float mapAspect, screenAspect, aspect;
ov->rotated = ( world.size[1] <= world.size[0] ) ? true : false;
// calculate nearest aspect
mapAspect = world.size[!ov->rotated] / world.size[ov->rotated];
screenAspect = (float)glState.width / (float)glState.height;
aspect = max( mapAspect, screenAspect );
ov->zNear = world.maxs[2];
ov->zFar = world.mins[2];
ov->flZoom = ( 8192.0f / world.size[ov->rotated] ) / aspect;
VectorAverage( world.mins, world.maxs, ov->origin );
}
/*
===============
V_WriteOverviewScript
Create overview scrip file
===============
*/
void V_WriteOverviewScript( void )
{
ref_overview_t *ov = &clgame.overView;
string filename;
file_t *f;
Q_snprintf( filename, sizeof( filename ), "overviews/%s.txt", clgame.mapname );
f = FS_Open( filename, "w", false );
if( !f ) return;
FS_Printf( f, "// overview description file for %s.bsp\n\n", clgame.mapname );
FS_Print( f, "global\n{\n" );
FS_Printf( f, "\tZOOM\t%.2f\n", ov->flZoom );
FS_Printf( f, "\tORIGIN\t%.f\t%.f\t%.f\n", ov->origin[0], ov->origin[1], ov->zFar + 1 );
FS_Printf( f, "\tROTATED\t%i\n", ov->rotated ? 1 : 0 );
FS_Print( f, "}\n\nlayer\n{\n" );
FS_Printf( f, "\tIMAGE\t\"overviews/%s.bmp\"\n", clgame.mapname );
FS_Printf( f, "\tHEIGHT\t%.f\n", ov->zFar + 1 ); // ???
FS_Print( f, "}\n" );
FS_Close( f );
}
/*
===============
V_ProcessOverviewCmds
Transform user movement into overview adjust
===============
*/
void V_ProcessOverviewCmds( usercmd_t *cmd )
{
ref_overview_t *ov = &clgame.overView;
int sign = 1;
if( !gl_overview->integer ) return;
if( ov->flZoom < 0.0f ) sign = -1;
if( cmd->upmove > 0.0f ) ov->zNear += 1.0f;
else if( cmd->upmove < 0.0f ) ov->zNear -= 1.0f;
if( cmd->buttons & IN_JUMP ) ov->zFar += 1.0f;
else if( cmd->buttons & IN_DUCK ) ov->zFar -= 1.0f;
if( cmd->buttons & IN_FORWARD ) ov->origin[ov->rotated] -= sign * 1.0f;
else if( cmd->buttons & IN_BACK ) ov->origin[ov->rotated] += sign * 1.0f;
if( ov->rotated )
{
if( cmd->buttons & ( IN_RIGHT|IN_MOVERIGHT ))
ov->origin[0] -= sign * 1.0f;
else if( cmd->buttons & ( IN_LEFT|IN_MOVELEFT ))
ov->origin[0] += sign * 1.0f;
}
else
{
if( cmd->buttons & ( IN_RIGHT|IN_MOVERIGHT ))
ov->origin[1] += sign * 1.0f;
else if( cmd->buttons & ( IN_LEFT|IN_MOVELEFT ))
ov->origin[1] -= sign * 1.0f;
}
if( cmd->buttons & IN_ATTACK ) ov->flZoom += 0.01f;
else if( cmd->buttons & IN_ATTACK2 ) ov->flZoom -= 0.01f;
if( ov->flZoom == 0.0f ) ov->flZoom = 0.0001f; // to prevent disivion by zero
}
/*
===============
V_MergeOverviewRefdef
merge refdef with overview settings
===============
*/
void V_MergeOverviewRefdef( ref_params_t *fd )
{
ref_overview_t *ov = &clgame.overView;
float aspect;
float size_x, size_y;
vec2_t mins, maxs;
if( !gl_overview->integer ) return;
// 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);
if( gl_overview->integer == 1 )
{
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 );
}
VectorCopy( ov->origin, fd->vieworg );
fd->vieworg[2] = ov->zFar + ov->zNear;
Vector2Copy( fd->vieworg, mins );
Vector2Copy( fd->vieworg, maxs );
mins[!ov->rotated] += ov->xLeft;
maxs[!ov->rotated] += ov->xRight;
mins[ov->rotated] += ov->xTop;
maxs[ov->rotated] += ov->xBottom;
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;
Mod_SetOrthoBounds( mins, maxs );
}
2012-12-23 21:00:00 +01:00
/*
===============
V_ProcessShowTexturesCmds
navigate around texture atlas
===============
*/
void V_ProcessShowTexturesCmds( usercmd_t *cmd )
{
static int oldbuttons;
int changed;
int pressed, released;
if( !gl_showtextures->integer ) return;
changed = (oldbuttons ^ cmd->buttons);
pressed = changed & cmd->buttons;
released = changed & (~cmd->buttons);
if( released & ( IN_RIGHT|IN_MOVERIGHT ))
Cvar_SetFloat( "r_showtextures", gl_showtextures->integer + 1 );
if( released & ( IN_LEFT|IN_MOVELEFT ))
Cvar_SetFloat( "r_showtextures", max( 1, gl_showtextures->integer - 1 ));
oldbuttons = cmd->buttons;
}
2007-06-21 22:00:00 +02:00
/*
2009-01-22 22:00:00 +01:00
===============
V_CalcRefDef
sets cl.refdef view values
===============
2007-06-21 22:00:00 +02:00
*/
2009-01-22 22:00:00 +01:00
void V_CalcRefDef( void )
2007-06-21 22:00:00 +02:00
{
2011-09-28 22:00:00 +02:00
R_Set2DMode( false );
tr.framecount++; // g-cont. keep actual frame for all viewpasses
2011-08-14 22:00:00 +02:00
2009-01-23 22:00:00 +01:00
do
{
2009-06-24 22:00:00 +02:00
clgame.dllFuncs.pfnCalcRefdef( &cl.refdef );
2011-08-21 22:00:00 +02:00
V_MergeOverviewRefdef( &cl.refdef );
2010-12-02 22:00:00 +01:00
R_RenderFrame( &cl.refdef, true );
2010-12-14 22:00:00 +01:00
cl.refdef.onlyClientDraw = false;
2009-01-23 22:00:00 +01:00
} while( cl.refdef.nextView );
2011-08-14 22:00:00 +02:00
2012-05-28 22:00:00 +02:00
// Xash3D extension. draw debug triangles on a server
SV_DrawDebugTriangles ();
2011-09-19 22:00:00 +02:00
SCR_AddDirtyPoint( cl.refdef.viewport[0], cl.refdef.viewport[1] );
SCR_AddDirtyPoint( cl.refdef.viewport[0] + cl.refdef.viewport[2] - 1, cl.refdef.viewport[1] + cl.refdef.viewport[3] - 1 );
2007-06-21 22:00:00 +02:00
}
//============================================================================
/*
==================
V_RenderView
==================
*/
2007-11-05 22:00:00 +01:00
void V_RenderView( void )
2007-06-21 22:00:00 +02:00
{
2011-04-05 22:00:00 +02:00
if( !cl.video_prepped || ( UI_IsVisible() && !cl.background ))
return; // still loading
2007-06-21 22:00:00 +02:00
2010-07-13 22:00:00 +02:00
if( cl.frame.valid && ( cl.force_refdef || !cl.refdef.paused ))
2007-06-21 22:00:00 +02:00
{
2009-09-28 22:00:00 +02:00
cl.force_refdef = false;
2007-06-21 22:00:00 +02:00
2011-04-09 22:00:00 +02:00
R_ClearScene ();
2009-09-28 22:00:00 +02:00
CL_AddEntities ();
V_SetupRefDef ();
}
2007-06-21 22:00:00 +02:00
2009-01-25 22:00:00 +01:00
V_CalcRefDef ();
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
{
MsgDev( D_NOTE, "V_PreRender: loading plaque timed out.\n" );
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
}
/*
==================
V_PostRender
==================
*/
void V_PostRender( void )
{
2011-09-03 22:00:00 +02:00
qboolean draw_2d = false;
2010-12-12 22:00:00 +01:00
R_Set2DMode( true );
if( cls.state == ca_active )
{
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();
2009-09-23 22:00:00 +02:00
SCR_DrawFPS();
2012-06-25 22:00:00 +02:00
SV_DrawOrthoTriangles();
2010-12-12 22:00:00 +01:00
CL_DrawDemoRecording();
R_ShowTextures();
2010-12-09 22:00:00 +01:00
CL_DrawHUD( CL_CHANGELEVEL );
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
2010-10-09 22:00:00 +02: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
}