From 70acd7943183d26e7335b7302a162574a84e2851 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Thu, 20 Jun 2019 17:13:03 +0200 Subject: [PATCH] Allow continued use of most of pathing even if entity tracker fails The failing entity tracker really only breaks spectator keyframes. This is also very desirable for minimal mode where entity tracker failure is highly likely. --- .../replaymod/simplepathing/SPTimeline.java | 7 +++--- .../gui/GuiKeyframeTimeline.java | 2 +- .../simplepathing/gui/GuiPathing.java | 23 +++++++++++++------ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/replaymod/simplepathing/SPTimeline.java b/src/main/java/com/replaymod/simplepathing/SPTimeline.java index f0223ed0..b3ab522c 100644 --- a/src/main/java/com/replaymod/simplepathing/SPTimeline.java +++ b/src/main/java/com/replaymod/simplepathing/SPTimeline.java @@ -107,9 +107,7 @@ public class SPTimeline implements PathingRegistry { Validate.isTrue(defaultInterpolatorType != InterpolatorType.DEFAULT, "Must not be DEFAULT"); this.defaultInterpolatorType = Validate.notNull(defaultInterpolatorType); - if (entityTracker != null) { - timeline.pushChange(updateInterpolators()); - } + timeline.pushChange(updateInterpolators()); } public Change setDefaultInterpolator(Interpolator interpolator) { @@ -521,6 +519,9 @@ public class SPTimeline implements PathingRegistry { } private Change updateSpectatorPositions() { + if (entityTracker == null) { + return CombinedChange.create(); + } List changes = new ArrayList<>(); timePath.updateAll(); for (Keyframe keyframe : positionPath.getKeyframes()) { diff --git a/src/main/java/com/replaymod/simplepathing/gui/GuiKeyframeTimeline.java b/src/main/java/com/replaymod/simplepathing/gui/GuiKeyframeTimeline.java index 413cb501..b152202b 100644 --- a/src/main/java/com/replaymod/simplepathing/gui/GuiKeyframeTimeline.java +++ b/src/main/java/com/replaymod/simplepathing/gui/GuiKeyframeTimeline.java @@ -272,7 +272,7 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline mouseDrag(position, button, timeSinceLastCall))) return true; + if (!gui.loadEntityTracker(() -> mouseDrag(position, button, timeSinceLastCall))) return true; // Threshold passed SPTimeline timeline = gui.getMod().getCurrentTimeline(); Point mouse = new Point(position); diff --git a/src/main/java/com/replaymod/simplepathing/gui/GuiPathing.java b/src/main/java/com/replaymod/simplepathing/gui/GuiPathing.java index 50730f81..87722653 100644 --- a/src/main/java/com/replaymod/simplepathing/gui/GuiPathing.java +++ b/src/main/java/com/replaymod/simplepathing/gui/GuiPathing.java @@ -265,6 +265,8 @@ public class GuiPathing { private final ReplayHandler replayHandler; private final RealtimeTimelinePlayer player; + // Whether any error which occured during entity tracker loading has already been shown to the user + private boolean errorShown; private EntityPositionTracker entityTracker; private Consumer entityTrackerLoadingProgress; private SettableFuture entityTrackerFuture; @@ -550,7 +552,7 @@ public class GuiPathing { scrollbar.setZoom(scrollbar.getZoom() * factor); } - public boolean ensureEntityTracker(Runnable withDelayedTracker) { + public boolean loadEntityTracker(Runnable thenRun) { if (entityTracker == null) { LOGGER.debug("Entity tracker not yet loaded, delaying..."); LoadEntityTrackerPopup popup = new LoadEntityTrackerPopup(replayHandler.getOverlay()); @@ -562,14 +564,21 @@ public class GuiPathing { if (mod.getCurrentTimeline().getEntityTracker() == null) { mod.getCurrentTimeline().setEntityTracker(entityTracker); } - withDelayedTracker.run(); + thenRun.run(); } @Override public void onFailure(@Nonnull Throwable t) { - String message = "Failed to load entity tracker, pathing will be unavailable."; - GuiReplayOverlay overlay = replayHandler.getOverlay(); - Utils.error(LOGGER, overlay, CrashReport.create(t, message), popup::close); + if (errorShown) { + String message = "Failed to load entity tracker, spectator keyframes will be broken."; + GuiReplayOverlay overlay = replayHandler.getOverlay(); + Utils.error(LOGGER, overlay, CrashReport.create(t, message), () -> { + popup.close(); + thenRun.run(); + }); + } else { + thenRun.run(); + } } }); return false; @@ -586,7 +595,7 @@ public class GuiPathing { */ private void updateKeyframe(SPPath path) { LOGGER.debug("Updating keyframe on path {}" + path); - if (!ensureEntityTracker(() -> updateKeyframe(path))) return; + if (!loadEntityTracker(() -> updateKeyframe(path))) return; int time = timeline.getCursorPosition(); SPTimeline timeline = mod.getCurrentTimeline(); @@ -640,7 +649,7 @@ public class GuiPathing { } public void openEditKeyframePopup(SPPath path, long time) { - if (!ensureEntityTracker(() -> openEditKeyframePopup(path, time))) return; + if (!loadEntityTracker(() -> openEditKeyframePopup(path, time))) return; Keyframe keyframe = mod.getCurrentTimeline().getKeyframe(path, time); if (keyframe.getProperties().contains(SpectatorProperty.PROPERTY)) { new GuiEditKeyframe.Spectator(this, path, keyframe.getTime()).open();