Skip to content

Commit d17e34e

Browse files
committed
unify(radar): Merge Radar code (#1894)
1 parent 2bd2ce6 commit d17e34e

File tree

7 files changed

+44
-50
lines changed

7 files changed

+44
-50
lines changed

Generals/Code/GameEngine/Source/Common/System/Radar.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -355,23 +355,25 @@ void Radar::newMap( TerrainLogic *terrain )
355355
m_ySample = m_mapExtent.height() / RADAR_CELL_HEIGHT;
356356

357357
// find the "middle" height for the terrain (most used value) and water table
358-
Int x, y, z;
358+
Int x, y;
359359
Int terrainSamples = 0, waterSamples = 0;
360360

361361
m_terrainAverageZ = 0.0f;
362362
m_waterAverageZ = 0.0f;
363-
ICoord2D radarPoint;
364363
Coord3D worldPoint;
365-
for( y = 0; y < RADAR_CELL_HEIGHT; y++ )
366-
for( x = 0; x < RADAR_CELL_WIDTH; x++ )
367-
{
368364

369-
radarPoint.x = x;
370-
radarPoint.y = y;
371-
radarToWorld( &radarPoint, &worldPoint );
372-
z = terrain->getGroundHeight( worldPoint.x, worldPoint.y );
373-
Real waterZ;
374-
if( terrain->isUnderwater( worldPoint.x, worldPoint.y, &waterZ ) )
365+
// since we're averaging let's skip every second sample...
366+
worldPoint.y=0;
367+
for( y = 0; y < RADAR_CELL_HEIGHT; y+=2, worldPoint.y+=2.0*m_ySample )
368+
{
369+
worldPoint.x=0;
370+
for( x = 0; x < RADAR_CELL_WIDTH; x+=2, worldPoint.x+=2.0*m_xSample )
371+
{
372+
// don't use this, we don't really need the
373+
// Z position by this function... radarToWorld( &radarPoint, &worldPoint );
374+
// and this is done by isUnderwater anyway: z = terrain->getGroundHeight( worldPoint.x, worldPoint.y );
375+
Real z,waterZ;
376+
if( terrain->isUnderwater( worldPoint.x, worldPoint.y, &waterZ, &z ) )
375377
{
376378
m_waterAverageZ += z;
377379
waterSamples++;
@@ -381,8 +383,8 @@ void Radar::newMap( TerrainLogic *terrain )
381383
m_terrainAverageZ += z;
382384
terrainSamples++;
383385
}
384-
385386
}
387+
}
386388

387389
// avoid divide by zeros
388390
if( terrainSamples == 0 )

Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,7 +2143,12 @@ Bool TerrainLogic::isUnderwater( Real x, Real y, Real *waterZ, Real *terrainZ )
21432143

21442144
// if no water here, no height, no nuttin
21452145
if( waterHandle == NULL )
2146+
{
2147+
// but we have to return the terrain Z if requested!
2148+
if (terrainZ)
2149+
*terrainZ=getGroundHeight(x,y);
21462150
return FALSE;
2151+
}
21472152

21482153
//
21492154
// if this water handle is a grid water use the grid height function, otherwise look into

Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ void StealthUpdate::changeVisualDisguise()
744744
FXList::doFXPos( data->m_disguiseFX, self->getPosition() );
745745

746746
m_disguised = true;
747+
self->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_DISGUISED ) );
747748
}
748749
else if( m_disguiseAsPlayerIndex != -1 )
749750
{
@@ -809,6 +810,7 @@ void StealthUpdate::changeVisualDisguise()
809810

810811
FXList::doFXPos( data->m_disguiseRevealFX, self->getPosition() );
811812
m_disguised = false;
813+
self->clearStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_DISGUISED ) );
812814
}
813815

814816
//Reset the radar (determines color on add)

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

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
#include "GameLogic/GameLogic.h"
4141
#include "GameLogic/Object.h"
4242

