MCPcopy Create free account
hub / github.com/DFHack/dfhack / save

Method save

library/modules/Persistence.cpp:202–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200};
201
202void Persistence::Internal::save(color_ostream& out) {
203 Core &core = Core::getInstance();
204
205 if (!core.isWorldLoaded())
206 return;
207
208 CoreSuspender suspend;
209 LastLoadSaveTickCountUpdater tickCountUpdater;
210
211 // write status
212 {
213 auto file = std::ofstream(getSaveFilePath("current", "status"));
214 file << "DF version: " << core.p->getDescriptor()->getVersion() << std::endl;
215 file << "DFHack version: " << Version::dfhack_version() << " (" << Version::git_commit(true) << ")" << std::endl;
216 file << "Tagged release: " << (Version::is_release() ? "yes" : "no") << std::endl;
217 file << "Pre-release: " << (Version::is_prerelease() ? "yes" : "no") << std::endl;
218 if (strlen(Version::dfhack_run_url())) {
219 file << "Build url: " << Version::dfhack_run_url() << std::endl;
220 }
221 if (df::global::world and df::global::version) {
222 file << std::endl;
223 file << "World name: " << World::getWorldName() << " (" << World::getWorldName(true) << ")" << std::endl;
224 file << "World generated in version: " << df::global::world->original_save_version << std::endl;
225 file << "World last saved in version: " << df::global::world->save_version << std::endl;
226 file << "World loaded in version: " << *df::global::version << std::endl;
227 }
228 }
229
230 // write entity data
231 for (auto & entity_store_entry : store) {
232 int entity_id = entity_store_entry.first;
233 Json::Value json(Json::arrayValue);
234 for (auto & entries : entity_store_entry.second) {
235 if (entries.second == nullptr)
236 continue;
237 json.append(entries.second->toJSON());
238 }
239 std::string name = (entity_id == Persistence::WORLD_ENTITY_ID) ?
240 "world" : "entity-" + int_to_string(entity_id);
241 auto file = std::ofstream(getSaveFilePath("current", name));
242 file << json;
243 }
244
245 // write perf counters
246 {
247 auto file = std::ofstream(getSaveFilePath("current", "perf-counters"));
248 color_ostream_wrapper wrapper(file);
249 Lua::CallLuaModuleFunction(wrapper, "script-manager", "print_timers");
250 }
251
252}
253
254static bool get_entity_id(const std::string & fname, int & entity_id) {
255 if (!fname.starts_with("dfhack-entity-"))

Callers 4

fIOthreadFunction · 0.45
dfhack_lineedit_syncFunction · 0.45
RunCoreQueryLoopMethod · 0.45
addCommandToHistoryFunction · 0.45

Calls 9

getSaveFilePathFunction · 0.85
dfhack_versionFunction · 0.85
git_commitFunction · 0.85
is_releaseFunction · 0.85
is_prereleaseFunction · 0.85
dfhack_run_urlFunction · 0.85
int_to_stringFunction · 0.85
CallLuaModuleFunctionFunction · 0.85
toJSONMethod · 0.80

Tested by

no test coverage detected