Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 171 for code/branches


Ignore:
Timestamp:
Nov 5, 2007, 9:29:25 PM (17 years ago)
Author:
rgrieder
Message:
  • added all my own files in the src directory
  • edited CMakeLists.txt in the src folder to match my files
Location:
code/branches/main_reto
Files:
23 added
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/main_reto/src/CMakeLists.txt

    r137 r171  
    22
    33# create a few variables to simplify life
    4 SET(SRC_FILES orxonox.cc)
    5 #SET(INC_FILES ExampleApplication.h  ExampleFrameListener.h)
     4SET(SRC_FILES
     5        orxonox.cc
     6        main.cc
     7        ammunition_dump.cc
     8        barrel_gun..c
     9        bullet.cc
     10        camera_manager.cc
     11        ogre_control.cc
     12        orxonox_scene.cc
     13        orxonox_ship.cc
     14        run_manager.cc
     15        weapon_manager.cc)
     16SET(INC_FILES
     17        ammunition_dump.h
     18        barrel_gun.h
     19        bullet.h
     20        camera_manager.h
     21        orgre_control.h
     22        orxonox.h
     23        orxonox_prerequisites.h
     24        orxonox_scene.h
     25        orxonox_ship.h
     26        run_manager.h
     27        weapon.h
     28        weapon_manager.h)
    629
    730#Creates an executable
  • code/branches/main_reto/src/orxonox.cc

    r151 r171  
    2020 *
    2121 *   Author:
    22  *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
     22 *      Reto Grieder
    2323 *   Co-authors:
    2424 *      ...
     
    2727
    2828/**
    29  @file  orxonox.cc
    30  @brief Orxonox Main File
    31  */
     29* Basic part of the game.
     30* It sets up Ogre and most important of all: Orxonox is the master of the
     31* main loop and therefore time itself.
     32*/
    3233
    33 #include <Ogre.h>
    34 #include <OIS/OIS.h>
    35 #include <CEGUI/CEGUI.h>
    36 #include <OgreCEGUIRenderer.h>
     34#include "OgreRoot.h"
     35#include "OgreTimer.h"
     36#include "OgreWindowEventUtilities.h"
    3737
    38 // some tests to see if enet works without includsion
    39 //#include <enet/enet.h>
    40 //#include <enet/protocol.h>
     38#include "ogre_control.h"
     39#include "run_manager.h"
     40#include "orxonox.h"
    4141
    42 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
    43 #include <CoreFoundation/CoreFoundation.h>
    4442
    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);
     43namespace orxonox {
    5344
    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 using namespace Ogre;
    70 
    71 class OrxExitListener : public FrameListener
    72 {
    73   public:
    74     OrxExitListener(OIS::Keyboard *keyboard)
    75   : mKeyboard(keyboard)
    76     {
    77     }
    78 
    79     bool frameStarted(const FrameEvent& evt)
    80     {
    81       mKeyboard->capture();
    82       return !mKeyboard->isKeyDown(OIS::KC_ESCAPE);
    83     }
    84 
    85   private:
    86     OIS::Keyboard *mKeyboard;
    87 };
    88 
    89 class OrxApplication
    90 {
    91   public:
    92     void go()
    93     {
    94       createRoot();
    95       defineResources();
    96       setupRenderSystem();
    97       createRenderWindow();
    98       initializeResourceGroups();
    99       setupScene();
    100       setupInputSystem();
    101       setupCEGUI();
    102       createFrameListener();
    103       startRenderLoop();
    104     }
    105 
    106     ~OrxApplication()
    107     {
    108       mInputManager->destroyInputObject(mKeyboard);
    109       OIS::InputManager::destroyInputSystem(mInputManager);
    110 
    111 //       delete mRenderer;
    112 //       delete mSystem;
    113 
    114       delete mListener;
    115       delete mRoot;
    116     }
    117 
    118   private:
    119     Root *mRoot;
    120     OIS::Keyboard *mKeyboard;
    121     OIS::Mouse *mMouse;
    122     OIS::InputManager *mInputManager;
    123     CEGUI::OgreCEGUIRenderer *mRenderer;
    124     CEGUI::System *mSystem;
    125     OrxExitListener *mListener;
    126 
    127     void createRoot()
    128     {
    129 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
    130       mRoot = new Root(macBundlePath() + "/Contents/Resources/plugins.cfg");
    131 #else
    132       mRoot = new Root();
    133 #endif
    134     }
    135 
    136     void defineResources()
    137     {
    138       String secName, typeName, archName;
    139       ConfigFile cf;
    140 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
    141       cf.load(macBundlePath() + "/Contents/Resources/resources.cfg");
    142 #else
    143       cf.load("resources.cfg");
    144 #endif
    145 
    146       ConfigFile::SectionIterator seci = cf.getSectionIterator();
    147       while (seci.hasMoreElements())
    148       {
    149         secName = seci.peekNextKey();
    150         ConfigFile::SettingsMultiMap *settings = seci.getNext();
    151         ConfigFile::SettingsMultiMap::iterator i;
    152         for (i = settings->begin(); i != settings->end(); ++i)
    153         {
    154           typeName = i->first;
    155           archName = i->second;
    156 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
    157           ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName);
    158 #else
    159           ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName);
    160 #endif
    161         }
    162       }
    163     }
    164 
    165     void setupRenderSystem()
    166     {
    167       if (!mRoot->restoreConfig() && !mRoot->showConfigDialog())
    168         throw Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()");
    169     }
    170 
    171     void createRenderWindow()
    172     {
    173       mRoot->initialise(true, "Ogre Render Window");
    174     }
    175 
    176     void initializeResourceGroups()
    177     {
    178       TextureManager::getSingleton().setDefaultNumMipmaps(5);
    179       ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    180     }
    181 
    182     void setupScene()
    183     {
    184       SceneManager *mgr = mRoot->createSceneManager(ST_GENERIC, "Default SceneManager");
    185       Camera *cam = mgr->createCamera("Camera");
    186       Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam);
    187     }
    188 
    189     void setupInputSystem()
    190     {
    191       size_t windowHnd = 0;
    192       std::ostringstream windowHndStr;
    193       OIS::ParamList pl;
    194       RenderWindow *win = mRoot->getAutoCreatedWindow();
    195 
    196       win->getCustomAttribute("WINDOW", &windowHnd);
    197       windowHndStr << windowHnd;
    198       pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
    199       mInputManager = OIS::InputManager::createInputSystem(pl);
    200 
    201       try
    202       {
    203         mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false));
    204         mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false));
    205       }
    206       catch (const OIS::Exception &e)
    207       {
    208         throw new Exception(42, e.eText, "OrxApplication::setupInputSystem");
    209       }
    210     }
    211 
    212     void setupCEGUI()
    213     {
    214       SceneManager *mgr = mRoot->getSceneManager("Default SceneManager");
    215       RenderWindow *win = mRoot->getAutoCreatedWindow();
    216 
    217       // CEGUI setup
    218 //       mRenderer = new CEGUI::OgreCEGUIRenderer(win, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mgr);
    219 //       mSystem = new CEGUI::System(mRenderer);
    220 
    221       // Other CEGUI setup here.
    222     }
    223 
    224     void createFrameListener()
    225     {
    226       mListener = new OrxExitListener(mKeyboard);
    227       mRoot->addFrameListener(mListener);
    228     }
    229 
    230     void startRenderLoop()
    231     {
    232       mRoot->startRendering();
    233     }
    234 };
    235 
    236 #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    237 #define WIN32_LEAN_AND_MEAN
    238 #include "windows.h"
    239 
    240              INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
    241 #else
    242              int main(int argc, char **argv)
    243 #endif
    244 {
    245   try
     45  /**
     46  * Empty Constructor.
     47  */
     48  Orxonox::Orxonox()
    24649  {
    247     OrxApplication orxonox;
    248     orxonox.go();
    249   }
    250   catch(Exception& e)
    251   {
    252 #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    253     MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
    254 #else
    255     fprintf(stderr, "An exception has occurred: %s\n",
    256             e.getFullDescription().c_str());
    257 #endif
    25850  }
    25951
    260   return 0;
     52
     53  /**
     54  * Empty Destructor.
     55  */
     56  Orxonox::~Orxonox()
     57  {
     58  }
     59
     60
     61  /**
     62  * Starts and runs the game
     63  */
     64  void Orxonox::go(void)
     65  {
     66          if (!setup())
     67                  return;
     68
     69    timer_ = new Ogre::Timer();
     70
     71          unsigned long lastTime = timer_->getMilliseconds();
     72
     73          while (true)
     74          {
     75                  //Pump messages in all registered RenderWindow windows
     76      Ogre::WindowEventUtilities::messagePump();
     77
     78                  ogre_->getRoot()->renderOneFrame();
     79
     80                  if (!runMgr_->tick(timer_->getMilliseconds(),
     81              (timer_->getMilliseconds() - lastTime) / 1000.0))
     82                          break;
     83                  lastTime = timer_->getMilliseconds();
     84          }
     85
     86          // clean up
     87          destroy();
     88  }
     89
     90
     91  /**
     92  * Create render engine, render window and the Run manager.
     93  * @return False if failed.
     94  */
     95  bool Orxonox::setup(void)
     96  {
     97          // create new 3D ogre render engine
     98          ogre_ = new OgreControl();
     99          ogre_->initialise();
     100
     101          runMgr_ = new RunManager(ogre_);
     102
     103          return true;
     104  }
     105
     106
     107  /**
     108  * Clean everything up.
     109  */
     110  void Orxonox::destroy()
     111  {
     112          if (timer_)
     113                  delete timer_;
     114          if (runMgr_)
     115                  delete runMgr_;
     116          if (ogre_)
     117                  delete ogre_;
     118  }
     119
    261120}
    262 
Note: See TracChangeset for help on using the changeset viewer.