The 'Pawn Language' Forum
An embedded scripting language
| Back To Forum Index |
|
prayer
|
Posted On 2011-05-05 05:43 -- Subject: FIX: Problem when using timer and datagram modules I use the same configuration as here http://www.compuphase.com/bitboard/index.php?DATEIN=tpc_hvbnzmyit_1304581132. And I was experiencing some problems with the following script: #include <datagram> #include <time> @receivestring(const message[], const source[]) { printf("[%s] says: %s\n", source, message); } @keypressed(key) { if (key == '\e') exit; /* quit on ’Esc’ key */ } @timer() { printf("Hello from timer\n"); } main() { printf("Hello from main!\n"); settimer(1); listenport(9930); } First thing I've noticed the dynamical loading functionality works only when a native function is used, not a callback as @receivestring here. So that is why I have to put listenport(9930) in the script in order to make the pawnrun program loading amxDGram.so dynamically. The problem with the script is that the timer is not running when a function call is to an another library (listenport here) is made. After investigating a bit I found that the function clock() in gettimestamp routine was always returning the same number. Here is how I solve the problem: Index: amx/amxtime.c =================================================================== --- amx/amxtime.c (révision 36) +++ amx/amxtime.c (copie de travail) @@ -71,14 +71,9 @@ #if defined _WIN32_ || defined _WIN32 || defined WIN32 value=timeGetTime(); /* this value is already in milliseconds */ #else - value=clock(); - #if CLOCKS_PER_SEC<1000 - /* convert to milliseconds */ - value=(cell)((1000L * value) / CLOCKS_PER_SEC); - #elif CLOCKS_PER_SEC>1000 - /* convert to milliseconds */ - value=(cell)(value/(CLOCKS_PER_SEC/1000)); - #endif + struct timeval tv; + gettimeofday(&tv, NULL); + value = ((tv.tv_sec * 1000) + (tv.tv_usec / 1000)); #endif return value; } gettimeofday seems to work whenever a call to a function belonging to an another library than amxTime.so is made in the script. |
| You Are On Page: 1/1 | << < 1 > >> |
- BiTBOARD version 2.5 by the
BiTSHiFTERS SDC -