MCPcopy Create free account
hub / github.com/NetHack/NetHack / save_timers

Function save_timers

src/timeout.c:2667–2699  ·  view source on GitHub ↗

* Save part of the timer list. The parameter 'range' specifies either * global or level timers to save. The timer ID is saved with the global * timers. * * Global range: * + timeouts that follow the hero (global) * + timeouts that follow obj & monst that are migrating * * Level range: * + timeouts that are level-specific (e.g. storms) * + timeouts that stay with the

Source from the content-addressed store, hash-verified

2665 * + timeouts that stay with the level (obj & monst)
2666 */
2667void
2668save_timers(NHFILE *nhfp, int range)
2669{
2670 timer_element *curr, *prev, *next_timer = 0;
2671 int count;
2672
2673 if (update_file(nhfp)) {
2674 if (range == RANGE_GLOBAL) {
2675 Sfo_ulong(nhfp, &svt.timer_id, "timer-timer_id");
2676 }
2677 count = maybe_write_timer(nhfp, range, FALSE);
2678 Sfo_int(nhfp, &count, "timer-timer_count");
2679 (void) maybe_write_timer(nhfp, range, TRUE);
2680 }
2681
2682 if (release_data(nhfp)) {
2683 for (prev = 0, curr = gt.timer_base; curr; curr = next_timer) {
2684 next_timer = curr->next; /* in case curr is removed */
2685
2686 if (!(!!(range == RANGE_LEVEL) ^ !!timer_is_local(curr))) {
2687 if (prev)
2688 prev->next = curr->next;
2689 else
2690 gt.timer_base = curr->next;
2691 (void) memset((genericptr_t) curr, 0, sizeof(timer_element));
2692 free((genericptr_t) curr);
2693 /* prev stays the same */
2694 } else {
2695 prev = curr;
2696 }
2697 }
2698 }
2699}
2700#endif /* !SFCTOOL */
2701
2702/*

Callers 2

savegamestateFunction · 0.85
savelev_coreFunction · 0.85

Calls 3

update_fileFunction · 0.85
maybe_write_timerFunction · 0.85
timer_is_localFunction · 0.85

Tested by

no test coverage detected