/
thinkerdata.h
94 lines (78 loc) · 2.65 KB
/
thinkerdata.h
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
84
85
86
87
88
89
90
91
92
93
94
/** @file thinkerdata.h Base class for thinker private data.
*
* @authors Copyright (c) 2014 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#ifndef LIBDOOMSDAY_THINKERDATA_H
#define LIBDOOMSDAY_THINKERDATA_H
#include "thinker.h"
#include <de/Process>
#include <de/Id>
#include <de/IObject>
/**
* Base class for thinker private data.
*
* Contains internal functionality common to all thinkers regardless of their type.
*/
class LIBDOOMSDAY_PUBLIC ThinkerData
: public Thinker::IData
, public de::IObject
{
public:
DENG2_DEFINE_AUDIENCE2(Deletion, void thinkerBeingDeleted(thinker_s &))
public:
ThinkerData();
ThinkerData(ThinkerData const &other);
void setThinker(thinker_s *thinker);
void think();
IData *duplicate() const;
thinker_s &thinker();
thinker_s const &thinker() const;
/**
* Initializes Doomsday Script bindings for the thinker. This is called
* when the thinker is added to the world, so mobjs have been assigned
* their IDs.
*/
virtual void initBindings();
// Implements IObject.
de::Record &objectNamespace();
de::Record const &objectNamespace() const;
private:
DENG2_PRIVATE(d)
#ifdef DENG2_DEBUG
public:
struct DebugCounter {
de::Id id;
static de::duint32 total;
DebugCounter() { total++; }
~DebugCounter() { total--; }
};
DebugCounter _debugCounter;
struct DebugValidator {
DebugValidator() { DENG2_ASSERT(DebugCounter::total == 0); }
~DebugValidator() { DENG2_ASSERT(DebugCounter::total == 0); }
};
#endif
};
DENG2_SCRIPT_ARGUMENT_TYPE(ThinkerData *,
if (!arg) return ScriptLex::NONE;
return scriptArgumentAsText(arg->objectNamespace());
)
DENG2_SCRIPT_ARGUMENT_TYPE(ThinkerData const *,
if (!arg) return ScriptLex::NONE;
return scriptArgumentAsText(arg->objectNamespace());
)
#endif // LIBDOOMSDAY_THINKERDATA_H