From a1670842b44f5ec70b3377446b49039cee4d9c22 Mon Sep 17 00:00:00 2001 From: Pan7 Date: Wed, 28 Jan 2015 18:12:06 +0100 Subject: [PATCH 1/3] snap hud --- code/client/cl_hud_snap.c | 206 ++++++++++++++++++++++++++++++++++++++ code/client/cl_main.c | 1 + code/client/cl_scrn.c | 31 ++++++ code/client/client.h | 19 ++++ code/renderer/tr_scene.c | 6 +- 5 files changed, 262 insertions(+), 1 deletion(-) create mode 100644 code/client/cl_hud_snap.c diff --git a/code/client/cl_hud_snap.c b/code/client/cl_hud_snap.c new file mode 100644 index 0000000..ef9b193 --- /dev/null +++ b/code/client/cl_hud_snap.c @@ -0,0 +1,206 @@ +/* +=========================================================================== +This file is part of Quake III Arena source code. + +Quake III Arena source code is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 2 of the License, +or (at your option) any later version. + +Quake III Arena source code is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Quake III Arena source code; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +=========================================================================== +*/ +// cl_hud.c -- additional head-up display tools + +#include "client.h" + +cvar_t *iodfe_hud_snap_draw; +cvar_t *iodfe_hud_snap_rgba1; +cvar_t *iodfe_hud_snap_rgba2; +cvar_t *iodfe_hud_snap_y; +cvar_t *iodfe_hud_snap_h; +cvar_t *iodfe_hud_snap_auto; +cvar_t *iodfe_hud_snap_def; +cvar_t *iodfe_hud_snap_speed; + +cvar_t *iodfe_hud_pitch; +cvar_t *iodfe_hud_pitch_rgba; +cvar_t *iodfe_hud_pitch_thickness; +cvar_t *iodfe_hud_pitch_width; +cvar_t *iodfe_hud_pitch_x; + +//============================================================================= + +static int QDECL sortzones( const void *a, const void *b ) { + return *(float *)a - *(float *)b; +} + +void HUD_UpdateSnappingSettings (float speed) { + float step; + const char *info; + + cl.snappinghud.speed=speed; + speed/=125; + cl.snappinghud.count = 0; + + for(step=floor(speed+0.5)-0.5;step>0 && cl.snappinghud.countinteger) { + return; + } + + speed = iodfe_hud_snap_speed->integer ? iodfe_hud_snap_speed->integer : cl.snap.ps.speed; + if (speed!=cl.snappinghud.speed) + HUD_UpdateSnappingSettings(speed); + + y = iodfe_hud_snap_y->value; + h = iodfe_hud_snap_h->value; + + switch (iodfe_hud_snap_auto->integer) { + case 0: + yaw+=iodfe_hud_snap_def->value; + break; + case 1: + if (cl.snappinghud.promode || (cl.snappinghud.m[0]!=0 && cl.snappinghud.m[1]!=0)){ + yaw+=45; + } else if (cl.snappinghud.m[0]==0 && cl.snappinghud.m[1]==0){ + yaw+=iodfe_hud_snap_def->value; + } + break; + case 2: + if (cl.snappinghud.m[0]!=0 && cl.snappinghud.m[1]!=0){ + yaw+=45; + } else if (cl.snappinghud.m[0]==0 && cl.snappinghud.m[1]==0){ + yaw+=iodfe_hud_snap_def->value; + } + break; + } + + t = iodfe_hud_snap_rgba2->string; + color[1][0] = atof(COM_Parse(&t)); + color[1][1] = atof(COM_Parse(&t)); + color[1][2] = atof(COM_Parse(&t)); + color[1][3] = atof(COM_Parse(&t)); + + t = iodfe_hud_snap_rgba1->string; + color[0][0] = atof(COM_Parse(&t)); + color[0][1] = atof(COM_Parse(&t)); + color[0][2] = atof(COM_Parse(&t)); + color[0][3] = atof(COM_Parse(&t)); + + for(i=0;istring; + color[2][0] = atof(COM_Parse(&t)); + color[2][1] = atof(COM_Parse(&t)); + color[2][2] = atof(COM_Parse(&t)); + color[2][3] = atof(COM_Parse(&t)); + + t = iodfe_hud_pitch->string; + mark = atof(COM_Parse(&t)); + while (mark){ + SCR_MarkAnglePitch( mark, iodfe_hud_pitch_thickness->value, pitch, iodfe_hud_pitch_x->value, iodfe_hud_pitch_width->value, color[2] ); + mark = atof(COM_Parse(&t)); + } +} + +/* +============== +HUD_Draw +============== +*/ +void HUD_Draw (void) { + vec2_t va; + + if (!Cvar_VariableIntegerValue("cg_draw2D")) { + return; + } + + if (cl.snap.ps.pm_flags & PMF_FOLLOW || clc.demoplaying){ + va[YAW] = cl.snap.ps.viewangles[YAW]; + va[PITCH] = -cl.snap.ps.viewangles[PITCH]; + } else if (cl.snap.ps.pm_type==0){ + va[YAW] = cl.viewangles[YAW]+SHORT2ANGLE(cl.snap.ps.delta_angles[YAW]); + va[PITCH] = -(cl.viewangles[PITCH]+SHORT2ANGLE(cl.snap.ps.delta_angles[PITCH])); + } else { + return; + } + + if (iodfe_hud_snap_draw->integer) { + HUD_DrawSnapping ( va[YAW] ); + } + + HUD_DrawPitch ( va[PITCH] ); +} + +/* +================== +HUD_Init +================== +*/ +void HUD_Init( void ) { + iodfe_hud_snap_draw = Cvar_Get ("iodfe_hud_snap_draw", "0", CVAR_ARCHIVE); + iodfe_hud_snap_rgba1 = Cvar_Get ("iodfe_hud_snap_rgba1", ".02 .1 .02 .4", CVAR_ARCHIVE); + iodfe_hud_snap_rgba2 = Cvar_Get ("iodfe_hud_snap_rgba2", ".05 .05 .05 .1", CVAR_ARCHIVE); + iodfe_hud_snap_y = Cvar_Get ("iodfe_hud_snap_y", "248", CVAR_ARCHIVE); + iodfe_hud_snap_h = Cvar_Get ("iodfe_hud_snap_h", "8", CVAR_ARCHIVE); + iodfe_hud_snap_auto = Cvar_Get ("iodfe_hud_snap_auto", "1", CVAR_ARCHIVE); + iodfe_hud_snap_def = Cvar_Get ("iodfe_hud_snap_def", "45", CVAR_ARCHIVE); + iodfe_hud_snap_speed = Cvar_Get ("iodfe_hud_snap_speed", "0", CVAR_ARCHIVE); + iodfe_hud_pitch = Cvar_Get ("iodfe_hud_pitch", "", CVAR_ARCHIVE); + iodfe_hud_pitch_thickness = Cvar_Get ("iodfe_hud_pitch_thickness", "2", CVAR_ARCHIVE); + iodfe_hud_pitch_x = Cvar_Get ("iodfe_hud_pitch_x", "320", CVAR_ARCHIVE); + iodfe_hud_pitch_width = Cvar_Get ("iodfe_hud_pitch_width", "10", CVAR_ARCHIVE); + iodfe_hud_pitch_rgba = Cvar_Get ("iodfe_hud_pitch_rgba", ".8 .8 .8 .8", CVAR_ARCHIVE); +} diff --git a/code/client/cl_main.c b/code/client/cl_main.c index 870a5dd..f0d93b0 100644 --- a/code/client/cl_main.c +++ b/code/client/cl_main.c @@ -2428,6 +2428,7 @@ void CL_Init( void ) { CL_InitRef(); SCR_Init (); + HUD_Init (); // snap hud DL_Init(); // Cgg - client download diff --git a/code/client/cl_scrn.c b/code/client/cl_scrn.c index e16dab0..62fecc5 100644 --- a/code/client/cl_scrn.c +++ b/code/client/cl_scrn.c @@ -32,6 +32,36 @@ cvar_t *cl_graphscale; cvar_t *cl_graphshift; cvar_t *ch_recordMessage; // Cgg +/* +================ +SCR_FillAngle, SCR_MarkAngle +================= +*/ +void SCR_FillAngleYaw( float start, float end, float viewangle, float y, float height, const float *color ) { + float x, width, fovscale; + fovscale=tan(DEG2RAD(cgamefov[0]/2)); + x = SCREEN_WIDTH/2+tan(DEG2RAD(viewangle+start))/fovscale*SCREEN_WIDTH/2; + width = abs(SCREEN_WIDTH*(tan(DEG2RAD(viewangle+end))-tan(DEG2RAD(viewangle+start)))/(fovscale*2))+1; + + re.SetColor( color ); + SCR_AdjustFrom640( &x, &y, &width, &height ); + re.DrawStretchPic( x, y, width, height, 0, 0, 0, 0, cls.whiteShader ); + re.SetColor( NULL ); +} + +void SCR_MarkAnglePitch( float angle, float height, float viewangle, float x, float width, const float *color ) { + float y, fovscale; + + if (-cl.snap.ps.viewangles[PITCH]+angle > cgamefov[1]/2+5) return; + fovscale=tan(DEG2RAD(cgamefov[1]/2)); + y = SCREEN_HEIGHT/2+tan(DEG2RAD(viewangle+angle))/fovscale*SCREEN_HEIGHT/2; + + re.SetColor( color ); + SCR_AdjustFrom640( &x, &y, &width, &height ); + re.DrawStretchPic( x-width/2, y-height/2, width, height, 0, 0, 0, 0, cls.whiteShader ); + re.SetColor( NULL ); +} + /* ================ SCR_DrawNamedPic @@ -519,6 +549,7 @@ void SCR_DrawScreenField( stereoFrame_t stereoFrame ) { case CA_ACTIVE: CL_CGameRendering( stereoFrame ); SCR_DrawDemoRecording(); + HUD_Draw (); //iodfe snap hud break; } } diff --git a/code/client/client.h b/code/client/client.h index 39c005a..6fd491a 100644 --- a/code/client/client.h +++ b/code/client/client.h @@ -32,6 +32,16 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define RETRANSMIT_TIMEOUT 3000 // time between connection packet retransmits +//iodfe snap hud +#define SNAPHUD_MAXZONES 128 + +typedef struct { + int speed; + float zones[SNAPHUD_MAXZONES]; + int count; + vec2_t m; + qboolean promode; +} snappingHud_t; // snapshots are a view of the server at a given time typedef struct { @@ -468,6 +478,8 @@ int SCR_GetBigStringWidth( const char *str ); // returns in virtual 640x480 coo void SCR_AdjustFrom640( float *x, float *y, float *w, float *h ); void SCR_FillRect( float x, float y, float width, float height, const float *color ); +void SCR_FillAngleYaw( float start, float end, float viewangle, float y, float height, const float *color ); +void SCR_MarkAnglePitch( float angle, float height, float viewangle, float x, float width, const float *color ); void SCR_DrawPic( float x, float y, float width, float height, qhandle_t hShader ); void SCR_DrawNamedPic( float x, float y, float width, float height, const char *picname ); @@ -477,6 +489,13 @@ void SCR_DrawSmallStringExt( int x, int y, const char *string, float *setColor, void SCR_DrawSmallChar( int x, int y, int ch ); +// +// cl_hud_snap.c +// + +void HUD_Init (void); +void HUD_Draw (void); + // // cl_cin.c // diff --git a/code/renderer/tr_scene.c b/code/renderer/tr_scene.c index 8cde15b..7a1324d 100644 --- a/code/renderer/tr_scene.c +++ b/code/renderer/tr_scene.c @@ -35,6 +35,7 @@ int r_firstScenePoly; int r_numpolyverts; +vec2_t cgamefov; /* ==================== @@ -312,7 +313,10 @@ void RE_RenderScene( const refdef_t *fd ) { tr.refdef.height = fd->height; tr.refdef.fov_x = fd->fov_x; tr.refdef.fov_y = fd->fov_y; - + if ( !fd->rdflags ) { + cgamefov[0]=fd->fov_x; + cgamefov[1]=fd->fov_y; + } VectorCopy( fd->vieworg, tr.refdef.vieworg ); VectorCopy( fd->viewaxis[0], tr.refdef.viewaxis[0] ); VectorCopy( fd->viewaxis[1], tr.refdef.viewaxis[1] ); From 0767df101fc2336ef4192012e3b677f946399cc2 Mon Sep 17 00:00:00 2001 From: Pan7 Date: Wed, 28 Jan 2015 20:42:01 +0100 Subject: [PATCH 2/3] snap hud part2 --- code/client/client.h | 2 ++ code/renderer/tr_public.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/code/client/client.h b/code/client/client.h index 6fd491a..b42f8dc 100644 --- a/code/client/client.h +++ b/code/client/client.h @@ -132,6 +132,8 @@ typedef struct { // and teleport direction changes vec3_t viewangles; + snappingHud_t snappinghud; + int serverId; // included in each client message so the server // can tell if it is for a prior map_restart // big stuff at end of structure so most offsets are 15 bits or less diff --git a/code/renderer/tr_public.h b/code/renderer/tr_public.h index 2ecc302..61d9287 100644 --- a/code/renderer/tr_public.h +++ b/code/renderer/tr_public.h @@ -26,6 +26,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define REF_API_VERSION 8 +extern vec2_t cgamefov; + // // these are the functions exported by the refresh module // From 50ba9a689dbe0c6fe0ef475e975afacb77da6d4b Mon Sep 17 00:00:00 2001 From: Pan7 Date: Wed, 28 Jan 2015 20:59:20 +0100 Subject: [PATCH 3/3] snap hud msvc project file update --- code/quake3.vcproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/code/quake3.vcproj b/code/quake3.vcproj index 03d53e8..8d6174e 100644 --- a/code/quake3.vcproj +++ b/code/quake3.vcproj @@ -946,6 +946,10 @@ RelativePath=".\client\cl_download.c" > + +