There are two major limitations with the current saver:
1) It does not support saving to multiple files
2) It does not save everything that is loaded from a file
1) The current CS saver only supports dumping the whole engine contents to one
file. This is not enough for applications that use the CS saver when they would
like to maintain a certain file structure and keep library files separate for
example. It is also not enough for an application like the lighter2 which must
write to multiple files and currently has to move around iDocumentNodes to work
around this.
I propose we have an interface, iSaverFile, which stores information about the
files that the saver should write to. The loader would create an instance of an
iSaverFile and add each object it loads to the iSaverFile. This would be an
optional behaviour so as not to slow down loading and waste memory when you do
not need the saver.
Here is how it might look:
//@{
/**
* Saver file types
*/
enum
{
/// World file
CS_SAVER_FILE_WORLD = 0,
/// Library file
CS_SAVER_FILE_LIBRARY = 1,
/// Meshfact file
CS_SAVER_FILE_MESHFACT = 2,
/// Addon params file
CS_SAVER_FILE_PARAMS = 3
};
//@}
SCF_VERSION (iSaverFile, 0, 0, 1);
/**
* This interface stores information about what engine objects are part of each
* file to save to. This is useful to the saver to support saving to multiple
* files.
*/
struct iSaverFile : public iBase
{
/**
* Get the file name of the saver file.
*/
virtual const char* GetFile () const = 0;
/**
* Set the file name of the saver file.
*/
virtual void SetFile (const char* filename) = 0;
/**
* Get the type of the saver file.
*/
virtual int GetFileType () const = 0;
/**
* Set the type of the saver file.
*/
virtual void SetFileType (int type) = 0;
/**
* Get the iObject for this object. Add all engine nodes that are to be
* saved to this file to the iObject.
*/
virtual iObject* QueryObject () = 0;
};
I am not sure what other file types need to be supported in addition to world,
library, meshfact, and renderloop files.
Finally, there are some additions to the iSaver interface that make saving to
multiple files possible:
struct iSaver : public iBase
{
/// Save the current engine contents to the filename.
virtual bool SaveMapFile(const char *filename) = 0;
/// Return the current engine contents as a string.
virtual csRef<iString> SaveMapFile() = 0;
/// Save map to DocumentNode
virtual bool SaveMapFile(csRef<iDocumentNode> &root) = 0;
// The additions:
/// Save the engine contents to multiple files.
virtual bool SaveToFiles() = 0;
/// Save the objects attached to the specified file.
virtual bool SaveToFile(iSaverFile* file) = 0;
};
These functions respect the files that objects are loaded from. SaveToFile()
allows you to save one file at a time. The other functions will continue to
function as normal.
2) In order to make perfect saves of loaded files, there must be an iObject
created and attached to an iSaverFile for each object loaded.
It also needs to save library references (like
"<library>/path/to/some/library</library>") within world files (and library
files too?). So, I propose we have a new object like the following:
SCF_VERSION (iLibraryReference, 0, 0, 1);
/**
* This interface represents a reference to a library file.
*/
struct iLibraryReference : public iBase
{
/**
* Get the file name of the library reference.
*/
virtual const char* GetLibrary () const = 0;
/**
* Set the file name of the library reference.
*/
virtual void SetLibrary (const char* filename) = 0;
/**
* Get the iObject for this interface.
*/
virtual iObject* QueryObject () = 0;
};
Addons are another thing that are not saved. Here is a proposed interface for
addons:
SCF_VERSION (iLibraryReference, 0, 0, 1);
/**
* This interface represents a reference to a library file.
*/
struct iAddon : public iBase
{
/**
* Get the SCF name of the plugin.
*/
virtual const char* GetPlugin () const = 0;
/**
* Set the SCF name of the plugin.
*/
virtual void SetPlugin (const char* plugin) = 0;
/**
* Get the file name of the params file.
*/
virtual const char* GetParamsFile () const = 0;
/**
* Set the file name of the params file.
*/
virtual void SetParamsFile (const char* filename) = 0;
/**
* Get the iObject for this interface.
*/
virtual iObject* QueryObject () = 0;
};
For objects directly embedded within the <addon> tags, the object should be
added to the iAddon's iObject. For addon parameters that are referenced using
<paramsfile>, the parameters should be added to the iSaverFile for the params file.
I would like to hear comments and suggestions. And if anyone wants to help
implementing it, then we can coordinate our efforts too. :)
Thanks,
Seth (aka iceeey)
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Crystal-main mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/crystal-main
Unsubscribe: mailto:[EMAIL PROTECTED]