diff --git a/ChangeLog b/ChangeLog index d35781706..d78147d3e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2007-11-06 Tomas Frydrych + + * clutter/clutter-fixed.h: + Added CLUTTER_SQRTI_ARG_MAX, CLUTTER_SQRTI_5_PERCENT, + CLUTTER_SQRTI_10_PERCENT expressing clutter_sqrti limits. + Stripped trailing whitespace. + + * clutter/clutter-fixed.c: + (clutter_sqrti): + Updated documentation, stripped trailing whitespace. + + * clutter/clutter-behaviour-path.c: + (node_distance): + Use clib sqrt if clutter_sqrti() precission would be worse than + 10%. + Stripped trailing whitespace. + 2007-11-06 Emmanuele Bassi * clutter/clutter-layout.h: Add commodity macros to test for @@ -19,7 +36,7 @@ * clutter/clutter-container.[ch]: removed find_child_by_id method from interface (and all implementations of it) since this functionality is now implemented using a global hash. - * clutter/clutter-box.c: + * clutter/clutter-box.c: * clutter/clutter-group.c: 2007-11-01 Emmanuele Bassi @@ -124,7 +141,7 @@ * clutter/cogl/gles/cogl-defines.h: * clutter/cogl/gl/cogl.c: * clutter/cogl/gles/cogl.c: - Switch from use of guint to COGLuint. Avoids problems when + Switch from use of guint to COGLuint. Avoids problems when guint != GLuint on some platforms, i.e OSX. (Tommi Komulainen, #525, #523) @@ -368,18 +385,18 @@ * clutter/clutter-color.c: Copy the alpha when shading. 2007-10-16 Tomas Frydrych - + * clutter.symbols: Added a bunch of missing symbols. - + * clutter/clutter-script.c: * json/json-node.c: Use g_slice_new0 instead of g_slice_new to avoid passing garbage to functions. - + * tests/test-threads.c: Replaced non-portable sleep() with g_usleep(). - + 2007-10-15 Tomas Frydrych * clutter/cogl/gl/cogl-defines.h: @@ -393,7 +410,7 @@ * clutter/clutter-event.c: * clutter/clutter-event.h: - Add synthetic flag and make put_event use it + Add synthetic flag and make put_event use it (via modded patch from pippin) * clutter/clutter-main.c: (clutter_do_event): @@ -412,9 +429,9 @@ * clutter.symbols: A list of public symbols, one per line; semi-autogenerated, so - might not be complete -- PLEASE when adding new public APIs, add + might not be complete -- PLEASE when adding new public APIs, add the function name to this file. - + 2007-10-12 Emmanuele Bassi * clutter/clutter-actor.c: Add a :depth property, so we can diff --git a/clutter/clutter-behaviour-path.c b/clutter/clutter-behaviour-path.c index ac9e04421..60bd66946 100644 --- a/clutter/clutter-behaviour-path.c +++ b/clutter/clutter-behaviour-path.c @@ -59,7 +59,7 @@ static void clutter_scriptable_iface_init (ClutterScriptableIface *iface); -G_DEFINE_TYPE_WITH_CODE (ClutterBehaviourPath, +G_DEFINE_TYPE_WITH_CODE (ClutterBehaviourPath, clutter_behaviour_path, CLUTTER_TYPE_BEHAVIOUR, G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_SCRIPTABLE, @@ -92,7 +92,7 @@ enum PROP_KNOT }; -static void +static void clutter_behaviour_path_finalize (GObject *object) { ClutterBehaviourPath *self = CLUTTER_BEHAVIOUR_PATH(object); @@ -104,8 +104,8 @@ clutter_behaviour_path_finalize (GObject *object) } static inline void -interpolate (const ClutterKnot *begin, - const ClutterKnot *end, +interpolate (const ClutterKnot *begin, + const ClutterKnot *end, ClutterKnot *out, ClutterFixed t) { @@ -117,18 +117,28 @@ static gint node_distance (const ClutterKnot *begin, const ClutterKnot *end) { + gint t; + g_return_val_if_fail (begin != NULL, 0); g_return_val_if_fail (end != NULL, 0); if (clutter_knot_equal (begin, end)) return 0; -#if 1 - return clutter_sqrti ((end->x - begin->x) * (end->x - begin->x) + - (end->y - begin->y) * (end->y - begin->y)); + t = (end->x - begin->x) * (end->x - begin->x) + + (end->y - begin->y) * (end->y - begin->y); + + /* + * If we are using limited precision sqrti implementation, fallback on + * clib sqrt if the precission would be less than 10% + */ +#if INT_MAX > CLUTTER_SQRTI_ARG_10_PERCENT + if (t <= CLUTTER_SQRTI_ARG_10_PERCENT) + return clutter_sqrti (t); + else + return CLUTTER_FLOAT_TO_INT(sqrt(t)); #else - return CLUTTER_FLOAT_TO_INT(sqrt((end->x - begin->x) * (end->x - begin->x) + - (end->y - begin->y) * (end->y - begin->y))); + return clutter_sqrti (t); #endif } @@ -166,7 +176,7 @@ path_alpha_to_position (ClutterBehaviourPath *behave, GSList *l; gint total_len, offset, dist = 0; - /* FIXME: Optimise. Much of the data used here can be pre-generated + /* FIXME: Optimise. Much of the data used here can be pre-generated * ( total_len, dist between knots ) when knots are added/removed. */ @@ -181,29 +191,29 @@ path_alpha_to_position (ClutterBehaviourPath *behave, total_len = path_total_length (behave); offset = (alpha * total_len) / CLUTTER_ALPHA_MAX_ALPHA; - CLUTTER_NOTE (BEHAVIOUR, "alpha %i vs %i, len: %i vs %i", + CLUTTER_NOTE (BEHAVIOUR, "alpha %i vs %i, len: %i vs %i", alpha, CLUTTER_ALPHA_MAX_ALPHA, offset, total_len); if (offset == 0) { /* first knot */ - clutter_behaviour_actors_foreach (behaviour, + clutter_behaviour_actors_foreach (behaviour, actor_apply_knot_foreach, priv->knots->data); - + priv->last_knot_passed = (ClutterKnot*)priv->knots->data; g_signal_emit (behave, path_signals[KNOT_REACHED], 0, priv->knots->data); return; } - + if (offset == total_len) { /* Special case for last knot */ ClutterKnot *last_knot = (g_slist_last (priv->knots))->data; - clutter_behaviour_actors_foreach (behaviour, + clutter_behaviour_actors_foreach (behaviour, actor_apply_knot_foreach, last_knot); @@ -217,7 +227,7 @@ path_alpha_to_position (ClutterBehaviourPath *behave, { gint dist_to_next = 0; ClutterKnot *knot = l->data; - + if (l->next) { ClutterKnot *next = l->next->data; @@ -228,12 +238,12 @@ path_alpha_to_position (ClutterBehaviourPath *behave, { ClutterKnot new; ClutterFixed t; - + t = CLUTTER_INT_TO_FIXED (offset - dist) / dist_to_next; interpolate (knot, next, &new, t); - clutter_behaviour_actors_foreach (behaviour, + clutter_behaviour_actors_foreach (behaviour, actor_apply_knot_foreach, &new); @@ -323,7 +333,7 @@ clutter_behaviour_path_class_init (ClutterBehaviourPathClass *klass) CLUTTER_TYPE_KNOT); behave_class->alpha_notify = clutter_behaviour_path_alpha_notify; - + g_type_class_add_private (klass, sizeof (ClutterBehaviourPathPrivate)); } @@ -379,7 +389,7 @@ clutter_behaviour_path_parse_custom_node (ClutterScriptable *scriptable, array = json_node_get_array (node); knots_len = json_array_get_length (array); - + for (i = 0; i < knots_len; i++) { JsonNode *val = json_array_get_element (array, i); @@ -430,8 +440,8 @@ clutter_behaviour_path_new (ClutterAlpha *alpha, { ClutterBehaviourPath *behave; gint i; - - behave = g_object_new (CLUTTER_TYPE_BEHAVIOUR_PATH, + + behave = g_object_new (CLUTTER_TYPE_BEHAVIOUR_PATH, "alpha", alpha, NULL); @@ -449,7 +459,7 @@ clutter_behaviour_path_new (ClutterAlpha *alpha, * clutter_behaviour_path_get_knots: * @pathb: a #ClutterBehvaiourPath * - * Returns a copy of the list of knots contained by @pathb + * Returns a copy of the list of knots contained by @pathb * * Return value: a #GSList of the paths knots. * @@ -465,7 +475,7 @@ clutter_behaviour_path_get_knots (ClutterBehaviourPath *pathb) retval = NULL; for (l = pathb->priv->knots; l != NULL; l = l->next) retval = g_slist_prepend (retval, l->data); - + return g_slist_reverse (retval); } @@ -473,7 +483,7 @@ clutter_behaviour_path_get_knots (ClutterBehaviourPath *pathb) * clutter_behaviour_path_append_knot: * @pathb: a #ClutterBehvaiourPath * @knot: a #ClutterKnot to append. - * + * * Appends a #ClutterKnot to the path * * Since: 0.2 @@ -494,9 +504,9 @@ clutter_behaviour_path_append_knot (ClutterBehaviourPath *pathb, /** * clutter_behaviour_path_insert_knot: * @pathb: a #ClutterBehvaiourPath - * @offset: position in path to insert knot. + * @offset: position in path to insert knot. * @knot: a #ClutterKnot to append. - * + * * Inserts a #ClutterKnot in the path at specified position. Values greater * than total number of knots will append the knot at the end of path. * @@ -520,7 +530,7 @@ clutter_behaviour_path_insert_knot (ClutterBehaviourPath *pathb, * clutter_behaviour_path_remove_knot: * @pathb: a #ClutterBehvaiourPath * @offset: position in path to remove knot. - * + * * Removes a #ClutterKnot in the path at specified offset. * * Since: 0.2 @@ -567,7 +577,7 @@ clutter_behaviour_path_append_knots_valist (ClutterBehaviourPath *pathb, * @Varargs: additional knots to add to the path * * Adds a NULL-terminated list of knots to a path. This function is - * equivalent to calling clutter_behaviour_path_append_knot() for each + * equivalent to calling clutter_behaviour_path_append_knot() for each * member of the list. * * Since: 0.2 @@ -590,7 +600,7 @@ clutter_behaviour_path_append_knots (ClutterBehaviourPath *pathb, /** * clutter_behaviour_path_clear: * @pathb: a #ClutterBehvaiourPath - * + * * Removes all knots from a path * * Since: 0.2 diff --git a/clutter/clutter-fixed.c b/clutter/clutter-fixed.c index 8ff63fb5a..1eaa313c6 100644 --- a/clutter/clutter-fixed.c +++ b/clutter/clutter-fixed.c @@ -608,7 +608,9 @@ clutter_sqrtx (ClutterFixed x) * * This function is about 10x faster than clib sqrt() on x86, and (this is * not a typo!) more than 800x faster on ARM without FPU. It's error is < 5% - * for arguments < 132 and < 10% for arguments < 5591. + * for arguments < #CLUTTER_SQRTI_ARG_5_PERCENT and < 10% for arguments < + * #CLUTTER_SQRTI_ARG_10_PERCENT. The maximum argument that can be passed to + * this function is CLUTTER_SQRTI_ARG_MAX. * * Return value: integer square root. * diff --git a/clutter/clutter-fixed.h b/clutter/clutter-fixed.h index 109a16b71..feac5d6a7 100644 --- a/clutter/clutter-fixed.h +++ b/clutter/clutter-fixed.h @@ -33,14 +33,14 @@ G_BEGIN_DECLS /** * ClutterFixed: - * + * * Fixed point number (16.16) */ typedef gint32 ClutterFixed; /** * ClutterAngle: - * + * * Integer representation of an angle such that 1024 corresponds to * full circle (i.e., 2*Pi). */ @@ -59,96 +59,96 @@ typedef gint32 ClutterAngle; /* angle such that 1024 == 2*PI */ /** * CFX_Q: - * + * * Size in bits of decimal part of floating point value. */ #define CFX_Q 16 /* Decimal part size in bits */ /** * CFX_ONE: - * + * * 1.0 represented as a fixed point value. */ #define CFX_ONE (1 << CFX_Q) /* 1 */ /** * CFX_HALF: - * + * * 0.5 represented as a fixed point value. */ #define CFX_HALF 32768 /** * CFX_MAX: - * + * * Maximum fixed point value. */ #define CFX_MAX 0x7fffffff /** * CFX_MIN: - * + * * Minimum fixed point value. */ #define CFX_MIN 0x80000000 /** * CFX_PI: - * + * * Fixed point representation of Pi */ #define CFX_PI 0x0003243f /** * CFX_2PI: - * + * * Fixed point representation of Pi*2 */ #define CFX_2PI 0x0006487f /** * CFX_PI_2: - * + * * Fixed point representation of Pi/2 */ #define CFX_PI_2 0x00019220 /* pi/2 */ /** * CFX_PI_4: - * + * * Fixed point representation of Pi/4 */ #define CFX_PI_4 0x0000c910 /* pi/4 */ /** * CFX_360: - * + * * Fixed point representation of the number 360 */ #define CFX_360 CLUTTER_INT_TO_FIXED (360) /** * CFX_240: - * + * * Fixed point representation of the number 240 */ #define CFX_240 CLUTTER_INT_TO_FIXED (240) /** * CFX_180: - * + * * Fixed point representation of the number 180 */ #define CFX_180 CLUTTER_INT_TO_FIXED (180) /** * CFX_120: - * + * * Fixed point representation of the number 120 */ #define CFX_120 CLUTTER_INT_TO_FIXED (120) /** * CFX_60: - * + * * Fixed point representation of the number 60 */ #define CFX_60 CLUTTER_INT_TO_FIXED (60) /** * CFX_255: - * + * * Fixed point representation of the number 255 */ #define CFX_255 CLUTTER_INT_TO_FIXED (255) @@ -156,7 +156,7 @@ typedef gint32 ClutterAngle; /* angle such that 1024 == 2*PI */ /** * CLUTTER_FIXED_TO_FLOAT: * @x: a fixed point value - * + * * Convert a fixed point value to float. */ #define CLUTTER_FIXED_TO_FLOAT(x) ((float) ((int)(x) / 65536.0)) @@ -164,7 +164,7 @@ typedef gint32 ClutterAngle; /* angle such that 1024 == 2*PI */ /** * CLUTTER_FIXED_TO_DOUBLE: * @x: a fixed point value - * + * * Convert a fixed point value to double. */ #define CLUTTER_FIXED_TO_DOUBLE(x) ((double) ((int)(x) / 65536.0)) @@ -172,7 +172,7 @@ typedef gint32 ClutterAngle; /* angle such that 1024 == 2*PI */ /** * CLUTTER_FLOAT_TO_FIXED: * @x: a floating point value - * + * * Convert a float value to fixed. */ #define CLUTTER_FLOAT_TO_FIXED(x) (_clutter_double_to_fixed ((x))) @@ -180,7 +180,7 @@ typedef gint32 ClutterAngle; /* angle such that 1024 == 2*PI */ /** * CLUTTER_FLOAT_TO_INT: * @x: a floating point value - * + * * Convert a float value to int. */ #define CLUTTER_FLOAT_TO_INT(x) (_clutter_double_to_int ((x))) @@ -188,7 +188,7 @@ typedef gint32 ClutterAngle; /* angle such that 1024 == 2*PI */ /** * CLUTTER_FLOAT_TO_UINT: * @x: a floating point value - * + * * Convert a float value to unsigned int. */ #define CLUTTER_FLOAT_TO_UINT(x) (_clutter_double_to_uint ((x))) @@ -196,7 +196,7 @@ typedef gint32 ClutterAngle; /* angle such that 1024 == 2*PI */ /** * CLUTTER_INT_TO_FIXED: * @x: an integer value - * + * * Convert an integer value to fixed point. */ #define CLUTTER_INT_TO_FIXED(x) ((x) << CFX_Q) @@ -216,7 +216,7 @@ typedef gint32 ClutterAngle; /* angle such that 1024 == 2*PI */ /** * CLUTTER_FIXED_INT: * @x: a fixed point value - * + * * Convert a fixed point value to integer (removing decimal part). * * Deprecated:0.6: Use %CLUTTER_FIXED_TO_INT instead @@ -228,7 +228,7 @@ typedef gint32 ClutterAngle; /* angle such that 1024 == 2*PI */ /** * CLUTTER_FIXED_FRACTION: * @x: a fixed point value - * + * * Retrieves the fractionary part of a fixed point value */ #define CLUTTER_FIXED_FRACTION(x) ((x) & ((1 << CFX_Q) - 1)) @@ -236,7 +236,7 @@ typedef gint32 ClutterAngle; /* angle such that 1024 == 2*PI */ /** * CLUTTER_FIXED_FLOOR: * @x: a fixed point value - * + * * Round down a fixed point value to an integer. */ #define CLUTTER_FIXED_FLOOR(x) (((x) >= 0) ? ((x) >> CFX_Q) \ @@ -244,7 +244,7 @@ typedef gint32 ClutterAngle; /* angle such that 1024 == 2*PI */ /** * CLUTTER_FIXED_CEIL: * @x: a fixed point value - * + * * Round up a fixed point value to an integer. */ #define CLUTTER_FIXED_CEIL(x) (CLUTTER_FIXED_FLOOR (x + 0xffff)) @@ -253,7 +253,7 @@ typedef gint32 ClutterAngle; /* angle such that 1024 == 2*PI */ * CLUTTER_FIXED_MUL: * @x: a fixed point value * @y: a fixed point value - * + * * Multiply two fixed point values */ #define CLUTTER_FIXED_MUL(x,y) ((x) >> 8) * ((y) >> 8) @@ -262,7 +262,7 @@ typedef gint32 ClutterAngle; /* angle such that 1024 == 2*PI */ * CLUTTER_FIXED_DIV: * @x: a fixed point value * @y: a fixed point value - * + * * Divide two fixed point values */ #define CLUTTER_FIXED_DIV(x,y) ((((x) << 8)/(y)) << 8) @@ -290,7 +290,7 @@ ClutterFixed clutter_tani (ClutterAngle angle); * @angle: a #ClutterFixed angle in radians * * Fixed point cosine function - * + * * Return value: #ClutterFixed cosine value. * * Note: Implemneted as a macro. @@ -307,7 +307,7 @@ ClutterFixed clutter_tani (ClutterAngle angle); * * ClutterAngle is an integer such that 1024 represents * full circle. - * + * * Return value: #ClutterFixed cosine value. * * Note: Implemneted as a macro. @@ -316,6 +316,47 @@ ClutterFixed clutter_tani (ClutterAngle angle); */ #define clutter_cosi(angle) (clutter_sini ((angle) + 256)) +/** + * CLUTTER_SQRTI_ARG_MAX + * + * Maximum argument that can be passed to #clutter_sqrti function. + * + * Since: 0.6 + */ +#ifndef __SSE2__ +#define CLUTTER_SQRTI_ARG_MAX 0x3fffff +#else +#define CLUTTER_SQRTI_ARG_MAX INT_MAX +#endif + +/** + * CLUTTER_SQRTI_ARG_5_PERCENT + * + * Maximum argument that can be passed to #clutter_sqrti for which the + * resulting error is < 5% + * + * Since: 0.6 + */ +#ifndef __SSE2__ +#define CLUTTER_SQRTI_ARG_5_PERCENT 131 +#else +#define CLUTTER_SQRTI_ARG_5_PERCENT INT_MAX +#endif + +/** + * CLUTTER_SQRTI_ARG_10_PERCENT + * + * Maximum argument that can be passed to #clutter_sqrti for which the + * resulting error is < 10% + * + * Since: 0.6 + */ +#ifndef __SSE2__ +#define CLUTTER_SQRTI_ARG_10_PERCENT 5590 +#else +#define CLUTTER_SQRTI_ARG_10_PERCENT INT_MAX +#endif + ClutterFixed clutter_sqrtx (ClutterFixed x); gint clutter_sqrti (gint x);