UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cp_overlay.cpp File Reference

Functions to generate and render overlay for geoscape. More...

#include "../../cl_shared.h"
#include "cp_campaign.h"
#include "cp_overlay.h"

Go to the source code of this file.

Functions

static byteCP_XVIGetAlpha (int x, int y)
 
static byteCP_RadarGet (int x, int y, bool source)
 
static void CP_UploadXVI (void)
 
void CP_GetXVIMapDimensions (int *width, int *height)
 
void CP_SetXVILevel (int x, int y, int value)
 
int CP_GetXVILevel (int x, int y)
 
static void CP_SetMinMaxOverlayRows (const vec2_t pos, float radius, const int height, int *yMin, int *yMax)
 Set lower and upper value of an overlay (radar, xvi) row that can be modified when tracing a circle. More...
 
static float CP_GetCircleDeltaLongitude (const vec2_t centerPos, float radius, const float yLat)
 Return the half longitude affected when tracing a circle at a given latitude. More...
 
static void CP_DrawXVIOverlayPixel (int xMin, int xMax, const vec2_t centerPos, int y, const float yLat, int xviLevel, float radius)
 Change the value of 1 pixel in XVI overlay, the new value is higher than old one. More...
 
static void CP_DrawXVIOverlayRow (float latMin, float latMax, const vec2_t center, int y, float yLat, int xviLevel, float radius)
 Draw XVI overlay for a given latitude between 2 longitudes. More...
 
static void CP_IncreaseXVILevel (const vec2_t pos, int xCenter, int yCenter, float factor)
 Applies spreading on xvi transparency channel centered on a given pos. More...
 
void CP_DecreaseXVILevelEverywhere (void)
 
void CP_ChangeXVILevel (const vec2_t pos, float factor)
 Convert the pos into degrees and increase XVI there. More...
 
void CP_InitializeXVIOverlay (void)
 Initialize XVI overlay on geoscape. More...
 
void CP_InitializeRadarOverlay (bool source)
 Initialize radar overlay on geoscape. More...
 
static void CP_DrawRadarOverlayRow (float latMin, float latMax, int y, byte alpha, bool source)
 Draw radar overlay for a given latitude between 2 longitudes. More...
 
void CP_AddRadarCoverage (const vec2_t pos, float innerRadius, float outerRadius, bool source)
 Add a radar coverage (base or aircraft) to radar overlay. More...
 
void CP_UploadRadarCoverage (void)
 Smooth radar coverage. More...
 

Variables

static const int MAX_ALPHA_VALUE = 200
 
static const int INITIAL_ALPHA_VALUE = 60
 

Detailed Description

Functions to generate and render overlay for geoscape.

Todo:
update the alpha values for radar like the ones for the xvi map - it's much faster like this

Definition in file cp_overlay.cpp.

Function Documentation

void CP_AddRadarCoverage ( const vec2_t  pos,
float  innerRadius,
float  outerRadius,
bool  source 
)

Add a radar coverage (base or aircraft) to radar overlay.

Parameters
[in]posPosition of the center of radar
[in]innerRadiusRadius of the radar coverage
[in]outerRadiusRadius of the outer radar coverage
[in]sourceTrue if we must update the source of the radar coverage, false if the copy must be updated.
Precondition
We assume outerRadius is smaller than 180 degrees

< Alpha of the inner radar range

< Alpha of the outer radar range

< current position (in pixel)

< Bounding box of the inner radar zone

< Bounding box of the outer radar zone

Todo:
add EQUAL_EPSILON here?

Definition at line 367 of file cp_overlay.cpp.

References CP_DrawRadarOverlayRow(), CP_GetCircleDeltaLongitude(), CP_SetMinMaxOverlayRows(), f, RADAR_HEIGHT, and torad.

Referenced by RADAR_DrawCoverage(), and RADAR_UpdateStaticRadarCoverage().

void CP_ChangeXVILevel ( const vec2_t  pos,
float  factor 
)

Convert the pos into degrees and increase XVI there.

Parameters
posThe x/y-location in the flat XVI map
factorThe factor of the XVI raise
Note
xvi rate is null when alpha = 0, max when alpha = maxAlpha

Definition at line 257 of file cp_overlay.cpp.

