Rusty Axe Games, home of Real E$tate Empire and Battle Castles

News
Casual Arcade
Shooters
Time Management
Seek And Find
Strategy
RPG
Toons Online
Rusty Blog
About Rusty Axe

Real E$tate Empire, a real estate simulation game
Shadow Armies fiction Domain of Heroes
Your ad here!
Share
<--! style: inset; border-color: black black black black; border-width: 3px; background-color: #000000">
The Data Lump, Part 3 - Mini API
December 11th, 2008


In this installment of the Data Lump I will detail the mini-API for interfacing with the Data Lump. When I was first contemplating this idea I wrote a little pseudo-code for extracting and putting data back into a game using the system. The simplicity of the game specific code sold me on the concept so I will start with that now:

Reading data:


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)
		));

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.

Writing data:

for(i=0;i<numHouses();i++)
	dlPutStruct(	"House", 
			i, 
			houseNode(i), 
			sizeof(House)
		);
dlWrite( "gameData.txt" );

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:

default Ship:
	LevelName:	"Lost Mans Bay"
End
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.

So, that's the overview. Here are function definitions for the entire API:


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);

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.

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 *