Cytopia  0.3
A city building simulation game
Map Class Reference

#include <Map.hxx>

+ Collaboration diagram for Map:

Public Member Functions

 Map (int columns, int rows, const bool generateTerrain)
 
 Map (int columns, int rows)
 
 ~Map ()
 
 Map (Map &other)=delete
 
Map & operator= (const Map &other)=delete
 
 Map (Map &&fp)=delete
 
const Map & operator= (Map &&fp)=delete
 
void renderMap () const
 Render the elements contained in the Map. More...
 

Private Member Functions

void refresh ()
 Refresh all the map tile textures. More...
 
MapNode & getMapNode (Point isoCoords)
 Get pointer to a single mapNode at specific iso coordinates. More...
 
const std::vector< MapNode > & getMapNodes ()
 Get all mapnodes as a vector. More...
 
void calculateVisibleMap (void)
 For implementing frustum culling, find all map nodes which are visible on the screen. Only visible nodes will be rendered. More...
 

Private Attributes

std::vector< MapNode > mapNodes
 
std::vector< MapNode * > mapNodesInDrawingOrder
 
Sprite ** pMapNodesVisible
 
int m_visibleNodesCount = 0
 
int m_columns
 
int m_rows
 
std::default_random_engine randomEngine
 
TerrainGenerator m_terrainGen
 

Static Private Attributes

static const size_t m_saveGameVersion
 

Friends

class MapFunctions
 

Detailed Description

Definition at line 23 of file Map.hxx.

Constructor & Destructor Documentation

◆ Map() [1/4]

Map::Map ( int  columns,
int  rows,
const bool  generateTerrain 
)

Definition at line 76 of file Map.cxx.

77  : pMapNodesVisible(new Sprite *[columns * rows]), m_columns(columns), m_rows(rows)
78 {
79  // TODO move Random Engine out of map
80  randomEngine.seed();
82 
83  if (generateTerrain)
84  {
87  }
88  else
89  {
90  for (int x = 0; x < Settings::instance().mapSize; x++)
91  {
92  for (int y = 0; y < Settings::instance().mapSize; y++)
93  {
94  mapNodes.emplace_back(MapNode{Point{x, y, 0, 1}, DEFAULT_TERRAIN});
95  }
96  }
97  }
98 }
+ Here is the call graph for this function:

◆ Map() [2/4]

Map::Map ( int  columns,
int  rows 
)

Definition at line 69 of file Map.cxx.

69  : pMapNodesVisible(new Sprite *[columns * rows]), m_columns(columns), m_rows(rows)
70 {
71  // TODO move Random Engine out of map
72  randomEngine.seed();
74 }
+ Here is the call graph for this function:

◆ ~Map()

Map::~Map ( )

Definition at line 100 of file Map.cxx.

100 { delete[] pMapNodesVisible; }

◆ Map() [3/4]

Map::Map ( Map &  other)
delete

◆ Map() [4/4]

Map::Map ( Map &&  fp)
delete

Member Function Documentation

◆ calculateVisibleMap()

void Map::calculateVisibleMap ( void  )
private

For implementing frustum culling, find all map nodes which are visible on the screen. Only visible nodes will be rendered.

Definition at line 128 of file Map.cxx.

