Upon further reading, I can't think of why this would not work.
What happens? It does not load. All loading stops.
//Experimental
void * ztFileStream(Sint8 * filename, void * startAddress, entity_t * model, Sint8 dummy)
{
memset_l((void*)startAddress,0x0000, (0xFFFE - ((Uint32)startAddress-(Uint32)LWRAM))); //Not 100% necessary, since data can just be overwritten, but good for testing and see how much data a level takes
void * currentAddress;
currentAddress = startAddress;
Sint32 fid = GFS_NameToId((Sint8*)filename);
GfsHn gfs;
Sint32 stat;
Sint32 nsct;
Sint32 bsize;
//Model Data is the destination of data.
modelData_t bufModel;
//Destination address?
void * ptr = &bufModel;
//Loading follows
gfs = GFS_Open(fid);
//Get sectors
GFS_GetFileSize(gfs, &nsct, NULL, NULL);
bsize = 2048 * nsct;
// nsct = GFS_ByteToSct(gfs, bytesOf);
//modelData_t has an assumed size?
GFS_NwFread(gfs, nsct, (Uint32*)currentAddress, bsize);
//For loop is blank because this will run until GFS_Close, AKA always run until GFS_Close.
for(;;)
{
stat = GFS_NwExecOne(gfs);
if(stat == GFS_SVR_COMPLETED)
{
break;
}
//Copy gfs to modelData_t bufmodel???
memcpy_l((Sint32*)ptr, (Sint32*)(startAddress), (sizeof(modelData_t)));
/**ADDED**/
model->pos[X]=bufModel.Origin[X]; model->pos[Y]=bufModel.Origin[Y]; model->pos[Z]=bufModel.Origin[Z];
model->length[X]=bufModel.Length[X]; model->length[Y]=bufModel.Length[Y]; model->length[Z]=bufModel.Length[Z];
model->nbMeshes=bufModel.TOTAL_MESH;
/**Load the texture list (using an offset to allow DMA transfer)**/
Uint16 first_texture = loadTextures(startAddress, &bufModel);
/**Load PDATA**/
Sint32 bytesOff = bufModel.TEXT_SIZE+(sizeof(modelData_t)) - (bytesOff*2048);
currentAddress = (void*)(currentAddress + bytesOff);
currentAddress = loadPDATA((void*)currentAddress, model, &bufModel);
/**Set textures**/
setTextures(first_texture, model, bufModel.TOTAL_MESH, true);
}
GFS_Close(gfs);
return currentAddress;
}
So what do we do:
1 - we set a new address so we don't overwrite the last data
2 - that address is now the current address
3 - we get a file ID from the file name
4 - variable and struct setup
? I question why bufModel is modelData_t and not entity_t, tried it one way or another it doesn't function properly
5 - Set GFS and GFS handler
6 - Get the file size in sectors, we don't need anything else (they are NULL).
6 - Set the size in bytes based on the sector size
7 - Queue the command NwFread for the file with current Address as the buffer area
8 - Execute NwFread in the open gfs
9 - When the server is complete with the file, stop the execution and
10 - memcpy destination bufModel, the source startAddress (which has never been set separate from currentAddress at this point BUT setting it to current causes unknown code crash), the size copied is the size of... you know.
? Why would current crash when it is no different from start...
? It doesn't crash or halt if everything past memcpy before GFS_Close is commented out.
11 What follows,
taking the contents of the buffered model data and putting it into the model which is the desired entity_t struct.
Truly, I know I don't really understand what is happening. Especially not enough to make a callback that could put the binary data into an entity_t struct from the Jo engine async read function.
I'm thinking in a forum post.