Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 10, 2008, 5:03:34 PM (16 years ago)
Author:
bknecht
Message:

merged back that script-branch

Location:
code/trunk/src/orxonox
Files:
2 deleted
32 edited
11 copied

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/CMakeLists.txt

    r871 r1021  
    11SET( ORXONOX_SRC_FILES
    22  GraphicsEngine.cc
     3  InputEventListener.cc
     4  InputHandler.cc
    35  Main.cc
    46  Orxonox.cc
    5   objects/Tickable.cc
    6   SpaceshipSteering.cc
     7#  SpaceshipSteering.cc
    78  hud/HUD.cc
    89  particle/ParticleInterface.cc
  • code/trunk/src/orxonox/GraphicsEngine.cc

    r790 r1021  
    3333
    3434#include <OgreRoot.h>
     35#include <OgreException.h>
    3536#include <OgreConfigFile.h>
    3637#include <OgreTextureManager.h>
     38#include <OgreRenderWindow.h>
    3739
     40#include "core/CoreIncludes.h"
    3841#include "core/Debug.h"
    3942#include "GraphicsEngine.h"
     
    4649  GraphicsEngine::GraphicsEngine()
    4750  {
     51    RegisterObject(GraphicsEngine);
     52    //this->bOverwritePath_ = false;
     53    this->setConfigValues();
    4854    // set to standard values
    4955    this->configPath_ = "";
    50     this->dataPath_ = "";
    51     scene_ = NULL;
     56    this->root_ = 0;
     57    this->scene_ = 0;
     58    this->renderWindow_ = 0;
    5259  }
    5360
     
    5562  GraphicsEngine::~GraphicsEngine()
    5663  {
     64    if (!this->root_)
     65      delete this->root_;
     66  }
     67
     68  void GraphicsEngine::setConfigValues()
     69  {
     70    SetConfigValue(dataPath_, dataPath_).description("relative path to media data");
     71
    5772  }
    5873
     
    6681    root_ = new Root(NULL, configPath_ + "ogre.cfg", configPath_ + "Ogre.log");
    6782#endif*/
    68 #if defined(_DEBUG) && defined(WIN32)
     83#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC && defined(_DEBUG)
    6984    std::string plugin_filename = "plugins_d.cfg";
    7085#else
     
    87102  }
    88103
    89   bool GraphicsEngine::load()
     104  bool GraphicsEngine::load(std::string dataPath)
    90105  {
     106    // temporary overwrite of dataPath, change ini file for permanent change
     107    if( dataPath != "" )
     108      dataPath_ = dataPath;
    91109    loadRessourceLocations(this->dataPath_);
    92110    if (!root_->restoreConfig() && !root_->showConfigDialog())
     
    95113  }
    96114
    97   void GraphicsEngine::startRender()
     115  void GraphicsEngine::initialise()
    98116  {
    99     root_->initialise(true, "OrxonoxV2");
     117    this->renderWindow_ = root_->initialise(true, "OrxonoxV2");
    100118    TextureManager::getSingleton().setDefaultNumMipmaps(5);
     119    //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load...
    101120    ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    102121  }
     
    131150  }
    132151
     152  /**
     153    Returns the window handle of the render window.
     154    At least the InputHandler uses this to create the OIS::InputManager
     155    @return The window handle of the render window
     156  */
     157  size_t GraphicsEngine::getWindowHandle()
     158  {
     159    if (this->renderWindow_)
     160    {
     161      Ogre::RenderWindow *renderWindow = this->root_->getAutoCreatedWindow();
     162      size_t windowHnd = 0;
     163      renderWindow->getCustomAttribute("WINDOW", &windowHnd);
     164      return windowHnd;
     165    }
     166    else
     167      return 0;
     168  }
     169
     170  /**
     171    Get the width of the current render window
     172    @return The width of the current render window
     173  */
     174  int GraphicsEngine::getWindowWidth() const
     175  {
     176    if (this->renderWindow_)
     177    {
     178      return this->renderWindow_->getWidth();
     179    }
     180    else
     181      return 0;
     182  }
     183
     184  /**
     185    Get the height of the current render window
     186    @return The height of the current render window
     187  */
     188  int GraphicsEngine::getWindowHeight() const
     189  {
     190    if (this->renderWindow_)
     191    {
     192      return this->renderWindow_->getHeight();
     193    }
     194    else
     195      return 0;
     196  }
    133197
    134198}
  • code/trunk/src/orxonox/GraphicsEngine.h

    r790 r1021  
    1010#include <string>
    1111
     12#include <OgrePrerequisites.h>
    1213#include <OgreRoot.h>
    1314#include <OgreSceneManager.h>
    1415
    1516#include "OrxonoxPrereqs.h"
     17#include "core/OrxonoxClass.h"
    1618
    1719
     
    2123   * graphics engine manager class
    2224 */
    23   class _OrxonoxExport GraphicsEngine {
     25  class _OrxonoxExport GraphicsEngine : public OrxonoxClass
     26  {
    2427    public:
    2528      GraphicsEngine();
    2629      inline void setConfigPath(std::string path) { this->configPath_ = path; };
    2730      // find a better way for this
    28       inline Ogre::Root* getRoot() { return root_; };
     31      //inline Ogre::Root* getRoot() { return root_; };
     32      void setConfigValues();
    2933      void setup();
    30       bool load();
     34      bool load(std::string path);
    3135      void loadRessourceLocations(std::string path);
    3236      Ogre::SceneManager* getSceneManager();
    33       void startRender();
     37      void initialise();
     38
     39      // several window properties
     40      Ogre::RenderWindow* getRenderWindow() { return this->renderWindow_; }
     41      size_t getWindowHandle();
     42      int getWindowWidth() const;
     43      int getWindowHeight() const;
     44
     45      // Ogre Root access for Orxonox
     46      void frameStarted(Ogre::FrameEvent &evt)
     47      { if (root_) root_->_fireFrameStarted(evt); }
     48      void frameEnded  (Ogre::FrameEvent &evt)
     49      { if (root_) root_->_fireFrameEnded(evt);   }
     50      void renderOneFrame()
     51      { if (root_) root_->_updateAllRenderTargets(); }
    3452
    3553      virtual ~GraphicsEngine();
     54
    3655    private:
    3756      Ogre::Root*         root_;        //!< Ogre's root
     
    3958      std::string         dataPath_;    //!< path to data file
    4059      Ogre::SceneManager* scene_;       //!< scene manager of the game
     60      Ogre::RenderWindow* renderWindow_;//!< the current render window
     61      //bool               bOverwritePath_; //!< overwrites path
    4162
    4263  };
  • code/trunk/src/orxonox/Main.cc

    r790 r1021  
    2727
    2828 /**
    29  @file  Main.cc
    30  @brief main file handling most of the machine specific code
     29 @file
     30 @brief Entry point of the program. Platform specific code.
    3131  */
    3232
    3333#include "OrxonoxStableHeaders.h"
    3434
    35 #include <OgrePlatform.h>
    36 #include <OgreException.h>
     35#include <exception>
    3736
    38 
     37#include "OrxonoxPlatform.h"
    3938#include "core/SignalHandler.h"
    4039#include "Orxonox.h"
    4140
    4241using namespace orxonox;
    43 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
     42#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE
    4443#include <CoreFoundation/CoreFoundation.h>
    4544
     
    7271#endif
    7372
    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;
     73int main(int argc, char **argv)
     74{
     75  try {
     76    SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
     77    Orxonox* orx = Orxonox::getSingleton();
     78
     79#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE
     80    orx->init(argc, argv, macBundlePath());
    11881#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 /*
    131 for (int i = 0; i < 500; i++)
    132 {
    133 int x = rand() % 40000 - 20000;
    134 int y = rand() % 40000 - 20000;
    135 int z = rand() % 40000 - 20000;
    136 
    137 int scale = rand() % 100 + 20;
    138 
    139 int version = rand() % 6 + 1;
    140 
    141 float rotx = float(rand()) / RAND_MAX;
    142 float roty = float(rand()) / RAND_MAX;
    143 float rotz = float(rand()) / RAND_MAX;
    144 
    145 int axis = rand() % 3 + 1;
    146 
    147 if (axis == 1)
    148   rotx = 0;
    149 if (axis == 2)
    150   roty = 0;
    151 if (axis == 3)
    152   rotz = 0;
    153 
    154 int rotation = rand() % 40 + 10;
    155 
    156 //    <Model position="1000,1500,0" scale="50" mesh="ast1.mesh" rotationAxis="0,1.25,0" rotationRate="70" />
    157 std::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 }
     82    orx->init(argc, argv, "");
    18183#endif
    18284
    183 
    184 /*int main(int argc, char **argv)
    185 {
    186   try
     85    orx->start();
     86    orx->destroy();
     87  }
     88  catch (std::exception &ex)
    18789  {
    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());
     90    std::cerr << "Exception:\n";
     91    std::cerr << ex.what() << "\n";
    20392    return 1;
    20493  }
     
    20796}
    20897
    209 */
     98#ifdef __cplusplus
     99}
     100#endif
  • code/trunk/src/orxonox/Orxonox.cc

    r871 r1021  
    3535
    3636//****** OGRE ******
    37 #include <OgreException.h>
    38 #include <OgreRoot.h>
     37//#include <OgreException.h>
    3938#include <OgreFrameListener.h>
    40 #include <OgreRenderWindow.h>
    41 #include <OgreTextureManager.h>
    42 #include <OgreResourceGroupManager.h>
    43 #include <OgreConfigFile.h>
    4439#include <OgreOverlay.h>
    4540#include <OgreOverlayManager.h>
    46 
    47 //****** OIS *******
    48 #include <OIS/OIS.h>
     41#include <OgreTimer.h>
     42#include <OgreWindowEventUtilities.h>
    4943
    5044//****** STD *******
    51 #include <iostream>
    52 #include <exception>
     45//#include <iostream>
     46//#include <exception>
     47#include <deque>
    5348
    5449//***** ORXONOX ****
    5550//misc
    56 #include "util/Sleep.h"
    57 
    58 // loader and audio
    59 //#include "loader/LevelLoader.h"
     51//#include "util/Sleep.h"
     52
     53// audio
    6054#include "audio/AudioManager.h"
    6155
     
    6357#include "network/Server.h"
    6458#include "network/Client.h"
    65 #include "network/NetworkFrameListener.h"
     59network::Client *client_g;
     60network::Server *server_g;
    6661
    6762// objects
    68 #include "objects/Tickable.h"
     63#include "core/ArgReader.h"
     64#include "core/Debug.h"
     65#include "core/Factory.h"
     66#include "core/Loader.h"
     67#include "core/Tickable.h"
     68#include "hud/HUD.h"
    6969#include "tools/Timer.h"
    70 #include "objects/NPC.h"
    71 #include "core/ArgReader.h"
    72 #include "core/Factory.h"
    73 #include "core/Debug.h"
    74 #include "core/Loader.h"
    75 #include "hud/HUD.h"
    7670#include "objects/weapon/BulletManager.h"
    77 #include "GraphicsEngine.h"
     71
     72#include "InputHandler.h"
    7873
    7974#include "Orxonox.h"
     
    8176namespace orxonox
    8277{
    83    // put this in a seperate Class or solve the problem in another fashion
    84   class OrxListener : public Ogre::FrameListener
    85   {
    86     public:
    87       OrxListener(OIS::Keyboard *keyboard, audio::AudioManager*  auMan, gameMode mode)
    88       {
    89         mKeyboard = keyboard;
    90         mode_=mode;
    91         auMan_ = auMan;
    92       }
    93 
    94       bool frameStarted(const Ogre::FrameEvent& evt)
    95       {
    96         auMan_->update();
    97         updateAI();
    98 
    99         if(mode_ == PRESENTATION)
    100           server_g->tick(evt.timeSinceLastFrame);
    101         else if(mode_ == CLIENT)
    102           client_g->tick(evt.timeSinceLastFrame);
    103 
    104         usleep(10);
    105 
    106         mKeyboard->capture();
    107         return !mKeyboard->isKeyDown(OIS::KC_ESCAPE);
    108       }
    109 
    110       void updateAI()
    111       {
    112         for(Iterator<NPC> it = ObjectList<NPC>::start(); it; ++it)
    113         {
    114           it->update();
    115         }
    116       }
    117 
    118     private:
    119       gameMode mode_;
    120       OIS::Keyboard *mKeyboard;
    121       audio::AudioManager*  auMan_;
    122   };
    123 
    124   // init static singleton reference of Orxonox
    125   Orxonox* Orxonox::singletonRef_ = NULL;
     78  /**
     79    @brief Reference to the only instance of the class.
     80  */
     81  Orxonox *Orxonox::singletonRef_s = 0;
    12682
    12783  /**
     
    13187  {
    13288    this->ogre_ = new GraphicsEngine();
     89    this->timer_ = 0;
    13390    this->dataPath_ = "";
    134 //    this->loader_ = 0;
    13591    this->auMan_ = 0;
    136     this->singletonRef_ = 0;
    137     this->keyboard_ = 0;
    138     this->mouse_ = 0;
    139     this->inputManager_ = 0;
    140     this->frameListener_ = 0;
    141     this->root_ = 0;
     92    this->inputHandler_ = 0;
     93    //this->root_ = 0;
     94    // turn on frame smoothing by setting a value different from 0
     95    this->frameSmoothingTime_ = 0.0f;
     96    this->bAbort_ = false;
    14297  }
    14398
     
    147102  Orxonox::~Orxonox()
    148103  {
    149     // nothing to delete as for now
     104    // keep in mind: the order of deletion is very important!
     105    if (this->bulletMgr_)
     106      delete this->bulletMgr_;
     107    if (this->orxonoxHUD_)
     108      delete this->orxonoxHUD_;
     109    Loader::close();
     110    InputHandler::destroy();
     111    if (this->auMan_)
     112      delete this->auMan_;
     113    if (this->timer_)
     114      delete this->timer_;
     115    if (this->ogre_)
     116      delete this->ogre_;
     117
     118    if (client_g)
     119      delete client_g;
     120    if (server_g)
     121      delete server_g;
     122  }
     123
     124  /**
     125   * error kills orxonox
     126   */
     127  void Orxonox::abortImmediate(/* some error code */)
     128  {
     129    //TODO: destroy and destruct everything and print nice error msg
     130    delete this;
     131  }
     132
     133  /**
     134    Asks the mainloop nicely to abort.
     135  */
     136  void Orxonox::abortRequest()
     137  {
     138    bAbort_ = true;
     139  }
     140
     141  /**
     142   * @return singleton object
     143   */
     144  Orxonox* Orxonox::getSingleton()
     145  {
     146    if (!singletonRef_s)
     147      singletonRef_s = new Orxonox();
     148    return singletonRef_s;
     149    //static Orxonox theOnlyInstance;
     150    //return &theOnlyInstance;
     151  }
     152
     153  /**
     154    @brief Destroys the Orxonox singleton.
     155  */
     156  void Orxonox::destroy()
     157  {
     158    if (singletonRef_s)
     159      delete singletonRef_s;
     160    singletonRef_s = 0;
    150161  }
    151162
     
    153164   * initialization of Orxonox object
    154165   * @param argc argument counter
    155    * @param argv list of arguments
     166   * @param argv list of argumenst
    156167   * @param path path to config (in home dir or something)
    157168   */
     
    162173    //TODO: give config file to Ogre
    163174    std::string mode;
    164 //     if(argc>=2)
    165 //       mode = std::string(argv[1]);
    166 //     else
    167 //       mode = "";
     175
    168176    ArgReader ar = ArgReader(argc, argv);
    169177    ar.checkArgument("mode", mode, false);
    170178    ar.checkArgument("data", this->dataPath_, false);
    171179    ar.checkArgument("ip", serverIp_, false);
    172     //mode = "presentation";
    173     if(ar.errorHandling()) die();
    174     if(mode == std::string("server"))
     180    if(ar.errorHandling()) abortImmediate();
     181    if(mode == std::string("client"))
    175182    {
     183      mode_ = CLIENT;
     184      clientInit(path);
     185    }
     186    else if(mode== std::string("server")){
     187      mode_ = SERVER;
    176188      serverInit(path);
    177       mode_ = SERVER;
    178     }
    179     else if(mode == std::string("client"))
    180     {
    181       clientInit(path);
    182       mode_ = CLIENT;
    183     }
    184     else if(mode == std::string("presentation"))
    185     {
    186       serverInit(path);
    187       mode_ = PRESENTATION;
    188189    }
    189190    else{
     191      mode_ = STANDALONE;
    190192      standaloneInit(path);
    191       mode_ = STANDALONE;
    192193    }
    193194  }
    194195
    195   /**
    196    * start modules
    197    */
    198   void Orxonox::start()
    199   {
    200     //TODO: start modules
    201     ogre_->startRender();
    202     //TODO: run engine
    203     Factory::createClassHierarchy();
    204     createScene();
    205     setupScene();
    206     setupInputSystem();
    207     if(mode_!=CLIENT){ // remove this in future ---- presentation hack
    208     }
    209     else
    210       std::cout << "client here" << std::endl;
    211     createFrameListener();
    212     switch(mode_){
    213     case PRESENTATION:
    214       //ogre_->getRoot()->addFrameListener(new network::ServerFrameListener());
    215       //std::cout << "could not add framelistener" << std::endl;
    216       server_g->open();
    217       break;
    218     case CLIENT:
    219       client_g->establishConnection();
    220       break;
    221     case SERVER:
    222     case STANDALONE:
    223     default:
    224       break;
    225     }
    226     startRenderLoop();
    227   }
    228 
    229   /**
    230    * @return singleton object
    231    */
    232   Orxonox* Orxonox::getSingleton()
    233   {
    234     if (!singletonRef_)
    235       singletonRef_ = new Orxonox();
    236     return singletonRef_;
    237   }
    238 
    239   /**
    240    * error kills orxonox
    241    */
    242   void Orxonox::die(/* some error code */)
    243   {
    244     //TODO: destroy and destruct everything and print nice error msg
    245     delete this;
    246   }
    247 
    248   void Orxonox::standaloneInit(std::string path)
    249   {
     196  void Orxonox::serverInit(std::string path)
     197  {
     198    COUT(2) << "initialising server" << std::endl;
     199   
    250200    ogre_->setConfigPath(path);
    251201    ogre_->setup();
    252     root_ = ogre_->getRoot();
    253     if(!ogre_->load()) die(/* unable to load */);
    254 
    255     //defineResources();
    256     //setupRenderSystem();
    257     //createRenderWindow();
    258     //initializeResourceGroups();
    259     /*createScene();
    260     setupScene();
    261     setupInputSystem();
    262     createFrameListener();
    263     Factory::createClassHierarchy();
    264     startRenderLoop();*/
    265   }
    266 
    267   void Orxonox::playableServer(std::string path)
    268   {
    269     ogre_->setConfigPath(path);
    270     ogre_->setup();
    271     root_ = ogre_->getRoot();
    272     defineResources();
    273     setupRenderSystem();
    274     createRenderWindow();
    275     initializeResourceGroups();
    276     setupInputSystem();
    277     Factory::createClassHierarchy();
    278     createScene();
    279     setupScene();
    280     createFrameListener();
    281     try{
    282       server_g = new network::Server(); //!< add port and bindadress
    283       server_g->open(); //!< open server and create listener thread
    284       if(ogre_ && ogre_->getRoot())
    285         ogre_->getRoot()->addFrameListener(new network::ServerFrameListener()); // adds a framelistener for the server
    286       COUT(3) << "Info: network framelistener added" << std::endl;
    287     }
    288     catch(...)
    289     {
    290       COUT(1) << "Error: There was a problem initialising the server :(" << std::endl;
    291     }
    292     startRenderLoop();
    293   }
    294 
    295   void Orxonox::standalone(){
    296 
    297 
    298 
    299   }
    300 
    301   void Orxonox::serverInit(std::string path)
    302   {
    303     COUT(2) << "initialising server" << std::endl;
    304     ogre_->setConfigPath(path);
    305     ogre_->setup();
    306     server_g = new network::Server(); // FIXME add some settings if wanted
    307     if(!ogre_->load()) die(/* unable to load */);
    308     // FIXME add network framelistener
     202    //root_ = ogre_->getRoot();
     203    if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */);
     204   
     205    server_g = new network::Server();
    309206  }
    310207
    311208  void Orxonox::clientInit(std::string path)
    312209  {
    313     COUT(2) << "initialising client" << std::endl;
     210    COUT(2) << "initialising client" << std::endl;\
     211   
    314212    ogre_->setConfigPath(path);
    315213    ogre_->setup();
     
    317215      client_g = new network::Client();
    318216    else
    319       client_g = new network::Client(serverIp_, 55556);
    320     if(!ogre_->load()) die(/* unable to load */);
    321     ogre_->getRoot()->addFrameListener(new network::ClientFrameListener());
    322   }
    323 
    324   void Orxonox::defineResources()
    325   {
    326     std::string secName, typeName, archName;
    327     Ogre::ConfigFile cf;
    328 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
    329     cf.load(macBundlePath() + "/Contents/Resources/resources.cfg");
    330 #else
    331     cf.load(dataPath_ + "resources.cfg");
    332 #endif
    333 
    334     Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
    335     while (seci.hasMoreElements())
    336     {
    337       secName = seci.peekNextKey();
    338       Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
    339       Ogre::ConfigFile::SettingsMultiMap::iterator i;
    340       for (i = settings->begin(); i != settings->end(); ++i)
    341       {
    342         typeName = i->first;
    343         archName = i->second;
    344 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
    345         Ogre::ResourceGroupManager::getSingleton().addResourceLocation( std::string(macBundlePath() + "/" + archName), typeName, secName);
    346 #else
    347         Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName);
    348 #endif
    349       }
     217      client_g = new network::Client(serverIp_, NETWORK_PORT);
     218    if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */);
     219  }
     220 
     221  void Orxonox::standaloneInit(std::string path)
     222  {
     223    COUT(2) << "initialising standalone mode" << std::endl;
     224   
     225    ogre_->setConfigPath(path);
     226    ogre_->setup();
     227    //root_ = ogre_->getRoot();
     228    if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */);
     229  }
     230 
     231  /**
     232   * start modules
     233   */
     234  void Orxonox::start()
     235  {
     236    switch(mode_){
     237    case CLIENT:
     238      clientStart();
     239      break;
     240    case SERVER:
     241      serverStart();
     242      break;
     243    default:
     244      standaloneStart();
    350245    }
    351246  }
    352 
    353   void Orxonox::setupRenderSystem()
    354   {
    355     if (!root_->restoreConfig() && !root_->showConfigDialog())
    356       throw Ogre::Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()");
    357   }
    358 
    359   void Orxonox::createRenderWindow()
    360   {
    361     root_->initialise(true, "OrxonoxV2");
    362   }
    363 
    364   void Orxonox::initializeResourceGroups()
    365   {
    366     Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
    367     Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    368   }
    369 
    370   /**
    371    *
    372    * @param
    373    */
    374   void Orxonox::createScene(void)
    375   {
    376         // Init audio
     247 
     248  void Orxonox::clientStart(){
     249    ogre_->initialise();
     250    Factory::createClassHierarchy();
     251   
     252   
    377253    auMan_ = new audio::AudioManager();
    378254
    379255    bulletMgr_ = new BulletManager();
    380 
    381     // load this file from config
    382 //    loader_ = new loader::LevelLoader("sample.oxw");
    383 //    loader_->loadLevel();
    384     Level* startlevel = new Level("levels/sample.oxw");
    385     Loader::open(startlevel);
    386 
     256   
    387257    Ogre::Overlay* hudOverlay = Ogre::OverlayManager::getSingleton().getByName("Orxonox/HUD1.2");
    388258    HUD* orxonoxHud;
     
    391261    orxonoxHud->setEnergyDistr(20,20,60);
    392262    hudOverlay->show();
     263   
     264    client_g->establishConnection();
     265    client_g->tick(0);
     266   
     267   
     268    //setupInputSystem();
     269   
     270    startRenderLoop();
     271  }
     272 
     273  void Orxonox::serverStart(){
     274    //TODO: start modules
     275    ogre_->initialise();
     276    //TODO: run engine
     277    Factory::createClassHierarchy();
     278    createScene();
     279    setupInputSystem();
     280   
     281    server_g->open();
     282   
     283    startRenderLoop();
     284  }
     285 
     286  void Orxonox::standaloneStart(){
     287    //TODO: start modules
     288    ogre_->initialise();
     289    //TODO: run engine
     290    Factory::createClassHierarchy();
     291    createScene();
     292    setupInputSystem();
     293   
     294    startRenderLoop();
     295  }
     296
     297  void Orxonox::createScene(void)
     298  {
     299          // Init audio
     300    auMan_ = new audio::AudioManager();
     301
     302    bulletMgr_ = new BulletManager();
     303
     304    // load this file from config
     305    Level* startlevel = new Level("levels/sample.oxw");
     306    Loader::open(startlevel);
     307
     308    Ogre::Overlay* hudOverlay = Ogre::OverlayManager::getSingleton().getByName("Orxonox/HUD1.2");
     309    orxonoxHUD_ = new HUD();
     310    orxonoxHUD_->setEnergyValue(20);
     311    orxonoxHUD_->setEnergyDistr(20,20,60);
     312    hudOverlay->show();
    393313
    394314        /*
     
    396316    auMan_->ambientAdd("a2");
    397317    auMan_->ambientAdd("a3");
    398                                 //auMan->ambientAdd("ambient1");
    399     auMan_->ambientStart();*/
    400   }
    401 
    402 
    403   /**
    404    *
    405    */
    406   void Orxonox::setupScene()
    407   {
    408 //    SceneManager *mgr = ogre_->getSceneManager();
    409 
    410 
    411 //    SceneNode* node = (SceneNode*)mgr->getRootSceneNode()->getChild("OgreHeadNode");
    412 //     SceneNode *node = mgr->getRootSceneNode()->createChildSceneNode("OgreHeadNode", Vector3(0,0,0));
    413 
    414 
    415 /*
    416     particle::ParticleInterface *e = new particle::ParticleInterface(mgr,"engine","Orxonox/strahl");
    417     e->particleSystem_->setParameter("local_space","true");
    418     e->setPositionOfEmitter(0, Vector3(0,-10,0));
    419     e->setDirection(Vector3(0,0,-1));
    420     e->addToSceneNode(node);
    421 */
    422   }
    423 
    424 
     318    //auMan->ambientAdd("ambient1");
     319    auMan_->ambientStart();
     320  */
     321  }
     322
     323  /**
     324    @brief Calls the InputHandler which sets up the input devices.
     325    The render window width and height are used to set up the mouse movement.
     326  */
    425327  void Orxonox::setupInputSystem()
    426328  {
    427     size_t windowHnd = 0;
    428     std::ostringstream windowHndStr;
    429     OIS::ParamList pl;
    430 
    431     // fixes auto repeat problem
    432     #if defined OIS_LINUX_PLATFORM
    433       pl.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
    434     #endif
    435 
    436       Ogre::RenderWindow *win = ogre_->getRoot()->getAutoCreatedWindow();
    437     win->getCustomAttribute("WINDOW", &windowHnd);
    438     windowHndStr << windowHnd;
    439     pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
    440     inputManager_ = OIS::InputManager::createInputSystem(pl);
    441 
    442     try
     329    inputHandler_ = InputHandler::getSingleton();
     330    if (!inputHandler_->initialise(ogre_->getWindowHandle(),
     331          ogre_->getWindowWidth(), ogre_->getWindowHeight()))
     332      abortImmediate();
     333  }
     334
     335  /**
     336    Main loop of the orxonox game.
     337    This is a new solution, using the ogre engine instead of being used by it.
     338    An alternative solution would be to simply use the timer of the Root object,
     339    but that implies using Ogre in any case. There would be no way to test
     340    our code without the help of the root object.
     341    There's even a chance that we can dispose of the root object entirely
     342    in server mode.
     343    About the loop: The design is almost exactly like the one in ogre, so that
     344    if any part of ogre registers a framelisteners, it will still behave
     345    correctly. Furthermore I have taken over the time smoothing feature from
     346    ogre. If turned on (see orxonox constructor), it will calculate the dt_n by
     347    means of the recent most dt_n-1, dt_n-2, etc.
     348  */
     349  void Orxonox::startRenderLoop()
     350  {
     351    // use the ogre timer class to measure time.
     352    if (!timer_)
     353      timer_ = new Ogre::Timer();
     354    timer_->reset();
     355
     356    // Contains the times of recently fired events
     357    std::deque<unsigned long> eventTimes[3];
     358    // Clear event times
     359    for (int i = 0; i < 3; ++i)
     360      eventTimes[i].clear();
     361
     362          while (!bAbort_)
     363          {
     364                  // Pump messages in all registered RenderWindows
     365      Ogre::WindowEventUtilities::messagePump();
     366
     367      // get current time
     368      unsigned long now = timer_->getMilliseconds();
     369
     370      // create an event to pass to the frameStarted method in ogre
     371      Ogre::FrameEvent evt;
     372      evt.timeSinceLastEvent = calculateEventTime(now, eventTimes[0]);
     373      evt.timeSinceLastFrame = calculateEventTime(now, eventTimes[1]);
     374
     375      // show the current time in the HUD
     376      orxonoxHUD_->setTime((int)now, 0);
     377
     378      // Iterate through all Tickables and call their tick(dt) function
     379      for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; )
     380        (it++)->tick((float)evt.timeSinceLastFrame);
     381
     382      // don't forget to call _fireFrameStarted in ogre to make sure
     383      // everything goes smoothly
     384      ogre_->frameStarted(evt);
     385
     386      if (mode_ != SERVER)
     387        ogre_->renderOneFrame(); // only render in non-server mode
     388
     389      // get current time
     390      now = timer_->getMilliseconds();
     391
     392      // create an event to pass to the frameEnded method in ogre
     393      evt.timeSinceLastEvent = calculateEventTime(now, eventTimes[0]);
     394      evt.timeSinceLastFrame = calculateEventTime(now, eventTimes[2]);
     395
     396      // again, just to be sure ogre works fine
     397      ogre_->frameEnded(evt);
     398          }
     399  }
     400
     401  /**
     402    Method for calculating the average time between recently fired events.
     403    Code directly taken from OgreRoot.cc
     404    @param now The current time in ms.
     405    @param type The type of event to be considered.
     406  */
     407  float Orxonox::calculateEventTime(unsigned long now, std::deque<unsigned long> &times)
     408  {
     409    // Calculate the average time passed between events of the given type
     410    // during the last mFrameSmoothingTime seconds.
     411
     412    times.push_back(now);
     413
     414    if(times.size() == 1)
     415      return 0;
     416
     417    // Times up to mFrameSmoothingTime seconds old should be kept
     418    unsigned long discardThreshold =
     419      static_cast<unsigned long>(frameSmoothingTime_ * 1000.0f);
     420
     421    // Find the oldest time to keep
     422    std::deque<unsigned long>::iterator it = times.begin(),
     423      end = times.end()-2; // We need at least two times
     424    while(it != end)
    443425    {
    444       keyboard_ = static_cast<OIS::Keyboard*>(inputManager_->createInputObject(OIS::OISKeyboard, false));
    445       mouse_ = static_cast<OIS::Mouse*>(inputManager_->createInputObject(OIS::OISMouse, true));
     426      if (now - *it > discardThreshold)
     427        ++it;
     428      else
     429        break;
    446430    }
    447     catch (const OIS::Exception &e)
    448     {
    449       throw new Ogre::Exception(42, e.eText, "OrxApplication::setupInputSystem");
    450     }
    451   }
    452 
    453   // FIXME we actually want to do this differently...
    454   void Orxonox::createFrameListener()
    455   {
    456     TickFrameListener* TickFL = new TickFrameListener();
    457     ogre_->getRoot()->addFrameListener(TickFL);
    458 
    459     TimerFrameListener* TimerFL = new TimerFrameListener();
    460     ogre_->getRoot()->addFrameListener(TimerFL);
    461 
    462     //if(mode_!=CLIENT) // FIXME just a hack ------- remove this in future
    463       frameListener_ = new OrxListener(keyboard_, auMan_, mode_);
    464     ogre_->getRoot()->addFrameListener(frameListener_);
    465   }
    466 
    467   void Orxonox::startRenderLoop()
    468   {
    469     // FIXME
    470     // this is a hack!!!
    471     // the call to reset the mouse clipping size should probably be somewhere
    472     // else, however this works for the moment.
    473     unsigned int width, height, depth;
    474     int left, top;
    475     ogre_->getRoot()->getAutoCreatedWindow()->getMetrics(width, height, depth, left, top);
    476 
    477     if(mode_!=CLIENT){
    478       const OIS::MouseState &ms = mouse_->getMouseState();
    479       ms.width = width;
    480       ms.height = height;
    481     }
    482     ogre_->getRoot()->startRendering();
     431
     432    // Remove old times
     433    times.erase(times.begin(), it);
     434
     435    return (float)(times.back() - times.front()) / ((times.size()-1) * 1000);
     436  }
     437
     438  /**
     439    @brief Test method for the InputHandler.
     440    But: Is actually responsible for catching an exit event..
     441  */
     442  void Orxonox::eventOccured(InputEvent &evt)
     443  {
     444    if (evt.id == 1)
     445      this->abortRequest();
    483446  }
    484447}
  • code/trunk/src/orxonox/Orxonox.h

    r871 r1021  
    1111
    1212#include <OgrePrerequisites.h>
    13 #include <OIS/OISPrereqs.h>
     13//#include <OIS/OISPrereqs.h>
    1414
    1515#include "OrxonoxPrereqs.h"
    16 //#include "loader/LoaderPrereqs.h"
    1716#include "audio/AudioPrereqs.h"
    1817
    1918#include "GraphicsEngine.h"
     19#include "InputEventListener.h"
    2020
    2121
     
    2525
    2626  enum gameMode{
    27     STANDALONE,
    2827    SERVER,
    2928    CLIENT,
    30     PRESENTATION
     29    STANDALONE
    3130  };
    3231
    33   class _OrxonoxExport Orxonox
     32  class _OrxonoxExport Orxonox : public InputEventListener
    3433  {
    3534    public:
     
    3736      void start();
    3837      // not sure if this should be private
    39       void die(/* some error code */);
     38      void abortImmediate(/* some error code */);
     39      void abortRequest();
     40      inline Ogre::SceneManager*  getSceneManager()        { return ogre_->getSceneManager(); };
     41      inline GraphicsEngine*      getOgrePointer()         { return ogre_; };
     42      inline audio::AudioManager* getAudioManagerPointer() { return auMan_; };
     43      inline BulletManager*       getBulletMgr()           { return this->bulletMgr_; }
     44
    4045      static Orxonox* getSingleton();
    41       inline Ogre::SceneManager* getSceneManager()         { return ogre_->getSceneManager(); };
    42       inline GraphicsEngine* getOgrePointer()              { return ogre_; };
    43       inline audio::AudioManager* getAudioManagerPointer() { return auMan_; };
    44       inline OIS::Keyboard* getKeyboard()                  { return this->keyboard_; }
    45       inline OIS::Mouse* getMouse()                        { return this->mouse_; }
    46       inline BulletManager* getBulletMgr()                 { return this->bulletMgr_; }
     46      static void destroy();
    4747
    48     private:
     48   private:
     49      // don't mess with singletons
    4950      Orxonox();
    50       virtual ~Orxonox();
     51      Orxonox(Orxonox& instance);
     52      Orxonox& operator=(const Orxonox& instance);
     53      ~Orxonox();
     54
    5155      // init functions
    5256      void serverInit(std::string path);
    5357      void clientInit(std::string path);
    5458      void standaloneInit(std::string path);
     59
    5560      // run functions
    56       void playableServer(std::string path);
    57       void standalone();
    58       void defineResources();
    59       void setupRenderSystem();
    60       void createRenderWindow();
    61       void initializeResourceGroups();
    62       void createScene(void);
    63       void setupScene();
     61      void serverStart();
     62      void clientStart();
     63      void standaloneStart();
     64
     65      void createScene();
    6466      void setupInputSystem();
    65       void createFrameListener();
    6667      void startRenderLoop();
     68      float calculateEventTime(unsigned long, std::deque<unsigned long>&);
     69
     70      void eventOccured(InputEvent &evt);
    6771
    6872    private:
    6973      GraphicsEngine*       ogre_;          //!< our dearest graphics engine <3
    7074      std::string           dataPath_;      //!< path to data
    71 //      loader::LevelLoader*  loader_;        //!< level loader builds the scene
    7275      audio::AudioManager*  auMan_;         //!< audio manager
    7376      BulletManager*        bulletMgr_;     //!< Keeps track of the thrown bullets
    74       static Orxonox*       singletonRef_;
    75       OIS::Keyboard*        keyboard_;
    76       OIS::Mouse*           mouse_;
    77       OIS::InputManager*    inputManager_;
    78       OrxListener*          frameListener_;
    79       Ogre::Root*           root_;
     77      InputHandler*         inputHandler_;  //!< Handles input with key bindings
     78      Ogre::Root*           root_;          //!< Holy grail of Ogre
     79      Ogre::Timer*          timer_;         //!< Main loop timer
     80      // TODO: make this a config-value by creating a config class for orxonox
     81      float                 frameSmoothingTime_;
     82      // little hack to actually show something dynamic in the HUD
     83      HUD*                  orxonoxHUD_;
     84      bool                  bAbort_;        //!< aborts the render loop if true
    8085
    8186      // this is used to identify the mode (server/client/...) we're in
    8287      gameMode              mode_;
    8388      std::string           serverIp_;
     89
     90      static Orxonox *singletonRef_s;
    8491  };
    8592}
  • code/trunk/src/orxonox/OrxonoxPlatform.h

    r890 r1021  
    210210//#   pragma warning (disable : 4503)
    211211
    212 // disable: "conversion from 'double' to 'float', possible loss of data
     212// disable: conversion from 'double' to 'float', possible loss of data
     213// disable: conversion from 'ogg_int64_t' to 'long', possible loss of data
     214// This has been dealt with in base_properties of the solution since the
     215// warning primarily occurs in library header files (which are mostly
     216// included before OrxonoxPlatform.h is)
    213217//#   pragma warning (disable : 4244)
    214218
     
    221225// disable: "<type> needs to have dll-interface to be used by clients'
    222226// Happens on STL member variables which are not public therefore is ok
     227// This has been dealt with in base_properties of the solution since the
     228// warning primarily occurs in library header files (which are mostly
     229// included before OrxonoxPlatform.h is)
    223230//#   pragma warning (disable : 4251)
     231
     232// disable: 'MultiTypeString' : multiple assignment operators specified
     233// Used in MultiType and works fine so far
     234#   pragma warning (disable : 4522)
    224235
    225236// disable: "non dll-interface class used as base for dll-interface class"
     
    252263
    253264
    254 // Create a logical xor operator
     265// Define the english written operators like and, or, xor
    255266#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC
    256 #  define XOR ^
    257 #elif ORXONOX_COMPILER == ORXONOX_COMPILER_GCC
    258 #  define XOR xor
    259 #else
    260 #  define XOR ^
     267#  include <iso646.h>
    261268#endif
    262269
  • code/trunk/src/orxonox/OrxonoxPrereqs.h

    r790 r1021  
    6868  class Camera;
    6969  class GraphicsEngine;
     70  struct InputEvent;
     71  class InputEventListener;
     72  class InputHandler;
    7073  class Mesh;
    7174  class Model;
  • code/trunk/src/orxonox/OrxonoxStableHeaders.h

    r890 r1021  
    4141
    4242// not including the entire Ogre.h doesn't exceed the default heap size for pch
     43#ifndef WIN32_LEAN_AND_MEAN
     44// prevent Ogre from including winsock.h that messes with winsock2.h from enet
     45#  define WIN32_LEAN_AND_MEAN
     46#endif
    4347//#include <Ogre.h>
    4448#include <OgreBillboardSet.h>
    4549#include <OgreCamera.h>
     50#include <OgreColourValue.h>
    4651#include <OgreConfigFile.h>
    4752#include <OgreEntity.h>
     
    4954#include <OgreFrameListener.h>
    5055#include <OgreLight.h>
     56#include <OgreMath.h>
     57#include <OgreMatrix3.h>
    5158#include <OgreOverlay.h>
    5259#include <OgreOverlayElement.h>
     
    5663#include <OgrePlatform.h>
    5764#include <OgrePrerequisites.h>
     65#include <OgreQuaternion.h>
     66#include <OgreResourceGroupManager.h>
    5867#include <OgreRenderWindow.h>
    5968#include <OgreRoot.h>
     
    6271#include <OgreStringConverter.h>
    6372#include <OgreTextureManager.h>
     73#include <OgreTimer.h>
     74#include <OgreVector2.h>
     75#include <OgreVector3.h>
     76#include <OgreVector3.h>
    6477#include <OgreViewport.h>
     78#include <OgreWindowEventUtilities.h>
    6579
    6680#include <OIS/OIS.h>
     
    6882/**
    6983* Some of the not so stable header files.
    70 * But it's not very useful to include them anyway..
     84* It's not very useful to include them anyway..
    7185**/
    7286
    73 //#include "audio/AudioManager.h"
    74 
    75 //#include "core/CoreIncludes.h"
     87#include "core/CoreIncludes.h"
    7688#include "core/BaseObject.h"
    77 //#include "core/ArgReader.h"
     89#include "core/Tickable.h"
    7890#include "core/Error.h"
     91#include "core/Loader.h"
     92#include "core/XMLPort.h"
    7993
    8094#include "network/Synchronisable.h"
     
    97111#include "util/tinyxml/tinyxml.h"
    98112
    99 //#include "hud/HUD.h"
    100 //#include "loader/LevelLoader.h"
    101 //#include "objects/weapon/AmmunitionDump.h"
    102 //#include "objects/weapon/BarrelGun.h"
    103 //#include "objects/weapon/Bullet.h"
    104 //#include "objects/weapon/BulletManager.h"
    105 //#include "objects/weapon/WeaponStation.h"
    106 //#include "objects/Ambient.h"
    107 //#include "objects/Camera.h"
    108 //#include "objects/Explosion.h"
    109 //#include "objects/Fighter.h"
    110113#include "objects/Model.h"
    111 //#include "objects/NPC.h"
    112 //#include "objects/Projectile.h"
    113 //#include "objects/Skybox.h"
    114 //#include "objects/SpaceShipSteeringObject.h"
    115 #include "objects/Tickable.h"
    116114#include "objects/WorldEntity.h"
    117 //#include "particle/ParticleInterface.h"
    118 //#include "tools/BillboardSet.h"
    119 //#include "tools/Light.h"
    120 //#include "tools/Mesh.h"
    121 //#include "tools/Timer.h"
    122 //#include "GraphicsEngine.h"
    123 //#include "InputManager.h"
    124 //#include "Orxonox.h"
    125 //#include "SpaceshipSteering.h"
    126115
    127116#endif
  • code/trunk/src/orxonox/PrecompiledHeaderFiles.cc

    r790 r1021  
    2727
    2828/**
    29  @file  PrecompiledHeaderFiles.cc
     29 @file
    3030 @brief This file actually generates the precompiled header file
    3131 */
  • code/trunk/src/orxonox/core/BaseObject.cc

    r871 r1021  
    2727
    2828/**
    29     @file BaseObject.cc
     29    @file
    3030    @brief Implementation of the BaseObject class.
    3131*/
  • code/trunk/src/orxonox/core/CMakeLists.txt

    r871 r1021  
    1717  Executor.cc
    1818  XMLPort.cc
     19  Tickable.cc
     20  Script.cc
    1921)
    2022
     
    2426TARGET_LINK_LIBRARIES( core
    2527  util
     28  ${Lua_LIBRARIES}
    2629)
  • code/trunk/src/orxonox/core/ClassTreeMask.cc

    r890 r1021  
    592592        {
    593593            const Identifier* subclass = it->getClass();
    594             newmask.add(subclass, this->isIncluded(subclass) || other.isIncluded(subclass), false, false);
     594            newmask.add(subclass, this->isIncluded(subclass) or other.isIncluded(subclass), false, false);
    595595        }
    596596
     
    599599        {
    600600            const Identifier* subclass = it->getClass();
    601             newmask.add(subclass, this->isIncluded(subclass) || other.isIncluded(subclass), false, false);
     601            newmask.add(subclass, this->isIncluded(subclass) or other.isIncluded(subclass), false, false);
    602602        }
    603603
     
    623623        {
    624624            const Identifier* subclass = it->getClass();
    625             newmask.add(subclass, this->isIncluded(subclass) && other.isIncluded(subclass), false, false);
     625            newmask.add(subclass, this->isIncluded(subclass) and other.isIncluded(subclass), false, false);
    626626        }
    627627
     
    630630        {
    631631            const Identifier* subclass = it->getClass();
    632             newmask.add(subclass, this->isIncluded(subclass) && other.isIncluded(subclass), false, false);
     632            newmask.add(subclass, this->isIncluded(subclass) and other.isIncluded(subclass), false, false);
    633633        }
    634634
     
    737737        {
    738738            const Identifier* subclass = it->getClass();
    739             newmask.add(subclass, this->isIncluded(subclass) XOR other.isIncluded(subclass), false, false);
     739            newmask.add(subclass, this->isIncluded(subclass) xor other.isIncluded(subclass), false, false);
    740740        }
    741741
     
    744744        {
    745745            const Identifier* subclass = it->getClass();
    746             newmask.add(subclass, this->isIncluded(subclass) XOR other.isIncluded(subclass), false, false);
     746            newmask.add(subclass, this->isIncluded(subclass) xor other.isIncluded(subclass), false, false);
    747747        }
    748748
  • code/trunk/src/orxonox/core/DebugLevel.cc

    r871 r1021  
    9595
    9696        // Return a constant value while we're creating the object
    97         return 4;
     97        return 3;
    9898    }
    9999}
  • code/trunk/src/orxonox/core/Loader.cc

    r871 r1021  
    3333#include "Debug.h"
    3434#include "CoreIncludes.h"
     35#include "Script.h"
    3536
    3637#include "util/tinyxml/ticpp.h"
     
    107108        Loader::currentMask_s = level->getMask() * mask;
    108109
     110        // let Lua work this out:
     111        //Script* lua;
     112        /*Script::loadFile(level->getFile(), true);
     113        Script::init(Script::getLuaState());
     114        Script::run();*/
     115        Script* lua = Script::getInstance();
     116        lua->loadFile(level->getFile(), true);
     117        lua->run();
     118
    109119        try
    110120        {
     
    112122            COUT(3) << "Mask: " << Loader::currentMask_s << std::endl;
    113123
    114             ticpp::Document xmlfile(level->getFile());
    115             xmlfile.LoadFile();
     124            //ticpp::Document xmlfile(level->getFile());
     125            //xmlfile.LoadFile();
     126            //ticpp::Element myelement(*Script::getFileString());
     127            ticpp::Document xmlfile;
     128            //xmlfile.ToDocument();
     129            xmlfile.Parse(lua->getLuaOutput(), true);
    116130
    117131            for ( ticpp::Iterator<ticpp::Element> child = xmlfile.FirstChildElement(false); child != child.end(); child++ )
  • code/trunk/src/orxonox/objects/Camera.cc

    r790 r1021  
    66#include <OgreSceneManager.h>
    77#include <OgreSceneNode.h>
    8 #include <OgreRoot.h>
    98#include <OgreRenderWindow.h>
    109#include <OgreViewport.h>
     
    6968
    7069        // FIXME: unused var
    71         Ogre::Viewport* vp = orxonox::Orxonox::getSingleton()->getOgrePointer()->getRoot()->getAutoCreatedWindow()->addViewport(cam);
     70        Ogre::Viewport* vp = orxonox::Orxonox::getSingleton()->getOgrePointer()->getRenderWindow()->addViewport(cam);
    7271
    7372
  • code/trunk/src/orxonox/objects/Fighter.cc

    r790 r1021  
    3737#include "util/tinyxml/tinyxml.h"
    3838#include "util/String2Number.h"
    39 #include "../core/CoreIncludes.h"
    40 #include "../Orxonox.h"
    41 #include "../particle/ParticleInterface.h"
     39#include "core/CoreIncludes.h"
     40#include "Orxonox.h"
     41#include "InputHandler.h"
     42#include "particle/ParticleInterface.h"
    4243#include "weapon/AmmunitionDump.h"
    4344#include "weapon/BarrelGun.h"
     
    207208
    208209            node->attachObject(cam);
    209             Orxonox::getSingleton()->getOgrePointer()->getRoot()->getAutoCreatedWindow()->addViewport(cam);
     210            Orxonox::getSingleton()->getOgrePointer()->getRenderWindow()->addViewport(cam);
    210211        }
    211212    }
     
    254255        if (!this->setMouseEventCallback_)
    255256        {
    256             if (Orxonox::getSingleton()->getMouse())
     257            if (InputHandler::getSingleton()->getMouse())
    257258            {
    258                 Orxonox::getSingleton()->getMouse()->setEventCallback(this);
     259                InputHandler::getSingleton()->getMouse()->setEventCallback(this);
    259260                this->setMouseEventCallback_ = true;
    260261            }
     
    263264        WorldEntity::tick(dt);
    264265
    265         OIS::Keyboard* mKeyboard = Orxonox::getSingleton()->getKeyboard();
    266         OIS::Mouse* mMouse = Orxonox::getSingleton()->getMouse();
     266        OIS::Keyboard* mKeyboard = InputHandler::getSingleton()->getKeyboard();
     267        OIS::Mouse* mMouse = InputHandler::getSingleton()->getMouse();
    267268
    268269        mKeyboard->capture();
  • code/trunk/src/orxonox/objects/Model.cc

    r871 r1021  
    4444    {
    4545        RegisterObject(Model);
     46        registerAllVariables();
    4647    }
    4748
     
    6364    /**
    6465        @brief XML loading and saving.
    65         @param xmlelement The XML-element
     66    @p
     67    aram xmlelement The XML-element
    6668        @param loading Loading (true) or saving (false)
    6769        @return The XML-element
     
    8284
    8385    bool Model::create(){
     86      WorldEntity::create();
    8487      if(meshSrc_.compare("")!=0){
    8588        this->mesh_.setMesh(meshSrc_);
     
    8790        COUT(4) << "Loader: Created model" << std::endl;
    8891      }
    89       registerAllVariables();
    9092      return true;
    9193    }
    9294
    9395    void Model::registerAllVariables(){
    94 //      registerVar(&meshSrc_, meshSrc_.length() + 1, network::STRING);
     96      WorldEntity::registerAllVariables();
     97      registerVar(&meshSrc_, meshSrc_.length() + 1, network::STRING);
    9598    }
    9699}
  • code/trunk/src/orxonox/objects/Model.h

    r871 r1021  
    2222            bool create();
    2323
     24        protected:
     25            void registerAllVariables();
     26           
    2427        private:
    2528            std::string meshSrc_;
    2629            Mesh mesh_;
    27             void registerAllVariables();
    2830    };
    2931}
  • code/trunk/src/orxonox/objects/NPC.cc

    r790 r1021  
    8585  void NPC::tick(float dt)
    8686  {
    87 
     87    update();
    8888    this->setVelocity(0.995*this->getVelocity() + this->getAcceleration()*dt);
    8989    this->translate(this->getVelocity()*dt);
  • code/trunk/src/orxonox/objects/SpaceShip.cc

    r978 r1021  
    3939#include "util/String2Number.h"
    4040#include "util/Math.h"
    41 #include "../core/CoreIncludes.h"
    42 #include "../core/Debug.h"
    43 #include "../Orxonox.h"
    44 #include "../particle/ParticleInterface.h"
     41#include "core/CoreIncludes.h"
     42#include "core/Debug.h"
     43#include "Orxonox.h"
     44#include "InputHandler.h"
     45#include "particle/ParticleInterface.h"
    4546#include "Projectile.h"
    4647#include "core/XMLPort.h"
     
    5556    {
    5657        RegisterObject(SpaceShip);
     58        this->registerAllVariables();
    5759
    5860        this->setConfigValues();
     
    124126        this->brakeLoop(loop);
    125127*/
    126         this->init();
    127 
     128//         this->create();
     129
     130       
    128131        COUT(3) << "Info: SpaceShip was loaded" << std::endl;
    129132    }
     
    135138    }
    136139
     140    bool SpaceShip::create(){
     141      if(Model::create())
     142        this->init();
     143      else
     144        return false;
     145      return true;
     146    }
     147   
     148    void SpaceShip::registerAllVariables(){
     149      Model::registerAllVariables();
     150     
     151     
     152     
     153    }
     154   
    137155    void SpaceShip::init()
    138156    {
     
    202220    {
    203221        Model::loadParams(xmlElem);
     222        this->create();
    204223/*
    205224        if (xmlElem->Attribute("forward") && xmlElem->Attribute("rotateupdown") && xmlElem->Attribute("rotaterightleft") && xmlElem->Attribute("looprightleft"))
     
    267286
    268287        this->camNode_->attachObject(cam);
    269         Orxonox::getSingleton()->getOgrePointer()->getRoot()->getAutoCreatedWindow()->addViewport(cam);
     288        Orxonox::getSingleton()->getOgrePointer()->getRenderWindow()->addViewport(cam);
    270289    }
    271290
     
    400419        if (!this->setMouseEventCallback_)
    401420        {
    402             if (Orxonox::getSingleton()->getMouse())
     421            if (InputHandler::getSingleton()->getMouse())
    403422            {
    404                 Orxonox::getSingleton()->getMouse()->setEventCallback(this);
     423                InputHandler::getSingleton()->getMouse()->setEventCallback(this);
    405424                this->setMouseEventCallback_ = true;
    406425            }
     
    427446        }
    428447
    429         OIS::Keyboard* mKeyboard = Orxonox::getSingleton()->getKeyboard();
    430         OIS::Mouse* mMouse = Orxonox::getSingleton()->getMouse();
     448        OIS::Keyboard* mKeyboard = InputHandler::getSingleton()->getKeyboard();
     449        OIS::Mouse* mMouse = InputHandler::getSingleton()->getMouse();
    431450
    432451        mKeyboard->capture();
  • code/trunk/src/orxonox/objects/SpaceShip.h

    r978 r1021  
    2121            SpaceShip();
    2222            ~SpaceShip();
     23            bool create();
     24            void registerAllVariables();
    2325            void init();
    2426            void setConfigValues();
  • code/trunk/src/orxonox/objects/WorldEntity.cc

    r871 r1021  
    4949        RegisterObject(WorldEntity);
    5050
    51         if (Orxonox::getSingleton()->getSceneManager())
    52         {
    53             std::ostringstream name;
    54             name << (WorldEntity::worldEntityCounter_s++);
    55             this->setName("WorldEntity" + name.str());
    56             this->node_ = Orxonox::getSingleton()->getSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName());
    57         }
    58         else
    59         {
    60             this->node_ = 0;
    61         }
     51        //create();
    6252
    6353        this->bStatic_ = true;
     
    6757        this->rotationRate_ = 0;
    6858        this->momentum_ = 0;
     59       
     60        if (Orxonox::getSingleton()->getSceneManager())
     61        {
     62          std::ostringstream name;
     63          name << (WorldEntity::worldEntityCounter_s++);
     64          this->setName("WorldEntity" + name.str());
     65          this->node_ = Orxonox::getSingleton()->getSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName());
     66       
     67          registerAllVariables();
     68        }
     69        else
     70        {
     71          this->node_ = 0;
     72        }
    6973    }
    7074
     
    8993
    9094        BaseObject::loadParams(xmlElem);
     95        create();
    9196/*
    9297        if (xmlElem->Attribute("position"))
     
    185190    }
    186191
    187     bool WorldEntity::create(){
    188       registerAllVariables();
    189       return true;
    190     }
    191192
    192193    void WorldEntity::registerAllVariables()
    193194    {
    194 /*      // register coordinates
     195      // register coordinates
    195196      registerVar( (void*) &(this->getPosition().x), sizeof(this->getPosition().x), network::DATA);
    196197      registerVar( (void*) &(this->getPosition().y), sizeof(this->getPosition().y), network::DATA);
     
    200201      registerVar( (void*) &(this->getOrientation().x), sizeof(this->getOrientation().x), network::DATA);
    201202      registerVar( (void*) &(this->getOrientation().y), sizeof(this->getOrientation().y), network::DATA);
    202       registerVar( (void*) &(this->getOrientation().z), sizeof(this->getOrientation().z), network::DATA);*/
     203      registerVar( (void*) &(this->getOrientation().z), sizeof(this->getOrientation().z), network::DATA);
    203204      // not needed at the moment, because we don't have prediction yet
    204       /*// register velocity_
     205      // register velocity_
    205206      registerVar( (void*) &(this->getVelocity().x), sizeof(this->getVelocity().x), network::DATA);
    206207      registerVar( (void*) &(this->getVelocity().y), sizeof(this->getVelocity().y), network::DATA);
     
    210211      registerVar( (void*) &(this->getRotationAxis().x), sizeof(this->getRotationAxis().x), network::DATA);
    211212      registerVar( (void*) &(this->getRotationAxis().y), sizeof(this->getRotationAxis().y), network::DATA);
    212       registerVar( (void*) &(this->getRotationAxis().z), sizeof(this->getRotationAxis().z), network::DATA);*/
     213      registerVar( (void*) &(this->getRotationAxis().z), sizeof(this->getRotationAxis().z), network::DATA);
    213214    }
    214215
  • code/trunk/src/orxonox/objects/WorldEntity.h

    r871 r1021  
    1212//#include "util/tinyxml/tinyxml.h"
    1313#include "core/BaseObject.h"
    14 #include "Tickable.h"
     14#include "core/Tickable.h"
    1515#include "../tools/Mesh.h"
    1616
    1717namespace orxonox
    1818{
    19     class _OrxonoxExport WorldEntity : public BaseObject, public Tickable//, public network::Synchronisable
     19    class _OrxonoxExport WorldEntity : public BaseObject, public Tickable, public network::Synchronisable
    2020    {
    2121        public:
     
    2626            virtual void loadParams(TiXmlElement* xmlElem);
    2727            virtual void XMLPort(Element& xmlelement, bool loading);
    28             bool create();
     28            inline bool create(){ return true; }
    2929
    3030            void attachWorldEntity(WorldEntity* entity);
  • code/trunk/src/orxonox/objects/weapon/AmmunitionDump.cc

    r871 r1021  
    4545  {
    4646    RegisterObject(AmmunitionDump);
     47    registerAllVariables();
    4748
    4849    for (int i = 0; i < numberOfAmmos_; i++)
     
    114115    return stock_[id];
    115116  }
     117 
     118  void AmmunitionDump::registerAllVariables(){
     119    registerVar( &numberOfAmmos_, sizeof(int), network::DATA);
     120   
     121    for (int i = 0; i < numberOfAmmos_; i++)
     122    {
     123      registerVar(&stock_[i], sizeof(int), network::DATA);
     124      registerVar(&capacity_[i], sizeof(int), network::DATA);
     125    }
     126  }
    116127}
  • code/trunk/src/orxonox/objects/weapon/AmmunitionDump.h

    r871 r1021  
    6060  protected:
    6161    inline bool create() { return true; }
     62    void registerAllVariables();
    6263
    6364    int numberOfAmmos_;
  • code/trunk/src/orxonox/objects/weapon/BulletManager.cc

    r871 r1021  
    3939  {
    4040    RegisterObject(BulletManager);
     41    registerAllVariables();
    4142    bullets_ = new Bullet*[bulletsSize_];
    4243  }
     
    103104  }
    104105
     106  void BulletManager::registerAllVariables(){
     107    registerVar(&bulletsSize_, sizeof(int), network::DATA);
     108    registerVar(&bulletsIndex_, sizeof(int), network::DATA);
     109    // TODO we got a problem here:
     110    // there is no possibility (so far) to synchronise pointers to objects
     111  }
     112 
    105113}
  • code/trunk/src/orxonox/objects/weapon/BulletManager.h

    r871 r1021  
    3939#include "util/tinyxml/tinyxml.h"
    4040#include "core/BaseObject.h"
    41 #include "../Tickable.h"
     41#include "core/Tickable.h"
    4242
    4343namespace orxonox {
     
    6060  protected:
    6161    inline bool create() { return true; }
     62    void registerAllVariables();
    6263
    6364    // Bullet array
  • code/trunk/src/orxonox/particle/ParticleInterface.cc

    r910 r1021  
    6969  {
    7070    //Abgleichen der anderen Emitter an die Variabeln
    71     for (int i=0; i < numberOfEmitters_; i++) {
     71    for (int i=1; i < numberOfEmitters_; i++) {
    7272      particleSystem_->getEmitter(i)->setColour( colour_ );
    7373      particleSystem_->getEmitter(i)->setTimeToLive( distance_ );
     
    8484  }
    8585
    86   void ParticleInterface::setRate(float r)
     86  void ParticleInterface::setRate(int r)
    8787  {
    8888    rate_ = r;
     
    127127  Vector3 ParticleInterface::getPositionOfEmitter ( int emitterNr )
    128128  {
    129     return particleSystem_->getEmitter(emitterNr)->getPosition();
     129    return particleSystem_->getEmitter(0)->getPosition();
    130130  }
    131131
  • code/trunk/src/orxonox/particle/ParticleInterface.h

    r910 r1021  
    4848    void setVelocity( Real v );
    4949
    50     inline float getRate()
     50    inline int getRate()
    5151      { return rate_; };
    52     void setRate( float r );
     52    void setRate( int r );
    5353
    5454    inline Real getDistance()
     
    7171    Real distance_;
    7272    Real velocity_;
    73     float rate_;
     73    int rate_;
    7474    ColourValue colour_;
    7575    int numberOfEmitters_;
  • code/trunk/src/orxonox/tools/Timer.cc

    r890 r1021  
    4646        this->time_ = 0;
    4747    }
     48
     49    /**
     50        @brief Updates the timer before the frames are rendered.
     51    */
     52    void TimerBase::tick(float dt)
     53    {
     54        if (this->bActive_)
     55        {
     56            // If active: Decrease the timer by the duration of the last frame
     57            this->time_ -= dt;
     58
     59            if (this->time_ <= 0)
     60            {
     61                // It's time to call the function
     62                if (this->bLoop_)
     63                    // Q: Why '+=' and not '='? A: Think about it. It's more accurate like that. Seriously.
     64                    this->time_ += this->interval_;
     65                else
     66                    this->stopTimer(); // Stop the timer if we don't want to loop
     67
     68                this->run();
     69            }
     70        }
     71    }
     72
    4873}
  • code/trunk/src/orxonox/tools/Timer.h

    r871 r1021  
    5858#define _Timer_H__
    5959
    60 #include <OgreFrameListener.h>
    6160#include "../OrxonoxPrereqs.h"
     61#include "core/Tickable.h"
    6262
    6363namespace orxonox
    6464{
    6565    //! TimerBase is the parent of the Timer class.
    66     class _OrxonoxExport TimerBase : public OrxonoxClass
     66    class _OrxonoxExport TimerBase : public Tickable
    6767    {
    68         friend class TimerFrameListener;
    69 
    7068        public:
    7169            TimerBase();
     
    8381            /** @brief Returns true if the Timer is active (= not stoped, not paused). @return True = Time is active */
    8482            inline bool isActive() const { return this->bActive_; }
     83
     84            void tick(float dt);
    8585
    8686        protected:
     
    145145    };
    146146
    147     //! The TimerFrameListener manages all Timers in the game.
    148     class TimerFrameListener : public Ogre::FrameListener
    149     {
    150         private:
    151             /** @brief Gets called before a frame gets rendered. */
    152             bool frameStarted(const Ogre::FrameEvent &evt)
    153             {
    154                 // Iterate through all Timers
    155                 for (Iterator<TimerBase> it = ObjectList<TimerBase>::start(); it; )
    156                 {
    157                     if (it->isActive())
    158                     {
    159                         // If active: Decrease the timer by the duration of the last frame
    160                         it->time_ -= evt.timeSinceLastFrame;
    161 
    162                         if (it->time_ <= 0)
    163                         {
    164                             // It's time to call the function
    165                             if (it->bLoop_)
    166                                 it->time_ += it->interval_; // Q: Why '+=' and not '='? A: Think about it. It's more accurate like that. Seriously.
    167                             else
    168                                 it->stopTimer(); // Stop the timer if we don't want to loop
    169 
    170                             (it++)->run();
    171                         }
    172                         else
    173                             ++it;
    174                     }
    175                     else
    176                         ++it;
    177                 }
    178 
    179                 return FrameListener::frameStarted(evt);
    180             }
    181     };
    182147}
    183148
Note: See TracChangeset for help on using the changeset viewer.