Skip to content

Commit b3b8c8e

Browse files
committed
refactor(radar): Simplify function W3DRadar::renderObjectList (#1893)
1 parent de13231 commit b3b8c8e

File tree

3 files changed

+51
-30
lines changed

3 files changed

+51
-30
lines changed

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6282,10 +6282,8 @@ void Object::goInvulnerable( UnsignedInt time )
62826282
// ------------------------------------------------------------------------------------------------
62836283
RadarPriorityType Object::getRadarPriority( void ) const
62846284
{
6285-
RadarPriorityType priority = RADAR_PRIORITY_INVALID;
6286-
62876285
// first, get the priority at the thing template level
6288-
priority = getTemplate()->getDefaultRadarPriority();
6286+
RadarPriorityType priority = getTemplate()->getDefaultRadarPriority();
62896287

62906288
//
62916289
// there are some objects that we want to show up on the radar when they have

GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/Common/W3DRadar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class W3DRadar : public Radar
8484
void buildTerrainTexture( TerrainLogic *terrain ); ///< create the terrain texture of the radar
8585
void drawIcons( Int pixelX, Int pixelY, Int width, Int height ); ///< draw all of the radar icons
8686
void updateObjectTexture(TextureClass *texture);
87+
static Bool canRenderObject( const RadarObject *rObj, const Player *localPlayer );
8788
void renderObjectList( const RadarObject *listHead, TextureClass *texture, Bool calcHero = FALSE ); ///< render an object list to the texture
8889
void interpolateColorForHeight( RGBColor *color,
8990
Real height,

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,52 @@ void W3DRadar::updateObjectTexture(TextureClass *texture)
625625
renderObjectList( getLocalObjectList(), texture, TRUE );
626626
}
627627

628+
//-------------------------------------------------------------------------------------------------
629+
//-------------------------------------------------------------------------------------------------
630+
Bool W3DRadar::canRenderObject( const RadarObject *rObj, const Player *localPlayer )
631+
{
632+
if (rObj->isTemporarilyHidden())
633+
return false;
634+
635+
const Int playerIndex = localPlayer->getPlayerIndex();
636+
const Object *obj = rObj->friend_getObject();
637+
638+
//
639+
// check for shrouded status
640+
// if object is fogged or shrouded, don't render it
641+
//
642+
if (obj->getShroudedStatus(playerIndex) > OBJECTSHROUD_PARTIAL_CLEAR)
643+
{
644+
return false;
645+
}
646+
647+
//
648+
// objects with a local only unit priority will only appear on the radar if they
649+
// are controlled by the local player, or if the local player is an observer (cause
650+
// they are godlike and can see everything)
651+
//
652+
if (obj->getRadarPriority() == RADAR_PRIORITY_LOCAL_UNIT_ONLY &&
653+
obj->getControllingPlayer() != localPlayer &&
654+
localPlayer->isPlayerActive() )
655+
{
656+
return false;
657+
}
658+
659+
//
660+
// ML-- What the heck is this? local-only and neutral-observer-viewed units are stealthy?? Since when?
661+
// Now it twinkles for any stealthed object, whether locally controlled or neutral-observer-viewed
662+
//
663+
if (TheControlBar->getCurrentlyViewedPlayerRelationship(obj->getTeam()) == ENEMIES &&
664+
obj->testStatus( OBJECT_STATUS_STEALTHED ) &&
665+
!obj->testStatus( OBJECT_STATUS_DETECTED ) &&
666+
!obj->testStatus( OBJECT_STATUS_DISGUISED ) )
667+
{
668+
return false;
669+
}
670+
671+
return true;
672+
}
673+
628674
//-------------------------------------------------------------------------------------------------
629675
/** Render an object list into the texture passed in */
630676
//-------------------------------------------------------------------------------------------------
@@ -642,7 +688,6 @@ void W3DRadar::renderObjectList( const RadarObject *listHead, TextureClass *text
642688
ICoord2D radarPoint;
643689

644690
Player *player = rts::getObservedOrLocalPlayer();
645-
const Int playerIndex = player->getPlayerIndex();
646691

647692
if( calcHero )
648693
{
@@ -652,49 +697,26 @@ void W3DRadar::renderObjectList( const RadarObject *listHead, TextureClass *text
652697

653698
for( const RadarObject *rObj = listHead; rObj; rObj = rObj->friend_getNext() )
654699
{
655-
656-
if (rObj->isTemporarilyHidden())
700+
if (!canRenderObject(rObj, player))
657701
continue;
658702

659-
// get object
660-
const Object *obj = rObj->friend_getObject();
661-
662-
// check for shrouded status
663-
if (obj->getShroudedStatus(playerIndex) > OBJECTSHROUD_PARTIAL_CLEAR)
664-
continue; //object is fogged or shrouded, don't render it.
665-
666-
//
667-
// objects with a local only unit priority will only appear on the radar if they
668-
// are controlled by the local player, or if the local player is an observer (cause
669-
// they are godlike and can see everything)
670-
//
671-
if( obj->getRadarPriority() == RADAR_PRIORITY_LOCAL_UNIT_ONLY &&
672-
obj->getControllingPlayer() != player &&
673-
player->isPlayerActive() )
674-
continue;
675-
676703
// get object position
704+
const Object *obj = rObj->friend_getObject();
677705
const Coord3D *pos = obj->getPosition();
678706

679707
// compute object position as a radar blip
680708
radarPoint.x = pos->x / (m_mapExtent.width() / RADAR_CELL_WIDTH);
681709
radarPoint.y = pos->y / (m_mapExtent.height() / RADAR_CELL_HEIGHT);
682710

683-
// get the color we're going to draw in
711+
// get the color we're going to draw in
684712
Color c = rObj->getColor();
685713

686-
687-
688714
// adjust the alpha for stealth units so they "fade/blink" on the radar for the controller
689715
// if( obj->getRadarPriority() == RADAR_PRIORITY_LOCAL_UNIT_ONLY )
690716
// ML-- What the heck is this? local-only and neutral-observer-viewed units are stealthy?? Since when?
691717
// Now it twinkles for any stealthed object, whether locally controlled or neutral-observer-viewed
692718
if( obj->testStatus( OBJECT_STATUS_STEALTHED ) )
693719
{
694-
if ( TheControlBar->getCurrentlyViewedPlayerRelationship(obj->getTeam()) == ENEMIES )
695-
if( !obj->testStatus( OBJECT_STATUS_DETECTED ) && !obj->testStatus( OBJECT_STATUS_DISGUISED ) )
696-
continue;
697-
698720
UnsignedByte r, g, b, a;
699721
GameGetColorComponents( c, &r, &g, &b, &a );
700722

0 commit comments

Comments
 (0)