src/main.cpp

changeset 493
16766ac1bbd9
parent 469
f2faed654633
child 497
c51941e590b6
equal deleted inserted replaced
492:e964085e6913 493:16766ac1bbd9
30 #include "primitives.h" 30 #include "primitives.h"
31 #include "gldraw.h" 31 #include "gldraw.h"
32 #include "configDialog.h" 32 #include "configDialog.h"
33 33
34 List<LDFile*> g_loadedFiles; 34 List<LDFile*> g_loadedFiles;
35 ForgeWindow* g_win = null; 35 ForgeWindow* g_win = null;
36 const QApplication* g_app = null; 36 const QApplication* g_app = null;
37 File g_file_stdout (stdout, File::Write); 37 File g_file_stdout (stdout, File::Write);
38 File g_file_stderr (stderr, File::Write); 38 File g_file_stderr (stderr, File::Write);
39 static str g_versionString, g_fullVersionString; 39 static str g_versionString, g_fullVersionString;
40 40
41 const vertex g_origin (0.0f, 0.0f, 0.0f); 41 const vertex g_origin (0.0f, 0.0f, 0.0f);
42 const matrix g_identity ({1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}); 42 const matrix g_identity ( {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f});
43 43
44 cfg (Bool, firststart, true); 44 cfg (Bool, firststart, true);
45 45
46 // ============================================================================= 46 // =============================================================================
47 // ----------------------------------------------------------------------------- 47 // -----------------------------------------------------------------------------
48 int main (int argc, char* argv[]) { 48 int main (int argc, char* argv[])
49 QApplication app (argc, argv); 49 { QApplication app (argc, argv);
50 app.setOrganizationName (APPNAME); 50 app.setOrganizationName (APPNAME);
51 app.setApplicationName (APPNAME); 51 app.setApplicationName (APPNAME);
52 52
53 g_app = &app; 53 g_app = &app;
54 LDFile::setCurrent (null); 54 LDFile::setCurrent (null);
55 55
56 // Load or create the configuration 56 // Load or create the configuration
57 if (!Config::load()) { 57 if (!Config::load())
58 print ("Creating configuration file...\n"); 58 { print ("Creating configuration file...\n");
59
59 if (Config::save()) 60 if (Config::save())
60 print ("Configuration file successfully created.\n"); 61 print ("Configuration file successfully created.\n");
61 else 62 else
62 print ("failed to create configuration file!\n"); 63 print ("failed to create configuration file!\n");
63 } 64 }
64 65
65 LDPaths::initPaths(); 66 LDPaths::initPaths();
66 initColors(); 67 initColors();
67 loadLogoedStuds(); 68 loadLogoedStuds();
68 69
69 ForgeWindow* win = new ForgeWindow; 70 ForgeWindow* win = new ForgeWindow;
70 newFile(); 71 newFile();
71 win->show(); 72 win->show();
72 73
73 // If this is the first start, get the user to configuration. Especially point 74 // If this is the first start, get the user to configuration. Especially point
74 // them to the profile tab, it's the most important form to fill in. 75 // them to the profile tab, it's the most important form to fill in.
75 if (firststart) { 76 if (firststart)
76 (new ConfigDialog (ConfigDialog::ProfileTab))->exec(); 77 { (new ConfigDialog (ConfigDialog::ProfileTab))->exec();
77 firststart = false; 78 firststart = false;
78 Config::save(); 79 Config::save();
79 } 80 }
80 81
81 loadPrimitives(); 82 loadPrimitives();
82 return app.exec(); 83 return app.exec();
83 } 84 }
84 85
85 // ============================================================================= 86 // =============================================================================
86 // ----------------------------------------------------------------------------- 87 // -----------------------------------------------------------------------------
87 void doPrint (File& f, initlist<StringFormatArg> args) { 88 void doPrint (File& f, initlist<StringFormatArg> args)
88 str msg = DoFormat (args); 89 { str msg = DoFormat (args);
89 f.write (msg.toUtf8()); 90 f.write (msg.toUtf8());
90 f.flush(); 91 f.flush();
91 } 92 }
92 93
93 // ============================================================================= 94 // =============================================================================
94 // ----------------------------------------------------------------------------- 95 // -----------------------------------------------------------------------------
95 void doPrint (FILE* fp, initlist<StringFormatArg> args) { 96 void doPrint (FILE* fp, initlist<StringFormatArg> args)
96 if (fp == stdout) 97 { if (fp == stdout)
97 doPrint (g_file_stdout, args); 98 doPrint (g_file_stdout, args);
99
98 elif (fp == stderr) 100 elif (fp == stderr)
99 doPrint (g_file_stderr, args); 101 doPrint (g_file_stderr, args);
100 else 102 else
101 fatal ("unknown FILE* argument"); 103 fatal ("unknown FILE* argument");
102 } 104 }
103 105
104 // ============================================================================= 106 // =============================================================================
105 // ----------------------------------------------------------------------------- 107 // -----------------------------------------------------------------------------
106 str versionString() { 108 str versionString()
107 if (g_versionString.length() == 0) { 109 { if (g_versionString.length() == 0)
110 {
108 #if VERSION_PATCH == 0 111 #if VERSION_PATCH == 0
109 g_versionString = fmt ("%1.%2", VERSION_MAJOR, VERSION_MINOR); 112 g_versionString = fmt ("%1.%2", VERSION_MAJOR, VERSION_MINOR);
110 #else 113 #else
111 g_versionString = fmt ("%1.%2.%3", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); 114 g_versionString = fmt ("%1.%2.%3", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
112 #endif // VERSION_PATCH 115 #endif // VERSION_PATCH
113 } 116 }
114 117
115 return g_versionString; 118 return g_versionString;
116 } 119 }
117 120
118 // ============================================================================= 121 // =============================================================================
119 // ----------------------------------------------------------------------------- 122 // -----------------------------------------------------------------------------
120 str versionMoniker() { 123 str versionMoniker()
124 {
121 #if BUILD_ID == BUILD_INTERNAL 125 #if BUILD_ID == BUILD_INTERNAL
122 return "Internal"; 126 return "Internal";
123 #elif BUILD_ID == BUILD_ALPHA 127 #elif BUILD_ID == BUILD_ALPHA
124 return "Alpha"; 128 return "Alpha";
125 #elif BUILD_ID == BUILD_BETA 129 #elif BUILD_ID == BUILD_BETA
131 #endif // BUILD_ID 135 #endif // BUILD_ID
132 } 136 }
133 137
134 // ============================================================================= 138 // =============================================================================
135 // ----------------------------------------------------------------------------- 139 // -----------------------------------------------------------------------------
136 str fullVersionString() { 140 str fullVersionString()
137 return fmt ("v%1 %2", versionString(), versionMoniker()); 141 { return fmt ("v%1 %2", versionString(), versionMoniker());
138 } 142 }
139 143
140 // ============================================================================= 144 // =============================================================================
141 // ----------------------------------------------------------------------------- 145 // -----------------------------------------------------------------------------
142 static void bombBox (str msg) { 146 static void bombBox (str msg)
143 msg.replace ("\n", "<br />"); 147 { msg.replace ("\n", "<br />");
144 148
145 QMessageBox box (null); 149 QMessageBox box (null);
146 const QMessageBox::StandardButton btn = QMessageBox::Close; 150 const QMessageBox::StandardButton btn = QMessageBox::Close;
147 box.setWindowTitle ("Fatal Error"); 151 box.setWindowTitle ("Fatal Error");
148 box.setIconPixmap (getIcon ("bomb")); 152 box.setIconPixmap (getIcon ("bomb"));
149 box.setWindowIcon (getIcon ("ldforge")); 153 box.setWindowIcon (getIcon ("ldforge"));
154 box.exec(); 158 box.exec();
155 } 159 }
156 160
157 // ============================================================================= 161 // =============================================================================
158 // ----------------------------------------------------------------------------- 162 // -----------------------------------------------------------------------------
159 void assertionFailure (const char* file, const ulong line, const char* funcname, const char* expr) { 163 void assertionFailure (const char* file, const ulong line, const char* funcname, const char* expr)
160 str errmsg = fmt ("File: %1\nLine: %2:\nFunction %3:\n\nAssertion `%4' failed", 164 { str errmsg = fmt ("File: %1\nLine: %2:\nFunction %3:\n\nAssertion `%4' failed",
161 file, line, funcname, expr); 165 file, line, funcname, expr);
162 166
163 #if BUILD_ID == BUILD_INTERNAL 167 #if BUILD_ID == BUILD_INTERNAL
164 errmsg += ", aborting."; 168 errmsg += ", aborting.";
165 #else 169 #else
166 errmsg += "."; 170 errmsg += ".";
167 #endif 171 #endif
168 172
169 printf ("%s\n", errmsg.toStdString().c_str()); 173 printf ("%s\n", errmsg.toStdString().c_str());
170 174
171 #if BUILD_ID == BUILD_INTERNAL 175 #if BUILD_ID == BUILD_INTERNAL
176
172 if (g_win) 177 if (g_win)
173 g_win->deleteLater(); 178 g_win->deleteLater();
174 179
175 bombBox (errmsg); 180 bombBox (errmsg);
176 abort(); 181 abort();
177 #endif 182 #endif
178 } 183 }
179 184
180 // ============================================================================= 185 // =============================================================================
181 // ----------------------------------------------------------------------------- 186 // -----------------------------------------------------------------------------
182 void fatalError (const char* file, const ulong line, const char* funcname, str msg) { 187 void fatalError (const char* file, const ulong line, const char* funcname, str msg)
183 str errmsg = fmt ("Aborting over a call to fatal():\nFile: %1\nLine: %2\nFunction: %3\n\n%4", 188 { str errmsg = fmt ("Aborting over a call to fatal():\nFile: %1\nLine: %2\nFunction: %3\n\n%4",
184 file, line, funcname, msg); 189 file, line, funcname, msg);
185 190
186 print ("%1\n", errmsg); 191 print ("%1\n", errmsg);
187 192
188 if (g_win) 193 if (g_win)
189 g_win->deleteLater(); 194 g_win->deleteLater();
190 195
191 bombBox (errmsg); 196 bombBox (errmsg);
192 abort(); 197 abort();
193 } 198 }

mercurial