ManaPlus
Public Member Functions | Private Attributes
ObjectsLayer Class Reference

#include <objectslayer.h>

Inheritance diagram for ObjectsLayer:
MemoryCounter

Public Member Functions

 ObjectsLayer (const unsigned width, const unsigned height)
 
 ~ObjectsLayer ()
 
void addObject (const std::string &name, const int type, const unsigned x, const unsigned y, unsigned dx, unsigned dy)
 
MapObjectListgetAt (const unsigned x, const unsigned 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

MapObjectList ** mTiles
 
unsigned mWidth
 
unsigned mHeight
 

Detailed Description

Definition at line 31 of file objectslayer.h.

Constructor & Destructor Documentation

◆ ObjectsLayer()

ObjectsLayer::ObjectsLayer ( const unsigned  width,
const unsigned  height 
)

Definition at line 30 of file objectslayer.cpp.

31  :
32  MemoryCounter(),
33  mTiles(new MapObjectList*[width * height]),
34  mWidth(width),
35  mHeight(height)
36 {
37  std::fill_n(mTiles, width * height, static_cast<MapObjectList*>(nullptr));
38 }
unsigned mWidth
Definition: objectslayer.h:54
MapObjectList ** mTiles
Definition: objectslayer.h:53
unsigned mHeight
Definition: objectslayer.h:55

References mTiles.

◆ ~ObjectsLayer()

ObjectsLayer::~ObjectsLayer ( )

Definition at line 40 of file objectslayer.cpp.

41 {
42  const unsigned size = mWidth * mHeight;
43  for (unsigned f = 0; f < size; f ++)
44  delete mTiles[f];
45 
46  delete [] mTiles;
47  mTiles = nullptr;
48 }
int size()
Definition: emotedb.cpp:306

References mHeight, mTiles, mWidth, and EmoteDB::size().

Member Function Documentation

◆ addObject()

void ObjectsLayer::addObject ( const std::string &  name,
const int  type,
const unsigned  x,
const unsigned  y,
unsigned  dx,
unsigned  dy 
)

Definition at line 50 of file objectslayer.cpp.

53 {
54  if (mTiles == nullptr)
55  return;
56 
57  if (x + dx > mWidth)
58  dx = mWidth - x;
59  if (y + dy > mHeight)
60  dy = mHeight - y;
61 
62  for (unsigned y1 = y; y1 < y + dy; y1 ++)
63  {
64  const unsigned idx1 = x + y1 * mWidth;
65  const unsigned idx2 = idx1 + dx;
66 
67  for (unsigned i = idx1; i < idx2; i ++)
68  {
69  if (mTiles[i] == nullptr)
70  mTiles[i] = new MapObjectList;
71  mTiles[i]->objects.push_back(MapObject(type, name));
72  }
73  }
74 }
std::vector< MapObject > objects
Definition: mapobjectlist.h:43

References mHeight, mTiles, mWidth, MapObjectList::objects, x, and y.

◆ calcMemoryLocal()

int ObjectsLayer::calcMemoryLocal ( ) const
virtual

Reimplemented from MemoryCounter.

Definition at line 83 of file objectslayer.cpp.

84 {
85  return CAST_S32(sizeof(ObjectsLayer) +
86  (sizeof(MapObjectList) + sizeof(MapObjectList*)) * mWidth * mHeight);
87 }
#define CAST_S32
Definition: cast.h:30

References CAST_S32, mHeight, and mWidth.

◆ getAt()

MapObjectList * ObjectsLayer::getAt ( const unsigned  x,
const unsigned  y 
) const

Definition at line 76 of file objectslayer.cpp.

77 {
78  if (x >= mWidth || y >= mHeight)
79  return nullptr;
80  return mTiles[x + y * mWidth];
81 }

References mHeight, mTiles, mWidth, x, and y.

◆ getCounterName()

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

Reimplemented from MemoryCounter.

Definition at line 49 of file objectslayer.h.

50  { return "objects layer"; }

Field Documentation

◆ mHeight

unsigned ObjectsLayer::mHeight
private

Definition at line 55 of file objectslayer.h.

Referenced by addObject(), calcMemoryLocal(), getAt(), and ~ObjectsLayer().

◆ mTiles

MapObjectList** ObjectsLayer::mTiles
private

Definition at line 53 of file objectslayer.h.

Referenced by addObject(), getAt(), ObjectsLayer(), and ~ObjectsLayer().

◆ mWidth

unsigned ObjectsLayer::mWidth
private

Definition at line 54 of file objectslayer.h.

Referenced by addObject(), calcMemoryLocal(), getAt(), and ~ObjectsLayer().


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