Changeset 3291
- Timestamp:
- Jul 14, 2009, 11:50:47 AM (15 years ago)
- Location:
- code/branches/core4/src
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core4/src/core/CorePrereqs.h
r3274 r3291 153 153 class TclThreadManager; 154 154 class Template; 155 class Tickable;155 class WindowEventListener; 156 156 class XMLFile; 157 157 class XMLNameListener; -
code/branches/core4/src/core/WindowEventListener.cc
r3290 r3291 32 32 namespace orxonox 33 33 { 34 unsigned int WindowEventListener::windowWidth_s = 0; 35 unsigned int WindowEventListener::windowHeight_s = 0; 36 34 37 WindowEventListener::WindowEventListener() 35 38 { 36 39 RegisterRootObject(WindowEventListener); 37 40 } 41 42 //! Calls all registered objects 43 /*static*/ void WindowEventListener::moveWindow() 44 { 45 for (ObjectList<WindowEventListener>::iterator it = ObjectList<WindowEventListener>::begin(); it; ++it) 46 it->windowMoved(); 47 } 48 49 //! Calls all registered objects and sets the static variables 50 /*static*/ void WindowEventListener::resizeWindow(unsigned int newWidth, unsigned int newHeight) 51 { 52 windowWidth_s = newWidth; 53 windowHeight_s = newHeight; 54 for (ObjectList<WindowEventListener>::iterator it = ObjectList<WindowEventListener>::begin(); it; ++it) 55 it->windowResized(newWidth, newHeight); 56 } 57 58 //! Calls all registered objects 59 /*static*/ void WindowEventListener::changeWindowFocus() 60 { 61 for (ObjectList<WindowEventListener>::iterator it = ObjectList<WindowEventListener>::begin(); it; ++it) 62 it->windowFocusChanged(); 63 } 38 64 } -
code/branches/core4/src/core/WindowEventListener.h
r3290 r3291 38 38 class _CoreExport WindowEventListener : virtual public OrxonoxClass 39 39 { 40 public: 40 friend class OgreWindowEventListener; 41 42 protected: 41 43 WindowEventListener(); 42 44 virtual ~WindowEventListener() { } 43 45 46 //! Returns the current render window width 47 unsigned int getWindowWidth() const { return windowWidth_s; } 48 //! Returns the current render window height 49 unsigned int getWindowHeight() const { return windowHeight_s; } 50 51 private: 44 52 //! Window has been moved 45 53 virtual void windowMoved() { } … … 50 58 //! Window has lost/gained focus 51 59 virtual void windowFocusChanged() { } 60 61 static void moveWindow(); 62 static void resizeWindow(unsigned int newWidth, unsigned int newHeight); 63 static void changeWindowFocus(); 64 65 //! Static variable that holds the latest distributed information 66 static unsigned int windowWidth_s; 67 static unsigned int windowHeight_s; 52 68 }; 53 69 } -
code/branches/core4/src/core/input/InputManager.cc
r3288 r3291 82 82 // ########## ########## 83 83 // ############################################################ 84 InputManager::InputManager(size_t windowHnd , unsigned int windowWidth, unsigned int windowHeight)84 InputManager::InputManager(size_t windowHnd) 85 85 : internalState_(Bad) 86 86 , oisInputManager_(0) … … 100 100 this->setConfigValues(); 101 101 102 this->loadDevices(windowHnd , windowWidth, windowHeight);102 this->loadDevices(windowHnd); 103 103 104 104 // Lowest priority empty InputState … … 157 157 The height of the render window 158 158 */ 159 void InputManager::loadDevices(size_t windowHnd , unsigned int windowWidth, unsigned int windowHeight)159 void InputManager::loadDevices(size_t windowHnd) 160 160 { 161 161 CCOUT(3) << "Loading input devices..." << std::endl; … … 216 216 217 217 // TODO: Remove the two parameters 218 this->loadMouse( windowWidth, windowHeight);218 this->loadMouse(); 219 219 this->loadJoySticks(); 220 220 … … 226 226 227 227 //! Creates a new orxonox::Mouse 228 void InputManager::loadMouse( unsigned int windowWidth, unsigned int windowHeight)228 void InputManager::loadMouse() 229 229 { 230 230 if (oisInputManager_->getNumberOfDevices(OIS::OISMouse) > 0) … … 232 232 try 233 233 { 234 devices_[InputDeviceEnumerator::Mouse] = new Mouse(InputDeviceEnumerator::Mouse, oisInputManager_ , windowWidth, windowHeight);234 devices_[InputDeviceEnumerator::Mouse] = new Mouse(InputDeviceEnumerator::Mouse, oisInputManager_); 235 235 } 236 236 catch (const OIS::Exception& ex) … … 368 368 CCOUT(3) << "Reloading ..." << std::endl; 369 369 370 // Save mouse clipping size371 int clippingWidth = 800;372 int clippingHeight = 600;373 if (devices_[InputDeviceEnumerator::Mouse])374 {375 int clippingWidth = static_cast<Mouse*>(devices_[InputDeviceEnumerator::Mouse])->getClippingWidth();376 int clippingHeight = static_cast<Mouse*>(devices_[InputDeviceEnumerator::Mouse])->getClippingHeight();377 }378 379 370 this->destroyDevices(); 380 this->loadDevices(windowHnd_ , clippingWidth, clippingHeight);371 this->loadDevices(windowHnd_); 381 372 382 373 internalState_ &= ~Bad; … … 563 554 } 564 555 556 //! Gets called by WindowEventListener upon focus change --> clear buffers 557 void InputManager::windowFocusChanged() 558 { 559 this->clearBuffers(); 560 } 561 565 562 // ############################################################ 566 563 // ##### Iput States ##### -
code/branches/core4/src/core/input/InputManager.h
r3286 r3291 37 37 #include <vector> 38 38 39 #include "core/ OrxonoxClass.h"39 #include "core/WindowEventListener.h" 40 40 #include "InputState.h" 41 41 … … 62 62 If the OIS::InputManager or the Keyboard fail, an exception is thrown. 63 63 */ 64 class _CoreExport InputManager : public OrxonoxClass64 class _CoreExport InputManager : public WindowEventListener 65 65 { 66 66 public: … … 82 82 the constructor fails with an std::exception. 83 83 */ 84 InputManager(size_t windowHnd , unsigned int windowWidth, unsigned int windowHeight);84 InputManager(size_t windowHnd); 85 85 //! Destroys all devices AND all input states! 86 86 ~InputManager(); … … 176 176 177 177 // Intenal methods 178 void loadDevices(size_t windowHnd , unsigned int windowWidth, unsigned int windowHeight);179 void loadMouse( unsigned int windowWidth, unsigned int windowHeight);178 void loadDevices(size_t windowHnd); 179 void loadMouse(); 180 180 void loadJoySticks(); 181 181 void destroyDevices(); … … 186 186 void destroyStateInternal(InputState* state); 187 187 void updateActiveStates(); 188 189 // From WindowEventListener 190 void windowFocusChanged(); 188 191 189 192 private: // variables -
code/branches/core4/src/core/input/JoyStickQuantityListener.h
r3288 r3291 44 44 { 45 45 friend InputManager; 46 p ublic:46 protected: 47 47 JoyStickQuantityListener(); 48 48 virtual ~JoyStickQuantityListener() { } -
code/branches/core4/src/core/input/Mouse.cc
r3286 r3291 30 30 31 31 #include <ois/OISMouse.h> 32 #include "core/ConsoleCommand.h" 33 #include "core/CoreIncludes.h" 32 34 #include "InputState.h" 33 #include "core/ConsoleCommand.h"34 35 35 // HACK (include this as last, X11 seems to define some macros...)36 36 #ifdef ORXONOX_PLATFORM_LINUX 37 # include <ois/linux/LinuxMouse.h> 37 // include this as last, X11 seems to define some macros... 38 #include <ois/linux/LinuxMouse.h> 38 39 #endif 39 40 40 41 namespace orxonox 41 42 { 42 Mouse::Mouse(unsigned int id, OIS::InputManager* oisInputManager , unsigned int windowWidth, unsigned int windowHeight)43 Mouse::Mouse(unsigned int id, OIS::InputManager* oisInputManager) 43 44 : super(id, oisInputManager) 44 45 { 45 this->setMouseClipping(windowWidth, windowHeight); 46 // HACK: 47 instancePointer_s = this; 48 } 46 RegisterRootObject(Mouse); 47 this->windowResized(this->getWindowHeight(), this->getWindowHeight()); 49 48 50 void Mouse::setMouseClipping(unsigned int width, unsigned int height) 51 {52 oisDevice_->getMouseState().width = width;53 oisDevice_->getMouseState().height = height;54 }55 56 unsigned int Mouse::getClippingWidth() const57 {58 return oisDevice_->getMouseState().width;59 }60 61 unsigned int Mouse::getClippingHeight() const62 {63 return oisDevice_->getMouseState().height; 49 #ifdef ORXONOX_PLATFORM_LINUX 50 { 51 // Mouse grab console command 52 FunctorMember<Mouse>* functor = createFunctor(&Mouse::grab); 53 functor->setObject(this); 54 this->getIdentifier()->addConsoleCommand(createConsoleCommand(functor, "grab"), false); 55 } 56 { 57 // Mouse ungrab console command 58 FunctorMember<Mouse>* functor = createFunctor(&Mouse::ungrab); 59 functor->setObject(this); 60 this->getIdentifier()->addConsoleCommand(createConsoleCommand(functor, "ungrab"), false); 61 } 62 #endif 64 63 } 65 64 … … 87 86 } 88 87 89 // ############################################################ 90 // ##### ugly hacks ##### 91 // ########## ########## 92 // ############################################################ 93 94 // HACK: 95 SetConsoleCommand(Mouse, setMouseClipping_s, false); 96 #ifdef ORXONOX_PLATFORM_LINUX 97 SetConsoleCommand(Mouse, grabMouse, true); 98 SetConsoleCommand(Mouse, ungrabMouse, true); 99 #endif 100 Mouse* Mouse::instancePointer_s = NULL; 88 void Mouse::windowResized(unsigned int newWidth, unsigned int newHeight) 89 { 90 oisDevice_->getMouseState().width = newWidth; 91 oisDevice_->getMouseState().height = newHeight; 92 } 101 93 102 94 #ifdef ORXONOX_PLATFORM_LINUX -
code/branches/core4/src/core/input/Mouse.h
r3286 r3291 31 31 32 32 #include "InputPrereqs.h" 33 33 34 #include "InputDevice.h" 35 #include "core/WindowEventListener.h" 34 36 35 37 namespace orxonox … … 53 55 : public InputDeviceTemplated<MouseTraits> 54 56 , public OIS::MouseListener 57 , public WindowEventListener 55 58 { 56 59 friend class InputDeviceTemplated<MouseTraits>; … … 60 63 public: 61 64 //! Only sets the clipping size. Initialising is done in the base class. 62 Mouse(unsigned int id, OIS::InputManager* oisInputManager , unsigned int windowWidth, unsigned int windowHeight);65 Mouse(unsigned int id, OIS::InputManager* oisInputManager); 63 66 ~Mouse() { } 64 67 65 /**66 @brief67 Adjusts the mouse window metrics.68 69 This method has to be called every time the size of the window changes.70 */71 void setMouseClipping(unsigned int width, unsigned int height);72 // Returns the width of the mouse window73 unsigned int getClippingWidth() const;74 // Returns the height of the mouse window75 unsigned int getClippingHeight() const;76 77 // HACK!78 static void setMouseClipping_s(unsigned int width, unsigned int height)79 { instancePointer_s->setMouseClipping(width, height); }80 void setConfigValues() { }81 68 #ifdef ORXONOX_PLATFORM_LINUX 82 // HACK!83 69 // TODO: Make this a feature rather than a hack 84 staticvoid grabMouse();85 staticvoid ungrabMouse();70 void grabMouse(); 71 void ungrabMouse(); 86 72 #endif 87 73 … … 103 89 bool mouseMoved(const OIS::MouseEvent &arg); 104 90 91 void windowResized(unsigned int newWidth, unsigned int newHeight); 92 105 93 // Returns the class name as string 106 94 static std::string getClassNameImpl() { return "Mouse"; } 107 108 // HACK:109 static Mouse* instancePointer_s;110 95 }; 111 96 } -
code/branches/core4/src/orxonox/GraphicsManager.cc
r3290 r3291 75 75 class _OrxonoxExport OgreWindowEventListener : public Ogre::WindowEventListener 76 76 { 77 void windowResized (Ogre::RenderWindow* rw); 78 void windowFocusChange (Ogre::RenderWindow* rw); 79 void windowClosed (Ogre::RenderWindow* rw); 80 //void windowMoved (Ogre::RenderWindow* rw); 77 void windowResized (Ogre::RenderWindow* rw) 78 { orxonox::WindowEventListener::resizeWindow(rw->getWidth(), rw->getHeight()); } 79 void windowFocusChange (Ogre::RenderWindow* rw) 80 { orxonox::WindowEventListener::changeWindowFocus(); } 81 void windowClosed (Ogre::RenderWindow* rw) 82 { orxonox::Game::getInstance().stop(); } 83 void windowMoved (Ogre::RenderWindow* rw) 84 { orxonox::WindowEventListener::moveWindow(); } 81 85 }; 82 86 … … 418 422 this->renderWindow_->writeContentsToTimestampedFile(Core::getLogPathString() + "screenShot_", ".jpg"); 419 423 } 420 421 422 /****** OgreWindowEventListener ******/423 424 void OgreWindowEventListener::windowResized(Ogre::RenderWindow* rw)425 {426 for (ObjectList<orxonox::WindowEventListener>::iterator it427 = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)428 it->windowResized(rw->getWidth(), rw->getHeight());429 }430 void OgreWindowEventListener::windowFocusChange(Ogre::RenderWindow* rw)431 {432 for (ObjectList<orxonox::WindowEventListener>::iterator it433 = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)434 it->windowFocusChanged();435 }436 void OgreWindowEventListener::windowClosed(Ogre::RenderWindow* rw)437 {438 Game::getInstance().stop();439 }440 424 } -
code/branches/core4/src/orxonox/OrxonoxPrereqs.h
r3261 r3291 92 92 class Level; 93 93 class Scene; 94 class Tickable; 94 95 95 96 class AddQuest; -
code/branches/core4/src/orxonox/gamestates/GSGraphics.cc
r3279 r3291 39 39 40 40 #include "util/Convert.h" 41 #include "core/ConfigValueIncludes.h"42 41 #include "core/Clock.h" 43 42 #include "core/CommandExecutor.h" 44 43 #include "core/ConsoleCommand.h" 45 44 #include "core/Core.h" 46 #include "core/CoreIncludes.h"47 45 #include "core/Game.h" 48 46 #include "core/GameMode.h" … … 72 70 , debugOverlay_(0) 73 71 { 74 RegisterRootObject(GSGraphics);75 72 } 76 73 77 74 GSGraphics::~GSGraphics() 78 {79 }80 81 /**82 @brief83 this function does nothing84 85 Indeed. Here goes nothing.86 */87 void GSGraphics::setConfigValues()88 75 { 89 76 } … … 108 95 GameMode::setShowsGraphics(true); 109 96 110 setConfigValues();111 112 97 // Load OGRE including the render window 113 98 this->graphicsManager_ = new GraphicsManager(); … … 124 109 125 110 // Calls the InputManager which sets up the input devices. 126 inputManager_ = new InputManager(windowHnd , renderWindow->getWidth(), renderWindow->getHeight());111 inputManager_ = new InputManager(windowHnd); 127 112 128 113 // load master key bindings … … 137 122 // Load the InGameConsole 138 123 console_ = new InGameConsole(); 139 console_->initialise( renderWindow->getWidth(), renderWindow->getHeight());124 console_->initialise(); 140 125 141 126 // load the CEGUI interface … … 233 218 this->graphicsManager_->update(time); 234 219 } 235 236 /**237 @brief238 Window has resized.239 @param rw240 The render window it occured in241 @note242 GraphicsManager has a render window stored itself. This is the same243 as rw. But we have to be careful when using multiple render windows!244 */245 void GSGraphics::windowResized(unsigned int newWidth, unsigned int newHeight)246 {247 // OIS needs this under linux even if we only use relative input measurement.248 // HACK:249 CommandExecutor::execute("setWindowExtents_s " + multi_cast<std::string>(newWidth) + " " + multi_cast<std::string>(newHeight));250 }251 252 /**253 @brief254 Window focus has changed.255 @param rw256 The render window it occured in257 */258 void GSGraphics::windowFocusChanged()259 {260 // instruct InputManager to clear the buffers (core library so we cannot use the interface)261 if (this->inputManager_)262 this->inputManager_->clearBuffers();263 }264 265 220 } -
code/branches/core4/src/orxonox/gamestates/GSGraphics.h
r3290 r3291 37 37 38 38 #include "OrxonoxPrereqs.h" 39 40 39 #include "core/GameState.h" 41 #include "core/WindowEventListener.h"42 40 43 41 namespace orxonox … … 49 47 This game state is only left out if we start a dedicated server where no graphics are present. 50 48 */ 51 class _OrxonoxExport GSGraphics : public GameState , public WindowEventListener49 class _OrxonoxExport GSGraphics : public GameState 52 50 { 53 51 public: 54 52 GSGraphics(const GameStateConstrParams& params); 55 53 ~GSGraphics(); 56 void setConfigValues();57 54 58 55 void activate(); … … 63 60 64 61 private: 65 // Window events from WindowEventListener66 void windowResized(unsigned int newWidth, unsigned int newHeight);67 void windowFocusChanged();68 69 62 // managed singletons 70 63 InputManager* inputManager_; //!< Reference to input management -
code/branches/core4/src/orxonox/overlays/OrxonoxOverlay.cc
r3265 r3291 47 47 #include "core/XMLPort.h" 48 48 #include "core/ConsoleCommand.h" 49 #include "GraphicsManager.h"50 49 51 50 namespace orxonox … … 81 80 82 81 // Get aspect ratio from the render window. Later on, we get informed automatically 83 Ogre::RenderWindow* defaultWindow = GraphicsManager::getInstance().getRenderWindow(); 84 this->windowAspectRatio_ = (float)defaultWindow->getWidth() / defaultWindow->getHeight(); 82 this->windowAspectRatio_ = (float)this->getWindowWidth() / this->getWindowHeight(); 85 83 this->sizeCorrectionChanged(); 86 84 -
code/branches/core4/src/orxonox/overlays/console/InGameConsole.cc
r3279 r3291 172 172 @brief Initializes the InGameConsole. 173 173 */ 174 void InGameConsole::initialise( int windowWidth, int windowHeight)174 void InGameConsole::initialise() 175 175 { 176 176 // create the corresponding input state … … 248 248 this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_); 249 249 250 this->windowResized( windowWidth, windowHeight);250 this->windowResized(this->getWindowWidth(), this->getWindowWidth()); 251 251 252 252 // move overlay "above" the top edge of the screen -
code/branches/core4/src/orxonox/overlays/console/InGameConsole.h
r3290 r3291 46 46 ~InGameConsole(); 47 47 48 void initialise( int windowWidth, int windowHeight);48 void initialise(); 49 49 void destroy(); 50 50 void setConfigValues();
Note: See TracChangeset
for help on using the changeset viewer.