-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move runnables to end of functions, abolish TickDuration
- Loading branch information
Showing
7 changed files
with
30 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 2 additions & 10 deletions
12
src/main/kotlin/net/mcbrawls/scheduler/RelativeScheduler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,19 @@ | ||
package net.mcbrawls.scheduler | ||
|
||
import net.mcbrawls.scheduler.duration.TickDuration | ||
import kotlin.time.Duration | ||
|
||
/** | ||
* A scheduler which performs in relation to a local tick variable. | ||
*/ | ||
class RelativeScheduler( | ||
/** | ||
* The amount of time which is simulated per tick. | ||
*/ | ||
durationPerTick: Duration = TickDuration.create(1) | ||
) : AbstractScheduler() { | ||
class RelativeScheduler : AbstractScheduler() { | ||
override val currentTimeNanos: Long get() = tickNanos | ||
|
||
private val nanosPerTick = durationPerTick.inWholeNanoseconds | ||
|
||
private var tickNanos: Long = 0L | ||
|
||
override fun processTick() { | ||
super.processTick() | ||
|
||
// increment tick | ||
tickNanos += nanosPerTick | ||
tickNanos += TickDuration.NANOS_PER_TICK | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters