Some random ideas regarding this feature
scripting-like API
One of the strong features of cocos2d, is that you can create actions without worrying about memory.
auto action = Sequence::create(
MoveBy::create( 2, ccp(240,0)),
RotateBy::create( 2, 540),
ScaleTo::create(1,0.1f),
RemoveSelf::create(),
NULL);
And I think the API should continue to be like that (either with retain/release/autorelease or with smart_ptrs)
I find super convenient that you can create actions like in C**.
smart_ptr vs retain/release/autorelease
On the one hand:
* std::shared_ptrs
are more c** friendly than manual retain/release/autorelease.
* you can use them with any std:: container. That means that we could get rid of all the CC containers (CCDictionary, CCSet, CCArray, CCString… etc.)
* but the API is more complex: you are returning a shared_ptr instead of a ptr. As Andre Rudlaff mentioned, you can simplify it by using typedefs, but still, it adds complexity.
On the other hand:
* retain/release/autorelease is an “imported pattern from objective-c”… in particular the autorelease
concept. It is not uncommon for c++ engines to use the retain/release model, but without the autorelease.
* And usually the API is easier to read and understand… you don’t need all the std::shared_ptr<> (or typedef’s for all the them)
* But then you need to have you own class containers (CCDictionary, CCArray, etc…), or you need to use your own smart_ptr to deal with your classes, which would be somewhat confusing
how to proceed
- I think that we still don’t know all the implications of migrating from retain/release/autorelease to shared_ptr. So, for the moment, at least for v3.0-alpha0 I wouldn’t migrate to shared_ptrs.
- I would like to understand all the implications: needed API changes, potential bugs and limitations, potential performance issues, understand the shared_ptr best practices, and then make the decision.
UPDATE: Yes, I agree with you Justin.
Regarding multithreading, I agree with Sergey (he mentioned this on the email list) that cocos2d should be able to run “tasks” in different threads (play sounds, effects, update the scene graph, render the scene graph, simulate physics), but we should not aim to have a completely multithreaded engine… that would be really difficult to maintain (it will add a lot of complexity in the code) and will be difficult to debug.