[612] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
[1293] | 3 | * > www.orxonox.net < |
---|
[612] | 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 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, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Benjamin Knecht <beni_at_orxonox.net>, (C) 2007 |
---|
[1638] | 24 | * Reto Grieder |
---|
[612] | 25 | * Co-authors: |
---|
| 26 | * ... |
---|
| 27 | * |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | /** |
---|
[1021] | 31 | @file |
---|
| 32 | @brief Entry point of the program. Platform specific code. |
---|
[612] | 33 | */ |
---|
| 34 | |
---|
[1293] | 35 | #include "OrxonoxStableHeaders.h" |
---|
[612] | 36 | |
---|
[1293] | 37 | #include <exception> |
---|
[1638] | 38 | #include <cassert> |
---|
[1293] | 39 | |
---|
[1502] | 40 | #include "util/OrxonoxPlatform.h" |
---|
[1638] | 41 | #include "util/ArgReader.h" |
---|
[612] | 42 | #include "core/SignalHandler.h" |
---|
[1638] | 43 | #include "core/Debug.h" |
---|
| 44 | #include "network/ClientConnection.h" |
---|
| 45 | #include "Settings.h" |
---|
[614] | 46 | #include "Orxonox.h" |
---|
[612] | 47 | |
---|
| 48 | using namespace orxonox; |
---|
[1638] | 49 | |
---|
[1021] | 50 | #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE |
---|
[612] | 51 | #include <CoreFoundation/CoreFoundation.h> |
---|
| 52 | |
---|
| 53 | // This function will locate the path to our application on OS X, |
---|
| 54 | // unlike windows you can not rely on the curent working directory |
---|
| 55 | // for locating your configuration files and resources. |
---|
| 56 | std::string macBundlePath() |
---|
| 57 | { |
---|
[1638] | 58 | char path[1024]; |
---|
| 59 | CFBundleRef mainBundle = CFBundleGetMainBundle(); |
---|
| 60 | assert(mainBundle); |
---|
[612] | 61 | |
---|
[1638] | 62 | CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle); |
---|
| 63 | assert(mainBundleURL); |
---|
[612] | 64 | |
---|
[1638] | 65 | CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle); |
---|
| 66 | assert(cfStringRef); |
---|
[612] | 67 | |
---|
[1638] | 68 | CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII); |
---|
[612] | 69 | |
---|
[1638] | 70 | CFRelease(mainBundleURL); |
---|
| 71 | CFRelease(cfStringRef); |
---|
[612] | 72 | |
---|
[1638] | 73 | return std::string(path); |
---|
[612] | 74 | } |
---|
| 75 | #endif |
---|
| 76 | |
---|
[1638] | 77 | bool parseCommandLine(int argc, char** argv) |
---|
| 78 | { |
---|
| 79 | ArgReader args; |
---|
| 80 | std::string errorStr = args.parse(argc, argv); |
---|
| 81 | if (errorStr != "") |
---|
| 82 | { |
---|
| 83 | COUT(1) << "Command Line: Parsing failed.\n" << errorStr << std::endl; |
---|
| 84 | return false; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | // Argument reader parses the command line to check syntax. |
---|
| 88 | // Settings Singleton then stores the arguments. It always |
---|
| 89 | // expects a default value. |
---|
| 90 | bool success = true; |
---|
| 91 | success &= Settings::addCommandLineArgument<std::string> |
---|
| 92 | ("mode", args.getArgument("mode"), "standalone"); |
---|
| 93 | success &= Settings::addCommandLineArgument<std::string> |
---|
| 94 | ("dataPath", args.getArgument("dataPath"), "./"); |
---|
| 95 | success &= Settings::addCommandLineArgument<std::string> |
---|
| 96 | ("ip", args.getArgument("ip"), "127.0.0.0"); |
---|
| 97 | success &= Settings::addCommandLineArgument<int> |
---|
| 98 | ("port", args.getArgument("port"), NETWORK_PORT); |
---|
| 99 | |
---|
| 100 | if (!success) |
---|
| 101 | return false; |
---|
| 102 | |
---|
| 103 | if (!args.allChecked()) |
---|
| 104 | { |
---|
| 105 | COUT(1) << "Command Line: Parsing failed.\nNot all arguments were matched." << std::endl; |
---|
| 106 | return false; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | return true; |
---|
| 110 | } |
---|
| 111 | |
---|
[612] | 112 | #ifdef __cplusplus |
---|
| 113 | extern "C" { |
---|
| 114 | #endif |
---|
| 115 | |
---|
[1638] | 116 | int main(int argc, char** argv) |
---|
[622] | 117 | { |
---|
[1638] | 118 | // create a signal handler (only works for linux) |
---|
[612] | 119 | SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log"); |
---|
[1021] | 120 | |
---|
[1638] | 121 | if (!parseCommandLine(argc, argv)) |
---|
| 122 | { |
---|
| 123 | COUT(0) << "Usage:" << std::endl << "orxonox [--mode client|server|dedicated|standalone] " |
---|
| 124 | << "[--data PATH] [--ip IP] [--port PORT]" << std::endl; |
---|
| 125 | return 0; |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | Orxonox orxonoxInstance; |
---|
| 129 | |
---|
| 130 | try |
---|
| 131 | { |
---|
[1021] | 132 | #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE |
---|
[1638] | 133 | orxonoxInstance.start(macBundlePath()); |
---|
[612] | 134 | #else |
---|
[1638] | 135 | orxonoxInstance.start(); |
---|
[612] | 136 | #endif |
---|
[1638] | 137 | } |
---|
| 138 | catch (std::exception& ex) |
---|
| 139 | { |
---|
| 140 | COUT(1) << ex.what() << std::endl; |
---|
| 141 | COUT(1) << "Abort." << std::endl; |
---|
| 142 | } |
---|
[612] | 143 | |
---|
[1638] | 144 | return 0; |
---|
[612] | 145 | } |
---|
| 146 | |
---|
[1021] | 147 | #ifdef __cplusplus |
---|
| 148 | } |
---|
| 149 | #endif |
---|