MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / LoadLevel

Method LoadLevel

Source/XML/level_loader.cpp:362–525  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

360}
361
362bool LevelLoader::LoadLevel(const Path& level_path, SceneGraph& s) {
363 Graphics* gi = Graphics::Instance();
364
365 if (level_path.isValid() == false) {
366 FatalError("Error", "Could not find level file: %s", level_path.GetFullPath());
367 }
368
369 LevelInfo li;
370 {
371 PROFILER_ZONE(g_profiler_ctx, "Parsing level xml");
372 ParseLevelXML(level_path.GetFullPath(), li);
373 g_level_shadows = li.shadows_;
374 const char* localized_load_tip = GetLevelTip(config["language"].str().c_str(), FindShortestPath(level_path.GetFullPath()).c_str());
375 char temp_load_screen_tip[kPathSize] = {'\0'};
376 if (localized_load_tip) {
377 FormatString(temp_load_screen_tip, kPathSize, "%s", localized_load_tip);
378 } else {
379 // Simple fallback to en_us in case there is one available
380 const char* localized_load_tip = GetLevelTip("en_us", FindShortestPath(level_path.GetFullPath()).c_str());
381 if (localized_load_tip) {
382 FormatString(temp_load_screen_tip, kPathSize, "%s", localized_load_tip);
383 } else if (li.spm_.find("Load Tip") != li.spm_.end()) {
384 FormatString(temp_load_screen_tip, kPathSize, li.spm_["Load Tip"].GetString().c_str());
385 }
386 }
387 AnalyzeForLineBreaks(temp_load_screen_tip, kPathSize);
388 FormatString(Engine::Instance()->load_screen_tip, kPathSize, "%s", temp_load_screen_tip);
389 if (!li.script_.empty()) {
390 std::string path = li.script_.substr(0, li.script_.size() - 3) + "_paths.xml";
391 if (!FileExists(path.c_str(), kAnyPath)) {
392 path = script_dir_path + path;
393 }
394 Path level_script_path;
395 level_script_path = FindFilePath(path.c_str(), kAnyPath, false);
396 if (level_script_path.isValid()) {
397 TiXmlDocument doc;
398 if (!doc.LoadFile(level_script_path.GetFullPath())) {
399 FatalError("Error", "Bad xml data in level script path file: %s", path.c_str());
400 }
401 const TiXmlElement* root = doc.RootElement();
402
403 LevelInfo::StrPair script_path;
404 for (const TiXmlElement* field = root; field; field = field->NextSiblingElement()) {
405 const char* val = field->Value();
406 if (strcmp(val, "path") == 0) {
407 script_path.first.clear();
408 script_path.second.clear();
409 const TiXmlAttribute* attrib = field->FirstAttribute();
410 while (attrib) {
411 const char* name = attrib->Name();
412 if (strcmp(name, "path") == 0) {
413 script_path.second = attrib->Value();
414 } else if (strcmp(name, "key") == 0) {
415 script_path.first = attrib->Value();
416 }
417 attrib = attrib->Next();
418 }
419 li.script_paths_.push_back(script_path);

Callers

nothing calls this directly

Calls 15

ParseLevelXMLFunction · 0.85
GetLevelTipFunction · 0.85
FindShortestPathFunction · 0.85
FormatStringFunction · 0.85
AnalyzeForLineBreaksFunction · 0.85
FileExistsFunction · 0.85
FindFilePathFunction · 0.85
FindShortestPath2Function · 0.85
LoadTerrainFunction · 0.85
FixDuplicateIDsFunction · 0.85
AddLoadingTextFunction · 0.85
AddCameraFunction · 0.85

Tested by

no test coverage detected