Settings::~Settings() { // Only main application is allowed to change settings. if (canModifySettings() && m_changed) { m_settings.sync(); beginSave(); QSettings to; while ( !m_settings.group().isEmpty() ) m_settings.endGroup(); copySettings(m_settings, &to); endSave(); } }
void Settings::restore() { Settings appSettings; if ( isLastSaveUnfinished() ) { log("Restoring application settings", LogWarning); if ( appSettings.isEmpty() ) { log("Cannot restore application settings", LogError); } else { QSettings settings; copySettings(appSettings.m_settings, &settings); } endSave(); } else { const QSettings settings; if ( needsUpdate(appSettings, settings) ) copySettings(settings, &appSettings.m_settings); } }
bool SkApply::draw(SkAnimateMaker& maker) { if (scope ==NULL) return false; if (scope->isApply() || scope->isDrawable() == false) return false; if (fEnabled == false) enable(maker); SkASSERT(scope); activate(maker); if (mode == kMode_immediate) return fActive->draw(); bool result = interpolate(maker, maker.getInTime()); if (dontDraw == false) { // if (scope->isDrawable()) result |= scope->draw(maker); } if (restore) { for (int index = 0; index < fActive->fAnimators.count(); index++) endSave(index); fActive->advance(); } return result; }
void Actor::save() { startSave("Actor"); Creature::save(); endSave(); }
void PlayerDatabaseSQLite3::savePlayer(RemotePlayer *player) { PlayerSAO* sao = player->getPlayerSAO(); sanity_check(sao); const v3f &pos = sao->getBasePosition(); // Begin save in brace is mandatory if (!playerDataExists(player->getName())) { beginSave(); str_to_sqlite(m_stmt_player_add, 1, player->getName()); double_to_sqlite(m_stmt_player_add, 2, sao->getPitch()); double_to_sqlite(m_stmt_player_add, 3, sao->getYaw()); double_to_sqlite(m_stmt_player_add, 4, pos.X); double_to_sqlite(m_stmt_player_add, 5, pos.Y); double_to_sqlite(m_stmt_player_add, 6, pos.Z); int64_to_sqlite(m_stmt_player_add, 7, sao->getHP()); int64_to_sqlite(m_stmt_player_add, 8, sao->getBreath()); sqlite3_vrfy(sqlite3_step(m_stmt_player_add), SQLITE_DONE); sqlite3_reset(m_stmt_player_add); } else { beginSave(); double_to_sqlite(m_stmt_player_update, 1, sao->getPitch()); double_to_sqlite(m_stmt_player_update, 2, sao->getYaw()); double_to_sqlite(m_stmt_player_update, 3, pos.X); double_to_sqlite(m_stmt_player_update, 4, pos.Y); double_to_sqlite(m_stmt_player_update, 5, pos.Z); int64_to_sqlite(m_stmt_player_update, 6, sao->getHP()); int64_to_sqlite(m_stmt_player_update, 7, sao->getBreath()); str_to_sqlite(m_stmt_player_update, 8, player->getName()); sqlite3_vrfy(sqlite3_step(m_stmt_player_update), SQLITE_DONE); sqlite3_reset(m_stmt_player_update); } // Write player inventories str_to_sqlite(m_stmt_player_remove_inventory, 1, player->getName()); sqlite3_vrfy(sqlite3_step(m_stmt_player_remove_inventory), SQLITE_DONE); sqlite3_reset(m_stmt_player_remove_inventory); str_to_sqlite(m_stmt_player_remove_inventory_items, 1, player->getName()); sqlite3_vrfy(sqlite3_step(m_stmt_player_remove_inventory_items), SQLITE_DONE); sqlite3_reset(m_stmt_player_remove_inventory_items); std::vector<const InventoryList*> inventory_lists = sao->getInventory()->getLists(); for (u16 i = 0; i < inventory_lists.size(); i++) { const InventoryList* list = inventory_lists[i]; str_to_sqlite(m_stmt_player_add_inventory, 1, player->getName()); int_to_sqlite(m_stmt_player_add_inventory, 2, i); int_to_sqlite(m_stmt_player_add_inventory, 3, list->getWidth()); str_to_sqlite(m_stmt_player_add_inventory, 4, list->getName()); int_to_sqlite(m_stmt_player_add_inventory, 5, list->getSize()); sqlite3_vrfy(sqlite3_step(m_stmt_player_add_inventory), SQLITE_DONE); sqlite3_reset(m_stmt_player_add_inventory); for (u32 j = 0; j < list->getSize(); j++) { std::ostringstream os; list->getItem(j).serialize(os); std::string itemStr = os.str(); str_to_sqlite(m_stmt_player_add_inventory_items, 1, player->getName()); int_to_sqlite(m_stmt_player_add_inventory_items, 2, i); int_to_sqlite(m_stmt_player_add_inventory_items, 3, j); str_to_sqlite(m_stmt_player_add_inventory_items, 4, itemStr); sqlite3_vrfy(sqlite3_step(m_stmt_player_add_inventory_items), SQLITE_DONE); sqlite3_reset(m_stmt_player_add_inventory_items); } } str_to_sqlite(m_stmt_player_metadata_remove, 1, player->getName()); sqlite3_vrfy(sqlite3_step(m_stmt_player_metadata_remove), SQLITE_DONE); sqlite3_reset(m_stmt_player_metadata_remove); const PlayerAttributes &attrs = sao->getExtendedAttributes(); for (PlayerAttributes::const_iterator it = attrs.begin(); it != attrs.end(); ++it) { str_to_sqlite(m_stmt_player_metadata_add, 1, player->getName()); str_to_sqlite(m_stmt_player_metadata_add, 2, it->first); str_to_sqlite(m_stmt_player_metadata_add, 3, it->second); sqlite3_vrfy(sqlite3_step(m_stmt_player_metadata_add), SQLITE_DONE); sqlite3_reset(m_stmt_player_metadata_add); } endSave(); }
u32 Map::timerUpdate(float uptime, float unload_timeout, u32 max_loaded_blocks, unsigned int max_cycle_ms, std::vector<v3POS> *unloaded_blocks) { bool save_before_unloading = (mapType() == MAPTYPE_SERVER); // Profile modified reasons Profiler modprofiler; if (/*!m_blocks_update_last && */ m_blocks_delete->size() > 1000) { m_blocks_delete = (m_blocks_delete == &m_blocks_delete_1 ? &m_blocks_delete_2 : &m_blocks_delete_1); verbosestream << "Deleting blocks=" << m_blocks_delete->size() << std::endl; for (auto & ir : *m_blocks_delete) delete ir.first; m_blocks_delete->clear(); getBlockCacheFlush(); } u32 deleted_blocks_count = 0; u32 saved_blocks_count = 0; u32 block_count_all = 0; u32 n = 0, calls = 0, end_ms = porting::getTimeMs() + max_cycle_ms; std::vector<MapBlockP> blocks_delete; int save_started = 0; { auto lock = m_blocks.try_lock_shared_rec(); if (!lock->owns_lock()) return m_blocks_update_last; #if !ENABLE_THREADS auto lock_map = m_nothread_locker.try_lock_unique_rec(); if (!lock_map->owns_lock()) return m_blocks_update_last; #endif for(auto ir : m_blocks) { if (n++ < m_blocks_update_last) { continue; } else { m_blocks_update_last = 0; } ++calls; auto block = ir.second; if (!block) continue; { auto lock = block->try_lock_unique_rec(); if (!lock->owns_lock()) continue; if(block->getUsageTimer() > unload_timeout) { // block->refGet() <= 0 && v3POS p = block->getPos(); //infostream<<" deleting block p="<<p<<" ustimer="<<block->getUsageTimer() <<" to="<< unload_timeout<<" inc="<<(uptime - block->m_uptime_timer_last)<<" state="<<block->getModified()<<std::endl; // Save if modified if (block->getModified() != MOD_STATE_CLEAN && save_before_unloading) { //modprofiler.add(block->getModifiedReasonString(), 1); if(!save_started++) beginSave(); if (!saveBlock(block)) continue; saved_blocks_count++; } blocks_delete.push_back(block); if(unloaded_blocks) unloaded_blocks->push_back(p); deleted_blocks_count++; } else { #ifndef SERVER if (block->mesh_old) block->mesh_old = nullptr; #endif if (!block->m_uptime_timer_last) // not very good place, but minimum modifications block->m_uptime_timer_last = uptime - 0.1; block->incrementUsageTimer(uptime - block->m_uptime_timer_last); block->m_uptime_timer_last = uptime; block_count_all++; /*#ifndef SERVER if(block->refGet() == 0 && block->getUsageTimer() > g_settings->getFloat("unload_unused_meshes_timeout")) { if(block->mesh){ delete block->mesh; block->mesh = NULL; } } #endif*/ } } // block lock if (porting::getTimeMs() > end_ms) { m_blocks_update_last = n; break; } } } if(save_started) endSave(); if (!calls) m_blocks_update_last = 0; for (auto & block : blocks_delete) this->deleteBlock(block); // Finally delete the empty sectors if(deleted_blocks_count != 0) { if (m_blocks_update_last) infostream << "ServerMap: timerUpdate(): Blocks processed:" << calls << "/" << m_blocks.size() << " to " << m_blocks_update_last << std::endl; PrintInfo(infostream); // ServerMap/ClientMap: infostream << "Unloaded " << deleted_blocks_count << "/" << (block_count_all + deleted_blocks_count) << " blocks from memory"; infostream << " (deleteq1=" << m_blocks_delete_1.size() << " deleteq2=" << m_blocks_delete_2.size() << ")"; if(saved_blocks_count) infostream << ", of which " << saved_blocks_count << " were written"; /* infostream<<", "<<block_count_all<<" blocks in memory"; */ infostream << "." << std::endl; if(saved_blocks_count != 0) { PrintInfo(infostream); // ServerMap/ClientMap: //infostream<<"Blocks modified by: "<<std::endl; modprofiler.print(infostream); } } return m_blocks_update_last; }
void PlayerDatabasePostgreSQL::savePlayer(RemotePlayer *player) { PlayerSAO* sao = player->getPlayerSAO(); if (!sao) return; verifyDatabase(); v3f pos = sao->getBasePosition(); std::string pitch = ftos(sao->getPitch()); std::string yaw = ftos(sao->getYaw()); std::string posx = ftos(pos.X); std::string posy = ftos(pos.Y); std::string posz = ftos(pos.Z); std::string hp = itos(sao->getHP()); std::string breath = itos(sao->getBreath()); const char *values[] = { player->getName(), pitch.c_str(), yaw.c_str(), posx.c_str(), posy.c_str(), posz.c_str(), hp.c_str(), breath.c_str() }; const char* rmvalues[] = { player->getName() }; beginSave(); if (getPGVersion() < 90500) { if (!playerDataExists(player->getName())) execPrepared("create_player", 8, values, true, false); else execPrepared("update_player", 8, values, true, false); } else execPrepared("save_player", 8, values, true, false); // Write player inventories execPrepared("remove_player_inventories", 1, rmvalues); execPrepared("remove_player_inventory_items", 1, rmvalues); std::vector<const InventoryList*> inventory_lists = sao->getInventory()->getLists(); for (u16 i = 0; i < inventory_lists.size(); i++) { const InventoryList* list = inventory_lists[i]; const std::string &name = list->getName(); std::string width = itos(list->getWidth()), inv_id = itos(i), lsize = itos(list->getSize()); const char* inv_values[] = { player->getName(), inv_id.c_str(), width.c_str(), name.c_str(), lsize.c_str() }; execPrepared("add_player_inventory", 5, inv_values); for (u32 j = 0; j < list->getSize(); j++) { std::ostringstream os; list->getItem(j).serialize(os); std::string itemStr = os.str(), slotId = itos(j); const char* invitem_values[] = { player->getName(), inv_id.c_str(), slotId.c_str(), itemStr.c_str() }; execPrepared("add_player_inventory_item", 4, invitem_values); } } execPrepared("remove_player_metadata", 1, rmvalues); const StringMap &attrs = sao->getMeta().getStrings(); for (const auto &attr : attrs) { const char *meta_values[] = { player->getName(), attr.first.c_str(), attr.second.c_str() }; execPrepared("save_player_metadata", 3, meta_values); } sao->getMeta().setModified(false); endSave(); }