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.
This commit is contained in:
Jonas Herzig
2019-06-20 17:13:03 +02:00
parent af55951f42
commit 70acd79431
3 changed files with 21 additions and 11 deletions

View File

@@ -107,10 +107,8 @@ public class SPTimeline implements PathingRegistry {
Validate.isTrue(defaultInterpolatorType != InterpolatorType.DEFAULT, "Must not be DEFAULT"); Validate.isTrue(defaultInterpolatorType != InterpolatorType.DEFAULT, "Must not be DEFAULT");
this.defaultInterpolatorType = Validate.notNull(defaultInterpolatorType); this.defaultInterpolatorType = Validate.notNull(defaultInterpolatorType);
if (entityTracker != null) {
timeline.pushChange(updateInterpolators()); timeline.pushChange(updateInterpolators());
} }
}
public Change setDefaultInterpolator(Interpolator interpolator) { public Change setDefaultInterpolator(Interpolator interpolator) {
Preconditions.checkState(defaultInterpolatorType != null, "Default interpolator type not set."); Preconditions.checkState(defaultInterpolatorType != null, "Default interpolator type not set.");
@@ -521,6 +519,9 @@ public class SPTimeline implements PathingRegistry {
} }
private Change updateSpectatorPositions() { private Change updateSpectatorPositions() {
if (entityTracker == null) {
return CombinedChange.create();
}
List<Change> changes = new ArrayList<>(); List<Change> changes = new ArrayList<>();
timePath.updateAll(); timePath.updateAll();
for (Keyframe keyframe : positionPath.getKeyframes()) { for (Keyframe keyframe : positionPath.getKeyframes()) {

View File

@@ -272,7 +272,7 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline<GuiKeyframeTimeline
} }
} }
if (actuallyDragging) { if (actuallyDragging) {
if (!gui.ensureEntityTracker(() -> mouseDrag(position, button, timeSinceLastCall))) return true; if (!gui.loadEntityTracker(() -> mouseDrag(position, button, timeSinceLastCall))) return true;
// Threshold passed // Threshold passed
SPTimeline timeline = gui.getMod().getCurrentTimeline(); SPTimeline timeline = gui.getMod().getCurrentTimeline();
Point mouse = new Point(position); Point mouse = new Point(position);

View File

@@ -265,6 +265,8 @@ public class GuiPathing {
private final ReplayHandler replayHandler; private final ReplayHandler replayHandler;
private final RealtimeTimelinePlayer player; 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 EntityPositionTracker entityTracker;
private Consumer<Double> entityTrackerLoadingProgress; private Consumer<Double> entityTrackerLoadingProgress;
private SettableFuture<Void> entityTrackerFuture; private SettableFuture<Void> entityTrackerFuture;
@@ -550,7 +552,7 @@ public class GuiPathing {
scrollbar.setZoom(scrollbar.getZoom() * factor); scrollbar.setZoom(scrollbar.getZoom() * factor);
} }
public boolean ensureEntityTracker(Runnable withDelayedTracker) { public boolean loadEntityTracker(Runnable thenRun) {
if (entityTracker == null) { if (entityTracker == null) {
LOGGER.debug("Entity tracker not yet loaded, delaying..."); LOGGER.debug("Entity tracker not yet loaded, delaying...");
LoadEntityTrackerPopup popup = new LoadEntityTrackerPopup(replayHandler.getOverlay()); LoadEntityTrackerPopup popup = new LoadEntityTrackerPopup(replayHandler.getOverlay());
@@ -562,14 +564,21 @@ public class GuiPathing {
if (mod.getCurrentTimeline().getEntityTracker() == null) { if (mod.getCurrentTimeline().getEntityTracker() == null) {
mod.getCurrentTimeline().setEntityTracker(entityTracker); mod.getCurrentTimeline().setEntityTracker(entityTracker);
} }
withDelayedTracker.run(); thenRun.run();
} }
@Override @Override
public void onFailure(@Nonnull Throwable t) { public void onFailure(@Nonnull Throwable t) {
String message = "Failed to load entity tracker, pathing will be unavailable."; if (errorShown) {
String message = "Failed to load entity tracker, spectator keyframes will be broken.";
GuiReplayOverlay overlay = replayHandler.getOverlay(); GuiReplayOverlay overlay = replayHandler.getOverlay();
Utils.error(LOGGER, overlay, CrashReport.create(t, message), popup::close); Utils.error(LOGGER, overlay, CrashReport.create(t, message), () -> {
popup.close();
thenRun.run();
});
} else {
thenRun.run();
}
} }
}); });
return false; return false;
@@ -586,7 +595,7 @@ public class GuiPathing {
*/ */
private void updateKeyframe(SPPath path) { private void updateKeyframe(SPPath path) {
LOGGER.debug("Updating keyframe on path {}" + path); LOGGER.debug("Updating keyframe on path {}" + path);
if (!ensureEntityTracker(() -> updateKeyframe(path))) return; if (!loadEntityTracker(() -> updateKeyframe(path))) return;
int time = timeline.getCursorPosition(); int time = timeline.getCursorPosition();
SPTimeline timeline = mod.getCurrentTimeline(); SPTimeline timeline = mod.getCurrentTimeline();
@@ -640,7 +649,7 @@ public class GuiPathing {
} }
public void openEditKeyframePopup(SPPath path, long time) { 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); Keyframe keyframe = mod.getCurrentTimeline().getKeyframe(path, time);
if (keyframe.getProperties().contains(SpectatorProperty.PROPERTY)) { if (keyframe.getProperties().contains(SpectatorProperty.PROPERTY)) {
new GuiEditKeyframe.Spectator(this, path, keyframe.getTime()).open(); new GuiEditKeyframe.Spectator(this, path, keyframe.getTime()).open();