[612] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * |
---|
| 4 | * |
---|
| 5 | * License notice: |
---|
| 6 | * |
---|
| 7 | * This program is free software; you can redistribute it and/or |
---|
| 8 | * modify it under the terms of the GNU General Public License |
---|
| 9 | * as published by the Free Software Foundation; either version 2 |
---|
| 10 | * of the License, or (at your option) any later version. |
---|
| 11 | * |
---|
| 12 | * This program is distributed in the hope that it will be useful, |
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | * GNU General Public License for more details. |
---|
| 16 | * |
---|
| 17 | * You should have received a copy of the GNU General Public License |
---|
| 18 | * along with this program; if not, write to the Free Software |
---|
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 20 | * |
---|
| 21 | * Author: |
---|
| 22 | * Benjamin Knecht <beni_at_orxonox.net>, (C) 2007 |
---|
| 23 | * Co-authors: |
---|
| 24 | * ... |
---|
| 25 | * |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | /** |
---|
[614] | 29 | @file Main.cc |
---|
[612] | 30 | @brief main file handling most of the machine specific code |
---|
| 31 | */ |
---|
| 32 | |
---|
| 33 | #include <OgrePlatform.h> |
---|
| 34 | #include <OgreException.h> |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | #include "core/SignalHandler.h" |
---|
[614] | 38 | #include "Orxonox.h" |
---|
[612] | 39 | |
---|
| 40 | using namespace orxonox; |
---|
| 41 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE |
---|
| 42 | #include <CoreFoundation/CoreFoundation.h> |
---|
| 43 | |
---|
| 44 | // This function will locate the path to our application on OS X, |
---|
| 45 | // unlike windows you can not rely on the curent working directory |
---|
| 46 | // for locating your configuration files and resources. |
---|
| 47 | std::string macBundlePath() |
---|
| 48 | { |
---|
| 49 | char path[1024]; |
---|
| 50 | CFBundleRef mainBundle = CFBundleGetMainBundle(); |
---|
| 51 | assert(mainBundle); |
---|
| 52 | |
---|
| 53 | CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle); |
---|
| 54 | assert(mainBundleURL); |
---|
| 55 | |
---|
| 56 | CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle); |
---|
| 57 | assert(cfStringRef); |
---|
| 58 | |
---|
| 59 | CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII); |
---|
| 60 | |
---|
| 61 | CFRelease(mainBundleURL); |
---|
| 62 | CFRelease(cfStringRef); |
---|
| 63 | |
---|
| 64 | return std::string(path); |
---|
| 65 | } |
---|
| 66 | #endif |
---|
| 67 | |
---|
| 68 | #ifdef __cplusplus |
---|
| 69 | extern "C" { |
---|
| 70 | #endif |
---|
| 71 | |
---|
[701] | 72 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 && !defined( __MINGW32__ ) |
---|
[668] | 73 | #ifndef WIN32_LEAN_AND_MEAN |
---|
[612] | 74 | #define WIN32_LEAN_AND_MEAN |
---|
[668] | 75 | #endif |
---|
[612] | 76 | #include "windows.h" |
---|
| 77 | INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT) |
---|
| 78 | { |
---|
| 79 | // something like this would be less hacky |
---|
| 80 | // maybe one can work with trailing '\0' |
---|
| 81 | // or maybe use string based functions |
---|
| 82 | // I was unable to test it without working windows version |
---|
| 83 | char* cmd = strCmdLine; |
---|
| 84 | int argc = 2; |
---|
| 85 | int i; |
---|
| 86 | for(i = 0; cmd[i] != NULL; i++) |
---|
| 87 | { |
---|
| 88 | if(cmd[i] == ' ') argc++; |
---|
| 89 | } |
---|
| 90 | char **argv = new char*[argc]; |
---|
| 91 | for (int j = 0; j < argc; j++) |
---|
| 92 | { |
---|
| 93 | argv[j] = new char[i]; |
---|
| 94 | } |
---|
| 95 | int j = 1; |
---|
| 96 | int k = 0; |
---|
| 97 | for(int i = 0; cmd[i] != NULL; i++) |
---|
| 98 | { |
---|
| 99 | if(cmd[i] != ' ') { |
---|
| 100 | argv[j][k] = cmd[i]; |
---|
| 101 | k++; |
---|
| 102 | } |
---|
| 103 | else { |
---|
| 104 | argv[j][k] = '\0'; |
---|
| 105 | k = 0; |
---|
| 106 | j++; |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | argv[j][k] = '\0'; |
---|
| 110 | argv[0] = "BeniXonox.exe"; |
---|
| 111 | //char *argv[2]; |
---|
| 112 | //argv[0] = "asdfProgram"; |
---|
| 113 | //argv[1] = strCmdLine; |
---|
| 114 | //int argc = 2; |
---|
| 115 | #else |
---|
| 116 | int main(int argc, char **argv) |
---|
| 117 | { |
---|
| 118 | #endif |
---|
| 119 | try { |
---|
[666] | 120 | srand(time(0)); //initaialize RNG; TODO check if it works on win |
---|
[612] | 121 | SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log"); |
---|
| 122 | Orxonox* orx = Orxonox::getSingleton(); |
---|
| 123 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE |
---|
| 124 | orx->init(argc, argv, macBundlePath()); |
---|
| 125 | orx->start(); |
---|
| 126 | #else |
---|
[622] | 127 | /* |
---|
| 128 | for (int i = 0; i < 500; i++) |
---|
| 129 | { |
---|
| 130 | int x = rand() % 40000 - 20000; |
---|
| 131 | int y = rand() % 40000 - 20000; |
---|
| 132 | int z = rand() % 40000 - 20000; |
---|
| 133 | |
---|
| 134 | int scale = rand() % 100 + 20; |
---|
| 135 | |
---|
| 136 | int version = rand() % 6 + 1; |
---|
| 137 | |
---|
| 138 | float rotx = float(rand()) / RAND_MAX; |
---|
| 139 | float roty = float(rand()) / RAND_MAX; |
---|
| 140 | float rotz = float(rand()) / RAND_MAX; |
---|
| 141 | |
---|
| 142 | int axis = rand() % 3 + 1; |
---|
| 143 | |
---|
| 144 | if (axis == 1) |
---|
| 145 | rotx = 0; |
---|
| 146 | if (axis == 2) |
---|
| 147 | roty = 0; |
---|
| 148 | if (axis == 3) |
---|
| 149 | rotz = 0; |
---|
| 150 | |
---|
| 151 | int rotation = rand() % 40 + 10; |
---|
| 152 | |
---|
| 153 | // <Model position="1000,1500,0" scale="50" mesh="ast1.mesh" rotationAxis="0,1.25,0" rotationRate="70" /> |
---|
| 154 | std::cout << " <Model position=\"" << x << "," << y << "," << z << "\" scale=\"" << scale << "\" mesh=\"ast" << version << ".mesh\" rotationAxis=\"" << rotx << "," << roty << "," << rotz << "\" rotationRate=\"" << rotation << "\" />" << std::endl; |
---|
| 155 | |
---|
| 156 | |
---|
| 157 | } |
---|
| 158 | */ |
---|
[612] | 159 | orx->init(argc, argv, ""); |
---|
| 160 | orx->start(); |
---|
| 161 | #endif |
---|
| 162 | } |
---|
| 163 | catch (Ogre::Exception& e) { |
---|
[713] | 164 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 && !defined( __MINGW32__ ) |
---|
[612] | 165 | MessageBoxA(NULL, e.getFullDescription().c_str(), |
---|
| 166 | "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL); |
---|
| 167 | #else |
---|
| 168 | std::cerr << "Exception:\n"; |
---|
| 169 | std::cerr << e.getFullDescription().c_str() << "\n"; |
---|
| 170 | #endif |
---|
| 171 | return 1; |
---|
| 172 | } |
---|
| 173 | return 0; |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | #ifdef __cplusplus |
---|
| 177 | } |
---|
| 178 | #endif |
---|
| 179 | |
---|
| 180 | |
---|
| 181 | /*int main(int argc, char **argv) |
---|
| 182 | { |
---|
| 183 | try |
---|
| 184 | { |
---|
| 185 | SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log"); |
---|
| 186 | Orxonox* orx = Orxonox::getSingleton(); |
---|
| 187 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE |
---|
| 188 | orx->init(argc, argv, macBundlePath()); |
---|
| 189 | orx->start(); |
---|
| 190 | #else |
---|
| 191 | orx->init(argc, argv, ""); |
---|
| 192 | orx->start(); |
---|
| 193 | #endif |
---|
| 194 | |
---|
| 195 | } |
---|
| 196 | catch(Ogre::Exception& e) |
---|
| 197 | { |
---|
| 198 | fprintf(stderr, "An exception has occurred: %s\n", |
---|
| 199 | e.getFullDescription().c_str()); |
---|
| 200 | return 1; |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | return 0; |
---|
| 204 | } |
---|
| 205 | |
---|
[618] | 206 | */ |
---|