cocos2d / cocos2d-js__old__

cocos2d in JavaScript central repository
14 stars 9 forks source link

cocos2d file format #68

Open ricardoquesada opened 11 years ago

ricardoquesada commented 11 years ago

cocos2d needs its own file format.

Currently we have different file formats for different objects. eg:

But what we need is a way to load (and save) a complete cocos2d scene. CocosBuilder reader lets you load a complete scene, but its current file format its highly coupled with CocosBuilder internals, and not necessarily improved for cocos2d. And it doesn't have a "saver".

What cocos2d needs is:

marshaling and unmarshaling the scene means:

ricardoquesada commented 11 years ago

Use cases: 1) Save the state of a game... and load it 2) Load the scenes created by editors (CocosBuilder or CocoStudio). In order for this to happen, the editors will need to have a "converter" or "exporter" to the cocos2d native format... (or continue to use their own reader, but this new file format will be optimized for speed and compactness)

chengstory commented 11 years ago

Currently CocoStudio uses JSON(JavaScript Object Notation) file format to load (and save) a complete scene.

JSON is built on two structures: * A collection of name/value pairs. * A ordered list of values, this is realized as an array, vector, list or sequence.

CocoStudio uses GameObject attached to the scene component as a complete scene, For instance:

{ "classname" : "gameobject", "components":[ { "classname" : "scene" } ], "gameobjects":[ ... ] }

sergey-shambir commented 11 years ago

Saving the state of a game with any cocos2d-x class serialization have one major trouble: fragile save files compatibility. Any change in cocos2d-x can break saves of game fans.

I also think there are no need to bind cocos2d to one serialization format. JSON, XML, fast binary - all formats have own use-cases, and even serialization to CCDictionary can be helpful (e.g for further serialization to JSON or XML).

It is possible to generate serialization code automatically using clang libraries. There is brief example: https://github.com/sergey-shambir/cocos2d-x-extensions-cpp2011 . In this code, example input and produced output are placed in serialization-codegen/test_data. It takes C++ header input with data structs and generates both declaration (in another header) and implementation for getters, setters and methods to save/load to/from CCDictionary. It already iterates over structures in file and uses information about variable type and annotation attributes __attribute__((annotate("any text")))

And of course any utility based on clang can do something using base classes of given class, includes list or other source code properties.

ricardoquesada commented 11 years ago

thanks for the feeback @sergey-shambir

Serialization based on CCDictionary is an option: it is easy to implement, understand, and debug the ouput. But it is not a fast option. The use case that I want to solve is:

In order to achieve that I think we should have:

ricardoquesada commented 11 years ago

More info here: https://github.com/cocos2d/cocos2d-js/issues/64#issuecomment-17892773