MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / Osiris_SaveSystemState

Function Osiris_SaveSystemState

Descent3/OsirisLoadandBind.cpp:2575–2681  ·  view source on GitHub ↗

Osiris_SaveSystemState Purpose: Saves the current state of the system (not the scripts!) to file

Source from the content-addressed store, hash-verified

2573// Purpose:
2574// Saves the current state of the system (not the scripts!) to file
2575void Osiris_SaveSystemState(CFILE *file) {
2576 int i;
2577 int save_start = cftell(file);
2578 int checksum_pos;
2579
2580 cf_WriteString(file, "OSIRIS");
2581
2582 cf_WriteByte(file, OSIRIS_SYSTEM_FILEVERSION);
2583
2584 checksum_pos = cftell(file);
2585 cf_WriteInt(file, 0); // this will be # of bytes writtens
2586
2587 cf_WriteInt(file, Osiris_timer_counter);
2588
2589 // save out the timer state
2590 for (i = 0; i < MAX_OSIRIS_TIMERS; i++) {
2591 if (OsirisTimers[i].flags & OITF_USED) {
2592 // write out information about this timer
2593 cf_WriteByte(file, 1); // timer exists
2594 cf_WriteShort(file, OsirisTimers[i].flags);
2595 cf_WriteInt(file, OsirisTimers[i].id);
2596 cf_WriteInt(file, OsirisTimers[i].repeat_count);
2597 cf_WriteFloat(file, OsirisTimers[i].timer_interval);
2598 cf_WriteFloat(file, OsirisTimers[i].timer_next_signal);
2599 cf_WriteFloat(file, OsirisTimers[i].timer_end);
2600 cf_WriteInt(file, OsirisTimers[i].objhandle);
2601 cf_WriteInt(file, OsirisTimers[i].objhandle_detonator);
2602 cf_WriteInt(file, OsirisTimers[i].handle);
2603 } else {
2604 cf_WriteByte(file, 0);
2605 }
2606 }
2607
2608 // auto-save script mallocs
2609 Osiris_SaveMemoryChunks(file);
2610
2611 // go through all loaded DLLs and save states
2612 // this is touchy, we need to make sure all DLL modules that are currently
2613 // loaded, be loaded when we restore states. As a safety precaution, the Global
2614 // state will be saved as the following (an array of the following):
2615 // byte offset size description
2616 // 0 1 Number of loaded DLLs
2617 // ...
2618 // +1 1 String length of module name
2619 // +2 x Name of the module
2620 // +2+x 4 Size of global data stored
2621 // +6+x y global data
2622 // ...
2623
2624 // first count up the number of loaded modules
2625 int loaded_module_count = 0;
2626 for (i = 0; i < MAX_LOADED_MODULES; i++) {
2627 if (OSIRIS_loaded_modules[i].flags & OSIMF_INUSE) {
2628 // this is a loaded module
2629 loaded_module_count++;
2630 }
2631 }
2632

Callers 2

SaveGameStateFunction · 0.85
DemoWriteHeaderFunction · 0.85

Calls 13

cftellFunction · 0.85
cf_WriteStringFunction · 0.85
cf_WriteByteFunction · 0.85
cf_WriteIntFunction · 0.85
cf_WriteShortFunction · 0.85
cf_WriteFloatFunction · 0.85
Osiris_SaveMemoryChunksFunction · 0.85
cf_WriteBytesFunction · 0.85
cfseekFunction · 0.85
Osiris_SaveOMMSFunction · 0.85
Osiris_CallLevelEventFunction · 0.85
Osiris_CallTriggerEventFunction · 0.85

Tested by

no test coverage detected