cp_overlay.c File Reference

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

#include "../cl_shared.h"
#include "../renderer/r_image.h"
#include "cp_campaign.h"
#include "cp_overlay.h"
Include dependency graph for cp_overlay.c:

Go to the source code of this file.

Defines

#define XVI_WIDTH   512
#define XVI_HEIGHT   256
#define RADAR_WIDTH   512
#define RADAR_HEIGHT   256
#define DAN_WIDTH   512
#define DAN_HEIGHT   256
#define DAWN   0.03

Functions

void CP_CalcAndUploadDayAndNightTexture (float q)
 Applies alpha values to the night overlay image for 2d geoscape.
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.
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.
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.
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.
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.
void CP_DecreaseXVILevelEverywhere (void)
void CP_ChangeXVILevel (const vec2_t pos, float factor)
void CP_InitializeXVIOverlay (const byte *data)
 Initialize XVI overlay on geoscape.
void CP_InitializeRadarOverlay (qboolean source)
 Radar overlay code description The radar overlay is handled in 2 times : bases radar range and aircraft radar range. Bases radar range needs to be updated only when a radar facilities is built or destroyed. The base radar overlay is stored in r_radarSourcePic. Aircraft radar overlay needs to be updated every time an aircraft moves, because the position of the radar moves. this overlay is created by duplicating r_radarSourcePic, and then adding any aircraft radar coverage. It is stored in r_radarTexture.
static void CP_DrawRadarOverlayRow (float latMin, float latMax, int y, byte alpha, qboolean source)
 Draw radar overlay for a given latitude between 2 longitudes.
void CP_AddRadarCoverage (const vec2_t pos, float innerRadius, float outerRadius, qboolean source)
 Add a radar coverage (base or aircraft) to radar overlay.
void CP_UploadRadarCoverage (void)
 Smooth radar coverage.
void CP_ShutdownOverlay (void)
void CP_InitOverlay (void)

Variables

static const int MAX_ALPHA_VALUE = 200
static const int INITIAL_ALPHA_VALUE = 60
image_tr_dayandnightTexture
image_tr_radarTexture
image_tr_xviTexture
static byte r_xviAlpha [XVI_WIDTH *XVI_HEIGHT]
static byte r_radarPic [RADAR_WIDTH *RADAR_HEIGHT]
static byte r_radarSourcePic [RADAR_WIDTH *RADAR_HEIGHT]
static byte r_dayandnightAlpha [DAN_WIDTH *DAN_HEIGHT]

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.c.


Define Documentation

#define DAN_HEIGHT   256

Definition at line 41 of file cp_overlay.c.

Referenced by CP_CalcAndUploadDayAndNightTexture(), and CP_InitOverlay().

#define DAN_WIDTH   512

Definition at line 40 of file cp_overlay.c.

Referenced by CP_CalcAndUploadDayAndNightTexture(), and CP_InitOverlay().

#define DAWN   0.03

Definition at line 43 of file cp_overlay.c.

Referenced by CP_CalcAndUploadDayAndNightTexture().

#define RADAR_HEIGHT   256

Definition at line 39 of file cp_overlay.c.

Referenced by CP_AddRadarCoverage(), CP_InitOverlay(), and CP_UploadRadarCoverage().

#define RADAR_WIDTH   512
#define XVI_HEIGHT   256
#define XVI_WIDTH   512

Function Documentation

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

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

Parameters:
[in] pos Position of the center of radar
[in] innerRadius Radius of the radar coverage
[in] outerRadius Radius of the outer radar coverage
[in] source True 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 420 of file cp_overlay.c.

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

Referenced by RADAR_DrawCoverage(), and RADAR_UpdateStaticRadarCoverage().

void CP_CalcAndUploadDayAndNightTexture ( float  q  ) 

Applies alpha values to the night overlay image for 2d geoscape.

Parameters:
[in] q The angle the sun is standing against the equator on earth

Definition at line 66 of file cp_overlay.c.

References byte, COS_ALPHA, DAN_HEIGHT, DAN_WIDTH, DAWN, HIGH_LAT, LOW_LAT, pos, r_dayandnightAlpha, R_UploadAlpha(), and SIN_ALPHA.

Referenced by MAP_DrawMap().

void CP_ChangeXVILevel ( const vec2_t  pos,
float  factor 
)

Definition at line 304 of file cp_overlay.c.

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

Referenced by CP_SpreadXVIAtPos().

void CP_DecreaseXVILevelEverywhere ( void   ) 
See also:
R_IncreaseXVILevel

< current position (in pixel)

Definition at line 289 of file cp_overlay.c.

References CP_GetXVILevel(), CP_SetXVILevel(), R_UploadAlpha(), r_xviAlpha, XVI_HEIGHT, and XVI_WIDTH.

Referenced by CP_ReduceXVIEverywhere().

static void CP_DrawRadarOverlayRow ( float  latMin,
float  latMax,
int  y,
byte  alpha,
qboolean  source 
) [static]

Draw radar overlay for a given latitude between 2 longitudes.

Parameters:
[in] latMin Minimum latitude.
[in] latMax Maximum latitude.
[in] y current row in radar overlay.
[in] source True 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 362 of file cp_overlay.c.

