Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/main.cc @ 552

Last change on this file since 552 was 546, checked in by bknecht, 17 years ago

suggestion for solution of WinMain problem

File size: 4.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 = 1;
84    for(int i = 0; cmd[i] != NULL; i++)
85    {
86      if(cmd[i] == ' ') argc++;
87    }
88    char* argv[argc];
89    int j = 0;
90    int k = 0;
91    for(int i = 0; cmd[i] != NULL; i++)
92    {
93      if(cmd[i] != ' ') {
94        argv[j][k];
95        k++;
96      }
97      else {
98        k = 0;
99        j++;
100      }
101    }*/
102    char *argv[2];
103    argv[0] = "asdfProgram";
104    argv[1] =  strCmdLine;
105    int argc = 2;
106#else
107  int main(int argc, char **argv)
108  {
109#endif
110    try {
111      SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
112      Orxonox* orx = Orxonox::getSingleton();
113#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
114      orx->init(argc, argv, macBundlePath());
115      orx->start();
116#else
117      orx->init(argc, argv, "");
118      orx->start();
119#endif
120    }
121    catch (Ogre::Exception& e) {
122#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
123      MessageBoxA(NULL, e.getFullDescription().c_str(),
124            "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
125#else
126      std::cerr << "Exception:\n";
127      std::cerr << e.getFullDescription().c_str() << "\n";
128#endif
129      return 1;
130    }
131    return 0;
132  }
133
134#ifdef __cplusplus
135}
136#endif
137
138
139/*int main(int argc, char **argv)
140{
141  try
142  {
143    SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
144    Orxonox* orx = Orxonox::getSingleton();
145#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
146    orx->init(argc, argv, macBundlePath());
147    orx->start();
148#else
149    orx->init(argc, argv, "");
150    orx->start();
151#endif
152
153  }
154  catch(Ogre::Exception& e)
155  {
156    fprintf(stderr, "An exception has occurred: %s\n",
157            e.getFullDescription().c_str());
158    return 1;
159  }
160
161  return 0;
162}
163
164*/
Note: See TracBrowser for help on using the repository browser.