SDL_GW_Params GameConfig::ParseWindow(const XMLDOC& doc) { using namespace tinyxml2; SDL_GW_Params params; const XMLElement* gameElement = doc.FirstChildElement("game"); const XMLElement* windowElement = gameElement->FirstChildElement("window"); #ifdef UNICODE /*this could change in future*/ UConverter convert; params.title = convert.from_bytes(windowElement->Attribute("title")); #else params.title = windowElement->Attribute("title"); #endif params.x = windowElement->IntAttribute("x"); params.y = windowElement->IntAttribute("y"); params.width = windowElement->IntAttribute("width"); params.height = windowElement->IntAttribute("height"); /* const XMLElement* rendererElement = gameElement->FirstChildElement("renderer"); const char* renderer = rendererElement->Attribute("type"); if (!strcmp(renderer, "DirectX")) params.renderer = SDL_GW_Renderer::OPENGL; else params.renderer = SDL_GW_Renderer::DIRECTX;*/ return params; }
Scene* Scene::Deserialize(File* file) { using namespace tinyxml2; //File is actually an XML file //we should now open for reading XMLDOC document; XMLError err = document.LoadFile(file->Handle()); UString errString; if (XMLErrCheck(err, errString)) { DebugPrintF(VTEXT("Scene File failed to load\n")); return NULL; } Scene* _scene = new Scene; SceneManager::AddScene(_scene); const XMLElement* sceneElement = document.FirstChildElement("scene"); const XMLElement* objectListElement = sceneElement->FirstChildElement("object-list"); const XMLElement* gameObjectElement = objectListElement->FirstChildElement("gameobject"); const char* sceneID = sceneElement->Attribute("id"); _scene->SetID(UStringFromCharArray(sceneID)); while (gameObjectElement != NULL) { GameObject* _gameObject = ParseGameObject(_scene, gameObjectElement); _scene->AddSceneObject(_gameObject); gameObjectElement = gameObjectElement->NextSiblingElement("gameobject"); } ///////////////////////////////////////////////////// // temporary until objects have their enabled status serialized ////////////////////////////////////////// /*for (auto& obj : _scene->m_sceneObjects) obj.second->SetEnabled(true, true); */ //spawn all queued objects for (auto& object : _scene->m_objectsToAdd) { _scene->AddSceneObject(object); } _scene->m_objectsToAdd.clear(); return _scene; }
bool ModelManager::Initialize() { ModelManager& _manager = ModelManager::instance(); using namespace tinyxml2; //need to attempt to open scene list File* file = FileManager::OpenFile(PathManager::ModelPath() + VTEXT("models.config")); if (file) { //File is actually an XML file //we should now open for reading XMLDOC document; XMLError err = document.LoadFile(file->Handle()); UString errString; if (XMLErrCheck(err, errString)) { DebugPrintF(VTEXT("Models Config File failed to load\n")); FileManager::CloseFile(file); return false; } const XMLElement* modelsElement = document.FirstChildElement("models"); const XMLElement* modelElement = modelsElement->FirstChildElement("model"); while (modelElement != NULL) { const char* fileID = modelElement->Attribute("file"); UString id = UStringFromCharArray(fileID); IModel* model = ResourceManager::OpenModel(id); if (model) _manager.m_models[id] = model; else DebugPrintF(VTEXT("ModelManager: %s failed to load"), id.c_str()); modelElement = modelElement->NextSiblingElement("model"); } FileManager::CloseFile(file); return true; } FileManager::CloseFile(file); return false; }
void PathManager::Initialize() { using namespace tinyxml2; //Open Environment Config File File* envFile = FileManager::OpenFile(os_exec_dir() + VTEXT("vixen.env")); XMLDOC document; XMLError err = document.LoadFile(envFile->Handle()); UString errMsg; if (XMLErrCheck(err, errMsg)) { DebugPrintF(VTEXT("Env file failed to load: %s\n"), errMsg.c_str()); return; } const XMLElement* envElement = document.FirstChildElement("env"); const XMLElement* assetPathElement = envElement->FirstChildElement("asset-path"); _AssetPath += UStringFromCharArray(assetPathElement->Attribute("value")); _AssetPath = os_path(_AssetPath); _ScenePath = _AssetPath + VTEXT("Scenes/"); _ScenePath = os_path(_ScenePath); _ModelPath = _AssetPath + VTEXT("Models/"); _ModelPath = os_path(_ModelPath); _ShaderPath = _AssetPath + VTEXT("Shaders/"); #ifdef VIX_SYS_WINDOWS _ShaderPath += VTEXT("DirectX/"); #endif _ShaderPath = os_path(_ShaderPath); _ScriptPath = _AssetPath + VTEXT("Scripts/"); _ScriptPath = os_path(_ScriptPath); _PrefabPath = _AssetPath + VTEXT("Prefabs/"); _PrefabPath = os_path(_PrefabPath); FileManager::CloseFile(envFile); }
Prefab* PrefabManager::LoadFile(UString file) { PrefabManager& _manager = PrefabManager::instance(); using namespace tinyxml2; File* _prefabFile = FileManager::OpenFile(PathManager::PrefabPath() + file, FileMode::ReadBinary); if (_prefabFile) { //File is actually an XML file //we should now open for reading XMLDOC document; XMLError err = document.LoadFile(_prefabFile->Handle()); UString errString; if (XMLErrCheck(err, errString)) { DebugPrintF(VTEXT("Prefab File failed to load\n")); FileManager::CloseFile(_prefabFile); return NULL; } const XMLElement* prefab = document.FirstChildElement("prefab"); const XMLElement* object = prefab->FirstChildElement("gameobject"); if (prefab) { if (object) { Prefab* _prefab = ParsePrefab(object); _manager.m_prefabs[file] = _prefab; FileManager::CloseFile(_prefabFile); return _prefab; } } } FileManager::CloseFile(_prefabFile); return NULL; }