Step 3 for the initial commits for 2.5: removing src/ and python,
[blender.git] / source / blender / windowmanager / intern / wm_init_exit.c
1 /**
2  * $Id:
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2007 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <string.h>
32
33 #include "MEM_guardedalloc.h"
34 #include "MEM_CacheLimiterC-Api.h"
35
36 #include "IMB_imbuf_types.h"
37 #include "IMB_imbuf.h"
38
39 #include "DNA_object_types.h"
40 #include "DNA_scene_types.h"
41 #include "DNA_sound_types.h"
42 #include "DNA_userdef_types.h"
43 #include "DNA_windowmanager_types.h"
44
45 #include "BKE_blender.h"
46 #include "BKE_curve.h"
47 #include "BKE_displist.h"
48 #include "BKE_DerivedMesh.h"
49 #include "BKE_font.h"
50 #include "BKE_global.h"
51 #include "BKE_library.h"
52 #include "BKE_mball.h"
53 #include "BKE_utildefines.h"
54 #include "BKE_packedFile.h"
55
56 #include "BMF_Api.h"
57 #include "BIF_language.h"
58 #ifdef INTERNATIONAL
59 #include "FTF_Api.h"
60 #endif
61
62 #include "BLI_blenlib.h"
63
64 #include "BIF_cursors.h"
65 #include "BIF_drawtext.h"
66 #include "BIF_editaction.h"
67 #include "BIF_editarmature.h"
68 #include "BIF_editlattice.h"
69 #include "BIF_editfont.h"
70 #include "BIF_editmesh.h"
71 #include "BIF_editmode_undo.h"
72 #include "BIF_editsound.h"
73 #include "BIF_filelist.h"
74 #include "BIF_fsmenu.h"
75 #include "BIF_interface.h"
76 #include "BIF_gl.h"
77 #include "BIF_poseobject.h"
78 #include "BIF_previewrender.h"
79 #include "BIF_resources.h"
80 #include "BIF_usiblender.h" /* XXX */
81
82 #include "BSE_drawview.h"
83 #include "BSE_edit.h"
84 #include "BSE_editipo.h"
85 #include "BSE_filesel.h"
86 #include "BSE_headerbuttons.h"
87 #include "BSE_node.h"
88
89 #include "BDR_drawobject.h"
90 #include "BDR_editobject.h"
91 #include "BDR_editcurve.h"
92 #include "BDR_imagepaint.h"
93 #include "BDR_vpaint.h"
94
95 #include "RE_pipeline.h"                /* RE_ free stuff */
96
97 #include "radio.h"
98
99 #include "BPY_extern.h"
100
101 #include "SYS_System.h"
102
103 #include "WM_api.h"
104 #include "wm.h"
105 #include "wm_files.h"
106 #include "wm_window.h"
107
108 static void initbuttons(void)
109 {
110 //      uiDefFont(UI_HELVB, 
111 //                        BMF_GetFont(BMF_kHelveticaBold14), 
112 //                        BMF_GetFont(BMF_kHelveticaBold12), 
113 //                        BMF_GetFont(BMF_kHelveticaBold10), 
114 //                        BMF_GetFont(BMF_kHelveticaBold8));
115 //      uiDefFont(UI_HELV, 
116 //                        BMF_GetFont(BMF_kHelvetica12), 
117 //                        BMF_GetFont(BMF_kHelvetica12), 
118 //                        BMF_GetFont(BMF_kHelvetica10), 
119 //                        BMF_GetFont(BMF_kHelveticaBold8));
120         
121 //      glClearColor(.7f, .7f, .6f, 0.0);
122         
123         G.font= BMF_GetFont(BMF_kHelvetica12);
124         G.fonts= BMF_GetFont(BMF_kHelvetica10);
125         G.fontss= BMF_GetFont(BMF_kHelveticaBold8);
126         
127 //      clear_matcopybuf(); /* XXX */
128         
129 //      glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
130 }
131
132 /* XXX */
133 static void sound_init_listener(void)
134 {
135         G.listener = MEM_callocN(sizeof(bSoundListener), "soundlistener");
136         G.listener->gain = 1.0;
137         G.listener->dopplerfactor = 1.0;
138         G.listener->dopplervelocity = 340.29f;
139 }
140
141 /* only called once, for startup */
142 void WM_init(bContext *C)
143 {
144         
145         wm_ghost_init(C);       /* note: it assigns C to ghost! */
146         wm_operatortype_init();
147         
148         set_free_windowmanager_cb(wm_close_and_free);   /* library.c */
149
150         /* get the default database, plus a wm */
151         WM_read_homefile(C, 0);
152         
153         wm_check(C); /* opens window(s), checks keymaps */
154         
155 //      initscreen();   /* for (visual) speed, this first, then setscreen */
156         initbuttons();
157 //      InitCursorData();
158         sound_init_listener();
159 //      init_node_butfuncs();
160         
161 // XXX  BIF_preview_init_dbase();
162         
163         
164 // XXX  BIF_resources_init();   /* after homefile, to dynamically load an icon file based on theme settings */
165         
166 // XXX  BIF_filelist_init_icons();
167         
168 //      init_gl_stuff();        /* drawview.c, after homefile */
169         read_Blog();
170         BLI_strncpy(G.lib, G.sce, FILE_MAX);
171 }
172
173 /* free strings of open recent files */
174 static void free_openrecent(void)
175 {
176         struct RecentFile *recent;
177         
178         for(recent = G.recent_files.first; recent; recent=recent->next)
179                 MEM_freeN(recent->filename);
180         
181         BLI_freelistN(&(G.recent_files));
182 }
183
184
185 /* bad stuff*/
186
187 extern ListBase editNurb;
188 extern ListBase editelems;
189 extern wchar_t *copybuf;
190 extern wchar_t *copybufinfo;
191
192 /* called in creator.c even... tsk, split this! */
193 void WM_exit(bContext *C)
194 {
195         wm_operatortype_free();
196         
197         free_ttfont(); /* bke_font.h */
198         
199 #ifdef WITH_VERSE
200         end_all_verse_sessions();
201 #endif
202         free_openrecent();
203         
204         freeAllRad();
205         BKE_freecubetable();
206         
207 //      if (G.background == 0)
208 //              sound_end_all_sounds();
209         
210         if(G.obedit) {
211                 if(G.obedit->type==OB_FONT) {
212 //                      free_editText();
213                 }
214 //              else if(G.obedit->type==OB_MBALL) BLI_freelistN(&editelems);
215 //              free_editMesh(G.editMesh);
216         }
217         
218 //      free_editLatt();
219 //      free_editArmature();
220 //      free_posebuf();
221         
222         /* before free_blender so py's gc happens while library still exists */
223         /* needed at least for a rare sigsegv that can happen in pydrivers */
224 //      BPY_end_python();
225         
226 //      fastshade_free_render();        /* shaded view */
227         free_blender();                         /* blender.c, does entire library */
228 //      free_matcopybuf();
229 //      free_ipocopybuf();
230 //      free_actcopybuf();
231 //      free_vertexpaint();
232 //      free_imagepaint();
233         
234         /* editnurb can remain to exist outside editmode */
235         freeNurblist(&editNurb);
236         
237 //      fsmenu_free();
238         
239 #ifdef INTERNATIONAL
240 //      free_languagemenu();
241 #endif
242         
243         RE_FreeAllRender();
244         
245 //      free_txt_data();
246         
247 //      sound_exit_audio();
248         if(G.listener) MEM_freeN(G.listener);
249         
250         
251         libtiff_exit();
252         
253 #ifdef WITH_QUICKTIME
254         quicktime_exit();
255 #endif
256         
257         if (!G.background) {
258 // XXX          BIF_resources_free();
259                 
260 // XXX          BIF_filelist_free_icons();
261         }
262         
263 #ifdef INTERNATIONAL
264         FTF_End();
265 #endif
266         
267 //      if (copybuf) MEM_freeN(copybuf);
268 //      if (copybufinfo) MEM_freeN(copybufinfo);
269         
270         /* undo free stuff */
271 //      undo_editmode_clear();
272         
273         BKE_undo_save_quit();   // saves quit.blend if global undo is on
274         BKE_reset_undo(); 
275         
276         BLI_freelistN(&U.themes);
277 // XXX  BIF_preview_free_dbase();
278         
279         MEM_freeN(C);
280         
281         if(totblock!=0) {
282                 printf("Error Totblock: %d\n",totblock);
283                 MEM_printmemlist();
284         }
285 //      delete_autosave();
286         
287         printf("\nBlender quit\n");
288         
289 #ifdef WIN32   
290         /* ask user to press enter when in debug mode */
291         if(G.f & G_DEBUG) {
292                 printf("press enter key to exit...\n\n");
293                 getchar();
294         }
295 #endif 
296         
297         
298         SYS_DeleteSystem(SYS_GetSystem());
299         
300         exit(G.afbreek==1);
301 }
302