[Freeciv-Dev] (PR#12187) idle-time callbacks for mapview updates
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12187 >
This patch does two things:
- Adds a GUI function add_idle_callback. This takes a function and a
pointer and should call the function with the pointer during an idle moment.
- Uses add_idle_callback to call unqueue_mapview_updates. Whenever an
update is enqueued we add an idle callback to dequeue (i.e., draw) the
update. The existing callers of unqueue_mapview_updates in the network
code are removed. This means the queue system is encapsulated entirely
in mapview_common.c now. It also means queues will work even if they
are not called from inside the network code.
add_idle_callback is only implemented for gui-gtk-2.0. The other GUIs
use a fallback of calling the callback immediately. This will make some
drawing operations up to 100x slower since the benefits of the queueing
system will be lost.
-jason
Index: client/clinet.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/clinet.c,v
retrieving revision 1.110
diff -u -r1.110 clinet.c
--- client/clinet.c 22 Jan 2005 19:45:39 -0000 1.110
+++ client/clinet.c 9 Feb 2005 17:38:05 -0000
@@ -347,8 +347,6 @@
} else {
close_socket_callback(&aconnection);
}
-
- unqueue_mapview_updates();
}
/**************************************************************************
@@ -391,7 +389,7 @@
if (aconnection.client.last_processed_request_id_seen >=
expected_request_id) {
freelog(LOG_DEBUG, "ifstrgp: got it; returning");
- goto out;
+ return;
}
}
}
@@ -400,9 +398,6 @@
break;
}
}
-
-out:
- unqueue_mapview_updates();
}
#ifdef WIN32_NATIVE
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.182
diff -u -r1.182 mapview_common.c
--- client/mapview_common.c 9 Feb 2005 17:15:17 -0000 1.182
+++ client/mapview_common.c 9 Feb 2005 17:38:06 -0000
@@ -25,6 +25,7 @@
#include "timing.h"
#include "graphics_g.h"
+#include "gui_main_g.h"
#include "mapctrl_g.h"
#include "mapview_g.h"
@@ -2187,10 +2188,33 @@
}
static enum update_type needed_updates = UPDATE_NONE;
+static bool callback_queued = FALSE;
struct tile_list *city_updates = NULL;
struct tile_list *unit_updates = NULL;
struct tile_list *tile_updates = NULL;
+/****************************************************************************
+ This callback is called during an idle moment to unqueue any pending
+ mapview updates.
+****************************************************************************/
+static void queue_callback(void *data)
+{
+ callback_queued = FALSE;
+ unqueue_mapview_updates();
+}
+
+/****************************************************************************
+ When a mapview update is queued this function should be called to prepare
+ an idle-time callback to unqueue the updates.
+****************************************************************************/
+static void queue_add_callback(void)
+{
+ if (!callback_queued) {
+ callback_queued = TRUE;
+ add_idle_callback(queue_callback, NULL);
+ }
+}
+
/**************************************************************************
This function, along with unqueue_mapview_update(), helps in updating
the mapview when a packet is received. Previously, we just called
@@ -2211,6 +2235,7 @@
void queue_mapview_update(enum update_type update)
{
needed_updates |= update;
+ queue_add_callback();
}
/**************************************************************************
@@ -2226,6 +2251,7 @@
tile_updates = tile_list_new();
}
tile_list_prepend(tile_updates, ptile);
+ queue_add_callback();
}
/**************************************************************************
@@ -2238,6 +2264,7 @@
unit_updates = tile_list_new();
}
tile_list_prepend(unit_updates, punit->tile);
+ queue_add_callback();
}
/**************************************************************************
@@ -2250,6 +2277,7 @@
city_updates = tile_list_new();
}
tile_list_prepend(city_updates, pcity->tile);
+ queue_add_callback();
}
/**************************************************************************
Index: client/gui-gtk/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/gui_main.c,v
retrieving revision 1.159
diff -u -r1.159 gui_main.c
--- client/gui-gtk/gui_main.c 22 Jan 2005 19:45:40 -0000 1.159
+++ client/gui-gtk/gui_main.c 9 Feb 2005 17:38:06 -0000
@@ -1197,3 +1197,17 @@
gdk_input_remove(gdk_input_id);
gdk_window_set_cursor(root_window, NULL);
}
+
+/****************************************************************************
+ Enqueue a callback to be called during an idle moment. The 'callback'
+ function should be called sometimes soon, and passed the 'data' pointer
+ as its data.
+****************************************************************************/
+void add_idle_callback(void (callback)(void *), void *data)
+{
+ /* PORTME */
+
+ /* This is a reasonable fallback if it's not ported. */
+ freelog(LOG_ERROR, "Unimplemented add_idle_callback.");
+ (callback)(data);
+}
Index: client/gui-gtk-2.0/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gui_main.c,v
retrieving revision 1.107
diff -u -r1.107 gui_main.c
--- client/gui-gtk-2.0/gui_main.c 5 Feb 2005 19:46:32 -0000 1.107
+++ client/gui-gtk-2.0/gui_main.c 9 Feb 2005 17:38:07 -0000
@@ -1535,3 +1535,33 @@
return TRUE;
}
+struct callback {
+ void (*callback)(void *data);
+ void *data;
+};
+
+/****************************************************************************
+ A wrapper for the callback called through add_idle_callback.
+****************************************************************************/
+static gint idle_callback_wrapper(gpointer data)
+{
+ struct callback *cb = data;
+
+ (cb->callback)(cb->data);
+ free(cb);
+ return 0;
+}
+
+/****************************************************************************
+ Enqueue a callback to be called during an idle moment. The 'callback'
+ function should be called sometimes soon, and passed the 'data' pointer
+ as its data.
+****************************************************************************/
+void add_idle_callback(void (callback)(void *), void *data)
+{
+ struct callback *cb = fc_malloc(sizeof(*cb));
+
+ cb->callback = callback;
+ cb->data = data;
+ gtk_idle_add(idle_callback_wrapper, cb);
+}
Index: client/gui-mui/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/gui_main.c,v
retrieving revision 1.88
diff -u -r1.88 gui_main.c
--- client/gui-mui/gui_main.c 22 Nov 2004 07:54:46 -0000 1.88
+++ client/gui-mui/gui_main.c 9 Feb 2005 17:38:07 -0000
@@ -1455,3 +1455,17 @@
void set_unit_icons_more_arrow(bool onoff)
{
}
+
+/****************************************************************************
+ Enqueue a callback to be called during an idle moment. The 'callback'
+ function should be called sometimes soon, and passed the 'data' pointer
+ as its data.
+****************************************************************************/
+void add_idle_callback(void (callback)(void *), void *data)
+{
+ /* PORTME */
+
+ /* This is a reasonable fallback if it's not ported. */
+ freelog(LOG_ERROR, "Unimplemented add_idle_callback.");
+ (callback)(data);
+}
Index: client/gui-sdl/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/gui_main.c,v
retrieving revision 1.47
diff -u -r1.47 gui_main.c
--- client/gui-sdl/gui_main.c 20 Nov 2004 21:27:17 -0000 1.47
+++ client/gui-sdl/gui_main.c 9 Feb 2005 17:38:08 -0000
@@ -960,3 +960,17 @@
pStoreAnimCursor = NULL;
}
}
+
+/****************************************************************************
+ Enqueue a callback to be called during an idle moment. The 'callback'
+ function should be called sometimes soon, and passed the 'data' pointer
+ as its data.
+****************************************************************************/
+void add_idle_callback(void (callback)(void *), void *data)
+{
+ /* PORTME */
+
+ /* This is a reasonable fallback if it's not ported. */
+ freelog(LOG_ERROR, "Unimplemented add_idle_callback.");
+ (callback)(data);
+}
Index: client/gui-stub/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-stub/gui_main.c,v
retrieving revision 1.14
diff -u -r1.14 gui_main.c
--- client/gui-stub/gui_main.c 5 Dec 2004 04:23:19 -0000 1.14
+++ client/gui-stub/gui_main.c 9 Feb 2005 17:38:08 -0000
@@ -107,3 +107,17 @@
{
/* PORTME */
}
+
+/****************************************************************************
+ Enqueue a callback to be called during an idle moment. The 'callback'
+ function should be called sometimes soon, and passed the 'data' pointer
+ as its data.
+****************************************************************************/
+void add_idle_callback(void (callback)(void *), void *data)
+{
+ /* PORTME */
+
+ /* This is a reasonable fallback if it's not ported. */
+ freelog(LOG_ERROR, "Unimplemented add_idle_callback.");
+ (callback)(data);
+}
Index: client/gui-win32/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/gui_main.c,v
retrieving revision 1.37
diff -u -r1.37 gui_main.c
--- client/gui-win32/gui_main.c 21 Jan 2005 02:14:08 -0000 1.37
+++ client/gui-win32/gui_main.c 9 Feb 2005 17:38:08 -0000
@@ -645,3 +645,17 @@
{
/* PORTME */
}
+
+/****************************************************************************
+ Enqueue a callback to be called during an idle moment. The 'callback'
+ function should be called sometimes soon, and passed the 'data' pointer
+ as its data.
+****************************************************************************/
+void add_idle_callback(void (callback)(void *), void *data)
+{
+ /* PORTME */
+
+ /* This is a reasonable fallback if it's not ported. */
+ freelog(LOG_ERROR, "Unimplemented add_idle_callback.");
+ (callback)(data);
+}
Index: client/gui-xaw/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/gui_main.c,v
retrieving revision 1.99
diff -u -r1.99 gui_main.c
--- client/gui-xaw/gui_main.c 1 Dec 2004 22:15:23 -0000 1.99
+++ client/gui-xaw/gui_main.c 9 Feb 2005 17:38:08 -0000
@@ -890,3 +890,17 @@
showing = FALSE;
}
}
+
+/****************************************************************************
+ Enqueue a callback to be called during an idle moment. The 'callback'
+ function should be called sometimes soon, and passed the 'data' pointer
+ as its data.
+****************************************************************************/
+void add_idle_callback(void (callback)(void *), void *data)
+{
+ /* PORTME */
+
+ /* This is a reasonable fallback if it's not ported. */
+ freelog(LOG_ERROR, "Unimplemented add_idle_callback.");
+ (callback)(data);
+}
Index: client/include/gui_main_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/gui_main_g.h,v
retrieving revision 1.10
diff -u -r1.10 gui_main_g.h
--- client/include/gui_main_g.h 3 Sep 2004 04:22:36 -0000 1.10
+++ client/include/gui_main_g.h 9 Feb 2005 17:38:08 -0000
@@ -27,6 +27,8 @@
void set_unit_icon(int idx, struct unit *punit);
void set_unit_icons_more_arrow(bool onoff);
+void add_idle_callback(void (callback)(void *), void *data);
+
extern const char *client_string;
#endif /* FC__GUI_MAIN_G_H */
- [Freeciv-Dev] (PR#12187) idle-time callbacks for mapview updates,
Jason Short <=
|
|