129 {
130  const Point topLeft = calculateIsoCoordinates({0, 0});
132 
133  // Screen edges
134  const int left = topLeft.x + topLeft.y - 2;
135  const int right = bottomRight.x + bottomRight.y + 1;
136  const int top = topLeft.y - topLeft.x + 1;
137  // Lower the bottom because of high terrain nodes under the screen which will be pushed into the view
138  const int bottom = bottomRight.y - bottomRight.x - 1 - MapNode::maxHeight;
139 
141 
142  // ZOrder starts from topmost node to the right. (0,127) =1,(1,127) =2, ...
143  for (int y = m_columns - 1; y >= 0; y--)
144  {
145  for (int x = 0; x < m_rows; x++)
146  {
147  const int xVal = x + y;
148  const int yVal = y - x;
149 
150  if ((xVal >= left) && (xVal <= right) && (yVal <= top) && (yVal >= bottom))
151  {
152  pMapNodesVisible[m_visibleNodesCount++] = getMapNode({x, y}).getSprite();
153  }
154  }
155  }
156 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMapNode()

MapNode& Map::getMapNode ( Point  isoCoords)
inlineprivate

Get pointer to a single mapNode at specific iso coordinates.

Parameters
isoCoordsThe node to retrieve.

Definition at line 54 of file Map.hxx.

54 { return mapNodes[isoCoords.toIndex()]; };
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMapNodes()

const std::vector<MapNode>& Map::getMapNodes ( )
inlineprivate

Get all mapnodes as a vector.

Definition at line 58 of file Map.hxx.

58 { return mapNodes; };

◆ operator=() [1/2]

Map& Map::operator= ( const Map &  other)
delete

◆ operator=() [2/2]

const Map& Map::operator= ( Map &&  fp)
delete

◆ refresh()

void Map::refresh ( )
private

Refresh all the map tile textures.

See also
Sprite::refresh

Definition at line 114 of file Map.cxx.

115 {
116 #ifdef MICROPROFILE_ENABLED
117  MICROPROFILE_SCOPEI("Map", "Refresh Map", MP_YELLOW);
118 #endif
119 
121 
122  for (int i = 0; i < m_visibleNodesCount; ++i)
123  {
125  }
126 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ renderMap()

void Map::renderMap ( ) const

Render the elements contained in the Map.

call the render() function of the sprite in the all contained MapNode elements

See also
Sprite::render

Definition at line 102 of file Map.cxx.

103 {
104 #ifdef MICROPROFILE_ENABLED
105  MICROPROFILE_SCOPEI("Map", "Render Map", MP_YELLOW);
106 #endif
107 
108  for (int i = 0; i < m_visibleNodesCount; ++i)
109  {
110  pMapNodesVisible[i]->render();
111  }
112 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ MapFunctions

friend class MapFunctions
friend

Definition at line 35 of file Map.hxx.

Member Data Documentation

◆ m_columns

int Map::m_columns
private

Definition at line 70 of file Map.hxx.

◆ m_rows

int Map::m_rows
private

Definition at line 71 of file Map.hxx.

◆ m_saveGameVersion

const size_t Map::m_saveGameVersion
staticprivate

Definition at line 75 of file Map.hxx.

◆ m_terrainGen

TerrainGenerator Map::m_terrainGen
private

Definition at line 73 of file Map.hxx.

◆ m_visibleNodesCount

int Map::m_visibleNodesCount = 0
private

Definition at line 69 of file Map.hxx.

◆ mapNodes

std::vector<MapNode> Map::mapNodes
private

Definition at line 66 of file Map.hxx.

◆ mapNodesInDrawingOrder

std::vector<MapNode *> Map::mapNodesInDrawingOrder
private

Definition at line 67 of file Map.hxx.

◆ pMapNodesVisible

Sprite** Map::pMapNodesVisible
private

Definition at line 68 of file Map.hxx.

◆ randomEngine

std::default_random_engine Map::randomEngine
private

Definition at line 72 of file Map.hxx.


The documentation for this class was generated from the following files:
WATER
@ WATER
6- Water tiles
Definition: enums.hxx:17
Map::mapNodes
std::vector< MapNode > mapNodes
Definition: Map.hxx:66
Map::m_terrainGen
TerrainGenerator m_terrainGen
Definition: Map.hxx:73
Point::toIndex
int toIndex() const
calculates the index (stride) that can be used to access in Map to access mapNodes vector.
Definition: Point.hxx:80
MapLayers::enableLayers
static void enableLayers(std::vector< unsigned int > &&layers)
Enable drawing layers.
Definition: MapLayers.cxx:26
Sprite
Definition: Sprite.hxx:32
calculateIsoCoordinates
Point calculateIsoCoordinates(const SDL_Point &screenCoordinates)
Calculates screen space coordinates to isometric space coordinates.
Definition: isoMath.cxx:11
SettingsData::screenHeight
ScreenDimension screenHeight
the screen height
Definition: Settings.hxx:46
Map::m_visibleNodesCount
int m_visibleNodesCount
Definition: Map.hxx:69
POWERLINES
@ POWERLINES
9- Powerlines
Definition: enums.hxx:20
Sprite::render
void render() const
Definition: Sprite.cxx:23
TerrainGenerator::generateTerrain
void generateTerrain(std::vector< MapNode > &mapNodes, std::vector< MapNode * > &mapNodesInDrawingOrder)
Definition: TerrainGenerator.cxx:21
MapNode::maxHeight
static const int maxHeight
Maximum height of the node.
Definition: MapNode.hxx:186
DemolishMode::GROUND_DECORATION
@ GROUND_DECORATION
Remove only ground decoration.
Point::y
int y
The y coordinate.
Definition: Point.hxx:20
SettingsData::mapSize
int mapSize
the size of the map
Definition: Settings.hxx:34
Map::m_rows
int m_rows
Definition: Map.hxx:71
Point::x
int x
The x coordinate.
Definition: Point.hxx:14
SettingsData::screenWidth
ScreenDimension screenWidth
the screen width
Definition: Settings.hxx:40
MapNode
Class that holds map nodes.
Definition: MapNode.hxx:30
ZONE
@ ZONE
4- Optional layer, zones(Industrial/Residential/Commercial).
Definition: enums.hxx:15
TerrainGenerator::generateRiver
void generateRiver(std::vector< MapNode > &mapNodes)
Definition: TerrainGenerator.cxx:179
BUILDINGS
@ BUILDINGS
8- Buildings, Streets and everything that goes on the terrain
Definition: enums.hxx:19
Map::m_columns
int m_columns
Definition: Map.hxx:70
DEFAULT_TERRAIN
const std::string DEFAULT_TERRAIN
Definition: Constants.hxx:27
Map::getMapNode
MapNode & getMapNode(Point isoCoords)
Get pointer to a single mapNode at specific iso coordinates.
Definition: Map.hxx:54
FLORA
@ FLORA
10- Trees and other flora/Fauna tiles
Definition: enums.hxx:21
Map::mapNodesInDrawingOrder
std::vector< MapNode * > mapNodesInDrawingOrder
Definition: Map.hxx:67
Map::calculateVisibleMap
void calculateVisibleMap(void)
For implementing frustum culling, find all map nodes which are visible on the screen....
Definition: Map.cxx:128
Map::randomEngine
std::default_random_engine randomEngine
Definition: Map.hxx:72
ROAD
@ ROAD
5- Optional layer, roads.
Definition: enums.hxx:16
LayerEditMode::TERRAIN
@ TERRAIN
Default "overworld" edit mode.
Sprite::refresh
void refresh(const Layer &layer=Layer::NONE)
Definition: Sprite.cxx:73
Point
Definition: Point.hxx:7
Singleton< Settings >::instance
static Settings & instance(void)
Get an instance of the singleton.
Definition: Singleton.hxx:15
Map::pMapNodesVisible
Sprite ** pMapNodesVisible
Definition: Map.hxx:68