Understanding asynchronus mode

Find quick help here to get you started with Hollywood
Post Reply
LarsB
Posts: 53
Joined: Sat May 06, 2017 4:37 pm

Understanding asynchronus mode

Post by LarsB » Thu Aug 22, 2019 1:35 pm

Hi,
just trying to find out how the async Tag can help me. I have two layers. Both I do move.
Of course, if I dont do asynchronously they are doing it one step after another.
Now I use the async = true tag to make them move simultaniously. But they dont move.
Can I change that?

@DISPLAY {Mode = "Windowed", Width = 960, Height = 610}
EnableLayers()

CreateLayer(0, 0, 300, 300,{Color=#BLUE})
CreateLayer(30, 300, 145, 32,{Color=#GREEN})
WaitKeyDown("Return")

/*Moves Layers not snchronously, but moves*/
MoveLayer(1, #USELAYERPOSITION, #USELAYERPOSITION, #CENTER, #CENTER)
MoveLayer(2, #USELAYERPOSITION, #USELAYERPOSITION, #CENTER, #CENTER)

WaitKeyDown("Return")

/*Moving Layers back*/
MoveLayer(1, #USELAYERPOSITION, #USELAYERPOSITION, 0,0)
MoveLayer(2, #USELAYERPOSITION, #USELAYERPOSITION, 30,300)

WaitKeyDown("Return")

/*Does not move afterall*/
MoveLayer(1, #USELAYERPOSITION, #USELAYERPOSITION, #CENTER, #CENTER,{Async=True})
MoveLayer(2, #USELAYERPOSITION, #USELAYERPOSITION, #CENTER, #CENTER,{Async=True})

WaitKeyDown("Return")

User avatar
emeck
Posts: 80
Joined: Fri Apr 03, 2015 3:17 pm

Re: Understanding asynchronus mode

Post by emeck » Thu Aug 22, 2019 6:19 pm

Hello,

I also had trouble trying to understand Asyncronous operation, but I think I'm understanding it a bit now. So others could do a better explanation. But this works for me from your example code. You have to call AsyncDrawFrame to actually show your async objects.

Code: Select all

@DISPLAY {Mode = "Windowed", Width = 960, Height = 610}
EnableLayers()

CreateLayer(0, 0, 300, 300,{Color=#BLUE})
CreateLayer(30, 300, 145, 32,{Color=#GREEN})
WaitKeyDown("Return")

/*Moves Layers not snchronously, but moves*/
MoveLayer(1, #USELAYERPOSITION, #USELAYERPOSITION, #CENTER, #CENTER)
MoveLayer(2, #USELAYERPOSITION, #USELAYERPOSITION, #CENTER, #CENTER)

WaitKeyDown("Return")

/*Moving Layers back*/
MoveLayer(1, #USELAYERPOSITION, #USELAYERPOSITION, 0,0)
MoveLayer(2, #USELAYERPOSITION, #USELAYERPOSITION, 30,300)

WaitKeyDown("Return")

/*
 * Changes begin here
 */
 
/*Does not move YET*/
object1 = MoveLayer(1, #USELAYERPOSITION, #USELAYERPOSITION, #CENTER, #CENTER,{Async=True})
object2 = MoveLayer(2, #USELAYERPOSITION, #USELAYERPOSITION, #CENTER, #CENTER,{Async=True})

/*Here it moves your layers*/
Repeat
    If Not done Then done = AsyncDrawFrame(object1)
    If Not finish Then finish = AsyncDrawFrame(object2)
    VWait
Until (done = True And finish = True)

WaitKeyDown("Return") 
Using the Async=True tag you create an async draw object that has n frames ("object1" and "object2" in your example), which then need to be shown with the AsyncDrawFrame function. This function returns False if there are still frames to be drawn. Because object1 and object2 in your example move different distance, the frame number is not the same for both, so I check with different variables("done" and "finish") during the loop. The loop finishes when BOTH have drawn all its frames. Inside the loop, the conditional checks if each async object still have frames to draw before attempting to draw it, otherwise at some point it will error due to one not existing while the other still does.

Hope it helps you. Maybe someone can show us a better way.
PowerBook 5.2 MorphOS 3.12
PowerBook 5.8 MorphOS 3.12
Amiga 1200 BPPC/BVision AOS4.1 FE

LarsB
Posts: 53
Joined: Sat May 06, 2017 4:37 pm

Re: Understanding asynchronus mode

Post by LarsB » Fri Aug 23, 2019 12:33 pm

Hey, great. It works and its a very good explanation. Brings me really forward. :)

LarsB
Posts: 53
Joined: Sat May 06, 2017 4:37 pm

Re: Understanding asynchronus mode

Post by LarsB » Fri Aug 23, 2019 2:32 pm

Just to continue the madness ... ;) .. btw how do you display the code segments properly?

@DISPLAY {Mode = "Windowed", Width = 960, Height = 610,Color=#WHITE}
@FONT 1, "Arial",32

EnableLayers()
CreateLayer(0, 0, 300, 300,{Color=#BLUE})
CreateLayer(30, 300, 145, 32,{Color=#GREEN})
CreateLayer(60, 200, 245, 64,{Color=#RED})

LayerToFront(1, noswap=False)

WaitKeyDown("Return")

/*Moves Layers not synchronously, but moves*/
MoveLayer(1, #USELAYERPOSITION, #USELAYERPOSITION, #CENTER, #CENTER)
MoveLayer(2, #USELAYERPOSITION, #USELAYERPOSITION, #CENTER, #CENTER)

SetLayerBorder(1, True, #BLACK,10)

WaitKeyDown("Return")

/*Moving Layers back*/
SetLayerShadow(2, True, ARGB(128, $00ff00),6,7,3)

LayerToFront(1, noswap = False)

MoveLayer(3, #USELAYERPOSITION, #USELAYERPOSITION, 10,10)
MoveLayer(2, #USELAYERPOSITION, #USELAYERPOSITION, 30,300)

WaitKeyDown("Return")

/*using not the asynchronous mode*/
x1= 0
x2 = 30

For i = 1 To 500
ShowLayer(1, x1+i,#USELAYERPOSITION)
ShowLayer(2, x2+i,#USELAYERPOSITION)
Next
WaitKeyDown("Return")

SetLayerShadow(2, True, ARGB(128, #BLACK),6,7,3)

/*Using the asynchronous Layer. Thanks to emmeck very much*/
object1 = MoveLayer(1, #USELAYERPOSITION, #USELAYERPOSITION, #CENTER, #CENTER,{Async=True})
object2 = MoveLayer(2, #USELAYERPOSITION, #USELAYERPOSITION, #CENTER, #CENTER,{Async=True})

/*Here it moves your layers*/
Repeat
If Not done Then done = AsyncDrawFrame(object1)
If Not finish Then finish = AsyncDrawFrame(object2)
VWait
Until (done = True And finish = True)

WaitKeyDown("Return")

User avatar
emeck
Posts: 80
Joined: Fri Apr 03, 2015 3:17 pm

Re: Understanding asynchronus mode

Post by emeck » Mon Aug 26, 2019 7:49 pm

For the code segment, you have to use the [_code] and [_/code] tags but without the underscore, like this:

[_code]
Your code here
[_/code]

And removing the undescore it shows:

Code: Select all

Your code here
PowerBook 5.2 MorphOS 3.12
PowerBook 5.8 MorphOS 3.12
Amiga 1200 BPPC/BVision AOS4.1 FE

LarsB
Posts: 53
Joined: Sat May 06, 2017 4:37 pm

Re: Understanding asynchronus mode

Post by LarsB » Tue Aug 27, 2019 12:46 pm

Thank you :)

Post Reply