[iortcw] 418/497: SP: Initial commit for fixed aspect HUD (Based on ZTM's flexible HUD mod)

Simon McVittie smcv at debian.org
Fri Sep 8 10:37:39 UTC 2017


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to annotated tag 1.42d
in repository iortcw.

commit 2d97b71dc8552043c44676420bb713aa1c50c507
Author: MAN-AT-ARMS <M4N4T4RMS at gmail.com>
Date:   Wed Nov 4 16:04:28 2015 -0500

    SP: Initial commit for fixed aspect HUD (Based on ZTM's flexible HUD mod)
---
 SP/code/cgame/cg_draw.c       | 223 ++++++++++++++++++++++++++++++++++--------
 SP/code/cgame/cg_drawtools.c  | 142 +++++++++++++++++++++++----
 SP/code/cgame/cg_local.h      |  24 ++++-
 SP/code/cgame/cg_main.c       |  31 +++++-
 SP/code/cgame/cg_newdraw.c    |   4 +
 SP/code/cgame/cg_scoreboard.c |  24 ++++-
 SP/code/cgame/cg_view.c       |  49 ++++++----
 SP/code/cgame/cg_weapons.c    |  31 ++++--
 8 files changed, 431 insertions(+), 97 deletions(-)

diff --git a/SP/code/cgame/cg_draw.c b/SP/code/cgame/cg_draw.c
index e9b0c3b..a39437e 100644
--- a/SP/code/cgame/cg_draw.c
+++ b/SP/code/cgame/cg_draw.c
@@ -603,9 +603,18 @@ void CG_DrawTeamBackground( int x, int y, int w, int h, float alpha, int team )
 	} else {
 		return;
 	}
-	trap_R_SetColor( hcolor );
-	CG_DrawPic( x, y, w, h, cgs.media.teamStatusBar );
-	trap_R_SetColor( NULL );
+
+	if ( cg_fixedAspect.integer ) {
+		trap_R_SetColor( hcolor );
+		CG_SetScreenPlacement(PLACE_STRETCH, CG_GetScreenVerticalPlacement());
+ 		CG_DrawPic( x, y, w, h, cgs.media.teamStatusBar );
+		CG_PopScreenPlacement();
+ 		trap_R_SetColor( NULL );
+	} else {
+		trap_R_SetColor( hcolor );
+		CG_DrawPic( x, y, w, h, cgs.media.teamStatusBar );
+		trap_R_SetColor( NULL );
+	}
 }
 
 //////////////////////
@@ -1490,10 +1499,15 @@ static void CG_DrawTeamInfo( void ) {
 	} else {
 		chatHeight = TEAMCHAT_HEIGHT;
 	}
+
 	if ( chatHeight <= 0 ) {
 		return; // disabled
+	}
 
+	if ( cg_fixedAspect.integer ) {
+		CG_SetScreenPlacement( PLACE_LEFT, PLACE_BOTTOM );
 	}
