Added recalculate() method to KeyframeList to recalc the underlying Interpolation
Recalculate Keyframe Lists in ReplayHandler upon firing a KeyframesModifyEvent
This commit is contained in:
@@ -30,8 +30,13 @@ public class GenericLinearInterpolation<T extends KeyframeValue> implements Inte
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyPoint(float position, T toEdit) {
|
public void applyPoint(float position, T toEdit) {
|
||||||
if(points.isEmpty()) {
|
if(fields == null) {
|
||||||
throw new IllegalStateException("At least one Value needs to be added for this operation");
|
throw new IllegalStateException("At least one Keyframe has to be added before preparing");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(fields.length <= 0) {
|
||||||
|
throw new IllegalStateException("The passed KeyframeValue class" +
|
||||||
|
" has to contain at least one Field");
|
||||||
}
|
}
|
||||||
|
|
||||||
//first, get previous and next T for given position
|
//first, get previous and next T for given position
|
||||||
|
|||||||
@@ -30,10 +30,15 @@ public class GenericSplineInterpolation<T extends KeyframeValue> extends BasicSp
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void prepare() {
|
public void prepare() {
|
||||||
|
if(fields == null) {
|
||||||
|
throw new IllegalStateException("At least one Keyframe has to be added before preparing");
|
||||||
|
}
|
||||||
|
|
||||||
if(fields.length <= 0) {
|
if(fields.length <= 0) {
|
||||||
throw new IllegalStateException("The passed KeyframeValue class" +
|
throw new IllegalStateException("The passed KeyframeValue class" +
|
||||||
" has to contain at least one Field");
|
" has to contain at least one Field");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!points.isEmpty()) {
|
if(!points.isEmpty()) {
|
||||||
cubics = new ArrayList<Vector<Cubic>>(fields.length);
|
cubics = new ArrayList<Vector<Cubic>>(fields.length);
|
||||||
for (Field field : fields) {
|
for (Field field : fields) {
|
||||||
|
|||||||
@@ -153,15 +153,7 @@ public class KeyframeList<K extends KeyframeValue> extends ArrayList<Keyframe<K>
|
|||||||
K toApply = (K) first().getValue().newInstance();
|
K toApply = (K) first().getValue().newInstance();
|
||||||
|
|
||||||
if(previousCallLinear != (Boolean)linear) {
|
if(previousCallLinear != (Boolean)linear) {
|
||||||
previousCallLinear = linear;
|
recalculate(linear);
|
||||||
|
|
||||||
interpolation = linear ? new GenericLinearInterpolation<K>() : new GenericSplineInterpolation<K>();
|
|
||||||
|
|
||||||
for(Keyframe<K> keyframe : this) {
|
|
||||||
interpolation.addPoint(keyframe.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
interpolation.prepare();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interpolation.applyPoint(pathPosition, toApply);
|
interpolation.applyPoint(pathPosition, toApply);
|
||||||
@@ -169,6 +161,24 @@ public class KeyframeList<K extends KeyframeValue> extends ArrayList<Keyframe<K>
|
|||||||
return toApply;
|
return toApply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recalculates the underlying Interpolation instances.
|
||||||
|
* @param linear Whether to prepare linear or cubic interpolation
|
||||||
|
*/
|
||||||
|
public void recalculate(boolean linear) {
|
||||||
|
previousCallLinear = linear;
|
||||||
|
|
||||||
|
if(isEmpty()) return;
|
||||||
|
|
||||||
|
interpolation = linear ? new GenericLinearInterpolation<K>() : new GenericSplineInterpolation<K>();
|
||||||
|
|
||||||
|
for(Keyframe<K> keyframe : this) {
|
||||||
|
interpolation.addPoint(keyframe.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
interpolation.prepare();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a value between 0 and 1, representing the number that should be passed
|
* Returns a value between 0 and 1, representing the number that should be passed
|
||||||
* to Interpolation#getValue() calls on this list of Keyframes.
|
* to Interpolation#getValue() calls on this list of Keyframes.
|
||||||
|
|||||||
@@ -579,6 +579,7 @@ public class ReplayHandler {
|
|||||||
|
|
||||||
public static void fireKeyframesModifyEvent() {
|
public static void fireKeyframesModifyEvent() {
|
||||||
FMLCommonHandler.instance().bus().post(new KeyframesModifyEvent(positionKeyframes, timeKeyframes));
|
FMLCommonHandler.instance().bus().post(new KeyframesModifyEvent(positionKeyframes, timeKeyframes));
|
||||||
|
positionKeyframes.recalculate(ReplayMod.replaySettings.isLinearMovement());
|
||||||
|
timeKeyframes.recalculate(ReplayMod.replaySettings.isLinearMovement());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user