1 | #include <OgreSceneManager.h> |
---|
2 | #include <string> |
---|
3 | |
---|
4 | #include "../orxonox.h" |
---|
5 | #include "../../tinyxml/tinyxml.h" |
---|
6 | #include "../../misc/Tokenizer.h" |
---|
7 | #include "../../misc/String2Number.h" |
---|
8 | |
---|
9 | #include "BaseEntity.h" |
---|
10 | |
---|
11 | namespace orxonox |
---|
12 | { |
---|
13 | CreateFactory(BaseEntity); |
---|
14 | |
---|
15 | BaseEntity::BaseEntity() |
---|
16 | { |
---|
17 | RegisterObject(BaseEntity); |
---|
18 | valid=false; |
---|
19 | } |
---|
20 | |
---|
21 | BaseEntity::~BaseEntity() |
---|
22 | { |
---|
23 | } |
---|
24 | |
---|
25 | void BaseEntity::loadParams(TiXmlElement* xmlElem) |
---|
26 | { |
---|
27 | if (xmlElem->Attribute("name") && xmlElem->Attribute("src")) |
---|
28 | { |
---|
29 | // save params |
---|
30 | name_ = xmlElem->Attribute("name"); |
---|
31 | mesh_ = xmlElem->Attribute("src"); |
---|
32 | node_ = xmlElem->Attribute("node"); |
---|
33 | |
---|
34 | // register variables to be synchronised |
---|
35 | registerAllVariables(); |
---|
36 | valid=true; |
---|
37 | create(); |
---|
38 | |
---|
39 | std::cout << "Loader: Created entity "<< name_ <<" with source " << mesh_ << " at node " << node_ << std::endl << std::endl; |
---|
40 | } |
---|
41 | } |
---|
42 | |
---|
43 | void BaseEntity::registerAllVariables(){ |
---|
44 | WorldEntity::registerAllVariables(); |
---|
45 | registerVar(&name_, name_.length()+1, network::STRING); |
---|
46 | registerVar(&mesh_, mesh_.length()+1, network::STRING); |
---|
47 | registerVar(&node_, node_.length()+1, network::STRING); |
---|
48 | } |
---|
49 | |
---|
50 | bool BaseEntity::create(){ |
---|
51 | if(!valid) |
---|
52 | return false; |
---|
53 | // get the node |
---|
54 | this->setNode(Orxonox::getSingleton()->getSceneManager()->getSceneNode(node_)); |
---|
55 | Ogre::SceneManager* mgr = orxonox::Orxonox::getSingleton()->getSceneManager(); |
---|
56 | |
---|
57 | Ogre::Entity* entity = mgr->createEntity(name_, mesh_); |
---|
58 | |
---|
59 | //Ogre::MovableObject *ent = (Ogre::MovableObject *)entity; |
---|
60 | getNode()->attachObject(entity); // big problem here: sigsegv |
---|
61 | return true; |
---|
62 | } |
---|
63 | } |
---|