]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/app.cpp
Added switch to disable untuned tank circuit, for slower computers.
[virtualjaguar] / src / gui / app.cpp
1 //
2 // app.cpp - Qt-based GUI for Virtual Jaguar
3 //
4 // by James Hammons
5 // (C) 2010 Underground Software
6 //
7 // JLH = James Hammons <jlhamm@acm.org>
8 //
9 // Who  When        What
10 // ---  ----------  -------------------------------------------------------------
11 // JLH  12/23/2009  Created this file
12 // JLH  01/21/2011  Added SDL initialization
13 // JLH  06/26/2011  Added fix to keep SDL from hijacking main() on win32
14 //
15
16 #include "app.h"
17
18 #include <SDL.h>
19 #include <QApplication>
20 #include "log.h"
21 #include "mainwin.h"
22 #include "settings.h"
23 #include "types.h"
24
25 #ifdef __GCCWIN32__
26 // Apparently on win32, SDL is hijacking main from Qt. So let's do this:
27 #undef main
28 #endif
29
30 //hm. :-/
31 // This is stuff we pass into the mainWindow...
32 bool noUntunedTankPlease = false;
33
34 // Here's the main application loop--short and simple...
35 int main(int argc, char * argv[])
36 {
37         // Normally, this would be read in from the settings module... :-P
38         vjs.hardwareTypeAlpine = false;
39         // This is stuff we pass into the mainWindow...
40 //      noUntunedTankPlease = false;
41
42         if (argc > 1)
43         {
44                 if ((strcmp(argv[1], "--help") == 0) || (strcmp(argv[1], "-h") == 0)
45                         || (strcmp(argv[1], "-?") == 0))
46                 {
47                         printf("Virtual Jaguar 2.0.0 help\n");
48                         printf("\n");
49                         printf("Command line interface is mostly non-functional ATM, but may return if\n"
50                                 "there is enough demand for it. :-)\n");
51                         return 0;
52                 }
53
54                 if (strcmp(argv[1], "--yarrr") == 0)
55                 {
56                         printf("\n");
57                         printf("Shiver me timbers!\n");
58                         printf("\n");
59                         return 0;
60                 }
61
62                 if ((strcmp(argv[1], "--alpine") == 0) || (strcmp(argv[1], "-a") == 0))
63                 {
64                         printf("Alpine Mode enabled.\n");
65                         vjs.hardwareTypeAlpine = true;
66                 }
67
68                 if (strcmp(argv[1], "--please-dont-kill-my-computer") == 0)
69                 {
70                         noUntunedTankPlease = true;
71                 }
72         }
73
74         Q_INIT_RESOURCE(virtualjaguar); // This must the same name as the exe filename
75 //or is it the .qrc filename???
76         // This is so we can pass this stuff using signal/slot mechanism...
77 //ick   int id = qRegisterMetaType<uint32>();
78
79         bool success = (bool)LogInit("virtualjaguar.log");      // Init logfile
80         int retVal = -1;                                                        // Default is failure
81
82         if (!success)
83                 printf("Failed to open virtualjaguar.log for writing!\n");
84
85         // Set up SDL library
86         if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0)
87         {
88                 WriteLog("VJ: Could not initialize the SDL library: %s\n", SDL_GetError());
89         }
90         else
91         {
92                 WriteLog("VJ: SDL (joystick, audio) successfully initialized.\n");
93                 App app(argc, argv);                                    // Declare an instance of the application
94                 retVal = app.exec();                                    // And run it!
95
96                 // Free SDL components last...!
97                 SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_AUDIO);
98                 SDL_Quit();
99         }
100
101         LogDone();                                                                      // Close logfile
102         return retVal;
103 }
104
105 // Main app constructor--we stick globally accessible stuff here...
106
107 App::App(int argc, char * argv[]): QApplication(argc, argv)
108 {
109         mainWindow = new MainWin();
110         mainWindow->plzDontKillMyComputer = noUntunedTankPlease;
111         mainWindow->show();
112 }