Micropolis
Map< DATA, BLKSIZE > Class Template Reference

#include <map_type.h>

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 ()
 
size_t getTotalByteSize () const
 

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
DATAData type of a data value.
BLKSIZESize of the cluster.

Definition at line 112 of file map_type.h.

Constructor & Destructor Documentation

◆ Map() [1/2]

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

Generic map constructor.

Parameters
defaultValueDefault value to use for off-map positions, and for clearing the map.

Definition at line 159 of file map_type.h.

◆ Map() [2/2]

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

Copy constructor

Definition at line 170 of file map_type.h.

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

◆ ~Map()

template<typename DATA , int BLKSIZE>
Map< DATA, BLKSIZE >::~Map

Generic map destructor

Definition at line 197 of file map_type.h.

Member Function Documentation

◆ clear()

template<typename DATA , int BLKSIZE>
void Map< DATA, BLKSIZE >::clear

Generic clear routine.

Resets all data of the map to _MAP_DEFAULT_VALUE.

Definition at line 222 of file map_type.h.

Referenced by Micropolis::destroyMapArrays(), Micropolis::doPowerScan(), Micropolis::init(), Micropolis::initWillStuff(), and Micropolis::populationDensityScan().

◆ fill()

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

Generic fill routine.

Parameters
valueValue with which to fill the map.

Definition at line 208 of file map_type.h.

Referenced by Micropolis::simLoadInit().

◆ get()

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
xX cluster position (at world position x * MAP_BLOCKSIZE).
yY cluster position (at world position y * MAP_BLOCKSIZE).
Returns
Value of the cluster.

Definition at line 265 of file map_type.h.

Referenced by Micropolis::decRateOfGrowthMap(), Micropolis::getCrimeRate(), Micropolis::getFireCoverage(), Micropolis::getLandValue(), Micropolis::getPoliceCoverage(), Micropolis::getPollutionDensity(), Micropolis::getPopulationDensity(), Micropolis::getRateOfGrowth(), Micropolis::getTrafficDensity(), smoothDitherMap(), and smoothStationMap().

◆ getBase()

◆ onMap()

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
xX cluster position (at world position x * MAP_BLOCKSIZE).
yY cluster position (at world position y * MAP_BLOCKSIZE).
Returns
Coordinate is within map boundaries.

Definition at line 282 of file map_type.h.

◆ operator=()

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

Assignment operator

Definition at line 184 of file map_type.h.

References Map< DATA, BLKSIZE >::_mapData.

◆ set()

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
xX cluster position (at world position x * MAP_BLOCKSIZE).
yY cluster position (at world position y * MAP_BLOCKSIZE).
valueValue to use.

Definition at line 248 of file map_type.h.

Referenced by Micropolis::computeComRateMap(), Micropolis::decRateOfGrowthMap(), Micropolis::setCrimeRate(), Micropolis::setFireCoverage(), Micropolis::setLandValue(), Micropolis::setPoliceCoverage(), Micropolis::setPollutionDensity(), Micropolis::setPopulationDensity(), Micropolis::setRateOfGrowth(), Micropolis::setTrafficDensity(), and smoothStationMap().

◆ worldGet()

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

◆ worldOnMap()

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
xX world position.
yY world position.
Returns
Coordinate is within map boundaries.

Definition at line 335 of file map_type.h.

References WORLD_H, and WORLD_W.

◆ worldSet()

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
xX world position.
yY world position.
valueValue to use.

Definition at line 297 of file map_type.h.

Referenced by Micropolis::crimeScan(), Micropolis::decTrafficMap(), Micropolis::doPowerScan(), Micropolis::doSpecialZone(), Micropolis::fireZone(), Micropolis::incRateOfGrowth(), Micropolis::populationDensityScan(), Micropolis::setPowerGrid(), and Micropolis::startFireInZone().

Member Data Documentation

◆ _mapData

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

Data fields of the map in column-major mode.

Definition at line 146 of file map_type.h.

Referenced by Map< DATA, BLKSIZE >::Map(), and Map< DATA, BLKSIZE >::operator=().

◆ MAP_BLOCKSIZE

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

Size of a cluster in number of world positions.

Definition at line 121 of file map_type.h.

Referenced by Micropolis::crimeScan(), Micropolis::decTrafficMap(), and Micropolis::getTrafficAverage().


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