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

Feature: AutoMagicCoding (NSCoding alternative) for nodes with actions. #141

Closed
wants to merge 288 commits into from

Conversation

psineur
Copy link
Contributor

@psineur psineur commented Jan 14, 2012

Well, i added some AMC support to cocos2d-iphone recently.
Actions AM support not yet added, so almost everything after loading will stand still (there are some exceptions used to demonstrate some stuff tough, but it's done via starting actions after loading).

BTW i think it's pretty good way to demonstrate actual saved state after loading, so probably even after adding actions support - in old test i will stop all actions before saving to have the same photo capture effect.

Anyway, here's what i got...

What's new

  1. Cocos2D-iPhone Sources:
    1. ADDED: cocos2d/AutoMagicCoding - AMC submodule
      TODO: remove submodule, use easier path, update all files , that uses that path.
      before adding actions amc support & merging it all - it's better to have AMC
      as a submodule - easier to maintain.
    2. CHANGED: Many cocos2d classes, that now have AMC Support (see pull request notes).
    3. ADDED: CCNodeRegistry - central key-value (by name string) for nodes, that
      doesn't retain nodes (Used for restoring links after loading, such as
      CCMenuItem target & other).
    4. REMOVED: CCBlocksAdditions category & CCBlockSupport.m (only implementation file
      header is still used) - CCMenuItem was refactored a little for
      better AMC support, now blocks used directly, but it's still
      backward compatible with old iOS versions & now you can set
      target/selector or block after creating CCMenuItem (or it's subclasses).
    5. CHANGED: Memory footprint of ccColor3B. 3 bytes is too small. It
      should be 5 bytes at least, to avoid KVC failure (corrupted isa
      pointer & garbage value returned).
    6. CHANGED: Templates. Removed CCBlockSupport.m, added Node Registry &
      AMC sources.
      TODO: test XCode3 templates, i don't have XCode3, so i can't test it.
  2. Tests:
    1. ADDED: New test target: AMCTest - includes additional tests for AMC:
      • NodeAMC - Simple node properties/hierarchy test.
      • LayersAMC - Test for CCLayer, CCLayerColor, CCLayerGradient & CCLayerMultiplex.
        (There was no Layers test before - so added new one).
      • ParallaxAMC - Test for AMC-Support CCParallaxNode with AMC-Supported children.
        (Used instead of existing test, cause it includes deprecated class children,
        that will not be supported by AMC).
      • ProgressTimerAMC - Test for CCProgressTimer AMC Support (there was no test for
        progressTimer before).
      • SceneAMC - explicit test for whole CCScene test.
    2. CHANGED: Existing tests - added save/purge/load toggle menu item.
      • EffectsAdvancedTest - tests CCGrid AMC Support.
      • LabelTest - tests CCLabel AMC Support.
      • MenuTest - tests CCMenu & Items subclasses AMC Support & CCNodeRegistry.
      • SpriteTest - tests CCSprite, Frame, BatchNode & CCCamera AMC Support.

Nodes supported by AMC

  1. Basic Nodes
    • CCNode - FULL SUPPORT
      • Children & all properties except for Camera & Grid ( tested in AMCTest.m in NodeAMC )
      • CCCamera ( tested in SpriteTest.m in SpriteZVertex )
      • CCGrid ( tested in EffectsAdvancedTest.m in Effect1, Effect2, etc... )
      • Name & CCNodeRegistry (tested in MenuTest - weak links to children & targets for menuItems)
    • CCLayer - FULL SUPPORT ( tested in AMCTest.m LayersAMC )
      • CCLayerColor ( tested in AMCTest.m LayersAMC )
      • CCLayerGradient ( tested in AMCTest.m LayersAMC )
      • CCLayerMultiplex
  2. Sprites - FULL SUPPORT (tested in SpriteTest.m - AMCTest functionality added to existing test)
    • CCSprite
    • CCSpriteFrame (key for CCSpriteFrameCache not saved yet - all SpriteFrames will be independent after loading).
    • CCSpriteBatchNode
  3. Textures - ALL NEEDED SUPPORT
    • CCTexture2D - only key for CCTextureCache saved (no custom texture support).
      As Riq said on forums: "serializing the TextureCache is sort of hackish."
      ( http: www.cocos2d-iphone.org/forum/topic/16980#post-95815 )
      So we will save only key (filepath) for Texture, making developer responsible
      for creating custom texture on deserialization
      (-initWithDictionaryRepresentation: method) or saving generated texture to
      documents or cache folder & setting it's key to that path, so next time it could
      be loaded from there.
    • CCTextureAtlas - Saves CCTexture2D (via key) & capacity (Tested in SpriteTest.m).
      (Used by CCSpriteBatchNode, so tested everywhere where BatchNode is tested.)
    • CCTextureCache - not supported - not needed.
      (Can be saved as array of texture keys - can be useful for preloading all
      needed for scene textures)
  4. Labels - FULL SUPPORT (Tested in LabelTest.m)
    • CCAtlasNode - FULL SUPPORT (not tested independently, but used only by CCLabelAtlas)
    • CCLabelAtlas - FULL SUPPORT
    • CCLabelTTF - MAC SUPPORT (iOS also should work, but i tested only on a Mac)
    • CCLabelMBFont - FULL SUPPORT by Magic. True magic... Tested only on a Mac, but...
      You know - i'll better just trust the Magic, cause Magic is VERY powerfull!
  5. Menus - FULL POSSIBLE SUPPORT
    • CCMenu - FULL SUPORT
    • CCMenuItem - ALL SUBCLASSES SUPPORTED:
      • CCMenuItemLabel
      • CCMenuItemAtlasFont
      • CCMenuItemFont
      • CCMenuItemSprite
      • CCMenuItemImage
      • CCMenuItemToggle
        Target saved as name of CCNode in CCNodeRegistry, selecter saved as
        NSString. It's impossible to save Blocks - user should manually restore
        them after loading
        (CCNodeRegistry can be used to obtain target nodes).
  6. More Nodes
    • CCParallaxNode - FULL SUPPORT (tested in AMCTest.m ParallaxAMC)
    • CCProgressTimer - FULL SUPPORT (tested in AMCTest.m ProgressTimerAMC)
      (btw found a bug - different acnhorPoints for radial timers aren't supported)

Actions supported by AMC

CCAction.m

  • CCAction-------------------Supported, Tested (ActionsTest)
  • CCFiniteTimeAction----Supported, Tested (ActionsTest)
  • CCRepeatForever-------Supported, Tested (ActionsTest)
  • CCSpeed-------------------Supported, Tested (ActionsTest)
  • CCFollow-------------------Supported, Tested (ActionsTest)

CCActionInterval.m

  • CCActionInterval--------Supported, Tested (ActionsTest)
  • CCSequence-------------Supported, Tested (ActionsTest), Issues = Minor fix #17
  • CCRepeat-----------------Supported, Tested (ActionsTest)
  • CCSpawn------------------Supported, Tested (ActionsTest)
  • CCRotateTo--------------Supported, Tested (ActionsTest)
  • CCRotateBy--------------Supported, Tested (ActionsTest)
  • CCMoveTo----------------Supported, Tested (ActionsTest)
  • CCMoveBy----------------Supported, Tested (ActionsTest)
  • CCSkewTo----------------Supported, Tested (ActionsTest)
  • CCSkewBy----------------Supported, Tested (ActionsTest)
  • CCJumpTo----------------Supported, Tested (ActionsTest)
  • CCJumpBy----------------Supported, Tested (ActionsTest)
  • CCBezierTo---------------Supported, Tested (ActionsTest)
  • CBezierBy-----------------Supported, Tested (ActionsTest)
  • CCScaleTo----------------Supported, Tested (ActionsTest)
  • CCScaleBy----------------Supported, Tested (ActionsTest)
  • CCBlink---------------------Supported, Tested (ActionsTest)
  • CCFadeIn------------------Supported, Tested (ActionsTest)
  • CCFadeOut----------------Supported, Tested (ActionsTest)
  • CCFadeTo------------------Supported, Tested (ActionsTest)
  • CCTintTo--------------------Supported, Tested (ActionsTest)
  • CCTintBy--------------------Supported, Tested (ActionsTest)
  • CCDelayTime--------------Supported, Tested (ActionsTest)
  • CCReverseTime----------Supported, Tested (ActionsTest)
  • CCAnimate-----------------Supported, Tested (ActionsTest)

CCActionTween.m

  • CCActionTween----------Supported, Tested (ActionsTest)

CCActionProgressTimer.m

  • CCProgressTo----------Supported, Tested (ActionsTest)
  • CCProgressFromTo---Supported, Tested (ActionsTest)

CCActionInstant.m

  • CCActionInstant-------------Supported, Tested (ActionsTest)
  • CCShow------------------------Supported, Tested (ActionsTest)
  • CHide----------------------------Supported, Tested (ActionsTest)
  • CCToggleVisibility----------Supported, Tested (ActionsTest)
  • CCFlipX------------------------Supported, Tested (ActionsTest)
  • CCFlipY------------------------Supported, Tested (ActionsTest)
  • CCPlace------------------------Supported, Tested (ActionsTest)
  • CCCallFunc-------------------Supported, Tested (ActionsTest)
  • CCCallFuncN -----------------Supported, Tested (ActionsTest)
  • CCCallFuncND---------------NOT-SUPPORTED (Can't save custom data)
  • CCCallFuncO-----------------NOT-SUPPORTED (Can't save custom object)
  • CCCallBlock-------------------NOT-SUPPORTED (Can't save block)
  • CCCallBlockN-----------------NOT-SUPPORTED (Can't save block)

CCActionCamera.m

  • CCActionCamera-------------Supported, Tested (ActionsTest)
  • CCOrbitCamera---------------Supported, Tested (ActionsTest)

CCActionEase.m

  • CCActionEase---------------------Supported, Tested (EaseActionsTest)
  • CCEaseRateAction--------------Supported, Tested (EaseActionsTest)
  • CCEaseIn---------------------------Supported, Tested (EaseActionsTest)
  • CCEaseOut------------------------Supported, Tested (EaseActionsTest)
  • CCEaseInOut----------------------Supported, Tested (EaseActionsTest)
  • CCEaseExponentialIn----------Supported, Tested (EaseActionsTest)
  • CCEaseExponentialOut--------Supported, Tested (EaseActionsTest)
  • CCEaseExponentialInOut-----Supported, Tested (EaseActionsTest)
  • CCEaseSineIn---------------------Supported, Tested (EaseActionsTest)
  • CCEaseSineOut-------------------Supported, Tested (EaseActionsTest)
  • CCEaseSineInOut----------------Supported, Tested (EaseActionsTest)
  • CCEaseElastic---------------------Supported, Tested (EaseActionsTest)
  • CCEaseElasticIn------------------Supported, Tested (EaseActionsTest)
  • CCEaseElasticOut---------------Supported, Tested (EaseActionsTest)
  • CCEaseElasticInOut-------------Supported, Tested (EaseActionsTest)
  • CCEaseBounce--------------------Supported, Tested (EaseActionsTest)
  • CCEaseBounceIn-----------------Supported, Tested (EaseActionsTest)
  • CCEaseBounceOut---------------Supported, Tested (EaseActionsTest)
  • CCEaseBounceInOut------------Supported, Tested (EaseActionsTest)
  • CCEaseBackIn---------------------Supported, Tested (EaseActionsTest)
  • CCEaseBackOut-------------------Supported, Tested (EaseActionsTest)
  • CCEaseBackInOut----------------Supported, Tested (EaseActionsTest)

Not Supported

  1. Possible in the future releases:
    • CCParticleBatchNode & other from "Particle Nodes" - OMG, lot of iVars & structs!
      Anyway - it should be possible, just needs time.
    • CCTMXLayer, CCTMXObjectGroup, CCTMXTiledMap. With ability to change something & it will be saved with changes.
    • CCTransitions - Low priority feature. Easy to save, hard to test.
      Only if do first ammount of tests that saves transition & 2nd - that loads it.
    • Effects (Grid) Actions.
    • CCRibbon - probably hard to support
    • CCMotionStreak - uses CCRibon.
  2. Probably not to be supported by AMC
    • CCTextureAtlas - Manual atlas not supported (last test in LabelTest)
    • CCTimer & scheduled methods. (Not used by Cocos2D-iPhone classes
      themselves - should be used by developer expicitly ).
    • CCGrabber (helper class),
    • CCRenderTexture (helper class),
    • CCTileMapAtlas (DEPRECATED (Will be removed from Cocos2D-iPhone in 1.0+ )).

All issues regarding AMC support for Cocos2D-iPhone is here:
https://github.com/psineur/cocos2d-iphone/issues?labels=feature-amc+branch

Issue about "More Nodes Support": psineur#19
Issue about "More Actions Support": psineur#18

All basic functional of Cocos2D-iPhone is supported and stable.
AMC isn't a submodule anymore.
Probably this can be merged now.

This functionality is enough for me to start working on Editor for Cocos2D.
So i will update this Pull Request only with critical fixes, or after releasing first public version of editor.

P.S. See big comment below for additional "What's New" regarding actions support.

To demonstrate that CCLayerMultiplex saves/loads as expected.
 * Added name.
 * Frames printed as array - this will print description
of each frame.
@psineur
Copy link
Contributor Author

psineur commented Feb 1, 2012

Ok, feature-amc-actions is merged to feature-amc, here's little overview what's changed:

Actions Support Added

  • Refactored CCAction & CCActionManager:
    • Added @Property BOOL started - used to start action on -resumeTarget instead of -addAction:target:paused. This means that action is actually started when node enters scene or immediately after -runAction: if node is already running.
    • Added -startOrContinueWithTarget: & -continueWithTarget: - this allows action start from intermediate state.
    • CCActionManager: Added -allActionsForTarget: method for ability to get all actions of given node when saving.
  • Refactored CCFollow:
    • Saves worldBoundary_ as rect, and supports different winSize during runtime.
    • Added followedNodeName property to allow loading with AMC, using CCNodeRegistry to get followedNode.
  • CCCallfunc - added targetName property to allow loading this action with AMC, using CCNodeRegistry to get target.
  • Added private properties to many other Actions for AMC support, but without adding any iVars, so won't mention them explicitly here.
  • Changes in CCAnimation / CCSpriteFrame
    • when frame or animation saved in corresponding cache - it's name is a key for them in cache.
    • SpriteFrame have no name property before - so it was added for this.
    • Added methods isEqual & improved description for logging inconsistencies when loading named frame or animation, and there's different frame/animation in cache with the same name. (Issue FSAA update, disregard fsaa frame buffer attachments when enabled #9 in psineur/cocos2d-iphone)

It should be mentioned that all supported actions, including action containers, like CCRepeat, CCSequence and others, who don't call -step: / change elapsed_ of inside actions are also supported AND can be saved in ANY INTERMEDIATE state properly.

Tests Changed

  • Old AMC tests from feature-amc branch purges actionsManager to save tests behavior, when node if action saved & loaded standing still - without any animation/running action. So AMCTests, SpriteTest, EffectsAdvancedTest & others non-actions tests demonstrates how node was saved loaded without actions.
  • ActionsTest modified to add AMC Test functionality (save/purge/load menu item).
    • It was also refactored, to make it easier to add AMCTest functionality - now prev/restart/next menuItems are added to test main layer, represented always by one class, and insideLayer with test itself is changed.
  • Some tests added, that doesn't exist before, i.e. ActionProgress for testing CCProgressTimer actions: CCProgressTo & FromTo
  • EaseActionsTest changed the same way, as ActionsTest to add AMC Test functionality.

@psineur
Copy link
Contributor Author

psineur commented Feb 1, 2012

Looks like GitHub doesn't allow to sequence commit & comments in Pull Request, sorry.
I will update first post in this pull request - adding info about what actions are supported & what issues left & must be moved to cocos2d-iphone issue tracker from my repo issues after merging.
I will comment here after doing this.

Another new thing is that AMC isn't a submodule anymore - it's plain source. This will be pushed to Pull Request in few minutes.

@psineur
Copy link
Contributor Author

psineur commented Feb 1, 2012

Ok, updated description, renamed Pull Request from

"Feature: AutoMagicCoding (NSCoding alternative) for nodes."

to

"Feature: AutoMagicCoding (NSCoding alternative) for nodes with actions."

@araker
Copy link
Contributor

araker commented Feb 23, 2012

Nice work. I'll try to integrate this into the first RC release of 1.1.

@ricardoquesada
Copy link
Contributor

great feature. I added some comments/questions in the cocos2d thread:
http://www.cocos2d-iphone.org/forum/topic/20528

@Birkemose Birkemose closed this Mar 28, 2014
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

4 participants