-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CHANGE: Remove redundant FastMouse current time call on InputState.Change (case ISX-1414) #1928
Conversation
…ate.Change (case ISX-1414)
…ce improvement (case ISX-1414)
Looks like I may need to fix-up some documentation after adding the default parameter. This change also fails the APIVerificationTests.cs test: o APIVerificationTests.API_MinorVersionsHaveNoBreakingChanges |
Yeah.. maybe we need a overload method to not break the API, unfortunately. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed this is changing public API but with additive default values so I guess package verification tool categories this as a minor API break and not a major. It might require next release to be a minor revision though but not sure. @unity-cliff or @stefanunity might have insight into this?
// Report any calls with no event and no specified time (relying on both default parameter values) | ||
// This may not matter but would like to know about these during testing with more devices | ||
// | ||
if (!eventPtr.valid && time == 0.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we still proceed without return if this scenario occurs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question - I thought it better to continue rather than just return here.
I haven't actually seen this case happen yet with my limited devices for testing.
What might be better is to simply set the time here in this case:
if (!eventPtr.valid && time == default)
{
Debug.Log($"InputState.Change<>('{control.name}') called with null event and default time\n");
time = InputRuntime.s_Instance.currentTime;
}
I think this would preserve the existing behaviour where it would query the time if no event was provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've refactored this so we no longer need this check.
There are two paths into this function from the two Change<>() templated functions.
The original Change<>() function always passes in an event (with it's own internal time) - if the event is not valid it passes the current time.
The other newly added Change<>() function always passes in a time value (it's a required parameter) along with a dummy event - this is the one used by the FastMouse.OnNextUpdate() function.
…tional time parameter. o Used to avoid extraneous currentTime calls for FastMouse.FastMouse o Updated CHANGELOG.md addressing PR feedback
I've added a new Change<>() API that takes a non-optional time parameter - this leaves the existing API unchanged. |
/ci prv |
public static void Change<TState>(InputControl control, TState state, InputUpdateType updateType = default, InputEventPtr eventPtr = default) | ||
where TState : struct | ||
{ | ||
double time = eventPtr.valid ? default : InputRuntime.s_Instance.currentTime; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this right - should it actually be set to default if the eventPtr is NOT valid ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's correct.
If the eventPtr IS valid then that event's internalTime will be used in the unsafe Change<>() function that's called (the time parameter can be default avoiding the call to get the current time).
If eventPtr is NOT valid then we need to look up the time here and pass that instead for the unsafe Change<>() function to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ok to me.
Just asked some comment improvements in the "new" added Change
method so that their need/use case is clearer. We will now have 4 overloaded Change
methods so it helps to have some differentiation between them
Closing as do not intend to land in trunk due to API change) |
Description
Reduce FastMouse calls to get the current time (one of them is redundant).
Changes made
FastMouse.OnNextUpdate() makes two calls to InputState.Change() - one each for delta and scroll.
This results in two calls to InputRuntime.s_Instance.currentTime inside the InputSystem.Change() to pass as a parameter to the InputSystem UpdateState().
Instead query the current time and pass that as a parameter to the new templated Change<>() function which takes a time parameter. Events have their own internalTime which is used if present.
Checklist
Before review:
Changed
,Fixed
,Added
sections.([case %number%](https://issuetracker.unity3d.com/issues/...))
.Area_CanDoX
,Area_CanDoX_EvenIfYIsTheCase
,Area_WhenIDoX_AndYHappens_ThisIsTheResult
.During merge:
CHANGE: FastMouse.OnNextUpdate() now queries the current time and passes it as a parameter to InputState.Change() avoiding a redundant native call (case ISX-1414)
NEW: ___
.FIX: ___
.DOCS: ___
.CHANGE: ___
.RELEASE: 1.1.0-preview.3
.