aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2023-05-18 06:34:05 +0200
committerGitHub <noreply@github.com>2023-05-18 14:34:05 +1000
commitc8ca57fa703011c2dcb87d9b544e1f04809efeaa (patch)
treef331bb38e03af990ce70c8eb0f187c236fbe2bcc /src
parent68a790e6750724785d9f2bc2bcee2f516203bc6b (diff)
downloadNotEnoughUpdates-c8ca57fa703011c2dcb87d9b544e1f04809efeaa.tar.gz
NotEnoughUpdates-c8ca57fa703011c2dcb87d9b544e1f04809efeaa.tar.bz2
NotEnoughUpdates-c8ca57fa703011c2dcb87d9b544e1f04809efeaa.zip
Equipment Overlay Cache (#692)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java
index 4d14e47f..140c533f 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/EquipmentOverlay.java
@@ -53,7 +53,9 @@ import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
@NEUAutoSubscribe
@@ -150,6 +152,8 @@ public class EquipmentOverlay {
public ItemStack petStack;
+ private Map<String, Map<Integer, ItemStack>> profileCache = new HashMap<>();
+
//<editor-fold desc="events">
@SubscribeEvent
public void onButtonExclusionZones(ButtonExclusionZoneEvent event) {
@@ -364,6 +368,8 @@ public class EquipmentOverlay {
NEUConfig.HiddenProfileSpecific profileSpecific = NotEnoughUpdates.INSTANCE.config.getProfileSpecific();
if (profileSpecific == null) return null;
+ profileCache.putIfAbsent(lastProfile, new HashMap<>());
+ Map<Integer, ItemStack> cache = profileCache.get(lastProfile);
if (isInNamedGui("Your Equipment")) {
ItemStack itemStack = getChestSlotsAsItemStack(armourSlot);
if (itemStack != null) {
@@ -373,15 +379,21 @@ public class EquipmentOverlay {
itemToSave.add("internalname", new JsonPrimitive("_"));
}
profileSpecific.savedEquipment.put(armourSlot, itemToSave);
+ cache.put(armourSlot, itemStack);
return itemStack;
}
} else {
if (profileSpecific.savedEquipment.containsKey(armourSlot)) {
+ if (cache.containsKey(armourSlot)) {
+ return cache.get(armourSlot);
+ }
//don't use cache since the internalName is identical in most cases
- JsonObject jsonObject = profileSpecific.savedEquipment
- .get(armourSlot);
- if (jsonObject != null) return NotEnoughUpdates.INSTANCE.manager.jsonToStack(jsonObject
- .getAsJsonObject(), false);
+ JsonObject jsonObject = profileSpecific.savedEquipment.get(armourSlot);
+ if (jsonObject != null) {
+ ItemStack result = NotEnoughUpdates.INSTANCE.manager.jsonToStack(jsonObject.getAsJsonObject(), false);
+ cache.put(armourSlot, result);
+ return result;
+ }
}
}
return null;