-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.hpp
More file actions
83 lines (63 loc) · 1.83 KB
/
Copy pathNode.hpp
File metadata and controls
83 lines (63 loc) · 1.83 KB
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
#ifndef GAME3D_NODE_HPP
#define GAME3D_NODE_HPP
#include <map>
#include <sstream>
#include <string>
#include <boost/shared_ptr.hpp>
#include <Ogre.h>
#include "Object.hpp"
namespace Game3D {
struct Node;
typedef boost::shared_ptr<Node> NodePtr;
class Node {
private:
ObjectPtr object_;
Ogre::SceneNode* sceneNode_;
std::map<std::string, NodePtr> children_;
public:
inline Node() { }
inline Node(ObjectPtr object, Ogre::SceneNode& sceneNode)
: object_(object), sceneNode_(&sceneNode) { }
inline NodePtr createChild(const std::string& name) {
NodePtr newNode(new Node(ObjectPtr(), *(sceneNode_->createChildSceneNode())));
attachChild(name, newNode);
return newNode;
}
inline void attachChild(const std::string& name, const NodePtr& node) {
typedef std::map<std::string, NodePtr>::iterator ItType;
std::size_t i = 0;
std::string childName(name);
while(true) {
std::pair<ItType, bool> result = children_.insert(std::make_pair(childName, node));
if(result.second) {
return;
}
std::ostringstream stream;
stream << name << (i++);
childName = stream.str();
}
}
inline NodePtr getChild(const std::string& name) {
typedef std::map<std::string, NodePtr>::iterator ItType;
ItType it = children_.find(name);
assert(it != children_.end());
return it->second;
}
inline Ogre::SceneNode& getSceneNode() {
return *sceneNode_;
}
inline void setObject(ObjectPtr object) {
object_ = object;
}
inline void onEvent(Event& event) {
if(object_) {
object_->onEvent(*this, event);
}
typedef std::map<std::string, NodePtr>::iterator ItType;
for(ItType it = children_.begin(); it != children_.end(); ++it) {
it->second->onEvent(event);
}
}
};
}
#endif