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

196 lines
4.2 KiB
C
Raw Normal View History

2009-11-23 22:00:00 +01:00
//=======================================================================
// Copyright XashXT Group 2009 <20>
// cl_view.c - player rendering positioning
//=======================================================================
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"
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
{
2010-07-18 22:00:00 +02:00
if( re ) 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-11-26 22:00:00 +01:00
edict_t *clent;
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
// UNDONE: temporary place for detect waterlevel
CL_CheckWater( clent );
2009-09-18 22:00:00 +02:00
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-09-18 22:00:00 +02:00
cl.refdef.health = clent->v.health;
cl.refdef.movetype = clent->v.movetype;
2010-06-23 22:00:00 +02:00
cl.refdef.idealpitch = clent->v.idealpitch;
2009-09-28 22:00:00 +02:00
cl.refdef.num_entities = clgame.globals->numEntities;
cl.refdef.max_entities = clgame.globals->maxEntities;
cl.refdef.maxclients = clgame.globals->maxClients;
2010-06-20 22:00:00 +02:00
cl.refdef.time = cl.time;
cl.refdef.frametime = cl.time - cl.oldtime;
2009-01-22 22:00:00 +01:00
cl.refdef.demoplayback = cls.demoplayback;
2010-06-20 22:00:00 +02:00
cl.refdef.smoothing = cl_smooth->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-12-05 22:00:00 +01: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
2010-03-14 22:00:00 +01:00
if( CL_IsPredicted( ) && !cl.refdef.demoplayback )
2009-01-22 22:00:00 +01:00
{
// use predicted values
2010-02-10 22:00:00 +01:00
float backlerp = 1.0f - cl.lerpFrac;
2010-06-20 22:00:00 +02:00
int i;
2009-01-22 22:00:00 +01:00
for( i = 0; i < 3; i++ )
2009-12-05 22:00:00 +01:00
{
cl.refdef.simorg[i] = cl.predicted_origin[i] - backlerp * cl.prediction_error[i];
cl.refdef.viewheight[i] = cl.predicted_viewofs[i] - backlerp * cl.prediction_error[i];
}
VectorCopy( cl.predicted_velocity, cl.refdef.simvel );
}
else
{
VectorCopy( clent->v.origin, cl.refdef.simorg );
VectorCopy( clent->v.view_ofs, cl.refdef.viewheight );
VectorCopy( clent->v.velocity, cl.refdef.simvel );
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-28 22:00:00 +02:00
if( cl.refdef.nextView ) return; // add viewmodel only at firstperson pass
2009-10-18 22:00:00 +02:00
if( !cl.frame.valid || cl.refdef.paused ) return;
2010-02-23 22:00:00 +01:00
2010-03-14 22:00:00 +01:00
clgame.dllFuncs.pfnAddVisibleEntity( &clgame.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
2010-07-13 22:00:00 +02:00
if( !cl.refdef.paused )
{
clgame.globals->time = cl.time; // clamped
clgame.globals->frametime = cl.time - cl.oldtime; // used by input code
}
else clgame.globals->frametime = 0.0f; // pause
2009-09-28 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
2009-09-28 22:00:00 +02:00
V_ClearScene ();
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
==================
*/
bool V_PreRender( void )
{
2010-04-12 22:00:00 +02:00
bool clearScene = true;
static bool oldState;
2010-03-30 22:00:00 +02:00
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
2010-02-07 22:00:00 +01:00
if( host.state == HOST_NOFOCUS )
return false;
if( host.state == HOST_SLEEP )
return false;
2010-07-17 22:00:00 +02:00
if( cl.refdef.paused || cls.changelevel )
2010-03-30 22:00:00 +02:00
clearScene = false;
re->BeginFrame( clearScene );
2010-06-28 22:00:00 +02:00
S_BeginFrame ();
2010-04-12 22:00:00 +02:00
2010-07-17 22:00:00 +02:00
if( !oldState && cls.changelevel )
2010-04-12 22:00:00 +02:00
{
// fire once
CL_DrawHUD( CL_CHANGELEVEL );
re->EndFrame();
}
2010-07-17 22:00:00 +02:00
oldState = cls.changelevel;
2010-04-12 22:00:00 +02:00
2010-07-17 22:00:00 +02:00
if( cls.changelevel )
return false;
return true;
2007-11-06 22:00:00 +01:00
}
/*
==================
V_PostRender
==================
*/
void V_PostRender( void )
{
2009-09-23 22:00:00 +02:00
if( cls.scrshot_action == scrshot_inactive )
{
SCR_RSpeeds();
SCR_DrawFPS();
2010-07-18 22:00:00 +02:00
UI_UpdateMenu( host.realtime );
2009-09-23 22:00:00 +02:00
Con_DrawConsole();
}
2009-12-11 22:00:00 +01:00
SCR_MakeScreenShot();
2007-11-06 22:00:00 +01:00
re->EndFrame();
2008-07-17 22:00:00 +02:00
}