This site is no longer active and is available for archival purposes only. Registration and login is disabled.

hi there ! a new trainig :)


hi there ! a new trainig :)

Postby Lewil » Jan 29, 2002 @ 2:51pm

i'm writing a game that has lvls. to help i wrote in VB6 a lvl editor that generates a file (standard writing, readable in notepad for exemple) with integers "where to put sprites" ie x and y and tganumber. i got something like this:

120 'coord x
40 'coord y
1 'tga type
etc etc...

my problem is that i do not succeed in reading the file to put it in a struct like this:

struct myobjects
{
int x;
int y;
int tgatype;
} objects[200];

i know this is not really easyCE programming but it has something to do with :)

thx by advance !
Lewil
 


Postby Dan East » Jan 29, 2002 @ 3:26pm

When you read via a struct, like you are attempting to do, numerical values must be stored in raw binary format. An int is 32 bits, thus you would have raw binary of 4 bytes / chars to represent that int. There also is no padding or line feeds between the members of the struct. Of course you cannot generate such datafiles with a standard text editor like NotePad. Basically if you want to read data in that manner, you must save it in that manner - fill the myobjects struct with data, then write it out to file. You would then be able to read using the simple method you desire. This method also has the advantage of creating much smaller data files; ints and floats are stored more efficiently in binary format than in human-readable form, and there would be no whitespace or comments. Load times would also be extremely fast because the data can be loaded straight into memory in blocks.

If you want to parse plain-text, human readable strings into binary data (as your sample data indicates), then try fscanf or similar. You can also write your own custom routines to parse the data yourself by examining the data one char at a time. Also, the addition of comments adds extra difficulty to the parsing, because the comments would be optional. You would have to properly handle empty lines, spaces before the values, etc. Basically you determine how flexible you want to code your loading routines, which dictates the guidlines that must be followed in creating / editing the data files.

Dan East
User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Return to Phantom's Forum


Sort


Forum Description

Discuss any of Phantom's projects here (Operation Nutcracker, etc.)

Moderators:

sponge, RICoder, Phantom

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum