/
Target.h
102 lines (83 loc) · 2.01 KB
/
Target.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
95
96
97
98
99
100
101
102
#pragma once
#include "inode.h"
#include "ientity.h"
#include "ilightnode.h"
#include "math/Vector3.h"
#include "math/AABB.h"
#include <sigc++/signal.h>
namespace entity {
/**
* greebo: This is an abstract representation of a target.
* In Doom3 maps, a Target can be any map entity, that's
* why this object encapsulates a reference to an actual
* scene::INode.
*
* Note: Such a Target object can be empty. That's the case for
* entities referring to non-existing entities in their
* "target" spawnarg.
*
* All Targets are owned by the TargetManager class.
*
* A Target can be referenced by one ore more TargetKey objects.
*/
class Target :
public ITargetableObject
{
// The actual node this Target refers to (can be NULL)
const scene::INode* _node;
sigc::signal<void> _sigPositionChanged;
public:
Target() :
_node(nullptr)
{}
Target(const scene::INode& node) :
_node(&node)
{}
const scene::INode* getNode() const override
{
return _node;
}
void setNode(const scene::INode& node)
{
_node = &node;
}
bool isEmpty() const override
{
return _node == nullptr;
}
bool isVisible() const
{
return _node != nullptr && _node->visible();
}
void clear()
{
_node = nullptr;
}
// greebo: Returns the position of this target or <0,0,0> if empty
Vector3 getPosition() const
{
const scene::INode* node = getNode();
if (node == nullptr)
{
return Vector3(0,0,0);
}
// Check if we're targeting a light, and use its center in that case (#5151)
auto lightNode = dynamic_cast<const ILightNode*>(node);
if (lightNode != nullptr)
{
return lightNode->getSelectAABB().getOrigin();
}
return node->worldAABB().getOrigin();
}
// Invoked by the TargetManager when an entity's position changed
void onPositionChanged()
{
signal_PositionChanged().emit();
}
sigc::signal<void>& signal_PositionChanged()
{
return _sigPositionChanged;
}
};
typedef std::shared_ptr<Target> TargetPtr;
} // namespace entity