bigendian model loading probs

tigital tigital at mac.com
Wed Dec 18 01:14:03 EST 2002


hiya,

...I started working on the OS X port again, aka byteswapping hell!

...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...

...here's an example from modeloctants.cpp, with some of my byte swap stuff:

void moff_defpoints(ubyte * p)
{
	int n;
	int nverts = SDL_SwapLE32( w(p+8));
	int offset = SDL_SwapLE32( w(p+16));
         //int nverts = w(p+8);
         //int offset = w(p+16);

	ubyte * normcount = p+20;
         vector *src = vp(p+offset);

	Assert( nverts < MAX_POLYGON_VECS );
	// Assert( nnorms < MAX_POLYGON_NORMS );

	for (n=0; n<nverts; n++ )	{
             src->xyz.x = LoadLEFloat( &src->xyz.x );		//tigital
             src->xyz.y = LoadLEFloat( &src->xyz.y );
             src->xyz.z = LoadLEFloat( &src->xyz.z );

             Interp_verts[n] = src;
             normcount[n] = SDL_SwapLE32( normcount[n] );	//tigital

             src += normcount[n]+1;
	}
}

...now, nverts and offset are ok, but I'm not so sure about normcount 
and src...the only reference I can find as to what "p+20" is at this 
point is a "n_verts*char", which I haven't figured out how to swap 
(but have so far assumed it to be an 'int')...

...the real problem I'm stuck with is that it seems that when I do 
the LoadLEFloat on the src vector, it changes the referenced 
(p+offset):  and this screws up later accesses, because it seems that 
models are re-read in with level loading...

Any ideas?  Does anything here look extremely wrong?

tanx,
jamie



More information about the freespace2 mailing list