Permalink
Browse files

Code cleanup.

  • Loading branch information...
fversnel committed May 8, 2012
1 parent f985eca commit 75a7e256e0bd2d8dc0e6f77e9b58e98bc771f11e
@@ -21,7 +21,7 @@ class EntityManager private(val renderer: Renderer) extends Logging {
def spawn(newGameObject: GameObject) {
_gameObjects ::= newGameObject
- onGameObjectAndChildren(newGameObject) { gameObject =>
+ newGameObject.onGameObjectAndChildren { gameObject =>
val component = gameObject.asInstanceOf[Component]
componentManagers.foreach(_.addComponent(component))
}
@@ -39,18 +39,11 @@ class EntityManager private(val renderer: Renderer) extends Logging {
_gameObjects = _gameObjects.filterNot(g => destroyedGameObjects.contains(g))
destroyedGameObjects.foreach { destroyedGameObject =>
- onGameObjectAndChildren(destroyedGameObject) { gameObject =>
+ destroyedGameObject.onGameObjectAndChildren { gameObject =>
componentManagers.foreach(_.removeComponent(gameObject.asInstanceOf[Component]))
}
}
}
-
- private def onGameObjectAndChildren(gameObject: GameObject)(apply: GameObject => Unit) {
- apply(gameObject)
- gameObject.children.foreach { childGameObject =>
- onGameObjectAndChildren(childGameObject)(apply)
- }
- }
}
object EntityManager {
var entityManager: Option[EntityManager] = None
@@ -31,4 +31,9 @@ abstract class GameObject {
private def addChild(child: GameObject) {
_children = child :: _children
}
+
+ def onGameObjectAndChildren(apply: GameObject => Unit) {
+ apply(this)
+ children.foreach(_.onGameObjectAndChildren(apply))
+ }
}

0 comments on commit 75a7e25

Please sign in to comment.