Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactored delta time tracking.

  • Loading branch information...
commit bb8dcf335bdfe2ec2baff521a65ee14e0bfe35af 1 parent 602ce76
@fversnel authored
View
14 src/main/scala/org/frankversnel/poortjes/common/delta_time_tracker.scala
@@ -0,0 +1,14 @@
+package org.frankversnel.poortjes
+
+import org.frankversnel.poortjes.util.DeltaTime
+
+class DeltaTimeTracker {
+ private var oldTime = System.currentTimeMillis
+
+ def getDelta = {
+ val newTime = System.currentTimeMillis
+ val deltaMillis = DeltaTime((newTime - oldTime).toInt)
+ oldTime = newTime
+ deltaMillis
+ }
+}
View
11 src/main/scala/org/frankversnel/poortjes/common/entity_manager.scala
@@ -4,11 +4,13 @@ import org.slf4j.scala.Logging;
import org.frankversnel.poortjes.rendering._;
import org.frankversnel.poortjes.collision._
-import org.frankversnel.poortjes.util.DeltaTime
import org.frankversnel.poortjes.game.gameobjects.Player
-class EntityManager private(private val componentManagers: List[ComponentManager]) extends Logging {
+class EntityManager private(private val componentManagers: List[ComponentManager])
+ extends Logging {
+
+ private val deltaTimeTracker = new DeltaTimeTracker
private var _gameObjects: List[GameObject] = Nil
def gameObjects = _gameObjects
@@ -22,9 +24,10 @@ class EntityManager private(private val componentManagers: List[ComponentManager
}
}
- def process(deltaTime: DeltaTime) {
+ def process {
+ val delta = deltaTimeTracker.getDelta
componentManagers.foreach {
- _.processComponents(Update(deltaTime, _gameObjects))
+ _.processComponents(Update(delta, _gameObjects))
}
}
View
7 src/main/scala/org/frankversnel/poortjes/game/poortjes.scala
@@ -135,13 +135,8 @@ class Poortjes extends PApplet with Logging {
})
}
- var oldTime = 0L
override def draw = {
- val newTime = millis
- val deltaMillis = (newTime - oldTime).toInt
- oldTime = newTime
-
- EntityManager().process(DeltaTime(deltaMillis))
+ EntityManager().process
EntityManager().cleanUp
}
}
View
2  src/main/scala/org/frankversnel/poortjes/game/poortjes_slick.scala
@@ -34,7 +34,7 @@ class PoortjesSlick extends BasicGame("Poortjes") {
}
override def update(container: GameContainer, delta: Int): Unit = {
- EntityManager().process(DeltaTime(delta))
+ EntityManager().process
EntityManager().cleanUp
}
Please sign in to comment.
Something went wrong with that request. Please try again.