Map< DATA, BLKSIZE > Class Template Reference

#include <map_type.h>

List of all members.

Public Member Functions

 Map (DATA defaultValue)
 Map (const Map< DATA, BLKSIZE > &map)
Mapoperator= (const Map< DATA, BLKSIZE > &map)
 ~Map ()
void fill (DATA val)
void clear ()
void set (int x, int y, DATA val)
DATA get (int x, int y) const
bool onMap (int x, int y) const
void worldSet (int x, int y, DATA val)
DATA worldGet (int x, int y) const
bool worldOnMap (int x, int y) const
DATA * getBase ()

Public Attributes

const int MAP_BLOCKSIZE
const int MAP_W
 Number of clusters in horizontal direction.
const int MAP_H
 Number of clusters in vertical direction.

Private Attributes

DATA _mapData [((WORLD_W+BLKSIZE-1)/BLKSIZE)*((WORLD_H+BLKSIZE-1)/BLKSIZE)]
const DATA _MAP_DEFAULT_VALUE
 Default value of a cluster.


Detailed Description

template<typename DATA, int BLKSIZE>
class Map< DATA, BLKSIZE >

Generic class for maps in the Micropolis game.

A map is assumed to cover a 2D grid of WORLD_W times WORLD_H positions. A block of positions may be clustered, and represented by a single data value.

Template Parameters:
DATA Data type of a data value.
BLKSIZE Size of the cluster.

Definition at line 95 of file map_type.h.


Constructor & Destructor Documentation

template<typename DATA, int BLKSIZE>
Map< DATA, BLKSIZE >::Map ( DATA  defaultValue  )  [inline]

Generic map constructor.

Parameters:
defaultValue Default value to use for off-map positions, and for clearing the map.

Definition at line 136 of file map_type.h.

template<typename DATA, int BLKSIZE>
Map< DATA, BLKSIZE >::Map ( const Map< DATA, BLKSIZE > &  map  )  [inline]

Copy constructor

Definition at line 147 of file map_type.h.

References Map< DATA, BLKSIZE >::_mapData, Map< DATA, BLKSIZE >::MAP_H, and Map< DATA, BLKSIZE >::MAP_W.

template<typename DATA, int BLKSIZE>
Map< DATA, BLKSIZE >::~Map (  )  [inline]

Generic map destructor

Definition at line 174 of file map_type.h.


Member Function Documentation

template<typename DATA, int BLKSIZE>
Map< DATA, BLKSIZE > & Map< DATA, BLKSIZE >::operator= ( const Map< DATA, BLKSIZE > &  map  )  [inline]

Assignment operator

Definition at line 161 of file map_type.h.

References Map< DATA, BLKSIZE >::_mapData, Map< DATA, BLKSIZE >::MAP_H, and Map< DATA, BLKSIZE >::MAP_W.

template<typename DATA, int BLKSIZE>
void Map< DATA, BLKSIZE >::fill ( DATA  value  )  [inline]

Generic fill routine.

Parameters:
value Value with which to fill the map.

Definition at line 185 of file map_type.h.

References Map< DATA, BLKSIZE >::_mapData, Map< DATA, BLKSIZE >::MAP_H, and Map< DATA, BLKSIZE >::MAP_W.

Referenced by Map< DATA, BLKSIZE >::clear().

template<typename DATA, int BLKSIZE>
void Map< DATA, BLKSIZE >::clear (  )  [inline]

Generic clear routine.

Resets all data of the map to _MAP_DEFAULT_VALUE.

Definition at line 199 of file map_type.h.

References Map< DATA, BLKSIZE >::_MAP_DEFAULT_VALUE, and Map< DATA, BLKSIZE >::fill().

Referenced by Micropolis::init(), and Micropolis::initWillStuff().

template<typename DATA, int BLKSIZE>
void Map< DATA, BLKSIZE >::set ( int  x,
int  y,
DATA  value 
) [inline]

Set the value of a cluster.

If the coordinate is off the map, the value is not stored.

Parameters:
x X cluster position (at world position x * MAP_BLOCKSIZE).
y Y cluster position (at world position y * MAP_BLOCKSIZE).
value Value to use.

Definition at line 225 of file map_type.h.

References Map< DATA, BLKSIZE >::_mapData, Map< DATA, BLKSIZE >::MAP_H, and Map< DATA, BLKSIZE >::onMap().

Referenced by Micropolis::computeComRateMap(), Micropolis::decRateOfGrowthMap(), Micropolis::setFireCoverage(), Micropolis::setPoliceCoverage(), Micropolis::setRateOfGrowth(), and smoothStationMap().

template<typename DATA, int BLKSIZE>
DATA Map< DATA, BLKSIZE >::get ( int  x,
int  y 
) const [inline]

