void Scene::save() { std::ifstream ifs(settings_file); rapidjson::IStreamWrapper isw(ifs); Document doc; doc.ParseStream(isw); ifs.close(); ofstream ofs(settings_file); OStreamWrapper osw(ofs); Writer<OStreamWrapper> writer(osw); Value& scene = doc["scene"]; scene["carcas_enabled"].SetBool(carcas_enabled); scene["animation_enabled"].SetBool(animation_enabled); scene["texture_enabled"].SetBool(texture_enabled); scene["partition"].SetInt(partition); scene["current_time"].SetFloat(current_time); scene["rotate_x"].SetFloat(rotate_x); scene["rotate_y"].SetFloat(rotate_y); scene["scale"].SetFloat(scale); auto lights = doc["lighting"]["local"].GetArray(); for(auto light : local_lights) lights[light.num]["enabled"].SetBool(light.enabled); doc.Accept(writer); ofs.close(); }
void plugin_options::parse_json(std::string path) { // first try to open as a directory osd_directory *directory = osd_opendir(path.c_str()); if (directory != nullptr) { // iterate over all files in the directory for (const osd_directory_entry *entry = osd_readdir(directory); entry != nullptr; entry = osd_readdir(directory)) { if (entry->type == ENTTYPE_FILE) { std::string name = entry->name; if (name == "plugin.json") { std::string curfile = std::string(path).append(PATH_SEPARATOR).append(entry->name); std::ifstream ifs(curfile); rapidjson::IStreamWrapper isw(ifs); rapidjson::Document document; document.ParseStream<0>(isw); if (document.HasParseError()) { std::string error(GetParseError_En(document.GetParseError())); osd_printf_error("Unable to parse plugin definition file %s. Errors returned:\n", curfile.c_str()); osd_printf_error("%s\n", error.c_str()); return; } if (document["plugin"].IsObject()) { std::string name = document["plugin"]["name"].GetString(); std::string description = document["plugin"]["description"].GetString(); std::string type = document["plugin"]["type"].GetString(); bool start = false; if (document["plugin"].HasMember("start") && (std::string(document["plugin"]["start"].GetString()) == "true")) start = true; if (type=="plugin") { add_entry(core_strdup(name.c_str()),core_strdup(description.c_str()), OPTION_BOOLEAN, start ? "1" : "0"); } } } } else if (entry->type == ENTTYPE_DIR) { std::string name = entry->name; if (!(name == "." || name == "..")) { parse_json(path + PATH_SEPARATOR + name); } } } // close the directory and be done osd_closedir(directory); } }
void Scene::load() { std::ifstream ifs(settings_file); rapidjson::IStreamWrapper isw(ifs); Document doc; doc.ParseStream(isw); deserializeLightParams(doc, global_light, local_lights, materials); deserializeTextures(textures, doc); if (!doc.HasMember("scene")) { std::cerr << "Incorrect settings file. Directive scene is absent" << endl; return; } Value& scene = doc["scene"]; carcas_enabled = scene["carcas_enabled"].GetBool(); animation_enabled = scene["animation_enabled"].GetBool(); partition = scene["partition"].GetInt(); current_time = scene["current_time"].GetFloat(); rotate_x = scene["rotate_x"].GetFloat(); rotate_y = scene["rotate_y"].GetFloat(); scale = scene["scale"].GetFloat(); texture_enabled = scene["texture_enabled"].GetBool(); if (!doc.HasMember("optimization")) { std::cout << "NOTE: optimization directive is absent" << std::endl; return; } Value& jOParams = doc["optimization"]; optimization.optimize_drawing = jOParams["optimize_drawing"].GetBool(); optimization.optimize_animation = jOParams["optimize_animation"].GetBool(); optimization.display_lists = jOParams["display_lists"].GetBool(); optimization.optimize_lighting = jOParams["optimize_lighting"].GetBool(); }