ManaPlus
Public Member Functions | Private Attributes | Friends
MapHeights Class Reference

#include <mapheights.h>

Inheritance diagram for MapHeights:
MemoryCounter

Public Member Functions

 MapHeights (const int width, const int height)
 
 ~MapHeights ()
 
void setHeight (const int x, const int y, const uint8_t height)
 
uint8_t getHeight (const int x, const int y) const
 
int calcMemoryLocal () const
 
std::string getCounterName () const
 
- Public Member Functions inherited from MemoryCounter
 MemoryCounter ()
 
virtual ~MemoryCounter ()
 
int calcMemory (const int level) const
 
virtual int calcMemoryChilds (const int level) const
 

Private Attributes

int mWidth
 
int mHeight
 
uint8_t * mTiles
 

Friends

class Map
 

Detailed Description

Definition at line 30 of file mapheights.h.

Constructor & Destructor Documentation

◆ MapHeights()

MapHeights::MapHeights ( const int  width,
const int  height 
)

Definition at line 25 of file mapheights.cpp.

References mHeight, mTiles, and mWidth.

Referenced by calcMemoryLocal().

26  :
27  MemoryCounter(),
28  mWidth(width),
29  mHeight(height),
30  mTiles(new uint8_t[mWidth * mHeight])
31 {
32  memset(mTiles, 0, mWidth * mHeight);
33 }
int mWidth
Definition: mapheights.h:55
int mHeight
Definition: mapheights.h:56
uint8_t * mTiles
Definition: mapheights.h:57

◆ ~MapHeights()

MapHeights::~MapHeights ( )

Definition at line 35 of file mapheights.cpp.

References mTiles.

36 {
37  delete [] mTiles;
38 }
uint8_t * mTiles
Definition: mapheights.h:57

Member Function Documentation

◆ calcMemoryLocal()

int MapHeights::calcMemoryLocal ( ) const
virtual

Reimplemented from MemoryCounter.

Definition at line 45 of file mapheights.cpp.

References MapHeights(), mHeight, and mWidth.

Referenced by getHeight().

46 {
47  return static_cast<int>(sizeof(MapHeights)) +
48  mWidth * mHeight;
49 }
int mWidth
Definition: mapheights.h:55
int mHeight
Definition: mapheights.h:56
MapHeights(const int width, const int height)
Definition: mapheights.cpp:25

◆ getCounterName()

std::string MapHeights::getCounterName ( ) const
inlinevirtual

Reimplemented from MemoryCounter.

Definition at line 51 of file mapheights.h.

52  { return "heights layer"; }

◆ getHeight()

uint8_t MapHeights::getHeight ( const int  x,
const int  y 
) const
inline

Definition at line 43 of file mapheights.h.

References calcMemoryLocal(), CAST_U8, mHeight, mTiles, and mWidth.

Referenced by Map::getHeightOffset().

44  {
45  return x < mWidth &&
46  y < mHeight ? mTiles[x + y * mWidth] : CAST_U8(0U);
47  }
#define CAST_U8
Definition: cast.h:26
int mWidth
Definition: mapheights.h:55
int mHeight
Definition: mapheights.h:56
uint8_t * mTiles
Definition: mapheights.h:57

◆ setHeight()

void MapHeights::setHeight ( const int  x,
const int  y,
const uint8_t  height 
)

Definition at line 40 of file mapheights.cpp.

References mTiles, and mWidth.

Referenced by setTile().

41 {
42  mTiles[x + y * mWidth] = height;
43 }
int mWidth
Definition: mapheights.h:55
uint8_t * mTiles
Definition: mapheights.h:57

Friends And Related Function Documentation

◆ Map

friend class Map
friend

Definition at line 33 of file mapheights.h.

Field Documentation

◆ mHeight

int MapHeights::mHeight
private

Definition at line 56 of file mapheights.h.

Referenced by calcMemoryLocal(), getHeight(), and MapHeights().

◆ mTiles

uint8_t* MapHeights::mTiles
private

Definition at line 57 of file mapheights.h.

Referenced by getHeight(), MapHeights(), setHeight(), and ~MapHeights().

◆ mWidth

int MapHeights::mWidth
private

Definition at line 55 of file mapheights.h.

Referenced by calcMemoryLocal(), getHeight(), MapHeights(), and setHeight().


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