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): one laser glow texture, no glow lines with glow off

Olcay Seygan05be1f8353ae
diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifest
index 56f203c86..310fc1263 100644
--- a/GeneralsMD/Code/BuildFingerprint.manifest
+++ b/GeneralsMD/Code/BuildFingerprint.manifest
@@ -484,6 +484,7 @@ Data/Scenarios/jetrunway.txt
Data/Scenarios/jetsturn.txt
Data/Scenarios/jetturn.txt
Data/Scenarios/kargu.txt
+Data/Scenarios/laserdefense.txt
Data/Scenarios/laserglow.txt
Data/Scenarios/laserlook.txt
Data/Scenarios/leadinfantry.txt
diff --git a/GeneralsMD/Code/Data/Scenarios/laserdefense.txt b/GeneralsMD/Code/Data/Scenarios/laserdefense.txt
new file mode 100644
index 000000000..e63bf4a7a
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/laserdefense.txt
@@ -0,0 +1,77 @@
+# Two Laser General Laser Defense turrets (Lazr_AmericaPatriotBattery) on Winter Wolf's open snow,
+# firing at a stream of unarmed Radar Vans that drive into their reach two at a time every two
+# seconds, for the frame time of laser beams (GitHub #150, #157). glowbase.txt's ground, so the
+# structures stand, and three power plants, since each turret takes 5. Draws, so -win, with
+# Bloom = 0 or 2 in the Options.ini of a ZH_USER_DATA_DIR of its own for each run:
+#
+# generals.exe -win -xres 1920 -yres 1080 -quickstart -noshellmap -observer -multiInstance
+# -noFPSLimit -map "Maps\Winter Wolf\Winter Wolf.map" -autoskirmish 2 -takeover
+# -side 0 FactionAmerica -side 1 FactionGLA -seed 7 -camera 1400 1120
+# -scenario laserdefense -maxframes 3900 -logPrefix laserdefense_
+
+20 spawn 0 AmericaPowerPlant 3 950 980 90
+20 spawn 0 Lazr_AmericaPatriotBattery 1 1320 1000
+20 spawn 0 Lazr_AmericaPatriotBattery 1 1320 1240
+60 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+61 move 1 GLAVehicleRadarVan 1480 1120
+120 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+121 move 1 GLAVehicleRadarVan 1480 1120
+180 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+181 move 1 GLAVehicleRadarVan 1480 1120
+240 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+241 move 1 GLAVehicleRadarVan 1480 1120
+300 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+301 move 1 GLAVehicleRadarVan 1480 1120
+360 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+361 move 1 GLAVehicleRadarVan 1480 1120
+420 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+421 move 1 GLAVehicleRadarVan 1480 1120
+480 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+481 move 1 GLAVehicleRadarVan 1480 1120
+540 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+541 move 1 GLAVehicleRadarVan 1480 1120
+600 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+601 move 1 GLAVehicleRadarVan 1480 1120
+660 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+661 move 1 GLAVehicleRadarVan 1480 1120
+720 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+721 move 1 GLAVehicleRadarVan 1480 1120
+780 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+781 move 1 GLAVehicleRadarVan 1480 1120
+840 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+841 move 1 GLAVehicleRadarVan 1480 1120
+900 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+901 move 1 GLAVehicleRadarVan 1480 1120
+960 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+961 move 1 GLAVehicleRadarVan 1480 1120
+1020 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+1021 move 1 GLAVehicleRadarVan 1480 1120
+1080 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+1081 move 1 GLAVehicleRadarVan 1480 1120
+1140 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+1141 move 1 GLAVehicleRadarVan 1480 1120
+1200 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+1201 move 1 GLAVehicleRadarVan 1480 1120
+1260 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+1261 move 1 GLAVehicleRadarVan 1480 1120
+1320 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+1321 move 1 GLAVehicleRadarVan 1480 1120
+1380 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+1381 move 1 GLAVehicleRadarVan 1480 1120
+1440 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+1441 move 1 GLAVehicleRadarVan 1480 1120
+1500 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+1501 move 1 GLAVehicleRadarVan 1480 1120
+1560 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+1561 move 1 GLAVehicleRadarVan 1480 1120
+1620 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+1621 move 1 GLAVehicleRadarVan 1480 1120
+1680 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+1681 move 1 GLAVehicleRadarVan 1480 1120
+1740 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+1741 move 1 GLAVehicleRadarVan 1480 1120
+1800 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+1801 move 1 GLAVehicleRadarVan 1480 1120
+1860 spawn 1 GLAVehicleRadarVan 2 1750 1120 40
+1861 move 1 GLAVehicleRadarVan 1480 1120
+1940 tally 1 GLAVehicleRadarVan
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp
index 017f0f623..cc1f813e7 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp
@@ -169,8 +169,6 @@ static void markBeamSeen( DrawableID parent, DrawableID target, UnsignedInt now
s_beamsSeen[ slot ].ms = now;
}
-static TextureClass *s_glowTexture = NULL;
-
// ponytail: chosen by template name so no INI field and no checksum change; a "Glow" field in
// W3DLaserDraw is the upgrade if a beam ever needs it on its own. Every weapon laser in ZH ends in
// LaserBeam; the data streams, the waypoint line and the Particle Cannon's beams do not. The
@@ -202,41 +200,43 @@ static Real glowTexel( Real across, Real along )
return glowFalloff( across ) * glowFalloff( MAX( cap, 0.0f ) );
}
-// u is -1..1 across the beam, v 0..1 along it
-static TextureClass *acquireGlowTexture()
+// The texture belongs to the asset manager, under a name no file has, which lets it go with the
+// unused textures between maps and with the rest at shutdown. Made and freed with the beams, as it
+// was, a lone turret's beam was gone before its next shot and every shot built a Direct3D 9 texture
+// and its Direct3D 11 copy again: 134 of them in a minute of two Laser Defense turrets firing.
+static const char *GLOW_TEXTURE_NAME = "zhr_laserglow";
+
+// u is -1..1 across the beam, v 0..1 along it; each line takes its own reference
+static TextureClass *peekGlowTexture()
{
- if( !s_glowTexture )
+ HashTemplateClass<StringClass,TextureClass*> &textures = WW3DAssetManager::Get_Instance()->Texture_Hash();
+ TextureClass *texture = textures.Get( GLOW_TEXTURE_NAME );
+ if( texture )
+ return texture;
+
+ // the one reference it is made with is the asset manager's
+ texture = MSGNEW("TextureClass") TextureClass( GLOW_TEXTURE_SIZE, GLOW_TEXTURE_SIZE, WW3D_FORMAT_A8R8G8B8, MIP_LEVELS_1 );
+ SurfaceClass *surf = texture->Get_Surface_Level();
+ Int pitch;
+ UnsignedByte *pData = (UnsignedByte*)surf->Lock( &pitch );
+ for( Int y = 0; y < GLOW_TEXTURE_SIZE; y++ )
{
- s_glowTexture = MSGNEW("TextureClass") TextureClass( GLOW_TEXTURE_SIZE, GLOW_TEXTURE_SIZE, WW3D_FORMAT_A8R8G8B8, MIP_LEVELS_1 );
- SurfaceClass *surf = s_glowTexture->Get_Surface_Level();
- Int pitch;
- UnsignedByte *pData = (UnsignedByte*)surf->Lock( &pitch );
- for( Int y = 0; y < GLOW_TEXTURE_SIZE; y++ )
+ Real along = ( y + 0.5f ) / GLOW_TEXTURE_SIZE;
+ UnsignedInt *row = (UnsignedInt*)( pData + y * pitch );
+ for( Int x = 0; x < GLOW_TEXTURE_SIZE; x++ )
{
- Real along = ( y + 0.5f ) / GLOW_TEXTURE_SIZE;
- UnsignedInt *row = (UnsignedInt*)( pData + y * pitch );
- for( Int x = 0; x < GLOW_TEXTURE_SIZE; x++ )
- {
- Real across = ( x + 0.5f ) / GLOW_TEXTURE_SIZE * 2.0f - 1.0f;
- UnsignedInt c = (UnsignedInt)( glowTexel( across, along ) * 255.0f + 0.5f );
- row[ x ] = ( c << 24 ) | ( c << 16 ) | ( c << 8 ) | c;
- }
+ Real across = ( x + 0.5f ) / GLOW_TEXTURE_SIZE * 2.0f - 1.0f;
+ UnsignedInt c = (UnsignedInt)( glowTexel( across, along ) * 255.0f + 0.5f );
+ row[ x ] = ( c << 24 ) | ( c << 16 ) | ( c << 8 ) | c;
}
- surf->Unlock();
- REF_PTR_RELEASE( surf );
- s_glowTexture->Get_Filter().Set_U_Addr_Mode( TextureFilterClass::TEXTURE_ADDRESS_CLAMP );
- s_glowTexture->Get_Filter().Set_V_Addr_Mode( TextureFilterClass::TEXTURE_ADDRESS_CLAMP );
}
- s_glowTexture->Add_Ref();
- return s_glowTexture;
-}
-
-static void releaseGlowTexture()
-{
- // the static pointer holds one reference of its own; the last beam takes it with it
- s_glowTexture->Release_Ref();
- if( s_glowTexture->Num_Refs() == 1 )
- REF_PTR_RELEASE( s_glowTexture );
+ surf->Unlock();
+ REF_PTR_RELEASE( surf );
+ texture->Get_Filter().Set_U_Addr_Mode( TextureFilterClass::TEXTURE_ADDRESS_CLAMP );
+ texture->Get_Filter().Set_V_Addr_Mode( TextureFilterClass::TEXTURE_ADDRESS_CLAMP );
+ texture->Set_Texture_Name( GLOW_TEXTURE_NAME );
+ textures.Insert( texture->Get_Texture_Name(), texture );
+ return texture;
}
// A flicker of one on average, varying by up to depth: a value per FLICKER_STEP_MS for each seed,
@@ -500,10 +500,10 @@ void W3DLaserDraw::buildRenderObjects( Bool madeInTick )
} //end segment loop
- if( beamGlows( getDrawable() ) )
+ // Off (and Classic) is EA's beam alone, so a beam fired then makes none of the glow's lines
+ if( beamGlows( getDrawable() ) && glowStrength() > 0.0f )
{
- // this beam's reference on the texture is given back by releaseGlowTexture in the destructor
- TextureClass *glowTexture = acquireGlowTexture();
+ TextureClass *glowTexture = peekGlowTexture();
const Int glowCount = (Int)data->m_segments * GLOW_LAYERS;
m_glow3D = NEW SegmentedLineClass *[ glowCount ];
@@ -562,7 +562,6 @@ W3DLaserDraw::~W3DLaserDraw( void )
W3DDisplay::m_3DScene->Remove_Render_Object( m_flare3D[ f ] );
REF_PTR_RELEASE( m_flare3D[ f ] );
}
- releaseGlowTexture();
}
}
@@ -865,7 +864,7 @@ void W3DLaserDraw::drawGlow( Real widthScale, Real sinceArrivalMs )
const Real brightness = MIN( glowStrength(), 1.0f );
if( brightness <= 0.0f )
{
- // Off: EA's beam alone, as it was
+ // Off since this beam was made: EA's beam alone, as it was
for( Int g = 0; g < (Int)data->m_segments * GLOW_LAYERS; g++ )
m_glow3D[ g ]->Set_Color( Vector3( 0.0f, 0.0f, 0.0f ) );
for( Int f = 0; f < FLARE_COUNT; f++ )