0

I'm writing a minesweeper clone using Seesaw. For the minefield, I'm using a simple grid-panel of buttons. I've gotten to the point where when you click on a button, it will flood fill the grid to uncover all the empty tiles surrounding where you clicked. To "uncover the tile", I'm just disabling the button associated with the tile.

The problem is, it's uncovering incrementally, even though the task being executed isn't that expensive. It will update a few spotty buttons around the grid randomly over time, and it looks really bad. I would rather have a second of lag than for it to disable the buttons procedurally.

This is basically the button click handler:

(doseq [b buttons] ; Buttons are the grid cells
  (let [[tx ty] (sc/user-data b) ; The cell position is stored in the user data
        tile (b/get-tile-at board tx ty)] ; O(1) lookup

    (when (:uncovered? tile)
      (sc/invoke-later ; Because this chunk is actually being executed in a pool
        (sc/config! b :enabled? false)))))

Since there's nothing expensive going on here, it seems like each config! call makes a change to a button, and the button's appearances are updated as the changes happen.

Is there a way to have every call to config!/button update happen all at once, even if it creates a small amount of perceived lag?

Carcigenicate
  • 43,494
  • 9
  • 68
  • 117

1 Answers1

1

I'm not familiar with seesaw or its internals, but you want to find a way to use double buffering in Swing.

See also: https://docs.oracle.com/javase/tutorial/extra/fullscreen/doublebuf.html

Alan Thompson
  • 29,276
  • 6
  • 41
  • 48
  • I've never heard of double buffering used outside of drawing to a canvas. I guess buttons can be painted directly? So I should paint the updated state to a buffer, then swap? Thanks, I'll look into it. – Carcigenicate May 13 '18 at 00:45