Return the value of a cluster.

If the coordinate is off the map, the _MAP_DEFAULT_VALUE is returned.

Parameters:
x X cluster position (at world position x * MAP_BLOCKSIZE).
y Y cluster position (at world position y * MAP_BLOCKSIZE).
Returns:
Value of the cluster.

Definition at line 242 of file map_type.h.

References Map< DATA, BLKSIZE >::_MAP_DEFAULT_VALUE, Map< DATA, BLKSIZE >::_mapData, Map< DATA, BLKSIZE >::MAP_H, and Map< DATA, BLKSIZE >::onMap().

Referenced by Micropolis::decRateOfGrowthMap(), Micropolis::getFireCoverage(), Micropolis::getPoliceCoverage(), Micropolis::getRateOfGrowth(), and smoothStationMap().

template<typename DATA, int BLKSIZE>
bool Map< DATA, BLKSIZE >::onMap ( int  x,
int  y 
) const [inline]

Verify that cluster coordinates are within map boundaries.

Parameters:
x X cluster position (at world position x * MAP_BLOCKSIZE).
y Y cluster position (at world position y * MAP_BLOCKSIZE).
Returns:
Coordinate is within map boundaries.

Definition at line 259 of file map_type.h.

References Map< DATA, BLKSIZE >::MAP_H, and Map< DATA, BLKSIZE >::MAP_W.

Referenced by Map< DATA, BLKSIZE >::get(), and Map< DATA, BLKSIZE >::set().

template<typename DATA, int BLKSIZE>
void Map< DATA, BLKSIZE >::worldSet ( int  x,
int  y,
DATA  value 
) [inline]

Set the value of a cluster.

If the coordinate is off the map, the value is not stored.

Parameters:
x X world position.
y Y world position.
value Value to use.

Definition at line 274 of file map_type.h.

References Map< DATA, BLKSIZE >::_mapData, Map< DATA, BLKSIZE >::MAP_H, and Map< DATA, BLKSIZE >::worldOnMap().

Referenced by Micropolis::doSpecialZone(), Micropolis::fireZone(), Micropolis::incRateOfGrowth(), and Micropolis::startFireInZone().

template<typename DATA, int BLKSIZE>
DATA Map< DATA, BLKSIZE >::worldGet ( int  x,
int  y 
) const [inline]

Return the value of a cluster.

If the coordinate is off the map, the _MAP_DEFAULT_VALUE is returned.

Parameters:
x X world position.
y Y world position.
Returns:
Value of the cluster.

Definition at line 293 of file map_type.h.

References Map< DATA, BLKSIZE >::_MAP_DEFAULT_VALUE, Map< DATA, BLKSIZE >::_mapData, Map< DATA, BLKSIZE >::MAP_H, and Map< DATA, BLKSIZE >::worldOnMap().

Referenced by Micropolis::crimeScan(), Micropolis::doFire(), Micropolis::doSpecialZone(), Micropolis::evalCom(), Micropolis::fireZone(), Micropolis::getDensityStr(), Micropolis::incRateOfGrowth(), and Micropolis::startFireInZone().

template<typename DATA, int BLKSIZE>
bool Map< DATA, BLKSIZE >::worldOnMap ( int  x,
int  y 
) const [inline]

Verify that world coordinates are within map boundaries.

Parameters:
x X world position.
y Y world position.
Returns:
Coordinate is within map boundaries.

Definition at line 312 of file map_type.h.

References WORLD_H, and WORLD_W.

Referenced by Map< DATA, BLKSIZE >::worldGet(), and Map< DATA, BLKSIZE >::worldSet().

template<typename DATA, int BLKSIZE>
DATA * Map< DATA, BLKSIZE >::getBase (  )  [inline]

Return the base address of the map data.

Note:
Data is stored in column-major mode.

Definition at line 210 of file map_type.h.

References Map< DATA, BLKSIZE >::_mapData.

Referenced by Micropolis::getFireCoverageMapBuffer(), Micropolis::getPoliceCoverageMapBuffer(), and Micropolis::getRateOfGrowthMapBuffer().


Member Data Documentation

template<typename DATA, int BLKSIZE>
const int Map< DATA, BLKSIZE >::MAP_BLOCKSIZE

Size of a cluster in number of world positions.

Definition at line 104 of file map_type.h.

template<typename DATA, int BLKSIZE>
DATA Map< DATA, BLKSIZE >::_mapData[((WORLD_W+BLKSIZE-1)/BLKSIZE)*((WORLD_H+BLKSIZE-1)/BLKSIZE)] [private]


The documentation for this class was generated from the following file:

Generated on Wed Feb 2 09:19:22 2011 for Micropolis by  doxygen 1.5.6