Skip to content

Commit c0f8b79

Browse files
authored
fix(shadow): Fix initial shadow states of draw modules (#1591)
1 parent 9385483 commit c0f8b79

File tree

17 files changed

+61
-25
lines changed

17 files changed

+61
-25
lines changed

Generals/Code/GameEngine/Include/Common/ThingFactory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class ThingFactory : public SubsystemInterface
9292
/** request a new drawable using the given template.
9393
this will throw an exception on failure; it will never return null.
9494
*/
95-
Drawable *newDrawable(const ThingTemplate *tmplate, DrawableStatus statusBits = DRAWABLE_STATUS_NONE );
95+
Drawable *newDrawable(const ThingTemplate *tmplate, DrawableStatusBits statusBits = DRAWABLE_STATUS_DEFAULT );
9696

9797
static void parseObjectDefinition( INI* ini, const AsciiString& name, const AsciiString& reskinFrom );
9898

Generals/Code/GameEngine/Include/GameClient/Drawable.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,17 @@ enum StealthLookType CPP_11(: Int)
225225
// ------------------------------------------------------------------------------------------------
226226
/** Drawable status bits */
227227
// ------------------------------------------------------------------------------------------------
228-
enum DrawableStatus CPP_11(: Int)
228+
typedef UnsignedInt DrawableStatusBits;
229+
enum DrawableStatus CPP_11(: DrawableStatusBits)
229230
{
230231
DRAWABLE_STATUS_NONE = 0x00000000, ///< no status
231232
DRAWABLE_STATUS_DRAWS_IN_MIRROR = 0x00000001, ///< drawable can reflect
232233
DRAWABLE_STATUS_SHADOWS = 0x00000002, ///< use setShadowsEnabled() access method
233234
DRAWABLE_STATUS_TINT_COLOR_LOCKED = 0x00000004, ///< drawable tint color is "locked" and won't fade to normal
234235
DRAWABLE_STATUS_NO_STATE_PARTICLES = 0x00000008, ///< do *not* auto-create particle systems based on model condition
235236
DRAWABLE_STATUS_NO_SAVE = 0x00000010, ///< do *not* save this drawable (UI fluff only). ignored (error, actually) if attached to an object
237+
238+
DRAWABLE_STATUS_DEFAULT = DRAWABLE_STATUS_SHADOWS,
236239
};
237240

238241
enum TintStatus CPP_11(: Int)
@@ -283,7 +286,7 @@ class Drawable : public Thing,
283286

284287
public:
285288

286-
Drawable( const ThingTemplate *thing, DrawableStatus statusBits = DRAWABLE_STATUS_NONE );
289+
Drawable( const ThingTemplate *thing, DrawableStatusBits statusBits = DRAWABLE_STATUS_DEFAULT );
287290

288291
void onDestroy( void ); ///< run from GameClient::destroyDrawable
289292

@@ -346,6 +349,7 @@ class Drawable : public Thing,
346349
ClientUpdateModule const** getClientUpdateModules() const { return (ClientUpdateModule const**)getModuleList(MODULETYPE_CLIENT_UPDATE); }
347350
ClientUpdateModule* findClientUpdateModule( NameKeyType key );
348351

352+
// never returns null
349353
DrawModule** getDrawModules();
350354
DrawModule const** getDrawModules() const;
351355

@@ -628,7 +632,7 @@ class Drawable : public Thing,
628632
Drawable *m_nextDrawable;
629633
Drawable *m_prevDrawable; ///< list links
630634

631-
UnsignedInt m_status; ///< status bits (see DrawableStatus enum)
635+
DrawableStatusBits m_status; ///< status bits (see DrawableStatus enum)
632636
UnsignedInt m_tintStatus; ///< tint color status bits (see TintStatus enum)
633637
UnsignedInt m_prevTintStatus;///< for edge testing with m_tintStatus
634638

Generals/Code/GameEngine/Include/GameClient/GameClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class GameClient : public SubsystemInterface,
126126

127127
virtual void iterateDrawablesInRegion( Region3D *region, GameClientFuncPtr userFunc, void *userData ); ///< Calls userFunc for each drawable contained within the region
128128

129-
virtual Drawable *friend_createDrawable( const ThingTemplate *thing, DrawableStatus statusBits = DRAWABLE_STATUS_NONE ) = 0;
129+
virtual Drawable *friend_createDrawable( const ThingTemplate *thing, DrawableStatusBits statusBits = DRAWABLE_STATUS_DEFAULT ) = 0;
130130
virtual void destroyDrawable( Drawable *draw ); ///< Destroy the given drawable
131131

132132
virtual void setTimeOfDay( TimeOfDay tod ); ///< Tell all the drawables what time of day it is now

Generals/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ Object *ThingFactory::newObject( const ThingTemplate *tmplate, Team *team, Objec
343343
}
344344

345345
//=============================================================================
346-
Drawable *ThingFactory::newDrawable(const ThingTemplate *tmplate, DrawableStatus statusBits)
346+
Drawable *ThingFactory::newDrawable(const ThingTemplate *tmplate, DrawableStatusBits statusBits)
347347
{
348348
if (tmplate == NULL)
349349
throw ERROR_BAD_ARG;

Generals/Code/GameEngine/Source/GameClient/Drawable.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ void Drawable::saturateRGB(RGBColor& color, Real factor)
308308
* graphical side of a logical object, whereas GameLogic objects encapsulate
309309
* behaviors and physics. */
310310
//-------------------------------------------------------------------------------------------------
311-
Drawable::Drawable( const ThingTemplate *thingTemplate, DrawableStatus statusBits )
311+
Drawable::Drawable( const ThingTemplate *thingTemplate, DrawableStatusBits statusBits )
312312
: Thing( thingTemplate )
313313
{
314314

@@ -459,6 +459,14 @@ Drawable::Drawable( const ThingTemplate *thingTemplate, DrawableStatus statusBit
459459
(*m)->onObjectCreated();
460460
}
461461

462+
const Bool shadowsEnabled = getShadowsEnabled();
463+
464+
// TheSuperHackers @fix xezon 14/09/2025 Match the shadow states of all draw modules with this drawable.
465+
for (DrawModule** dm = (DrawModule**)getModuleList(MODULETYPE_DRAW); *dm; ++dm)
466+
{
467+
(*dm)->setShadowsEnabled(shadowsEnabled);
468+
}
469+
462470
m_groupNumber = NULL;
463471
m_captionDisplayString = NULL;
464472
m_drawableInfo.m_drawable = this;
@@ -3464,6 +3472,7 @@ void Drawable::clearAndSetModelConditionState( ModelConditionFlagType clr, Model
34643472
DrawModule** Drawable::getDrawModules()
34653473
{
34663474
DrawModule** dm = (DrawModule**)getModuleList(MODULETYPE_DRAW);
3475+
34673476
#ifdef DIRTY_CONDITION_FLAGS
34683477
if (m_isModelDirty)
34693478
{
@@ -3486,13 +3495,16 @@ DrawModule** Drawable::getDrawModules()
34863495
}
34873496
}
34883497
#endif
3498+
3499+
DEBUG_ASSERTCRASH(dm != NULL, ("Draw Module List is not expected NULL"));
34893500
return dm;
34903501
}
34913502

34923503
//-------------------------------------------------------------------------------------------------
34933504
DrawModule const** Drawable::getDrawModules() const
34943505
{
34953506
DrawModule const** dm = (DrawModule const**)getModuleList(MODULETYPE_DRAW);
3507+
34963508
#ifdef DIRTY_CONDITION_FLAGS
34973509
if (m_isModelDirty)
34983510
{
@@ -3516,6 +3528,8 @@ DrawModule const** Drawable::getDrawModules() const
35163528
}
35173529
}
35183530
#endif
3531+
3532+
DEBUG_ASSERTCRASH(dm != NULL, ("Draw Module List is not expected NULL"));
35193533
return dm;
35203534
}
35213535

Generals/Code/GameEngine/Source/GameClient/InGameUI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,7 @@ void InGameUI::handleBuildPlacements( void )
15291529

15301530
if( m_placeIcon[ i ] == NULL )
15311531
m_placeIcon[ i ] = TheThingFactory->newDrawable( m_pendingPlaceType,
1532-
DRAWABLE_STATUS_NO_STATE_PARTICLES );
1532+
DRAWABLE_STATUS_SHADOWS | DRAWABLE_STATUS_NO_STATE_PARTICLES );
15331533

15341534
}
15351535

