synched with trunk at revision 30243
authorNick Samarin <nicks1987@bigmir.net>
Wed, 14 Jul 2010 07:35:39 +0000 (07:35 +0000)
committerNick Samarin <nicks1987@bigmir.net>
Wed, 14 Jul 2010 07:35:39 +0000 (07:35 +0000)
27 files changed:
1  2 
release/scripts/ui/properties_data_modifier.py
release/scripts/ui/properties_game.py
release/scripts/ui/properties_scene.py
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/sca.c
source/blender/blenkernel/intern/scene.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/editors/include/ED_object.h
source/blender/editors/object/object_intern.h
source/blender/editors/object/object_ops.c
source/blender/editors/space_logic/logic_window.c
source/blender/makesdna/DNA_modifier_types.h
source/blender/makesdna/DNA_object_types.h
source/blender/makesdna/DNA_scene_types.h
source/blender/makesrna/intern/rna_actuator.c
source/blender/makesrna/intern/rna_modifier.c
source/blender/makesrna/intern/rna_object.c
source/blender/makesrna/intern/rna_scene.c
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/GameLogic/SCA_IActuator.h
source/gameengine/Ketsji/KX_GameObject.cpp
source/gameengine/Ketsji/KX_PythonInit.cpp
source/gameengine/Ketsji/KX_Scene.cpp
source/gameengine/Ketsji/KX_Scene.h
source/gameengine/Rasterizer/RAS_IRasterizer.h
source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h

@@@ -452,75 -452,14 +452,75 @@@ class DATA_PT_modifiers(DataButtonsPane
          col = layout.column()
          row = col.row()
          if md.external:
-             row.operator("object.multires_pack_external", text="Pack External")
+             row.operator("object.multires_external_pack", text="Pack External")
              row.label()
              row = col.row()
-             row.prop(md, "filename", text="")
+             row.prop(md, "filepath", text="")
          else:
-             row.operator("object.multires_save_external", text="Save External...")
+             row.operator("object.multires_external_save", text="Save External...")
              row.label()
  
 +    def NAVMESH(self, layout, ob, md, wide_ui):
 +        layout.label(text="Rasterization:")
 +        split = layout.split()
 +
 +        col = split.column()
 +        col.prop(md, "cellsize")
 +        if wide_ui:
 +            col = split.column()
 +        col.prop(md, "cellheight")
 +
 +        layout.separator()
 +
 +        layout.label(text="Agent:")
 +        split = layout.split()
 +        col = split.column()
 +        row = col.row()
 +        row.prop(md, "agentheight")
 +        row = col.row()
 +        row.prop(md, "agentradius")
 +        if wide_ui:
 +            col = split.column()
 +        row = col.row()
 +        row.prop(md, "agentmaxslope")
 +        row = col.row()
 +        row.prop(md, "agentmaxclimb")
 +
 +        layout.separator()
 +
 +        layout.label(text="Region:")
 +        split = layout.split()
 +        col = split.column()
 +        col.prop(md, "regionminsize")
 +        if wide_ui:
 +            col = split.column()
 +        col.prop(md, "regionmergesize")
 +
 +        layout.separator()
 +
 +        layout.label(text="Polygonization:")
 +        split = layout.split()
 +        col = split.column()
 +        row = col.row()
 +        row.prop(md, "edgemaxlen")
 +        row = col.row()
 +        row.prop(md, "edgemaxerror")
 +        if wide_ui:
 +            col = split.column()
 +        row = col.row()
 +        row.prop(md, "vertsperpoly")
 +
 +        layout.separator()
 +
 +        layout.label(text="Detail Mesh:")
 +        split = layout.split()
 +        col = split.column()
 +        col.prop(md, "detailsampledist")
 +        if wide_ui:
 +            col = split.column()
 +        col.prop(md, "detailsamplemaxerror")
 +
 +
      def PARTICLE_INSTANCE(self, layout, ob, md, wide_ui):
          layout.prop(md, "object")
          layout.prop(md, "particle_system_number", text="Particle System")
  
          layout.separator()
  
-         layout.prop(md, "path", text="Create Along Paths")
+         layout.prop(md, "use_path", text="Create Along Paths")
  
          split = layout.split()
-         split.active = md.path
+         split.active = md.use_path
          col = split.column()
          col.row().prop(md, "axis", expand=True)
          col.prop(md, "keep_shape")
          colsub.active = (md.vertex_group is not "")
          colsub.prop(md, "invert", text="Invert")
  
-         if wide_ui:
-             col.label(text="")
-         col.prop(md, "use_rim")
          col.prop(md, "use_even_offset")
          col.prop(md, "use_quality_normals")
  
+         col.prop(md, "use_rim")
+         colsub = col.column()
+         colsub.active = md.use_rim
+         colsub.prop(md, "use_rim_material")
          # col = layout.column()
          # col.label(text="Vertex Group:")
          # col.prop_object(md, "vertex_group", ob, "vertex_groups", text="")
@@@ -30,11 -30,12 +30,12 @@@ class PhysicsButtonsPanel(bpy.types.Pan
      def poll(self, context):
          ob = context.active_object
          rd = context.scene.render
-         return ob and ob.game and (rd.engine == 'BLENDER_GAME')
+         return ob and ob.game and (rd.engine in self.COMPAT_ENGINES)
  
  
  class PHYSICS_PT_game_physics(PhysicsButtonsPanel):
      bl_label = "Physics"
+     COMPAT_ENGINES = {'BLENDER_GAME'}
  
      def draw(self, context):
          layout = self.layout
  
  class PHYSICS_PT_game_collision_bounds(PhysicsButtonsPanel):
      bl_label = "Collision Bounds"
+     COMPAT_ENGINES = {'BLENDER_GAME'}
  
      def poll(self, context):
          game = context.object.game
          rd = context.scene.render
-         return (game.physics_type in ('DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC')) and (rd.engine == 'BLENDER_GAME')
+         return (game.physics_type in ('DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC')) and (rd.engine in self.COMPAT_ENGINES)
  
      def draw_header(self, context):
          game = context.active_object.game
          if wide_ui:
              col = split.column()
          col.prop(game, "collision_compound", text="Compound")
 +              
 +class PHYSICS_PT_game_obstacles(PhysicsButtonsPanel):
 +    bl_label = "Create obstacle"
  
 +    def poll(self, context):
 +        game = context.object.game
 +        rd = context.scene.render
 +        return (game.physics_type in ('DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC')) and (rd.engine == 'BLENDER_GAME')
 +
 +    def draw_header(self, context):
 +        game = context.active_object.game
 +
 +        self.layout.prop(game, "create_obstacle", text="")
 +
 +    def draw(self, context):
 +        layout = self.layout
 +
 +        game = context.active_object.game
 +        wide_ui = context.region.width > narrowui
 +
 +        layout.active = game.create_obstacle
 +
 +        split = layout.split()
 +        col = split.column()
 +        col.prop(game, "obstacle_radius", text="Radius")
  
  class RenderButtonsPanel(bpy.types.Panel):
      bl_space_type = 'PROPERTIES'
  
      def poll(self, context):
          rd = context.scene.render
-         return (rd.engine == 'BLENDER_GAME')
+         return (rd.engine in self.COMPAT_ENGINES)
  
  
  class RENDER_PT_game(RenderButtonsPanel):
      bl_label = "Game"
+     COMPAT_ENGINES = {'BLENDER_GAME'}
  
      def draw(self, context):
          layout = self.layout
  
  class RENDER_PT_game_player(RenderButtonsPanel):
      bl_label = "Standalone Player"
+     COMPAT_ENGINES = {'BLENDER_GAME'}
  
      def draw(self, context):
          layout = self.layout
  
  class RENDER_PT_game_stereo(RenderButtonsPanel):
      bl_label = "Stereo"
+     COMPAT_ENGINES = {'BLENDER_GAME'}
  
      def draw(self, context):
          layout = self.layout
  
  class RENDER_PT_game_shading(RenderButtonsPanel):
      bl_label = "Shading"
+     COMPAT_ENGINES = {'BLENDER_GAME'}
  
      def draw(self, context):
          layout = self.layout
  
  class RENDER_PT_game_performance(RenderButtonsPanel):
      bl_label = "Performance"
+     COMPAT_ENGINES = {'BLENDER_GAME'}
  
      def draw(self, context):
          layout = self.layout
  
  class RENDER_PT_game_sound(RenderButtonsPanel):
      bl_label = "Sound"
+     COMPAT_ENGINES = {'BLENDER_GAME'}
  
      def draw(self, context):
          layout = self.layout
@@@ -414,12 -398,13 +422,13 @@@ class WorldButtonsPanel(bpy.types.Panel
  
      def poll(self, context):
          scene = context.scene
-         return (scene.render.engine == 'BLENDER_GAME') and (scene.world is not None)
+         return (scene.render.engine in self.COMPAT_ENGINES) and (scene.world is not None)
  
  
  class WORLD_PT_game_context_world(WorldButtonsPanel):
      bl_label = ""
      bl_show_header = False
+     COMPAT_ENGINES = {'BLENDER_GAME'}
  
      def poll(self, context):
          rd = context.scene.render
  
  class WORLD_PT_game_world(WorldButtonsPanel):
      bl_label = "World"
+     COMPAT_ENGINES = {'BLENDER_GAME'}
  
      def draw(self, context):
          layout = self.layout
  
  class WORLD_PT_game_mist(WorldButtonsPanel):
      bl_label = "Mist"
+     COMPAT_ENGINES = {'BLENDER_GAME'}
  
      def draw_header(self, context):
          world = context.world
  
-         self.layout.prop(world.mist, "enabled", text="")
+         self.layout.prop(world.mist, "use_mist", text="")
  
      def draw(self, context):
          layout = self.layout
          world = context.world
          wide_ui = context.region.width > narrowui
  
-         layout.active = world.mist.enabled
+         layout.active = world.mist.use_mist
          split = layout.split()
  
          col = split.column()
  
  class WORLD_PT_game_physics(WorldButtonsPanel):
      bl_label = "Physics"
+     COMPAT_ENGINES = {'BLENDER_GAME'}
  
      def draw(self, context):
          layout = self.layout
              col.label(text="Logic Steps:")
              col.prop(gs, "logic_step_max", text="Max")
  
 +class WORLD_PT_game_physics_obstacles(WorldButtonsPanel):
 +    bl_label = "Obstacle simulation"
 +
 +    def draw(self, context):
 +        layout = self.layout
 +
 +        gs = context.scene.game_data
 +        wide_ui = context.region.width > narrowui
 +
 +        layout.prop(gs, "obstacle_simulation", text = "Type")
 +        if gs.obstacle_simulation != 'None':
 +            layout.prop(gs, "level_height", text="Level height")
 +                      
  
  classes = [
      PHYSICS_PT_game_physics,
      PHYSICS_PT_game_collision_bounds,
 +    PHYSICS_PT_game_obstacles,
  
      RENDER_PT_game,
      RENDER_PT_game_player,
      WORLD_PT_game_context_world,
      WORLD_PT_game_world,
      WORLD_PT_game_mist,
 -    WORLD_PT_game_physics]
 +    WORLD_PT_game_physics,
 +    WORLD_PT_game_physics_obstacles]
  
  
  def register():
@@@ -105,7 -105,7 +105,7 @@@ class SCENE_PT_keying_sets(SceneButtons
              subcol = col.column()
              subcol.operator_context = 'INVOKE_DEFAULT'
              op = subcol.operator("anim.keying_set_export", text="Export to File")
-             op.path = "keyingset.py"
+             op.filepath = "keyingset.py"
  
              if wide_ui:
                  col = row.column()
@@@ -229,18 -229,16 +229,16 @@@ class ANIM_OT_keying_set_export(bpy.typ
      bl_idname = "anim.keying_set_export"
      bl_label = "Export Keying Set..."
  
-     path = bpy.props.StringProperty(name="File Path", description="File path to write file to.")
-     filename = bpy.props.StringProperty(name="File Name", description="Name of the file.")
-     directory = bpy.props.StringProperty(name="Directory", description="Directory of the file.")
+     filepath = bpy.props.StringProperty(name="File Path", description="Filepath to write file to.")
      filter_folder = bpy.props.BoolProperty(name="Filter folders", description="", default=True, options={'HIDDEN'})
      filter_text = bpy.props.BoolProperty(name="Filter text", description="", default=True, options={'HIDDEN'})
      filter_python = bpy.props.BoolProperty(name="Filter python", description="", default=True, options={'HIDDEN'})
  
      def execute(self, context):
-         if not self.properties.path:
-             raise Exception("File path not set.")
+         if not self.properties.filepath:
+             raise Exception("Filepath not set.")
  
-         f = open(self.properties.path, "w")
+         f = open(self.properties.filepath, "w")
          if not f:
              raise Exception("Could not open file.")
  
          for ksp in ks.paths:
              f.write("ksp = ks.paths.add(")
  
-             # id-block + RNA-path
+             # id-block + data_path
              if ksp.id:
                  # find the relevant shorthand from the cache
                  id_bpy_path = id_to_paths_cache[ksp.id][0]
          wm.add_fileselect(self)
          return {'RUNNING_MODAL'}
  
 +class SCENE_PT_navmesh(SceneButtonsPanel):
 +    bl_label = "Navmesh"
 +    bl_default_closed = True
 +    COMPAT_ENGINES = {'BLENDER_RENDER'}
 +
 +    def draw(self, context):
 +        layout = self.layout
 +
 +        rd = context.scene.game_data.recast_data
 +        wide_ui = context.region.width > narrowui
 +
 +        layout.operator("object.create_navmesh", text='Build navigation mesh')
 +
 +        layout.label(text="Rasterization:")
 +        split = layout.split()
 +
 +        col = split.column()
 +        col.prop(rd, "cellsize")
 +        if wide_ui:
 +            col = split.column()
 +        col.prop(rd, "cellheight")
 +
 +        layout.separator()
 +
 +        layout.label(text="Agent:")
 +        split = layout.split()
 +        col = split.column()
 +        row = col.row()
 +        row.prop(rd, "agentheight")
 +        row = col.row()
 +        row.prop(rd, "agentradius")
 +        if wide_ui:
 +            col = split.column()
 +        row = col.row()
 +        row.prop(rd, "agentmaxslope")
 +        row = col.row()
 +        row.prop(rd, "agentmaxclimb")
 +
 +        layout.separator()
 +
 +        layout.label(text="Region:")
 +        split = layout.split()
 +        col = split.column()
 +        col.prop(rd, "regionminsize")
 +        if wide_ui:
 +            col = split.column()
 +        col.prop(rd, "regionmergesize")
 +
 +        layout.separator()
 +
 +        layout.label(text="Polygonization:")
 +        split = layout.split()
 +        col = split.column()
 +        row = col.row()
 +        row.prop(rd, "edgemaxlen")
 +        row = col.row()
 +        row.prop(rd, "edgemaxerror")
 +        if wide_ui:
 +            col = split.column()
 +        row = col.row()
 +        row.prop(rd, "vertsperpoly")
 +
 +        layout.separator()
 +
 +        layout.label(text="Detail Mesh:")
 +        split = layout.split()
 +        col = split.column()
 +        col.prop(rd, "detailsampledist")
 +        if wide_ui:
 +            col = split.column()
 +        col.prop(rd, "detailsamplemaxerror")
 +
  
  classes = [
      SCENE_PT_scene,
      SCENE_PT_keying_set_paths,
      SCENE_PT_physics,
      SCENE_PT_simplify,
 +      SCENE_PT_navmesh,
  
      SCENE_PT_custom_props,
  
@@@ -317,9 -317,10 +317,10 @@@ static void unlink_object__unlinkModifi
  
        if (*obpoin==unlinkOb) {
                *obpoin = NULL;
-               ob->recalc |= OB_RECALC;
+               ob->recalc |= OB_RECALC_ALL; // XXX: should this just be OB_RECALC_DATA?
        }
  }
  void unlink_object(Scene *scene, Object *ob)
  {
        Object *obt;
        bConstraint *con;
        //bActionStrip *strip; // XXX animsys 
        ModifierData *md;
-       int a;
+       ARegion *ar;
+       RegionView3D *rv3d;
+       int a, found;
        
        unlink_controllers(&ob->controllers);
        unlink_actuators(&ob->actuators);
                
                if(obt->parent==ob) {
                        obt->parent= NULL;
-                       obt->recalc |= OB_RECALC;
+                       obt->recalc |= OB_RECALC_ALL;
                }
                
                modifiers_foreachObjectLink(obt, unlink_object__unlinkModifierLinks, ob);
  
                        if(cu->bevobj==ob) {
                                cu->bevobj= NULL;
-                               obt->recalc |= OB_RECALC;
+                               obt->recalc |= OB_RECALC_ALL;
                        }
                        if(cu->taperobj==ob) {
                                cu->taperobj= NULL;
-                               obt->recalc |= OB_RECALC;
+                               obt->recalc |= OB_RECALC_ALL;
                        }
                        if(cu->textoncurve==ob) {
                                cu->textoncurve= NULL;
-                               obt->recalc |= OB_RECALC;
+                               obt->recalc |= OB_RECALC_ALL;
                        }
                }
                else if(obt->type==OB_ARMATURE && obt->pose) {
                                if(pchan->custom==ob)
                                        pchan->custom= NULL;
                        }
+               } else if(ELEM(OB_MBALL, ob->type, obt->type)) {
+                       if(is_mball_basis_for(obt, ob))
+                               obt->recalc|= OB_RECALC_DATA;
                }
                
                sca_remove_ob_poin(obt, ob);
                }
                tex= tex->id.next;
        }
-       
-       /* mballs (scene==NULL when called from library.c) */
-       if(scene && ob->type==OB_MBALL) {
-               obt= find_basis_mball(scene, ob);
-               if(obt) freedisplist(&obt->disp);
-       }
-       
        /* worlds */
        wrld= G.main->world.first;
        while(wrld) {
                                if(sl->spacetype==SPACE_VIEW3D) {
                                        View3D *v3d= (View3D*) sl;
  
+                                       found= 0;
                                        if(v3d->camera==ob) {
                                                v3d->camera= NULL;
-                                               // XXX if(v3d->persp==V3D_CAMOB) v3d->persp= V3D_PERSP;
+                                               found= 1;
                                        }
                                        if(v3d->localvd && v3d->localvd->camera==ob ) {
                                                v3d->localvd->camera= NULL;
-                                               // XXX if(v3d->localvd->persp==V3D_CAMOB) v3d->localvd->persp= V3D_PERSP;
+                                               found += 2;
+                                       }
+                                       if (found) {
+                                               if (sa->spacetype == SPACE_VIEW3D) {
+                                                       for (ar= sa->regionbase.first; ar; ar= ar->next) {
+                                                               if (ar->regiontype==RGN_TYPE_WINDOW) {
+                                                                       rv3d= (RegionView3D *)ar->regiondata;
+                                                                       if (found == 1 || found == 3) {
+                                                                               if (rv3d->persp == RV3D_CAMOB)
+                                                                                       rv3d->persp= RV3D_PERSP;
+                                                                       }
+                                                                       if (found == 2 || found == 3) {
+                                                                               if (rv3d->localvd && rv3d->localvd->persp == RV3D_CAMOB)
+                                                                                       rv3d->localvd->persp= RV3D_PERSP;
+                                                                       }
+                                                               }
+                                                       }
+                                               }
                                        }
                                }
                                else if(sl->spacetype==SPACE_OUTLINER) {
                                                }
                                        }
                                }
+                               else if(sl->spacetype==SPACE_BUTS) {
+                                       SpaceButs *sbuts= (SpaceButs *)sl;
+                                       if(sbuts->pinid==(ID *)ob) {
+                                               sbuts->flag&= ~SB_PIN_CONTEXT;
+                                               sbuts->pinid= NULL;
+                                       }
+                               }
                        }
  
                        sa= sa->next;
@@@ -679,8 -706,8 +706,8 @@@ void *add_camera(char *name
        cam->clipend= 100.0f;
        cam->drawsize= 0.5f;
        cam->ortho_scale= 6.0;
-       cam->flag |= CAM_SHOWTITLESAFE;
-       cam->passepartalpha = 0.2f;
+       cam->flag |= CAM_SHOWPASSEPARTOUT;
+       cam->passepartalpha = 0.5f;
        
        return cam;
  }
