-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainApp.java
50 lines (42 loc) · 1.42 KB
/
MainApp.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package TickSystemThread;
import javafx.application.Application;
import javafx.stage.Stage;
import java.util.HashMap;
import java.util.Map;
public class MainApp extends Application{
TickThread gameThread;
Map<Integer,MethodRunner> stepsMethods = new HashMap<>();
Map<Integer,Integer> msStep = new HashMap<>();
int updateCount = 0;
int drawCount = 0;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage){
primaryStage.show();
setupThread();
this.gameThread.start();
}
public void stop(){
this.gameThread.stopIt();
System.out.println("Update Count : "+updateCount);
System.out.println("Draw Count : "+drawCount);
System.out.println("Runtime : "+this.gameThread.runtime/1000000000+" s");
}
public void setupThread(){
MethodRunner mRUpdate = new MethodRunner("TickSystemThread.MainApp","update",null,this,null);
MethodRunner mRDraw = new MethodRunner("TickSystemThread.MainApp","draw",null,this,null);
stepsMethods.put(0,mRUpdate);
msStep.put(0,1000/60);
stepsMethods.put(1,mRDraw);
msStep.put(1,1000/120);
this.gameThread = new TickThread(msStep, stepsMethods);
}
public void update() {
updateCount++;
}
public void draw() {
drawCount++;
}
}