Oolite 1.91.0.7604-240417-a536cbe
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 // Detect current working directory and set up GNUstep environment variables
74 #define MAX_PATH_LEN 256
75 char currentWorkingDir[MAX_PATH_LEN];
76 char envVarString[2 * MAX_PATH_LEN];
77 DWORD bufferSize = MAX_PATH_LEN;
78
79 QueryFullProcessImageName(GetCurrentProcess(), 0, currentWorkingDir, &bufferSize);
80 // Strip the exe filenameb (from last backslash onwards), leave just the path
81 char *probeString = strrchr(currentWorkingDir, '\\');
82 if (probeString) *probeString = '\0'; // currentWorkingDir now contains the path we need
83
84 // Prepend system PATH env variable with our own executable's path
85 char finalPath[16 * MAX_PATH_LEN];
86 char *systemPath = SDL_getenv("PATH");
87 strcpy(finalPath, currentWorkingDir);
88 strcat(finalPath, ";");
89 strcat(finalPath, systemPath);
90
91 #define SETENVVAR(var, value) do {\
92 sprintf(envVarString, "%s=%s", (var), (value));\
93 SDL_putenv (envVarString);\
94 } while (0);
95
96 SETENVVAR("GNUSTEP_PATH_HANDLING", "windows");
97 SETENVVAR("PATH", finalPath);
98 SETENVVAR("GNUSTEP_SYSTEM_ROOT", currentWorkingDir);
99 SETENVVAR("GNUSTEP_LOCAL_ROOT", currentWorkingDir);
100 SETENVVAR("GNUSTEP_NETWORK_ROOT", currentWorkingDir);
101 SETENVVAR("GNUSTEP_USERS_ROOT", currentWorkingDir);
102 SETENVVAR("HOMEPATH", currentWorkingDir);
103
104 SetCurrentDirectory(currentWorkingDir);
105
106 /* Windows amibtiously starts apps with the C library locale set to the
107 system locale rather than the "C" locale as per spec. Fixing here so
108 numbers don't behave strangely.
109 */
110 setlocale(LC_ALL, "C");
111#endif
112
113 // Need this because we're not using the default run loop's autorelease
114 // pool.
115 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
117
118 @try
119 {
120 // dajt: allocate and set the NSApplication delegate manually because not
121 // using NIB to do this
122 controller = [[GameController alloc] init];
123
124 for (i = 1; i < argc; i++)
125 {
126 if (strcmp("-load", argv[i]) == 0)
127 {
128 i++;
129 if (i < argc)
130 [controller setPlayerFileToLoad: [NSString stringWithCString: argv[i]]];
131 }
132 }
133
134 // Release anything allocated during the controller initialisation that
135 // is no longer required.
136 DESTROY(pool);
137
138 // Call applicationDidFinishLaunching because NSApp is not running in
139 // GNUstep port.
140 [controller applicationDidFinishLaunching: nil];
141 }
142 @catch (NSException *exception)
143 {
144 OOLogERR(kOOLogException, @"Root exception handler hit - terminating. This is an internal error, please report it. Exception name: %@, reason: %@", [exception name], [exception reason]);
145 return EXIT_FAILURE;
146 }
147#endif
148
149 // never reached
150 return 0;
151}
NSUInteger gDebugFlags
Definition main.m:7
#define DESTROY(x)
Definition OOCocoa.h:77
#define OOLogERR(class, format,...)
Definition OOLogging.h:112
NSString *const kOOLogException
Definition OOLogging.m:651
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)