From a32d30c1be541219086f39a852855dfb1559330d Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Sat, 21 Nov 2009 21:39:31 +0000 Subject: [PATCH 01/14] Fixed a memory leak in sf::Window implementation on Windows Synchronized sfml2 with trunk git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1280 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Window/Win32/WindowImplWin32.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp index d613e5568..8ae110e54 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.cpp +++ b/src/SFML/Window/Win32/WindowImplWin32.cpp @@ -150,10 +150,12 @@ myIsCursorIn (false) RegisterWindowClass(); // Compute position and size - int Left = (GetDeviceCaps(GetDC(NULL), HORZRES) - Mode.Width) / 2; - int Top = (GetDeviceCaps(GetDC(NULL), VERTRES) - Mode.Height) / 2; + HDC ScreenDC = GetDC(NULL); + int Left = (GetDeviceCaps(ScreenDC, HORZRES) - Mode.Width) / 2; + int Top = (GetDeviceCaps(ScreenDC, VERTRES) - Mode.Height) / 2; int Width = myWidth = Mode.Width; int Height = myHeight = Mode.Height; + ReleaseDC(NULL, ScreenDC); // Choose the window style according to the Style parameter DWORD Win32Style = WS_VISIBLE; From f3f630142a8ca57afe74ea4cdcb0e77814649b59 Mon Sep 17 00:00:00 2001 From: remi-k Date: Tue, 24 Nov 2009 11:25:46 +0000 Subject: [PATCH 02/14] Minor fix in sf.Window git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1284 4e206d99-4929-0410-ac5d-dfc041789085 --- python/src/Window.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/src/Window.cpp b/python/src/Window.cpp index 6e16e654c..a15c735e1 100644 --- a/python/src/Window.cpp +++ b/python/src/Window.cpp @@ -151,7 +151,9 @@ PySfWindow_init(PySfWindow *self, PyObject *args, PyObject *kwds) PySfWindowSettings *Params; if (args != NULL) - { + { + if (PyTuple_Size(args) == 0) + return 0; if (PyArg_ParseTuple(args, "l|O!:Window.__new__", &Handle, &PySfWindowSettingsType, &Params)) return 0; PyErr_Clear(); From 053042bf5a180f36c489606bd30354fddbc72d36 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Fri, 4 Dec 2009 06:35:03 +0000 Subject: [PATCH 03/14] Fixed wglChoosePixelFormatARB crashing when not supported git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1304 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Window/Win32/WindowImplWin32.cpp | 114 ++++++++++++---------- 1 file changed, 61 insertions(+), 53 deletions(-) diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp index 8ae110e54..1b92ee7be 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.cpp +++ b/src/SFML/Window/Win32/WindowImplWin32.cpp @@ -514,67 +514,75 @@ void WindowImplWin32::CreateContext(const VideoMode& Mode, WindowSettings& Param { // Get the wglChoosePixelFormatARB function (it is an extension) PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = reinterpret_cast(wglGetProcAddress("wglChoosePixelFormatARB")); - - // Define the basic attributes we want for our window - int IntAttributes[] = + if (wglChoosePixelFormatARB) { - WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, - WGL_SUPPORT_OPENGL_ARB, GL_TRUE, - WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, - WGL_DOUBLE_BUFFER_ARB, GL_TRUE, - WGL_SAMPLE_BUFFERS_ARB, (Params.AntialiasingLevel ? GL_TRUE : GL_FALSE), - WGL_SAMPLES_ARB, Params.AntialiasingLevel, - 0, 0 - }; - - // Let's check how many formats are supporting our requirements - int Formats[128]; - UINT NbFormats; - float FloatAttributes[] = {0, 0}; - bool IsValid = wglChoosePixelFormatARB(myDeviceContext, IntAttributes, FloatAttributes, sizeof(Formats) / sizeof(*Formats), Formats, &NbFormats) != 0; - if (!IsValid || (NbFormats == 0)) - { - if (Params.AntialiasingLevel > 2) + // Define the basic attributes we want for our window + int IntAttributes[] = { - // No format matching our needs : reduce the multisampling level - std::cerr << "Failed to find a pixel format supporting " - << Params.AntialiasingLevel << " antialiasing levels ; trying with 2 levels" << std::endl; - - Params.AntialiasingLevel = IntAttributes[11] = 2; - IsValid = wglChoosePixelFormatARB(myDeviceContext, IntAttributes, FloatAttributes, sizeof(Formats) / sizeof(*Formats), Formats, &NbFormats) != 0; - } + WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, + WGL_SUPPORT_OPENGL_ARB, GL_TRUE, + WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, + WGL_DOUBLE_BUFFER_ARB, GL_TRUE, + WGL_SAMPLE_BUFFERS_ARB, (Params.AntialiasingLevel ? GL_TRUE : GL_FALSE), + WGL_SAMPLES_ARB, Params.AntialiasingLevel, + 0, 0 + }; + // Let's check how many formats are supporting our requirements + int Formats[128]; + UINT NbFormats; + float FloatAttributes[] = {0, 0}; + bool IsValid = wglChoosePixelFormatARB(myDeviceContext, IntAttributes, FloatAttributes, sizeof(Formats) / sizeof(*Formats), Formats, &NbFormats) != 0; if (!IsValid || (NbFormats == 0)) { - // Cannot find any pixel format supporting multisampling ; disabling antialiasing - std::cerr << "Failed to find a pixel format supporting antialiasing ; antialiasing will be disabled" << std::endl; - Params.AntialiasingLevel = 0; - } - } - - // Get the best format among the returned ones - if (IsValid && (NbFormats > 0)) - { - int BestScore = 0xFFFF; - for (UINT i = 0; i < NbFormats; ++i) - { - // Get the current format's attributes - PIXELFORMATDESCRIPTOR Attribs; - Attribs.nSize = sizeof(PIXELFORMATDESCRIPTOR); - Attribs.nVersion = 1; - DescribePixelFormat(myDeviceContext, Formats[i], sizeof(PIXELFORMATDESCRIPTOR), &Attribs); - - // Evaluate the current configuration - int Color = Attribs.cRedBits + Attribs.cGreenBits + Attribs.cBlueBits + Attribs.cAlphaBits; - int Score = EvaluateConfig(Mode, Params, Color, Attribs.cDepthBits, Attribs.cStencilBits, Params.AntialiasingLevel); - - // Keep it if it's better than the current best - if (Score < BestScore) + if (Params.AntialiasingLevel > 2) { - BestScore = Score; - BestFormat = Formats[i]; + // No format matching our needs : reduce the multisampling level + std::cerr << "Failed to find a pixel format supporting " + << Params.AntialiasingLevel << " antialiasing levels ; trying with 2 levels" << std::endl; + + Params.AntialiasingLevel = IntAttributes[11] = 2; + IsValid = wglChoosePixelFormatARB(myDeviceContext, IntAttributes, FloatAttributes, sizeof(Formats) / sizeof(*Formats), Formats, &NbFormats) != 0; + } + + if (!IsValid || (NbFormats == 0)) + { + // Cannot find any pixel format supporting multisampling ; disabling antialiasing + std::cerr << "Failed to find a pixel format supporting antialiasing ; antialiasing will be disabled" << std::endl; + Params.AntialiasingLevel = 0; } } + + // Get the best format among the returned ones + if (IsValid && (NbFormats > 0)) + { + int BestScore = 0xFFFF; + for (UINT i = 0; i < NbFormats; ++i) + { + // Get the current format's attributes + PIXELFORMATDESCRIPTOR Attribs; + Attribs.nSize = sizeof(PIXELFORMATDESCRIPTOR); + Attribs.nVersion = 1; + DescribePixelFormat(myDeviceContext, Formats[i], sizeof(PIXELFORMATDESCRIPTOR), &Attribs); + + // Evaluate the current configuration + int Color = Attribs.cRedBits + Attribs.cGreenBits + Attribs.cBlueBits + Attribs.cAlphaBits; + int Score = EvaluateConfig(Mode, Params, Color, Attribs.cDepthBits, Attribs.cStencilBits, Params.AntialiasingLevel); + + // Keep it if it's better than the current best + if (Score < BestScore) + { + BestScore = Score; + BestFormat = Formats[i]; + } + } + } + } + else + { + // wglChoosePixelFormatARB not supported ; disabling antialiasing + std::cerr << "Antialiasing is not supported ; it will be disabled" << std::endl; + Params.AntialiasingLevel = 0; } } From 8bbf7dfc46bbc271f1beb29a642092ce798041e1 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Tue, 5 Jan 2010 16:48:32 +0000 Subject: [PATCH 04/14] FS#143 - Increase the number of supported joysticks to 4 FS#142 - Fix joystick axes being sometimes ignored git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1318 4e206d99-4929-0410-ac5d-dfc041789085 --- build/vc2008/sfml-window.vcproj | 2 +- src/SFML/Window/Linux/Joystick.cpp | 83 ++++++++++++++++++++++++------ src/SFML/Window/Linux/Joystick.hpp | 18 ++++--- src/SFML/Window/Win32/Joystick.cpp | 31 +++++++---- src/SFML/Window/Win32/Joystick.hpp | 17 +++--- src/SFML/Window/WindowImpl.cpp | 23 +++++---- src/SFML/Window/WindowImpl.hpp | 2 +- 7 files changed, 125 insertions(+), 51 deletions(-) diff --git a/build/vc2008/sfml-window.vcproj b/build/vc2008/sfml-window.vcproj index 3b9af5d5d..81225ab9b 100644 --- a/build/vc2008/sfml-window.vcproj +++ b/build/vc2008/sfml-window.vcproj @@ -412,7 +412,7 @@ > JoystickState::MaxButtons) myNbButtons = JoystickState::MaxButtons; + myAxes[Joy::AxisX] = true; + myAxes[Joy::AxisY] = true; + myAxes[Joy::AxisZ] = (Caps.wCaps & JOYCAPS_HASZ) != 0; + myAxes[Joy::AxisR] = (Caps.wCaps & JOYCAPS_HASR) != 0; + myAxes[Joy::AxisU] = (Caps.wCaps & JOYCAPS_HASU) != 0; + myAxes[Joy::AxisV] = (Caps.wCaps & JOYCAPS_HASV) != 0; + myAxes[Joy::AxisPOV] = (Caps.wCaps & JOYCAPS_HASPOV) != 0; + myHasContinuousPOV = (Caps.wCaps & JOYCAPS_POVCTS) != 0; + return; } @@ -94,8 +104,9 @@ JoystickState Joystick::UpdateState() { // Get the current joystick state JOYINFOEX Pos; - Pos.dwFlags = JOY_RETURNALL; - Pos.dwSize = sizeof(JOYINFOEX); + Pos.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNZ | JOY_RETURNR | JOY_RETURNU | JOY_RETURNV | JOY_RETURNBUTTONS; + Pos.dwFlags |= myHasContinuousPOV ? JOY_RETURNPOVCTS : JOY_RETURNPOV; + Pos.dwSize = sizeof(JOYINFOEX); if (joyGetPosEx(myIndex, &Pos) == JOYERR_NOERROR) { // Axes @@ -121,11 +132,11 @@ JoystickState Joystick::UpdateState() //////////////////////////////////////////////////////////// -/// Get the number of axes supported by the joystick +/// Check if the joystick supports the given axis //////////////////////////////////////////////////////////// -unsigned int Joystick::GetAxesCount() const +bool Joystick::HasAxis(Joy::Axis Axis) const { - return myNbAxes; + return myAxes[Axis]; } diff --git a/src/SFML/Window/Win32/Joystick.hpp b/src/SFML/Window/Win32/Joystick.hpp index d2f10174c..51666e5fb 100644 --- a/src/SFML/Window/Win32/Joystick.hpp +++ b/src/SFML/Window/Win32/Joystick.hpp @@ -58,12 +58,14 @@ public : JoystickState UpdateState(); //////////////////////////////////////////////////////////// - /// Get the number of axes supported by the joystick + /// Check if the joystick supports the given axis /// - /// \return Number of axis + /// \param Axis : Axis to check + /// + /// \return True of the axis is supported, false otherwise /// //////////////////////////////////////////////////////////// - unsigned int GetAxesCount() const; + bool HasAxis(Joy::Axis Axis) const; //////////////////////////////////////////////////////////// /// Get the number of buttons supported by the joystick @@ -78,10 +80,11 @@ private : //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - bool myIsConnected; ///< Is there a joystick connected? - unsigned int myIndex; ///< Windows ID of the joystick - unsigned int myNbAxes; ///< Number of axis supported by the joystick - unsigned int myNbButtons; ///< Number of buttons supported by the joystick + bool myIsConnected; ///< Is there a joystick connected? + unsigned int myIndex; ///< Windows ID of the joystick + unsigned int myNbButtons; ///< Number of buttons supported by the joystick + bool myAxes[Joy::Count]; ///< Supported axes + bool myHasContinuousPOV; ///< True if the driver supports continuous values for the POV }; } // namespace priv diff --git a/src/SFML/Window/WindowImpl.cpp b/src/SFML/Window/WindowImpl.cpp index bc6054364..782f8e3ed 100644 --- a/src/SFML/Window/WindowImpl.cpp +++ b/src/SFML/Window/WindowImpl.cpp @@ -221,18 +221,21 @@ void WindowImpl::ProcessJoystickEvents() myJoyStates[i] = myJoysticks[i].UpdateState(); // Axis - for (unsigned int j = 0; j < myJoysticks[i].GetAxesCount(); ++j) + for (unsigned int j = 0; j < Joy::Count; ++j) { - float PrevPos = PreviousState.Axis[j]; - float CurrPos = myJoyStates[i].Axis[j]; - if (fabs(CurrPos - PrevPos) >= myJoyThreshold) + if (myJoysticks[i].HasAxis(static_cast(i))) { - Event Event; - Event.Type = Event::JoyMoved; - Event.JoyMove.JoystickId = i; - Event.JoyMove.Axis = static_cast(j); - Event.JoyMove.Position = CurrPos; - SendEvent(Event); + float PrevPos = PreviousState.Axis[j]; + float CurrPos = myJoyStates[i].Axis[j]; + if (fabs(CurrPos - PrevPos) >= myJoyThreshold) + { + Event Event; + Event.Type = Event::JoyMoved; + Event.JoyMove.JoystickId = i; + Event.JoyMove.Axis = static_cast(j); + Event.JoyMove.Position = CurrPos; + SendEvent(Event); + } } } diff --git a/src/SFML/Window/WindowImpl.hpp b/src/SFML/Window/WindowImpl.hpp index 15d29ecff..2e0198094 100644 --- a/src/SFML/Window/WindowImpl.hpp +++ b/src/SFML/Window/WindowImpl.hpp @@ -293,7 +293,7 @@ private : //////////////////////////////////////////////////////////// // Total number of joysticks supported //////////////////////////////////////////////////////////// - enum {JoysticksCount = 2}; + enum {JoysticksCount = 4}; //////////////////////////////////////////////////////////// // Member data From 63867b654c31cbe16a0becbcaef86791d3337edc Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Tue, 5 Jan 2010 16:50:21 +0000 Subject: [PATCH 05/14] Fixed error in last commit git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1319 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Window/WindowImpl.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/SFML/Window/WindowImpl.cpp b/src/SFML/Window/WindowImpl.cpp index 782f8e3ed..7337fcabb 100644 --- a/src/SFML/Window/WindowImpl.cpp +++ b/src/SFML/Window/WindowImpl.cpp @@ -223,7 +223,8 @@ void WindowImpl::ProcessJoystickEvents() // Axis for (unsigned int j = 0; j < Joy::Count; ++j) { - if (myJoysticks[i].HasAxis(static_cast(i))) + Joy::Axis Axis = static_cast(j); + if (myJoysticks[i].HasAxis(Axis)) { float PrevPos = PreviousState.Axis[j]; float CurrPos = myJoyStates[i].Axis[j]; @@ -232,7 +233,7 @@ void WindowImpl::ProcessJoystickEvents() Event Event; Event.Type = Event::JoyMoved; Event.JoyMove.JoystickId = i; - Event.JoyMove.Axis = static_cast(j); + Event.JoyMove.Axis = Axis; Event.JoyMove.Position = CurrPos; SendEvent(Event); } From 42b97d230fc43e616c7d8739bb7ecf537525fcc4 Mon Sep 17 00:00:00 2001 From: ceylo Date: Tue, 5 Jan 2010 18:10:29 +0000 Subject: [PATCH 06/14] Replaced GetAxesCount() with HasAxis(). git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1321 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Window/Cocoa/Joystick.cpp | 7 +++---- src/SFML/Window/Cocoa/Joystick.hpp | 10 ++++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/SFML/Window/Cocoa/Joystick.cpp b/src/SFML/Window/Cocoa/Joystick.cpp index 4ade09c4d..ff2a353aa 100644 --- a/src/SFML/Window/Cocoa/Joystick.cpp +++ b/src/SFML/Window/Cocoa/Joystick.cpp @@ -55,12 +55,11 @@ JoystickState Joystick::UpdateState() //////////////////////////////////////////////////////////// -/// Get the number of axes supported by the joystick +/// Check if the joystick supports the given axis //////////////////////////////////////////////////////////// -unsigned int Joystick::GetAxesCount() const +bool Joystick::HasAxis(Joy::Axis Axis) const { - // Return number of supported axes - return 0; + return false; } diff --git a/src/SFML/Window/Cocoa/Joystick.hpp b/src/SFML/Window/Cocoa/Joystick.hpp index 425907517..60c5db243 100644 --- a/src/SFML/Window/Cocoa/Joystick.hpp +++ b/src/SFML/Window/Cocoa/Joystick.hpp @@ -58,13 +58,15 @@ public : JoystickState UpdateState(); //////////////////////////////////////////////////////////// - /// Get the number of axes supported by the joystick + /// Check if the joystick supports the given axis /// - /// \return Number of axis + /// \param Axis : Axis to check + /// + /// \return True of the axis is supported, false otherwise /// //////////////////////////////////////////////////////////// - unsigned int GetAxesCount() const; - + bool HasAxis(Joy::Axis Axis) const; + //////////////////////////////////////////////////////////// /// Get the number of buttons supported by the joystick /// From e2d0ffcdcfeb91fa04e1cfbf104198bab1cc240b Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Wed, 6 Jan 2010 08:36:55 +0000 Subject: [PATCH 07/14] Fixed the number of supported joysticks in sf::Input git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1327 4e206d99-4929-0410-ac5d-dfc041789085 --- build/vc2008/sfml-window.vcproj | 12 +++---- include/SFML/Window/Input.hpp | 27 +++++++++++---- src/SFML/Window/Input.cpp | 59 ++++++++++++++++----------------- 3 files changed, 56 insertions(+), 42 deletions(-) diff --git a/build/vc2008/sfml-window.vcproj b/build/vc2008/sfml-window.vcproj index 81225ab9b..3082eb7aa 100644 --- a/build/vc2008/sfml-window.vcproj +++ b/build/vc2008/sfml-window.vcproj @@ -420,7 +420,7 @@ > diff --git a/include/SFML/Window/Input.hpp b/include/SFML/Window/Input.hpp index fbac66a4e..3485b80a2 100644 --- a/include/SFML/Window/Input.hpp +++ b/include/SFML/Window/Input.hpp @@ -117,15 +117,30 @@ private : //////////////////////////////////////////////////////////// virtual void OnEvent(const Event& EventReceived); + //////////////////////////////////////////////////////////// + /// Reset all the states + /// + //////////////////////////////////////////////////////////// + void ResetStates(); + + //////////////////////////////////////////////////////////// + // Joystick limits + //////////////////////////////////////////////////////////// + enum + { + NbJoysticks = 4, + NbJoystickButtons = 32 + }; + //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - bool myKeys[Key::Count]; ///< Array containing the state of all keyboard keys - bool myMouseButtons[Mouse::Count]; ///< Array containing the state of all mouse buttons - bool myJoystickButtons[2][16]; ///< Array containing the state of all joysticks buttons - int myMouseX; ///< Mouse position on X - int myMouseY; ///< Mouse position on Y - float myJoystickAxis[2][Joy::Count]; ///< Joysticks position on each axis + bool myKeys[Key::Count]; ///< Array containing the state of all keyboard keys + bool myMouseButtons[Mouse::Count]; ///< Array containing the state of all mouse buttons + int myMouseX; ///< Mouse position on X + int myMouseY; ///< Mouse position on Y + bool myJoystickButtons[NbJoysticks][NbJoystickButtons]; ///< Array containing the state of all joysticks buttons + float myJoystickAxis[NbJoysticks][Joy::Count]; ///< Joysticks position on each axis }; } // namespace sf diff --git a/src/SFML/Window/Input.cpp b/src/SFML/Window/Input.cpp index 7b10270d2..06397d443 100644 --- a/src/SFML/Window/Input.cpp +++ b/src/SFML/Window/Input.cpp @@ -37,23 +37,7 @@ Input::Input() : myMouseX(0), myMouseY(0) { - for (int i = 0; i < Key::Count; ++i) - myKeys[i] = false; - - for (int i = 0; i < Mouse::Count; ++i) - myMouseButtons[i] = false; - - for (int i = 0; i < 16; ++i) - { - myJoystickButtons[0][i] = false; - myJoystickButtons[1][i] = false; - } - - for (int i = 0; i < Joy::Count; ++i) - { - myJoystickAxis[0][i] = 0.f; - myJoystickAxis[1][i] = 0.f; - } + ResetStates(); } @@ -80,7 +64,7 @@ bool Input::IsMouseButtonDown(Mouse::Button Button) const //////////////////////////////////////////////////////////// bool Input::IsJoystickButtonDown(unsigned int JoyId, unsigned int Button) const { - if ((JoyId < 2) && (Button < 16)) + if ((JoyId < NbJoysticks) && (Button < NbJoystickButtons)) return myJoystickButtons[JoyId][Button]; else return false; @@ -110,7 +94,10 @@ int Input::GetMouseY() const //////////////////////////////////////////////////////////// float Input::GetJoystickAxis(unsigned int JoyId, Joy::Axis Axis) const { - return myJoystickAxis[JoyId][Axis]; + if (JoyId < NbJoysticks) + return myJoystickAxis[JoyId][Axis]; + else + return 0.f; } @@ -147,17 +134,7 @@ void Input::OnEvent(const Event& EventReceived) // Lost focus event : we must reset all persistent states case Event::LostFocus : { - for (int i = 0; i < Key::Count; ++i) - myKeys[i] = false; - - for (int i = 0; i < Mouse::Count; ++i) - myMouseButtons[i] = false; - - for (int i = 0; i < 16; ++i) - { - myJoystickButtons[0][i] = false; - myJoystickButtons[1][i] = false; - } + ResetStates(); break; } @@ -166,4 +143,26 @@ void Input::OnEvent(const Event& EventReceived) } } + +//////////////////////////////////////////////////////////// +/// Reset all the states +//////////////////////////////////////////////////////////// +void Input::ResetStates() +{ + for (int i = 0; i < Key::Count; ++i) + myKeys[i] = false; + + for (int i = 0; i < Mouse::Count; ++i) + myMouseButtons[i] = false; + + for (int i = 0; i < NbJoysticks; ++i) + { + for (int j = 0; j < NbJoystickButtons; ++j) + myJoystickButtons[i][j] = false; + + for (int j = 0; j < Joy::Count; ++j) + myJoystickAxis[i][j] = 0.f; + } +} + } // namespace sf From db72c6e47c13db097b13501d1d3a4744b087ec4a Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Wed, 6 Jan 2010 08:48:57 +0000 Subject: [PATCH 08/14] Renamed Mouse::Count to Mouse::ButtonCount Renamed Joy::Count to Joy::AxisCount Added Joy::Count and Joy::ButtonCount git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1328 4e206d99-4929-0410-ac5d-dfc041789085 --- include/SFML/Window/Event.hpp | 10 ++++++++-- include/SFML/Window/Input.hpp | 21 ++++++--------------- src/SFML/Window/Input.cpp | 12 ++++++------ src/SFML/Window/Joystick.hpp | 6 ++---- src/SFML/Window/Linux/Joystick.cpp | 10 ++++++---- src/SFML/Window/Linux/Joystick.hpp | 12 ++++++------ src/SFML/Window/Win32/Joystick.cpp | 6 +++--- src/SFML/Window/Win32/Joystick.hpp | 10 +++++----- src/SFML/Window/WindowImpl.cpp | 6 +++--- src/SFML/Window/WindowImpl.hpp | 13 ++++--------- 10 files changed, 49 insertions(+), 57 deletions(-) diff --git a/include/SFML/Window/Event.hpp b/include/SFML/Window/Event.hpp index c436d791f..35ac57553 100644 --- a/include/SFML/Window/Event.hpp +++ b/include/SFML/Window/Event.hpp @@ -160,7 +160,7 @@ namespace Mouse XButton1, XButton2, - Count // Keep last -- total number of mouse buttons + ButtonCount // Keep last -- total number of mouse buttons }; } @@ -180,7 +180,13 @@ namespace Joy AxisV, AxisPOV, - Count // Keep last -- total number of joystick axis + AxisCount // Keep last -- total number of joystick axis + }; + + enum + { + Count = 4, ///< Total number of supported joysticks + ButtonCount = 32 ///< Total number of supported joystick buttons }; } diff --git a/include/SFML/Window/Input.hpp b/include/SFML/Window/Input.hpp index 3485b80a2..e9e9c5e4a 100644 --- a/include/SFML/Window/Input.hpp +++ b/include/SFML/Window/Input.hpp @@ -123,24 +123,15 @@ private : //////////////////////////////////////////////////////////// void ResetStates(); - //////////////////////////////////////////////////////////// - // Joystick limits - //////////////////////////////////////////////////////////// - enum - { - NbJoysticks = 4, - NbJoystickButtons = 32 - }; - //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - bool myKeys[Key::Count]; ///< Array containing the state of all keyboard keys - bool myMouseButtons[Mouse::Count]; ///< Array containing the state of all mouse buttons - int myMouseX; ///< Mouse position on X - int myMouseY; ///< Mouse position on Y - bool myJoystickButtons[NbJoysticks][NbJoystickButtons]; ///< Array containing the state of all joysticks buttons - float myJoystickAxis[NbJoysticks][Joy::Count]; ///< Joysticks position on each axis + bool myKeys[Key::Count]; ///< Array containing the state of all keyboard keys + bool myMouseButtons[Mouse::ButtonCount]; ///< Array containing the state of all mouse buttons + int myMouseX; ///< Mouse position on X + int myMouseY; ///< Mouse position on Y + bool myJoystickButtons[Joy::Count][Joy::ButtonCount]; ///< Array containing the state of all joysticks buttons + float myJoystickAxis[Joy::Count][Joy::AxisCount]; ///< Joysticks position on each axis }; } // namespace sf diff --git a/src/SFML/Window/Input.cpp b/src/SFML/Window/Input.cpp index 06397d443..33b7161e0 100644 --- a/src/SFML/Window/Input.cpp +++ b/src/SFML/Window/Input.cpp @@ -64,7 +64,7 @@ bool Input::IsMouseButtonDown(Mouse::Button Button) const //////////////////////////////////////////////////////////// bool Input::IsJoystickButtonDown(unsigned int JoyId, unsigned int Button) const { - if ((JoyId < NbJoysticks) && (Button < NbJoystickButtons)) + if ((JoyId < Joy::Count) && (Button < Joy::ButtonCount)) return myJoystickButtons[JoyId][Button]; else return false; @@ -94,7 +94,7 @@ int Input::GetMouseY() const //////////////////////////////////////////////////////////// float Input::GetJoystickAxis(unsigned int JoyId, Joy::Axis Axis) const { - if (JoyId < NbJoysticks) + if (JoyId < Joy::Count) return myJoystickAxis[JoyId][Axis]; else return 0.f; @@ -152,15 +152,15 @@ void Input::ResetStates() for (int i = 0; i < Key::Count; ++i) myKeys[i] = false; - for (int i = 0; i < Mouse::Count; ++i) + for (int i = 0; i < Mouse::ButtonCount; ++i) myMouseButtons[i] = false; - for (int i = 0; i < NbJoysticks; ++i) + for (int i = 0; i < Joy::Count; ++i) { - for (int j = 0; j < NbJoystickButtons; ++j) + for (int j = 0; j < Joy::ButtonCount; ++j) myJoystickButtons[i][j] = false; - for (int j = 0; j < Joy::Count; ++j) + for (int j = 0; j < Joy::AxisCount; ++j) myJoystickAxis[i][j] = 0.f; } } diff --git a/src/SFML/Window/Joystick.hpp b/src/SFML/Window/Joystick.hpp index 4a17f4ef1..33e684e1a 100644 --- a/src/SFML/Window/Joystick.hpp +++ b/src/SFML/Window/Joystick.hpp @@ -41,10 +41,8 @@ namespace priv //////////////////////////////////////////////////////////// struct JoystickState { - enum {MaxButtons = 32}; - - float Axis[Joy::Count]; ///< Position on each axis in range [-100, 100] (except POV which is [0, 360]) - bool Buttons[MaxButtons]; ///< Status of each button (true = pressed) + float Axis[Joy::AxisCount]; ///< Position on each axis in range [-100, 100] (except POV which is [0, 360]) + bool Buttons[Joy::ButtonCount]; ///< Status of each button (true = pressed) }; } // namespace priv diff --git a/src/SFML/Window/Linux/Joystick.cpp b/src/SFML/Window/Linux/Joystick.cpp index c525ccb88..b14a292b0 100644 --- a/src/SFML/Window/Linux/Joystick.cpp +++ b/src/SFML/Window/Linux/Joystick.cpp @@ -51,11 +51,11 @@ void Joystick::Initialize(unsigned int Index) myNbButtons = 0; myPovX = 0; myPovY = 0; - for (int i = 0; i < JoystickState::MaxButtons; ++i) + for (int i = 0; i < Joy::ButtonCount; ++i) { myState.Buttons[i] = false; } - for (int i = 0; i < Joy::Count; ++i) + for (int i = 0; i < Joy::AxisCount; ++i) { myState.Axis[i] = 0.f; myAxes[i] = false; @@ -74,6 +74,8 @@ void Joystick::Initialize(unsigned int Index) char NbButtons; ioctl(myDescriptor, JSIOCGBUTTONS, &NbButtons); myNbButtons = NbButtons; + if (myNbButtons > Joy::ButtonCount) + myNbButtons = Joy::ButtonCount; // Get the supported axes char NbAxes, Axes[ABS_MAX + 1]; @@ -120,8 +122,8 @@ JoystickState Joystick::UpdateState() case ABS_RZ: case ABS_RUDDER: myState.Axis[Joy::AxisR] = JoyState.value * 100.f / 32767.f; break; case ABS_RX : myState.Axis[Joy::AxisU] = JoyState.value * 100.f / 32767.f; break; case ABS_RY : myState.Axis[Joy::AxisV] = JoyState.value * 100.f / 32767.f; break; - case ABS_HAT0X : myPovX = JoyState.value; break; - case ABS_HAT0Y : myPovY = JoyState.value; break; + case ABS_HAT0X : myPovX = JoyState.value; break; + case ABS_HAT0Y : myPovY = JoyState.value; break; default : break; } break; diff --git a/src/SFML/Window/Linux/Joystick.hpp b/src/SFML/Window/Linux/Joystick.hpp index 48855e92d..ea780f493 100644 --- a/src/SFML/Window/Linux/Joystick.hpp +++ b/src/SFML/Window/Linux/Joystick.hpp @@ -80,12 +80,12 @@ private : //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - int myDescriptor; ///< Linux descriptor of the joystick - unsigned int myNbButtons; ///< Number of buttons supported by the joystick - bool myAxes[Joy::Count]; ///< Supported axes - JoystickState myState; ///< Current state of the joystick - int myPovX; ///< Last X position of the POV - int myPovY; ///< Last Y position of the POV + int myDescriptor; ///< Linux descriptor of the joystick + unsigned int myNbButtons; ///< Number of buttons supported by the joystick + bool myAxes[Joy::AxisCount]; ///< Supported axes + JoystickState myState; ///< Current state of the joystick + int myPovX; ///< Last X position of the POV + int myPovY; ///< Last Y position of the POV }; } // namespace priv diff --git a/src/SFML/Window/Win32/Joystick.cpp b/src/SFML/Window/Win32/Joystick.cpp index 9d489aef9..486bbb403 100644 --- a/src/SFML/Window/Win32/Joystick.cpp +++ b/src/SFML/Window/Win32/Joystick.cpp @@ -46,7 +46,7 @@ void Joystick::Initialize(unsigned int Index) myNbButtons = 0; myIsConnected = false; myHasContinuousPOV = false; - for (int i = 0; i < Joy::Count; ++i) + for (int i = 0; i < Joy::AxisCount; ++i) myAxes[i] = false; // Get the Index-th connected joystick @@ -67,8 +67,8 @@ void Joystick::Initialize(unsigned int Index) JOYCAPS Caps; joyGetDevCaps(myIndex, &Caps, sizeof(Caps)); myNbButtons = Caps.wNumButtons; - if (myNbButtons > JoystickState::MaxButtons) - myNbButtons = JoystickState::MaxButtons; + if (myNbButtons > Joy::ButtonCount) + myNbButtons = Joy::ButtonCount; myAxes[Joy::AxisX] = true; myAxes[Joy::AxisY] = true; diff --git a/src/SFML/Window/Win32/Joystick.hpp b/src/SFML/Window/Win32/Joystick.hpp index 51666e5fb..153806944 100644 --- a/src/SFML/Window/Win32/Joystick.hpp +++ b/src/SFML/Window/Win32/Joystick.hpp @@ -80,11 +80,11 @@ private : //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - bool myIsConnected; ///< Is there a joystick connected? - unsigned int myIndex; ///< Windows ID of the joystick - unsigned int myNbButtons; ///< Number of buttons supported by the joystick - bool myAxes[Joy::Count]; ///< Supported axes - bool myHasContinuousPOV; ///< True if the driver supports continuous values for the POV + bool myIsConnected; ///< Is there a joystick connected? + unsigned int myIndex; ///< Windows ID of the joystick + unsigned int myNbButtons; ///< Number of buttons supported by the joystick + bool myAxes[Joy::AxisCount]; ///< Supported axes + bool myHasContinuousPOV; ///< True if the driver supports continuous values for the POV }; } // namespace priv diff --git a/src/SFML/Window/WindowImpl.cpp b/src/SFML/Window/WindowImpl.cpp index 7337fcabb..dd0584fb5 100644 --- a/src/SFML/Window/WindowImpl.cpp +++ b/src/SFML/Window/WindowImpl.cpp @@ -125,7 +125,7 @@ void WindowImpl::RemoveListener(WindowListener* Listener) void WindowImpl::Initialize() { // Initialize the joysticks - for (unsigned int i = 0; i < JoysticksCount; ++i) + for (unsigned int i = 0; i < Joy::Count; ++i) { myJoysticks[i].Initialize(i); myJoyStates[i] = myJoysticks[i].UpdateState(); @@ -214,14 +214,14 @@ int WindowImpl::EvaluateConfig(const VideoMode& Mode, const WindowSettings& Sett //////////////////////////////////////////////////////////// void WindowImpl::ProcessJoystickEvents() { - for (unsigned int i = 0; i < JoysticksCount; ++i) + for (unsigned int i = 0; i < Joy::Count; ++i) { // Copy the previous state of the joystick and get the new one JoystickState PreviousState = myJoyStates[i]; myJoyStates[i] = myJoysticks[i].UpdateState(); // Axis - for (unsigned int j = 0; j < Joy::Count; ++j) + for (unsigned int j = 0; j < Joy::AxisCount; ++j) { Joy::Axis Axis = static_cast(j); if (myJoysticks[i].HasAxis(Axis)) diff --git a/src/SFML/Window/WindowImpl.hpp b/src/SFML/Window/WindowImpl.hpp index 2e0198094..09f8b54ab 100644 --- a/src/SFML/Window/WindowImpl.hpp +++ b/src/SFML/Window/WindowImpl.hpp @@ -290,18 +290,13 @@ private : //////////////////////////////////////////////////////////// virtual void ProcessEvents() = 0; - //////////////////////////////////////////////////////////// - // Total number of joysticks supported - //////////////////////////////////////////////////////////// - enum {JoysticksCount = 4}; - //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - std::set myListeners; ///< Array of listeners connected to the window - Joystick myJoysticks[JoysticksCount]; ///< Joysticks to observe - JoystickState myJoyStates[JoysticksCount]; ///< Current states of the joysticks - float myJoyThreshold; ///< Joystick threshold (minimum motion for MOVE event to be generated) + std::set myListeners; ///< Array of listeners connected to the window + Joystick myJoysticks[Joy::Count]; ///< Joysticks to observe + JoystickState myJoyStates[Joy::Count]; ///< Current states of the joysticks + float myJoyThreshold; ///< Joystick threshold (minimum motion for MOVE event to be generated) }; } // namespace priv From 5eaec85d87ce5a8f820cfa1ac00d58752dc89bce Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Wed, 6 Jan 2010 08:51:25 +0000 Subject: [PATCH 09/14] Added a special value of -1 for centered joystick POV position git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1329 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Window/Joystick.hpp | 12 ++++++++++++ src/SFML/Window/Linux/Joystick.cpp | 2 +- src/SFML/Window/Win32/Joystick.cpp | 5 ++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/SFML/Window/Joystick.hpp b/src/SFML/Window/Joystick.hpp index 33e684e1a..6dd1b6e20 100644 --- a/src/SFML/Window/Joystick.hpp +++ b/src/SFML/Window/Joystick.hpp @@ -41,6 +41,18 @@ namespace priv //////////////////////////////////////////////////////////// struct JoystickState { + JoystickState() + { + // Default value for axes + for (int i = 0; i < Joy::AxisCount; ++i) + Axis[i] = 0.f; + Axis[Joy::AxisPOV] = -1.f; + + // Default value for buttons + for (int i = 0; i < Joy::ButtonCount; ++i) + Buttons[i] = false; + } + float Axis[Joy::AxisCount]; ///< Position on each axis in range [-100, 100] (except POV which is [0, 360]) bool Buttons[Joy::ButtonCount]; ///< Status of each button (true = pressed) }; diff --git a/src/SFML/Window/Linux/Joystick.cpp b/src/SFML/Window/Linux/Joystick.cpp index b14a292b0..e8267d482 100644 --- a/src/SFML/Window/Linux/Joystick.cpp +++ b/src/SFML/Window/Linux/Joystick.cpp @@ -145,7 +145,7 @@ JoystickState Joystick::UpdateState() { if (myPovY == 1) myState.Axis[Joy::AxisPOV] = 270.f; else if (myPovY == -1) myState.Axis[Joy::AxisPOV] = 90.f; - else myState.Axis[Joy::AxisPOV] = 0.f; // what is it supposed to be?? + else myState.Axis[Joy::AxisPOV] = -1.f; } } diff --git a/src/SFML/Window/Win32/Joystick.cpp b/src/SFML/Window/Win32/Joystick.cpp index 486bbb403..5d37e4c7b 100644 --- a/src/SFML/Window/Win32/Joystick.cpp +++ b/src/SFML/Window/Win32/Joystick.cpp @@ -118,7 +118,10 @@ JoystickState Joystick::UpdateState() State.Axis[Joy::AxisV] = (Pos.dwVpos - (Caps.wVmax + Caps.wVmin) / 2.f) * 200.f / (Caps.wVmax - Caps.wVmin); // POV - State.Axis[Joy::AxisPOV] = Pos.dwPOV / 100.f; + if (Pos.dwPOV != 0xFFFF) + State.Axis[Joy::AxisPOV] = Pos.dwPOV / 100.f; + else + State.Axis[Joy::AxisPOV] = -1.f; // Buttons for (unsigned int i = 0; i < GetButtonsCount(); ++i) From cbee33e76473cafa01bb9f3a9fb9803986ac6b3e Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Wed, 6 Jan 2010 14:19:37 +0000 Subject: [PATCH 10/14] Fixed POV value initialized to 0 instead of -1 in sf::Input git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1331 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Window/Input.cpp | 1 + src/SFML/Window/Win32/Joystick.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SFML/Window/Input.cpp b/src/SFML/Window/Input.cpp index 33b7161e0..01dd54fce 100644 --- a/src/SFML/Window/Input.cpp +++ b/src/SFML/Window/Input.cpp @@ -162,6 +162,7 @@ void Input::ResetStates() for (int j = 0; j < Joy::AxisCount; ++j) myJoystickAxis[i][j] = 0.f; + myJoystickAxis[i][Joy::AxisPOV] = -1.f; } } diff --git a/src/SFML/Window/Win32/Joystick.cpp b/src/SFML/Window/Win32/Joystick.cpp index 5d37e4c7b..e5e16a90f 100644 --- a/src/SFML/Window/Win32/Joystick.cpp +++ b/src/SFML/Window/Win32/Joystick.cpp @@ -94,7 +94,7 @@ void Joystick::Initialize(unsigned int Index) //////////////////////////////////////////////////////////// JoystickState Joystick::UpdateState() { - JoystickState State = {0}; + JoystickState State; if (myIsConnected) { From b9a2d3a8f4d9b55f66391b3368da146085a77158 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Wed, 6 Jan 2010 14:28:20 +0000 Subject: [PATCH 11/14] Fixed joystick axes mapping (to be tested) git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1332 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Window/Linux/Joystick.cpp | 19 ++++++------------- src/SFML/Window/Linux/Joystick.hpp | 19 +++++++++++++------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/SFML/Window/Linux/Joystick.cpp b/src/SFML/Window/Linux/Joystick.cpp index e8267d482..4f3ca725f 100644 --- a/src/SFML/Window/Linux/Joystick.cpp +++ b/src/SFML/Window/Linux/Joystick.cpp @@ -28,13 +28,6 @@ #include #include -#if defined(SFML_SYSTEM_LINUX) - #include - #include -#elif defined(SFML_SYSTEM_FREEBSD) - // #include ? -#endif - namespace sf { @@ -69,7 +62,7 @@ void Joystick::Initialize(unsigned int Index) { // Use non-blocking mode fcntl(myDescriptor, F_SETFL, O_NONBLOCK); - + // Get number of buttons char NbButtons; ioctl(myDescriptor, JSIOCGBUTTONS, &NbButtons); @@ -78,12 +71,12 @@ void Joystick::Initialize(unsigned int Index) myNbButtons = Joy::ButtonCount; // Get the supported axes - char NbAxes, Axes[ABS_MAX + 1]; - ioctl(myDescriptor, JSIOCGAXES, &NbAxes); - ioctl(myDescriptor, JSIOCGAXMAP, Axes); + char NbAxes; + ioctl(myDescriptor, JSIOCGAXES, &NbAxes); + ioctl(myDescriptor, JSIOCGAXMAP, myAxesMapping); for (int i = 0; i < NbAxes; ++i) { - switch (Axes[i]) + switch (myAxesMapping[i]) { case ABS_X : myAxes[Joy::AxisX] = true; break; case ABS_Y : myAxes[Joy::AxisY] = true; break; @@ -114,7 +107,7 @@ JoystickState Joystick::UpdateState() // An axis has been moved case JS_EVENT_AXIS : { - switch (JoyState.number) + switch (myAxesMapping[JoyState.number]) { case ABS_X : myState.Axis[Joy::AxisX] = JoyState.value * 100.f / 32767.f; break; case ABS_Y : myState.Axis[Joy::AxisY] = JoyState.value * 100.f / 32767.f; break; diff --git a/src/SFML/Window/Linux/Joystick.hpp b/src/SFML/Window/Linux/Joystick.hpp index ea780f493..c03bf08e8 100644 --- a/src/SFML/Window/Linux/Joystick.hpp +++ b/src/SFML/Window/Linux/Joystick.hpp @@ -28,6 +28,12 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// +#if defined(SFML_SYSTEM_LINUX) + #include + #include +#elif defined(SFML_SYSTEM_FREEBSD) + // #include ? +#endif namespace sf @@ -80,12 +86,13 @@ private : //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - int myDescriptor; ///< Linux descriptor of the joystick - unsigned int myNbButtons; ///< Number of buttons supported by the joystick - bool myAxes[Joy::AxisCount]; ///< Supported axes - JoystickState myState; ///< Current state of the joystick - int myPovX; ///< Last X position of the POV - int myPovY; ///< Last Y position of the POV + int myDescriptor; ///< Linux descriptor of the joystick + unsigned int myNbButtons; ///< Number of buttons supported by the joystick + bool myAxes[Joy::AxisCount]; ///< Supported axes + JoystickState myState; ///< Current state of the joystick + int myPovX; ///< Last X position of the POV + int myPovY; ///< Last Y position of the POV + char myAxesMapping[ABS_MAX + 1]; ///< Axes mapping (index --> axis id) }; } // namespace priv From 44c943e651bc712a5ee960c84091ef3b17af1760 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Fri, 8 Jan 2010 17:21:03 +0000 Subject: [PATCH 12/14] FS#146 - Fix current OpenGL matrix mode not properly saved when PreserveOpenGLStates is activated git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1338 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Graphics/RenderTarget.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SFML/Graphics/RenderTarget.cpp b/src/SFML/Graphics/RenderTarget.cpp index f9d9096ad..2dca86676 100644 --- a/src/SFML/Graphics/RenderTarget.cpp +++ b/src/SFML/Graphics/RenderTarget.cpp @@ -86,10 +86,10 @@ void RenderTarget::Draw(const Drawable& Object) // Save the current render states and set the SFML ones if (myPreserveStates) { - GLCheck(glMatrixMode(GL_MODELVIEW)); GLCheck(glPushMatrix()); - GLCheck(glMatrixMode(GL_PROJECTION)); GLCheck(glPushMatrix()); GLCheck(glPushAttrib(GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT | GL_TEXTURE_BIT | GL_TRANSFORM_BIT | GL_VIEWPORT_BIT)); + GLCheck(glMatrixMode(GL_MODELVIEW)); GLCheck(glPushMatrix()); + GLCheck(glMatrixMode(GL_PROJECTION)); GLCheck(glPushMatrix()); SetRenderStates(); } From 489ee2b17baa2b643b907acd3269ae8a7e84033f Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Sat, 9 Jan 2010 09:13:06 +0000 Subject: [PATCH 13/14] Fixed POV handling on Linux git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1339 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Window/Linux/Joystick.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/SFML/Window/Linux/Joystick.cpp b/src/SFML/Window/Linux/Joystick.cpp index 4f3ca725f..6052cc914 100644 --- a/src/SFML/Window/Linux/Joystick.cpp +++ b/src/SFML/Window/Linux/Joystick.cpp @@ -122,23 +122,23 @@ JoystickState Joystick::UpdateState() break; // Compute the new POV angle - if (myPovX == 1) + if (myPovX > 0) { - if (myPovY == 1) myState.Axis[Joy::AxisPOV] = 315.f; - else if (myPovY == -1) myState.Axis[Joy::AxisPOV] = 45.f; - else myState.Axis[Joy::AxisPOV] = 0.f; + if (myPovY > 0) myState.Axis[Joy::AxisPOV] = 315.f; + else if (myPovY < 0) myState.Axis[Joy::AxisPOV] = 45.f; + else myState.Axis[Joy::AxisPOV] = 0.f; } - else if (myPovX == -1) + else if (myPovX < 0) { - if (myPovY == 1) myState.Axis[Joy::AxisPOV] = 225.f; - else if (myPovY == -1) myState.Axis[Joy::AxisPOV] = 135.f; - else myState.Axis[Joy::AxisPOV] = 180.f; + if (myPovY > 0) myState.Axis[Joy::AxisPOV] = 225.f; + else if (myPovY < 0) myState.Axis[Joy::AxisPOV] = 135.f; + else myState.Axis[Joy::AxisPOV] = 180.f; } else { - if (myPovY == 1) myState.Axis[Joy::AxisPOV] = 270.f; - else if (myPovY == -1) myState.Axis[Joy::AxisPOV] = 90.f; - else myState.Axis[Joy::AxisPOV] = -1.f; + if (myPovY > 0) myState.Axis[Joy::AxisPOV] = 270.f; + else if (myPovY < 0) myState.Axis[Joy::AxisPOV] = 90.f; + else myState.Axis[Joy::AxisPOV] = -1.f; } } From 8df50b9774026b7c59bfd871ebc4813bd2d93c45 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Sat, 9 Jan 2010 17:24:51 +0000 Subject: [PATCH 14/14] Fixed wrong joystick POV values in the Linux implementation git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1341 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Window/Linux/Joystick.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/SFML/Window/Linux/Joystick.cpp b/src/SFML/Window/Linux/Joystick.cpp index 6052cc914..829a74151 100644 --- a/src/SFML/Window/Linux/Joystick.cpp +++ b/src/SFML/Window/Linux/Joystick.cpp @@ -119,29 +119,29 @@ JoystickState Joystick::UpdateState() case ABS_HAT0Y : myPovY = JoyState.value; break; default : break; } - break; // Compute the new POV angle if (myPovX > 0) { - if (myPovY > 0) myState.Axis[Joy::AxisPOV] = 315.f; + if (myPovY > 0) myState.Axis[Joy::AxisPOV] = 135.f; else if (myPovY < 0) myState.Axis[Joy::AxisPOV] = 45.f; - else myState.Axis[Joy::AxisPOV] = 0.f; + else myState.Axis[Joy::AxisPOV] = 90.f; } else if (myPovX < 0) { if (myPovY > 0) myState.Axis[Joy::AxisPOV] = 225.f; - else if (myPovY < 0) myState.Axis[Joy::AxisPOV] = 135.f; - else myState.Axis[Joy::AxisPOV] = 180.f; + else if (myPovY < 0) myState.Axis[Joy::AxisPOV] = 315.f; + else myState.Axis[Joy::AxisPOV] = 270.f; } else { - if (myPovY > 0) myState.Axis[Joy::AxisPOV] = 270.f; - else if (myPovY < 0) myState.Axis[Joy::AxisPOV] = 90.f; + if (myPovY > 0) myState.Axis[Joy::AxisPOV] = 180.f; + else if (myPovY < 0) myState.Axis[Joy::AxisPOV] = 0.f; else myState.Axis[Joy::AxisPOV] = -1.f; } + break; } - + // A button has been pressed case JS_EVENT_BUTTON : {