The PathPreviewRenderer now uses the ReplayHandler's AdvancedPositionKeyframeList's interpolation methods instead of manually handling spectator keyframes

This commit is contained in:
CrushedPixel
2015-09-10 13:02:49 +02:00
parent bfc591e7b6
commit b99d49ee72

View File

@@ -6,7 +6,7 @@ import eu.crushedpixel.replaymod.gui.overlay.GuiReplayOverlay;
import eu.crushedpixel.replaymod.holders.AdvancedPosition; import eu.crushedpixel.replaymod.holders.AdvancedPosition;
import eu.crushedpixel.replaymod.holders.Keyframe; import eu.crushedpixel.replaymod.holders.Keyframe;
import eu.crushedpixel.replaymod.holders.SpectatorData; import eu.crushedpixel.replaymod.holders.SpectatorData;
import eu.crushedpixel.replaymod.interpolation.KeyframeList; import eu.crushedpixel.replaymod.interpolation.AdvancedPositionKeyframeList;
import eu.crushedpixel.replaymod.replay.ReplayHandler; import eu.crushedpixel.replaymod.replay.ReplayHandler;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
@@ -27,10 +27,12 @@ import java.util.List;
public class PathPreviewRenderer { public class PathPreviewRenderer {
private static final Minecraft mc = Minecraft.getMinecraft(); private static final Minecraft mc = Minecraft.getMinecraft();
private static final int DEFAULT_PATH_COLOR = Color.RED.getRGB();
private static final int SPECTATOR_PATH_COLOR = Color.BLUE.getRGB();
private DistanceComparator distanceComparator = new DistanceComparator(); private DistanceComparator distanceComparator = new DistanceComparator();
private KeyframeList<AdvancedPosition> keyframes; private AdvancedPositionKeyframeList keyframes;
private final ResourceLocation cameraHeadResource = new ResourceLocation("replaymod", "camera_head.png"); private final ResourceLocation cameraHeadResource = new ResourceLocation("replaymod", "camera_head.png");
@@ -54,33 +56,29 @@ public class PathPreviewRenderer {
GlStateManager.enableBlend(); GlStateManager.enableBlend();
if(keyframes.size() > 1) { if(keyframes.size() > 1) {
AdvancedPosition previousPosition = null;
AdvancedPosition prev = null; int i = 0;
for(Keyframe<AdvancedPosition> keyframe : keyframes) {
int timestamp = keyframe.getRealTimestamp();
int nextTimestamp = timestamp;
if(ReplayMod.replaySettings.isLinearMovement()) { if(i+1 < keyframes.size()) {
nextTimestamp = keyframes.get(i+1).getRealTimestamp();
for(Keyframe<AdvancedPosition> point : keyframes) {
if(prev != null) {
drawConnection(doubleX, doubleY, doubleZ, prev, point.getValue(), Color.RED.getRGB());
}
prev = point.getValue();
} }
} else { int diff = nextTimestamp-timestamp;
int step = diff/100;
float max = keyframes.size() * 50; for(int currentTimestamp = timestamp; currentTimestamp < nextTimestamp; currentTimestamp += step) {
for(int i = 0; i < max; i++) { AdvancedPosition position = keyframes.getInterpolatedValueForTimestamp(currentTimestamp, ReplayMod.replaySettings.isLinearMovement());
AdvancedPosition point = keyframes.getInterpolatedValueForPathPosition(i/max, false); if(previousPosition != null) {
drawConnection(doubleX, doubleY, doubleZ, previousPosition, position, DEFAULT_PATH_COLOR, renderDistanceSquared);
if(point.distanceSquared(entity.posX, entity.posY, entity.posZ) < renderDistanceSquared) {
if(prev != null) {
drawConnection(doubleX, doubleY, doubleZ, prev, point, Color.RED.getRGB());
}
} }
previousPosition = position;
prev = point;
} }
i++;
} }
} }
@@ -116,7 +114,7 @@ public class PathPreviewRenderer {
@SubscribeEvent @SubscribeEvent
public void recalcSpline(KeyframesModifyEvent event) { public void recalcSpline(KeyframesModifyEvent event) {
keyframes = event.getPositionKeyframes(); keyframes = ReplayHandler.getPositionKeyframes();
} }
private class DistanceComparator implements Comparator<Keyframe<AdvancedPosition>> { private class DistanceComparator implements Comparator<Keyframe<AdvancedPosition>> {
@@ -140,7 +138,8 @@ public class PathPreviewRenderer {
} }
} }
private void drawConnection(double playerX, double playerY, double playerZ, AdvancedPosition pos1, AdvancedPosition pos2, int color) { private void drawConnection(double playerX, double playerY, double playerZ, AdvancedPosition pos1, AdvancedPosition pos2, int color, int renderDistanceSquared) {
if(pos2.distanceSquared(playerX, playerY, playerZ) > renderDistanceSquared) return;
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();
Tessellator tessellator = Tessellator.getInstance(); Tessellator tessellator = Tessellator.getInstance();