Check min- and maxDiviation against endless loops (max >= min)

Strict

Private

Function OutBounce:Float(progress:Float)
    If progress < (1 / 2.75) Return 7.5625 * Pow(progress, 2)

    If progress < (2 / 2.75)
        progress -= 1.5 / 2.75
        Return 7.5625 * Pow(progress, 2) + 0.75
    End

    If progress < (2.5 / 2.75)
        progress -= 2.25 / 2.75
        Return 7.5625 * Pow(progress, 2) + 0.9375
    End

    progress -= 2.625 / 2.75
    Return 7.5625 * Pow(progress, 2) + 0.984375
End

Function InBounce:Float(progress:Float)
    Return 1 - OutBounce(1 - progress)
End

Public

' All transitions where ported from the Kivy project
' See: https://github.com/kivy/kivy/blob/master/kivy/animation.py#L366

Interface Transition
    Method Calculate:Float(progress:Float)
End

Class TransitionLinear Implements Transition
    Method Calculate:Float(progress:Float)
        Return progress
    End
End

Class TransitionInQuad Implements Transition
    Method Calculate:Float(progress:Float)
        Return Pow(progress, 2)
    End
End

Class TransitionOutQuad Implements Transition
    Method Calculate:Float(progress:Float)
        Return -1 * progress * (progress - 2)
    End
End

Class TransitionInOutQuad Implements Transition
    Method Calculate:Float(progress:Float)
        progress *= 2
        If progress < 1 Then Return 0.5 * Pow(progress, 2)

        progress -= 1
        Return -0.5 * (progress * (progress - 2) - 1)
    End
End

Class TransitionInCubic Implements Transition
    Method Calculate:Float(progress:Float)
        Return Pow(progress, 3)
    End
End

Class TransitionOutCubic Implements Transition
    Method Calculate:Float(progress:Float)
        progress -= 1
        Return Pow(progress, 3) + 1
    End
End

Class TransitionInOutCubic Implements Transition
    Method Calculate:Float(progress:Float)
        progress *= 2
        If progress < 1 Then Return 0.5 * Pow(progress, 3)

        progress -= 2
        Return 0.5 * (Pow(progress, 3) + 2)
    End
End

Class TransitionInQuart Implements Transition
    Method Calculate:Float(progress:Float)
        Return Pow(progress, 4)
    End
End

Class TransitionOutQuart Implements Transition
    Method Calculate:Float(progress:Float)
        progress -= 1
        Return -1 * (Pow(progress, 4) - 1)
    End
End

Class TransitionInOutQuart Implements Transition
    Method Calculate:Float(progress:Float)
        progress *= 2
        If progress < 1 Then Return 0.5 * Pow(progress, 4)

        progress -= 2
        Return -0.5 * (Pow(progress, 4) - 2)
    End
End

Class TransitionInSine Implements Transition
    Method Calculate:Float(progress:Float)
        Return -1 * Cosr(progress * HALFPI) + 1
    End
End

Class TransitionOutSine Implements Transition
    Method Calculate:Float(progress:Float)
        Return Sinr(progress * HALFPI)
    End
End

Class TransitionInOutSine Implements Transition
    Method Calculate:Float(progress:Float)
        Return -0.5 * (Cosr(progress * PI) - 1.0)
    End
End

Class TransitionInExpo Implements Transition
    Method Calculate:Float(progress:Float)
        If progress = 0 Then Return 0
        Return Pow(2, 10 * (progress - 1.0))
    End
End

Class TransitionOutExpo Implements Transition
    Method Calculate:Float(progress:Float)
        If progress = 1 Then Return 1
        Return -Pow(2, -10 * progress) + 1
    End
End

Class TransitionInOutExpo Implements Transition
    Method Calculate:Float(progress:Float)
        If progress = 0 Then Return 0
        If progress = 1 Then Return 1

        progress *= 2
        If progress < 1 Then Return 0.5 * Pow(2, 10 * (progress - 1.0))

        progress -= 1
        Return 0.5 * (-Pow(2, -10 * progress) + 2)
    End
End

Class TransitionInCirc Implements Transition
    Method Calculate:Float(progress:Float)
        Return -1 * (Sqrt(1 - Pow(progress, 2)) - 1)
    End
End

Class TransitionOutCirc Implements Transition
    Method Calculate:Float(progress:Float)
        progress -= 1
        Return Sqrt(1 - Pow(progress, 2))
    End
End

Class TransitionInOutCirc Implements Transition
    Method Calculate:Float(progress:Float)
        progress *= 2
        If progress < 1 Then Return -0.5 * (Sqrt(1 - Pow(progress, 2)) - 1)

        progress -= 2
        Return 0.5 * (Sqrt(1 - Pow(progress, 2)) + 1)
    End
End

Class TransitionInElastic Implements Transition
    Private

    Const P:Float = 0.3
    Const S:Float = P / 4

    Public

    Method Calculate:Float(progress:Float)
        If progress = 1 Then Return 1
        progress -= 1

        Return -(Pow(2, 10 * progress) * Sinr((progress - S) * TWOPI / P))
    End
End

Class TransitionOutElastic Implements Transition
    Private

    Const P:Float = 0.3
    Const S:Float = P / 4

    Public

    Method Calculate:Float(progress:Float)
        If progress = 1 Then Return 1
        Return Pow(2, -10 * progress) * Sinr((progress - S) * TWOPI / P) + 1
    End
