Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <physfs.h>
- class FileStream : public sf::InputStream
- {
- public:
- FileStream() : m_file(NULL){}
- virtual ~FileStream()
- {
- PHYSFS_close(m_file);
- }
- bool open(const char* filename)
- {
- if(m_file)
- {
- PHYSFS_close(m_file);
- }
- m_file = PHYSFS_openRead(filename);
- return m_file != NULL;
- }
- virtual sf::Int64 read(void* data, sf::Int64 size)
- {
- if(m_file)
- {
- return PHYSFS_read(m_file, data, 1, static_cast<PHYSFS_uint32>(size));
- }
- return -1;
- }
- virtual sf::Int64 seek(sf::Int64 position)
- {
- if(m_file)
- {
- PHYSFS_seek(m_file, position);
- return tell();
- }
- return -1;
- }
- virtual sf::Int64 tell()
- {
- if (m_file)
- {
- return PHYSFS_tell(m_file);
- }
- return -1;
- }
- virtual sf::Int64 getSize()
- {
- if(m_file)
- {
- return PHYSFS_fileLength(m_file);
- }
- return -1;
- }
- private:
- PHYSFS_File* m_file;
- };
- // ----------------------------------------------------------------------------------------------
- // Example :
- // ----------------------------------------------------------------------------------------------
- PHYSFS_init(argv[0]);
- PHYSFS_addToSearchPath("images.zip",1);
- sf::Texture my_texture;
- FileStream my_stream;
- if(!my_stream.open("images/img.png"))
- {
- // Erreur
- }
- if(!my_texture.loadFromStream(my_stream))
- {
- // Erreur
- }
- sf::Sprite my_sprite;
- my_sprite.setTexture(my_texture);
- // Un peu plus bas... à la fin du programme
- PHYSFS_deinit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement