Merge pull request #303 from cbeck88/troubleshooting_travis
SDL RW Ops (master, new)
This commit is contained in:
commit
2d719f21db
8 changed files with 107 additions and 7 deletions
|
@ -31,6 +31,7 @@ before_install:
|
|||
- if [ "$CXX" = "g++" ]; then time sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y; fi
|
||||
|
||||
install:
|
||||
- sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu/ saucy main universe"
|
||||
- time sudo apt-get update -qq
|
||||
- time sudo apt-get install -qq libboost-filesystem-dev libboost-iostreams-dev libboost-program-options-dev libboost-regex-dev libboost-system-dev libboost-test-dev libcairo2-dev libfribidi-dev libpango1.0-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-net1.2-dev libsdl-ttf2.0-dev gdb
|
||||
- if [ "$CXX" = "g++" ]; then time sudo apt-get -qq install g++-4.8; fi
|
||||
|
|
|
@ -547,7 +547,7 @@ if(ENABLE_TOOLS OR ENABLE_GAME OR ENABLE_TESTS)
|
|||
find_package( SDL_image 1.2 REQUIRED )
|
||||
endif(ENABLE_TOOLS OR ENABLE_GAME OR ENABLE_TESTS)
|
||||
if(ENABLE_GAME OR ENABLE_TESTS)
|
||||
find_package( SDL_mixer 1.2 REQUIRED )
|
||||
find_package( SDL_mixer 1.2.12 REQUIRED )
|
||||
find_package( SDL_ttf 2.0.8 REQUIRED )
|
||||
|
||||
if(NOT MSVC)
|
||||
|
|
|
@ -357,7 +357,7 @@ if env["prereqs"]:
|
|||
return \
|
||||
conf.CheckSDL(require_version = '1.2.0') & \
|
||||
conf.CheckSDL("SDL_ttf", require_version = "2.0.8") & \
|
||||
conf.CheckSDL("SDL_mixer", require_version = '1.2.0') & \
|
||||
conf.CheckSDL("SDL_mixer", require_version = '1.2.12') & \
|
||||
conf.CheckSDL("SDL_image", require_version = '1.2.0')
|
||||
|
||||
have_server_prereqs = (\
|
||||
|
|
|
@ -30,8 +30,13 @@
|
|||
|
||||
class config;
|
||||
|
||||
//TODO: will this compile for msvc <= 2010 which has a bug when it comes to forward declaring return values?
|
||||
struct SDL_RWops;
|
||||
|
||||
namespace filesystem {
|
||||
|
||||
SDL_RWops* load_RWops(const std::string &path);
|
||||
|
||||
/** An exception object used when an IO error occurs */
|
||||
struct io_exception : public game::error {
|
||||
io_exception() : game::error("") {}
|
||||
|
|
|
@ -13,8 +13,11 @@
|
|||
#include "serialization/unicode.hpp"
|
||||
#include "util.hpp"
|
||||
|
||||
#include <SDL_rwops.h>
|
||||
|
||||
static lg::log_domain log_filesystem("filesystem");
|
||||
#define LOG_FS LOG_STREAM(info, log_filesystem)
|
||||
#define ERR_FS LOG_STREAM(err, log_filesystem)
|
||||
|
||||
namespace filesystem {
|
||||
|
||||
|
@ -198,4 +201,90 @@ const file_tree_checksum& data_tree_checksum(bool reset)
|
|||
return checksum;
|
||||
}
|
||||
|
||||
|
||||
static int SDLCALL ifs_seek(struct SDL_RWops *context, int offset, int whence);
|
||||
static int SDLCALL ifs_read(struct SDL_RWops *context, void *ptr, int size, int maxnum);
|
||||
static int SDLCALL ifs_write(struct SDL_RWops *context, const void *ptr, int size, int num);
|
||||
static int SDLCALL ifs_close(struct SDL_RWops *context);
|
||||
|
||||
SDL_RWops* load_RWops(const std::string &path) {
|
||||
SDL_RWops *rw = SDL_AllocRW();
|
||||
|
||||
rw->seek = &ifs_seek;
|
||||
rw->read = &ifs_read;
|
||||
rw->write = &ifs_write;
|
||||
rw->close = &ifs_close;
|
||||
|
||||
rw->type = 7; // Random number that is larger than 5
|
||||
|
||||
std::istream *ifs = istream_file(path);
|
||||
if(!ifs) {
|
||||
ERR_FS << "load_RWops: istream_file returned NULL on " << path << '\n';
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rw->hidden.unknown.data1 = ifs;
|
||||
|
||||
return rw;
|
||||
}
|
||||
|
||||
static int SDLCALL ifs_seek(struct SDL_RWops *context, int offset, int whence) {
|
||||
std::ios_base::seekdir seekdir;
|
||||
switch(whence){
|
||||
case RW_SEEK_SET:
|
||||
seekdir = std::ios_base::beg;
|
||||
if(offset < 0)
|
||||
offset = 0;
|
||||
break;
|
||||
case RW_SEEK_CUR:
|
||||
seekdir = std::ios_base::cur;
|
||||
break;
|
||||
case RW_SEEK_END:
|
||||
seekdir = std::ios_base::end;
|
||||
if(offset > 0)
|
||||
offset = 0;
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
std::istream *ifs = static_cast<std::istream*>(context->hidden.unknown.data1);
|
||||
const std::ios_base::iostate saved_state = ifs->rdstate();
|
||||
|
||||
ifs->seekg(offset, seekdir);
|
||||
|
||||
if(saved_state != ifs->rdstate() && offset < 0) {
|
||||
ifs->clear(saved_state);
|
||||
ifs->seekg(0, std::ios_base::beg);
|
||||
}
|
||||
|
||||
std::streamsize pos = ifs->tellg();
|
||||
return static_cast<int>(pos);
|
||||
}
|
||||
static int SDLCALL ifs_read(struct SDL_RWops *context, void *ptr, int size, int maxnum) {
|
||||
std::istream *ifs = static_cast<std::istream*>(context->hidden.unknown.data1);
|
||||
|
||||
// This seems overly simplistic, but it's the same as mem_read's implementation
|
||||
ifs->read(static_cast<char*>(ptr), maxnum * size);
|
||||
std::streamsize num = ifs->good() ? maxnum : ifs->gcount() / size;
|
||||
|
||||
// EOF sticks unless we clear it. Bad is an actual I/O error
|
||||
if(!ifs->bad())
|
||||
ifs->clear();
|
||||
|
||||
return static_cast<int>(num);
|
||||
}
|
||||
static int SDLCALL ifs_write(struct SDL_RWops * /*context*/, const void * /*ptr*/, int /*size*/, int /*num*/) {
|
||||
SDL_SetError("Writing not implemented");
|
||||
return 0;
|
||||
}
|
||||
static int SDLCALL ifs_close(struct SDL_RWops *context) {
|
||||
if (context) {
|
||||
std::istream *ifs = static_cast<std::istream*>(context->hidden.unknown.data1);
|
||||
delete ifs;
|
||||
SDL_FreeRW(context);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -228,7 +228,8 @@ static TTF_Font* open_font(const std::string& fname, int size)
|
|||
}
|
||||
}
|
||||
|
||||
TTF_Font* font = TTF_OpenFont(name.c_str(),size);
|
||||
SDL_RWops *rwops = filesystem::load_RWops(name);
|
||||
TTF_Font* font = TTF_OpenFontRW(rwops, true, size); // SDL takes ownership of rwops
|
||||
if(font == NULL) {
|
||||
ERR_FT << "Failed opening font: TTF_OpenFont: " << TTF_GetError() << std::endl;
|
||||
return NULL;
|
||||
|
|
|
@ -450,7 +450,8 @@ static std::string get_localized_path (const std::string& file, const std::strin
|
|||
// Load overlay image and compose it with the original surface.
|
||||
static void add_localized_overlay (const std::string& ovr_file, surface &orig_surf)
|
||||
{
|
||||
surface ovr_surf = IMG_Load(ovr_file.c_str());
|
||||
SDL_RWops *rwops = filesystem::load_RWops(ovr_file);
|
||||
surface ovr_surf = IMG_Load_RW(rwops, true); // SDL takes ownership of rwops
|
||||
if (ovr_surf.null()) {
|
||||
return;
|
||||
}
|
||||
|
@ -476,7 +477,8 @@ static surface load_image_file(const image::locator &loc)
|
|||
if (!loc_location.empty()) {
|
||||
location = loc_location;
|
||||
}
|
||||
res = IMG_Load(location.c_str());
|
||||
SDL_RWops *rwops = filesystem::load_RWops(location);
|
||||
res = IMG_Load_RW(rwops, true); // SDL takes ownership of rwops
|
||||
// If there was no standalone localized image, check if there is an overlay.
|
||||
if (!res.null() && loc_location.empty()) {
|
||||
const std::string ovr_location = get_localized_path(location, "--overlay");
|
||||
|
|
|
@ -499,7 +499,8 @@ static void play_new_music()
|
|||
std::map<std::string,Mix_Music*>::const_iterator itor = music_cache.find(filename);
|
||||
if(itor == music_cache.end()) {
|
||||
LOG_AUDIO << "attempting to insert track '" << filename << "' into cache\n";
|
||||
Mix_Music* const music = Mix_LoadMUS(filename.c_str());
|
||||
SDL_RWops *rwops = filesystem::load_RWops(filename);
|
||||
Mix_Music* const music = Mix_LoadMUSType_RW(rwops, MUS_NONE, true); // SDL takes ownership of rwops
|
||||
if(music == NULL) {
|
||||
ERR_AUDIO << "Could not load music file '" << filename << "': "
|
||||
<< Mix_GetError() << "\n";
|
||||
|
@ -721,7 +722,8 @@ static Mix_Chunk* load_chunk(const std::string& file, channel_group group)
|
|||
std::string const &filename = filesystem::get_binary_file_location("sounds", file);
|
||||
|
||||
if (!filename.empty()) {
|
||||
temp_chunk.set_data(Mix_LoadWAV(filename.c_str()));
|
||||
SDL_RWops *rwops = filesystem::load_RWops(filename);
|
||||
temp_chunk.set_data(Mix_LoadWAV_RW(rwops, true)); // SDL takes ownership of rwops
|
||||
} else {
|
||||
ERR_AUDIO << "Could not load sound file '" << file << "'." << std::endl;
|
||||
throw chunk_load_exception();
|
||||
|
|
Loading…
Add table
Reference in a new issue