2007-06-21 22:00:00 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 1997-2001 Id Software, Inc.
|
|
|
|
|
|
|
|
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 2
|
|
|
|
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.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
// cl_view.c -- player rendering positioning
|
|
|
|
|
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"
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
V_ClearScene
|
|
|
|
|
|
|
|
Specifies the model that will be used as the world
|
|
|
|
====================
|
|
|
|
*/
|
2008-08-02 22:00:00 +02:00
|
|
|
void V_ClearScene( void )
|
2007-06-21 22:00:00 +02:00
|
|
|
{
|
2008-08-29 22:00:00 +02:00
|
|
|
re->ClearScene();
|
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
|
|
|
{
|
2009-01-23 22:00:00 +01:00
|
|
|
edict_t *clent;
|
2009-01-22 22:00:00 +01:00
|
|
|
|
2009-01-23 22:00:00 +01:00
|
|
|
clent = EDICT_NUM( cl.playernum + 1 );
|
|
|
|
|
|
|
|
// UNDONE: temporary place for detect waterlevel
|
|
|
|
CL_CheckWater( clent );
|
|
|
|
|
2009-09-18 22:00:00 +02:00
|
|
|
VectorCopy( clent->v.velocity, cl.refdef.simvel );
|
|
|
|
VectorCopy( clent->v.origin, cl.refdef.simorg );
|
|
|
|
VectorCopy( clent->v.view_ofs, cl.refdef.viewheight );
|
|
|
|
VectorCopy( clent->v.punchangle, cl.refdef.punchangle );
|
2009-01-22 22:00:00 +01:00
|
|
|
|
|
|
|
cl.refdef.movevars = &clgame.movevars;
|
2009-09-22 22:00:00 +02:00
|
|
|
cl.refdef.onground = clent->v.groundentity;
|
2009-01-23 22:00:00 +01:00
|
|
|
cl.refdef.areabits = cl.frame.areabits;
|
2009-09-18 22:00:00 +02:00
|
|
|
cl.refdef.health = clent->v.health;
|
|
|
|
cl.refdef.movetype = clent->v.movetype;
|
|
|
|
cl.refdef.idealpitch = clent->v.ideal_pitch;
|
2009-01-22 22:00:00 +01:00
|
|
|
cl.refdef.num_entities = clgame.numEntities;
|
|
|
|
cl.refdef.max_entities = clgame.maxEntities;
|
2009-09-18 22:00:00 +02:00
|
|
|
cl.refdef.maxclients = clgame.maxClients;
|
|
|
|
cl.refdef.time = cl.time * 0.001f;
|
2009-07-04 22:00:00 +02:00
|
|
|
cl.refdef.frametime = cls.frametime;
|
2009-01-22 22:00:00 +01:00
|
|
|
cl.refdef.demoplayback = cls.demoplayback;
|
|
|
|
cl.refdef.paused = cl_paused->integer;
|
2009-09-18 22:00:00 +02:00
|
|
|
cl.refdef.smoothing = cl_predict->integer;
|
2009-01-23 22:00:00 +01:00
|
|
|
cl.refdef.waterlevel = clent->v.waterlevel;
|
2009-09-18 22:00:00 +02:00
|
|
|
cl.refdef.flags = cl.render_flags;
|
2009-09-22 22:00:00 +02:00
|
|
|
cl.refdef.viewsize = 120; // fixme if you can
|
2009-01-23 22:00:00 +01:00
|
|
|
cl.refdef.nextView = 0;
|
2009-01-22 22:00:00 +01:00
|
|
|
|
|
|
|
// calculate the origin
|
2009-09-22 22:00:00 +02:00
|
|
|
if( cl_predict->integer && !cl.refdef.demoplayback )
|
2009-01-22 22:00:00 +01:00
|
|
|
{
|
|
|
|
// use predicted values
|
2009-09-18 22:00:00 +02:00
|
|
|
int i, delta;
|
|
|
|
float backlerp = 1.0 - cl.lerpFrac;
|
2009-01-22 22:00:00 +01:00
|
|
|
|
|
|
|
for( i = 0; i < 3; i++ )
|
2009-09-18 22:00:00 +02:00
|
|
|
cl.refdef.vieworg[i] = cl.predicted_origin[i] + cl.refdef.viewheight[i] - backlerp * cl.prediction_error[i];
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2009-01-22 22:00:00 +01:00
|
|
|
// smooth out stair climbing
|
2009-07-04 22:00:00 +02:00
|
|
|
delta = cls.realtime - cl.predicted_step_time;
|
2009-09-18 22:00:00 +02:00
|
|
|
if( delta < cl.serverframetime )
|
|
|
|
cl.refdef.vieworg[2] -= cl.predicted_step * ((cl.serverframetime - delta) / (float)cl.serverframetime);
|
2007-06-21 22:00:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-01-22 22:00:00 +01:00
|
|
|
===============
|
|
|
|
V_ApplyRefDef
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2009-01-22 22:00:00 +01:00
|
|
|
apply pre-calculated values
|
|
|
|
===============
|
2007-06-21 22:00:00 +02:00
|
|
|
*/
|
2009-01-23 22:00:00 +01:00
|
|
|
void V_AddViewModel( void )
|
2007-06-21 22:00:00 +02:00
|
|
|
{
|
2009-09-18 22:00:00 +02:00
|
|
|
if( cl.viewent.v.modelindex && !cl.refdef.nextView )
|
|
|
|
re->AddRefEntity( &cl.viewent, ED_VIEWMODEL );
|
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
|
|
|
{
|
2009-01-23 22:00:00 +01:00
|
|
|
do
|
|
|
|
{
|
2009-06-24 22:00:00 +02:00
|
|
|
clgame.dllFuncs.pfnCalcRefdef( &cl.refdef );
|
2009-01-23 22:00:00 +01:00
|
|
|
V_AddViewModel();
|
2009-01-25 22:00:00 +01:00
|
|
|
re->RenderFrame( &cl.refdef );
|
2009-01-23 22:00:00 +01:00
|
|
|
} while( cl.refdef.nextView );
|
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
|
|
|
{
|
2008-08-03 22:00:00 +02:00
|
|
|
if( !cl.video_prepped ) return; // still loading
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2009-01-25 22:00:00 +01:00
|
|
|
if( !cl.frame.valid )
|
2007-06-21 22:00:00 +02:00
|
|
|
{
|
2009-01-25 22:00:00 +01:00
|
|
|
SCR_FillRect( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, g_color_table[0] );
|
|
|
|
return;
|
|
|
|
}
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2009-01-25 22:00:00 +01:00
|
|
|
V_ClearScene ();
|
|
|
|
CL_AddEntities ();
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2009-01-25 22:00:00 +01:00
|
|
|
V_SetupRefDef ();
|
|
|
|
V_CalcRefDef ();
|
2007-06-21 22:00:00 +02:00
|
|
|
}
|
|
|
|
|
2007-11-06 22:00:00 +01:00
|
|
|
/*
|
|
|
|
==================
|
|
|
|
V_PreRender
|
|
|
|
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
bool V_PreRender( void )
|
|
|
|
{
|
2008-05-18 22:00:00 +02:00
|
|
|
// too early
|
2008-08-02 22:00:00 +02:00
|
|
|
if( !re ) return false;
|
2009-07-17 22:00:00 +02:00
|
|
|
|
2008-10-19 22:00:00 +02:00
|
|
|
re->BeginFrame();
|
2007-11-06 22:00:00 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
V_PostRender
|
|
|
|
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
void V_PostRender( void )
|
|
|
|
{
|
2009-09-23 22:00:00 +02:00
|
|
|
if( cls.scrshot_action == scrshot_inactive )
|
|
|
|
{
|
|
|
|
SCR_RSpeeds();
|
|
|
|
SCR_DrawNet();
|
|
|
|
SCR_DrawFPS();
|
|
|
|
UI_UpdateMenu( cls.realtime );
|
|
|
|
Con_DrawConsole();
|
|
|
|
}
|
2007-11-06 22:00:00 +01:00
|
|
|
re->EndFrame();
|
2008-07-17 22:00:00 +02:00
|
|
|
}
|