More perf improvements to grid

This commit is contained in:
Raoul Van den Berge
2016-08-09 21:25:28 +02:00
parent 2d1a559c52
commit c3690f72a0
6 changed files with 34 additions and 17 deletions

View File

@@ -1,5 +1,9 @@
# Refined Storage Changelog
### 0.8.17
**Bugfixes**
- Fixed Grid causing sorting lag on the client
### 0.8.16
**Bugfixes**
- Fixed issue with IC2 integration causing console spam

View File

@@ -1,5 +1,7 @@
package refinedstorage.gui.grid;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
@@ -36,10 +38,10 @@ public class GuiGrid extends GuiBase {
public static final GridSortingQuantity SORTING_QUANTITY = new GridSortingQuantity();
public static final GridSortingName SORTING_NAME = new GridSortingName();
public static List<ClientStack> ITEMS = new ArrayList<>();
public static Multimap<Item, ClientStack> ITEMS = ArrayListMultimap.create();
public static List<ClientStack> SORTED_ITEMS = new ArrayList<>();
public static boolean markedForSorting;
private static boolean markedForSorting;
private GuiTextField searchField;
@@ -48,6 +50,10 @@ public class GuiGrid extends GuiBase {
private int slotNumber;
public static void markForSorting() {
markedForSorting = true;
}
public GuiGrid(ContainerGrid container, IGrid grid) {
super(container, 227, (grid.getType() == EnumGridType.CRAFTING || grid.getType() == EnumGridType.PATTERN) ? 247 : 208);
@@ -95,7 +101,7 @@ public class GuiGrid extends GuiBase {
List<ClientStack> sortedItems = new ArrayList<>();
if (grid.isConnected()) {
sortedItems.addAll(ITEMS);
sortedItems.addAll(ITEMS.values());
String query = searchField.getText().trim().toLowerCase();

View File

@@ -1,6 +1,7 @@
package refinedstorage.network;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
@@ -39,22 +40,24 @@ public class MessageGridDelta implements IMessage, IMessageHandler<MessageGridDe
@Override
public IMessage onMessage(MessageGridDelta message, MessageContext ctx) {
for (ClientStack stack : GuiGrid.ITEMS) {
Item item = message.clientStack.getStack().getItem();
for (ClientStack stack : GuiGrid.ITEMS.get(item)) {
if (stack.equals(message.clientStack)) {
if (stack.getStack().stackSize + message.delta == 0 && !message.clientStack.isCraftable()) {
GuiGrid.ITEMS.remove(stack);
GuiGrid.ITEMS.remove(item, stack);
} else {
stack.getStack().stackSize += message.delta;
}
GuiGrid.markedForSorting = true;
GuiGrid.markForSorting();
return null;
}
}
GuiGrid.ITEMS.add(message.clientStack);
GuiGrid.markedForSorting = true;
GuiGrid.ITEMS.put(item, message.clientStack);
GuiGrid.markForSorting();
return null;
}

View File

@@ -43,8 +43,13 @@ public class MessageGridUpdate implements IMessage, IMessageHandler<MessageGridU
@Override
public IMessage onMessage(MessageGridUpdate message, MessageContext ctx) {
GuiGrid.ITEMS = message.items;
GuiGrid.markedForSorting = true;
GuiGrid.ITEMS.clear();
for (ClientStack item : message.items) {
GuiGrid.ITEMS.put(item.getStack().getItem(), item);
}
GuiGrid.markForSorting();
return null;
}

View File

@@ -51,8 +51,7 @@ public class TileGrid extends TileNode implements IGrid {
tile.markDirty();
}
}
}, parameter ->
GuiGrid.markedForSorting = true);
}, parameter -> GuiGrid.markForSorting());
public static final TileDataParameter<Integer> SORTING_DIRECTION = new TileDataParameter<>(DataSerializers.VARINT, 0, new ITileDataProducer<Integer, TileGrid>() {
@Override
@@ -68,7 +67,7 @@ public class TileGrid extends TileNode implements IGrid {
tile.markDirty();
}
}
}, parameter -> GuiGrid.markedForSorting = true);
}, parameter -> GuiGrid.markForSorting());
public static final TileDataParameter<Integer> SORTING_TYPE = new TileDataParameter<>(DataSerializers.VARINT, 0, new ITileDataProducer<Integer, TileGrid>() {
@Override
@@ -84,7 +83,7 @@ public class TileGrid extends TileNode implements IGrid {
tile.markDirty();
}
}
}, parameter -> GuiGrid.markedForSorting = true);
}, parameter -> GuiGrid.markForSorting());
public static final TileDataParameter<Integer> SEARCH_BOX_MODE = new TileDataParameter<>(DataSerializers.VARINT, 0, new ITileDataProducer<Integer, TileGrid>() {
@Override

View File

@@ -116,7 +116,7 @@ public class WirelessGrid implements IGrid {
this.viewType = type;
GuiGrid.markedForSorting = true;
GuiGrid.markForSorting();
}
@Override
@@ -125,7 +125,7 @@ public class WirelessGrid implements IGrid {
this.sortingType = type;
GuiGrid.markedForSorting = true;
GuiGrid.markForSorting();
}
@Override
@@ -134,7 +134,7 @@ public class WirelessGrid implements IGrid {
this.sortingDirection = direction;
GuiGrid.markedForSorting = true;
GuiGrid.markForSorting();
}
@Override