References CP_IncreaseXVILevel(), f, XVI_HEIGHT, and XVI_WIDTH.

Referenced by CP_SpreadXVIAtPos().

void CP_DecreaseXVILevelEverywhere ( void  )
See also
R_IncreaseXVILevel

x,y: current position (in pixel)

Definition at line 237 of file cp_overlay.cpp.

References CP_GetXVILevel(), CP_SetXVILevel(), CP_UploadXVI(), XVI_HEIGHT, and XVI_WIDTH.

Referenced by CP_ReduceXVIEverywhere().

static void CP_DrawRadarOverlayRow ( float  latMin,
float  latMax,
int  y,
byte  alpha,
bool  source 
)
static

Draw radar overlay for a given latitude between 2 longitudes.

Parameters
[in]latMin,latMaxMinimum and maximum latitude.
[in]ycurrent row in radar overlay.
[in]alphaThe value for the alpha channel (creates the different look).
[in]sourceTrue if we must update the source of the radar coverage, false if the copy must be updated.
Precondition
We assume latMax - latMin <= 360 degrees.

Definition at line 309 of file cp_overlay.cpp.

References CP_RadarGet(), dest, EQUAL_EPSILON, f, and RADAR_WIDTH.

Referenced by CP_AddRadarCoverage().

static void CP_DrawXVIOverlayPixel ( int  xMin,
int  xMax,
const vec2_t  centerPos,
int  y,
const float  yLat,
int  xviLevel,
float  radius 
)
static

Change the value of 1 pixel in XVI overlay, the new value is higher than old one.

