[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25217] trunk/blender/source/blender: RNA:

Brecht Van Lommel brecht at blender.org
Tue Dec 8 18:23:50 CET 2009


Revision: 25217
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25217
Author:   blendix
Date:     2009-12-08 18:23:48 +0100 (Tue, 08 Dec 2009)

Log Message:
-----------
RNA:

* Property update functions no longer get context, instead they get only
  Main and Scene. The RNA api was intended to be as context-less as
  possible, since it doesn't really matter who is changing the property,
  everything that uses the property should be updated.
* There's still one exception case that use it now, screen operations
  still depend on context too much. It also revealed a few places using
  context where they shouldn't.
* Ideally Scene shouldn't be passed, but much of Blender still depends on
  it, should be dropped when we try to support multiple scene editing.

Change was planned for a while, but need this now to be able to call
update without a context pointer.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/ED_screen.h
    trunk/blender/source/blender/editors/screen/screen_edit.c
    trunk/blender/source/blender/editors/screen/screen_ops.c
    trunk/blender/source/blender/makesrna/RNA_access.h
    trunk/blender/source/blender/makesrna/RNA_types.h
    trunk/blender/source/blender/makesrna/intern/makesrna.c
    trunk/blender/source/blender/makesrna/intern/rna_access.c
    trunk/blender/source/blender/makesrna/intern/rna_armature.c
    trunk/blender/source/blender/makesrna/intern/rna_boid.c
    trunk/blender/source/blender/makesrna/intern/rna_brush.c
    trunk/blender/source/blender/makesrna/intern/rna_camera.c
    trunk/blender/source/blender/makesrna/intern/rna_cloth.c
    trunk/blender/source/blender/makesrna/intern/rna_constraint.c
    trunk/blender/source/blender/makesrna/intern/rna_curve.c
    trunk/blender/source/blender/makesrna/intern/rna_fcurve.c
    trunk/blender/source/blender/makesrna/intern/rna_fluidsim.c
    trunk/blender/source/blender/makesrna/intern/rna_group.c
    trunk/blender/source/blender/makesrna/intern/rna_image.c
    trunk/blender/source/blender/makesrna/intern/rna_internal.h
    trunk/blender/source/blender/makesrna/intern/rna_internal_types.h
    trunk/blender/source/blender/makesrna/intern/rna_key.c
    trunk/blender/source/blender/makesrna/intern/rna_lamp.c
    trunk/blender/source/blender/makesrna/intern/rna_lattice.c
    trunk/blender/source/blender/makesrna/intern/rna_main_api.c
    trunk/blender/source/blender/makesrna/intern/rna_material.c
    trunk/blender/source/blender/makesrna/intern/rna_mesh.c
    trunk/blender/source/blender/makesrna/intern/rna_meta.c
    trunk/blender/source/blender/makesrna/intern/rna_modifier.c
    trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
    trunk/blender/source/blender/makesrna/intern/rna_object.c
    trunk/blender/source/blender/makesrna/intern/rna_object_force.c
    trunk/blender/source/blender/makesrna/intern/rna_particle.c
    trunk/blender/source/blender/makesrna/intern/rna_pose.c
    trunk/blender/source/blender/makesrna/intern/rna_scene.c
    trunk/blender/source/blender/makesrna/intern/rna_scene_api.c
    trunk/blender/source/blender/makesrna/intern/rna_screen.c
    trunk/blender/source/blender/makesrna/intern/rna_sculpt_paint.c
    trunk/blender/source/blender/makesrna/intern/rna_sequence.c
    trunk/blender/source/blender/makesrna/intern/rna_smoke.c
    trunk/blender/source/blender/makesrna/intern/rna_sound.c
    trunk/blender/source/blender/makesrna/intern/rna_space.c
    trunk/blender/source/blender/makesrna/intern/rna_texture.c
    trunk/blender/source/blender/makesrna/intern/rna_ui.c
    trunk/blender/source/blender/makesrna/intern/rna_userdef.c
    trunk/blender/source/blender/makesrna/intern/rna_wm.c
    trunk/blender/source/blender/makesrna/intern/rna_world.c
    trunk/blender/source/blender/windowmanager/WM_api.h
    trunk/blender/source/blender/windowmanager/intern/wm.c
    trunk/blender/source/blender/windowmanager/intern/wm_files.c

