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 | std::string node = xmlElem->Attribute("node"); |
---|
33 | |
---|
34 | // get the node |
---|
35 | this->setNode(Orxonox::getSingleton()->getSceneManager()->getSceneNode(node)); |
---|
36 | |
---|
37 | |
---|
38 | // register variables to be synchronised |
---|
39 | registerAllVariables(); |
---|
40 | valid=true; |
---|
41 | create(); |
---|
42 | |
---|
43 | std::cout << "Loader: Created entity "<< name_ <<" with source " << mesh_ << " at node " << node << std::endl << std::endl; |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | void BaseEntity::registerAllVariables(){ |
---|
48 | WorldEntity::registerAllVariables(); |
---|
49 | registerVar(&name_, name_.length()+1, network::STRING); |
---|
50 | registerVar(&mesh_, mesh_.length()+1, network::STRING); |
---|
51 | } |
---|
52 | |
---|
53 | bool BaseEntity::create(){ |
---|
54 | if(!valid) |
---|
55 | return false; |
---|
56 | Ogre::SceneManager* mgr = orxonox::Orxonox::getSingleton()->getSceneManager(); |
---|
57 | |
---|
58 | Ogre::Entity* entity = mgr->createEntity(name_, mesh_); |
---|
59 | |
---|
60 | //Ogre::MovableObject *ent = (Ogre::MovableObject *)entity; |
---|
61 | getNode()->attachObject(entity); // big problem here: sigsegv |
---|
62 | return true; |
---|
63 | } |
---|
64 | } |
---|