Improve client

This commit is contained in:
mittorn 2016-03-01 20:18:42 +00:00
parent 06d38e3feb
commit d254f1bd0e
15 changed files with 148 additions and 104 deletions

1
Android.mk Normal file
View File

@ -0,0 +1 @@
include $(call all-subdir-makefiles)

View File

@ -90,8 +90,9 @@ int CHudMOTD :: Draw( float fTime )
gHUD.DrawDarkRectangle(xpos-5, ypos_r - 5, xmax - xpos+10, height + 10);
while ( *ch )
{
char *next_line;
int line_length = 0; // count the length of the current line
for ( char *next_line = ch; *next_line != '\n' && *next_line != 0; next_line++ )
for ( next_line = ch; *next_line != '\n' && *next_line != 0; next_line++ )
line_length += gHUD.m_scrinfo.charWidths[ *next_line ];
char *top = next_line;
if ( *top == '\n' )

View File

@ -108,7 +108,7 @@ void WeaponsResource :: LoadWeaponSprites( WEAPON *pWeapon )
pWeapon->rcCrosshair = p->rc;
}
else
pWeapon->hCrosshair = NULL;
pWeapon->hCrosshair = 0;
p = GetSpriteList(pList, "autoaim", iRes, i);
if (p)

View File

@ -82,8 +82,15 @@ inline struct cvar_s *CVAR_CREATE( const char *cv, const char *val, const int fl
#define ClientCmd (*gEngfuncs.pfnClientCmd)
#define SetCrosshair (*gEngfuncs.pfnSetCrosshair)
#define AngleVectors (*gEngfuncs.pfnAngleVectors)
extern cvar_t *hud_textmode;
extern float g_hud_text_color[3];
inline int DrawSetTextColor(float r, float g, float b)
{
if( hud_textmode->value == 1 )
g_hud_text_color[0]=r, g_hud_text_color[1] = g, g_hud_text_color[2] = b;
else
gEngfuncs.pfnDrawSetTextColor( r, g, b );
}
// Gets the height & width of a sprite, at the specified frame
inline int SPR_Height( HSPRITE x, int f ) { return gEngfuncs.pfnSPR_Height(x, f); }
inline int SPR_Width( HSPRITE x, int f ) { return gEngfuncs.pfnSPR_Width(x, f); }
@ -96,17 +103,24 @@ inline int TextMessageDrawChar( int x, int y, int number, int r, int g, in
inline int DrawConsoleString( int x, int y, const char *string )
{
if( hud_textmode->value == 1 )
return gHUD.DrawHudString( x, y, 9999, (char*)string, 255*g_hud_text_color[0], 255*g_hud_text_color[1], 255*g_hud_text_color[2]);
return gEngfuncs.pfnDrawConsoleString( x, y, (char*) string );
}
inline void GetConsoleStringSize( const char *string, int *width, int *height )
{
gEngfuncs.pfnDrawConsoleStringLen( string, width, height );
if( hud_textmode->value == 1 )
*height = 13, *width = gHUD.DrawHudStringLen(string);
else
gEngfuncs.pfnDrawConsoleStringLen( (char*)string, width, height );
}
inline int ConsoleStringLen( const char *string )
{
int _width, _height;
int _width = 0, _height = 0;
if( hud_textmode->value == 1 )
return gHUD.DrawHudStringLen((char*)string);
GetConsoleStringSize( string, &_width, &_height );
return _width;
}

View File

@ -125,7 +125,7 @@ int CHudDeathNotice :: Draw( float flTime )
// Draw killers name
if ( rgDeathNoticeList[i].KillerColor )
gEngfuncs.pfnDrawSetTextColor( rgDeathNoticeList[i].KillerColor[0], rgDeathNoticeList[i].KillerColor[1], rgDeathNoticeList[i].KillerColor[2] );
DrawSetTextColor( rgDeathNoticeList[i].KillerColor[0], rgDeathNoticeList[i].KillerColor[1], rgDeathNoticeList[i].KillerColor[2] );
x = 5 + DrawConsoleString( x, y, rgDeathNoticeList[i].szKiller );
}
@ -145,7 +145,7 @@ int CHudDeathNotice :: Draw( float flTime )
if (rgDeathNoticeList[i].iNonPlayerKill == FALSE)
{
if ( rgDeathNoticeList[i].VictimColor )
gEngfuncs.pfnDrawSetTextColor( rgDeathNoticeList[i].VictimColor[0], rgDeathNoticeList[i].VictimColor[1], rgDeathNoticeList[i].VictimColor[2] );
DrawSetTextColor( rgDeathNoticeList[i].VictimColor[0], rgDeathNoticeList[i].VictimColor[1], rgDeathNoticeList[i].VictimColor[2] );
x = DrawConsoleString( x, y, rgDeathNoticeList[i].szVictim );
}
}
@ -279,7 +279,7 @@ int CHudDeathNotice :: MsgFunc_DeathMsg( const char *pszName, int iSize, void *p
ConsolePrint( rgDeathNoticeList[i].szVictim );
}
if ( killedwith && *killedwith && (*killedwith > 13 ) && strcmp( killedwith, "d_world" ) && !rgDeathNoticeList[i].iTeamKill )
if ( *killedwith && (*killedwith > 13 ) && strcmp( killedwith, "d_world" ) && !rgDeathNoticeList[i].iTeamKill )
{
ConsolePrint( " with " );

View File

@ -579,6 +579,12 @@ void CBasePlayerWeapon::PrintState( void )
COM_Log( "c:\\hl.log", "%i ", m_iClip );
}
int RandomLong( int a, int b )
{
return gEngfuncs.pfnRandomLong(a, b);
}
/*
=====================
HUD_InitClientWeapons
@ -615,7 +621,7 @@ void HUD_InitClientWeapons( void )
// Pass through to engine
g_engfuncs.pfnPrecacheEvent = gEngfuncs.pfnPrecacheEvent;
g_engfuncs.pfnRandomFloat = gEngfuncs.pfnRandomFloat;
g_engfuncs.pfnRandomLong = gEngfuncs.pfnRandomLong;
g_engfuncs.pfnRandomLong = RandomLong;
// Allocate a slot for the local player
HUD_PrepEntity( &player , NULL );

View File

@ -29,7 +29,8 @@
#include "demo.h"
#include "demo_api.h"
cvar_t *hud_textmode;
float g_hud_text_color[3];
extern client_sprite_t *GetSpriteList(client_sprite_t *pList, const char *psz, int iRes, int iCount);
@ -186,7 +187,7 @@ void CHud :: Init( void )
CVAR_CREATE( "hud_classautokill", "1", FCVAR_ARCHIVE | FCVAR_USERINFO ); // controls whether or not to suicide immediately on TF class switch
CVAR_CREATE( "hud_takesshots", "0", FCVAR_ARCHIVE ); // controls whether or not to automatically take screenshots at the end of a round
hud_textmode = CVAR_CREATE ( "hud_textmode", "0", FCVAR_ARCHIVE );
m_iLogo = 0;
m_iFOV = 0;

View File

@ -610,6 +610,7 @@ public:
int DrawHudStringReverse( int xpos, int ypos, int iMinX, char *szString, int r, int g, int b );
int DrawHudNumberString( int xpos, int ypos, int iMinX, int iNumber, int r, int g, int b );
int GetNumWidth(int iNumber, int iFlags);
int DrawHudStringLen( char *szIt );
void DrawDarkRectangle( int x, int y, int wide, int tall);
private:

View File

@ -18,7 +18,7 @@
#include <math.h>
#include "hud.h"
#include "cl_util.h"
#include "triangleapi.h"
//#include "triangleapi.h"
#define MAX_LOGO_FRAMES 56
@ -182,22 +182,58 @@ void ScaleColors( int &r, int &g, int &b, int a )
b = (int)(b * x);
}
const unsigned char colors[8][3] =
{
{127, 127, 127}, // additive cannot be black
{255, 0, 0},
{ 0, 255, 0},
{255, 255, 0},
{ 0, 0, 255},
{ 0, 255, 255},
{255, 0, 255},
{240, 180, 24}
};
int CHud :: DrawHudString(int xpos, int ypos, int iMaxX, char *szIt, int r, int g, int b )
{
if( hud_textmode->value == 2 )
{
gEngfuncs.pfnDrawSetTextColor( r/255.0, g/255.0, b/255.0 );
return gEngfuncs.pfnDrawConsoleString( xpos, ypos, (char*) szIt );
}
// draw the string until we hit the null character or a newline character
for ( ; *szIt != 0 && *szIt != '\n'; szIt++ )
{
int next = xpos + gHUD.m_scrinfo.charWidths[ *szIt ]; // variable-width fonts look cool
if ( next > iMaxX )
int w = gHUD.m_scrinfo.charWidths[ 'M' ];
if ( xpos + w > iMaxX )
return xpos;
if( *szIt == '^' && *(szIt + 1) >= '0' && *(szIt + 1) <= '7' )
{
szIt++;
r = colors[ *szIt - '0' ][0];
g = colors[ *szIt - '0' ][1];
b = colors[ *szIt - '0' ][2];
if( !*(++szIt))
return xpos;
}
TextMessageDrawChar( xpos, ypos, *szIt, r, g, b );
xpos = next;
xpos += TextMessageDrawChar( xpos, ypos, *szIt, r, g, b );
}
return xpos;
}
int CHud :: DrawHudStringLen( char *szIt )
{
int l = 0;
for ( ; *szIt != 0 && *szIt != '\n'; szIt++ )
{
l += gHUD.m_scrinfo.charWidths[ (unsigned int)*szIt ];
}
return l;
}
int CHud :: DrawHudNumberString( int xpos, int ypos, int iMinX, int iNumber, int r, int g, int b )
{
char szString[32];
@ -210,21 +246,11 @@ int CHud :: DrawHudNumberString( int xpos, int ypos, int iMinX, int iNumber, int
int CHud :: DrawHudStringReverse( int xpos, int ypos, int iMinX, char *szString, int r, int g, int b )
{
// find the end of the string
for ( char *szIt = szString; *szIt != 0; szIt++ )
{ // we should count the length?
}
// iterate throug the string in reverse
for ( szIt--; szIt != (szString-1); szIt-- )
{
int next = xpos - gHUD.m_scrinfo.charWidths[ *szIt ]; // variable-width fonts look cool
if ( next < iMinX )
return xpos;
xpos = next;
TextMessageDrawChar( xpos, ypos, *szIt, r, g, b );
}
for( char *szIt = szString; *szIt != 0; szIt++ )
xpos -= gHUD.m_scrinfo.charWidths[ (unsigned char) *szIt ];
if( xpos < iMinX )
xpos = iMinX;
DrawHudString( xpos, ypos, gHUD.m_scrinfo.iWidth, szString, r, g, b );
return xpos;
}
@ -325,16 +351,8 @@ int CHud::GetNumWidth( int iNumber, int iFlags )
void CHud::DrawDarkRectangle( int x, int y, int wide, int tall )
{
FillRGBA( x, y, wide, tall, 0, 0, 0, 0 );
float m_flScale = 1;
gEngfuncs.pTriAPI->RenderMode( kRenderTransTexture );
gEngfuncs.pTriAPI->Begin(TRI_QUADS);
gEngfuncs.pTriAPI->Color4f(0.0, 0.0, 0.0, 0.6);
gEngfuncs.pTriAPI->Vertex3f(x * m_flScale, (y+tall)*m_flScale, 0);
gEngfuncs.pTriAPI->Vertex3f(x * m_flScale, y*m_flScale, 0);
gEngfuncs.pTriAPI->Vertex3f((x + wide)*m_flScale, y*m_flScale, 0);
gEngfuncs.pTriAPI->Vertex3f((x + wide)*m_flScale, (y+tall)*m_flScale, 0);
gEngfuncs.pTriAPI->End();
//gEngfuncs.pTriAPI->RenderMode( kRenderTransTexture );
gEngfuncs.pfnFillRGBABlend( x, y, wide, tall, 0, 0, 0, 255 * 0.6 );
FillRGBA( x+1, y, wide-1, 1, 255, 140, 0, 255 );
FillRGBA( x, y, 1, tall-1, 255, 140, 0, 255 );
FillRGBA( x+wide-1, y+1, 1, tall-1, 255, 140, 0, 255 );

View File

@ -434,7 +434,7 @@ int CHudSpectator::Draw(float flTime)
lx = strlen(string)*3; // 3 is avg. character length :)
gEngfuncs.pfnDrawSetTextColor( color[0], color[1], color[2] );
DrawSetTextColor( color[0], color[1], color[2] );
DrawConsoleString( m_vPlayerPos[i][0]-lx,m_vPlayerPos[i][1], string);
}

View File

@ -94,7 +94,7 @@ float MoveToward( float cur, float goal, float maxspeed )
{
if( cur != goal )
{
if( abs( cur - goal ) > 180.0 )
if( fabs( cur - goal ) > 180.0 )
{
if( cur < goal )
cur += 360.0;
@ -376,7 +376,7 @@ void DLLEXPORT CAM_Think( void )
if( camAngles[ PITCH ] - viewangles[ PITCH ] != cam_idealpitch->value )
camAngles[ PITCH ] = MoveToward( camAngles[ PITCH ], cam_idealpitch->value + viewangles[ PITCH ], CAM_ANGLE_SPEED );
if( abs( camAngles[ 2 ] - cam_idealdist->value ) < 2.0 )
if( fabs( camAngles[ 2 ] - cam_idealdist->value ) < 2.0 )
camAngles[ 2 ] = cam_idealdist->value;
else
camAngles[ 2 ] += ( cam_idealdist->value - camAngles[ 2 ] ) / 4.0;

View File

@ -44,12 +44,12 @@ int ac_movecount;
float rel_yaw;
float rel_pitch;
#define F 1<<0 // Forward
#define B 1<<1 // Back
#define L 1<<2 // Left
#define R 1<<3 // Right
#define T 1<<4 // Forward stop
#define S 1<<5 // Side stop
#define F 1U<<0 // Forward
#define B 1U<<1 // Back
#define L 1U<<2 // Left
#define R 1U<<3 // Right
#define T 1U<<4 // Forward stop
#define S 1U<<5 // Side stop
#define BUTTON_DOWN 1
#define IMPULSE_DOWN 2
@ -58,7 +58,7 @@ float rel_pitch;
void IN_ToggleButtons( float forwardmove, float sidemove )
{
static uint moveflags = T | S;
static unsigned int moveflags = T | S;
if( forwardmove )
moveflags &= ~T;
@ -180,7 +180,7 @@ void IN_Move( float frametime, usercmd_t *cmd )
viewangles[YAW] += rel_yaw;
if( fLadder )
{
if( ( cl_laddermode->value == 1 ) )
if( cl_laddermode->value == 1 )
viewangles[YAW] -= ac_sidemove * 5;
ac_sidemove = 0;
}

View File

@ -130,7 +130,7 @@ int CHudSayText :: Draw( float flTime )
// draw the first x characters in the player color
strncpy( buf, g_szLineBuffer[i], min(g_iNameLengths[i], MAX_PLAYER_NAME_LENGTH+32) );
buf[ min(g_iNameLengths[i], MAX_PLAYER_NAME_LENGTH+31) ] = 0;
gEngfuncs.pfnDrawSetTextColor( g_pflNameColors[i][0], g_pflNameColors[i][1], g_pflNameColors[i][2] );
DrawSetTextColor( g_pflNameColors[i][0], g_pflNameColors[i][1], g_pflNameColors[i][2] );
int x = DrawConsoleString( LINE_START, y, buf );
// color is reset after each string draw

View File

@ -113,7 +113,7 @@ int SCOREBOARD_WIDTH = 320;
int CHudScoreboard :: Draw( float fTime )
{
int can_show_packetloss = 0;
int i, j, can_show_packetloss = 0;
int FAR_RIGHT;
gHUD.m_iNoConsolePrint &= ~( 1 << 0 );
@ -178,7 +178,7 @@ int CHudScoreboard :: Draw( float fTime )
}
// clear out team scores
for ( int i = 1; i <= m_iNumTeams; i++ )
for ( i = 1; i <= m_iNumTeams; i++ )
{
if ( !g_TeamInfo[i].scores_overriden )
g_TeamInfo[i].frags = g_TeamInfo[i].deaths = 0;
@ -195,7 +195,7 @@ int CHudScoreboard :: Draw( float fTime )
continue; // skip over players who are not in a team
// find what team this player is in
for ( int j = 1; j <= m_iNumTeams; j++ )
for ( j = 1; j <= m_iNumTeams; j++ )
{
if ( !stricmp( g_PlayerExtraInfo[i].teamname, g_TeamInfo[j].name ) )
break;
@ -485,6 +485,7 @@ int CHudScoreboard :: MsgFunc_ScoreInfo( const char *pszName, int iSize, void *p
// string: client team name
int CHudScoreboard :: MsgFunc_TeamInfo( const char *pszName, int iSize, void *pbuf )
{
int i, j;
BEGIN_READ( pbuf, iSize );
short cl = READ_BYTE();
@ -496,7 +497,7 @@ int CHudScoreboard :: MsgFunc_TeamInfo( const char *pszName, int iSize, void *pb
// rebuild the list of teams
// clear out player counts from teams
for ( int i = 1; i <= m_iNumTeams; i++ )
for ( i = 1; i <= m_iNumTeams; i++ )
{
g_TeamInfo[i].players = 0;
}
@ -513,7 +514,7 @@ int CHudScoreboard :: MsgFunc_TeamInfo( const char *pszName, int iSize, void *pb
continue; // skip over players who are not in a team
// is this player in an existing team?
for ( int j = 1; j <= m_iNumTeams; j++ )
for ( j = 1; j <= m_iNumTeams; j++ )
{
if ( g_TeamInfo[j].name[0] == '\0' )
break;
@ -559,9 +560,10 @@ int CHudScoreboard :: MsgFunc_TeamScore( const char *pszName, int iSize, void *p
{
BEGIN_READ( pbuf, iSize );
char *TeamName = READ_STRING();
int i;
// find the team matching the name
for ( int i = 1; i <= m_iNumTeams; i++ )
for ( i = 1; i <= m_iNumTeams; i++ )
{
if ( !stricmp( TeamName, g_TeamInfo[i].name ) )
break;

View File

@ -203,7 +203,7 @@ int CHudStatusBar :: Draw( float fTime )
}
if ( m_pflNameColors[i] )
gEngfuncs.pfnDrawSetTextColor( m_pflNameColors[i][0], m_pflNameColors[i][1], m_pflNameColors[i][2] );
DrawSetTextColor( m_pflNameColors[i][0], m_pflNameColors[i][1], m_pflNameColors[i][2] );
DrawConsoleString( x, y, m_szStatusBar[i] );
}