1 // Copyright Timothy Goya 2007.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 #include <unison/vfs/sdl/Utils.hpp>
16 int rwops_seek(SDL_RWops *context, int offset, int whence)
18 PHYSFS_File *file = reinterpret_cast<PHYSFS_File *>(context->hidden.unknown.data1);
22 res = PHYSFS_seek(file, offset);
25 res = PHYSFS_seek(file, PHYSFS_tell(file) + offset);
28 res = PHYSFS_seek(file, PHYSFS_fileLength(file) + offset);
35 return (int) PHYSFS_tell(file);
38 int rwops_read(SDL_RWops *context, void *ptr, int size, int maxnum)
40 PHYSFS_File *file = reinterpret_cast<PHYSFS_File *>(context->hidden.unknown.data1);
42 int res = PHYSFS_read(file, ptr, size, maxnum);
46 int rwops_close(SDL_RWops *context)
48 PHYSFS_File *file = reinterpret_cast<PHYSFS_File *>(context->hidden.unknown.data1);
64 SDL_RWops *Utils::open_physfs_in(const std::string &filename)
66 PHYSFS_File *file = PHYSFS_openRead(filename.c_str());
68 SDL_RWops* ops = new SDL_RWops;
70 ops->hidden.unknown.data1 = file;
71 ops->seek = rwops_seek;
72 ops->read = rwops_read;
74 ops->close = rwops_close;