[freespace2] bigendian model loading probs
Ryan C. Gordon
icculus at clutteredmind.org
Wed Dec 18 02:32:54 EST 2002
> ...The problem I'm having is with model loading/parsing: I've been
> SDL_SwapLE16 or 32 whenever it seems necessary, but there's a whole
> bunch of pointer passing to a ubyte *p, which is referenced by
> offsets, and it's confusing me greatly...confusing me, because it
> seems sometimes a dereferenced pointer swap needs to be done twice,
> so that future accesses don't get screwed up...
Ideally, you want to find where these things are originally loaded from
disk/read from the network, and swap them there if humanly possible.
If they are read from disk like this:
typedef struct
{
int x;
int y;
} MyStruct;
MyStruct mystruct;
read(fp, &mystruct, 1, sizeof (mystruct));
Then you want to make a new function:
int serialize_mystruct(int fp, MyStruct *mystruct)
{
READ32(fp, mystruct->x);
READ32(fp, mystruct->y);
}
"READ32" is an exercise for the reader.
This is never fun. I've done this work for several games, and it's a total
motherfucker if byte ordering isn't respected during development.
Trying to swap on the fly (i.e. -- "will this get swapped more than
once?!") is a last resort, and should be avoided unless it's seriously
non-trivial to rewrite offending portions of code to behave.
--ryan.
More information about the freespace2
mailing list