ManaPlus
src
resources
map
objectslayer.cpp
Go to the documentation of this file.
1
/*
2
* The ManaPlus Client
3
* Copyright (C) 2011-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
#include "
resources/map/objectslayer.h
"
23
24
#include "
utils/cast.h
"
25
26
#include "
resources/map/mapobjectlist.h
"
27
28
#include "
debug.h
"
29
30
ObjectsLayer::ObjectsLayer
(
const
unsigned
width,
31
const
unsigned
height) :
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
}
39
40
ObjectsLayer::~ObjectsLayer
()
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
}
49
50
void
ObjectsLayer::addObject
(
const
std::string &name,
const
int
type,
51
const
unsigned
x
,
const
unsigned
y
,
52
unsigned
dx,
unsigned
dy)
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
}
75
76
MapObjectList
*
ObjectsLayer::getAt
(
const
unsigned
x
,
const
unsigned
y
)
const
77
{
78
if
(
x
>=
mWidth
||
y
>=
mHeight
)
79
return
nullptr
;
80
return
mTiles
[
x
+
y
*
mWidth
];
81
}
82
83
int
ObjectsLayer::calcMemoryLocal
()
const
84
{
85
return
CAST_S32
(
sizeof
(
ObjectsLayer
) +
86
(
sizeof
(
MapObjectList
) +
sizeof
(
MapObjectList
*)) *
mWidth
*
mHeight
);
87
}
cast.h
CAST_S32
#define CAST_S32
Definition:
cast.h:30
MapObjectList
Definition:
mapobjectlist.h:34
MapObjectList::objects
std::vector< MapObject > objects
Definition:
mapobjectlist.h:43
MapObject
Definition:
mapobject.h:32
MemoryCounter
Definition:
memorycounter.h:30
ObjectsLayer
Definition:
objectslayer.h:32
ObjectsLayer::calcMemoryLocal
int calcMemoryLocal() const
Definition:
objectslayer.cpp:83
ObjectsLayer::ObjectsLayer
ObjectsLayer(const unsigned width, const unsigned height)
Definition:
objectslayer.cpp:30
ObjectsLayer::~ObjectsLayer
~ObjectsLayer()
Definition:
objectslayer.cpp:40
ObjectsLayer::getAt
MapObjectList * getAt(const unsigned x, const unsigned y) const
Definition:
objectslayer.cpp:76
ObjectsLayer::mWidth
unsigned mWidth
Definition:
objectslayer.h:54
ObjectsLayer::addObject
void addObject(const std::string &name, const int type, const unsigned x, const unsigned y, unsigned dx, unsigned dy)
Definition:
objectslayer.cpp:50
ObjectsLayer::mTiles
MapObjectList ** mTiles
Definition:
objectslayer.h:53
ObjectsLayer::mHeight
unsigned mHeight
Definition:
objectslayer.h:55
debug.h
new
#define new
Definition:
debug_new.h:147
y
y
Definition:
graphics_calcImageRect.hpp:73
x
x
Definition:
graphics_calcImageRect.hpp:73
mapobjectlist.h
EmoteDB::size
int size()
Definition:
emotedb.cpp:306
objectslayer.h
Generated on Wed Mar 17 2021 19:19:10 for ManaPlus by
1.9.1