End

Class TransitionInOutElastic Implements Transition
    Private

    Const P:Float = 0.45
    Const S:Float = P / 4

    Public

    Method Calculate:Float(progress:Float)
        progress *= 2
        If progress = 2 Then Return 1

        If progress < 1 Then
            progress -= 1
            Return -0.5 * (Pow(2, 10 * progress) * Sinr((progress - S) * TWOPI / P))
        Else
            progress -= 1
            Return Pow(2, -10 * progress) * Sinr((progress - S) * TWOPI / P) * 0.5 + 1
        End
    End
End

Class TransitionInBack Implements Transition
    Method Calculate:Float(progress:Float)
        Return Pow(progress, 2) * (2.70158 * progress - 1.70158)
    End
End

Class TransitionOutBack Implements Transition
    Method Calculate:Float(progress:Float)
        progress -= 1
        Return Pow(progress, 2) * (2.70158 * progress + 1.70158) + 1
    End
End

Class TransitionInOutBack Implements Transition
    Private

    Const S:Float = 1.70158 * 1.525

    Public

    Method Calculate:Float(progress:Float)
        progress *= 2
        If progress < 1 Then Return 0.5 * (Pow(progress, 2) * ((S + 1) * progress - S))

        progress -= 2
        Return 0.5 * (Pow(progress, 2) * ((S + 1) * progress + S) + 2)
    End
End

Class TransitionInBounce Implements Transition
    Method Calculate:Float(progress:Float)
        Return InBounce(progress)
    End
End

Class TransitionOutBounce Implements Transition
    Method Calculate:Float(progress:Float)
        Return OutBounce(progress)
    End
End

Class TransitionInOutBounce Implements Transition
    Method Calculate:Float(progress:Float)
        progress *= 2
        If progress < 1 Then Return InBounce(progress) * 0.5

        Return OutBounce(progress - 1) * 0.5 + 0.5
    End
End

Class TransitionRandom Implements Transition
    Private

    Field transition:Transition
    Field minDiviation:Float
    Field maxDiviation:Float
    Field maxDiviationHalf:Float

    Public

    Method New(minDiviation:Float=0, maxDiviation:Float=1, transition:Transition)
        Self.minDiviation = minDiviation
        Self.maxDiviation = maxDiviation
        Self.transition = transition
        maxDiviationHalf = maxDiviation / 2

        If minDiviation >= maxDiviation
            Error("minDiviation must be geater than maxDiviation")
        End
    End

    Method Calculate:Float(progress:Float)
        If progress >= 1 Then Return progress
        If progress <= 0 Then Return progress
        If Not transition Then Return Rnd(0, 1)

        progress = transition.Calculate(progress)

        Local diviation:Float
        Repeat
            diviation = Rnd(maxDiviationHalf * -1, maxDiviationHalf)
        Until diviation > minDiviation Or diviation < (minDiviation * -1)

        Return progress + diviation
    End
End

Strict

Private

Function OutBounce:Float(progress:Float)
    If progress < (1 / 2.75) Return 7.5625 * Pow(progress, 2)

    If progress < (2 / 2.75)
        progress -= 1.5 / 2.75
        Return 7.5625 * Pow(progress, 2) + 0.75
    End

    If progress < (2.5 / 2.75)
        progress -= 2.25 / 2.75
        Return 7.5625 * Pow(progress, 2) + 0.9375
    End

    progress -= 2.625 / 2.75
    Return 7.5625 * Pow(progress, 2) + 0.984375
End

Function InBounce:Float(progress:Float)
    Return 1 - OutBounce(1 - progress)
End

Public

' All transitions where ported from the Kivy project
' See: https://github.com/kivy/kivy/blob/master/kivy/animation.py#L366

Interface Transition
    Method Calculate:Float(progress:Float)
End

Class TransitionLinear Implements Transition
    Method Calculate:Float(progress:Float)
        Return progress
    End
End

Class TransitionInQuad Implements Transition
    Method Calculate:Float(progress:Float)
        Return Pow(progress, 2)
    End
End

Class TransitionOutQuad Implements Transition
    Method Calculate:Float(progress:Float)
        Return -1 * progress * (progress - 2)
    End
End

Class TransitionInOutQuad Implements Transition
    Method Calculate:Float(progress:Float)
        progress *= 2
        If progress < 1 Then Return 0.5 * Pow(progress, 2)

        progress -= 1
        Return -0.5 * (progress * (progress - 2) - 1)
    End
End

Class TransitionInCubic Implements Transition
    Method Calculate:Float(progress:Float)
        Return Pow(progress, 3)
    End
End

Class TransitionOutCubic Implements Transition
    Method Calculate:Float(progress:Float)
        progress -= 1
        Return Pow(progress, 3) + 1
    End
End

Class TransitionInOutCubic Implements Transition
    Method Calculate:Float(progress:Float)
        progress *= 2
        If progress < 1 Then Return 0.5 * Pow(progress, 3)

        progress -= 2
        Return 0.5 * (Pow(progress, 3) + 2)
    End
End

Class TransitionInQuart Implements Transition
    Method Calculate:Float(progress:Float)
        Return Pow(progress, 4)
    End
End

