In order for the File class to work properly all loadable objects must be able
to be created without arguments.
For example, soy.bodies.Body no longer needs a scene; it's just disabled until
one is set on it.
The process to load is thus like this:
s = soy.Scene()
f = soy.File('tree.soy')
if f.has_key('TreeMesh') and \
type(f['TreeMesh']) == soy.bodies.Body :
f['TreeMesh'].scene = s
Each object's load function will receive the file loading it as it's first
parameter and, thus, will be able to later save changes as well as reference
other objects in the same file as part of it's parameters.
Ie, the above Mesh may have a Texture named 'TreeMeshTexture1' in the same
file. When saving it may also save this texture by a name it knows and records
into it's string.
The loading process has three steps;
1) the object is created from the class name provided in the header
2) the object's __load__ method is called with a dict of other objects being
loaded from the same chain and that object's name. The return value is a
CObject which the File stores for loading data to.
3) coreloop calls a C method of File which, when new data is loaded, is sent
as a parameter to the CObject function.
The saving process is virtually the same;
1) the object is added to File as a dict item (ie, f['PineTree'] = pinetree)
2) when File.save() is called, each object's __save__ method is called with
an object dict and that object's name. The return value is a CObject
3) that same C method coreloop calls runs through a loop of files being saved
and will call that CObject for each packet it needs
The structure and content of these packets is unique to each type, no format is
dictated, so it could (ie) be progressive or one-shot. The first data packet
is always loaded just after the object is created (before Python can touch it)
so critical data can be pre-loaded.
In order to achieve this a wee bit of restructure is needed. For example,
joints need to belong to bodies so that groups of connected bodies can be saved
at once. When one body in that group is added to a scene they all must be
added to that scene. The code to do that is not in yet.
I'm sure there's more, this is just off the top of my head.
We also need to check to ensure objects are setup internally before they're
used, ie, Body._bodyID will be NULL when not in a Scene since ode bodies are
specific to a scene and are non-transferable. If a Body is removed from a
scene it's _bodyID is destroyed and reset to NULL.
This needs to go for everything. Windows, if they are to be saved, need to be
created when they're added to a Screen. This also provides a nice API for
off-screen rendering.
_______________________________________________
PySoy-Dev mailing list
[email protected]
http://www.pysoy.org/mailman/listinfo/pysoy-dev