     ###
     Register an event handler.
     ###
-    add_handler: (event, handler) ->
+    addHandler: (event, handler) ->
         if not @handlers[event.type]
             @handlers[event.type] = []
 

    handlers: {}

    ###
    Delay inbetween loops triggered by
    `loop_forever`, in ms.

    @type integer
    @see `loop_forever`
    ###
    loop_delay: 2

    ###
    {@inheritDoc}
    ###
    start: () ->
        super

        @loop_forever()

    ###
    Perform a single iteration of the event loop,

    ###
    Handle a tick event.
    ###
    onTick: (event) =>
        # For each room, increment the current server tick counter
        # Once we reach the required amount of server ticks for a room
        # tick, we reset the counter.
        for id, room of Game.rooms
            room.tickCounter ?= 0
            room.tickCounter += 1

            if room.tickCounter >= (Game.constants.ticksPerSecond / room.difficulty)
                room.tickCounter = 0
                @onRoomTick event, room

    ###
    Handle a room tick.
    ###
    onRoomTick: (event, room) ->
        for id, player of room.players
            oldPosition = player.position[..]
            position = player.position
            direction = player.direction

            # Increment x, y and z positioning by direction
            # vector value
            for i in [0 .. 2]
                position[i] += direction[i]

                # Reset axis position when exceeding level
                # axis size
                if position[i] < 0
                    position[i] = room.level.size[i]
                else if position[i] > room.level.size[i]
                    position[i] = 0

            player.positionHistory.pop()
            player.positionHistory.unshift oldPosition


###
