LCOV - code coverage report
Current view: top level - SDL - main.m (source / functions) Hit Total Coverage
Test: coverxygen.info Lines: 1 3 33.3 %
Date: 2025-05-28 07:50:54 Functions: 0 0 -

          Line data    Source code
       1           0 : /*
       2             : 
       3             : main.m
       4             : 
       5             : Oolite
       6             : Copyright (C) 2004-2013 Giles C Williams and contributors
       7             : 
       8             : This program is free software; you can redistribute it and/or
       9             : modify it under the terms of the GNU General Public License
      10             : as published by the Free Software Foundation; either version 2
      11             : of the License, or (at your option) any later version.
      12             : 
      13             : This program is distributed in the hope that it will be useful,
      14             : but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             : GNU General Public License for more details.
      17             : 
      18             : You should have received a copy of the GNU General Public License
      19             : along with this program; if not, write to the Free Software
      20             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
      21             : MA 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             : 
      44             : GameController* controller;
      45             : #endif
      46             : 
      47             : 
      48             : #ifndef NDEBUG
      49           0 : uint32_t gDebugFlags = 0;
      50             : #endif
      51             : 
      52             : /**
      53             :  * \ingroup cli
      54             :  * Entry point for Linux and Windows systems.
      55             :  * Initializes logging. If -load is passed, the argument after that is loaded
      56             :  * as savegame.
      57             :  *
      58             :  * @param argc the number of command line arguments
      59             :  * @param argv the string array values of the command line arguments
      60             :  * @return returns 0 on success, or EXITFAILURE when an exception is caught
      61             :  */
      62           1 : int 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];
     129             :         OOLoggingInit();
     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"
     154             : #if OOLITE_WINDOWS
     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             :                                                         "-nodust    "TABS2 TABS4"Do not draw space dust\n"
     160             :                                                         "-noshaders"TABS2 TABS4"Start up with shaders disabled\n"
     161             :                                                         "-nosplash    "TABS2 TABS4"Force disable splash screen on startup\n"
     162             :                                                         "-nosound    "TABS2 TABS4"Start up with sound disabled\n"
     163             :                                                         "-novsync"TABS3"Force disable V-Sync\n"
     164             :                                                         "--openstep"TABS2 TABS4"When compiling or exporting\n"TABS3 TABS4"system descriptions, use openstep\n"TABS3 TABS4"format *\n"
     165             :                                                         "-showversion"TABS2 TABS4"Display version at startup screen\n"
     166             :                                                         "-splash"TABS3 TABS4"Force splash screen on startup\n"
     167             :                                                         "-verify-oxp [filepath]    "TABS1"Verify OXP at [filepath] *\n"
     168             :                                                         "--xml"TABS3 TABS4"When compiling or exporting\n"TABS3 TABS4"system descriptions, use xml\n"TABS3 TABS4"format *\n"
     169             :                                                         "\n"
     170             :                                                         "Options marked with \"*\" are available only in Test Release configuration.\n\n", processName);
     171             :                                 OO_SHOW_MSG(s, processName, MB_OK);
     172             :                                 OOLog(@"process.args", @"%s option detected, exiting after help page has been displayed.", argv[i]);
     173             :                                 return 0;
     174             :                         }
     175             :                 }
     176             :                 
     177             :                 // Release anything allocated during the controller initialisation that
     178             :                 // is no longer required.
     179             :                 DESTROY(pool);
     180             :                 
     181             :                 // Call applicationDidFinishLaunching because NSApp is not running in
     182             :                 // GNUstep port.
     183             :                 [controller applicationDidFinishLaunching: nil];
     184             :         }
     185             :         @catch (NSException *exception)
     186             :         {
     187             :                 OOLogERR(kOOLogException, @"Root exception handler hit - terminating. This is an internal error, please report it. Exception name: %@, reason: %@", [exception name], [exception reason]);
     188             :                 return EXIT_FAILURE;
     189             :         }
     190             : #endif
     191             : 
     192             :         // never reached
     193             :         return 0;
     194             : }

Generated by: LCOV version 1.14