-
Notifications
You must be signed in to change notification settings - Fork 497
/
TabletThread.java
51 lines (43 loc) · 1.05 KB
/
TabletThread.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
51
package buildcraft.core.tablet.manager;
import java.util.Date;
import buildcraft.core.tablet.TabletBase;
public class TabletThread implements Runnable {
private final TabletBase tablet;
private long begunTickDate;
private long lastTickReceivedDate;
private float ticksLeft = 0.0F;
private boolean isRunning = false;
public TabletThread(TabletBase tablet) {
this.tablet = tablet;
lastTickReceivedDate = begunTickDate = (new Date()).getTime();
}
public TabletBase getTablet() {
return tablet;
}
@Override
public void run() {
isRunning = true;
while (isRunning) {
if (ticksLeft > 0.0F) {
begunTickDate = (new Date()).getTime();
tablet.tick(ticksLeft);
float timeElapsed = (float) (lastTickReceivedDate - begunTickDate) / 1000.0F;
if (timeElapsed > 0) {
ticksLeft -= timeElapsed;
}
} else {
try {
Thread.sleep(1);
} catch (Exception e) {
}
}
}
}
public void stop() {
isRunning = false;
}
public void tick(float time) {
ticksLeft += time;
lastTickReceivedDate = (new Date()).getTime();
}
}