Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 668 was 668, checked in by rgrieder, 16 years ago
  • updated weapon system file names
  • some code style modifications in a few other files
  • removed some compiler warnings
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 <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#ifndef WIN32_LEAN_AND_MEAN
75#define WIN32_LEAN_AND_MEAN
76#endif
77#include "windows.h"
78  INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
79  {
80    // something like this would be less hacky
81    // maybe one can work with trailing '\0'
82    // or maybe use string based functions
83    // I was unable to test it without working windows version
84    char* cmd = strCmdLine;
85    int argc = 2;
86    int i;
87    for(i = 0; cmd[i] != NULL; i++)
88    {
89      if(cmd[i] == ' ') argc++;
90    }
91    char **argv = new char*[argc];
92    for (int j = 0; j < argc; j++)
93    {
94      argv[j] = new char[i];
95    }
96    int j = 1;
97    int k = 0;
98    for(int i = 0; cmd[i] != NULL; i++)
99    {
100      if(cmd[i] != ' ') {
101        argv[j][k] = cmd[i];
102        k++;
103      }
104      else {
105        argv[j][k] = '\0';
106        k = 0;
107        j++;
108      }
109    }
110    argv[j][k] = '\0';
111    argv[0] = "BeniXonox.exe";
112    //char *argv[2];
113    //argv[0] = "asdfProgram";
114    //argv[1] =  strCmdLine;
115    //int argc = 2;
116#else
117  int main(int argc, char **argv)
118  {
119#endif
120    try {
121      srand(time(0));  //initaialize RNG; TODO check if it works on win
122      SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
123      Orxonox* orx = Orxonox::getSingleton();
124#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
125      orx->init(argc, argv, macBundlePath());
126      orx->start();
127#else
128/*
129for (int i = 0; i < 500; i++)
130{
131int x = rand() % 40000 - 20000;
132int y = rand() % 40000 - 20000;
133int z = rand() % 40000 - 20000;
134
135int scale = rand() % 100 + 20;
136
137int version = rand() % 6 + 1;
138
139float rotx = float(rand()) / RAND_MAX;
140float roty = float(rand()) / RAND_MAX;
141float rotz = float(rand()) / RAND_MAX;
142
143int axis = rand() % 3 + 1;
144
145if (axis == 1)
146  rotx = 0;
147if (axis == 2)
148  roty = 0;
149if (axis == 3)
150  rotz = 0;
151
152int rotation = rand() % 40 + 10;
153
154//    <Model position="1000,1500,0" scale="50" mesh="ast1.mesh" rotationAxis="0,1.25,0" rotationRate="70" />
155std::cout << "    <Model position=\"" << x << "," << y << "," << z << "\" scale=\"" << scale << "\" mesh=\"ast" << version << ".mesh\" rotationAxis=\"" << rotx << "," << roty << "," << rotz << "\" rotationRate=\"" << rotation << "\" />" << std::endl;
156
157
158}
159*/
160      orx->init(argc, argv, "");
161      orx->start();
162#endif
163    }
164    catch (Ogre::Exception& e) {
165#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
166      MessageBoxA(NULL, e.getFullDescription().c_str(),
167            "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
168#else
169      std::cerr << "Exception:\n";
170      std::cerr << e.getFullDescription().c_str() << "\n";
171#endif
172      return 1;
173    }
174    return 0;
175  }
176
177#ifdef __cplusplus
178}
179#endif
180
181
182/*int main(int argc, char **argv)
183{
184  try
185  {
186    SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
187    Orxonox* orx = Orxonox::getSingleton();
188#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
189    orx->init(argc, argv, macBundlePath());
190    orx->start();
191#else
192    orx->init(argc, argv, "");
193    orx->start();
194#endif
195
196  }
197  catch(Ogre::Exception& e)
198  {
199    fprintf(stderr, "An exception has occurred: %s\n",
200            e.getFullDescription().c_str());
201    return 1;
202  }
203
204  return 0;
205}
206
207*/
Note: See TracBrowser for help on using the repository browser.