Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2004:
[Freeciv-Dev] Re: (PR#8073) win32: unit moves aren't smooth
Home

[Freeciv-Dev] Re: (PR#8073) win32: unit moves aren't smooth

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: use_less@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#8073) win32: unit moves aren't smooth
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 15 Mar 2004 13:38:18 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=8073 >

Jason Short wrote:

>>>>After a little research, I find that mingw has no support for
>>>>gettimeofday(), which is required for millisecond resolution for freeciv
>>>>timers.

>>I believe ftime() should work.
> 
> 
> And the patch.  Please test it (remember to rerun autogen.sh first).

Hmm, it looks like ftime() doesn't always have a return value.  This 
patch ignores the return value.

jason

Index: configure.ac
===================================================================
RCS file: /home/freeciv/CVS/freeciv/configure.ac,v
retrieving revision 1.55
diff -u -r1.55 configure.ac
--- configure.ac        26 Feb 2004 13:32:20 -0000      1.55
+++ configure.ac        15 Mar 2004 21:37:20 -0000
@@ -541,9 +541,9 @@
 AC_FUNC_VPRINTF
 AC_FUNC_VSNPRINTF
 
-AC_CHECK_FUNCS(fileno gethostname getpwuid inet_aton \
-               select snooze strerror strcasecmp strncasecmp \
-               strlcat strlcpy strstr usleep vsnprintf uname flock)
+AC_CHECK_FUNCS([fileno ftime gethostname getpwuid inet_aton \
+               select snooze strerror strcasecmp strncasecmp \
+               strlcat strlcpy strstr usleep vsnprintf uname flock])
 
 AC_MSG_CHECKING(for working gettimeofday)
   FC_CHECK_GETTIMEOFDAY_RUNTIME(,AC_DEFINE(HAVE_GETTIMEOFDAY, 1,
Index: configure.in
===================================================================
RCS file: /home/freeciv/CVS/freeciv/configure.in,v
retrieving revision 1.230
diff -u -r1.230 configure.in
--- configure.in        10 Mar 2004 22:14:27 -0000      1.230
+++ configure.in        15 Mar 2004 21:37:20 -0000
@@ -525,9 +525,9 @@
 AC_FUNC_VPRINTF
 AC_FUNC_VSNPRINTF
 
-AC_CHECK_FUNCS(fileno gethostname getpwuid inet_aton \
-               select snooze strerror strcasecmp strncasecmp \
-               strlcat strlcpy strstr usleep vsnprintf uname flock)
+AC_CHECK_FUNCS([fileno ftime gethostname getpwuid inet_aton \
+               select snooze strerror strcasecmp strncasecmp \
+               strlcat strlcpy strstr usleep vsnprintf uname flock\)
 AC_MSG_CHECKING(for working gettimeofday)
   FC_CHECK_GETTIMEOFDAY_RUNTIME(,AC_DEFINE(HAVE_GETTIMEOFDAY),)
 
Index: common/timing.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/timing.c,v
retrieving revision 1.11
diff -u -r1.11 timing.c
--- common/timing.c     4 Apr 2003 15:47:49 -0000       1.11
+++ common/timing.c     15 Mar 2004 21:37:20 -0000
@@ -52,6 +52,10 @@
 #include <unistd.h>
 #endif
 
+#ifdef HAVE_FTIME
+# include <sys/timeb.h>
+#endif
+
 #include "log.h"
 #include "mem.h"
 #include "shared.h"            /* TRUE, FALSE */
@@ -90,6 +94,8 @@
     clock_t c;
 #ifdef HAVE_GETTIMEOFDAY
     struct timeval tv;
+#elif HAVE_FTIME
+    struct timeb tp;
 #else
     time_t t;
 #endif
@@ -126,7 +132,7 @@
   }
   t->use = TIMER_IGNORE;
 }
-#else
+#elsif !defined HAVE_FTIME
 /********************************************************************** 
   Report if time() returns -1, but only the first time.
   Ignore this timer from now on.
@@ -260,6 +266,8 @@
       report_gettimeofday_failed(t);
       return;
     }
+#elif defined HAVE_FTIME
+    ftime(&t->start.tp);
 #else
     t->start.t = time(NULL);
     if (t->start.t == (time_t) -1) {
@@ -324,6 +332,21 @@
       t->usec -= sec * N_USEC_PER_SEC;
     }
     t->start.tv = now;
+#elif defined HAVE_FTIME
+    struct timeb now;
+
+    ftime(&now);
+    t->usec += 1000 * ((long)now.millitm - (long)t->start.tp.millitm);
+    t->sec += now.time - t->start.tp.time;
+    if (t->usec < 0) {
+      t->usec += N_USEC_PER_SEC;
+      t->sec -= 1.0;
+    } else if (t->usec >= N_USEC_PER_SEC) {
+      long sec = t->usec / N_USEC_PER_SEC;
+      t->sec += sec;
+      t->usec -= sec * N_USEC_PER_SEC;
+    }
+    t->start.tp = now;
 #else
     time_t now = time(NULL);
     if (now == (time_t) -1) {
@@ -407,6 +430,19 @@
 
   if (wait_usec > 0)
     myusleep(wait_usec);
+#elif HAVE_FTIME
+  struct timeb now;
+  long elapsed_usec, wait_usec;
+
+  ftime(&now);
+
+  elapsed_usec = (now.time - t->start.tp.time) * N_USEC_PER_SEC
+    + (now.millitm - t->start.tp.millitm);
+  wait_usec = usec - elapsed_usec;
+
+  if (wait_usec > 0) {
+    myusleep(wait_usec);
+  }
 #else
   myusleep(usec);
 #endif

[Prev in Thread] Current Thread [Next in Thread]