File: ModelKey.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 (79 lines) | stat: -rw-r--r-- 2,187 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
#pragma once

#include <string>
#include "inode.h"
#include "ieclass.h"
#include "ObservedUndoable.h"
#include <sigc++/connection.h>

/**
 * @brief A ModelKey watches the "model" spawnarg of an entity.
 *
 * As soon as the keyvalue changes, the according modelnode is loaded and
 * inserted into the entity's Traversable.
 */
class ModelKey :
    public sigc::trackable
{
private:
	// The parent node, where the model node can be added to (as child)
	scene::INode& _parentNode;

	struct ModelNodeAndPath
	{
		scene::INodePtr node;
		std::string path;
        std::string explicitSkin;
        bool modelDefMonitored;
	};

	ModelNodeAndPath _model;

	// To deactivate model handling during node destruction
	bool _active;

	// Saves modelnode and modelpath to undo stack
	undo::ObservedUndoable<ModelNodeAndPath> _undo;

    sigc::connection _modelDefChanged;

public:
	ModelKey(scene::INode& parentNode);

    // Remove any model node from the parent entity
    // used during Entity destruction to remove any child nodes
    // before the parent entity node is going out of business.
    // Disables any further behaviour of this instance, it will no longer be functional
    void destroy();

	// Refreshes the attached model
	void refreshModel();

	// Update the model to the provided keyvalue, this removes the old scene::Node
	// and inserts the new one after acquiring the model from the cache.
	void modelChanged(const std::string& value);

	// Gets called by the attached Entity when the "skin" spawnarg changes
	void skinChanged(const std::string& value);

	// Returns the reference to the "singleton" model node
	const scene::INodePtr& getNode() const;

	void connectUndoSystem(IUndoSystem& undoSystem);
	void disconnectUndoSystem(IUndoSystem& undoSystem);

private:
    void onModelDefChanged();

	// Loads the model node and attaches it to the parent node
    void attachModelNode();
    void detachModelNode();

    // Attaches a model node, making sure that the skin setting is kept
    void attachModelNodeKeepingSkin();

	void importState(const ModelNodeAndPath& data);

    void subscribeToModelDef(const IModelDef::Ptr& modelDef);
    void unsubscribeFromModelDef();
};