Parameters
[in]xMinMinimum column (this volumn will be reached).
[in]xMaxMaximum column (this volumn won't be reached).
[in]centerPosPosition of the center of the circle.
[in]ycurrent row in XVI overlay.
[in]yLatLatitude (in degree) of the current Row.
[in]xviLevelLevel of XVI at the center of the circle (ie at center ).
[in]radiusRadius of the circle.

Definition at line 138 of file cp_overlay.cpp.

References CP_GetXVILevel(), CP_SetXVILevel(), GetDistanceOnGlobe(), and XVI_WIDTH.

Referenced by CP_DrawXVIOverlayRow().

static void CP_DrawXVIOverlayRow ( float  latMin,
float  latMax,
const vec2_t  center,
int  y,
float  yLat,
int  xviLevel,
float  radius 
)
static

Draw XVI overlay for a given latitude between 2 longitudes.

Parameters
[in]latMin,latMaxMinimum and maximum latitude (in degree).
[in]centerPosition of the center of the circle.
[in]ycurrent row in XVI overlay.
[in]yLatLatitude (in degree) of the current Row.
[in]xviLevelLevel of XVI at the center of the circle (ie at center ).
[in]radiusRadius of the circle.
Precondition
We assume latMax - latMin <= 360 degrees.

Definition at line 168 of file cp_overlay.cpp.

References CP_DrawXVIOverlayPixel(), EQUAL_EPSILON, f, RADAR_WIDTH, and XVI_WIDTH.

Referenced by CP_IncreaseXVILevel().

static float CP_GetCircleDeltaLongitude ( const vec2_t  centerPos,
float  radius,
const float  yLat 
)
inlinestatic

Return the half longitude affected when tracing a circle at a given latitude.

Parameters
[in]centerPoscenter of the circle (radar coverage, XVI infection zone).
[in]radiusradius of the circle.
[in]yLatlatitude of current point (in radians).
Note
This is an implementation of the following facts:
  • the distance (on a sphere) between the center of the circle and the border of the circle at current latitude is equal to radius
  • the border of the circle on a row has the same latitude than current latitude.

Definition at line 122 of file cp_overlay.cpp.

References todeg, and torad.

Referenced by CP_AddRadarCoverage(), and CP_IncreaseXVILevel().

void CP_GetXVIMapDimensions ( int width,
int height 
)

Definition at line 52 of file cp_overlay.cpp.

References XVI_HEIGHT, and XVI_WIDTH.

Referenced by CP_UpdateNationXVIInfection(), and XVI_SaveXML().

static void CP_IncreaseXVILevel ( const vec2_t  pos,
int  xCenter,
int  yCenter,
float  factor 
)
static

Applies spreading on xvi transparency channel centered on a given pos.

Parameters
posThe x/y-location in the flat XVI map
[in]xCenter,yCenterPosition of the center of XVI spreading (in degrees)
factorThe factor of the XVI raise
See also
R_DecreaseXVILevel
Note
xvi rate is null when alpha = 0, max when alpha = maxAlpha XVI spreads in circle, and the alpha value of one pixel indicates the XVI level of infection. This is necessary to take into account a new event that would spread in the zone where XVI is already spread.

< XVI level rate at position pos

< current position (in pixel)

< Bounding box of the XVI zone to be drawn (circle)

< radius of the new XVI circle (in degree)

Definition at line 207 of file cp_overlay.cpp.

References CP_DrawXVIOverlayRow(), CP_GetCircleDeltaLongitude(), CP_GetXVILevel(), CP_SetMinMaxOverlayRows(), CP_UploadXVI(), INITIAL_ALPHA_VALUE, MAX_ALPHA_VALUE, torad, and XVI_HEIGHT.

Referenced by CP_ChangeXVILevel().

void CP_InitializeRadarOverlay ( bool  source)

Initialize radar overlay on geoscape.

Parameters
[in]sourceInitialize the source texture if true: if you are updating base radar overlay. false if you are updating aircraft radar overlay (base radar overlay will be copied to aircraft radar overlay)

Definition at line 292 of file cp_overlay.cpp.

References cgi, INITIAL_ALPHA_VALUE, cgame_import_s::r_radarPic, cgame_import_s::r_radarSourcePic, RADAR_HEIGHT, and RADAR_WIDTH.

Referenced by RADAR_UpdateStaticRadarCoverage(), and RADAR_UpdateWholeRadarOverlay().

void CP_InitializeXVIOverlay ( void  )

Initialize XVI overlay on geoscape.

Note
xvi rate is null when alpha = 0, max when alpha = maxAlpha

Definition at line 269 of file cp_overlay.cpp.

References cgi, CP_UploadXVI(), cgame_import_s::r_xviAlpha, XVI_HEIGHT, and XVI_WIDTH.

Referenced by CP_CampaignInit(), CP_InitStartup(), and XVI_LoadXML().

static byte* CP_RadarGet ( int  x,
int  y,
bool  source 
)
inlinestatic
static void CP_SetMinMaxOverlayRows ( const vec2_t  pos,
float  radius,
const int  height,
int yMin,
int yMax 
)
static

Set lower and upper value of an overlay (radar, xvi) row that can be modified when tracing a circle.

Parameters
[in]posPosition of the center of circle.
[in]radiusRadius of the circle to be drawn.
[in]heightHeight of the overlay (in pixel).
[out]yMinPointer to the lower row of the overlay that should be changed.
[out]yMaxPointer to the higher row of the overlay that should be changed.
Note
circle will be drawn between yMin (included) and yMin (excluded). So yMin and yMax are rounded respectively by lower and upper value.

Definition at line 91 of file cp_overlay.cpp.

Referenced by CP_AddRadarCoverage(), and CP_IncreaseXVILevel().

void CP_SetXVILevel ( int  x,
int  y,
int  value 
)
void CP_UploadRadarCoverage ( void  )

Smooth radar coverage.

Note
allows to make texture pixels less visible.

Definition at line 422 of file cp_overlay.cpp.

References cgi, cgame_import_s::r_radarPic, RADAR_HEIGHT, and RADAR_WIDTH.

Referenced by RADAR_UpdateStaticRadarCoverage(), and RADAR_UpdateWholeRadarOverlay().

static void CP_UploadXVI ( void  )
inlinestatic
static byte* CP_XVIGetAlpha ( int  x,
int  y 
)
inlinestatic

Definition at line 35 of file cp_overlay.cpp.

References cgi, cgame_import_s::r_xviAlpha, and XVI_WIDTH.

Referenced by CP_GetXVILevel(), and CP_SetXVILevel().

Variable Documentation

const int INITIAL_ALPHA_VALUE = 60
static
const int MAX_ALPHA_VALUE = 200
static

Max alpha level - don't set this to 255 or nothing else will be visible below the mask

Definition at line 32 of file cp_overlay.cpp.

Referenced by CP_IncreaseXVILevel(), and CP_SetXVILevel().