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!
//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;
}
Hi XL2,
You will find below, the prototypes of the functions I have added in the next release:
/** @brief Open a file
* @param file Pointer to an allocated jo_file struct
* @param filename Filename (upper case and shorter as possible like "A.TXT")
* @return true if succeed
*/
bool jo_fs_open(jo_file * const file, const char *const filename);
/** @brief Close a file
* @param file Pointer to an allocated and valid jo_file struct
*/
void jo_fs_close(jo_file * const file);
/** @brief Read bytes from a file
* @param file Pointer to an allocated and valid jo_file struct
* @param buffer Pointer to an allocated buffer (length >= nbytes)
* @param nbytes number of bytes to read
* @return Number of bytes read (<= 0 means EOF)
*/
int jo_fs_read_next_bytes(jo_file * const file, char *buffer, unsigned int nbytes);
Sample:
jo_file file;
char buf[2048];
if (jo_fs_open(&file, "TEST.TXT"))
{
while (jo_fs_read_next_bytes(&file, buf, 2048) > 0)
/*DO SOMETHING */;
jo_fs_close(&file);
}
I made a new version (http://jo-engine.org/download/) with CD read-retry and a new function:
/** @brief Seek forward from current position of a file
* @param file Pointer to an allocated and valid jo_file struct
* @param nbytes number of bytes to skip
* @return true if succeed
*/
bool jo_fs_seek_forward(jo_file * const file, unsigned int nbytes);
Now you can skip a part of a file and use jo_fs_read_next_bytes() after (just don't forget to shift the pointer : buffer + nbytes)
Example:
jo_file file;
char *file_contents;
...
jo_fs_open(&file, "FILE.TXT");
jo_fs_seek_forward(&file, 4096); /* I assume that 4096 is the size of the part to skip in the file and to preserve in the buffer */
jo_fs_read_next_bytes(&file, file_contents + 4096, 42);
jo_fs_close(&file);
Hi friend!
C is a strongly typed language so it enforces correct use of types, but if you know what you are doing you can cast a pointer to something else.
You can cast the return pointer to the type you are using like int* or your_type* or a void* (which matches everything) and the warning will go away.
For example:
jo_file file;
char * temp_pointer;
super_duper_type * awesome_thing;
...
jo_fs_open(&file, "FILE.TXT");
jo_fs_seek_forward(&file, 4096); /* I assume that 4096 is the size of the part to skip in the file and to preserve in the buffer */
jo_fs_read_next_bytes(&file, temp_pointer + 4096, 42);
jo_fs_close(&file);
awesome_thing = (super_duper_type*) temp_pointer;
// or like this: awesome_thing = (void*) temp_pointer;
I think Johannes specified the temp pointer as char because when you use pointer arithmetic like temp_pointer+2 what you really are saying is temp_pointer+(2*sizeof(char));
If you do pointer arithmetic on a int* like int_ptr+2 what you are really saying is int_ptr+(sizeof(int))
If I remember correctly if you try to do pointer arithmetic on a void* it wont work correctly because void has no size, since it has no size the compiler does not know how much to add.
Nope, the size of a pointer depends of the architecture. (32 bits => 4 bytes, 64 bits => 8 bytes, etc). It's just not portable.
Yes you are correct, I did not explain myself correctly, what I meant is that with void* you don't know the size of what you are pointing to so when you do pointer arithmetic it might not work correctly.
Like you said the void* size depends on the CPU architecture, all the pointers in an application have the same size and that is why you can simply cast them from one pointer type to another, whatever the data the pointer is pointing to it just contains an address.
You can even have pointers that point to another pointers xD:
//have an int
int int_val = 1;
//save its pointer
int* int_pointer = &int_val;
//save the pointer to that pointer
int** pointer_to_int_pointer =&int_pointer ;
//now increase the original int with the pointer to pointer 8D
*(*pointer_to_int_pointer)++;
//int_val will now be 2
Done.
You can pull from GIT
/** @brief Set how many sector is read on the same time
* @param count Sector count
*/
void jo_fs_set_read_sector_count(const int count);
Restriction: don't change read size if a file is being read ;)