@Ben:
+1, yes please, start a new thread with it.
Thanks!
@Ben:
+1, yes please, start a new thread with it.
Thanks!
Jonathan Beck wrote:
@Dawid Drozd
Hey, I took a look at your GitHub. I am new to Cocos2d.I am wondering why in your Example Code section you name your variable “pSprite” ? Is it because in order to create a ComponentNode you must add a default type, which in that example is CCSprite? Or maybe more likely that you’re never going to have a game object that doesn’t include a CCSprite.
Or is it because Cocos2d doesn’t have the right inheritance setup to do something like create a base Component class, let’s call it CCComponent.
CCSprite inherits from CCComponent, along with TouchComponent, ClickComponent, etc. Then the code looks like:ComponentNode<CCComponent>* pGameObject = ComponentNode<CCComponent>::create();
pGameObject->getComponentManager().addComponent ( CCSprite::createWithFile ( R::Sprite::GUI_BUTTON_GREEN_9 ) );
pGameObject->getComponentManager().addComponent ( TouchComponent::create() );
pGameObject->getComponentManager().addComponent ( StandardPressActionComponent::create() );
pGameObject->getComponentManager().addComponent ( ClickComponent::create ( Utils::makeCallback ( this, &AchievementRow::onSkipClickedCallback ) ) );
Simply look at implementation of ComponentNode it only adds ability for callback such onEnter,onExit,update,visit (you can add more) and adds ComponentManager who is dealing with components.
For example i want CCSprite with my component system so i create it
ComponentNode< CCSprite >* pSprite; (pSprite is only name for my var it could be "myVariable")
So now i have something on my screen that can display image and it has my component system.
For example i want CCLayer with my component system so i create:
ComponentNode<CCLayer>* pLayer;
Next thing you must do is simpli init your object so call init* methods as you want.
My component system was created for back compability in my code for example in my code i use some CCSprite
CCSprite* pSprite = CCSprite::create("myfile.png");
.... // here i set position and other kind of stuff
so no i only need to change 2 lines.
ComponentNode< CCSprite >* pSprite = ComponentNode< CCSprite >::create();
pSprite->initWithFile("myfile.png");
.... // rest of the code
So it is simple to change your code to component system.
Also benefit form inheriting for example from CCSprite is that i can add it to CCSpriteBatchNode.
So class name in template variable is simply base class.
What you suggest my is also good thing but… i can’t add callbacks like onEnter etc. I must create something like
class MyCCSpriteClazz : public CCSprite
....
To add callback so now i must create X classes and override in them onEnter ,onExit … and add there my notyfications. I event more like your solutions but only problem i see is with callbacks for onEnter and onExit because i use them a lot. If you have any suggestions how to resolve this problem i will appreciate it :).
@Gene Han and all,
I just have made a refactoring about my ECS framework, now it’s support Cocos2d-x 3.0 beta2.
some feature:
1, based on the Origin Entity Component System idea(Decoupbe the system from component,this make it diff from Component-based design).
2, automatic attching system to Entity,you only need concern component.So,
3, it’s data-driven.
4, better performance,we make every Entity has it’s own System instance,but still keep auto-attaching,you do not need care about System.
5, lua binding support.(progress…)
6, system ordered.
BUT IT’S UNTESTED YET!!! I’m working on it.
I want to notice you after my test on Nexus 4 (ok it is quite good phone)
results:
avg1: 0µ, avg2: 1µ, min: 0µ, max: 977µ, total: 1.44s, nr calls: 1000000 Notifier_1kk_notify_to_1_listener
avg1: 0µ, avg2: 1µ, min: 0µ, max: 641µ, total: 1.46s, nr calls: 1000000 Notifier_1kk_notify_to_1_listener
avg1: 1µ, avg2: 3µ, min: 0µ, max: 12238µ,total: 3.87s, nr calls: 1000000 CCNotificationCenter_1kk_notify_to_1_listener
avg1: 0µ, avg2: 3µ, min: 0µ, max: 3204µ, total: 3.80s, nr calls: 1000000 CCNotificationCenter_1kk_notify_to_1_listener
avg1: 55µ, avg2: 50µ, min: 30µ, max: 10163µ,total: 5.03s, nr calls: 100000 Notifier_100k_notify_to_1k_listeners
avg1: 53µ, avg2: 49µ, min: 30µ, max: 1495µ, total: 4.99s, nr calls: 100000 Notifier_100k_notify_to_1k_listeners
avg1: 151µ, avg2: 151µ, min: 122µ, max: 2106µ, total: 15.13s, nr calls: 100000 CCNotificationCenter_100k_notify_to_1k_listeners
avg1: 154µ, avg2: 152µ, min: 122µ, max: 4334µ, total: 15.25s, nr calls: 100000 CCNotificationCenter_100k_notify_to_1k_listeners
avg1: 14µ, avg2: 18µ, min: 0µ, max: 519µ, total: 1.83s, nr calls: 100000 Notifier_100k_notify_to_1k_listener_multiple_notifications
avg1: 7µ, avg2: 18µ, min: 0µ, max: 1862µ, total: 1.86s, nr calls: 100000 Notifier_100k_notify_to_1k_listener_multiple_notifications
avg1: 129µ, avg2: 128µ, min: 91µ, max: 2319µ, total: 12.86s, nr calls: 100000 CCNotificationCenter_100k_notify_to_1k_listener_multiple_notifications
avg1: 137µ, avg2: 129µ, min: 91µ, max: 3449µ, total: 12.94s, nr calls: 100000 CCNotificationCenter_100k_notify_to_1k_listener_multiple_notifications
On last test i have 6x performance boost and test are done for best performance in CCNotificationCenter