301
Jo Engine Wish List / Re: Reading binary files with pointers instead of returned char stream?
« on: August 08, 2017, 10:52:11 pm »
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!
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: [Select]
//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;
}