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