GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/delayedmanager.cpp Lines: 2 23 8.7 %
Date: 2021-03-17 Branches: 0 16 0.0 %

Line Branch Exec Source
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/delayedmanager.h"
23
24
#include "resources/sprite/animationdelayload.h"
25
26
#include "utils/foreach.h"
27
#include "utils/timer.h"
28
29
#include "debug.h"
30
31
1
DelayedAnim DelayedManager::mDelayedAnimations;
32
33
void DelayedManager::delayedLoad()
34
{
35
    BLOCK_START("DelayedManager::delayedLoad")
36
    static int loadTime = 0;
37
    if (loadTime < cur_time)
38
    {
39
        loadTime = tick_time;
40
41
        int k = 0;
42
        DelayedAnimIter it = mDelayedAnimations.begin();
43
        const DelayedAnimIter it_end = mDelayedAnimations.end();
44
        while (it != it_end && k < 1)
45
        {
46
            (*it)->load();
47
            AnimationDelayLoad *tmp = *it;
48
            it = mDelayedAnimations.erase(it);
49
            delete tmp;
50
            k ++;
51
        }
52
        const int time2 = tick_time;
53
        if (time2 > loadTime)
54
            loadTime = time2 + (time2 - loadTime) * 2 + 10;
55
        else
56
            loadTime = time2 + 3;
57
    }
58
    BLOCK_END("DelayedManager::delayedLoad")
59
}
60
61
void DelayedManager::removeDelayLoad(const AnimationDelayLoad
62
                                     *const delayedLoad)
63
{
64
    FOR_EACH (DelayedAnimIter, it, mDelayedAnimations)
65
    {
66
        if (*it == delayedLoad)
67
        {
68
            mDelayedAnimations.erase(it);
69
            return;
70
        }
71
    }
72
2
}