Merge remote-tracking branch 'runelite/master'

This commit is contained in:
Owain van Brakel
2021-11-17 16:35:59 +01:00
28 changed files with 154 additions and 116 deletions

View File

@@ -100,7 +100,7 @@ public class EventBus
{
final ImmutableMultimap.Builder<Class<?>, Subscriber> builder = ImmutableMultimap.builder();
builder.putAll(subscribers);
builder.orderValuesBy(Comparator.comparing(Subscriber::getPriority).reversed()
builder.orderValuesBy(Comparator.comparingDouble(Subscriber::getPriority).reversed()
.thenComparing(s -> s.object.getClass().getName()));
for (Class<?> clazz = object.getClass(); clazz != null; clazz = clazz.getSuperclass())
@@ -168,7 +168,7 @@ public class EventBus
{
final ImmutableMultimap.Builder<Class<?>, Subscriber> builder = ImmutableMultimap.builder();
builder.putAll(subscribers);
builder.orderValuesBy(Comparator.comparing(Subscriber::getPriority).reversed()
builder.orderValuesBy(Comparator.comparingDouble(Subscriber::getPriority).reversed()
.thenComparing(s -> s.object.getClass().getName()));
Subscriber sub = new Subscriber(subFn, null, priority, (Consumer<Object>) subFn);

View File

@@ -546,8 +546,8 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener
Widget[] containerChildren = itemContainer.getDynamicChildren();
// sort the child array as the items are not in the displayed order
Arrays.sort(containerChildren, Comparator.comparing(Widget::getOriginalY)
.thenComparing(Widget::getOriginalX));
Arrays.sort(containerChildren, Comparator.comparingInt(Widget::getOriginalY)
.thenComparingInt(Widget::getOriginalX));
for (Widget child : containerChildren)
{

View File

@@ -436,9 +436,9 @@ class WidgetInspector extends DevToolsFrame
parent = Stream.of(roots)
.filter(w -> w.getType() == WidgetType.LAYER && w.getContentType() == 0 && !w.isSelfHidden())
.sorted(Comparator.comparing((Widget w) -> w.getRelativeX() + w.getRelativeY())
.sorted(Comparator.comparingInt((Widget w) -> w.getRelativeX() + w.getRelativeY())
.reversed()
.thenComparing(Widget::getId)
.thenComparingInt(Widget::getId)
.reversed())
.findFirst().get();
x = 4;

View File

@@ -462,14 +462,14 @@ public class FishingPlugin extends Plugin
final LocalPoint cameraPoint = new LocalPoint(client.getCameraX(), client.getCameraY());
fishingSpots.sort(
Comparator.comparing(
Comparator.comparingInt(
// Negate to have the furthest first
(NPC npc) -> -npc.getLocalLocation().distanceTo(cameraPoint))
// Order by position
.thenComparing(NPC::getLocalLocation, Comparator.comparing(LocalPoint::getX)
.thenComparing(LocalPoint::getY))
.thenComparing(NPC::getLocalLocation, Comparator.comparingInt(LocalPoint::getX)
.thenComparingInt(LocalPoint::getY))
// And then by id
.thenComparing(NPC::getId)
.thenComparingInt(NPC::getId)
);
}
}

View File

@@ -394,9 +394,7 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
this.gl = glContext.getGL().getGL4();
final boolean unlockFps = this.config.unlockFps();
client.setUnlockedFps(unlockFps);
gl.setSwapInterval(unlockFps ? -1 : 0);
setupSyncMode();
if (log.isDebugEnabled())
{
@@ -556,18 +554,43 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
{
if (configChanged.getGroup().equals(GpuPluginConfig.GROUP))
{
if (configChanged.getKey().equals("unlockFps"))
if (configChanged.getKey().equals("unlockFps")
|| configChanged.getKey().equals("vsyncMode")
|| configChanged.getKey().equals("fpsTarget"))
{
boolean unlockFps = Boolean.parseBoolean(configChanged.getNewValue());
clientThread.invokeLater(() ->
{
client.setUnlockedFps(unlockFps);
invokeOnMainThread(() -> gl.setSwapInterval(unlockFps ? -1 : 0));
});
log.debug("Rebuilding sync mode");
clientThread.invokeLater(() -> invokeOnMainThread(this::setupSyncMode));
}
}
}
private void setupSyncMode()
{
final boolean unlockFps = config.unlockFps();
client.setUnlockedFps(unlockFps);
// Without unlocked fps, the client manages sync on its 20ms timer
GpuPluginConfig.SyncMode syncMode = unlockFps
? this.config.syncMode()
: GpuPluginConfig.SyncMode.OFF;
switch (syncMode)
{
case ON:
gl.setSwapInterval(1);
client.setUnlockedFpsTarget(0);
break;
case OFF:
gl.setSwapInterval(0);
client.setUnlockedFpsTarget(config.fpsTarget()); // has no effect with unlockFps=false
break;
case ADAPTIVE:
gl.setSwapInterval(-1);
client.setUnlockedFpsTarget(0);
break;
}
}
private void initProgram() throws ShaderException
{
String versionHeader = OSType.getOSType() == OSType.Linux ? LINUX_VERSION_HEADER : WINDOWS_VERSION_HEADER;

View File

@@ -159,4 +159,37 @@ public interface GpuPluginConfig extends Config
{
return false;
}
enum SyncMode
{
OFF,
ON,
ADAPTIVE
}
@ConfigItem(
keyName = "vsyncMode",
name = "Vsync Mode",
description = "Method to synchronize frame rate with refresh rate",
position = 11
)
default SyncMode syncMode()
{
return SyncMode.ADAPTIVE;
}
@ConfigItem(
keyName = "fpsTarget",
name = "FPS Target",
description = "Target FPS when unlock FPS is enabled and Vsync mode is OFF",
position = 12
)
@Range(
min = 1,
max = 999
)
default int fpsTarget()
{
return 60;
}
}

View File

@@ -72,7 +72,7 @@ public class SaradominBrew implements Effect
).toArray(StatChange[]::new));
changes.setPositivity(Stream.of(changes.getStatChanges())
.map(sc -> sc.getPositivity())
.max(Comparator.comparing(Enum::ordinal)).get());
.max(Comparator.naturalOrder()).get());
return changes;
}
}

View File

@@ -68,7 +68,9 @@ public class SuperRestore implements Effect
return calc.effect(client);
})
).toArray(StatChange[]::new));
changes.setPositivity(Stream.of(changes.getStatChanges()).map(sc -> sc.getPositivity()).max(Comparator.comparing(Enum::ordinal)).get());
changes.setPositivity(Stream.of(changes.getStatChanges())
.map(sc -> sc.getPositivity())
.max(Comparator.naturalOrder()).get());
return changes;
}

