Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes

Map Class Reference

Map Loading and Manipulation. More...

#include <Map.h>

Inheritance diagram for Map:
IsoMap TileMap IsoBlock

List of all members.

Public Member Functions

 Map (const std::string &filePath, const std::string &driverName)
 Map (int width, int height, TileSet &tset)
virtual ~Map ()
void debug ()
int save (const std::string &filename)
void setViewport (int x, int y)
void moveViewport (int x, int y)
void attachCamera (Entity *entity)
void detachCamera ()
void drawCursor (bool draw)
bool drawCursor ()
void injectMouseCoords (int pointerX, int pointerY)
void insertTile (Uint tsetId, Uint tsetIndex, Uint layerId, int mapX, int mapY)
void insertProp (Prop *prop, int x, int y)
void deleteProp (Prop *prop)
void update ()
const std::string & getName () const
void setName (const std::string &name)
const std::string & getBgAudio () const
void setBgAudio (const std::string &audio)
bool isLoaded () const
const TsetListgetTileSets () const
const int getWorldWidth () const
const int getWorldHeight () const
const int getCameraOffsetX () const
const int getCameraOffsetY () const
const PropFactorygetPropFactory () const
const PropsgetProps () const
const WarpAreasgetWarpAreas () const
WarpAreagetWarpArea (int x, int y)

Protected Member Functions

pair< int, int > getScreenGridBox ()

Protected Attributes

CameramCamera
PropFactorymPropFactory
int mMapWidth
int mMapHeight
int mTileWidth
int mTileHeight
int mTileTallestHeight
std::string mVersion
std::string mName
std::string mBgMusic
std::string mDriver
int mWorldSpaceW
int mWorldSpaceH
int mOffsetX
int mOffsetY
int mPointerX
int mPointerY
int mMouseTileX
int mMouseTileY
TsetList mTileSets
Layers mLayers
Props mProps
WarpAreas mWarpAreas
bool mIsLoaded
bool mDrawCursor

Private Member Functions

bool readXml (const std::string &filePath)
bool parseProperties (TiXmlNode *node)
bool parseTileSets (TiXmlNode *node)
bool parseLayers (TiXmlNode *node)
bool parseObjects (TiXmlNode *node)
bool parseProp (TiXmlNode *node)
bool parseWarpAreas (TiXmlNode *node)
int parseInteractors (TiXmlElement *xmlRootElement)
int parseSeats (TiXmlElement *xmlRootElement)
int parseNPCs (TiXmlElement *xmlRootElement)
int parseLights (TiXmlElement *xmlRootElement)
int parseTriggers (TiXmlElement *xmlRootElement)
void ensureTileIntegrity ()
void sortProps ()
virtual void draw ()=0
virtual void drawGrid ()
virtual void updateCursor ()=0
void drawDebug (int x, int y)

Private Attributes

TiXmlDocument * mMapXML
EntityManager mEntityManager
StringList mMessageList

Detailed Description

Map Loading and Manipulation.

The Map class handles all aspects of loading and storing map information. It includes internal lists of various objects and entities that are contained in the game world and also provides functions for drawing the map through a Renderer object.

Note:
Derived Map classes must create a Camera object. The Camera object will be destroyed by the base Map object and should not be destroyed by dervatives.
Regarding TileSets -- The last index of the TileSet list will always be a default constructed TileSet object. See TileSet for more information.
The Map class does not provide a copy constructor or overloaded assignment operator. All Map's must be either loaded from a map file or created from scratch dynamically. This is by design.

Constructor & Destructor Documentation

Map::Map ( const std::string &  filePath,
const std::string &  driverName 
)
Map::Map ( int  width,
int  height,
TileSet tset 
)
Map::~Map (  )  [virtual]

Destroys Map objects.


Member Function Documentation

void Map::attachCamera ( Entity entity  ) 

Move Camera position to fine coordinate X, Y.

void Map::debug (  ) 

Provides various debug information.

void Map::deleteProp ( Prop prop  ) 
void Map::detachCamera (  ) 

Move Camera position to fine coordinate X, Y.

virtual void Map::draw (  )  [private, pure virtual]

Implemented in IsoBlock.

bool Map::drawCursor (  ) 

Gets what the tile cursor draw flag is set to.

void Map::drawCursor ( bool  draw  ) 

Sets wether the tile cursor should be drawn or not.

void Map::drawDebug ( int  x,
int  y 
) [private]

Draws basic debug information.

This will generally be turned off for release builds although we can possibly add a toggle function to turn it on and off at will.

void Map::drawGrid (  )  [private, virtual]

Draws gridboxes on-screen as a visual aid.

This is generally a debugging visual aid and will typically not be drawn except during debugging and mapping sessions.

void Map::ensureTileIntegrity (  )  [private]

Scans through the tiles on all layers and ensures that the tile references a valid TileSet. If it doesn't, the tile's TileSet reference is changed to the default TileSet.

const std::string& Map::getBgAudio (  )  const [inline]
const int Map::getCameraOffsetX (  )  const

Gets the current camera's viewport X coordinate.

const int Map::getCameraOffsetY (  )  const

Gets the current camera's viewport Y coordinate.

const std::string& Map::getName (  )  const [inline]
const PropFactory* Map::getPropFactory (  )  const [inline]
const Props& Map::getProps (  )  const [inline]
pair< int, int > Map::getScreenGridBox (  )  [protected]

Returns a pair of values indicating the screenbox coordinates pointed at by mouse values.

const TsetList& Map::getTileSets (  )  const [inline]
WarpArea * Map::getWarpArea ( int  x,
int  y 
)

Gets a pointer to a WarpArea given a point.

