WorldMapPlugin: Cache icons, don't get icons on edt

This commit is contained in:
Lucwousin
2019-10-15 12:41:35 +02:00
parent 3b9a5df8b1
commit 535fccde53
3 changed files with 51 additions and 26 deletions

View File

@@ -25,8 +25,10 @@
*/
package net.runelite.client.plugins.worldmap;
import java.awt.image.BufferedImage;
import lombok.Getter;
import net.runelite.api.coords.WorldPoint;
import net.runelite.client.util.ImageUtil;
@Getter
enum TeleportLocationData
@@ -188,6 +190,24 @@ enum TeleportLocationData
private final String tooltip;
private final WorldPoint location;
private final String iconPath;
private BufferedImage image;
BufferedImage getImage()
{
if (image == null)
{
try
{
image = ImageUtil.getResourceStreamFromClass(WorldMapPlugin.class, this.getIconPath());
}
catch (RuntimeException e)
{
return WorldMapPlugin.BLANK_ICON;
}
}
return image;
}
TeleportLocationData(TeleportType type, String destination, int magicLevel, WorldPoint location, String iconPath)
{

View File

@@ -26,14 +26,12 @@
package net.runelite.client.plugins.worldmap;
import net.runelite.client.ui.overlay.worldmap.WorldMapPoint;
import net.runelite.client.util.ImageUtil;
class TeleportPoint extends WorldMapPoint
{
TeleportPoint(TeleportLocationData data)
{
super(data.getLocation(), WorldMapPlugin.BLANK_ICON);
super(data.getLocation(), data.getImage());
setTooltip(data.getTooltip());
setImage(ImageUtil.getResourceStreamFromClass(WorldMapPlugin.class, data.getIconPath()));
}
}

View File

@@ -29,6 +29,7 @@ import com.google.inject.Inject;
import com.google.inject.Provides;
import java.awt.image.BufferedImage;
import java.util.Arrays;
import java.util.concurrent.ScheduledExecutorService;
import net.runelite.api.Client;
import net.runelite.api.Experience;
import net.runelite.api.GameState;
@@ -127,6 +128,9 @@ public class WorldMapPlugin extends Plugin
@Inject
private EventBus eventBus;
@Inject
private ScheduledExecutorService executor;
private int agilityLevel = 0;
private int woodcuttingLevel = 0;
@@ -308,30 +312,33 @@ public class WorldMapPlugin extends Plugin
}
worldMapPointManager.removeIf(TeleportPoint.class::isInstance);
Arrays.stream(TeleportLocationData.values())
.filter(data ->
{
switch (data.getType())
// This next part gets 142 icons from disk, and does so on the EDT (at first run)
executor.submit(() ->
Arrays.stream(TeleportLocationData.values())
.filter(data ->
{
case NORMAL_MAGIC:
return this.normalTeleportIcon;
case ANCIENT_MAGICKS:
return this.ancientTeleportIcon;
case LUNAR_MAGIC:
return this.lunarTeleportIcon;
case ARCEUUS_MAGIC:
return this.arceuusTeleportIcon;
case JEWELLERY:
return this.jewelleryTeleportIcon;
case SCROLL:
return this.scrollTeleportIcon;
case OTHER:
return this.miscellaneousTeleportIcon;
default:
return false;
}
}).map(TeleportPoint::new)
.forEach(worldMapPointManager::add);
switch (data.getType())
{
case NORMAL_MAGIC:
return this.normalTeleportIcon;
case ANCIENT_MAGICKS:
return this.ancientTeleportIcon;
case LUNAR_MAGIC:
return this.lunarTeleportIcon;
case ARCEUUS_MAGIC:
return this.arceuusTeleportIcon;
case JEWELLERY:
return this.jewelleryTeleportIcon;
case SCROLL:
return this.scrollTeleportIcon;
case OTHER:
return this.miscellaneousTeleportIcon;
default:
return false;
}
}).map(TeleportPoint::new)
.forEach(worldMapPointManager::add)
);
}
private void updateQuestStartPointIcons()