Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/class_hierarchy/orxonox.cc @ 389

Last change on this file since 389 was 389, checked in by nicolasc, 17 years ago

merged audio into FICN

File size: 8.2 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 modify
8 *   it under the terms of the GNU General Public License as published by
9 *   the Free Software Foundation, either version 3 of the License, or
10 *   (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, see <http://www.gnu.org/licenses/>.
19 *
20 *
21 *   Author:
22 *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28#include <Ogre.h>
29#include <OIS/OIS.h>
30#include <CEGUI/CEGUI.h>
31#include <OgreCEGUIRenderer.h>
32
33#include "BaseObject.h"
34#include "Test.h"
35#include "test1.h"
36#include "test2.h"
37#include "test3.h"
38
39#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
40#include <CoreFoundation/CoreFoundation.h>
41
42// This function will locate the path to our application on OS X,
43// unlike windows you can not rely on the curent working directory
44// for locating your configuration files and resources.
45std::string macBundlePath()
46{
47  char path[1024];
48  CFBundleRef mainBundle = CFBundleGetMainBundle();
49  assert(mainBundle);
50
51  CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle);
52  assert(mainBundleURL);
53
54  CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
55  assert(cfStringRef);
56
57  CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII);
58
59  CFRelease(mainBundleURL);
60  CFRelease(cfStringRef);
61
62  return std::string(path);
63}
64#endif
65
66namespace orxonox
67{
68  class OrxExitListener : public Ogre::FrameListener
69  {
70    public:
71      OrxExitListener(OIS::Keyboard *keyboard)
72    : mKeyboard(keyboard)
73      {
74      }
75
76      bool frameStarted(const Ogre::FrameEvent& evt)
77      {
78        mKeyboard->capture();
79        return !mKeyboard->isKeyDown(OIS::KC_ESCAPE);
80      }
81
82    private:
83      OIS::Keyboard *mKeyboard;
84  };
85
86  class OrxApplication
87  {
88    public:
89      void go()
90      {
91
92        #define testandcout(code) \
93          std::cout << #code << " " << code << "\n"
94
95
96        std::cout << "Test 8\n";
97
98        std::cout << "1\n";
99        Test1* test8_01 = new Test1;
100        Test3* test8_03 = new Test3;
101        test8_03->usefullClassesIsATest(test8_01);
102
103        std::cout << "2\n";
104        Test2* test8_02 = new Test2;
105        test8_03->usefullClassesIsATest(test8_02);
106
107        std::cout << "3\n";
108        test8_01->setUsefullClass1(Class(Test1));
109        test8_01->setUsefullClass1(test8_02->getIdentifier());
110        test8_01->setUsefullClass2(Class(Test2));
111        test8_01->setUsefullClassOfTypeTest3(Class(Test3));
112        test8_01->setUsefullClassOfTypeTest3(test8_03->getIdentifier());
113
114
115        testandcout(test8_01->isA(Class(Test1)));
116        testandcout(test8_01->isA(Class(Test2)));
117        testandcout(test8_01->isA(Class(Test3)));
118
119        Test2* test8_04 = new Test2;
120        testandcout(test8_02->isA(Class(Test1)));
121        testandcout(test8_02->isA(Class(Test2)));
122        testandcout(test8_02->isA(Class(Test3)));
123
124        Test3* test8_05 = new Test3;
125        testandcout(test8_03->isA(Class(Test1)));
126        testandcout(test8_03->isA(Class(Test2)));
127        testandcout(test8_03->isA(Class(Test3)));
128
129        delete test8_01;
130        delete test8_02;
131        delete test8_03;
132
133
134      }
135
136      ~OrxApplication()
137      {
138        mInputManager->destroyInputObject(mKeyboard);
139        OIS::InputManager::destroyInputSystem(mInputManager);
140
141        delete mRenderer;
142        delete mSystem;
143
144        delete mListener;
145        delete mRoot;
146      }
147
148    private:
149      Ogre::Root *mRoot;
150      OIS::Keyboard *mKeyboard;
151      OIS::Mouse *mMouse;
152      OIS::InputManager *mInputManager;
153      CEGUI::OgreCEGUIRenderer *mRenderer;
154      CEGUI::System *mSystem;
155      OrxExitListener *mListener;
156
157      void createRoot()
158      {
159#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
160        mRoot = new Ogre::Root(macBundlePath() + "/Contents/Resources/plugins.cfg");
161#else
162        mRoot = new Ogre::Root();
163#endif
164      }
165
166      void defineResources()
167      {
168        Ogre::String secName, typeName, archName;
169        Ogre::ConfigFile cf;
170#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
171        cf.load(macBundlePath() + "/Contents/Resources/resources.cfg");
172#else
173        cf.load("resources.cfg");
174#endif
175
176        Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
177        while (seci.hasMoreElements())
178        {
179          secName = seci.peekNextKey();
180          Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
181          Ogre::ConfigFile::SettingsMultiMap::iterator i;
182          for (i = settings->begin(); i != settings->end(); ++i)
183          {
184            typeName = i->first;
185            archName = i->second;
186#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
187            Ogre::ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName);
188#else
189            Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName);
190#endif
191          }
192        }
193      }
194
195      void setupRenderSystem()
196      {
197        if (!mRoot->restoreConfig() && !mRoot->showConfigDialog())
198          throw Ogre::Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()");
199      }
200
201      void createRenderWindow()
202      {
203        mRoot->initialise(true, "Ogre Render Window");
204      }
205
206      void initializeResourceGroups()
207      {
208        Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
209        Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
210      }
211
212      void setupScene()
213      {
214        Ogre::SceneManager *mgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager");
215        Ogre::Camera *cam = mgr->createCamera("Camera");
216        Ogre::Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam);
217      }
218
219      void setupInputSystem()
220      {
221        size_t windowHnd = 0;
222        std::ostringstream windowHndStr;
223        OIS::ParamList pl;
224        Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow();
225
226        win->getCustomAttribute("WINDOW", &windowHnd);
227        windowHndStr << windowHnd;
228        pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
229        mInputManager = OIS::InputManager::createInputSystem(pl);
230
231        try
232        {
233          mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false));
234          mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false));
235        }
236        catch (const OIS::Exception &e)
237        {
238          throw new Ogre::Exception(42, e.eText, "OrxApplication::setupInputSystem");
239        }
240      }
241
242      void setupCEGUI()
243      {
244        Ogre::SceneManager *mgr = mRoot->getSceneManager("Default SceneManager");
245        Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow();
246
247        // CEGUI setup
248        mRenderer = new CEGUI::OgreCEGUIRenderer(win, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mgr);
249        mSystem = new CEGUI::System(mRenderer);
250
251        // Other CEGUI setup here.
252      }
253
254      void createFrameListener()
255      {
256        mListener = new OrxExitListener(mKeyboard);
257        mRoot->addFrameListener(mListener);
258      }
259
260      void startRenderLoop()
261      {
262        mRoot->startRendering();
263      }
264  };
265}
266
267using namespace Ogre;
268
269#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
270#define WIN32_LEAN_AND_MEAN
271#include "windows.h"
272
273             INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
274#else
275             int main(int argc, char **argv)
276#endif
277{
278  try
279  {
280    orxonox::OrxApplication orxonox;
281    orxonox.go();
282  }
283  catch(Exception& e)
284  {
285#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
286    MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
287#else
288    fprintf(stderr, "An exception has occurred: %s\n",
289            e.getFullDescription().c_str());
290#endif
291  }
292
293  return 0;
294}
Note: See TracBrowser for help on using the repository browser.