43-
#include "GameLogic/Module/StealthUpdate.h"
44-
4543
#include "GameClient/Color.h"
4644
#include "GameClient/ControlBar.h"
4745
#include "GameClient/Display.h"
@@ -671,9 +669,9 @@ void W3DRadar::renderObjectList( const RadarObject *listHead, TextureClass *text
671669
// they are godlike and can see everything)
672670
//
673671
if( obj->getRadarPriority() == RADAR_PRIORITY_LOCAL_UNIT_ONLY &&
674-
obj->getControllingPlayer() != player &&
672+
obj->getControllingPlayer() != player &&
675673
player->isPlayerActive() )
676-
continue;
674+
continue;
677675

678676
// get object position
679677
const Coord3D *pos = obj->getPosition();
@@ -693,12 +691,8 @@ void W3DRadar::renderObjectList( const RadarObject *listHead, TextureClass *text
693691
// Now it twinkles for any stealthed object, whether locally controlled or neutral-observer-viewed
694692
if( obj->testStatus( OBJECT_STATUS_STEALTHED ) )
695693
{
696-
StealthUpdate* stealth = obj->getStealth();
697-
if( !stealth )
698-
continue;
699-
700694
if ( TheControlBar->getCurrentlyViewedPlayerRelationship(obj->getTeam()) == ENEMIES )
701-
if( !obj->testStatus( OBJECT_STATUS_DETECTED ) && !stealth->isDisguised() )
695+
if( !obj->testStatus( OBJECT_STATUS_DETECTED ) && !obj->testStatus( OBJECT_STATUS_DISGUISED ) )
702696
continue;
703697

704698
UnsignedByte r, g, b, a;
@@ -1081,7 +1075,7 @@ void W3DRadar::buildTerrainTexture( TerrainLogic *terrain )
10811075
RGBColor sampleColor;
10821076
RGBColor color;
10831077
Int i, j, samples;
1084-
Int x, y, z;
1078+
Int x, y;
10851079
ICoord2D radarPoint;
10861080
Coord3D worldPoint;
10871081
Bridge *bridge;
@@ -1094,10 +1088,7 @@ void W3DRadar::buildTerrainTexture( TerrainLogic *terrain )
10941088
// what point are we inspecting
10951089
radarPoint.x = x;
10961090
radarPoint.y = y;
1097-
radarToWorld( &radarPoint, &worldPoint );
1098-
1099-
// get height of the terrain at this sample point
1100-
z = terrain->getGroundHeight( worldPoint.x, worldPoint.y );
1091+
radarToWorld2D( &radarPoint, &worldPoint );
11011092

11021093
// check to see if this point is part of a working bridge
11031094
Bool workingBridge = FALSE;
@@ -1142,15 +1133,12 @@ void W3DRadar::buildTerrainTexture( TerrainLogic *terrain )
11421133
// the the world point we are concerned with
11431134
radarPoint.x = i;
11441135
radarPoint.y = j;
1145-
radarToWorld( &radarPoint, &worldPoint );
1146-
1147-
// get Z at this sample height
1148-
Real underwaterZ = terrain->getGroundHeight( worldPoint.x, worldPoint.y );
1136+
radarToWorld2D( &radarPoint, &worldPoint );
11491137

11501138
// get color for this Z and add to our sample color
1151-
if( terrain->isUnderwater( worldPoint.x, worldPoint.y ) )
1139+
Real underwaterZ;
1140+
if( terrain->isUnderwater( worldPoint.x, worldPoint.y, NULL, &underwaterZ ) )
11521141
{
1153-
11541142
// this is our "color" for water
11551143
color = waterColor;
11561144

@@ -1246,7 +1234,7 @@ void W3DRadar::buildTerrainTexture( TerrainLogic *terrain )
12461234
TheTerrainVisual->getTerrainColorAt( worldPoint.x, worldPoint.y, &color );
12471235

12481236
// interpolate the color for height
1249-
interpolateColorForHeight( &color, z, getTerrainAverageZ(),
1237+
interpolateColorForHeight( &color, worldPoint.z, getTerrainAverageZ(),
12501238
m_mapExtent.hi.z, m_mapExtent.lo.z );
12511239

12521240
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ enum RadarEventType CPP_11(: Int)
7373
RADAR_EVENT_FAKE, //Internally creates a radar event, but doesn't notify the player (unit lost
7474
//for example, so we can use the spacebar to jump to the event).
7575

76-
RADAR_EVENT_NUM_EVENTS
76+
RADAR_EVENT_NUM_EVENTS
7777

7878
};
7979

@@ -258,8 +258,6 @@ class Radar : public Snapshot,
258258
RadarObject *m_localObjectList; /** list of objects for the local player, sorted
259259
* in exactly the same priority as the regular
260260
* object list for all other objects */
261-
// typedef std::list<Object*> HeroList;
262-
// HeroList m_heroList; //< list of pointers to objects with radar icon representations
263261

264262
Real m_terrainAverageZ; ///< average Z for terrain samples
265263
Real m_waterAverageZ; ///< average Z for water samples

GeneralsMD/Code/GameEngine/Source/Common/System/Radar.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,15 @@ void Radar::newMap( TerrainLogic *terrain )
362362
m_waterAverageZ = 0.0f;
363363
Coord3D worldPoint;
364364

365-
// since we're averaging let's skip every second sample...
366-
worldPoint.y=0;
365+
// since we're averaging let's skip every second sample...
366+
worldPoint.y=0;
367367
for( y = 0; y < RADAR_CELL_HEIGHT; y+=2, worldPoint.y+=2.0*m_ySample )
368-
{
369-
worldPoint.x=0;
370-
for( x = 0; x < RADAR_CELL_WIDTH; x+=2, worldPoint.x+=2.0*m_xSample )
368+
{
369+
worldPoint.x=0;
370+
for( x = 0; x < RADAR_CELL_WIDTH; x+=2, worldPoint.x+=2.0*m_xSample )
371371
{
372372
// don't use this, we don't really need the
373-
// Z position by this function... radarToWorld( &radarPoint, &worldPoint );
373+
// Z position by this function... radarToWorld( &radarPoint, &worldPoint );
374374
// and this is done by isUnderwater anyway: z = terrain->getGroundHeight( worldPoint.x, worldPoint.y );
375375
Real z,waterZ;
376376
if( terrain->isUnderwater( worldPoint.x, worldPoint.y, &waterZ, &z ) )
@@ -383,9 +383,8 @@ void Radar::newMap( TerrainLogic *terrain )
383383
m_terrainAverageZ += z;
384384
terrainSamples++;
385385
}
386-
387386
}
388-
}
387+
}
389388

390389
// avoid divide by zeros
391390
if( terrainSamples == 0 )
@@ -436,7 +435,7 @@ RadarObjectType Radar::addObject( Object *obj )
436435
//Because we have support for disguised units pretending to be units from another
437436
//team, we need to intercept it here and make sure it's rendered appropriately
438437
//based on which client is rendering it.
439-
StealthUpdate *update = obj->getStealth();
438+
StealthUpdate *update = obj->getStealth();
440439
if( update )
441440
{
442441
if( update->isDisguised() )
@@ -1506,7 +1505,7 @@ void Radar::xfer( Xfer *xfer )
15061505
XferVersion version = currentVersion;
15071506
xfer->xferVersion( &version, currentVersion );
15081507

1509-
1508+
15101509
if (version <= 1)
15111510
{
15121511
const Int localPlayerIndex = ThePlayerList->getLocalPlayer()->getPlayerIndex();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -890,8 +890,8 @@ void W3DRadar::init( void )
890890
DEBUG_ASSERTCRASH( m_overlayTexture, ("W3DRadar: Unable to allocate overlay texture") );
891891

892892
// set filter type for the overlay texture, try it and see if you like it, I don't ;)
893-
// m_overlayTexture->Set_Min_Filter( TextureClass::FILTER_TYPE_NONE );
894-
// m_overlayTexture->Set_Mag_Filter( TextureClass::FILTER_TYPE_NONE );
893+
// m_overlayTexture->Set_Min_Filter( TextureFilterClass::FILTER_TYPE_NONE );
894+
// m_overlayTexture->Set_Mag_Filter( TextureFilterClass::FILTER_TYPE_NONE );
895895

896896
// allocate our shroud texture
897897
m_shroudTexture = MSGNEW("TextureClass") TextureClass( m_textureWidth, m_textureHeight,
@@ -1136,7 +1136,7 @@ void W3DRadar::buildTerrainTexture( TerrainLogic *terrain )
11361136
radarToWorld2D( &radarPoint, &worldPoint );
11371137

11381138
// get color for this Z and add to our sample color
1139-
Real underwaterZ;
1139+
Real underwaterZ;
11401140
if( terrain->isUnderwater( worldPoint.x, worldPoint.y, NULL, &underwaterZ ) )
11411141
{
11421142
// this is our "color" for water
@@ -1544,7 +1544,7 @@ void W3DRadar::refreshObjects()
15441544
// they are godlike and can see everything)
15451545
//
15461546
if( obj->getRadarPriority() == RADAR_PRIORITY_LOCAL_UNIT_ONLY &&
1547-
obj->getControllingPlayer() != player &&
1547+
obj->getControllingPlayer() != player &&
15481548
player->isPlayerActive() )
15491549
continue;
15501550

0 commit comments

Comments
 (0)