Reading data:
houseNode in the above example is a game specific data allocator that will return a pointer to a house structure that the game will keep track of. BTW, that 5 lines of code, including an assert is all I would have needed to parse in Real E$tate Empire data had I been using the Data Lump system with the added benefit that any mod's to data at run time could then have been pushed back to the external data file.
S32 house_cnt = 0;
dlRead( STRUCTS, "dataStructs.h");
dlRead( DATA, "gameData.txt" );
dlStructSize("house", &size);
ASSERT( size==sizeof(House));
while(dlGetStruct( "house",
houseNode(),
house_cnt++,
sizeof(House)
));
Writing data:
One of the ideas that I mulled over when designing this API was a container or grouping system that multiple levels could be contained within. I ultimately discarded this idea in favor of simplicity as a data lump that describes level files could easily be built. To do this you would just parse in all level descriptors, dump that data lump and then on a level by level basis read in a particular levels data. Alternately if you want all of your data in memory at once then you could achieve this with a level name field as follows:
for(i=0;i<numHouses();i++)
dlPutStruct( "House",
i,
houseNode(i),
sizeof(House)
);
dlWrite( "gameData.txt" );
All subsequent ships would inherit this level name field until the default ships LevelName is modifed for a new level. NOTE: default structure definitions will be pushed into actual structures when they are written back out.
default Ship:
LevelName: "Lost Mans Bay"
End
So, that's the overview. Here are function definitions for the entire API:
All functions return FALSE (0) if they fail. If the optional 3rd parameter for dlRead is defined as FALSE then structures or data are appended to existing data otherwise they are flushed from memory. dlGetConst returns a pointer to either a string or an integer constant - since the program will need to know of the variable (and thus type) before hand it doesn't make sense to add a third parameter describing type.
typedef enum
{
DATA,
STRUCTS,
}DataType;
Bool dlRead( DataType t,
U8* filename,
(Bool Flush)
);
Bool dlWrite( U8 *filename);
Bool dlGetConst( U8 *tag, void *var_ptr);
Bool dlGetStruct( U8 *tag,
void* dest,
U32 idx,
U32 size
);
Bool dlStructSize( U8 *tag);
Bool dlDelStruct( U8 *tag, U32 idx);
Part 4, adding and preserving comments, coming soon,
L
No comments have been provided.

Your Name: | |
Your Location: | |
Country (flag): | |
Article Rating: | |
Your Comments: | |
Security check * | |