Sega Saturn Development > Jo Engine Wish List
Reading binary files with pointers instead of returned char stream?
XL2:
I managed to build my custom binary file format and read it on the Saturn, so I can display a mesh loaded from a binary file on the CD.
My concern now is that I'm using the jo_fs_read_file, which returns a char stream, which takes memory while I'm loading everything to the right place.
It's not a huge problem while loading small images and sound files, but for a map taking 1 MB, it just won't be doable (unless I'm mistaken and got it all wrong).
Is there a way, in Jo Engine, to just use a pointer to read the file and return each time only what you need (like 8, 16, 24 or 32 bits from a start pointer)?
If not, can it be added in the next version?
Thanks!
mindslight:
Sure :)
XL2:
Great! Thanks!
I know the topic is now in "Wish list", but I could need some help.
Bad news ; while the binary mesh loading works in Yabause, in SSF it's a real mess (but works with lower compatibility) while on real hardware it doesn't work at all (it crashes before even loading anything).
It's probably a mistake related to memory allocation or initalization, but I have no idea what's wrong at the moment.
I've attached the files, if anyone with better knowledge of memory allocation could look it up, I would really appreciate!
Thanks!
--- Code: ---
//Start address is 0x00200000
void * LoadBinaryMAP(void * startAddress)
{
char * stream;
void * currentAddress;
int length;
mesh_tot = 0;
stream = jo_fs_read_file("MAPT.ZTM", &length);
register unsigned int idx = 0;
register unsigned short i=0;
register unsigned int ii=0;
register unsigned int iii=0;
register unsigned int nbpoint=0;
register unsigned int nbpolygon=0;
currentAddress = startAddress;
mesh_tot = jo_swap_endian_ushort(*((unsigned short *)(stream)));
idx+=2;
for (i=0; i<mesh_tot; i++)
{
jo3dMesh[i] = currentAddress;
nbpoint = jo_swap_endian_uint(*((unsigned int *)(stream+idx)));
idx+=4;
nbpolygon = jo_swap_endian_uint(*((unsigned int *)(stream + idx)));
idx+=4;
jo3dMesh[i]->data.pntbl = (POINT*)(jo3dMesh[i] + sizeof(unsigned int));
for (JO_ZERO(ii); ii<nbpoint; ii++)
{
for (JO_ZERO(iii); iii<3; iii++)
{
jo3dMesh[i]->data.pntbl[ii][iii] = jo_swap_endian_int(*((int *)(stream + idx)));
idx+=4;
}
}
jo3dMesh[i]->data.pltbl = (POLYGON*) (jo3dMesh[i]->data.pntbl + sizeof(POINT)*nbpoint);
for (JO_ZERO(ii); ii<nbpolygon; ii++)
{
for (JO_ZERO(iii); iii<3; iii++)
{
jo3dMesh[i]->data.pltbl[ii].norm[iii] = jo_swap_endian_int(*((int *)(stream + idx)));
idx+=4;
}
for (JO_ZERO(iii); iii<4; iii++)
{
jo3dMesh[i]->data.pltbl[ii].Vertices[iii]=jo_swap_endian_ushort(*((unsigned short*)(stream + idx)));
idx+=2;
}
}
jo3dMesh[i]->data.attbl = (ATTR*) (jo3dMesh[i]->data.pltbl + sizeof(POLYGON)*nbpolygon);
for (JO_ZERO(ii); ii<nbpolygon; ii++)
{
jo3dMesh[i]->data.attbl[ii].texno = jo_swap_endian_ushort(*((unsigned short*)(stream + idx)));
idx+=2;
jo3dMesh[i]->data.attbl[ii].sort = SORT_MAX;
jo3dMesh[i]->data.attbl[ii].flag = Dual_Plane;
jo3dMesh[i]->data.attbl[ii].colno = No_Palet;
jo3dMesh[i]->data.attbl[ii].gstb = No_Gouraud;
jo3dMesh[i]->data.attbl[ii].dir = MESHoff, sprNoflip, UseLight;
}
jo3dMesh[i]->data.nbPoint = nbpoint;
jo3dMesh[i]->data.nbPolygon = nbpolygon;
currentAddress = (void*) (jo3dMesh[i] + sizeof(jo3dMesh[i]));
}
jo_free(stream);
jo_printf(0, 6, "current adress : %d ", currentAddress);
return currentAddress;
}
--- End code ---
XL2:
The good folks at SegaXtreme helped with it, and it was an issue with data alignment.
Seems to be fixed for now!
I will update the tool and FPS demo in the next few days to show map loading from the disc.
mindslight:
Great !
BTW, I'll add more filesystem feature in the next release
Navigation
[0] Message Index
[#] Next page
Go to full version