Skip to content

Commit

Permalink
VRPoseHistory Index 0 now most recent
Browse files Browse the repository at this point in the history
  • Loading branch information
hammy275 committed Feb 18, 2024
1 parent bf2dcc2 commit 8d06ea5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,15 @@ public interface VRPoseHistory {
List<VRPose> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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();
}
}

Expand All @@ -38,13 +35,13 @@ public List<VRPose> 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
Expand Down

0 comments on commit 8d06ea5

Please sign in to comment.