# http://mantis.bearnip.com/view.php?id=477 # # another fine contribution by fufu. requires 'improve-statistics.patch' int get_eval_number() Return the current evaluation number. It's incremented for each top-level call. [...] The intended purpose of this function is to find out if something has already been done for the current command, heart_beat, call_out or whatever. Control flow in mudlibs is often complicated and adding the necessary infrastructure to a mudlib to answer this question is error-prone and tedious. In the driver it's just a few lines of code. Index: doc/efun/get_eval_number =================================================================== --- doc/efun/get_eval_number (revision 0) +++ doc/efun/get_eval_number (revision 0) @@ -0,0 +1,17 @@ +SYNOPSIS + int get_eval_number() + +DESCRIPTION + Return the current evaluation number. It's incremented for each + top-level call. These are: commands, calls to heart_beat, reset, + or clean_up, and calls generated by call_out or input_to, master + applies triggered by external events, send_erq callbacks and the + calls to logon on player login. + + The counter is a 32 bits counter so it can overflow occasionally. + +HISTORY + Since ldmud 3.3.372 + +SEE ALSO + get_eval_cost() Index: src/efuns.c =================================================================== --- src/efuns.c (revision 2306) +++ src/efuns.c (working copy) @@ -8702,5 +8702,23 @@ return sp; } /* f_utime() */ +/*-------------------------------------------------------------------------*/ +svalue_t * +f_get_eval_number (svalue_t *sp) + +/* EFUN get_eval_number() + * + * Return the current evaluation number. It's incremented for each + * top-level call. These are: commands, calls to heart_beat, reset, + * or clean_up, and calls generated by call_out or input_to. + * + * The counter is a 32 bits counter so it will overflow occasionally. + */ + +{ + push_number(sp, eval_number); + return sp; +} /* f_get_eval_number */ + /***************************************************************************/ Index: src/func_spec =================================================================== --- src/func_spec (revision 2306) +++ src/func_spec (working copy) @@ -772,6 +772,7 @@ int set_is_wizard(object, int default: F_CONST1); #endif +int get_eval_number(); /* Obsolete and deprecated functions */ Index: src/interpret.c =================================================================== --- src/interpret.c (revision 2306) +++ src/interpret.c (working copy) @@ -697,7 +697,8 @@ #endif - unsigned long total_evalcost; +unsigned long eval_number; /* evaluation number. 32 bits - will overflow */ +unsigned long total_evalcost; static struct timeval eval_begin; /* Current total evalcost counter, and start of the evaluation. */ @@ -772,6 +773,7 @@ */ { + eval_number++; total_evalcost = 0; if (gettimeofday(&eval_begin, NULL)) { Index: src/interpret.h =================================================================== --- src/interpret.h (revision 2306) +++ src/interpret.h (working copy) @@ -116,6 +116,7 @@ extern p_int apply_cache_miss; #endif +extern unsigned long eval_number; extern unsigned long total_evalcost; extern unsigned long last_total_evalcost; extern struct timeval last_eval_duration;