Changeset 934 for code/branches/network/src/orxonox/InputHandler.cc
- Timestamp:
- Mar 27, 2008, 5:15:08 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/orxonox/InputHandler.cc
r930 r934 22 22 * Reto Grieder 23 23 * Co-authors: 24 * Some guy writing the example code from Ogre24 * ... 25 25 * 26 26 */ … … 35 35 36 36 #include "core/CoreIncludes.h" 37 #include "core/Debug.h" 37 38 #include "Orxonox.h" 38 39 #include "InputEventListener.h" … … 42 43 { 43 44 /** 45 @brief The reference to the singleton 46 */ 47 InputHandler* InputHandler::singletonRef_s = 0; 48 49 /** 44 50 @brief Constructor only resets the pointer values to 0. 45 51 */ 46 52 InputHandler::InputHandler() : 47 mouse_(0), keyboard_(0), inputSystem_(0), 48 uninitialized_(true) 53 mouse_(0), keyboard_(0), inputSystem_(0) 49 54 { 50 55 //RegisterObject(InputHandler); … … 56 61 InputHandler::~InputHandler() 57 62 { 58 this->destroy();59 63 } 60 64 … … 65 69 InputHandler *InputHandler::getSingleton() 66 70 { 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; 69 76 } 70 77 … … 76 83 @param windowHeight The height of the render window 77 84 */ 78 voidInputHandler::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_) 81 88 { 82 89 // Setup basic variables … … 92 99 #endif 93 100 94 // Create inputsystem 95 inputSystem_ = OIS::InputManager::createInputSystem(paramList); 96 97 // If possible create a buffered keyboard 98 if (inputSystem_->numKeyboards() > 0) 101 try 99 102 { 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 } 102 127 } 103 104 // If possible create a buffered mouse 105 if (inputSystem_->numMice() > 0 ) 128 catch (OIS::Exception ex) 106 129 { 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; 112 134 } 113 114 uninitialized_ = false;115 135 } 116 136 137 COUT(ORX_DEBUG) << "*** InputHandler: Loading key bindings..." << std::endl; 138 // temporary solution: create event list 139 //InputEvent[] list = this->createEventList(); 117 140 // load the key bindings 118 141 InputEvent empty = {0, false, 0, 0, 0}; … … 122 145 //assign 'abort' to the escape key 123 146 this->bindingsKeyPressed_[(int)OIS::KC_ESCAPE].id = 1; 147 COUT(ORX_DEBUG) << "*** InputHandler: Loading done." << std::endl; 148 149 return true; 124 150 } 125 151 … … 127 153 @brief Destroys all the created input devices. 128 154 */ 129 void InputHandler::destroy() 130 { 155 void InputHandler::destroyDevices() 156 { 157 COUT(ORX_DEBUG) << "*** InputHandler: Destroying InputHandler..." << std::endl; 131 158 if (this->mouse_) 132 159 this->inputSystem_->destroyInputObject(mouse_); … … 139 166 this->keyboard_ = 0; 140 167 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; 142 179 } 143 180
Note: See TracChangeset
for help on using the changeset viewer.