Class TransitionOutQuart Implements Transition
    Method Calculate:Float(progress:Float)
        progress -= 1
        Return -1 * (Pow(progress, 4) - 1)
    End
End

Class TransitionInOutQuart Implements Transition
    Method Calculate:Float(progress:Float)
        progress *= 2
        If progress < 1 Then Return 0.5 * Pow(progress, 4)

        progress -= 2
        Return -0.5 * (Pow(progress, 4) - 2)
    End
End

Class TransitionInSine Implements Transition
    Method Calculate:Float(progress:Float)
        Return -1 * Cosr(progress * HALFPI) + 1
    End
End

Class TransitionOutSine Implements Transition
    Method Calculate:Float(progress:Float)
        Return Sinr(progress * HALFPI)
    End
End

Class TransitionInOutSine Implements Transition
    Method Calculate:Float(progress:Float)
        Return -0.5 * (Cosr(progress * PI) - 1.0)
    End
End

Class TransitionInExpo Implements Transition
    Method Calculate:Float(progress:Float)
        If progress = 0 Then Return 0
        Return Pow(2, 10 * (progress - 1.0))
    End
End

Class TransitionOutExpo Implements Transition
    Method Calculate:Float(progress:Float)
        If progress = 1 Then Return 1
        Return -Pow(2, -10 * progress) + 1
    End
End

Class TransitionInOutExpo Implements Transition
    Method Calculate:Float(progress:Float)
        If progress = 0 Then Return 0
        If progress = 1 Then Return 1

        progress *= 2
        If progress < 1 Then Return 0.5 * Pow(2, 10 * (progress - 1.0))

        progress -= 1
        Return 0.5 * (-Pow(2, -10 * progress) + 2)
    End
End

Class TransitionInCirc Implements Transition
    Method Calculate:Float(progress:Float)
        Return -1 * (Sqrt(1 - Pow(progress, 2)) - 1)
    End
End

Class TransitionOutCirc Implements Transition
    Method Calculate:Float(progress:Float)
        progress -= 1
        Return Sqrt(1 - Pow(progress, 2))
    End
End

Class TransitionInOutCirc Implements Transition
    Method Calculate:Float(progress:Float)
        progress *= 2
        If progress < 1 Then Return -0.5 * (Sqrt(1 - Pow(progress, 2)) - 1)

        progress -= 2
        Return 0.5 * (Sqrt(1 - Pow(progress, 2)) + 1)
    End
End

Class TransitionInElastic Implements Transition
    Private

    Const P:Float = 0.3
    Const S:Float = P / 4

    Public

    Method Calculate:Float(progress:Float)
        If progress = 1 Then Return 1
        progress -= 1

        Return -(Pow(2, 10 * progress) * Sinr((progress - S) * TWOPI / P))
    End
End

Class TransitionOutElastic Implements Transition
    Private

    Const P:Float = 0.3
    Const S:Float = P / 4

    Public

    Method Calculate:Float(progress:Float)
        If progress = 1 Then Return 1
        Return Pow(2, -10 * progress) * Sinr((progress - S) * TWOPI / P) + 1
    End
End

Class TransitionInOutElastic Implements Transition
    Private

    Const P:Float = 0.45
    Const S:Float = P / 4

    Public

    Method Calculate:Float(progress:Float)
        progress *= 2
        If progress = 2 Then Return 1

        If progress < 1 Then
            progress -= 1
            Return -0.5 * (Pow(2, 10 * progress) * Sinr((progress - S) * TWOPI / P))
        Else
            progress -= 1
            Return Pow(2, -10 * progress) * Sinr((progress - S) * TWOPI / P) * 0.5 + 1
        End
    End
End

Class TransitionInBack Implements Transition
    Method Calculate:Float(progress:Float)
        Return Pow(progress, 2) * (2.70158 * progress - 1.70158)
    End
End

Class TransitionOutBack Implements Transition
    Method Calculate:Float(progress:Float)
        progress -= 1
        Return Pow(progress, 2) * (2.70158 * progress + 1.70158) + 1
    End
End

Class TransitionInOutBack Implements Transition
    Private

    Const S:Float = 1.70158 * 1.525

    Public

    Method Calculate:Float(progress:Float)
        progress *= 2
        If progress < 1 Then Return 0.5 * (Pow(progress, 2) * ((S + 1) * progress - S))

        progress -= 2
        Return 0.5 * (Pow(progress, 2) * ((S + 1) * progress + S) + 2)
    End
End

Class TransitionInBounce Implements Transition
    Method Calculate:Float(progress:Float)
        Return InBounce(progress)
    End
End

Class TransitionOutBounce Implements Transition
    Method Calculate:Float(progress:Float)
        Return OutBounce(progress)
    End
End

Class TransitionInOutBounce Implements Transition
    Method Calculate:Float(progress:Float)
        progress *= 2
        If progress < 1 Then Return InBounce(progress) * 0.5

        Return OutBounce(progress - 1) * 0.5 + 0.5
    End
End