@@@ -956,7 -983,7 +983,7 @@@ static char *get_obdata_defname(int typ
        case OB_MESH: return "Mesh";
        case OB_CURVE: return "Curve";
        case OB_SURF: return "Surf";
-       case OB_FONT: return "Font";
+       case OB_FONT: return "Text";
        case OB_MBALL: return "Mball";
        case OB_CAMERA: return "Camera";
        case OB_LAMP: return "Lamp";
@@@ -1026,9 -1053,10 +1053,11 @@@ Object *add_only_object(int type, char 
        ob->anisotropicFriction[2] = 1.0f;
        ob->gameflag= OB_PROP|OB_COLLISION;
        ob->margin = 0.0;
+       ob->init_state=1;
+       ob->state=1;
        /* ob->pad3 == Contact Processing Threshold */
        ob->m_contactProcessingThreshold = 1.;
 +      ob->obstacleRad = 1.;
        
        /* NT fluid sim defaults */
        ob->fluidsimFlag = 0;
@@@ -1059,7 -1087,7 +1088,7 @@@ Object *add_object(struct Scene *scene
        
        base= scene_add_base(scene, ob);
        scene_select_base(scene, base);
-       ob->recalc |= OB_RECALC;
+       ob->recalc |= OB_RECALC_ALL;
  
        return ob;
  }
@@@ -1266,6 -1294,7 +1295,7 @@@ Object *copy_object(Object *ob
        
        for (md=ob->modifiers.first; md; md=md->next) {
                ModifierData *nmd = modifier_new(md->type);
+               BLI_strncpy(nmd->name, md->name, sizeof(nmd->name));
                modifier_copyData(md, nmd);
                BLI_addtail(&obn->modifiers, nmd);
        }
@@@ -1504,7 -1533,7 +1534,7 @@@ void object_make_proxy(Object *ob, Obje
        ob->proxy_group= gob;
        id_lib_extern(&target->id);
        
-       ob->recalc= target->recalc= OB_RECALC;
+       ob->recalc= target->recalc= OB_RECALC_ALL;
        
        /* copy transform */
        if(gob) {
  
  /* there is also a timing calculation in drawobject() */
  
- float bluroffs= 0.0f, fieldoffs= 0.0f;
  int no_speed_curve= 0;
  
- /* ugly calls from render */
- void set_mblur_offs(float blur)
- {
-       bluroffs= blur;
- }
- void set_field_offs(float field)
- {
-       fieldoffs= field;
- }
  void disable_speed_curve(int val)
  {
        no_speed_curve= val;
  /* ob can be NULL */
  float bsystem_time(struct Scene *scene, Object *ob, float cfra, float ofs)
  {
-       /* returns float ( see frame_to_float in ipo.c) */
+       /* returns float ( see BKE_curframe in scene.c) */
+       cfra += scene->r.subframe;
        
-       /* bluroffs and fieldoffs are ugly globals that are set by render */
-       cfra+= bluroffs+fieldoffs;
        /* global time */
        if (scene)
                cfra*= scene->r.framelen;       
@@@ -1709,10 -1724,8 +1725,8 @@@ void object_to_mat4(Object *ob, float m
        object_to_mat3(ob, tmat);
        
        copy_m4_m3(mat, tmat);
-       
-       mat[3][0]= ob->loc[0] + ob->dloc[0];
-       mat[3][1]= ob->loc[1] + ob->dloc[1];
-       mat[3][2]= ob->loc[2] + ob->dloc[2];
+       add_v3_v3v3(mat[3], ob->loc, ob->dloc);
  }
  
  int enable_cu_speed= 1;
@@@ -2461,14 -2474,26 +2475,26 @@@ void object_tfm_restore(Object *ob, voi
  /* requires flags to be set! */
  void object_handle_update(Scene *scene, Object *ob)
  {
-       if(ob->recalc & OB_RECALC) {
+       if(ob->recalc & OB_RECALC_ALL) {
                /* speed optimization for animation lookups */
                if(ob->pose)
                        make_pose_channels_hash(ob->pose);
  
+               if(ob->recalc & OB_RECALC_DATA) {
+                       if(ob->type==OB_ARMATURE) {
+                               /* this happens for reading old files and to match library armatures
+                                  with poses we do it ahead of where_is_object to ensure animation
+                                  is evaluated on the rebuilt pose, otherwise we get incorrect poses
+                                  on file load */
+                               if(ob->pose==NULL || (ob->pose->flag & POSE_RECALC))
+                                       armature_rebuild_pose(ob, ob->data);
+                       }
+               }
                /* XXX new animsys warning: depsgraph tag OB_RECALC_DATA should not skip drivers, 
                   which is only in where_is_object now */
-               if(ob->recalc & OB_RECALC) {
+               // XXX: should this case be OB_RECALC_OB instead?
+               if(ob->recalc & OB_RECALC_ALL) {
                        
                        if (G.f & G_DEBUG)
                                printf("recalcob %s\n", ob->id.name+2);
                                lattice_calc_modifiers(scene, ob);
                        }
                        else if(ob->type==OB_ARMATURE) {
-                               /* this happens for reading old files and to match library armatures with poses */
-                               // XXX this won't screw up the pose set already...
-                               if(ob->pose==NULL || (ob->pose->flag & POSE_RECALC))
-                                       armature_rebuild_pose(ob, ob->data);
-                               
                                /* evaluate drivers */
                                BKE_animsys_evaluate_animdata(data_id, adt, ctime, ADT_RECALC_DRIVERS);
                                
                        object_handle_update(scene, ob->proxy);
                }
        
-               ob->recalc &= ~OB_RECALC;
+               ob->recalc &= ~OB_RECALC_ALL;
        }
  
        /* the case when this is a group proxy, object_update is called in group.c */
@@@ -2735,7 -2755,7 +2756,7 @@@ void object_camera_matrix
        float pixsize;
        float shiftx=0.0, shifty=0.0, winside, viewfac;
  
-       rd->mode &= ~R_ORTHO;
+       rd->mode &= ~(R_ORTHO|R_PANORAMA);
  
        /* question mark */
        (*ycor)= rd->yasp / rd->xasp;
@@@ -45,6 -45,7 +45,7 @@@
  #include "BKE_global.h"
  #include "BKE_main.h"
  #include "BKE_library.h"
+ #include "BKE_sca.h"
  
  /* ******************* SENSORS ************************ */
  
@@@ -189,26 -190,13 +190,13 @@@ void unlink_controller(bController *con
  {
        bSensor *sens;
        Object *ob;
-       int a, removed;
        
        /* check for controller pointers in sensors */
        ob= G.main->object.first;
        while(ob) {
                sens= ob->sensors.first;
                while(sens) {
-                       removed= 0;
-                       for(a=0; a<sens->totlinks; a++) {
-                               if(removed) (sens->links)[a-1] = (sens->links)[a];
-                               else if((sens->links)[a] == cont) removed= 1;
-                       }
-                       if(removed) {
-                               sens->totlinks--;
-                               
-                               if(sens->totlinks==0) {
-                                       MEM_freeN(sens->links);
-                                       sens->links= NULL;
-                               }
-                       }
+                       unlink_logicbricks((void **)&cont, (void ***)&(sens->links), &sens->totlinks);
                        sens= sens->next;
                }
                ob= ob->id.next;
@@@ -313,26 -301,13 +301,13 @@@ void unlink_actuator(bActuator *act
  {
        bController *cont;
        Object *ob;
-       int a, removed;
        
        /* check for actuator pointers in controllers */
        ob= G.main->object.first;
        while(ob) {
                cont= ob->controllers.first;
                while(cont) {
-                       removed= 0;
-                       for(a=0; a<cont->totlinks; a++) {
-                               if(removed) (cont->links)[a-1] = (cont->links)[a];
-                               else if((cont->links)[a] == act) removed= 1;
-                       }
-                       if(removed) {
-                               cont->totlinks--;
-                               
-                               if(cont->totlinks==0) {
-                                       MEM_freeN(cont->links);
-                                       cont->links= NULL;
-                               }
-                       }
+                       unlink_logicbricks((void **)&act, (void ***)&(cont->links), &cont->totlinks);
                        cont= cont->next;
                }
                ob= ob->id.next;
@@@ -416,7 -391,6 +391,7 @@@ void init_actuator(bActuator *act
        bObjectActuator *oa;
        bRandomActuator *ra;
        bSoundActuator *sa;
 +      bSteeringActuator *sta;
        
        if(act->data) MEM_freeN(act->data);
        act->data= 0;
        case ACT_ARMATURE:
                act->data = MEM_callocN(sizeof( bArmatureActuator ), "armature act");
                break;
 +      case ACT_STEERING:
 +              act->data = MEM_callocN(sizeof( bSteeringActuator), "steering act");
 +              sta = act->data;
 +              sta->acceleration = 3;
 +              sta->turnspeed = 120;
        default:
                ; /* this is very severe... I cannot make any memory for this        */
                /* logic brick...                                                    */
@@@ -518,7 -487,6 +493,6 @@@ bActuator *new_actuator(int type
  }
  
  /* ******************** GENERAL ******************* */
  void clear_sca_new_poins_ob(Object *ob)
  {
        bSensor *sens;
@@@ -638,7 -606,6 +612,7 @@@ void sca_remove_ob_poin(Object *obt, Ob
        bMessageActuator *ma;
        bParentActuator *para;
        bArmatureActuator *aa;
 +      bSteeringActuator *sta;
  
        sens= obt->sensors.first;
        while(sens) {
                        if (aa->target == ob) aa->target = NULL;
                        if (aa->subtarget == ob) aa->subtarget = NULL;
                        break;
 +              case ACT_STEERING:
 +                      sta = act->data;
 +                      if (sta->target==ob) sta->target = NULL;
 +                      if (sta->navmesh==ob) sta->navmesh = NULL;
 +                      break;                  
                }
                act= act->next;
        }       
  }
+ /* ******************** INTERFACE ******************* */
+ void sca_move_sensor(bSensor *sens_to_move, Object *ob, int move_up)
+ {
+       bSensor *sens, *tmp;
+       int val;
+       val = move_up ? 1:2;
+       /* make sure this sensor belongs to this object */
+       sens= ob->sensors.first;
+       while(sens) {
+               if(sens == sens_to_move) break;
+               sens= sens->next;
+       }
+       if(!sens) return;
+       /* move up */
+       if( val==1 && sens->prev) {
+               for (tmp=sens->prev; tmp; tmp=tmp->prev) {
+                       if (tmp->flag & SENS_VISIBLE)
+                               break;
+               }
+               if (tmp) {
+                       BLI_remlink(&ob->sensors, sens);
+                       BLI_insertlinkbefore(&ob->sensors, tmp, sens);
+               }
+       }
+       /* move down */
+       else if( val==2 && sens->next) {
+               for (tmp=sens->next; tmp; tmp=tmp->next) {
+                       if (tmp->flag & SENS_VISIBLE)
+                               break;
+               }
+               if (tmp) {
+                       BLI_remlink(&ob->sensors, sens);
+                       BLI_insertlink(&ob->sensors, tmp, sens);
+               }
+       }
+ }
+ void sca_move_controller(bController *cont_to_move, Object *ob, int move_up)
+ {
+       bController *cont, *tmp;
+       int val;
+       val = move_up ? 1:2;
+       /* make sure this controller belongs to this object */
+       cont= ob->controllers.first;
+       while(cont) {
+               if(cont == cont_to_move) break;
+               cont= cont->next;
+       }
+       if(!cont) return;
+       /* move up */
+       if( val==1 && cont->prev) {
+               /* locate the controller that has the same state mask but is earlier in the list */
+               tmp = cont->prev;
+               while(tmp) {
+                       if(tmp->state_mask & cont->state_mask) 
+                               break;
+                       tmp = tmp->prev;
+               }
+               if (tmp) {
+                       BLI_remlink(&ob->controllers, cont);
+                       BLI_insertlinkbefore(&ob->controllers, tmp, cont);
+               }
+       }
+       /* move down */
+       else if( val==2 && cont->next) {
+               tmp = cont->next;
+               while(tmp) {
+                       if(tmp->state_mask & cont->state_mask) 
+                               break;
+                       tmp = tmp->next;
+               }
+               BLI_remlink(&ob->controllers, cont);
+               BLI_insertlink(&ob->controllers, tmp, cont);
+       }
+ }
+ void sca_move_actuator(bActuator *act_to_move, Object *ob, int move_up)
+ {
+       bActuator *act, *tmp;
+       int val;
+       val = move_up ? 1:2;
+       /* make sure this actuator belongs to this object */
+       act= ob->actuators.first;
+       while(act) {
+               if(act == act_to_move) break;
+               act= act->next;
+       }
+       if(!act) return;
+       /* move up */
+       if( val==1 && act->prev) {
+               /* locate the first visible actuators before this one */
+               for (tmp = act->prev; tmp; tmp=tmp->prev) {
+                       if (tmp->flag & ACT_VISIBLE)
+                               break;
+               }
+               if (tmp) {
+                       BLI_remlink(&ob->actuators, act);
+                       BLI_insertlinkbefore(&ob->actuators, tmp, act);
+               }
+       }
+       /* move down */
+       else if( val==2 && act->next) {
+               /* locate the first visible actuators after this one */
+               for (tmp=act->next; tmp; tmp=tmp->next) {
+                       if (tmp->flag & ACT_VISIBLE)
+                               break;
+               }
+               if (tmp) {
+                       BLI_remlink(&ob->actuators, act);
+                       BLI_insertlink(&ob->actuators, tmp, act);
+               }
+       }
+ }
+ void link_logicbricks(void **poin, void ***ppoin, short *tot, short size)
+ {
+       void **old_links= NULL;
+       
+       int ibrick;
+       /* check if the bricks are already linked */
+       for (ibrick=0; ibrick < *tot; ibrick++) {
+               if ((*ppoin)[ibrick] == *poin)
+                       return;
+       }
+       if (*ppoin) {
+               old_links= *ppoin;
+               (*tot) ++;
+               *ppoin = MEM_callocN((*tot)*size, "new link");
+       
+               for (ibrick=0; ibrick < *tot - 1; ibrick++) {
+                       (*ppoin)[ibrick] = old_links[ibrick];
+               }
+               (*ppoin)[ibrick] = *poin;
+               if(old_links) MEM_freeN(old_links);
+       }
+       else {
+               (*tot) = 1;
+               *ppoin = MEM_callocN((*tot)*size, "new link");
+               (*ppoin)[0] = *poin;
+       }
+ }
+ void unlink_logicbricks(void **poin, void ***ppoin, short *tot)
+ {
+       int ibrick, removed;
+       removed= 0;
+       for (ibrick=0; ibrick < *tot; ibrick++) {
+               if(removed) (*ppoin)[ibrick - removed] = (*ppoin)[ibrick];
+               else if((*ppoin)[ibrick] == *poin) removed = 1;
+       }
+       if (removed) {
+               (*tot) --;
+               if(*tot == 0) {
+                       MEM_freeN(*ppoin);
+                       (*ppoin)= NULL;
+               }
+               return;
+       }
+ }
@@@ -44,6 -44,7 +44,7 @@@
  #include "DNA_group_types.h"
  #include "DNA_scene_types.h"
  #include "DNA_screen_types.h"
+ #include "DNA_sequence_types.h"
  
  #include "BKE_anim.h"
  #include "BKE_animsys.h"
@@@ -197,6 -198,10 +198,10 @@@ Scene *copy_scene(Main *bmain, Scene *s
                scen->r.qtcodecdata->cdParms = MEM_dupallocN(scen->r.qtcodecdata->cdParms);
        }
        
+       if(sce->r.ffcodecdata.properties) { /* intentionally check scen not sce. */
+               scen->r.ffcodecdata.properties= IDP_CopyProperty(sce->r.ffcodecdata.properties);
+       }
        /* NOTE: part of SCE_COPY_LINK_DATA and SCE_COPY_FULL operations
         * are done outside of blenkernel with ED_objects_single_users! */
  
                        id_us_plus((ID *)scen->world);
                        scen->world= copy_world(scen->world);
                }
+               if(sce->ed) {
+                       scen->ed= MEM_callocN( sizeof(Editing), "addseq");
+                       scen->ed->seqbasep= &scen->ed->seqbase;
+                       seqbase_dupli_recursive(sce, &scen->ed->seqbase, &sce->ed->seqbase, SEQ_DUPE_ALL);
+               }
        }
  
        sound_create_scene(scen);
@@@ -310,7 -321,7 +321,7 @@@ Scene *add_scene(char *name
        int a;
  
        sce= alloc_libblock(&G.main->scene, ID_SCE, name);
-       sce->lay= 1;
+       sce->lay= sce->layact= 1;
        
        sce->r.mode= R_GAMMA|R_OSA|R_SHADOW|R_SSS|R_ENVMAP|R_RAYTRACE;
        sce->r.cfra= 1;
        sce->gm.flag = GAME_DISPLAY_LISTS;
        sce->gm.matmode = GAME_MAT_MULTITEX;
  
 +      sce->gm.obstacleSimulation= OBSTSIMULATION_NONE;
 +      sce->gm.levelHeight = 2.f;
 +
 +      sce->gm.recastData.cellsize = 0.3f;
 +      sce->gm.recastData.cellheight = 0.2f;
 +      sce->gm.recastData.agentmaxslope = M_PI/2;
 +      sce->gm.recastData.agentmaxclimb = 0.9f;
 +      sce->gm.recastData.agentheight = 2.0f;
 +      sce->gm.recastData.agentradius = 0.6f;
 +      sce->gm.recastData.edgemaxlen = 12.0f;
 +      sce->gm.recastData.edgemaxerror = 1.3f;
 +      sce->gm.recastData.regionminsize = 50.f;
 +      sce->gm.recastData.regionmergesize = 20.f;
 +      sce->gm.recastData.vertsperpoly = 6;
 +      sce->gm.recastData.detailsampledist = 6.0f;
 +      sce->gm.recastData.detailsamplemaxerror = 1.0f;
 +
        sound_create_scene(sce);
  
        return sce;
@@@ -559,18 -553,17 +570,17 @@@ void set_scene_bg(Scene *scene
  }
  
  /* called from creator.c */
void set_scene_name(char *name)
Scene *set_scene_name(char *name)
  {
-       Scene *sce;
-       for (sce= G.main->scene.first; sce; sce= sce->id.next) {
-               if (BLI_streq(name, sce->id.name+2)) {
-                       set_scene_bg(sce);
-                       return;
-               }
+       Scene *sce= (Scene *)find_id("SC", name);
+       if(sce) {
+               set_scene_bg(sce);
+               printf("Scene switch: '%s' in file: '%s'\n", name, G.sce);
+               return sce;
        }
-       
-       //XXX error("Can't find scene: %s", name);
+       printf("Can't find scene: '%s' in file: '%s'\n", name, G.sce);
+       return NULL;
  }
  
  void unlink_scene(Main *bmain, Scene *sce, Scene *newsce)
@@@ -885,87 -878,54 +895,54 @@@ int scene_check_setscene(Scene *sce
        return 1;
  }
  
- /* This (evil) function is needed to cope with two legacy Blender rendering features
- * mblur (motion blur that renders 'subframes' and blurs them together), and fields 
- * rendering. Thus, the use of ugly globals from object.c
- */
- // BAD... EVIL... JUJU...!!!!
- // XXX moved here temporarily
- float frame_to_float (Scene *scene, int cfra)         /* see also bsystem_time in object.c */
+ /* This function is needed to cope with fractional frames - including two Blender rendering features
+ * mblur (motion blur that renders 'subframes' and blurs them together), and fields rendering. */
+ /* see also bsystem_time in object.c */
+ float BKE_curframe(Scene *scene)
  {
-       extern float bluroffs;  /* bad stuff borrowed from object.c */
-       extern float fieldoffs;
-       float ctime;
-       
-       ctime= (float)cfra;
-       ctime+= bluroffs+fieldoffs;
-       ctime*= scene->r.framelen;
-       
+       float ctime = scene->r.cfra;
+       ctime+= scene->r.subframe;
+       ctime*= scene->r.framelen;      
        return ctime;
  }
  
- static void scene_update_newframe(Scene *scene, int cfra, unsigned int lay)
+ static void scene_update_tagged_recursive(Scene *scene, Scene *scene_parent)
  {
        Base *base;
-       Object *ob;
-       int cfra_back= scene->r.cfra;
-       scene->r.cfra= cfra;
-       
+       /* sets first, we allow per definition current scene to have
+          dependencies on sets, but not the other way around. */
+       if(scene->set)
+               scene_update_tagged_recursive(scene->set, scene_parent);
        for(base= scene->base.first; base; base= base->next) {
-               ob= base->object;
-               
-               object_handle_update(scene, ob);   // bke_object.h
+               Object *ob= base->object;
+               object_handle_update(scene_parent, ob);
  
                if(ob->dup_group && (ob->transflag & OB_DUPLIGROUP))
-                       group_handle_recalc_and_update(scene, ob, ob->dup_group);
-               
-               /* only update layer when an ipo */
-                       // XXX old animation system
-               //if(ob->ipo && has_ipo_code(ob->ipo, OB_LAY) ) {
-               //      base->lay= ob->lay;
-               //}
+                       group_handle_recalc_and_update(scene_parent, ob, ob->dup_group);
+                       
+               /* always update layer, so that animating layers works */
+               base->lay= ob->lay;
        }
-       scene->r.cfra= cfra_back;
  }
  
  /* this is called in main loop, doing tagged updates before redraw */
  void scene_update_tagged(Scene *scene)
  {
-       Scene *sce;
-       Base *base;
-       Object *ob;
-       float ctime = frame_to_float(scene, scene->r.cfra); 
        scene->physics_settings.quick_cache_step= 0;
  
        /* update all objects: drivers, matrices, displists, etc. flags set
           by depgraph or manual, no layer check here, gets correct flushed */
  
-       /* sets first, we allow per definition current scene to have
-          dependencies on sets, but not the other way around. */
-       if(scene->set) {
-               for(SETLOOPER(scene->set, base)) {
-                       ob= base->object;
-                       object_handle_update(scene, ob);
-                       if(ob->dup_group && (ob->transflag & OB_DUPLIGROUP))
-                               group_handle_recalc_and_update(scene, ob, ob->dup_group);
-               }
-       }
-       
-       for(base= scene->base.first; base; base= base->next) {
-               ob= base->object;
-               object_handle_update(scene, ob);
-               if(ob->dup_group && (ob->transflag & OB_DUPLIGROUP))
-                       group_handle_recalc_and_update(scene, ob, ob->dup_group);
-       }
+       scene_update_tagged_recursive(scene, scene);
  
        /* recalc scene animation data here (for sequencer) */
        {
+               float ctime = BKE_curframe(scene); 
                AnimData *adt= BKE_animdata_from_id(&scene->id);
  
                if(adt && (adt->recalc & ADT_RECALC_ANIM))
  /* applies changes right away, does all sets too */
  void scene_update_for_newframe(Scene *sce, unsigned int lay)
  {
-       float ctime = frame_to_float(sce, sce->r.cfra);
+       float ctime = BKE_curframe(sce);
        Scene *sce_iter;
        
        /* clear animation overrides */
  
  
        /* Following 2 functions are recursive
-        * so dont call within 'scene_update_newframe' */
+        * so dont call within 'scene_update_tagged_recursive' */
        DAG_scene_update_flags(sce, lay);   // only stuff that moves or needs display still
  
        /* All 'standard' (i.e. without any dependencies) animation is handled here,
        BKE_animsys_evaluate_all_animation(G.main, ctime);
        /*...done with recusrive funcs */
  
-       /* sets first, we allow per definition current scene to have dependencies on sets */
-       for(sce_iter= sce->set; sce_iter; sce_iter= sce_iter->set) {
-               scene_update_newframe(sce_iter, sce->r.cfra, lay);
-     }
-       scene_update_newframe(sce, sce->r.cfra, lay);
+       /* object_handle_update() on all objects, groups and sets */
+       scene_update_tagged_recursive(sce, sce);
  }
  
  /* return default layer, also used to patch old files */
  #include "BKE_sequencer.h"
  #include "BKE_texture.h" // for open_plugin_tex
  #include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND
+ #include "BKE_ipo.h"
  #include "BKE_sound.h"
  
  //XXX #include "BIF_butspace.h" // badlevel, for do_versions, patching event codes
@@@ -507,7 -507,7 +507,7 @@@ static Main *blo_find_main(FileData *fd
  //    printf("blo_find_main: converted to %s\n", name1);
  
        for (m= mainlist->first; m; m= m->next) {
-               char *libname= (m->curlib)?m->curlib->filename:m->name;
+               char *libname= (m->curlib)?m->curlib->filepath:m->name;
                
                if (BLI_streq(name1, libname)) {
                        if(G.f & G_DEBUG) printf("blo_find_main: found library %s\n", libname);
  
        lib= alloc_libblock(&m->library, ID_LI, "lib");
        strncpy(lib->name, name, sizeof(lib->name)-1);
-       BLI_strncpy(lib->filename, name1, sizeof(lib->filename));
+       BLI_strncpy(lib->filepath, name1, sizeof(lib->filepath));
        
        m->curlib= lib;
        
@@@ -959,11 -959,11 +959,11 @@@ static FileData *blo_decode_and_check(F
  FileData *blo_openblenderfile(char *name, ReportList *reports)
  {
        gzFile gzfile;
-       
+       errno= 0;
        gzfile= gzopen(name, "rb");
  
-       if (NULL == gzfile) {
-               BKE_report(reports, RPT_ERROR, "Unable to open");
+       if (gzfile == Z_NULL) {
+               BKE_reportf(reports, RPT_ERROR, "Unable to open \"%s\": %s.", name, errno ? strerror(errno) : "Unknown erro reading file");
                return NULL;
        } else {
                FileData *fd = filedata_new();
@@@ -996,7 -996,7 +996,7 @@@ FileData *blo_openblendermemory(void *m
  FileData *blo_openblendermemfile(MemFile *memfile, ReportList *reports)
  {
        if (!memfile) {
-               BKE_report(reports, RPT_ERROR, "Unable to open");
+               BKE_report(reports, RPT_ERROR, "Unable to open blend <memory>");
                return NULL;
        } else {
                FileData *fd= filedata_new();
@@@ -2244,7 -2244,7 +2244,7 @@@ static void lib_link_pose(FileData *fd
        }
        
        if(rebuild) {
-               ob->recalc= OB_RECALC;
+               ob->recalc= OB_RECALC_ALL;
                pose->flag |= POSE_RECALC;
        }
  }
@@@ -2839,6 -2839,7 +2839,7 @@@ static void direct_link_texture(FileDat
        tex->vd= newdataadr(fd, tex->vd);
        if(tex->vd) {
                tex->vd->dataset = NULL;
+               tex->vd->ok = 0;
        }
        
        tex->nodetree= newdataadr(fd, tex->nodetree);
@@@ -3073,6 -3074,7 +3074,7 @@@ static void lib_link_particlesystems(Fi
                        for(; pt; pt=pt->next)
                                pt->ob=newlibadr(fd, id->lib, pt->ob);
  
+                       psys->parent= newlibadr_us(fd, id->lib, psys->parent);
                        psys->target_ob = newlibadr(fd, id->lib, psys->target_ob);
  
                        if(psys->clmd) {
@@@ -3142,7 -3144,7 +3144,7 @@@ static void direct_link_particlesystems
                psys->childcachebufs.first = psys->childcachebufs.last = NULL;
                psys->frand = NULL;
                psys->pdd = NULL;
+               
                direct_link_pointcache_list(fd, &psys->ptcaches, &psys->pointcache);
  
                if(psys->clmd) {
@@@ -3456,7 -3458,7 +3458,7 @@@ static void lib_link_object(FileData *f
                                        /* this triggers object_update to always use a copy */
                                        ob->proxy->proxy_from= ob;
                                        /* force proxy updates after load/undo, a bit weak */
-                                       ob->recalc= ob->proxy->recalc= OB_RECALC;
+                                       ob->recalc= ob->proxy->recalc= OB_RECALC_ALL;
                                }
                        }
                        ob->proxy_group= newlibadr(fd, ob->id.lib, ob->proxy_group);
                                        arma->target= newlibadr(fd, ob->id.lib, arma->target);
                                        arma->subtarget= newlibadr(fd, ob->id.lib, arma->subtarget);
                                }
 +                              else if(act->type==ACT_STEERING) {
 +                                      bSteeringActuator *steeringa = act->data; 
 +                                      steeringa->target = newlibadr(fd, ob->id.lib, steeringa->target);
 +                                      steeringa->navmesh = newlibadr(fd, ob->id.lib, steeringa->navmesh);
 +                              }
                                act= act->next;
                        }
                        
@@@ -4562,6 -4559,7 +4564,7 @@@ static void lib_link_screen(FileData *f
                if(sc->id.flag & LIB_NEEDLINK) {
                        sc->id.us= 1;
                        sc->scene= newlibadr(fd, sc->id.lib, sc->scene);
+                       sc->animtimer= NULL; /* saved in rare cases */
                        
                        sa= sc->areabase.first;
                        while(sa) {
@@@ -5164,6 -5162,10 +5167,10 @@@ static void direct_link_screen(FileDat
                                }
                                snode->nodetree= snode->edittree= NULL;
                        }
+                       else if(sl->spacetype==SPACE_TIME) {
+                               SpaceTime *stime= (SpaceTime *)sl;
+                               stime->caches.first= stime->caches.last= NULL;
+                       }
                        else if(sl->spacetype==SPACE_LOGIC) {
                                SpaceLogic *slogic= (SpaceLogic *)sl;
                                        
@@@ -5237,8 -5239,8 +5244,8 @@@ static void direct_link_library(FileDat
        
        for(newmain= fd->mainlist.first; newmain; newmain= newmain->next) {
                if(newmain->curlib) {
-                       if(strcmp(newmain->curlib->filename, lib->filename)==0) {
-                               printf("Fixed error in file; multiple instances of lib:\n %s\n", lib->filename);
+                       if(strcmp(newmain->curlib->filepath, lib->filepath)==0) {
+                               printf("Fixed error in file; multiple instances of lib:\n %s\n", lib->filepath);
                                
                                change_idid_adr(&fd->mainlist, fd, lib, newmain->curlib);
  //                            change_idid_adr_fd(fd, lib, newmain->curlib);
                }
        }
        /* make sure we have full path in lib->filename */
-       BLI_strncpy(lib->filename, lib->name, sizeof(lib->name));
-       cleanup_path(fd->relabase, lib->filename);
+       BLI_strncpy(lib->filepath, lib->name, sizeof(lib->name));
+       cleanup_path(fd->relabase, lib->filepath);
        
  //    printf("direct_link_library: name %s\n", lib->name);
  //    printf("direct_link_library: filename %s\n", lib->filename);
@@@ -5287,7 -5289,7 +5294,7 @@@ static void fix_relpaths_library(const 
                /* Libraries store both relative and abs paths, recreate relative paths,
                 * relative to the blend file since indirectly linked libs will be relative to their direct linked library */
                if (strncmp(lib->name, "//", 2)==0) { /* if this is relative to begin with? */
-                       strncpy(lib->name, lib->filename, sizeof(lib->name));
+                       strncpy(lib->name, lib->filepath, sizeof(lib->name));
                        BLI_path_rel(lib->name, basepath);
                }
        }
@@@ -7890,7 -7892,7 +7897,7 @@@ static void do_versions(FileData *fd, L
                        if(ob->type==OB_ARMATURE) {
                                if(ob->pose)
                                        ob->pose->flag |= POSE_RECALC;
-                               ob->recalc |= OB_RECALC;        // cannot call stuff now (pointers!), done in setup_app_data
+                               ob->recalc |= OB_RECALC_ALL;    // cannot call stuff now (pointers!), done in setup_app_data
  
                                /* new generic xray option */
                                arm= newlibadr(fd, lib, ob->data);
                        do_versions_gpencil_2_50(main, screen);
                }
                
-               /* old Animation System (using IPO's) needs to be converted to the new Animato system 
-                * (NOTE: conversion code in blenkernel/intern/ipo.c for now)
-                */
-               //do_versions_ipos_to_animato(main);
-               
                /* shader, composit and texture node trees have id.name empty, put something in
                 * to have them show in RNA viewer and accessible otherwise.
                 */
        /* put 2.50 compatibility code here until next subversion bump */
        {
                Object *ob;
+               Scene *scene;
                bScreen *sc;
+               Tex *tex;
  
                for (sc= main->screen.first; sc; sc= sc->id.next) {
                        ScrArea *sa;
                                SpaceLink *sl;
                                for (sl= sa->spacedata.first; sl; sl= sl->next) {
                                        if (sl->spacetype == SPACE_NODE) {
-                                               SpaceNode *snode;
+                                               SpaceNode *snode= (SpaceNode *)sl;
+                                               ListBase *regionbase;
+                                               ARegion *ar;
+                                               if (sl == sa->spacedata.first)
+                                                       regionbase = &sa->regionbase;
+                                               else
+                                                       regionbase = &sl->regionbase;
  
-                                               snode= (SpaceNode *)sl;
                                                if (snode->v2d.minzoom > 0.09f)
                                                        snode->v2d.minzoom= 0.09f;
                                                if (snode->v2d.maxzoom < 2.31f)
                                                        snode->v2d.maxzoom= 2.31f;
+                                               for (ar= regionbase->first; ar; ar= ar->next) {
+                                                       if (ar->regiontype == RGN_TYPE_WINDOW) {
+                                                               if (ar->v2d.minzoom > 0.09f)
+                                                                       ar->v2d.minzoom= 0.09f;
+                                                               if (ar->v2d.maxzoom < 2.31f)
+                                                                       ar->v2d.maxzoom= 2.31f;
+                                                       }
+                                               }
+                                       }
+                                       else if (sl->spacetype == SPACE_TIME) {
+                                               SpaceTime *stime= (SpaceTime *)sl;
+                                               
+                                               /* enable all cache display */
+                                               stime->cache_display |= TIME_CACHE_DISPLAY;
+                                               stime->cache_display |= (TIME_CACHE_SOFTBODY|TIME_CACHE_PARTICLES);
+                                               stime->cache_display |= (TIME_CACHE_CLOTH|TIME_CACHE_SMOKE);
                                        }
                                }
                        }
                                }
                        }
                }
+               
+               /* initialise scene active layer */
+               for (scene= main->scene.first; scene; scene=scene->id.next) {
+                       int i;
+                       for(i=0; i<20; i++) {
+                               if(scene->lay & (1<<i)) {
+                                       scene->layact= 1<<i;
+                                       break;
+                               }
+                       }
+               }
+               for(tex= main->tex.first; tex; tex= tex->id.next) {
+                       /* if youre picky, this isn't correct until we do a version bump
+                        * since you could set saturation to be 0.0*/
+                       if(tex->saturation==0.0f)
+                               tex->saturation= 1.0f;
+               }
  
 +              //set defaults for recast data
 +              {
 +                      Scene *sce;
 +                      for(sce = main->scene.first; sce; sce = sce->id.next)
 +                      {
 +                              if(sce->unit.scale_length == 0.0f)
 +                                      sce->unit.scale_length= 1.0f;
 +                              if(sce->gm.recastData.cellsize == 0.0f)
 +                                      sce->gm.recastData.cellsize = 0.3f;
 +                              if(sce->gm.recastData.cellheight == 0.0f)
 +                                      sce->gm.recastData.cellheight = 0.2f;
 +                              if(sce->gm.recastData.agentmaxslope == 0.0f)
 +                                      sce->gm.recastData.agentmaxslope = M_PI/4;
 +                              if(sce->gm.recastData.agentmaxclimb == 0.0f)
 +                                      sce->gm.recastData.agentmaxclimb = 0.9f;
 +                              if(sce->gm.recastData.agentheight == 0.0f)
 +                                      sce->gm.recastData.agentheight = 2.0f;
 +                              if(sce->gm.recastData.agentradius == 0.0f)
 +                                      sce->gm.recastData.agentradius = 0.6f;
 +                              if(sce->gm.recastData.edgemaxlen == 0.0f)
 +                                      sce->gm.recastData.edgemaxlen = 12.0f;
 +                              if(sce->gm.recastData.edgemaxerror == 0.0f)
 +                                      sce->gm.recastData.edgemaxerror = 1.3f;
 +                              if(sce->gm.recastData.regionminsize == 0.0f)
 +                                      sce->gm.recastData.regionminsize = 50.f;
 +                              if(sce->gm.recastData.regionmergesize == 0.0f)
 +                                      sce->gm.recastData.regionmergesize = 20.f;
 +                              if(sce->gm.recastData.vertsperpoly<3)
 +                                      sce->gm.recastData.vertsperpoly = 6;
 +                              if(sce->gm.recastData.detailsampledist == 0.0f)
 +                                      sce->gm.recastData.detailsampledist = 6.0f;
 +                              if(sce->gm.recastData.detailsamplemaxerror == 0.0f)
 +                                      sce->gm.recastData.detailsamplemaxerror = 1.0f;
 +                      }                       
 +              }
        }
--
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
        /* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */
  
        /* don't forget to set version number in blender.c! */
  }
  
+ #if 0 // XXX: disabled for now... we still don't have this in the right place in the loading code for it to work
+ static void do_versions_after_linking(FileData *fd, Library *lib, Main *main)
+ {
+       /* old Animation System (using IPO's) needs to be converted to the new Animato system */
+       if(main->versionfile < 250)
+               do_versions_ipos_to_animato(main);
+ }
+ #endif
  static void lib_link_all(FileData *fd, Main *main)
  {
        oldnewmap_sort(fd);
@@@ -11102,6 -11116,7 +11155,7 @@@ BlendFileData *blo_read_file_internal(F
        blo_join_main(&fd->mainlist);
  
        lib_link_all(fd, bfd->main);
+       //do_versions_after_linking(fd, NULL, bfd->main); // XXX: not here (or even in this function at all)! this causes crashes on many files - Aligorith (July 04, 2010)
        lib_verify_nodetree(bfd->main, 1);
        fix_relpaths_library(fd->relabase, bfd->main); /* make all relative paths, relative to the open blend file */
        
@@@ -11822,11 -11837,6 +11876,11 @@@ static void expand_object(FileData *fd
                        bArmatureActuator *arma= act->data;
                        expand_doit(fd, mainvar, arma->target);
                }
 +              else if(act->type==ACT_STEERING) {
 +                      bSteeringActuator *sta= act->data;
 +                      expand_doit(fd, mainvar, sta->target);
 +                      expand_doit(fd, mainvar, sta->navmesh);
 +              }
                act= act->next;
        }
  
@@@ -12067,7 -12077,7 +12121,7 @@@ static void give_base_to_groups(Main *m
                        base= scene_add_base(scene, ob);
                        base->flag |= SELECT;
                        base->object->flag= base->flag;
-                       ob->recalc |= OB_RECALC;
+                       ob->recalc |= OB_RECALC_ALL;
                        scene->basact= base;
  
                        /* assign the group */
@@@ -12126,6 -12136,7 +12180,7 @@@ static void append_named_part(const bCo
                                                        ob->lay = scene->lay;
                                                }
                                        }
+                                       ob->mode= 0;
                                        base->lay= ob->lay;
                                        base->object= ob;
                                        ob->id.us++;
@@@ -12261,7 -12272,7 +12316,7 @@@ static void library_append_end(const bC
        if(flag & FILE_RELPATH) {
  
                /* use the full path, this could have been read by other library even */
-               BLI_strncpy(mainl->curlib->name, mainl->curlib->filename, sizeof(mainl->curlib->name));
+               BLI_strncpy(mainl->curlib->name, mainl->curlib->filepath, sizeof(mainl->curlib->name));
                
                /* uses current .blend file as reference */
                BLI_path_rel(mainl->curlib->name, G.sce);
@@@ -12378,10 -12389,10 +12433,10 @@@ static void read_libraries(FileData *ba
                                if(fd==NULL) {
  
                                        /* printf and reports for now... its important users know this */
-                                       BKE_reportf(basefd->reports, RPT_INFO, "read library:  '%s', '%s'\n", mainptr->curlib->filename, mainptr->curlib->name);
-                                       if(!G.background && basefd->reports) printf("read library: '%s', '%s'\n", mainptr->curlib->filename, mainptr->curlib->name);
+                                       BKE_reportf(basefd->reports, RPT_INFO, "read library:  '%s', '%s'\n", mainptr->curlib->filepath, mainptr->curlib->name);
+                                       if(!G.background && basefd->reports) printf("read library: '%s', '%s'\n", mainptr->curlib->filepath, mainptr->curlib->name);
  
-                                       fd= blo_openblenderfile(mainptr->curlib->filename, basefd->reports);
+                                       fd= blo_openblenderfile(mainptr->curlib->filepath, basefd->reports);
                                        
                                        /* allow typing in a new lib path */
                                        if(G.rt==-666) {
                                                        char newlib_path[240] = { 0 };
                                                        printf("Missing library...'\n");
                                                        printf("        current file: %s\n", G.sce);
-                                                       printf("        absolute lib: %s\n", mainptr->curlib->filename);
+                                                       printf("        absolute lib: %s\n", mainptr->curlib->filepath);
                                                        printf("        relative lib: %s\n", mainptr->curlib->name);
                                                        printf("  enter a new path:\n");
  
                                                        if(scanf("%s", newlib_path) > 0) {
                                                                strcpy(mainptr->curlib->name, newlib_path);
-                                                               strcpy(mainptr->curlib->filename, newlib_path);
-                                                               cleanup_path(G.sce, mainptr->curlib->filename);
+                                                               strcpy(mainptr->curlib->filepath, newlib_path);
+                                                               cleanup_path(G.sce, mainptr->curlib->filepath);
                                                                
-                                                               fd= blo_openblenderfile(mainptr->curlib->filename, basefd->reports);
+                                                               fd= blo_openblenderfile(mainptr->curlib->filepath, basefd->reports);
  
                                                                if(fd) {
-                                                                       printf("found: '%s', party on macuno!\n", mainptr->curlib->filename);
+                                                                       printf("found: '%s', party on macuno!\n", mainptr->curlib->filepath);
                                                                }
                                                        }
                                                }
                                        else mainptr->curlib->filedata= NULL;
  
                                        if (fd==NULL) {
-                                               BKE_reportf(basefd->reports, RPT_ERROR, "Can't find lib '%s'\n", mainptr->curlib->filename);
-                                               if(!G.background && basefd->reports) printf("ERROR: can't find lib %s \n", mainptr->curlib->filename);
+                                               BKE_reportf(basefd->reports, RPT_ERROR, "Can't find lib '%s'\n", mainptr->curlib->filepath);
+                                               if(!G.background && basefd->reports) printf("ERROR: can't find lib %s \n", mainptr->curlib->filepath);
                                        }
                                }
                                if(fd) {
  
                                                                append_id_part(fd, mainptr, id, &realid);
                                                                if (!realid) {
-                                                                       BKE_reportf(fd->reports, RPT_ERROR, "LIB ERROR: %s:'%s' missing from '%s'\n", BLO_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filename);
-                                                                       if(!G.background && basefd->reports) printf("LIB ERROR: %s:'%s' missing from '%s'\n", BLO_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filename);
+                                                                       BKE_reportf(fd->reports, RPT_ERROR, "LIB ERROR: %s:'%s' missing from '%s'\n", BLO_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
+                                                                       if(!G.background && basefd->reports) printf("LIB ERROR: %s:'%s' missing from '%s'\n", BLO_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
                                                                }
                                                                
                                                                change_idid_adr(mainlist, basefd, id, realid);
                                ID *idn= id->next;
                                if(id->flag & LIB_READ) {
                                        BLI_remlink(lbarray[a], id);
-                                       BKE_reportf(basefd->reports, RPT_ERROR, "LIB ERROR: %s:'%s' unread libblock missing from '%s'\n", BLO_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filename);
-                                       if(!G.background && basefd->reports)printf("LIB ERROR: %s:'%s' unread libblock missing from '%s'\n", BLO_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filename);
+                                       BKE_reportf(basefd->reports, RPT_ERROR, "LIB ERROR: %s:'%s' unread libblock missing from '%s'\n", BLO_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
+                                       if(!G.background && basefd->reports)printf("LIB ERROR: %s:'%s' unread libblock missing from '%s'\n", BLO_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
                                        change_idid_adr(mainlist, basefd, id, NULL);
  
                                        MEM_freeN(id);
@@@ -859,9 -859,6 +859,9 @@@ static void write_actuators(WriteData *
                case ACT_ARMATURE:
                        writestruct(wd, DATA, "bArmatureActuator", 1, act->data);
                        break;
 +              case ACT_STEERING:
 +                      writestruct(wd, DATA, "bSteeringActuator", 1, act->data);
 +                      break;
                default:
                        ; /* error: don't know how to write this file */
                }
@@@ -2484,7 -2481,7 +2484,7 @@@ int BLO_write_file(Main *mainvar, char 
  
        file = open(tempname,O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666);
        if(file == -1) {
-               BKE_report(reports, RPT_ERROR, "Unable to open file for writing.");
+               BKE_reportf(reports, RPT_ERROR, "Can't open file for writing: %s.", strerror(errno));
                return 0;
        }
  
                        makeFilesAbsolute(G.sce, NULL);
        }
  
-       BLI_make_file_string(G.sce, userfilename, BLI_gethome(), ".B25.blend");
+       BLI_make_file_string(G.sce, userfilename, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_STARTUP_FILE);
        write_user_block= BLI_streq(dir, userfilename);
  
        if(write_flags & G_FILE_RELATIVE_REMAP)
@@@ -84,11 -84,11 +84,11 @@@ void ED_object_enter_editmode(struct bC
  void ED_object_location_from_view(struct bContext *C, float *loc);
  void ED_object_rotation_from_view(struct bContext *C, float *rot);
  void ED_object_base_init_transform(struct bContext *C, struct Base *base, float *loc, float *rot);
- float ED_object_new_primitive_matrix(struct bContext *C, float *loc, float *rot, float primmat[][4]);
+ float ED_object_new_primitive_matrix(struct bContext *C, struct Object *editob, float *loc, float *rot, float primmat[][4]);
  
  void ED_object_add_generic_props(struct wmOperatorType *ot, int do_editmode);
  int ED_object_add_generic_invoke(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
void ED_object_add_generic_get_opts(struct bContext *C, struct wmOperator *op, float *loc, float *rot, int *enter_editmode, unsigned int *layer);
int ED_object_add_generic_get_opts(struct bContext *C, struct wmOperator *op, float *loc, float *rot, int *enter_editmode, unsigned int *layer);
  struct Object *ED_object_add_type(struct bContext *C, int type, float *loc, float *rot, int enter_editmode, unsigned int layer);
  
  void ED_object_single_users(struct Scene *scene, int full);
@@@ -124,7 -124,7 +124,7 @@@ void ED_setflagsLatt(struct Object *obe
  enum {
        MODIFIER_APPLY_DATA=1,
        MODIFIER_APPLY_SHAPE,
 -} eModifier_Apply_Mode;
 +};//eModifier_Apply_Mode
  
  struct ModifierData *ED_object_modifier_add(struct ReportList *reports, struct Scene *scene, struct Object *ob, char *name, int type);
  int ED_object_modifier_remove(struct ReportList *reports, struct Scene *scene, struct Object *ob, struct ModifierData *md);
@@@ -88,6 -88,7 +88,7 @@@ void OBJECT_OT_paths_clear(struct wmOpe
  void OBJECT_OT_game_property_new(struct wmOperatorType *ot);
  void OBJECT_OT_game_property_remove(struct wmOperatorType *ot);
  void OBJECT_OT_game_property_copy(struct wmOperatorType *ot);
+ void OBJECT_OT_game_property_clear(struct wmOperatorType *ot);
  void OBJECT_OT_logic_bricks_copy(struct wmOperatorType *ot);
  
  /* object_select.c */
@@@ -105,7 -106,6 +106,6 @@@ void OBJECT_OT_select_same_group(struc
  /* object_add.c */
  void OBJECT_OT_add(struct wmOperatorType *ot);
  void OBJECT_OT_add_named(struct wmOperatorType *ot);
- void OBJECT_OT_surface_add(struct wmOperatorType *ot);
  void OBJECT_OT_metaball_add(struct wmOperatorType *ot);
  void OBJECT_OT_text_add(struct wmOperatorType *ot);
  void OBJECT_OT_armature_add(struct wmOperatorType *ot);
@@@ -156,8 -156,8 +156,8 @@@ void OBJECT_OT_modifier_copy(struct wmO
  void OBJECT_OT_multires_subdivide(struct wmOperatorType *ot);
  void OBJECT_OT_multires_reshape(struct wmOperatorType *ot);
  void OBJECT_OT_multires_higher_levels_delete(struct wmOperatorType *ot);
- void OBJECT_OT_multires_save_external(struct wmOperatorType *ot);
- void OBJECT_OT_multires_pack_external(struct wmOperatorType *ot);
+ void OBJECT_OT_multires_external_save(struct wmOperatorType *ot);
+ void OBJECT_OT_multires_external_pack(struct wmOperatorType *ot);
  void OBJECT_OT_meshdeform_bind(struct wmOperatorType *ot);
  void OBJECT_OT_explode_refresh(struct wmOperatorType *ot);
  
@@@ -222,8 -222,5 +222,8 @@@ void OBJECT_OT_group_remove(struct wmOp
  /* object_bake.c */
  void OBJECT_OT_bake_image(wmOperatorType *ot);
  
 +/* object_navmesh.cpp */
 +void OBJECT_OT_create_navmesh(struct wmOperatorType *ot);
 +
  #endif /* ED_OBJECT_INTERN_H */
  
@@@ -113,7 -113,6 +113,6 @@@ void ED_operatortypes_object(void
  
        WM_operatortype_append(OBJECT_OT_delete);
        WM_operatortype_append(OBJECT_OT_text_add);
-       WM_operatortype_append(OBJECT_OT_surface_add);
        WM_operatortype_append(OBJECT_OT_armature_add);
        WM_operatortype_append(OBJECT_OT_lamp_add);
        WM_operatortype_append(OBJECT_OT_camera_add);
        WM_operatortype_append(OBJECT_OT_multires_subdivide);
        WM_operatortype_append(OBJECT_OT_multires_reshape);
        WM_operatortype_append(OBJECT_OT_multires_higher_levels_delete);
-       WM_operatortype_append(OBJECT_OT_multires_save_external);
-       WM_operatortype_append(OBJECT_OT_multires_pack_external);
+       WM_operatortype_append(OBJECT_OT_multires_external_save);
+       WM_operatortype_append(OBJECT_OT_multires_external_pack);
        WM_operatortype_append(OBJECT_OT_meshdeform_bind);
        WM_operatortype_append(OBJECT_OT_explode_refresh);
        
        WM_operatortype_append(OBJECT_OT_game_property_new);
        WM_operatortype_append(OBJECT_OT_game_property_remove);
        WM_operatortype_append(OBJECT_OT_game_property_copy);
+       WM_operatortype_append(OBJECT_OT_game_property_clear);
        WM_operatortype_append(OBJECT_OT_logic_bricks_copy);
  
        WM_operatortype_append(OBJECT_OT_shape_key_add);
  
        WM_operatortype_append(OBJECT_OT_bake_image);
        WM_operatortype_append(OBJECT_OT_drop_named_material);
 +
 +      WM_operatortype_append(OBJECT_OT_create_navmesh);
  }
  
  void ED_operatormacros_object(void)
@@@ -389,17 -387,17 +389,17 @@@ void ED_object_generic_keymap(struct wm
        if(do_pet > 0) {
                /* context ops */
                kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_enum", OKEY, KM_PRESS, KM_SHIFT, 0);
-               RNA_string_set(kmi->ptr, "path", "tool_settings.proportional_editing_falloff");
+               RNA_string_set(kmi->ptr, "data_path", "tool_settings.proportional_editing_falloff");
  
                kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle_enum", OKEY, KM_PRESS, 0, 0);
-               RNA_string_set(kmi->ptr, "path", "tool_settings.proportional_editing");
+               RNA_string_set(kmi->ptr, "data_path", "tool_settings.proportional_editing");
                RNA_string_set(kmi->ptr, "value_1", "DISABLED");
                RNA_string_set(kmi->ptr, "value_2", "ENABLED");
  
                /* for modes/object types that allow 'conencted' mode, add the Alt O key */
                if (do_pet > 1) {
                        kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle_enum", OKEY, KM_PRESS, KM_ALT, 0);
-                       RNA_string_set(kmi->ptr, "path", "tool_settings.proportional_editing");
+                       RNA_string_set(kmi->ptr, "data_path", "tool_settings.proportional_editing");
                        RNA_string_set(kmi->ptr, "value_1", "DISABLED");
                        RNA_string_set(kmi->ptr, "value_2", "CONNECTED");
                }
@@@ -194,8 -194,9 +194,9 @@@ static void make_unique_prop_names_cb(b
  }
  
  
- static void sca_move_sensor(bContext *C, void *datav, void *move_up)
+ static void old_sca_move_sensor(bContext *C, void *datav, void *move_up)
  {
+       /* deprecated, no longer using it (moved to sca.c) */
        Scene *scene= CTX_data_scene(C);
        bSensor *sens_to_delete= datav;
        int val;
        }
  }
  
- static void sca_move_controller(bContext *C, void *datav, void *move_up)
+ static void old_sca_move_controller(bContext *C, void *datav, void *move_up)
  {
+       /* deprecated, no longer using it (moved to sca.c) */
        Scene *scene= CTX_data_scene(C);
        bController *controller_to_del= datav;
        int val;
        }
  }
  
- static void sca_move_actuator(bContext *C, void *datav, void *move_up)
+ static void old_sca_move_actuator(bContext *C, void *datav, void *move_up)
  {
+       /* deprecated, no longer using it (moved to sca.c) */
        Scene *scene= CTX_data_scene(C);
        bActuator *actuator_to_move= datav;
        int val;
@@@ -710,8 -713,6 +713,8 @@@ static char *actuator_name(int type
                return "State";
        case ACT_ARMATURE:
                return "Armature";
 +      case ACT_STEERING:
 +              return "Steering";
        }
        return "unknown";
  }
@@@ -2897,6 -2898,7 +2900,6 @@@ static short draw_actuatorbuttons(Objec
                uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
                  yco-= ysize; 
                  break; 
 -
         default:
                ysize= 4;
  
@@@ -3173,9 -3175,9 +3176,9 @@@ static int is_sensor_linked(uiBlock *bl
  
  /* Sensors code */
  
- static void draw_sensor_header(uiLayout *layout, PointerRNA *ptr)
+ static void draw_sensor_header(uiLayout *layout, PointerRNA *ptr, PointerRNA *logic_ptr)
  {
-       uiLayout *box, *row;
+       uiLayout *box, *row, *subrow;
        
        box= uiLayoutBox(layout);
        row= uiLayoutRow(box, 0);
        uiItemR(row, ptr, "expanded", UI_ITEM_R_NO_BG, "", 0);
        uiItemR(row, ptr, "type", 0, "", 0);
        uiItemR(row, ptr, "name", 0, "", 0);
+       subrow= uiLayoutRow(row, 0);
+       uiLayoutSetActive(subrow, ((RNA_boolean_get(logic_ptr, "sensors_show_active_states")
+                                                       && RNA_boolean_get(ptr, "expanded")) || RNA_boolean_get(ptr, "pinned")));
+       uiItemR(subrow, ptr, "pinned", UI_ITEM_R_NO_BG, "", 0);
+       if(RNA_boolean_get(ptr, "expanded")==0) {
+               uiItemEnumO(row, "LOGIC_OT_sensor_move", "", ICON_TRIA_UP, "direction", 1); // up
+               uiItemEnumO(row, "LOGIC_OT_sensor_move", "", ICON_TRIA_DOWN, "direction", 2); // down
+       }
        uiItemO(row, "", ICON_X, "LOGIC_OT_sensor_remove");
  }
  
@@@ -3246,9 -3259,12 +3260,12 @@@ static void draw_sensor_armature(uiLayo
        uiItemR(row, ptr, "value", 0, NULL, 0);
  }
  
- static void draw_sensor_collision(uiLayout *layout, PointerRNA *ptr)
+ static void draw_sensor_collision(uiLayout *layout, PointerRNA *ptr, bContext *C)
  {
        uiLayout *row, *split;
+       PointerRNA main_ptr;
+       RNA_main_pointer_create(CTX_data_main(C), &main_ptr);
  
        split = uiLayoutSplit(layout, 0.3, 0);
        row = uiLayoutRow(split, 1);
                        uiItemR(split, ptr, "property", 0, NULL, 0);
                        break;
                case SENS_COLLISION_MATERIAL:
-                       uiItemR(split, ptr, "material", 0, NULL, 0);
+                       uiItemPointerR(split, ptr, "material", &main_ptr, "materials", NULL, ICON_MATERIAL_DATA);
                        break;
        }
  }
@@@ -3344,9 -3360,6 +3361,6 @@@ static void draw_sensor_keyboard(uiLayo
        RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
        uiItemPointerR(layout, ptr, "target", &settings_ptr, "properties", NULL, 0);
        uiItemPointerR(layout, ptr, "log", &settings_ptr, "properties", NULL, 0);
- //    uiItemR(layout, ptr, "target", 0, NULL, 0);
- //    uiItemR(layout, ptr, "log", 0, NULL, 0);
  }
  
  static void draw_sensor_message(uiLayout *layout, PointerRNA *ptr)
@@@ -3415,17 -3428,21 +3429,21 @@@ static void draw_sensor_random(uiLayou
        uiItemR(layout, ptr, "seed", 0, NULL, 0);
  }
  
- static void draw_sensor_ray(uiLayout *layout, PointerRNA *ptr)
+ static void draw_sensor_ray(uiLayout *layout, PointerRNA *ptr, bContext *C)
  {
        uiLayout *split, *row;
+       PointerRNA main_ptr;
  
+       RNA_main_pointer_create(CTX_data_main(C), &main_ptr);
        split= uiLayoutSplit(layout, 0.3, 0);
        uiItemR(split, ptr, "ray_type", 0, "", 0);
        switch (RNA_enum_get(ptr, "ray_type")) {
                case SENS_RAY_PROPERTY:
-                       uiItemR(split, ptr, "property", 0, "", 0); break;
+                       uiItemR(split, ptr, "property", 0, "", 0);
+                       break;
                case SENS_RAY_MATERIAL:
-                       uiItemR(split, ptr, "material", 0, "", 0); break;
+                       uiItemPointerR(split, ptr, "material", &main_ptr, "materials", "", ICON_MATERIAL_DATA);
+                       break;
        }
  
        split= uiLayoutSplit(layout, 0.3, 0);
@@@ -3440,7 -3457,7 +3458,7 @@@ static void draw_sensor_touch(uiLayout 
        uiItemR(layout, ptr, "material", 0, NULL, 0);
  }
  
- void draw_brick_sensor(uiLayout *layout, PointerRNA *ptr)
+ void draw_brick_sensor(uiLayout *layout, PointerRNA *ptr, bContext *C)
  {
        uiLayout *box;
        
                        draw_sensor_armature(box, ptr);
                        break;
                case SENS_COLLISION:
-                       draw_sensor_collision(box, ptr);
+                       draw_sensor_collision(box, ptr, C);
                        break;
                case SENS_DELAY:
                        draw_sensor_delay(box, ptr);
                        draw_sensor_random(box, ptr);
                        break;
                case SENS_RAY:
-                       draw_sensor_ray(box, ptr);
+                       draw_sensor_ray(box, ptr, C);
                        break;
                case SENS_TOUCH:
                        draw_sensor_touch(box, ptr);
  static void draw_controller_header(uiLayout *layout, PointerRNA *ptr)
  {
        uiLayout *box, *row;
+       char name[3]; //XXX provisorly for state number
        
        box= uiLayoutBox(layout);
        row= uiLayoutRow(box, 0);
        uiItemR(row, ptr, "expanded", UI_ITEM_R_NO_BG, "", 0);
        uiItemR(row, ptr, "type", 0, "", 0);
        uiItemR(row, ptr, "name", 0, "", 0);
+       /* XXX provisory: state number */
+       sprintf(name, "%d", RNA_int_get(ptr, "state_number"));
+       uiItemL(row, name, 0);
        uiItemR(row, ptr, "priority", 0, "", 0);
+       if(RNA_boolean_get(ptr, "expanded")==0) {
+               uiItemEnumO(row, "LOGIC_OT_controller_move", "", ICON_TRIA_UP, "direction", 1); // up
+               uiItemEnumO(row, "LOGIC_OT_controller_move", "", ICON_TRIA_DOWN, "direction", 2); // down
+       }
        uiItemO(row, "", ICON_X, "LOGIC_OT_controller_remove");
  }
  
@@@ -3575,9 -3603,9 +3604,9 @@@ void draw_brick_controller(uiLayout *la
  }
  
  /* Actuator code */
- static void draw_actuator_header(uiLayout *layout, PointerRNA *ptr)
+ static void draw_actuator_header(uiLayout *layout, PointerRNA *ptr, PointerRNA *logic_ptr)
  {
-       uiLayout *box, *row;
+       uiLayout *box, *row, *subrow;
        
        box= uiLayoutBox(layout);
        row= uiLayoutRow(box, 0);
        uiItemR(row, ptr, "expanded", UI_ITEM_R_NO_BG, "", 0);
        uiItemR(row, ptr, "type", 0, "", 0);
        uiItemR(row, ptr, "name", 0, "", 0);
+       subrow= uiLayoutRow(row, 0);
+       uiLayoutSetActive(subrow, ((RNA_boolean_get(logic_ptr, "actuators_show_active_states")
+                                                       && RNA_boolean_get(ptr, "expanded")) || RNA_boolean_get(ptr, "pinned")));
+       uiItemR(subrow, ptr, "pinned", UI_ITEM_R_NO_BG, "", 0);
+       if(RNA_boolean_get(ptr, "expanded")==0) {
+               uiItemEnumO(row, "LOGIC_OT_actuator_move", "", ICON_TRIA_UP, "direction", 1); // up
+               uiItemEnumO(row, "LOGIC_OT_actuator_move", "", ICON_TRIA_DOWN, "direction", 2); // down
+       }
        uiItemO(row, "", ICON_X, "LOGIC_OT_actuator_remove");
  }
  
@@@ -3697,9 -3735,12 +3736,12 @@@ static void draw_actuator_camera(uiLayo
        uiItemR(row, ptr, "max", 0, NULL, 0);
  }
  
- static void draw_actuator_constraint(uiLayout *layout, PointerRNA *ptr)
+ static void draw_actuator_constraint(uiLayout *layout, PointerRNA *ptr, bContext *C)
  {
        uiLayout *row, *col, *subcol, *split;
+       PointerRNA main_ptr;
+       RNA_main_pointer_create(CTX_data_main(C), &main_ptr);
  
        uiItemR(layout, ptr, "mode", 0, NULL, 0);
        switch (RNA_enum_get(ptr, "mode"))
                        split = uiLayoutSplit(layout, 0.15, 0);
                        uiItemR(split, ptr, "detect_material", UI_ITEM_R_TOGGLE, NULL, 0);
                        if (RNA_boolean_get(ptr, "detect_material"))
-                               uiItemR(split, ptr, "material", 0, NULL, 0);
+                               uiItemPointerR(split, ptr, "material", &main_ptr, "materials", NULL, ICON_MATERIAL_DATA);
                        else
                                uiItemR(split, ptr, "property", 0, NULL, 0);
  
                        split = uiLayoutSplit(layout, 0.15, 0);
                        uiItemR(split, ptr, "detect_material", UI_ITEM_R_TOGGLE, NULL, 0);
                        if (RNA_boolean_get(ptr, "detect_material"))
-                               uiItemR(split, ptr, "material", 0, NULL, 0);
+                               uiItemPointerR(split, ptr, "material", &main_ptr, "materials", NULL, ICON_MATERIAL_DATA);
                        else
                                uiItemR(split, ptr, "property", 0, NULL, 0);
  
@@@ -3914,16 -3955,18 +3956,18 @@@ static void draw_actuator_ipo(uiLayout 
        uiItemPointerR(row, ptr, "frame_property", &settings_ptr, "properties", NULL, 0);
  }
  
- static void draw_actuator_message(uiLayout *layout, PointerRNA *ptr)
+ static void draw_actuator_message(uiLayout *layout, PointerRNA *ptr, bContext *C)
  {
        Object *ob;
-       PointerRNA settings_ptr;
+       PointerRNA main_ptr, settings_ptr;
        uiLayout *row;
  
+       RNA_main_pointer_create(CTX_data_main(C), &main_ptr);
        ob = (Object *)ptr->id.data;
        RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
  
-       uiItemR(layout, ptr, "to_property", 0, NULL, 0);
+       uiItemPointerR(layout, ptr, "to_property", &main_ptr, "objects", NULL, ICON_OBJECT_DATA);
        uiItemR(layout, ptr, "subject", 0, NULL, 0);
  
        row= uiLayoutRow(layout, 1);
@@@ -3940,9 -3983,11 +3984,11 @@@ static void draw_actuator_motion(uiLayo
        Object *ob;
        PointerRNA settings_ptr;
        uiLayout *split, *row, *col, *subcol;
+       int physics_type;
  
        ob = (Object *)ptr->id.data;    
        RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
+       physics_type = RNA_enum_get(&settings_ptr, "physics_type");
        
        uiItemR(layout, ptr, "mode", 0, NULL, 0);
        
                        uiItemR(row, ptr, "rot", 0, NULL, 0);
                        uiItemR(split, ptr, "local_rotation", UI_ITEM_R_TOGGLE, NULL, 0);
                        
-                       if (RNA_enum_get(&settings_ptr, "physics_type") != OB_BODY_TYPE_DYNAMIC)
-                               break;
-                       
-                       uiItemL(layout, "Dynamic Object Settings:", 0);
-                       split = uiLayoutSplit(layout, 0.9, 0);
-                       row = uiLayoutRow(split, 0);
-                       uiItemR(row, ptr, "force", 0, NULL, 0);
-                       uiItemR(split, ptr, "local_force", UI_ITEM_R_TOGGLE, NULL, 0);
-                       split = uiLayoutSplit(layout, 0.9, 0);
-                       row = uiLayoutRow(split, 0);
-                       uiItemR(row, ptr, "torque", 0, NULL, 0);
-                       uiItemR(split, ptr, "local_torque", UI_ITEM_R_TOGGLE, NULL, 0);
-                       split = uiLayoutSplit(layout, 0.9, 0);
-                       row = uiLayoutRow(split, 0);
-                       uiItemR(row, ptr, "linear_velocity", 0, NULL, 0);
-                       row = uiLayoutRow(split, 1);
-                       uiItemR(row, ptr, "local_linear_velocity", UI_ITEM_R_TOGGLE, NULL, 0);
-                       uiItemR(row, ptr, "add_linear_velocity", UI_ITEM_R_TOGGLE, NULL, 0);
-                       split = uiLayoutSplit(layout, 0.9, 0);
-                       row = uiLayoutRow(split, 0);
-                       uiItemR(row, ptr, "angular_velocity", 0, NULL, 0);
-                       uiItemR(split, ptr, "local_angular_velocity", UI_ITEM_R_TOGGLE, NULL, 0);
-                       uiItemR(layout, ptr, "damping", 0, NULL, 0);
+                       if (ELEM3(physics_type, OB_BODY_TYPE_DYNAMIC, OB_BODY_TYPE_RIGID, OB_BODY_TYPE_SOFT)) {                 
+                               uiItemL(layout, "Dynamic Object Settings:", 0);
+                               split = uiLayoutSplit(layout, 0.9, 0);
+                               row = uiLayoutRow(split, 0);
+                               uiItemR(row, ptr, "force", 0, NULL, 0);
+                               uiItemR(split, ptr, "local_force", UI_ITEM_R_TOGGLE, NULL, 0);
+                               split = uiLayoutSplit(layout, 0.9, 0);
+                               row = uiLayoutRow(split, 0);
+                               uiItemR(row, ptr, "torque", 0, NULL, 0);
+                               uiItemR(split, ptr, "local_torque", UI_ITEM_R_TOGGLE, NULL, 0);
+                               split = uiLayoutSplit(layout, 0.9, 0);
+                               row = uiLayoutRow(split, 0);
+                               uiItemR(row, ptr, "linear_velocity", 0, NULL, 0);
+                               row = uiLayoutRow(split, 1);
+                               uiItemR(row, ptr, "local_linear_velocity", UI_ITEM_R_TOGGLE, NULL, 0);
+                               uiItemR(row, ptr, "add_linear_velocity", UI_ITEM_R_TOGGLE, NULL, 0);
+                               split = uiLayoutSplit(layout, 0.9, 0);
+                               row = uiLayoutRow(split, 0);
+                               uiItemR(row, ptr, "angular_velocity", 0, NULL, 0);
+                               uiItemR(split, ptr, "local_angular_velocity", UI_ITEM_R_TOGGLE, NULL, 0);
+                               uiItemR(layout, ptr, "damping", 0, NULL, 0);
+                       }
                        break;
                case ACT_OBJECT_SERVO:
                        uiItemR(layout, ptr, "reference_object", 0, NULL, 0);
@@@ -4262,27 -4306,6 +4307,27 @@@ static void draw_actuator_visibility(ui
        uiItemR(row, ptr, "children", 0, NULL, 0);
  }
  
 +static void draw_actuator_steering(uiLayout *layout, PointerRNA *ptr)
 +{
 +      uiLayout *row;
 +
 +      uiItemR(layout, ptr, "mode", 0, NULL, 0);
 +      uiItemR(layout, ptr, "target", 0, NULL, 0);
 +      uiItemR(layout, ptr, "navmesh", 0, NULL, 0);    
 +
 +      row = uiLayoutRow(layout, 0);
 +      uiItemR(row, ptr, "distance", 0, NULL, 0);
 +      uiItemR(row, ptr, "velocity", 0, NULL, 0);
 +      row = uiLayoutRow(layout, 0);
 +      uiItemR(row, ptr, "acceleration", 0, NULL, 0);
 +      uiItemR(row, ptr, "turnspeed", 0, NULL, 0);
 +      row = uiLayoutRow(layout, 0);
 +      uiItemR(row, ptr, "selfterminated", 0, NULL, 0);
 +      if (RNA_enum_get(ptr, "mode")==ACT_STEERING_PATHFOLLOWING)
 +              uiItemR(row, ptr, "updateperiod", 0, NULL, 0);  
 +}
 +
 +
  void draw_brick_actuator(uiLayout *layout, PointerRNA *ptr, bContext *C)
  {
        uiLayout *box;
                        draw_actuator_camera(box, ptr);
                        break;
                case ACT_CONSTRAINT:
-                       draw_actuator_constraint(box, ptr);
+                       draw_actuator_constraint(box, ptr, C);
                        break;
                case ACT_EDIT_OBJECT:
                        draw_actuator_edit_object(box, ptr);
                        draw_actuator_ipo(box, ptr);
                        break;
                case ACT_MESSAGE:
-                       draw_actuator_message(box, ptr);
+                       draw_actuator_message(box, ptr, C);
                        break;
                case ACT_OBJECT:
                        draw_actuator_motion(box, ptr);
                case ACT_VISIBILITY:
                        draw_actuator_visibility(box, ptr);
                        break;
 +              case ACT_STEERING:
 +                      draw_actuator_steering(box, ptr);
        }
  }
  
@@@ -4360,7 -4381,7 +4405,7 @@@ static void logic_buttons_new(bContext 
        
        PointerRNA logic_ptr, settings_ptr;
        
-       uiLayout *layout, *row, *split, *subsplit, *box, *col;
+       uiLayout *layout, *row, *box;
        uiBlock *block;
        uiBut *but;
        char name[32];
        block= uiBeginBlock(C, ar, name, UI_EMBOSS);
        uiBlockSetHandleFunc(block, do_logic_buts, NULL);
        
-       /* clean ACT_LINKED and ACT_VISIBLE of all potentially visible actuators so that 
-        we can determine which is actually linked/visible */
+       /* loop over all objects and set visible/linked flags for the logic bricks */
        for(a=0; a<count; a++) {
                bActuator *act;
                bSensor *sens;
+               bController *cont;
+               int iact;
+               short flag;
                ob= (Object *)idar[a];
                
+               /* clean ACT_LINKED and ACT_VISIBLE of all potentially visible actuators so that we can determine which is actually linked/visible */
                act = ob->actuators.first;
                while(act) {
                        act->flag &= ~(ACT_LINKED|ACT_VISIBLE);
                        sens->flag &= ~(SENS_VISIBLE);
                        sens = sens->next;
                }
+               /* mark the linked and visible actuators */
+               cont= ob->controllers.first;
+               while(cont) {
+                       flag = ACT_LINKED;
+                       /* this controller is visible, mark all its actuator */
+                       if ((ob->scaflag & OB_ALLSTATE) || (ob->state & cont->state_mask))
+                               flag |= ACT_VISIBLE;
+                       for (iact=0; iact<cont->totlinks; iact++) {
+                               act = cont->links[iact];
+                               if (act)
+                                       act->flag |= flag;
+                       }
+                       cont = cont->next;
+               }
        }
        
        /* ****************** Controllers ****************** */
        layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, xco, yco, width, 20, U.uistyles.first);
        row = uiLayoutRow(layout, 1);
        
-       uiDefBlockBut(block, controller_menu, NULL, "Controllers", xco-10, yco, 70, UI_UNIT_Y, "");             /* replace this with uiLayout stuff later */
+       uiDefBlockBut(block, controller_menu, NULL, "Controllers", xco-10, yco, 300, UI_UNIT_Y, "");            /* replace this with uiLayout stuff later */
        
        uiItemR(row, &logic_ptr, "controllers_show_selected_objects", 0, "Sel", 0);
        uiItemR(row, &logic_ptr, "controllers_show_active_objects", 0, "Act", 0);
        uiItemR(row, &logic_ptr, "controllers_show_linked_controller", 0, "Link", 0);
  
-       RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
-       split= uiLayoutSplit(layout, 0.05, 0);
-       uiItemR(split, &settings_ptr, "show_state_panel", UI_ITEM_R_NO_BG, "", ICON_DISCLOSURE_TRI_RIGHT);
-       row = uiLayoutRow(split, 1);
-       uiDefButBitS(block, TOG, OB_SHOWCONT, B_REDR, ob->id.name+2,(short)(xco-10), yco, (short)(width-30), UI_UNIT_Y, &ob->scaflag, 0, 31, 0, 0, "Object name, click to show/hide controllers");
-       uiItemMenuEnumO(row, "LOGIC_OT_controller_add", "type", "Add Controller", 0);
-       if (RNA_boolean_get(&settings_ptr, "show_state_panel")) {
-               box= uiLayoutBox(layout);
-               uiLayoutSetAlignment(box, UI_LAYOUT_ALIGN_CENTER); //XXX doesn't seem to work
-               split= uiLayoutSplit(box, 0.2, 0);
-               col= uiLayoutColumn(split, 0);
-               uiItemL(col, "Visible", 0);
-               uiItemL(col, "Initial", 0);
-               subsplit= uiLayoutSplit(split, 0.85, 0);
-               col= uiLayoutColumn(subsplit, 0);
-               row= uiLayoutRow(col, 0);
-               uiLayoutSetActive(row, RNA_boolean_get(&settings_ptr, "all_states")==0);
-               uiTemplateLayers(row, &settings_ptr, "state", &settings_ptr, "used_state", 0);
-               row= uiLayoutRow(col, 0);
-               uiTemplateLayers(row, &settings_ptr, "initial_state", &settings_ptr, "used_state", 0);
-               col= uiLayoutColumn(subsplit, 0);
-               uiItemR(col, &settings_ptr, "all_states", UI_ITEM_R_TOGGLE, NULL, 0);
-               uiItemR(col, &settings_ptr, "debug_state", 0, "", 0); 
-       }
        for(a=0; a<count; a++) {
                bController *cont;
                PointerRNA ptr;
                uiLayout *split, *subsplit, *col;
-               int iact;
                
                ob= (Object *)idar[a];
+               /* only draw the controller common header if "visible" */
+               if( (ob->scavisflag & OB_VIS_CONT) == 0) continue;
+       
+               /* Drawing the Controller Header common to all Selected Objects */
+               RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
+               split= uiLayoutSplit(layout, 0.05, 0);
+               uiItemR(split, &settings_ptr, "show_state_panel", UI_ITEM_R_NO_BG, "", ICON_DISCLOSURE_TRI_RIGHT);
+               row = uiLayoutRow(split, 1);
+               uiDefButBitS(block, TOG, OB_SHOWCONT, B_REDR, ob->id.name+2,(short)(xco-10), yco, (short)(width-30), UI_UNIT_Y, &ob->scaflag, 0, 31, 0, 0, "Object name, click to show/hide controllers");
+               uiItemMenuEnumO(row, "LOGIC_OT_controller_add", "type", "Add Controller", 0);
+               if (RNA_boolean_get(&settings_ptr, "show_state_panel")) {
+                       box= uiLayoutBox(layout);
+                       split= uiLayoutSplit(box, 0.2, 0);
+                       col= uiLayoutColumn(split, 0);
+                       uiItemL(col, "Visible", 0);
+                       uiItemL(col, "Initial", 0);
+                       subsplit= uiLayoutSplit(split, 0.85, 0);
+                       col= uiLayoutColumn(subsplit, 0);
+                       row= uiLayoutRow(col, 0);
+                       uiLayoutSetActive(row, RNA_boolean_get(&settings_ptr, "all_states")==0);
+                       uiTemplateLayers(row, &settings_ptr, "visible_state", &settings_ptr, "used_state", 0);
+                       row= uiLayoutRow(col, 0);
+                       uiTemplateLayers(row, &settings_ptr, "initial_state", &settings_ptr, "used_state", 0);
+                       col= uiLayoutColumn(subsplit, 0);
+                       uiItemR(col, &settings_ptr, "all_states", UI_ITEM_R_TOGGLE, NULL, 0);
+                       uiItemR(col, &settings_ptr, "debug_state", 0, "", 0); 
+               }
+               /* End of Drawing the Controller Header common to all Selected Objects */
+               if ((ob->scaflag & OB_SHOWCONT) == 0) continue;
                
-               if (!(ob->scavisflag & OB_VIS_CONT) || !(ob->scaflag & OB_SHOWCONT)) continue;
-               
                uiItemS(layout);
                
                for(cont= ob->controllers.first; cont; cont=cont->next) {
                        
                        if (!(ob->scaflag & OB_ALLSTATE) && !(ob->state & cont->state_mask))
                                continue;
-                       //if (!(cont->state_mask & (1<<stbit))) 
-                       //      continue;
-                       
-                       /* this controller is visible, mark all its actuator */
-                       /* XXX: perhaps move this to a preprocessing stage if possible? */
-                       for (iact=0; iact<cont->totlinks; iact++) {
-                               bActuator *act = cont->links[iact];
-                               if (act)
-                                       act->flag |= ACT_VISIBLE;
-                       }
                        
                        /* use two nested splits to align inlinks/links properly */
                        split = uiLayoutSplit(layout, 0.05, 0);
        layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, xco, yco, width, 20, U.uistyles.first);
        row = uiLayoutRow(layout, 1);
        
-       uiDefBlockBut(block, sensor_menu, NULL, "Sensors", xco-10, yco, 70, UI_UNIT_Y, "");             /* replace this with uiLayout stuff later */
+       uiDefBlockBut(block, sensor_menu, NULL, "Sensors", xco-10, yco, 300, UI_UNIT_Y, "");            /* replace this with uiLayout stuff later */
        
        uiItemR(row, &logic_ptr, "sensors_show_selected_objects", 0, "Sel", 0);
        uiItemR(row, &logic_ptr, "sensors_show_active_objects", 0, "Act", 0);
        uiItemR(row, &logic_ptr, "sensors_show_linked_controller", 0, "Link", 0);
        uiItemR(row, &logic_ptr, "sensors_show_active_states", 0, "State", 0);
        
-       row = uiLayoutRow(layout, 1);
-       uiDefButBitS(block, TOG, OB_SHOWSENS, B_REDR, ob->id.name+2,(short)(xco-10), yco, (short)(width-30), UI_UNIT_Y, &ob->scaflag, 0, 31, 0, 0, "Object name, click to show/hide sensors");
-       uiItemMenuEnumO(row, "LOGIC_OT_sensor_add", "type", "Add Sensor", 0);
-       
        for(a=0; a<count; a++) {
                bSensor *sens;
                PointerRNA ptr;
                
                ob= (Object *)idar[a];
+               /* only draw the sensor common header if "visible" */
+               if((ob->scavisflag & OB_VIS_SENS) == 0) continue;
+               row = uiLayoutRow(layout, 1);
+               uiDefButBitS(block, TOG, OB_SHOWSENS, B_REDR, ob->id.name+2,(short)(xco-10), yco, (short)(width-30), UI_UNIT_Y, &ob->scaflag, 0, 31, 0, 0, "Object name, click to show/hide sensors");
+               uiItemMenuEnumO(row, "LOGIC_OT_sensor_add", "type", "Add Sensor", 0);
                
-               if (!(ob->scavisflag & OB_VIS_SENS) || !(ob->scaflag & OB_SHOWSENS)) continue;
+               if ((ob->scaflag & OB_SHOWSENS) == 0) continue;
                
                uiItemS(layout);
                
                        RNA_pointer_create((ID *)ob, &RNA_Sensor, sens, &ptr);
                        
                        if ((ob->scaflag & OB_ALLSTATE) ||
-                               (slogic->scaflag & BUTS_SENS_STATE) ||
+                               !(slogic->scaflag & BUTS_SENS_STATE) ||
                                (sens->totlinks == 0) ||                                                                                        /* always display sensor without links so that is can be edited */
                                (sens->flag & SENS_PIN && slogic->scaflag & BUTS_SENS_STATE) || /* states can hide some sensors, pinned sensors ignore the visible state */
                                (is_sensor_linked(block, sens))
                        {       // gotta check if the current state is visible or not
                                uiLayout *split, *col;
                                
+                               /* make as visible, for move operator */
+                               sens->flag |= SENS_VISIBLE;
                                split = uiLayoutSplit(layout, 0.95, 0);
                                col = uiLayoutColumn(split, 1);
                                uiLayoutSetContextPointer(col, "sensor", &ptr);
                                
                                /* should make UI template for sensor header.. function will do for now */
-                               draw_sensor_header(col, &ptr);
+                               draw_sensor_header(col, &ptr, &logic_ptr);
                                
                                /* draw the brick contents */
-                               draw_brick_sensor(col, &ptr);
+                               draw_brick_sensor(col, &ptr, C);
                                
                                /* put link button to the right */
                                col = uiLayoutColumn(split, 0);
        layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, xco, yco, width, 20, U.uistyles.first);
        row = uiLayoutRow(layout, 1);
        
-       uiDefBlockBut(block, sensor_menu, NULL, "Actuators", xco-10, yco, 70, UI_UNIT_Y, "");           /* replace this with uiLayout stuff later */
+       uiDefBlockBut(block, actuator_menu, NULL, "Actuators", xco-10, yco, 300, UI_UNIT_Y, "");                /* replace this with uiLayout stuff later */
        
        uiItemR(row, &logic_ptr, "actuators_show_selected_objects", 0, "Sel", 0);
        uiItemR(row, &logic_ptr, "actuators_show_active_objects", 0, "Act", 0);
        uiItemR(row, &logic_ptr, "actuators_show_linked_controller", 0, "Link", 0);
        uiItemR(row, &logic_ptr, "actuators_show_active_states", 0, "State", 0);
        
-       row = uiLayoutRow(layout, 1);
-       uiDefButBitS(block, TOG, OB_SHOWACT, B_REDR, ob->id.name+2,(short)(xco-10), yco, (short)(width-30), UI_UNIT_Y, &ob->scaflag, 0, 31, 0, 0, "Object name, click to show/hide actuators");
-       uiItemMenuEnumO(row, "LOGIC_OT_actuator_add", "type", "Add Actuator", 0);
-       
        for(a=0; a<count; a++) {
                bActuator *act;
                PointerRNA ptr;
                
                ob= (Object *)idar[a];
-               
-               if (!(ob->scavisflag & OB_VIS_ACT) || !(ob->scaflag & OB_SHOWACT)) continue;
+               /* only draw the actuator common header if "visible" */
+               if( (ob->scavisflag & OB_VIS_ACT) == 0) continue;
+               row = uiLayoutRow(layout, 1);
+               uiDefButBitS(block, TOG, OB_SHOWACT, B_REDR, ob->id.name+2,(short)(xco-10), yco, (short)(width-30), UI_UNIT_Y, &ob->scaflag, 0, 31, 0, 0, "Object name, click to show/hide actuators");
+               uiItemMenuEnumO(row, "LOGIC_OT_actuator_add", "type", "Add Actuator", 0);
+               if ((ob->scaflag & OB_SHOWACT) == 0) continue;
                
                uiItemS(layout);
                
                        RNA_pointer_create((ID *)ob, &RNA_Actuator, act, &ptr);
                        
                        if ((ob->scaflag & OB_ALLSTATE) ||
-                               (slogic->scaflag & BUTS_ACT_STATE) ||
+                               !(slogic->scaflag & BUTS_ACT_STATE) ||
                                !(act->flag & ACT_LINKED) ||            /* always display actuators without links so that is can be edited */
                                (act->flag & ACT_VISIBLE) ||            /* this actuator has visible connection, display it */
                                (act->flag & ACT_PIN && slogic->scaflag & BUTS_ACT_STATE)       /* states can hide some sensors, pinned sensors ignore the visible state */
                        {       // gotta check if the current state is visible or not
                                uiLayout *split, *col;
                                
+                               /* make as visible, for move operator */
+                               act->flag |= ACT_VISIBLE;
                                split = uiLayoutSplit(layout, 0.05, 0);
                                
                                /* put inlink button to the left */
                                uiLayoutSetContextPointer(col, "actuator", &ptr);
                                
                                /* should make UI template for actuator header.. function will do for now */
-                               draw_actuator_header(col, &ptr);
+                               draw_actuator_header(col, &ptr, &logic_ptr);
                                
                                /* draw the brick contents */
                                draw_brick_actuator(col, &ptr, C);
@@@ -4791,15 -4842,15 +4866,15 @@@ void logic_buttons(bContext *C, ARegio
                                                        cpack(0x999999);
                                                        glRecti(xco+22, yco, xco+width-22,yco+19);
                                                        but= uiDefBut(block, LABEL, 0, controller_name(cont->type), (short)(xco+22), yco, 70, UI_UNIT_Y, cont, 0, 0, 0, 0, "Controller type");
-                                                       //uiButSetFunc(but, sca_move_controller, cont, NULL);
+                                                       //uiButSetFunc(but, old_sca_move_controller, cont, NULL);
                                                        but= uiDefBut(block, LABEL, 0, cont->name,(short)(xco+92), yco,(short)(width-158), UI_UNIT_Y, cont, 0, 0, 0, 0, "Controller name");
-                                                       //uiButSetFunc(but, sca_move_controller, cont, NULL);
+                                                       //uiButSetFunc(but, old_sca_move_controller, cont, NULL);
  
                                                        uiBlockBeginAlign(block);
                                                        but= uiDefIconBut(block, BUT, B_REDR, ICON_TRIA_UP, (short)(xco+width-(110+5)), yco, 22, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Move this logic brick up");
-                                                       uiButSetFunc(but, sca_move_controller, cont, (void *)TRUE);
+                                                       uiButSetFunc(but, old_sca_move_controller, cont, (void *)TRUE);
                                                        but= uiDefIconBut(block, BUT, B_REDR, ICON_TRIA_DOWN, (short)(xco+width-(88+5)), yco, 22, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Move this logic brick down");
-                                                       uiButSetFunc(but, sca_move_controller, cont, (void *)FALSE);
+                                                       uiButSetFunc(but, old_sca_move_controller, cont, (void *)FALSE);
                                                        uiBlockEndAlign(block);
  
                                                        ycoo= yco;
                                                set_col_sensor(sens->type, 1);
                                                glRecti(xco+22, yco, xco+width-22,yco+19);
                                                but= uiDefBut(block, LABEL, 0, sensor_name(sens->type), (short)(xco+22), yco, 80, UI_UNIT_Y, sens, 0, 0, 0, 0, "");
-                                               //uiButSetFunc(but, sca_move_sensor, sens, NULL);
+                                               //uiButSetFunc(but, old_sca_move_sensor, sens, NULL);
                                                but= uiDefBut(block, LABEL, 0, sens->name, (short)(xco+102), yco, (short)(width-(pin?146:124)), UI_UNIT_Y, sens, 0, 31, 0, 0, "");
-                                               //uiButSetFunc(but, sca_move_sensor, sens, NULL);
+                                               //uiButSetFunc(but, old_sca_move_sensor, sens, NULL);
  
                                                uiBlockBeginAlign(block);
                                                but= uiDefIconBut(block, BUT, B_REDR, ICON_TRIA_UP, (short)(xco+width-(66+5)), yco, 22, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Move this logic brick up");
-                                               uiButSetFunc(but, sca_move_sensor, sens, (void *)TRUE);
+                                               uiButSetFunc(but, old_sca_move_sensor, sens, (void *)TRUE);
                                                but= uiDefIconBut(block, BUT, B_REDR, ICON_TRIA_DOWN, (short)(xco+width-(44+5)), yco, 22, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Move this logic brick down");
-                                               uiButSetFunc(but, sca_move_sensor, sens, (void *)FALSE);
+                                               uiButSetFunc(but, old_sca_move_sensor, sens, (void *)FALSE);
                                                uiBlockEndAlign(block);
                                        }
  
                                                set_col_actuator(act->type, 1);
                                                glRecti((short)(xco+22), yco, (short)(xco+width-22),(short)(yco+19));
                                                but= uiDefBut(block, LABEL, 0, actuator_name(act->type), (short)(xco+22), yco, 90, UI_UNIT_Y, act, 0, 0, 0, 0, "Actuator type");
-                                               // uiButSetFunc(but, sca_move_actuator, act, NULL);
+                                               // uiButSetFunc(but, old_sca_move_actuator, act, NULL);
                                                but= uiDefBut(block, LABEL, 0, act->name, (short)(xco+112), yco, (short)(width-(pin?156:134)), UI_UNIT_Y, act, 0, 0, 0, 0, "Actuator name");
-                                               // uiButSetFunc(but, sca_move_actuator, act, NULL);
+                                               // uiButSetFunc(but, old_sca_move_actuator, act, NULL);
  
                                                uiBlockBeginAlign(block);
                                                but= uiDefIconBut(block, BUT, B_REDR, ICON_TRIA_UP, (short)(xco+width-(66+5)), yco, 22, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Move this logic brick up");
-                                               uiButSetFunc(but, sca_move_actuator, act, (void *)TRUE);
+                                               uiButSetFunc(but, old_sca_move_actuator, act, (void *)TRUE);
                                                but= uiDefIconBut(block, BUT, B_REDR, ICON_TRIA_DOWN, (short)(xco+width-(44+5)), yco, 22, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Move this logic brick down");
-                                               uiButSetFunc(but, sca_move_actuator, act, (void *)FALSE);
+                                               uiButSetFunc(but, old_sca_move_actuator, act, (void *)FALSE);
                                                uiBlockEndAlign(block);
  
                                                ycoo= yco;
@@@ -66,7 -66,6 +66,7 @@@ typedef enum ModifierType 
        eModifierType_ShapeKey,
        eModifierType_Solidify,
        eModifierType_Screw,
 +      eModifierType_NavMesh,
        NUM_MODIFIER_TYPES
  } ModifierType;
  
@@@ -337,7 -336,6 +337,7 @@@ typedef struct DecimateModifierData 
        int faceCount;
  } DecimateModifierData;
  
 +
  /* Smooth modifier flags */
  #define MOD_SMOOTH_X (1<<1)
  #define MOD_SMOOTH_Y (1<<2)
@@@ -540,7 -538,7 +540,7 @@@ typedef struct MeshDeformModifierData 
        float *bindcos;                                 /* deprecated storage of cage coords */
  
        /* runtime */
-       void (*bindfunc)(struct Scene *scene, struct DerivedMesh *dm,
+       void (*bindfunc)(struct Scene *scene,
                struct MeshDeformModifierData *mmd,
                float *vertexcos, int totvert, float cagemat[][4]);
  } MeshDeformModifierData;
@@@ -705,6 -703,7 +705,7 @@@ typedef struct SolidifyModifierData 
  #define MOD_SOLIDIFY_EVEN                     (1<<1)
  #define MOD_SOLIDIFY_NORMAL_CALC      (1<<2)
  #define MOD_SOLIDIFY_VGROUP_INV               (1<<3)
+ #define MOD_SOLIDIFY_RIM_MATERIAL     (1<<4)
  
  typedef struct ScrewModifierData {
        ModifierData modifier;
  // #define MOD_SCREW_OBJECT_ANGLE     (1<<4)
  
  
 +typedef struct NavMeshModifierData {
 +      ModifierData modifier;
 +      char pad[4];
 +      float cellsize;
 +      float cellheight;
 +      float agentmaxslope;
 +      float agentmaxclimb;
 +      float agentheight;
 +      float agentradius;
 +      float edgemaxlen;
 +      float edgemaxerror;
 +      float regionminsize;
 +      float regionmergesize;
 +      int vertsperpoly;
 +      float detailsampledist;
 +      float detailsamplemaxerror;
 +
 +} NavMeshModifierData;
 +
  #endif
@@@ -182,8 -182,6 +182,8 @@@ typedef struct Object 
        float max_vel; /* clamp the maximum velocity 0.0 is disabled */
        float min_vel; /* clamp the maximum velocity 0.0 is disabled */
        float m_contactProcessingThreshold;
 +      float obstacleRad;
 +      char pad0[4];
        
        short rotmode;          /* rotation mode - uses defines set out in DNA_action_types.h for PoseChannel rotations... */
        
@@@ -438,7 -436,7 +438,7 @@@ extern Object workob
  #define OB_RECALC_DATA                2
                /* time flag is set when time changes need recalc, so baked systems can ignore it */
  #define OB_RECALC_TIME                4
- #define OB_RECALC                     7
+ #define OB_RECALC_ALL         7
  
  /* controller state */
  #define OB_MAX_STATES         30
  #define OB_SOFT_BODY  0x20000
  #define OB_OCCLUDER           0x40000
  #define OB_SENSOR             0x80000
 +#define OB_NAVMESH            0x100000
 +#define OB_HASOBSTACLE        0x200000
  
  /* ob->gameflag2 */
  #define OB_NEVER_DO_ACTIVITY_CULLING  1
  #define OB_BODY_TYPE_SOFT                     4
  #define OB_BODY_TYPE_OCCLUDER         5
  #define OB_BODY_TYPE_SENSOR                   6
 +#define OB_BODY_TYPE_NAVMESH          7
  
  /* ob->scavisflag */
  #define OB_VIS_SENS           1
@@@ -209,12 -209,12 +209,12 @@@ typedef struct RenderData 
        struct FFMpegCodecData ffcodecdata;
        
        int cfra, sfra, efra;   /* frames as in 'images' */
+       float subframe;                 /* subframe offset from cfra, in 0.0-1.0 */
        int psfra, pefra;               /* start+end frames of preview range */
  
        int images, framapto;
        short flag, threads;
  
-       float ctime;                    /* use for calcutions */
        float framelen, blurfac;
  
        /** For UR edge rendering: give the edges this color */
        short bake_osa, bake_filter, bake_mode, bake_flag;
        short bake_normal_space, bake_quad_split;
        float bake_maxdist, bake_biasdist, bake_pad;
-       
-       /* yafray: global panel params. TODO: move elsewhere */
-       short GIquality, GIcache, GImethod, GIphotons, GIdirect;
-       short YF_AA, YFexportxml, YF_nobump, YF_clamprgb, yfpad1;
-       int GIdepth, GIcausdepth, GIpixelspersample;
-       int GIphotoncount, GImixphotons;
-       float GIphotonradius;
-       int YF_raydepth, YF_AApasses, YF_AAsamples, yfpad2;
-       float GIshadowquality, GIrefinement, GIpower, GIindirpower;
-       float YF_gamma, YF_exposure, YF_raybias, YF_AApixelsize, YF_AAthreshold;
  
        /* paths to backbufffer, output, ftype */
        char backbuf[160], pic[160];
@@@ -438,23 -428,6 +428,23 @@@ typedef struct GameFraming 
  #define SCE_GAMEFRAMING_EXTEND 1
  #define SCE_GAMEFRAMING_SCALE  2
  
 +typedef struct RecastData
 +{
 +      float cellsize;
 +      float cellheight;
 +      float agentmaxslope;
 +      float agentmaxclimb;
 +      float agentheight;
 +      float agentradius;
 +      float edgemaxlen;
 +      float edgemaxerror;
 +      float regionminsize;
 +      float regionmergesize;
 +      int vertsperpoly;
 +      float detailsampledist;
 +      float detailsamplemaxerror;
 +} RecastData;
 +
  typedef struct GameData {
  
        /* physics (it was in world)*/
         * bit 3: (gameengine): Activity culling is enabled.
         * bit 5: (gameengine) : enable Bullet DBVT tree for view frustrum culling
        */
 -      short mode, flag, matmode, pad[3];
 +      short mode, flag, matmode/*, pad[2]*/;
        short occlusionRes;             /* resolution of occlusion Z buffer in pixel */
        short physicsEngine;
        short ticrate, maxlogicstep, physubstep, maxphystep;
 +      short obstacleSimulation;
 +      float levelHeight;
  
        /*  standalone player */
        struct GameFraming framing;
        /* stereo/dome mode */
        struct GameDome dome;
        short stereoflag, stereomode, xsch, ysch; //xsch and ysch can be deleted !!!
 -      float eyeseparation, pad1;
 +      float eyeseparation;
 +      RecastData recastData;
  } GameData;
  
  #define STEREO_NOSTEREO               1
  #define WOPHY_ODE             4
  #define WOPHY_BULLET  5
  
 +/* obstacleSimulation */
 +#define OBSTSIMULATION_NONE           0
 +#define OBSTSIMULATION_TOI            1
 +
  /* GameData.flag */
  #define GAME_ENABLE_ALL_FRAMES                                (1 << 1)
  #define GAME_SHOW_DEBUG_PROPS                         (1 << 2)
@@@ -779,9 -745,11 +769,11 @@@ typedef struct Scene 
        float cursor[3];                        /* 3d cursor location */
        float twcent[3];                        /* center for transform widget */
        float twmin[3], twmax[3];       /* boundbox of selection for transform widget */
-       unsigned int lay;
        
+       unsigned int lay;                       /* bitflags for layer visibility */
+       int layact;             /* active layer */
+       int pad1;
+       
        short flag;                                                             /* various settings */
        
        short use_nodes;
  #define ID_NEW_US(a)  if( (a)->id.newid) {(a)= (void *)(a)->id.newid; (a)->id.us++;}
  #define ID_NEW_US2(a) if( ((ID *)a)->newid) {(a)= ((ID *)a)->newid; ((ID *)a)->us++;}
  #define       CFRA                    (scene->r.cfra)
+ #define SUBFRA                        (scene->r.subframe)
  #define       F_CFRA                  ((float)(scene->r.cfra))
  #define       SFRA                    (scene->r.sfra)
  #define       EFRA                    (scene->r.efra)
@@@ -54,7 -54,6 +54,7 @@@ EnumPropertyItem actuator_type_items[] 
        {ACT_SOUND, "SOUND", 0, "Sound", ""},
        {ACT_STATE, "STATE", 0, "State", ""},
        {ACT_VISIBILITY, "VISIBILITY", 0, "Visibility", ""},
 +      {ACT_STEERING, "STEERING", 0, "Steering", ""},
        {0, NULL, 0, NULL, NULL}};
  
  #ifdef RNA_RUNTIME
@@@ -102,8 -101,6 +102,8 @@@ static StructRNA* rna_Actuator_refine(s
                        return &RNA_StateActuator;
                case ACT_ARMATURE:
                        return &RNA_ArmatureActuator;
 +              case ACT_STEERING:
 +                      return &RNA_SteeringActuator;
                default:
                        return &RNA_Actuator;
        }
@@@ -287,6 -284,21 +287,21 @@@ static void rna_ConstraintActuator_spri
        *fp = value;
  }
  
+ /* ConstraintActuator uses the same property for Material and Property.
+    Therefore we need to clear the property when "detect_material" mode changes */
+ static void rna_Actuator_constraint_detect_material_set(struct PointerRNA *ptr, int value)
+ {
+       bActuator *act = (bActuator*)ptr->data;
+       bConstraintActuator *ca = act->data;
+       short old_value = (ca->flag & ACT_CONST_MATERIAL? 1:0);
+       if (old_value != value) {
+               ca->flag ^= ACT_CONST_MATERIAL;
+               ca->matprop[0] = '\0';
+       }
+ }
  static void rna_FcurveActuator_add_set(struct PointerRNA *ptr, int value)
  {
        bActuator *act = (bActuator *)ptr->data;
@@@ -374,7 -386,6 +389,7 @@@ EnumPropertyItem *rna_Actuator_type_ite
        RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_PROPERTY);
        RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_RANDOM);
        RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_SCENE);
 +      RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_STEERING);
  
        if (ob != NULL) {
                if (ob->type==OB_MESH){
@@@ -465,10 -476,18 +480,18 @@@ void rna_def_actuator(BlenderRNA *brna
        RNA_def_property_enum_funcs(prop, NULL, "rna_Actuator_type_set", "rna_Actuator_type_itemf");
        RNA_def_property_ui_text(prop, "Type", "");
  
+       prop= RNA_def_property(srna, "pinned", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_PIN);
+       RNA_def_property_ui_text(prop, "Pinned", "Display when not linked to a visible states controller");
+       RNA_def_property_ui_icon(prop, ICON_UNPINNED, 1);
+       RNA_def_property_update(prop, NC_LOGIC, NULL);
        prop= RNA_def_property(srna, "expanded", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_SHOW);
        RNA_def_property_ui_text(prop, "Expanded", "Set actuator expanded in the user interface");
        RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);
+       RNA_api_actuator(srna);
  }
  
  static void rna_def_action_actuator(BlenderRNA *brna)
@@@ -903,7 -922,7 +926,7 @@@ static void rna_def_sound_actuator(Blen
        prop= RNA_def_property(srna, "maximum_gain_3d", PROP_FLOAT, PROP_NONE);
        RNA_def_property_float_sdna(prop, NULL, "sound3D.max_gain");
        RNA_def_property_ui_range(prop, 0.0, 1.0, 0.1, 0.01);
-       RNA_def_property_ui_text(prop, "Minimum Gain", "The maximum gain of the sound, no matter how near it is");
+       RNA_def_property_ui_text(prop, "Maximum Gain", "The maximum gain of the sound, no matter how near it is");
        RNA_def_property_update(prop, NC_LOGIC, NULL);
  
        prop= RNA_def_property(srna, "reference_distance_3d", PROP_FLOAT, PROP_NONE);
@@@ -1176,6 -1195,7 +1199,7 @@@ static void rna_def_constraint_actuator
        prop= RNA_def_property(srna, "detect_material", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_CONST_MATERIAL);
        RNA_def_property_ui_text(prop, "M/P", "Detect material instead of property");
+       RNA_def_property_boolean_funcs(prop, NULL, "rna_Actuator_constraint_detect_material_set");
        RNA_def_property_update(prop, NC_LOGIC, NULL);
  
        prop= RNA_def_property(srna, "fh_paralel_axis", PROP_BOOLEAN, PROP_NONE);
@@@ -1568,7 -1588,7 +1592,7 @@@ static void rna_def_visibility_actuator
        RNA_def_struct_sdna_from(srna, "bVisibilityActuator", "data");
  
        prop= RNA_def_property(srna, "visible", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_VISIBILITY_INVISIBLE);
+       RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", ACT_VISIBILITY_INVISIBLE);
        RNA_def_property_ui_text(prop, "Visible", "Set the objects visible. Initialized from the objects render restriction toggle (access in the outliner)");
        RNA_def_property_update(prop, NC_LOGIC, NULL);
  
@@@ -1845,77 -1865,6 +1869,77 @@@ static void rna_def_armature_actuator(B
        RNA_def_property_update(prop, NC_LOGIC, NULL);
  }
  
 +static void rna_def_steering_actuator(BlenderRNA *brna)
 +{
 +      StructRNA *srna;
 +      PropertyRNA *prop;
 +
 +      static EnumPropertyItem prop_type_items[] ={
 +              {ACT_STEERING_SEEK, "SEEK", 0, "Seek", ""},
 +              {ACT_STEERING_FLEE, "FLEE", 0, "Flee", ""},
 +              {ACT_STEERING_PATHFOLLOWING, "PATHFOLLOWING", 0, "Path following", ""},
 +              {0, NULL, 0, NULL, NULL}};
 +
 +      srna= RNA_def_struct(brna, "SteeringActuator", "Actuator");
 +      RNA_def_struct_ui_text(srna, "Steering Actuator", "");
 +      RNA_def_struct_sdna_from(srna, "bSteeringActuator", "data");
 +
 +      prop= RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
 +      RNA_def_property_enum_sdna(prop, NULL, "type");
 +      RNA_def_property_enum_items(prop, prop_type_items);
 +      RNA_def_property_ui_text(prop, "Behavior", "");
 +      RNA_def_property_update(prop, NC_LOGIC, NULL);
 +
 +      prop= RNA_def_property(srna, "velocity", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_float_sdna(prop, NULL, "velocity");
 +      RNA_def_property_range(prop, 0.0, 1000.0);
 +      RNA_def_property_ui_text(prop, "Velocity", "Velocity magnitude");
 +      RNA_def_property_update(prop, NC_LOGIC, NULL);
 +
 +      prop= RNA_def_property(srna, "acceleration", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_float_sdna(prop, NULL, "acceleration");
 +      RNA_def_property_range(prop, 0.0, 1000.0);
 +      RNA_def_property_ui_text(prop, "Acceleration", "Max acceleration");
 +      RNA_def_property_update(prop, NC_LOGIC, NULL);
 +
 +      prop= RNA_def_property(srna, "turnspeed", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_float_sdna(prop, NULL, "turnspeed");
 +      RNA_def_property_range(prop, 0.0, 720.0);
 +      RNA_def_property_ui_text(prop, "Turn speed", "Max turn speed");
 +      RNA_def_property_update(prop, NC_LOGIC, NULL);
 +
 +      prop= RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_float_sdna(prop, NULL, "dist");
 +      RNA_def_property_range(prop, 0.0, 1000.0);
 +      RNA_def_property_ui_text(prop, "Dist", "Relax distance");
 +      RNA_def_property_update(prop, NC_LOGIC, NULL);
 +
 +      prop= RNA_def_property(srna, "target", PROP_POINTER, PROP_NONE);
 +      RNA_def_property_struct_type(prop, "Object");
 +      RNA_def_property_pointer_sdna(prop, NULL, "target");
 +      RNA_def_property_flag(prop, PROP_EDITABLE);
 +      RNA_def_property_ui_text(prop, "Target Object", "Set target object");
 +      RNA_def_property_update(prop, NC_LOGIC, NULL);
 +
 +      prop= RNA_def_property(srna, "selfterminated", PROP_BOOLEAN, PROP_NONE);
 +      RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_STEERING_SELFTERMINATED);
 +      RNA_def_property_ui_text(prop, "Self terminated", "Terminate when target is reached");
 +      RNA_def_property_update(prop, NC_LOGIC, NULL);
 +
 +      prop= RNA_def_property(srna, "updateperiod", PROP_INT, PROP_NONE);
 +      RNA_def_property_int_sdna(prop, NULL, "updateTime");
 +      RNA_def_property_ui_range(prop, -1, 100000, 1, 1);
 +      RNA_def_property_ui_text(prop, "Update period", "Path update period");
 +      RNA_def_property_update(prop, NC_LOGIC, NULL);
 +
 +      prop= RNA_def_property(srna, "navmesh", PROP_POINTER, PROP_NONE);
 +      RNA_def_property_struct_type(prop, "Object");
 +      RNA_def_property_pointer_sdna(prop, NULL, "navmesh");
 +      RNA_def_property_flag(prop, PROP_EDITABLE);
 +      RNA_def_property_ui_text(prop, "NavMesh Object", "Navigation mesh");
 +      RNA_def_property_update(prop, NC_LOGIC, NULL);
 +}
 +
  void RNA_def_actuator(BlenderRNA *brna)
  {
        rna_def_actuator(brna);
        rna_def_shape_action_actuator(brna);
        rna_def_state_actuator(brna);
        rna_def_armature_actuator(brna);
 +      rna_def_steering_actuator(brna);
  }
  
  #endif
@@@ -40,6 -40,7 +40,7 @@@
  
  #include "BKE_animsys.h"
  #include "BKE_bmesh.h" /* For BevelModifierData */
+ #include "BKE_multires.h"
  #include "BKE_smoke.h" /* For smokeModifier_free & smokeModifier_createType */
  
  #include "WM_api.h"
@@@ -60,7 -61,6 +61,7 @@@ EnumPropertyItem modifier_type_items[] 
        {eModifierType_Solidify, "SOLIDIFY", ICON_MOD_SOLIDIFY, "Solidify", ""},
        {eModifierType_Subsurf, "SUBSURF", ICON_MOD_SUBSURF, "Subdivision Surface", ""},
        {eModifierType_UVProject, "UV_PROJECT", ICON_MOD_UVPROJECT, "UV Project", ""},
 +      {eModifierType_NavMesh, "NAVMESH", ICON_MOD_DECIM, "Navigation mesh", ""},
        {0, "", 0, "Deform", ""},
        {eModifierType_Armature, "ARMATURE", ICON_MOD_ARMATURE, "Armature", ""},
        {eModifierType_Cast, "CAST", ICON_MOD_CAST, "Cast", ""},
@@@ -169,8 -169,6 +170,8 @@@ static StructRNA* rna_Modifier_refine(s
                        return &RNA_SolidifyModifier;
                case eModifierType_Screw:
                        return &RNA_ScrewModifier;
 +              case eModifierType_NavMesh:
 +                      return &RNA_NavMeshModifier;
                default:
                        return &RNA_Modifier;
        }
@@@ -372,7 -370,7 +373,7 @@@ static int rna_MultiresModifier_externa
        return CustomData_external_test(&me->fdata, CD_MDISPS);
  }
  
- static void rna_MultiresModifier_filename_get(PointerRNA *ptr, char *value)
+ static void rna_MultiresModifier_filepath_get(PointerRNA *ptr, char *value)
  {
        Object *ob= (Object*)ptr->id.data;
        CustomDataExternal *external= ((Mesh*)ob->data)->fdata.external;
        BLI_strncpy(value, (external)? external->filename: "", sizeof(external->filename));
  }
  
- static void rna_MultiresModifier_filename_set(PointerRNA *ptr, const char *value)
+ static void rna_MultiresModifier_filepath_set(PointerRNA *ptr, const char *value)
  {
        Object *ob= (Object*)ptr->id.data;
        CustomDataExternal *external= ((Mesh*)ob->data)->fdata.external;
  
-       if(external)
+       if(external && strcmp(external->filename, value)) {
                BLI_strncpy(external->filename, value, sizeof(external->filename));
+               multires_force_external_reload(ob);
+       }
  }
  
- static int rna_MultiresModifier_filename_length(PointerRNA *ptr)
+ static int rna_MultiresModifier_filepath_length(PointerRNA *ptr)
  {
        Object *ob= (Object*)ptr->id.data;
        CustomDataExternal *external= ((Mesh*)ob->data)->fdata.external;
@@@ -606,9 -606,9 +609,9 @@@ static void rna_def_modifier_multires(B
        RNA_def_property_boolean_funcs(prop, "rna_MultiresModifier_external_get", NULL);
        RNA_def_property_ui_text(prop, "External", "Store multires displacements outside the .blend file, to save memory");
  
-       prop= RNA_def_property(srna, "filename", PROP_STRING, PROP_FILEPATH);
-       RNA_def_property_string_funcs(prop, "rna_MultiresModifier_filename_get", "rna_MultiresModifier_filename_length", "rna_MultiresModifier_filename_set");
-       RNA_def_property_ui_text(prop, "Filename", "Path to external displacements file");
+       prop= RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
+       RNA_def_property_string_funcs(prop, "rna_MultiresModifier_filepath_get", "rna_MultiresModifier_filepath_length", "rna_MultiresModifier_filepath_set");
+       RNA_def_property_ui_text(prop, "File Path", "Path to external displacements file");
        RNA_def_property_update(prop, 0, "rna_Modifier_update");
  
        prop= RNA_def_property(srna, "optimal_display", PROP_BOOLEAN, PROP_NONE);
@@@ -1547,11 -1547,17 +1550,17 @@@ static void rna_def_modifier_meshdeform
  static void rna_def_modifier_particlesystem(BlenderRNA *brna)
  {
        StructRNA *srna;
+       PropertyRNA *prop;
  
        srna= RNA_def_struct(brna, "ParticleSystemModifier", "Modifier");
        RNA_def_struct_ui_text(srna, "ParticleSystem Modifier", "Particle system simulation modifier");
        RNA_def_struct_sdna(srna, "ParticleSystemModifierData");
        RNA_def_struct_ui_icon(srna, ICON_MOD_PARTICLES);
+       
+       prop= RNA_def_property(srna, "particle_system", PROP_POINTER, PROP_NONE);
+       RNA_def_property_flag(prop, PROP_NEVER_NULL);
+       RNA_def_property_pointer_sdna(prop, NULL, "psys");
+       RNA_def_property_ui_text(prop, "Particle System", "Particle System that this modifier controls");
  }
  
  static void rna_def_modifier_particleinstance(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Children", "Create instances from child particles");
        RNA_def_property_update(prop, 0, "rna_Modifier_update");
  
-       prop= RNA_def_property(srna, "path", PROP_BOOLEAN, PROP_NONE);
+       prop= RNA_def_property(srna, "use_path", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "flag", eParticleInstanceFlag_Path);
        RNA_def_property_ui_text(prop, "Path", "Create instances along particle paths");
        RNA_def_property_update(prop, 0, "rna_Modifier_update");
@@@ -1719,9 -1725,9 +1728,9 @@@ static void rna_def_modifier_smoke(Blen
        
        static EnumPropertyItem prop_smoke_type_items[] = {
                        {0, "NONE", 0, "None", ""},
-                       {MOD_SMOKE_TYPE_DOMAIN, "TYPE_DOMAIN", 0, "Domain", ""},
-                       {MOD_SMOKE_TYPE_FLOW, "TYPE_FLOW", 0, "Flow", "Inflow/Outflow"},
-                       {MOD_SMOKE_TYPE_COLL, "TYPE_COLL", 0, "Collision", ""},
+                       {MOD_SMOKE_TYPE_DOMAIN, "DOMAIN", 0, "Domain", ""},
+                       {MOD_SMOKE_TYPE_FLOW, "FLOW", 0, "Flow", "Inflow/Outflow"},
+                       {MOD_SMOKE_TYPE_COLL, "COLLISION", 0, "Collision", ""},
                        {0, NULL, 0, NULL, NULL}};
        
        srna= RNA_def_struct(brna, "SmokeModifier", "Modifier");
@@@ -2098,6 -2104,11 +2107,11 @@@ static void rna_def_modifier_solidify(B
        RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_SOLIDIFY_RIM);
        RNA_def_property_ui_text(prop, "Fill Rim", "Create edge loops between the inner and outer surfaces on face edges (slow, disable when not needed)");
        RNA_def_property_update(prop, 0, "rna_Modifier_update");
+       
+       prop= RNA_def_property(srna, "use_rim_material", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_SOLIDIFY_RIM_MATERIAL);
+       RNA_def_property_ui_text(prop, "Rim Material", "Use in the next material for rim faces");
+       RNA_def_property_update(prop, 0, "rna_Modifier_update");
  
        prop= RNA_def_property(srna, "use_even_offset", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_SOLIDIFY_EVEN);
        RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_SOLIDIFY_VGROUP_INV);
        RNA_def_property_ui_text(prop, "Vertex Group Invert", "Invert the vertex group influence");
        RNA_def_property_update(prop, 0, "rna_Modifier_update");
+       
+       
  }
  
  static void rna_def_modifier_screw(BlenderRNA *brna)
        RNA_def_property_update(prop, 0, "rna_Modifier_update");*/
  }
  
 +static void rna_def_modifier_navmesh(BlenderRNA *brna)
 +{
 +      StructRNA *srna;
 +      PropertyRNA *prop;
 +
 +      srna= RNA_def_struct(brna, "NavMeshModifier", "Modifier");
 +      RNA_def_struct_ui_text(srna, "NavMesh Modifier", "NavMesh modifier");
 +      RNA_def_struct_sdna(srna, "NavMeshModifierData");
 +      RNA_def_struct_ui_icon(srna, ICON_MOD_DECIM);
 +
 +      prop= RNA_def_property(srna, "cellsize", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 0.1, 1, 0.01, 2);
 +      RNA_def_property_ui_text(prop, "Cell size", "Rasterized cell size");
 +      RNA_def_property_update(prop, 0, "rna_Modifier_update");
 +
 +      prop= RNA_def_property(srna, "cellheight", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 0.1, 1, 0.01, 2);
 +      RNA_def_property_ui_text(prop, "Cell height", "Rasterized cell height");
 +      RNA_def_property_update(prop, 0, "rna_Modifier_update");
 +
 +      prop= RNA_def_property(srna, "agentheight", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 0.1, 5, 0.1, 2);
 +      RNA_def_property_ui_text(prop, "Agent height", "Minimum height where the agent can still walk");
 +      RNA_def_property_update(prop, 0, "rna_Modifier_update");
 +
 +      prop= RNA_def_property(srna, "agentradius", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 0.1, 5, 0.1, 2);
 +      RNA_def_property_ui_text(prop, "Agent radius", "Radius of the agent");
 +      RNA_def_property_update(prop, 0, "rna_Modifier_update");
 +
 +      prop= RNA_def_property(srna, "agentmaxclimb", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 0.1, 5, 0.1, 2);
 +      RNA_def_property_ui_text(prop, "Max climb", "Maximum height between grid cells the agent can climb");
 +      RNA_def_property_update(prop, 0, "rna_Modifier_update");
 +
 +      prop= RNA_def_property(srna, "agentmaxslope", PROP_FLOAT, PROP_ANGLE);
 +      RNA_def_property_ui_range(prop, 0, 90, 1, 2);
 +      RNA_def_property_ui_text(prop, "Max slope", "Maximum walkable slope angle in degrees");
 +      RNA_def_property_update(prop, 0, "rna_Modifier_update");
 +
 +
 +      prop= RNA_def_property(srna, "regionminsize", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 0, 150, 1, 2);
 +      RNA_def_property_ui_text(prop, "Min region size", "Minimum regions size. Smaller regions will be deleted");
 +      RNA_def_property_update(prop, 0, "rna_Modifier_update");
 +
 +      prop= RNA_def_property(srna, "regionmergesize", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 0, 150, 1, 2);
 +      RNA_def_property_ui_text(prop, "Merged region size", "Minimum regions size. Smaller regions will be merged");
 +      RNA_def_property_update(prop, 0, "rna_Modifier_update");
 +
 +      prop= RNA_def_property(srna, "edgemaxlen", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 0, 50, 1, 2);
 +      RNA_def_property_ui_text(prop, "Max edge length", "Maximum contour edge length");
 +      RNA_def_property_update(prop, 0, "rna_Modifier_update");
 +
 +      prop= RNA_def_property(srna, "edgemaxerror", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 0.1, 3.0, 0.1, 2);
 +      RNA_def_property_ui_text(prop, "Max edge error", "Maximum distance error from contour to cells");
 +      RNA_def_property_update(prop, 0, "rna_Modifier_update");
 +
 +      prop= RNA_def_property(srna, "vertsperpoly", PROP_INT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 3, 12, 1, 0);
 +      RNA_def_property_ui_text(prop, "Verts per poly", "Max number of vertices per polygon");
 +      RNA_def_property_update(prop, 0, "rna_Modifier_update");
 +
 +      prop= RNA_def_property(srna, "detailsampledist", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 0.0, 16.0, 1, 2);
 +      RNA_def_property_ui_text(prop, "Sample Distance", "Detail mesh sample spacing");
 +      RNA_def_property_update(prop, 0, "rna_Modifier_update");
 +
 +      prop= RNA_def_property(srna, "detailsamplemaxerror", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 0.0, 16.0, 1, 2);
 +      RNA_def_property_ui_text(prop, "Max Sample Error", "Detail mesh simplification max sample error");
 +      RNA_def_property_update(prop, 0, "rna_Modifier_update");
 +
 +}
 +
  void RNA_def_modifier(BlenderRNA *brna)
  {
        StructRNA *srna;
        rna_def_modifier_smoke(brna);
        rna_def_modifier_solidify(brna);
        rna_def_modifier_screw(brna);
 +      rna_def_modifier_navmesh(brna);
  }
  
  #endif
@@@ -129,18 -129,51 +129,51 @@@ EnumPropertyItem object_type_curve_item
  #include "ED_object.h"
  #include "ED_particle.h"
  
- void rna_Object_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+ void rna_Object_internal_update(Main *bmain, Scene *scene, PointerRNA *ptr)
  {
        DAG_id_flush_update(ptr->id.data, OB_RECALC_OB);
  }
  
- void rna_Object_matrix_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+ void rna_Object_matrix_world_update(Main *bmain, Scene *scene, PointerRNA *ptr)
  {
        object_apply_mat4(ptr->id.data, ((Object *)ptr->id.data)->obmat);
-       rna_Object_update(bmain, scene, ptr);
+       rna_Object_internal_update(bmain, scene, ptr);
  }
  
- void rna_Object_update_data(Main *bmain, Scene *scene, PointerRNA *ptr)
+ void rna_Object_matrix_local_get(PointerRNA *ptr, float values[16])
+ {
+       Object *ob= ptr->id.data;
+       if(ob->parent) {
+               float invmat[4][4]; /* for inverse of parent's matrix */
+               invert_m4_m4(invmat, ob->parent->obmat);
+               mul_m4_m4m4((float(*)[4])values, ob->obmat, invmat);
+       }
+       else {
+               copy_m4_m4((float(*)[4])values, ob->obmat);
+       }
+ }
+ void rna_Object_matrix_local_set(PointerRNA *ptr, const float values[16])
+ {
+       Object *ob= ptr->id.data;
+       /* localspace matrix is truly relative to the parent, but parameters
+        * stored in object are relative to parentinv matrix.  Undo the parent
+        * inverse part before updating obmat and calling apply_obmat() */
+       if(ob->parent) {
+               float invmat[4][4];
+               invert_m4_m4(invmat, ob->parentinv);
+               mul_m4_m4m4(ob->obmat, (float(*)[4])values, invmat);
+       }
+       else {
+               copy_m4_m4(ob->obmat, (float(*)[4])values);
+       }
+       object_apply_mat4(ob, ob->obmat);
+ }
+ void rna_Object_internal_update_data(Main *bmain, Scene *scene, PointerRNA *ptr)
  {
        DAG_id_flush_update(ptr->id.data, OB_RECALC_DATA);
        WM_main_add_notifier(NC_OBJECT|ND_DRAW, ptr->id.data);
@@@ -157,7 -190,7 +190,7 @@@ void rna_Object_active_shape_update(Mai
                make_editMesh(scene, ob);
        }
  
-       rna_Object_update_data(bmain, scene, ptr);
+       rna_Object_internal_update_data(bmain, scene, ptr);
  }
  
  static void rna_Object_dependency_update(Main *bmain, Scene *scene, PointerRNA *ptr)
@@@ -210,7 -243,7 +243,7 @@@ static void rna_Object_layer_update(Mai
  
  static void rna_Base_layer_update(Main *bmain, Scene *scene, PointerRNA *ptr)
  {
-       Base *base= (Base*)ptr->id.data;
+       Base *base= (Base*)ptr->data;
        Object *ob= (Object*)base->object;
  
        rna_Object_layer_update__internal(scene, base, ob);
@@@ -737,8 -770,6 +770,8 @@@ static int rna_GameObjectSettings_physi
        if (!(ob->gameflag & OB_COLLISION)) {
                if (ob->gameflag & OB_OCCLUDER) {
                        ob->body_type = OB_BODY_TYPE_OCCLUDER;
 +              } else if (ob->gameflag & OB_NAVMESH){
 +                      ob->body_type = OB_BODY_TYPE_NAVMESH;
                } else {
                        ob->body_type = OB_BODY_TYPE_NO_COLLISION;
                }
@@@ -768,35 -799,31 +801,35 @@@ static void rna_GameObjectSettings_phys
        switch (ob->body_type) {
        case OB_BODY_TYPE_SENSOR:
                ob->gameflag |= OB_SENSOR|OB_COLLISION|OB_GHOST;
 -              ob->gameflag &= ~(OB_OCCLUDER|OB_DYNAMIC|OB_RIGID_BODY|OB_SOFT_BODY|OB_ACTOR|OB_ANISOTROPIC_FRICTION|OB_DO_FH|OB_ROT_FH|OB_COLLISION_RESPONSE);
 +              ob->gameflag &= ~(OB_OCCLUDER|OB_NAVMESH|OB_DYNAMIC|OB_RIGID_BODY|OB_SOFT_BODY|OB_ACTOR|OB_ANISOTROPIC_FRICTION|OB_DO_FH|OB_ROT_FH|OB_COLLISION_RESPONSE);
                break;
        case OB_BODY_TYPE_OCCLUDER:
                ob->gameflag |= OB_OCCLUDER;
 -              ob->gameflag &= ~(OB_SENSOR|OB_COLLISION|OB_DYNAMIC);
 +              ob->gameflag &= ~(OB_SENSOR|OB_COLLISION|OB_DYNAMIC|OB_NAVMESH);
 +              break;
 +      case OB_BODY_TYPE_NAVMESH:
 +              ob->gameflag |= OB_NAVMESH;
 +              ob->gameflag &= ~(OB_SENSOR|OB_COLLISION|OB_DYNAMIC|OB_OCCLUDER);
                break;
        case OB_BODY_TYPE_NO_COLLISION:
 -              ob->gameflag &= ~(OB_SENSOR|OB_COLLISION|OB_OCCLUDER|OB_DYNAMIC);
 +              ob->gameflag &= ~(OB_SENSOR|OB_COLLISION|OB_OCCLUDER|OB_DYNAMIC|OB_NAVMESH);
                break;
        case OB_BODY_TYPE_STATIC:
                ob->gameflag |= OB_COLLISION;
 -              ob->gameflag &= ~(OB_DYNAMIC|OB_RIGID_BODY|OB_SOFT_BODY|OB_OCCLUDER|OB_SENSOR);
 +              ob->gameflag &= ~(OB_DYNAMIC|OB_RIGID_BODY|OB_SOFT_BODY|OB_OCCLUDER|OB_SENSOR|OB_NAVMESH);
                break;
        case OB_BODY_TYPE_DYNAMIC:
                ob->gameflag |= OB_COLLISION|OB_DYNAMIC|OB_ACTOR;
 -              ob->gameflag &= ~(OB_RIGID_BODY|OB_SOFT_BODY|OB_OCCLUDER|OB_SENSOR);
 +              ob->gameflag &= ~(OB_RIGID_BODY|OB_SOFT_BODY|OB_OCCLUDER|OB_SENSOR|OB_NAVMESH);
                break;
        case OB_BODY_TYPE_RIGID:
                ob->gameflag |= OB_COLLISION|OB_DYNAMIC|OB_RIGID_BODY|OB_ACTOR;
 -              ob->gameflag &= ~(OB_SOFT_BODY|OB_OCCLUDER|OB_SENSOR);
 +              ob->gameflag &= ~(OB_SOFT_BODY|OB_OCCLUDER|OB_SENSOR|OB_NAVMESH);
                break;
        default:
        case OB_BODY_TYPE_SOFT:
                ob->gameflag |= OB_COLLISION|OB_DYNAMIC|OB_SOFT_BODY|OB_ACTOR;
 -              ob->gameflag &= ~(OB_RIGID_BODY|OB_OCCLUDER|OB_SENSOR);
 +              ob->gameflag &= ~(OB_RIGID_BODY|OB_OCCLUDER|OB_SENSOR|OB_NAVMESH);
  
                /* assume triangle mesh, if no bounds chosen for soft body */
                if ((ob->gameflag & OB_BOUNDS) && (ob->boundtype<OB_BOUND_POLYH))
@@@ -1071,13 -1098,13 +1104,13 @@@ static void rna_def_material_slot(Blend
        RNA_def_property_flag(prop, PROP_EDITABLE);
        RNA_def_property_pointer_funcs(prop, "rna_MaterialSlot_material_get", "rna_MaterialSlot_material_set", NULL);
        RNA_def_property_ui_text(prop, "Material", "Material datablock used by this material slot");
-       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_internal_update");
  
        prop= RNA_def_property(srna, "link", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_items(prop, link_items);
        RNA_def_property_enum_funcs(prop, "rna_MaterialSlot_link_get", "rna_MaterialSlot_link_set", NULL);
        RNA_def_property_ui_text(prop, "Link", "Link material to object or the object's data");
-       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_internal_update");
  
        prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
        RNA_def_property_string_funcs(prop, "rna_MaterialSlot_name_get", "rna_MaterialSlot_name_length", NULL);
@@@ -1099,7 -1126,6 +1132,7 @@@ static void rna_def_object_game_setting
                {OB_BODY_TYPE_SOFT, "SOFT_BODY", 0, "Soft Body", "Soft body"},
                {OB_BODY_TYPE_OCCLUDER, "OCCLUDE", 0, "Occlude", "Occluder for optimizing scene rendering"},
                {OB_BODY_TYPE_SENSOR, "SENSOR", 0, "Sensor", "Collision Sensor, detects static and dynamic objects but not the other collision sensor objects"},
 +              {OB_BODY_TYPE_NAVMESH, "NAVMESH", 0, "NavMesh", "Navigation mesh"},
                {0, NULL, 0, NULL, NULL}};
  
        srna= RNA_def_struct(brna, "GameObjectSettings", NULL);
        RNA_def_property_pointer_sdna(prop, NULL, "bsoft");
        RNA_def_property_ui_text(prop, "Soft Body Settings", "Settings for Bullet soft body simulation");
  
 +      prop= RNA_def_property(srna, "create_obstacle", PROP_BOOLEAN, PROP_NONE);
 +      RNA_def_property_boolean_sdna(prop, NULL, "gameflag", OB_HASOBSTACLE);
 +      RNA_def_property_ui_text(prop, "Create obstacle", "Create representation for obstacle simulation");
 +
 +      prop= RNA_def_property(srna, "obstacle_radius", PROP_FLOAT, PROP_NONE|PROP_UNIT_LENGTH);
 +      RNA_def_property_float_sdna(prop, NULL, "obstacleRad");
 +      RNA_def_property_range(prop, 0.0, 1000.0);
 +      RNA_def_property_ui_text(prop, "Obstacle Radius", "Radius of object representation in obstacle simulation");
 +
        /* state */
  
-       prop= RNA_def_property(srna, "state", PROP_BOOLEAN, PROP_LAYER_MEMBER);
+       prop= RNA_def_property(srna, "visible_state", PROP_BOOLEAN, PROP_LAYER_MEMBER);
        RNA_def_property_boolean_sdna(prop, NULL, "state", 1);
        RNA_def_property_array(prop, OB_MAX_STATES);
        RNA_def_property_ui_text(prop, "State", "State determining which controllers are displayed");
@@@ -1459,7 -1476,7 +1492,7 @@@ static void rna_def_object(BlenderRNA *
                {OB_BOUND_SPHERE, "SPHERE", 0, "Sphere", ""},
                {OB_BOUND_CYLINDER, "CYLINDER", 0, "Cylinder", ""},
                {OB_BOUND_CONE, "CONE", 0, "Cone", ""},
-               {OB_BOUND_POLYH, "POLYHEDER", 0, "Polyheder", ""},
+               {OB_BOUND_POLYH, "POLYHEDRON", 0, "Polyhedron", ""},
                {0, NULL, 0, NULL, NULL}};
  
        static EnumPropertyItem dupli_items[] = {
        RNA_def_property_editable_func(prop, "rna_Object_data_editable");
        RNA_def_property_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "Data", "Object data");
-       RNA_def_property_update(prop, 0, "rna_Object_update_data");
+       RNA_def_property_update(prop, 0, "rna_Object_internal_update_data");
  
        prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_sdna(prop, NULL, "type");
        RNA_def_property_array(prop, 3);
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "Parent Vertices", "Indices of vertices in cases of a vertex parenting relation");
-       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_internal_update");
  
        prop= RNA_def_property(srna, "parent_bone", PROP_STRING, PROP_NONE);
        RNA_def_property_string_sdna(prop, NULL, "parsubstr");
        RNA_def_property_enum_sdna(prop, NULL, "trackflag");
        RNA_def_property_enum_items(prop, track_items);
        RNA_def_property_ui_text(prop, "Track Axis", "Axis that points in 'forward' direction");
-       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_internal_update");
  
        prop= RNA_def_property(srna, "up_axis", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_sdna(prop, NULL, "upflag");
        RNA_def_property_enum_items(prop, up_items);
        RNA_def_property_ui_text(prop, "Up Axis", "Axis that points in the upward direction");
-       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_internal_update");
        
        /* proxy */
        prop= RNA_def_property(srna, "proxy", PROP_POINTER, PROP_NONE);
        RNA_def_property_pointer_funcs(prop, "rna_Object_active_material_get", "rna_Object_active_material_set", NULL);
        RNA_def_property_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "Active Material", "Active material being displayed");
-       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_internal_update");
  
        prop= RNA_def_property(srna, "active_material_index", PROP_INT, PROP_UNSIGNED);
        RNA_def_property_int_sdna(prop, NULL, "actcol");
        RNA_def_property_float_sdna(prop, NULL, "loc");
        RNA_def_property_editable_array_func(prop, "rna_Object_location_editable");
        RNA_def_property_ui_text(prop, "Location", "Location of the object");
-       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
        
        prop= RNA_def_property(srna, "rotation_quaternion", PROP_FLOAT, PROP_QUATERNION);
        RNA_def_property_float_sdna(prop, NULL, "quat");
        RNA_def_property_editable_array_func(prop, "rna_Object_rotation_4d_editable");
        RNA_def_property_float_array_default(prop, default_quat);
        RNA_def_property_ui_text(prop, "Quaternion Rotation", "Rotation in Quaternions");
-       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
        
                /* XXX: for axis-angle, it would have been nice to have 2 separate fields for UI purposes, but
                 * having a single one is better for Keyframing and other property-management situations...
        RNA_def_property_editable_array_func(prop, "rna_Object_rotation_4d_editable");
        RNA_def_property_float_array_default(prop, default_axisAngle);
        RNA_def_property_ui_text(prop, "Axis-Angle Rotation", "Angle of Rotation for Axis-Angle rotation representation");
-       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
        
        prop= RNA_def_property(srna, "rotation_euler", PROP_FLOAT, PROP_EULER);
        RNA_def_property_float_sdna(prop, NULL, "rot");
        RNA_def_property_editable_array_func(prop, "rna_Object_rotation_euler_editable");
        RNA_def_property_ui_text(prop, "Euler Rotation", "Rotation in Eulers");
-       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
        
        prop= RNA_def_property(srna, "rotation_mode", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_sdna(prop, NULL, "rotmode");
        RNA_def_property_enum_items(prop, prop_rotmode_items); // XXX move to using a single define of this someday
        RNA_def_property_enum_funcs(prop, NULL, "rna_Object_rotation_mode_set", NULL);
        RNA_def_property_ui_text(prop, "Rotation Mode", "");
-       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
        
        prop= RNA_def_property(srna, "scale", PROP_FLOAT, PROP_XYZ);
        RNA_def_property_float_sdna(prop, NULL, "size");
        RNA_def_property_editable_array_func(prop, "rna_Object_scale_editable");
        RNA_def_property_float_array_default(prop, default_scale);
        RNA_def_property_ui_text(prop, "Scale", "Scaling of the object");
-       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
  
-       prop= RNA_def_property(srna, "dimensions", PROP_FLOAT, PROP_XYZ|PROP_UNIT_LENGTH);
+       prop= RNA_def_property(srna, "dimensions", PROP_FLOAT, PROP_XYZ_LENGTH);
        RNA_def_property_array(prop, 3);
        RNA_def_property_float_funcs(prop, "rna_Object_dimensions_get", "rna_Object_dimensions_set", NULL);
        RNA_def_property_ui_text(prop, "Dimensions", "Absolute bounding box dimensions of the object");
-       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
        
  
        /* delta transforms */
        prop= RNA_def_property(srna, "delta_location", PROP_FLOAT, PROP_TRANSLATION);
        RNA_def_property_float_sdna(prop, NULL, "dloc");
        RNA_def_property_ui_text(prop, "Delta Location", "Extra translation added to the location of the object");
-       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
        
        prop= RNA_def_property(srna, "delta_rotation_euler", PROP_FLOAT, PROP_EULER);
        RNA_def_property_float_sdna(prop, NULL, "drot");
        RNA_def_property_ui_text(prop, "Delta Rotation (Euler)", "Extra rotation added to the rotation of the object (when using Euler rotations)");
-       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
        
        prop= RNA_def_property(srna, "delta_rotation_quaternion", PROP_FLOAT, PROP_QUATERNION);
        RNA_def_property_float_sdna(prop, NULL, "dquat");
        RNA_def_property_float_array_default(prop, default_quat);
        RNA_def_property_ui_text(prop, "Delta Rotation (Quaternion)", "Extra rotation added to the rotation of the object (when using Quaternion rotations)");
-       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
        
  #if 0 // XXX not supported well yet...
        prop= RNA_def_property(srna, "delta_rotation_axis_angle", PROP_FLOAT, PROP_AXISANGLE);
        RNA_def_property_float_sdna(prop, NULL, "dquat"); // FIXME: this is not a single field any more! (drotAxis and drotAngle)
        RNA_def_property_float_array_default(prop, default_axisAngle);
        RNA_def_property_ui_text(prop, "Delta Rotation (Axis Angle)", "Extra rotation added to the rotation of the object (when using Axis-Angle rotations)");
-       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
  #endif
        
        prop= RNA_def_property(srna, "delta_scale", PROP_FLOAT, PROP_XYZ);
        RNA_def_property_float_sdna(prop, NULL, "dsize");
        RNA_def_property_ui_text(prop, "Delta Scale", "Extra scaling added to the scale of the object");
-       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
        
        /* transform locks */
        prop= RNA_def_property(srna, "lock_location", PROP_BOOLEAN, PROP_XYZ);
        RNA_def_property_array(prop, 3);
        RNA_def_property_ui_text(prop, "Lock Location", "Lock editing of location in the interface");
        RNA_def_property_ui_icon(prop, ICON_UNLOCKED, 1);
-       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
  
        prop= RNA_def_property(srna, "lock_rotation", PROP_BOOLEAN, PROP_XYZ);
        RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_ROTX);
        RNA_def_property_array(prop, 3);
        RNA_def_property_ui_text(prop, "Lock Rotation", "Lock editing of rotation in the interface");
        RNA_def_property_ui_icon(prop, ICON_UNLOCKED, 1);
-       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
        
                // XXX this is sub-optimal - it really should be included above, but due to technical reasons we can't do this!
        prop= RNA_def_property(srna, "lock_rotation_w", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_array(prop, 3);
        RNA_def_property_ui_text(prop, "Lock Scale", "Lock editing of scale in the interface");
        RNA_def_property_ui_icon(prop, ICON_UNLOCKED, 1);
-       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
  
        /* matrix */
-       prop= RNA_def_property(srna, "matrix", PROP_FLOAT, PROP_MATRIX);
+       prop= RNA_def_property(srna, "matrix_world", PROP_FLOAT, PROP_MATRIX);
        RNA_def_property_float_sdna(prop, NULL, "obmat");
        RNA_def_property_multi_array(prop, 2, matrix_dimsize);
-       RNA_def_property_ui_text(prop, "Matrix", "Transformation matrix");
-       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_matrix_update");
+       RNA_def_property_ui_text(prop, "Matrix World", "Worldspace transformation matrix");
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_matrix_world_update");
+       prop= RNA_def_property(srna, "matrix_local", PROP_FLOAT, PROP_MATRIX);
+       RNA_def_property_multi_array(prop, 2, matrix_dimsize);
+       RNA_def_property_ui_text(prop, "Local Matrix", "Parent relative transformation matrix");
+       RNA_def_property_float_funcs(prop, "rna_Object_matrix_local_get", "rna_Object_matrix_local_set", NULL);
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, NULL);
  
        /* collections */
        prop= RNA_def_property(srna, "constraints", PROP_COLLECTION, PROP_NONE);
        RNA_def_property_struct_type(prop, "VertexGroup");
        RNA_def_property_pointer_funcs(prop, "rna_Object_active_vertex_group_get", "rna_Object_active_vertex_group_set", NULL);
        RNA_def_property_ui_text(prop, "Active Vertex Group", "Vertex groups of the object");
-       RNA_def_property_update(prop, NC_GEOM|ND_DATA, "rna_Object_update_data");
+       RNA_def_property_update(prop, NC_GEOM|ND_DATA, "rna_Object_internal_update_data");
  
        prop= RNA_def_property(srna, "active_vertex_group_index", PROP_INT, PROP_NONE);
        RNA_def_property_int_sdna(prop, NULL, "actdef");
        RNA_def_property_int_funcs(prop, "rna_Object_active_vertex_group_index_get", "rna_Object_active_vertex_group_index_set", "rna_Object_active_vertex_group_index_range");
        RNA_def_property_ui_text(prop, "Active Vertex Group Index", "Active index in vertex group array");
-       RNA_def_property_update(prop, NC_GEOM|ND_DATA, "rna_Object_update_data");
+       RNA_def_property_update(prop, NC_GEOM|ND_DATA, "rna_Object_internal_update_data");
  
        /* empty */
        prop= RNA_def_property(srna, "empty_draw_type", PROP_ENUM, PROP_NONE);
        prop= RNA_def_property(srna, "slow_parent", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "partype", PARSLOW);
        RNA_def_property_ui_text(prop, "Slow Parent", "Create a delay in the parent relationship");
-       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_internal_update");
  
        prop= RNA_def_property(srna, "dupli_type", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_bitflag_sdna(prop, NULL, "transflag");
        prop= RNA_def_property(srna, "use_dupli_frames_speed", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_negative_sdna(prop, NULL, "transflag", OB_DUPLINOSPEED);
        RNA_def_property_ui_text(prop, "Dupli Frames Speed", "Set dupliframes to use the frame"); // TODO, better descriptio!
-       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_internal_update");
  
        prop= RNA_def_property(srna, "use_dupli_verts_rotation", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "transflag", OB_DUPLIROT);
        prop= RNA_def_property(srna, "use_dupli_faces_scale", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "transflag", OB_DUPLIFACES_SCALE);
        RNA_def_property_ui_text(prop, "Dupli Faces Inherit Scale", "Scale dupli based on face size");
-       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_internal_update");
  
        prop= RNA_def_property(srna, "dupli_faces_scale", PROP_FLOAT, PROP_NONE);
        RNA_def_property_float_sdna(prop, NULL, "dupfacesca");
        RNA_def_property_int_sdna(prop, NULL, "dupsta");
        RNA_def_property_range(prop, MINAFRAME, MAXFRAME);
        RNA_def_property_ui_text(prop, "Dupli Frames Start", "Start frame for DupliFrames");
-       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_internal_update");
  
        prop= RNA_def_property(srna, "dupli_frames_end", PROP_INT, PROP_NONE|PROP_UNIT_TIME);
        RNA_def_property_int_sdna(prop, NULL, "dupend");
        RNA_def_property_range(prop, MINAFRAME, MAXFRAME);
        RNA_def_property_ui_text(prop, "Dupli Frames End", "End frame for DupliFrames");
-       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_internal_update");
  
        prop= RNA_def_property(srna, "dupli_frames_on", PROP_INT, PROP_NONE|PROP_UNIT_TIME);
        RNA_def_property_int_sdna(prop, NULL, "dupon");
        RNA_def_property_range(prop, MINFRAME, MAXFRAME);
        RNA_def_property_ui_range(prop, 1, 1500, 1, 0);
        RNA_def_property_ui_text(prop, "Dupli Frames On", "Number of frames to use between DupOff frames");
-       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_internal_update");
  
        prop= RNA_def_property(srna, "dupli_frames_off", PROP_INT, PROP_NONE|PROP_UNIT_TIME);
        RNA_def_property_int_sdna(prop, NULL, "dupoff");
        RNA_def_property_range(prop, 0, MAXFRAME);
        RNA_def_property_ui_range(prop, 0, 1500, 1, 0);
        RNA_def_property_ui_text(prop, "Dupli Frames Off", "Recurring frames to exclude from the Dupliframes");
-       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_internal_update");
  
        prop= RNA_def_property(srna, "dupli_list", PROP_COLLECTION, PROP_NONE);
        RNA_def_property_collection_sdna(prop, NULL, "duplilist", NULL);
        RNA_def_property_float_sdna(prop, NULL, "sf");
        RNA_def_property_range(prop, MINAFRAMEF, MAXFRAMEF);
        RNA_def_property_ui_text(prop, "Time Offset", "Animation offset in frames for F-Curve and dupligroup instances");
-       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
  
        prop= RNA_def_property(srna, "time_offset_edit", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "ipoflag", OB_OFFS_OB);
        prop= RNA_def_property(srna, "time_offset_parent", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "ipoflag", OB_OFFS_PARENT);
        RNA_def_property_ui_text(prop, "Time Offset Parent", "Apply the time offset to this objects parent relationship");
-       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
  
        prop= RNA_def_property(srna, "time_offset_particle", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "ipoflag", OB_OFFS_PARTICLE);
        RNA_def_property_ui_text(prop, "Time Offset Particle", "Let the time offset work on the particle effect");
-       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
  
        prop= RNA_def_property(srna, "time_offset_add_parent", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "ipoflag", OB_OFFS_PARENTADD);
        RNA_def_property_ui_text(prop, "Time Offset Add Parent", "Add the parents time offset value");
-       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update");
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
  
        /* drawing */
        prop= RNA_def_property(srna, "max_draw_type", PROP_ENUM, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "shapeflag", OB_SHAPE_LOCK);
        RNA_def_property_ui_text(prop, "Shape Key Lock", "Always show the current Shape for this Object");
        RNA_def_property_ui_icon(prop, ICON_UNPINNED, 1);
-       RNA_def_property_update(prop, 0, "rna_Object_update_data");
+       RNA_def_property_update(prop, 0, "rna_Object_internal_update_data");
  
        prop= RNA_def_property(srna, "shape_key_edit_mode", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "shapeflag", OB_SHAPE_EDIT_MODE);
        RNA_def_property_ui_text(prop, "Shape Key Edit Mode", "Apply shape keys in edit mode (for Meshes only)");
        RNA_def_property_ui_icon(prop, ICON_EDITMODE_HLT, 0);
-       RNA_def_property_update(prop, 0, "rna_Object_update_data");
+       RNA_def_property_update(prop, 0, "rna_Object_internal_update_data");
  
        prop= RNA_def_property(srna, "active_shape_key", PROP_POINTER, PROP_NONE);
        RNA_def_property_struct_type(prop, "ShapeKey");
  
  #include "DNA_group_types.h"
  #include "DNA_modifier_types.h"
+ #include "DNA_particle_types.h"
  #include "DNA_scene_types.h"
  #include "DNA_userdef_types.h"
 +#include "BLI_math.h"
  
  /* Include for Bake Options */
  #include "RE_pipeline.h"
@@@ -161,13 -161,13 +162,13 @@@ EnumPropertyItem image_type_items[] = 
  
  #include "BLI_threads.h"
  #include "BLI_editVert.h"
+ #include "BLI_blenlib.h"
  
  #include "WM_api.h"
  
  #include "ED_info.h"
  #include "ED_node.h"
  #include "ED_view3d.h"
- #include "ED_object.h"
  #include "ED_mesh.h"
  #include "ED_keyframing.h"
  
@@@ -201,7 -201,7 +202,7 @@@ static Base *rna_Scene_object_link(Scen
        if(scene == scene_act)
                ob->lay= base->lay;
  
-       ob->recalc |= OB_RECALC;
+       ob->recalc |= OB_RECALC_ALL;
  
        DAG_scene_sort(scene);
  
@@@ -212,16 -212,21 +213,21 @@@ static void rna_Scene_object_unlink(Sce
  {
        Base *base= object_in_scene(ob, scene);
        if (!base) {
-               BKE_report(reports, RPT_ERROR, "Object is not in this scene.");
+               BKE_reportf(reports, RPT_ERROR, "Object '%s' is not in this scene '%s'.", ob->id.name+2, scene->id.name+2);
                return;
        }
        if (base==scene->basact && ob->mode != OB_MODE_OBJECT) {
-               BKE_report(reports, RPT_ERROR, "Object must be in 'Object Mode' to unlink.");
+               BKE_reportf(reports, RPT_ERROR, "Object '%s' must be in 'Object Mode' to unlink.", ob->id.name+2);
                return;
        }
+       if(scene->basact==base) {
+               scene->basact= NULL;
+       }
  
-       /* as long as ED_base_object_free_and_unlink calls free_libblock_us, we don't have to decrement ob->id.us */
-       ED_base_object_free_and_unlink(scene, base);
+       BLI_remlink(&scene->base, base);
+       MEM_freeN(base);
+       ob->id.us--;
  
        /* needed otherwise the depgraph will contain free'd objects which can crash, see [#20958] */
        DAG_scene_sort(scene);
@@@ -272,7 -277,7 +278,7 @@@ static void rna_Scene_layer_set(Pointer
  {
        Scene *scene= (Scene*)ptr->data;
  
-       scene->lay= ED_view3d_scene_layer_set(scene->lay, values);
+       scene->lay= ED_view3d_scene_layer_set(scene->lay, values, &scene->layact);
  }
  
  static void rna_Scene_view3d_update(Main *bmain, Scene *unused, PointerRNA *ptr)
@@@ -734,7 -739,7 +740,7 @@@ static int rna_RenderSettings_use_game_
  static void rna_SceneRenderLayer_layer_set(PointerRNA *ptr, const int *values)
  {
        SceneRenderLayer *rl= (SceneRenderLayer*)ptr->data;
-       rl->lay= ED_view3d_scene_layer_set(rl->lay, values);
+       rl->lay= ED_view3d_scene_layer_set(rl->lay, values, NULL);
  }
  
  static void rna_SceneRenderLayer_pass_update(Main *bmain, Scene *unused, PointerRNA *ptr)
@@@ -799,10 -804,14 +805,14 @@@ static void rna_Scene_editmesh_select_m
  static void object_simplify_update(Object *ob)
  {
        ModifierData *md;
+       ParticleSystem *psys;
  
        for(md=ob->modifiers.first; md; md=md->next)
                if(ELEM3(md->type, eModifierType_Subsurf, eModifierType_Multires, eModifierType_ParticleSystem))
-                       ob->recalc |= OB_RECALC_DATA;
+                       ob->recalc |= OB_RECALC_DATA|PSYS_RECALC_CHILD;
+       for(psys=ob->particlesystem.first; psys; psys=psys->next)
+               psys->recalc |= PSYS_RECALC_CHILD;
        
        if(ob->dup_group) {
                GroupObject *gob;
        }
  }
  
- static void rna_Scene_simplify_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+ static void rna_Scene_use_simplify_update(Main *bmain, Scene *scene, PointerRNA *ptr)
  {
+       Scene *sce;
        Base *base;
  
-       for(base= scene->base.first; base; base= base->next)
+       for(SETLOOPER(scene, base))
                object_simplify_update(base->object);
        
        DAG_ids_flush_update(0);
        WM_main_add_notifier(NC_GEOM|ND_DATA, NULL);
  }
  
+ static void rna_Scene_simplify_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+ {
+       if(scene->r.mode & R_SIMPLIFY)
+               rna_Scene_use_simplify_update(bmain, scene, ptr);
+ }
  static int rna_Scene_sync_mode_get(PointerRNA *ptr)
  {
        Scene *scene= (Scene*)ptr->data;
@@@ -1463,83 -1479,6 +1480,83 @@@ void rna_def_render_layer_common(Struct
        else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
  }
  
 +static void rna_def_scene_game_recast_data(BlenderRNA *brna)
 +{
 +      StructRNA *srna;
 +      PropertyRNA *prop;
 +
 +      srna= RNA_def_struct(brna, "SceneGameRecastData", NULL);
 +      RNA_def_struct_sdna(srna, "RecastData");
 +      RNA_def_struct_nested(brna, srna, "Scene");
 +      RNA_def_struct_ui_text(srna, "Recast Data", "Recast data for a Game datablock");
 +
 +      prop= RNA_def_property(srna, "cellsize", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 0.1, 1, 0.01, 2);
 +      RNA_def_property_ui_text(prop, "Cell size", "Rasterized cell size");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "cellheight", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 0.1, 1, 0.01, 2);
 +      RNA_def_property_ui_text(prop, "Cell height", "Rasterized cell height");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "agentheight", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 0.1, 5, 0.1, 2);
 +      RNA_def_property_ui_text(prop, "Agent height", "Minimum height where the agent can still walk");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "agentradius", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 0.1, 5, 0.1, 2);
 +      RNA_def_property_ui_text(prop, "Agent radius", "Radius of the agent");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "agentmaxclimb", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 0.1, 5, 0.1, 2);
 +      RNA_def_property_ui_text(prop, "Max climb", "Maximum height between grid cells the agent can climb");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "agentmaxslope", PROP_FLOAT, PROP_ANGLE);
 +      RNA_def_property_range(prop, 0, M_PI/2);
 +      RNA_def_property_ui_text(prop, "Max slope", "Maximum walkable slope angle in degrees");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +
 +      prop= RNA_def_property(srna, "regionminsize", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 0, 150, 1, 2);
 +      RNA_def_property_ui_text(prop, "Min region size", "Minimum regions size. Smaller regions will be deleted");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "regionmergesize", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 0, 150, 1, 2);
 +      RNA_def_property_ui_text(prop, "Merged region size", "Minimum regions size. Smaller regions will be merged");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "edgemaxlen", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 0, 50, 1, 2);
 +      RNA_def_property_ui_text(prop, "Max edge length", "Maximum contour edge length");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "edgemaxerror", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 0.1, 3.0, 0.1, 2);
 +      RNA_def_property_ui_text(prop, "Max edge error", "Maximum distance error from contour to cells");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "vertsperpoly", PROP_INT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 3, 12, 1, 0);
 +      RNA_def_property_ui_text(prop, "Verts per poly", "Max number of vertices per polygon");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "detailsampledist", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 0.0, 16.0, 1, 2);
 +      RNA_def_property_ui_text(prop, "Sample Distance", "Detail mesh sample spacing");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "detailsamplemaxerror", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_range(prop, 0.0, 16.0, 1, 2);
 +      RNA_def_property_ui_text(prop, "Max Sample Error", "Detail mesh simplification max sample error");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +}
 +
  static void rna_def_scene_game_data(BlenderRNA *brna)
  {
        StructRNA *srna;
                {GAME_MAT_GLSL, "GLSL", 0, "GLSL", "OpenGL shading language shaders"},
                {0, NULL, 0, NULL, NULL}};
  
 +      static EnumPropertyItem obstacle_simulation_items[] = {
 +              {OBSTSIMULATION_NONE, "NONE", 0, "None", ""},
 +              {OBSTSIMULATION_TOI, "TOI", 0, "TOI", ""},
 +              {0, NULL, 0, NULL, NULL}};
 +
        srna= RNA_def_struct(brna, "SceneGameData", NULL);
        RNA_def_struct_sdna(srna, "GameData");
        RNA_def_struct_nested(brna, srna, "Scene");
        RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GAME_GLSL_NO_EXTRA_TEX);
        RNA_def_property_ui_text(prop, "GLSL Extra Textures", "Use extra textures like normal or specular maps for GLSL rendering");
        RNA_def_property_update(prop, NC_SCENE|NA_EDITED, NULL);
 +
 +      /* obstacle simulation */
 +      prop= RNA_def_property(srna, "obstacle_simulation", PROP_ENUM, PROP_NONE);
 +      RNA_def_property_enum_sdna(prop, NULL, "obstacleSimulation");
 +      RNA_def_property_enum_items(prop, obstacle_simulation_items);
 +      RNA_def_property_ui_text(prop, "Obstacle simulation", "Simulation used for obstacle avoidance in the game engine");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      prop= RNA_def_property(srna, "level_height", PROP_FLOAT, PROP_ACCELERATION);
 +      RNA_def_property_float_sdna(prop, NULL, "levelHeight");
 +      RNA_def_property_range(prop, 0.0f, 200.0f);
 +      RNA_def_property_ui_text(prop, "Level height", "Max difference in heights of obstacles to enable their interaction");
 +      RNA_def_property_update(prop, NC_SCENE, NULL);
 +
 +      /* Recast Settings */
 +      prop= RNA_def_property(srna, "recast_data", PROP_POINTER, PROP_NONE);
 +      RNA_def_property_flag(prop, PROP_NEVER_NULL);
 +      RNA_def_property_pointer_sdna(prop, NULL, "recastData");
 +      RNA_def_property_struct_type(prop, "SceneGameRecastData");
 +      RNA_def_property_ui_text(prop, "Recast Data", "");
 +
 +      /* Nestled Data  */
 +      rna_def_scene_game_recast_data(brna);
 +      
  }
  
  static void rna_def_scene_render_layer(BlenderRNA *brna)
@@@ -2519,6 -2429,13 +2536,13 @@@ static void rna_def_scene_render_data(B
        RNA_def_property_ui_text(prop, "Motion Samples", "Number of scene samples to take with motion blur");
        RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
        
+       prop= RNA_def_property(srna, "motion_blur_shutter", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_float_sdna(prop, NULL, "blurfac");
+       RNA_def_property_range(prop, 0.01f, 10.0f);
+       RNA_def_property_ui_range(prop, 0.01, 2.0f, 1, 0);
+       RNA_def_property_ui_text(prop, "Shutter", "Time taken in frames between shutter open and close");
+       RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
+       
        /* border */
        prop= RNA_def_property(srna, "use_border", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "mode", R_BORDER);
        
        prop= RNA_def_property(srna, "color_management", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "color_mgt_flag", R_COLOR_MANAGEMENT);
-       RNA_def_property_ui_text(prop, "Color Management", "Use color profiles and gamma corrected imaging pipeline");
-       RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS|NC_MATERIAL|ND_SHADING, "rna_RenderSettings_color_management_update");
+       RNA_def_property_ui_text(prop, "Color Management", "Use linear workflow - gamma corrected imaging pipeline");
+       RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, "rna_RenderSettings_color_management_update");
        
        prop= RNA_def_property(srna, "use_file_extension", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "scemode", R_EXTENSION);
        RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
  
        prop= RNA_def_property(srna, "free_unused_nodes", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_sdna(prop, NULL, "scemode", R_FREE_IMAGE);
+       RNA_def_property_boolean_sdna(prop, NULL, "scemode", R_COMP_FREE);
        RNA_def_property_ui_text(prop, "Free Unused Nodes", "Free Nodes that are not used while compositing, to save memory");
        RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
  
        prop= RNA_def_property(srna, "use_simplify", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "mode", R_SIMPLIFY);
        RNA_def_property_ui_text(prop, "Use Simplify", "Enable simplification of scene for quicker preview renders");
-       RNA_def_property_update(prop, 0, "rna_Scene_simplify_update");
+       RNA_def_property_update(prop, 0, "rna_Scene_use_simplify_update");
  
        prop= RNA_def_property(srna, "simplify_subdivision", PROP_INT, PROP_UNSIGNED);
        RNA_def_property_int_sdna(prop, NULL, "simplify_subsurf");
@@@ -3002,7 -2920,7 +3027,7 @@@ void RNA_def_scene(BlenderRNA *brna
        RNA_def_property_ui_text(prop, "World", "World used for rendering the scene");
        RNA_def_property_update(prop, NC_SCENE|NC_WORLD, NULL);
  
-       prop= RNA_def_property(srna, "cursor_location", PROP_FLOAT, PROP_XYZ|PROP_UNIT_LENGTH);
+       prop= RNA_def_property(srna, "cursor_location", PROP_FLOAT, PROP_XYZ_LENGTH);
        RNA_def_property_float_sdna(prop, NULL, "cursor");
        RNA_def_property_ui_text(prop, "Cursor Location", "3D cursor location");
        RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, 4);
        RNA_def_property_int_funcs(prop, NULL, "rna_Scene_start_frame_set", NULL);
        RNA_def_property_range(prop, MINFRAME, MAXFRAME);
        RNA_def_property_ui_text(prop, "Start Frame", "First frame of the playback/rendering range");
-       RNA_def_property_update(prop, NC_SCENE|ND_FRAME, NULL);
+       RNA_def_property_update(prop, NC_SCENE|ND_FRAME_RANGE, NULL);
        
        prop= RNA_def_property(srna, "frame_end", PROP_INT, PROP_TIME);
        RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
        RNA_def_property_int_funcs(prop, NULL, "rna_Scene_end_frame_set", NULL);
        RNA_def_property_range(prop, MINFRAME, MAXFRAME);
        RNA_def_property_ui_text(prop, "End Frame", "Final frame of the playback/rendering range");
-       RNA_def_property_update(prop, NC_SCENE|ND_FRAME, NULL);
+       RNA_def_property_update(prop, NC_SCENE|ND_FRAME_RANGE, NULL);
        
        prop= RNA_def_property(srna, "frame_step", PROP_INT, PROP_TIME);
        RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
@@@ -172,9 -172,6 +172,9 @@@ extern "C" 
  #include "BL_ArmatureObject.h"
  #include "BL_DeformableGameObject.h"
  
 +#include "KX_NavMeshObject.h"
 +#include "KX_ObstacleSimulation.h"
 +
  #ifdef __cplusplus
  extern "C" {
  #endif
@@@ -1551,7 -1548,7 +1551,7 @@@ void BL_CreatePhysicsObjectNew(KX_GameO
                                        objprop.m_boundclass = KX_BOUNDMESH;
                                        break;
                                }
-                               // Object is not a mesh... can't use polyheder. 
+                               // Object is not a mesh... can't use polyhedron.
                                // Fall through and become a sphere.
                        case OB_BOUND_SPHERE:
                        {
@@@ -1716,13 -1713,6 +1716,13 @@@ static KX_GameObject *gameobject_from_b
                // needed for python scripting
                kxscene->GetLogicManager()->RegisterMeshName(meshobj->GetName(),meshobj);
        
 +              if (ob->gameflag & OB_NAVMESH)
 +              {
 +                      gameobj = new KX_NavMeshObject(kxscene,KX_Scene::m_callbacks);
 +                      gameobj->AddMesh(meshobj);
 +                      break;
 +              }
 +                      
                gameobj = new BL_DeformableGameObject(ob,kxscene,KX_Scene::m_callbacks);
        
                // set transformation
@@@ -2639,47 -2629,6 +2639,47 @@@ void BL_ConvertBlenderObjects(struct Ma
        converter->RegisterWorldInfo(worldinfo);
        kxscene->SetWorldInfo(worldinfo);
  
 +
 +      //create object representations for obstacle simulation
 +      KX_ObstacleSimulation* obssimulation = kxscene->GetObstacleSimulation();
 +      if (obssimulation)
 +      {
 +              for ( i=0;i<objectlist->GetCount();i++)
 +              {
 +                      KX_GameObject* gameobj = static_cast<KX_GameObject*>(objectlist->GetValue(i));
 +                      struct Object* blenderobject = gameobj->GetBlenderObject();
 +                      if (blenderobject->gameflag & OB_HASOBSTACLE)
 +                      {
 +                              obssimulation->AddObstacleForObj(gameobj);
 +                      }
 +              }
 +      }
 +
 +      //process navigation mesh objects
 +      for ( i=0; i<objectlist->GetCount();i++)
 +      {
 +              KX_GameObject* gameobj = static_cast<KX_GameObject*>(objectlist->GetValue(i));
 +              struct Object* blenderobject = gameobj->GetBlenderObject();
 +              if (blenderobject->type==OB_MESH && (blenderobject->gameflag & OB_NAVMESH))
 +              {
 +                      KX_NavMeshObject* navmesh = static_cast<KX_NavMeshObject*>(gameobj);
 +                      navmesh->SetVisible(0, true);
 +                      navmesh->BuildNavMesh();
 +                      if (obssimulation)
 +                              obssimulation->AddObstaclesForNavMesh(navmesh);
 +              }
 +      }
 +      for ( i=0; i<inactivelist->GetCount();i++)
 +      {
 +              KX_GameObject* gameobj = static_cast<KX_GameObject*>(inactivelist->GetValue(i));
 +              struct Object* blenderobject = gameobj->GetBlenderObject();
 +              if (blenderobject->type==OB_MESH && (blenderobject->gameflag & OB_NAVMESH))
 +              {
 +                      KX_NavMeshObject* navmesh = static_cast<KX_NavMeshObject*>(gameobj);
 +                      navmesh->SetVisible(0, true);
 +              }
 +      }
 +
  #define CONVERT_LOGIC
  #ifdef CONVERT_LOGIC
        // convert logic bricks, sensors, controllers and actuators
  
        logicbrick_conversionlist->Release();
        
 +
        // Calculate the scene btree -
        // too slow - commented out.
        //kxscene->SetNodeTree(tf.MakeTree());
@@@ -85,7 -85,6 +85,7 @@@ public
                KX_ACT_SHAPEACTION,
                KX_ACT_STATE,
                KX_ACT_ARMATURE,
 +              KX_ACT_STEERING,
        };
  
        SCA_IActuator(SCA_IObject* gameobj, KX_ACTUATOR_TYPE type); 
        
  #ifdef WITH_CXX_GUARDEDALLOC
  public:
-       void *operator new( unsigned int num_bytes) { return MEM_mallocN(num_bytes, "GE:SCA_IActuator"); }
+       void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:SCA_IActuator"); }
        void operator delete( void *mem ) { MEM_freeN(mem); }
  #endif
  };
@@@ -67,7 -67,6 +67,7 @@@ typedef unsigned long uint_ptr
  #include "SCA_ISensor.h"
  #include "SCA_IController.h"
  #include "NG_NetworkScene.h" //Needed for sendMessage()
 +#include "KX_ObstacleSimulation.h"
  
  #include "PyObjectPlus.h" /* python stuff */
  
@@@ -102,7 -101,6 +102,7 @@@ KX_GameObject::KX_GameObject
        m_pGraphicController(NULL),
        m_xray(false),
        m_pHitObject(NULL),
 +      m_pObstacleSimulation(NULL),
        m_isDeformable(false)
  #ifndef DISABLE_PYTHON
        , m_attr_dict(NULL)
@@@ -150,12 -148,6 +150,12 @@@ KX_GameObject::~KX_GameObject(
        {
                delete m_pGraphicController;
        }
 +
 +      if (m_pObstacleSimulation)
 +      {
 +              m_pObstacleSimulation->DestroyObstacleForObj(this);
 +      }
 +
  #ifndef DISABLE_PYTHON
        if (m_attr_dict) {
                PyDict_Clear(m_attr_dict); /* incase of circular refs or other weired cases */
@@@ -356,14 -348,6 +356,14 @@@ void KX_GameObject::ProcessReplica(
        m_pClient_info->m_gameobject = this;
        m_state = 0;
  
 +      KX_Scene* scene = KX_GetActiveScene();
 +      KX_ObstacleSimulation* obssimulation = scene->GetObstacleSimulation();
 +      struct Object* blenderobject = GetBlenderObject();
 +      if (obssimulation && (blenderobject->gameflag & OB_HASOBSTACLE))
 +      {
 +              obssimulation->AddObstacleForObj(this);
 +      }
 +
  #ifndef DISABLE_PYTHON
        if(m_attr_dict)
                m_attr_dict= PyDict_Copy(m_attr_dict);
@@@ -1345,7 -1329,8 +1345,8 @@@ static int mathutils_kxgameob_vector_se
                        self->NodeUpdateGS(0.f);
                        break;
                case MATHUTILS_VEC_CB_SCALE_GLOBAL:
-                       break;
+                       PyErr_SetString(PyExc_AttributeError, "KX_GameObject.worldScale is read-only");
+                       return 0;
                case MATHUTILS_VEC_CB_INERTIA_LOCAL:
                        /* read only */
                        break;
@@@ -1386,9 -1371,7 +1387,7 @@@ static int mathutils_kxgameob_vector_se
                return 0;
        
        bmo->data[index]= f;
-       mathutils_kxgameob_vector_set(bmo, subtype);
-       
-       return 1;
+       return mathutils_kxgameob_vector_set(bmo, subtype);
  }
  
  Mathutils_Callback mathutils_kxgameob_vector_cb = {
@@@ -121,18 -121,21 +121,21 @@@ extern "C" 
        #include "BLO_readfile.h"
  }
  
  #include "NG_NetworkScene.h" //Needed for sendMessage()
  
- static void setSandbox(TPythonSecurityLevel level);
  // 'local' copy of canvas ptr, for window height/width python scripts
+ #ifndef DISABLE_PYTHON
  static RAS_ICanvas* gp_Canvas = NULL;
+ static char gp_GamePythonPath[FILE_MAXDIR + FILE_MAXFILE] = "";
+ static char gp_GamePythonPathOrig[FILE_MAXDIR + FILE_MAXFILE] = ""; // not super happy about this, but we need to remember the first loaded file for the global/dict load save
+ #endif // DISABLE_PYTHON
  static KX_Scene*      gp_KetsjiScene = NULL;
  static KX_KetsjiEngine*       gp_KetsjiEngine = NULL;
  static RAS_IRasterizer* gp_Rasterizer = NULL;
- static char gp_GamePythonPath[FILE_MAXDIR + FILE_MAXFILE] = "";
- static char gp_GamePythonPathOrig[FILE_MAXDIR + FILE_MAXFILE] = ""; // not super happy about this, but we need to remember the first loaded file for the global/dict load save
  
  void KX_SetActiveScene(class KX_Scene* scene)
  {
@@@ -156,13 -159,6 +159,13 @@@ void     KX_RasterizerDrawDebugLine(const M
                gp_Rasterizer->DrawDebugLine(from,to,color);
  }
  
 +void  KX_RasterizerDrawDebugCircle(const MT_Vector3& center, const MT_Scalar radius, const MT_Vector3& color,
 +                                                                 const MT_Vector3& normal, int nsector)
 +{
 +      if (gp_Rasterizer)
 +              gp_Rasterizer->DrawDebugCircle(center, radius, color, normal, nsector);
 +}
 +
  #ifndef DISABLE_PYTHON
  
  static PyObject *gp_OrigPythonSysPath= NULL;
@@@ -1317,6 -1313,7 +1320,7 @@@ PyObject* initGameLogic(KX_KetsjiEngin
        KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_EXPRESSION, SCA_PropertySensor::KX_PROPSENSOR_EXPRESSION);
  
        /* 3. Constraint actuator                                                  */
+       /* XXX, TODO NXBGE, move constants names from KX_ACT_CONSTRAINT_foo to KX_CONSTRAINTACT_foo */
        KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCX);
        KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCY);
        KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCZ);
        KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ROTZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTZ);
        KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRPX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPX);
        KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRPY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPY);
-       KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRPY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPY);
+       KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRPZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPZ);
        KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRNX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNX);
        KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRNY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNY);
-       KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRNY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNY);
+       KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRNZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNZ);
        KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ORIX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIX);
        KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ORIY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIY);
        KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ORIZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIZ);
        KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_FHNX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNX);
        KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_FHNY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNY);
        KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_FHNZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNZ);
+       KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_NORMAL, KX_ConstraintActuator::KX_ACT_CONSTRAINT_NORMAL);
+       KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_MATERIAL, KX_ConstraintActuator::KX_ACT_CONSTRAINT_MATERIAL);
+       KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_PERMANENT, KX_ConstraintActuator::KX_ACT_CONSTRAINT_PERMANENT);
+       KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_DISTANCE, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DISTANCE);
+       KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_LOCAL, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCAL);
+       KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_DOROTFH, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DOROTFH);
  
        /* 4. Ipo actuator, simple part                                            */
        KX_MACRO_addTypesToDict(d, KX_IPOACT_PLAY,     KX_IpoActuator::KX_ACT_IPO_PLAY);
        KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_MIDDLE, SCA_IInputDevice::KX_MIDDLEMOUSE);
        KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_RIGHT, SCA_IInputDevice::KX_RIGHTMOUSE);
  
+       /* 2D Filter Actuator */
        KX_MACRO_addTypesToDict(d, RAS_2DFILTER_ENABLED, RAS_2DFilterManager::RAS_2DFILTER_ENABLED);
        KX_MACRO_addTypesToDict(d, RAS_2DFILTER_DISABLED, RAS_2DFilterManager::RAS_2DFILTER_DISABLED);
        KX_MACRO_addTypesToDict(d, RAS_2DFILTER_NOFILTER, RAS_2DFilterManager::RAS_2DFILTER_NOFILTER);
        KX_MACRO_addTypesToDict(d, RAS_2DFILTER_SEPIA, RAS_2DFilterManager::RAS_2DFILTER_SEPIA);
        KX_MACRO_addTypesToDict(d, RAS_2DFILTER_INVERT, RAS_2DFilterManager::RAS_2DFILTER_INVERT);
        KX_MACRO_addTypesToDict(d, RAS_2DFILTER_CUSTOMFILTER, RAS_2DFilterManager::RAS_2DFILTER_CUSTOMFILTER);
-               
+       /* Sound Actuator */
        KX_MACRO_addTypesToDict(d, KX_SOUNDACT_PLAYSTOP, KX_SoundActuator::KX_SOUNDACT_PLAYSTOP);
        KX_MACRO_addTypesToDict(d, KX_SOUNDACT_PLAYEND, KX_SoundActuator::KX_SOUNDACT_PLAYEND);
        KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPSTOP, KX_SoundActuator::KX_SOUNDACT_LOOPSTOP);
        KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL, KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL);
        KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP, KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP);
  
+       /* State Actuator */
        KX_MACRO_addTypesToDict(d, KX_STATE_OP_CPY, KX_StateActuator::OP_CPY);
        KX_MACRO_addTypesToDict(d, KX_STATE_OP_SET, KX_StateActuator::OP_SET);
        KX_MACRO_addTypesToDict(d, KX_STATE_OP_CLR, KX_StateActuator::OP_CLR);
        KX_MACRO_addTypesToDict(d, KX_STATE_OP_NEG, KX_StateActuator::OP_NEG);
  
-       KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_NORMAL, KX_ConstraintActuator::KX_ACT_CONSTRAINT_NORMAL);
-       KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_MATERIAL, KX_ConstraintActuator::KX_ACT_CONSTRAINT_MATERIAL);
-       KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_PERMANENT, KX_ConstraintActuator::KX_ACT_CONSTRAINT_PERMANENT);
-       KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_DISTANCE, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DISTANCE);
-       KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_LOCAL, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCAL);
-       KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_DOROTFH, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DOROTFH);
        /* Game Actuator Modes */
        KX_MACRO_addTypesToDict(d, KX_GAME_LOAD, KX_GameActuator::KX_GAME_LOAD);
        KX_MACRO_addTypesToDict(d, KX_GAME_START, KX_GameActuator::KX_GAME_START);
@@@ -1708,7 -1707,7 +1714,7 @@@ static PyMethodDef meth_import[] = {{ "
  //static PyObject *g_oldimport = 0;
  //static int g_security = 0;
  
- void setSandbox(TPythonSecurityLevel level)
static void setSandbox(TPythonSecurityLevel level)
  {
      PyObject *m = PyImport_AddModule("__builtin__");
      PyObject *d = PyModule_GetDict(m);
@@@ -1835,7 -1834,7 +1841,7 @@@ static void initPySysObjects(Main *magg
        while(lib) {
                /* lib->name wont work in some cases (on win32),
                 * even when expanding with gp_GamePythonPath, using lib->filename is less trouble */
-               initPySysObjects__append(sys_path, lib->filename);
+               initPySysObjects__append(sys_path, lib->filepath);
                lib= (Library *)lib->id.next;
        }
        
@@@ -1990,10 -1989,7 +1996,7 @@@ void setupGamePython(KX_KetsjiEngine* k
        initGeometry();
        initBGL();
        initBLF();
- #ifdef WITH_FFMPEG
        initVideoTexture();
- #endif
  
        /* could be done a lot more nicely, but for now a quick way to get bge.* working */
        PyRun_SimpleString("__import__('sys').modules['bge']=[mod for mod in (type(__builtins__)('bge'), ) if mod.__dict__.update({'logic':__import__('GameLogic'), 'render':__import__('Rasterizer'), 'events':__import__('GameKeys'), 'constraints':__import__('PhysicsConstraints'), 'types':__import__('GameTypes')}) is None][0]");
@@@ -85,7 -85,6 +85,7 @@@
  #include "BL_DeformableGameObject.h"
  #include "KX_SoftBodyDeformer.h"
  
 +#include "KX_ObstacleSimulation.h"
  // to get USE_BULLET!
  #include "KX_ConvertPhysicsObject.h"
  
@@@ -95,6 -94,7 +95,6 @@@
  #endif
  
  #include "KX_Light.h"
 -
  #include <stdio.h>
  
  void* KX_SceneReplicationFunc(SG_IObject* node,void* gameobj,void* scene)
@@@ -210,17 -210,7 +210,17 @@@ KX_Scene::KX_Scene(class SCA_IInputDevi
        m_rootnode = NULL;
  
        m_bucketmanager=new RAS_BucketManager();
 +
 +      switch (scene->gm.obstacleSimulation)
 +      {
 +      case OBSTSIMULATION_TOI:
 +              m_obstacleSimulation = new KX_ObstacleSimulationTOI((MT_Scalar)scene->gm.levelHeight);
 +              break;
 +      default:
 +              m_obstacleSimulation = NULL;
 +      }
        
 +
  #ifndef DISABLE_PYTHON
        m_attr_dict = PyDict_New(); /* new ref */
        m_draw_call_pre = NULL;
  
  KX_Scene::~KX_Scene()
  {
 +      if (m_obstacleSimulation)
 +              delete m_obstacleSimulation;
 +
        // The release of debug properties used to be in SCA_IScene::~SCA_IScene
        // It's still there but we remove all properties here otherwise some
        // reference might be hanging and causing late release of objects
@@@ -1474,11 -1461,6 +1474,11 @@@ void KX_Scene::LogicBeginFrame(double c
                        // all object is the tempObjectList should have a clock
                }
        }
 +
 +      //prepare obstacle simulation for new frame
 +      if (m_obstacleSimulation)
 +              m_obstacleSimulation->UpdateObstacles();
 +
        m_logicmgr->BeginFrame(curtime, 1.0/KX_KetsjiEngine::GetTicRate());
  }
  
@@@ -1772,7 -1754,7 +1772,7 @@@ bool KX_Scene::MergeScene(KX_Scene *oth
        }
  
  
-       GetBucketManager()->MergeBucketManager(other->GetBucketManager());
+       GetBucketManager()->MergeBucketManager(other->GetBucketManager(), this);
  
        /* move materials across, assume they both use the same scene-converters */
        GetSceneConverter()->MergeScene(this, other);
@@@ -1908,11 -1890,9 +1908,11 @@@ PyMethodDef KX_Scene::Methods[] = 
        KX_PYMETHODTABLE(KX_Scene, replace),
        KX_PYMETHODTABLE(KX_Scene, suspend),
        KX_PYMETHODTABLE(KX_Scene, resume),
 +      KX_PYMETHODTABLE(KX_Scene, drawObstacleSimulation),
        
        /* dict style access */
        KX_PYMETHODTABLE(KX_Scene, get),
 +
        
        {NULL,NULL} //Sentinel
  };
@@@ -2236,16 -2216,6 +2236,16 @@@ KX_PYMETHODDEF_DOC(KX_Scene, resume
        Py_RETURN_NONE;
  }
  
 +KX_PYMETHODDEF_DOC(KX_Scene, drawObstacleSimulation,
 +                                 "drawObstacleSimulation()\n"
 +                                 "Draw debug visualization of obstacle simulation.\n")
 +{
 +      if (GetObstacleSimulation())
 +              GetObstacleSimulation()->DrawObstacles();
 +
 +      Py_RETURN_NONE;
 +}
 +
  /* Matches python dict.get(key, [default]) */
  KX_PYMETHODDEF_DOC(KX_Scene, get, "")
  {
@@@ -83,8 -83,11 +83,12 @@@ class SCA_JoystickManager
  class btCollisionShape;
  class KX_BlenderSceneConverter;
  struct KX_ClientObjectInfo;
 +class KX_ObstacleSimulation;
  
+ #ifdef WITH_CXX_GUARDEDALLOC
+ #include "MEM_guardedalloc.h"
+ #endif
  /* for ID freeing */
  #define IS_TAGGED(_id) ((_id) && (((ID *)_id)->flag & LIB_DOIT))
  
@@@ -277,9 -280,6 +281,9 @@@ protected
        struct Scene* m_blenderScene;
  
        RAS_2DFilterManager m_filtermanager;
 +
 +      KX_ObstacleSimulation* m_obstacleSimulation;
 +
  public:       
        KX_Scene(class SCA_IInputDevice* keyboarddevice,
                class SCA_IInputDevice* mousedevice,
        void Update2DFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text);
        void Render2DFilters(RAS_ICanvas* canvas);
  
 +      KX_ObstacleSimulation* GetObstacleSimulation() {return m_obstacleSimulation;};
 +
  #ifndef DISABLE_PYTHON
        /* --------------------------------------------------------------------- */
        /* Python interface ---------------------------------------------------- */
        KX_PYMETHOD_DOC(KX_Scene, suspend);
        KX_PYMETHOD_DOC(KX_Scene, resume);
        KX_PYMETHOD_DOC(KX_Scene, get);
 +      KX_PYMETHOD_DOC(KX_Scene, drawObstacleSimulation);
  
        /* attributes */
        static PyObject*        pyattr_get_name(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
        //void PrintStats(int verbose_level) {
        //      m_bucketmanager->PrintStats(verbose_level)
        //}
 +
  };
  
  typedef std::vector<KX_Scene*> KX_SceneList;
@@@ -386,9 -386,7 +386,9 @@@ public
        virtual void    SetPolygonOffset(float mult, float add) = 0;
        
        virtual void    DrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)=0;
 -      virtual void    FlushDebugLines()=0;
 +      virtual void    DrawDebugCircle(const MT_Vector3& center, const MT_Scalar radius, const MT_Vector3& color,
 +                                                                              const MT_Vector3& normal, int nsector)=0;
 +      virtual void    FlushDebugShapes()=0;
        
  
  
        
  #ifdef WITH_CXX_GUARDEDALLOC
  public:
-       void *operator new( unsigned int num_bytes) { return MEM_mallocN(num_bytes, "GE:RAS_IRasterizer"); }
+       void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:RAS_IRasterizer"); }
        void operator delete( void *mem ) { MEM_freeN(mem); }
  #endif
  };
@@@ -44,15 -44,10 +44,15 @@@ using namespace std
  #define RAS_MAX_TEXCO 8       // match in BL_Material
  #define RAS_MAX_ATTRIB        16      // match in BL_BlenderShader
  
 -struct        OglDebugLine
 +struct        OglDebugShape
  {
 -      MT_Vector3      m_from;
 -      MT_Vector3      m_to;
 +      enum SHAPE_TYPE{
 +              LINE, CIRCLE
 +      };
 +      SHAPE_TYPE  m_type;
 +      MT_Vector3      m_pos;
 +      MT_Vector3      m_param;
 +      MT_Vector3      m_param2;
        MT_Vector3      m_color;
  };
  
@@@ -254,13 -249,18 +254,13 @@@ public
  
        virtual void    SetPolygonOffset(float mult, float add);
  
 -      virtual void    FlushDebugLines();
 +      virtual void    FlushDebugShapes();
 +      virtual void    DrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color);
 +      virtual void    DrawDebugCircle(const MT_Vector3& center, const MT_Scalar radius, const MT_Vector3& color,
 +                                                                      const MT_Vector3& normal, int nsector);
  
 -      virtual void    DrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)
 -      {
 -              OglDebugLine line;
 -              line.m_from = from;
 -              line.m_to = to;
 -              line.m_color = color;
 -              m_debugLines.push_back(line);
 -      }
 -
 -      std::vector <OglDebugLine>      m_debugLines;
 +
 +      std::vector <OglDebugShape>     m_debugShapes;
  
        virtual void SetTexCoordNum(int num);
        virtual void SetAttribNum(int num);
        
  #ifdef WITH_CXX_GUARDEDALLOC
  public:
-       void *operator new( unsigned int num_bytes) { return MEM_mallocN(num_bytes, "GE:RAS_OpenGLRasterizer"); }
+       void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:RAS_OpenGLRasterizer"); }
        void operator delete( void *mem ) { MEM_freeN(mem); }
  #endif
  };