diff options
-rw-r--r-- | src/char/char.c | 1 | ||||
-rw-r--r-- | src/common/timer.c | 20 | ||||
-rw-r--r-- | src/common/timer.h | 19 | ||||
-rw-r--r-- | src/map/map.c | 1 | ||||
-rw-r--r-- | src/map/npc.c | 2 |
5 files changed, 16 insertions, 27 deletions
diff --git a/src/char/char.c b/src/char/char.c index d340f1d..dc77c31 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -2337,7 +2337,6 @@ void parse_tologin (int fd) //-------------------------------- // Map-server anti-freeze system //-------------------------------- -typedef void (*timer_func) (timer_id, tick_t, custom_id_t, custom_data_t); void map_anti_freeze_system (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { int i; diff --git a/src/common/timer.c b/src/common/timer.c index bf21c8e..915aeb4 100644 --- a/src/common/timer.c +++ b/src/common/timer.c @@ -20,7 +20,7 @@ static uint32_t free_timer_list_max, free_timer_list_pos; // timer_heap[0] is the size (greatest index into the heap) // timer_heap[1] is the first actual element // timer_heap_max increases 256 at a time and never decreases -static uint32_t timer_heap_max = 256; +static uint32_t timer_heap_max = 0; /// FIXME: refactor the code to put the size in a separate variable //nontrivial because indices get multiplied static timer_id *timer_heap = NULL; @@ -48,19 +48,14 @@ uint32_t gettick (void) static void push_timer_heap (timer_id index) { - if (timer_heap == NULL) + if (timer_heap == NULL || timer_heap[0] + 1 >= timer_heap_max) { timer_heap_max += 256; - CREATE (timer_heap, timer_id, timer_heap_max); + RECREATE (timer_heap, int, timer_heap_max); + memset (timer_heap + (timer_heap_max - 256), 0, sizeof (timer_id) * 256); } // timer_heap[0] is the greatest index into the heap, which increases timer_heap[0]++; - if (timer_heap[0] >= timer_heap_max) - { - timer_heap_max += 256; - RECREATE (timer_heap, timer_id, timer_heap_max); - memset (timer_heap + (timer_heap_max - 256), 0, 4 * 256); - } timer_id h = timer_heap[0]-1, i = (h - 1) / 2; while (h) @@ -104,7 +99,8 @@ static timer_id pop_timer_heap () uint32_t i = (h - 1) / 2; while (h) { - if (DIFF_TICK(timer_data[timer_heap[i + 1]].tick, timer_data[last].tick) <= 0) + if (DIFF_TICK (timer_data[timer_heap[i + 1]].tick, timer_data[last].tick) <= 0) + break; timer_heap[h + 1] = timer_heap[i + 1]; h = i; i = (h - 1) / 2; @@ -152,7 +148,7 @@ timer_id add_timer (tick_t tick, timer_func func, custom_id_t id, custom_data_t } timer_data[i].tick = tick; timer_data[i].func = func; - timer_data[i].id = id; + timer_data[i].id = id; timer_data[i].data = data; timer_data[i].type = TIMER_ONCE_AUTODEL; timer_data[i].interval = 1000; @@ -237,7 +233,7 @@ interdb_val_t do_timer (tick_t tick) free_timer_list_max += 256; RECREATE (free_timer_list, uint32_t, free_timer_list_max); memset (free_timer_list + (free_timer_list_max - 256), - 0, 256 * sizeof (timer_id)); + 0, 256 * sizeof (uint32_t)); } free_timer_list[free_timer_list_pos++] = i; break; diff --git a/src/common/timer.h b/src/common/timer.h index 4fa5db8..2a38e04 100644 --- a/src/common/timer.h +++ b/src/common/timer.h @@ -3,7 +3,8 @@ # include "sanity.h" -enum TIMER_TYPE { +enum TIMER_TYPE +{ TIMER_ONCE_AUTODEL = 1, TIMER_INTERVAL = 2, }; @@ -32,7 +33,7 @@ struct TimerData /// Type of timer - 0 initially enum TIMER_TYPE type; /// Repeat rate - uint32_t interval; + interdb_val_t interval; }; /// Server time, in milliseconds, since the epoch, @@ -44,24 +45,16 @@ tick_t gettick_nocache (void); /// the next 255 times tick_t gettick (void); -timer_id add_timer (tick_t tick, timer_func func, custom_id_t id, - custom_data_t data); -timer_id add_timer_interval (tick_t tick, timer_func func, custom_id_t id, - custom_data_t data, interdb_val_t interval); +timer_id add_timer (tick_t, timer_func, custom_id_t, custom_data_t); +timer_id add_timer_interval (tick_t, timer_func, custom_id_t, custom_data_t, interdb_val_t); void delete_timer (timer_id, timer_func); -tick_t addtick_timer (timer_id tid, interdb_val_t tick); +tick_t addtick_timer (timer_id, interdb_val_t); struct TimerData *get_timer (timer_id tid); /// Do all timers scheduled before tick, and return the number of milliseconds until the next timer happens interdb_val_t do_timer (tick_t tick); -// debugging -static void add_timer_func_list (timer_func, char *) __attribute__((deprecated)); -static inline void add_timer_func_list (timer_func UNUSED, char *UNUSED) {} -// used to just call free(), which doesn't matter when we're exiting -static void timer_final () __attribute__((deprecated)); -static inline void timer_final() {}; #endif // TIMER_H diff --git a/src/map/map.c b/src/map/map.c index 8261e49..7730b94 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -2113,7 +2113,6 @@ void do_final (void) delete_session (i); map_removenpc (); - timer_final (); numdb_final (id_db, NULL); strdb_final (map_db, NULL); diff --git a/src/map/npc.c b/src/map/npc.c index 54b13d8..85ac6e9 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -2236,6 +2236,8 @@ int do_final_npc (void) if (ev_db) strdb_final (ev_db, ev_db_final); + if (npcname_db) + strdb_final (npcname_db, NULL); for (i = START_NPC_NUM; i < npc_id; i++) { |