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,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<Change> changes = new ArrayList<>();
timePath.updateAll();
for (Keyframe keyframe : positionPath.getKeyframes()) {

View File

@@ -272,7 +272,7 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline<GuiKeyframeTimeline
}
}
if (actuallyDragging) {
if (!gui.ensureEntityTracker(() -> 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);

View File

@@ -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<Double> entityTrackerLoadingProgress;
private SettableFuture<Void> 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();