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:
And here is how I call it:
And if somebody is interested in my project: IsoTactics Blog.
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.