Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 666 was 666, checked in by nicolasc, 16 years ago
  • added initialisation of random generator
  • music starts at a random piece
File size: 5.0 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      srand(time(0));  //initaialize RNG; TODO check if it works on win
120      SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
121      Orxonox* orx = Orxonox::getSingleton();
122#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
123      orx->init(argc, argv, macBundlePath());
124      orx->start();
125#else
126/*
127for (int i = 0; i < 500; i++)
128{
129int x = rand() % 40000 - 20000;
130int y = rand() % 40000 - 20000;
131int z = rand() % 40000 - 20000;
132
133int scale = rand() % 100 + 20;
134
135int version = rand() % 6 + 1;
136
137float rotx = float(rand()) / RAND_MAX;
138float roty = float(rand()) / RAND_MAX;
139float rotz = float(rand()) / RAND_MAX;
140
141int axis = rand() % 3 + 1;
142
143if (axis == 1)
144  rotx = 0;
145if (axis == 2)
146  roty = 0;
147if (axis == 3)
148  rotz = 0;
149
150int rotation = rand() % 40 + 10;
151
152//    <Model position="1000,1500,0" scale="50" mesh="ast1.mesh" rotationAxis="0,1.25,0" rotationRate="70" />
153std::cout << "    <Model position=\"" << x << "," << y << "," << z << "\" scale=\"" << scale << "\" mesh=\"ast" << version << ".mesh\" rotationAxis=\"" << rotx << "," << roty << "," << rotz << "\" rotationRate=\"" << rotation << "\" />" << std::endl;
154
155
156}
157*/
158      orx->init(argc, argv, "");
159      orx->start();
160#endif
161    }
162    catch (Ogre::Exception& e) {
163#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
164      MessageBoxA(NULL, e.getFullDescription().c_str(),
165            "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
166#else
167      std::cerr << "Exception:\n";
168      std::cerr << e.getFullDescription().c_str() << "\n";
169#endif
170      return 1;
171    }
172    return 0;
173  }
174
175#ifdef __cplusplus
176}
177#endif
178
179
180/*int main(int argc, char **argv)
181{
182  try
183  {
184    SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
185    Orxonox* orx = Orxonox::getSingleton();
186#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
187    orx->init(argc, argv, macBundlePath());
188    orx->start();
189#else
190    orx->init(argc, argv, "");
191    orx->start();
192#endif
193
194  }
195  catch(Ogre::Exception& e)
196  {
197    fprintf(stderr, "An exception has occurred: %s\n",
198            e.getFullDescription().c_str());
199    return 1;
200  }
201
202  return 0;
203}
204
205*/
Note: See TracBrowser for help on using the repository browser.