Modified: trunk/blender/source/blender/editors/include/ED_screen.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_screen.h	2009-12-08 17:00:53 UTC (rev 25216)
+++ trunk/blender/source/blender/editors/include/ED_screen.h	2009-12-08 17:23:48 UTC (rev 25217)
@@ -98,7 +98,7 @@
 void	ED_screen_set_subwinactive(struct wmWindow *win, struct wmEvent *event);
 void	ED_screen_exit(struct bContext *C, struct wmWindow *window, struct bScreen *screen);
 void	ED_screen_animation_timer(struct bContext *C, int redraws, int sync, int enable);
-void	ED_screen_animation_timer_update(struct bContext *C, int redraws);
+void	ED_screen_animation_timer_update(struct bScreen *screen, int redraws);
 int		ED_screen_full_newspace(struct bContext *C, ScrArea *sa, int type);
 void	ED_screen_full_prevspace(struct bContext *C, ScrArea *sa);
 void	ED_screen_full_restore(struct bContext *C, ScrArea *sa);

Modified: trunk/blender/source/blender/editors/screen/screen_edit.c
===================================================================
--- trunk/blender/source/blender/editors/screen/screen_edit.c	2009-12-08 17:00:53 UTC (rev 25216)
+++ trunk/blender/source/blender/editors/screen/screen_edit.c	2009-12-08 17:23:48 UTC (rev 25217)
@@ -1632,10 +1632,8 @@
 	return aret;
 }
 
