synched with trunk at revision 30597
[blender.git] / source / blender / blenkernel / intern / scene.c
index 0e4b36d..429cbfe 100644 (file)
@@ -44,6 +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 @@ Scene *copy_scene(Main *bmain, Scene *sce, int type)
                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! */
 
@@ -211,6 +216,12 @@ Scene *copy_scene(Main *bmain, Scene *sce, int type)
                        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);
@@ -472,6 +483,23 @@ Scene *add_scene(char *name)
        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;
@@ -542,18 +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)
@@ -583,7 +610,7 @@ void unlink_scene(Main *bmain, Scene *sce, Scene *newsce)
 /* used by metaballs
  * doesnt return the original duplicated object, only dupli's
  */
-int next_object(Scene *scene, int val, Base **base, Object **ob)
+int next_object(Scene **scene, int val, Base **base, Object **ob)
 {
        static ListBase *duplilist= NULL;
        static DupliObject *dupob;
@@ -612,17 +639,21 @@ int next_object(Scene *scene, int val, Base **base, Object **ob)
 
                        /* the first base */
                        if(fase==F_START) {
-                               *base= scene->base.first;
+                               *base= (*scene)->base.first;
                                if(*base) {
                                        *ob= (*base)->object;
                                        fase= F_SCENE;
                                }
                                else {
                                        /* exception: empty scene */
-                                       if(scene->set && scene->set->base.first) {
-                                               *base= scene->set->base.first;
-                                               *ob= (*base)->object;
-                                               fase= F_SET;
+                                       while((*scene)->set) {
+                                               (*scene)= (*scene)->set;
+                                               if((*scene)->base.first) {
+                                                       *base= (*scene)->base.first;
+                                                       *ob= (*base)->object;
+                                                       fase= F_SCENE;
+                                                       break;
+                                               }
                                        }
                                }
                        }
@@ -632,11 +663,14 @@ int next_object(Scene *scene, int val, Base **base, Object **ob)
                                        if(*base) *ob= (*base)->object;
                                        else {
                                                if(fase==F_SCENE) {
-                                                       /* scene is finished, now do the set */
-                                                       if(scene->set && scene->set->base.first) {
-                                                               *base= scene->set->base.first;
-                                                               *ob= (*base)->object;
-                                                               fase= F_SET;
+                                                       /* (*scene) is finished, now do the set */
+                                                       while((*scene)->set) {
+                                                               (*scene)= (*scene)->set;
+                                                               if((*scene)->base.first) {
+                                                                       *base= (*scene)->base.first;
+                                                                       *ob= (*base)->object;
+                                                                       break;
+                                                               }
                                                        }
                                                }
                                        }
@@ -651,7 +685,7 @@ int next_object(Scene *scene, int val, Base **base, Object **ob)
                                                this enters eternal loop because of 
                                                makeDispListMBall getting called inside of group_duplilist */
                                                if((*base)->object->dup_group == NULL) {
-                                                       duplilist= object_duplilist(scene, (*base)->object);
+                                                       duplilist= object_duplilist((*scene), (*base)->object);
                                                        
                                                        dupob= duplilist->first;
 
@@ -687,6 +721,10 @@ int next_object(Scene *scene, int val, Base **base, Object **ob)
                }
        }
        
+       /* if(ob && *ob) {
+               printf("Scene: '%s', '%s'\n", (*scene)->id.name+2, (*ob)->id.name+2);
+       } */
+
        /* reset recursion test */
        in_next_object= 0;
        
@@ -868,22 +906,16 @@ 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;
 }
 
@@ -903,6 +935,9 @@ static void scene_update_tagged_recursive(Scene *scene, Scene *scene_parent)
 
                if(ob->dup_group && (ob->transflag & OB_DUPLIGROUP))
                        group_handle_recalc_and_update(scene_parent, ob, ob->dup_group);
+                       
+               /* always update layer, so that animating layers works */
+               base->lay= ob->lay;
        }
 }
 
@@ -918,7 +953,7 @@ void scene_update_tagged(Scene *scene)
 
        /* recalc scene animation data here (for sequencer) */
        {
-               float ctime = frame_to_float(scene, scene->r.cfra); 
+               float ctime = BKE_curframe(scene); 
                AnimData *adt= BKE_animdata_from_id(&scene->id);
 
                if(adt && (adt->recalc & ADT_RECALC_ANIM))
@@ -935,7 +970,7 @@ void scene_update_tagged(Scene *scene)
 /* 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 */