Class TransitionRandom Implements Transition
    Private

    Field transition:Transition
    Field minDiviation:Float
    Field maxDiviation:Float
    Field maxDiviationHalf:Float

    Public

    Method New(minDiviation:Float=0, maxDiviation:Float=1, transition:Transition)
        Self.minDiviation = minDiviation
        Self.maxDiviation = maxDiviation
        Self.transition = transition
        maxDiviationHalf = maxDiviation / 2
    End

    Method Calculate:Float(progress:Float)
        If progress >= 1 Then Return progress
        If progress <= 0 Then Return progress
        If Not transition Then Return Rnd(0, 1)

        progress = transition.Calculate(progress)

        Local diviation:Float
        Repeat
            diviation = Rnd(maxDiviationHalf * -1, maxDiviationHalf)
        Until diviation > minDiviation Or diviation < (minDiviation * -1)

        Return progress + diviation
    End
End


Added exit from demo splitscreen

Added exit from demo splitscreen

Strict

Import flixel
Import assets

Class PlayState Extends FlxState

	Global ClassObject:FlxClass = New PlayStateClass()

	Field level:FlxTilemap
	Field player1:FlxSprite
	Field player2:FlxSprite

	Method Create:Void()
		FlxG.mouse.Show()

		level = New FlxTilemap()
		level.LoadMap(FlxAssetsManager.GetString(Assets.LEVEL_DATA), FlxTilemap.AUTOTILES, 0, 0, FlxTilemap.AUTO)
		Add(level)

		player1 = (New FlxSprite(65, 200)).MakeGraphic(10, 12, $FFFF0000)
		player1.maxVelocity.x = 80
		player1.maxVelocity.y = 200
		player1.acceleration.y = 200
		player1.drag.x = player1.maxVelocity.x * 4
		Add(player1)

		player2 = (New FlxSprite(265, 200)).MakeGraphic(10, 12, $FF0000FF)
		player2.maxVelocity.x = 80
		player2.maxVelocity.y = 200
		player2.acceleration.y = 200
		player2.drag.x = player1.maxVelocity.x * 4
		Add(player2)

		Local cam:FlxCamera = New FlxCamera(0, 0, FlxG.width / 2, FlxG.height)
		cam.BgColor = $FFFDCBCB
		cam.Follow(player2)
		cam.SetBounds(0, 0, level.width, level.height)
		FlxG.AddCamera(cam)

		cam= New FlxCamera(FlxG.width / 2, 0, FlxG.width / 2, FlxG.height)
		cam.BgColor = $FFCBCBFD
		cam.Follow(player1)
		cam.SetBounds(0, 0, level.width, level.height)
		FlxG.AddCamera(cam)

		FlxG.camera.active = False
	End Method

	Method Update:Void()
		FlxG.Collide()

		player1.acceleration.x = 0

		If (FlxG.keys.Left) Then
			player1.acceleration.x = -player1.maxVelocity.x * 4
		End If

		If (FlxG.keys.Right) Then
			player1.acceleration.x = player1.maxVelocity.x * 4
		End If

		If (FlxG.keys.JustPressed(KEY_UP) And player1.IsTouching(FlxObject.FLOOR)) Then
			player1.velocity.y -= player1.maxVelocity.y / 1.5
		End If

		player2.acceleration.x = 0

		If (FlxG.keys.A) Then
			player2.acceleration.x = -player2.maxVelocity.x * 4
		End If

		If (FlxG.keys.D) Then
			player2.acceleration.x = player2.maxVelocity.x * 4
		End If

		If (FlxG.keys.JustPressed(KEY_W) And player2.IsTouching(FlxObject.FLOOR)) Then
			player2.velocity.y -= player2.maxVelocity.y / 1.5
		End If

		If (FlxG.keys.JustPressed(KEY_ESCAPE)) Error ""

		Super.Update()
	End Method

End Class

Class PlayStateClass Implements FlxClass

	Method CreateInstance:Object()
		Return New PlayState()
	End Method

	Method InstanceOf:Bool(object:Object)
		Return PlayState(object) <> Null
	End Method

End Class

Strict

Import flixel
Import assets

Class PlayState Extends FlxState

	Global ClassObject:FlxClass = New PlayStateClass()

	Field level:FlxTilemap
	Field player1:FlxSprite
	Field player2:FlxSprite

	Method Create:Void()
		FlxG.mouse.Show()

		level = New FlxTilemap()
		level.LoadMap(FlxAssetsManager.GetString(Assets.LEVEL_DATA), FlxTilemap.AUTOTILES, 0, 0, FlxTilemap.AUTO)
		Add(level)

		player1 = (New FlxSprite(65, 200)).MakeGraphic(10, 12, $FFFF0000)
		player1.maxVelocity.x = 80
		player1.maxVelocity.y = 200
		player1.acceleration.y = 200
		player1.drag.x = player1.maxVelocity.x * 4
		Add(player1)

		player2 = (New FlxSprite(265, 200)).MakeGraphic(10, 12, $FF0000FF)
		player2.maxVelocity.x = 80
		player2.maxVelocity.y = 200
		player2.acceleration.y = 200
		player2.drag.x = player1.maxVelocity.x * 4
		Add(player2)

		Local cam:FlxCamera = New FlxCamera(0, 0, FlxG.width / 2, FlxG.height)
		cam.BgColor = $FFFDCBCB
		cam.Follow(player2)
		cam.SetBounds(0, 0, level.width, level.height)
		FlxG.AddCamera(cam)

		cam= New FlxCamera(FlxG.width / 2, 0, FlxG.width / 2, FlxG.height)
		cam.BgColor = $FFCBCBFD
		cam.Follow(player1)
		cam.SetBounds(0, 0, level.width, level.height)
		FlxG.AddCamera(cam)

		FlxG.camera.active = False
	End Method

	Method Update:Void()
		FlxG.Collide()

		player1.acceleration.x = 0

		If (FlxG.keys.Left) Then
			player1.acceleration.x = -player1.maxVelocity.x * 4
		End If

		If (FlxG.keys.Right) Then
			player1.acceleration.x = player1.maxVelocity.x * 4
		End If

		If (FlxG.keys.JustPressed(KEY_UP) And player1.IsTouching(FlxObject.FLOOR)) Then
			player1.velocity.y -= player1.maxVelocity.y / 1.5
		End If

		player2.acceleration.x = 0

		If (FlxG.keys.A) Then
			player2.acceleration.x = -player2.maxVelocity.x * 4
		End If

		If (FlxG.keys.D) Then
			player2.acceleration.x = player2.maxVelocity.x * 4
		End If

		If (FlxG.keys.JustPressed(KEY_W) And player2.IsTouching(FlxObject.FLOOR)) Then
			player2.velocity.y -= player2.maxVelocity.y / 1.5
		End If

		Super.Update()
	End Method