-void ED_screen_animation_timer_update(bContext *C, int redraws)
+void ED_screen_animation_timer_update(bScreen *screen, int redraws)
 {
-	bScreen *screen= CTX_wm_screen(C);
-	
 	if(screen && screen->animtimer) {
 		wmTimer *wt= screen->animtimer;
 		ScreenAnimData *sad= wt->customdata;

Modified: trunk/blender/source/blender/editors/screen/screen_ops.c
===================================================================
--- trunk/blender/source/blender/editors/screen/screen_ops.c	2009-12-08 17:00:53 UTC (rev 25216)
+++ trunk/blender/source/blender/editors/screen/screen_ops.c	2009-12-08 17:23:48 UTC (rev 25217)
@@ -2418,7 +2418,7 @@
 			ED_screen_animation_timer(C, stime->redraws, sync, mode);
 			
 			/* update region if TIME_REGION was set, to leftmost 3d window */
-			ED_screen_animation_timer_update(C, stime->redraws);
+			ED_screen_animation_timer_update(screen, stime->redraws);
 		}
 		else {
 			int redraws = TIME_REGION|TIME_ALL_3D_WIN;

Modified: trunk/blender/source/blender/makesrna/RNA_access.h
===================================================================
--- trunk/blender/source/blender/makesrna/RNA_access.h	2009-12-08 17:00:53 UTC (rev 25216)
+++ trunk/blender/source/blender/makesrna/RNA_access.h	2009-12-08 17:23:48 UTC (rev 25217)
@@ -38,6 +38,7 @@
 struct ID;
 struct Main;
 struct ReportList;
+struct Scene;
 
 /* Types */
 
@@ -649,6 +650,7 @@
 int RNA_property_animated(PointerRNA *ptr, PropertyRNA *prop);
 
 void RNA_property_update(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop);
+void RNA_property_update_main(struct Main *bmain, struct Scene *scene, PointerRNA *ptr, PropertyRNA *prop);
 
 /* Property Data */
 

Modified: trunk/blender/source/blender/makesrna/RNA_types.h
===================================================================
--- trunk/blender/source/blender/makesrna/RNA_types.h	2009-12-08 17:00:53 UTC (rev 25216)
+++ trunk/blender/source/blender/makesrna/RNA_types.h	2009-12-08 17:23:48 UTC (rev 25217)
@@ -166,6 +166,9 @@
 	/* flag contains multiple enums */
 	PROP_ENUM_FLAG = 1<<21,
 
+	/* need context for update function */
+	PROP_CONTEXT_UPDATE = 1<<22,
+
 	/* internal flags */
 	PROP_BUILTIN = 1<<7,
 	PROP_EXPORT = 1<<8,

Modified: trunk/blender/source/blender/makesrna/intern/makesrna.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/makesrna.c	2009-12-08 17:00:53 UTC (rev 25216)
+++ trunk/blender/source/blender/makesrna/intern/makesrna.c	2009-12-08 17:23:48 UTC (rev 25217)
@@ -1763,7 +1763,7 @@
 	rna_print_c_string(f, prop->description); fprintf(f, ",\n\t");
 	fprintf(f, "%d,\n", prop->icon);
 	fprintf(f, "\t%s, %s|%s, %s, %d, {%d, %d, %d}, %d,\n", rna_property_typename(prop->type), rna_property_subtypename(prop->subtype), rna_property_subtype_unit(prop->subtype), rna_function_string(prop->getlength), prop->arraydimension, prop->arraylength[0], prop->arraylength[1], prop->arraylength[2], prop->totarraylength);
-	fprintf(f, "\t%s, %d, %s, %s,\n", rna_function_string(prop->update), prop->noteflag, rna_function_string(prop->editable), rna_function_string(prop->itemeditable));
+	fprintf(f, "\t%s%s, %d, %s, %s,\n", (prop->flag & PROP_CONTEXT_UPDATE)? "(UpdateFunc)": "", rna_function_string(prop->update), prop->noteflag, rna_function_string(prop->editable), rna_function_string(prop->itemeditable));
 
 	if(prop->flag & PROP_RAW_ACCESS) rna_set_raw_offset(f, srna, prop);
 	else fprintf(f, "\t0, 0");
@@ -2050,11 +2050,13 @@
 	fprintf(f, "#include <stddef.h>\n\n");
 
 	fprintf(f, "#include \"DNA_ID.h\"\n");
+	fprintf(f, "#include \"DNA_scene_types.h\"\n");
 
 	fprintf(f, "#include \"BLI_blenlib.h\"\n\n");
 
 	fprintf(f, "#include \"BKE_context.h\"\n");
 	fprintf(f, "#include \"BKE_library.h\"\n");
+	fprintf(f, "#include \"BKE_main.h\"\n");
 	fprintf(f, "#include \"BKE_report.h\"\n");
 	fprintf(f, "#include \"BKE_utildefines.h\"\n\n");
 

Modified: trunk/blender/source/blender/makesrna/intern/rna_access.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_access.c	2009-12-08 17:00:53 UTC (rev 25216)
+++ trunk/blender/source/blender/makesrna/intern/rna_access.c	2009-12-08 17:23:48 UTC (rev 25217)
@@ -29,6 +29,7 @@
 #include "MEM_guardedalloc.h"
 
 #include "DNA_ID.h"
+#include "DNA_scene_types.h"
 #include "DNA_windowmanager_types.h"
 
 #include "BLI_blenlib.h"
@@ -37,6 +38,7 @@
 
 #include "BKE_context.h"
 #include "BKE_idprop.h"
+#include "BKE_main.h"
 #include "BKE_report.h"
 #include "BKE_utildefines.h"
 
@@ -1103,25 +1105,43 @@
 	return 0;
 }
 
-void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
+static void rna_property_update(bContext *C, Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop)
 {
 	int is_rna = (prop->magic == RNA_MAGIC);
 	prop= rna_ensure_property(prop);
 
 	if(is_rna) {
-		if(prop->update)
-			prop->update(C, ptr);
+		if(prop->update) {
+			/* ideally no context would be needed for update, but there's some
+			   parts of the code that need it still, so we have this exception */
+			if(prop->flag & PROP_CONTEXT_UPDATE) {
+				if(C) ((ContextUpdateFunc)prop->update)(C, ptr);
+			}
+			else
+				prop->update(bmain, scene, ptr);
+		}
 		if(prop->noteflag)
-			WM_event_add_notifier(C, prop->noteflag, ptr->id.data);
+			WM_main_add_notifier(prop->noteflag, ptr->id.data);
 	}
 	else {
 		/* WARNING! This is so property drivers update the display!
 		 * not especially nice  */
 		DAG_id_flush_update(ptr->id.data, OB_RECALC_OB);
-		WM_event_add_notifier(C, NC_WINDOW, NULL);
+		WM_main_add_notifier(NC_WINDOW, NULL);
 	}
+
 }
 
+void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
+{
+	rna_property_update(C, CTX_data_main(C), CTX_data_scene(C), ptr, prop);
+}
+
+void RNA_property_update_main(Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop)
+{
+	rna_property_update(NULL, bmain, scene, ptr, prop);
+}
+
 /* Property Data */
 
 int RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)

