GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/being/actor.cpp Lines: 14 27 51.9 %
Date: 2017-11-29 Branches: 5 16 31.3 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2010  The Mana Developers
4
 *  Copyright (C) 2011-2017  The ManaPlus Developers
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 "being/actor.h"
23
24
#include "resources/map/map.h"
25
26
#include "debug.h"
27
28
204
Actor::Actor() :
29
    mPixelX(0),
30
    mPixelY(0),
31
    mMap(nullptr),
32
    mPos(),
33
    mYDiff(0),
34
612
    mMapActor()
35
{
36
204
}
37
38
408
Actor::~Actor()
39
{
40

204
    if (mMap != nullptr)
41
    {
42
4
        mMap->removeActor(mMapActor);
43
        mMap = nullptr;
44
    }
45
204
}
46
47
204
void Actor::setMap(Map *const map)
48
{
49
    // Remove Actor from potential previous map
50
204
    if (mMap != nullptr)
51
        mMap->removeActor(mMapActor);
52
53
204
    mMap = map;
54
55
    // Add Actor to potential new map
56
204
    if (mMap != nullptr)
57
4
        mMapActor = mMap->addActor(this);
58
204
}
59
60
int Actor::getTileX() const
61
{
62
    if (mMap == nullptr ||
63
        mMap->getTileWidth() == 0)
64
    {
65
        return 0;
66
    }
67
68
    return getPixelX() / mMap->getTileWidth();
69
}
70
71
int Actor::getTileY() const
72
{
73
    if (mMap == nullptr ||
74
        mMap->getTileHeight() == 0)
75
    {
76
        return 0;
77
    }
78
79
    return getPixelY() / mMap->getTileHeight();
80
}
81
82
void Actor::setPixelPositionF(const Vector &restrict pos) restrict2
83
{
84
    mPos = pos;
85
    mPixelX = CAST_S32(mPos.x);
86
    mPixelY = CAST_S32(mPos.y);
87
4
}