Changeset 7963
- Timestamp:
- Feb 26, 2011, 6:44:25 AM (14 years ago)
- Location:
- code/branches/usability/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/usability/src/libraries/core/Loader.cc
r7648 r7963 147 147 Returns true if successful. 148 148 */ 149 bool Loader::load(const XMLFile* file, const ClassTreeMask& mask, bool verbose )149 bool Loader::load(const XMLFile* file, const ClassTreeMask& mask, bool verbose, bool bRemoveLuaTags) 150 150 { 151 151 if (!file) … … 155 155 156 156 std::string xmlInput; 157 if (file->getLuaSupport() )157 if (file->getLuaSupport() && !bRemoveLuaTags) 158 158 { 159 159 // Use the LuaState to replace the XML tags (calls our function) … … 172 172 } 173 173 xmlInput = Resource::open(file->getFilename())->getAsString(); 174 175 if (bRemoveLuaTags) 176 { 177 // Remove all Lua code. 178 // Note: we only need this to speed up parsing of level files at the 179 // start of the program. 180 // Assumption: the LevelInfo tag does not use Lua scripting 181 xmlInput = removeLuaTags(xmlInput); 182 } 174 183 } 175 184 … … 271 280 } 272 281 273 std::string Loader::replaceLuaTags(const std::string& text) 274 { 275 // create map with all Lua tags 276 std::map<size_t, bool> luaTags; 282 bool Loader::getLuaTags(const std::string& text, std::map<size_t, bool>& luaTags) 283 { 284 // fill map with all Lua tags 277 285 { 278 286 size_t pos = 0; … … 328 336 { 329 337 COUT(2) << "Warning: Error in level file" << std::endl; 330 // todo: errorhandling 331 return ""; 332 } 333 } 338 // TODO: error handling 339 return false; 340 } 341 } 342 343 return true; 344 } 345 346 std::string Loader::replaceLuaTags(const std::string& text) 347 { 348 // create a map with all lua tags 349 std::map<size_t, bool> luaTags; 350 if (!getLuaTags(text, luaTags)) 351 return ""; 334 352 335 353 // Use a stringstream object to speed up the parsing … … 421 439 return output.str(); 422 440 } 441 442 std::string Loader::removeLuaTags(const std::string& text) 443 { 444 // create a map with all lua tags 445 std::map<size_t, bool> luaTags; 446 if (!getLuaTags(text, luaTags)) 447 return ""; 448 449 // Use a stringstream object to speed up the concatenation 450 std::ostringstream output; 451 452 // cut the original string into pieces and only write the non Lua parts 453 std::map<size_t, bool>::iterator it = luaTags.begin(); 454 bool bLuaCode = false; 455 size_t start = 0; 456 size_t end = 0; 457 458 do 459 { 460 if (it != luaTags.end()) 461 end = (it++)->first; 462 else 463 end = std::string::npos; 464 465 if (!bLuaCode) 466 { 467 output << text.substr(start, end - start); 468 start = end + 5; 469 } 470 else 471 start = end + 2; 472 473 bLuaCode = !bLuaCode; 474 } 475 while (end != std::string::npos); 476 477 return output.str(); 478 } 423 479 } -
code/branches/usability/src/libraries/core/Loader.h
r7648 r7963 42 42 #include "CorePrereqs.h" 43 43 44 #include <map> 44 45 #include <vector> 45 46 #include "ClassTreeMask.h" … … 61 62 static bool reload(const ClassTreeMask& mask = ClassTreeMask(), bool verbose = true); 62 63 63 static bool load(const XMLFile* file, const ClassTreeMask& mask = ClassTreeMask(), bool verbose = true); 64 static bool load(const XMLFile* file, const ClassTreeMask& mask = ClassTreeMask(), 65 bool verbose = true, bool bRemoveLuaTags = false); 64 66 static void unload(const XMLFile* file, const ClassTreeMask& mask = ClassTreeMask()); 65 67 static bool reload(const XMLFile* file, const ClassTreeMask& mask = ClassTreeMask(), bool verbose = true); 66 68 67 69 static std::string replaceLuaTags(const std::string& text); 70 static std::string removeLuaTags(const std::string& text); 68 71 69 72 static ClassTreeMask currentMask_s; 70 73 71 74 private: 75 static bool getLuaTags(const std::string& text, std::map<size_t, bool>& luaTags); 76 72 77 static std::vector<std::pair<const XMLFile*, ClassTreeMask> > files_s; 73 78 }; -
code/branches/usability/src/orxonox/LevelManager.cc
r7839 r7963 253 253 mask.exclude(ClassIdentifier<BaseObject>::getIdentifier()); 254 254 mask.include(ClassIdentifier<LevelInfo>::getIdentifier()); 255 Loader::load(&file, mask, false );255 Loader::load(&file, mask, false, true); 256 256 // Iterate over all LevelInfos. 257 257 for(ObjectList<LevelInfo>::iterator item = ObjectList<LevelInfo>::begin(); item != ObjectList<LevelInfo>::end(); ++item)
Note: See TracChangeset
for help on using the changeset viewer.