Archived

This topic is now archived and is closed to further replies.

McZ

loading files (FileManager)

Recommended Posts

I have been thinking about a FileManager class that will controll the loading of everything in my engine.. and I want it to load the files in a separate thread. And it should be using some kind of codecs to be able to load different filetypes this way I can support new filetypes just to write a new codec.. altough I can''t figure out how the codec thing should work and how the thread-controll thing.. becouse if I tell the FileManager to load in a thread the main-thread will proceed and try to use an object that hasn''t been loaded yet.. and then I don''t know how the codec should pass around the loaded file.. this is how I would like it to work:

// First example is loading on demand, non-threaded.


// Loading of the file

cImageData *Image = cFileManager::Create()->LoadFile( "image.tga" );

// or to load a mesh

cMeshData *Mesh = cFileManager::Create()->LoadFile("Mesh.Obj");
..
but I don''t know how to do it when the fileManager is threaded... becouse I can''t return a pointer to a mesh/image if it hasn''t been loaded!? I thought I could use a FileHandle thing like this

enum FileStatus { FS_OK, FS_NOT_LOADED, FS_FAILED };

struct sFileHandle {

 char *FileName;

 int iStatus; // the status so the user can check if it is loaded ok.


 int iSize; // size of the data.

 void *Data; // a pointer to the memory where the data is ( could point to some error struct with an error message if it failed loading. )

};

cImageData *Image = NULL;
cMeshData  *Mesh  = NULL;
// to queue a file

sFileHandle *ImageHandle = cFileManager::Create()->QueueFile( "image.tga" );

sFileHandle *MeshHandle = cFileManager::Create()->QueueFile( "mesh.obj" );

// Then to load them when the engine is ready

cFileManager::Create()->ProcessQueue();

do {
 // some kind of wait loop or something

 // update a progress indicator...


}while(cFileManager::Create()->IsWorking());

// So here all files has been loaded... now I can convert them

if( ImageHandle->iStatus == FS_OK )
{
 Image = (cImageData*)ImageHandle->Data;
}
so.. anyone got some other better idea for me?

Share this post


Link to post
Share on other sites
You could have the filemanger return a ResourceID. This id is known the moment you try to load the file. Then when you want the resource call FileManager->GetResourceByID(myMeshId).
If the resource isn''t loaded yet, it should return a null-pointer, else it''ll return the valid resource.

Of course you''ll always have to check for the nullpointer.

Share this post


Link to post
Share on other sites