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 30 of file objectslayer.h.

Constructor & Destructor Documentation

◆ ObjectsLayer()

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

Definition at line 29 of file objectslayer.cpp.

References mTiles.

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

◆ ~ObjectsLayer()

ObjectsLayer::~ObjectsLayer ( )

Definition at line 39 of file objectslayer.cpp.

References mHeight, mTiles, mWidth, and ServerCommandType::size.

40 {
41  const unsigned size = mWidth * mHeight;
42  for (unsigned f = 0; f < size; f ++)
43  delete mTiles[f];
44 
45  delete [] mTiles;
46  mTiles = nullptr;
47 }
unsigned mWidth
Definition: objectslayer.h:53
unsigned mHeight
Definition: objectslayer.h:54
MapObjectList ** mTiles
Definition: objectslayer.h:52

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 49 of file objectslayer.cpp.

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

Referenced by Map::addRange().

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

◆ calcMemoryLocal()

int ObjectsLayer::calcMemoryLocal ( ) const
virtual

Reimplemented from MemoryCounter.

Definition at line 82 of file objectslayer.cpp.

References CAST_S32, mHeight, and mWidth.

83 {
84  return CAST_S32(sizeof(ObjectsLayer) +
85  (sizeof(MapObjectList) + sizeof(MapObjectList*)) * mWidth * mHeight);
86 }
unsigned mWidth
Definition: objectslayer.h:53
unsigned mHeight
Definition: objectslayer.h:54
#define CAST_S32
Definition: cast.h:29

◆ getAt()

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

Definition at line 75 of file objectslayer.cpp.

References mHeight, mTiles, and mWidth.

Referenced by Map::getObjectData().

76 {
77  if (x >= mWidth || y >= mHeight)
78  return nullptr;
79  return mTiles[x + y * mWidth];
80 }
unsigned mWidth
Definition: objectslayer.h:53
unsigned mHeight
Definition: objectslayer.h:54
MapObjectList ** mTiles
Definition: objectslayer.h:52

◆ getCounterName()

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

Reimplemented from MemoryCounter.

Definition at line 48 of file objectslayer.h.

49  { return "objects layer"; }

Field Documentation

◆ mHeight

unsigned ObjectsLayer::mHeight
private

Definition at line 54 of file objectslayer.h.

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

◆ mTiles

MapObjectList** ObjectsLayer::mTiles
private

Definition at line 52 of file objectslayer.h.

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

◆ mWidth

unsigned ObjectsLayer::mWidth
private

Definition at line 53 of file objectslayer.h.

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


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