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.

perf(w3ddevice): draw each guard shield as one picture

Olcay Seygand5c925dbb239
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3ec861906..cca65de94 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -30,6 +30,7 @@ found and fixed, EA's own, not port damage.**
- The card that rises when you point at a build button is drawn in your side's own art now, with the price and the build time beside the name behind a coin and a clock. Under them one row of icons says what you are buying: health, armour class, damage, damage a second, range and speed for a unit, health, armour and the power it adds or draws for a building. The six lines of figures that used to pad out the description are gone, and so is the "Power Required" line EA wrote into every building's text, in every language. The small tooltip beside the pointer sits in a framed well of the same art in a match and of the watcher's steel in the menus. Both are cut from the bar itself: the same near-black shell, bevelled lip and sunk glass, the card's corner shaped like the side's bar (America's 45 degree cut, China's two steps, the GLA's bitten scrap, Turkiye's wide chamfer with its turquoise light), open on the side that meets the screen's edge.
- The army screen, the lobby and the score screen wear our own emblems. Every army has a card of its own on the army screen, the generals included, where EA's faces and logos used to be, and the player card shows the same one. Turkiye stops borrowing America's logo there and in the lobby's game list. On the score screen each player's row starts with his army's emblem, and your own army's card stands faint behind the table.
- The Tab screen, with the players, their teams and the chat buttons, is painted in your side's bar now instead of EA's see-through black with a blue rule. It stands in the top left corner on the same dark steel in three tiers, square on the screen's two edges and cut at the corner facing the battlefield, every player's row in a sunk well with alternate rows a shade lighter so a name lines up with its team at a glance. Its buttons are cut from the same metal: the mute switch carries a speaker that is struck through once you have muted someone, the money's minus, plus and Send sit in bezels shaped like the side's toolbar buttons, and Main Menu stands in a socket of its own. In a campaign the mission's briefing fills one clear well of dark glass, without the empty player rows, the grey veil and the blue frame it used to wear, and its scroll bar's arrows and groove are cut from the same steel. The watcher gets it in his own steel. The panel is solid, so the battlefield no longer shows through the list. The Classic interface keeps EA's screen.
+- An army standing guard no longer slows the game down. Each shield over a guarding unit's head was painted a line at a time, 60 to 180 little pieces a unit, and three hundred Rangers on guard took the picture down to 12 frames a second. The shield is now one picture, the same shield, and the same three hundred draw at about 240.
- Eight new player colours after the original eight: Teal, Lime, Navy, Magenta, Brown, Lavender, Coral and Olive, for players and AI in skirmish, LAN and online. They replace Crimson, Azure and Salmon.
## Your queue in pictures again
diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifest
index 0668a4ef7..56f203c86 100644
--- a/GeneralsMD/Code/BuildFingerprint.manifest
+++ b/GeneralsMD/Code/BuildFingerprint.manifest
@@ -14,6 +14,7 @@ Data/Art/Textures/ReforgedFactionTurkiye.tga
Data/Art/Textures/ReforgedForceAttack.tga
Data/Art/Textures/ReforgedGuardCentre.tga
Data/Art/Textures/ReforgedGuardRing.tga
+Data/Art/Textures/ReforgedGuardShield.tga
Data/Art/Textures/ReforgedHudAmericaCommandBar.dds
Data/Art/Textures/ReforgedHudAmericaPowers.dds
Data/Art/Textures/ReforgedHudAmericaTabPanel.dds
@@ -347,6 +348,7 @@ Data/INI/MappedImages/HandCreated/ReforgedBarChinaBeacon.ini
Data/INI/MappedImages/HandCreated/ReforgedFactionEmblems.ini
Data/INI/MappedImages/HandCreated/ReforgedFactionPicker.ini
Data/INI/MappedImages/HandCreated/ReforgedForceAttack.ini
+Data/INI/MappedImages/HandCreated/ReforgedGuardShield.ini
Data/INI/MappedImages/HandCreated/ReforgedHudAmericaCommandBar.ini
Data/INI/MappedImages/HandCreated/ReforgedHudAmericaPowers.ini
Data/INI/MappedImages/HandCreated/ReforgedHudAmericaTabPanel.ini
@@ -448,6 +450,7 @@ Data/Scenarios/glowmicrowave.txt
Data/Scenarios/gpu1m_battle.txt
Data/Scenarios/guardair.txt
Data/Scenarios/guardradius.txt
+Data/Scenarios/guardshields.txt
Data/Scenarios/gunfx.txt
Data/Scenarios/handicap.txt
Data/Scenarios/headlights.txt
diff --git a/GeneralsMD/Code/Data/Art/Textures/ReforgedGuardShield.tga b/GeneralsMD/Code/Data/Art/Textures/ReforgedGuardShield.tga
new file mode 100644
index 000000000..9f70b8cc9
Binary files /dev/null and b/GeneralsMD/Code/Data/Art/Textures/ReforgedGuardShield.tga differ
diff --git a/GeneralsMD/Code/Data/INI/MappedImages/HandCreated/ReforgedGuardShield.ini b/GeneralsMD/Code/Data/INI/MappedImages/HandCreated/ReforgedGuardShield.ini
new file mode 100644
index 000000000..3076ce693
--- /dev/null
+++ b/GeneralsMD/Code/Data/INI/MappedImages/HandCreated/ReforgedGuardShield.ini
@@ -0,0 +1,283 @@
+; The shield over a guarding unit's head (Tools/hud_command_bar.py guard_shield, W3DInGameUI::drawGuardMarkers):
+; GuardShield<h> for every whole height h from 6 to 40, each drawn texel for pixel. Uncompressed, so the edges
+; keep the coverage the old row-by-row fill gave them.
+
+MappedImage GuardShield6
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:4 Top:4 Right:13 Bottom:11
+ Status = NONE
+End
+
+MappedImage GuardShield7
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:17 Top:4 Right:26 Bottom:12
+ Status = NONE
+End
+
+MappedImage GuardShield8
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:30 Top:4 Right:41 Bottom:13
+ Status = NONE
+End
+
+MappedImage GuardShield9
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:45 Top:4 Right:56 Bottom:14
+ Status = NONE
+End
+
+MappedImage GuardShield10
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:60 Top:4 Right:71 Bottom:15
+ Status = NONE
+End
+
+MappedImage GuardShield11
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:75 Top:4 Right:88 Bottom:16
+ Status = NONE
+End
+
+MappedImage GuardShield12
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:92 Top:4 Right:107 Bottom:17
+ Status = NONE
+End
+
+MappedImage GuardShield13
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:111 Top:4 Right:126 Bottom:18
+ Status = NONE
+End
+
+MappedImage GuardShield14
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:130 Top:4 Right:145 Bottom:19
+ Status = NONE
+End
+
+MappedImage GuardShield15
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:149 Top:4 Right:166 Bottom:20
+ Status = NONE
+End
+
+MappedImage GuardShield16
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:170 Top:4 Right:187 Bottom:21
+ Status = NONE
+End
+
+MappedImage GuardShield17
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:191 Top:4 Right:210 Bottom:22
+ Status = NONE
+End
+
+MappedImage GuardShield18
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:214 Top:4 Right:233 Bottom:23
+ Status = NONE
+End
+
+MappedImage GuardShield19
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:237 Top:4 Right:258 Bottom:24
+ Status = NONE
+End
+
+MappedImage GuardShield20
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:262 Top:4 Right:283 Bottom:26
+ Status = NONE
+End
+
+MappedImage GuardShield21
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:287 Top:4 Right:310 Bottom:27
+ Status = NONE
+End
+
+MappedImage GuardShield22
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:314 Top:4 Right:337 Bottom:28
+ Status = NONE
+End
+
+MappedImage GuardShield23
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:341 Top:4 Right:366 Bottom:29
+ Status = NONE
+End
+
+MappedImage GuardShield24
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:370 Top:4 Right:397 Bottom:30
+ Status = NONE
+End
+
+MappedImage GuardShield25
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:401 Top:4 Right:428 Bottom:31
+ Status = NONE
+End
+
+MappedImage GuardShield26
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:432 Top:4 Right:459 Bottom:32
+ Status = NONE
+End
+
+MappedImage GuardShield27
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:463 Top:4 Right:492 Bottom:33
+ Status = NONE
+End
+
+MappedImage GuardShield28
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:4 Top:37 Right:33 Bottom:67
+ Status = NONE
+End
+
+MappedImage GuardShield29
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:37 Top:37 Right:68 Bottom:68
+ Status = NONE
+End
+
+MappedImage GuardShield30
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:72 Top:37 Right:103 Bottom:70
+ Status = NONE
+End
+
+MappedImage GuardShield31
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:107 Top:37 Right:140 Bottom:71
+ Status = NONE
+End
+
+MappedImage GuardShield32
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:144 Top:37 Right:177 Bottom:72
+ Status = NONE
+End
+
+MappedImage GuardShield33
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:181 Top:37 Right:216 Bottom:73
+ Status = NONE
+End
+
+MappedImage GuardShield34
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:220 Top:37 Right:255 Bottom:74
+ Status = NONE
+End
+
+MappedImage GuardShield35
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:259 Top:37 Right:296 Bottom:75
+ Status = NONE
+End
+
+MappedImage GuardShield36
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:300 Top:37 Right:337 Bottom:76
+ Status = NONE
+End
+
+MappedImage GuardShield37
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:341 Top:37 Right:380 Bottom:77
+ Status = NONE
+End
+
+MappedImage GuardShield38
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:384 Top:37 Right:423 Bottom:78
+ Status = NONE
+End
+
+MappedImage GuardShield39
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:427 Top:37 Right:468 Bottom:79
+ Status = NONE
+End
+
+MappedImage GuardShield40
+ Texture = ReforgedGuardShield.tga
+ TextureWidth = 512
+ TextureHeight = 256
+ Coords = Left:4 Top:83 Right:45 Bottom:127
+ Status = NONE
+End
diff --git a/GeneralsMD/Code/Data/Scenarios/guardshields.txt b/GeneralsMD/Code/Data/Scenarios/guardshields.txt
new file mode 100644
index 000000000..71782e7f8
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/guardshields.txt
@@ -0,0 +1,15 @@
+# What the guard markers cost (GitHub #165): three hundred Rangers of the local player on guard round his
+# command center, every one wearing the shield over his head, in front of the opening camera.
+#
+# generals.exe -quickstart -noshellmap -multiInstance -map "Maps\Tournament Desert\Tournament Desert.map"
+# -autoskirmish 2 -takeover -side 0 FactionAmerica -side 1 FactionChina -seed 8 -noFPSLimit
+# -borderless -xres 1920 -yres 1080 -msaa 0 -maxframes 3000 -scenario guardshields -logPrefix guard_
+#
+# Read HEADLESS FRAMETIME from the log; the shields are drawn from frame 61 on.
+#
+# See mobstress.txt for the line grammar.
+
+30 spawn 0 AmericaInfantryRanger 100 start0:-250:-150 18
+30 spawn 0 AmericaInfantryRanger 100 start0:0:-250 18
+30 spawn 0 AmericaInfantryRanger 100 start0:250:-150 18
+60 guard 0 AmericaInfantryRanger 0 AmericaCommandCenter
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
index 3951eeb11..8ef1c2437 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
@@ -1271,50 +1271,6 @@ void W3DInGameUI::drawAttackCircle( void )
} // end drawAttackCircle
-//-------------------------------------------------------------------------------------------------
-/** One screen row from `left` to `right`, the two end pixels at the share of them the span covers,
- * so a slanted edge fades across a pixel instead of stepping. */
-//-------------------------------------------------------------------------------------------------
-static void drawCoveredSpan( Real left, Real right, Int y, UnsignedInt color )
-{
- if( right <= left )
- return;
- const UnsignedInt rgb = color & 0x00FFFFFF;
- const Real alpha = (Real)( color >> 24 );
- const Int first = (Int)floorf( left );
- const Int last = (Int)floorf( right );
- if( first == last )
- {
- TheDisplay->drawFillRect( first, y, 1, 1, rgb | ( REAL_TO_INT( alpha * ( right - left ) ) << 24 ) );
- return;
- }
- TheDisplay->drawFillRect( first, y, 1, 1, rgb | ( REAL_TO_INT( alpha * ( first + 1 - left ) ) << 24 ) );
- if( last > first + 1 )
- TheDisplay->drawFillRect( first + 1, y, last - first - 1, 1, color );
- if( right > last )
- TheDisplay->drawFillRect( last, y, 1, 1, rgb | ( REAL_TO_INT( alpha * ( right - last ) ) << 24 ) );
-}
-
-//-------------------------------------------------------------------------------------------------
-/** A heater shield centred on `centreX`, filled one screen row at a time: straight sides for the
- * upper part, then a curve closing to the point at the bottom. The left half takes `leftColor`
- * and the right half `rightColor`, which with a light and a darker steel reads as a raised
- * centre ridge with the light from the left. */
-//-------------------------------------------------------------------------------------------------
-static void drawShieldShape( Real centreX, Int top, Real width, Int height, UnsignedInt leftColor, UnsignedInt rightColor )
-{
- const Real SHOULDER = 0.4f; // share of the height above the taper
- for( Int row = 0; row < height; ++row )
- {
- const Real t = ( row + 0.5f ) / height;
- Real half = width * 0.5f;
- if( t > SHOULDER )
- half *= sqrtf( ( 1.0f - t ) / ( 1.0f - SHOULDER ) );
- drawCoveredSpan( centreX - half, centreX, top + row, leftColor );
- drawCoveredSpan( centreX, centreX + half, top + row, rightColor );
- }
-}
-
//-------------------------------------------------------------------------------------------------
/** Player::iterateObjects callback: the spot over the head of one of the local player's guards, into
* the vector of them. */
@@ -1347,10 +1303,7 @@ void W3DInGameUI::drawGuardMarkers( void )
const Real MARKER_HEIGHT = 10.0f; // at 800x600 and zoom 1, a little closer than the opening camera
const Real MARKER_MIN_HEIGHT = 6.0f;
const Real MARKER_MAX_HEIGHT = 10.0f;
- const UnsignedInt SHADOW_COLOR = 0x60000000; // lifts it off snow and sand alike
- const UnsignedInt EDGE_COLOR = 0xE00C1014;
- const UnsignedInt LIT_COLOR = 0xF0E8EEF4; // the command bar's steel, the side facing the light
- const UnsignedInt SHADED_COLOR = 0xF0939FAC;
+ const Int TALLEST_SHIELD = 40; // GUARD_HEIGHTS' last, 10 x 4K's UI scale; taller ones stretch it
if( !TheGameLogic->isInGame() || TheGameLogic->isInShellGame() )
return;
@@ -1358,9 +1311,20 @@ void W3DInGameUI::drawGuardMarkers( void )
const Real uiScale = TheUIScale();
const Real size = MARKER_HEIGHT * uiScale / TheTacticalView->getZoom();
const Int height = REAL_TO_INT( max( MARKER_MIN_HEIGHT * uiScale, min( MARKER_MAX_HEIGHT * uiScale, size ) ) );
- const Real width = height * 0.8f;
const Int lift = height / 2; // clear of the health bar's line over the model's top
- const Real rim = max( 1.0f, height / 10.0f );
+
+ // One picture a guard, GuardShield<h> (ReforgedGuardShield, Tools/hud_command_bar.py guard_shield): the
+ // heater shield, its dark edge, lit and shaded halves and drop shadow exactly as the rows of covered spans
+ // drew them, which cost 60 to 180 rectangles a guard every picture (GitHub #165). It is drawn texel for
+ // pixel, 2K + 1 wide round the shield's pixel column (K = ceil(rim + width / 2)) and h + inset high.
+ const Int drawn = min( height, TALLEST_SHIELD );
+ AsciiString name;
+ name.format( "GuardShield%d", drawn );
+ const Image *shield = TheMappedImageCollection->findImageByName( name );
+ const Real rim = max( 1.0f, drawn / 10.0f );
+ const Real stretch = (Real)height / drawn;
+ const Int imageWidth = REAL_TO_INT( ( 2 * (Int)ceilf( rim + drawn * 0.4f ) + 1 ) * stretch );
+ const Int imageHeight = REAL_TO_INT( ( drawn + (Int)rim ) * stretch );
// Who stands guard, and where, moves only with a tick, so the walk runs once a logic frame; it ran
// on every pass and was most of what this method cost. Only the camera is this pass's, except under
@@ -1392,12 +1356,9 @@ void W3DInGameUI::drawGuardMarkers( void )
if( !TheTacticalView->worldToScreen( &top, &spot ) )
continue;
- const Real centreX = spot.x + 0.5f;
+ const Int left = spot.x - imageWidth / 2;
const Int y = spot.y - lift - height;
- const Int inset = REAL_TO_INT( rim );
- drawShieldShape( centreX + rim, y + inset, width, height, SHADOW_COLOR, SHADOW_COLOR );
- drawShieldShape( centreX, y, width, height, EDGE_COLOR, EDGE_COLOR );
- drawShieldShape( centreX, y + inset, width - 2.0f * rim, height - 3 * inset, LIT_COLOR, SHADED_COLOR );
+ TheDisplay->drawImage( shield, left, y, left + imageWidth, y + imageHeight );
}
} // end drawGuardMarkers
diff --git a/GeneralsMD/Code/Tools/hud_command_bar.py b/GeneralsMD/Code/Tools/hud_command_bar.py
index 63517ac49..2203dd784 100644
--- a/GeneralsMD/Code/Tools/hud_command_bar.py
+++ b/GeneralsMD/Code/Tools/hud_command_bar.py
@@ -3296,9 +3296,99 @@ def check_sheet(sheet_img, side_name, glow="B"):
assert g[-1, :, 0].min() >= 240, "%sHudReadyGlow's bottom row is not white" % pre
+# ---------------------------------------------------------------------------------------------- the guard shield
+
+# The shield over a guarding unit's head (W3DInGameUI::drawGuardMarkers, GitHub #165). It used to be filled one
+# screen row at a time, three shapes of covered spans, 60 to 180 rectangles a unit a picture; now it is one
+# picture, GuardShield<h> for every whole height h the code asks for, drawn texel for pixel. guard_shield
+# rebuilds the old fill exactly: the same rows, the same covered ends, the same colours laid on in the same
+# order, so the picture over the field is the one the rectangles made. A sprite is 2K+1 wide round the
+# pixel column the shield is centred on (K = ceil(rim + width / 2)), h + inset high from the shield's top.
+GUARD_HEIGHTS = range(6, 41) # 6 x UI scale (1.0) to 10 x 4K's 3.6, rounded up
+GUARD_SHOULDER = 0.4
+GUARD_SHADOW, GUARD_EDGE, GUARD_LIT, GUARD_SHADED = 0x60000000, 0xE00C1014, 0xF0E8EEF4, 0xF0939FAC
+GUARD_SHEET = (512, 256)
+
+
+def guard_geometry(h):
+ """The shield's width, rim and inset at height h, as drawGuardMarkers works them out."""
+ width = h * 0.8
+ rim = max(1.0, h / 10.0)
+ return width, rim, int(rim)
+
+
+def guard_shield(h):
+ width, rim, inset = guard_geometry(h)
+ k = int(np.ceil(rim + width / 2))
+ w, hh = 2 * k + 1, h + inset
+ premul = np.zeros((hh, w, 4), np.float64) # rgb times alpha, and alpha, laid on rectangle by rectangle
+
+ def fill(x, y, n, colour, alpha):
+ if alpha <= 0:
+ return
+ a = alpha / 255.0
+ rgb = np.array([(colour >> 16) & 255, (colour >> 8) & 255, colour & 255], np.float64) / 255.0
+ cell = premul[y, x:x + n]
+ cell[:, :3] = rgb * a + cell[:, :3] * (1 - a)
+ cell[:, 3] = a + cell[:, 3] * (1 - a)
+
+ def span(left, right, y, colour): # drawCoveredSpan
+ if right <= left:
+ return
+ alpha = colour >> 24
+ first, last = int(np.floor(left)), int(np.floor(right))
+ if first == last:
+ fill(first, y, 1, colour, int(alpha * (right - left)))
+ return
+ fill(first, y, 1, colour, int(alpha * (first + 1 - left)))
+ if last > first + 1:
+ fill(first + 1, y, last - first - 1, colour, alpha)
+ if right > last:
+ fill(last, y, 1, colour, int(alpha * (right - last)))
+
+ def shape(centre, top, wd, ht, left_colour, right_colour): # drawShieldShape
+ for row in range(ht):
+ t = (row + 0.5) / ht
+ half = wd * 0.5
+ if t > GUARD_SHOULDER:
+ half *= np.sqrt((1.0 - t) / (1.0 - GUARD_SHOULDER))
+ span(centre - half, centre, top + row, left_colour)
+ span(centre, centre + half, top + row, right_colour)
+
+ centre = k + 0.5
+ shape(centre + rim, inset, width, h, GUARD_SHADOW, GUARD_SHADOW)
+ shape(centre, 0, width, h, GUARD_EDGE, GUARD_EDGE)
+ shape(centre, inset, width - 2.0 * rim, h - 3 * inset, GUARD_LIT, GUARD_SHADED)
+ a = premul[..., 3:]
+ rgb = np.where(a > 0, premul[..., :3] / np.maximum(a, 1e-9), 0)
+ return Image.fromarray((np.concatenate([rgb, a], axis=2) * 255).round().astype(np.uint8), "RGBA")
+
+
+def guard_boxes():
+ """GuardShield<h> -> its box on the sheet, shelf-packed left to right, 4 texels apart."""
+ boxes, x, y, row = {}, 4, 4, 0
+ for h in GUARD_HEIGHTS:
+ width, rim, inset = guard_geometry(h)
+ w, hh = 2 * int(np.ceil(rim + width / 2)) + 1, h + inset
+ if x + w + 4 > GUARD_SHEET[0]:
+ x, y, row = 4, y + row + 4, 0
+ boxes["GuardShield%d" % h] = (x, y, x + w, y + hh)
+ x, row = x + w + 4, max(row, hh)
+ assert y + row + 4 <= GUARD_SHEET[1], "the guard shields overflow their sheet"
+ return boxes
+
+
+def paint_guard_shields():
+ sheet_img = Image.new("RGBA", GUARD_SHEET, (0, 0, 0, 0))
+ for name, box in guard_boxes().items():
+ put(sheet_img, guard_shield(int(name[len("GuardShield"):])), box)
+ assert read_mapped(None, name="ReforgedGuardShield") == guard_boxes(), "ReforgedGuardShield.ini is not the generator's layout"
+ return sheet_img
+
+
def main():
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
- ap.add_argument("--side", default="all", choices=["all", "Observer", "Lobby"] + sorted(SIDES))
+ ap.add_argument("--side", default="all", choices=["all", "Observer", "Lobby", "Guard"] + sorted(SIDES))
ap.add_argument("--out", required=True, help="where the PNGs go")
ap.add_argument("--dds", help="Data/Art/Textures, to write the DXT5 textures too")
ap.add_argument("--emblem", default=EMBLEM_SVG)
@@ -3306,9 +3396,15 @@ def main():
help="a charged superweapon's light: B, the breath and a rising band (default, ships), or A, the breath alone")
args = ap.parse_args()
os.makedirs(args.out, exist_ok=True)
- for side in (list(SIDES) + ["Observer", "Lobby"] if args.side == "all" else [args.side]):
+ for side in (list(SIDES) + ["Observer", "Lobby", "Guard"] if args.side == "all" else [args.side]):
made = {}
- if side == "Lobby":
+ if side == "Guard": # uncompressed: DXT5 would smear its covered edges
+ shields = paint_guard_shields()
+ shields.save(os.path.join(args.out, "ReforgedGuardShield.png"))
+ if args.dds:
+ shields.save(os.path.join(args.dds, "ReforgedGuardShield.tga"))
+ print("wrote ReforgedGuardShield")
+ elif side == "Lobby":
made = {"ReforgedFactionEmblems": paint_faction_emblems()}
elif side == "Observer":
bar, panel = paint_observer_bar(), paint_observer_panel()