herbiboar: Fix FPS drops by removing clickbox option (#1509)

* Add option to Herbiboar plugin to only show the most recent trail

* Optimize finding Herbiboar to highlight

* Fix checkstyle violation

* Use ModelOutlineRenderer to draw Herbiboar and fix review comments

* herbiboar: Improve performance by removing clickbox option

* Update HerbiboarOverlay.java

* Update HerbiboarConfig.java

* Update HerbiboarOverlay.java

* Update HerbiboarPlugin.java

* Create RenderStyle.java
This commit is contained in:
Gamer1120
2019-09-12 14:15:42 +02:00
committed by Kyle
parent de26e3a126
commit b16a7de720
5 changed files with 218 additions and 38 deletions

View File

@@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2017, Tyler <https://github.com/tylerthardy> * Copyright (c) 2017, Tyler <https://github.com/tylerthardy>
* Copyright (c) 2019, Gamer1120 <https://github.com/Gamer1120>
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -45,17 +46,30 @@ public interface HerbiboarConfig extends Config
@ConfigItem( @ConfigItem(
position = 1, position = 1,
keyName = "showClickboxes", keyName = "showOutline",
name = "Show Clickboxes", name = "Show Outlines",
description = "Show clickboxes on trail objects and tunnels instead of tiles" description = "Show outlines on trail objects and tunnels instead of tiles"
) )
default boolean showClickBoxes() default boolean showOutlines()
{ {
return false; return false;
} }
@ConfigItem( @ConfigItem(
position = 2, position = 2,
keyName = "highlightStyle",
name = "Outline Style",
description = "Outline setting",
hidden = true,
unhide = "showOutline"
)
default RenderStyle outlineStyle()
{
return RenderStyle.THIN_OUTLINE;
}
@ConfigItem(
position = 3,
keyName = "colorStart", keyName = "colorStart",
name = "Start Color", name = "Start Color",
description = "Color for rocks that start the trails" description = "Color for rocks that start the trails"
@@ -66,7 +80,7 @@ public interface HerbiboarConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 3, position = 4,
keyName = "showTunnel", keyName = "showTunnel",
name = "Show End Tunnels", name = "Show End Tunnels",
description = "Show highlights for tunnels with herbiboars" description = "Show highlights for tunnels with herbiboars"
@@ -77,7 +91,7 @@ public interface HerbiboarConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 4, position = 5,
keyName = "colorTunnel", keyName = "colorTunnel",
name = "Tunnel Color", name = "Tunnel Color",
description = "Color for tunnels with herbiboars" description = "Color for tunnels with herbiboars"
@@ -88,7 +102,7 @@ public interface HerbiboarConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 5, position = 6,
keyName = "showObject", keyName = "showObject",
name = "Show Trail Objects", name = "Show Trail Objects",
description = "Show highlights for mushrooms, mud, seaweed, etc" description = "Show highlights for mushrooms, mud, seaweed, etc"
@@ -99,7 +113,7 @@ public interface HerbiboarConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 6, position = 7,
keyName = "colorGameObject", keyName = "colorGameObject",
name = "Trail Object Color", name = "Trail Object Color",
description = "Color for mushrooms, mud, seaweed, etc" description = "Color for mushrooms, mud, seaweed, etc"
@@ -110,7 +124,7 @@ public interface HerbiboarConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 7, position = 8,
keyName = "showTrail", keyName = "showTrail",
name = "Show Trail", name = "Show Trail",
description = "Show highlights for trail prints" description = "Show highlights for trail prints"
@@ -121,7 +135,18 @@ public interface HerbiboarConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 8, position = 9,
keyName = "showOnlyCurrentTrail",
name = "Show Current Trail Only",
description = "Only show the trail that you currently have to follow to get to the next object you have to inspect. Requires that the \"Show Trail\" option is enabled"
)
default boolean isOnlyCurrentTrailShown()
{
return false;
}
@ConfigItem(
position = 10,
keyName = "colorTrail", keyName = "colorTrail",
name = "Trail Color", name = "Trail Color",
description = "Color for mushrooms, mud, seaweed, etc" description = "Color for mushrooms, mud, seaweed, etc"

View File

@@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018, Kamiel * Copyright (c) 2018, Kamiel
* Copyright (c) 2019, Gamer1120 <https://github.com/Gamer1120>
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -55,7 +56,15 @@ public class HerbiboarMinimapOverlay extends Overlay
{ {
HerbiboarTrail currentTrail = plugin.getCurrentTrail(); HerbiboarTrail currentTrail = plugin.getCurrentTrail();
int finishId = plugin.getFinishId(); int finishId = plugin.getFinishId();
Set<Integer> shownTrailIds = plugin.getShownTrails(); Set<Integer> shownTrailIds;
if (plugin.isOnlyCurrentTrailShown())
{
shownTrailIds = plugin.getCurrentTrailIds();
}
else
{
shownTrailIds = plugin.getShownTrails();
}
for (TileObject tileObject : plugin.getTrails().values()) for (TileObject tileObject : plugin.getTrails().values())
{ {

View File

@@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2017, Tyler <https://github.com/tylerthardy> * Copyright (c) 2017, Tyler <https://github.com/tylerthardy>
* Copyright (c) 2019, Gamer1120 <https://github.com/Gamer1120>
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -29,10 +30,13 @@ import com.google.inject.Singleton;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.geom.Area;
import java.util.Set; import java.util.Set;
import net.runelite.api.Client;
import net.runelite.api.NPC;
import net.runelite.api.NpcID;
import net.runelite.api.TileObject; import net.runelite.api.TileObject;
import net.runelite.api.coords.WorldPoint; import net.runelite.api.coords.WorldPoint;
import net.runelite.client.graphics.ModelOutlineRenderer;
import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer; import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.OverlayPosition;
@@ -41,14 +45,21 @@ import net.runelite.client.ui.overlay.OverlayUtil;
@Singleton @Singleton
class HerbiboarOverlay extends Overlay class HerbiboarOverlay extends Overlay
{ {
private static final Color TRANSPARENT = new Color(0, 0, 0, 0);
private Client client;
private final HerbiboarPlugin plugin; private final HerbiboarPlugin plugin;
private final ModelOutlineRenderer modelOutlineRenderer;
@Inject @Inject
public HerbiboarOverlay(final HerbiboarPlugin plugin) public HerbiboarOverlay(final HerbiboarPlugin plugin, ModelOutlineRenderer modelOutlineRenderer, Client client)
{ {
setPosition(OverlayPosition.DYNAMIC); setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_SCENE); setLayer(OverlayLayer.ABOVE_SCENE);
this.plugin = plugin; this.plugin = plugin;
this.modelOutlineRenderer = modelOutlineRenderer;
this.client = client;
} }
@Override @Override
@@ -64,16 +75,24 @@ class HerbiboarOverlay extends Overlay
int finishId = plugin.getFinishId(); int finishId = plugin.getFinishId();
// Draw start objects // Draw start objects
if (plugin.isStartShown() && (currentTrail == null && finishId == 0)) if (plugin.isStartShown() && currentTrail == null && finishId == 0 && !plugin.isHerbiboarRendered())
{ {
plugin.getStarts().values().forEach((obj) -> plugin.getStarts().values().forEach((obj) ->
OverlayUtil.renderTileOverlay(graphics, obj, "", plugin.getGetStartColor())); OverlayUtil.renderTileOverlay(graphics, obj, "", plugin.getGetStartColor()));
} }
// Draw trails // Draw trails
Set<Integer> shownTrailIds;
if (plugin.isTrailShown()) if (plugin.isTrailShown())
{ {
Set<Integer> shownTrailIds = plugin.getShownTrails(); if (plugin.isOnlyCurrentTrailShown())
{
shownTrailIds = plugin.getCurrentTrailIds();
}
else
{
shownTrailIds = plugin.getShownTrails();
}
plugin.getTrails().values().forEach((x) -> plugin.getTrails().values().forEach((x) ->
{ {
int id = x.getId(); int id = x.getId();
@@ -97,18 +116,12 @@ class HerbiboarOverlay extends Overlay
} }
TileObject object = plugin.getTrailObjects().get(trailLoc); TileObject object = plugin.getTrailObjects().get(trailLoc);
if (object != null) if (object != null)
{ {
if (plugin.isShowClickBoxes()) if (plugin.isShowOutlines())
{ {
Area clickbox = object.getClickbox(); renderOutline(object, new Color(255, 0, 255, 20));
if (clickbox != null)
{
graphics.setColor(plugin.getGetObjectColor());
graphics.draw(clickbox);
graphics.setColor(new Color(255, 0, 255, 20));
graphics.fill(clickbox);
}
} }
else else
{ {
@@ -125,17 +138,10 @@ class HerbiboarOverlay extends Overlay
TileObject object = plugin.getTunnels().get(finishLoc); TileObject object = plugin.getTunnels().get(finishLoc);
if (object != null) if (object != null)
{ {
if (plugin.isShowClickBoxes()) if (plugin.isShowOutlines())
{ {
Area clickbox = object.getClickbox(); Color col = plugin.getGetObjectColor();
if (clickbox != null) renderOutline(object, new Color(col.getRed(), col.getGreen(), col.getBlue(), 20));
{
Color col = plugin.getGetObjectColor();
graphics.setColor(col);
graphics.draw(clickbox);
graphics.setColor(new Color(col.getRed(), col.getGreen(), col.getBlue(), 20));
graphics.fill(clickbox);
}
} }
else else
{ {
@@ -144,6 +150,39 @@ class HerbiboarOverlay extends Overlay
} }
} }
// Draw herbiboar
if (plugin.isHerbiboarRendered())
{
for (NPC npc : client.getNpcs())
{
if (npc.getId() == NpcID.HERBIBOAR || npc.getId() == NpcID.HERBIBOAR_7786)
{
modelOutlineRenderer.drawOutline(npc, 2, plugin.getGetObjectColor());
}
}
}
return null; return null;
} }
private void renderOutline(TileObject object, Color color)
{
switch (plugin.getOutlineStyle())
{
case THIN_OUTLINE:
modelOutlineRenderer.drawOutline(object, 1, color);
break;
case OUTLINE:
modelOutlineRenderer.drawOutline(object, 2, color);
break;
case THIN_GLOW:
modelOutlineRenderer.drawOutline(object, 4, color, TRANSPARENT);
break;
case GLOW:
modelOutlineRenderer.drawOutline(object, 8, color, TRANSPARENT);
break;
}
}
} }

View File

@@ -38,6 +38,8 @@ import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.NPC;
import net.runelite.api.NpcID;
import static net.runelite.api.ObjectID.DRIFTWOOD_30523; import static net.runelite.api.ObjectID.DRIFTWOOD_30523;
import static net.runelite.api.ObjectID.MUSHROOM_30520; import static net.runelite.api.ObjectID.MUSHROOM_30520;
import static net.runelite.api.ObjectID.ROCK_30519; import static net.runelite.api.ObjectID.ROCK_30519;
@@ -47,6 +49,7 @@ import net.runelite.api.Tile;
import net.runelite.api.TileObject; import net.runelite.api.TileObject;
import net.runelite.api.Varbits; import net.runelite.api.Varbits;
import net.runelite.api.coords.WorldPoint; import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.AnimationChanged;
import net.runelite.api.events.ConfigChanged; import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.GameObjectChanged; import net.runelite.api.events.GameObjectChanged;
import net.runelite.api.events.GameObjectDespawned; import net.runelite.api.events.GameObjectDespawned;
@@ -146,11 +149,21 @@ public class HerbiboarPlugin extends Plugin
@Setter(AccessLevel.PACKAGE) @Setter(AccessLevel.PACKAGE)
private int finishId; private int finishId;
@Getter
@Setter
private Set<Integer> previousShownTrailIds;
@Getter
@Setter
private Integer previousTrailId = null;
@Getter
@Setter
private boolean herbiboarRendered = false;
@Getter(AccessLevel.PACKAGE) @Getter(AccessLevel.PACKAGE)
private boolean isStartShown; private boolean isStartShown;
@Getter(AccessLevel.PACKAGE) @Getter(AccessLevel.PACKAGE)
private boolean showClickBoxes;
@Getter(AccessLevel.PACKAGE)
private Color getStartColor; private Color getStartColor;
@Getter(AccessLevel.PACKAGE) @Getter(AccessLevel.PACKAGE)
private boolean isTunnelShown; private boolean isTunnelShown;
@@ -164,6 +177,12 @@ public class HerbiboarPlugin extends Plugin
private boolean isTrailShown; private boolean isTrailShown;
@Getter(AccessLevel.PACKAGE) @Getter(AccessLevel.PACKAGE)
private Color getTrailColor; private Color getTrailColor;
@Getter(AccessLevel.PACKAGE)
private boolean isOnlyCurrentTrailShown;
@Getter(AccessLevel.PACKAGE)
private boolean showOutlines;
@Getter(AccessLevel.PACKAGE)
private RenderStyle outlineStyle;
@Provides @Provides
HerbiboarConfig getConfig(ConfigManager configManager) HerbiboarConfig getConfig(ConfigManager configManager)
@@ -196,6 +215,7 @@ public class HerbiboarPlugin extends Plugin
eventBus.subscribe(ConfigChanged.class, this, this::onConfigChanged); eventBus.subscribe(ConfigChanged.class, this, this::onConfigChanged);
eventBus.subscribe(GameStateChanged.class, this, this::onGameStateChanged); eventBus.subscribe(GameStateChanged.class, this, this::onGameStateChanged);
eventBus.subscribe(VarbitChanged.class, this, this::onVarbitChanged); eventBus.subscribe(VarbitChanged.class, this, this::onVarbitChanged);
eventBus.subscribe(AnimationChanged.class, this, this::onAnimationChanged);
eventBus.subscribe(GameObjectSpawned.class, this, this::onGameObjectSpawned); eventBus.subscribe(GameObjectSpawned.class, this, this::onGameObjectSpawned);
eventBus.subscribe(GameObjectChanged.class, this, this::onGameObjectChanged); eventBus.subscribe(GameObjectChanged.class, this, this::onGameObjectChanged);
eventBus.subscribe(GameObjectDespawned.class, this, this::onGameObjectDespawned); eventBus.subscribe(GameObjectDespawned.class, this, this::onGameObjectDespawned);
@@ -242,6 +262,44 @@ public class HerbiboarPlugin extends Plugin
{ {
resetTrailData(); resetTrailData();
} }
}
public Set<Integer> getCurrentTrailIds()
{
Set<Integer> shownTrailIds;
if (currentTrail == null)
{
if (finishId <= 0)
{
previousTrailId = null;
shownTrailIds = new HashSet<>();
}
else
{
shownTrailIds = new HashSet<>();
shownTrailIds.add(previousTrailId);
shownTrailIds.add(previousTrailId + 1);
}
}
else if (previousTrailId == null)
{
previousTrailId = currentTrail.getTrailId();
shownTrailIds = getShownTrails();
}
else if (currentTrail.getTrailId() == previousTrailId)
{
shownTrailIds = previousShownTrailIds;
}
else
{
shownTrailIds = new HashSet<>();
shownTrailIds.add(previousTrailId);
shownTrailIds.add(previousTrailId + 1);
previousTrailId = currentTrail.getTrailId();
}
previousShownTrailIds = shownTrailIds;
return shownTrailIds;
} }
private void resetTrailData() private void resetTrailData()
@@ -290,6 +348,31 @@ public class HerbiboarPlugin extends Plugin
onGameObject(event.getTile(), null, event.getGameObject()); onGameObject(event.getTile(), null, event.getGameObject());
} }
public void onAnimationChanged(AnimationChanged event)
{
if (!(event.getActor() instanceof NPC))
{
return;
}
NPC npc = (NPC) event.getActor();
// Herbiboar spawns
if (npc.getId() == NpcID.HERBIBOAR_7786 && npc.getAnimation() == 7687)
{
herbiboarRendered = true;
}
// Herbiboar is stunned
else if (npc.getId() == NpcID.HERBIBOAR && npc.getAnimation() == 7689)
{
herbiboarRendered = true;
}
// Herbiboar is harvested
else if (npc.getId() == NpcID.HERBIBOAR_7786 && npc.getAnimation() == 7690)
{
herbiboarRendered = false;
}
}
private void onGameObjectChanged(GameObjectChanged event) private void onGameObjectChanged(GameObjectChanged event)
{ {
onGameObject(event.getTile(), event.getPrevious(), event.getGameObject()); onGameObject(event.getTile(), event.getPrevious(), event.getGameObject());
@@ -404,7 +487,6 @@ public class HerbiboarPlugin extends Plugin
private void updateConfig() private void updateConfig()
{ {
this.isStartShown = config.isStartShown(); this.isStartShown = config.isStartShown();
this.showClickBoxes = config.showClickBoxes();
this.getStartColor = config.getStartColor(); this.getStartColor = config.getStartColor();
this.isTunnelShown = config.isTunnelShown(); this.isTunnelShown = config.isTunnelShown();
this.getTunnelColor = config.getTunnelColor(); this.getTunnelColor = config.getTunnelColor();
@@ -412,5 +494,8 @@ public class HerbiboarPlugin extends Plugin
this.getObjectColor = config.getObjectColor(); this.getObjectColor = config.getObjectColor();
this.isTrailShown = config.isTrailShown(); this.isTrailShown = config.isTrailShown();
this.getTrailColor = config.getTrailColor(); this.getTrailColor = config.getTrailColor();
this.isOnlyCurrentTrailShown = config.isOnlyCurrentTrailShown();
this.showOutlines = config.showOutlines();
this.outlineStyle = config.outlineStyle();
} }
} }

View File

@@ -0,0 +1,22 @@
package net.runelite.client.plugins.herbiboars;
public enum RenderStyle
{
THIN_OUTLINE("Thin outline"),
OUTLINE("Outline"),
THIN_GLOW("Thin glow"),
GLOW("Glow");
private final String name;
RenderStyle(final String name)
{
this.name = name;
}
@Override
public String toString()
{
return name;
}
}