End Class

Class PlayStateClass Implements FlxClass

	Method CreateInstance:Object()
		Return New PlayState()
	End Method

	Method InstanceOf:Bool(object:Object)
		Return PlayState(object) <> Null
	End Method

End Class


Added stubs to the other targets

Added stubs to the other targets

--HG--
extra : convert_revision : svn%3Ae934d3cd-0d57-f34a-94d0-9e8d31ae1c29/trunk%404

Import "native/diddy.${TARGET}.${LANG}"

Extern

	#If LANG="cpp" Then
		Function RealMillisecs:Int() = "diddy::systemMillisecs"
		Function FlushKeys:Void() = "diddy::flushKeys"

	#Else
		Function RealMillisecs:Int() = "diddy.systemMillisecs"
		Function FlushKeys:Void() = "diddy.flushKeys"

	#End

Public

Import "native/diddy.${TARGET}.${LANG}"

Extern

	#If TARGET="android" Then
		Function RealMillisecs:Int() = "diddy.systemMillisecs"
		Function FlushKeys:Void() = "diddy.flushKeys"

	#Else If TARGET="html5"
		Function RealMillisecs:Int() = "systemMillisecs"
		Function FlushKeys:Void() = "flushKeys"

	#Else If TARGET="flash"
		Function RealMillisecs:Int() = "systemMillisecs"
		Function FlushKeys:Void() = "flushKeys"

	#Endif

Public


Connect and Disconnect now returns observers

Strict

Import reflection
Import system.signals.flxsignal

Class FlxSignals

Private
	Field _signals:IntMap<FlxSignal>

	Field _methodSlots:List<FlxMethodSlot>

	Field _functionSlots:List<FlxFunctionSlot>

