ManaPlus
Public Member Functions | Data Fields
AtlasResource Class Reference

#include <atlasresource.h>

Inheritance diagram for AtlasResource:
Resource MemoryCounter

Public Member Functions

 AtlasResource ()
 
 ~AtlasResource ()
 
void incRef ()
 
void decRef ()
 
int calcMemoryLocal () const
 
int calcMemoryChilds (const int level) const
 
- Public Member Functions inherited from Resource
 Resource ()
 
 ~Resource ()
 
int calcMemoryLocal () const
 
std::string getCounterName () const
 
- Public Member Functions inherited from MemoryCounter
 MemoryCounter ()
 
virtual ~MemoryCounter ()
 
int calcMemory (const int level) const
 

Data Fields

std::vector< TextureAtlas * > atlases
 
- Data Fields inherited from Resource
time_t mTimeStamp
 
std::string mIdPath
 
std::string mSource
 
unsigned int mRefCount
 
bool mProtected
 
bool mNotCount
 

Detailed Description

Definition at line 32 of file atlasresource.h.

Constructor & Destructor Documentation

◆ AtlasResource()

AtlasResource::AtlasResource ( )
inline

Definition at line 35 of file atlasresource.h.

35  :
36  atlases()
37  { }

Referenced by calcMemoryLocal().

◆ ~AtlasResource()

AtlasResource::~AtlasResource ( )

Definition at line 32 of file atlasresource.cpp.

33 {
34  FOR_EACH (STD_VECTOR<TextureAtlas*>::iterator, it, atlases)
35  {
36  TextureAtlas *const atlas = *it;
37  if (atlas != nullptr)
38  {
39  FOR_EACH (STD_VECTOR<AtlasItem*>::iterator, it2, atlas->items)
40  {
41  AtlasItem *const item = *it2;
42  if (item != nullptr)
43  {
44  Image *const image2 = item->image;
45  if (image2 != nullptr)
46  image2->decRef();
47  delete item;
48  }
49  }
50  Image *const image = atlas->atlasImage;
51  if (image != nullptr)
52  image->decRef();
53  delete atlas;
54  }
55  }
57 }

References atlases, TextureAtlas::atlasImage, ResourceManager::clearDeleted(), Image::decRef(), FOR_EACH, AtlasItem::image, and TextureAtlas::items.

Member Function Documentation

◆ calcMemoryChilds()

int AtlasResource::calcMemoryChilds ( const int  level) const
virtual

Reimplemented from MemoryCounter.

Definition at line 80 of file atlasresource.cpp.

81 {
82  int sz = 0;
83  FOR_EACH (STD_VECTOR<TextureAtlas*>::const_iterator, it, atlases)
84  {
85  TextureAtlas *const atlas = *it;
86  sz += atlas->calcMemory(level + 1);
87  }
88  return sz;
89 }

References atlases, MemoryCounter::calcMemory(), and FOR_EACH.

◆ calcMemoryLocal()

int AtlasResource::calcMemoryLocal ( ) const
virtual

Reimplemented from MemoryCounter.

Definition at line 73 of file atlasresource.cpp.

74 {
75  return static_cast<int>(sizeof(AtlasResource)) +
77  static_cast<int>(atlases.capacity() * sizeof(TextureAtlas*));
78 }

References atlases, AtlasResource(), and Resource::calcMemoryLocal().

◆ decRef()

void AtlasResource::decRef ( )
virtual

Decrements the reference count and deletes the object if no references are left.

Returns
true if the object was deleted false otherwise.

Reimplemented from Resource.

Definition at line 66 of file atlasresource.cpp.

67 {
69  if (mRefCount == 0U)
71 }

References Resource::decRef(), AtlasManager::moveToDeleted(), and Resource::mRefCount.

Referenced by Map::~Map().

◆ incRef()

void AtlasResource::incRef ( )
virtual

Increments the internal reference count.

Reimplemented from Resource.

Definition at line 59 of file atlasresource.cpp.

60 {
61  if (mRefCount == 0U)
64 }

References Resource::incRef(), AtlasManager::injectToResources(), and Resource::mRefCount.

Field Documentation

◆ atlases

std::vector<TextureAtlas*> AtlasResource::atlases

The documentation for this class was generated from the following files:
AtlasResource::atlases
std::vector< TextureAtlas * > atlases
Definition: atlasresource.h:51
AtlasManager::injectToResources
static void injectToResources(const AtlasResource *const resource)
Definition: atlasmanager.cpp:496
AtlasItem
Definition: atlasitem.h:28
TextureAtlas::items
std::vector< AtlasItem * > items
Definition: textureatlas.h:77
Image
Definition: image.h:67
Resource::incRef
virtual void incRef()
Definition: resource.cpp:37
AtlasManager::moveToDeleted
static void moveToDeleted(AtlasResource *const resource)
Definition: atlasmanager.cpp:522
ResourceManager::clearDeleted
void clearDeleted(const bool full)
Definition: resourcemanager.cpp:320
MemoryCounter::calcMemory
int calcMemory(const int level) const
Definition: memorycounter.cpp:36
AtlasResource::AtlasResource
AtlasResource()
Definition: atlasresource.h:35
AtlasItem::image
Image * image
Definition: atlasitem.h:53
TextureAtlas
Definition: textureatlas.h:39
Resource::decRef
virtual void decRef()
Definition: resource.cpp:49
Resource::calcMemoryLocal
int calcMemoryLocal() const
Definition: resource.cpp:75
TextureAtlas::atlasImage
Image * atlasImage
Definition: textureatlas.h:74
Resource::mRefCount
unsigned int mRefCount
Definition: resource.h:86
FOR_EACH
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
Image::decRef
void decRef()
Definition: image.cpp:522