Jump to content

  • Log In with Google      Sign In   
  • Create Account


We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.

Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!

URI's and filesystem access

Posted by Kimmi, in ZFX-Community-Engine 2, Realtime graphic, assimp 02 November 2011 · 564 views

  • first screen1

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?

So I added a class called Uri. This stands for unique resource identification ( see http://en.wikipedia....urce_Identifier 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
[source lang="cpp"][/size][/font][/size][/font][font="arial"][size="2"][font="arial, sans-serif"][size="2"]filename = "c:\models\spider.obj"[/size][/font][/size][/font][font="arial"][size="2"][font="arial, sans-serif"][size="2"][/source]

the URI format will be:

[source lang="cpp"]
uri = "file://c:/models/spider.obj" ( on a windows xp system )

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:
[source lang="cpp"][/size][/font][/size][/font][font="arial"][size="2"][font="arial, sans-serif"][size="2"]uri = "zip://texture.jpg";[/size][/font][/size][/font][font="arial"][size="2"][font="arial, sans-serif"][size="2"][/source]
You can get the mounted filesystem and get a stream to access the resource as following:
[source lang ="cpp"][/size][/font][/size][/font][font="arial"][size="2"][font="arial, sans-serif"][size="2"]Stream *pZipStream = NULL;[/size][/font][/size][/font][font="arial"][size="2"][font="arial, sans-serif"][size="2"]IFileSystem *pFS = IOServer::instance()->getFileSystem( "zip" );[/size][/font][/size][/font][font="arial"][size="2"][font="arial, sans-serif"][size="2"]if ( pFS )[/size][/font][font="arial, sans-serif"] [/font][/size][/font][font="arial"][size="2"][font="arial, sans-serif"][size="2"] pZipStream = pFS->open( uri, Stream::ReadAccess );[/size][/font][/size][/font][font="arial"][size="2"][font="arial, sans-serif"][size="2"][/source]

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:

[source lang="cpp"]
// Mount the zip file system.
IOServer::instance()->mountFileSystem( "zip", new ZipFileSystem( "c:\\archive.zip" );
// get the file system
IFileSystem *pFS = IOServer::instance()->getFileSystem( "zip" );

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!

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.

December 2014 »

2122232425 26 27