From 1510e27dadf7c5d47b873dc220e22f442873cd1b Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Thu, 8 Mar 2018 18:46:26 +0100 Subject: [PATCH] Attempted to fix FPS drop on Grid sorting, fixes #1674 --- CHANGELOG.md | 1 + .../refinedstorage/gui/grid/GuiGrid.java | 15 +++-------- .../gui/grid/sorting/Sorter.java | 26 ++++++------------- 3 files changed, 12 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ea31acbb..e2fb40381 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Fixed Disk Manipulator being stuck on unemptiable, non-empty disks (ineternet) - Fixed orientations of the Portable Grid (TeamSpen210) - Fixed crafting event in Crafting Grid being fired twice (raoulvdberge) +- Attempted to fix FPS drop on Grid sorting (raoulvdberge) - Disk Manipulator in fluid mode will now extract a bucket at a time instead of 1 mB (or 64 buckets at a time with a Stack Upgrade instead of 64 mB) (raoulvdberge) ### 1.5.31 diff --git a/src/main/java/com/raoulvdberge/refinedstorage/gui/grid/GuiGrid.java b/src/main/java/com/raoulvdberge/refinedstorage/gui/grid/GuiGrid.java index 9a4296794..5d1678f0d 100755 --- a/src/main/java/com/raoulvdberge/refinedstorage/gui/grid/GuiGrid.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/gui/grid/GuiGrid.java @@ -62,8 +62,8 @@ public class GuiGrid extends GuiBase implements IGridDisplay { public static List STACKS = new ArrayList<>(); public static boolean CAN_CRAFT; - private static boolean SCHEDULE_SORT = false; - private Queue sortingQueue = new ArrayDeque<>(); + private static final Sorter SORTER = new Sorter(); + private static boolean SCHEDULE_SORT; private boolean wasConnected; @@ -210,16 +210,7 @@ public class GuiGrid extends GuiBase implements IGridDisplay { if (SCHEDULE_SORT) { SCHEDULE_SORT = false; - sortingQueue.add(new Sorter(this)); - } - - Sorter sorter = sortingQueue.peek(); - if (sorter != null) { - if (!sorter.isStarted()) { - sorter.start(); - } else if (sorter.isDone()) { - sortingQueue.poll(); - } + SORTER.startIfPossible(this); } } diff --git a/src/main/java/com/raoulvdberge/refinedstorage/gui/grid/sorting/Sorter.java b/src/main/java/com/raoulvdberge/refinedstorage/gui/grid/sorting/Sorter.java index 8d0d0a005..3a20dc084 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/gui/grid/sorting/Sorter.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/gui/grid/sorting/Sorter.java @@ -18,15 +18,10 @@ public class Sorter implements Runnable { private static final GridSorting SORTING_INVENTORYTWEAKS = new GridSortingInventoryTweaks(); private static final GridSorting SORTING_LAST_MODIFIED = new GridSortingLastModified(); - private boolean done; - private boolean started; + private boolean busy; private GuiGrid gui; - public Sorter(GuiGrid gui) { - this.gui = gui; - } - @Override public void run() { IGrid grid = gui.getGrid(); @@ -90,20 +85,15 @@ public class Sorter implements Runnable { gui.getTabPageRight().visible = grid.getTotalTabPages() > 0; } - this.done = true; + this.busy = false; } - public void start() { - this.started = true; + public void startIfPossible(GuiGrid gui) { + if (!busy) { + this.busy = true; + this.gui = gui; - new Thread(this, "RS grid sorting").start(); - } - - public boolean isStarted() { - return started; - } - - public boolean isDone() { - return done; + new Thread(this, "RS grid sorting").start(); + } } }