Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifiers improved to be able to use them in more general pools : #208

Open
wants to merge 1 commit into
base: GLES2
Choose a base branch
from

Conversation

flomin
Copy link

@flomin flomin commented Apr 10, 2013

This patch improves the modifiers to be able to use them in pools:

  • reset methods taking a IEaseFunction as parameter added in BaseDoubleValueSpanModifier and BaseSingleValueSpanModifier classes
  • IModifier.clearModifierListeners method added to able to clear all modifier listeners when the modifier goes back in the pool
  • IModifier.onUnregister event method added to be able to recycle the modifier back to the pool easily
  • ModifierList.clear, remove and onUpdate method overridden from super class to call onUnregister event on modifiers

With this patch it's possible to create and use a pool of modifiers like this:

new GenericPool<MoveModifier> mMoveModifierPool = new GenericPool<MoveModifier>() {
    @Override
    protected MoveModifier onAllocatePoolItem() {
        final MoveModifier lRes = new MoveModifier(0, 0, 0, 0, 0) {
            @Override
            public void onUnregister(final IEntity pItem) {
                recyclePoolItem(this);
            }
        };
        lRes.setAutoUnregisterWhenFinished(true);
        return lRes;
    }

    @Override
    protected void onHandleObtainItem(final MoveModifier pItem) {
        pItem.clearModifierListeners();
    }
};

final MoveModifier lMoveModifier = mMoveModifierPool.obtainPoolItem();
lMoveModifier.reset(aDuration, fromX, toX, fromY, toY, EaseStrongIn.getInstance());
lMoveModifier.addModifierListener(new IModifierListener<IEntity>() {
    @Override public void onModifierStarted(final IModifier<IEntity> pModifier, final IEntity pItem) { }

    @Override
    public void onModifierFinished(final IModifier<IEntity> pModifier, final IEntity pItem) {
        // do something
    }
});
aShape.registerEntityModifier(lMoveModifier);

 - reset methods taking a IEaseFunction as parameter added in BaseDoubleValueSpanModifier and BaseSingleValueSpanModifier classes
 - IModifier.clearModifierListeners method added to able to clear all modifier listeners when the modifier goes back in the pool
 - IModifier.onUnregister event method added to be able to recycle the modifier back to the pool easily
 - ModifierList.clear, remove and onUpdate method overridden from super class to call onUnregister event on modifiers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant