Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 27, 2008, 5:15:08 PM (16 years ago)
Author:
rgrieder
Message:
  • added debug output to the InputHandler
  • fixed singleton issues
  • cleaned up Main.cc (replaced WinMain by main)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/orxonox/InputHandler.cc

    r930 r934  
    2222 *      Reto Grieder
    2323 *   Co-authors:
    24  *      Some guy writing the example code from Ogre
     24 *      ...
    2525 *
    2626 */
     
    3535
    3636#include "core/CoreIncludes.h"
     37#include "core/Debug.h"
    3738#include "Orxonox.h"
    3839#include "InputEventListener.h"
     
    4243{
    4344  /**
     45    @brief The reference to the singleton
     46  */
     47  InputHandler* InputHandler::singletonRef_s = 0;
     48
     49  /**
    4450    @brief Constructor only resets the pointer values to 0.
    4551  */
    4652  InputHandler::InputHandler() :
    47       mouse_(0), keyboard_(0), inputSystem_(0),
    48       uninitialized_(true)
     53      mouse_(0), keyboard_(0), inputSystem_(0)
    4954  {
    5055    //RegisterObject(InputHandler);
     
    5661  InputHandler::~InputHandler()
    5762  {
    58     this->destroy();
    5963  }
    6064
     
    6569  InputHandler *InputHandler::getSingleton()
    6670  {
    67     static InputHandler theOnlyInstance;
    68     return &theOnlyInstance;
     71    if (!singletonRef_s)
     72      singletonRef_s = new InputHandler();
     73    return singletonRef_s;
     74    //static InputHandler theOnlyInstance;
     75    //return &theOnlyInstance;
    6976  }
    7077
     
    7683    @param windowHeight The height of the render window
    7784  */
    78   void InputHandler::initialise(size_t windowHnd, int windowWidth, int windowHeight)
    79   {
    80     if (this->uninitialized_ || !this->inputSystem_)
     85  bool InputHandler::initialise(size_t windowHnd, int windowWidth, int windowHeight)
     86  {
     87    if (!this->inputSystem_)
    8188    {
    8289      // Setup basic variables
     
    9299#endif
    93100
    94       // Create inputsystem
    95       inputSystem_ = OIS::InputManager::createInputSystem(paramList);
    96 
    97       // If possible create a buffered keyboard
    98       if (inputSystem_->numKeyboards() > 0)
     101      try
    99102      {
    100         keyboard_ = static_cast<OIS::Keyboard*>(inputSystem_->createInputObject(OIS::OISKeyboard, true));
    101         keyboard_->setEventCallback(this);
     103        // Create inputsystem
     104        inputSystem_ = OIS::InputManager::createInputSystem(paramList);
     105        //if (getSoftDebugLevel() >= ORX_DEBUG)
     106        //  orxonox::OutputHandler::getOutStream().setOutputLevel(4) << "asdfblah" << std::endl;
     107        COUT(ORX_DEBUG) << "*** InputHandler: Created OIS input system" << std::endl;
     108
     109        // If possible create a buffered keyboard
     110        if (inputSystem_->numKeyboards() > 0)
     111        {
     112          keyboard_ = static_cast<OIS::Keyboard*>(inputSystem_->createInputObject(OIS::OISKeyboard, true));
     113          keyboard_->setEventCallback(this);
     114          COUT(ORX_DEBUG) << "*** InputHandler: Created OIS mouse" << std::endl;
     115        }
     116
     117        // If possible create a buffered mouse
     118        if (inputSystem_->numMice() > 0 )
     119        {
     120          mouse_ = static_cast<OIS::Mouse*>(inputSystem_->createInputObject(OIS::OISMouse, true));
     121          mouse_->setEventCallback(this);
     122          COUT(ORX_DEBUG) << "*** InputHandler: Created OIS keyboard" << std::endl;
     123
     124          // Set mouse region
     125          this->setWindowExtents(windowWidth, windowHeight);
     126        }
    102127      }
    103 
    104       // If possible create a buffered mouse
    105       if (inputSystem_->numMice() > 0 )
     128      catch (OIS::Exception ex)
    106129      {
    107         mouse_ = static_cast<OIS::Mouse*>(inputSystem_->createInputObject(OIS::OISMouse, true));
    108         mouse_->setEventCallback(this);
    109 
    110         // Set mouse region
    111         this->setWindowExtents(windowWidth, windowHeight);
     130        // something went wrong with the initialisation
     131        COUT(ORX_ERROR) << "Error: Failed creating an input system. Message: \"" << ex.eText << "\"" << std::endl;
     132        this->inputSystem_ = 0;
     133        return false;
    112134      }
    113 
    114       uninitialized_ = false;
    115135    }
    116136
     137    COUT(ORX_DEBUG) << "*** InputHandler: Loading key bindings..." << std::endl;
     138    // temporary solution: create event list
     139    //InputEvent[] list = this->createEventList();
    117140    // load the key bindings
    118141    InputEvent empty = {0, false, 0, 0, 0};
     
    122145    //assign 'abort' to the escape key
    123146    this->bindingsKeyPressed_[(int)OIS::KC_ESCAPE].id = 1;
     147    COUT(ORX_DEBUG) << "*** InputHandler: Loading done." << std::endl;
     148
     149    return true;
    124150  }
    125151
     
    127153    @brief Destroys all the created input devices.
    128154  */
    129   void InputHandler::destroy()
    130   {
     155  void InputHandler::destroyDevices()
     156  {
     157    COUT(ORX_DEBUG) << "*** InputHandler: Destroying InputHandler..." << std::endl;
    131158    if (this->mouse_)
    132159      this->inputSystem_->destroyInputObject(mouse_);
     
    139166    this->keyboard_      = 0;
    140167    this->inputSystem_   = 0;
    141     this->uninitialized_ = true;
     168    COUT(ORX_DEBUG) << "*** InputHandler: Destroying done." << std::endl;
     169  }
     170
     171  /**
     172    @brief Destroys the singleton.
     173  */
     174  void InputHandler::destroy()
     175  {
     176    if (singletonRef_s)
     177      delete singletonRef_s;
     178    singletonRef_s = 0;
    142179  }
    143180
Note: See TracChangeset for help on using the changeset viewer.