Changeset 934 for code/branches/network
- Timestamp:
- Mar 27, 2008, 5:15:08 PM (17 years ago)
- Location:
- code/branches/network/src/orxonox
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/orxonox/CMakeLists.txt
r922 r934 1 1 SET( ORXONOX_SRC_FILES 2 2 GraphicsEngine.cc 3 InputEventListener.cc 3 4 InputHandler.cc 4 InputEventListener.cc5 5 Main.cc 6 6 Orxonox.cc -
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 -
code/branches/network/src/orxonox/InputHandler.h
r929 r934 43 43 namespace orxonox 44 44 { 45 /** 46 @brief Captures and distributes mouse and keyboard input. 47 It resolves the key bindings to InputEvents which can be heard by 48 implementing the InputEventListener interface. 49 */ 45 50 class _OrxonoxExport InputHandler 46 51 : public Tickable, public OIS::KeyListener, public OIS::MouseListener 47 52 { 48 //friend ClassIdentifier<InputHandler>;53 //friend class ClassIdentifier<InputHandler>; 49 54 public: 50 voidinitialise(size_t windowHnd, int windowWidth, int windowHeight);51 void destroy ();55 bool initialise(size_t windowHnd, int windowWidth, int windowHeight); 56 void destroyDevices(); 52 57 void tick(float dt); 53 58 void setWindowExtents(int width, int height); 54 59 60 // Temporary solutions. Will be removed soon! 55 61 OIS::Mouse *getMouse() { return this->mouse_ ; } 56 62 OIS::Keyboard *getKeyboard() { return this->keyboard_; } 57 63 58 64 static InputHandler* getSingleton(); 65 static void destroy(); 59 66 60 67 private: … … 78 85 OIS::Mouse *mouse_; //!< OIS keyboard 79 86 80 /** 81 @bref Tells whether initialise has been called successfully 82 Also true if destroy() has been called. 83 */ 84 bool uninitialized_; 85 86 //! denotes the maximum number of different keys there are in OIS. 87 //! 256 should be ok since the highest number in the enum is 237. 87 /** denotes the maximum number of different keys there are in OIS. 88 256 should be ok since the highest number in the enum is 237. */ 88 89 static const int numberOfKeys_ = 256; 89 90 //! Array of input events for every pressed key … … 92 93 InputEvent bindingsKeyReleased_[numberOfKeys_]; 93 94 94 / /!denotes the maximum number of different buttons there are in OIS.95 //! 16 should be ok since the highest number in the enum is 7.95 /** denotes the maximum number of different buttons there are in OIS. 96 16 should be ok since the highest number in the enum is 7. */ 96 97 static const int numberOfButtons_ = 16; 97 98 //! Array of input events for every pressed key … … 100 101 InputEvent bindingsButtonReleased_[numberOfButtons_]; 101 102 103 //! Pointer to the instance of the singleton 104 static InputHandler *singletonRef_s; 102 105 }; 103 106 } -
code/branches/network/src/orxonox/Main.cc
r918 r934 27 27 28 28 /** 29 @file Main.cc30 @brief main file handling most of the machine specific code29 @file 30 @brief Entry point of the program. Platform specific code. 31 31 */ 32 32 33 33 #include "OrxonoxStableHeaders.h" 34 34 35 #include <OgrePlatform.h> 36 #include <OgreException.h> 35 #include <exception> 37 36 38 37 #include "OrxonoxPlatform.h" 39 38 #include "core/SignalHandler.h" 40 39 #include "Orxonox.h" 41 40 42 41 using namespace orxonox; 43 #if O GRE_PLATFORM == OGRE_PLATFORM_APPLE42 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE 44 43 #include <CoreFoundation/CoreFoundation.h> 45 44 … … 72 71 #endif 73 72 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; 73 int 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()); 118 81 #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, ""); 181 83 #endif 182 84 183 184 /*int main(int argc, char **argv) 185 { 186 try85 orx->start(); 86 orx->destroy(); 87 } 88 catch (std::exception &ex) 187 89 { 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"; 203 92 return 1; 204 93 } … … 207 96 } 208 97 209 */ 98 #ifdef __cplusplus 99 } 100 #endif -
code/branches/network/src/orxonox/Orxonox.cc
r930 r934 46 46 //#include <exception> 47 47 #include <deque> 48 #define _CRTDBG_MAP_ALLOC49 #include <stdlib.h>50 #include <crtdbg.h>51 48 52 49 //***** ORXONOX **** … … 80 77 { 81 78 /** 79 @brief Reference to the only instance of the class. 80 */ 81 Orxonox *Orxonox::singletonRef_s = 0; 82 83 /** 82 84 * create a new instance of Orxonox 83 85 */ … … 85 87 { 86 88 this->ogre_ = new GraphicsEngine(); 89 this->timer_ = 0; 87 90 this->dataPath_ = ""; 88 91 this->auMan_ = 0; … … 105 108 delete this->orxonoxHUD_; 106 109 Loader::close(); 107 // do not destroy the InputHandler since this is a singleton too 108 // and might have been deleted already (after return 0; in main()) 110 InputHandler::destroy(); 109 111 if (this->auMan_) 110 112 delete this->auMan_; … … 142 144 Orxonox* Orxonox::getSingleton() 143 145 { 144 static Orxonox theOnlyInstance; 145 return &theOnlyInstance; 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; 146 161 } 147 162 … … 313 328 { 314 329 inputHandler_ = InputHandler::getSingleton(); 315 inputHandler_->initialise(ogre_->getWindowHandle(), 316 ogre_->getWindowWidth(), ogre_->getWindowHeight()); 330 if (!inputHandler_->initialise(ogre_->getWindowHandle(), 331 ogre_->getWindowWidth(), ogre_->getWindowHeight())) 332 abortImmediate(); 317 333 } 318 334 -
code/branches/network/src/orxonox/Orxonox.h
r929 r934 44 44 45 45 static Orxonox* getSingleton(); 46 static void destroy(); 46 47 47 48 private: … … 86 87 gameMode mode_; 87 88 std::string serverIp_; 89 90 static Orxonox *singletonRef_s; 88 91 }; 89 92 } -
code/branches/network/src/orxonox/core/DebugLevel.cc
r871 r934 95 95 96 96 // Return a constant value while we're creating the object 97 return 4;97 return 3; 98 98 } 99 99 }
Note: See TracChangeset
for help on using the changeset viewer.