AssetsManager do the networking on main thread


#1

That’s what AssetsManagerTest looks like.

So developers, not cocos2d-x have to do the threading, what we want is:

  1. cocos2d-x do the threading, games just get callback, like CCHttpClient
  2. user can cancel downloading anytime

will you guys consider doing these?


#2

is it this forbidden by apple to do the networking on the main thread ?


#3

sKy wAr wrote:

That’s what AssetsManagerTest looks like.
>
So developers, not cocos2d-x have to do the threading, what we want is:

  1. cocos2d-x do the threading, games just get callback, like CCHttpClient
  2. user can cancel downloading anytime
    >
    will you guys consider doing these?

1:you can use CCDirector::sharedDirector()->getScheduler()->scheduleSelector to do callback to notify the main thread .2:you can use close of curl to cancel downloading
BTW, the AssetsManagerTest is not so stable , if you click enter button 2 times, it will crash, maybe they don’t have enough time to test it , but it’s just a guiding for me.:slight_smile:


#4

Yep, AssetsManager will support downloading in a new thread later.
There are two ways to do it
* Change update(), make it download resources in a new thread.
* Add a new method, such as updateAsync(), to download resources in a new thread.

Which is better?

Of course, AssetsManager should add a method to stop downloading.

Thank you for your feedback.


#5

I have created #1857, #1858 and #1859 for them.


#6

Minggo Zhang wrote:

I have created #1857, #1858 and #1859 for them.

should we add an error callback of downloading?
OK, I hope it more useful :
1.support pause, resume , cancel downloading.
2.continue from last downloading.


#7

Minggo Zhang wrote:

Yep, AssetsManager will support downloading in a new thread later.
There are two ways to do it
* Change update(), make it download resources in a new thread.
* Add a new method, such as updateAsync(), to download resources in a new thread.
>
Which is better?
>
Of course, AssetsManager should add a method to stop downloading.
>
Thank you for your feedback.

option2,adding updateAsync() method, so that AssetsManager can do both sync and async downloading? it may not be a good thing to have too many options.
plus, it needs a lot more effort to document it, as i can see you guys are very good coders, not very good at documenting, :slight_smile:

i prefer option1, “* Change update(), make it download resources in a new thread.” and dispatch message to my main thread(getting call back) for:

  1. progress, so that i can modify my progress bar
  2. errors, sometimes games are Forbidden to download new versions to continue.

and i think pausing, resuming are alot to ask


#8

C ZhangsKy wAr

Thank you for your suggestion.

About errors, i think i can invoke a delegate when there is an error, but i think it is impossible to return error type,
because there are so many types of errors.
What’s your opinion?


#9

Minggo Zhang wrote:

C ZhangsKy wAr
>
Thank you for your suggestion.
>
About errors, i think i can invoke a delegate when there is an error, but i think it is impossible to return error type,
because there are so many types of errors.
What’s your opinion?

Exactly , I just care two errors : net and I/O errors , so I think it will be more useful if we can return the two error types at current version.
in the future , we can add more error types if someone wants to improve it.


#10

Ok, i will update this thread when i pull a request.


#11

I suggest to use non-blocking mode in the main thread,not use thread


#12

I have sent a pull request to download resources in a new thread.

@Dpull com
Could you describe it more detail?


#13

Using the curl_multi_init to create a non-blocking’s http request, through the the update function gradually the download is complete, to return to the: Success, failure, in the downloading