Skip to content

Commit

Permalink
now removed time waiting for input from sim time in info
Browse files Browse the repository at this point in the history
  • Loading branch information
aspwil committed Nov 6, 2020
1 parent 66a795b commit 4404765
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ndballsim/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static void main(String[] args) {
boolean log = false;
boolean info = false;
int max = 10000;
String version = "V1.0.4";
String version = "V1.0.5";
String help = "NDBall Simulator " + version + "\n"
+ "Commands are formated like this:\n"
+ "[flags] (file containing code)\n"
Expand Down
23 changes: 17 additions & 6 deletions src/ndballsim/Simulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class Simulator {
private static boolean log = false;
private static long startTime;
private static long parseTime;
private static long timeToRemove;
// ... the code being measured ...

public static void run(String file, int max, boolean doLog, boolean step, boolean infoTag) {
Expand Down Expand Up @@ -76,7 +77,7 @@ public static void run(String file, int max, boolean doLog, boolean step, boolea
case "%":
newVal = 0;
System.out.print("\nPlease input a number:");
input = in.nextLine();
input = getInput(in);
try {
//parse in a new vaule from command line
newVal = Integer.parseInt(input);
Expand All @@ -88,7 +89,7 @@ public static void run(String file, int max, boolean doLog, boolean step, boolea
newVal += 256;
}
ballVal = newVal % 255;
log("input number \"" + input + "\" read in as number: " + newVal);
log("Input number \"" + input + "\" read in as number: " + newVal);
break;
//Y logic case
case "Y":
Expand Down Expand Up @@ -121,6 +122,8 @@ public static void run(String file, int max, boolean doLog, boolean step, boolea
break;
}
}
//log the movement change
log("Movement changed to [" + movement[0] + "," + movement[1] + "]");
break;
//add one to the balls value while keeping bounded in (0-255)
case "+":
Expand Down Expand Up @@ -148,13 +151,14 @@ public static void run(String file, int max, boolean doLog, boolean step, boolea
} else {
//read from the cell
ballVal = (int) instr.info[0];
log("MEM CELL READ Val:" + ballVal + " Pos:" + instr.pos);
}
break;
//input a char
case "$":
newVal = 0;
System.out.print("\nPlease input a char:");
input = in.nextLine();
input = getInput(in);
try {
//parse in a new vaule from command line
newVal = (int) input.charAt(0);
Expand All @@ -166,7 +170,7 @@ public static void run(String file, int max, boolean doLog, boolean step, boolea
newVal += 256;
}
ballVal = newVal % 255;
log("input number \"" + input + "\" read in as number: " + newVal);
log("Input number \"" + input + "\" read in as number: " + newVal);
break;
//output the value of the ball as a char
case "p":
Expand Down Expand Up @@ -241,7 +245,7 @@ private static void exit(boolean outputInfo, int steps, int instNum) {
+ ((double) parseTime / 1_000_000.0)
+ "ms\n"
+ "Sim Time: "
+ ((double) (System.nanoTime() - startTime) / 1_000_000.0)
+ ((double) (System.nanoTime() - startTime - timeToRemove) / 1_000_000.0)
+ "ms\n"
+ "Steps: "
+ steps
Expand All @@ -256,7 +260,7 @@ private static void exit(boolean outputInfo, int steps, int instNum) {
}

//memory useage statisitics
public static String memoryStats() {
private static String memoryStats() {
System.gc();
int kb = 1024;
// get Runtime instance
Expand All @@ -265,5 +269,12 @@ public static String memoryStats() {
return "Active Mem: ~" + (instance.totalMemory() - instance.freeMemory()) / kb + "KB\n";

}
//this allows up to get input and pause timer for time waiting for input
private static String getInput(Scanner scan){
long start = System.nanoTime();
String input = scan.nextLine();
timeToRemove+= (System.nanoTime() - start);
return input;
}

}

0 comments on commit 4404765

Please sign in to comment.