Public
	Method New()
		_signals = New IntMap<FlxSignal>()
		_methodSlots = New List<FlxMethodSlot>()
		_functionSlots = New List<FlxFunctionSlot>()
	End Method

	Method Destroy:Void(signalID:Int)
		Local s:FlxSignal = _signals.Get(signalID)
		If (s <> Null) s.Destroy()
	End Method

	Method Destroy:Void()
		For Local signal:FlxSignal = EachIn _signals.Values()
			signal.Destroy()
		Next

		_signals.Clear()

		Local methodSlotNode:list.Node<FlxMethodSlot> = _methodSlots.FirstNode()

		While (methodSlotNode <> Null)
			methodSlotNode.Value().Destroy()
			methodSlotNode.Remove()

			methodSlotNode = methodSlotNode.NextNode()
		Wend

		Local functionSlotNode:list.Node<FlxFunctionSlot> = _functionSlots.FirstNode()

		While (methodSlotNode <> Null)
			functionSlotNode.Value().Destroy()
			functionSlotNode.Remove()

			functionSlotNode = functionSlotNode.NextNode()
		Wend

		_methodSlots.Clear()
		_functionSlots.Clear()
	End Method

	Method Connect:FlxSignalObserver(signalID:Int, listener:FlxSignalListener)
		Return _GetSignal(signalID).RegisterListener(listener)
	End Method

	Method Connect:FlxSignalObserver(signalID:Int, listener:FlxSignalListener, instant:Bool)
		Return _GetSignal(signalID).RegisterListener(listener, instant)
	End Method

	Method Connect:FlxSignalObserver(signalID:Int, listener:FlxSignalListener, instant:Bool, priority:Int)
		Return _GetSignal(signalID).RegisterListener(listener, instant, priority)
	End Method

	Method Connect:FlxSignalObserver(signalID:Int, methodInfo:MethodInfo, context:Object)
		Return Connect(signalID, _GetMethodSlot(methodInfo, context))
	End Method

	Method Connect:FlxSignalObserver(signalID:Int, methodInfo:MethodInfo, context:Object, instant:Bool)
		Return Connect(signalID, _GetMethodSlot(methodInfo, context), instant)
	End Method

	Method Connect:FlxSignalObserver(signalID:Int, methodInfo:MethodInfo, context:Object, instant:Bool, priority:Int)
		Return Connect(signalID, _GetMethodSlot(methodInfo, context), instant, priority)
	End Method

	Method Connect:FlxSignalObserver(signalID:Int, functionInfo:FunctionInfo)
		Return Connect(signalID, _GetFunctionSlot(functionInfo))
	End Method

	Method Connect:FlxSignalObserver(signalID:Int, functionInfo:FunctionInfo, instant:Bool)
		Return Connect(signalID, _GetFunctionSlot(functionInfo), instant)
	End Method

	Method Connect:FlxSignalObserver(signalID:Int, functionInfo:FunctionInfo, instant:Bool, priority:Int)
		Return Connect(signalID, _GetFunctionSlot(functionInfo), instant, priority)
	End Method

	Method ConnectM:FlxSignalObserver(signalID:Int, methodName:String, context:Object)
		Return Connect(signalID, _GetMethodSlot(_GetMethodInfo(methodName, context), context))
	End Method

	Method ConnectM:FlxSignalObserver(signalID:Int, methodName:String, context:Object, instant:Bool)
		Return Connect(signalID, _GetMethodSlot(_GetMethodInfo(methodName, context), context), instant)
	End Method

	Method ConnectM:FlxSignalObserver(signalID:Int, methodName:String, context:Object, instant:Bool, priority:Int)
		Return Connect(signalID, _GetMethodSlot(_GetMethodInfo(methodName, context), context), instant, priority)
	End Method

	Method ConnectF:FlxSignalObserver(signalID:Int, functionName:String)
		Return Connect(signalID, _GetFunctionSlot(GetFunction(functionName,[])))
	End Method

	Method ConnectF:FlxSignalObserver(signalID:Int, functionName:String, instant:Bool)
		Return Connect(signalID, _GetFunctionSlot(GetFunction(functionName,[])), instant)
	End Method

	Method ConnectF:FlxSignalObserver(signalID:Int, functionName:String, instant:Bool, priority:Int)
		Return Connect(signalID, _GetFunctionSlot(GetFunction(functionName,[])), instant, priority)
	End Method

	Method Disconnect:FlxSignalObserver(signalID:Int, listener:FlxSignalListener)
		Local s:FlxSignal = _signals.Get(signalID)
		If (s <> Null) Return s.RemoveListener(listener)

		Return Null
	End Method

	Method Disconnect:FlxSignalObserver(signalID:Int, methodInfo:MethodInfo, context:Object)
		Return Disconnect(signalID, _GetMethodSlot(methodInfo, context))
	End Method

	Method Disconnect:FlxSignalObserver(signalID:Int, functionInfo:FunctionInfo)
		Return Disconnect(signalID, _GetFunctionSlot(functionInfo))
	End Method

	Method DisconnectM:FlxSignalObserver(signalID:Int, methodName:String, context:Object)
		Return Disconnect(signalID, _GetMethodSlot(_GetMethodInfo(methodName, context), context))
	End Method

	Method DisconnectF:FlxSignalObserver(signalID:Int, functionName:String)
		Return Disconnect(signalID, _GetFunctionSlot(GetFunction(functionName,[])))
	End Method

	Method Emit:Void(signalID:Int, data:Object = Null)
		_GetSignal(signalID).Emit(data)
	End Method

	Method Emit:Void(signalIDs:Int[], data:Object = Null)
		For Local id:Int = EachIn signalIDs
			_GetSignal(id).Emit(data)
		Next
	End Method

	Method Emit:Void(data:Object = Null)
		For Local signal:FlxSignal = EachIn _signals.Values()
			signal.Emit(data)
		Next
	End Method

	Method Clear:Void(signalID:Int)
		Local s:FlxSignal = _signals.Get(signalID)
		If (s <> Null) s.Clear()
	End Method

	Method Clear:Void()
		For Local signal:FlxSignal = EachIn _signals.Values()
			signal.Clear()
		Next
	End Method

Private
	Method _GetSignal:FlxSignal(signalID:Int)
		Local s:FlxSignal = _signals.Get(signalID)

		If (s = Null) Then
			s = New FlxSignal(signalID)
			_signals.Set(signalID, s)
		End If

		Return s
	End Method

	Method _GetMethodInfo:MethodInfo(methodName:String, context:Object)
		Local classInfo:ClassInfo = GetClass(context)

		If (classInfo <> Null) Then
			Return classInfo.GetMethod(methodName,[])
		End If

		Return Null
	End Method

	Method _GetMethodSlot:FlxMethodSlot(methodInfo:MethodInfo, context:Object)
		If (methodInfo = Null) Return Null

		Local node:list.Node<FlxMethodSlot> = _methodSlots.FirstNode()

		While (node <> Null)
			If (node.Value()._method = methodInfo And node.Value()._context = context) Then
				Return node.Value()
			End If

			node = node.NextNode()
		Wend

		Return _methodSlots.AddLast(New FlxMethodSlot(context, methodInfo)).Value()
	End Method

	Method _GetFunctionSlot:FlxFunctionSlot(functionInfo:FunctionInfo)
		If (functionInfo = Null) Return Null

		Local node:list.Node<FlxFunctionSlot> = _functionSlots.FirstNode()

		While (node <> Null)
			If (node.Value()._function = functionInfo) Then
				Return node.Value()
			End If

			node = node.NextNode()
		Wend

		Return _functionSlots.AddLast(New FlxFunctionSlot(functionInfo)).Value()
	End Method

End Class

Private

Class FlxMethodSlot Implements FlxSignalListener

