Skip to content

Commit 88bebfa

Browse files
committed
implement TimerGetElapsed for compiletime
1 parent 4a6902d commit 88bebfa

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/jassinterpreter/mocks/TimerMock.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class TimerMock {
1616
private IlConstHandle timerHandle;
1717
private TimerMockHandler.RunTask runTask;
1818
private TimerMockHandler.PausedTask pausedTask;
19+
private long startedMillis;
1920

2021
public class TimerMockRunnable implements Runnable {
2122

@@ -63,6 +64,7 @@ public void start(ILconstReal timeout, ILconstBool periodic, ILconstFuncRef hand
6364
timerMockHandler.cancelTask(runTask);
6465
}
6566
pausedTask = null;
67+
startedMillis = System.currentTimeMillis();
6668
TimerMockRunnable toRun = new TimerMockRunnable(handlerFunc, periodic.getVal(), timeout.getVal());
6769
this.runTask = timerMockHandler.registerTimedAction(timeout.getVal(), toRun);
6870
}
@@ -97,4 +99,8 @@ public void resume() {
9799
runTask = timerMockHandler.resumeTask(pausedTask);
98100
pausedTask = null;
99101
}
102+
103+
public long getElapsed() {
104+
return (System.currentTimeMillis() - startedMillis) / 1000;
105+
}
100106
}

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/jassinterpreter/providers/TimerProvider.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ public IlConstHandle CreateTimer() {
1818
return timer;
1919
}
2020

21+
public ILconstReal TimerGetElapsed(IlConstHandle timer) {
22+
TimerMock timerMock = (TimerMock) timer.getObj();
23+
return new ILconstReal(timerMock.getElapsed());
24+
}
25+
2126
public void DestroyTimer(IlConstHandle timer) {
2227
TimerMock timerMock = (TimerMock) timer.getObj();
2328
timerMock.destroy();

0 commit comments

Comments
 (0)