using draw signals.
This commit is contained in:
parent
b7b39e4034
commit
fb00e29a0d
53
balls.c
53
balls.c
@ -647,11 +647,6 @@ gint keyboard_input (GtkWidget *widget, GdkEventKey *event) {
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer data) {
|
|
||||||
draw_balls_onto_window();
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroy_window (void) {
|
void destroy_window (void) {
|
||||||
gtk_main_quit();
|
gtk_main_quit();
|
||||||
}
|
}
|
||||||
@ -675,34 +670,44 @@ void print_usage (const char * progname) {
|
|||||||
progname);
|
progname);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int stats_sampling = 0;
|
static unsigned int stats_sampling = 0;
|
||||||
|
static guint64 stats_update_usec = 0;
|
||||||
|
static unsigned int stats_update_samples = 0;
|
||||||
|
static guint64 stats_draw_usec = 0;
|
||||||
|
static unsigned int stats_draw_samples = 0;
|
||||||
|
|
||||||
|
gboolean draw_event (GtkWidget *widget, cairo_t *cr, gpointer data) {
|
||||||
|
if (stats_sampling > 0) {
|
||||||
|
guint64 start = g_get_monotonic_time ();
|
||||||
|
draw_balls_onto_window();
|
||||||
|
stats_draw_usec += g_get_monotonic_time () - start;
|
||||||
|
++stats_draw_samples;
|
||||||
|
} else
|
||||||
|
draw_balls_onto_window();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
gboolean timeout (gpointer user_data) {
|
gboolean timeout (gpointer user_data) {
|
||||||
if (stats_sampling > 0) {
|
if (stats_sampling > 0) {
|
||||||
static guint64 elapsed_usec_total = 0;
|
|
||||||
static guint64 update_usec_total = 0;
|
|
||||||
static unsigned int samples = 0;
|
|
||||||
guint64 start = g_get_monotonic_time ();
|
guint64 start = g_get_monotonic_time ();
|
||||||
update_state();
|
update_state();
|
||||||
guint64 update_usec = g_get_monotonic_time () - start;
|
stats_update_usec += g_get_monotonic_time () - start;
|
||||||
draw_balls_onto_window();
|
if (++stats_update_samples == stats_sampling) {
|
||||||
guint64 elapsed_usec = g_get_monotonic_time () - start;
|
float uavg = 1.0*stats_update_usec / stats_update_samples;
|
||||||
++samples;
|
float davg = 1.0*stats_draw_usec / stats_draw_samples;
|
||||||
elapsed_usec_total += elapsed_usec;
|
printf("\rupdate = %.0f us, draw = %.0f us, load = %.0f%% (%u update, %u draw) ",
|
||||||
update_usec_total += update_usec;
|
uavg, davg, (uavg+davg)/(10000.0*delta),
|
||||||
if (samples == stats_sampling) {
|
stats_update_samples, stats_draw_samples);
|
||||||
printf("\rupdate = %lu us, total = %lu us, load = %.0f%% (avg over %u samples) ",
|
|
||||||
update_usec_total / samples, elapsed_usec_total / samples,
|
|
||||||
(100.0*elapsed_usec_total / (1000000.0*samples*delta)), samples);
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
samples = 0;
|
stats_update_usec = 0;
|
||||||
elapsed_usec_total = 0;
|
stats_update_samples = 0;
|
||||||
update_usec_total = 0;
|
stats_draw_usec = 0;
|
||||||
|
stats_draw_samples = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
update_state();
|
update_state();
|
||||||
draw_balls_onto_window();
|
|
||||||
}
|
}
|
||||||
|
gtk_widget_queue_draw(canvas);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -781,7 +786,7 @@ int main (int argc, const char *argv[]) {
|
|||||||
canvas = gtk_drawing_area_new ();
|
canvas = gtk_drawing_area_new ();
|
||||||
|
|
||||||
g_signal_connect (G_OBJECT (canvas), "configure-event", G_CALLBACK(configure_event), NULL);
|
g_signal_connect (G_OBJECT (canvas), "configure-event", G_CALLBACK(configure_event), NULL);
|
||||||
|
g_signal_connect (G_OBJECT (canvas), "draw", G_CALLBACK (draw_event), NULL);
|
||||||
gtk_container_add (GTK_CONTAINER (window), canvas);
|
gtk_container_add (GTK_CONTAINER (window), canvas);
|
||||||
|
|
||||||
g_timeout_add (delta * 1000, timeout, canvas);
|
g_timeout_add (delta * 1000, timeout, canvas);
|
||||||
|
Loading…
Reference in New Issue
Block a user