File: con_timer.cpp

package info (click to toggle)
openmohaa 0.82.1%2Bdfsg-1
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 34,192 kB
  • sloc: cpp: 315,720; ansic: 275,789; sh: 312; xml: 246; asm: 141; makefile: 7
file content (83 lines) | stat: -rw-r--r-- 1,662 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "con_timer.h"

#if defined(ARCHIVE_SUPPORTED)
#    include "../fgame/archive.h"
#endif

con_timer::con_timer(void)
{
    m_inttime = 0;
    m_bDirty  = false;
}

void con_timer::AddElement(Class *e, int inttime)
{
    Element element;

    element.obj     = e;
    element.inttime = inttime;

    m_Elements.AddObject(element);

    if (inttime <= m_inttime) {
        SetDirty();
    }
}

void con_timer::RemoveElement(Class *e)
{
    for (int i = m_Elements.NumObjects(); i > 0; i--) {
        Element *index = &m_Elements.ObjectAt(i);

        if (index->obj == e) {
            m_Elements.RemoveObjectAt(i);
            return;
        }
    }
}

Class *con_timer::GetNextElement(int& foundtime)
{
    int    best_inttime;
    int    i;
    int    foundIndex;
    Class *result;

    foundIndex   = 0;
    best_inttime = m_inttime;

    for (i = m_Elements.NumObjects(); i > 0; i--) {
        if (m_Elements.ObjectAt(i).inttime <= best_inttime) {
            best_inttime = m_Elements.ObjectAt(i).inttime;
            foundIndex   = i;
        }
    }

    if (foundIndex) {
        result = m_Elements.ObjectAt(foundIndex).obj;
        m_Elements.RemoveObjectAt(foundIndex);
        foundtime = best_inttime;
    } else {
        result   = NULL;
        m_bDirty = false;
    }

    return result;
}

#if defined(ARCHIVE_SUPPORTED)

void con_timer::ArchiveElement(Archiver& arc, Element *e)
{
    arc.ArchiveObjectPointer(&e->obj);
    arc.ArchiveInteger(&e->inttime);
}

void con_timer::Archive(Archiver& arc)
{
    arc.ArchiveBool(&m_bDirty);
    arc.ArchiveInteger(&m_inttime);

    m_Elements.Archive(arc, con_timer::ArchiveElement);
}
#endif