Essential cleanup for mess involved with reading files, initializing UI and

patching versions for UI settings.

Currently four different levels of routines for .blend file reading exist;

/* interface level */
1) BIF_init() -> calls 3
2) BIF_read_file() -> calls 11, optional 4
3) BIF_read_homefile() -> calls 11 or 12, and then 4
4) init_userdef_file()

/* kernel level */
11) BKE_read_file() -> calls 21, and then 14
12) BKE_read_file_from_memory() -> calls 22, and then 14
13) BKE_read_file_from_memfile() -> calls 23, and then 14
14) setup_app_data()

/* loader module level */
21) BLO_read_from_file() -> calls 24
22) BLO_read_from_memory() -> calls 24
23) BLO_read_from_memfile() -> calls 24

/* loader module, internal */
24) blo_read_file_internal()


Note:
- BIF_read_homefile() has additional UI initialize calls, like windows fullscreen and executing commandline options

- Reading from memory (12) only happens for the compiled-in .B.blend

- The "memfile" here is a name I gave to the undo "file" structure. Which is constructed out of memory chunks with basic compression features.

- the kernel function setup_app_data() sets globals like "current screen" and "current scene".

So far, so good. The levels as mentioned here clearly distinguish UI from kernel, and should enable for example game loading (runtime) or background (no UI) loading. In the past years however, 'bad level' dependencies were added, and especially the patches for 'file versions' were added in too many places. The latter is evidently a result of the problem that the "UserDef" struct cannot be initialized/patched if there's not a need for a UI.

Here's how the flow goes in four different cases:

----- Starting up Blender, in foreground with UI --------------------

- creator/creator.c, main() -> calls 1
- If the commandline contains a filename, it calls 11

----- Starting up Blender, in background without UI --------------------

- creator/creator.c, main() -> calls 11 if the commandline has a filename

Note: no Userdef is read, nor initialized. Please note that this was already an existing problem for using Yafray, not setting proper file paths in background mode. The Yafray paths don't belong in the User menu.

----- Starting up Blender as a runtime executable --------------------

This only has calls to 22

----- Loading a file from within the UI (with F1, CTRL+O, using pulldowns) -----

Only calls allowed to 2. It detects if a UserDef has been read too, and in that case the init_userdef_file() will be executed.

Hope this is understandable :)

-Ton-
This commit is contained in:
2004-12-08 14:12:47 +00:00
parent 28303c80e7
commit 8712c7dab4
5 changed files with 145 additions and 130 deletions

View File

@@ -303,20 +303,13 @@ static void setup_app_data(BlendFileData *bfd, char *filename)
G.main= bfd->main;
if (bfd->user) {
/* only here free userdef themes... */
BLI_freelistN(&U.themes);
U= *bfd->user;
MEM_freeN(bfd->user);
/* the UserDef struct is not corrected with do_versions() .... ugh! */
if(U.wheellinescroll == 0) U.wheellinescroll = 3;
if(U.menuthreshold1==0) {
U.menuthreshold1= 5;
U.menuthreshold2= 2;
}
if(U.tb_leftmouse==0) {
U.tb_leftmouse= 5;
U.tb_rightmouse= 5;
}
if(U.mixbufsize==0) U.mixbufsize= 2048;
}
/* case G_FILE_NO_UI or no screens in file */
@@ -374,16 +367,24 @@ static void setup_app_data(BlendFileData *bfd, char *filename)
MEM_freeN(bfd);
}
/* returns:
0: no load file
1: OK
2: OK, and with new user settings
*/
int BKE_read_file(char *dir, void *type_r)
{
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;
@@ -395,7 +396,7 @@ int BKE_read_file(char *dir, void *type_r)
if (!G.background)
waitcursor(0);
return (bfd?1:0);
return (bfd?retval:0);
}
int BKE_read_file_from_memory(char* filebuf, int filelength, void *type_r)

View File

