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