Changeset View
Standalone View
source/blender/makesrna/intern/rna_action.c
| Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | static FCurve *rna_Action_fcurve_new(bAction *act, ReportList *reports, const char *data_path, | ||||
| if (verify_fcurve(act, group, NULL, data_path, index, 0)) { | if (verify_fcurve(act, group, NULL, data_path, index, 0)) { | ||||
| BKE_reportf(reports, RPT_ERROR, "F-Curve '%s[%d]' already exists in action '%s'", data_path, | BKE_reportf(reports, RPT_ERROR, "F-Curve '%s[%d]' already exists in action '%s'", data_path, | ||||
| index, act->id.name + 2); | index, act->id.name + 2); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| return verify_fcurve(act, group, NULL, data_path, index, 1); | return verify_fcurve(act, group, NULL, data_path, index, 1); | ||||
| } | } | ||||
| static FCurve *rna_Action_fcurve_find(bAction *act, ReportList *reports, const char *data_path, int index) | |||||
| { | |||||
| if (data_path[0] == '\0') { | |||||
| BKE_report(reports, RPT_ERROR, "F-Curve data path empty, invalid argument"); | |||||
| return NULL; | |||||
| } | |||||
| /* Returns NULL if not found. */ | |||||
aligorith: Use c-style comment here | |||||
| return list_find_fcurve(&act->curves, data_path, index); | |||||
Done Inline ActionsSince you're not directly adding a FCurve, it may be better to just use list_find_fcurve directly (in the same way that verify_fcurve does now). aligorith: Since you're not directly adding a FCurve, it may be better to just use list_find_fcurve… | |||||
Not Done Inline ActionsAnother useful thing you could consider doing is to restrict the search to a FCurve from a particular group instead. You'd want the group name operator to be optional - if not provided, it uses the action's full set of fcurves as you're doing now. Then this code becomes something like: bActionGroup *agrp = BKE_action_group_find_name(act, groupname);
if (agrp) {
return list_find_fcurve(&agrp->channels, data_path, index);
}
else {
return list_find_fcurve(&act->curves, data_path, index);
}aligorith: Another useful thing you could consider doing is to restrict the search to a FCurve from a… | |||||
Not Done Inline ActionsUnfortunately, this doesn't work (I just tried). agrp->channels points to the first channel in the group. However, list_find_fcurve will keep iterating until it finds NULL, which is the last channel in the action. This means that such a search would only limit itself to the channels in the group and all subsequent channels. Fixing this would require keeping track of the last channel in the group as well, and limiting the search to that too. However, that seems like excessive work just to get this to work. sybren: Unfortunately, this doesn't work (I just tried). `agrp->channels` points to the first channel… | |||||
Not Done Inline ActionsOops... indeed, forgot about that issue. Ok, it's still fine without that extra filtering option :) aligorith: Oops... indeed, forgot about that issue. Ok, it's still fine without that extra filtering… | |||||
| } | |||||
| static void rna_Action_fcurve_remove(bAction *act, ReportList *reports, PointerRNA *fcu_ptr) | static void rna_Action_fcurve_remove(bAction *act, ReportList *reports, PointerRNA *fcu_ptr) | ||||
| { | { | ||||
| FCurve *fcu = fcu_ptr->data; | FCurve *fcu = fcu_ptr->data; | ||||
| if (fcu->grp) { | if (fcu->grp) { | ||||
| if (BLI_findindex(&act->groups, fcu->grp) == -1) { | if (BLI_findindex(&act->groups, fcu->grp) == -1) { | ||||
| BKE_reportf(reports, RPT_ERROR, "F-Curve's action group '%s' not found in action '%s'", | BKE_reportf(reports, RPT_ERROR, "F-Curve's action group '%s' not found in action '%s'", | ||||
| fcu->grp->name, act->id.name + 2); | fcu->grp->name, act->id.name + 2); | ||||
| return; | return; | ||||
| ▲ Show 20 Lines • Show All 441 Lines • ▼ Show 20 Lines | static void rna_def_action_fcurves(BlenderRNA *brna, PropertyRNA *cprop) | ||||
| FunctionRNA *func; | FunctionRNA *func; | ||||
| PropertyRNA *parm; | PropertyRNA *parm; | ||||
| RNA_def_property_srna(cprop, "ActionFCurves"); | RNA_def_property_srna(cprop, "ActionFCurves"); | ||||
| srna = RNA_def_struct(brna, "ActionFCurves", NULL); | srna = RNA_def_struct(brna, "ActionFCurves", NULL); | ||||
| RNA_def_struct_sdna(srna, "bAction"); | RNA_def_struct_sdna(srna, "bAction"); | ||||
| RNA_def_struct_ui_text(srna, "Action F-Curves", "Collection of action F-Curves"); | RNA_def_struct_ui_text(srna, "Action F-Curves", "Collection of action F-Curves"); | ||||
| /* Action.fcurves.new(...) */ | |||||
| func = RNA_def_function(srna, "new", "rna_Action_fcurve_new"); | func = RNA_def_function(srna, "new", "rna_Action_fcurve_new"); | ||||
| RNA_def_function_ui_description(func, "Add an F-Curve to the action"); | RNA_def_function_ui_description(func, "Add an F-Curve to the action"); | ||||
| RNA_def_function_flag(func, FUNC_USE_REPORTS); | RNA_def_function_flag(func, FUNC_USE_REPORTS); | ||||
| parm = RNA_def_string(func, "data_path", NULL, 0, "Data Path", "F-Curve data path to use"); | parm = RNA_def_string(func, "data_path", NULL, 0, "Data Path", "F-Curve data path to use"); | ||||
| RNA_def_property_flag(parm, PROP_REQUIRED); | RNA_def_property_flag(parm, PROP_REQUIRED); | ||||
| RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "Array index", 0, INT_MAX); | RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "Array index", 0, INT_MAX); | ||||
| RNA_def_string(func, "action_group", NULL, 0, "Action Group", "Acton group to add this F-Curve into"); | RNA_def_string(func, "action_group", NULL, 0, "Action Group", "Acton group to add this F-Curve into"); | ||||
| parm = RNA_def_pointer(func, "fcurve", "FCurve", "", "Newly created F-Curve"); | parm = RNA_def_pointer(func, "fcurve", "FCurve", "", "Newly created F-Curve"); | ||||
| RNA_def_function_return(func, parm); | RNA_def_function_return(func, parm); | ||||
| /* Action.fcurves.find(...) */ | |||||
| func = RNA_def_function(srna, "find", "rna_Action_fcurve_find"); | |||||
| RNA_def_function_ui_description(func, "Find an F-Curve. Note that this function performs a linear scan " | |||||
Not Done Inline ActionsI can see why adding this hint would be nice to have. However, since these same methods are used everywhere anyway (i.e. via the UI, etc.) I think everyone should have a fair idea of what the general performance is like. aligorith: I can see why adding this hint would be nice to have. However, since these same methods are… | |||||
Not Done Inline ActionsI agree that everybody should know that; however, for people that aren't intimitely familiar with Blender's structure, it might be a bit of a surprise that such a lookup is O(n) and not O(log n) or even O(1). sybren: I agree that everybody should know that; however, for people that aren't intimitely familiar… | |||||
| "of all F-Curves in the action."); | |||||
| RNA_def_function_flag(func, FUNC_USE_REPORTS); | |||||
| parm = RNA_def_string(func, "data_path", NULL, 0, "Data Path", "F-Curve data path"); | |||||
| RNA_def_property_flag(parm, PROP_REQUIRED); | |||||
| RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "Array index", 0, INT_MAX); | |||||
| parm = RNA_def_pointer(func, "fcurve", "FCurve", "", "The found F-Curve, or None if it doesn't exist"); | |||||
| RNA_def_function_return(func, parm); | |||||
| /* Action.fcurves.remove(...) */ | |||||
| func = RNA_def_function(srna, "remove", "rna_Action_fcurve_remove"); | func = RNA_def_function(srna, "remove", "rna_Action_fcurve_remove"); | ||||
| RNA_def_function_ui_description(func, "Remove action group"); | RNA_def_function_ui_description(func, "Remove action group"); | ||||
| RNA_def_function_flag(func, FUNC_USE_REPORTS); | RNA_def_function_flag(func, FUNC_USE_REPORTS); | ||||
| parm = RNA_def_pointer(func, "fcurve", "FCurve", "", "F-Curve to remove"); | parm = RNA_def_pointer(func, "fcurve", "FCurve", "", "F-Curve to remove"); | ||||
| RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); | RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); | ||||
| RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); | RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines | |||||
Use c-style comment here