Revision: 17951 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17951 Author: blendix Date: 2008-12-19 17:36:15 +0100 (Fri, 19 Dec 2008)
Log Message: ----------- 2.5: blenloader/ cleaning: - removed context usage, should not be in this module - remove G.main usage, now is passed along - still some globals in use here, goal is to get rid of those too, so that it's possible to load/save blendfiles without having to think about some global state. Modified Paths: -------------- branches/blender2.5/blender/source/blender/blenkernel/intern/blender.c branches/blender2.5/blender/source/blender/blenloader/BLO_readfile.h branches/blender2.5/blender/source/blender/blenloader/BLO_writefile.h branches/blender2.5/blender/source/blender/blenloader/intern/readblenentry.c branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c branches/blender2.5/blender/source/blender/blenloader/intern/readfile.h branches/blender2.5/blender/source/blender/blenloader/intern/writefile.c branches/blender2.5/blender/source/blender/editors/space_file/filelist.c branches/blender2.5/blender/source/blender/editors/space_file/filelist.h branches/blender2.5/blender/source/blender/windowmanager/intern/wm_files.c Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/blender.c =================================================================== --- branches/blender2.5/blender/source/blender/blenkernel/intern/blender.c 2008-12-19 16:25:50 UTC (rev 17950) +++ branches/blender2.5/blender/source/blender/blenkernel/intern/blender.c 2008-12-19 16:36:15 UTC (rev 17951) @@ -486,7 +486,7 @@ BKE_reports_init(&reports, RPT_STORE); - bfd= BLO_read_from_memfile(G.sce, memfile, &reports); + bfd= BLO_read_from_memfile(CTX_data_main(C), G.sce, memfile, &reports); if (bfd) { setup_app_data(C, bfd, "<memory1>"); } else { @@ -594,7 +594,7 @@ BLI_make_file_string("/", tstr, btempdir, numstr); BKE_reports_init(&reports, 0); - success= BLO_write_file(C, tstr, G.fileflags, &reports); + success= BLO_write_file(CTX_data_main(C), tstr, G.fileflags, &reports); BKE_reports_clear(&reports); strcpy(curundo->str, tstr); @@ -607,7 +607,7 @@ memused= MEM_get_memory_in_use(); BKE_reports_init(&reports, 0); - success= BLO_write_file_mem(C, prevfile, &curundo->memfile, G.fileflags, &reports); + success= BLO_write_file_mem(CTX_data_main(C), prevfile, &curundo->memfile, G.fileflags, &reports); BKE_reports_clear(&reports); curundo->undosize= MEM_get_memory_in_use() - memused; } Modified: branches/blender2.5/blender/source/blender/blenloader/BLO_readfile.h =================================================================== --- branches/blender2.5/blender/source/blender/blenloader/BLO_readfile.h 2008-12-19 16:25:50 UTC (rev 17950) +++ branches/blender2.5/blender/source/blender/blenloader/BLO_readfile.h 2008-12-19 16:36:15 UTC (rev 17951) @@ -95,9 +95,10 @@ BlendFileData* BLO_read_from_memory(void *mem, int memsize, struct ReportList *reports); /** + * oldmain is old main, from which we will keep libraries, images, .. * file name is current file, only for retrieving library data */ -BlendFileData *BLO_read_from_memfile(const char *filename, struct MemFile *memfile, struct ReportList *reports); +BlendFileData *BLO_read_from_memfile(struct Main *oldmain, const char *filename, struct MemFile *memfile, struct ReportList *reports); /** * Free's a BlendFileData structure and _all_ the @@ -199,10 +200,10 @@ char *BLO_gethome(void); int BLO_has_bfile_extension(char *str); -void BLO_library_append(struct SpaceFile *sfile, char *dir, int idcode, struct Scene *scene); +void BLO_library_append(struct SpaceFile *sfile, char *dir, int idcode, struct Main *mainvar, struct Scene *scene); void BLO_library_append_(BlendHandle **libfiledata, struct direntry* filelist, int totfile, - char *dir, char* file, short flag, int idcode, struct Scene *scene); -void BLO_script_library_append(BlendHandle **bh, char *dir, char *name, int idcode, short flag, struct Scene *scene); + char *dir, char* file, short flag, int idcode, struct Main *mainvar, struct Scene *scene); +void BLO_script_library_append(BlendHandle **bh, char *dir, char *name, int idcode, short flag, struct Main *mainvar, struct Scene *scene); BlendFileData* blo_read_blendafterruntime(int file, char *name, int actualsize, struct ReportList *reports); Modified: branches/blender2.5/blender/source/blender/blenloader/BLO_writefile.h =================================================================== --- branches/blender2.5/blender/source/blender/blenloader/BLO_writefile.h 2008-12-19 16:25:50 UTC (rev 17950) +++ branches/blender2.5/blender/source/blender/blenloader/BLO_writefile.h 2008-12-19 16:36:15 UTC (rev 17951) @@ -32,13 +32,13 @@ #define BLO_WRITEFILE_H struct MemFile; -struct bContext; +struct Main; struct ReportList; -extern int BLO_write_file(struct bContext *C, char *dir, int write_flags, struct ReportList *reports); -extern int BLO_write_file_mem(struct bContext *C, struct MemFile *compare, struct MemFile *current, +extern int BLO_write_file(struct Main *mainvar, char *dir, int write_flags, struct ReportList *reports); +extern int BLO_write_file_mem(struct Main *mainvar, struct MemFile *compare, struct MemFile *current, int write_flags, struct ReportList *reports); -extern int BLO_write_runtime(struct bContext *C, char *file, char *exename, struct ReportList *reports); +extern int BLO_write_runtime(struct Main *mainvar, char *file, char *exename, struct ReportList *reports); #endif Modified: branches/blender2.5/blender/source/blender/blenloader/intern/readblenentry.c =================================================================== --- branches/blender2.5/blender/source/blender/blenloader/intern/readblenentry.c 2008-12-19 16:25:50 UTC (rev 17950) +++ branches/blender2.5/blender/source/blender/blenloader/intern/readblenentry.c 2008-12-19 16:36:15 UTC (rev 17951) @@ -53,7 +53,6 @@ #include "BKE_utildefines.h" // for ENDB #include "BKE_main.h" -#include "BKE_global.h" #include "BKE_library.h" // for free_main #include "BKE_report.h" @@ -360,7 +359,7 @@ return bfd; } -BlendFileData *BLO_read_from_memfile(const char *filename, MemFile *memfile, ReportList *reports) +BlendFileData *BLO_read_from_memfile(Main *oldmain, const char *filename, MemFile *memfile, ReportList *reports) { BlendFileData *bfd = NULL; FileData *fd; @@ -370,16 +369,16 @@ if (fd) { strcpy(fd->filename, filename); - /* clear ob->proxy_from pointers in G.main */ - blo_clear_proxy_pointers_from_lib(fd); + /* clear ob->proxy_from pointers in old main */ + blo_clear_proxy_pointers_from_lib(fd, oldmain); - /* separate libraries from G.main */ - blo_split_main(&mainlist, G.main); + /* separate libraries from old main */ + blo_split_main(&mainlist, oldmain); /* add the library pointers in oldmap lookup */ blo_add_library_pointer_map(&mainlist, fd); - /* makes lookup of existing images in G.main */ - blo_make_image_pointer_map(fd); + /* makes lookup of existing images in old main */ + blo_make_image_pointer_map(fd, oldmain); bfd= blo_read_file_internal(fd, reports); if (bfd) { @@ -388,17 +387,17 @@ } /* ensures relinked images are not freed */ - blo_end_image_pointer_map(fd); + blo_end_image_pointer_map(fd, oldmain); - /* move libraries from G.main to new main */ + /* move libraries from old main to new main */ if(bfd && mainlist.first!=mainlist.last) { /* Library structs themselves */ - bfd->main->library= G.main->library; - G.main->library.first= G.main->library.last= NULL; + bfd->main->library= oldmain->library; + oldmain->library.first= oldmain->library.last= NULL; /* add the Library mainlist to the new main */ - BLI_remlink(&mainlist, G.main); + BLI_remlink(&mainlist, oldmain); BLI_addhead(&mainlist, bfd->main); } blo_join_main(&mainlist); Modified: branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c =================================================================== --- branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c 2008-12-19 16:25:50 UTC (rev 17950) +++ branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c 2008-12-19 16:36:15 UTC (rev 17951) @@ -1123,20 +1123,19 @@ * to clear that pointer before reading the undo memfile since * the object might be removed, it is set again in reading * if the local object still exists */ -void blo_clear_proxy_pointers_from_lib(FileData *fd) +void blo_clear_proxy_pointers_from_lib(FileData *fd, Main *oldmain) { - Object *ob= G.main->object.first; + Object *ob= oldmain->object.first; for(;ob; ob= ob->id.next) if(ob->id.lib) ob->proxy_from= NULL; } -/* assumed; G.main still exists */ -void blo_make_image_pointer_map(FileData *fd) +void blo_make_image_pointer_map(FileData *fd, Main *oldmain) { - Image *ima= G.main->image.first; - Scene *sce= G.main->scene.first; + Image *ima= oldmain->image.first; + Scene *sce= oldmain->scene.first; fd->imamap= oldnewmap_new(); @@ -1156,13 +1155,13 @@ } } -/* set G.main image ibufs to zero if it has been restored */ -/* this works because freeing G.main only happens after this call */ -void blo_end_image_pointer_map(FileData *fd) +/* set old main image ibufs to zero if it has been restored */ +/* this works because freeing old main only happens after this call */ +void blo_end_image_pointer_map(FileData *fd, Main *oldmain) { OldNew *entry= fd->imamap->entries; - Image *ima= G.main->image.first; - Scene *sce= G.main->scene.first; + Image *ima= oldmain->image.first; + Scene *sce= oldmain->scene.first; int i; /* used entries were restored, so we put them to zero */ @@ -9246,24 +9245,24 @@ } } -static int object_in_any_scene(Object *ob) +static int object_in_any_scene(Main *mainvar, Object *ob) { Scene *sce; - for(sce= G.main->scene.first; sce; sce= sce->id.next) + for(sce= mainvar->scene.first; sce; sce= sce->id.next) if(object_in_scene(ob, sce)) return 1; return 0; } /* when *lib set, it also does objects that were in the appended group */ -static void give_base_to_objects(Scene *sce, ListBase *lb, Library *lib, int is_group_append) +static void give_base_to_objects(Main *mainvar, Scene *sce, Library *lib, int is_group_append) { Object *ob; Base *base; /* give all objects which are LIB_INDIRECT a base, or for a group when *lib has been set */ - for(ob= lb->first; ob; ob= ob->id.next) { + for(ob= mainvar->object.first; ob; ob= ob->id.next) { if( ob->id.flag & LIB_INDIRECT ) { @@ -9279,7 +9278,7 @@ if(ob->id.us==0) do_it= 1; else if(ob->id.us==1 && lib) - if(ob->id.lib==lib && (ob->flag & OB_FROMGROUP) && object_in_any_scene(ob)==0) + if(ob->id.lib==lib && (ob->flag & OB_FROMGROUP) && object_in_any_scene(mainvar, ob)==0) do_it= 1; if(do_it) { @@ -9380,14 +9379,14 @@ /* common routine to append/link something from a library */ -static Library* library_append(Scene *scene, char* file, char *dir, int idcode, +static Library* library_append(Main *mainvar, Scene *scene, char* file, char *dir, int idcode, int totsel, FileData **fd, struct direntry* filelist, int totfile, short flag) { Main *mainl; Library *curlib; /* make mains */ - blo_split_main(&(*fd)->mainlist, G.main); + blo_split_main(&(*fd)->mainlist, mainvar); /* which one do we need? */ mainl = blo_find_main(*fd, &(*fd)->mainlist, dir, G.sce); @@ -9424,21 +9423,21 @@ } blo_join_main(&(*fd)->mainlist); - G.main= (*fd)->mainlist.first; @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs