| 1 |
|
| 2 |
#include <math.h> |
| 3 |
#include <stdlib.h> |
| 4 |
#include <clutter/clutter.h> |
| 5 |
|
| 6 |
#define N_ACTORS 100 |
| 7 |
#define N_EVENTS 5 |
| 8 |
|
| 9 |
static gint n_actors = N_ACTORS; |
| 10 |
static gint n_events = N_EVENTS; |
| 11 |
|
| 12 |
static GOptionEntry entries[] = { |
| 13 |
{ |
| 14 |
"num-actors", 'a', |
| 15 |
0, |
| 16 |
G_OPTION_ARG_INT, &n_actors, |
| 17 |
"Number of actors", "ACTORS" |
| 18 |
}, |
| 19 |
{ |
| 20 |
"num-events", 'e', |
| 21 |
0, |
| 22 |
G_OPTION_ARG_INT, &n_events, |
| 23 |
"Number of events", "EVENTS" |
| 24 |
}, |
| 25 |
{ NULL } |
| 26 |
}; |
| 27 |
|
| 28 |
static gboolean |
| 29 |
motion_event_cb (ClutterActor *actor, ClutterEvent *event, gpointer user_data) |
| 30 |
{ |
| 31 |
return FALSE; |
| 32 |
} |
| 33 |
|
| 34 |
static void |
| 35 |
do_events (ClutterActor *stage) |
| 36 |
{ |
| 37 |
glong i; |
| 38 |
static gdouble angle = 0; |
| 39 |
|
| 40 |
for (i = 0; i < n_events; i++) |
| 41 |
{ |
| 42 |
angle += (2.0 * G_PI) / (gdouble)n_actors; |
| 43 |
while (angle > G_PI * 2.0) |
| 44 |
angle -= G_PI * 2.0; |
| 45 |
|
| 46 |
/* If we synthesized events, they would be motion compressed; |
| 47 |
* calling get_actor_at_position() doesn't have that problem |
| 48 |
*/ |
| 49 |
clutter_stage_get_actor_at_pos (CLUTTER_STAGE (stage), |
| 50 |
CLUTTER_PICK_REACTIVE, |
| 51 |
256.0 + 206.0 * cos (angle), |
| 52 |
256.0 + 206.0 * sin (angle)); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
static void |
| 57 |
on_paint (ClutterActor *stage, gconstpointer *data) |
| 58 |
{ |
| 59 |
do_events (stage); |
| 60 |
} |
| 61 |
|
| 62 |
static gboolean |
| 63 |
queue_redraw (gpointer stage) |
| 64 |
{ |
| 65 |
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage)); |
| 66 |
|
| 67 |
return TRUE; |
| 68 |
} |
| 69 |
|
| 70 |
int |
| 71 |
main (int argc, char **argv) |
| 72 |
{ |
| 73 |
glong i; |
| 74 |
gdouble angle; |
| 75 |
ClutterColor color = { 0x00, 0x00, 0x00, 0xff }; |
| 76 |
ClutterActor *stage, *rect; |
| 77 |
GError *error = NULL; |
| 78 |
|
| 79 |
g_setenv ("CLUTTER_VBLANK", "none", FALSE); |
| 80 |
g_setenv ("CLUTTER_DEFAULT_FPS", "1000", FALSE); |
| 81 |
g_setenv ("CLUTTER_SHOW_FPS", "1", FALSE); |
| 82 |
|
| 83 |
if (clutter_init_with_args (&argc, &argv, |
| 84 |
NULL, |
| 85 |
entries, |
| 86 |
NULL, |
| 87 |
&error) != CLUTTER_INIT_SUCCESS) |
| 88 |
return 1; |
| 89 |
|
| 90 |
stage = clutter_stage_new (); |
| 91 |
clutter_actor_set_size (stage, 512, 512); |
| 92 |
clutter_stage_set_color (CLUTTER_STAGE (stage), CLUTTER_COLOR_Black); |
| 93 |
clutter_stage_set_title (CLUTTER_STAGE (stage), "Picking"); |
| 94 |
|
| 95 |
printf ("Picking performance test with " |
| 96 |
"%d actors and %d events per frame\n", |
| 97 |
n_actors, |
| 98 |
n_events); |
| 99 |
|
| 100 |
for (i = n_actors - 1; i >= 0; i--) |
| 101 |
{ |
| 102 |
angle = ((2.0 * G_PI) / (gdouble) n_actors) * i; |
| 103 |
|
| 104 |
color.red = (1.0 - ABS ((MAX (0, MIN (n_actors/2.0 + 0, i))) / |
| 105 |
(gdouble)(n_actors/4.0) - 1.0)) * 255.0; |
| 106 |
color.green = (1.0 - ABS ((MAX (0, MIN (n_actors/2.0 + 0, |
| 107 |
fmod (i + (n_actors/3.0)*2, n_actors)))) / |
| 108 |
(gdouble)(n_actors/4) - 1.0)) * 255.0; |
| 109 |
color.blue = (1.0 - ABS ((MAX (0, MIN (n_actors/2.0 + 0, |
| 110 |
fmod ((i + (n_actors/3.0)), n_actors)))) / |
| 111 |
(gdouble)(n_actors/4.0) - 1.0)) * 255.0; |
| 112 |
|
| 113 |
rect = clutter_rectangle_new_with_color (&color); |
| 114 |
clutter_actor_set_size (rect, 100, 100); |
| 115 |
clutter_actor_set_anchor_point_from_gravity (rect, |
| 116 |
CLUTTER_GRAVITY_CENTER); |
| 117 |
clutter_actor_set_position (rect, |
| 118 |
256 + 206 * cos (angle), |
| 119 |
256 + 206 * sin (angle)); |
| 120 |
clutter_actor_set_reactive (rect, TRUE); |
| 121 |
g_signal_connect (rect, "motion-event", |
| 122 |
G_CALLBACK (motion_event_cb), NULL); |
| 123 |
|
| 124 |
clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); |
| 125 |
} |
| 126 |
|
| 127 |
clutter_actor_show (stage); |
| 128 |
|
| 129 |
clutter_threads_add_idle (queue_redraw, stage); |
| 130 |
|
| 131 |
g_signal_connect (stage, "paint", G_CALLBACK (on_paint), NULL); |
| 132 |
|
| 133 |
clutter_main (); |
| 134 |
|
| 135 |
clutter_actor_destroy (stage); |
| 136 |
|
| 137 |
return 0; |
| 138 |
} |
| 139 |
|
| 140 |
|