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

477 lines
12 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"
2010-03-15 22:00:00 +01:00
#include "aurora.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 =
{
sizeof( HUD_FUNCTIONS ),
HUD_VidInit,
HUD_Init,
HUD_Redraw,
2009-08-22 22:00:00 +02:00
HUD_UpdateEntityVars,
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,
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" );
g_engfuncs.pfnAddCommand ("fly", NULL, "fly mode (flight)" );
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
{
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:
2010-02-26 22:00:00 +01:00
gHUD.Redraw( flTime );
break;
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;
}
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
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-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 );
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
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-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();
// 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:
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;
break;
2009-08-22 22:00:00 +02:00
default:
ent->v.movedir = Vector( 0, 0, 0 );
break;
}
2010-03-06 22:00:00 +01:00
// add env_beam to drawing list
if( state->ed_type == ED_BEAM )
g_pViewRenderBeams->AddServerBeam( ent );
2009-08-22 22:00:00 +02:00
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;
}
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;
}
// 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-03-15 22:00:00 +01:00
g_pTempEnts->AllocDLight( pEnt->v.origin, 100, 100, 100, 200, 0.001f, 0 );
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
{
g_pTempEnts->AllocDLight( pEnt->v.origin, RANDOM_LONG( 200, 230 ), 0.001f, 0 );
}
}
if ( pEnt->v.effects & EF_BRIGHTLIGHT )
{
Vector pos( pEnt->v.origin.x, pEnt->v.origin.y, pEnt->v.origin.z + 16 );
g_pTempEnts->AllocDLight( pos, RANDOM_LONG( 400, 430 ), 0.001f, 0 );
}
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( );
}
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
2010-02-10 22:00:00 +01:00
gHUD.m_Sound.Update();
2008-12-25 22:00:00 +01:00
}
void HUD_Shutdown( void )
{
2010-02-07 22:00:00 +01:00
gHUD.m_Sound.Close();
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-10-29 22:00:00 +01:00
g_engfuncs.pfnDelCommand ("fly" );
2009-12-05 22:00:00 +01:00
}