39 const vertex g_origin (0.0f, 0.0f, 0.0f); |
39 const vertex g_origin (0.0f, 0.0f, 0.0f); |
40 const matrix g_identity ({1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}); |
40 const matrix g_identity ({1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}); |
41 |
41 |
42 void doPrint (File& f, initlist<StringFormatArg> args) { |
42 void doPrint (File& f, initlist<StringFormatArg> args) { |
43 str msg = DoFormat (args); |
43 str msg = DoFormat (args); |
44 f.write (msg.toUtf8 ()); |
44 f.write (msg.toUtf8()); |
45 f.flush (); |
45 f.flush(); |
46 } |
46 } |
47 |
47 |
48 void doPrint (FILE* fp, initlist<StringFormatArg> args) { |
48 void doPrint (FILE* fp, initlist<StringFormatArg> args) { |
49 if (fp == stdout) |
49 if (fp == stdout) |
50 doPrint (g_file_stdout, args); |
50 doPrint (g_file_stdout, args); |
61 const QApplication app (argc, argv); |
61 const QApplication app (argc, argv); |
62 g_app = &app; |
62 g_app = &app; |
63 LDFile::setCurrent (null); |
63 LDFile::setCurrent (null); |
64 |
64 |
65 // Load or create the configuration |
65 // Load or create the configuration |
66 if (!config::load ()) { |
66 if (!config::load()) { |
67 print ("Creating configuration file...\n"); |
67 print ("Creating configuration file...\n"); |
68 if (config::save ()) |
68 if (config::save()) |
69 print ("Configuration file successfully created.\n"); |
69 print ("Configuration file successfully created.\n"); |
70 else |
70 else |
71 print ("failed to create configuration file!\n"); |
71 print ("failed to create configuration file!\n"); |
72 } |
72 } |
73 |
73 |
74 LDPaths::initPaths (); |
74 LDPaths::initPaths(); |
75 initColors (); |
75 initColors(); |
76 |
76 |
77 ForgeWindow* win = new ForgeWindow; |
77 ForgeWindow* win = new ForgeWindow; |
78 |
78 |
79 newFile (); |
79 newFile(); |
80 loadPrimitives (); |
80 loadPrimitives(); |
81 |
81 |
82 win->show (); |
82 win->show(); |
83 return app.exec (); |
83 return app.exec(); |
84 } |
84 } |
85 |
85 |
86 void doDevf (const char* func, const char* fmtstr, ...) { |
86 void doDevf (const char* func, const char* fmtstr, ...) { |
87 va_list va; |
87 va_list va; |
88 |
88 |
91 va_start (va, fmtstr); |
91 va_start (va, fmtstr); |
92 vprintf (fmtstr, va); |
92 vprintf (fmtstr, va); |
93 va_end (va); |
93 va_end (va); |
94 } |
94 } |
95 |
95 |
96 const char* versionString () { |
96 const char* versionString() { |
97 if (g_versionString.length() == 0) { |
97 if (g_versionString.length() == 0) { |
98 #if VERSION_PATCH == 0 |
98 #if VERSION_PATCH == 0 |
99 g_versionString = fmt ("%1.%2", VERSION_MAJOR, VERSION_MINOR); |
99 g_versionString = fmt ("%1.%2", VERSION_MAJOR, VERSION_MINOR); |
100 #else |
100 #else |
101 g_versionString = fmt ("%1.%2.%3", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); |
101 g_versionString = fmt ("%1.%2.%3", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); |
103 } |
103 } |
104 |
104 |
105 return g_versionString.toStdString().c_str(); |
105 return g_versionString.toStdString().c_str(); |
106 } |
106 } |
107 |
107 |
108 const char* versionMoniker () { |
108 const char* versionMoniker() { |
109 #if BUILD_ID == BUILD_INTERNAL |
109 #if BUILD_ID == BUILD_INTERNAL |
110 return " Internal"; |
110 return " Internal"; |
111 #elif BUILD_ID == BUILD_ALPHA |
111 #elif BUILD_ID == BUILD_ALPHA |
112 return " Alpha"; |
112 return " Alpha"; |
113 #elif BUILD_ID == BUILD_BETA |
113 #elif BUILD_ID == BUILD_BETA |
117 #else |
117 #else |
118 return ""; |
118 return ""; |
119 #endif // BUILD_ID |
119 #endif // BUILD_ID |
120 } |
120 } |
121 |
121 |
122 const char* fullVersionString () { |
122 const char* fullVersionString() { |
123 if (g_fullVersionString.length() == 0) |
123 if (g_fullVersionString.length() == 0) |
124 g_fullVersionString = fmt ("v%1%2", versionString (), versionMoniker ()); |
124 g_fullVersionString = fmt ("v%1%2", versionString(), versionMoniker()); |
125 |
125 |
126 return g_fullVersionString.toStdString().c_str(); |
126 return g_fullVersionString.toStdString().c_str(); |
127 } |
127 } |
128 |
128 |
129 static void bombBox (str msg) { |
129 static void bombBox (str msg) { |
136 box.setWindowIcon (getIcon ("ldforge")); |
136 box.setWindowIcon (getIcon ("ldforge")); |
137 box.setText (msg); |
137 box.setText (msg); |
138 box.addButton (btn); |
138 box.addButton (btn); |
139 box.button (btn)->setText ("Damn it"); |
139 box.button (btn)->setText ("Damn it"); |
140 box.setDefaultButton (btn); |
140 box.setDefaultButton (btn); |
141 box.exec (); |
141 box.exec(); |
142 } |
142 } |
143 |
143 |
144 void assertionFailure (const char* file, const ulong line, const char* funcname, const char* expr) { |
144 void assertionFailure (const char* file, const ulong line, const char* funcname, const char* expr) { |
145 str errmsg = fmt ("File: %1\nLine: %2:\nFunction %3:\n\nAssertion `%4' failed", |
145 str errmsg = fmt ("File: %1\nLine: %2:\nFunction %3:\n\nAssertion `%4' failed", |
146 file, line, funcname, expr); |
146 file, line, funcname, expr); |
153 |
153 |
154 printf ("%s\n", errmsg.toStdString().c_str()); |
154 printf ("%s\n", errmsg.toStdString().c_str()); |
155 |
155 |
156 #if BUILD_ID == BUILD_INTERNAL |
156 #if BUILD_ID == BUILD_INTERNAL |
157 if (g_win) |
157 if (g_win) |
158 g_win->deleteLater (); |
158 g_win->deleteLater(); |
159 |
159 |
160 bombBox (errmsg); |
160 bombBox (errmsg); |
161 abort (); |
161 abort(); |
162 #endif |
162 #endif |
163 } |
163 } |
164 |
164 |
165 void fatalError (const char* file, const ulong line, const char* funcname, str msg) { |
165 void fatalError (const char* file, const ulong line, const char* funcname, str msg) { |
166 str errmsg = fmt ("Aborting over a call to fatal():\nFile: %1\nLine: %2\nFunction: %3\n\n%4", |
166 str errmsg = fmt ("Aborting over a call to fatal():\nFile: %1\nLine: %2\nFunction: %3\n\n%4", |
167 file, line, funcname, msg); |
167 file, line, funcname, msg); |
168 |
168 |
169 print ("%1\n", errmsg); |
169 print ("%1\n", errmsg); |
170 |
170 |
171 if (g_win) |
171 if (g_win) |
172 g_win->deleteLater (); |
172 g_win->deleteLater(); |
173 |
173 |
174 bombBox (errmsg); |
174 bombBox (errmsg); |
175 abort (); |
175 abort(); |
176 } |
176 } |