ManaPlus
src
resources
atlas
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
24
#include "
resources/atlas/atlasresource.h
"
25
26
#include "
resources/atlas/atlasmanager.h
"
27
#include "
resources/atlas/textureatlas.h
"
28
29
#include "
resources/resourcemanager/resourcemanager.h
"
30
31
#include "
debug.h
"
32
33
AtlasResource::~AtlasResource
()
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
}
57
ResourceManager::clearDeleted
(
false
);
58
}
59
60
void
AtlasResource::incRef
()
61
{
62
if
(
mRefCount
== 0U)
63
AtlasManager::injectToResources
(
this
);
64
Resource::incRef
();
65
}
66
67
void
AtlasResource::decRef
()
68
{
69
Resource::decRef
();
70
if
(
mRefCount
== 0U)
71
AtlasManager::moveToDeleted
(
this
);
72
}
73
74
int
AtlasResource::calcMemoryLocal
()
const
75
{
76
return
static_cast<
int
>
(
sizeof
(
AtlasResource
)) +
77
Resource::calcMemoryLocal
() +
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
atlasmanager.h
atlasresource.h
AtlasManager::injectToResources
static void injectToResources(const AtlasResource *const resource)
Definition:
atlasmanager.cpp:497
AtlasManager::moveToDeleted
static void moveToDeleted(AtlasResource *const resource)
Definition:
atlasmanager.cpp:523
AtlasResource::decRef
void decRef()
Definition:
atlasresource.cpp:67
AtlasResource::~AtlasResource
~AtlasResource()
Definition:
atlasresource.cpp:33
AtlasResource::calcMemoryChilds
int calcMemoryChilds(const int level) const
Definition:
atlasresource.cpp:81
AtlasResource::calcMemoryLocal
int calcMemoryLocal() const
Definition:
atlasresource.cpp:74
AtlasResource::AtlasResource
AtlasResource()
Definition:
atlasresource.h:36
AtlasResource::atlases
std::vector< TextureAtlas * > atlases
Definition:
atlasresource.h:52
AtlasResource::incRef
void incRef()
Definition:
atlasresource.cpp:60
Image
MemoryCounter::calcMemory
int calcMemory(const int level) const
Definition:
memorycounter.cpp:37
Resource::incRef
virtual void incRef()
Definition:
resource.cpp:38
Resource::decRef
virtual void decRef()
Definition:
resource.cpp:50
Resource::mRefCount
unsigned int mRefCount
Definition:
resource.h:87
Resource::calcMemoryLocal
int calcMemoryLocal() const
Definition:
resource.cpp:76
debug.h
FOR_EACH
#define FOR_EACH(type, iter, array)
Definition:
foreach.h:25
ResourceManager::clearDeleted
void clearDeleted(const bool full)
Definition:
resourcemanager.cpp:321
resourcemanager.h
AtlasItem
Definition:
atlasitem.h:30
AtlasItem::image
Image * image
Definition:
atlasitem.h:54
TextureAtlas
Definition:
textureatlas.h:41
TextureAtlas::atlasImage
Image * atlasImage
Definition:
textureatlas.h:75
TextureAtlas::items
std::vector< AtlasItem * > items
Definition:
textureatlas.h:78
textureatlas.h
Generated on Wed Mar 17 2021 19:19:09 for ManaPlus by
1.9.1