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/client/global/dll_int.cpp

300 lines
8.6 KiB
C++
Raw Normal View History

2008-12-25 22:00:00 +01:00
//=======================================================================
// Copyright XashXT Group 2008 <20>
// dll_int.cpp - dll entry points
//=======================================================================
#include "extdll.h"
2009-01-22 22:00:00 +01:00
#include "utils.h"
2009-08-22 22:00:00 +02:00
#include "ref_params.h"
#include "studio_ref.h"
2008-12-25 22:00:00 +01:00
#include "hud.h"
2009-10-20 22:00:00 +02:00
#include "r_particle.h"
2009-12-02 22:00:00 +01:00
#include "ev_hldm.h"
2008-12-25 22:00:00 +01:00
cl_enginefuncs_t g_engfuncs;
2009-09-28 22:00:00 +02:00
cl_globalvars_t *gpGlobals;
2008-12-25 22:00:00 +01:00
CHud gHUD;
// main DLL entry point
BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
{
return TRUE;
}
static HUD_FUNCTIONS gFunctionTable =
{
sizeof( HUD_FUNCTIONS ),
HUD_VidInit,
HUD_Init,
HUD_Redraw,
HUD_UpdateClientData,
2009-08-22 22:00:00 +02:00
HUD_UpdateEntityVars,
2008-12-25 22:00:00 +01:00
HUD_Reset,
HUD_Frame,
HUD_Shutdown,
2009-10-20 22:00:00 +02:00
HUD_DrawTriangles,
2008-12-25 22:00:00 +01:00
HUD_CreateEntities,
HUD_StudioEvent,
2009-09-17 22:00:00 +02:00
HUD_StudioFxTransform,
2008-12-25 22:00:00 +01:00
V_CalcRefdef,
2009-09-13 22:00:00 +02:00
V_StartPitchDrift,
V_StopPitchDrift,
2008-12-25 22:00:00 +01:00
};
//=======================================================================
// GetApi
//=======================================================================
2009-09-28 22:00:00 +02:00
int CreateAPI( HUD_FUNCTIONS *pFunctionTable, cl_enginefuncs_t* pEngfuncsFromEngine, cl_globalvars_t *pGlobals )
2008-12-25 22:00:00 +01:00
{
2009-01-11 22:00:00 +01:00
if( !pFunctionTable || !pEngfuncsFromEngine )
2008-12-25 22:00:00 +01:00
{
return FALSE;
}
// copy HUD_FUNCTIONS table to engine, copy engfuncs table from engine
memcpy( pFunctionTable, &gFunctionTable, sizeof( HUD_FUNCTIONS ));
memcpy( &g_engfuncs, pEngfuncsFromEngine, sizeof( cl_enginefuncs_t ));
2009-09-28 22:00:00 +02:00
gpGlobals = pGlobals;
2008-12-25 22:00:00 +01:00
return TRUE;
}
int HUD_VidInit( void )
{
2009-10-20 22:00:00 +02:00
if( g_pParticleSystems )
g_pParticleSystems->ClearSystems();
2008-12-25 22:00:00 +01:00
gHUD.VidInit();
return 1;
}
void HUD_Init( void )
{
2009-10-18 22:00:00 +02:00
g_engfuncs.pfnAddCommand ("noclip", NULL, "enable or disable no clipping mode" );
g_engfuncs.pfnAddCommand ("notarget", NULL, "notarget mode (monsters do not see you)" );
g_engfuncs.pfnAddCommand ("fullupdate", NULL, "re-init HUD on start demo recording" );
g_engfuncs.pfnAddCommand ("give", NULL, "give specified item or weapon" );
g_engfuncs.pfnAddCommand ("drop", NULL, "drop current/specified item or weapon" );
g_engfuncs.pfnAddCommand ("intermission", NULL, "go to intermission" );
2009-10-23 22:00:00 +02:00
g_engfuncs.pfnAddCommand ("spectate", NULL, "enable spectator mode" );
g_engfuncs.pfnAddCommand ("gametitle", NULL, "show game logo" );
2009-10-18 22:00:00 +02:00
g_engfuncs.pfnAddCommand ("god", NULL, "classic cheat" );
g_engfuncs.pfnAddCommand ("fov", NULL, "set client field of view" );
2009-10-29 22:00:00 +01:00
g_engfuncs.pfnAddCommand ("fly", NULL, "fly mode (flight)" );
2009-10-18 22:00:00 +02:00
2009-10-20 22:00:00 +02:00
if ( g_pParticleSystems )
{
// init partsystem
delete g_pParticleSystems;
g_pParticleSystems = NULL;
}
g_pParticleSystems = new ParticleSystemManager();
2008-12-25 22:00:00 +01:00
gHUD.Init();
2009-01-22 22:00:00 +01:00
V_Init();
2009-12-02 22:00:00 +01:00
// link all events
EV_HookEvents ();
2008-12-25 22:00:00 +01:00
}
2008-12-26 22:00:00 +01:00
int HUD_Redraw( float flTime, int state )
2008-12-25 22:00:00 +01:00
{
2009-09-28 22:00:00 +02:00
static int oldstate;
if( oldstate == CL_ACTIVE && state == CL_LOADING )
{
2009-11-10 22:00:00 +01:00
// fire only once to prevent multiply GL_BLEND each frame
2009-09-28 22:00:00 +02:00
DrawImageBar( 100, "m_loading" ); // HACKHACK
}
oldstate = state;
2008-12-26 22:00:00 +01:00
switch( state )
{
case CL_LOADING:
2009-10-18 22:00:00 +02:00
DrawProgressBar();
2008-12-26 22:00:00 +01:00
break;
case CL_ACTIVE:
2009-01-25 22:00:00 +01:00
case CL_PAUSED:
2008-12-26 22:00:00 +01:00
gHUD.Redraw( flTime );
DrawPause();
break;
}
2008-12-25 22:00:00 +01:00
return 1;
}
2009-01-05 22:00:00 +01:00
int HUD_UpdateClientData( client_data_t *cdata, float flTime )
2008-12-25 22:00:00 +01:00
{
2009-01-05 22:00:00 +01:00
return gHUD.UpdateClientData( cdata, flTime );
2008-12-25 22:00:00 +01:00
}
2009-09-28 22:00:00 +02:00
void HUD_UpdateEntityVars( edict_t *ent, skyportal_t *sky, const entity_state_t *state, const entity_state_t *prev )
2009-08-22 22:00:00 +02:00
{
2009-09-28 22:00:00 +02:00
int i;
float m_fLerp;
2009-09-18 22:00:00 +02:00
if( state->ed_type == ED_CLIENT && state->ed_flags & ESF_NO_PREDICTION )
2009-09-28 22:00:00 +02:00
m_fLerp = 1.0f;
2009-09-18 22:00:00 +02:00
else m_fLerp = GetLerpFrac();
2009-08-22 22:00:00 +02:00
// copy state to progs
ent->v.modelindex = state->modelindex;
ent->v.weaponmodel = state->weaponmodel;
ent->v.frame = state->frame;
ent->v.sequence = state->sequence;
ent->v.gaitsequence = state->gaitsequence;
ent->v.body = state->body;
ent->v.skin = state->skin;
ent->v.effects = state->effects;
ent->v.velocity = state->velocity;
2009-11-25 22:00:00 +01:00
ent->v.basevelocity = state->basevelocity;
2009-08-22 22:00:00 +02:00
ent->v.oldorigin = ent->v.origin;
ent->v.mins = state->mins;
ent->v.maxs = state->maxs;
ent->v.framerate = state->framerate;
ent->v.colormap = state->colormap;
ent->v.rendermode = state->rendermode;
ent->v.renderfx = state->renderfx;
ent->v.fov = state->fov;
ent->v.scale = state->scale;
ent->v.weapons = state->weapons;
ent->v.gravity = state->gravity;
ent->v.health = state->health;
ent->v.solid = state->solid;
ent->v.movetype = state->movetype;
ent->v.flags = state->flags;
2009-09-13 22:00:00 +02:00
ent->v.ideal_pitch = state->idealpitch;
2009-09-17 22:00:00 +02:00
ent->v.oldangles = ent->v.angles; // just a delta between frames
2009-09-20 22:00:00 +02:00
ent->v.animtime = state->animtime;
2009-09-17 22:00:00 +02:00
2009-10-22 22:00:00 +02:00
// ent->v.animtime = bound( gpGlobals->time - gpGlobals->frametime, ent->v.animtime, gpGlobals->time );
2009-09-22 22:00:00 +02:00
if( state->groundent != -1 )
ent->v.groundentity = GetEntityByIndex( state->groundent );
else ent->v.groundentity = NULL;
if( state->aiment != -1 )
2009-09-17 22:00:00 +02:00
ent->v.aiment = GetEntityByIndex( state->aiment );
else ent->v.aiment = NULL;
2009-10-23 22:00:00 +02:00
switch( ent->v.movetype )
{
case MOVETYPE_NONE:
ent->v.origin = state->origin;
break;
default:
ent->v.origin = LerpPoint( prev->origin, state->origin, m_fLerp );
break;
}
2009-09-17 22:00:00 +02:00
// lerping some fields
for( i = 0; i < 3; i++ )
{
ent->v.angles[i] = LerpAngle( prev->angles[i], state->angles[i], m_fLerp );
ent->v.rendercolor[i] = LerpPoint( prev->rendercolor[i], state->rendercolor[i], m_fLerp );
}
// interpolate scale, renderamount etc
ent->v.renderamt = LerpPoint( prev->renderamt, state->renderamt, m_fLerp );
ent->v.scale = LerpPoint( prev->scale, state->scale, m_fLerp );
2009-09-22 22:00:00 +02:00
if(!( ent->v.effects & EF_ANIMATE )) // auto-animation uses v.frame for hold ending frame
2009-09-20 22:00:00 +02:00
{
float frame = state->frame;
float prevframe = prev->frame;
float lerpTime = (frame - prevframe);
if( ent->v.animtime )
{
2009-09-21 22:00:00 +02:00
if( ent->v.effects & EF_NOINTERP )
{
// adjust lerping values if animation restarted
if( lerpTime < 0 ) prevframe = 1.001;
ent->v.frame = LerpPoint( prevframe, frame, m_fLerp );
}
else ent->v.frame = state->frame; // use normal studio lerping
2009-09-20 22:00:00 +02:00
}
2009-09-21 22:00:00 +02:00
else ent->v.frame = Q_rint( state->frame ); // sprite frames will be interpolated in other place
2009-09-20 22:00:00 +02:00
}
2009-08-22 22:00:00 +02:00
switch( state->ed_type )
{
2009-09-17 22:00:00 +02:00
case ED_CLIENT:
2009-09-19 22:00:00 +02:00
for( i = 0; i < 3; i++ )
{
ent->v.punchangle[i] = LerpAngle( prev->punch_angles[i], state->punch_angles[i], m_fLerp);
ent->v.viewangles[i] = LerpAngle( prev->viewangles[i], state->viewangles[i], m_fLerp);
ent->v.view_ofs[i] = LerpAngle( prev->viewoffset[i], state->viewoffset[i], m_fLerp);
}
if( prev->fov < 90 && state->fov == 90 ) ent->v.fov = state->fov; // fov is reset, so don't lerping
else ent->v.fov = LerpPoint( prev->fov, state->fov, m_fLerp );
2009-09-18 22:00:00 +02:00
if( ent == GetLocalPlayer())
{
edict_t *viewent = GetViewModel();
// setup player viewmodel (only for local player!)
viewent->v.modelindex = state->viewmodel;
2009-09-19 22:00:00 +02:00
gHUD.m_flFOV = ent->v.fov; // keep client fov an actual
2009-09-18 22:00:00 +02:00
}
2009-09-17 22:00:00 +02:00
break;
2009-08-22 22:00:00 +02:00
case ED_PORTAL:
case ED_MOVER:
case ED_BSPBRUSH:
2009-11-16 22:00:00 +01:00
ent->v.movedir = BitsToDir( state->body );
2009-08-22 22:00:00 +02:00
ent->v.oldorigin = state->oldorigin;
break;
case ED_SKYPORTAL:
// setup sky portal
2009-09-17 22:00:00 +02:00
sky->vieworg = ent->v.origin;
sky->viewanglesOffset.x = sky->viewanglesOffset.z = 0.0f;
sky->viewanglesOffset.y = gHUD.m_flTime * ent->v.angles[1];
sky->fov = ent->v.fov;
sky->scale = (ent->v.scale ? 1.0f / ent->v.scale : 0); // critical stuff
2009-08-22 22:00:00 +02:00
break;
default:
ent->v.movedir = Vector( 0, 0, 0 );
break;
}
for( i = 0; i < MAXSTUDIOBLENDS; i++ )
2009-10-22 22:00:00 +02:00
{
ent->v.blending[i] = LerpByte( prev->blending[i], state->blending[i], m_fLerp );
}
2009-08-22 22:00:00 +02:00
for( i = 0; i < MAXSTUDIOCONTROLLERS; i++ )
2009-10-22 22:00:00 +02:00
{
if( abs( prev->controller[i] - state->controller[i] ) > 128 )
ent->v.controller[i] = state->controller[i];
else ent->v.controller[i] = LerpByte( prev->controller[i], state->controller[i], m_fLerp );
}
2009-08-22 22:00:00 +02:00
// g-cont. moved here because we may needs apply null scale to skyportal
if( ent->v.scale == 0.0f ) ent->v.scale = 1.0f;
ent->v.pContainingEntity = ent;
}
2008-12-25 22:00:00 +01:00
void HUD_Reset( void )
{
gHUD.VidInit();
}
void HUD_Frame( double time )
{
// place to call vgui_frame
}
void HUD_Shutdown( void )
{
2009-10-18 22:00:00 +02:00
// perform shutdown operations
g_engfuncs.pfnDelCommand ("noclip" );
g_engfuncs.pfnDelCommand ("notarget" );
g_engfuncs.pfnDelCommand ("fullupdate" );
g_engfuncs.pfnDelCommand ("give" );
g_engfuncs.pfnDelCommand ("drop" );
g_engfuncs.pfnDelCommand ("intermission" );
2009-10-23 22:00:00 +02:00
g_engfuncs.pfnDelCommand ("spectate" );
g_engfuncs.pfnDelCommand ("gametitle" );
2009-10-18 22:00:00 +02:00
g_engfuncs.pfnDelCommand ("god" );
g_engfuncs.pfnDelCommand ("fov" );
2009-10-29 22:00:00 +01:00
g_engfuncs.pfnDelCommand ("fly" );
2008-12-25 22:00:00 +01:00
}