Skip to content
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

Fix some stutters when dragging maps #4003

Merged
merged 4 commits into from
Apr 26, 2023

Conversation

kwvanderlinde
Copy link
Collaborator

@kwvanderlinde kwvanderlinde commented Apr 26, 2023

Identify the Bug or Feature request

Implements #4002

Description of the Change

In addition to the change requested in #4002, I found these additional things along the way:

  1. NotificationOverlay is unused and has been removed.
  2. We don't need to clear the images returned from BufferedImagePool. Callers already either apply a fill colour or completely fill the buffer with rendering results. So the clearing step is just wasted work, and has been removed.
  3. The DebounceExecutor would always delay a task by the full amount, even if it's been a while since the last execution. This can create noticable extra delays when the frame rate is capped, similar to the stutters caused by DefaultTool.mouseDragged(). I've put in a new implementation that delays tasks by only enough to get past the last execution's time budget, and runs tasks with no delay if it's been long enough since the last execution.

Possible Drawbacks

Should be none.

Documentation Notes

N/A

Release Notes

  • Slight improvement to reduce map dragging lag.

This change is Reviewable

`ZoneRenderer` debounces repaints, so it isn't necessary to throttle updates just to avoid excessive repaints. By not
throttling updates, the next `ZoneRenderer` paint will tend to be more up-to-date than it would be with the throttling.
It can be the callers responsibility instead to clear the image if necessary. As it happens, current usage already fills
the buffers completely and does not require a prior clearing:
- `renderLumensOverlay` and `renderLightOverlay` fill with a solid colour first.
- `renderFog` and `paintComponent` render opaquely to the entire buffer.
The previous implementation would always apply a full delay to any dispatch request, regardless of how long it had been
since the last scheduling of a task. This meant that execution A could complete, then execution B could be requested
_just before_ the end of the delay time and still be delayed the full time, resulting a double delay. This is noticeable
when events are coming in rapid succession (e.g., mouse dragging) as what should be a steady stream of task runs is
instead choppy and inconsistent.

The new implementation only delays tasks that have come in close succession to a previous task. If a long time has
passed, no delay is applied. The new implementation also avoids locks in favour of a lighter weight compare-exchange
operation.
@cwisniew cwisniew added this pull request to the merge queue Apr 26, 2023
Merged via the queue into RPTools:develop with commit b1dc4de Apr 26, 2023
@cwisniew cwisniew added the code-maintenance Adding/editing javadocs, unit tests, formatting. label Apr 26, 2023
@kwvanderlinde kwvanderlinde deleted the refactor/choppy-map-dragging branch May 1, 2023 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code-maintenance Adding/editing javadocs, unit tests, formatting.
Projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

None yet

2 participants