diff --git a/common/src/main/java/org/vivecraft/api/client/data/VRPoseHistory.java b/common/src/main/java/org/vivecraft/api/client/data/VRPoseHistory.java index 7d3dcb342..b0a50549c 100644 --- a/common/src/main/java/org/vivecraft/api/client/data/VRPoseHistory.java +++ b/common/src/main/java/org/vivecraft/api/client/data/VRPoseHistory.java @@ -34,17 +34,15 @@ public interface VRPoseHistory { List getAllHistoricalData() throws IllegalArgumentException; /** - * Gets the historical data at the supplied index. This will throw an IllegalStateException if the data cannot + * Gets the historical data ticksBack ticks back. This will throw an IllegalStateException if the data cannot * be retrieved due to not having enough history. * - * @param index The index of historical data to retrieve back. Index 0 is the oldest stored {@link VRPose}, while - * the index calculated as '{@link VRPoseHistory#ticksOfHistory()} - 1' is the most recently stored - * data (the current tick's data). + * @param ticksBack Ticks back to retrieve data. * @return A {@link VRPose} instance from index ticks ago. - * @throws IllegalStateException If index references a tick that there is not yet data for. + * @throws IllegalStateException If ticksBack references a tick that there is not yet data for. * @throws IllegalArgumentException Thrown when maxTicksBack is larger than {@value #MAX_TICKS_BACK} or less than 0. */ - VRPose getHistoricalData(int index) throws IllegalArgumentException, IllegalStateException; + VRPose getHistoricalData(int ticksBack) throws IllegalArgumentException, IllegalStateException; /** * Gets the net movement between the most recent data in this instance and the oldest position that can be diff --git a/common/src/main/java/org/vivecraft/client/api_impl/data/VRPoseHistoryImpl.java b/common/src/main/java/org/vivecraft/client/api_impl/data/VRPoseHistoryImpl.java index 47dc75016..3058a06cd 100644 --- a/common/src/main/java/org/vivecraft/client/api_impl/data/VRPoseHistoryImpl.java +++ b/common/src/main/java/org/vivecraft/client/api_impl/data/VRPoseHistoryImpl.java @@ -4,10 +4,7 @@ import org.vivecraft.api.client.data.VRPoseHistory; import org.vivecraft.api.data.VRPose; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; +import java.util.*; public class VRPoseHistoryImpl implements VRPoseHistory { @@ -17,9 +14,9 @@ public VRPoseHistoryImpl() { } public void addPose(VRPose pose) { - this.dataQueue.add(pose); + this.dataQueue.addFirst(pose); if (this.dataQueue.size() > VRPoseHistory.MAX_TICKS_BACK) { - this.dataQueue.removeFirst(); + this.dataQueue.removeLast(); } } @@ -38,13 +35,13 @@ public List getAllHistoricalData() { } @Override - public VRPose getHistoricalData(int index) throws IllegalArgumentException, IllegalStateException { - checkTicksBack(index); - if (this.dataQueue.size() <= index) { - throw new IllegalStateException("Cannot retrieve data from " + index + " ticks ago, when there is " + + public VRPose getHistoricalData(int ticksBack) throws IllegalArgumentException, IllegalStateException { + checkTicksBack(ticksBack); + if (this.dataQueue.size() <= ticksBack) { + throw new IllegalStateException("Cannot retrieve data from " + ticksBack + " ticks ago, when there is " + "only data for up to " + (this.dataQueue.size() - 1) + " ticks ago."); } - return this.dataQueue.get(index); + return this.dataQueue.get(ticksBack); } @Override