diff options
Diffstat (limited to 'source/blender/blenkernel/intern/blender.c')
-rw-r--r-- | source/blender/blenkernel/intern/blender.c | 173 |
1 files changed, 69 insertions, 104 deletions
diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index 5dcccc56d06..e5625fa03e0 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -48,12 +48,16 @@ #include "MEM_guardedalloc.h" +#include "DNA_curve_types.h" #include "DNA_listBase.h" #include "DNA_sdna_types.h" #include "DNA_userdef_types.h" #include "DNA_object_types.h" -#include "DNA_curve_types.h" +#include "DNA_mesh_types.h" #include "DNA_scene_types.h" +#include "DNA_screen_types.h" +#include "DNA_sound_types.h" +#include "DNA_sequence_types.h" #include "BLI_blenlib.h" #include "BLI_dynstr.h" @@ -61,9 +65,6 @@ #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" -#include "DNA_mesh_types.h" -#include "DNA_screen_types.h" - #include "BKE_action.h" #include "BKE_blender.h" #include "BKE_curve.h" @@ -76,6 +77,7 @@ #include "BKE_node.h" #include "BKE_object.h" #include "BKE_scene.h" +#include "BKE_screen.h" #include "BKE_sound.h" #include "BLI_editVert.h" @@ -84,15 +86,12 @@ #include "BLO_readfile.h" #include "BLO_writefile.h" -#include "BKE_bad_level_calls.h" // for freeAllRad editNurb free_editMesh free_editText free_editArmature #include "BKE_utildefines.h" // O_BINARY FALSE -#include "BIF_mainqueue.h" // mainqenter for onload script -#include "mydevice.h" -#include "nla.h" -#include "blendef.h" + Global G; UserDef U; +ListBase WMlist= {NULL, NULL}; char versionstr[48]= ""; @@ -168,6 +167,7 @@ void pushpop_test() /* ********** free ********** */ +/* only to be called on exit blender */ void free_blender(void) { /* samples are in a global list..., also sets G.main->sound->sample NULL */ @@ -176,27 +176,13 @@ void free_blender(void) free_main(G.main); G.main= NULL; + BKE_spacetypes_free(); /* after free main, it uses space callbacks */ + IMB_freeImBufdata(); /* imbuf lib */ free_nodesystem(); } -void duplicatelist(ListBase *list1, ListBase *list2) /* copy from 2 to 1 */ -{ - struct Link *link1, *link2; - - list1->first= list1->last= 0; - - link2= list2->first; - while(link2) { - - link1= MEM_dupallocN(link2); - BLI_addtail(list1, link1); - - link2= link2->next; - } -} - static EditMesh theEditMesh; void initglobals(void) @@ -237,21 +223,19 @@ void initglobals(void) static void clear_global(void) { - extern short winqueue_break; /* screen.c */ +// extern short winqueue_break; /* screen.c */ - freeAllRad(); +// XXX freeAllRad(); fastshade_free_render(); /* lamps hang otherwise */ free_main(G.main); /* free all lib data */ - - /* force all queues to be left */ - winqueue_break= 1; if (G.obedit) { - freeNurblist(&editNurb); - free_editMesh(G.editMesh); - free_editText(); - free_editArmature(); +// freeNurblist(&editNurb); +// free_editMesh(G.editMesh); +// free_editText(); +// free_editArmature(); } +// free_vertexpaint(); G.curscreen= NULL; G.scene= NULL; @@ -266,8 +250,6 @@ static void clear_global(void) G.sima= NULL; G.sipo= NULL; - free_vertexpaint(); - G.f &= ~(G_WEIGHTPAINT + G_VERTEXPAINT + G_FACESELECT + G_PARTICLEEDIT); } @@ -314,7 +296,10 @@ static void clean_paths(Main *main) } } -static void setup_app_data(BlendFileData *bfd, char *filename) +/* context matching */ +/* handle no-ui case */ + +static void setup_app_data(bContext *C, BlendFileData *bfd, char *filename) { Object *ob; bScreen *curscreen= NULL; @@ -328,6 +313,8 @@ static void setup_app_data(BlendFileData *bfd, char *filename) clean_paths(bfd->main); + /* XXX here the complex windowmanager matching */ + /* no load screens? */ if(mode) { /* comes from readfile.c */ @@ -337,7 +324,7 @@ static void setup_app_data(BlendFileData *bfd, char *filename) SWAP(ListBase, G.main->script, bfd->main->script); /* we re-use current screen */ - curscreen= G.curscreen; + curscreen= C->screen; /* but use new Scene pointer */ curscene= bfd->curscene; if(curscene==NULL) curscene= bfd->main->scene.first; @@ -348,11 +335,13 @@ static void setup_app_data(BlendFileData *bfd, char *filename) lib_link_screen_restore(bfd->main, curscene); } - clear_global(); /* free Main database */ + /* free G.main Main database */ + clear_global(); if(mode!='u') G.save_over = 1; G.main= bfd->main; + if (bfd->user) { /* only here free userdef themes... */ @@ -360,7 +349,6 @@ static void setup_app_data(BlendFileData *bfd, char *filename) U= *bfd->user; MEM_freeN(bfd->user); - } /* samples is a global list... */ @@ -368,20 +356,20 @@ static void setup_app_data(BlendFileData *bfd, char *filename) /* case G_FILE_NO_UI or no screens in file */ if(mode) { - G.curscreen= curscreen; - G.scene= curscene; + C->screen= curscreen; + C->scene= curscene; } else { G.winpos= bfd->winpos; G.displaymode= bfd->displaymode; G.fileflags= bfd->fileflags; - G.curscreen= bfd->curscreen; - G.scene= G.curscreen->scene; + C->screen= bfd->curscreen; + C->scene= C->screen->scene; } /* this can happen when active scene was lib-linked, and doesnt exist anymore */ - if(G.scene==NULL) { - G.scene= G.main->scene.first; - G.curscreen->scene= G.scene; + if(C->scene==NULL) { + C->scene= G.main->scene.first; + C->screen->scene= C->scene; } /* special cases, override loaded flags: */ @@ -393,11 +381,11 @@ static void setup_app_data(BlendFileData *bfd, char *filename) G.f= bfd->globalf; if (!G.background) { - setscreen(G.curscreen); + //setscreen(G.curscreen); } /* baseflags, groups, make depsgraph, etc */ - set_scene_bg(G.scene); + set_scene_bg(C->scene); /* clear BONE_UNKEYED flags, these are not valid anymore for proxies */ framechange_poses_clear_unkeyed(); @@ -409,11 +397,11 @@ static void setup_app_data(BlendFileData *bfd, char *filename) } /* now tag update flags, to ensure deformers get calculated on redraw */ - DAG_scene_update_flags(G.scene, G.scene->lay); + DAG_scene_update_flags(C->scene, C->scene->lay); if (G.f & G_DOSCRIPTLINKS) { /* there's an onload scriptlink to execute in screenmain */ - mainqenter(ONLOAD_SCRIPT, 1); +// XXX mainqenter(ONLOAD_SCRIPT, 1); } if (G.sce != filename) /* these are the same at times, should never copy to the same location */ strcpy(G.sce, filename); @@ -432,7 +420,7 @@ static void handle_subversion_warning(Main *main) char str[128]; sprintf(str, "File written by newer Blender binary: %d.%d , expect loss of data!", main->minversionfile, main->minsubversionfile); - error(str); +// XXX error(str); } } @@ -443,78 +431,55 @@ static void handle_subversion_warning(Main *main) 2: OK, and with new user settings */ -int BKE_read_file(char *dir, void *type_r) +int BKE_read_file(bContext *C, char *dir, void *unused) { BlendReadError bre; BlendFileData *bfd; int retval= 1; - if (!G.background) - waitcursor(1); - bfd= BLO_read_from_file(dir, &bre); if (bfd) { if(bfd->user) retval= 2; - if (type_r) - *((BlenFileType*)type_r)= bfd->type; - setup_app_data(bfd, dir); + setup_app_data(C, bfd, dir); handle_subversion_warning(G.main); } else { - error("Loading %s failed: %s", dir, BLO_bre_as_string(bre)); +// XXX error("Loading %s failed: %s", dir, BLO_bre_as_string(bre)); } - - if (!G.background) - waitcursor(0); - + return (bfd?retval:0); } -int BKE_read_file_from_memory(char* filebuf, int filelength, void *type_r) +int BKE_read_file_from_memory(bContext *C, char* filebuf, int filelength, void *unused) { BlendReadError bre; BlendFileData *bfd; - - if (!G.background) - waitcursor(1); - + bfd= BLO_read_from_memory(filebuf, filelength, &bre); if (bfd) { - if (type_r) - *((BlenFileType*)type_r)= bfd->type; - - setup_app_data(bfd, "<memory2>"); + setup_app_data(C, bfd, "<memory2>"); } else { - error("Loading failed: %s", BLO_bre_as_string(bre)); +// XXX error("Loading failed: %s", BLO_bre_as_string(bre)); } - - if (!G.background) - waitcursor(0); - + return (bfd?1:0); } /* memfile is the undo buffer */ -int BKE_read_file_from_memfile(MemFile *memfile) +int BKE_read_file_from_memfile(bContext *C, MemFile *memfile) { BlendReadError bre; BlendFileData *bfd; - if (!G.background) - waitcursor(1); - bfd= BLO_read_from_memfile(G.sce, memfile, &bre); if (bfd) { - setup_app_data(bfd, "<memory1>"); + setup_app_data(C, bfd, "<memory1>"); } else { - error("Loading failed: %s", BLO_bre_as_string(bre)); +// XXX error("Loading failed: %s", BLO_bre_as_string(bre)); } - - if (!G.background) - waitcursor(0); - + return (bfd?1:0); } @@ -536,7 +501,7 @@ static ListBase undobase={NULL, NULL}; static UndoElem *curundo= NULL; -static int read_undosave(UndoElem *uel) +static int read_undosave(bContext *C, UndoElem *uel) { char scestr[FILE_MAXDIR+FILE_MAXFILE]; int success=0, fileflags; @@ -546,9 +511,9 @@ static int read_undosave(UndoElem *uel) G.fileflags |= G_FILE_NO_UI; if(UNDO_DISK) - success= BKE_read_file(uel->str, NULL); + success= BKE_read_file(C, uel->str, NULL); else - success= BKE_read_file_from_memfile(&uel->memfile); + success= BKE_read_file_from_memfile(C, &uel->memfile); /* restore */ strcpy(G.sce, scestr); @@ -558,7 +523,7 @@ static int read_undosave(UndoElem *uel) } /* name can be a dynamic string */ -void BKE_write_undo(char *name) +void BKE_write_undo(bContext *C, char *name) { uintptr_t maxmem, totmem, memused; int nr, success; @@ -612,7 +577,7 @@ void BKE_write_undo(char *name) sprintf(numstr, "%d.blend", counter); BLI_make_file_string("/", tstr, btempdir, numstr); - success= BLO_write_file(tstr, G.fileflags, &err); + success= BLO_write_file(C, tstr, G.fileflags, &err); strcpy(curundo->str, tstr); } @@ -623,7 +588,7 @@ void BKE_write_undo(char *name) if(curundo->prev) prevfile= &(curundo->prev->memfile); memused= MEM_get_memory_in_use(); - success= BLO_write_file_mem(prevfile, &curundo->memfile, G.fileflags, &err); + success= BLO_write_file_mem(C, prevfile, &curundo->memfile, G.fileflags, &err); curundo->undosize= MEM_get_memory_in_use() - memused; } @@ -657,28 +622,28 @@ void BKE_write_undo(char *name) /* 1= an undo, -1 is a redo. we have to make sure 'curundo' remains at current situation * Note, ALWAYS call sound_initialize_sounds after BKE_undo_step() */ -void BKE_undo_step(int step) +void BKE_undo_step(bContext *C, int step) { if(step==0) { - read_undosave(curundo); + read_undosave(C, curundo); } else if(step==1) { /* curundo should never be NULL, after restart or load file it should call undo_save */ - if(curundo==NULL || curundo->prev==NULL) error("No undo available"); + if(curundo==NULL || curundo->prev==NULL) ; // XXX error("No undo available"); else { if(G.f & G_DEBUG) printf("undo %s\n", curundo->name); curundo= curundo->prev; - read_undosave(curundo); + read_undosave(C, curundo); } } else { /* curundo has to remain current situation! */ - if(curundo==NULL || curundo->next==NULL) error("No redo available"); + if(curundo==NULL || curundo->next==NULL) ; // XXX error("No redo available"); else { - read_undosave(curundo->next); + read_undosave(C, curundo->next); curundo= curundo->next; if(G.f & G_DEBUG) printf("redo %s\n", curundo->name); } @@ -700,7 +665,7 @@ void BKE_reset_undo(void) } /* based on index nr it does a restore */ -void BKE_undo_number(int nr) +void BKE_undo_number(bContext *C, int nr) { UndoElem *uel; int a=1; @@ -709,7 +674,7 @@ void BKE_undo_number(int nr) if(a==nr) break; } curundo= uel; - BKE_undo_step(0); + BKE_undo_step(C, 0); } char *BKE_undo_menu_string(void) @@ -754,7 +719,7 @@ void BKE_undo_save_quit(void) file = open(str,O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666); if(file == -1) { - error("Unable to save %s, check you have permissions", str); + //XXX error("Unable to save %s, check you have permissions", str); return; } @@ -766,7 +731,7 @@ void BKE_undo_save_quit(void) close(file); - if(chunk) error("Unable to save %s, internal error", str); + if(chunk) ; //XXX error("Unable to save %s, internal error", str); else printf("Saved session recovery to %s\n", str); } |