URI's and filesystem access

Published November 02, 2011
Advertisement
[font="arial"][size="2"][font="arial, sans-serif"][size="2"]I finished the first approach to import assets in a separate loader task and I was able to see my first imported model. Currently any kind of texturing needs to be implemented. But how can you desribe the location of a resource like a texture or a shader in a elegant way? [/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"] [/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"][size="2"]So [/font][/font][font="arial, sans-serif"][size="2"]I added a class called Uri. This stands for unique resource identification ( see [/font]http://en.wikipedia....urce_Identifier[font="arial, sans-serif"][size="2"] to learn more about this ). This Uri is the new way to describe the place where you find your resources. For instance if you want to load a resource from your locale filesystem at[/font]
[font="arial"][size="2"][font="arial, sans-serif"] [/font][font="arial, sans-serif"][/font][font="arial, sans-serif"][size="2"][source lang="cpp"][/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"][size="2"]filename = "c:\models\spider.obj"[/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"][size="2"][/source][/font][font="arial, sans-serif"] [/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"] [/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"][size="2"]the URI format will be:[/font][/font]
[font="arial, sans-serif"] [/font]
[font="arial"][size="2"][font="arial, sans-serif"] [/font][font="arial, sans-serif"][size="2"][source[/font][/font][font="arial, sans-serif"] [/font][font="arial, sans-serif"][size="2"]lang="cpp"[/font][font="arial, sans-serif"][size="2"]][/font]
[font="arial"][size="2"][font="arial, sans-serif"][size="2"]uri = "file://c:/models/spider.obj" ( on a windows xp system )[/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"][size="2"][/source][/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"] [/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"] [/font][font="arial, sans-serif"][size="2"]The interesting thing is the scheme of the URI ( here the attribute file:// ), which describes the type of filesystem we have to use to open this resource. I introduced a new class called IOServer, where you can get a filesystem instance to manage the requested file system. For instance if you have a URI like:[/font][font="arial, sans-serif"] [/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"][size="2"][source lang="cpp"][/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"][size="2"]uri = "zip://texture.jpg";[/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"][size="2"][/source][/font][font="arial, sans-serif"] [/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"][size="2"]You can get the mounted filesystem and get a stream to access the resource as following:[/font][font="arial, sans-serif"] [/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"][size="2"][source lang ="cpp"][/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"][size="2"]Stream *pZipStream = NULL;[/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"][size="2"]IFileSystem *pFS = IOServer::instance()->getFileSystem( "zip" );[/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"][size="2"]if ( pFS )[/font][font="arial, sans-serif"] [/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"][size="2"] pZipStream = pFS->open( uri, Stream::ReadAccess );[/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"][size="2"][/source][/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"] [/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"] [/font][font="arial, sans-serif"][size="2"]Currently I only have mounted the locale filesystem as the default one. If you want to use this you have to mount the zip-filesystem before:[/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"] [/font][/font]
[font="arial"][size="2"][font="arial, sans-serif"] [/font][font="arial, sans-serif"][size="2"][source[/font][/font][font="arial, sans-serif"] [/font][font="arial, sans-serif"][size="2"]lang="cpp"[/font][font="arial, sans-serif"][size="2"][size="2"]][/font]
[font="arial, sans-serif"][size="2"]// Mount the zip file system.[/font]
[font="arial, sans-serif"][size="2"]IOServer::instance()->mountFileSystem( "zip", new ZipFileSystem( "c:\\archive.zip" );[/font]
[font="arial, sans-serif"][size="2"]...[/font]
[font="arial, sans-serif"][size="2"]// get the file system[/font]
[font="arial, sans-serif"][size="2"][size="2"]IFileSystem *pFS = IOServer::instance()->getFileSystem( "zip" );[/font]
[font="arial, sans-serif"][size="2"][size="2"][/source][/font]
[font="arial, sans-serif"] [/font]
[font="arial, sans-serif"] [/font][font="arial, sans-serif"][size="2"][size="2"]I saw this approach first in the Nebula3 Device and I was amazed to see a really clean design for that kind of problems. Thanks guys![/font]
[font="arial, sans-serif"] [/font]
[font="arial, sans-serif"][size="2"][size="2"]But there is still some work to do. Currently you can only mount one Zip-Archive. If you want to switch to a different one you have to unmount the older one and remount the new. Here I want to be able to deal with multiple archives. But for a first proof of concept this should work. And I missed a simple search method as well. Currently you have to know where to look for your textures. And this is not comfortable in my eyes. [/font]
[font="arial, sans-serif"] [/font]
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement