Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
main.m
Go to the documentation of this file.
1/*
2
3main.m
4
5Oolite
6Copyright (C) 2004-2013 Giles C Williams and contributors
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21MA 02110-1301, USA.
22
23*/
24
25
26#ifdef GNUSTEP
27#import <Foundation/NSAutoreleasePool.h>
28#if (GNUSTEP_BASE_MAJOR_VERSION == 1 && (GNUSTEP_BASE_MINOR_VERSION == 24 && GNUSTEP_BASE_SUBMINOR_VERSION >= 9) || (GNUSTEP_BASE_MINOR_VERSION > 24)) || (GNUSTEP_BASE_MAJOR_VERSION > 1)
29#import <Foundation/NSDate.h>
30#endif
31#import <Foundation/NSString.h>
32#import "GameController.h"
33#import "OOLoggingExtended.h"
34
35#if OOLITE_WINDOWS
36#include <locale.h>
37#include <SDL.h>
38// Make sure that a high performance GPU is
39// selected, if more than one are available
40__declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
41__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
42#endif
43
44GameController* controller;
45#endif
46
47
48#ifndef NDEBUG
49uint32_t gDebugFlags = 0;
50#endif
51
62int main(int argc, char *argv[])
63{
64#ifdef GNUSTEP
65 int i;
66
67#if (GNUSTEP_BASE_MAJOR_VERSION == 1 && (GNUSTEP_BASE_MINOR_VERSION == 24 && GNUSTEP_BASE_SUBMINOR_VERSION >= 9) || (GNUSTEP_BASE_MINOR_VERSION > 24)) || (GNUSTEP_BASE_MAJOR_VERSION > 1)
68 [NSDate class]; // See github issue #202
69#endif
70
71#if OOLITE_WINDOWS
72
73 #define OO_SHOW_MSG(ooMsg, ooMsgTitle, ooMsgFlags) MessageBox(NULL, ooMsg, ooMsgTitle, ooMsgFlags)
74 #define TABS1 "\t"
75 #define TABS2 "\t\t"
76 #define TABS3 "\t\t\t"
77 #define TABS4 ""
78
79 // Detect current working directory and set up GNUstep environment variables
80 #define MAX_PATH_LEN 256
81 char currentWorkingDir[MAX_PATH_LEN];
82 char envVarString[2 * MAX_PATH_LEN];
83 DWORD bufferSize = MAX_PATH_LEN;
84
85 QueryFullProcessImageName(GetCurrentProcess(), 0, currentWorkingDir, &bufferSize);
86 // Strip the exe filenameb (from last backslash onwards), leave just the path
87 char *probeString = strrchr(currentWorkingDir, '\\');
88 if (probeString) *probeString = '\0'; // currentWorkingDir now contains the path we need
89
90 // Prepend system PATH env variable with our own executable's path
91 char finalPath[16 * MAX_PATH_LEN];
92 char *systemPath = SDL_getenv("PATH");
93 strcpy(finalPath, currentWorkingDir);
94 strcat(finalPath, ";");
95 strcat(finalPath, systemPath);
96
97 #define SETENVVAR(var, value) do {\
98 sprintf(envVarString, "%s=%s", (var), (value));\
99 SDL_putenv (envVarString);\
100 } while (0);
101
102 SETENVVAR("GNUSTEP_PATH_HANDLING", "windows");
103 SETENVVAR("PATH", finalPath);
104 SETENVVAR("GNUSTEP_SYSTEM_ROOT", currentWorkingDir);
105 SETENVVAR("GNUSTEP_LOCAL_ROOT", currentWorkingDir);
106 SETENVVAR("GNUSTEP_NETWORK_ROOT", currentWorkingDir);
107 SETENVVAR("GNUSTEP_USERS_ROOT", currentWorkingDir);
108 SETENVVAR("HOMEPATH", currentWorkingDir);
109
110 SetCurrentDirectory(currentWorkingDir);
111
112 /* Windows amibtiously starts apps with the C library locale set to the
113 system locale rather than the "C" locale as per spec. Fixing here so
114 numbers don't behave strangely.
115 */
116 setlocale(LC_ALL, "C");
117
118#else // Linux
119 #define OO_SHOW_MSG(ooMsg, ooTitle, ooFlags) fprintf(stdout, ooMsg)
120 #define TABS1 "\t\t"
121 #define TABS2 "\t\t\t"
122 #define TABS3 "\t\t\t\t"
123 #define TABS4 "\t"
124#endif
125
126 // Need this because we're not using the default run loop's autorelease
127 // pool.
128 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
130
131 @try
132 {
133 // dajt: allocate and set the NSApplication delegate manually because not
134 // using NIB to do this
135 controller = [[GameController alloc] init];
136
137 for (i = 1; i < argc; i++)
138 {
139 if (strcmp("-load", argv[i]) == 0)
140 {
141 i++;
142 if (i < argc)
143 [controller setPlayerFileToLoad: [NSString stringWithCString: argv[i]]];
144 }
145
146 if (!strcmp("-help", argv[i]) || !strcmp("--help", argv[i]))
147 {
148 char const *processName = [[[NSProcessInfo processInfo] processName] UTF8String];
149 char s[2048];
150 snprintf(s, sizeof(s), "Usage: %s [options]\n\n"
151 "Options can be any of the following: \n\n"
152 "--compile-sysdesc"TABS2"Compile system descriptions *\n"
153 "--export-sysdesc"TABS2"Export system descriptions *\n"
155 "-hdr"TABS3"Start up in HDR mode\n"
156#endif
157 "-load [filepath]"TABS2"Load commander from [filepath]\n"
158 "-message [messageString]"TABS1"Display [messageString] at startup\n"
159 "-noshaders"TABS2 TABS4"Start up with shaders disabled\n"
160 "-nosplash "TABS2 TABS4"Force disable splash screen on startup\n"
161 "-nosound "TABS2 TABS4"Start up with sound disabled\n"
162 "-novsync"TABS3"Force disable V-Sync\n"
163 "--openstep"TABS2 TABS4"When compiling or exporting\n"TABS3 TABS4"system descriptions, use openstep\n"TABS3 TABS4"format *\n"
164 "-showversion"TABS2 TABS4"Display version at startup screen\n"
165 "-splash"TABS3 TABS4"Force splash screen on startup\n"
166 "-verify-oxp [filepath] "TABS1"Verify OXP at [filepath] *\n"
167 "--xml"TABS3 TABS4"When compiling or exporting\n"TABS3 TABS4"system descriptions, use xml\n"TABS3 TABS4"format *\n"
168 "\n"
169 "Options marked with \"*\" are available only in Test Release configuration.\n\n", processName);
170 OO_SHOW_MSG(s, processName, MB_OK);
171 OOLog(@"process.args", @"%s option detected, exiting after help page has been displayed.", argv[i]);
172 return 0;
173 }
174 }
175
176 // Release anything allocated during the controller initialisation that
177 // is no longer required.
178 DESTROY(pool);
179
180 // Call applicationDidFinishLaunching because NSApp is not running in
181 // GNUstep port.
182 [controller applicationDidFinishLaunching: nil];
183 }
184 @catch (NSException *exception)
185 {
186 OOLogERR(kOOLogException, @"Root exception handler hit - terminating. This is an internal error, please report it. Exception name: %@, reason: %@", [exception name], [exception reason]);
187 return EXIT_FAILURE;
188 }
189#endif
190
191 // never reached
192 return 0;
193}
NSUInteger gDebugFlags
Definition main.m:7
#define OOLITE_WINDOWS
Definition OOCocoa.h:247
#define DESTROY(x)
Definition OOCocoa.h:77
#define OOLogERR(class, format,...)
Definition OOLogging.h:112
NSString *const kOOLogException
Definition OOLogging.m:651
#define OOLog(class, format,...)
Definition OOLogging.h:88
void OOLoggingInit(void)
Definition OOLogging.m:585
int main(int argc, const char *argv[])
Definition main.m:18
void applicationDidFinishLaunching:(NSNotification *notification)
void setPlayerFileToLoad:(NSString *filename)