Finished the AdvancedPositionKeyframeList and SpectatorDataInterpolation
This commit is contained in:
@@ -3,16 +3,17 @@ package eu.crushedpixel.replaymod.interpolation;
|
||||
import eu.crushedpixel.replaymod.holders.AdvancedPosition;
|
||||
import eu.crushedpixel.replaymod.holders.Keyframe;
|
||||
import eu.crushedpixel.replaymod.holders.SpectatorData;
|
||||
import eu.crushedpixel.replaymod.holders.TimestampValue;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@NoArgsConstructor
|
||||
public class AdvancedPositionKeyframeList extends KeyframeList<AdvancedPosition> {
|
||||
|
||||
private Set<SpectatorDataInterpolation> spectatorDataInterpolators;
|
||||
private Map<List<Integer>, SpectatorDataInterpolation> spectatorDataInterpolators;
|
||||
|
||||
@Override
|
||||
public AdvancedPosition getInterpolatedValueForPathPosition(float pathPosition, boolean linear) {
|
||||
@@ -26,17 +27,16 @@ public class AdvancedPositionKeyframeList extends KeyframeList<AdvancedPosition>
|
||||
recalculate(linear);
|
||||
}
|
||||
|
||||
int keyframeIndex = (int)(pathPosition/size());
|
||||
float percentage = (pathPosition/size() - keyframeIndex)/(1f/size());
|
||||
int keyframeIndex = (int)Math.min(size()-1, pathPosition*(size()-1));
|
||||
float remainder = (pathPosition - ((float)keyframeIndex/(size()-1)));
|
||||
float partial = remainder / (1f/(size()-1));
|
||||
|
||||
AdvancedPosition current = get(keyframeIndex).getValue();
|
||||
|
||||
SpectatorDataInterpolation dataInterpolation = null;
|
||||
if(current instanceof SpectatorData) {
|
||||
for(SpectatorDataInterpolation interpolation : spectatorDataInterpolators) {
|
||||
if(interpolation.contains((SpectatorData)current)) {
|
||||
dataInterpolation = interpolation;
|
||||
break;
|
||||
}
|
||||
for(Entry<List<Integer>, SpectatorDataInterpolation> entry : spectatorDataInterpolators.entrySet()) {
|
||||
if(entry.getKey().contains(keyframeIndex)) dataInterpolation = entry.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,9 +45,10 @@ public class AdvancedPositionKeyframeList extends KeyframeList<AdvancedPosition>
|
||||
} else {
|
||||
SpectatorData spectatorData = (SpectatorData)current;
|
||||
int index = dataInterpolation.indexOf(spectatorData);
|
||||
int size = dataInterpolation.size();
|
||||
int size = dataInterpolation.size()-1;
|
||||
float one = 1f/size;
|
||||
dataInterpolation.applyPoint((index/size)+(percentage*one), toApply);
|
||||
float pathPos = (index/(float)size)+(partial*one);
|
||||
dataInterpolation.applyPoint(pathPos, toApply);
|
||||
}
|
||||
|
||||
return toApply;
|
||||
@@ -68,7 +69,7 @@ public class AdvancedPositionKeyframeList extends KeyframeList<AdvancedPosition>
|
||||
|
||||
interpolation.prepare();
|
||||
|
||||
spectatorDataInterpolators = new HashSet<SpectatorDataInterpolation>();
|
||||
spectatorDataInterpolators = new HashMap<List<Integer>, SpectatorDataInterpolation>();
|
||||
|
||||
//find subsequent Spectator Keyframes with the same Entity ID
|
||||
ListIterator<Keyframe<AdvancedPosition>> iterator = this.listIterator();
|
||||
@@ -77,13 +78,18 @@ public class AdvancedPositionKeyframeList extends KeyframeList<AdvancedPosition>
|
||||
SpectatorDataInterpolation spectatorInterpolation = null;
|
||||
|
||||
boolean found = keyframe.getValue() instanceof SpectatorData;
|
||||
int first = iterator.nextIndex()-1;
|
||||
int firstTimestamp = -1;
|
||||
|
||||
while(found) {
|
||||
if(spectatorInterpolation == null) {
|
||||
spectatorInterpolation = new SpectatorDataInterpolation(linear);
|
||||
}
|
||||
spectatorInterpolation.addPoint((SpectatorData)keyframe.getValue(), keyframe.getRealTimestamp());
|
||||
|
||||
int keyframeTimestamp = keyframe.getRealTimestamp();
|
||||
TimestampValue timestampValue = ReplayHandler.getTimeKeyframes().getInterpolatedValueForTimestamp(keyframeTimestamp, true);
|
||||
int replayTimestamp = timestampValue == null ? 0 : timestampValue.asInt();
|
||||
if(firstTimestamp == -1) firstTimestamp = replayTimestamp;
|
||||
spectatorInterpolation.addPoint((SpectatorData)keyframe.getValue(), replayTimestamp);
|
||||
if(iterator.hasNext()) {
|
||||
keyframe = iterator.next();
|
||||
found = keyframe.getValue() instanceof SpectatorData;
|
||||
@@ -94,7 +100,11 @@ public class AdvancedPositionKeyframeList extends KeyframeList<AdvancedPosition>
|
||||
|
||||
if(spectatorInterpolation != null && spectatorInterpolation.size() > 1) {
|
||||
spectatorInterpolation.prepare();
|
||||
spectatorDataInterpolators.add(spectatorInterpolation);
|
||||
List<Integer> keys = new ArrayList<Integer>();
|
||||
for(int i=first; i<first+spectatorInterpolation.size()-1; i++) {
|
||||
keys.add(i);
|
||||
}
|
||||
spectatorDataInterpolators.put(keys, spectatorInterpolation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,17 +58,22 @@ public class SpectatorDataInterpolation {
|
||||
if(pair.getValue().getSpectatingMethod() == SpectatorData.SpectatingMethod.FIRST_PERSON) {
|
||||
thirdPersonInfoInterpolation.addPoint(new SpectatorDataThirdPersonInfo(0, 0, 0, previousSmoothness));
|
||||
} else {
|
||||
thirdPersonInfoInterpolation.addPoint(pair.getValue().getThirdPersonInfo());
|
||||
previousSmoothness = pair.getValue().getThirdPersonInfo().shoulderCamSmoothness;
|
||||
SpectatorDataThirdPersonInfo thirdPersonInfo = pair.getValue().getThirdPersonInfo();
|
||||
thirdPersonInfoInterpolation.addPoint(thirdPersonInfo);
|
||||
previousSmoothness = thirdPersonInfo.shoulderCamSmoothness;
|
||||
}
|
||||
}
|
||||
thirdPersonInfoInterpolation.prepare();
|
||||
|
||||
//feed the underlying interpolator with AdvancedPosition Keyframes that are derived from the Spectator Keyframes
|
||||
//feed the underlying keyframe list with AdvancedPosition Keyframes that are derived from the Spectator Keyframes
|
||||
underlyingKeyframes = new KeyframeList<AdvancedPosition>();
|
||||
int i = 0;
|
||||
int size = points.size();
|
||||
int firstTimestamp = -1;
|
||||
int size = points.size()-1;
|
||||
for(Pair<Integer, SpectatorData> pair : points) {
|
||||
int timestamp = pair.getKey();
|
||||
if(firstTimestamp == -1) firstTimestamp = timestamp;
|
||||
|
||||
int currentTimestamp = timestamp;
|
||||
int nextTimestamp = timestamp;
|
||||
|
||||
@@ -79,12 +84,13 @@ public class SpectatorDataInterpolation {
|
||||
int difference = nextTimestamp - timestamp;
|
||||
|
||||
int smoothness = 0;
|
||||
while(currentTimestamp + smoothness < nextTimestamp) {
|
||||
while(currentTimestamp + smoothness <= nextTimestamp) {
|
||||
currentTimestamp += smoothness;
|
||||
|
||||
SpectatorDataThirdPersonInfo thirdPersonInfo = new SpectatorDataThirdPersonInfo();
|
||||
float percentage = (float)i/size;
|
||||
percentage += ((currentTimestamp-timestamp)/(float)difference) * 1f/size;
|
||||
if(Float.isNaN(percentage)) percentage = 1;
|
||||
|
||||
thirdPersonInfoInterpolation.applyPoint(percentage, thirdPersonInfo);
|
||||
|
||||
@@ -100,20 +106,17 @@ public class SpectatorDataInterpolation {
|
||||
|
||||
//next, move the camera point to fulfill the specified distance to the entity
|
||||
entityPosition = entityPosition.getDestination(-1 * thirdPersonInfo.shoulderCamDistance);
|
||||
underlyingKeyframes.add(new Keyframe<AdvancedPosition>(currentTimestamp, entityPosition));
|
||||
underlyingKeyframes.add(new Keyframe<AdvancedPosition>(currentTimestamp-firstTimestamp, entityPosition));
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
underlyingKeyframes.recalculate(linear);
|
||||
}
|
||||
|
||||
public void applyPoint(float position, AdvancedPosition toEdit) {
|
||||
int keyframeIndex = (int)position*points.size();
|
||||
|
||||
//the progress between this and the next keyframe (between 0 and 1)
|
||||
float partial = (position - ((float)keyframeIndex/points.size())) / (1f/points.size());
|
||||
int keyframeIndex = (int)Math.min(size()-1, position*(size()-1));
|
||||
float remainder = (position - ((float)keyframeIndex/(size()-1)));
|
||||
float partial = remainder / (1f/(size()-1));
|
||||
|
||||
Pair<Integer, SpectatorData> pair = points.get(keyframeIndex);
|
||||
Pair<Integer, SpectatorData> next = keyframeIndex < points.size()-1 ? points.get(keyframeIndex+1) : null;
|
||||
@@ -140,8 +143,7 @@ public class SpectatorDataInterpolation {
|
||||
int interpolatedTimestamp = firstTimestamp+(int)(partial*diff);
|
||||
|
||||
AdvancedPosition pos = ReplayHandler.getEntityPositionTracker().getEntityPositionAtTimestamp(entityID, interpolatedTimestamp);
|
||||
if(pos != null)
|
||||
toEdit.apply(pos);
|
||||
if(pos != null) toEdit.apply(pos);
|
||||
} else {
|
||||
toEdit.apply(underlyingKeyframes.getInterpolatedValueForPathPosition(position, linear));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user