Skip to content

Commit

Permalink
cache scenario preview widget (#2143)
Browse files Browse the repository at this point in the history
Fixes the lag issue noted in #1515.

# Demo

1. First, launch a toplevel scenario:
    ```
    scripts/play.sh -i data/scenarios/blank.yaml
    ```
2. Then use <kbd>Ctrl</kbd>+<kbd>q</kbd> to quit to the scenario selection menu.
3. Notice when using up-arrow to select the "Classic" and "Creative" scenarios, there is a delay as the preview is computed for the first time.
4. Finally, when subsequently selecting back and forth between the two again, notice that the lag is gone, as the cache is being used.
  • Loading branch information
kostmo authored Sep 10, 2024
1 parent 9270ff8 commit 7b99e72
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/swarm-tui/Swarm/TUI/Model/Name.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ data Name
InventoryList
| -- | The inventory item position in the InventoryList.
InventoryListItem Int
| -- | Cacheable scenario preview
ScenarioPreview FilePath
| -- | The list of main menu choices.
MenuList
| -- | The list of achievements.
Expand Down
7 changes: 3 additions & 4 deletions src/swarm-tui/Swarm/TUI/View.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ module Swarm.TUI.View (
drawModalMenu,
drawKeyCmd,

-- * World
drawWorldPane,

-- * Robot panel
drawRobotPanel,
drawItem,
Expand Down Expand Up @@ -255,7 +252,9 @@ drawNewGameMenuUI (l :| ls) launchOptions = case displayedFor of
drawDescription (SISingle (s, si)) =
vBox
[ drawMarkdown (nonBlank (s ^. scenarioOperation . scenarioDescription))
, hCenter . padTop (Pad 1) . vLimit 6 $ hLimitPercent 60 worldPeek
, cached (ScenarioPreview $ si ^. scenarioPath) $
hCenter . padTop (Pad 1) . vLimit 6 $
hLimitPercent 60 worldPeek
, padTop (Pad 1) table
]
where
Expand Down

0 comments on commit 7b99e72

Please sign in to comment.