GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/delayedmanager.cpp Lines: 2 22 9.1 %
Date: 2017-11-29 Branches: 0 14 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2017  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "resources/delayedmanager.h"
22
23
#include "resources/sprite/animationdelayload.h"
24
25
#include "utils/foreach.h"
26
#include "utils/timer.h"
27
28
#include "debug.h"
29
30
2
DelayedAnim DelayedManager::mDelayedAnimations;
31
32
void DelayedManager::delayedLoad()
33
{
34
    BLOCK_START("DelayedManager::delayedLoad")
35
    static int loadTime = 0;
36
    if (loadTime < cur_time)
37
    {
38
        loadTime = tick_time;
39
40
        int k = 0;
41
        DelayedAnimIter it = mDelayedAnimations.begin();
42
        const DelayedAnimIter it_end = mDelayedAnimations.end();
43
        while (it != it_end && k < 1)
44
        {
45
            (*it)->load();
46
            AnimationDelayLoad *tmp = *it;
47
            it = mDelayedAnimations.erase(it);
48
            delete tmp;
49
            k ++;
50
        }
51
        const int time2 = tick_time;
52
        if (time2 > loadTime)
53
            loadTime = time2 + (time2 - loadTime) * 2 + 10;
54
        else
55
            loadTime = time2 + 3;
56
    }
57
    BLOCK_END("DelayedManager::delayedLoad")
58
}
59
60
void DelayedManager::removeDelayLoad(const AnimationDelayLoad
61
                                     *const delayedLoad)
62
{
63
    FOR_EACH (DelayedAnimIter, it, mDelayedAnimations)
64
    {
65
        if (*it == delayedLoad)
66
        {
67
            mDelayedAnimations.erase(it);
68
            return;
69
        }
70
    }
71
4
}