[Alephmodular-devel] Serializing the world
Status: Pre-Alpha
Brought to you by:
brefin
|
From: Br'fin <br...@ma...> - 2005-06-14 01:08:36
|
Ok, I've been working on adding more AI/OStreams friends and the like
to more objects. As well as tweaking the code that iterates over the
various save game tags and throws the various data out into a file.
Specifically, this array:
> struct save_game_data save_data[]=
> {
> { ENDPOINT_DATA_TAG, FILE_SIZEOF_endpoint_data, TRUE },
> { LINE_TAG, FILE_SIZEOF_line_data, TRUE },
> { SIDE_TAG, FILE_SIZEOF_side_data, TRUE },
> { POLYGON_TAG, FILE_SIZEOF_polygon_data, TRUE },
> { LIGHTSOURCE_TAG, FILE_SIZEOF_light_data, FALSE },
Now, in the past, this thing basically helped develop count of data
per tag, size of data per tag, and array location for data. So,
especially for those elements not handled by the level loader, it
could just say, data, size, source/dest, memcpy. With packing, things
progress with a big switch for determining size, a big switch for
source, and then packs the data for copying into a wad.
And that doesn't even cover the additional code to unpack it from a
saved game.
It feels reasonable to me to have some loader classes that
encapsulate the elements needed to load/save data.
Something along the lines of
MyFoo.h
-------
#include "CLoader.h" // CSerializer?
// CLoader::Result some variable size data run with a count
class MyFooLoader : public CLoader
{
void load_raw_data(char* raw_data, size_t length);
CLoader::Result get_save_data();
}
Where load_raw_data does an appropriate unpack event. And
get_save_returns you some stream of data that you need to dispose of
yourself. This could be an auto_ptr to a vector<char> that is self
maintaining, or it could be a pair<char*,size_t> that you need to
explicitly free in some fashion. (AM has 2-3 instances of the latter
around resource using functions, like sound_handles and
CResourceFile, not that I'm perfectly happy with them.)
Thoughts? Comments? Examples of similar objects?
I'm undecided on the return format of get_save_data and am definitely
not happy with the names load_raw_data and get_save_data.
-Jeremy Parsons
http://alephmodular.sourceforge.net/
|