PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/test_data/c_code/0007.c

https://gitlab.com/ideasman42/py-array-cow
C | 557 lines | 381 code | 94 blank | 82 comment | 55 complexity | d20b776d47330e21831de88b7f84f11b MD5 | raw file
  1. /*
  2. * $Id$
  3. *
  4. * ***** BEGIN GPL/BL DUAL 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. The Blender
  10. * Foundation also sells licenses for use in proprietary software under
  11. * the Blender License. See http://www.blender.org/BL/ for information
  12. * about this.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software Foundation,
  21. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  24. * All rights reserved.
  25. *
  26. * The Original Code is: all of this file.
  27. *
  28. * Contributor(s): none yet.
  29. *
  30. * ***** END GPL/BL DUAL LICENSE BLOCK *****
  31. */
  32. #include <stdlib.h>
  33. #ifdef HAVE_CONFIG_H
  34. #include <config.h>
  35. #endif
  36. /* This little block needed for linking to Blender... */
  37. #include "MEM_guardedalloc.h"
  38. #ifdef WIN32
  39. #include "BLI_winstuff.h"
  40. #endif
  41. #include "GEN_messaging.h"
  42. #include "DNA_ID.h"
  43. #include "BLI_blenlib.h"
  44. #include "BKE_utildefines.h"
  45. #include "BKE_blender.h"
  46. #include "BKE_global.h"
  47. #include "BKE_main.h"
  48. #include "BKE_scene.h"
  49. #include "BIF_gl.h"
  50. #include "BIF_graphics.h"
  51. #include "BIF_mainqueue.h"
  52. #include "BIF_graphics.h"
  53. #include "BIF_editsound.h"
  54. #include "BIF_usiblender.h"
  55. #include "BIF_drawscene.h" /* set_scene() */
  56. #include "BIF_screen.h" /* waitcursor and more */
  57. #include "BIF_usiblender.h"
  58. #include "BIF_toolbox.h"
  59. #include "BLO_writefile.h"
  60. #include "BLO_readfile.h"
  61. #include "BPY_extern.h" // for init of blender python extension
  62. #include "BSE_headerbuttons.h" // for BIF_read_homefile
  63. #include "BDR_drawmesh.h"
  64. #include "RE_renderconverter.h"
  65. #include "playanim_ext.h"
  66. #include "mydevice.h"
  67. #include "render.h"
  68. #include "nla.h"
  69. /* for passing information between creator and gameengine */
  70. #include "SYS_System.h"
  71. #include <signal.h>
  72. #ifdef __FreeBSD__
  73. #ifndef __OpenBSD__
  74. #include <floatingpoint.h>
  75. #include <sys/rtprio.h>
  76. #endif
  77. #endif
  78. #ifdef WITH_QUICKTIME
  79. # ifdef _WIN32
  80. # include <QTML.h>
  81. # endif /* _WIN32 */
  82. # if defined (_WIN32) || defined (__APPLE__)
  83. # include <Movies.h>
  84. # elif defined (__linux__)
  85. # include <quicktime/lqt.h>
  86. # endif /* __linux__ */
  87. #endif /* WITH_QUICKTIME */
  88. // from buildinfo.c
  89. extern char * build_date;
  90. extern char * build_time;
  91. extern char * build_platform;
  92. extern char * build_type;
  93. /* Local Function prototypes */
  94. static void print_help();
  95. /* for the callbacks: */
  96. extern int pluginapi_force_ref(void); /* from blenpluginapi:pluginapi.c */
  97. char bprogname[FILE_MAXDIR+FILE_MAXFILE];
  98. /* Initialise callbacks for the modules that need them */
  99. void setCallbacks(void);
  100. static void fpe_handler(int sig)
  101. {
  102. // printf("SIGFPE trapped\n");
  103. }
  104. static void print_help(void)
  105. {
  106. printf ("Blender V %d.%02d\n", G.version/100, G.version%100);
  107. printf ("Usage: blender [options ...] [file]\n");
  108. printf ("\nRender options:\n");
  109. printf (" -b <file>\tRender <file> in background\n");
  110. printf (" -S <name>\tSet scene <name>\n");
  111. printf (" -f <frame>\tRender frame <frame> and save it\n");
  112. printf (" -s <frame>\tSet start to frame <frame> (use with -a)\n");
  113. printf (" -e <frame>\tSet end to frame (use with -a)<frame>\n");
  114. printf (" -a\t\tRender animation\n");
  115. printf ("\nAnimation options:\n");
  116. printf (" -a <file(s)>\tPlayback <file(s)>\n");
  117. printf (" -p <sx> <sy>\tOpen with lower left corner at <sx>, <sy>\n");
  118. printf (" -m\t\tRead from disk (Don't buffer)\n");
  119. printf ("\nWindow options:\n");
  120. printf (" -w\t\tForce opening with borders\n");
  121. #ifdef WIN32
  122. printf (" -W\t\tForce opening without borders\n");
  123. #endif
  124. printf (" -p <sx> <sy> <w> <h>\tOpen with lower left corner at <sx>, <sy>\n");
  125. printf (" \tand width and height <w>, <h>\n");
  126. printf ("\nGame Engine specific options:\n");
  127. printf (" -g fixedtime\t\tRun on 50 hertz without dropping frames\n");
  128. printf (" -g vertexarrays\tUse Vertex Arrays for rendering (usually faster)\n");
  129. printf (" -g noaudio\t\tNo audio in Game Engine\n");
  130. printf (" -g nomipmap\t\tNo Texture Mipmapping\n");
  131. printf (" -g linearmipmap\tLinear Texture Mipmapping instead of Nearest (default)\n");
  132. printf ("\nMisc options:\n");
  133. printf (" -d\t\tTurn debugging on\n");
  134. printf (" -noaudio\tDisable audio on systems that support audio\n");
  135. printf (" -h\t\tPrint this help text\n");
  136. printf (" -y\t\tDisable OnLoad scene scripts, use -Y to find out why its -y\n");
  137. #ifdef WIN32
  138. printf (" -R\t\tRegister .blend extension\n");
  139. #endif
  140. }
  141. double PIL_check_seconds_timer(void);
  142. extern void winlay_get_screensize(int *width_r, int *height_r);
  143. int main(int argc, char **argv)
  144. {
  145. int a, i, stax, stay, sizx, sizy;
  146. SYS_SystemHandle syshandle;
  147. Scene *sce;
  148. #if defined(WIN32) || defined (__linux__)
  149. int audio = 1;
  150. #else
  151. int audio = 0;
  152. #endif
  153. setCallbacks();
  154. #ifdef __APPLE__
  155. /* patch to ignore argument finder gives us (pid?) */
  156. if (argc==2 && strncmp(argv[1], "-psn_", 5)==0) {
  157. extern int GHOST_HACK_getFirstFile(char buf[]);
  158. static char firstfilebuf[512];
  159. int scr_x,scr_y;
  160. argc= 1;
  161. setprefsize(100, 100, 800, 600);
  162. winlay_get_screensize(&scr_x, &scr_y);
  163. winlay_process_events(0);
  164. if (GHOST_HACK_getFirstFile(firstfilebuf)) {
  165. argc= 2;
  166. argv[1]= firstfilebuf;
  167. }
  168. }
  169. #endif
  170. #ifdef __FreeBSD__
  171. fpsetmask(0);
  172. #endif
  173. #ifdef __linux__
  174. #ifdef __alpha__
  175. signal (SIGFPE, fpe_handler);
  176. #endif
  177. #endif
  178. #if defined(__sgi)
  179. signal (SIGFPE, fpe_handler);
  180. #endif
  181. // copy path to executable in bprogname. playanim and creting runtimes
  182. // need this.
  183. BLI_where_am_i(bprogname, argv[0]);
  184. /* Hack - force inclusion of the plugin api functions,
  185. * see blenpluginapi:pluginapi.c
  186. */
  187. pluginapi_force_ref();
  188. initglobals(); /* blender.c */
  189. syshandle = SYS_GetSystem();
  190. GEN_init_messaging_system();
  191. /* first test for background */
  192. G.f |= G_SCENESCRIPT; /* scenescript always set! */
  193. for(a=1; a<argc; a++) {
  194. /* Handle unix and windows style help requests */
  195. if ((!strcmp(argv[a], "--help")) || (!strcmp(argv[a], "/?"))){
  196. print_help();
  197. exit(0);
  198. }
  199. /* Handle -* switches */
  200. else if(argv[a][0] == '-') {
  201. switch(argv[a][1]) {
  202. case 'a':
  203. playanim(argc-1, argv+1);
  204. exit(0);
  205. break;
  206. case 'b':
  207. case 'B':
  208. G.background = 1;
  209. a= argc;
  210. break;
  211. case 'm':
  212. /* unified render pipeline */
  213. /* G.magic = 1; has become obsolete */
  214. printf("-m: enable unified renderer has become obsolete. Set \n");
  215. printf("\tthis option per individual file now.\n");
  216. break;
  217. case 'y':
  218. G.f &= ~G_SCENESCRIPT;
  219. break;
  220. case 'Y':
  221. printf ("-y was used to disable scene scripts because,\n");
  222. printf ("\t-p being taken, Ton was of the opinion that Y\n");
  223. printf ("\tlooked like a split (disabled) snake, and also\n");
  224. printf ("\twas similar to a python's tongue (unproven).\n\n");
  225. printf ("\tZr agreed because it gave him a reason to add a\n");
  226. printf ("\tcompletely useless text into Blender.\n\n");
  227. printf ("\tADDENDUM! Ton, in defense, found this picture of\n");
  228. printf ("\tan Australian python, exhibiting her (his/its) forked\n");
  229. printf ("\tY tongue. It could be part of an H Zr retorted!\n\n");
  230. printf ("\thttp://www.users.bigpond.com/snake.man/\n");
  231. exit(252);
  232. case 'h':
  233. print_help();
  234. exit(0);
  235. default:
  236. break;
  237. }
  238. }
  239. }
  240. #ifdef __sgi
  241. setuid(getuid()); /* end superuser */
  242. #endif
  243. RE_init_render_data(); /* must be called here because R.winpos from default file */
  244. if(G.background==0) {
  245. for(a=1; a<argc; a++) {
  246. if(argv[a][0] == '-') {
  247. switch(argv[a][1]) {
  248. case 'p': /* prefsize */
  249. if (argc-a < 5) {
  250. printf ("-p requires four arguments\n");
  251. exit(1);
  252. }
  253. a++;
  254. stax= atoi(argv[a]);
  255. a++;
  256. stay= atoi(argv[a]);
  257. a++;
  258. sizx= atoi(argv[a]);
  259. a++;
  260. sizy= atoi(argv[a]);
  261. setprefsize(stax, stay, sizx, sizy);
  262. break;
  263. case 'd':
  264. G.f |= G_DEBUG; /* std output printf's */
  265. printf ("Blender V %d.%02d\n", G.version/100, G.version%100);
  266. #ifdef NAN_BUILDINFO
  267. printf("Build: %s %s %s %s\n", build_date, build_time, build_platform, build_type);
  268. #endif // NAN_BUILDINFO
  269. for (i = 0; i < argc; i++) {
  270. printf("argv[%d] = %s\n", i, argv[i]);
  271. }
  272. break;
  273. case 'w':
  274. /* XXX, fixme zr, with borders */
  275. /* there probably is a better way to do
  276. * this, right now do as if blender was
  277. * called with "-p 0 0 xres yres" -- sgefant
  278. */
  279. winlay_get_screensize(&sizx, &sizy);
  280. setprefsize(0, 0, sizx, sizy);
  281. break;
  282. case 'W':
  283. /* XXX, fixme zr, borderless on win32 */
  284. break;
  285. case 'n':
  286. case 'N':
  287. if (strcasecmp(argv[a], "-noaudio") == 0|| strcasecmp(argv[a], "-nosound") == 0) {
  288. /**
  289. notify the gameengine that no audio is wanted, even if the user didn't give
  290. the flag -g noaudio
  291. */
  292. SYS_WriteCommandLineInt(syshandle,"noaudio",1);
  293. audio = 0;
  294. if (G.f & G_DEBUG) printf("setting audio to: %d\n", audio);
  295. }
  296. else if (strcasecmp(argv[a], "-nofrozen") == 0) {
  297. /* disable initialization of frozen python modules */
  298. if (G.f & G_DEBUG) printf("disable frozen modules\n");
  299. G.f |= G_NOFROZEN;
  300. }
  301. break;
  302. }
  303. }
  304. }
  305. BPY_start_python();
  306. /* NOTE: initialize_sound *must be* after start_python,
  307. * at least on FreeBSD */
  308. sound_init_audio();
  309. BIF_init();
  310. }
  311. else {
  312. BPY_start_python();
  313. SYS_WriteCommandLineInt(syshandle,"noaudio",1);
  314. audio = 0;
  315. sound_init_audio();
  316. if (G.f & G_DEBUG) printf("setting audio to: %d\n", audio);
  317. }
  318. RE_init_filt_mask();
  319. #ifdef WITH_QUICKTIME
  320. #ifdef _WIN32
  321. if (InitializeQTML(0) != noErr)
  322. G.have_quicktime = FALSE;
  323. else
  324. G.have_quicktime = TRUE;
  325. #endif /* _WIN32 */
  326. /* Initialize QuickTime */
  327. #if defined(_WIN32) || defined (__APPLE__)
  328. if (EnterMovies() != noErr)
  329. G.have_quicktime = FALSE;
  330. else
  331. #endif /* _WIN32 || __APPLE__ */
  332. #ifdef __linux__
  333. /* inititalize quicktime codec registry */
  334. lqt_registry_init();
  335. #endif
  336. G.have_quicktime = TRUE;
  337. #endif /* WITH_QUICKTIME */
  338. /* OK we are ready for it */
  339. for(a=1; a<argc; a++) {
  340. if (G.afbreek==1) break;
  341. if(argv[a][0] == '-') {
  342. switch(argv[a][1]) {
  343. case 'p': /* prefsize */
  344. a+= 4;
  345. break;
  346. case 'g':
  347. {
  348. /**
  349. gameengine parameters are automaticly put into system
  350. -g [paramname = value]
  351. -g [boolparamname]
  352. example:
  353. -g novertexarrays
  354. -g maxvertexarraysize = 512
  355. */
  356. if(++a < argc)
  357. {
  358. char* paramname = argv[a];
  359. /* check for single value versus assignment */
  360. if (a+1 < argc && (*(argv[a+1]) == '='))
  361. {
  362. a++;
  363. if (a+1 < argc)
  364. {
  365. a++;
  366. /* assignment */
  367. SYS_WriteCommandLineString(syshandle,paramname,argv[a]);
  368. } else
  369. {
  370. printf("error: argument assignment (%s) without value.\n",paramname);
  371. }
  372. /* name arg eaten */
  373. } else
  374. {
  375. SYS_WriteCommandLineInt(syshandle,argv[a],1);
  376. /* doMipMap */
  377. if (!strcmp(argv[a],"nomipmap"))
  378. {
  379. set_mipmap(0); //doMipMap = 0;
  380. }
  381. /* linearMipMap */
  382. if (!strcmp(argv[a],"linearmipmap"))
  383. {
  384. set_linear_mipmap(1); //linearMipMap = 1;
  385. }
  386. } /* if (*(argv[a+1]) == '=') */
  387. } /* if(++a < argc) */
  388. break;
  389. }
  390. case 'f':
  391. a++;
  392. if (G.scene && a < argc) {
  393. G.real_sfra = (G.scene->r.sfra);
  394. G.real_efra = (G.scene->r.efra);
  395. (G.scene->r.sfra) = atoi(argv[a]);
  396. (G.scene->r.efra) = (G.scene->r.sfra);
  397. RE_animrender(NULL);
  398. }
  399. break;
  400. case 'a':
  401. if (G.scene) {
  402. G.real_sfra = (G.scene->r.sfra);
  403. G.real_efra = (G.scene->r.efra);
  404. RE_animrender(NULL);
  405. }
  406. break;
  407. case 'S':
  408. if(++a < argc) {
  409. set_scene_name(argv[a]);
  410. }
  411. break;
  412. case 's':
  413. a++;
  414. if(G.scene) {
  415. if (a < argc) (G.scene->r.sfra) = atoi(argv[a]);
  416. }
  417. break;
  418. case 'e':
  419. a++;
  420. if(G.scene) {
  421. if (a < argc) (G.scene->r.efra) = atoi(argv[a]);
  422. }
  423. break;
  424. case 'R':
  425. /* Registering filetypes only makes sense on windows... */
  426. #ifdef WIN32
  427. RegisterBlendExtension(argv[0]);
  428. #endif
  429. break;
  430. }
  431. }
  432. else {
  433. BKE_read_file(argv[a], NULL);
  434. sound_initialize_sounds();
  435. }
  436. }
  437. if(G.background)
  438. {
  439. exit_usiblender();
  440. }
  441. setscreen(G.curscreen);
  442. if(G.main->scene.first==0) {
  443. sce= add_scene("1");
  444. set_scene(sce);
  445. }
  446. screenmain();
  447. return 0;
  448. } /* end of int main(argc,argv) */
  449. static void error_cb(char *err)
  450. {
  451. error("%s", err);
  452. }
  453. void setCallbacks(void)
  454. {
  455. /* Error output from the alloc routines: */
  456. MEM_set_error_stream(stderr);
  457. /* BLI_blenlib: */
  458. BLI_setErrorCallBack(error_cb); /* */
  459. BLI_setInterruptCallBack(blender_test_break);
  460. /* render module: execution flow, timers, cursors and display. */
  461. RE_set_getrenderdata_callback(RE_rotateBlenderScene);
  462. RE_set_freerenderdata_callback(RE_freeRotateBlenderScene);
  463. }