Modified: trunk/blender/source/blender/makesrna/intern/rna_armature.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_armature.c	2009-12-08 17:00:53 UTC (rev 25216)
+++ trunk/blender/source/blender/makesrna/intern/rna_armature.c	2009-12-08 17:23:48 UTC (rev 25217)
@@ -47,13 +47,13 @@
 
 #include "ED_armature.h"
 
-static void rna_Armature_update_data(bContext *C, PointerRNA *ptr)
+static void rna_Armature_update_data(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
 	ID *id= ptr->id.data;
 
 	DAG_id_flush_update(id, OB_RECALC_DATA);
-	WM_event_add_notifier(C, NC_GEOM|ND_DATA, id);
-	//WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
+	WM_main_add_notifier(NC_GEOM|ND_DATA, id);
+	//WM_main_add_notifier(NC_OBJECT|ND_POSE, NULL);
 }
 
 
@@ -103,11 +103,11 @@
 	ED_armature_edit_bone_remove(arm, ebone);
 }
 
-static void rna_Armature_redraw_data(bContext *C, PointerRNA *ptr)
+static void rna_Armature_redraw_data(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
 	ID *id= ptr->id.data;
 
-	WM_event_add_notifier(C, NC_GEOM|ND_DATA, id);
+	WM_main_add_notifier(NC_GEOM|ND_DATA, id);
 }
 
 static char *rna_Bone_path(PointerRNA *ptr)
@@ -304,7 +304,7 @@
 	}
 }
 
-static void rna_Armature_editbone_transform_update(bContext *C, PointerRNA *ptr)
+static void rna_Armature_editbone_transform_update(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
 	bArmature *arm= (bArmature*)ptr->id.data;
 	EditBone *ebone= (EditBone*)ptr->data;
@@ -339,7 +339,7 @@
 		}
 	}
 
-	rna_Armature_update_data(C, ptr);
+	rna_Armature_update_data(bmain, scene, ptr);
 }
 
 static void rna_Armature_bones_next(CollectionPropertyIterator *iter)

Modified: trunk/blender/source/blender/makesrna/intern/rna_boid.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_boid.c	2009-12-08 17:00:53 UTC (rev 25216)
+++ trunk/blender/source/blender/makesrna/intern/rna_boid.c	2009-12-08 17:23:48 UTC (rev 25217)
@@ -72,7 +72,7 @@
 #include "BKE_depsgraph.h"
 #include "BKE_particle.h"
 
-static void rna_Boids_reset(bContext *C, PointerRNA *ptr)
+static void rna_Boids_reset(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
 	if(ptr->type==&RNA_ParticleSystem) {
 		ParticleSystem *psys = (ParticleSystem*)ptr->data;
@@ -84,12 +84,10 @@
 	else
 		DAG_id_flush_update(ptr->id.data, OB_RECALC_DATA|PSYS_RECALC_RESET);
 
-	WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE_DATA, NULL);
+	WM_main_add_notifier(NC_OBJECT|ND_PARTICLE_DATA, NULL);
 }
-static void rna_Boids_reset_deps(bContext *C, PointerRNA *ptr)
+static void rna_Boids_reset_deps(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
-	Scene *scene = CTX_data_scene(C);
-
 	if(ptr->type==&RNA_ParticleSystem) {
 		ParticleSystem *psys = (ParticleSystem*)ptr->data;
 		
@@ -102,7 +100,7 @@
 
 	DAG_scene_sort(scene);
 
-	WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE_DATA, NULL);
+	WM_main_add_notifier(NC_OBJECT|ND_PARTICLE_DATA, NULL);
 }
 
 static StructRNA* rna_BoidRule_refine(struct PointerRNA *ptr)


@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list