summaryrefslogtreecommitdiff
path: root/src/ui-arena.c
diff options
context:
space:
mode:
authorJoshua Judson Rosen2017-03-28 00:22:07 -0400
committerJoshua Judson Rosen2017-03-28 22:07:50 -0400
commitbb508ed7a38d4088e33d30818a435e06b983c274 (patch)
treebbcaea405f1113e7709a33b800bd2983bafd775d /src/ui-arena.c
parentUI: show for _what_ types of things robot is smelling/feeling/looking (diff)
downloadgnurobots-bb508ed7a38d4088e33d30818a435e06b983c274.tar.gz
Let the GUI process between updates!
Move the GDK lock-management into the various arena action functions so that we can release the lock _before_ sleeping in the guile thread, allowing the GUI thread to update when the sleep starts rather than when the sleep ends, so that the messages actually stand a chance at remaining visible for something close to USLEEP_TIME-- rather than not showing until USLEEP_TIME has already expired. Otherwise many of the updates get lost, e.g.: (while (robot-feel "space") (robot-move 1)) ... never seems to actually spend any time with the "Robot feels ..." messages visible onscreen between the "Robot moves.." messages. Note also that this change allows the GUI to generally be much more responsive to user interaction (e.g.: scrolling, selection/copy/paste) while a robot program is running!
Diffstat (limited to 'src/ui-arena.c')
-rw-r--r--src/ui-arena.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/ui-arena.c b/src/ui-arena.c
index 854d75d..e6ce836 100644
--- a/src/ui-arena.c
+++ b/src/ui-arena.c
@@ -305,6 +305,8 @@ void ui_arena_add_thing(UIArena *arena, gint x, gint y, gint thing)
w_x = x * TILE_SIZE;
w_y = y * TILE_SIZE;
+ gdk_threads_enter ();
+
switch (thing)
{
case SPACE:
@@ -332,6 +334,8 @@ void ui_arena_add_thing(UIArena *arena, gint x, gint y, gint thing)
gtk_widget_queue_draw_area(GTK_WIDGET(arena), 0, 0, arena->priv->width,
arena->priv->height);
+
+ gdk_threads_leave ();
}
void ui_arena_move_robot(UIArena *arena, gint from_x, gint from_y,
@@ -345,6 +349,8 @@ void ui_arena_move_robot(UIArena *arena, gint from_x, gint from_y,
g_assert(distance <= 1);
+ gdk_threads_enter ();
+
ui_arena_update_status(arena, "Robot moves..", NULL,
energy, score, shields);
@@ -359,6 +365,7 @@ void ui_arena_move_robot(UIArena *arena, gint from_x, gint from_y,
gtk_widget_queue_draw_area(GTK_WIDGET(arena), 0, 0,
arena->priv->width, arena->priv->height);
+ gdk_threads_leave ();
return;
}
@@ -416,12 +423,15 @@ void ui_arena_move_robot(UIArena *arena, gint from_x, gint from_y,
arena->priv->width, arena->priv->height);
gdk_window_process_all_updates();
+ gdk_threads_leave ();
g_usleep(USLEEP_TIME / 16);
+ gdk_threads_enter ();
if (!ok)
break;
}
+ gdk_threads_leave ();
g_usleep(USLEEP_TIME);
}
@@ -429,9 +439,11 @@ void ui_arena_move_robot(UIArena *arena, gint from_x, gint from_y,
void ui_arena_robot_smell(UIArena *arena, gint x, gint y, gint cdir,
glong energy, glong score, glong shields, const gchar *thing)
{
+ gdk_threads_enter ();
/* If we want to change the pic, do it here */
ui_arena_update_status(arena, "Robot sniffs for %s...", thing,
energy, score, shields);
+ gdk_threads_leave ();
g_usleep(USLEEP_TIME);
}
@@ -439,8 +451,10 @@ void ui_arena_robot_smell(UIArena *arena, gint x, gint y, gint cdir,
void ui_arena_robot_zap(UIArena *arena, gint x, gint y, gint cdir,
gint x_to, gint y_to, glong energy, glong score, glong shields)
{
+ gdk_threads_enter ();
ui_arena_update_status(arena, "Robot fires his little gun...", NULL,
energy, score, shields);
+ gdk_threads_leave ();
g_usleep(USLEEP_TIME);
}
@@ -450,8 +464,10 @@ void ui_arena_robot_feel(UIArena *arena,
gint x_to, gint y_to, glong energy, glong score, glong shields,
const gchar *thing)
{
+ gdk_threads_enter ();
ui_arena_update_status(arena, "Robot feels for %s...", thing,
energy, score, shields);
+ gdk_threads_leave ();
g_usleep(USLEEP_TIME);
}
@@ -459,8 +475,10 @@ void ui_arena_robot_feel(UIArena *arena,
void ui_arena_robot_grab(UIArena *arena, gint x, gint y, gint cdir,
gint x_to, gint y_to, glong energy, glong score, glong shields)
{
+ gdk_threads_enter ();
ui_arena_update_status(arena, "Robot grabs...", NULL,
energy, score, shields);
+ gdk_threads_leave ();
g_usleep(USLEEP_TIME);
}
@@ -469,8 +487,10 @@ void ui_arena_robot_look(UIArena *arena, gint x, gint y, gint cdir,
gint x_to, gint y_to, glong energy, glong score, glong shields,
const gchar *thing)
{
+ gdk_threads_enter ();
ui_arena_update_status(arena, "Robot looks for %s...", thing,
energy, score, shields);
+ gdk_threads_leave ();
g_usleep(USLEEP_TIME);
}