Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 919


Ignore:
Timestamp:
Mar 24, 2008, 1:12:31 PM (16 years ago)
Author:
rgrieder
Message:
  • AudioManager is now Tickable
  • NPC update moved to its tick-function
  • corrected CMakeLists
  • added a few window properties to GraphicsEngine
  • OrxListener has been completely replaced
Location:
code/branches/network
Files:
2 deleted
15 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/audio/AudioManager.cc

    r790 r919  
    8484        }
    8585
    86         void AudioManager::update()
     86        void AudioManager::tick(float dt)
    8787        {
    8888                if (bgSounds.size() > 0)
  • code/branches/network/src/audio/AudioManager.h

    r790 r919  
    33
    44#include "AudioIncludes.h"
     5
     6#include "core/Tickable.h"
    57
    68#include "AudioPrereqs.h"
     
    1214namespace audio
    1315{
    14         class _AudioExport AudioManager
     16  class _AudioExport AudioManager : public orxonox::Tickable
    1517        {
    1618        public:
     
    3739
    3840                // Update
    39                 void update();
     41                void tick(float dt);
    4042
    4143                void ambientAdd(std::string file);
  • code/branches/network/src/orxonox/CMakeLists.txt

    r871 r919  
    11SET( ORXONOX_SRC_FILES
    22  GraphicsEngine.cc
     3  InputHandler.cc
    34  Main.cc
    45  Orxonox.cc
    5   objects/Tickable.cc
    6   SpaceshipSteering.cc
     6#  SpaceshipSteering.cc
    77  hud/HUD.cc
    88  particle/ParticleInterface.cc
  • code/branches/network/src/orxonox/GraphicsEngine.cc

    r790 r919  
    3535#include <OgreConfigFile.h>
    3636#include <OgreTextureManager.h>
     37#include <OgreRenderWindow.h>
    3738
    3839#include "core/Debug.h"
     
    4950    this->configPath_ = "";
    5051    this->dataPath_ = "";
    51     scene_ = NULL;
     52    this->root_ = 0;
     53    this->scene_ = 0;
     54    this->renderWindow_ = 0;
    5255  }
    5356
     
    98101  {
    99102    root_->initialise(true, "OrxonoxV2");
     103    this->renderWindow_ = root_->getAutoCreatedWindow();
    100104    TextureManager::getSingleton().setDefaultNumMipmaps(5);
    101105    ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
     
    131135  }
    132136
     137  /**
     138    Returns the window handle of the render window.
     139    At least the InputHandler uses this to create the OIS::InputManager
     140    @return The window handle of the render window
     141  */
     142  size_t GraphicsEngine::getWindowHandle()
     143  {
     144    if (this->renderWindow_)
     145    {
     146      Ogre::RenderWindow *renderWindow = this->root_->getAutoCreatedWindow();
     147      size_t windowHnd = 0;
     148      renderWindow->getCustomAttribute("WINDOW", &windowHnd);
     149      return windowHnd;
     150    }
     151    else
     152      return 0;
     153  }
     154
     155  /**
     156    Get the width of the current render window
     157    @return The width of the current render window
     158  */
     159  int GraphicsEngine::getWindowWidth() const
     160  {
     161    if (this->renderWindow_)
     162    {
     163      return this->renderWindow_->getWidth();
     164    }
     165    else
     166      return 0;
     167  }
     168
     169  /**
     170    Get the height of the current render window
     171    @return The height of the current render window
     172  */
     173  int GraphicsEngine::getWindowHeight() const
     174  {
     175    if (this->renderWindow_)
     176    {
     177      return this->renderWindow_->getHeight();
     178    }
     179    else
     180      return 0;
     181  }
    133182
    134183}
  • code/branches/network/src/orxonox/GraphicsEngine.h

    r790 r919  
    3333      void startRender();
    3434
     35      // several window properties
     36      size_t getWindowHandle();
     37      int getWindowWidth() const;
     38      int getWindowHeight() const;
     39
    3540      virtual ~GraphicsEngine();
    3641    private:
     
    3944      std::string         dataPath_;    //!< path to data file
    4045      Ogre::SceneManager* scene_;       //!< scene manager of the game
     46      Ogre::RenderWindow* renderWindow_;//!< the current render window
    4147
    4248  };
  • code/branches/network/src/orxonox/InputHandler.cc

    r918 r919  
    2222 *      Reto Grieder
    2323 *   Co-authors:
    24  *      ...
     24 *      Some guy writing the example code from Ogre
    2525 *
    2626 */
     
    3434#include "OrxonoxStableHeaders.h"
    3535
    36 #include <OgreRenderWindow.h>
    37 
     36#include "Orxonox.h"
    3837#include "InputHandler.h"
    3938
     
    4241  //using namespace OIS;
    4342
     43  /**
     44    @brief Constructor only resets the pointer values to 0.
     45  */
    4446  InputHandler::InputHandler()
    4547  {
    46     RegisterObject(InputHandler);
    47   }
    48 
    49   void InputHandler::initialise(Ogre::RenderWindow *renderWindow)
     48    /*if (orxonox::Identifier::isCreatingHierarchy() && !this->getParents())
     49        this->createParents();
     50    this->setIdentifier(orxonox::ClassManager<InputHandler>::getIdentifier()->registerClass(this->getParents(), "InputHandler", true));
     51    if (orxonox::Identifier::isCreatingHierarchy() && this->getParents())
     52        this->getParents()->insert(this->getParents()->end(), this->getIdentifier());
     53    orxonox::ClassManager<InputHandler>::getIdentifier()->addObject(this);*/
     54
     55    //RegisterObject(InputHandler);
     56
     57    this->mouse_       = 0;
     58    this->keyboard_    = 0;
     59    this->inputSystem_ = 0;
     60
     61    //this->setConfigValues();
     62  }
     63
     64  void InputHandler::setConfigValues()
     65  {
     66    //SetConfigValue(codeFire_, 4).description("test value");
     67
     68    ConfigValueContainer *containercodeFire_ = new ConfigValueContainer("asdfblah", "codeFire_", 4);
     69    containercodeFire_->getValue(&codeFire_).description("test");
     70    //containercodeFire_->
     71  }
     72
     73  /**
     74    @brief The one instance of the InputHandler is stored in this function.
     75    @return The pointer to the only instance of the InputHandler
     76  */
     77  InputHandler* InputHandler::getSingleton()
     78  {
     79    static InputHandler theOnlyInstance;
     80    return &theOnlyInstance;
     81  }
     82
     83  /**
     84    @brief Creates the OIS::InputMananger, the keyboard and the mouse
     85    @param windowHnd The window handle of the render window
     86    @param windowWidth The width of the render window
     87    @param windowHeight The height of the render window
     88  */
     89  void InputHandler::initialise(size_t windowHnd, int windowWidth, int windowHeight)
    5090  {
    5191    if (!inputSystem_)
     
    5393      // Setup basic variables
    5494      OIS::ParamList paramList;
    55       size_t windowHnd = 0;
    5695      std::ostringstream windowHndStr;
    57 
    58       // Get window handle
    59       renderWindow->getCustomAttribute("WINDOW", &windowHnd);
    6096
    6197      // Fill parameter list
     
    67103
    68104      // If possible create a buffered keyboard
    69       // (note: if below line doesn't compile, try:  if (inputSystem_->getNumberOfDevices(OIS::OISKeyboard) > 0) {
    70105      if (inputSystem_->numKeyboards() > 0)
    71106      {
    72         //if (inputSystem_->getNumberOfDevices(OIS::OISKeyboard) > 0)
    73         //{
    74107        keyboard_ = static_cast<OIS::Keyboard*>(inputSystem_->createInputObject(OIS::OISKeyboard, true));
    75108        keyboard_->setEventCallback(this);
     
    77110
    78111      // If possible create a buffered mouse
    79       // (note: if below line doesn't compile, try:  if (inputSystem_->getNumberOfDevices(OIS::OISMouse) > 0) {
    80112      if (inputSystem_->numMice() > 0 )
    81113      {
    82         //if (inputSystem_->getNumberOfDevices(OIS::OISMouse) > 0)
    83         //{
    84114        mouse_ = static_cast<OIS::Mouse*>(inputSystem_->createInputObject(OIS::OISMouse, true));
    85115        mouse_->setEventCallback(this);
    86116
    87         // Get window size
    88         unsigned int width, height, depth;
    89         int left, top;
    90         renderWindow->getMetrics(width, height, depth, left, top);
    91 
    92117        // Set mouse region
    93         this->setWindowExtents(width, height);
     118        this->setWindowExtents(windowWidth, windowHeight);
    94119      }
    95120    }
    96121  }
    97122
     123  /**
     124    @brief Updates the InputHandler
     125    @param dt Delta time
     126  */
    98127  void InputHandler::tick(float dt)
    99128  {
     
    110139  }
    111140
     141  /**
     142    @brief Adjusts the mouse window metrics.
     143    This method has to be called every time the size of the window changes.
     144    @param width The new width of the render window
     145    @param height the new height of the render window
     146  */
    112147  void InputHandler::setWindowExtents(int width, int height)
    113148  {
     
    118153  }
    119154
     155  /**
     156    @brief Event handler for the keyPressed Event.
     157    @param e Event information
     158  */
    120159  bool InputHandler::keyPressed(const OIS::KeyEvent &e)
    121160  {
    122     return true;
    123   }
    124 
     161    if (e.key == OIS::KC_ESCAPE)
     162      Orxonox::getSingleton()->abortRequest();
     163    return true;
     164  }
     165
     166  /**
     167    @brief Event handler for the keyReleased Event.
     168    @param e Event information
     169  */
    125170  bool InputHandler::keyReleased(const OIS::KeyEvent &e)
    126171  {
     
    128173  }
    129174
     175  /**
     176    @brief Event handler for the mouseMoved Event.
     177    @param e Event information
     178  */
    130179  bool InputHandler::mouseMoved(const OIS::MouseEvent &e)
    131180  {
     
    133182  }
    134183
     184  /**
     185    @brief Event handler for the mousePressed Event.
     186    @param e Event information
     187    @param id The ID of the mouse button
     188  */
    135189  bool InputHandler::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    136190  {
     
    138192  }
    139193
     194  /**
     195    @brief Event handler for the mouseReleased Event.
     196    @param e Event information
     197    @param id The ID of the mouse button
     198  */
    140199  bool InputHandler::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    141200  {
  • code/branches/network/src/orxonox/InputHandler.h

    r918 r919  
    3939#include <OIS/OISKeyboard.h>
    4040
    41 #include <OgrePrerequisites.h>
    42 
    4341#include "OrxonoxPrereqs.h"
     42//#include "core/OrxonoxClass.h"
    4443#include "core/Tickable.h"
    4544
    4645namespace orxonox
    4746{
    48   class _OrxonoxExport InputHandler : public Tickable, public OIS::KeyListener,
    49                                       public OIS::MouseListener
     47  class _OrxonoxExport InputHandler
     48        : public Tickable,
     49          public OIS::KeyListener, public OIS::MouseListener
    5050  {
    5151  public:
    52     InputHandler();
    5352
    54     void initialise(Ogre::RenderWindow *renderWindow);
     53    void initialise(size_t windowHnd, int windowWidth, int windowHeight);
    5554    void tick(float dt);
    5655    void setWindowExtents(int width, int height);
     56
     57    OIS::Mouse    *getMouse()    { return this->mouse_   ; }
     58    OIS::Keyboard *getKeyboard() { return this->keyboard_; }
    5759
    5860    // input events
     
    6365                bool keyReleased  (const OIS::KeyEvent   &arg);
    6466
     67    static InputHandler* getSingleton();
     68
     69    void setConfigValues();
     70
    6571  private:
     72    // don't mess with a Singleton
     73    InputHandler ();
     74    InputHandler (const InputHandler&) { }
     75    ~InputHandler() { }
     76
    6677    OIS::InputManager *inputSystem_;
    6778    OIS::Keyboard     *keyboard_;
    6879    OIS::Mouse        *mouse_;
     80
     81    // Key bindings
     82    int codeFire_;
     83    OIS::KeyCode codeMoveForward_;
    6984
    7085  };
  • code/branches/network/src/orxonox/Orxonox.cc

    r918 r919  
    6767network::Server *server_g;
    6868
    69 
    7069// objects
    7170#include "tools/Timer.h"
    72 #include "tools/OrxListener.h"
    7371#include "core/ArgReader.h"
    7472#include "core/Debug.h"
     
    7977#include "objects/weapon/BulletManager.h"
    8078
     79#include "InputHandler.h"
     80
    8181#include "Orxonox.h"
    8282
     
    9595    this->auMan_ = 0;
    9696    this->singletonRef_ = 0;
    97     this->keyboard_ = 0;
    98     this->mouse_ = 0;
    99     this->inputManager_ = 0;
     97    //this->keyboard_ = 0;
     98    //this->mouse_ = 0;
     99    //this->inputManager_ = 0;
     100    this->inputHandler_ = 0;
    100101    this->frameListener_ = 0;
    101102    this->root_ = 0;
     
    187188    //setupInputSystem();
    188189   
    189     createFrameListener();
    190    
    191190    startRenderLoop();
    192191  }
     
    201200    setupInputSystem();
    202201   
    203     createFrameListener();
    204202    server_g->open();
    205203   
     
    215213    setupScene();
    216214    setupInputSystem();
    217    
    218     createFrameListener();
    219215   
    220216    startRenderLoop();
     
    380376  void Orxonox::setupInputSystem()
    381377  {
    382     size_t windowHnd = 0;
     378    inputHandler_ = InputHandler::getSingleton();
     379    inputHandler_->initialise(ogre_->getWindowHandle(),
     380          ogre_->getWindowWidth(), ogre_->getWindowHeight());
     381
     382    /*size_t windowHnd = 0;
    383383    std::ostringstream windowHndStr;
    384384    OIS::ParamList pl;
     
    403403    {
    404404      throw new Ogre::Exception(42, e.eText, "OrxApplication::setupInputSystem");
    405     }
    406   }
    407 
    408   // FIXME we actually want to do this differently...
    409   void Orxonox::createFrameListener()
    410   {
    411     frameListener_ = new OrxListener(keyboard_, auMan_, mode_);
    412   }
    413 
    414   void Orxonox::startRenderLoop()
    415   {
    416     // FIXME
    417     // this is a hack!!!
    418     // the call to reset the mouse clipping size should probably be somewhere
    419     // else, however this works for the moment.
    420     unsigned int width, height, depth;
    421     int left, top;
    422     ogre_->getRoot()->getAutoCreatedWindow()->getMetrics(width, height, depth, left, top);
    423 
    424     if(mode_!=CLIENT){
    425       const OIS::MouseState &ms = mouse_->getMouseState();
    426       ms.width = width;
    427       ms.height = height;
    428     }
    429     mainLoop();
     405    }*/
    430406  }
    431407
     
    444420    means of the recent most dt_n-1, dt_n-2, etc.
    445421  */
    446   void Orxonox::mainLoop()
     422  void Orxonox::startRenderLoop()
    447423  {
    448424    // use the ogre timer class to measure time.
  • code/branches/network/src/orxonox/Orxonox.h

    r918 r919  
    4242      inline GraphicsEngine* getOgrePointer()              { return ogre_; };
    4343      inline audio::AudioManager* getAudioManagerPointer() { return auMan_; };
    44       inline OIS::Keyboard* getKeyboard()                  { return this->keyboard_; }
    45       inline OIS::Mouse* getMouse()                        { return this->mouse_; }
     44      //inline OIS::Keyboard* getKeyboard()                  { return this->keyboard_; }
     45      //inline OIS::Mouse* getMouse()                        { return this->mouse_; }
    4646      inline BulletManager* getBulletMgr()                 { return this->bulletMgr_; }
    4747
     
    6464      void setupScene();
    6565      void setupInputSystem();
    66       void createFrameListener();
    6766      void startRenderLoop();
    68       void mainLoop();
    6967      void updateTimers(float);
    7068      float calculateEventTime(unsigned long, std::deque<unsigned long>&);
     
    7775      BulletManager*        bulletMgr_;     //!< Keeps track of the thrown bullets
    7876      static Orxonox*       singletonRef_;
    79       OIS::Keyboard*        keyboard_;
    80       OIS::Mouse*           mouse_;
    81       OIS::InputManager*    inputManager_;
     77      InputHandler*         inputHandler_;
     78      //OIS::Keyboard*        keyboard_;
     79      //OIS::Mouse*           mouse_;
     80      //OIS::InputManager*    inputManager_;
    8281      OrxListener*          frameListener_;
    8382      Ogre::Root*           root_;
  • code/branches/network/src/orxonox/OrxonoxPrereqs.h

    r790 r919  
    6868  class Camera;
    6969  class GraphicsEngine;
     70  class InputHandler;
    7071  class Mesh;
    7172  class Model;
  • code/branches/network/src/orxonox/core/CMakeLists.txt

    r871 r919  
    1717  Executor.cc
    1818  XMLPort.cc
     19  Tickable.cc
    1920)
    2021
  • code/branches/network/src/orxonox/objects/Fighter.cc

    r790 r919  
    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"
     
    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/branches/network/src/orxonox/objects/NPC.cc

    r790 r919  
    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/branches/network/src/orxonox/objects/SpaceShip.cc

    r889 r919  
    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"
     
    400401        if (!this->setMouseEventCallback_)
    401402        {
    402             if (Orxonox::getSingleton()->getMouse())
     403            if (InputHandler::getSingleton()->getMouse())
    403404            {
    404                 Orxonox::getSingleton()->getMouse()->setEventCallback(this);
     405                InputHandler::getSingleton()->getMouse()->setEventCallback(this);
    405406                this->setMouseEventCallback_ = true;
    406407            }
     
    427428        }
    428429
    429         OIS::Keyboard* mKeyboard = Orxonox::getSingleton()->getKeyboard();
    430         OIS::Mouse* mMouse = Orxonox::getSingleton()->getMouse();
     430        OIS::Keyboard* mKeyboard = InputHandler::getSingleton()->getKeyboard();
     431        OIS::Mouse* mMouse = InputHandler::getSingleton()->getMouse();
    431432
    432433        mKeyboard->capture();
  • code/branches/network/visual_studio/vc8/orxonox.vcproj

    r918 r919  
    640640                                </File>
    641641                                <File
    642                                         RelativePath="..\..\src\orxonox\tools\OrxListener.cc"
    643                                         >
    644                                 </File>
    645                                 <File
    646642                                        RelativePath="..\..\src\orxonox\tools\Timer.cc"
    647643                                        >
     
    810806                                </File>
    811807                                <File
    812                                         RelativePath="..\..\src\orxonox\tools\OrxListener.h"
    813                                         >
    814                                 </File>
    815                                 <File
    816808                                        RelativePath="..\..\src\orxonox\tools\Timer.h"
    817809                                        >
Note: See TracChangeset for help on using the changeset viewer.