Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 116


Ignore:
Timestamp:
Oct 29, 2007, 12:00:43 AM (17 years ago)
Author:
anonymous
Message:

freed application of ExampleFramework

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/bin/resources.cfg

    r107 r116  
    66# Resource locations to be added to the default path
    77[General]
    8 #FileSystem=../Media
    9 #FileSystem=../Media/fonts
    10 #FileSystem=../Media/materials/programs
    11 #FileSystem=../Media/materials/scripts
    12 #FileSystem=../Media/materials/textures
    13 #FileSystem=../Media/models
    14 #FileSystem=../Media/overlays
    15 #FileSystem=../Media/particle
    16 #FileSystem=../Media/gui
    17 #FileSystem=../Media/DeferredShadingMedia
    18 #Zip=../Media/packs/cubemap.zip
    19 #Zip=../Media/packs/cubemapsJS.zip
    20 #Zip=../Media/packs/dragon.zip
    21 #Zip=../Media/packs/fresneldemo.zip
    22 #Zip=../Media/packs/ogretestmap.zip
    23 #Zip=../Media/packs/skybox.zip
     8FileSystem=../Media
     9FileSystem=../Media/fonts
     10FileSystem=../Media/materials/programs
     11FileSystem=../Media/materials/scripts
     12FileSystem=../Media/materials/textures
     13FileSystem=../Media/models
     14FileSystem=../Media/overlays
     15FileSystem=../Media/particle
     16FileSystem=../Media/gui
     17FileSystem=../Media/DeferredShadingMedia
     18Zip=../Media/packs/cubemap.zip
     19Zip=../Media/packs/cubemapsJS.zip
     20Zip=../Media/packs/dragon.zip
     21Zip=../Media/packs/fresneldemo.zip
     22Zip=../Media/packs/ogretestmap.zip
     23Zip=../Media/packs/skybox.zip
  • code/trunk/src/orxonox.cc

    r112 r116  
    2626 */
    2727
    28 // TODO: Change this to orxonox.h and include all necessary functions there
    29 #include "ExampleApplication.h"
     28#include <Ogre.h>
     29#include <OIS/OIS.h>
    3030#include <CEGUI/CEGUI.h>
    31 
    32 // TODO: Put creation of SceneNode and implementation of FrameListener into an extern file
    33 SceneNode *lightNode;
    34 
    35 class OrxFrameListener : public ExampleFrameListener
     31#include <OgreCEGUIRenderer.h>
     32
     33#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
     34#include <CoreFoundation/CoreFoundation.h>
     35
     36// This function will locate the path to our application on OS X,
     37// unlike windows you can not rely on the curent working directory
     38// for locating your configuration files and resources.
     39std::string macBundlePath()
     40{
     41  char path[1024];
     42  CFBundleRef mainBundle = CFBundleGetMainBundle();
     43  assert(mainBundle);
     44
     45  CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle);
     46  assert(mainBundleURL);
     47
     48  CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
     49  assert(cfStringRef);
     50
     51  CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII);
     52
     53  CFRelease(mainBundleURL);
     54  CFRelease(cfStringRef);
     55
     56  return std::string(path);
     57}
     58#endif
     59
     60using namespace Ogre;
     61
     62class OrxExitListener : public FrameListener
    3663{
    3764  public:
    38     OrxFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneMgr)
    39   : ExampleFrameListener(win, cam, false, false)
    40     {
    41     }
    42 
    43     bool frameStarted(const FrameEvent &evt)
    44     {
    45         // add tutorial code here:
    46         // ...
    47       lightNode->translate(Vector3(0, -10 * evt.timeSinceLastFrame, 0));
    48 
    49       return ExampleFrameListener::frameStarted(evt);
    50     }
     65    OrxExitListener(OIS::Keyboard *keyboard)
     66  : mKeyboard(keyboard)
     67    {
     68    }
     69
     70    bool frameStarted(const FrameEvent& evt)
     71    {
     72      mKeyboard->capture();
     73      return !mKeyboard->isKeyDown(OIS::KC_ESCAPE);
     74    }
     75
    5176  private:
     77    OIS::Keyboard *mKeyboard;
    5278};
    5379
    54 // TODO: Make Doxygen tags work and create scene AFTER loading in an extern file
    55 //! This is the application class of Orxonox
    56 /**
    57   Application class. The starting point of Orxonox.
    58   Loading of ressources should start in here.
    59   ...
    60 */
    61 class Orxonox : public ExampleApplication
    62 {
    63   protected:
     80class OrxApplication
     81{
    6482  public:
    65     Orxonox()
    66     {
    67     }
    68 
    69     ~Orxonox()
    70     {
    71     }
    72   protected:
    73     void createCamera(void)
    74     {
    75         // create camera
    76       mCamera = mSceneMgr->createCamera("PlayerCam");
    77       mCamera->setNearClipDistance(5);
    78       mCamera->setPosition(Vector3(0,10,500));
    79       mCamera->lookAt(Vector3(0,0,0));
    80     }
    81 
    82     void createScene(void)
    83     {
    84         // add tutorial code here:
    85         // ...
    86       //mSceneMgr->setAmbientLight( ColourValue( 0.3, 0.3, 0.3 ) );
    87       //Entity* head = mSceneMgr->createEntity("head", "ogrehead.mesh");
    88 
    89       //Entity* head2 = mSceneMgr->createEntity("head2", "ogrehead.mesh");
    90 
    91       //ceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode( "OgreHeadNode", Vector3( 0, 0, 0 ) );
    92       //node->attachObject( head );
    93 
    94       //SceneNode *node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "OgreHeadNode2", Vector3( 50, 0, 0 ) );
    95       //node2->attachObject( head2 );
    96 
    97 
    98       //mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox");
    99 
    100       Light *light = mSceneMgr->createLight("Light1");
    101       light->setType(Light::LT_POINT);
    102       light->setPosition(Vector3(0, 100, 0));
    103       light->setDiffuseColour(0.5, 0.5, 0.0);
    104       light->setSpecularColour(0.5, 0.5, 0.0);
    105 
    106       BillboardSet *bbs = mSceneMgr->createBillboardSet("bb", 1);
    107       bbs->createBillboard(Vector3::ZERO, ColourValue(1.0, 0.0, 0.0));
    108       //bbs->setMaterialName("Examples/Flare");
    109 
    110       lightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("LightNode", Vector3(0, 100, 0));
    111       lightNode->attachObject(bbs);
    112       lightNode->attachObject(light);
    113       light->setPosition(0.0, 0.0, 0.0);
    114     }
    115 
    116     void createFrameListener(void)
    117     {
    118         // create frame listener
    119       mFrameListener = new OrxFrameListener(mWindow, mCamera, mSceneMgr);
    120       mRoot->addFrameListener(mFrameListener);
     83    void go()
     84    {
     85      createRoot();
     86      defineResources();
     87      setupRenderSystem();
     88      createRenderWindow();
     89      initializeResourceGroups();
     90      setupScene();
     91      setupInputSystem();
     92      setupCEGUI();
     93      createFrameListener();
     94      startRenderLoop();
     95    }
     96
     97    ~OrxApplication()
     98    {
     99      mInputManager->destroyInputObject(mKeyboard);
     100      OIS::InputManager::destroyInputSystem(mInputManager);
     101
     102      delete mRenderer;
     103      delete mSystem;
     104
     105      delete mListener;
     106      delete mRoot;
     107    }
     108
     109  private:
     110    Root *mRoot;
     111    OIS::Keyboard *mKeyboard;
     112    OIS::Mouse *mMouse;
     113    OIS::InputManager *mInputManager;
     114    CEGUI::OgreCEGUIRenderer *mRenderer;
     115    CEGUI::System *mSystem;
     116    OrxExitListener *mListener;
     117
     118    void createRoot()
     119    {
     120#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
     121      mRoot = new Root(macBundlePath() + "/Contents/Resources/plugins.cfg");
     122#else
     123      mRoot = new Root();
     124#endif
     125    }
     126
     127    void defineResources()
     128    {
     129      String secName, typeName, archName;
     130      ConfigFile cf;
     131#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
     132      cf.load(macBundlePath() + "/Contents/Resources/resources.cfg");
     133#else
     134      cf.load("resources.cfg");
     135#endif
     136
     137      ConfigFile::SectionIterator seci = cf.getSectionIterator();
     138      while (seci.hasMoreElements())
     139      {
     140        secName = seci.peekNextKey();
     141        ConfigFile::SettingsMultiMap *settings = seci.getNext();
     142        ConfigFile::SettingsMultiMap::iterator i;
     143        for (i = settings->begin(); i != settings->end(); ++i)
     144        {
     145          typeName = i->first;
     146          archName = i->second;
     147#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
     148          ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName);
     149#else
     150          ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName);
     151#endif
     152        }
     153      }
     154    }
     155
     156    void setupRenderSystem()
     157    {
     158      if (!mRoot->restoreConfig() && !mRoot->showConfigDialog())
     159        throw Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()");
     160    }
     161
     162    void createRenderWindow()
     163    {
     164      mRoot->initialise(true, "Ogre Render Window");
     165    }
     166
     167    void initializeResourceGroups()
     168    {
     169      TextureManager::getSingleton().setDefaultNumMipmaps(5);
     170      ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
     171    }
     172
     173    void setupScene()
     174    {
     175      SceneManager *mgr = mRoot->createSceneManager(ST_GENERIC, "Default SceneManager");
     176      Camera *cam = mgr->createCamera("Camera");
     177      Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam);
     178    }
     179
     180    void setupInputSystem()
     181    {
     182      size_t windowHnd = 0;
     183      std::ostringstream windowHndStr;
     184      OIS::ParamList pl;
     185      RenderWindow *win = mRoot->getAutoCreatedWindow();
     186
     187      win->getCustomAttribute("WINDOW", &windowHnd);
     188      windowHndStr << windowHnd;
     189      pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
     190      mInputManager = OIS::InputManager::createInputSystem(pl);
     191
     192      try
     193      {
     194        mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false));
     195        mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false));
     196      }
     197      catch (const OIS::Exception &e)
     198      {
     199        throw new Exception(42, e.eText, "OrxApplication::setupInputSystem");
     200      }
     201    }
     202
     203    void setupCEGUI()
     204    {
     205      SceneManager *mgr = mRoot->getSceneManager("Default SceneManager");
     206      RenderWindow *win = mRoot->getAutoCreatedWindow();
     207
     208      // CEGUI setup
     209      mRenderer = new CEGUI::OgreCEGUIRenderer(win, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mgr);
     210      mSystem = new CEGUI::System(mRenderer);
     211
     212      // Other CEGUI setup here.
     213    }
     214
     215    void createFrameListener()
     216    {
     217      mListener = new OrxExitListener(mKeyboard);
     218      mRoot->addFrameListener(mListener);
     219    }
     220
     221    void startRenderLoop()
     222    {
     223      mRoot->startRendering();
    121224    }
    122225};
    123226
    124 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
     227#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    125228#define WIN32_LEAN_AND_MEAN
    126229#include "windows.h"
    127230
    128 INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
    129 #else
    130 
    131 int main(int argc, char **argv)
    132 #endif
    133 {
    134   // Create application object
    135   Orxonox orxonox;
    136 
    137   try {
     231             INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
     232#else
     233             int main(int argc, char **argv)
     234#endif
     235{
     236  try
     237  {
     238    OrxApplication orxonox;
    138239    orxonox.go();
    139   } catch( Exception& e ) {
    140 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    141     MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
     240  }
     241  catch(Exception& e)
     242  {
     243#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
     244    MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
    142245#else
    143246    fprintf(stderr, "An exception has occurred: %s\n",
     
    148251  return 0;
    149252}
     253
Note: See TracChangeset for help on using the changeset viewer.