Browse Source

Rework scope code.

poke646
Andrey Akhmichin 5 years ago
parent
commit
81e2eac904
  1. 2
      cl_dll/entity.cpp
  2. 2
      cl_dll/hud.cpp
  3. 5
      cl_dll/hud.h
  4. 2
      cl_dll/hud_redraw.cpp
  5. 384
      cl_dll/poke646/scope.cpp

2
cl_dll/entity.cpp

@ -96,7 +96,7 @@ void DLLEXPORT HUD_TxferLocalOverrides( struct entity_state_s *state, const stru
// Fire prevention // Fire prevention
state->iuser4 = client->iuser4; state->iuser4 = client->iuser4;
bDrawScope = client->iuser4; // bDrawScope = client->iuser4;
} }
/* /*

2
cl_dll/hud.cpp

@ -36,6 +36,7 @@ extern client_sprite_t *GetSpriteList( client_sprite_t *pList, const char *psz,
extern cvar_t *sensitivity; extern cvar_t *sensitivity;
cvar_t *cl_lw = NULL; cvar_t *cl_lw = NULL;
cvar_t *cl_viewbob = NULL; cvar_t *cl_viewbob = NULL;
cvar_t *adjust_fov = NULL;
void ShutdownInput( void ); void ShutdownInput( void );
@ -220,6 +221,7 @@ void CHud::Init( void )
m_pCvarDraw = CVAR_CREATE( "hud_draw", "1", FCVAR_ARCHIVE ); m_pCvarDraw = CVAR_CREATE( "hud_draw", "1", FCVAR_ARCHIVE );
cl_lw = gEngfuncs.pfnGetCvarPointer( "cl_lw" ); cl_lw = gEngfuncs.pfnGetCvarPointer( "cl_lw" );
cl_viewbob = CVAR_CREATE( "cl_viewbob", "0", FCVAR_ARCHIVE ); cl_viewbob = CVAR_CREATE( "cl_viewbob", "0", FCVAR_ARCHIVE );
adjust_fov = gEngfuncs.pfnGetCvarPointer( "r_adjust_fov" ); // Xash3D widescreen fix
m_pSpriteList = NULL; m_pSpriteList = NULL;

5
cl_dll/hud.h

@ -567,9 +567,12 @@ class CHudScope
{ {
public: public:
int DrawScope( void ); int DrawScope( void );
int DrawText( void );
private: private:
HSPRITE m_hSprite; struct model_s *m_hSpriteModel;
HSPRITE m_hSprite;
char m_szDist[16];
}; };
// //

2
cl_dll/hud_redraw.cpp

@ -178,6 +178,8 @@ int CHud::Redraw( float flTime, int intermission )
} }
*/ */
gHUD.m_Scope.DrawText();
return 1; return 1;
} }

384
cl_dll/poke646/scope.cpp

