Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 621 was 618, checked in by nicolasc, 17 years ago
  • changed comments to doxygen tags in flocking
  • reduced ogre depency in HUD and ParticleInterface
  • various
File size: 4.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#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      orx->init(argc, argv, "");
126      orx->start();
127#endif
128    }
129    catch (Ogre::Exception& e) {
130#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
131      MessageBoxA(NULL, e.getFullDescription().c_str(),
132            "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
133#else
134      std::cerr << "Exception:\n";
135      std::cerr << e.getFullDescription().c_str() << "\n";
136#endif
137      return 1;
138    }
139    return 0;
140  }
141
142#ifdef __cplusplus
143}
144#endif
145
146
147/*int main(int argc, char **argv)
148{
149  try
150  {
151    SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
152    Orxonox* orx = Orxonox::getSingleton();
153#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
154    orx->init(argc, argv, macBundlePath());
155    orx->start();
156#else
157    orx->init(argc, argv, "");
158    orx->start();
159#endif
160
161  }
162  catch(Ogre::Exception& e)
163  {
164    fprintf(stderr, "An exception has occurred: %s\n",
165            e.getFullDescription().c_str());
166    return 1;
167  }
168
169  return 0;
170}
171
172*/
Note: See TracBrowser for help on using the repository browser.