@@ -125,6 +125,104 @@
/***/
/* patching UserDef struct, set globals for UI stuff */
static void init_userdef_file(void)
{
BIF_InitTheme(); // sets default again
mainwindow_set_filename_to_title(""); // empty string re-initializes title to "Blender"
countall();
G.save_over = 0; // start with save preference untitled.blend
/* disable autoplay in .B.blend... */
G.fileflags &= ~G_FILE_AUTOPLAY;
/* the UserDef struct is not corrected with do_versions() .... ugh! */
if(U.wheellinescroll == 0) U.wheellinescroll = 3;
if(U.menuthreshold1==0) {
U.menuthreshold1= 5;
U.menuthreshold2= 2;
}
if(U.tb_leftmouse==0) {
U.tb_leftmouse= 5;
U.tb_rightmouse= 5;
}
if(U.mixbufsize==0) U.mixbufsize= 2048;
if (BLI_streq(U.tempdir, "/")) {
char *tmp= getenv("TEMP");
strcpy(U.tempdir, tmp?tmp:"/tmp/");
}
if (U.savetime <= 0) {
U.savetime = 1;
error(".B.blend is buggy, please consider removing it.\n");
}
if (G.main->versionfile <= 191) {
strcpy(U.plugtexdir, U.textudir);
strcpy(U.sounddir, "/");
}
/* patch to set Dupli Armature */
if (G.main->versionfile < 220) {
U.dupflag |= USER_DUP_ARM;
}
/* userdef new option */
if (G.main->versionfile <= 222) {
U.vrmlflag= USER_VRML_LAYERS;
}
/* added seam, normal color, undo */
if (G.main->versionfile <= 234) {
bTheme *btheme;
U.uiflag |= USER_GLOBALUNDO;
for(btheme= U.themes.first; btheme; btheme= btheme->next) {
/* check for alpha==0 is safe, then color was never set */
if(btheme->tv3d.edge_seam[3]==0) {
btheme->tv3d.edge_seam[0]= 230;
btheme->tv3d.edge_seam[1]= 150;
btheme->tv3d.edge_seam[2]= 50;
btheme->tv3d.edge_seam[3]= 255;
}
if(btheme->tv3d.normal[3]==0) {
btheme->tv3d.normal[0]= 0x22;
btheme->tv3d.normal[1]= 0xDD;
btheme->tv3d.normal[2]= 0xDD;
btheme->tv3d.normal[3]= 255;
}
if(btheme->tv3d.face_dot[3]==0) {
btheme->tv3d.face_dot[0]= 255;
btheme->tv3d.face_dot[1]= 138;
btheme->tv3d.face_dot[2]= 48;
btheme->tv3d.face_dot[3]= 255;
btheme->tv3d.facedot_size= 4;
}
}
}
if (G.main->versionfile <= 235) {
/* illegal combo... */
if (U.flag & USER_LMOUSESELECT)
U.flag &= ~USER_TWOBUTTONMOUSE;
}
if (U.undosteps==0) U.undosteps=32;
reset_autosave();
#ifdef INTERNATIONAL
read_languagefile();
if(U.transopts & USER_DOTRANSLATE)
start_interface_font();
else
G.ui_international = FALSE;
#endif // INTERNATIONAL
}
void BIF_read_file(char *name)
{
extern short winqueue_break; /* editscreen.c */
@@ -137,15 +235,16 @@ void BIF_read_file(char *name)
/* we didn't succeed, now try to read Blender file
calls readfile, calls toolbox, throws one more,
on failure calls the stream, and that is stubbed.... */
BKE_read_file(name, NULL);
int retval= BKE_read_file(name, NULL);
mainwindow_set_filename_to_title(G.main->name);
countall();
sound_initialize_sounds();
winqueue_break= 1; /* leave queues everywhere */
if(retval==2) init_userdef_file(); // in case a userdef is read from regular .blend
undo_editmode_clear();
BKE_reset_undo();
BKE_write_undo("original"); /* save current state */
@@ -153,6 +252,7 @@ void BIF_read_file(char *name)
else BIF_undo_push("Import file");
}
/* only here settings for fullscreen */
int BIF_read_homefile(void)
{
char tstr[FILE_MAXDIR+FILE_MAXFILE], scestr[FILE_MAXDIR];
@@ -160,15 +260,12 @@ int BIF_read_homefile(void)
int success;
#ifdef _WIN32 // FULLSCREEN
static int screenmode = -1;
screenmode = U.uiflag & USER_FLIPFULLSCREEN;
#endif
BLI_make_file_string(G.sce, tstr, home, ".B.blend");
strcpy(scestr, G.sce); /* temporal store */
/* only here free userdef themes... */
BLI_freelistN(&U.themes);
/* prevent loading no UI */
G.fileflags &= ~G_FILE_NO_UI;
@@ -179,118 +276,37 @@ int BIF_read_homefile(void)
success = BKE_read_file_from_memory(datatoc_B_blend, datatoc_B_blend_size, NULL);
}
strcpy(G.sce, scestr);
BIF_InitTheme(); // sets default again
if (success) {
mainwindow_set_filename_to_title(tstr);
countall();
G.save_over = 0;
/* disable autoplay in .B.blend... */
G.fileflags &= ~G_FILE_AUTOPLAY;
#ifdef _WIN32 // FULLSCREEN
/* choose window startmode */
switch (G.windowstate){
case G_WINDOWSTATE_USERDEF: /* use the usersetting */
break;
case G_WINDOWSTATE_FULLSCREEN: /* force fullscreen */
U.uiflag |= USER_FLIPFULLSCREEN;
break;
case G_WINDOWSTATE_BORDER: /* force with borders */
U.uiflag &= ~USER_FLIPFULLSCREEN;
}
if(screenmode != (U.uiflag & USER_FLIPFULLSCREEN)) {
mainwindow_toggle_fullscreen ((U.uiflag & USER_FLIPFULLSCREEN));
screenmode = (U.uiflag & USER_FLIPFULLSCREEN);
}
#endif
if (BLI_streq(U.tempdir, "/")) {
char *tmp= getenv("TEMP");
strcpy(U.tempdir, tmp?tmp:"/tmp/");
}
if (U.savetime <= 0) {
U.savetime = 1;
error("%s is buggy, please consider removing it.\n",
tstr);
}
if (G.main->versionfile <= 191) {
strcpy(U.plugtexdir, U.textudir);
strcpy(U.sounddir, "/");
}
/* patch to set Dupli Armature */
if (G.main->versionfile < 220) {
U.dupflag |= USER_DUP_ARM;
}
/* userdef new option */
if (G.main->versionfile <= 222) {
U.vrmlflag= USER_VRML_LAYERS;
}
/* added seam, normal color, undo */
if (G.main->versionfile <= 234) {
bTheme *btheme;
U.uiflag |= USER_GLOBALUNDO;
for(btheme= U.themes.first; btheme; btheme= btheme->next) {
/* check for alpha==0 is safe, then color was never set */
if(btheme->tv3d.edge_seam[3]==0) {
btheme->tv3d.edge_seam[0]= 230;
btheme->tv3d.edge_seam[1]= 150;
btheme->tv3d.edge_seam[2]= 50;
btheme->tv3d.edge_seam[3]= 255;
}
if(btheme->tv3d.normal[3]==0) {
btheme->tv3d.normal[0]= 0x22;
btheme->tv3d.normal[1]= 0xDD;
btheme->tv3d.normal[2]= 0xDD;
btheme->tv3d.normal[3]= 255;
}
if(btheme->tv3d.face_dot[3]==0) {
btheme->tv3d.face_dot[0]= 255;
btheme->tv3d.face_dot[1]= 138;
btheme->tv3d.face_dot[2]= 48;
btheme->tv3d.face_dot[3]= 255;
btheme->tv3d.facedot_size= 4;
}
}
}
if (G.main->versionfile <= 235) {
/* illegal combo... */
if (U.flag & USER_LMOUSESELECT)
U.flag &= ~USER_TWOBUTTONMOUSE;
}
space_set_commmandline_options();
if (U.undosteps==0) U.undosteps=32;
undo_editmode_clear();
BKE_reset_undo();
BKE_write_undo("original"); /* save current state */
reset_autosave();
#ifdef INTERNATIONAL
read_languagefile();
if(U.transopts & USER_DOTRANSLATE)
start_interface_font();
else
G.ui_international = FALSE;
#endif // INTERNATIONAL
#ifdef _WIN32 // FULLSCREEN
/* choose window startmode */
switch (G.windowstate){
case G_WINDOWSTATE_USERDEF: /* use the usersetting */
break;
case G_WINDOWSTATE_FULLSCREEN: /* force fullscreen */
U.uiflag |= USER_FLIPFULLSCREEN;
break;
case G_WINDOWSTATE_BORDER: /* force with borders */
U.uiflag &= ~USER_FLIPFULLSCREEN;
}
if(screenmode != (U.uiflag & USER_FLIPFULLSCREEN)) {
mainwindow_toggle_fullscreen ((U.uiflag & USER_FLIPFULLSCREEN));
screenmode = (U.uiflag & USER_FLIPFULLSCREEN);
}
#endif
space_set_commmandline_options();
init_userdef_file();
undo_editmode_clear();
BKE_reset_undo();
BKE_write_undo("original"); /* save current state */
return success;
}
static void get_autosave_location(char buf[FILE_MAXDIR+FILE_MAXFILE])
{
char pidstr[32];

View File

@@ -72,8 +72,6 @@
#include "BLO_writefile.h"
#include "BLO_readfile.h"
#include "BSE_headerbuttons.h" // for BIF_read_homefile
#include "BDR_drawmesh.h"
#include "IMB_imbuf.h" // for quicktime_init

View File

@@ -78,8 +78,8 @@ endif
ifeq ($(OS),darwin)
CC = gcc
CCC = g++
CFLAGS += -pipe -fPIC -ffast-math
CCFLAGS += -pipe -fPIC
CFLAGS += -pipe -fPIC -ffast-math -mcpu=7450 -mtune=7450
CCFLAGS += -pipe -fPIC
REL_CFLAGS += -O2
REL_CCFLAGS += -O2
CPPFLAGS += -D_THREAD_SAFE

View File

@@ -137,7 +137,7 @@ endif
export ID = $(shell whoami)
export HOST = $(shell hostname -s)
export PY_FRAMEWORK = 1
# export PY_FRAMEWORK = 1
ifdef PY_FRAMEWORK
export NAN_PYTHON ?= /System/Library/Frameworks/Python.framework/Versions/2.3