savefile.h defines functions for writing savefiles and reading
them. In this scheme, data to be saved is divided up into "objects,"
which consist of two kinds of information: references to other objects, and
strings of binary data. References are simply C pointers to sections of
memory which represent the objects they refer to in some fashion.
When a savefile is written, the savefile framework keeps track of the size
of each object in memory. It interns objects, assigns them index numbers,
and translates references accordingly.
When a savefile is read, the framework allocates the memory for each object
according to the sizes given in the writing stage and resolves the
references back to C pointers. It then calls a callback for each object,
which is responsible for determining the type of the object and restoring it
using the references and data that were stored with it.
restore_first() and read_reference_restoring_first() read_reference_restoring_first(), but it does so only after
creating a Lua reference for the table and storing it in the allocated
memory. This is so that other objects which refer cyclically to the table
will be able to work with this reference without referring to uninitialized
memory.
get_object_data() and reset_object_data() reset_object_data() can be used to put start the process
over again with the first datum.
The conventional use of these functions in the restoring of a particular data
type is as follows:
reset_object_data() first. Sometimes other restore functions will
get_object_data() in order for each data segment needed to restore
get_object_data()
are freed after the current savefile is restored. You should never save these
pointers for use outside the scope of the restore function, and you should never
attempt to free them.
luasave.h defines functions that save and
restore lua data. The method employed is to intern each object to be saved,
mapping it to a C pointer to an integer, which is itself a canonical Lua
reference to the object. This pointer is used within the savefile framework
to represent the object and to refer to it.
save_lua_value() on it.
read_reference_restoring_first() to restore the Lua data
and retreive a C pointer to a Lua reference to it.
lua_getref() to push the Lua data onto the stack.
read_reference_restoring_first(), as both will
be released when the restoring process is complete.
| Kind | Size | Description |
|---|---|---|
| Data | 4 | The string "LUA" |
| Data | int | LUA_TNIL |
| Kind | Size | Description |
|---|---|---|
| Data | 4 | The string "LUA" |
| Data | int | LUA_TNUMBER |
| Data | float | The number |
| Kind | Size | Description |
|---|---|---|
| Data | 4 | The string "LUA" |
| Data | int | LUA_TSTRING |
| Data | n | The string |
| Kind | Size | Description |
|---|---|---|
| Data | 4 | The string "LUA" |
| Data | int | LUA_TTABLE |
| Reference | N/A | Key of first field, always to a Lua value |
| Reference | N/A | Value of first field, always to a Lua value |
| Continues in (key, value) pairs for all instance data | ||
| Kind | Size | Description |
|---|---|---|
| Data | 4 | The string "LUA" |
| Data | int | LUA_TUSERDATA |
| Reference | N/A | To the C structure |
adatasave.h defines a constant
ADATA_TAG, which should be compared to the tag interpreted as an integer. An
analogous constant, LUA_TAG, is defined by luasave.h.
ADATA_TAG mentioned above,
followed by a constant from the DataType enum defined in luascript/data.h.
Vector:
| Kind | Size | Description |
|---|---|---|
| Data | 4 | ADATA_TAG |
| Data | int | D_VECTOR |
| Data | int | LUA_REFNIL if the vector is unreferenced, or some other value if it is referenced |
| Data | float | The x component of the vector |
| Data | float | The y component of the vector |
| Data | float | The z component of the vector |
| Kind | Size | Description |
|---|---|---|
| Data | 4 | ADATA_TAG |
| Data | int | D_VECTOR |
| Data | int | LUA_REFNIL if the range is unreferenced, or some other value if it is referenced |
| Data | float | The minimum value in the range |
| Data | float | The maximum value in the range |
| Data | 1 | A bitset in which the lowest bit is set iff the range has a minimum value and the second-lowest is set iff it has a maximum value |
| Kind | Size | Description |
|---|---|---|
| Data | 4 | ADATA_TAG |
| Data | int | D_LIST (yet to be created, corresponds to List* as defined in lualist.h) |
| Data | 1 | Nonzero if the list has an Instance |
| Reference | N/A | To the Instance (not present if the previous data is zero) |
| Reference | N/A | To the first item |
| Reference | N/A | To the second item |
| Continues for all list items | ||
| Kind | Size | Description |
|---|---|---|
| Data | 4 | ADATA_TAG |
| Data | int | D_CLASS |
| Data | int | LUA_NOREF unless the class is referenced by C code |
| Data | int | Sequence number in file |
| Data | ? | String filename of file the class was defined in |
| Reference | N/A | To the MTable of members |
| Reference | N/A | To the class data (if non-NULL) |
| Kind | Size | Description |
|---|---|---|
| Data | 4 | ADATA_TAG |
| Data | int | D_INSTANCE |
| Data | int | LUA_NOREF unless the instance is referenced by C code |
| Reference | N/A | To the class the instance was instantiated from |
| Reference | N/A | To the MTable of members |
| Reference | N/A | To the class for the first instance data |
| Reference | N/A | To the first instance data |
| Reference | N/A | To the class for the second instance data |
| Reference | N/A | To the second instance data |
| Continues in (class, data) pairs for all instance data | ||
| Topic GameSavingPlans . { Edit | Attach | Ref-By | Printable | Diffs | r1.7 | > | r1.6 | > | r1.5 | More } |
|
Revision r1.7 - 03 Nov 2004 - 22:21 GMT - ElminI Parents: WebHome |
Copyright © 1999-2003 by the contributing authors.
All material on this collaboration platform is the property of the contributing authors. Ideas, requests, problems regarding EgoWiki? Send feedback. |