2 #include <unistd.h> // Because we can.
4 #include "controlpanel.h"
12 bool ignore_sigfpe = false;
14 void sigfpe_handler(int sig)
17 Fatal("Floating point exception!");
21 int main(int argc, char ** argv)
23 signal(SIGFPE, sigfpe_handler);
24 #if REALTYPE == REAL_IRRAM
25 iRRAM_initialize(argc,argv);
28 #ifndef __STDC_IEC_559__
29 Warn("__STDC_IEC_559__ not defined. IEEE 754 floating point not fully supported.\n");
32 // We want to crash if we ever get a NaN.
33 feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
35 Debug("Compiled with REAL = %d => \"%s\" sizeof(Real) == %d bytes", REALTYPE, g_real_name[REALTYPE], sizeof(Real));
37 Document doc("","fonts/ComicSans.ttf");
40 enum {OUTPUT_TO_BMP, LOOP} mode = LOOP;
45 const char * output_bmp = NULL;
46 const char * input_filename = NULL;
47 const char * input_text = NULL;
48 float b[4] = {0,0,1,1};
50 bool hide_control_panel;
51 bool lazy_rendering = true;
56 View view(doc,scr, {0,0,1,1});
59 view.SetLazyRendering(false);
64 if (argv[i][0] != '-')
66 input_filename = argv[i];
74 Fatal("No output argument following -o switch");
76 hide_control_panel = true;
80 Debug("Reading view bounds");
81 for (int j = 1; j <= 4; ++j)
84 Fatal("No %d bounds component following -b switch", j);
86 b[j-1] = strtof(argv[i+j], &e);
88 Fatal("Bounds component %d not a valid float", j);
96 Fatal("No text input following -t switch");
98 Debug("Insert text: %s", input_text);
105 Fatal("Expected \"gpu\" or \"cpu\" after -r switch");
106 if (strcmp(argv[i], "gpu") == 0)
108 view.SetGPURendering(true);
110 else if (strcmp(argv[i], "cpu") == 0)
112 view.SetGPURendering(false);
116 Fatal("Expected \"gpu\" or \"cpu\" after -r switch, not \"%s\"", argv[i]);
124 Fatal("Expected \"gpu\" or \"cpu\" after -T switch");
125 if (strcmp(argv[i], "gpu") == 0)
127 view.SetGPUTransform(true);
129 else if (strcmp(argv[i], "cpu") == 0)
131 view.SetGPUTransform(false);
135 Fatal("Expected \"gpu\" or \"cpu\" after -T switch, not \"%s\"", argv[i]);
142 view.SetLazyRendering(!view.UsingLazyRendering());
147 Fatal("No frame number following -f switch");
148 max_frames = strtol(argv[i], NULL, 10);
149 hide_control_panel = true;
153 hide_control_panel = true;
159 Rect bounds(b[0],b[1],b[2],b[3]);
160 view.SetBounds(bounds);
161 if (input_filename != NULL)
164 doc.LoadSVG(input_filename, Rect(bounds.x+bounds.w/Real(2),bounds.y+bounds.h/Real(2),bounds.w/Real(800),bounds.h/Real(600)));
166 else if (input_text != NULL)
168 doc.AddText(input_text, bounds.h/Real(2), bounds.x, bounds.y+bounds.h/Real(2));
172 doc.Add(RECT_OUTLINE, Rect(0,0,0,0),0); // hack to stop segfault if document is empty (:S)
176 #ifndef CONTROLPANEL_DISABLED
177 SDL_Thread * cp_thread = NULL;
178 if (!hide_control_panel)
180 ControlPanel::RunArgs args = {argc, argv, view, doc, scr};
181 cp_thread = SDL_CreateThread(ControlPanel::Run, "ControlPanel", &args);
182 if (cp_thread == NULL)
184 Error("Couldn't create ControlPanel thread: %s", SDL_GetError());
187 #endif //CONTROLPANEL_DISABLED
190 MainLoop(doc, scr, view, max_frames);
191 else if (mode == OUTPUT_TO_BMP) //TODO: Remove this shit
193 if (view.UsingGPURendering())
194 OverlayBMP(doc, output_bmp, output_bmp, bounds, c);
196 view.SaveCPUBMP(output_bmp);
199 #ifndef CONTROLPANEL_DISABLED
200 if (cp_thread != NULL)
203 qApp->quit(); // will close the control panel
204 // (seems to not explode if the qApp has already been quit)
205 SDL_WaitThread(cp_thread, &cp_return);
206 Debug("ControlPanel thread returned %d", cp_return);
208 #endif //CONTROLPANEL_DISABLED
210 ignore_sigfpe = true;