Private
	Field _context:Object

	Field _method:MethodInfo

Public
	Method New(context:Object, methodInfo:MethodInfo)
		_context = context
		_method = methodInfo
	End Method

	Method Destroy:Void()
		_context = Null
		_method = Null
	End Method

	Method OnSignalEmitted:Void(signal:FlxSignal, data:Object)
		_method.Invoke(_context,[])
	End Method

End Class

Class FlxFunctionSlot Implements FlxSignalListener

Private
	Field _function:FunctionInfo

Public
	Method New(functionInfo:FunctionInfo)
		_function = functionInfo
	End Method

	Method Destroy:Void()
		_function = Null
	End Method

	Method OnSignalEmitted:Void(signal:FlxSignal, data:Object)
		_function.Invoke([])
	End Method

End Class

Strict

Import reflection
Import system.signals.flxsignal

Class FlxSignals

Private
	Field _signals:IntMap<FlxSignal>

	Field _methodSlots:List<FlxMethodSlot>

	Field _functionSlots:List<FlxFunctionSlot>

Public
	Method New()
		_signals = New IntMap<FlxSignal>()
		_methodSlots = New List<FlxMethodSlot>()
		_functionSlots = New List<FlxFunctionSlot>()
	End Method

	Method Destroy:Void(signalID:Int)
		Local s:FlxSignal = _signals.Get(signalID)
		If (s <> Null) s.Destroy()
	End Method

	Method Destroy:Void()
		For Local signal:FlxSignal = EachIn _signals.Values()
			signal.Destroy()
		Next

		_signals.Clear()

		Local methodSlotNode:list.Node<FlxMethodSlot> = _methodSlots.FirstNode()

		While (methodSlotNode <> Null)
			methodSlotNode.Value().Destroy()
			methodSlotNode.Remove()

			methodSlotNode = methodSlotNode.NextNode()
		Wend

		Local functionSlotNode:list.Node<FlxFunctionSlot> = _functionSlots.FirstNode()

		While (methodSlotNode <> Null)
			functionSlotNode.Value().Destroy()
			functionSlotNode.Remove()

			functionSlotNode = functionSlotNode.NextNode()
		Wend

		_methodSlots.Clear()
		_functionSlots.Clear()
	End Method

	Method Connect:Void(signalID:Int, listener:FlxSignalListener)
		_GetSignal(signalID).RegisterListener(listener)
	End Method

	Method Connect:Void(signalID:Int, listener:FlxSignalListener, instant:Bool)
		_GetSignal(signalID).RegisterListener(listener, instant)
	End Method

	Method Connect:Void(signalID:Int, listener:FlxSignalListener, instant:Bool, priority:Int)
		_GetSignal(signalID).RegisterListener(listener, instant, priority)
	End Method

	Method Connect:Void(signalID:Int, methodInfo:MethodInfo, context:Object)
		Connect(signalID, _GetMethodSlot(methodInfo, context))
	End Method

	Method Connect:Void(signalID:Int, methodInfo:MethodInfo, context:Object, instant:Bool)
		Connect(signalID, _GetMethodSlot(methodInfo, context), instant)
	End Method

	Method Connect:Void(signalID:Int, methodInfo:MethodInfo, context:Object, instant:Bool, priority:Int)
		Connect(signalID, _GetMethodSlot(methodInfo, context), instant, priority)
	End Method

	Method Connect:Void(signalID:Int, functionInfo:FunctionInfo)
		Connect(signalID, _GetFunctionSlot(functionInfo))
	End Method

	Method Connect:Void(signalID:Int, functionInfo:FunctionInfo, instant:Bool)
		Connect(signalID, _GetFunctionSlot(functionInfo), instant)
	End Method

	Method Connect:Void(signalID:Int, functionInfo:FunctionInfo, instant:Bool, priority:Int)
		Connect(signalID, _GetFunctionSlot(functionInfo), instant, priority)
	End Method

	Method ConnectM:Void(signalID:Int, methodName:String, context:Object)
		Connect(signalID, _GetMethodSlot(_GetMethodInfo(methodName, context), context))
	End Method

	Method ConnectM:Void(signalID:Int, methodName:String, context:Object, instant:Bool)
		Connect(signalID, _GetMethodSlot(_GetMethodInfo(methodName, context), context), instant)
	End Method

	Method ConnectM:Void(signalID:Int, methodName:String, context:Object, instant:Bool, priority:Int)
		Connect(signalID, _GetMethodSlot(_GetMethodInfo(methodName, context), context), instant, priority)
	End Method

	Method ConnectF:Void(signalID:Int, functionName:String)
		Connect(signalID, _GetFunctionSlot(GetFunction(functionName,[])))
	End Method

	Method ConnectF:Void(signalID:Int, functionName:String, instant:Bool)
		Connect(signalID, _GetFunctionSlot(GetFunction(functionName,[])), instant)
	End Method

	Method ConnectF:Void(signalID:Int, functionName:String, instant:Bool, priority:Int)
		Connect(signalID, _GetFunctionSlot(GetFunction(functionName,[])), instant, priority)
	End Method

	Method Disconnect:Void(signalID:Int, listener:FlxSignalListener)
		Local s:FlxSignal = _signals.Get(signalID)
		If (s <> Null) s.RemoveListener(listener)
	End Method

	Method Disconnect:Void(signalID:Int, methodInfo:MethodInfo, context:Object)
		Disconnect(signalID, _GetMethodSlot(methodInfo, context))
	End Method

	Method Disconnect:Void(signalID:Int, functionInfo:FunctionInfo)
		Disconnect(signalID, _GetFunctionSlot(functionInfo))
	End Method

	Method DisconnectM:Void(signalID:Int, methodName:String, context:Object)
		Disconnect(signalID, _GetMethodSlot(_GetMethodInfo(methodName, context), context))
	End Method

	Method DisconnectF:Void(signalID:Int, functionName:String)
		Disconnect(signalID, _GetFunctionSlot(GetFunction(functionName,[])))
	End Method

	Method Emit:Void(signalID:Int, data:Object = Null)
		_GetSignal(signalID).Emit(data)
	End Method

	Method Emit:Void(signalIDs:Int[], data:Object = Null)
		For Local id:Int = EachIn signalIDs
			_GetSignal(id).Emit(data)
		Next
	End Method

	Method Emit:Void(data:Object = Null)
		For Local signal:FlxSignal = EachIn _signals.Values()
			signal.Emit(data)
		Next
	End Method

	Method Clear:Void(signalID:Int)
		Local s:FlxSignal = _signals.Get(signalID)
		If (s <> Null) s.Clear()
	End Method

	Method Clear:Void()
		For Local signal:FlxSignal = EachIn _signals.Values()
			signal.Clear()
		Next
	End Method

