Archived

This topic is now archived and is closed to further replies.

oo22

Loading 3D levels

Recommended Posts

oo22    122
This may sound a little stupid to the better programmers but, how would you go about saving a 3D world into a file so you can load it exactly as it is later..

Share this post


Link to post
Share on other sites
Taulin    100
One way is the toFile( FILE* fp ) way.

Have a method that takes a file pointer first.
Then for every member, just write it out
the way you like.

For example, if it has an array of objects, write how many elements it has first, then call toFile() on the objects it holds.

For reading, just do it the same way, except read it.
Example...

class X
{
int someVariable;
CSomething* pSomePointer;

bool toFile( FILE* fp );
bool fromFile( FILE* fp );
};

bool X::toFile( FILE* fp )
{
fprintf( fp, "%d\n", someVariable );
pSomePointer->toFile( fp );
}

You may want to have it spit out comments also
for debugging purposes.

Share this post


Link to post
Share on other sites
rickpeek    122
yes, usually you can have 2 projects
one world compiler and one runtime rasterizer

you precalculate your world aabb leafs/portals or
etc data with your compiler and then >>write whole
partitioned leaf data into the file<<

This compiler actually does all hard work.

Then you simply fire up your rasterizer application
and read your compiled fileformat world data into memory

it''s important to understand that runtime part of your
application is usually stupid and no need to say you minimize all
stuffs it must do, that way you keep it fast
mostly all stuffs are taken from precalculated table
(there''s no faster way than look-ups)

Share this post


Link to post
Share on other sites
King1297    127
RickPeek is right, let me if I may add my 2 cents

Read the help files on fread and fwritein your compiler. Borland doies this for you!

Then create your own file format

like struct MyFileFormat
{
int hp;
int mp;


position etc duh.
};

then fwrite to save a game to disk, and fread to load a game.

Share this post


Link to post
Share on other sites