project: Upstream merge (#1228)

* menuentryswapper - Add volcanic mine entrance to swapQuick

* idle notifier: notify when adding feathers or heads to shafts

* client: cache and reuse Graphics

* client: cache config values
This commit is contained in:
Tyler Bochard
2019-08-02 06:38:02 -04:00
committed by Kyleeld
parent 76068a9f6b
commit 4d2b9f9c17
5 changed files with 55 additions and 34 deletions

View File

@@ -71,6 +71,8 @@ public final class AnimationID
public static final int FLETCHING_STRING_YEW_LONGBOW = 6688;
public static final int FLETCHING_STRING_MAGIC_SHORTBOW = 6683;
public static final int FLETCHING_STRING_MAGIC_LONGBOW = 6689;
public static final int FLETCHING_ATTACH_FEATHERS_TO_ARROWSHAFT = 8481;
public static final int FLETCHING_ATTACH_HEADS = 8480;
public static final int GEM_CUTTING_OPAL = 890;
public static final int GEM_CUTTING_JADE = 891;
public static final int GEM_CUTTING_REDTOPAZ = 892;

View File

@@ -29,7 +29,7 @@ import java.awt.Image;
/**
* Represents the clients primary image buffer.
*/
public interface MainBufferProvider
public interface MainBufferProvider extends BufferProvider
{
/**
* Gets the image currently loaded in the buffer.

View File

@@ -128,6 +128,31 @@ public class Hooks implements Callbacks
private long lastCheck;
private boolean shouldProcessGameTick;
private static MainBufferProvider lastMainBufferProvider;
private static Graphics2D lastGraphics;
/**
* Get the Graphics2D for the MainBufferProvider image
* This caches the Graphics2D instance so it can be reused
* @param mainBufferProvider
* @return
*/
private static Graphics2D getGraphics(MainBufferProvider mainBufferProvider)
{
if (lastGraphics == null || lastMainBufferProvider != mainBufferProvider)
{
if (lastGraphics != null)
{
log.debug("Graphics reset!");
lastGraphics.dispose();
}
lastMainBufferProvider = mainBufferProvider;
lastGraphics = (Graphics2D) mainBufferProvider.getImage().getGraphics();
}
return lastGraphics;
}
@Override
public <T> void post(Class<T> eventClass, Event event)
{
@@ -293,9 +318,7 @@ public class Hooks implements Callbacks
return;
}
Image image = mainBufferProvider.getImage();
final Image finalImage;
final Graphics2D graphics2d = (Graphics2D) image.getGraphics();
final Graphics2D graphics2d = getGraphics(mainBufferProvider);
try
{
@@ -311,8 +334,6 @@ public class Hooks implements Callbacks
// Draw clientUI overlays
clientUi.paintOverlays(graphics2d);
graphics2d.dispose();
if (client.isGpu())
{
// processDrawComplete gets called on GPU by the gpu plugin at the end of its
@@ -321,6 +342,8 @@ public class Hooks implements Callbacks
}
// Stretch the game image if the user has that enabled
Image image = mainBufferProvider.getImage();
final Image finalImage;
if (client.isStretchedEnabled())
{
GraphicsConfiguration gc = clientUi.getGraphicsConfiguration();
@@ -388,8 +411,7 @@ public class Hooks implements Callbacks
public void drawScene()
{
MainBufferProvider bufferProvider = (MainBufferProvider) client.getBufferProvider();
BufferedImage image = (BufferedImage) bufferProvider.getImage();
Graphics2D graphics2d = image.createGraphics();
Graphics2D graphics2d = getGraphics(bufferProvider);
try
{
@@ -399,18 +421,13 @@ public class Hooks implements Callbacks
{
log.warn("Error during overlay rendering", ex);
}
finally
{
graphics2d.dispose();
}
}
@Override
public void drawAboveOverheads()
{
MainBufferProvider bufferProvider = (MainBufferProvider) client.getBufferProvider();
BufferedImage image = (BufferedImage) bufferProvider.getImage();
Graphics2D graphics2d = image.createGraphics();
Graphics2D graphics2d = getGraphics(bufferProvider);
try
{
@@ -420,17 +437,12 @@ public class Hooks implements Callbacks
{
log.warn("Error during overlay rendering", ex);
}
finally
{
graphics2d.dispose();
}
}
public static void drawAfterWidgets()
{
MainBufferProvider bufferProvider = (MainBufferProvider) client.getBufferProvider();
BufferedImage image = (BufferedImage) bufferProvider.getImage();
Graphics2D graphics2d = image.createGraphics();
Graphics2D graphics2d = getGraphics(bufferProvider);
try
{
@@ -441,10 +453,6 @@ public class Hooks implements Callbacks
{
log.warn("Error during overlay rendering", ex);
}
finally
{
graphics2d.dispose();
}
// WidgetItemOverlays render at ABOVE_WIDGETS, reset widget item
// list for next frame.

View File

@@ -215,7 +215,7 @@ public class IdleNotifierPlugin extends Plugin
case CRAFTING_LEATHER:
case CRAFTING_POTTERS_WHEEL:
case CRAFTING_POTTERY_OVEN:
/* Fletching(Cutting, Stringing) */
/* Fletching(Cutting, Stringing, Adding feathers and heads) */
case FLETCHING_BOW_CUTTING:
case FLETCHING_STRING_NORMAL_SHORTBOW:
case FLETCHING_STRING_OAK_SHORTBOW:
@@ -229,6 +229,8 @@ public class IdleNotifierPlugin extends Plugin
case FLETCHING_STRING_MAPLE_LONGBOW:
case FLETCHING_STRING_YEW_LONGBOW:
case FLETCHING_STRING_MAGIC_LONGBOW:
case FLETCHING_ATTACH_FEATHERS_TO_ARROWSHAFT:
case FLETCHING_ATTACH_HEADS:
/* Smithing(Anvil, Furnace, Cannonballs */
case SMITHING_ANVIL:
case SMITHING_SMELTING:

View File

@@ -34,6 +34,7 @@ import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.geom.AffineTransform;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
@@ -469,38 +470,46 @@ public class OverlayRenderer extends MouseAdapter implements KeyListener
private void safeRender(Client client, Overlay overlay, OverlayLayer layer, Graphics2D graphics, Point point)
{
final Graphics2D subGraphics = (Graphics2D) graphics.create();
if (!isResizeable && (layer == OverlayLayer.ABOVE_SCENE || layer == OverlayLayer.UNDER_WIDGETS))
{
subGraphics.setClip(client.getViewportXOffset(),
graphics.setClip(client.getViewportXOffset(),
client.getViewportYOffset(),
client.getViewportWidth(),
client.getViewportHeight());
}
else
{
graphics.setClip(0, 0, client.getCanvasWidth(), client.getCanvasHeight());
}
final OverlayPosition position = overlay.getPosition();
// Set font based on configuration
if (position == OverlayPosition.DYNAMIC || position == OverlayPosition.DETACHED)
{
subGraphics.setFont(this.standardFont); // TODO MAKE USE CONFIG SYSTEM
graphics.setFont(this.standardFont); // TODO MAKE USE CONFIG SYSTEM
}
else if (position == OverlayPosition.TOOLTIP)
{
subGraphics.setFont(this.tooltipFont);
graphics.setFont(this.tooltipFont);
}
else
{
subGraphics.setFont(this.interfaceFont);
graphics.setFont(this.interfaceFont);
}
subGraphics.translate(point.x, point.y);
// Reset the default color
graphics.setColor(Color.WHITE);
// Get transform so we can reset it after drawing
AffineTransform transform = graphics.getTransform();
graphics.translate(point.x, point.y);
final Dimension overlayDimension;
try
{
overlayDimension = overlay.render(subGraphics);
overlayDimension = overlay.render(graphics);
}
catch (Exception ex)
{
@@ -509,7 +518,7 @@ public class OverlayRenderer extends MouseAdapter implements KeyListener
}
finally
{
subGraphics.dispose();
graphics.setTransform(transform);
}
final Dimension dimension = MoreObjects.firstNonNull(overlayDimension, new Dimension());