@@ -3040,7 +3040,7 @@ void InGameUI::placeBuildAvailable( const ThingTemplate *build, Drawable *buildD
30403040
// TheInGameUI->deselectAllDrawables();
30413041

30423042
// create a drawble of what we are building to be "attached" at the cursor
3043-
draw = TheThingFactory->newDrawable( build, DRAWABLE_STATUS_NO_STATE_PARTICLES );
3043+
draw = TheThingFactory->newDrawable( build, DRAWABLE_STATUS_SHADOWS | DRAWABLE_STATUS_NO_STATE_PARTICLES );
30443044
if (sourceObject)
30453045
{
30463046
if (TheGlobalData->m_timeOfDay == TIME_OF_DAY_NIGHT)

Generals/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DGameClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class W3DGameClient : public GameClient
7474
virtual ~W3DGameClient();
7575

7676
/// given a type, create a drawable
77-
virtual Drawable *friend_createDrawable( const ThingTemplate *thing, DrawableStatus statusBits = DRAWABLE_STATUS_NONE );
77+
virtual Drawable *friend_createDrawable( const ThingTemplate *thing, DrawableStatusBits statusBits = DRAWABLE_STATUS_DEFAULT );
7878

7979
virtual void init( void ); ///< initialize resources
8080
virtual void update( void ); ///< per frame update

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DGameClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void W3DGameClient::reset( void )
115115
* in the GameLogic and GameClient themselves */
116116
//-------------------------------------------------------------------------------------------------
117117
Drawable *W3DGameClient::friend_createDrawable( const ThingTemplate *tmplate,
118-
DrawableStatus statusBits )
118+
DrawableStatusBits statusBits )
119119
{
120120
Drawable *draw = NULL;
121121

GeneralsMD/Code/GameEngine/Include/Common/ThingFactory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class ThingFactory : public SubsystemInterface
9292
/** request a new drawable using the given template.
9393
this will throw an exception on failure; it will never return null.
9494
*/
95-
Drawable *newDrawable(const ThingTemplate *tmplate, DrawableStatus statusBits = DRAWABLE_STATUS_NONE );
95+
Drawable *newDrawable(const ThingTemplate *tmplate, DrawableStatusBits statusBits = DRAWABLE_STATUS_DEFAULT );
9696

9797
static void parseObjectDefinition( INI* ini, const AsciiString& name, const AsciiString& reskinFrom );
9898

GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,17 @@ enum StealthLookType CPP_11(: Int)
228228
// ------------------------------------------------------------------------------------------------
229229
/** Drawable status bits */
230230
// ------------------------------------------------------------------------------------------------
231-
enum DrawableStatus CPP_11(: Int)
231+
typedef UnsignedInt DrawableStatusBits;
232+
enum DrawableStatus CPP_11(: DrawableStatusBits)
232233
{
233234
DRAWABLE_STATUS_NONE = 0x00000000, ///< no status
234235
DRAWABLE_STATUS_DRAWS_IN_MIRROR = 0x00000001, ///< drawable can reflect
235236
DRAWABLE_STATUS_SHADOWS = 0x00000002, ///< use setShadowsEnabled() access method
236237
DRAWABLE_STATUS_TINT_COLOR_LOCKED = 0x00000004, ///< drawable tint color is "locked" and won't fade to normal
237238
DRAWABLE_STATUS_NO_STATE_PARTICLES = 0x00000008, ///< do *not* auto-create particle systems based on model condition
238239
DRAWABLE_STATUS_NO_SAVE = 0x00000010, ///< do *not* save this drawable (UI fluff only). ignored (error, actually) if attached to an object
240+
241+
DRAWABLE_STATUS_DEFAULT = DRAWABLE_STATUS_SHADOWS,
239242
};
240243

241244
enum TintStatus CPP_11(: Int)
@@ -291,7 +294,7 @@ class Drawable : public Thing,
291294

292295
public:
293296

294-
Drawable( const ThingTemplate *thing, DrawableStatus statusBits = DRAWABLE_STATUS_NONE );
297+
Drawable( const ThingTemplate *thing, DrawableStatusBits statusBits = DRAWABLE_STATUS_DEFAULT );
295298

296299
void onDestroy( void ); ///< run from GameClient::destroyDrawable
297300
void onLevelStart(); ///< run from GameLogic::startNewGame
@@ -358,6 +361,7 @@ class Drawable : public Thing,
358361
ClientUpdateModule const** getClientUpdateModules() const { return (ClientUpdateModule const**)getModuleList(MODULETYPE_CLIENT_UPDATE); }
359362
ClientUpdateModule* findClientUpdateModule( NameKeyType key );
360363

364+
// never returns null
361365
DrawModule** getDrawModulesNonDirty();
362366
DrawModule** getDrawModules();
363367
DrawModule const** getDrawModules() const;
@@ -669,7 +673,7 @@ class Drawable : public Thing,
669673

670674
DynamicAudioEventInfo *m_customSoundAmbientInfo; ///< If not NULL, info about the ambient sound to attach to this object
671675

672-
UnsignedInt m_status; ///< status bits (see DrawableStatus enum)
676+
DrawableStatusBits m_status; ///< status bits (see DrawableStatus enum)
673677
UnsignedInt m_tintStatus; ///< tint color status bits (see TintStatus enum)
674678
UnsignedInt m_prevTintStatus;///< for edge testing with m_tintStatus
675679

0 commit comments

Comments
 (0)