@ -26,271 +26,179 @@
#include "pm_shared.h" #include "pm_shared.h"
#include "pm_defs.h" #include "pm_defs.h"
#include "pmtrace.h" #include "pmtrace.h"
extern bool bDrawScope; extern bool bDrawScope;
extern vec3_t v_origin; // last view origin extern vec3_t v_origin; // last view origin
extern vec3_t v_angles; // last view angle extern vec3_t v_angles; // last view angle
extern vec3_t v_cl_angles; // last client/mouse angle extern vec3_t v_cl_angles; // last client/mouse angle
extern vec3_t v_sim_org; // last sim origin extern vec3_t v_sim_org; // last sim origin
extern cvar_t *adjust_fov;
int CHudScope::DrawScope() int CHudScope::DrawScope()
{ {
vec3_t angles, forward, right, up;
vec3_t dir, delta, vert;
int frame;
float flDist, x, y;
pmtrace_t *trace;
if( !bDrawScope ) if( !bDrawScope )
return 1; return 1;
if (!m_hSprite) if( !m_hSprite )
m_hSprite = SPR_Load("sprites/scopeborder.spr"); {
m_hSprite = SPR_Load( "sprites/scopeborder.spr" );
int halfScopeHeight = ScreenHeight / 2; m_hSpriteModel = (struct model_s *)gEngfuncs.GetSpritePointer( m_hSprite );
int halfScopeWidth = halfScopeHeight; }
int x, y;
struct model_s* hSpriteModel = (struct model_s *)gEngfuncs.GetSpritePointer(m_hSprite);
gEngfuncs.pTriAPI->RenderMode(kRenderTransTexture); //additive
//
// Top left Half scope.
//
x = ScreenWidth / 2 - halfScopeWidth;
y = 0;
gEngfuncs.pTriAPI->SpriteTexture(hSpriteModel, 0);
gEngfuncs.pTriAPI->Color4f( 1.0, 1.0, 1.0, 1.0 );
gEngfuncs.pTriAPI->CullFace(TRI_NONE);
gEngfuncs.pTriAPI->Begin(TRI_QUADS);
//top left
gEngfuncs.pTriAPI->TexCoord2f(0.3f, 0.3f); // 0 0
gEngfuncs.pTriAPI->Vertex3f(x, y, 0);
//bottom left
gEngfuncs.pTriAPI->TexCoord2f(0.3f, 1.0f); // 0 1
gEngfuncs.pTriAPI->Vertex3f(x, y + halfScopeHeight, 0);
//bottom right
gEngfuncs.pTriAPI->TexCoord2f(1.0f, 1.0f); // 1 1
gEngfuncs.pTriAPI->Vertex3f(x + halfScopeWidth, y + halfScopeHeight, 0);
//top right
gEngfuncs.pTriAPI->TexCoord2f(1.0f, 0.3f); // 1 0
gEngfuncs.pTriAPI->Vertex3f(x + halfScopeWidth, y, 0);
gEngfuncs.pTriAPI->End();
//
// Top right Half scope.
//
x = ScreenWidth / 2;
y = 0;
gEngfuncs.pTriAPI->SpriteTexture(hSpriteModel, 1);
gEngfuncs.pTriAPI->CullFace(TRI_NONE);
gEngfuncs.pTriAPI->Begin(TRI_QUADS);
//top left
gEngfuncs.pTriAPI->TexCoord2f(0.0f, 0.3f);
gEngfuncs.pTriAPI->Vertex3f(x, y, 0);
//bottom left
gEngfuncs.pTriAPI->TexCoord2f(0.0f, 1.0f);
gEngfuncs.pTriAPI->Vertex3f(x, y + halfScopeHeight, 0);
//bottom right
gEngfuncs.pTriAPI->TexCoord2f(0.7f, 1.0f);
gEngfuncs.pTriAPI->Vertex3f(x + halfScopeWidth, y + halfScopeHeight, 0);
//top right
gEngfuncs.pTriAPI->TexCoord2f(0.7f, 0.3f);
gEngfuncs.pTriAPI->Vertex3f(x + halfScopeWidth, y, 0);
gEngfuncs.pTriAPI->End();
//
// Bottom left Half scope.
//
x = ScreenWidth / 2 - halfScopeWidth;
y = ScreenHeight / 2;
gEngfuncs.pTriAPI->SpriteTexture(hSpriteModel, 2);
gEngfuncs.pTriAPI->CullFace(TRI_NONE);
gEngfuncs.pTriAPI->Begin(TRI_QUADS);
//top left
gEngfuncs.pTriAPI->TexCoord2f(0.3f, 0.0f);
gEngfuncs.pTriAPI->Vertex3f(x, y, 0);
//bottom left
gEngfuncs.pTriAPI->TexCoord2f(0.3f, 0.7f);
gEngfuncs.pTriAPI->Vertex3f(x, y + halfScopeHeight, 0);
//bottom right
gEngfuncs.pTriAPI->TexCoord2f(1.0f, 0.7f);
gEngfuncs.pTriAPI->Vertex3f(x + halfScopeWidth, y + halfScopeHeight, 0);
//top right
gEngfuncs.pTriAPI->TexCoord2f(1.0f, 0.0f);
gEngfuncs.pTriAPI->Vertex3f(x + halfScopeWidth, y, 0);
gEngfuncs.pTriAPI->End();
//
// Bottom right Half scope.
//
x = ScreenWidth / 2;
y = ScreenHeight / 2;
gEngfuncs.pTriAPI->SpriteTexture(hSpriteModel, 3);
gEngfuncs.pTriAPI->CullFace(TRI_NONE);
gEngfuncs.pTriAPI->Begin(TRI_QUADS);
//top left
gEngfuncs.pTriAPI->TexCoord2f(0.0f, 0.0f);
gEngfuncs.pTriAPI->Vertex3f(x, y, 0);
//bottom left
gEngfuncs.pTriAPI->TexCoord2f(0.0f, 0.7f);
gEngfuncs.pTriAPI->Vertex3f(x, y + halfScopeHeight, 0);
//bottom right
gEngfuncs.pTriAPI->TexCoord2f(0.7f, 0.7f);
gEngfuncs.pTriAPI->Vertex3f(x + halfScopeWidth, y + halfScopeHeight, 0);
//top right
gEngfuncs.pTriAPI->TexCoord2f(0.7f, 0.0f);
gEngfuncs.pTriAPI->Vertex3f(x + halfScopeWidth, y, 0);
gEngfuncs.pTriAPI->End();
gEngfuncs.pTriAPI->RenderMode(kRenderNormal); // normal
gEngfuncs.pTriAPI->Color4f(1.0, 0.0, 0.0, 1.0);
int w = ScreenWidth / 2 - halfScopeWidth + 5;
//
// Left black bar
//
gEngfuncs.pTriAPI->SpriteTexture(hSpriteModel, 0);
gEngfuncs.pTriAPI->CullFace(TRI_NONE);
gEngfuncs.pTriAPI->Begin(TRI_QUADS);
//top left
gEngfuncs.pTriAPI->TexCoord2f(0.0f, 0.0f);
gEngfuncs.pTriAPI->Vertex3f(0, 0, 0);
//bottom left
gEngfuncs.pTriAPI->TexCoord2f(0.0f, 1.0f);
gEngfuncs.pTriAPI->Vertex3f(0, ScreenHeight, 0);
//bottom right
gEngfuncs.pTriAPI->TexCoord2f(1.0f, 1.0f);
gEngfuncs.pTriAPI->Vertex3f(w, ScreenHeight, 0);
//top right
gEngfuncs.pTriAPI->TexCoord2f(1.0f, 0.0f);
gEngfuncs.pTriAPI->Vertex3f(w, 0, 0);
gEngfuncs.pTriAPI->End();
x = ScreenWidth / 2 + halfScopeWidth - 5;
//
// Right black bar
//
gEngfuncs.pTriAPI->CullFace(TRI_NONE);
gEngfuncs.pTriAPI->Begin(TRI_QUADS);
gEngfuncs.pTriAPI->Color4f(0.0, 1.0, 0.0, 1.0);
//top left
gEngfuncs.pTriAPI->TexCoord2f(0.0f, 0.0f);
gEngfuncs.pTriAPI->Vertex3f(x, 0, 0);
//bottom left
gEngfuncs.pTriAPI->TexCoord2f(0.0f, 1.0f);
gEngfuncs.pTriAPI->Vertex3f(x, ScreenHeight, 0);
//bottom right
gEngfuncs.pTriAPI->TexCoord2f(1.0f, 1.0f);
gEngfuncs.pTriAPI->Vertex3f(ScreenWidth, ScreenHeight, 0);
//top right
gEngfuncs.pTriAPI->TexCoord2f(1.0f, 0.0f);
gEngfuncs.pTriAPI->Vertex3f(ScreenWidth, 0, 0);
gEngfuncs.pTriAPI->End();
gEngfuncs.pTriAPI->RenderMode(kRenderNormal); //return to normal
vec3_t forward; gEngfuncs.GetViewAngles( angles );
AngleVectors(v_angles, forward, NULL, NULL); AngleVectors( angles, forward, right, up );
VectorScale(forward, 1024, forward);
VectorAdd(forward, v_origin, forward);
pmtrace_t * trace = gEngfuncs.PM_TraceLine(v_origin, forward, PM_TRACELINE_PHYSENTSONLY, 2, -1);
float dist = (trace->endpos - v_origin).Length(); VectorMA( v_origin, 8192.0f, forward, dir );
float meters = dist * 0.021527f; // Convert hammer units to meters.
trace = gEngfuncs.PM_TraceLine( v_origin, dir, PM_TRACELINE_PHYSENTSONLY, 2, -1 );
VectorSubtract( trace->endpos, v_origin, delta );
char szDistance[16]; flDist = Length( delta );
sprintf(szDistance, "%.2f m", meters);
int len = strlen(szDistance); if( flDist >= 118.0f )
sprintf( m_szDist, "%.2f m", flDist * 0.0254f );
else
strcpy( m_szDist, "-.-- m" );
int x1, y1; x = tan( gHUD.m_iFOV * 0.008726646259971648 ) * 11.0;
x = ScreenWidth / 2 + ((float)halfScopeWidth * 0.7f); y = x * 0.00390625;
y = ScreenHeight / 2 - ((float)halfScopeHeight * 0.0625f);
x1 = x + 1; gEngfuncs.pTriAPI->RenderMode( kRenderTransTexture ); //additive
y1 = y + 1; gEngfuncs.pTriAPI->CullFace( TRI_NONE );
char c; if( adjust_fov && adjust_fov->value )
int i; VectorMA( v_origin, 8.0f, forward, dir );
int r, g, b; else
VectorMA( v_origin, 10.0f, forward, dir );
r = g = b = 15; frame = 0;
for (i = 0; i < len; i++) while( true )
{ {
TextMessageDrawChar(x1, y1, szDistance[i], r, g, b); if( !gEngfuncs.pTriAPI->SpriteTexture( m_hSpriteModel, frame ) )
break;
c = szDistance[i];
x1 += gHUD.m_scrinfo.charWidths[c]; gEngfuncs.pTriAPI->Color4f( 1.0f, 1.0f, 1.0f, 1.0f );
gEngfuncs.pTriAPI->Begin( TRI_QUADS );
gEngfuncs.pTriAPI->Brightness( 1.0f );
gEngfuncs.pTriAPI->TexCoord2f( 0.0f, 1.0f );
switch( frame )
{
case 0:
VectorMA( dir, -x, right, vert );
break;
case 1:
VectorCopy( dir, vert );
break;
case 2:
VectorMA( dir, -x, up, vert );
VectorMA( vert, -x, right, vert );
break;
case 3:
VectorMA( dir, -x, up, vert );
break;
}
gEngfuncs.pTriAPI->Vertex3fv( vert );
gEngfuncs.pTriAPI->Brightness( 1.0f );
gEngfuncs.pTriAPI->TexCoord2f( 0.0f, 0.0f );
switch( frame )
{
case 0:
VectorMA( dir, x, up, vert );
VectorMA( vert, -x, right, vert );
break;
case 1:
VectorMA( dir, x, up, vert );
break;
case 2:
VectorMA( dir, y, up, vert );
VectorMA( vert, -x, right, vert );
break;
case 3:
VectorCopy( dir, vert );
break;
}
gEngfuncs.pTriAPI->Vertex3fv( vert );
gEngfuncs.pTriAPI->Brightness( 1.0f );
gEngfuncs.pTriAPI->TexCoord2f( 1.0f, 0.0f );
switch( frame )
{
case 0:
VectorMA( dir, x, up, vert );
break;
case 1:
VectorMA( dir, x, up, vert );
VectorMA( vert, x, right, vert );
break;
case 2:
VectorCopy( dir, vert );
break;
case 3:
VectorMA( dir, y, up, vert );
VectorMA( vert, x, right, vert );
break;
}
gEngfuncs.pTriAPI->Vertex3fv( vert );
gEngfuncs.pTriAPI->Brightness( 1.0f );
gEngfuncs.pTriAPI->TexCoord2f( 1.0f, 1.0f );
switch( frame )
{
case 0:
VectorCopy( dir, vert );
break;
case 1:
VectorMA( dir, x, right, vert );
break;
case 2:
VectorMA( dir, -x, up, vert );
break;
case 3:
VectorMA( dir, -x, up, vert );
VectorMA( vert, x, right, vert );
break;
}
gEngfuncs.pTriAPI->Vertex3fv( vert );
gEngfuncs.pTriAPI->End();
if( ++frame >= 4 )
{
gEngfuncs.pTriAPI->RenderMode( kRenderNormal );
cl_entity_t *viewmodel = gEngfuncs.GetViewModel();
viewmodel->curstate.rendermode = kRenderGlow;
viewmodel->curstate.renderamt = 5;
break;
}
} }
r = 255; return 1;
g = b = 0; }
for (i = 0; i < len; i++) int CHudScope::DrawText()
{ {
TextMessageDrawChar(x, y, szDistance[i], r, g, b); int w, h;
c = szDistance[i]; if( !bDrawScope )
x += gHUD.m_scrinfo.charWidths[c]; return 1;
}
GetConsoleStringSize( m_szDist, &w, &h );
// gEngfuncs.Con_Printf("CMLWBR trace distance: %.3f\n", meters); DrawSetTextColor( 1.0f, 0.25f, 0.25f );
DrawConsoleString( ScreenWidth * 0.82f - w, ScreenHeight * 0.49f - h, m_szDist );
return 1; return 1;
} }

Loading…
Cancel
Save