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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(w3ddevice): soft orange glow around machine-gun tracers
Olcay Seyganc6b002364878
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f29363646..07ee00ab0 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -519,6 +519,7 @@ found and fixed, EA's own, not port damage.**- Artillery lands on time. The Fire Base, the Inferno Cannon, the Nuke Cannon and the campaign's battleships fire like real guns now: the shell flies a true arc and comes down the same time after it left at any range, 1.2 seconds for a Fire Base and 1.6 for the Inferno and Nuke Cannons, and the gun raises its barrel to that arc before it fires. A target close in gets a steep lob from a barrel near upright (a Fire Base fires at 57 degrees on a 108 shot, an Inferno at 77 on a 55 one), a far one a flatter shot (34 degrees at 225, 49 at 235), and the drawn barrel and the shell's way out agree to under a degree. Each flight time is the old shot's average over the gun's range, so a tank has as long to drive out from under it as it had, and a shell still follows a target that keeps moving. Before this the barrel's angle and the arc came from two places and never met. The Fire Base's howitzer fires the tanks' shell, so when tank shells went straight it fired flat under a barrel 46 degrees up; the Inferno's barrel sat at 45 whatever the range. The battleships fired from a point 65 past their front guns and from under the waterline behind them, and both turrets aimed for the front gun; every shell now leaves its own drawn muzzle. A Technical's cannon shell left 17 in front of its gun and now leaves the gun. Tank shells still fly straight.- A SCUD or a Tomahawk flies one smooth curve to its target. A SCUD went straight up, flipped over the top at six degrees a frame, glided flat for a moment and then kinked again into its dive. Now it rolls over and comes down in a single sweep that only ever eases off, its sharpest turn 4.6 degrees a frame. The Scud Storm takes the same curve and lands within half a second of when it did. Replays recorded before this play back differently.- Machine gun fire looks fast. The tracers of a Humvee, a Technical or a Quad Cannon crawled across the field at 300 a second and took half a second to reach a target 150 away; they now cross it in a tenth of a second, at 1,500, as streaks twice as long. Rangers, Rebels, Gattling Tanks and Cannons, Comanches and the Spectre got the same treatment. Only the picture changed: every bullet lands when it always did.+- Tracers glow. Each machine gun round keeps EA's streak and adds a soft orange glow around it, strongest at the head of the round and thinning toward its tail. Glow at Off, or Classic Graphics, gives you EA's streak alone.## Point defense lasers back on the planes, in clips on the tanksdiff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DTracerDraw.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DTracerDraw.hindex 00c86a4ce..55901af52 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DTracerDraw.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DTracerDraw.h@@ -15,6 +15,7 @@** You should have received a copy of the GNU General Public License** along with this program. If not, see <http://www.gnu.org/licenses/>.*/+// Modified 2026 by Olcay Seygan for Zero Hour Reforged; see the git history.// Modified 2026 by İlyas Akın for the macOS/Linux port; see NOTICE.md and the git history.////////////////////////////////////////////////////////////////////////////////@@ -37,6 +38,8 @@#include "Common/DrawModule.h"#include "WW3D2/line3d.h"+class SegmentedLineClass;+//-------------------------------------------------------------------------------------------------/** W3D tracer draw *///-------------------------------------------------------------------------------------------------@@ -66,7 +69,13 @@ public:protected:+ void createTracer( const Matrix3D &mtx );+ void shapeTracer( void ); ///< length, width and colour onto the tracer and its halo+ void lightTracer( void ); ///< the opacity onto them+ void placeTracer( const Matrix3D &mtx );+Line3DClass *m_theTracer; ///< the tracer render object in the W3D scene+ SegmentedLineClass *m_glow; ///< the Glow option's halo round it, NULL with the option offReal m_length; ///< length of tracerReal m_width; ///< width of tracerRGBColor m_color; ///< color of tracerdiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTracerDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTracerDraw.cppindex 601baec5a..828c901f1 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTracerDraw.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTracerDraw.cpp@@ -15,6 +15,7 @@** You should have received a copy of the GNU General Public License** along with this program. If not, see <http://www.gnu.org/licenses/>.*/+// Modified 2026 by Olcay Seygan for Zero Hour Reforged; see the git history.// Modified 2026 by İlyas Akın for the macOS/Linux port; see NOTICE.md and the git history.////////////////////////////////////////////////////////////////////////////////@@ -31,6 +32,7 @@// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////#include <stdlib.h>+#include "Common/GlobalData.h"#include "Common/Thing.h"#include "Common/ThingTemplate.h"#include "Common/Xfer.h"@@ -40,6 +42,9 @@#include "W3DDevice/GameClient/W3DDisplay.h"#include "W3DDevice/GameClient/Module/W3DTracerDraw.h"#include "WW3D2/line3d.h"+#include "WW3D2/segline.h"+#include "WW3D2/surfaceclass.h"+#include "WW3D2/texture.h"#include "W3DDevice/GameClient/W3DScene.h"#ifdef _INTERNAL@@ -48,6 +53,69 @@//#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")#endif+// GLOWING TRACERS ////////////////////////////////////////////////////////////////////////////////+// With the Glow option on, EA's tracer is drawn as it always was and a halo goes round it, the way+// C&C 3 draws its tracers: a strip turned to face the camera, a soft falloff across it and a fade+// along it, brightest at the head. The halo is added to what is behind it, in the tracer's INI+// colour run toward orange, and opted into the Direct3D 11 glow gain. Inside EA's box it adds+// nothing, since the box is opaque and nearer the eye than the strip through its axis.+// EA's streak is the floor. The try before this (2026-11-06) replaced the box with a blended core+// and a faint halo, both shaped by the texture: across, the falloff averages 0.43 of its peak, along,+// a fade to the power 1.5 averages 0.4, so the two together carried 0.17 of what the constants said,+// and a core two to four pixels wide sampled the shoulders of its profile, not its peak. Shot on a+// desert map the tracer was gone, the ground lifted by about 16 for two logic frames. Glow at Off,+// or Classic Graphics, draws EA's box alone. Draw side only: nothing here is read by GameLogic or+// parsed from INI.+static const Real TRACER_HALO_WIDTH_SCALE = 6.0f; // over the INI width, 0.7 on Reforged's guns+static const Real TRACER_HALO_INTENSITY = 0.5f; // the halo's peak, at the head+static const Real TRACER_HALO_TAIL = 0.3f; // share of that left at the tail, the fade linear between+static const Vector3 TRACER_HALO_TINT( 1.0f, 0.6f, 0.25f ); // times the INI colour, most of which are white or cream+static const Real TRACER_HEAD_CAP = 0.06f; // share of the length that rounds off the head+static const Int TRACER_TEXTURE_SIZE = 64;++// ponytail: made by the first glowing tracer and kept for the process (64x64, 16 KB), since bursts+// come and go several times a second; a release at display shutdown if a leak report ever names it+static TextureClass *s_tracerTexture = NULL;++// one at the middle (0), zero at the edge (1)+static Real tracerFalloff( Real distance )+{+ const Real edge = expf( -4.0f );+ return MAX( ( expf( -4.0f * distance * distance ) - edge ) / ( 1.0f - edge ), 0.0f );+}++// across runs -1..1 over the strip's width, along 0 at the tail to 1 at the head+static Real tracerTexel( Real across, Real along )+{+ Real cap = ( along - ( 1.0f - TRACER_HEAD_CAP ) ) / TRACER_HEAD_CAP; // 0 where the head's cap starts, 1 at its tip+ Real fade = TRACER_HALO_TAIL + ( 1.0f - TRACER_HALO_TAIL ) * along;+ return tracerFalloff( across ) * fade * tracerFalloff( MAX( cap, 0.0f ) );+}++static TextureClass *makeTracerTexture( void )+{+ TextureClass *texture = MSGNEW("TextureClass") TextureClass( TRACER_TEXTURE_SIZE, TRACER_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 < TRACER_TEXTURE_SIZE; y++ )+ {+ Real along = ( y + 0.5f ) / TRACER_TEXTURE_SIZE;+ UnsignedInt *row = (UnsignedInt*)( pData + y * pitch );+ for( Int x = 0; x < TRACER_TEXTURE_SIZE; x++ )+ {+ Real across = ( x + 0.5f ) / TRACER_TEXTURE_SIZE * 2.0f - 1.0f;+ UnsignedInt c = (UnsignedInt)( tracerTexel( across, along ) * 255.0f + 0.5f );+ row[ x ] = ( c << 24 ) | ( c << 16 ) | ( c << 8 ) | c;+ }+ }+ 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 );+ return texture;+}+///////////////////////////////////////////////////////////////////////////////////////////////////// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////@@ -66,6 +134,7 @@ W3DTracerDraw::W3DTracerDraw( Thing *thing, const ModuleData* moduleData ) : Dram_color.blue = 0.7f;m_speedInDistPerFrame = 1.0f;m_theTracer = NULL;+ m_glow = NULL;} // end W3DTracerDraw@@ -78,15 +147,11 @@ void W3DTracerDraw::setTracerParms(Real speed, Real length, Real width, const RGm_width = width;m_color = color;m_opacity = initialOpacity;- if (m_theTracer)+ if( m_theTracer ){- Vector3 start( 0.0f, 0.0f, 0.0f );- Vector3 stop( m_length, 0.0f, 0.0f );- m_theTracer->Reset(start, stop, m_width);- m_theTracer->Re_Color(m_color.red, m_color.green, m_color.blue);- m_theTracer->Set_Opacity( m_opacity );+ shapeTracer();// these calls nuke the internal transform, so re-set it here- m_theTracer->Set_Transform( *getDrawable()->getTransformMatrix() );+ placeTracer( *getDrawable()->getTransformMatrix() );}}@@ -100,51 +165,114 @@ W3DTracerDraw::~W3DTracerDraw( void )W3DDisplay::m_3DScene->Remove_Render_Object( m_theTracer );REF_PTR_RELEASE( m_theTracer );}+ if( m_glow )+ {+ W3DDisplay::m_3DScene->Remove_Render_Object( m_glow );+ REF_PTR_RELEASE( m_glow );+ }}//--------------------------------------------------------------------------------------------------void W3DTracerDraw::reactToTransformChange( const Matrix3D *oldMtx,- const Coord3D *oldPos,+void W3DTracerDraw::reactToTransformChange( const Matrix3D *oldMtx,+ const Coord3D *oldPos,Real oldAngle ){- if( m_theTracer )- m_theTracer->Set_Transform( *getDrawable()->getTransformMatrix() );+ placeTracer( *getDrawable()->getTransformMatrix() );}//-------------------------------------------------------------------------------------------------+// The Glow option is read once a tracer, since one lives a few frames.//--------------------------------------------------------------------------------------------------void W3DTracerDraw::doDrawModule(const Matrix3D* transformMtx)+void W3DTracerDraw::createTracer( const Matrix3D &mtx ){+ Vector3 start( 0.0f, 0.0f, 0.0f );+ Vector3 stop( m_length, 0.0f, 0.0f );++ // create tracer render object for us to manipulate+ // poolify+ m_theTracer = NEW Line3DClass( start,+ stop,+ m_width, // width+ m_color.red, // red+ m_color.green, // green+ m_color.blue, // blue+ m_opacity ); // transparency+ W3DDisplay::m_3DScene->Add_Render_Object( m_theTracer );++ if( !TheGlobalData->m_classicGraphics && TheGlobalData->m_bloomIntensity > 0 )+ {+ if( !s_tracerTexture )+ s_tracerTexture = makeTracerTexture();+ ShaderClass halo = ShaderClass::_PresetAdditiveShader;+ halo.Set_Glow( ShaderClass::GLOW_ENABLE );+ m_glow = NEW SegmentedLineClass;+ m_glow->Set_Shader( halo );+ m_glow->Set_Texture( s_tracerTexture );+ m_glow->Set_Texture_Mapping_Mode( SegLineRendererClass::TILED_TEXTURE_MAP );+ m_glow->Set_Texture_Tile_Factor( 1.0f ); // v 0 at the first point, the tail, and 1 at the head+ W3DDisplay::m_3DScene->Add_Render_Object( m_glow );+ shapeTracer();+ }- // create tracer- if( m_theTracer == NULL )+ // set the transform for the tracer to that of the drawable+ placeTracer( mtx );+}++//-------------------------------------------------------------------------------------------------+//-------------------------------------------------------------------------------------------------+void W3DTracerDraw::shapeTracer( void )+{+ Vector3 start( 0.0f, 0.0f, 0.0f );+ Vector3 stop( m_length, 0.0f, 0.0f );+ m_theTracer->Reset( start, stop, m_width );+ m_theTracer->Re_Color( m_color.red, m_color.green, m_color.blue );+ if( m_glow ){+ Vector3 points[ 2 ] = { start, stop }; // the tail, then the head+ m_glow->Set_Points( 2, points );+ m_glow->Set_Width( m_width * TRACER_HALO_WIDTH_SCALE );+ }+ lightTracer();+}- Vector3 start( 0.0f, 0.0f, 0.0f );- Vector3 stop( m_length, 0.0f, 0.0f );+//-------------------------------------------------------------------------------------------------+//-------------------------------------------------------------------------------------------------+void W3DTracerDraw::lightTracer( void )+{+ m_theTracer->Set_Opacity( m_opacity );+ if( m_glow )+ {+ // an additive draw has no alpha, so the halo fades by its colour+ const Real halo = TRACER_HALO_INTENSITY * MAX( m_opacity, 0.0f );+ m_glow->Set_Color( Vector3( m_color.red * TRACER_HALO_TINT.X * halo, m_color.green * TRACER_HALO_TINT.Y * halo, m_color.blue * TRACER_HALO_TINT.Z * halo ) );+ }+}- // create tracer render object for us to manipulate- // poolify- m_theTracer = NEW Line3DClass( start,- stop,- m_width, // width- m_color.red, // red- m_color.green, // green- m_color.blue, // blue- m_opacity ); // transparency- W3DDisplay::m_3DScene->Add_Render_Object( m_theTracer );+//-------------------------------------------------------------------------------------------------+//-------------------------------------------------------------------------------------------------+void W3DTracerDraw::placeTracer( const Matrix3D &mtx )+{+ if( m_theTracer )+ m_theTracer->Set_Transform( mtx );+ if( m_glow )+ m_glow->Set_Transform( mtx );+}- // set the transform for the tracer to that of the drawable- m_theTracer->Set_Transform( *transformMtx );+//-------------------------------------------------------------------------------------------------+//-------------------------------------------------------------------------------------------------+void W3DTracerDraw::doDrawModule(const Matrix3D* transformMtx)+{- }+ // create tracer+ if( m_theTracer == NULL )+ createTracer( *transformMtx );UnsignedInt expDate = getDrawable()->getExpirationDate();if (expDate != 0){Real decay = m_opacity / (expDate - TheGameLogic->getFrame());m_opacity -= decay;- m_theTracer->Set_Opacity( m_opacity );+ lightTracer();}// set the position for the tracer@@ -152,7 +280,7 @@ void W3DTracerDraw::doDrawModule(const Matrix3D* transformMtx){Matrix3D pos = m_theTracer->Get_Transform();pos.Translate( Vector3( m_speedInDistPerFrame, 0.0f, 0.0 ) );- m_theTracer->Set_Transform( pos );+ placeTracer( pos );}}