From 81e2eac904d0c67d0a22c3e6226debebd1734de7 Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin Date: Wed, 8 Apr 2020 12:17:35 +0500 Subject: [PATCH] Rework scope code. --- cl_dll/entity.cpp | 2 +- cl_dll/hud.cpp | 2 + cl_dll/hud.h | 5 +- cl_dll/hud_redraw.cpp | 2 + cl_dll/poke646/scope.cpp | 384 +++++++++++++++------------------------ 5 files changed, 155 insertions(+), 240 deletions(-) diff --git a/cl_dll/entity.cpp b/cl_dll/entity.cpp index ef30d6fe..c864dcf3 100644 --- a/cl_dll/entity.cpp +++ b/cl_dll/entity.cpp @@ -96,7 +96,7 @@ void DLLEXPORT HUD_TxferLocalOverrides( struct entity_state_s *state, const stru // Fire prevention state->iuser4 = client->iuser4; - bDrawScope = client->iuser4; + // bDrawScope = client->iuser4; } /* diff --git a/cl_dll/hud.cpp b/cl_dll/hud.cpp index f1058dbf..212ec667 100644 --- a/cl_dll/hud.cpp +++ b/cl_dll/hud.cpp @@ -36,6 +36,7 @@ extern client_sprite_t *GetSpriteList( client_sprite_t *pList, const char *psz, extern cvar_t *sensitivity; cvar_t *cl_lw = NULL; cvar_t *cl_viewbob = NULL; +cvar_t *adjust_fov = NULL; void ShutdownInput( void ); @@ -220,6 +221,7 @@ void CHud::Init( void ) m_pCvarDraw = CVAR_CREATE( "hud_draw", "1", FCVAR_ARCHIVE ); cl_lw = gEngfuncs.pfnGetCvarPointer( "cl_lw" ); cl_viewbob = CVAR_CREATE( "cl_viewbob", "0", FCVAR_ARCHIVE ); + adjust_fov = gEngfuncs.pfnGetCvarPointer( "r_adjust_fov" ); // Xash3D widescreen fix m_pSpriteList = NULL; diff --git a/cl_dll/hud.h b/cl_dll/hud.h index 6591a0d1..12063e52 100644 --- a/cl_dll/hud.h +++ b/cl_dll/hud.h @@ -567,9 +567,12 @@ class CHudScope { public: int DrawScope( void ); + int DrawText( void ); private: - HSPRITE m_hSprite; + struct model_s *m_hSpriteModel; + HSPRITE m_hSprite; + char m_szDist[16]; }; // diff --git a/cl_dll/hud_redraw.cpp b/cl_dll/hud_redraw.cpp index bbc5c77d..b4889a59 100644 --- a/cl_dll/hud_redraw.cpp +++ b/cl_dll/hud_redraw.cpp @@ -178,6 +178,8 @@ int CHud::Redraw( float flTime, int intermission ) } */ + gHUD.m_Scope.DrawText(); + return 1; } diff --git a/cl_dll/poke646/scope.cpp b/cl_dll/poke646/scope.cpp index 7ce5b209..e777a3e2 100644 --- a/cl_dll/poke646/scope.cpp +++ b/cl_dll/poke646/scope.cpp @@ -26,271 +26,179 @@ #include "pm_shared.h" #include "pm_defs.h" #include "pmtrace.h" + extern bool bDrawScope; extern vec3_t v_origin; // last view origin extern vec3_t v_angles; // last view angle extern vec3_t v_cl_angles; // last client/mouse angle extern vec3_t v_sim_org; // last sim origin +extern cvar_t *adjust_fov; 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 ) return 1; - if (!m_hSprite) - m_hSprite = SPR_Load("sprites/scopeborder.spr"); - - int halfScopeHeight = ScreenHeight / 2; - 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 - + if( !m_hSprite ) + { + m_hSprite = SPR_Load( "sprites/scopeborder.spr" ); + m_hSpriteModel = (struct model_s *)gEngfuncs.GetSpritePointer( m_hSprite ); + } - vec3_t forward; - AngleVectors(v_angles, forward, NULL, NULL); - VectorScale(forward, 1024, forward); - VectorAdd(forward, v_origin, forward); - pmtrace_t * trace = gEngfuncs.PM_TraceLine(v_origin, forward, PM_TRACELINE_PHYSENTSONLY, 2, -1); + gEngfuncs.GetViewAngles( angles ); + AngleVectors( angles, forward, right, up ); - float dist = (trace->endpos - v_origin).Length(); - float meters = dist * 0.021527f; // Convert hammer units to meters. + VectorMA( v_origin, 8192.0f, forward, dir ); + trace = gEngfuncs.PM_TraceLine( v_origin, dir, PM_TRACELINE_PHYSENTSONLY, 2, -1 ); + VectorSubtract( trace->endpos, v_origin, delta ); - char szDistance[16]; - sprintf(szDistance, "%.2f m", meters); + flDist = Length( delta ); - 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 = ScreenWidth / 2 + ((float)halfScopeWidth * 0.7f); - y = ScreenHeight / 2 - ((float)halfScopeHeight * 0.0625f); + x = tan( gHUD.m_iFOV * 0.008726646259971648 ) * 11.0; + y = x * 0.00390625; - x1 = x + 1; - y1 = y + 1; + gEngfuncs.pTriAPI->RenderMode( kRenderTransTexture ); //additive + gEngfuncs.pTriAPI->CullFace( TRI_NONE ); - char c; - int i; - int r, g, b; + if( adjust_fov && adjust_fov->value ) + VectorMA( v_origin, 8.0f, forward, dir ); + 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); - - c = szDistance[i]; - x1 += gHUD.m_scrinfo.charWidths[c]; + if( !gEngfuncs.pTriAPI->SpriteTexture( m_hSpriteModel, frame ) ) + break; + + 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; - g = b = 0; + return 1; +} - for (i = 0; i < len; i++) - { - TextMessageDrawChar(x, y, szDistance[i], r, g, b); +int CHudScope::DrawText() +{ + int w, h; - c = szDistance[i]; - x += gHUD.m_scrinfo.charWidths[c]; - } + if( !bDrawScope ) + 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; }