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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Buckermann

Pages: [1]
1
General discussions / PhysFS and SFML, seeking advice
« on: April 23, 2009, 11:42:39 am »
Greetings,
I'm playing around with a simple isometric graphics engine, and since it uses lots of small files, I decided to use PhysFS for the file handling. Thankfully SFML provides LoadFromMemory() functions, so I figured a way out to actually use PhysFS (only for images for now, but the principle should be the same for sound/music I hope).
Since I'm not a very experienced coder, I have the nagging feeling that I did something wrong, even when it seems to work like it should. So it would be nice if you could have a look at this simple function and tell me if something is wrong with it.

The image loading function:
Code: [Select]

int PHYS_LoadImage(char* Filename, sf::Image* ptrImage)
{
    PHYSFS_File* LoadFile;
    if(!(LoadFile = PHYSFS_openRead(Filename)))
    {
        const char* error = PHYSFS_getLastError();
        std::cout<<error<<std::endl;
        Log(error);
        return 1;
    }
    int FileSize = PHYSFS_fileLength(LoadFile);
    //std::cout<<"Filesize in byte for "<<Filename<<" is "<<FileSize<<std::endl;
    char *FileBuffer = new char [FileSize];
    PHYSFS_setBuffer(LoadFile, 1024);
    PHYSFS_read(LoadFile, FileBuffer, FileSize, 1);
    ptrImage->LoadFromMemory(FileBuffer, FileSize);
    delete[] FileBuffer;
    return 0;
}


And here is how I call it:
Code: [Select]


    //physfs testing
    PHYSFS_init(NULL);
    if(!PHYSFS_mount("Data/IsoTiles/Chars.zip", "Chars", 1))
    {
        std::cout << "Zip File NOT found!"<<std::endl;
        Log("Zip File NOT found!");
    }
    sf::Image CharImageSource[9];
    if(!PHYS_LoadImage("Chars/char_m001_001.png", &CharImageSource[0]));
        Log("PhysFS File load to Sfml Image failed");



And if somebody is interested in my project: IsoTactics Blog.

Pages: [1]