Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/Main.cc @ 785

Last change on this file since 785 was 784, checked in by rgrieder, 18 years ago
  • added precompiled headers for visual studio (speeds up orxonox executable by about 80%)
File size: 5.1 KB
Line 
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 /**
29 @file  Main.cc
30 @brief main file handling most of the machine specific code
31  */
32
33#include "StableHeaders.h"
34
35#include <OgrePlatform.h>
36#include <OgreException.h>
37
38
39#include "core/SignalHandler.h"
40#include "Orxonox.h"
41
42using namespace orxonox;
43#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
44#include <CoreFoundation/CoreFoundation.h>
45
46// This function will locate the path to our application on OS X,
47// unlike windows you can not rely on the curent working directory
48// for locating your configuration files and resources.
49             std::string macBundlePath()
50{
51  char path[1024];
52  CFBundleRef mainBundle = CFBundleGetMainBundle();
53  assert(mainBundle);
54
55  CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle);
56  assert(mainBundleURL);
57
58  CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
59  assert(cfStringRef);
60
61  CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII);
62
63  CFRelease(mainBundleURL);
64  CFRelease(cfStringRef);
65
66  return std::string(path);
67}
68#endif
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
74#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 && !defined( __MINGW32__ )
75#ifndef WIN32_LEAN_AND_MEAN
76#define WIN32_LEAN_AND_MEAN
77#endif
78#include "windows.h"
79  INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
80  {
81    // something like this would be less hacky
82    // maybe one can work with trailing '\0'
83    // or maybe use string based functions
84    // I was unable to test it without working windows version
85    char* cmd = strCmdLine;
86    int argc = 2;
87    int i;
88    for(i = 0; cmd[i] != NULL; i++)
89    {
90      if(cmd[i] == ' ') argc++;
91    }
92    char **argv = new char*[argc];
93    for (int j = 0; j < argc; j++)
94    {
95      argv[j] = new char[i];
96    }
97    int j = 1;
98    int k = 0;
99    for(int i = 0; cmd[i] != NULL; i++)
100    {
101      if(cmd[i] != ' ') {
102        argv[j][k] = cmd[i];
103        k++;
104      }
105      else {
106        argv[j][k] = '\0';
107        k = 0;
108        j++;
109      }
110    }
111    argv[j][k] = '\0';
112    argv[0] = "BeniXonox.exe";
113    //char *argv[2];
114    //argv[0] = "asdfProgram";
115    //argv[1] =  strCmdLine;
116    //int argc = 2;
117#else
118  int main(int argc, char **argv)
119  {
120#endif
121    try {
122      srand(time(0));  //initaialize RNG; TODO check if it works on win
123      SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
124      Orxonox* orx = Orxonox::getSingleton();
125#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
126      orx->init(argc, argv, macBundlePath());
127      orx->start();
128#else
129/*
130for (int i = 0; i < 500; i++)
131{
132int x = rand() % 40000 - 20000;
133int y = rand() % 40000 - 20000;
134int z = rand() % 40000 - 20000;
135
136int scale = rand() % 100 + 20;
137
138int version = rand() % 6 + 1;
139
140float rotx = float(rand()) / RAND_MAX;
141float roty = float(rand()) / RAND_MAX;
142float rotz = float(rand()) / RAND_MAX;
143
144int axis = rand() % 3 + 1;
145
146if (axis == 1)
147  rotx = 0;
148if (axis == 2)
149  roty = 0;
150if (axis == 3)
151  rotz = 0;
152
153int rotation = rand() % 40 + 10;
154
155//    <Model position="1000,1500,0" scale="50" mesh="ast1.mesh" rotationAxis="0,1.25,0" rotationRate="70" />
156std::cout << "    <Model position=\"" << x << "," << y << "," << z << "\" scale=\"" << scale << "\" mesh=\"ast" << version << ".mesh\" rotationAxis=\"" << rotx << "," << roty << "," << rotz << "\" rotationRate=\"" << rotation << "\" />" << std::endl;
157
158
159}
160*/
161      orx->init(argc, argv, "");
162      orx->start();
163#endif
164    }
165    catch (Ogre::Exception& e) {
166#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 && !defined( __MINGW32__ )
167      MessageBoxA(NULL, e.getFullDescription().c_str(),
168            "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
169#else
170      std::cerr << "Exception:\n";
171      std::cerr << e.getFullDescription().c_str() << "\n";
172#endif
173      return 1;
174    }
175    return 0;
176  }
177
178#ifdef __cplusplus
179}
180#endif
181
182
183/*int main(int argc, char **argv)
184{
185  try
186  {
187    SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
188    Orxonox* orx = Orxonox::getSingleton();
189#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
190    orx->init(argc, argv, macBundlePath());
191    orx->start();
192#else
193    orx->init(argc, argv, "");
194    orx->start();
195#endif
196
197  }
198  catch(Ogre::Exception& e)
199  {
200    fprintf(stderr, "An exception has occurred: %s\n",
201            e.getFullDescription().c_str());
202    return 1;
203  }
204
205  return 0;
206}
207
208*/
Note: See TracBrowser for help on using the repository browser.