Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/orxonox/Main.cc @ 920

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