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_game.c

2501 lines
53 KiB
C
Raw Normal View History

2008-12-25 22:00:00 +01:00
//=======================================================================
// Copyright XashXT Group 2008 <20>
// cl_game.c - client dlls interaction
//=======================================================================
#include "common.h"
#include "client.h"
#include "byteorder.h"
#include "matrix_lib.h"
#include "const.h"
2009-11-23 22:00:00 +01:00
#include "com_library.h"
2009-01-11 22:00:00 +01:00
#include "triangle_api.h"
#include "effects_api.h"
2009-11-26 22:00:00 +01:00
#include "pm_defs.h"
2008-12-25 22:00:00 +01:00
/*
====================
CL_GetClientEntity
Render callback for studio models
====================
*/
2009-01-03 22:00:00 +01:00
edict_t *CL_GetEdictByIndex( int index )
2008-12-25 22:00:00 +01:00
{
2009-10-18 22:00:00 +02:00
if( index == MAX_EDICTS - 1 )
return &clgame.playermodel;
2009-09-28 22:00:00 +02:00
if( index < 0 || index > clgame.globals->numEntities )
2009-01-03 22:00:00 +01:00
{
2009-10-18 22:00:00 +02:00
if( index == VIEWENT_INDEX ) return &clgame.viewent;
2009-10-15 22:00:00 +02:00
if( index == NULLENT_INDEX ) return NULL;
2009-01-03 22:00:00 +01:00
MsgDev( D_ERROR, "CL_GetEntityByIndex: invalid entindex %i\n", index );
return NULL;
}
2009-10-10 22:00:00 +02:00
if( EDICT_NUM( index )->free )
return NULL;
2009-01-03 22:00:00 +01:00
return EDICT_NUM( index );
2008-12-25 22:00:00 +01:00
}
2009-12-05 22:00:00 +01:00
/*
=============
CL_AllocString
=============
*/
string_t CL_AllocString( const char *szValue )
{
return StringTable_SetString( clgame.hStringTable, szValue );
}
/*
=============
CL_GetString
=============
*/
const char *CL_GetString( string_t iString )
{
return StringTable_GetString( clgame.hStringTable, iString );
}
2009-10-02 22:00:00 +02:00
/*
====================
CL_GetServerTime
don't clamped time that come from server
====================
*/
int CL_GetServerTime( void )
{
return cl.frame.servertime;
}
2009-09-17 22:00:00 +02:00
/*
====================
StudioEvent
Event callback for studio models
====================
*/
void CL_StudioEvent( dstudioevent_t *event, edict_t *pEdict )
{
clgame.dllFuncs.pfnStudioEvent( event, pEdict );
}
2009-09-03 22:00:00 +02:00
/*
====================
Studio_FxTransform
2009-09-17 22:00:00 +02:00
apply fxtransforms for each studio bone
2009-09-03 22:00:00 +02:00
====================
*/
void CL_StudioFxTransform( edict_t *ent, float transform[4][4] )
{
2009-09-17 22:00:00 +02:00
clgame.dllFuncs.pfnStudioFxTransform( ent, transform );
2009-09-03 22:00:00 +02:00
}
2009-10-15 22:00:00 +02:00
bool CL_GetAttachment( int entityIndex, int number, vec3_t origin, vec3_t angles )
{
edict_t *ed = CL_GetEdictByIndex( entityIndex );
if( !ed || ed->free || !ed->pvClientData )
return false;
number = bound( 1, number, MAXSTUDIOATTACHMENTS );
2009-10-20 22:00:00 +02:00
if( origin ) VectorAdd( ed->v.origin, ed->pvClientData->origin[number-1], origin );
2009-10-15 22:00:00 +02:00
if( angles ) VectorCopy( ed->pvClientData->angles[number-1], angles );
return true;
}
bool CL_SetAttachment( int entityIndex, int number, vec3_t origin, vec3_t angles )
{
edict_t *ed = CL_GetEdictByIndex( entityIndex );
if( !ed || ed->free || !ed->pvClientData )
return false;
if( number > MAXSTUDIOATTACHMENTS )
number = MAXSTUDIOATTACHMENTS;
if( origin ) VectorCopy( origin, ed->pvClientData->origin[number-1] );
if( angles ) VectorCopy( angles, ed->pvClientData->angles[number-1] );
return true;
}
2009-10-22 22:00:00 +02:00
byte CL_GetMouthOpen( int entityIndex )
2009-10-15 22:00:00 +02:00
{
edict_t *ed;
if( entityIndex <= 0 || entityIndex >= clgame.globals->numEntities )
2009-10-22 22:00:00 +02:00
return 0;
2009-10-15 22:00:00 +02:00
ed = CL_GetEdictByIndex( entityIndex );
if( !ed || ed->free || !ed->pvClientData )
2009-10-22 22:00:00 +02:00
return 0;
return ed->pvClientData->mouth.open;
2009-10-15 22:00:00 +02:00
}
2009-12-06 22:00:00 +01:00
studioframe_t *CL_GetStudioFrame( int entityIndex )
2009-10-18 22:00:00 +02:00
{
edict_t *pEnt = CL_GetEdictByIndex( entityIndex );
if( !pEnt || !pEnt->pvClientData )
return NULL;
2009-12-06 22:00:00 +01:00
return &pEnt->pvClientData->frame;
2009-10-18 22:00:00 +02:00
}
2009-12-05 22:00:00 +01:00
/*
=============
CL_GetLerpFrac
=============
*/
float CL_GetLerpFrac( void )
{
return cl.lerpFrac;
}
2009-12-04 22:00:00 +01:00
/*
================
CL_FadeAlpha
================
*/
void CL_FadeAlpha( int starttime, int endtime, rgba_t color )
{
int time, fade_time;
if( starttime == 0 )
{
MakeRGBA( color, 255, 255, 255, 255 );
return;
}
time = cls.realtime - starttime;
if( time >= endtime )
{
MakeRGBA( color, 255, 255, 255, 0 );
return;
}
// fade time is 1/4 of endtime
fade_time = endtime / 4;
fade_time = bound( 300, fade_time, 10000 );
color[0] = color[1] = color[2] = 255;
// fade out
if(( endtime - time ) < fade_time )
color[3] = bound( 0, ((endtime - time) * 1.0f / fade_time) * 255, 255 );
else color[3] = 255;
}
/*
=============
CL_DrawCenterPrint
called each frame
=============
*/
void CL_DrawCenterPrint( void )
{
char *start;
int l, x, y, w;
rgba_t color;
if( !re || !clgame.ds.centerPrintTime ) return;
CL_FadeAlpha( clgame.ds.centerPrintTime, scr_centertime->value * 1000, color );
if( *(int *)color == 0x00FFFFFF )
{
// faded out
clgame.ds.centerPrintTime = 0;
return;
}
re->SetColor( color );
start = clgame.ds.centerPrint;
y = clgame.ds.centerPrintY - clgame.ds.centerPrintLines * BIGCHAR_HEIGHT / 2;
while( 1 )
{
char linebuffer[1024];
for( l = 0; l < 50; l++ )
{
if( !start[l] || start[l] == '\n' )
break;
linebuffer[l] = start[l];
}
linebuffer[l] = 0;
w = clgame.ds.centerPrintCharWidth * com.cstrlen( linebuffer );
x = (SCREEN_WIDTH - w)>>1;
SCR_DrawStringExt( x, y, clgame.ds.centerPrintCharWidth, SMALLCHAR_HEIGHT, linebuffer, color, false );
y += clgame.ds.centerPrintCharWidth * 1.5;
while( *start && ( *start != '\n' )) start++;
if( !*start ) break;
start++;
}
re->SetColor( NULL );
}
/*
=============
CL_CenterPrint
print centerscreen message
=============
*/
void CL_CenterPrint( const char *text, int y, int charWidth )
{
char *s;
com.strncpy( clgame.ds.centerPrint, text, sizeof( clgame.ds.centerPrint ));
clgame.ds.centerPrintTime = cls.realtime;
clgame.ds.centerPrintCharWidth = charWidth;
clgame.ds.centerPrintY = y;
// count the number of lines for centering
clgame.ds.centerPrintLines = 1;
s = clgame.ds.centerPrint;
while( *s )
{
if( *s == '\n' )
clgame.ds.centerPrintLines++;
s++;
}
}
2009-12-03 22:00:00 +01:00
/*
====================
SPR_AdjustSize
draw hudsprite routine
====================
*/
static void SPR_AdjustSize( float *x, float *y, float *w, float *h )
{
float xscale, yscale;
if( !x && !y && !w && !h ) return;
// scale for screen sizes
xscale = clgame.scrInfo.iRealWidth / (float)clgame.scrInfo.iWidth;
yscale = clgame.scrInfo.iRealHeight / (float)clgame.scrInfo.iHeight;
if( x ) *x *= xscale;
if( y ) *y *= yscale;
if( w ) *w *= xscale;
if( h ) *h *= yscale;
}
static bool SPR_Scissor( float *x, float *y, float *width, float *height, float *u0, float *v0, float *u1, float *v1 )
{
float dudx, dvdy;
// clip sub rect to sprite
if(( width == 0 ) || ( height == 0 ))
return false;
if( *x + *width <= clgame.ds.scissor_x )
return false;
if( *x >= clgame.ds.scissor_x + clgame.ds.scissor_width )
return false;
if( *y + *height <= clgame.ds.scissor_y )
return false;
if( *y >= clgame.ds.scissor_y + clgame.ds.scissor_height )
return false;
dudx = (*u1 - *u0) / *width;
dvdy = (*v1 - *v0) / *height;
if( *x < clgame.ds.scissor_x )
{
*u0 += (clgame.ds.scissor_x - *x) * dudx;
*width -= clgame.ds.scissor_x - *x;
*x = clgame.ds.scissor_x;
}
if( *x + *width > clgame.ds.scissor_x + clgame.ds.scissor_width )
{
*u1 -= (*x + *width - (clgame.ds.scissor_x + clgame.ds.scissor_width)) * dudx;
*width = clgame.ds.scissor_x + clgame.ds.scissor_width - *x;
}
if( *y < clgame.ds.scissor_y )
{
*v0 += (clgame.ds.scissor_y - *y) * dvdy;
*height -= clgame.ds.scissor_y - *y;
*y = clgame.ds.scissor_y;
}
if( *y + *height > clgame.ds.scissor_y + clgame.ds.scissor_height )
{
*v1 -= (*y + *height - (clgame.ds.scissor_y + clgame.ds.scissor_height)) * dvdy;
*height = clgame.ds.scissor_y + clgame.ds.scissor_height - *y;
}
return true;
}
/*
====================
SPR_DrawGeneric
draw hudsprite routine
====================
*/
static void SPR_DrawGeneric( int frame, float x, float y, float width, float height, const wrect_t *prc )
{
float s1, s2, t1, t2;
if( !re ) return;
if( width == -1 && height == -1 )
{
int w, h;
// undoc feature: get drawsizes from image
re->GetParms( &w, &h, NULL, frame, clgame.ds.hSprite );
width = w;
height = h;
}
if( prc )
{
// calc user-defined rectangle
s1 = (float)prc->left / width;
t1 = (float)prc->top / height;
s2 = (float)prc->right / width;
t2 = (float)prc->bottom / height;
width = prc->right - prc->left;
height = prc->bottom - prc->top;
}
else
{
s1 = t1 = 0.0f;
s2 = t2 = 1.0f;
}
// pass scissor test if supposed
if( clgame.ds.scissor_test && !SPR_Scissor( &x, &y, &width, &height, &s1, &t1, &s2, &t2 ))
return;
// scale for screen sizes
SPR_AdjustSize( &x, &y, &width, &height );
re->DrawStretchPic( x, y, width, height, s1, t1, s2, t2, clgame.ds.hSprite );
re->SetColor( NULL );
}
2009-10-23 22:00:00 +02:00
/*
====================
CL_InitTitles
parse all messages that declared in titles.txt
and hold them into permament memory pool
====================
*/
static void CL_InitTitles( const char *filename )
{
token_t token;
client_textmessage_t state;
char *pName = NULL;
char *pMessage = NULL;
script_t *script;
Mem_Set( &state, 0, sizeof( state ));
Mem_Set( &clgame.titles, 0, sizeof( clgame.titles ));
clgame.numTitles = 0;
script = Com_OpenScript( filename, NULL, 0 );
if( !script ) return;
while( script )
{
if( !Com_ReadToken( script, SC_ALLOW_NEWLINES, &token ))
break;
if( !com.stricmp( token.string, "$" )) // skip dollar
Com_ReadToken( script, false, &token );
if( !com.stricmp( token.string, "position" ))
{
Com_ReadFloat( script, false, &state.x );
Com_ReadFloat( script, false, &state.y );
}
else if( !com.stricmp( token.string, "effect" ))
{
Com_ReadUlong( script, false, &state.effect );
}
else if( !com.stricmp( token.string, "fadein" ))
{
Com_ReadFloat( script, false, &state.fadein );
}
else if( !com.stricmp( token.string, "fadeout" ))
{
Com_ReadFloat( script, false, &state.fadeout );
}
else if( !com.stricmp( token.string, "fxtime" ))
{
Com_ReadFloat( script, false, &state.fxtime );
}
else if( !com.stricmp( token.string, "holdtime" ))
{
Com_ReadFloat( script, false, &state.holdtime );
}
else if( !com.strnicmp( token.string, "color2", 6 ))
{
uint temp;
Com_ReadUlong( script, false, &temp );
state.r2 = temp;
Com_ReadUlong( script, false, &temp );
state.g2 = temp;
Com_ReadUlong( script, false, &temp );
state.b2 = temp;
if( Com_ReadUlong( script, false, &temp ))
state.a2 = temp; // optional, nevers used in Half-Life
else state.a2 = 255;
}
else if( !com.stricmp( token.string, "color" ))
{
uint temp;
Com_ReadUlong( script, false, &temp );
state.r1 = temp;
Com_ReadUlong( script, false, &temp );
state.g1 = temp;
Com_ReadUlong( script, false, &temp );
state.b1 = temp;
if( Com_ReadUlong( script, false, &temp ))
state.a1 = temp; // optional, nevers used in Half-Life
else state.a1 = 255;
}
else if( !com.stricmp( token.string, "{" ))
{
client_textmessage_t *newmsg;
const char *buffer, *end;
size_t size;
Com_SaveToken( script, &token );
// parse the message
buffer = script->text;
Com_SkipBracedSection( script, 0 );
end = script->text - 1; // skip '}'
if( !buffer ) buffer = script->buffer; // missing body ?
if( !end ) end = script->buffer + script->size; // EOF ?
size = end - buffer;
pMessage = Mem_Alloc( cls.mempool, size + 1 );
Mem_Copy( pMessage, buffer, size );
pMessage[size] = 0; // terminator
// create new client textmessage
newmsg = &clgame.titles[clgame.numTitles];
Mem_Copy( newmsg, &state, sizeof( *newmsg ));
newmsg->pName = pName;
newmsg->pMessage = pMessage;
clgame.numTitles++; // registered
}
else
{
// begin message declaration
pName = com.stralloc( cls.mempool, token.string, __FILE__, __LINE__ );
}
}
Com_CloseScript( script );
}
2008-12-25 22:00:00 +01:00
/*
====================
CL_GetLocalPlayer
Render callback for studio models
====================
*/
2009-01-03 22:00:00 +01:00
edict_t *CL_GetLocalPlayer( void )
2008-12-25 22:00:00 +01:00
{
2009-10-13 22:00:00 +02:00
if( cls.state == ca_active )
2009-11-26 22:00:00 +01:00
{
edict_t *player = EDICT_NUM( cl.playernum + 1 );
if( CL_IsValidEdict( player )) return player;
Host_Error( "CL_GetLocalPlayer: invalid edict\n" );
}
2009-10-13 22:00:00 +02:00
return NULL;
2008-12-25 22:00:00 +01:00
}
/*
====================
CL_GetMaxlients
Render callback for studio models
====================
*/
int CL_GetMaxClients( void )
{
2009-11-27 22:00:00 +01:00
return clgame.globals->maxClients;
2008-12-25 22:00:00 +01:00
}
2009-12-03 22:00:00 +01:00
void CL_DrawCrosshair( void )
{
2009-12-04 22:00:00 +01:00
int x, y, width, height;
edict_t *pPlayer;
2009-12-03 22:00:00 +01:00
if( !re || clgame.ds.hCrosshair <= 0 || cl.refdef.crosshairangle[2] || !cl_crosshair->integer )
return;
2009-12-04 22:00:00 +01:00
pPlayer = CL_GetLocalPlayer();
2009-12-03 22:00:00 +01:00
2009-12-04 22:00:00 +01:00
if( pPlayer->v.health <= 0.0f || pPlayer->v.flags & FL_FROZEN )
return;
2009-12-03 22:00:00 +01:00
2009-12-04 22:00:00 +01:00
// camera on
if( pPlayer->serialnumber != cl.refdef.viewentity )
return;
2009-12-03 22:00:00 +01:00
2009-12-04 22:00:00 +01:00
// get crosshair dimension
width = clgame.ds.rcCrosshair.right - clgame.ds.rcCrosshair.left;
height = clgame.ds.rcCrosshair.bottom - clgame.ds.rcCrosshair.top;
2009-12-03 22:00:00 +01:00
2009-12-04 22:00:00 +01:00
// g-cont - cl.refdef.crosshairangle is the autoaim angle.
// if we're not using autoaim, just draw in the middle of the
// screen
if( !VectorIsNull( cl.refdef.crosshairangle ))
{
vec3_t angles;
vec3_t forward;
vec3_t point, screen;
2009-12-03 22:00:00 +01:00
2009-12-04 22:00:00 +01:00
// FIXME: this code is wrong
VectorAdd( cl.refdef.cl_viewangles, cl.refdef.crosshairangle, angles );
AngleVectors( angles, forward, NULL, NULL );
VectorAdd( cl.refdef.vieworg, forward, point );
re->WorldToScreen( point, screen );
2009-12-03 22:00:00 +01:00
2009-12-04 22:00:00 +01:00
if( clgame.scrInfo.iFlags & SCRINFO_VIRTUALSPACE )
{
float xscale, yscale;
// NOTE: WorldToScreen returns real coordinates, we need to divide it
// into virtual screenspace
xscale = clgame.scrInfo.iRealWidth / (float)clgame.scrInfo.iWidth;
yscale = clgame.scrInfo.iRealHeight / (float)clgame.scrInfo.iHeight;
x = screen[0] / xscale;
y = screen[1] / yscale;
}
else
{
x = screen[0];
y = screen[1];
}
}
else
{
x = clgame.scrInfo.iWidth / 2;
y = clgame.scrInfo.iHeight / 2;
}
2009-12-03 22:00:00 +01:00
clgame.ds.hSprite = clgame.ds.hCrosshair;
re->SetColor( clgame.ds.rgbaCrosshair );
re->SetParms( clgame.ds.hSprite, kRenderTransAlpha, 0 );
2009-12-04 22:00:00 +01:00
SPR_DrawGeneric( 0, x - 0.5f * width, y - 0.5f * height, -1, -1, &clgame.ds.rcCrosshair );
2009-12-03 22:00:00 +01:00
}
2008-12-26 22:00:00 +01:00
void CL_DrawHUD( int state )
2008-12-25 22:00:00 +01:00
{
2009-01-25 22:00:00 +01:00
if( state == CL_ACTIVE && !cl.video_prepped )
state = CL_LOADING;
2009-11-10 22:00:00 +01:00
if( state == CL_ACTIVE && cl.refdef.paused )
2009-01-25 22:00:00 +01:00
state = CL_PAUSED;
2009-09-17 22:00:00 +02:00
clgame.dllFuncs.pfnRedraw( cl.time * 0.001f, state );
2009-01-22 22:00:00 +01:00
2009-12-03 22:00:00 +01:00
if( state == CL_ACTIVE || state == CL_PAUSED )
2009-12-04 22:00:00 +01:00
{
CL_DrawCrosshair ();
CL_DrawCenterPrint ();
}
2009-12-03 22:00:00 +01:00
2009-01-22 22:00:00 +01:00
if( state == CL_ACTIVE )
2009-09-17 22:00:00 +02:00
clgame.dllFuncs.pfnFrame( cl.time * 0.001f );
2008-12-25 22:00:00 +01:00
}
2008-12-26 22:00:00 +01:00
static void CL_CreateUserMessage( int lastnum, const char *szMsgName, int svc_num, int iSize, pfnUserMsgHook pfn )
2008-12-25 22:00:00 +01:00
{
user_message_t *msg;
2008-12-26 22:00:00 +01:00
if( lastnum == clgame.numMessages )
2008-12-25 22:00:00 +01:00
{
2008-12-26 22:00:00 +01:00
if( clgame.numMessages == MAX_USER_MESSAGES )
{
MsgDev( D_ERROR, "CL_CreateUserMessage: user messages limit is out\n" );
return;
}
clgame.numMessages++;
2008-12-25 22:00:00 +01:00
}
2008-12-26 22:00:00 +01:00
msg = clgame.msg[lastnum];
2008-12-25 22:00:00 +01:00
// clear existing or allocate new one
if( msg ) Mem_Set( msg, 0, sizeof( *msg ));
2008-12-26 22:00:00 +01:00
else msg = clgame.msg[lastnum] = Mem_Alloc( cls.mempool, sizeof( *msg ));
com.strncpy( msg->name, szMsgName, CS_SIZE );
msg->number = svc_num;
msg->size = iSize;
msg->func = pfn;
}
2008-12-25 22:00:00 +01:00
2008-12-26 22:00:00 +01:00
void CL_LinkUserMessage( char *pszName, const int svc_num )
{
user_message_t *msg;
char *end;
char msgName[CS_SIZE];
int i, msgSize;
if( !pszName || !*pszName ) return; // ignore blank names
com.strncpy( msgName, pszName, CS_SIZE );
end = com.strchr( msgName, '@' );
2008-12-25 22:00:00 +01:00
if( !end )
{
2008-12-26 22:00:00 +01:00
MsgDev( D_ERROR, "CL_LinkUserMessage: can't register message %s\n", msgName );
2008-12-25 22:00:00 +01:00
return;
}
2008-12-26 22:00:00 +01:00
msgSize = com.atoi( end + 1 );
msgName[end-msgName] = '\0'; // remove size description from MsgName
2008-12-25 22:00:00 +01:00
2008-12-26 22:00:00 +01:00
// search message by name to link with
for( i = 0; i < clgame.numMessages; i++ )
{
msg = clgame.msg[i];
if( !msg ) continue;
if( !com.strcmp( msg->name, msgName ))
{
msg->number = svc_num;
msg->size = msgSize;
return;
}
}
// create an empty message
CL_CreateUserMessage( i, msgName, svc_num, msgSize, NULL );
}
2009-12-03 22:00:00 +01:00
/*
=======================
CL_MsgNumbers
=======================
*/
static int CL_MsgNumbers( const void *a, const void *b )
{
user_message_t *msga, *msgb;
msga = (user_message_t *)a;
msgb = (user_message_t *)b;
if( msga == NULL )
{
if ( msgb == NULL ) return 0;
else return -1;
}
else if ( msgb == NULL ) return 1;
if( msga->number < msgb->number )
return -1;
return 1;
}
2008-12-26 22:00:00 +01:00
void CL_SortUserMessages( void )
{
2009-12-03 22:00:00 +01:00
// qsort( clgame.msg, clgame.numMessages, sizeof( user_message_t ), CL_MsgNumbers );
2008-12-25 22:00:00 +01:00
}
void CL_ParseUserMessage( sizebuf_t *net_buffer, int svc_num )
{
user_message_t *msg;
2008-12-26 22:00:00 +01:00
int i, iSize;
2008-12-25 22:00:00 +01:00
byte *pbuf;
2008-12-26 22:00:00 +01:00
2008-12-25 22:00:00 +01:00
// NOTE: any user message parse on engine, not in client.dll
2008-12-26 22:00:00 +01:00
if( svc_num >= clgame.numMessages )
2008-12-25 22:00:00 +01:00
{
// unregister message can't be parsed
Host_Error( "CL_ParseUserMessage: illegible server message %d\n", svc_num );
return;
}
2008-12-26 22:00:00 +01:00
// search for svc_num
for( i = 0; i < clgame.numMessages; i++ )
2008-12-25 22:00:00 +01:00
{
2008-12-26 22:00:00 +01:00
msg = clgame.msg[i];
if( !msg ) continue;
if( msg->number == svc_num )
break;
}
2008-12-25 22:00:00 +01:00
2008-12-26 22:00:00 +01:00
if( i == clgame.numMessages || !msg )
{
// unregistered message ?
Host_Error( "CL_ParseUserMessage: illegible server message %d\n", svc_num );
return;
2008-12-25 22:00:00 +01:00
}
iSize = msg->size;
pbuf = NULL;
2008-12-26 22:00:00 +01:00
// message with variable sizes receive an actual size as first byte
2008-12-25 22:00:00 +01:00
if( iSize == -1 ) iSize = MSG_ReadByte( net_buffer );
2009-06-24 22:00:00 +02:00
if( iSize > 0 ) pbuf = Mem_Alloc( clgame.private, iSize );
2008-12-25 22:00:00 +01:00
// parse user message into buffer
MSG_ReadData( net_buffer, pbuf, iSize );
if( msg->func ) msg->func( msg->name, iSize, pbuf );
2008-12-26 22:00:00 +01:00
else MsgDev( D_WARN, "CL_ParseUserMessage: %s not hooked\n", msg->name );
2008-12-25 22:00:00 +01:00
if( pbuf ) Mem_Free( pbuf );
}
2009-12-02 22:00:00 +01:00
static void CL_RegisterEvent( int lastnum, const char *szEvName, pfnEventHook func )
{
user_event_t *ev;
if( lastnum == MAX_EVENTS )
{
MsgDev( D_ERROR, "CL_RegisterEvent: MAX_EVENTS hit!!!\n" );
return;
}
ev = clgame.events[lastnum];
// clear existing or allocate new one
if( ev ) Mem_Set( ev, 0, sizeof( *ev ));
else ev = clgame.events[lastnum] = Mem_Alloc( cls.mempool, sizeof( *ev ));
com.strncpy( ev->name, szEvName, CS_SIZE );
ev->func = func;
// ev->index will be set later
}
void CL_SetEventIndex( const char *szEvName, int ev_index )
{
user_event_t *ev;
int i;
if( !szEvName || !*szEvName ) return; // ignore blank names
// search event by name to link with
for( i = 0; i < MAX_EVENTS; i++ )
{
ev = clgame.events[i];
if( !ev ) break;
if( !com.strcmp( ev->name, szEvName ))
{
ev->index = ev_index;
return;
}
}
}
2008-12-25 22:00:00 +01:00
void CL_InitEdict( edict_t *pEdict )
{
Com_Assert( pEdict == NULL );
2009-09-25 22:00:00 +02:00
Com_Assert( pEdict->pvPrivateData != NULL );
Com_Assert( pEdict->pvClientData != NULL );
2008-12-25 22:00:00 +01:00
pEdict->v.pContainingEntity = pEdict; // make cross-links for consistency
2009-09-25 22:00:00 +02:00
pEdict->pvClientData = (cl_priv_t *)Mem_Alloc( cls.mempool, sizeof( cl_priv_t ));
pEdict->pvPrivateData = NULL;
2008-12-25 22:00:00 +01:00
pEdict->serialnumber = NUM_FOR_EDICT( pEdict ); // merged on first update
pEdict->free = false;
}
void CL_FreeEdict( edict_t *pEdict )
{
Com_Assert( pEdict == NULL );
Com_Assert( pEdict->free );
// unlink from world
2009-11-26 22:00:00 +01:00
CL_UnlinkEdict( pEdict );
2008-12-25 22:00:00 +01:00
2008-12-26 22:00:00 +01:00
if( pEdict->pvClientData ) Mem_Free( pEdict->pvClientData );
2009-09-25 22:00:00 +02:00
if( pEdict->pvPrivateData ) Mem_Free( pEdict->pvPrivateData );
Mem_Set( pEdict, 0, sizeof( *pEdict ));
2008-12-25 22:00:00 +01:00
// mark edict as freed
2009-09-17 22:00:00 +02:00
pEdict->freetime = cl.time * 0.001f;
2009-09-25 22:00:00 +02:00
pEdict->v.nextthink = -1;
2008-12-25 22:00:00 +01:00
pEdict->free = true;
}
edict_t *CL_AllocEdict( void )
{
edict_t *pEdict;
int i;
2009-11-27 22:00:00 +01:00
for( i = clgame.globals->maxClients + 1; i < clgame.globals->numEntities; i++ )
2008-12-25 22:00:00 +01:00
{
pEdict = EDICT_NUM( i );
2009-01-04 22:00:00 +01:00
// the first couple seconds of client time can involve a lot of
2008-12-25 22:00:00 +01:00
// freeing and allocating, so relax the replacement policy
2009-09-17 22:00:00 +02:00
if( pEdict->free && ( pEdict->freetime < 2.0f || ((cl.time * 0.001f) - pEdict->freetime) > 0.5f ))
2008-12-25 22:00:00 +01:00
{
CL_InitEdict( pEdict );
return pEdict;
}
}
2009-09-28 22:00:00 +02:00
if( i == clgame.globals->maxEntities )
2008-12-25 22:00:00 +01:00
Host_Error( "CL_AllocEdict: no free edicts\n" );
2009-09-28 22:00:00 +02:00
clgame.globals->numEntities++;
2008-12-25 22:00:00 +01:00
pEdict = EDICT_NUM( i );
CL_InitEdict( pEdict );
return pEdict;
}
2009-11-27 22:00:00 +01:00
void CL_InitWorld( void )
2009-09-25 22:00:00 +02:00
{
2009-11-26 22:00:00 +01:00
edict_t *ent;
2009-09-25 22:00:00 +02:00
int i;
2009-11-26 22:00:00 +01:00
ent = EDICT_NUM( 0 );
if( ent->free ) CL_InitEdict( ent );
2009-11-27 22:00:00 +01:00
ent->v.classname = MAKE_STRING( "worldspawn" );
2009-11-26 22:00:00 +01:00
ent->v.model = MAKE_STRING( cl.configstrings[CS_MODELS+1] );
ent->v.modelindex = 1; // world model
ent->v.solid = SOLID_BSP;
ent->v.movetype = MOVETYPE_PUSH;
clgame.globals->numEntities = 1;
2009-09-28 22:00:00 +02:00
clgame.globals->mapname = MAKE_STRING( cl.configstrings[CS_NAME] );
clgame.globals->coop = Cvar_VariableInteger( "coop" );
clgame.globals->teamplay = Cvar_VariableInteger( "teamplay" );
2009-11-27 22:00:00 +01:00
clgame.globals->deathmatch = Cvar_VariableInteger( "deathmatch" );
2009-11-26 22:00:00 +01:00
clgame.globals->serverflags = com.atoi( cl.configstrings[CS_SERVERFLAGS] );
2009-10-18 22:00:00 +02:00
2009-11-27 22:00:00 +01:00
for( i = 0; i < clgame.globals->maxClients; i++ )
{
// setup all clients
ent = EDICT_NUM( i + 1 );
CL_InitEdict( ent );
clgame.globals->numClients++;
}
// clear viewmodel prevstate
2009-12-06 22:00:00 +01:00
Mem_Set( &clgame.viewent.pvClientData->frame, 0, sizeof( studioframe_t ));
2009-09-25 22:00:00 +02:00
}
2009-11-27 22:00:00 +01:00
void CL_InitEdicts( void )
{
edict_t *e;
int i;
Com_Assert( clgame.edicts != NULL );
2009-11-28 22:00:00 +01:00
Com_Assert( clgame.baselines != NULL );
2009-11-27 22:00:00 +01:00
clgame.edicts = Mem_Alloc( clgame.mempool, sizeof( edict_t ) * clgame.globals->maxEntities );
2009-11-28 22:00:00 +01:00
clgame.baselines = Mem_Alloc( clgame.mempool, sizeof( entity_state_t ) * clgame.globals->maxEntities );
2009-11-27 22:00:00 +01:00
for( i = 0, e = clgame.edicts; i < clgame.globals->maxEntities; i++, e++ )
e->free = true; // mark all edicts as freed
}
2008-12-25 22:00:00 +01:00
void CL_FreeEdicts( void )
{
int i;
edict_t *ent;
2009-11-27 22:00:00 +01:00
if( clgame.edicts )
2008-12-25 22:00:00 +01:00
{
2009-11-27 22:00:00 +01:00
for( i = 0; i < clgame.globals->maxEntities; i++ )
{
ent = EDICT_NUM( i );
if( ent->free ) continue;
CL_FreeEdict( ent );
}
Mem_Free( clgame.edicts );
2008-12-25 22:00:00 +01:00
}
2009-01-02 22:00:00 +01:00
2009-11-28 22:00:00 +01:00
if( clgame.baselines ) Mem_Free( clgame.baselines );
2009-01-02 22:00:00 +01:00
// clear globals
StringTable_Clear( clgame.hStringTable );
2009-09-28 22:00:00 +02:00
clgame.globals->numEntities = 0;
2009-11-27 22:00:00 +01:00
clgame.globals->numClients = 0;
2009-11-28 22:00:00 +01:00
clgame.baselines = NULL;
2009-11-27 22:00:00 +01:00
clgame.edicts = NULL;
2008-12-25 22:00:00 +01:00
}
2009-11-26 22:00:00 +01:00
bool CL_IsValidEdict( const edict_t *e )
{
if( !e ) return false;
if( e->free ) return false;
if( e == EDICT_NUM( 0 )) return false; // world is the read-only entity
if( !e->pvServerData ) return false;
// edict without pvPrivateData is valid edict
// server.dll know how allocate it
return true;
}
const char *CL_ClassName( const edict_t *e )
{
if( !e ) return "(null)";
if( e->free ) return "freed";
return STRING( e->v.classname );
}
2008-12-25 22:00:00 +01:00
/*
===============================================================================
CGame Builtin Functions
===============================================================================
*/
2009-12-03 22:00:00 +01:00
/*
=========
pfnSPR_Load
=========
*/
2009-12-04 22:00:00 +01:00
static HSPRITE pfnSPR_Load( const char *szPicName )
2009-12-03 22:00:00 +01:00
{
if( !re ) return 0; // render not initialized
if( !szPicName || !*szPicName )
{
MsgDev( D_ERROR, "CL_SpriteLoad: invalid spritename\n" );
return -1;
}
return re->RegisterShader( szPicName, SHADER_NOMIP ); // replace with SHADER_GENERIC ?
}
/*
=========
pfnSPR_Load
=========
*/
static int pfnSPR_Frames( HSPRITE hPic )
{
int numFrames;
if( !re ) return 1;
re->GetParms( NULL, NULL, &numFrames, 0, hPic );
return numFrames;
}
/*
=========
pfnSPR_Load
=========
*/
static int pfnSPR_Height( HSPRITE hPic, int frame )
{
int sprHeight;
if( !re ) return 0;
re->GetParms( NULL, &sprHeight, NULL, frame, hPic );
return sprHeight;
}
/*
=========
pfnSPR_Load
=========
*/
static int pfnSPR_Width( HSPRITE hPic, int frame )
{
int sprWidth;
if( !re ) return 0;
re->GetParms( &sprWidth, NULL, NULL, frame, hPic );
return sprWidth;
}
/*
=========
pfnSPR_Load
=========
*/
static void pfnSPR_Set( HSPRITE hPic, int r, int g, int b, int a )
{
rgba_t color;
if( !re ) return; // render not initialized
clgame.ds.hSprite = hPic;
MakeRGBA( color, r, g, b, a );
re->SetColor( color );
}
/*
=========
pfnSPR_Draw
=========
*/
static void pfnSPR_Draw( int frame, int x, int y, int width, int height, const wrect_t *prc )
{
if( !re ) return; // render not initialized
re->SetParms( clgame.ds.hSprite, kRenderNormal, frame );
SPR_DrawGeneric( frame, x, y, width, height, prc );
}
/*
=========
pfnSPR_DrawTrans
=========
*/
static void pfnSPR_DrawTrans( int frame, int x, int y, int width, int height, const wrect_t *prc )
{
if( !re ) return; // render not initialized
re->SetParms( clgame.ds.hSprite, kRenderTransColor, frame );
SPR_DrawGeneric( frame, x, y, width, height, prc );
}
/*
=========
pfnSPR_DrawHoles
=========
*/
static void pfnSPR_DrawHoles( int frame, int x, int y, int width, int height, const wrect_t *prc )
{
if( !re ) return; // render not initialized
re->SetParms( clgame.ds.hSprite, kRenderTransAlpha, frame );
SPR_DrawGeneric( frame, x, y, width, height, prc );
}
/*
=========
pfnSPR_DrawAdditive
=========
*/
static void pfnSPR_DrawAdditive( int frame, int x, int y, int width, int height, const wrect_t *prc )
{
if( !re ) return; // render not initialized
re->SetParms( clgame.ds.hSprite, kRenderTransAdd, frame );
SPR_DrawGeneric( frame, x, y, width, height, prc );
}
/*
=========
pfnSPR_EnableScissor
=========
*/
static void pfnSPR_EnableScissor( int x, int y, int width, int height )
{
// check bounds
x = bound( 0, x, clgame.scrInfo.iWidth );
y = bound( 0, y, clgame.scrInfo.iHeight );
width = bound( 0, width, clgame.scrInfo.iWidth - x );
height = bound( 0, height, clgame.scrInfo.iHeight - y );
clgame.ds.scissor_x = x;
clgame.ds.scissor_width = width;
clgame.ds.scissor_y = y;
clgame.ds.scissor_height = height;
clgame.ds.scissor_test = true;
}
/*
=========
pfnSPR_DisableScissor
=========
*/
static void pfnSPR_DisableScissor( void )
{
clgame.ds.scissor_x = 0;
clgame.ds.scissor_width = 0;
clgame.ds.scissor_y = 0;
clgame.ds.scissor_height = 0;
clgame.ds.scissor_test = false;
}
/*
=========
pfnSPR_GetList
FIXME: implement original hl1 SPR_GetList
=========
*/
static client_sprite_t *pfnSPR_GetList( char *psz, int *piCount )
{
return NULL;
}
/*
=============
pfnFillRGBA
=============
*/
static void pfnFillRGBA( int x, int y, int width, int height, int r, int g, int b, int a )
{
rgba_t color;
if( !re ) return;
MakeRGBA( color, r, g, b, a );
re->SetColor( color );
SPR_AdjustSize( (float *)&x, (float *)&y, (float *)&width, (float *)&height );
re->DrawStretchPic( x, y, width, height, 0, 0, 1, 1, cls.fillShader );
re->SetColor( NULL );
}
/*
=============
pfnGetScreenInfo
get actual screen info
=============
*/
static int pfnGetScreenInfo( SCREENINFO *pscrinfo )
{
int i;
// setup screen info
clgame.scrInfo.iRealWidth = scr_width->integer;
clgame.scrInfo.iRealHeight = scr_height->integer;
if( pscrinfo && pscrinfo->iFlags & SCRINFO_VIRTUALSPACE )
{
// virtual screen space 640x480
// see cl_screen.c from Quake3 code for more details
clgame.scrInfo.iWidth = SCREEN_WIDTH;
clgame.scrInfo.iHeight = SCREEN_HEIGHT;
2009-12-04 22:00:00 +01:00
clgame.scrInfo.iFlags |= SCRINFO_VIRTUALSPACE;
2009-12-03 22:00:00 +01:00
}
else
{
clgame.scrInfo.iWidth = scr_width->integer;
clgame.scrInfo.iHeight = scr_height->integer;
2009-12-04 22:00:00 +01:00
clgame.scrInfo.iFlags &= ~SCRINFO_VIRTUALSPACE;
2009-12-03 22:00:00 +01:00
}
// TODO: build real table of fonts widthInChars
2009-12-04 22:00:00 +01:00
// TODO: load half-life credits font from wad
2009-12-03 22:00:00 +01:00
for( i = 0; i < 256; i++ )
clgame.scrInfo.charWidths[i] = SMALLCHAR_WIDTH;
clgame.scrInfo.iCharHeight = SMALLCHAR_HEIGHT;
if( !pscrinfo ) return 0;
*pscrinfo = clgame.scrInfo; // copy screeninfo out
return 1;
}
/*
=============
pfnSetCrosshair
setup auto-aim crosshair
=============
*/
static void pfnSetCrosshair( HSPRITE hspr, wrect_t rc, int r, int g, int b )
{
clgame.ds.rgbaCrosshair[0] = (byte)r;
clgame.ds.rgbaCrosshair[1] = (byte)g;
clgame.ds.rgbaCrosshair[2] = (byte)b;
clgame.ds.rgbaCrosshair[3] = (byte)0xFF;
clgame.ds.hCrosshair = hspr;
clgame.ds.rcCrosshair = rc;
}
2008-12-25 22:00:00 +01:00
/*
=============
2009-10-18 22:00:00 +02:00
pfnAddCommand
2008-12-25 22:00:00 +01:00
=============
*/
2009-12-04 22:00:00 +01:00
static void pfnAddCommand( const char *cmd_name, xcommand_t func, const char *cmd_desc )
2008-12-25 22:00:00 +01:00
{
2009-10-18 22:00:00 +02:00
if( !cmd_name || !*cmd_name ) return;
if( !cmd_desc ) cmd_desc = ""; // hidden for makehelep system
2008-12-25 22:00:00 +01:00
// NOTE: if( func == NULL ) cmd will be forwarded to a server
Cmd_AddCommand( cmd_name, func, cmd_desc );
}
/*
=============
pfnHookUserMsg
=============
*/
2009-12-04 22:00:00 +01:00
static void pfnHookUserMsg( const char *szMsgName, pfnUserMsgHook pfn )
2008-12-25 22:00:00 +01:00
{
user_message_t *msg;
int i;
// ignore blank names
if( !szMsgName || !*szMsgName ) return;
2008-12-26 22:00:00 +01:00
2009-09-17 22:00:00 +02:00
// second call can change msgFunc
2008-12-26 22:00:00 +01:00
for( i = 0; i < clgame.numMessages; i++ )
2008-12-25 22:00:00 +01:00
{
2008-12-26 22:00:00 +01:00
msg = clgame.msg[i];
if( !msg ) continue;
2008-12-25 22:00:00 +01:00
if( !com.strcmp( szMsgName, msg->name ))
{
2008-12-26 22:00:00 +01:00
if( msg->func != pfn )
msg->func = pfn;
2008-12-25 22:00:00 +01:00
return;
}
}
2008-12-26 22:00:00 +01:00
// allocate a new one
CL_CreateUserMessage( i, szMsgName, 0, 0, pfn );
2008-12-25 22:00:00 +01:00
}
/*
=============
pfnServerCmd
=============
*/
2009-12-04 22:00:00 +01:00
static void pfnServerCmd( const char *szCmdString )
2008-12-25 22:00:00 +01:00
{
// server command adding in cmds queue
Cbuf_AddText( va( "cmd %s", szCmdString ));
}
/*
=============
pfnClientCmd
=============
*/
2009-12-04 22:00:00 +01:00
static void pfnClientCmd( const char *szCmdString )
2008-12-25 22:00:00 +01:00
{
// client command executes immediately
Cmd_ExecuteString( szCmdString );
}
2009-01-09 22:00:00 +01:00
/*
=============
2009-12-04 22:00:00 +01:00
pfnGetPlayerInfo
2009-01-09 22:00:00 +01:00
=============
*/
2009-12-04 22:00:00 +01:00
static void pfnGetPlayerInfo( int ent_num, hud_player_info_t *pinfo )
2009-01-09 22:00:00 +01:00
{
2009-12-04 22:00:00 +01:00
player_info_t *player;
ent_num -= 1; // player list if offset by 1 from ents
if( ent_num >= clgame.globals->maxClients || ent_num < 0 || !cl.players[ent_num].name[0] )
2009-01-09 22:00:00 +01:00
{
2009-12-04 22:00:00 +01:00
Mem_Set( pinfo, 0, sizeof( *pinfo ));
return;
2009-01-09 22:00:00 +01:00
}
2009-12-04 22:00:00 +01:00
player = &cl.players[ent_num];
pinfo->thisplayer = ( ent_num == cl.playernum ) ? true : false;
pinfo->name = player->name;
pinfo->model = player->model;
pinfo->ping = com.atoi( Info_ValueForKey( player->userinfo, "ping" ));
pinfo->spectator = com.atoi( Info_ValueForKey( player->userinfo, "spectator" ));
pinfo->packetloss = com.atoi( Info_ValueForKey( player->userinfo, "loss" ));
pinfo->topcolor = com.atoi( Info_ValueForKey( player->userinfo, "topcolor" ));
pinfo->bottomcolor = com.atoi( Info_ValueForKey( player->userinfo, "bottomcolor" ));
2009-01-09 22:00:00 +01:00
}
2009-12-04 22:00:00 +01:00
2008-12-25 22:00:00 +01:00
/*
=============
2009-12-04 22:00:00 +01:00
pfnPlaySoundByName
2008-12-25 22:00:00 +01:00
=============
*/
2009-12-04 22:00:00 +01:00
static void pfnPlaySoundByName( const char *szSound, float volume, int pitch, const float *org )
2008-12-25 22:00:00 +01:00
{
2009-12-04 22:00:00 +01:00
S_StartLocalSound( szSound, volume, pitch, org );
}
2008-12-25 22:00:00 +01:00
2009-12-04 22:00:00 +01:00
/*
=============
pfnPlaySoundByIndex
=============
*/
static void pfnPlaySoundByIndex( int iSound, float volume, int pitch, const float *org )
{
// make sure what we in-bounds
iSound = bound( 0, iSound, MAX_SOUNDS );
if( cl.sound_precache[iSound] == 0 )
{
MsgDev( D_ERROR, "CL_PlaySoundByIndex: invalid sound handle %i\n", iSound );
return;
}
S_StartSound( org, cl.refdef.viewentity, CHAN_AUTO, cl.sound_precache[iSound], volume, ATTN_NORM, pitch, 0 );
2008-12-25 22:00:00 +01:00
}
/*
=============
2009-01-03 22:00:00 +01:00
pfnTextMessageGet
2008-12-25 22:00:00 +01:00
2009-12-04 22:00:00 +01:00
returns specified message from titles.txt
2008-12-25 22:00:00 +01:00
=============
*/
2009-12-04 22:00:00 +01:00
static client_textmessage_t *pfnTextMessageGet( const char *pName )
2008-12-25 22:00:00 +01:00
{
2009-10-23 22:00:00 +02:00
int i;
2008-12-25 22:00:00 +01:00
2009-10-23 22:00:00 +02:00
// find desired message
for( i = 0; i < clgame.numTitles; i++ )
{
if( !com.strcmp( pName, clgame.titles[i].pName ))
return clgame.titles + i;
}
return NULL; // found nothing
2008-12-25 22:00:00 +01:00
}
/*
=============
2009-12-04 22:00:00 +01:00
pfnDrawCharacter
2008-12-25 22:00:00 +01:00
2009-12-04 22:00:00 +01:00
returns drawed chachter width (in real screen pixels)
2008-12-25 22:00:00 +01:00
=============
*/
2009-12-04 22:00:00 +01:00
static int pfnDrawCharacter( int x, int y, int number, int r, int g, int b )
2008-12-25 22:00:00 +01:00
{
2009-12-04 22:00:00 +01:00
float size, frow, fcol;
float ax, ay, aw, ah;
int fontWidth, fontHeight;
rgba_t color;
number &= 255;
if( !re ) return 0;
if( number == ' ' ) return 0;
if( y < -clgame.scrInfo.iCharHeight )
return 0;
ax = x;
ay = y;
aw = clgame.scrInfo.charWidths[number];
ah = clgame.scrInfo.iCharHeight;
SPR_AdjustSize( &ax, &ay, &aw, &ah );
re->GetParms( &fontWidth, &fontHeight, NULL, 0, clgame.ds.hHudFont );
MakeRGBA( color, r, g, b, 255 );
re->SetColor( color );
frow = (number >> 4)*0.0625f + (0.5f / (float)fontWidth);
fcol = (number & 15)*0.0625f + (0.5f / (float)fontHeight);
size = 0.0625f - (1.0f / (float)fontWidth);
re->DrawStretchPic( ax, ay, aw, ah, fcol, frow, fcol + size, frow + size, clgame.ds.hHudFont );
re->SetColor( NULL ); // don't forget reset color
return clgame.scrInfo.charWidths[number];
2008-12-25 22:00:00 +01:00
}
/*
=============
2009-12-04 22:00:00 +01:00
pfnDrawConsoleString
2008-12-25 22:00:00 +01:00
2009-12-04 22:00:00 +01:00
drawing string like a console string
2008-12-25 22:00:00 +01:00
=============
2009-12-04 22:00:00 +01:00
*/
static int pfnDrawConsoleString( int x, int y, char *string )
2008-12-25 22:00:00 +01:00
{
2009-12-04 22:00:00 +01:00
if( !string || !*string ) return 0; // silent ignore
SCR_DrawSmallStringExt( x, y, string, NULL, false );
return com.cstrlen( string ) * SMALLCHAR_WIDTH; // not includes color prexfixes
2008-12-25 22:00:00 +01:00
}
/*
=============
2009-12-04 22:00:00 +01:00
pfnDrawSetTextColor
2008-12-25 22:00:00 +01:00
2009-12-04 22:00:00 +01:00
set color for anything
2008-12-25 22:00:00 +01:00
=============
*/
2009-12-04 22:00:00 +01:00
static void pfnDrawSetTextColor( float r, float g, float b )
2008-12-25 22:00:00 +01:00
{
2009-12-04 22:00:00 +01:00
rgba_t color;
// bound color and convert to byte
color[0] = (byte)bound( 0, r * 255, 255 );
color[1] = (byte)bound( 0, g * 255, 255 );
color[2] = (byte)bound( 0, b * 255, 255 );
color[3] = (byte)0xFF;
if( re ) re->SetColor( color );
2008-12-25 22:00:00 +01:00
}
/*
=============
2009-12-04 22:00:00 +01:00
pfnDrawConsoleStringLen
2008-12-25 22:00:00 +01:00
2009-12-04 22:00:00 +01:00
returns width and height (in real pixels)
for specified string
2008-12-25 22:00:00 +01:00
=============
*/
2009-12-04 22:00:00 +01:00
static void pfnDrawConsoleStringLen( const char *string, int *length, int *height )
2008-12-25 22:00:00 +01:00
{
2009-12-04 22:00:00 +01:00
// console used fixed font size
if( length ) *length = com.cstrlen( string ) * SMALLCHAR_WIDTH;
if( height ) *height = SMALLCHAR_HEIGHT;
2008-12-25 22:00:00 +01:00
}
/*
=============
2009-12-04 22:00:00 +01:00
pfnConsolePrint
2008-12-25 22:00:00 +01:00
2009-12-04 22:00:00 +01:00
prints dirctly into console (can skip notify)
2008-12-25 22:00:00 +01:00
=============
*/
2009-12-04 22:00:00 +01:00
static void pfnConsolePrint( const char *string )
2008-12-25 22:00:00 +01:00
{
2009-12-04 22:00:00 +01:00
if( !string || !*string ) return;
if( *string == 1 ) Con_Print( string + 1 ); // show notify
else Con_Print( va( "[skipnotify]%s", string )); // skip notify
}
2008-12-25 22:00:00 +01:00
2009-12-04 22:00:00 +01:00
/*
=============
pfnCenterPrint
2008-12-25 22:00:00 +01:00
2009-12-04 22:00:00 +01:00
holds and fade message at center of screen
like trigger_multiple message in q1
=============
*/
static void pfnCenterPrint( const char *string )
{
if( !string || !*string ) return; // someone stupid joke
CL_CenterPrint( string, 160, SMALLCHAR_WIDTH );
}
2009-12-05 22:00:00 +01:00
2009-12-04 22:00:00 +01:00
/*
=========
pfnMemAlloc
2008-12-25 22:00:00 +01:00
2009-12-04 22:00:00 +01:00
=========
*/
static void *pfnMemAlloc( size_t cb, const char *filename, const int fileline )
{
return com.malloc( clgame.private, cb, filename, fileline );
}
2008-12-25 22:00:00 +01:00
2009-12-04 22:00:00 +01:00
/*
=========
pfnMemFree
2008-12-25 22:00:00 +01:00
2009-12-04 22:00:00 +01:00
=========
*/
static void pfnMemFree( void *mem, const char *filename, const int fileline )
{
com.free( mem, filename, fileline );
2008-12-25 22:00:00 +01:00
}
/*
=============
2009-12-05 22:00:00 +01:00
pfnGetViewAngles
2008-12-25 22:00:00 +01:00
2009-12-05 22:00:00 +01:00
return interpolated angles from previous frame
2008-12-25 22:00:00 +01:00
=============
*/
2009-12-05 22:00:00 +01:00
static void pfnGetViewAngles( float *angles )
2008-12-25 22:00:00 +01:00
{
2009-12-05 22:00:00 +01:00
if( angles == NULL ) return;
VectorCopy( cl.refdef.cl_viewangles, angles );
2008-12-25 22:00:00 +01:00
}
/*
=============
2009-12-05 22:00:00 +01:00
pfnSetViewAngles
2008-12-25 22:00:00 +01:00
2009-12-05 22:00:00 +01:00
return interpolated angles from previous frame
2008-12-25 22:00:00 +01:00
=============
*/
2009-12-05 22:00:00 +01:00
static void pfnSetViewAngles( float *angles )
2008-12-25 22:00:00 +01:00
{
2009-12-05 22:00:00 +01:00
if( angles == NULL ) return;
VectorCopy( angles, cl.refdef.cl_viewangles );
2008-12-25 22:00:00 +01:00
}
2008-12-28 22:00:00 +01:00
/*
=============
2009-12-05 22:00:00 +01:00
pfnDelCommand
2008-12-28 22:00:00 +01:00
=============
*/
2009-12-05 22:00:00 +01:00
static void pfnDelCommand( const char *cmd_name )
2008-12-25 22:00:00 +01:00
{
2009-12-05 22:00:00 +01:00
if( !cmd_name || !*cmd_name ) return;
2008-12-28 22:00:00 +01:00
2009-12-05 22:00:00 +01:00
Cmd_RemoveCommand( cmd_name );
2009-12-04 22:00:00 +01:00
}
/*
=============
2009-12-05 22:00:00 +01:00
pfnPhysInfo_ValueForKey
2009-12-04 22:00:00 +01:00
=============
2009-12-05 22:00:00 +01:00
*/
static const char* pfnPhysInfo_ValueForKey( const char *key )
2009-12-04 22:00:00 +01:00
{
2009-12-05 22:00:00 +01:00
return Info_ValueForKey( cl.physinfo, key );
2008-12-28 22:00:00 +01:00
}
2008-12-25 22:00:00 +01:00
/*
=============
2009-12-05 22:00:00 +01:00
pfnServerInfo_ValueForKey
2008-12-25 22:00:00 +01:00
2009-12-05 22:00:00 +01:00
FIXME: this is valid only for local client
2008-12-25 22:00:00 +01:00
=============
*/
2009-12-05 22:00:00 +01:00
static const char* pfnServerInfo_ValueForKey( const char *key )
2008-12-25 22:00:00 +01:00
{
2009-12-05 22:00:00 +01:00
return Info_ValueForKey( Cvar_Serverinfo(), key );
2008-12-25 22:00:00 +01:00
}
/*
=============
2009-12-05 22:00:00 +01:00
pfnGetClientMaxspeed
2008-12-25 22:00:00 +01:00
2009-12-05 22:00:00 +01:00
value that come from server
2008-12-25 22:00:00 +01:00
=============
*/
2009-12-05 22:00:00 +01:00
static float pfnGetClientMaxspeed( void )
2008-12-25 22:00:00 +01:00
{
2009-12-05 22:00:00 +01:00
edict_t *player = CL_GetLocalPlayer ();
if( !player ) return 0;
return player->v.maxspeed;
2008-12-25 22:00:00 +01:00
}
/*
=============
2009-12-05 22:00:00 +01:00
pfnGetModelPtr
2008-12-25 22:00:00 +01:00
2009-12-05 22:00:00 +01:00
returns pointer to a studiomodel
2008-12-25 22:00:00 +01:00
=============
*/
2009-12-05 22:00:00 +01:00
static void *pfnGetModelPtr( edict_t *pEdict )
2008-12-25 22:00:00 +01:00
{
2009-12-05 22:00:00 +01:00
if( !pEdict || pEdict->free )
return NULL;
return Mod_Extradata( pEdict->v.modelindex );
2009-09-17 22:00:00 +02:00
}
/*
=============
2009-12-05 22:00:00 +01:00
pfnGetBonePosition
2009-09-17 22:00:00 +02:00
=============
*/
2009-12-05 22:00:00 +01:00
static void pfnGetBonePosition( const edict_t* pEdict, int iBone, float *rgflOrigin, float *rgflAngles )
2009-09-17 22:00:00 +02:00
{
2009-12-05 22:00:00 +01:00
if( !CL_IsValidEdict( pEdict ))
{
MsgDev( D_WARN, "CL_GetBonePos: invalid entity %s\n", CL_ClassName( pEdict ));
return;
}
CM_GetBonePosition( (edict_t *)pEdict, iBone, rgflOrigin, rgflAngles );
2008-12-25 22:00:00 +01:00
}
/*
=============
2009-12-05 22:00:00 +01:00
pfnGetViewModel
2008-12-25 22:00:00 +01:00
2009-12-05 22:00:00 +01:00
can return NULL
2008-12-25 22:00:00 +01:00
=============
*/
2009-12-05 22:00:00 +01:00
static edict_t* pfnGetViewModel( void )
2008-12-25 22:00:00 +01:00
{
2009-12-05 22:00:00 +01:00
return &clgame.viewent;
2008-12-25 22:00:00 +01:00
}
/*
=============
2009-12-05 22:00:00 +01:00
pfnGetClientTime
2008-12-25 22:00:00 +01:00
=============
*/
2009-12-05 22:00:00 +01:00
static float pfnGetClientTime( void )
2008-12-25 22:00:00 +01:00
{
2009-12-05 22:00:00 +01:00
return cl.time * 0.001f;
2008-12-25 22:00:00 +01:00
}
2009-01-22 22:00:00 +01:00
/*
=============
2009-12-05 22:00:00 +01:00
pfnIsSpectateOnly
2009-01-22 22:00:00 +01:00
=============
*/
2009-12-05 22:00:00 +01:00
static int pfnIsSpectateOnly( void )
2009-01-22 22:00:00 +01:00
{
2009-12-05 22:00:00 +01:00
return com.atoi( Info_ValueForKey( Cvar_Userinfo(), "spectator" )) ? true : false;
2009-01-22 22:00:00 +01:00
}
2009-10-15 22:00:00 +02:00
/*
=============
pfnGetAttachment
=============
*/
static void pfnGetAttachment( const edict_t *pEdict, int iAttachment, float *rgflOrigin, float *rgflAngles )
{
if( !pEdict )
{
if( rgflOrigin ) VectorClear( rgflOrigin );
if( rgflAngles ) VectorClear( rgflAngles );
return;
}
CL_GetAttachment( pEdict->serialnumber, iAttachment, rgflOrigin, rgflAngles );
}
2008-12-25 22:00:00 +01:00
/*
=============
pfnPointContents
=============
*/
static int pfnPointContents( const float *rgflVector )
{
return CL_PointContents( rgflVector );
}
2009-12-05 22:00:00 +01:00
/*
=============
pfnWaterEntity
=============
*/
static edict_t *pfnWaterEntity( const float *rgflPos )
{
edict_t *player, *pWater;
if( !rgflPos ) return NULL;
player = CL_GetLocalPlayer ();
if( !player ) return NULL;
pWater = CL_Move( rgflPos, vec3_origin, vec3_origin, rgflPos, MOVE_NOMONSTERS, player ).pHit;
if( CL_IsValidEdict( pWater ))
{
int mod_type = CM_GetModelType( pWater->v.modelindex );
int cont = pWater->v.skin;
// make sure what is a really water entity
if(( mod_type == mod_brush || mod_type == mod_world ) && (cont <= CONTENTS_WATER && cont >= CONTENTS_LAVA ))
return pWater;
}
return NULL;
}
2008-12-25 22:00:00 +01:00
/*
=============
pfnTraceLine
=============
*/
static void pfnTraceLine( const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr )
{
2009-11-02 22:00:00 +01:00
trace_t result;
2008-12-25 22:00:00 +01:00
2009-11-26 22:00:00 +01:00
if( VectorIsNAN( v1 ) || VectorIsNAN( v2 ))
Host_Error( "TraceLine: NAN errors detected '%f %f %f', '%f %f %f'\n", v1[0], v1[1], v1[2], v2[0], v2[1], v2[2] );
result = CL_Move( v1, vec3_origin, vec3_origin, v2, fNoMonsters, pentToSkip );
if( ptr ) Mem_Copy( ptr, &result, sizeof( *ptr ));
2008-12-25 22:00:00 +01:00
}
2009-01-11 22:00:00 +01:00
/*
=================
pfnTraceToss
=================
*/
static void pfnTraceToss( edict_t* pent, edict_t* pentToIgnore, TraceResult *ptr )
{
2009-11-02 22:00:00 +01:00
trace_t result;
2009-11-26 22:00:00 +01:00
if( !CL_IsValidEdict( pent ))
{
MsgDev( D_WARN, "CL_MoveToss: invalid entity %s\n", CL_ClassName( pent ));
return;
}
result = CL_MoveToss( pent, pentToIgnore );
if( ptr ) Mem_Copy( ptr, &result, sizeof( *ptr ));
2009-01-11 22:00:00 +01:00
}
/*
=================
pfnTraceHull
=================
*/
2009-11-26 22:00:00 +01:00
static void pfnTraceHull( const float *v1, const float *v2, int fNoMonsters, int hullNumber, edict_t *pentToSkip, TraceResult *ptr )
2009-01-11 22:00:00 +01:00
{
2009-11-02 22:00:00 +01:00
trace_t result;
2009-11-26 22:00:00 +01:00
float *mins, *maxs;
2009-01-11 22:00:00 +01:00
2009-11-26 22:00:00 +01:00
hullNumber = bound( 0, hullNumber, 3 );
mins = GI->client_mins[hullNumber];
maxs = GI->client_maxs[hullNumber];
2009-01-11 22:00:00 +01:00
2009-11-26 22:00:00 +01:00
if( VectorIsNAN( v1 ) || VectorIsNAN( v2 ))
Host_Error( "TraceHull: NAN errors detected '%f %f %f', '%f %f %f'\n", v1[0], v1[1], v1[2], v2[0], v2[1], v2[2] );
result = CL_Move( v1, mins, maxs, v2, fNoMonsters, pentToSkip );
if( ptr ) Mem_Copy( ptr, &result, sizeof( *ptr ));
2009-01-11 22:00:00 +01:00
}
static void pfnTraceModel( const float *v1, const float *v2, edict_t *pent, TraceResult *ptr )
{
2009-11-26 22:00:00 +01:00
trace_t result;
if( !CL_IsValidEdict( pent ))
{
MsgDev( D_WARN, "CL_TraceModel: invalid entity %s\n", CL_ClassName( pent ));
return;
}
if( VectorIsNAN( v1 ) || VectorIsNAN( v2 ))
Host_Error( "TraceModel: NAN errors detected '%f %f %f', '%f %f %f'\n", v1[0], v1[1], v1[2], v2[0], v2[1], v2[2] );
result = CL_ClipMoveToEntity( pent, v1, pent->v.mins, pent->v.maxs, v2, MASK_SOLID, 0 );
if( ptr ) Mem_Copy( ptr, &result, sizeof( *ptr ));
2009-01-11 22:00:00 +01:00
}
static const char *pfnTraceTexture( edict_t *pTextureEntity, const float *v1, const float *v2 )
{
2009-11-26 22:00:00 +01:00
if( VectorIsNAN( v1 ) || VectorIsNAN( v2 ))
Host_Error( "TraceTexture: NAN errors detected '%f %f %f', '%f %f %f'\n", v1[0], v1[1], v1[2], v2[0], v2[1], v2[2] );
if( !pTextureEntity || pTextureEntity->free ) return NULL;
return CL_ClipMoveToEntity( pTextureEntity, v1, vec3_origin, vec3_origin, v2, MASK_SOLID, 0 ).pTexName;
2009-01-11 22:00:00 +01:00
}
/*
=============
pfnPrecacheEvent
=============
*/
static word pfnPrecacheEvent( int type, const char* psz )
{
2009-12-02 22:00:00 +01:00
return CL_PrecacheEvent( psz );
2009-01-11 22:00:00 +01:00
}
/*
=============
pfnPlaybackEvent
=============
*/
static void pfnPlaybackEvent( int flags, const edict_t *pInvoker, word eventindex, float delay, event_args_t *args )
{
2009-12-02 22:00:00 +01:00
event_args_t dummy;
int invokerIndex = 0;
// first check event for out of bounds
if( eventindex < 1 || eventindex > MAX_EVENTS )
{
MsgDev( D_ERROR, "CL_PlaybackEvent: invalid eventindex %i\n", eventindex );
return;
}
// check event for precached
if( !CL_PrecacheEvent( cl.configstrings[CS_EVENTS+eventindex] ))
{
MsgDev( D_ERROR, "CL_PlaybackEvent: event %i was not precached\n", eventindex );
return;
}
flags |= FEV_CLIENT; // it's a client event
flags &= ~(FEV_NOTHOST|FEV_HOSTONLY|FEV_GLOBAL);
if( delay < 0.0f )
delay = 0.0f; // fixup negative delays
if( CL_IsValidEdict( pInvoker ))
invokerIndex = NUM_FOR_EDICT( pInvoker );
if( args == NULL )
{
Mem_Set( &dummy, 0, sizeof( dummy ));
args = &dummy;
}
if( flags & FEV_RELIABLE )
{
args->ducking = 0;
VectorClear( args->velocity );
}
else if( invokerIndex )
{
// get up some info from invoker
if( VectorIsNull( args->origin ))
VectorCopy( pInvoker->v.origin, args->origin );
if( VectorIsNull( args->angles ))
VectorCopy( pInvoker->v.angles, args->angles );
VectorCopy( pInvoker->v.velocity, args->velocity );
args->ducking = (pInvoker->v.flags & FL_DUCKING) ? true : false;
}
CL_QueueEvent( flags, eventindex, delay, args );
2009-01-11 22:00:00 +01:00
}
2009-12-05 22:00:00 +01:00
/*
=============
pfnWeaponAnim
just set viewmodel anim
=============
*/
static void pfnWeaponAnim( int iAnim, int body, float framerate )
{
edict_t *viewmodel = &clgame.viewent;
viewmodel->v.sequence = iAnim;
viewmodel->v.body = body;
viewmodel->v.framerate = framerate;
viewmodel->v.effects |= EF_ANIMATE;
viewmodel->v.frame = -1; // force to start new sequence
viewmodel->v.scale = 1.0f;
}
/*
=============
pfnHookEvent
=============
*/
static void pfnHookEvent( const char *name, pfnEventHook pfn )
{
word event_index = CL_PrecacheEvent( name );
user_event_t *ev;
int i;
// ignore blank names
if( !name || !*name ) return;
// second call can change EventFunc
for( i = 0; i < MAX_EVENTS; i++ )
{
ev = clgame.events[i];
if( !ev ) break;
if( !com.strcmp( name, ev->name ))
{
if( ev->func != pfn )
ev->func = pfn;
return;
}
}
CL_RegisterEvent( i, name, pfn );
}
2009-01-11 22:00:00 +01:00
/*
=============
pfnKillEvent
=============
*/
2009-12-05 22:00:00 +01:00
static void pfnKillEvents( int entnum, const char *eventname )
{
int i;
event_state_t *es;
event_info_t *ei;
int eventIndex = CL_PrecacheEvent( eventname );
if( eventIndex < 0 || eventIndex >= MAX_EVENTS )
return;
if( entnum < 0 || entnum > clgame.globals->maxEntities )
return;
es = &cl.events;
// find all events with specified index and kill it
for( i = 0; i < MAX_EVENT_QUEUE; i++ )
{
ei = &es->ei[i];
if( ei->index != eventIndex || ei->entity_index != entnum )
continue;
CL_ResetEvent( ei );
}
}
/*
=============
VGui_GetPanel
=============
*/
void *VGui_GetPanel( void )
2009-01-11 22:00:00 +01:00
{
// FIXME: implement
2009-12-05 22:00:00 +01:00
return NULL;
2009-01-11 22:00:00 +01:00
}
2008-12-26 22:00:00 +01:00
/*
=============
2009-12-05 22:00:00 +01:00
VGui_ViewportPaintBackground
2008-12-26 22:00:00 +01:00
=============
*/
2009-12-05 22:00:00 +01:00
void VGui_ViewportPaintBackground( int extents[4] )
2008-12-26 22:00:00 +01:00
{
2009-12-05 22:00:00 +01:00
// FIXME: implement
}
2008-12-26 22:00:00 +01:00
2009-12-05 22:00:00 +01:00
/*
===============================================================================
EffectsAPI Builtin Functions
===============================================================================
*/
2009-01-15 22:00:00 +01:00
/*
=================
pfnFindExplosionPlane
=================
*/
static void pfnFindExplosionPlane( const float *origin, float radius, float *result )
{
2009-11-23 22:00:00 +01:00
CL_FindExplosionPlane( origin, radius, result );
2009-01-15 22:00:00 +01:00
}
2009-01-16 22:00:00 +01:00
/*
=================
pfnDecalIndexFromName
=================
*/
static int pfnDecalIndexFromName( const char *szDecalName )
{
int i;
// look through the loaded sprite name list for SpriteName
for( i = 0; i < MAX_DECALS && cl.configstrings[CS_DECALS+i+1][0]; i++ )
{
if( !strcmp( szDecalName, cl.configstrings[CS_DECALS+i+1] ))
return cl.decal_shaders[i+1];
}
return 0; // invalid sprite
}
/*
=================
pfnDecalIndex
=================
*/
static int pfnDecalIndex( int id )
{
id = bound( 0, id, MAX_DECALS - 1 );
return cl.decal_shaders[id];
}
2009-01-22 22:00:00 +01:00
/*
=================
TriApi implementation
=================
*/
2009-12-07 22:00:00 +01:00
/*
=================
Tri_DrawTriangles
2009-10-20 22:00:00 +02:00
2009-12-07 22:00:00 +01:00
callback from renderer
=================
*/
void Tri_DrawTriangles( int fTrans )
2009-10-20 22:00:00 +02:00
{
2009-12-07 22:00:00 +01:00
clgame.dllFuncs.pfnDrawTriangles( fTrans );
2009-10-20 22:00:00 +02:00
}
2009-12-06 22:00:00 +01:00
/*
=============
TriLoadShader
=============
*/
shader_t TriLoadShader( const char *szShaderName, int fShaderNoMip )
{
if( !re ) return 0; // render not initialized
if( !szShaderName || !*szShaderName )
{
2009-12-07 22:00:00 +01:00
MsgDev( D_ERROR, "Tri_LoadShader: invalid shadername (%s)\n", fShaderNoMip ? "nomip" : "generic" );
2009-12-06 22:00:00 +01:00
return -1;
}
if( fShaderNoMip )
return re->RegisterShader( szShaderName, SHADER_NOMIP );
return re->RegisterShader( szShaderName, SHADER_GENERIC );
}
2009-12-07 22:00:00 +01:00
/*
=============
TriRenderMode
=============
*/
2009-01-22 22:00:00 +01:00
void TriRenderMode( kRenderMode_t mode )
{
2009-10-20 22:00:00 +02:00
if( !re ) return;
2009-12-07 22:00:00 +01:00
re->RenderMode( mode );
2009-01-22 22:00:00 +01:00
}
2009-12-07 22:00:00 +01:00
/*
=============
TriBind
bind current shader
=============
*/
2009-10-20 22:00:00 +02:00
void TriBind( shader_t shader, int frame )
2009-01-22 22:00:00 +01:00
{
2009-12-07 22:00:00 +01:00
if( !re ) return;
re->Bind( shader, frame );
2009-01-22 22:00:00 +01:00
}
2009-12-07 22:00:00 +01:00
/*
=============
TriBegin
begin triangle sequence
=============
*/
2009-01-22 22:00:00 +01:00
void TriBegin( TRI_DRAW mode )
{
2009-12-07 22:00:00 +01:00
if( re ) re->Begin( mode );
2009-01-22 22:00:00 +01:00
}
2009-12-07 22:00:00 +01:00
/*
=============
TriEnd
draw triangle sequence
=============
*/
2009-01-22 22:00:00 +01:00
void TriEnd( void )
{
2009-12-07 22:00:00 +01:00
if( re ) re->End();
2009-01-22 22:00:00 +01:00
}
2009-12-07 22:00:00 +01:00
/*
=============
TriEnable
=============
*/
2009-01-22 22:00:00 +01:00
void TriEnable( int cap )
{
2009-12-07 22:00:00 +01:00
if( !re ) return;
re->Enable( cap );
2009-01-22 22:00:00 +01:00
}
2009-12-07 22:00:00 +01:00
/*
=============
TriDisable
=============
*/
2009-01-22 22:00:00 +01:00
void TriDisable( int cap )
{
2009-12-07 22:00:00 +01:00
if( !re ) return;
re->Disable( cap );
2009-01-22 22:00:00 +01:00
}
2009-12-07 22:00:00 +01:00
/*
=============
TriVertex3f
=============
*/
2009-01-22 22:00:00 +01:00
void TriVertex3f( float x, float y, float z )
{
2009-12-07 22:00:00 +01:00
if( !re ) return;
re->Vertex3f( x, y, z );
2009-01-22 22:00:00 +01:00
}
2009-12-07 22:00:00 +01:00
/*
=============
TriVertex3fv
=============
*/
2009-10-20 22:00:00 +02:00
void TriVertex3fv( const float *v )
2009-01-22 22:00:00 +01:00
{
2009-12-07 22:00:00 +01:00
if( !re || !v ) return;
re->Vertex3f( v[0], v[1], v[2] );
2009-01-22 22:00:00 +01:00
}
2009-12-07 22:00:00 +01:00
/*
=============
TriNormal3f
=============
*/
2009-10-20 22:00:00 +02:00
void TriNormal3f( float x, float y, float z )
2009-01-22 22:00:00 +01:00
{
2009-12-07 22:00:00 +01:00
if( !re ) return;
re->Normal3f( x, y, z );
2009-01-22 22:00:00 +01:00
}
2009-12-07 22:00:00 +01:00
/*
=============
TriNormal3fv
=============
*/
2009-10-20 22:00:00 +02:00
void TriNormal3fv( const float *v )
2009-01-22 22:00:00 +01:00
{
2009-12-07 22:00:00 +01:00
if( !re || !v ) return;
re->Normal3f( v[0], v[1], v[2] );
2009-01-22 22:00:00 +01:00
}
2009-12-07 22:00:00 +01:00
/*
=============
TriColor4f
=============
*/
2009-01-22 22:00:00 +01:00
void TriColor4f( float r, float g, float b, float a )
{
2009-12-07 22:00:00 +01:00
rgba_t rgba;
if( !re ) return;
rgba[0] = (byte)bound( 0, r * 255, 255 );
rgba[1] = (byte)bound( 0, g * 255, 255 );
rgba[2] = (byte)bound( 0, b * 255, 255 );
rgba[3] = (byte)bound( 0, a * 255, 255 );
re->Color4ub( rgba[0], rgba[1], rgba[2], rgba[3] );
2009-01-22 22:00:00 +01:00
}
2009-12-07 22:00:00 +01:00
/*
=============
TriColor4ub
=============
*/
2009-01-22 22:00:00 +01:00
void TriColor4ub( byte r, byte g, byte b, byte a )
{
2009-12-07 22:00:00 +01:00
if( !re ) return;
re->Color4ub( r, g, b, a );
2009-01-22 22:00:00 +01:00
}
2009-12-07 22:00:00 +01:00
/*
=============
TriTexCoord2f
=============
*/
2009-01-22 22:00:00 +01:00
void TriTexCoord2f( float u, float v )
{
2009-12-07 22:00:00 +01:00
if( !re ) return;
re->TexCoord2f( u, v );
2009-01-22 22:00:00 +01:00
}
2009-12-07 22:00:00 +01:00
/*
=============
TriCullFace
=============
*/
2009-01-22 22:00:00 +01:00
void TriCullFace( TRI_CULL mode )
{
2009-12-07 22:00:00 +01:00
if( !re ) return;
re->CullFace( mode );
2009-01-22 22:00:00 +01:00
}
2009-12-07 22:00:00 +01:00
/*
=============
TriScreenToWorld
convert screen coordinates (x,y) into world (x, y, z)
=============
*/
2009-01-22 22:00:00 +01:00
void TriScreenToWorld( float *screen, float *world )
{
2009-10-20 22:00:00 +02:00
if( !re ) return;
re->ScreenToWorld( screen, world );
2009-01-22 22:00:00 +01:00
}
2009-12-07 22:00:00 +01:00
/*
=============
TriWorldToScreen
convert world coordinates (x,y,z) into screen (x, y)
=============
*/
2009-01-22 22:00:00 +01:00
int TriWorldToScreen( float *world, float *screen )
{
2009-10-20 22:00:00 +02:00
if( !re ) return 0;
return re->WorldToScreen( world, screen );
2009-01-22 22:00:00 +01:00
}
2009-12-07 22:00:00 +01:00
/*
=============
TriFog
enables global fog on the level
=============
*/
2009-01-22 22:00:00 +01:00
void TriFog( float flFogColor[3], float flStart, float flEnd, int bOn )
{
2009-12-07 22:00:00 +01:00
if( re ) re->Fog( flFogColor, flStart, flEnd, bOn );
2009-01-22 22:00:00 +01:00
}
2008-12-25 22:00:00 +01:00
static triapi_t gTriApi =
{
sizeof( triapi_t ),
2009-12-06 22:00:00 +01:00
TriLoadShader,
2009-01-22 22:00:00 +01:00
TriRenderMode,
TriBegin,
TriEnd,
TriEnable,
TriDisable,
TriVertex3f,
TriVertex3fv,
2009-10-20 22:00:00 +02:00
TriNormal3f,
TriNormal3fv,
2009-01-22 22:00:00 +01:00
TriColor4f,
TriColor4ub,
TriTexCoord2f,
2009-10-20 22:00:00 +02:00
TriBind,
2009-01-22 22:00:00 +01:00
TriCullFace,
TriScreenToWorld,
TriWorldToScreen,
TriFog
2008-12-25 22:00:00 +01:00
};
2009-01-11 22:00:00 +01:00
static efxapi_t gEfxApi =
{
sizeof( efxapi_t ),
2009-01-15 22:00:00 +01:00
pfnAddParticle,
pfnAddDecal,
pfnAddDLight,
pfnFindExplosionPlane,
2009-01-16 22:00:00 +01:00
pfnDecalIndexFromName,
pfnDecalIndex,
2009-01-11 22:00:00 +01:00
};
2009-12-05 22:00:00 +01:00
static event_api_t gEventApi =
{
sizeof( event_api_t ),
pfnPrecacheEvent,
pfnPlaybackEvent,
pfnWeaponAnim,
pfnRandomFloat,
pfnRandomLong,
pfnHookEvent,
pfnKillEvents,
};
2008-12-25 22:00:00 +01:00
// engine callbacks
static cl_enginefuncs_t gEngfuncs =
{
sizeof( cl_enginefuncs_t ),
2009-12-03 22:00:00 +01:00
pfnSPR_Load,
pfnSPR_Frames,
pfnSPR_Height,
pfnSPR_Width,
pfnSPR_Set,
pfnSPR_Draw,
pfnSPR_DrawHoles,
pfnSPR_DrawTrans,
pfnSPR_DrawAdditive,
pfnSPR_EnableScissor,
pfnSPR_DisableScissor,
pfnSPR_GetList,
pfnFillRGBA,
pfnGetScreenInfo,
pfnSetCrosshair,
2009-01-22 22:00:00 +01:00
pfnCVarRegister,
2009-12-04 22:00:00 +01:00
pfnCVarGetValue,
pfnCVarGetString,
2008-12-25 22:00:00 +01:00
pfnAddCommand,
pfnHookUserMsg,
pfnServerCmd,
pfnClientCmd,
pfnGetPlayerInfo,
2009-12-04 22:00:00 +01:00
pfnPlaySoundByName,
pfnPlaySoundByIndex,
AngleVectors,
2008-12-25 22:00:00 +01:00
pfnTextMessageGet,
2009-12-04 22:00:00 +01:00
pfnDrawCharacter,
pfnDrawConsoleString,
pfnDrawSetTextColor,
pfnDrawConsoleStringLen,
pfnConsolePrint,
pfnCenterPrint,
pfnMemAlloc,
pfnMemFree,
2009-12-05 22:00:00 +01:00
pfnGetViewAngles,
pfnSetViewAngles,
2009-12-04 22:00:00 +01:00
pfnCVarSetString,
pfnCVarSetValue,
2009-12-05 22:00:00 +01:00
pfnCmd_Argc,
pfnCmd_Argv,
pfnCmd_Args,
CL_GetLerpFrac,
2009-12-04 22:00:00 +01:00
pfnDelCommand,
2008-12-25 22:00:00 +01:00
pfnAlertMessage,
2009-12-05 22:00:00 +01:00
pfnPhysInfo_ValueForKey,
pfnServerInfo_ValueForKey,
pfnGetClientMaxspeed,
pfnGetModelPtr,
pfnGetBonePosition,
CL_AllocString,
CL_GetString,
CL_GetLocalPlayer,
pfnGetViewModel,
2009-01-03 22:00:00 +01:00
CL_GetEdictByIndex,
2008-12-25 22:00:00 +01:00
pfnGetClientTime,
2009-12-05 22:00:00 +01:00
pfnIsSpectateOnly,
2009-10-15 22:00:00 +02:00
pfnGetAttachment,
2008-12-25 22:00:00 +01:00
pfnPointContents,
2009-12-05 22:00:00 +01:00
pfnWaterEntity,
2008-12-25 22:00:00 +01:00
pfnTraceLine,
2009-01-11 22:00:00 +01:00
pfnTraceToss,
pfnTraceHull,
pfnTraceModel,
pfnTraceTexture,
2009-12-05 22:00:00 +01:00
pfnFOpen,
pfnFRead,
pfnFWrite,
pfnFClose,
pfnFGets,
pfnFSeek,
pfnFTell,
2009-11-23 22:00:00 +01:00
pfnLoadLibrary,
pfnGetProcAddress,
2009-12-05 22:00:00 +01:00
pfnFreeLibrary,
2008-12-25 22:00:00 +01:00
Host_Error,
2009-12-05 22:00:00 +01:00
pfnFileExists,
pfnRemoveFile,
VGui_GetPanel,
VGui_ViewportPaintBackground,
pfnLoadFile,
pfnParseToken,
pfnFreeFile,
2009-01-11 22:00:00 +01:00
&gTriApi,
2009-12-05 22:00:00 +01:00
&gEfxApi,
&gEventApi
2008-12-25 22:00:00 +01:00
};
void CL_UnloadProgs( void )
{
// initialize game
2009-06-24 22:00:00 +02:00
clgame.dllFuncs.pfnShutdown();
2008-12-25 22:00:00 +01:00
2009-10-18 22:00:00 +02:00
CL_FreeEdicts();
CL_FreeEdict( &clgame.viewent );
CL_FreeEdict( &clgame.playermodel );
2008-12-26 22:00:00 +01:00
StringTable_Delete( clgame.hStringTable );
2009-06-24 22:00:00 +02:00
Com_FreeLibrary( clgame.hInstance );
2008-12-25 22:00:00 +01:00
Mem_FreePool( &cls.mempool );
2009-11-27 22:00:00 +01:00
Mem_FreePool( &clgame.mempool );
2009-06-24 22:00:00 +02:00
Mem_FreePool( &clgame.private );
2008-12-25 22:00:00 +01:00
}
bool CL_LoadProgs( const char *name )
{
static CLIENTAPI GetClientAPI;
2009-09-28 22:00:00 +02:00
static cl_globalvars_t gpGlobals;
2009-11-26 22:00:00 +01:00
static playermove_t gpMove;
2009-01-21 22:00:00 +01:00
string libpath;
2008-12-25 22:00:00 +01:00
2009-06-24 22:00:00 +02:00
if( clgame.hInstance ) CL_UnloadProgs();
2008-12-25 22:00:00 +01:00
2009-10-20 22:00:00 +02:00
// setup globals
2009-09-28 22:00:00 +02:00
clgame.globals = &gpGlobals;
2009-10-20 22:00:00 +02:00
// initialize TriAPI
2009-11-26 22:00:00 +01:00
clgame.pmove = &gpMove;
2009-12-07 22:00:00 +01:00
2009-01-21 22:00:00 +01:00
Com_BuildPath( name, libpath );
2009-11-27 22:00:00 +01:00
cls.mempool = Mem_AllocPool( "Client Static Pool" );
clgame.mempool = Mem_AllocPool( "Client Edicts Zone" );
2009-06-24 22:00:00 +02:00
clgame.private = Mem_AllocPool( "Client Private Zone" );
2009-11-28 22:00:00 +01:00
clgame.baselines = NULL;
2009-11-27 22:00:00 +01:00
clgame.edicts = NULL;
2008-12-25 22:00:00 +01:00
2009-06-24 22:00:00 +02:00
clgame.hInstance = Com_LoadLibrary( libpath );
if( !clgame.hInstance ) return false;
2008-12-25 22:00:00 +01:00
2009-06-24 22:00:00 +02:00
GetClientAPI = (CLIENTAPI)Com_GetProcAddress( clgame.hInstance, "CreateAPI" );
2008-12-25 22:00:00 +01:00
if( !GetClientAPI )
{
MsgDev( D_ERROR, "CL_LoadProgs: failed to get address of CreateAPI proc\n" );
return false;
}
2009-09-28 22:00:00 +02:00
if( !GetClientAPI( &clgame.dllFuncs, &gEngfuncs, clgame.globals ))
2008-12-25 22:00:00 +01:00
{
MsgDev( D_ERROR, "CL_LoadProgs: can't init client API\n" );
return false;
}
// 65535 unique strings should be enough ...
2009-01-02 22:00:00 +01:00
clgame.hStringTable = StringTable_Create( "Client", 0x10000 );
2009-11-27 22:00:00 +01:00
clgame.globals->maxEntities = GI->max_edicts; // merge during loading
2008-12-26 22:00:00 +01:00
// register svc_bad message
pfnHookUserMsg( "bad", NULL );
CL_LinkUserMessage( "bad@0", svc_bad );
2009-10-18 22:00:00 +02:00
CL_InitEdict( &clgame.viewent );
clgame.viewent.serialnumber = VIEWENT_INDEX;
CL_InitEdict( &clgame.playermodel );
2009-10-22 22:00:00 +02:00
clgame.playermodel.serialnumber = MAX_EDICTS - 1;
2009-10-18 22:00:00 +02:00
2009-10-23 22:00:00 +02:00
CL_InitTitles( "scripts/titles.txt" );
2008-12-25 22:00:00 +01:00
// initialize game
2009-06-24 22:00:00 +02:00
clgame.dllFuncs.pfnInit();
2008-12-25 22:00:00 +01:00
2009-12-05 22:00:00 +01:00
// initialize pm_shared
CL_InitClientMove();
2008-12-25 22:00:00 +01:00
return true;
}