Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Custom file interface  (Read 1996 times)

0 Members and 1 Guest are viewing this topic.

Disch

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Custom file interface
« on: April 17, 2010, 02:28:52 pm »
Hello again!

I've been looking into a few areas of SFML and seeing if it fullfills all my needs.  So far it's looking like it will fit the bill beautifully!

I do have one more question about it, though...

It looks like the interfaces for loading files (ie:  sf::Image::LoadFromFile, sf::Music::LoadFromFile, sf::SoundBuffer::LoadFromFile, sf::Font::LoadFromFile, etc) all just take either a string filename or a pointer to a memory buffer.

Is there any way to load an audio/image file via a callback system so that I can use a different file system?

For example, let's say I want my game to have "packages" that can be user defined and could contain things like custom sound effects, images, different game levels, etc.  For ease of distribution and installation, I'd want the packages to be individual .zip files.

So... assuming I have my own method to read .zip files, how could I load audio/image files from a zip, without reading the entire file into memory and using LoadFromMemory (which is particularly impractical for fonts and large audio files that are to be streamed)

Libraries like libpng have a callback system where you can supply your own read/seek/tell/etc functions, but I don't see anything like this in the documentation for SFML.

Is it possible?  Or is LoadFromMemory my only option?

Thanks!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Custom file interface
« Reply #1 on: April 17, 2010, 02:46:10 pm »
It is currently not possible, but it is planned for SFML 2 (look at the "DataStream" feature in the task list).
Laurent Gomila - SFML developer

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Re: Custom file interface
« Reply #2 on: April 17, 2010, 03:39:20 pm »
I'm personally doing it myself somehow.
I have a DataInputStream and DataOutputStream classes with an interface like the java io streams. I also have abstract classes for codification methods over chunks of data to be defined later (I'll use zlib for compression and something else for codification... maybe my own algorithms). Those codification classes can be passed to the streams to be called right after/before the read/write operations (respectively), to encode/decode that chunk of data.

I'm not using it for streaming yet, but I plan to, soon.

So for images, sounds and all other stuff that needs to be fully in memory, I use my inputstream to read the needed data into a buffer until it's filled, and then use the LoadFromMemory methods. For music streaming, I'll ask the next chunk of bytes from my DataInputStream on the method OnGetData of a class derived from sf::SoundStream.
Pluma - Plug-in Management Framework