Changeset 2010 for code/branches/objecthierarchy/src/core/Loader.cc
- Timestamp:
- Oct 25, 2008, 5:13:35 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/core/Loader.cc
r1959 r2010 28 28 29 29 #include "Loader.h" 30 #include " Level.h"30 #include "XMLFile.h" 31 31 #include "BaseObject.h" 32 32 #include "Identifier.h" … … 42 42 namespace orxonox 43 43 { 44 std::vector<std::pair<const Level*, ClassTreeMask> > Loader::levels_s;44 std::vector<std::pair<const XMLFile*, ClassTreeMask> > Loader::files_s; 45 45 ClassTreeMask Loader::currentMask_s; 46 46 47 bool Loader::open(const Level* level, const ClassTreeMask& mask)47 bool Loader::open(const XMLFile* file, const ClassTreeMask& mask) 48 48 { 49 Loader::add( level, mask);50 return Loader::load( level, mask);49 Loader::add(file, mask); 50 return Loader::load(file, mask); 51 51 } 52 52 … … 54 54 { 55 55 Loader::unload(); 56 Loader:: levels_s.clear();56 Loader::files_s.clear(); 57 57 } 58 58 59 void Loader::close(const Level* level)59 void Loader::close(const XMLFile* file) 60 60 { 61 Loader::unload( level);62 Loader::remove( level);61 Loader::unload(file); 62 Loader::remove(file); 63 63 } 64 64 65 void Loader::add(const Level* level, const ClassTreeMask& mask)65 void Loader::add(const XMLFile* file, const ClassTreeMask& mask) 66 66 { 67 if (! level)67 if (!file) 68 68 return; 69 Loader:: levels_s.insert(Loader::levels_s.end(), std::pair<const Level*, ClassTreeMask>(level, mask));69 Loader::files_s.insert(Loader::files_s.end(), std::pair<const XMLFile*, ClassTreeMask>(file, mask)); 70 70 } 71 71 72 void Loader::remove(const Level* level)72 void Loader::remove(const XMLFile* file) 73 73 { 74 if (! level)74 if (!file) 75 75 return; 76 for (std::vector<std::pair<const Level*, ClassTreeMask> >::iterator it = Loader::levels_s.begin(); it != Loader::levels_s.end(); ++it)76 for (std::vector<std::pair<const XMLFile*, ClassTreeMask> >::iterator it = Loader::files_s.begin(); it != Loader::files_s.end(); ++it) 77 77 { 78 if ((*it).first == level)78 if ((*it).first == file) 79 79 { 80 Loader:: levels_s.erase(it);80 Loader::files_s.erase(it); 81 81 break; 82 82 } … … 87 87 { 88 88 bool success = true; 89 for (std::vector<std::pair<const Level*, ClassTreeMask> >::iterator it = Loader::levels_s.begin(); it != Loader::levels_s.end(); ++it)89 for (std::vector<std::pair<const XMLFile*, ClassTreeMask> >::iterator it = Loader::files_s.begin(); it != Loader::files_s.end(); ++it) 90 90 if (!Loader::load((*it).first, (*it).second * mask)) 91 91 success = false; … … 111 111 } 112 112 113 bool Loader::load(const Level* level, const ClassTreeMask& mask)113 bool Loader::load(const XMLFile* file, const ClassTreeMask& mask) 114 114 { 115 if (! level)115 if (!file) 116 116 return false; 117 117 118 Loader::currentMask_s = level->getMask() * mask;118 Loader::currentMask_s = file->getMask() * mask; 119 119 120 120 // let Lua work this out: 121 121 LuaBind* lua = LuaBind::getInstance(); 122 122 lua->clearLuaOutput(); 123 lua->loadFile( level->getFile(), true);123 lua->loadFile(file->getFilename(), true); 124 124 lua->run(); 125 125 126 126 try 127 127 { 128 COUT(0) << "Start loading " << level->getFile() << "..." << std::endl;128 COUT(0) << "Start loading " << file->getFilename() << "..." << std::endl; 129 129 COUT(3) << "Mask: " << Loader::currentMask_s << std::endl; 130 130 131 //ticpp::Document xmlfile( level->getFile());131 //ticpp::Document xmlfile(file->getFilename()); 132 132 //xmlfile.LoadFile(); 133 133 //ticpp::Element myelement(*Script::getFileString()); … … 146 146 Namespace* rootNamespace = new Namespace(); 147 147 rootNamespace->setLoaderIndentation(" "); 148 rootNamespace->set Level(level);148 rootNamespace->setFile(file); 149 149 rootNamespace->setNamespace(rootNamespace); 150 150 rootNamespace->setRoot(true); 151 151 rootNamespace->XMLPort(rootElement, XMLPort::LoadObject); 152 152 153 COUT(0) << "Finished loading " << level->getFile() << "." << std::endl;153 COUT(0) << "Finished loading " << file->getFilename() << "." << std::endl; 154 154 155 155 COUT(4) << "Namespace-tree:" << std::endl << rootNamespace->toString(" ") << std::endl; … … 160 160 { 161 161 COUT(1) << std::endl; 162 COUT(1) << "An error occurred in Loader.cc while loading " << level->getFile() << ":" << std::endl;162 COUT(1) << "An error occurred in Loader.cc while loading " << file->getFilename() << ":" << std::endl; 163 163 COUT(1) << ex.what() << std::endl; 164 164 COUT(1) << "Loading aborted." << std::endl; … … 167 167 } 168 168 169 void Loader::unload(const Level* level, const ClassTreeMask& mask)169 void Loader::unload(const XMLFile* file, const ClassTreeMask& mask) 170 170 { 171 if (! level)171 if (!file) 172 172 return; 173 173 for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it; ) 174 174 { 175 if ((it->get Level() == level) && mask.isIncluded(it->getIdentifier()))175 if ((it->getFile() == file) && mask.isIncluded(it->getIdentifier())) 176 176 delete (*(it++)); 177 177 else … … 180 180 } 181 181 182 bool Loader::reload(const Level* level, const ClassTreeMask& mask)182 bool Loader::reload(const XMLFile* file, const ClassTreeMask& mask) 183 183 { 184 Loader::unload( level, mask);185 return Loader::load( level, mask);184 Loader::unload(file, mask); 185 return Loader::load(file, mask); 186 186 } 187 187 }
Note: See TracChangeset
for help on using the changeset viewer.