Private
	Method _GetSignal:FlxSignal(signalID:Int)
		Local s:FlxSignal = _signals.Get(signalID)

		If (s = Null) Then
			s = New FlxSignal(signalID)
			_signals.Set(signalID, s)
		End If

		Return s
	End Method

	Method _GetMethodInfo:MethodInfo(methodName:String, context:Object)
		Local classInfo:ClassInfo = GetClass(context)

		If (classInfo <> Null) Then
			Return classInfo.GetMethod(methodName,[])
		End If

		Return Null
	End Method

	Method _GetMethodSlot:FlxMethodSlot(methodInfo:MethodInfo, context:Object)
		If (methodInfo = Null) Return Null

		Local node:list.Node<FlxMethodSlot> = _methodSlots.FirstNode()

		While (node <> Null)
			If (node.Value()._method = methodInfo And node.Value()._context = context) Then
				Return node.Value()
			End If

			node = node.NextNode()
		Wend

		Return _methodSlots.AddLast(New FlxMethodSlot(context, methodInfo)).Value()
	End Method

	Method _GetFunctionSlot:FlxFunctionSlot(functionInfo:FunctionInfo)
		If (functionInfo = Null) Return Null

		Local node:list.Node<FlxFunctionSlot> = _functionSlots.FirstNode()

		While (node <> Null)
			If (node.Value()._function = functionInfo) Then
				Return node.Value()
			End If

			node = node.NextNode()
		Wend

		Return _functionSlots.AddLast(New FlxFunctionSlot(functionInfo)).Value()
	End Method

End Class

Private

Class FlxMethodSlot Implements FlxSignalListener

Private
	Field _context:Object

	Field _method:MethodInfo

Public
	Method New(context:Object, methodInfo:MethodInfo)
		_context = context
		_method = methodInfo
	End Method

	Method Destroy:Void()
		_context = Null
		_method = Null
	End Method

	Method OnSignalEmitted:Void(signal:FlxSignal, data:Object)
		_method.Invoke(_context,[])
	End Method

End Class

Class FlxFunctionSlot Implements FlxSignalListener

Private
	Field _function:FunctionInfo

Public
	Method New(functionInfo:FunctionInfo)
		_function = functionInfo
	End Method

	Method Destroy:Void()
		_function = Null
	End Method

	Method OnSignalEmitted:Void(signal:FlxSignal, data:Object)
		_function.Invoke([])
	End Method

End Class


Added missing return statement.

Added missing return statement.

--HG--
extra : convert_revision : svn%3Ae934d3cd-0d57-f34a-94d0-9e8d31ae1c29/trunk%40253

Strict

Import diddy

Function Main:Int()
	New TestApp
End Function

Class TestApp Extends App
	Field fileHandler:FileSystem

	Method OnCreate:Int()
		Self.fileHandler = New FileSystem
		Local stream:FileStream
		stream = Self.fileHandler.WriteFile("test.bin")
		stream.WriteString("Hello World!")
		stream.WriteFloat(1.234567890)

		Self.fileHandler.SaveAll()
		Self.fileHandler.ListDir()

		stream = Self.fileHandler.ReadFile("test.bin")
		if stream
			Print stream.ReadString()
			Print stream.ReadFloat()
		End
		Return 0
	End
End

Strict

Import diddy

Function Main:Int()
	New TestApp
End Function

Class TestApp Extends App
	Field fileHandler:FileSystem

	Method OnCreate:Int()
		Self.fileHandler = New FileSystem
		Local stream:FileStream
		stream = Self.fileHandler.WriteFile("test.bin")
		stream.WriteString("Hello World!")
		stream.WriteFloat(1.234567890)

		Self.fileHandler.SaveAll()
		Self.fileHandler.ListDir()

		stream = Self.fileHandler.ReadFile("test.bin")
		if stream
			Print stream.ReadString()
			Print stream.ReadFloat()
		End
	End
End