Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 664 was 622, checked in by landauf, 17 years ago

added some randomly generated (rotating) asteroids

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