File: TargetableNode.h

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (81 lines) | stat: -rw-r--r-- 2,321 bytes parent folder | download | duplicates (3)
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
#pragma once

#include "selectionlib.h"
#include "scene/Node.h"
#include "entitylib.h"

#include "../SpawnArgs.h"

#include "TargetKeyCollection.h"
#include "RenderableTargetLines.h"

namespace entity
{

class EntityNode;

class TargetLineNode;
typedef std::shared_ptr<TargetLineNode> TargetLineNodePtr;

/**
 * greebo: Each targetable entity (D3Group, Speaker, Lights, etc.) derives from
 *         this class.
 *
 * This registers itself with the contained SpawnArgs and observes its keys.
 * As soon as "name" keys are encountered, the TargetManager is notified about
 * the change, so that the name can be associated with a Target object.
 */
class TargetableNode :
	public Entity::Observer,
	public KeyObserver
{
	SpawnArgs& _d3entity;
	TargetKeyCollection _targetKeys;

	// The current name of this entity (used for comparison in "onKeyValueChanged")
	std::string _targetName;

	// The node we're associated with
	EntityNode& _node;

    // The targetmanager of the map we're in (is nullptr if not in the scene)
    ITargetManager* _targetManager;

    // The actual scene representation rendering the lines
    TargetLineNodePtr _targetLineNode;

public:
	TargetableNode(SpawnArgs& entity, EntityNode& node);

    // This might return nullptr if the node is not inserted in a scene
    ITargetManager* getTargetManager();

	// Connect this class with the SpawnArgs
	void construct();
	// Disconnect this class from the entity
	void destruct();

    TargetKeyCollection& getTargetKeys();

	// Gets called as soon as the "name" keyvalue changes
	void onKeyValueChanged(const std::string& name) override;

	// Entity::Observer implementation, gets called on key insert
	void onKeyInsert(const std::string& key, EntityKeyValue& value) override;
	void onKeyErase(const std::string& key, EntityKeyValue& value) override;
    void onKeyChange(const std::string& key, const std::string& value) override;

    // scene insert/remove handling
    void onInsertIntoScene(scene::IMapRootNode& root);
    void onRemoveFromScene(scene::IMapRootNode& root);

    void onVisibilityChanged(bool isVisibleNow);

    // Invoked by the TargetKeyCollection when the number of observed has changed
    void onTargetKeyCollectionChanged();

    void onTransformationChanged();
    void onRenderSystemChanged();
};

} // namespace entity