Although I am still exploring the texturemanager, I can tell you what I have learned so far. This may change
A: If you are using the asynchronous services of the manager, which most of us do, you need to keep it that way. So
you should perform what is known as hand-shaking. The best way I have found to do this so far is by using an associativearray
Create an associative array above the scope of your texture processing
Create your texturerequest. Once created the Unique ID is avalible so get it before you send the request to the texturemanager
and add it to your list along with the request.
Create a function or just Fire off all your requests and return without polling anything Function SendAll( urlArray As Object )
m.MyList.Clear()
for each url In urlArray
request = CreateObject( "roTextureRequest", url )
m.myList.AddReplace( request.GetID().ToStr(), request )
myTextureManager.RequestTexture( request )
end for
return
End Function
Once back in your message loop listen on the port you have defined for your TextureManager. It really is best to use a separate port only for your requests
Forget about wait and use getMessage ' Create and set the port
tPort = CreateObject( "roMessagePort")
myTextureManager.SetMessagePort( tPort )
' Send all requests
SendAll()
' Go into message loop
while true
' As they come in then just process each one
tmsg = tPort.GetMessage()
if tmsg <> Invalid
ReceiveTexture( tmsg)
end if
' If you have another interface port then you can process them as well. but they should be brief until all you sent is received. usually just to exit or
'scroll the screen
msg = uPort.Getmessage()
if msg <> Invalid....
end while
Now your receive would look something like thisFunction ReceiveTexture( msg As DYNAMIC ) As Void
' Create the string key and get the value from your list
key = msg.GetID().ToStr()
value = m.myList.LookUp( key )
' If the key is not found in your list (and this does happen) and the bitmap is also invalid then what is going on with the
' texture manager we are not told. (Could be that I am doing something I have not discovered yet but don't think so)
' It may have something to do with keeping an active connection alive until all is received
' However, if value is invalid but the bitmap is valid then likely there is something wrong with your code. You should use a dedicated port
' to receive only the requests that you sent, so no other bitmaps should be coming in that cannot be identified
if value = Invalid
if msg.GetBitmap() <> Invalid
try to find your error
end if
return
end if
' Ok now that you have a valid value just delete it from your list. With this method I have never had a duplicate key
m.myList.Delete( key )
' Now process the message
state = a_msg.GetState()
'If return state is 3 then process the bitmap if valid, should always be when you reach this point
if state = 3
bitmap = msg.GetBitmap()
if bitmap <> Invalid
Do something with the bitmap and return. As I mentioned above you can also use an aa to include a service or
parameters to instruct the screen where to draw
request = value.Request
rect = value.Rect
screen.DrawObject( rect.x, rect.y, bitmap)
return
else
may want to attempt to resend it but if you do use some type of counter so if there is something really wrong you only
resend a couple of times. I designed an object called AsyncManager that handles all this for me
end if
else if state = .....
...
end if
return True
End Function
Well that is the general idea. May be some typo mistakes but you should get the idea. In my AsyncManager object, I have counters, error lists so I always
know what is going on. I can also pre-fetch using a type of polling but if you do this you would send x number of requests and then poll. Do not send/poll each one
It seems that the more you send the more responsive it is. I have never seen a duplicate id using this method.
But, I would really like to know what is happening when I get these responses with invalid bitmap, state = 3,
my correct url, and an ID that is not in my list. seems to happen when things are a little slower
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )