ManaPlus
atlasresource.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2012-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifdef USE_OPENGL
23 
25 
28 
30 
31 #include "debug.h"
32 
34 {
35  FOR_EACH (STD_VECTOR<TextureAtlas*>::iterator, it, atlases)
36  {
37  TextureAtlas *const atlas = *it;
38  if (atlas != nullptr)
39  {
40  FOR_EACH (STD_VECTOR<AtlasItem*>::iterator, it2, atlas->items)
41  {
42  AtlasItem *const item = *it2;
43  if (item != nullptr)
44  {
45  Image *const image2 = item->image;
46  if (image2 != nullptr)
47  image2->decRef();
48  delete item;
49  }
50  }
51  Image *const image = atlas->atlasImage;
52  if (image != nullptr)
53  image->decRef();
54  delete atlas;
55  }
56  }
58 }
59 
61 {
62  if (mRefCount == 0U)
65 }
66 
68 {
70  if (mRefCount == 0U)
72 }
73 
75 {
76  return static_cast<int>(sizeof(AtlasResource)) +
78  static_cast<int>(atlases.capacity() * sizeof(TextureAtlas*));
79 }
80 
81 int AtlasResource::calcMemoryChilds(const int level) const
82 {
83  int sz = 0;
84  FOR_EACH (STD_VECTOR<TextureAtlas*>::const_iterator, it, atlases)
85  {
86  TextureAtlas *const atlas = *it;
87  sz += atlas->calcMemory(level + 1);
88  }
89  return sz;
90 }
91 
92 #endif // USE_OPENGL
static void injectToResources(const AtlasResource *const resource)
static void moveToDeleted(AtlasResource *const resource)
int calcMemoryChilds(const int level) const
int calcMemoryLocal() const
std::vector< TextureAtlas * > atlases
Definition: atlasresource.h:52
int calcMemory(const int level) const
virtual void incRef()
Definition: resource.cpp:38
virtual void decRef()
Definition: resource.cpp:50
unsigned int mRefCount
Definition: resource.h:87
int calcMemoryLocal() const
Definition: resource.cpp:76
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
void clearDeleted(const bool full)
Image * image
Definition: atlasitem.h:54
Image * atlasImage
Definition: textureatlas.h:75
std::vector< AtlasItem * > items
Definition: textureatlas.h:78