References byte, dest, EQUAL_EPSILON, f, r_radarPic, r_radarSourcePic, 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] xMin Minimum column (this volumn will be reached).
[in] xMax Maximum column (this volumn won't be reached).
[in] centerPos Position of the center of the circle.
[in] y current row in XVI overlay.
[in] yLat Latitude (in degree) of the current Row.
[in] xviLevel Level of XVI at the center of the circle (ie at center ).
[in] radius Radius of the circle.

Definition at line 189 of file cp_overlay.c.

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 Minimum latitude (in degree).
[in] latMax Maximum latitude (in degree).
[in] center Position of the center of the circle.
[in] y current row in XVI overlay.
[in] yLat Latitude (in degree) of the current Row.
[in] xviLevel Level of XVI at the center of the circle (ie at center ).
[in] radius Radius of the circle.
Precondition:
We assume latMax - latMin <= 360 degrees.

Definition at line 220 of file cp_overlay.c.

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 
) [inline, static]

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

Parameters:
[in] centerPos center of the circle (radar coverage, XVI infection zone).
[in] radius radius of the circle.
[in] yLat latitude 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 173 of file cp_overlay.c.

References todeg, and torad.

Referenced by CP_AddRadarCoverage(), and CP_IncreaseXVILevel().

int CP_GetXVILevel ( int  x,
int  y 
)
void CP_GetXVIMapDimensions ( int *  width,
int *  height 
)

Definition at line 103 of file cp_overlay.c.

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:
[in] xCenter X Position of the center of XVI spreading
[in] yCenter Y Position of the center of XVI spreading
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.
Returns:
the radius of the new XVI level

< 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 259 of file cp_overlay.c.

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

Referenced by CP_ChangeXVILevel().

void CP_InitializeRadarOverlay ( qboolean  source  ) 

Radar overlay code description The radar overlay is handled in 2 times : bases radar range and aircraft radar range. Bases radar range needs to be updated only when a radar facilities is built or destroyed. The base radar overlay is stored in r_radarSourcePic. Aircraft radar overlay needs to be updated every time an aircraft moves, because the position of the radar moves. this overlay is created by duplicating r_radarSourcePic, and then adding any aircraft radar coverage. It is stored in r_radarTexture.

See also:
RADAR_UpdateWholeRadarOverlay Initialize radar overlay on geoscape.
Parameters:
[in] source Initialize the source texture if qtrue: 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 345 of file cp_overlay.c.

References INITIAL_ALPHA_VALUE, r_radarPic, and r_radarSourcePic.

Referenced by RADAR_UpdateStaticRadarCoverage(), and RADAR_UpdateWholeRadarOverlay().

void CP_InitializeXVIOverlay ( const byte data  ) 

Initialize XVI overlay on geoscape.

Parameters:
[in] data Pointer to the data containing values to store in XVI map. Can be NULL for new games. This is only the alpha channel of the xvi map
Note:
xvi rate is null when alpha = 0, max when alpha = maxAlpha

Definition at line 318 of file cp_overlay.c.

References R_UploadAlpha(), and r_xviAlpha.

Referenced by CP_CampaignInit(), and XVI_LoadXML().

void CP_InitOverlay ( void   ) 
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] pos Position of the center of circle.
[in] radius Radius of the circle to be drawn.
[in] height Height of the overlay (in pixel).
[out] yMin Pointer to the lower row of the overlay that should be changed.
[out] yMax Pointer 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 142 of file cp_overlay.c.

Referenced by CP_AddRadarCoverage(), and CP_IncreaseXVILevel().

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

Definition at line 482 of file cp_overlay.c.

Referenced by CP_CampaignExit().

void CP_UploadRadarCoverage ( void   ) 

Smooth radar coverage.

Note:
allows to make texture pixels less visible.

Definition at line 475 of file cp_overlay.c.

References r_radarPic, R_SoftenTexture(), R_UploadAlpha(), RADAR_HEIGHT, and RADAR_WIDTH.

Referenced by RADAR_UpdateStaticRadarCoverage(), and RADAR_UpdateWholeRadarOverlay().


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 33 of file cp_overlay.c.

Referenced by CP_IncreaseXVILevel(), and CP_SetXVILevel().

byte r_dayandnightAlpha[DAN_WIDTH *DAN_HEIGHT] [static]

this is the data that is used with r_dayandnightTexture

Definition at line 60 of file cp_overlay.c.

Referenced by CP_CalcAndUploadDayAndNightTexture().

this is the mask that is used to display day/night on (2d-)geoscape

Definition at line 46 of file cp_overlay.c.

byte r_radarPic[RADAR_WIDTH *RADAR_HEIGHT] [static]

this is the data that is used with r_radarTexture

Definition at line 54 of file cp_overlay.c.

Referenced by CP_DrawRadarOverlayRow(), CP_InitializeRadarOverlay(), and CP_UploadRadarCoverage().

byte r_radarSourcePic[RADAR_WIDTH *RADAR_HEIGHT] [static]

this is the data that is used with r_radarTexture

Definition at line 57 of file cp_overlay.c.

Referenced by CP_DrawRadarOverlayRow(), and CP_InitializeRadarOverlay().

radar texture

Definition at line 47 of file cp_overlay.c.

byte r_xviAlpha[XVI_WIDTH *XVI_HEIGHT] [static]

this is the data that is used with r_xviTexture

Definition at line 51 of file cp_overlay.c.

Referenced by CP_DecreaseXVILevelEverywhere(), CP_GetXVILevel(), CP_IncreaseXVILevel(), CP_InitializeXVIOverlay(), and CP_SetXVILevel().

XVI alpha mask texture

Definition at line 48 of file cp_overlay.c.


Generated by  doxygen 1.6.2