cocos2d/cocos2d-iphone — pull request #141 by psineur (2012-01-14 16:23:38+00:00)
Title: Feature: AutoMagicCoding (NSCoding alternative) for nodes.

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.

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)

Will be supported soon (work in progress)
=================================

1. Actions

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.
* 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+ )).