diff --git a/legacy/edje/data/include/edje.inc b/legacy/edje/data/include/edje.inc index 286dfebc81..9ee0cdeda7 100644 --- a/legacy/edje/data/include/edje.inc +++ b/legacy/edje/data/include/edje.inc @@ -213,7 +213,9 @@ enum State_Param STATE_PERSP_FOCAL = 42, STATE_PHYSICS_MASS = 43, STATE_PHYSICS_FRICTION = 44, - STATE_PHYSICS_RESTITUTION = 45 + STATE_PHYSICS_RESTITUTION = 45, + STATE_PHYSICS_DAMPING = 46, + STATE_PHYSICS_SLEEP = 47 }; native set_state_val(part_id, State_Param:p, ...); diff --git a/legacy/edje/src/bin/edje_cc_handlers.c b/legacy/edje/src/bin/edje_cc_handlers.c index 7fbe674ca1..edaa8c578f 100644 --- a/legacy/edje/src/bin/edje_cc_handlers.c +++ b/legacy/edje/src/bin/edje_cc_handlers.c @@ -313,6 +313,8 @@ static void st_collections_group_parts_part_description_table_min(void); static void st_collections_group_parts_part_description_physics_mass(void); static void st_collections_group_parts_part_description_physics_restitution(void); static void st_collections_group_parts_part_description_physics_friction(void); +static void st_collections_group_parts_part_description_physics_damping(void); +static void st_collections_group_parts_part_description_physics_sleep(void); static void st_collections_group_parts_part_description_physics_ignore_part_position(void); #endif static void st_collections_group_parts_part_description_map_perspective(void); @@ -599,6 +601,8 @@ New_Statement_Handler statement_handlers[] = {"collections.group.parts.part.description.physics.mass", st_collections_group_parts_part_description_physics_mass}, {"collections.group.parts.part.description.physics.restitution", st_collections_group_parts_part_description_physics_restitution}, {"collections.group.parts.part.description.physics.friction", st_collections_group_parts_part_description_physics_friction}, + {"collections.group.parts.part.description.physics.damping", st_collections_group_parts_part_description_physics_damping}, + {"collections.group.parts.part.description.physics.sleep", st_collections_group_parts_part_description_physics_sleep}, {"collections.group.parts.part.description.physics.ignore_part_position", st_collections_group_parts_part_description_physics_ignore_part_position}, #endif {"collections.group.parts.part.description.map.perspective", st_collections_group_parts_part_description_map_perspective}, @@ -1091,6 +1095,8 @@ _edje_part_description_alloc(unsigned char type, const char *collection, const c #ifdef HAVE_EPHYSICS result->physics.mass = FROM_DOUBLE(1.0); result->physics.friction = FROM_DOUBLE(0.5); + result->physics.sleep.linear = FROM_DOUBLE(24); + result->physics.sleep.angular = FROM_DOUBLE(57.29); result->physics.ignore_part_position = 1; #endif @@ -7183,6 +7189,8 @@ st_collections_group_parts_part_description_table_min(void) mass: 5.31; friction: 0.5; restitution: 0.82; + damping: 0.4 0.24; + sleep: 32 18.9; } .. } @@ -7298,6 +7306,65 @@ st_collections_group_parts_part_description_physics_ignore_part_position(void) } #endif +/** + @page edcref + @property + damping + @parameters + [linear damping] [angular damping] + @effect + Damping(linear and angular) values are applied to body's linear and + angular velocity. + By applying a bodies damping factor the user will face a velocity + reduction, with a force applied to it - "like" air resistance. + The force is applied to slow it down. + Values should be between 0.0 and 1.0, and are set to 0 by default. + @endproperty + @since 1.8.0 +*/ +#ifdef HAVE_EPHYSICS +static void +st_collections_group_parts_part_description_physics_damping(void) +{ + check_arg_count(2); + + current_desc->physics.damping.linear = parse_float_range(0, 0, 1.0); + current_desc->physics.damping.angular = parse_float_range(1, 0, 1.0); +} +#endif + +/** + @page edcref + @property + sleep + @parameters + [linear sleeping threshold] [angular sleeping threshold] + @effect + Sleeping threshold factors are used to determine whenever a rigid body + is supposed to increment the sleeping time. Linear threshold is + measured in Evas coordinates per second and angular threshold is + measured in degrees per second. + After every tick the sleeping time is incremented, if the body's + linear and angular speed is less than the respective thresholds + the sleeping time is incremented by the current time step (delta time). + Reaching the max sleeping time the body is marked to sleep, that means + the rigid body is to be deactivated. + By default linear threshold is 24 pixels / second and angular is + 57.29 degrees / sec (1 rad/sec). + @endproperty + @since 1.8.0 +*/ +#ifdef HAVE_EPHYSICS +static void +st_collections_group_parts_part_description_physics_sleep(void) +{ + check_arg_count(2); + + current_desc->physics.sleep.linear = parse_float(0); + current_desc->physics.sleep.angular = parse_float(1); +} +#endif + /** @edcsubsection{collections_group_parts_description_map,Map} */ diff --git a/legacy/edje/src/examples/physics_actions.edc b/legacy/edje/src/examples/physics_actions.edc index 54f1f4315c..cadb22ab96 100644 --- a/legacy/edje/src/examples/physics_actions.edc +++ b/legacy/edje/src/examples/physics_actions.edc @@ -456,12 +456,17 @@ collections { signal: "custom"; script { new Float: mass, Float:rest, Float:fric; + new Float: linear, Float:angular; custom_state(PART:"red_circle", "default", 0.0); set_state_val(PART:"red_circle", STATE_COLOR, 0, 0, 0, 255); set_state_val(PART:"red_circle", STATE_PHYSICS_MASS, 4.5); set_state_val(PART:"red_circle", STATE_PHYSICS_RESTITUTION, 0.1); set_state_val(PART:"red_circle", STATE_PHYSICS_FRICTION, 0.345); + set_state_val(PART:"red_circle", STATE_PHYSICS_DAMPING, 0.3, + 0.1); + set_state_val(PART:"red_circle", STATE_PHYSICS_SLEEP, 34.1, + 12.83); set_state(PART:"red_circle", "custom", 0.0); get_state_val(PART:"red_circle", STATE_PHYSICS_MASS, mass); @@ -472,6 +477,16 @@ collections { send_message(MSG_STRING_FLOAT_SET, 1, "Mass", mass); send_message(MSG_STRING_FLOAT_SET, 1, "Friction", fric); send_message(MSG_STRING_FLOAT_SET, 1, "Restitution", rest); + + get_state_val(PART:"red_circle", STATE_PHYSICS_DAMPING, + linear, angular); + send_message(MSG_STRING_FLOAT_SET, 1, "Damping", linear, + angular); + + get_state_val(PART:"red_circle", STATE_PHYSICS_SLEEP, + linear, angular); + send_message(MSG_STRING_FLOAT_SET, 1, "Sleep", linear, + angular); } } diff --git a/legacy/edje/src/examples/physics_complex.edc b/legacy/edje/src/examples/physics_complex.edc index ed7be9714c..db90d01041 100644 --- a/legacy/edje/src/examples/physics_complex.edc +++ b/legacy/edje/src/examples/physics_complex.edc @@ -43,6 +43,8 @@ collections { physics { mass: 30; restitution: 0; + damping: 0.4 0.2; + sleep: 18 13.4; } } } diff --git a/legacy/edje/src/lib/edje_calc.c b/legacy/edje/src/lib/edje_calc.c index bb18de9635..7a79f71cda 100644 --- a/legacy/edje/src/lib/edje_calc.c +++ b/legacy/edje/src/lib/edje_calc.c @@ -2293,6 +2293,10 @@ _edje_part_recalc_single(Edje *ed, params->physics.mass = desc->physics.mass; params->physics.restitution = desc->physics.restitution; params->physics.friction = desc->physics.friction; + params->physics.damping.linear = desc->physics.damping.linear; + params->physics.damping.angular = desc->physics.damping.angular; + params->physics.sleep.linear = desc->physics.sleep.linear; + params->physics.sleep.angular = desc->physics.sleep.angular; params->ignore_part_position = desc->physics.ignore_part_position; #endif _edje_part_recalc_single_map(ed, ep, center, light, persp, desc, chosen_desc, params); @@ -2466,6 +2470,10 @@ _edje_physics_body_props_update(Edje_Real_Part *ep, Edje_Calc_Params *pf, Eina_B ephysics_body_restitution_set(ep->body, pf->physics.restitution); ephysics_body_friction_set(ep->body, pf->physics.friction); + ephysics_body_damping_set(ep->body, pf->physics.damping.linear, + pf->physics.damping.angular); + ephysics_body_sleeping_threshold_set(ep->body, pf->physics.sleep.linear, + pf->physics.sleep.angular); } static void @@ -2917,6 +2925,17 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *sta pos)); p3->physics.friction = TO_DOUBLE(FINTP(p1->physics.friction, p2->physics.friction, pos)); + + p3->physics.damping.linear = TO_DOUBLE(FINTP( + p1->physics.damping.linear, p2->physics.damping.linear, pos)); + p3->physics.damping.angular = TO_DOUBLE(FINTP( + p1->physics.damping.angular, p2->physics.damping.angular, pos)); + + p3->physics.sleep.linear = TO_DOUBLE(FINTP( + p1->physics.sleep.linear, p2->physics.sleep.linear, pos)); + p3->physics.sleep.angular = TO_DOUBLE(FINTP( + p1->physics.sleep.angular, p2->physics.sleep.angular, pos)); + if ((p1->ignore_part_position) && (p2->ignore_part_position)) p3->ignore_part_position = 1; else diff --git a/legacy/edje/src/lib/edje_data.c b/legacy/edje/src/lib/edje_data.c index 62a718c51b..f34834b7cc 100644 --- a/legacy/edje/src/lib/edje_data.c +++ b/legacy/edje/src/lib/edje_data.c @@ -522,6 +522,10 @@ _edje_edd_init(void) EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.mass", physics.mass, EET_T_DOUBLE); \ EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.restitution", physics.restitution, EET_T_DOUBLE); \ EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.friction", physics.friction, EET_T_DOUBLE); \ + EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.damping.linear", physics.damping.linear, EET_T_DOUBLE); \ + EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.damping.angular", physics.damping.angular, EET_T_DOUBLE); \ + EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.sleep.linear", physics.sleep.linear, EET_T_DOUBLE); \ + EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.sleep.angular", physics.sleep.angular, EET_T_DOUBLE); \ EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.ignore_part_position", physics.ignore_part_position, EET_T_UCHAR); \ } #else @@ -590,6 +594,10 @@ _edje_edd_init(void) EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.mass", Dec.physics.mass, EET_T_DOUBLE); \ EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.restitution", Dec.physics.restitution, EET_T_DOUBLE); \ EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.friction", Dec.physics.friction, EET_T_DOUBLE); \ + EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.damping.linear", Dec.physics.damping.linear, EET_T_DOUBLE); \ + EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.damping.angular", Dec.physics.damping.angular, EET_T_DOUBLE); \ + EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.sleep.linear", Dec.physics.sleep.linear, EET_T_DOUBLE); \ + EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.sleep.angular", Dec.physics.sleep.angular, EET_T_DOUBLE); \ EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.ignore_part_position", Dec.physics.ignore_part_position, EET_T_UCHAR); \ } #else diff --git a/legacy/edje/src/lib/edje_embryo.c b/legacy/edje/src/lib/edje_embryo.c index 1ea31abefa..7e90e78baf 100644 --- a/legacy/edje/src/lib/edje_embryo.c +++ b/legacy/edje/src/lib/edje_embryo.c @@ -2276,6 +2276,21 @@ _edje_embryo_fn_set_state_val(Embryo_Program *ep, Embryo_Cell *params) GETFLOAT_T(rp->custom->description->physics.friction, params[3]); + break; + case EDJE_STATE_PARAM_PHYSICS_DAMPING: + CHKPARAM(4); + + GETFLOAT_T(rp->custom->description->physics.damping.linear, params[3]); + GETFLOAT_T(rp->custom->description->physics.damping.angular, + params[4]); + + break; + case EDJE_STATE_PARAM_PHYSICS_SLEEP: + CHKPARAM(4); + + GETFLOAT_T(rp->custom->description->physics.sleep.linear, params[3]); + GETFLOAT_T(rp->custom->description->physics.sleep.angular, params[4]); + break; #endif default: @@ -2745,6 +2760,21 @@ _edje_embryo_fn_get_state_val(Embryo_Program *ep, Embryo_Cell *params) SETFLOAT_T(rp->custom->description->physics.friction, params[3]); + break; + case EDJE_STATE_PARAM_PHYSICS_DAMPING: + CHKPARAM(4); + + SETFLOAT_T(rp->custom->description->physics.damping.linear, params[3]); + SETFLOAT_T(rp->custom->description->physics.damping.angular, + params[4]); + + break; + case EDJE_STATE_PARAM_PHYSICS_SLEEP: + CHKPARAM(4); + + SETFLOAT_T(rp->custom->description->physics.sleep.linear, params[3]); + SETFLOAT_T(rp->custom->description->physics.sleep.angular, params[4]); + break; #endif default: diff --git a/legacy/edje/src/lib/edje_private.h b/legacy/edje/src/lib/edje_private.h index 245fe09eb4..7587b0715b 100644 --- a/legacy/edje/src/lib/edje_private.h +++ b/legacy/edje/src/lib/edje_private.h @@ -417,7 +417,9 @@ typedef struct _Edje_Markup_Filter_Callback Edje_Markup_Filter_Callback; #define EDJE_STATE_PARAM_PHYSICS_MASS 43 #define EDJE_STATE_PARAM_PHYSICS_FRICTION 44 #define EDJE_STATE_PARAM_PHYSICS_RESTITUTION 45 -#define EDJE_STATE_PARAM_LAST 46 +#define EDJE_STATE_PARAM_PHYSICS_DAMPING 46 +#define EDJE_STATE_PARAM_PHYSICS_SLEEP 47 +#define EDJE_STATE_PARAM_LAST 48 #define EDJE_ENTRY_EDIT_MODE_NONE 0 #define EDJE_ENTRY_EDIT_MODE_SELECTABLE 1 @@ -973,6 +975,14 @@ struct _Edje_Part_Description_Common double mass; double restitution; double friction; + struct { + double linear; + double angular; + } damping; + struct { + double linear; + double angular; + } sleep; unsigned char ignore_part_position; } physics; #endif @@ -1310,7 +1320,15 @@ struct _Edje_Calc_Params double mass; // 8 double restitution; // 8 double friction; // 8 - } physics; // 24 + struct { + double linear; //8 + double angular; //8 + } damping; // 16 + struct { + double linear; //8 + double angular; //8 + } sleep; // 16 + } physics; // 56 unsigned char ignore_part_position : 1; #endif unsigned char persp_on : 1;