Page MenuHomeWildfire Games

CSlider IGUIButtonBehavior inheritance to gain Sound, Press and Release events
ClosedPublic

Authored by elexis on Jan 23 2020, 6:18 AM.

Details

Summary

The purpose of this patch is to fix these defects:

  1. The CSlider GUI object type in rP19479/D325 doesn't play sounds when pressed (unlike buttons, checkboxes, dropdowns)
  2. The CSlider GUI object does not allow the script side to determine if the value is currently being changed by the user (mouse being pressed, moved)
  3. The Gamesetup usage of this slider in rP23430/D2571 has the issue that the slider is lagging behind in multiplayer mode, because the slider value is updated to the current selection, but that selection is updated only after being sent across the network. (Noticed by me before the commit, but I didn't notice that it was inacceptably bad until nani reported it to me.)

The patch solves (1) and (2) by adding inheritance of IGUIButtonBehavior to CSlider, and solves (3) by not updating the slider value with the g_GameAttributes value if the user is currently picking a value.

There are two aspects to consider:

  • The CSlider changes values incrementally upon mousemove events. It could be changed to pick the value at the current mouse position, as was done in rP22164/D1622. That would fix the slider position not being at the current mouse position. However it would not fix that the slider would still jump back to an outdated g_GameAttributes value in multiplayer mode (due to the greater than zero network lag) before jumping back to the mouse position.
  • In the future code, there may be multiple gamesetup controlers changing g_GameAttributes simultaneously, so one should not assume that only the host changes settings.
Test Plan

Notice that CGUI already has some release events, but those are Mouse release events whereas the IGUIButton ones might hypothetically also be triggered without the mouse.
Equally the CGUI class has Press events that IGUIButtonBehavior has too.
Notice that duplication is bad and that inheritance of IGUIButtonBehavior avoids that, and that the class exists to avoid duplication.
Notice that sound is actually missing.
Ensure that ResetStates is called always when needed and that the m_Pressed variable has the correct state at any point in time.
Ensure that the Gamesetup slider would still work correctly if there is a second client changing the same slider at the same time, or changing a gamesetting that would make the slider unavailable.

Notice that calling the events from ResetStates is necessary for the case where the mouse leaves the GUI object, as the SDL release case is not triggered then.

Event Timeline

elexis created this revision.Jan 23 2020, 6:18 AM
elexis edited the test plan for this revision. (Show Details)Jan 23 2020, 6:21 AM

Successful build - Chance fights ever on the side of the prudent.

Linter detected issues:
Executing section Source...

source/gui/SGUIMessage.h
|   1| /*·Copyright·(C)·2019·Wildfire·Games.
|    | [NORMAL] LicenseYearBear:
|    | License should have "2020" year instead of "2019"

source/gui/ObjectTypes/CSlider.h
|   1| /*·Copyright·(C)·2019·Wildfire·Games.
|    | [NORMAL] LicenseYearBear:
|    | License should have "2020" year instead of "2019"

source/gui/ObjectTypes/CSlider.h
|  25| class·CSlider·:·public·IGUIObject,·IGUIButtonBehavior
|    | [MAJOR] CPPCheckBear (syntaxError):
|    | Code 'classCSlider:' is invalid C code. Use --std or --language to configure the language.

source/gui/ObjectBases/IGUIButtonBehavior.cpp
|   1| /*·Copyright·(C)·2019·Wildfire·Games.
|    | [NORMAL] LicenseYearBear:
|    | License should have "2020" year instead of "2019"

source/gui/ObjectTypes/CSlider.cpp
|   1| /*·Copyright·(C)·2019·Wildfire·Games.
|    | [NORMAL] LicenseYearBear:
|    | License should have "2020" year instead of "2019"

source/gui/ObjectBases/IGUIButtonBehavior.h
|   1| /*·Copyright·(C)·2019·Wildfire·Games.
|    | [NORMAL] LicenseYearBear:
|    | License should have "2020" year instead of "2019"

source/gui/ObjectBases/IGUIButtonBehavior.h
|  38| class·IGUIButtonBehavior
|    | [MAJOR] CPPCheckBear (syntaxError):
|    | Code 'classIGUIButtonBehavior{' is invalid C code. Use --std or --language to configure the language.
Executing section JS...
Executing section cli...

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/1631/display/redirect

elexis updated this revision to Diff 11157.Jan 23 2020, 5:06 PM

Simplify CSlider code following the IGUIButtonBehavior inheritance by deleting m_IsPressed which is now redundant with m_Pressed from the inherited class.

Change CSlider behavior to:

  • continue sliding as long as the mouse is pressed, even when the mouse is not over the slider,
  • slide to the value at the current mouse position (fallthrough to code from rP22164) instead of changing the mouse offset. Firstly that is more precise and secondly it would fail in case of the JS issue described or when the mouse leaves the GUI object bbox) if not performed.

Successful build - Chance fights ever on the side of the prudent.

Linter detected issues:
Executing section Source...

source/gui/ObjectTypes/CSlider.h
|  25| class·CSlider·:·public·IGUIObject,·public·IGUIButtonBehavior
|    | [MAJOR] CPPCheckBear (syntaxError):
|    | Code 'classCSlider:' is invalid C code. Use --std or --language to configure the language.

source/gui/ObjectBases/IGUIButtonBehavior.h
|  38| class·IGUIButtonBehavior
|    | [MAJOR] CPPCheckBear (syntaxError):
|    | Code 'classIGUIButtonBehavior{' is invalid C code. Use --std or --language to configure the language.
Executing section JS...
Executing section cli...

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/1636/display/redirect

nani added a subscriber: nani.Jan 23 2020, 7:45 PM

Tested. Works as advertised.

nani accepted this revision.Jan 23 2020, 7:46 PM
This revision is now accepted and ready to land.Jan 23 2020, 7:46 PM

nani posted more review comments in a PM conversation, most importantly motivating me to create the second iteration of the patch, also he tested the patch.

Comments by Vladislav on http://irclogs.wildfiregames.com/2020-01/2020-01-23-QuakeNet-%230ad-dev.log (Got a useless this-> hint and a "the patch isn't bad", the rest was discussion about virtual inheritance, refs D2325/rP23020)

Owners added a subscriber: Restricted Owners Package.Jan 24 2020, 1:57 AM