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

522 lines
14 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"
2010-07-08 22:00:00 +02:00
#include "studio.h"
2008-12-25 22:00:00 +01:00
#include "hud.h"
2010-03-15 22:00:00 +01:00
#include "aurora.h"
2010-07-13 22:00:00 +02:00
#include "effects_api.h"
2009-10-20 22:00:00 +02:00
#include "r_particle.h"
2010-03-14 22:00:00 +01:00
#include "r_tempents.h"
2010-03-06 22:00:00 +01:00
#include "r_beams.h"
2009-12-02 22:00:00 +01:00
#include "ev_hldm.h"
2009-12-05 22:00:00 +01:00
#include "pm_shared.h"
2009-12-08 22:00:00 +01:00
#include "r_weather.h"
2008-12-25 22:00:00 +01:00
2010-02-23 22:00:00 +01:00
cl_enginefuncs_t g_engfuncs;
cl_globalvars_t *gpGlobals;
movevars_t *gpMovevars = NULL;
2010-03-06 22:00:00 +01:00
ref_params_t *gpViewParams = NULL;
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 =
{
HUD_VidInit,
HUD_Init,
HUD_Redraw,
2009-08-22 22:00:00 +02:00
HUD_UpdateEntityVars,
2010-06-28 22:00:00 +02:00
HUD_UpdateClientVars,
2010-03-10 22:00:00 +01:00
HUD_UpdateOnRemove,
2008-12-25 22:00:00 +01:00
HUD_Reset,
2010-03-09 22:00:00 +01:00
HUD_StartFrame,
2008-12-25 22:00:00 +01:00
HUD_Frame,
HUD_Shutdown,
2009-12-07 22:00:00 +01:00
HUD_RenderCallback,
2008-12-25 22:00:00 +01:00
HUD_CreateEntities,
2010-03-14 22:00:00 +01:00
HUD_AddVisibleEntity,
2008-12-25 22:00:00 +01:00
HUD_StudioEvent,
2009-09-17 22:00:00 +02:00
HUD_StudioFxTransform,
2008-12-25 22:00:00 +01:00
V_CalcRefdef,
2009-12-05 22:00:00 +01:00
PM_Move, // pfnPM_Move
PM_Init, // pfnPM_Init
PM_FindTextureType, // pfnPM_FindTextureType
HUD_CmdStart,
HUD_CmdEnd,
IN_CreateMove,
IN_MouseEvent,
IN_KeyEvent,
VGui_ConsolePrint,
2010-07-13 22:00:00 +02:00
HUD_ParticleEffect
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 ));
2010-03-07 22:00:00 +01:00
2009-09-28 22:00:00 +02:00
gpGlobals = pGlobals;
2010-03-07 22:00:00 +01:00
gpViewParams = gpGlobals->pViewParms;
gpMovevars = gpViewParams->movevars;
2008-12-25 22:00:00 +01:00
return TRUE;
}
int HUD_VidInit( void )
{
2010-03-15 22:00:00 +01:00
if ( g_pParticleSystems )
2009-10-20 22:00:00 +02:00
g_pParticleSystems->ClearSystems();
2009-12-08 22:00:00 +01:00
2010-03-15 22:00:00 +01:00
if ( g_pViewRenderBeams )
2010-03-06 22:00:00 +01:00
g_pViewRenderBeams->ClearBeams();
2010-03-15 22:00:00 +01:00
if ( g_pParticles )
g_pParticles->Clear();
2010-03-14 22:00:00 +01:00
if ( g_pTempEnts )
g_pTempEnts->Clear();
2009-12-08 22:00:00 +01:00
ResetRain ();
2009-10-20 22:00:00 +02:00
2008-12-25 22:00:00 +01:00
gHUD.VidInit();
return 1;
}
2010-03-14 22:00:00 +01:00
void HUD_ShutdownEffects( void )
2008-12-25 22:00:00 +01:00
{
2009-10-20 22:00:00 +02:00
if ( g_pParticleSystems )
{
// init partsystem
delete g_pParticleSystems;
g_pParticleSystems = NULL;
}
2009-12-08 22:00:00 +01:00
2010-03-06 22:00:00 +01:00
if ( g_pViewRenderBeams )
{
// init render beams
delete g_pViewRenderBeams;
g_pViewRenderBeams = NULL;
}
2010-03-15 22:00:00 +01:00
if ( g_pParticles )
{
// init particles
delete g_pParticles;
g_pParticles = NULL;
}
2010-03-14 22:00:00 +01:00
if ( g_pTempEnts )
{
// init client tempents
delete g_pTempEnts;
g_pTempEnts = NULL;
}
}
void HUD_Init( void )
{
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" );
g_engfuncs.pfnAddCommand ("spectate", NULL, "enable spectator mode" );
g_engfuncs.pfnAddCommand ("gametitle", NULL, "show game logo" );
g_engfuncs.pfnAddCommand ("god", NULL, "classic cheat" );
g_engfuncs.pfnAddCommand ("fov", NULL, "set client field of view" );
HUD_ShutdownEffects ();
2009-10-20 22:00:00 +02:00
g_pParticleSystems = new ParticleSystemManager();
2010-03-06 22:00:00 +01:00
g_pViewRenderBeams = new CViewRenderBeams();
2010-03-15 22:00:00 +01:00
g_pParticles = new CParticleSystem();
2010-03-14 22:00:00 +01:00
g_pTempEnts = new CTempEnts();
2010-03-06 22:00:00 +01:00
2009-12-08 22:00:00 +01:00
InitRain(); // init weather system
2009-10-20 22:00:00 +02:00
2008-12-25 22:00:00 +01:00
gHUD.Init();
2009-01-22 22:00:00 +01:00
2009-12-05 22:00:00 +01:00
IN_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
{
2008-12-26 22:00:00 +01:00
switch( state )
{
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 );
2010-07-08 22:00:00 +02:00
break;
case CL_LOADING:
// called while map is loading
2008-12-26 22:00:00 +01:00
break;
2010-04-12 22:00:00 +02:00
case CL_CHANGELEVEL:
2010-07-08 22:00:00 +02:00
// called once when changelevel in-action
2010-04-12 22:00:00 +02:00
break;
2008-12-26 22:00:00 +01:00
}
2008-12-25 22:00:00 +01:00
return 1;
}
2010-03-14 22:00:00 +01:00
void HUD_UpdateEntityVars( edict_t *ent, 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
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
2010-03-18 22:00:00 +01:00
if( state->flags & FL_PROJECTILE && state->ed_flags & ( ESF_NO_PREDICTION|ESF_NODELTA ))
{
// cut rocket trail, dont pass it from teleport
// FIXME: don't work
g_pViewRenderBeams->KillDeadBeams( ent );
}
2009-08-22 22:00:00 +02:00
// copy state to progs
ent->v.modelindex = state->modelindex;
ent->v.weaponmodel = state->weaponmodel;
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;
2010-04-04 22:00:00 +02:00
ent->v.oldorigin = ent->v.origin; // previous origin holds
2009-08-22 22:00:00 +02:00
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;
2010-06-23 22:00:00 +02:00
ent->v.idealpitch = state->idealpitch;
2009-09-20 22:00:00 +02:00
ent->v.animtime = state->animtime;
2010-04-24 22:00:00 +02:00
ent->v.ltime = state->localtime;
2009-09-17 22:00:00 +02:00
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;
2010-07-26 22:00:00 +02:00
if( ent->v.flags & FL_MONSTER )
{
switch( ent->v.movetype )
{
case MOVETYPE_NONE:
case MOVETYPE_STEP:
case MOVETYPE_FLY:
// monster's steps will be interpolated on render-side
ent->v.origin = state->origin;
ent->v.angles = state->angles;
ent->v.oldorigin = prev->origin; // used for lerp 'monster view'
ent->v.oldangles = prev->angles; // used for lerp 'monster view'
break;
default:
ent->v.angles = LerpAngle( prev->angles, state->angles, m_fLerp );
ent->v.origin = LerpPoint( prev->origin, state->origin, m_fLerp );
ent->v.basevelocity = LerpPoint( prev->basevelocity, state->basevelocity, m_fLerp );
break;
}
}
else
2009-10-23 22:00:00 +02:00
{
2010-04-04 22:00:00 +02:00
ent->v.angles = LerpAngle( prev->angles, state->angles, m_fLerp );
2009-10-23 22:00:00 +02:00
ent->v.origin = LerpPoint( prev->origin, state->origin, m_fLerp );
2009-12-05 22:00:00 +01:00
ent->v.basevelocity = LerpPoint( prev->basevelocity, state->basevelocity, m_fLerp );
2009-10-23 22:00:00 +02:00
}
2009-09-17 22:00:00 +02:00
// interpolate scale, renderamount etc
ent->v.scale = LerpPoint( prev->scale, state->scale, m_fLerp );
2010-04-04 22:00:00 +02:00
ent->v.rendercolor = LerpPoint( prev->rendercolor, state->rendercolor, m_fLerp );
ent->v.renderamt = LerpPoint( prev->renderamt, state->renderamt, m_fLerp );
2009-09-17 22:00:00 +02:00
2010-04-05 22:00:00 +02:00
if( ent->v.animtime )
2009-09-20 22:00:00 +02:00
{
2010-04-05 22:00:00 +02:00
// use normal studio lerping
ent->v.frame = state->frame;
}
else
{
// round sprite and brushmodel frames
ent->v.frame = Q_rint( state->frame );
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:
2010-04-05 22:00:00 +02:00
ent->v.punchangle = LerpAngle( prev->punch_angles, state->punch_angles, m_fLerp );
2010-06-23 22:00:00 +02:00
ent->v.v_angle = LerpAngle( prev->viewangles, state->viewangles, m_fLerp );
2010-04-05 22:00:00 +02:00
ent->v.view_ofs = LerpPoint( prev->viewoffset, state->viewoffset, m_fLerp );
2009-09-19 22:00:00 +02:00
2010-04-05 22:00:00 +02:00
if( prev->fov != 90.0f && state->fov == 90.0f )
ent->v.fov = state->fov; // fov is reset, so don't lerping
2009-09-19 22:00:00 +02:00
else ent->v.fov = LerpPoint( prev->fov, state->fov, m_fLerp );
2009-12-05 22:00:00 +01:00
ent->v.maxspeed = state->maxspeed;
ent->v.iStepLeft = state->iStepLeft;
ent->v.flFallVelocity = state->flFallVelocity;
2009-09-18 22:00:00 +02:00
if( ent == GetLocalPlayer())
{
edict_t *viewent = GetViewModel();
2010-04-12 22:00:00 +02:00
// if viewmodel has changed update sequence here
if( viewent->v.modelindex != state->viewmodel )
{
// ALERT( at_console, "Viewmodel changed\n" );
SendWeaponAnim( viewent->v.sequence, viewent->v.body, viewent->v.framerate );
}
2009-09-18 22:00:00 +02:00
// setup player viewmodel (only for local player!)
viewent->v.modelindex = state->viewmodel;
2010-04-12 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:
2010-03-14 22:00:00 +01:00
{
skyportal_t *sky = &gpViewParams->skyportal;
// setup sky portal
sky->vieworg = ent->v.origin;
sky->viewanglesOffset.x = sky->viewanglesOffset.z = 0.0f;
sky->viewanglesOffset.y = gHUD.m_flTime * ent->v.angles[1];
sky->scale = (ent->v.scale ? 1.0f / ent->v.scale : 0.0f ); // critical stuff
sky->fov = ent->v.fov;
}
2009-08-22 22:00:00 +02:00
break;
2010-03-06 22:00:00 +01:00
case ED_BEAM:
ent->v.oldorigin = state->oldorigin; // beam endpoint
ent->v.frags = state->gaitsequence;
if( state->owner != -1 )
ent->v.owner = GetEntityByIndex( state->owner );
else ent->v.owner = NULL;
2010-04-04 22:00:00 +02:00
// add server beam now
g_pViewRenderBeams->AddServerBeam( ent );
2010-03-06 22:00:00 +01:00
break;
2009-08-22 22:00:00 +02:00
default:
ent->v.movedir = Vector( 0, 0, 0 );
break;
}
2010-04-05 22:00:00 +02:00
int i;
// copy blendings
2009-08-22 22:00:00 +02:00
for( i = 0; i < MAXSTUDIOBLENDS; i++ )
2010-04-05 22:00:00 +02:00
ent->v.blending[i] = state->blending[i];
2010-04-04 22:00:00 +02:00
2010-04-05 22:00:00 +02:00
// copy controllers
2009-08-22 22:00:00 +02:00
for( i = 0; i < MAXSTUDIOCONTROLLERS; i++ )
2010-04-05 22:00:00 +02:00
ent->v.controller[i] = state->controller[i];
2010-04-04 22:00:00 +02:00
2009-08-22 22:00:00 +02:00
// g-cont. moved here because we may needs apply null scale to skyportal
2010-05-04 22:00:00 +02:00
if( ent->v.scale == 0.0f && ent->v.skin >= 0 ) ent->v.scale = 1.0f;
2010-07-13 22:00:00 +02:00
switch( state->ed_type )
{
case ED_MOVER:
case ED_NORMAL:
case ED_BSPBRUSH:
if( ent->v.scale >= 100.0f )
ent->v.scale = 1.0f; // original HL issues
break;
}
2009-08-22 22:00:00 +02:00
ent->v.pContainingEntity = ent;
}
2010-06-28 22:00:00 +02:00
/*
=========================
HUD_UpdateClientVars
The server sends us our origin with extra precision as part of the clientdata structure, not during the normal
playerstate update in entity_state_t. In order for these overrides to eventually get to the appropriate playerstate
structure, we need to copy them into the state structure at this point.
=========================
*/
void HUD_UpdateClientVars( entity_state_t *state, const clientdata_t *client )
{
// Copy origin
state->origin = client->origin;
// Spectator
state->iuser1 = client->iuser1;
state->iuser2 = client->iuser2;
// Duck prevention
state->iuser3 = client->iuser3;
// Fire prevention
state->iuser4 = client->iuser4;
}
2010-03-14 22:00:00 +01:00
int HUD_AddVisibleEntity( edict_t *pEnt, int ed_type )
{
float oldScale, oldRenderAmt;
float shellScale = 1.0f;
int result;
2010-03-15 22:00:00 +01:00
if ( pEnt->v.renderfx == kRenderFxGlowShell )
2010-03-14 22:00:00 +01:00
{
oldRenderAmt = pEnt->v.renderamt;
oldScale = pEnt->v.scale;
pEnt->v.renderamt = 255; // clear amount
}
result = CL_AddEntity( pEnt, ed_type, -1 );
2010-03-15 22:00:00 +01:00
if ( pEnt->v.renderfx == kRenderFxGlowShell )
2010-03-14 22:00:00 +01:00
{
shellScale = (oldRenderAmt * 0.0015f); // shellOffset
pEnt->v.scale = oldScale + shellScale; // sets new scale
pEnt->v.renderamt = 128;
// render glowshell
result |= CL_AddEntity( pEnt, ed_type, g_pTempEnts->hSprGlowShell );
// restore parms
pEnt->v.scale = oldScale;
pEnt->v.renderamt = oldRenderAmt;
}
2010-03-16 22:00:00 +01:00
if ( pEnt->v.effects & EF_BRIGHTFIELD )
{
2010-07-13 22:00:00 +02:00
g_pParticles->EntityParticles( pEnt );
2010-03-16 22:00:00 +01:00
}
2010-03-14 22:00:00 +01:00
// add in muzzleflash effect
2010-03-15 22:00:00 +01:00
if ( pEnt->v.effects & EF_MUZZLEFLASH )
2010-03-14 22:00:00 +01:00
{
2010-03-15 22:00:00 +01:00
if( ed_type == ED_VIEWMODEL )
pEnt->v.effects &= ~EF_MUZZLEFLASH;
2010-03-14 22:00:00 +01:00
g_pTempEnts->WeaponFlash( pEnt, 1 );
}
// add light effect
2010-03-15 22:00:00 +01:00
if ( pEnt->v.effects & EF_LIGHT )
2010-03-14 22:00:00 +01:00
{
2010-06-28 22:00:00 +02:00
g_pTempEnts->AllocDLight( pEnt->v.origin, 100, 100, 100, 200, 0.001f );
2010-03-14 22:00:00 +01:00
g_pTempEnts->RocketFlare( pEnt->v.origin );
}
2010-03-15 22:00:00 +01:00
// add dimlight
if ( pEnt->v.effects & EF_DIMLIGHT )
{
if ( ed_type == ED_CLIENT )
{
EV_UpadteFlashlight( pEnt );
}
else
{
2010-06-28 22:00:00 +02:00
g_pTempEnts->AllocDLight( pEnt->v.origin, RANDOM_LONG( 200, 230 ), 0.001f );
2010-03-15 22:00:00 +01:00
}
}
2010-06-17 22:00:00 +02:00
// NOTE: Xash3D sent entities to client even if it has EF_NODRAW flags
// run simple check here to prevent lighting invisible entity
if ( pEnt->v.effects & EF_BRIGHTLIGHT && !( pEnt->v.effects & EF_NODRAW ))
2010-03-15 22:00:00 +01:00
{
Vector pos( pEnt->v.origin.x, pEnt->v.origin.y, pEnt->v.origin.z + 16 );
2010-06-28 22:00:00 +02:00
g_pTempEnts->AllocDLight( pos, RANDOM_LONG( 400, 430 ), 0.001f );
2010-03-15 22:00:00 +01:00
}
2010-03-14 22:00:00 +01:00
return result;
}
void HUD_CreateEntities( void )
{
EV_UpdateBeams (); // egon use this
EV_UpdateLaserSpot (); // predictable laserspot
// add in any game specific objects here
g_pViewRenderBeams->UpdateTempEntBeams( );
g_pTempEnts->Update();
}
2010-03-10 22:00:00 +01:00
void HUD_UpdateOnRemove( edict_t *pEdict )
{
// move TE_BEAMTRAIL, kill other beams
g_pViewRenderBeams->KillDeadBeams( pEdict );
}
2008-12-25 22:00:00 +01:00
void HUD_Reset( void )
{
2010-03-14 22:00:00 +01:00
HUD_VidInit ();
2008-12-25 22:00:00 +01:00
}
2010-03-09 22:00:00 +01:00
void HUD_StartFrame( void )
{
// clear list of server beams after each frame
g_pViewRenderBeams->ClearServerBeams( );
}
2010-07-13 22:00:00 +02:00
void HUD_ParticleEffect( const float *org, const float *dir, int color, int count )
{
g_pParticles->ParticleEffect( org, dir, color, count );
}
2008-12-25 22:00:00 +01:00
void HUD_Frame( double time )
{
// place to call vgui_frame
2009-12-05 22:00:00 +01:00
// VGUI not implemented, wait for version 0.75
2008-12-25 22:00:00 +01:00
}
void HUD_Shutdown( void )
{
2010-03-14 22:00:00 +01:00
HUD_ShutdownEffects ();
2009-12-05 22:00:00 +01:00
IN_Shutdown ();
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-12-05 22:00:00 +01:00
}