Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
206 changes: 206 additions & 0 deletions code/client/cl_hud_snap.c
Original file line number Diff line number Diff line change
@@ -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.count<SNAPHUD_MAXZONES-2;step--){
cl.snappinghud.zones[cl.snappinghud.count]=RAD2DEG(acos(step/speed));
cl.snappinghud.count++;
cl.snappinghud.zones[cl.snappinghud.count]=RAD2DEG(asin(step/speed));
cl.snappinghud.count++;
}

qsort(cl.snappinghud.zones,cl.snappinghud.count,sizeof(cl.snappinghud.zones[0]),sortzones);
cl.snappinghud.zones[cl.snappinghud.count]=cl.snappinghud.zones[0]+90;

info = cl.gameState.stringData + cl.gameState.stringOffsets[ CS_SERVERINFO ];
cl.snappinghud.promode = atoi(Info_ValueForKey(info, "df_promode"));
}

/*
==============
HUD_DrawSnapping
==============
*/
void HUD_DrawSnapping ( float yaw ) {
int i,y,h;
char *t;
vec4_t color[3];
float speed;
int colorid = 0;

if (cl.snap.ps.pm_flags & PMF_FOLLOW || clc.demoplaying) {
cl.snappinghud.m[0]=(cl.snap.ps.stats[13] & 1) - (cl.snap.ps.stats[13] & 2);
cl.snappinghud.m[1]=(cl.snap.ps.stats[13] & 8) - (cl.snap.ps.stats[13] & 16);
}

if (!iodfe_hud_snap_draw->integer) {
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;i<cl.snappinghud.count;i++){
SCR_FillAngleYaw( cl.snappinghud.zones[i],cl.snappinghud.zones[i+1], yaw, y, h, color[colorid]);
SCR_FillAngleYaw( cl.snappinghud.zones[i]+90,cl.snappinghud.zones[i+1]+90, yaw, y, h, color[colorid]);
colorid^=1;
}
}

/*
==============
HUD_DrawPitch
==============
*/
void HUD_DrawPitch ( float pitch ) {
char *t;
vec4_t color[3];
float mark;

t = iodfe_hud_pitch_rgba->string;
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);
}
1 change: 1 addition & 0 deletions code/client/cl_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2428,6 +2428,7 @@ void CL_Init( void ) {
CL_InitRef();

SCR_Init ();
HUD_Init (); // snap hud

DL_Init(); // Cgg - client download

Expand Down
31 changes: 31 additions & 0 deletions code/client/cl_scrn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -519,6 +549,7 @@ void SCR_DrawScreenField( stereoFrame_t stereoFrame ) {
case CA_ACTIVE:
CL_CGameRendering( stereoFrame );
SCR_DrawDemoRecording();
HUD_Draw (); //iodfe snap hud
break;
}
}
Expand Down
21 changes: 21 additions & 0 deletions code/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -122,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
Expand Down Expand Up @@ -468,6 +480,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 );

Expand All @@ -477,6 +491,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
//
Expand Down
4 changes: 4 additions & 0 deletions code/quake3.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,10 @@
RelativePath=".\client\cl_download.c"
>
</File>
<File
RelativePath="client\cl_hud_snap.c"
>
</File>
<File
RelativePath="client\cl_input.c"
>
Expand Down
2 changes: 2 additions & 0 deletions code/renderer/tr_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
6 changes: 5 additions & 1 deletion code/renderer/tr_scene.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ int r_firstScenePoly;

int r_numpolyverts;

vec2_t cgamefov;

/*
====================
Expand Down Expand Up @@ -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] );
Expand Down