Skip to content

Commit 3fabbb3

Browse files
committed
refactor(radar): Simplify function W3DRadar::renderObjectList (#1893)
1 parent e25f968 commit 3fabbb3

File tree

3 files changed

+53
-30
lines changed

3 files changed

+53
-30
lines changed

Core/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,

Core/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,54 @@ 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+
{
634+
return false;
635+
}
636+
637+
const Int playerIndex = localPlayer->getPlayerIndex();
638+
const Object *obj = rObj->friend_getObject();
639+
640+
//
641+
// check for shrouded status
642+
// if object is fogged or shrouded, don't render it
643+
//
644+
if (obj->getShroudedStatus(playerIndex) > OBJECTSHROUD_PARTIAL_CLEAR)
645+
{
646+
return false;
647+
}
648+
649+
//
650+
// objects with a local only unit priority will only appear on the radar if they
651+
// are controlled by the local player, or if the local player is an observer (cause
652+
// they are godlike and can see everything)
653+
//
654+
if (obj->getRadarPriority() == RADAR_PRIORITY_LOCAL_UNIT_ONLY &&
655+
obj->getControllingPlayer() != localPlayer &&
656+
localPlayer->isPlayerActive() )
657+
{
658+
return false;
659+
}
660+
661+
//
662+
// ML-- What the heck is this? local-only and neutral-observer-viewed units are stealthy?? Since when?
663+
// Now it twinkles for any stealthed object, whether locally controlled or neutral-observer-viewed
664+
//
665+
if (TheControlBar->getCurrentlyViewedPlayerRelationship(obj->getTeam()) == ENEMIES &&
666+
obj->testStatus( OBJECT_STATUS_STEALTHED ) &&
667+
!obj->testStatus( OBJECT_STATUS_DETECTED ) &&
668+
!obj->testStatus( OBJECT_STATUS_DISGUISED ) )
669+
{
670+
return false;
671+
}
672+
673+
return true;
674+
}
675+
628676
//-------------------------------------------------------------------------------------------------
629677
/** Render an object list into the texture passed in */
630678
//-------------------------------------------------------------------------------------------------
@@ -642,7 +690,6 @@ void W3DRadar::renderObjectList( const RadarObject *listHead, TextureClass *text
642690
ICoord2D radarPoint;
643691

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

647694
if( calcHero )
648695
{
@@ -652,49 +699,26 @@ void W3DRadar::renderObjectList( const RadarObject *listHead, TextureClass *text
652699

653700
for( const RadarObject *rObj = listHead; rObj; rObj = rObj->friend_getNext() )
654701
{
655-
656-
if (rObj->isTemporarilyHidden())
702+
if (!canRenderObject(rObj, player))
657703
continue;
658704

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-
676705
// get object position
706+
const Object *obj = rObj->friend_getObject();
677707
const Coord3D *pos = obj->getPosition();
678708

679709
// compute object position as a radar blip
680710
radarPoint.x = pos->x / (m_mapExtent.width() / RADAR_CELL_WIDTH);
681711
radarPoint.y = pos->y / (m_mapExtent.height() / RADAR_CELL_HEIGHT);
682712

683-
// get the color we're going to draw in
713+
// get the color we're going to draw in
684714
Color c = rObj->getColor();
685715

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

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

0 commit comments

Comments
 (0)