Game Development Reference
In-Depth Information
private:
clPtr<Bitmap> FBmp;
};
6.
To load a Bitmap object, we implement the following function:
clPtr<Bitmap> LoadImg( const std::string& FileName )
{
clPtr<iIStream> IStream = g_FS->CreateReader(FileName);
clPtr<Bitmap> Bmp = new Bitmap(1, 1);
g_Loader->AddTask( new LoadOp_Image( Bmp, IStream ) );
return Bmp;
}
7. We use three global objects: the ilesystem g_FS , the event queue g_Events , and
the loader thread g_Loader . We initialize them at the beginning of our program. At
irst, we start FileSystem :
g_FS = new FileSystem();
g_FS->Mount(".");
8.
The iAsyncQueue and WorkerThread objects are created, just as in Chapter 3 ,
Networking :
g_Events = new iAsyncQueue();
g_Loader = new WorkerThread();
g_Loader->Start( iThread::Priority_Normal );
9.
Finally, we can load the bitmap:
clPtr<Bitmap> Bmp = LoadImg("test.bmp");
At this point Bmp is a ready-to-use object that will be automatically updated on another thread.
Of course, it is not thread-safe to use the Bmp->FBitmapData , since it might be destroyed
while we read it, or only partially updated. To overcome these dificulties, we have to introduce
so-called proxy objects that we use in Chapter 6 , Unifying OpenGL ES 3 and OpenGL 3 .
There's more
The complete example can be found in 3_AsyncTextures . It implements the asynchronous
images loading technique described in this recipe.
See also
F Chapter 5 , Cross-platform Audio Streaming
F Chapter 3 , Networking
 
Search WWH ::




Custom Search