Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2005:
[Freeciv-Dev] (PR#12634) ftwl: Rewrite main redraw loop (repost)
Home

[Freeciv-Dev] (PR#12634) ftwl: Rewrite main redraw loop (repost)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12634) ftwl: Rewrite main redraw loop (repost)
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Fri, 25 Mar 2005 03:53:47 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12634 >

Reposting to RT as RT is now working. - Per

---------- Forwarded message ----------
Date: Sat, 9 Oct 2004 13:42:01 +0000 (GMT)
From: Per Inge Mathisen <per@xxxxxxxxxxx>
To: freeciv-dev@xxxxxxxxxxx
Cc: Raimar Falke <hawk@xxxxxxxxxxxxxxxxx>
Subject: [Freeciv-Dev] ftwl: Rewrite main redraw loop

(Reposting this to list only, as RT seems defunct ATM.)

I found the problem with the SDL backend. SDL was innocent of all charges,
and the same was the SDL backend code. Turns out the problem was that the
redraw loop was ... pretty much non-existent. Basically there would be
redraws at random intervals due to other stuff happening, but not as a
result of actual map movement. The x11 backend had fixed this by inserting
a call to the high-level sw_paint_all() function directly into the
low-level backend code. The sdl backend did not have this incredible
kludge.

So, I decided to make a change I had long wanted, making ftwl a
constant-frame-rate application. This is nice for doing animations. The
framerate should probably be either user set or dynamic, depending on
speed of graphics hardware, but so far a fixed FPS of 20 at least makes
the graphics smooth pretty much irrespective of backend choice.

To change the FPS, just change the #define FTWL_FPS in the top of
client/gui-ftwl/gui_main.c to another value.

  - Per

Index: client/gui-ftwl/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-ftwl/gui_main.c,v
retrieving revision 1.4
diff -u -r1.4 gui_main.c
--- client/gui-ftwl/gui_main.c  9 Oct 2004 11:59:38 -0000       1.4
+++ client/gui-ftwl/gui_main.c  9 Oct 2004 13:16:09 -0000
@@ -39,6 +39,11 @@
 
 #include "gui_main.h"
 
+/* See timer_callback() below for documentation on these */
+#define FTWL_FPS 20
+#define FTWL_MSPF 1000 / FTWL_FPS
+#define FPS_INTERVAL_COUNTER (TIMER_INTERVAL / FTWL_MSPF)
+
 client_option gui_options[] = {
 };
 const int num_gui_options = ARRAY_SIZE(gui_options);
@@ -61,13 +66,24 @@
 }
 
 /**************************************************************************
-  ...
+  This sets up the FPS (frames per second) of our map redraw, and also 
+  calls real_timer_callback() from the client common code, which sets up 
+  the game countdown and unit blinking. real_timer_callback() must be 
+  called every TIMER_INTERVAL ms.
+
+  FTWL_FPS  = Frames per second
+  FTWL_MSPF = Milliseconds between each frame
+  FPS_INTERVAL_COUNTER = Frames until we need to call real_timer_callback
 **************************************************************************/
 static void timer_callback(void *data)
 {
-  real_timer_callback();
-  //sw_add_timeout(TIMER_INTERVAL, timer_callback, NULL);
-  sw_add_timeout(1000, timer_callback, NULL);
+  static int counter = FPS_INTERVAL_COUNTER;
+
+  if (counter == 0) {
+    real_timer_callback();
+    counter = FPS_INTERVAL_COUNTER;
+  }
+  sw_add_timeout(FTWL_MSPF, timer_callback, NULL);
 }
 
 /**************************************************************************
Index: utility/ftwl/be_x11_ximage.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/ftwl/be_x11_ximage.c,v
retrieving revision 1.2
diff -u -r1.2 be_x11_ximage.c
--- utility/ftwl/be_x11_ximage.c        7 Oct 2004 15:24:45 -0000       1.2
+++ utility/ftwl/be_x11_ximage.c        9 Oct 2004 13:16:10 -0000
@@ -33,10 +33,6 @@
 
 #include "mem.h"
 
-// fixme
-#include "timing.h"
-#include "widget.h"
-
 static Display *display;
 static Window window;
 static int screen_number;
@@ -236,8 +232,6 @@
     }
   }
 
-  sw_paint_all();
-
   {
     fd_set readfds, exceptfds;
     int ret, highest = x11fd;

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12634) ftwl: Rewrite main redraw loop (repost), Per I. Mathisen <=