Parameters:
x X-Coordinate within the map area.
y Y-Coordinate within the map area.
Returns:
Returns a pointer to a WarpArea. NULL if the point doesn't lie within the bounds of any WarpAreas.
const WarpAreas& Map::getWarpAreas (  )  const [inline]
const int Map::getWorldHeight (  )  const [inline]
const int Map::getWorldWidth (  )  const [inline]
void Map::injectMouseCoords ( int  pointerX,
int  pointerY 
)

Updates Pointer coordinates.

Parameters:
int pointerX X-Screen Coordinate.
int pointerY Y-Screen Coordinate.

I decided that I wanted to have the class store mouse coordinates and separate it from any sort of input code as input handling has no place within the map class.

void Map::insertProp ( Prop prop,
int  x,
int  y 
)

Inserts an Entity into the map and sets its position.

Parameters:
prop A pointer to a properly constructed Prop.
x X-Coordinate of the Prop's world location.
y Y-Coordinate of the Prop's world location.
Warning:
The Prop that's inserted into the Map becomes owned by the Map. When the Map is destroyed, the Prop is also destroyed and any remaining pointers to it will be invalidated.
Todo:
Because of the possibility of inserting multiple props at the same coordinates this function should ensure that no two props can occupy the same coordinate.
void Map::insertTile ( Uint  tsetId,
Uint  tsetIndex,
Uint  layerId,
int  mapX,
int  mapY 
)

Inserts a tile at map tile location (X, Y) from a tileset.

Parameters:
tsetId A TileSet ID as defined in a map file.
tsetIndex Index in a given TileSet.
layerId Map Layer to insert Tile into.
mapX Map X coordinate. -1 indicates to use the internal Mouse/Tile conversion.
mapY Map Y coordainte. -1 indicates to use the internal Mouse/Tile conversion.
Todo:
This function does absolutely no sanity or bounds checking so expect crashing should garbage data be passed in.
bool Map::isLoaded (  )  const [inline]
void Map::moveViewport ( int  x,
int  y 
)

Moves Camera'a position by X, Y.

int Map::parseInteractors ( TiXmlElement *  xmlRootElement  )  [private]
Todo:
Finish these functions.
bool Map::parseLayers ( TiXmlNode *  node  )  [private]

Parses <layer> tags in <layers> group.

int Map::parseLights ( TiXmlElement *  xmlRootElement  )  [private]
int Map::parseNPCs ( TiXmlElement *  mapRootElement  )  [private]

Reads and loads the NPCs section of XML.

bool Map::parseObjects ( TiXmlNode *  node  )  [private]
bool Map::parseProp ( TiXmlNode *  node  )  [private]

Parses an XML node for properties needed to generate a Prop, validates it, generates a Prop and adds it to the Map object's Prop list.

bool Map::parseProperties ( TiXmlNode *  node  )  [private]

Reads in the map properties from the XML file.

int Map::parseSeats ( TiXmlElement *  xmlRootElement  )  [private]
bool Map::parseTileSets ( TiXmlNode *  node  )  [private]

Parses through and loads any TileSets.

int Map::parseTriggers ( TiXmlElement *  xmlRootElement  )  [private]
bool Map::parseWarpAreas ( TiXmlNode *  node  )  [private]

Parses the child nodes of a 'warpareas' node.

bool Map::readXml ( const std::string &  filePath  )  [private]
int Map::save ( const std::string &  filename  ) 
void Map::setBgAudio ( const std::string &  audio  )  [inline]
void Map::setName ( const std::string &  name  )  [inline]
void Map::setViewport ( int  x,
int  y 
)

Sets Camera's position to fine coordinate X, Y.

void Map::sortProps (  )  [private]
void Map::update (  ) 

Updates map states and draws the map, cursors and debug information.

virtual void Map::updateCursor (  )  [private, pure virtual]

Implemented in IsoMap.


Member Data Documentation

std::string Map::mBgMusic [protected]

Filepath to a music file relative to the base data path.

Camera* Map::mCamera [protected]

Camera properties.

bool Map::mDrawCursor [protected]

Internal flag indicating whether or not to draw the tile cursor.

std::string Map::mDriver [protected]

Driver type. Used to determine what type of map is being drawn.

bool Map::mIsLoaded [protected]

Internal flag indicating if the map loaded properly.

Layers Map::mLayers [protected]

List of mapLayer objects.

int Map::mMapHeight [protected]

Height of the Map in Tiles.

int Map::mMapWidth [protected]

Width of the Map in Tiles.

TiXmlDocument* Map::mMapXML [private]

XML Document.

List of messages, error or otherwise, generated during processing and operation of the Map.

int Map::mMouseTileX [protected]
int Map::mMouseTileY [protected]

Tile pointed at by the mouse.

std::string Map::mName [protected]

Map Name string.

int Map::mOffsetX [protected]
int Map::mOffsetY [protected]

Amount to offset a tile's raster coordinates during each iteration of the tile drawing loop. This is used instead of multiplcations to keep things fast.

int Map::mPointerX [protected]
int Map::mPointerY [protected]

Mouse pointer coordinates.

A pointer to a PropFactory.

Props Map::mProps [protected]

List of Doodad objects.

int Map::mTileHeight [protected]

Tile Height in Pixels.

TsetList Map::mTileSets [protected]

List of TileSet objects.

int Map::mTileTallestHeight [protected]

Tallest tile within the TileSets.

int Map::mTileWidth [protected]

Tile Width in Pixels.

std::string Map::mVersion [protected]

Map version string.

List of mapLink objects.

int Map::mWorldSpaceH [protected]

Width/Height of the world area.

int Map::mWorldSpaceW [protected]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines