Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(gameclient): thicker pane lines under a square radar frame

Olcay Seygan06fa100163eb
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
index 83d68554e..f5cd21b2a 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
@@ -159,6 +159,13 @@ void ObserverCamera_paneMiddles( const Real *rays, Int count, Int width, Int hei
Real ObserverCamera_easeFrames( UnsignedInt frame, UnsignedInt start, UnsignedInt length );
/// how much higher every camera stands while count panes are progress of the way in, 1 with none
Real ObserverCamera_paneZoom( Int count, Real progress );
+/// the dark edge each side of the gold of a line between panes and of the radar's frame, in pixels
+enum { OBSERVER_PANE_LINE_EDGE = 2 };
+/// the gold of a line between panes, in pixels, for a picture height pixels high: 6 at 720, 9 at 1080
+Int ObserverCamera_paneLineWidth( Int height );
+/// how far either side of a seam the join keeps pane 0's pixels, which is where its line is drawn:
+/// the whole edged line's half width, measured along a row or column across a 45 degree line
+Int ObserverCamera_paneSeamBand( Int height );
class ObserverCamera
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
index ec39ca204..05ccaf749 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
@@ -128,6 +128,8 @@ static const UnsignedInt PANE_INTRO_FRAMES = 7 * LOGICFRAMES_PER_SECOND;
static const Real PANE_ZOOM_TWO = 1.3f;
static const Real PANE_ZOOM_THREE = 1.4f;
static const Real PANE_ZOOM_FOUR_OR_MORE = 1.5f;
+/// the gold of a line between panes is a pixel for every this many rows of the picture
+static const Real PANE_LINE_ROWS_A_PIXEL = 120.0f;
/// a pane's middle is measured on a grid this coarse, which is plenty for where to put a subject
static const Int PANE_MIDDLE_COLUMNS = 64;
static const Int PANE_MIDDLE_ROWS = 36;
@@ -540,6 +542,22 @@ Real ObserverCamera_paneZoom( Int count, Real progress )
return 1.0f + ( highest - 1.0f ) * progress;
}
+//-------------------------------------------------------------------------------------------------
+Int ObserverCamera_paneLineWidth( Int height )
+{
+ return max( REAL_TO_INT( height / PANE_LINE_ROWS_A_PIXEL ), 2 );
+}
+
+//-------------------------------------------------------------------------------------------------
+/** A row crosses a 45 degree line over its width times the square root of two, the widest any of
+ * the rays is cut; one pixel more for the rounding of the line's quad. */
+//-------------------------------------------------------------------------------------------------
+Int ObserverCamera_paneSeamBand( Int height )
+{
+ const Real whole = (Real)( ObserverCamera_paneLineWidth( height ) + 2 * OBSERVER_PANE_LINE_EDGE );
+ return REAL_TO_INT_CEIL( whole * 0.5f * sqrtf( 2.0f ) ) + 1;
+}
+
//-------------------------------------------------------------------------------------------------
ObserverCamera::ObserverCamera()
{
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
index 16c6c575b..2edf8796f 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
@@ -4305,7 +4305,7 @@ static Bool openVideoPipe(Int width, Int height)
* 0's. */
static void joinVideoPanes(char *rows, Int width, Int height, UnsignedInt frame)
{
- enum { SEAM_BAND = 2 };
+ const Int seamBand = ObserverCamera_paneSeamBand(height);
const Int count = TheObserverCamera.getDrawnPaneCount();
const Real *rays = TheObserverCamera.getPaneRays();
const Coord2D origin = TheObserverCamera.getPaneOrigin();
@@ -4334,10 +4334,10 @@ static void joinVideoPanes(char *rows, Int width, Int height, UnsignedInt frame)
continue;
if (x >= radar.lo.x && x < radar.hi.x && y >= radar.lo.y && y < radar.hi.y)
continue;
- const Int left = max(x - SEAM_BAND, 0);
- const Int right = min(x + SEAM_BAND, width - 1);
- const Int up = max(y - SEAM_BAND, 0);
- const Int down = min(y + SEAM_BAND, height - 1);
+ const Int left = max(x - seamBand, 0);
+ const Int right = min(x + seamBand, width - 1);
+ const Int up = max(y - seamBand, 0);
+ const Int down = min(y + seamBand, height - 1);
if (s_videoPaneMap[y * width + left] != pane || s_videoPaneMap[y * width + right] != pane
|| s_videoPaneMap[up * width + x] != pane || s_videoPaneMap[down * width + x] != pane)
continue;
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
index 06ec423b0..9af6dc8ec 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
@@ -423,83 +423,39 @@ void W3DInGameUI::reset( void )
static void drawGroundRing( const Coord3D& center, Real radius, UnsignedInt color, Real width );
-/// -directorrecord's lines between panes and round the framed radar: the brand's gold (zerohour.gg's
-/// --gold, #f2c230) on an edge of its ground (--bg, #0c1220), so the line reads on snow and on night
-/// maps alike
-enum { PANE_LINE_WIDTH = 3, PANE_EDGE_WIDTH = 5, PANE_MOST_LINES = 2 * OBSERVER_MOST_PANES + 4 };
-struct PaneLine
+/// -directorrecord's lines between panes and the radar's frame: the brand's gold (zerohour.gg's
+/// --gold, #f2c230) between two edges of its ground (--bg, #0c1220), so they read on snow and on
+/// night maps alike
+static const Color PANE_GOLD = GameMakeColor( 0xf2, 0xc2, 0x30, 255 );
+static const Color PANE_EDGE = GameMakeColor( 0x0c, 0x12, 0x20, 255 );
+
+/** The rays between the panes, from their meeting point to past the screen's edge, every ray's edge
+ * before any gold so the gold runs on unbroken where they meet. */
+static void drawPaneRays( void )
{
- Coord2D from;
- Coord2D to;
-};
-
-/// every edge drawn before any gold, so where two lines meet the gold runs on unbroken
-static void drawPaneLines( const PaneLine *lines, Int count )
-{
- const Color edge = GameMakeColor( 0x0c, 0x12, 0x20, 255 );
- const Color gold = GameMakeColor( 0xf2, 0xc2, 0x30, 255 );
- for( Int line = 0; line < count; line++ )
- TheDisplay->drawLine( REAL_TO_INT( lines[ line ].from.x ), REAL_TO_INT( lines[ line ].from.y ),
- REAL_TO_INT( lines[ line ].to.x ), REAL_TO_INT( lines[ line ].to.y ), (Real)PANE_EDGE_WIDTH, edge );
- for( Int line = 0; line < count; line++ )
- TheDisplay->drawLine( REAL_TO_INT( lines[ line ].from.x ), REAL_TO_INT( lines[ line ].from.y ),
- REAL_TO_INT( lines[ line ].to.x ), REAL_TO_INT( lines[ line ].to.y ), (Real)PANE_LINE_WIDTH, gold );
-}
-
-/** A ray from the panes' meeting point with the part inside the radar's frame left out, so the ray
- * starts on the frame's line: one piece, two when the meeting point is outside the frame and the ray
- * crosses it, none when it ends inside. */
-static Int addRayOutsideFrame( const Coord2D &from, const Coord2D &to, const IRegion2D *frame, PaneLine *lines )
-{
- PaneLine whole = { from, to };
- if( frame == NULL )
- {
- lines[ 0 ] = whole;
- return 1;
- }
-
- // the stretch of the ray inside the frame, as fractions of it (Liang and Barsky's clip)
- const Real start[ 2 ] = { from.x, from.y };
- const Real along[ 2 ] = { to.x - from.x, to.y - from.y };
- const Real low[ 2 ] = { (Real)frame->lo.x, (Real)frame->lo.y };
- const Real high[ 2 ] = { (Real)frame->hi.x, (Real)frame->hi.y };
- Real enter = 0.0f;
- Real leave = 1.0f;
- for( Int axis = 0; axis < 2; axis++ )
+ const Real gold = (Real)ObserverCamera_paneLineWidth( TheDisplay->getHeight() );
+ const Real edged = gold + 2 * OBSERVER_PANE_LINE_EDGE;
+ const Real reach = 2.0f * ( TheDisplay->getWidth() + TheDisplay->getHeight() );
+ const Coord2D origin = TheObserverCamera.getPaneOrigin();
+ const Real *rays = TheObserverCamera.getPaneRays();
+ const Int count = TheObserverCamera.getDrawnPaneCount();
+ for( Int pass = 0; pass < 2; pass++ )
{
- if( along[ axis ] == 0.0f )
+ for( Int ray = 0; ray < count; ray++ )
{
- if( start[ axis ] < low[ axis ] || start[ axis ] > high[ axis ] )
- enter = 2.0f;
- continue;
+ const Real angle = rays[ ray ] * PI / 180.0f;
+ TheDisplay->drawLine( REAL_TO_INT( origin.x ), REAL_TO_INT( origin.y ),
+ REAL_TO_INT( origin.x + cosf( angle ) * reach ), REAL_TO_INT( origin.y - sinf( angle ) * reach ),
+ pass == 0 ? edged : gold, pass == 0 ? PANE_EDGE : PANE_GOLD );
}
- const Real atLow = ( low[ axis ] - start[ axis ] ) / along[ axis ];
- const Real atHigh = ( high[ axis ] - start[ axis ] ) / along[ axis ];
- enter = max( enter, min( atLow, atHigh ) );
- leave = min( leave, max( atLow, atHigh ) );
- }
- if( enter >= leave )
- {
- lines[ 0 ] = whole;
- return 1;
}
+}
- Int count = 0;
- if( enter > 0.0f )
- {
- lines[ count ].from = from;
- lines[ count ].to.x = from.x + along[ 0 ] * enter;
- lines[ count ].to.y = from.y + along[ 1 ] * enter;
- count++;
- }
- if( leave < 1.0f )
- {
- lines[ count ].from.x = from.x + along[ 0 ] * leave;
- lines[ count ].from.y = from.y + along[ 1 ] * leave;
- lines[ count ].to = to;
- count++;
- }
- return count;
+/// a rectangle the given pixels larger than window on every side, filled
+static void fillAround( const IRegion2D &window, Int outside, Color color )
+{
+ TheDisplay->drawFillRect( window.lo.x - outside, window.lo.y - outside,
+ window.hi.x - window.lo.x + 2 * outside, window.hi.y - window.lo.y + 2 * outside, color );
}
//-------------------------------------------------------------------------------------------------
@@ -516,10 +472,11 @@ void W3DInGameUI::draw( void )
IRegion2D noFrame;
noFrame.lo.x = noFrame.lo.y = noFrame.hi.x = noFrame.hi.y = 0;
TheObserverCamera.setRadarFrame( noFrame );
- // the frame's line runs along the radar window's outside edge, its inner side on the window's
- // one pixel bezel, so the map meets it with no gap
- IRegion2D frame = noFrame;
- Bool hasFrame = FALSE;
+
+ // -directorrecord's panes: the rays between them, drawn in pane 0's draw alone and under the
+ // radar; the join takes a band along every seam from pane 0, line and all
+ if( framed && !TheObserverCamera.isDrawingSecond() )
+ drawPaneRays();
// the console's 'hidehud showmap=true': the bar is hidden, so its radar window is put in the
// corner by hand, where the radar's own pixel maths find it too, and painted. Under
@@ -543,11 +500,12 @@ void W3DInGameUI::draw( void )
corner.lo.y = corner.hi.y - ( lr.y - ul.y ) - 2 * RADAR_BEZEL;
const Int mapWidth = corner.hi.x - corner.lo.x;
const Int mapHeight = corner.hi.y - corner.lo.y;
- // how far the frame's line and its edge reach outside the window
- enum { RADAR_FRAME_OUTSIDE = 1 + PANE_EDGE_WIDTH / 2 + 1 };
+ // the frame is the rays' gold and outer edge laid round the window, the gold on the bezel
+ const Int frameGold = ObserverCamera_paneLineWidth( TheDisplay->getHeight() );
+ const Int frameOutside = frameGold + OBSERVER_PANE_LINE_EDGE;
if( framed )
{
- const Real diagonal = sqrtf( (Real)( mapWidth * mapWidth + mapHeight * mapHeight ) ) + 2 * RADAR_FRAME_OUTSIDE;
+ const Real diagonal = sqrtf( (Real)( mapWidth * mapWidth + mapHeight * mapHeight ) ) + 2 * frameOutside;
const Coord2D middle = TheObserverCamera.getFramedRadarMiddle( diagonal );
corner.lo.x = REAL_TO_INT( middle.x ) - mapWidth / 2;
corner.hi.x = corner.lo.x + mapWidth;
@@ -556,69 +514,26 @@ void W3DInGameUI::draw( void )
}
else
{
- const Int slide = REAL_TO_INT( TheObserverCamera.getCornerRadarSlide() * ( mapWidth + RADAR_FRAME_OUTSIDE ) );
+ const Int slide = REAL_TO_INT( TheObserverCamera.getCornerRadarSlide() * ( mapWidth + frameOutside ) );
corner.lo.x -= slide;
corner.hi.x -= slide;
}
- TheControlBar->placeWindowAt( radarWindow, corner );
- W3DLeftHUDDraw( radarWindow, NULL );
+ // two filled rectangles under the radar, square at the corners: the edge, then the gold up
+ // to the window, so the map sits on the gold with no gap. All of it is pane 0's in the join
if( framed )
{
- // the window's last column is corner.hi.x - 1, so the line's middle is one pixel
- // outside the bezel on every side
- frame.lo.x = corner.lo.x - 1;
- frame.lo.y = corner.lo.y - 1;
- frame.hi.x = corner.hi.x;
- frame.hi.y = corner.hi.y;
- hasFrame = TRUE;
- // the line and its edge are drawn over the frame's outline, so they are pane 0's too
- IRegion2D taken = frame;
- taken.lo.x -= PANE_EDGE_WIDTH / 2 + 1;
- taken.lo.y -= PANE_EDGE_WIDTH / 2 + 1;
- taken.hi.x += PANE_EDGE_WIDTH / 2 + 1;
- taken.hi.y += PANE_EDGE_WIDTH / 2 + 1;
+ fillAround( corner, frameOutside, PANE_EDGE );
+ fillAround( corner, frameGold, PANE_GOLD );
+ IRegion2D taken = corner;
+ taken.lo.x -= frameOutside;
+ taken.lo.y -= frameOutside;
+ taken.hi.x += frameOutside;
+ taken.hi.y += frameOutside;
TheObserverCamera.setRadarFrame( taken );
}
- }
-
- // -directorrecord's panes: the rays between them, from where they meet to past the screen's
- // edge, meeting the radar's frame and drawn with it in pane 0's draw alone; the join takes a
- // band along every seam from pane 0, line and all
- if( framed && !TheObserverCamera.isDrawingSecond() )
- {
- PaneLine lines[ PANE_MOST_LINES ];
- Int count = 0;
- const Real reach = 2.0f * ( TheDisplay->getWidth() + TheDisplay->getHeight() );
- const Coord2D origin = TheObserverCamera.getPaneOrigin();
- const Real *rays = TheObserverCamera.getPaneRays();
- for( Int ray = 0; ray < TheObserverCamera.getDrawnPaneCount(); ray++ )
- {
- const Real angle = rays[ ray ] * PI / 180.0f;
- Coord2D end;
- end.x = origin.x + cosf( angle ) * reach;
- end.y = origin.y - sinf( angle ) * reach;
- count += addRayOutsideFrame( origin, end, hasFrame ? &frame : NULL, lines + count );
- }
- if( hasFrame )
- {
- // each side runs on past the corners by half the edge, so the corners are filled
- const Real past = PANE_EDGE_WIDTH / 2;
- const Real left = (Real)frame.lo.x;
- const Real top = (Real)frame.lo.y;
- const Real right = (Real)frame.hi.x;
- const Real bottom = (Real)frame.hi.y;
- const PaneLine sides[ 4 ] =
- {
- { { left - past, top }, { right + past, top } },
- { { right, top - past }, { right, bottom + past } },
- { { right + past, bottom }, { left - past, bottom } },
- { { left, bottom + past }, { left, top - past } },
- };
- for( Int side = 0; side < 4; side++ )
- lines[ count++ ] = sides[ side ];
- }
- drawPaneLines( lines, count );
+ TheControlBar->placeWindowAt( radarWindow, corner );
+ W3DLeftHUDDraw( radarWindow, NULL );
}
return;
}
diff --git a/GeneralsMD/Code/Tests/test_observer_camera.inc b/GeneralsMD/Code/Tests/test_observer_camera.inc
index f48565a02..c1cb7b979 100644
--- a/GeneralsMD/Code/Tests/test_observer_camera.inc
+++ b/GeneralsMD/Code/Tests/test_observer_camera.inc
@@ -422,6 +422,16 @@ TEST(pane_cameras_stand_higher_the_more_panes_there_are)
CHECK_NEAR( ObserverCamera_paneZoom( 8, 1.0f ), 1.5f, 0.0001f );
}
+TEST(pane_lines_grow_with_the_picture_and_the_join_keeps_all_of_them)
+{
+ CHECK_EQ( ObserverCamera_paneLineWidth( 720 ), 6 );
+ CHECK_EQ( ObserverCamera_paneLineWidth( 1080 ), 9 );
+ CHECK_EQ( ObserverCamera_paneLineWidth( 2160 ), 18 );
+ // the gold and both edges, crossed by a row at 45 degrees: 13 * 0.707 is 9.2 at 1080
+ CHECK( ObserverCamera_paneSeamBand( 1080 ) >= 10 );
+ CHECK( ObserverCamera_paneSeamBand( 720 ) >= 8 );
+}
+
TEST(pane_animations_ease_over_logic_frames)
{
CHECK_NEAR( ObserverCamera_easeFrames( 100, 100, 15 ), 0.0f, 0.0001f );