View File

@@ -61,7 +61,7 @@ public class CastleWarsBandage implements Effect
changes.setStatChanges(new StatChange[]{hitPoints, runEnergy});
changes.setPositivity(Stream.of(changes.getStatChanges())
.map(StatChange::getPositivity)
.max(Comparator.comparing(Enum::ordinal)).get());
.max(Comparator.naturalOrder()).get());
return changes;
}

View File

@@ -418,7 +418,7 @@ public class MusicPlugin extends Plugin
if (tracks == null)
{
tracks = Arrays.stream(musicList.getDynamicChildren())
.sorted(Comparator.comparing(Widget::getRelativeY))
.sorted(Comparator.comparingInt(Widget::getRelativeY))
.collect(Collectors.toList());
}

View File

@@ -336,7 +336,7 @@ public class QuestListPlugin extends Plugin
{
// Find all of the widgets that we care about, sorting by their Y value
quests = Arrays.stream(list.getDynamicChildren())
.sorted(Comparator.comparing(Widget::getRelativeY))
.sorted(Comparator.comparingInt(Widget::getRelativeY))
.filter(w -> !QUEST_HEADERS.contains(w.getText()))
.map(w -> new QuestWidget(w, Text.removeTags(w.getText()).toLowerCase()))
.collect(Collectors.toList());

View File

@@ -72,7 +72,8 @@ public class SpecialCounterPlugin extends Plugin
{
private static final Set<Integer> IGNORED_NPCS = ImmutableSet.of(
NpcID.DARK_ENERGY_CORE, NpcID.ZOMBIFIED_SPAWN, NpcID.ZOMBIFIED_SPAWN_8063,
NpcID.COMBAT_DUMMY, NpcID.UNDEAD_COMBAT_DUMMY
NpcID.COMBAT_DUMMY, NpcID.UNDEAD_COMBAT_DUMMY,
NpcID.SKELETON_HELLHOUND_6613, NpcID.GREATER_SKELETON_HELLHOUND
);
private static final Set<Integer> RESET_ON_LEAVE_INSTANCED_REGIONS = ImmutableSet.of(

View File

@@ -29,9 +29,11 @@ import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
@ConfigGroup("timestamp")
@ConfigGroup(TimestampConfig.GROUP)
public interface TimestampConfig extends Config
{
String GROUP = "timestamp";
@ConfigItem(
keyName = "opaqueTimestamp",
name = "Timestamps (opaque)",

View File

@@ -38,11 +38,11 @@ import net.runelite.api.Client;
import net.runelite.api.MessageNode;
import net.runelite.api.ScriptID;
import net.runelite.api.Varbits;
import net.runelite.api.events.ScriptPreFired;
import net.runelite.client.events.ConfigChanged;
import net.runelite.api.events.ScriptCallbackEvent;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ConfigChanged;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.util.ColorUtil;
@@ -58,14 +58,15 @@ public class TimestampPlugin extends Plugin
@Inject
private Client client;
@Inject
private ClientThread clientThread;
@Inject
private TimestampConfig config;
@Getter
private SimpleDateFormat formatter;
private MessageNode currentlyBuildingMessage = null;
@Provides
public TimestampConfig provideConfig(final ConfigManager configManager)
{
@@ -87,9 +88,18 @@ public class TimestampPlugin extends Plugin
@Subscribe
public void onConfigChanged(ConfigChanged event)
{
if (event.getGroup().equals("timestamp") && event.getKey().equals("format"))
if (event.getGroup().equals(TimestampConfig.GROUP))
{
updateFormatter();
switch (event.getKey())
{
case "format":
updateFormatter();
break;
case "opaqueTimestamp":
case "transparentTimestamp":
clientThread.invokeLater(() -> client.runScript(ScriptID.SPLITPM_CHANGED));
break;
}
}
}
@@ -102,51 +112,18 @@ public class TimestampPlugin extends Plugin
}
int uid = client.getIntStack()[client.getIntStackSize() - 1];
currentlyBuildingMessage = client.getMessages().get(uid);
}
final MessageNode messageNode = client.getMessages().get(uid);
assert messageNode != null : "chat message build for unknown message";
@Subscribe
private void onScriptPreFired(ScriptPreFired ev)
{
int numStringArgs;
int messagePrefixArg = 0;
switch (ev.getScriptId())
{
case ScriptID.CHATBOX_BUILD_LINE_WITHOUT_USER:
numStringArgs = 1;
break;
case ScriptID.CHATBOX_BUILD_LINE_WITH_USER:
numStringArgs = 2;
break;
case ScriptID.CHATBOX_BUILD_LINE_WITH_CLAN:
numStringArgs = 3;
break;
default:
return;
}
if (currentlyBuildingMessage == null)
{
return;
}
MessageNode messageNode = currentlyBuildingMessage;
currentlyBuildingMessage = null;
String[] stringStack = client.getStringStack();
int stringArgStart = client.getStringStackSize() - numStringArgs;
String timestamp = generateTimestamp(messageNode.getTimestamp(), ZoneId.systemDefault()) + " ";
String timestamp = generateTimestamp(messageNode.getTimestamp(), ZoneId.systemDefault());
Color timestampColour = getTimestampColour();
if (timestampColour != null)
{
timestamp = ColorUtil.wrapWithColorTag(timestamp, timestampColour);
}
String segment = stringStack[stringArgStart + messagePrefixArg];
segment = timestamp + segment;
stringStack[stringArgStart + messagePrefixArg] = segment;
client.getStringStack()[client.getStringStackSize() - 1] = timestamp;
}
private Color getTimestampColour()

View File

@@ -282,7 +282,7 @@ public class ContainableFrame extends JFrame
{
return Arrays.stream(GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices())
.map(GraphicsDevice::getDefaultConfiguration)
.max(Comparator.comparing(config ->
.max(Comparator.comparingInt(config ->
{
Rectangle intersection = config.getBounds().intersection(getBounds());
return intersection.width * intersection.height;