PageRenderTime 55ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/test_data/c_code/0019.c

https://gitlab.com/ideasman42/py-array-cow
C | 593 lines | 401 code | 100 blank | 92 comment | 57 complexity | db46381a1a3f2d3eadc1e6783a12a05e 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. #include <Movies.h>
  82. #elif defined(__APPLE__)
  83. #undef NDEBUG
  84. #include <QuickTime/Movies.h>
  85. #endif /* __APPLE__ */
  86. #endif /* WITH_QUICKTIME */
  87. // from buildinfo.c
  88. extern char * build_date;
  89. extern char * build_time;
  90. extern char * build_platform;
  91. extern char * build_type;
  92. /* Local Function prototypes */
  93. static void print_help();
  94. /* for the callbacks: */
  95. extern int pluginapi_force_ref(void); /* from blenpluginapi:pluginapi.c */
  96. char bprogname[FILE_MAXDIR+FILE_MAXFILE]; /* from blenpluginapi:pluginapi.c */
  97. /* Initialise callbacks for the modules that need them */
  98. void setCallbacks(void);
  99. static void fpe_handler(int sig)
  100. {
  101. // printf("SIGFPE trapped\n");
  102. }
  103. /* handling ctrl-c event in console */
  104. static void blender_esc(int sig)
  105. {
  106. static int count = 0;
  107. G.afbreek = 1; /* forces render loop to read queue, not sure if its needed */
  108. if (sig == 2) {
  109. if (count) {
  110. printf("\nBlender killed\n");
  111. exit(2);
  112. }
  113. printf("\nSent an internal break event. Press ^C again to kill Blender\n");
  114. count++;
  115. }
  116. }
  117. static void print_help(void)
  118. {
  119. printf ("Blender V %d.%02d\n", G.version/100, G.version%100);
  120. printf ("Usage: blender [options ...] [file]\n");
  121. printf ("\nRender options:\n");
  122. printf (" -b <file>\tRender <file> in background\n");
  123. printf (" -S <name>\tSet scene <name>\n");
  124. printf (" -f <frame>\tRender frame <frame> and save it\n");
  125. printf (" -s <frame>\tSet start to frame <frame> (use with -a)\n");
  126. printf (" -e <frame>\tSet end to frame (use with -a)<frame>\n");
  127. printf (" -a\t\tRender animation\n");
  128. printf ("\nAnimation options:\n");
  129. printf (" -a <file(s)>\tPlayback <file(s)>\n");
  130. printf (" -p <sx> <sy>\tOpen with lower left corner at <sx>, <sy>\n");
  131. printf (" -m\t\tRead from disk (Don't buffer)\n");
  132. printf ("\nWindow options:\n");
  133. printf (" -w\t\tForce opening with borders\n");
  134. #ifdef WIN32
  135. printf (" -W\t\tForce opening without borders\n");
  136. #endif
  137. printf (" -p <sx> <sy> <w> <h>\tOpen with lower left corner at <sx>, <sy>\n");
  138. printf (" \tand width and height <w>, <h>\n");
  139. printf ("\nGame Engine specific options:\n");
  140. printf (" -g fixedtime\t\tRun on 50 hertz without dropping frames\n");
  141. printf (" -g vertexarrays\tUse Vertex Arrays for rendering (usually faster)\n");
  142. printf (" -g noaudio\t\tNo audio in Game Engine\n");
  143. printf (" -g nomipmap\t\tNo Texture Mipmapping\n");
  144. printf (" -g linearmipmap\tLinear Texture Mipmapping instead of Nearest (default)\n");
  145. printf ("\nMisc options:\n");
  146. printf (" -d\t\tTurn debugging on\n");
  147. printf (" -noaudio\tDisable audio on systems that support audio\n");
  148. printf (" -h\t\tPrint this help text\n");
  149. printf (" -y\t\tDisable OnLoad scene scripts, use -Y to find out why its -y\n");
  150. #ifdef WIN32
  151. printf (" -R\t\tRegister .blend extension\n");
  152. #endif
  153. }
  154. double PIL_check_seconds_timer(void);
  155. extern void winlay_get_screensize(int *width_r, int *height_r);
  156. int main(int argc, char **argv)
  157. {
  158. int a, i, stax, stay, sizx, sizy;
  159. SYS_SystemHandle syshandle;
  160. Scene *sce;
  161. #if defined(WIN32) || defined (__linux__)
  162. int audio = 1;
  163. #else
  164. int audio = 0;
  165. #endif
  166. setCallbacks();
  167. #ifdef __APPLE__
  168. /* patch to ignore argument finder gives us (pid?) */
  169. if (argc==2 && strncmp(argv[1], "-psn_", 5)==0) {
  170. extern int GHOST_HACK_getFirstFile(char buf[]);
  171. static char firstfilebuf[512];
  172. int scr_x,scr_y;
  173. argc= 1;
  174. setprefsize(100, 100, 800, 600);
  175. winlay_get_screensize(&scr_x, &scr_y);
  176. winlay_process_events(0);
  177. if (GHOST_HACK_getFirstFile(firstfilebuf)) {
  178. argc= 2;
  179. argv[1]= firstfilebuf;
  180. }
  181. }
  182. #endif
  183. #ifdef __FreeBSD__
  184. fpsetmask(0);
  185. #endif
  186. #ifdef __linux__
  187. #ifdef __alpha__
  188. signal (SIGFPE, fpe_handler);
  189. #endif
  190. #endif
  191. #if defined(__sgi)
  192. signal (SIGFPE, fpe_handler);
  193. #endif
  194. // copy path to executable in bprogname. playanim and creting runtimes
  195. // need this.
  196. BLI_where_am_i(bprogname, argv[0]);
  197. /* Hack - force inclusion of the plugin api functions,
  198. * see blenpluginapi:pluginapi.c
  199. */
  200. pluginapi_force_ref();
  201. initglobals(); /* blender.c */
  202. syshandle = SYS_GetSystem();
  203. GEN_init_messaging_system();
  204. /* first test for background */
  205. G.f |= G_SCENESCRIPT; /* scenescript always set! */
  206. for(a=1; a<argc; a++) {
  207. /* Handle unix and windows style help requests */
  208. if ((!strcmp(argv[a], "--help")) || (!strcmp(argv[a], "/?"))){
  209. print_help();
  210. exit(0);
  211. }
  212. /* Handle -* switches */
  213. else if(argv[a][0] == '-') {
  214. switch(argv[a][1]) {
  215. case 'a':
  216. playanim(argc-1, argv+1);
  217. exit(0);
  218. break;
  219. case 'b':
  220. case 'B':
  221. G.background = 1;
  222. a= argc;
  223. break;
  224. case 'm':
  225. /* unified render pipeline */
  226. /* G.magic = 1; has become obsolete */
  227. printf("-m: enable unified renderer has become obsolete. Set \n");
  228. printf("\tthis option per individual file now.\n");
  229. break;
  230. case 'y':
  231. G.f &= ~G_SCENESCRIPT;
  232. break;
  233. case 'Y':
  234. printf ("-y was used to disable scene scripts because,\n");
  235. printf ("\t-p being taken, Ton was of the opinion that Y\n");
  236. printf ("\tlooked like a split (disabled) snake, and also\n");
  237. printf ("\twas similar to a python's tongue (unproven).\n\n");
  238. printf ("\tZr agreed because it gave him a reason to add a\n");
  239. printf ("\tcompletely useless text into Blender.\n\n");
  240. printf ("\tADDENDUM! Ton, in defense, found this picture of\n");
  241. printf ("\tan Australian python, exhibiting her (his/its) forked\n");
  242. printf ("\tY tongue. It could be part of an H Zr retorted!\n\n");
  243. printf ("\thttp://www.users.bigpond.com/snake.man/\n");
  244. exit(252);
  245. case 'h':
  246. print_help();
  247. exit(0);
  248. default:
  249. break;
  250. }
  251. }
  252. }
  253. #ifdef __sgi
  254. setuid(getuid()); /* end superuser */
  255. #endif
  256. /* for all platforms, even windos has it! */
  257. if(G.background) signal(SIGINT, blender_esc); /* ctrl c out bg render */
  258. RE_init_render_data(); /* must be called here because R.winpos from default file */
  259. if(G.background==0) {
  260. for(a=1; a<argc; a++) {
  261. if(argv[a][0] == '-') {
  262. switch(argv[a][1]) {
  263. case 'p': /* prefsize */
  264. if (argc-a < 5) {
  265. printf ("-p requires four arguments\n");
  266. exit(1);
  267. }
  268. a++;
  269. stax= atoi(argv[a]);
  270. a++;
  271. stay= atoi(argv[a]);
  272. a++;
  273. sizx= atoi(argv[a]);
  274. a++;
  275. sizy= atoi(argv[a]);
  276. setprefsize(stax, stay, sizx, sizy);
  277. break;
  278. case 'd':
  279. G.f |= G_DEBUG; /* std output printf's */
  280. printf ("Blender V %d.%02d\n", G.version/100, G.version%100);
  281. #ifdef NAN_BUILDINFO
  282. printf("Build: %s %s %s %s\n", build_date, build_time, build_platform, build_type);
  283. #endif // NAN_BUILDINFO
  284. for (i = 0; i < argc; i++) {
  285. printf("argv[%d] = %s\n", i, argv[i]);
  286. }
  287. break;
  288. case 'w':
  289. /* XXX, fixme zr, with borders */
  290. /* there probably is a better way to do
  291. * this, right now do as if blender was
  292. * called with "-p 0 0 xres yres" -- sgefant
  293. */
  294. winlay_get_screensize(&sizx, &sizy);
  295. setprefsize(0, 0, sizx, sizy);
  296. #ifdef _WIN32 // FULLSCREEN
  297. G.windowstate = G_WINDOWSTATE_BORDER;
  298. #endif
  299. break;
  300. case 'W':
  301. /* XXX, fixme zr, borderless on win32 */
  302. #ifdef _WIN32 // FULLSCREEN
  303. G.windowstate = G_WINDOWSTATE_FULLSCREEN;
  304. #endif
  305. break;
  306. case 'R':
  307. /* Registering filetypes only makes sense on windows... */
  308. #ifdef WIN32
  309. RegisterBlendExtension(argv[0]);
  310. #endif
  311. break;
  312. case 'n':
  313. case 'N':
  314. if (strcasecmp(argv[a], "-noaudio") == 0|| strcasecmp(argv[a], "-nosound") == 0) {
  315. /**
  316. notify the gameengine that no audio is wanted, even if the user didn't give
  317. the flag -g noaudio.
  318. */
  319. SYS_WriteCommandLineInt(syshandle,"noaudio",1);
  320. audio = 0;
  321. if (G.f & G_DEBUG) printf("setting audio to: %d\n", audio);
  322. }
  323. else if (strcasecmp(argv[a], "-nofrozen") == 0) {
  324. /* disable initialization of frozen python modules */
  325. if (G.f & G_DEBUG) printf("disable frozen modules\n");
  326. G.f |= G_NOFROZEN;
  327. }
  328. break;
  329. }
  330. }
  331. }
  332. BPY_start_python();
  333. /**
  334. * NOTE: sound_init_audio() *must be* after start_python,
  335. * at least on FreeBSD.
  336. */
  337. sound_init_audio();
  338. BIF_init();
  339. /**
  340. * NOTE: the U.pythondir string is NULL until BIF_init() is executed,
  341. * so we provide the BPY_ function below to append the user defined
  342. * pythondir to Python's sys.path at this point. Simply putting
  343. * BIF_init() before BPY_start_python() crashes Blender at startup.
  344. */
  345. BPY_syspath_append_pythondir();
  346. }
  347. else {
  348. BPY_start_python();
  349. SYS_WriteCommandLineInt(syshandle,"noaudio",1);
  350. audio = 0;
  351. sound_init_audio();
  352. if (G.f & G_DEBUG) printf("setting audio to: %d\n", audio);
  353. }
  354. RE_init_filt_mask();
  355. #ifdef WITH_QUICKTIME
  356. #ifdef _WIN32
  357. if (InitializeQTML(0) != noErr)
  358. G.have_quicktime = FALSE;
  359. else
  360. G.have_quicktime = TRUE;
  361. #endif /* _WIN32 */
  362. /* Initialize QuickTime */
  363. #if defined(_WIN32) || defined (__APPLE__)
  364. if (EnterMovies() != noErr)
  365. G.have_quicktime = FALSE;
  366. else
  367. #endif /* _WIN32 || __APPLE__ */
  368. #ifdef __linux__
  369. /* inititalize quicktime codec registry */
  370. lqt_registry_init();
  371. #endif
  372. G.have_quicktime = TRUE;
  373. #endif /* WITH_QUICKTIME */
  374. /* OK we are ready for it */
  375. for(a=1; a<argc; a++) {
  376. if (G.afbreek==1) break;
  377. if(argv[a][0] == '-') {
  378. switch(argv[a][1]) {
  379. case 'p': /* prefsize */
  380. a+= 4;
  381. break;
  382. case 'g':
  383. {
  384. /**
  385. gameengine parameters are automaticly put into system
  386. -g [paramname = value]
  387. -g [boolparamname]
  388. example:
  389. -g novertexarrays
  390. -g maxvertexarraysize = 512
  391. */
  392. if(++a < argc)
  393. {
  394. char* paramname = argv[a];
  395. /* check for single value versus assignment */
  396. if (a+1 < argc && (*(argv[a+1]) == '='))
  397. {
  398. a++;
  399. if (a+1 < argc)
  400. {
  401. a++;
  402. /* assignment */
  403. SYS_WriteCommandLineString(syshandle,paramname,argv[a]);
  404. } else
  405. {
  406. printf("error: argument assignment (%s) without value.\n",paramname);
  407. }
  408. /* name arg eaten */
  409. } else
  410. {
  411. SYS_WriteCommandLineInt(syshandle,argv[a],1);
  412. /* doMipMap */
  413. if (!strcmp(argv[a],"nomipmap"))
  414. {
  415. set_mipmap(0); //doMipMap = 0;
  416. }
  417. /* linearMipMap */
  418. if (!strcmp(argv[a],"linearmipmap"))
  419. {
  420. set_linear_mipmap(1); //linearMipMap = 1;
  421. }
  422. } /* if (*(argv[a+1]) == '=') */
  423. } /* if(++a < argc) */
  424. break;
  425. }
  426. case 'f':
  427. a++;
  428. if (G.scene && a < argc) {
  429. G.real_sfra = (G.scene->r.sfra);
  430. G.real_efra = (G.scene->r.efra);
  431. (G.scene->r.sfra) = atoi(argv[a]);
  432. (G.scene->r.efra) = (G.scene->r.sfra);
  433. RE_animrender(NULL);
  434. }
  435. break;
  436. case 'a':
  437. if (G.scene) {
  438. G.real_sfra = (G.scene->r.sfra);
  439. G.real_efra = (G.scene->r.efra);
  440. RE_animrender(NULL);
  441. }
  442. break;
  443. case 'S':
  444. if(++a < argc) {
  445. set_scene_name(argv[a]);
  446. }
  447. break;
  448. case 's':
  449. a++;
  450. if(G.scene) {
  451. if (a < argc) (G.scene->r.sfra) = atoi(argv[a]);
  452. }
  453. break;
  454. case 'e':
  455. a++;
  456. if(G.scene) {
  457. if (a < argc) (G.scene->r.efra) = atoi(argv[a]);
  458. }
  459. break;
  460. }
  461. }
  462. else {
  463. BKE_read_file(argv[a], NULL);
  464. sound_initialize_sounds();
  465. }
  466. }
  467. if(G.background)
  468. {
  469. exit_usiblender();
  470. }
  471. setscreen(G.curscreen);
  472. if(G.main->scene.first==0) {
  473. sce= add_scene("1");
  474. set_scene(sce);
  475. }
  476. screenmain();
  477. return 0;
  478. } /* end of int main(argc,argv) */
  479. static void error_cb(char *err)
  480. {
  481. error("%s", err);
  482. }
  483. void setCallbacks(void)
  484. {
  485. /* Error output from the alloc routines: */
  486. MEM_set_error_stream(stderr);
  487. /* BLI_blenlib: */
  488. BLI_setErrorCallBack(error_cb); /* */
  489. BLI_setInterruptCallBack(blender_test_break);
  490. /* render module: execution flow, timers, cursors and display. */
  491. RE_set_getrenderdata_callback(RE_rotateBlenderScene);
  492. RE_set_freerenderdata_callback(RE_freeRotateBlenderScene);
  493. }