Initialize libbullet git in 2.0_beta.
[platform/upstream/libbullet.git] / Extras / Serialize / BlenderSerialize / bMain.cpp
1 /*
2 bParse
3 Copyright (c) 2006-2009 Charlie C & Erwin Coumans  http://gamekit.googlecode.com
4
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15
16 #include "bMain.h"
17 #include "bBlenderFile.h"
18 #include "bDefines.h"
19 #include "bChunk.h"
20 #include "bDNA.h"
21
22 using namespace bParse;
23
24
25 // ----------------------------------------------------- //
26 bMain::bMain(bBlenderFile *filePtr, const char *baseName, int fileVersion)
27         :       mFP(filePtr),
28                 mVersion(fileVersion),
29                 mName(baseName) 
30 {
31         mData.insert(ID_SCE,bListBasePtr());
32         mData.insert(ID_LI,bListBasePtr());
33         mData.insert(ID_OB,bListBasePtr());
34         mData.insert(ID_ME,bListBasePtr());
35         mData.insert(ID_CU,bListBasePtr());
36         mData.insert(ID_MB,bListBasePtr());
37         mData.insert(ID_MA,bListBasePtr());
38         mData.insert(ID_TE,bListBasePtr());
39         mData.insert(ID_IM,bListBasePtr());
40         mData.insert(ID_WV,bListBasePtr());
41         mData.insert(ID_LT,bListBasePtr());
42         mData.insert(ID_LA,bListBasePtr());
43         mData.insert(ID_CA,bListBasePtr());
44         mData.insert(ID_IP,bListBasePtr());
45         mData.insert(ID_KE,bListBasePtr());
46         mData.insert(ID_WO,bListBasePtr());
47         mData.insert(ID_SCR,bListBasePtr());
48         mData.insert(ID_VF,bListBasePtr());
49         mData.insert(ID_TXT,bListBasePtr());
50         mData.insert(ID_SO,bListBasePtr());
51         mData.insert(ID_GR,bListBasePtr());
52         mData.insert(ID_AR,bListBasePtr());
53         mData.insert(ID_AC,bListBasePtr());
54         mData.insert(ID_NT,bListBasePtr());
55         mData.insert(ID_BR,bListBasePtr());
56         mData.insert(ID_SCRIPT, bListBasePtr());
57 }
58
59
60 // ----------------------------------------------------- //
61 bMain::~bMain()
62 {
63         // allocated data blocks!
64
65         int sz = mPool.size();
66         for (int i=0;i<sz;i++)
67         {
68                 delete [] mPool[i];
69         }
70 }
71
72 // ----------------------------------------------------- //
73 int bMain::getVersion()
74 {
75         return mVersion;
76 }
77
78 // ----------------------------------------------------- //
79 const char *bMain::getName()
80 {
81         return mName;
82 }
83
84 // ----------------------------------------------------- //
85 void bMain::addDatablock(void *allocated)
86 {
87         assert(allocated);
88         mPool.push_back((bStructHandle*)allocated);
89 }
90
91
92
93
94 // ------------------------------------------------------------//
95 void bMain::linkList(void *listBasePtr)
96 {
97
98         struct ListBase // local Blender::ListBase
99         {
100                 void *first;
101                 void *last;
102         };
103
104         struct Link // local Blender::Link
105         {
106                 void *next;
107                 void *prev;
108         };
109
110
111         ListBase *base = (ListBase*)listBasePtr;
112
113         if (!base || !base->first)
114                 return;
115
116         base->first = mFP->findLibPointer(base->first);
117         if (!base->first)
118         {
119                 base->last = 0;
120                 return;
121         }
122
123         void *prev = 0;
124         Link *l = (Link*)base->first;
125         while (l)
126         {
127                 l->next = mFP->findLibPointer(l->next);
128                 l->prev = l->next;
129                 prev = l->next;
130                 l = (Link*)l->next;
131         }
132 }
133
134 // ------------------------------------------------------------//
135 bListBasePtr* bMain::getListBasePtr(int listBaseCode)
136 {
137         bListBasePtr *ptr = _findCode(listBaseCode);
138         if (!ptr)
139                 return 0;
140         return ptr;
141 }
142
143 // ------------------------------------------------------------//
144 bListBasePtr *bMain::_findCode(int code)
145 {
146         
147         bListBasePtr* lbPtr = mData.find(code);
148         return lbPtr;
149 }
150
151
152 // ------------------------------------------------------------//
153 bListBasePtr *bMain::getScene()
154 {
155         bListBasePtr *ptr = _findCode(ID_SCE);
156         if (!ptr)
157                 return 0;
158         return ptr;
159 }
160
161 // ------------------------------------------------------------//
162 bListBasePtr *bMain::getLibrary()
163 {
164         bListBasePtr *ptr = _findCode(ID_LI);
165         if (!ptr)
166                 return 0;
167         return ptr;
168 }
169 // ------------------------------------------------------------//
170 bListBasePtr *bMain::getObject()
171 {
172         bListBasePtr *ptr = _findCode(ID_OB);
173         if (!ptr)
174                 return 0;
175         return ptr;
176 }
177
178 // ------------------------------------------------------------//
179 bListBasePtr *bMain::getMesh()
180 {
181         bListBasePtr *ptr = _findCode(ID_ME);
182         if (!ptr)
183                 return 0;
184         return ptr;
185 }
186
187 // ------------------------------------------------------------//
188 bListBasePtr *bMain::getCurve()
189 {
190         bListBasePtr *ptr = _findCode(ID_CU);
191         if (!ptr)
192                 return 0;
193         return ptr;
194 }
195
196
197
198 // ------------------------------------------------------------//
199 bListBasePtr *bMain::getMball()
200 {
201         bListBasePtr *ptr = _findCode(ID_MB);
202         if (!ptr)
203                 return 0;
204         return ptr;
205 }
206
207 // ------------------------------------------------------------//
208 bListBasePtr *bMain::getMat()
209 {
210         bListBasePtr *ptr = _findCode(ID_MA);
211         if (!ptr)
212                 return 0;
213         return ptr;
214 }
215
216 // ------------------------------------------------------------//
217 bListBasePtr *bMain::getTex()
218 {
219         bListBasePtr *ptr = _findCode(ID_TE);
220         if (!ptr)
221                 return 0;
222         return ptr;
223 }
224
225
226 // ------------------------------------------------------------//
227 bListBasePtr *bMain::getImage()
228 {
229         bListBasePtr *ptr = _findCode(ID_IM);
230         if (!ptr)
231                 return 0;
232         return ptr;
233 }
234
235 // ------------------------------------------------------------//
236 bListBasePtr *bMain::getWave()
237 {
238         bListBasePtr *ptr = _findCode(ID_WV);
239         if (!ptr)
240                 return 0;
241         return ptr;
242 }
243
244 // ------------------------------------------------------------//
245 bListBasePtr *bMain::getLatt()
246 {
247         bListBasePtr *ptr = _findCode(ID_LT);
248         if (!ptr)
249                 return 0;
250         return ptr;
251 }
252
253 // ------------------------------------------------------------//
254 bListBasePtr *bMain::getLamp()
255 {
256         bListBasePtr *ptr = _findCode(ID_LA);
257         if (!ptr)
258                 return 0;
259         return ptr;
260 }
261
262 // ------------------------------------------------------------//
263 bListBasePtr *bMain::getCamera()
264 {
265         bListBasePtr *ptr = _findCode(ID_CA);
266         if (!ptr)
267                 return 0;
268         return ptr;
269 }
270
271 // ------------------------------------------------------------//
272 bListBasePtr *bMain::getIpo()
273 {
274         bListBasePtr *ptr = _findCode(ID_IP);
275         if (!ptr)
276                 return 0;
277         return ptr;
278 }
279
280 // ------------------------------------------------------------//
281 bListBasePtr *bMain::getKey()
282 {
283         bListBasePtr *ptr = _findCode(ID_KE);
284         if (!ptr)
285                 return 0;
286         return ptr;
287 }
288
289 // ------------------------------------------------------------//
290 bListBasePtr *bMain::getWorld()
291 {
292         bListBasePtr *ptr = _findCode(ID_WO);
293         if (!ptr)
294                 return 0;
295         return ptr;
296 }
297
298
299 // ------------------------------------------------------------//
300 bListBasePtr *bMain::getScreen()
301 {
302         bListBasePtr *ptr = _findCode(ID_SCR);
303         if (!ptr)
304                 return 0;
305         return ptr;
306 }
307
308 // ------------------------------------------------------------//
309 bListBasePtr *bMain::getScript()
310 {
311         bListBasePtr *ptr = _findCode(ID_SCRIPT);
312         if (!ptr)
313                 return 0;
314         return ptr;
315 }
316
317 // ------------------------------------------------------------//
318 bListBasePtr *bMain::getVfont()
319 {
320         bListBasePtr *ptr = _findCode(ID_VF);
321         if (!ptr)
322                 return 0;
323         return ptr;
324 }
325
326 // ------------------------------------------------------------//
327 bListBasePtr *bMain::getText()
328 {
329         bListBasePtr *ptr = _findCode(ID_TXT);
330         if (!ptr)
331                 return 0;
332         return ptr;
333 }
334
335 // ------------------------------------------------------------//
336 bListBasePtr *bMain::getSound()
337 {
338         bListBasePtr *ptr = _findCode(ID_SO);
339         if (!ptr)
340                 return 0;
341         return ptr;
342 }
343
344 // ------------------------------------------------------------//
345 bListBasePtr *bMain::getGroup()
346 {
347         bListBasePtr *ptr = _findCode(ID_GR);
348         if (!ptr)
349                 return 0;
350         return ptr;
351 }
352
353 // ------------------------------------------------------------//
354 bListBasePtr *bMain::getArmature()
355 {
356         bListBasePtr *ptr = _findCode(ID_AR);
357         if (!ptr)
358                 return 0;
359         return ptr;
360 }
361
362 // ------------------------------------------------------------//
363 bListBasePtr *bMain::getAction()
364 {
365         bListBasePtr *ptr = _findCode(ID_AC);
366         if (!ptr)
367                 return 0;
368         return ptr;
369 }
370
371
372 // ------------------------------------------------------------//
373 bListBasePtr *bMain::getNodetree()
374 {
375         bListBasePtr *ptr = _findCode(ID_NT);
376         if (!ptr)
377                 return 0;
378         return ptr;
379 }
380
381 // ------------------------------------------------------------//
382 bListBasePtr *bMain::getBrush()
383 {
384         bListBasePtr *ptr = _findCode(ID_BR);
385         if (!ptr)
386                 return 0;
387         return ptr;
388 }
389
390
391
392 //eof