+
 	if ( cgs.teamLastChatPos != cgs.teamChatPos ) {
 		if ( cg.time - cgs.teamChatMsgTimes[cgs.teamLastChatPos % chatHeight] > cg_teamChatTime.integer ) {
 			cgs.teamLastChatPos++;
@@ -1664,6 +1678,11 @@ static void CG_DrawReward( void ) {
 	if ( !cg_drawRewards.integer ) {
 		return;
 	}
+
+	if ( cg_fixedAspect.integer ) {
+		CG_SetScreenPlacement(PLACE_CENTER, PLACE_CENTER);
+	}
+
 	color = CG_FadeColor( cg.rewardTime, REWARD_TIME );
 	if ( !color ) {
 		return;
@@ -1762,6 +1781,10 @@ static void CG_DrawDisconnect( void ) {
 		return;
 	}
 
+	if ( cg_fixedAspect.integer ) {
+		CG_SetScreenPlacement(PLACE_CENTER, PLACE_CENTER);
+	}
+
 	// also add text in center of screen
 	s = "Connection Interrupted"; // bk 010215 - FIXME
 	w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH;
@@ -1772,6 +1795,10 @@ static void CG_DrawDisconnect( void ) {
 		return;
 	}
 
+	if ( cg_fixedAspect.integer ) {
+		CG_SetScreenPlacement(PLACE_RIGHT, PLACE_BOTTOM);
+	}
+
 	x = 640 - 48;
 	y = 480 - 48;
 
@@ -1800,6 +1827,10 @@ static void CG_DrawLagometer( void ) {
 		return;
 	}
 
+	if ( cg_fixedAspect.integer ) {
+		CG_SetScreenPlacement(PLACE_RIGHT, PLACE_BOTTOM);
+	}
+
 	//
 	// draw the graph
 	//
@@ -1955,6 +1986,10 @@ static void CG_DrawCenterString( void ) {
 		return;
 	}
 
+	if ( cg_fixedAspect.integer ) {
+		CG_SetScreenPlacement(PLACE_CENTER, PLACE_CENTER);
+	}
+
 	trap_R_SetColor( color );
 
 	start = cg.centerPrint;
@@ -2021,6 +2056,7 @@ static void CG_DrawWeapReticle( void ) {
 	vec4_t snoopercolor = {0.7, .8, 0.7, 0};    // greenish
 	float snooperBrightness;
 	float x = 80, y, w = 240, h = 240;
+	float width = 80.0;
 
 	CG_AdjustFrom640( &x, &y, &w, &h );
 
@@ -2033,13 +2069,26 @@ static void CG_DrawWeapReticle( void ) {
 
 
 	if ( weap == WP_SNIPERRIFLE ) {
-
-
 		// sides
-		CG_FillRect( 0, 0, 80, 480, color );
-		CG_FillRect( 560, 0, 80, 480, color );
+		if ( cg_fixedAspect.integer ) {
+			if ( cgs.glconfig.vidWidth * 480 > cgs.glconfig.vidHeight * 640 ) {
+				width = 0.5 * ( ( cgs.glconfig.vidWidth - ( min( cgs.screenXScale, cgs.screenYScale ) * 480 ) ) / min( cgs.screenXScale, cgs.screenYScale ) );
+			}
+
+			CG_SetScreenPlacement(PLACE_LEFT, PLACE_BOTTOM);
+			CG_FillRect( 0, 0, width, 480, color );
+			CG_SetScreenPlacement(PLACE_RIGHT, PLACE_BOTTOM);
+			CG_FillRect( 640-width, 0, width, 480, color );
+		} else {
+			CG_FillRect( 0, 0, 80, 480, color );
+			CG_FillRect( 560, 0, 80, 480, color );
+		}
 
 		// center
+		if ( cg_fixedAspect.integer ) {
+			CG_SetScreenPlacement(PLACE_CENTER, PLACE_CENTER);
+		}
+
 		if ( cgs.media.reticleShaderSimpleQ ) {
 			trap_R_DrawStretchPic( x, 0, w, h, 0, 0, 1, 1, cgs.media.reticleShaderSimpleQ );    // tl
 			trap_R_DrawStretchPic( x + w, 0, w, h, 1, 0, 0, 1, cgs.media.reticleShaderSimpleQ );  // tr
@@ -2054,10 +2103,24 @@ static void CG_DrawWeapReticle( void ) {
 		CG_FillRect( 380, 239, 177, 2, color );  // right
 	} else if ( weap == WP_SNOOPERSCOPE ) {
 		// sides
-		CG_FillRect( 0, 0, 80, 480, color );
-		CG_FillRect( 560, 0, 80, 480, color );
+		if ( cg_fixedAspect.integer ) {
+			if ( cgs.glconfig.vidWidth * 480 > cgs.glconfig.vidHeight * 640 ) {
+				width = 0.5 * ( ( cgs.glconfig.vidWidth - ( min( cgs.screenXScale, cgs.screenYScale ) * 480 ) ) / min( cgs.screenXScale, cgs.screenYScale ) );
+			}
+
+			CG_SetScreenPlacement(PLACE_LEFT, PLACE_BOTTOM);
+			CG_FillRect( 0, 0, width, 480, color );
+			CG_SetScreenPlacement(PLACE_RIGHT, PLACE_BOTTOM);
+			CG_FillRect( 640-width, 0, width, 480, color );
+		} else {
+			CG_FillRect( 0, 0, 80, 480, color );
+			CG_FillRect( 560, 0, 80, 480, color );
+		}
 
 		// center
+		if ( cg_fixedAspect.integer ) {
+			CG_SetScreenPlacement(PLACE_CENTER, PLACE_CENTER);
+		}
 
 //----(SA)	added
 		// DM didn't like how bright it gets
@@ -2093,10 +2156,25 @@ static void CG_DrawWeapReticle( void ) {
 		CG_FillRect( 240, 220, 1, 40, color );   // r
 	} else if ( weap == WP_FG42SCOPE ) {
 		// sides
-		CG_FillRect( 0, 0, 80, 480, color );
-		CG_FillRect( 560, 0, 80, 480, color );
+		if ( cg_fixedAspect.integer ) {
+			if ( cgs.glconfig.vidWidth * 480 > cgs.glconfig.vidHeight * 640 ) {
+				width = 0.5 * ( ( cgs.glconfig.vidWidth - ( min( cgs.screenXScale, cgs.screenYScale ) * 480 ) ) / min( cgs.screenXScale, cgs.screenYScale ) );
+			}
+
+			CG_SetScreenPlacement(PLACE_LEFT, PLACE_BOTTOM);
+			CG_FillRect( 0, 0, width, 480, color );
+			CG_SetScreenPlacement(PLACE_RIGHT, PLACE_BOTTOM);
+			CG_FillRect( 640-width, 0, width, 480, color );
+		} else {
+			CG_FillRect( 0, 0, 80, 480, color );
+			CG_FillRect( 560, 0, 80, 480, color );
+		}
 
 		// center
+		if ( cg_fixedAspect.integer ) {
+			CG_SetScreenPlacement(PLACE_CENTER, PLACE_CENTER);
+		}
+
 		if ( cgs.media.reticleShaderSimpleQ ) {
 			trap_R_DrawStretchPic( x,   0, w, h, 0, 0, 1, 1, cgs.media.reticleShaderSimpleQ );  // tl
 			trap_R_DrawStretchPic( x + w, 0, w, h, 1, 0, 0, 1, cgs.media.reticleShaderSimpleQ );  // tr
@@ -2131,6 +2209,10 @@ static void CG_DrawBinocReticle( void ) {
 	vec4_t color = {0, 0, 0, 1};
 	float x, y, w = 320, h = 240;
 
+	if ( cg_fixedAspect.integer ) {
+		CG_SetScreenPlacement(PLACE_STRETCH, PLACE_STRETCH);
+	}
+
 	if ( cgs.media.binocShaderSimpleQ ) {
 		CG_AdjustFrom640( &x, &y, &w, &h );
 		trap_R_DrawStretchPic( 0, 0, w, h, 0, 0, 1, 1, cgs.media.binocShaderSimpleQ );  // tl
@@ -2173,6 +2255,9 @@ static void CG_DrawCrosshair( void ) {
 
 	hcolor[3] = cg_crosshairAlpha.value;    //----(SA)	added
 
+	if ( cg_fixedAspect.integer ) {
+		CG_SetScreenPlacement(PLACE_CENTER, PLACE_CENTER);
+	}
 
 	// on mg42
 	if ( cg.snap->ps.eFlags & EF_MG42_ACTIVE ) {
@@ -2308,7 +2393,9 @@ static void CG_DrawCrosshair( void ) {
 
 	x = cg_crosshairX.integer;
 	y = cg_crosshairY.integer;
-	CG_AdjustFrom640( &x, &y, &w, &h );
+	if ( !cg_fixedAspect.integer ) {
+		CG_AdjustFrom640( &x, &y, &w, &h );
+	}
 
 //----(SA)	modified
 	if ( friendInSights ) {
@@ -2320,9 +2407,13 @@ static void CG_DrawCrosshair( void ) {
 
 	// NERVE - SMF - modified, fixes crosshair offset in shifted/scaled 3d views
 	// (SA) also breaks scaled view...
-	trap_R_DrawStretchPic(  x + cg.refdef.x + 0.5 * ( cg.refdef.width - w ),
-							y + cg.refdef.y + 0.5 * ( cg.refdef.height - h ),
-							w, h, 0, 0, 1, 1, hShader );
+	if ( cg_fixedAspect.integer ) {
+		CG_DrawPic( ((SCREEN_WIDTH-w)*0.5f)+x, ((SCREEN_HEIGHT-h)*0.5f)+y, w, h, hShader );
+	} else {
+		trap_R_DrawStretchPic(  x + cg.refdef.x + 0.5 * ( cg.refdef.width - w ),
+								y + cg.refdef.y + 0.5 * ( cg.refdef.height - h ),
+								w, h, 0, 0, 1, 1, hShader );
+	}
 
 	trap_R_SetColor( NULL );
 }
@@ -2675,6 +2766,10 @@ static void CG_DrawCrosshairNames( void ) {
 	}
 	// done.
 
+	if ( cg_fixedAspect.integer ) {
+		CG_SetScreenPlacement(PLACE_CENTER, PLACE_CENTER);
+	}
+
 	// scan the known entities to see if the crosshair is sighted on one
 	CG_ScanForCrosshairEntity();
 
@@ -2727,6 +2822,9 @@ CG_DrawSpectator
 =================
 */
 static void CG_DrawSpectator( void ) {
+	if ( cg_fixedAspect.integer ) {
+		CG_SetScreenPlacement(PLACE_CENTER, PLACE_BOTTOM);
+	}
 	CG_DrawBigString( 320 - 9 * 8, 440, "SPECTATOR", 1.0F );
 	if ( cgs.gametype == GT_TOURNAMENT ) {
 		CG_DrawBigString( 320 - 15 * 8, 460, "waiting to play", 1.0F );
@@ -2749,6 +2847,10 @@ static void CG_DrawVote( void ) {
 		return;
 	}
 
+	if ( cg_fixedAspect.integer ) {
+		CG_SetScreenPlacement(PLACE_LEFT, PLACE_TOP);
+	}
+
 	// play a talk beep whenever it is modified
 	if ( cgs.voteModified ) {
 		cgs.voteModified = qfalse;
@@ -2833,6 +2935,11 @@ static qboolean CG_DrawFollow( void ) {
 	if ( !( cg.snap->ps.pm_flags & PMF_FOLLOW ) ) {
 		return qfalse;
 	}
+
+	if ( cg_fixedAspect.integer ) {
+		CG_SetScreenPlacement(PLACE_CENTER, PLACE_TOP);
+	}
+
 	color[0] = 1;
 	color[1] = 1;
 	color[2] = 1;
@@ -2922,6 +3029,10 @@ static void CG_DrawWarmup( void ) {
 		return;
 	}
 
+	if ( cg_fixedAspect.integer ) {
+		CG_SetScreenPlacement(PLACE_CENTER, PLACE_TOP);
+	}
+
 	if ( sec < 0 ) {
 		s = "Waiting for players";
 		w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH;
@@ -3035,7 +3146,13 @@ static void CG_DrawFlashFade( void ) {
 		VectorClear( col );
 		col[3] = cgs.scrFadeAlphaCurrent;
 //		CG_FillRect( -10, -10, 650, 490, col );
-		CG_FillRect( 0, 0, 640, 480, col ); // why do a bunch of these extend outside 640x480?
+		if ( cg_fixedAspect.integer ) {
+			CG_SetScreenPlacement(PLACE_STRETCH, PLACE_STRETCH);
+		 	CG_FillRect( 0, 0, 640, 480, col );
+			CG_PopScreenPlacement();
+		} else {	
+			CG_FillRect( 0, 0, 640, 480, col ); // why do a bunch of these extend outside 640x480?
+		}
 	}
 }
 
@@ -3089,7 +3206,13 @@ static void CG_DrawFlashZoomTransition( void ) {
 			Vector4Set( color, 0, 0, 0, 1.0f - frac );
 		}
 
-		CG_FillRect( -10, -10, 650, 490, color );
+		if ( cg_fixedAspect.integer ) {
+			CG_SetScreenPlacement(PLACE_STRETCH, PLACE_STRETCH);
+			CG_FillRect( -10, -10, 650, 490, color );
+			CG_PopScreenPlacement();
+		} else {
+			CG_FillRect( -10, -10, 650, 490, color );
+		}
 	}
 }
 
@@ -3119,7 +3242,13 @@ static void CG_DrawFlashDamage( void ) {
 		VectorSet( col, 0.2, 0, 0 );
 		col[3] =  0.7 * ( redFlash / 5.0 );
 
-		CG_FillRect( -10, -10, 650, 490, col );
+		if ( cg_fixedAspect.integer ) {
+			CG_SetScreenPlacement(PLACE_STRETCH, PLACE_STRETCH);
+			CG_FillRect( -10, -10, 650, 490, col );
+			CG_PopScreenPlacement();
+		} else {
+			CG_FillRect( -10, -10, 650, 490, col );
+		}
 	}
 }
 
@@ -3171,7 +3300,11 @@ static void CG_DrawFlashFire( void ) {
 		col[2] = alpha;
 		col[3] = alpha;
 		trap_R_SetColor( col );
-		CG_DrawPic( -10, -10, 650, 490, cgs.media.viewFlashFire[( cg.time / 50 ) % 16] );
+		if ( cg_fixedAspect.integer ) {
+			trap_R_DrawStretchPic( -10, -10, 650, 490, 0, 0, 1, 1, cgs.media.viewFlashFire[( cg.time / 50 ) % 16] );
+		} else {
+			CG_DrawPic( -10, -10, 650, 490, cgs.media.viewFlashFire[( cg.time / 50 ) % 16] );
+		}
 		trap_R_SetColor( NULL );
 
 		CG_S_AddLoopingSound( cg.snap->ps.clientNum, cg.snap->ps.origin, vec3_origin, cgs.media.flameSound, (int)( 255.0 * alpha ) );
@@ -3209,8 +3342,11 @@ static void CG_DrawFlashLightning( void ) {
 	} else {
 		shader = cgs.media.viewTeslaDamageEffectShader;
 	}
-
-	CG_DrawPic( -10, -10, 650, 490, shader );
+	if ( cg_fixedAspect.integer ) {
+		trap_R_DrawStretchPic( -10, -10, 650, 490, 0, 0, 1, 1, shader );
+	} else {
+		CG_DrawPic( -10, -10, 650, 490, shader );
+	}
 }
 
 
@@ -3404,23 +3540,7 @@ void CG_Fade( int r, int g, int b, int a, int time, int duration ) {
 		cgs.scrFadeAlphaCurrent = cgs.scrFadeAlpha;
 	}
 
-
 	return;
-
-#if 0 // This is the MP code (Which is correct?)
-	if ( time <= 0 ) {  // do instantly
-		cg.fadeRate = 1;
-		cg.fadeTime = cg.time - 1;  // set cg.fadeTime behind cg.time so it will start out 'done'
-	} else {
-		cg.fadeRate = 1.0f / time;
-		cg.fadeTime = cg.time + time;
-	}
-
-	cg.fadeColor2[ 0 ] = ( float )r / 255.0f;
-	cg.fadeColor2[ 1 ] = ( float )g / 255.0f;
-	cg.fadeColor2[ 2 ] = ( float )b / 255.0f;
-	cg.fadeColor2[ 3 ] = ( float )a / 255.0f;
-#endif
 }
 
 
@@ -3442,7 +3562,13 @@ static void CG_DrawGameScreenFade( void ) {
 
 	VectorClear( col );
 	col[3] = cg.viewFade;
-	CG_FillRect( 0, 0, 640, 480, col );
+	if ( cg_fixedAspect.integer ) {
+		CG_SetScreenPlacement(PLACE_STRETCH, PLACE_STRETCH);
+		CG_FillRect( 0, 0, 640, 480, col );
+		CG_PopScreenPlacement();
+	} else {
+		CG_FillRect( 0, 0, 640, 480, col );
+	}
 }
 
 /*
@@ -3475,7 +3601,13 @@ static void CG_ScreenFade( void ) {
 			return;
 		}
 
-		CG_FillRect( 0, 0, 640, 480, cg.fadeColor1 );
+		if ( cg_fixedAspect.integer ) {
+			CG_SetScreenPlacement(PLACE_STRETCH, PLACE_STRETCH);
+			CG_FillRect( 0, 0, 640, 480, cg.fadeColor1 );
+			CG_PopScreenPlacement();
+		} else {
+			CG_FillRect( 0, 0, 640, 480, cg.fadeColor1 );
+		}
 
 	} else {
 		t = ( float )msec * cg.fadeRate;
@@ -3486,7 +3618,13 @@ static void CG_ScreenFade( void ) {
 		}
 
 		if ( color[ 3 ] ) {
-			CG_FillRect( 0, 0, 640, 480, color );
+			if ( cg_fixedAspect.integer ) {
+				CG_SetScreenPlacement(PLACE_STRETCH, PLACE_STRETCH);
+				CG_FillRect( 0, 0, 640, 480, color );
+				CG_PopScreenPlacement();
+			} else {
+				CG_FillRect( 0, 0, 640, 480, color );
+			}
 		}
 	}
 }
@@ -3539,6 +3677,10 @@ static void CG_Draw2D(stereoFrame_t stereoFrame) {
 				CG_DrawCrosshair();
 
 			if ( cg_drawStatus.integer ) {
+				if ( cg_fixedAspect.integer ) {
+					CG_SetScreenPlacement(PLACE_CENTER, PLACE_BOTTOM);
+				}
+
 				Menu_PaintAll();
 				CG_DrawTimedMenus();
 			}
@@ -3751,4 +3893,3 @@ void CG_DrawActive( stereoFrame_t stereoView ) {
 	CG_Draw2D(stereoView);
 }
 
-
diff --git a/SP/code/cgame/cg_drawtools.c b/SP/code/cgame/cg_drawtools.c
index dff1484..7b88f64 100644
--- a/SP/code/cgame/cg_drawtools.c
+++ b/SP/code/cgame/cg_drawtools.c
@@ -29,6 +29,56 @@ If you have questions concerning this license or the applicable additional terms
 // cg_drawtools.c -- helper functions called by cg_draw, cg_scoreboard, cg_info, etc
 #include "cg_local.h"
 
+static screenPlacement_e cg_horizontalPlacement = PLACE_CENTER;
+static screenPlacement_e cg_verticalPlacement = PLACE_CENTER;
+static screenPlacement_e cg_lastHorizontalPlacement = PLACE_CENTER;
+static screenPlacement_e cg_lastVerticalPlacement = PLACE_CENTER;
+
+/*
+================
+CG_SetScreenPlacement
+================
+*/
+void CG_SetScreenPlacement(screenPlacement_e hpos, screenPlacement_e vpos)
+{
+	cg_lastHorizontalPlacement = cg_horizontalPlacement;
+	cg_lastVerticalPlacement = cg_verticalPlacement;
+
+	cg_horizontalPlacement = hpos;
+	cg_verticalPlacement = vpos;
+}
+
+/*
+================
+CG_PopScreenPlacement
+================
+*/
+void CG_PopScreenPlacement(void)
+{
+	cg_horizontalPlacement = cg_lastHorizontalPlacement;
+	cg_verticalPlacement = cg_lastVerticalPlacement;
+}
+
+/*
+================
+CG_GetScreenHorizontalPlacement
+================
+*/
+screenPlacement_e CG_GetScreenHorizontalPlacement(void)
+{
+	return cg_horizontalPlacement;
+}
+
+/*
+================
+CG_GetScreenVerticalPlacement
+================
+*/
+screenPlacement_e CG_GetScreenVerticalPlacement(void)
+{
+	return cg_verticalPlacement;
+}
+
 /*
 ================
 CG_AdjustFrom640
@@ -44,23 +94,73 @@ void CG_AdjustFrom640( float *x, float *y, float *w, float *h ) {
 	}
 #endif
 
-	// NERVE - SMF - hack to make images display properly in small view / limbo mode
-	if ( cg.limboMenu && cg.refdef.width ) {
-		float xscale = ( ( cg.refdef.width / cgs.screenXScale ) / 640.f );
-		float yscale = ( ( cg.refdef.height / cgs.screenYScale ) / 480.f );
+	if ( cg_fixedAspect.integer ) {
+		if (cg_horizontalPlacement == PLACE_STRETCH) {
+			// scale for screen sizes (not aspect correct in wide screen)
+			*w *= cgs.screenXScaleStretch;
+			*x *= cgs.screenXScaleStretch;
+		} else {
+			// NERVE - SMF - hack to make images display properly in small view / limbo mode
+			if ( cg.limboMenu && cg.refdef.width ) {
+				float xscale = ( ( cg.refdef.width / cgs.screenXScale ) / 640.f );
 
-		( *x ) = ( *x ) * xscale + ( cg.refdef.x / cgs.screenXScale );
-		( *y ) = ( *y ) * yscale + ( cg.refdef.y / cgs.screenYScale );
-		( *w ) *= xscale;
-		( *h ) *= yscale;
-	}
-	// -NERVE - SMF
+				( *x ) = ( *x ) * xscale + ( cg.refdef.x / cgs.screenXScale );
+				( *w ) *= xscale;
+			}
+			// -NERVE - SMF
+	
+			// scale for screen sizes
+			*w *= cgs.screenXScale;
+			*x *= cgs.screenXScale;
+	
+			if (cg_horizontalPlacement == PLACE_CENTER) {
+				*x += cgs.screenXBias;
+			} else if (cg_horizontalPlacement == PLACE_RIGHT) {
+				*x += cgs.screenXBias*2;
+			}
+		}
+
+		if (cg_verticalPlacement == PLACE_STRETCH) {
+			*h *= cgs.screenYScaleStretch;
+			*y *= cgs.screenYScaleStretch;
+		} else {
+			// NERVE - SMF - hack to make images display properly in small view / limbo mode
+			if ( cg.limboMenu && cg.refdef.width ) {
+				float yscale = ( ( cg.refdef.height / cgs.screenYScale ) / 480.f );
 
-	// scale for screen sizes
-	*x *= cgs.screenXScale;
-	*y *= cgs.screenYScale;
-	*w *= cgs.screenXScale;
-	*h *= cgs.screenYScale;
+				( *y ) = ( *y ) * yscale + ( cg.refdef.y / cgs.screenYScale );
+				( *h ) *= yscale;
+			}
+			// -NERVE - SMF
+
+			*h *= cgs.screenYScale;
+			*y *= cgs.screenYScale;
+	
+			if (cg_verticalPlacement == PLACE_CENTER) {
+				*y += cgs.screenYBias;
+			} else if (cg_verticalPlacement == PLACE_BOTTOM) {
+				*y += cgs.screenYBias*2;
+			}
+		}
+	} else {
+		// NERVE - SMF - hack to make images display properly in small view / limbo mode
+		if ( cg.limboMenu && cg.refdef.width ) {
+			float xscale = ( ( cg.refdef.width / cgs.screenXScale ) / 640.f );
+			float yscale = ( ( cg.refdef.height / cgs.screenYScale ) / 480.f );
+
+			( *x ) = ( *x ) * xscale + ( cg.refdef.x / cgs.screenXScale );
+			( *y ) = ( *y ) * yscale + ( cg.refdef.y / cgs.screenYScale );
+			( *w ) *= xscale;
+			( *h ) *= yscale;
+		}
+		// -NERVE - SMF
+
+		// scale for screen sizes
+		*x *= cgs.screenXScale;
+		*y *= cgs.screenYScale;
+		*w *= cgs.screenXScale;
+		*h *= cgs.screenYScale;
+	}
 }
 
 /*
@@ -1063,7 +1163,11 @@ static void UI_DrawBannerString2( int x, int y, const char* str, vec4_t color )
 	trap_R_SetColor( color );
 
 	ax = x * cgs.screenXScale + cgs.screenXBias;
-	ay = y * cgs.screenYScale;
+	if ( cg_fixedAspect.integer ) {
+		ay = y * cgs.screenYScale + cgs.screenYBias;
+	} else {
+		ay = y * cgs.screenYScale;
+	}
 
 	s = str;
 	while ( *s )
@@ -1170,7 +1274,11 @@ static void UI_DrawProportionalString2( int x, int y, const char* str, vec4_t co
 	trap_R_SetColor( color );
 
 	ax = x * cgs.screenXScale + cgs.screenXBias;
-	ay = y * cgs.screenYScale;
+	if ( cg_fixedAspect.integer ) {
+		ay = y * cgs.screenYScale + cgs.screenYBias;
+	} else {
+		ay = y * cgs.screenYScale;
+	}
 
 	s = str;
 	while ( *s )
diff --git a/SP/code/cgame/cg_local.h b/SP/code/cgame/cg_local.h
index 9c4b557..dc9135f 100644
--- a/SP/code/cgame/cg_local.h
+++ b/SP/code/cgame/cg_local.h
@@ -799,7 +799,8 @@ typedef struct {
 
 	// view rendering
 	refdef_t refdef;
-	vec3_t refdefViewAngles;            // will be converted to refdef.viewaxis
+	vec3_t refdefViewAngles;	// will be converted to refdef.viewaxis
+	float fov;			// either range checked cg_fov or forced value
 
 	// zoom key
 	qboolean zoomed;
@@ -1520,6 +1521,9 @@ typedef struct {
 	float screenXScale;                 // derived from glconfig
 	float screenYScale;
 	float screenXBias;
+	float screenYBias;
+	float screenXScaleStretch;
+	float screenYScaleStretch;
 
 	int serverCommandSequence;              // reliable command stream counter
 	int processedSnapshotNum;            // the number of snapshots cgame has requested
@@ -1825,6 +1829,24 @@ void CG_Concussive( centity_t *cent );
 //
 // cg_drawtools.c
 //
+typedef enum {
+	PLACE_STRETCH,
+	PLACE_CENTER,
+
+	// horizontal only
+	PLACE_LEFT,
+	PLACE_RIGHT,
+
+	// vertical only
+	PLACE_TOP,
+	PLACE_BOTTOM
+} screenPlacement_e;
+
+void CG_SetScreenPlacement(screenPlacement_e hpos, screenPlacement_e vpos);
+void CG_PopScreenPlacement(void);
+screenPlacement_e CG_GetScreenHorizontalPlacement(void);
+screenPlacement_e CG_GetScreenVerticalPlacement(void);
+
 void CG_AdjustFrom640( float *x, float *y, float *w, float *h );
 void CG_FillRect( float x, float y, float width, float height, const float *color );
 void CG_HorizontalPercentBar( float x, float y, float width, float height, float percent );
diff --git a/SP/code/cgame/cg_main.c b/SP/code/cgame/cg_main.c
index 103186f..fa03b62 100644
--- a/SP/code/cgame/cg_main.c
+++ b/SP/code/cgame/cg_main.c
@@ -296,7 +296,7 @@ cvarTable_t cvarTable[] = {
 	{ &cg_zoomStepSnooper, "cg_zoomStepSnooper", "5", CVAR_ARCHIVE },
 	{ &cg_zoomStepFG, "cg_zoomStepFG", "10", CVAR_ARCHIVE },          //----(SA)	added
 	{ &cg_fov, "cg_fov", "90", CVAR_ARCHIVE },	// NOTE: there is already a dmflag (DF_FIXED_FOV) to allow server control of this cheat
-	{ &cg_fixedAspect, "cg_fixedAspect", "0", CVAR_ARCHIVE }, // Essentially the same as setting DF_FIXED_FOV for widescreen aspects
+	{ &cg_fixedAspect, "cg_fixedAspect", "0", CVAR_ARCHIVE | CVAR_LATCH }, // Essentially the same as setting DF_FIXED_FOV for widescreen aspects
 	{ &cg_viewsize, "cg_viewsize", "100", CVAR_ARCHIVE },
 	{ &cg_letterbox, "cg_letterbox", "0", CVAR_TEMP },    //----(SA)	added
 	{ &cg_shadows, "cg_shadows", "1", CVAR_ARCHIVE  },
@@ -1443,6 +1443,9 @@ static void CG_RegisterGraphics( void ) {
 		}
 	}
 
+	// can be used by HUD so always load it
+	CG_RegisterItemVisuals( 6 /* item_health_large */ );
+
 	// wall marks
 	cgs.media.bulletMarkShader = trap_R_RegisterShader( "gfx/damage/bullet_mrk" );
 	cgs.media.burnMarkShader = trap_R_RegisterShader( "gfx/damage/burn_med_mrk" );
@@ -2317,8 +2320,30 @@ void CG_Init( int serverMessageNum, int serverCommandSequence ) {
 
 	// get the rendering configuration from the client system
 	trap_GetGlconfig( &cgs.glconfig );
-	cgs.screenXScale = cgs.glconfig.vidWidth / 640.0;
-	cgs.screenYScale = cgs.glconfig.vidHeight / 480.0;
+	if ( cg_fixedAspect.integer ) {
+		cgs.screenXScaleStretch = cgs.glconfig.vidWidth * (1.0/640.0);
+		cgs.screenYScaleStretch = cgs.glconfig.vidHeight * (1.0/480.0);
+		if ( cgs.glconfig.vidWidth * 480 > cgs.glconfig.vidHeight * 640 ) {
+			cgs.screenXScale = cgs.glconfig.vidWidth * (1.0/640.0);
+			cgs.screenYScale = cgs.glconfig.vidHeight * (1.0/480.0);
+			// wide screen
+			cgs.screenXBias = 0.5 * ( cgs.glconfig.vidWidth - ( cgs.glconfig.vidHeight * (640.0/480.0) ) );
+			cgs.screenXScale = cgs.screenYScale;
+			// no narrow screen
+			cgs.screenYBias = 0;
+		} else {
+			cgs.screenXScale = cgs.glconfig.vidWidth * (1.0/640.0);
+			cgs.screenYScale = cgs.glconfig.vidHeight * (1.0/480.0);
+			// narrow screen
+			cgs.screenYBias = 0.5 * ( cgs.glconfig.vidHeight - ( cgs.glconfig.vidWidth * (480.0/640.0) ) );
+			cgs.screenYScale = cgs.screenXScale;
+			// no wide screen
+			cgs.screenXBias = 0;
+		}
+	} else {
+		cgs.screenXScale = cgs.glconfig.vidWidth / 640.0;
+		cgs.screenYScale = cgs.glconfig.vidHeight / 480.0;
+	}
 
 	// get the gamestate from the client system
 	trap_GetGameState( &cgs.gameState );
diff --git a/SP/code/cgame/cg_newdraw.c b/SP/code/cgame/cg_newdraw.c
index 73a5422..191e791 100644
--- a/SP/code/cgame/cg_newdraw.c
+++ b/SP/code/cgame/cg_newdraw.c
@@ -875,6 +875,10 @@ static void CG_DrawHoldableItem( rectDef_t *rect, int font, float scale, qboolea
 		return;
 	}
 
+	if ( cg_fixedAspect.integer ) {
+		CG_SetScreenPlacement(PLACE_RIGHT, PLACE_CENTER);
+	}
+
 	value   = cg.predictedPlayerState.holdable[cg.holdableSelect];
 
 	if ( value ) {
diff --git a/SP/code/cgame/cg_scoreboard.c b/SP/code/cgame/cg_scoreboard.c
index 341f9cb..382067c 100644
--- a/SP/code/cgame/cg_scoreboard.c
+++ b/SP/code/cgame/cg_scoreboard.c
@@ -440,7 +440,11 @@ qboolean CG_DrawScoreboard( void ) {
 	float   *fadeColor;
 	char    *s;
 
-	// don't draw amuthing if the menu or console is up
+	if ( cg_fixedAspect.integer ) {
+		CG_SetScreenPlacement(PLACE_CENTER, PLACE_CENTER);
+	}
+
+	// don't draw anything if the menu or console is up
 	if ( cg_paused.integer ) {
 		cg.deferredPlayerLoading = 0;
 		return qfalse;
@@ -616,6 +620,10 @@ void CG_DrawTourneyScoreboard( void ) {
 	int y;
 	int i;
 
+	if ( cg_fixedAspect.integer ) {
+		CG_SetScreenPlacement(PLACE_CENTER, PLACE_CENTER);
+	}
+
 	// request more scores regularly
 	if ( cg.scoresRequestTime + 2000 < cg.time ) {
 		cg.scoresRequestTime = cg.time;
@@ -623,9 +631,17 @@ void CG_DrawTourneyScoreboard( void ) {
 	}
 
 	// draw the dialog background
-	color[0] = color[1] = color[2] = 0;
-	color[3] = 1;
-	CG_FillRect( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, color );
+	if ( cg_fixedAspect.integer ) {
+		color[0] = color[1] = color[2] = 0;
+	 	color[3] = 1;
+		CG_SetScreenPlacement(PLACE_STRETCH, PLACE_STRETCH);
+ 		CG_FillRect( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, color );
+		CG_PopScreenPlacement();
+	} else {
+		color[0] = color[1] = color[2] = 0;
+		color[3] = 1;
+		CG_FillRect( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, color );
+	}
 
 	color[0] = 1;
 	color[1] = 1;
diff --git a/SP/code/cgame/cg_view.c b/SP/code/cgame/cg_view.c
index 0e141f3..213eb69 100644
--- a/SP/code/cgame/cg_view.c
+++ b/SP/code/cgame/cg_view.c
@@ -775,7 +775,6 @@ Fixed fov at intermissions, otherwise account for fov variable and zooms.
 */
 #define WAVE_AMPLITUDE  1
 #define WAVE_FREQUENCY  0.4
-#define STANDARD_ASPECT_RATIO  ( (float)640 / (float)480 )
 
 static int CG_CalcFov( void ) {
 	static float lastfov = 90;      // for transitions back from zoomed in modes
@@ -802,10 +801,10 @@ static int CG_CalcFov( void ) {
 
 	if ( cg.predictedPlayerState.pm_type == PM_INTERMISSION ) {
 		// if in intermission, use a fixed value
-		fov_x = 90;
+		cg.fov = fov_x = 90;
 	} else {
 		// user selectable
-		if ( ( cgs.dmflags & DF_FIXED_FOV ) || cg_fixedAspect.value ) {
+		if ( ( cgs.dmflags & DF_FIXED_FOV ) || cg_fixedAspect.integer ) {
 			// dmflag to prevent wide fov for all clients
 			fov_x = 90;
 		} else {
@@ -817,6 +816,8 @@ static int CG_CalcFov( void ) {
 			}
 		}
 
+		cg.fov = fov_x;
+
 		// account for zooms
 		if ( cg.zoomval ) {
 			zoomFov = cg.zoomval;   // (SA) use user scrolled amount
@@ -868,12 +869,14 @@ static int CG_CalcFov( void ) {
 		fov_x = 55;
 	}
 
-	if ( cg_fixedAspect.value ) {
-		float aspectRatio = (float)cg.refdef.width / (float)cg.refdef.height;
+	if ( cg_fixedAspect.integer ) {
+		// Based on LordHavoc's code for Darkplaces
+		// http://www.quakeworld.nu/forum/topic/53/what-does-your-qw-look-like/page/30
+		const float baseAspect = 0.75f; // 3/4
+		const float aspect = (float)cg.refdef.width/(float)cg.refdef.height;
+		const float desiredFov = fov_x;
 
-		if ( aspectRatio > STANDARD_ASPECT_RATIO )
-			fov_x = RAD2DEG( 2 * atan2( ( aspectRatio / STANDARD_ASPECT_RATIO ) * tan( DEG2RAD( fov_x ) * 0.5 ), 1 ) );	
-		fov_x = min( fov_x, 160 );
+		fov_x = atan2( tan( desiredFov*M_PI / 360.0f ) * baseAspect*aspect, 1 )*360.0f / M_PI;
 	}
 
 	x = cg.refdef.width / tan( fov_x / 360 * M_PI );
@@ -1059,12 +1062,14 @@ static int CG_CalcViewValues( void ) {
 			VectorCopy( angles, cg.refdefViewAngles );
 			AnglesToAxis( cg.refdefViewAngles, cg.refdef.viewaxis );
 
-			if ( cg_fixedAspect.value ) {
-				float aspectRatio = (float)cg.refdef.width / (float)cg.refdef.height;
-
-				if ( aspectRatio > STANDARD_ASPECT_RATIO )
-					fov = RAD2DEG( 2 * atan2( ( aspectRatio / STANDARD_ASPECT_RATIO ) * tan( DEG2RAD( fov ) * 0.5 ), 1 ) );
-				fov = min( fov, 160 );
+			if ( cg_fixedAspect.integer ) {
+				// Based on LordHavoc's code for Darkplaces
+				// http://www.quakeworld.nu/forum/topic/53/what-does-your-qw-look-like/page/30
+				const float baseAspect = 0.75f; // 3/4
+				const float aspect = (float)cg.refdef.width/(float)cg.refdef.height;
+				const float desiredFov = fov;
+		
+				fov = atan2( tan( desiredFov*M_PI / 360.0f ) * baseAspect*aspect, 1 )*360.0f / M_PI;
 			}
 
 			x = cg.refdef.width / tan( fov / 360 * M_PI );
@@ -1316,7 +1321,7 @@ void CG_DrawSkyBoxPortal( void ) {
 			fov_x = 90;
 		} else {
 			// user selectable
-			if ( ( cgs.dmflags & DF_FIXED_FOV ) || cg_fixedAspect.value ) {
+			if ( ( cgs.dmflags & DF_FIXED_FOV ) || cg_fixedAspect.integer ) {
 				// dmflag to prevent wide fov for all clients
 				fov_x = 90;
 			} else {
@@ -1371,12 +1376,14 @@ void CG_DrawSkyBoxPortal( void ) {
 			fov_x = 55;
 		}
 
-		if ( cg_fixedAspect.value ) {
-			float aspectRatio = (float)cg.refdef.width / (float)cg.refdef.height;
-
-			if ( aspectRatio > STANDARD_ASPECT_RATIO )
-				fov_x = RAD2DEG( 2 * atan2( ( aspectRatio / STANDARD_ASPECT_RATIO ) * tan( DEG2RAD( fov_x ) * 0.5 ), 1 ) );
-			fov_x = min( fov_x, 160 );
+		if ( cg_fixedAspect.integer ) {
+			// Based on LordHavoc's code for Darkplaces
+			// http://www.quakeworld.nu/forum/topic/53/what-does-your-qw-look-like/page/30
+			const float baseAspect = 0.75f; // 3/4
+			const float aspect = (float)cg.refdef.width/(float)cg.refdef.height;
+			const float desiredFov = fov_x;
+	
+			fov_x = atan2( tan( desiredFov*M_PI / 360.0f ) * baseAspect*aspect, 1 )*360.0f / M_PI;
 		}
 
 		x = cg.refdef.width / tan( fov_x / 360 * M_PI );
diff --git a/SP/code/cgame/cg_weapons.c b/SP/code/cgame/cg_weapons.c
index e6ea655..91d3662 100644
--- a/SP/code/cgame/cg_weapons.c
+++ b/SP/code/cgame/cg_weapons.c
@@ -2953,7 +2953,7 @@ Add the weapon, and flash for the player's view
 */
 void CG_AddViewWeapon( playerState_t *ps ) {
 	refEntity_t hand;
-	float fovOffset;
+	vec3_t		fovOffset;
 	vec3_t angles;
 	vec3_t gunoff;
 	weaponInfo_t    *weapon;
@@ -2995,13 +2995,20 @@ void CG_AddViewWeapon( playerState_t *ps ) {
 		return;
 	}
 
+	VectorClear(fovOffset);
 
-	// drop gun lower at higher fov
-	if ( cg_fov.integer > 90 && !cg_fixedAspect.value ) {
-		fovOffset = -0.2 * ( cg_fov.integer - 90 );
-	} else {
-		fovOffset = 0;
-	}
+	if ( cg_fixedAspect.integer ) {
+		fovOffset[2] = 0;
+	} else if ( cg.fov > 90 ) {
+		// drop gun lower at higher fov
+		fovOffset[2] = -0.2 * ( cg.fov - 90 ) * cg.refdef.fov_x / cg.fov;
+	} else if ( cg.fov < 90 ) {
+		// move gun forward at lower fov
+		fovOffset[0] = -0.2 * ( cg.fov - 90 ) * cg.refdef.fov_x / cg.fov;
+	} else if ( cg_fov.integer > 90 ) {
+		// old auto adjust
+		fovOffset[2] = -0.2 * ( cg_fov.integer - 90 );
+ 	}
 
 	if ( ps->weapon > WP_NONE ) {
 		// DHM - Nerve :: handle WP_CLASS_SPECIAL for different classes
@@ -3041,9 +3048,9 @@ void CG_AddViewWeapon( playerState_t *ps ) {
 
 //----(SA)	removed
 
-		VectorMA( hand.origin, gunoff[0], cg.refdef.viewaxis[0], hand.origin );
-		VectorMA( hand.origin, gunoff[1], cg.refdef.viewaxis[1], hand.origin );
-		VectorMA( hand.origin, ( gunoff[2] + fovOffset ), cg.refdef.viewaxis[2], hand.origin );
+		VectorMA( hand.origin, ( gunoff[0] + fovOffset[0] ), cg.refdef.viewaxis[0], hand.origin );
+		VectorMA( hand.origin, ( gunoff[1] + fovOffset[1] ), cg.refdef.viewaxis[1], hand.origin );
+		VectorMA( hand.origin, ( gunoff[2] + fovOffset[2] ), cg.refdef.viewaxis[2], hand.origin );
 
 		AnglesToAxis( angles, hand.axis );
 
@@ -3105,6 +3112,10 @@ void CG_DrawWeaponSelect( void ) {
 	int bits[MAX_WEAPONS / ( sizeof( int ) * 8 )];
 	float       *color;
 
+	if ( cg_fixedAspect.integer ) {
+		CG_SetScreenPlacement(PLACE_CENTER, PLACE_BOTTOM);
+	}
+
 	// don't display if dead
 	if ( cg.predictedPlayerState.stats[STAT_HEALTH] <= 0 ) {
 		return;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/iortcw.git



More information about the Pkg-games-commits mailing list