mirror of
https://github.com/TimeCrafters/UltimateGoal.git
synced 2025-12-13 05:02:34 +00:00
Replace usage of ArrayList in CyberarmEngine/State with CopyOnWriteArrayList, added showStateChildrenListInTelemetry variable to list off states children class names in telemetry
This commit is contained in:
@@ -4,7 +4,7 @@ import android.util.Log;
|
||||
|
||||
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
/**
|
||||
* CyberarmEngine Version 2.0 | October 26th 2018
|
||||
@@ -15,11 +15,12 @@ public abstract class CyberarmEngine extends OpMode {
|
||||
|
||||
public static CyberarmEngine instance;
|
||||
//Array To Hold States
|
||||
private ArrayList<CyberarmState> cyberarmStates = new ArrayList<>();
|
||||
private CopyOnWriteArrayList<CyberarmState> cyberarmStates = new CopyOnWriteArrayList<>();
|
||||
private int activeStateIndex = 0;
|
||||
private boolean isRunning;
|
||||
|
||||
private static String TAG = "PROGRAM.ENGINE: ";
|
||||
private static String TAG = "PROGRAM.ENGINE";
|
||||
public boolean showStateChildrenListInTelemetry = false;
|
||||
|
||||
/**
|
||||
* Called when INIT button on Driver Station is pushed
|
||||
@@ -83,6 +84,11 @@ public abstract class CyberarmEngine extends OpMode {
|
||||
|
||||
// Add telemetry to show currently running state
|
||||
telemetry.addLine("Running state: " +state.getClass().getSimpleName() + ". State: " + activeStateIndex + " of " + (cyberarmStates.size()-1));
|
||||
if (showStateChildrenListInTelemetry && state.hasChildren()) {
|
||||
for(CyberarmState child: state.children) {
|
||||
telemetry.addLine(" Child: " + child.getClass().getSimpleName() + " [" + child.children.size() + "] grandchildren");
|
||||
}
|
||||
}
|
||||
telemetry.addLine();
|
||||
|
||||
if (state.getHasFinished() && state.childrenHaveFinished()) {
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.cyberarm.engine.V2;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
/**
|
||||
* A State for use with CyberarmEngineV2
|
||||
@@ -12,7 +12,7 @@ public abstract class CyberarmState implements Runnable {
|
||||
private volatile boolean isRunning, hasFinished;
|
||||
public static String TAG = "PROGRAM.STATE";
|
||||
public CyberarmEngine engine = CyberarmEngine.instance;
|
||||
public ArrayList<CyberarmState> children = new ArrayList<>();
|
||||
public CopyOnWriteArrayList<CyberarmState> children = new CopyOnWriteArrayList<>();
|
||||
public long startTime = 0;
|
||||
public int insertOffset = 1;
|
||||
|
||||
@@ -90,7 +90,7 @@ public abstract class CyberarmState implements Runnable {
|
||||
|
||||
/**
|
||||
* Have all of the states children finished running themselves?
|
||||
* @return Wether or not all children have finished running
|
||||
* @return Whether or not all children have finished running
|
||||
*/
|
||||
public boolean childrenHaveFinished() {
|
||||
return childrenHaveFinished(children);
|
||||
@@ -98,10 +98,10 @@ public abstract class CyberarmState implements Runnable {
|
||||
|
||||
/**
|
||||
* Have all of the states children finished running themselves?
|
||||
* @param kids ArrayList of children to check for hasFinished()
|
||||
* @param kids CopyOnWriteArrayList of children to check for hasFinished()
|
||||
* @return Whether or not all children have finished running
|
||||
*/
|
||||
public boolean childrenHaveFinished(ArrayList<CyberarmState> kids) {
|
||||
public boolean childrenHaveFinished(CopyOnWriteArrayList<CyberarmState> kids) {
|
||||
boolean allDone = true;
|
||||
|
||||
for (CyberarmState state : kids) {
|
||||
|
||||
Reference in New Issue
Block a user