Merge branch 'master' of github.com:wesnoth/wesnoth

This commit is contained in:
Alexander van Gessel 2017-09-21 15:42:05 +02:00
commit 2a742182d8
16 changed files with 140 additions and 98 deletions

View file

@ -42,12 +42,9 @@
{PLAYABLE}
save_id=Kalenz
no_leader=yes
[unit]
{KALENZ}
x=17
y=38
[/unit]
{KALENZ}
x=17
y=38
#ifndef MULTIPLAYER
{PLAYER_GOLD}

View file

@ -60,14 +60,11 @@
[side]
side=1
{PLAYABLE}
no_leader=yes
save_id=Kalenz
[unit]
{KALENZ}
x=46
y=21
[/unit]
{KALENZ}
x=46
y=21
#ifndef MULTIPLAYER
{PLAYER_GOLD}

View file

@ -15,16 +15,13 @@
{SCENARIO_MUSIC "revelation.ogg"}
[side]
no_leader=yes
# The mp connect code doesn't like scenarios without human sides
controller=human
allow_player=yes
previous_save_id=Kalenz
save_id=temp1234
persistent=no
[unit]
{KALENZ}
[/unit]
{KALENZ}
gold=0
[/side]

View file

@ -40,15 +40,12 @@
[side]
side=1
fog=yes
no_leader=yes
{PLAYABLE}
save_id=Kalenz
[unit]
{KALENZ}
x=18
y=31
[/unit]
{KALENZ}
x=18
y=31
#ifndef MULTIPLAYER
[unit]

View file

@ -40,15 +40,12 @@
[side]
side=1
fog=yes
no_leader=yes
{PLAYABLE}
save_id=Kalenz
[unit]
{KALENZ}
x=20
y=27
[/unit]
{KALENZ}
x=20
y=27
#ifndef MULTIPLAYER
{PLAYER_GOLD}

View file

@ -38,14 +38,11 @@
side=1
fog=yes
share_view=yes
no_leader=yes
{PLAYABLE}
save_id=Kalenz
[unit]
{KALENZ}
x=12
y=1
[/unit]
{KALENZ}
x=12
y=1
#ifndef MULTIPLAYER
[unit]
{LANDAR}

View file

@ -69,15 +69,12 @@ Chapter Four"
[side]
side=1
{PLAYABLE}
no_leader=yes
save_id=Kalenz
[unit]
{KALENZ}
# wmllint: recognize Kalenz
x=25
y=11
[/unit]
{KALENZ}
# wmllint: recognize Kalenz
x=25
y=11
#ifndef MULTIPLAYER
{PLAYER_GOLD}

View file

@ -82,12 +82,9 @@ Chapter Five"
{PLAYABLE}
save_id=Kalenz
no_leader=yes
[unit]
{KALENZ}
x=3
y=18
[/unit]
{KALENZ}
x=3
y=18
#ifndef MULTIPLAYER
{PLAYER_GOLD}

View file

@ -44,12 +44,9 @@
save_id=Kalenz
{GOLD 100 100 100}
no_leader=yes
[unit]
{KALENZ}
x=46
y=39
[/unit]
{KALENZ}
x=46
y=39
#ifndef MULTIPLAYER
[unit]

View file

@ -40,11 +40,8 @@
{GOLD 200 180 160}
save_id=Kalenz
no_leader=yes
[unit]
{KALENZ}
placement=leader
[/unit]
{KALENZ}
placement=leader
#ifndef MULTIPLAYER
#TODO Let's keep cleodil out of multiplayer, shall we?

View file

@ -7,16 +7,7 @@
* http://www.libpng.org/pub/png/src/libpng-LICENSE.txt
*/
#include <SDL_video.h>
/*
* Save an SDL_Surface as a PNG file.
*
* Returns 0 success or -1 on failure, the error message is then retrievable
* via SDL_GetError().
*/
#define SDL_SavePNG(surface, file) \
SDL_SavePNG_RW(surface, SDL_RWFromFile(file, "wb"), 1)
//
//TODO: filesystem::load_RWops is only for reading, would like a writing version also
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

View file

@ -39,7 +39,8 @@ using scoped_ostream = std::unique_ptr<std::ostream>;
typedef std::unique_ptr<SDL_RWops, void(*)(SDL_RWops*)> rwops_ptr;
rwops_ptr load_RWops(const std::string &path);
rwops_ptr make_read_RWops(const std::string &path);
rwops_ptr make_write_RWops(const std::string &path);
/** An exception object used when an IO error occurs */
struct io_exception : public game::error {

View file

@ -17,18 +17,29 @@
#include "filesystem.hpp"
#include "log.hpp"
#include <algorithm>
static lg::log_domain log_filesystem("filesystem");
#define ERR_FS LOG_STREAM(err, log_filesystem)
namespace filesystem {
static Sint64 ifs_size (struct SDL_RWops * context);
static Sint64 SDLCALL ifs_seek(struct SDL_RWops *context, Sint64 offset, int whence);
static size_t SDLCALL ifs_read(struct SDL_RWops *context, void *ptr, size_t size, size_t maxnum);
static size_t SDLCALL ifs_write(struct SDL_RWops *context, const void *ptr, size_t size, size_t num);
static int SDLCALL ifs_close(struct SDL_RWops *context);
// Arbitrary numbers larger than 5
static const Uint32 read_type = 7;
static const Uint32 write_type = 8;
rwops_ptr load_RWops(const std::string &path) {
static Sint64 ifs_size (struct SDL_RWops * context);
static Sint64 ofs_size (struct SDL_RWops * context);
static Sint64 SDLCALL ifs_seek(struct SDL_RWops *context, Sint64 offset, int whence);
static Sint64 SDLCALL ofs_seek(struct SDL_RWops *context, Sint64 offset, int whence);
static size_t SDLCALL ifs_read(struct SDL_RWops *context, void *ptr, size_t size, size_t maxnum);
static size_t SDLCALL ofs_read(struct SDL_RWops *context, void *ptr, size_t size, size_t maxnum);
static size_t SDLCALL ifs_write(struct SDL_RWops *context, const void *ptr, size_t size, size_t num);
static size_t SDLCALL ofs_write(struct SDL_RWops *context, const void *ptr, size_t size, size_t num);
static int SDLCALL ifs_close(struct SDL_RWops *context);
static int SDLCALL ofs_close(struct SDL_RWops *context);
rwops_ptr make_read_RWops(const std::string &path) {
rwops_ptr rw(SDL_AllocRW(), &SDL_FreeRW);
rw->size = &ifs_size;
@ -37,11 +48,11 @@ rwops_ptr load_RWops(const std::string &path) {
rw->write = &ifs_write;
rw->close = &ifs_close;
rw->type = 7; // Random number that is larger than 5
rw->type = read_type;
scoped_istream ifs = istream_file(path);
if(!ifs) {
ERR_FS << "load_RWops: istream_file returned NULL on " << path << '\n';
ERR_FS << "make_read_RWops: istream_file returned NULL on " << path << '\n';
rw.reset();
return rw;
}
@ -50,7 +61,28 @@ rwops_ptr load_RWops(const std::string &path) {
return rw;
}
rwops_ptr make_write_RWops(const std::string &path) {
rwops_ptr rw(SDL_AllocRW(), &SDL_FreeRW);
rw->size = &ofs_size;
rw->seek = &ofs_seek;
rw->read = &ofs_read;
rw->write = &ofs_write;
rw->close = &ofs_close;
rw->type = write_type;
scoped_ostream ofs = ostream_file(path);
if(!ofs) {
ERR_FS << "make_write_RWops: ostream_file returned NULL on " << path << '\n';
rw.reset();
return rw;
}
rw->hidden.unknown.data1 = ofs.release();
return rw;
}
static Sint64 ifs_size (struct SDL_RWops * context) {
std::istream *ifs = static_cast<std::istream*>(context->hidden.unknown.data1);
@ -63,30 +95,38 @@ static Sint64 ifs_size (struct SDL_RWops * context) {
ifs->seekg(orig);
return len;
}
static Sint64 ofs_size (struct SDL_RWops * context) {
std::ostream *ofs = static_cast<std::ostream*>(context->hidden.unknown.data1);
std::streampos orig = ofs->tellp();
ofs->seekp(0, std::ios::end);
std::streampos len = ofs->tellp();
ofs->seekp(orig);
return len;
}
static Sint64 SDLCALL ifs_seek(struct SDL_RWops *context, Sint64 offset, int whence) {
std::ios_base::seekdir seekdir;
typedef std::pair<Sint64, std::ios_base::seekdir> offset_dir;
static offset_dir translate_seekdir(Sint64 offset, int whence) {
switch(whence){
case RW_SEEK_SET:
seekdir = std::ios_base::beg;
if(offset < 0)
offset = 0;
break;
return std::make_pair(std::max(0l, offset), std::ios_base::beg);
case RW_SEEK_CUR:
seekdir = std::ios_base::cur;
break;
return std::make_pair(offset, std::ios_base::cur);
case RW_SEEK_END:
seekdir = std::ios_base::end;
if(offset > 0)
offset = 0;
break;
return std::make_pair(std::min(0l, offset), std::ios_base::end);
default:
assert(false);
throw "assertion ignored";
}
}
static Sint64 SDLCALL ifs_seek(struct SDL_RWops *context, Sint64 offset, int whence) {
std::ios_base::seekdir seekdir;
std::tie(offset, seekdir) = translate_seekdir(offset, whence);
std::istream *ifs = static_cast<std::istream*>(context->hidden.unknown.data1);
const std::ios_base::iostate saved_state = ifs->rdstate();
@ -100,6 +140,23 @@ static Sint64 SDLCALL ifs_seek(struct SDL_RWops *context, Sint64 offset, int whe
std::streamsize pos = ifs->tellg();
return static_cast<int>(pos);
}
static Sint64 SDLCALL ofs_seek(struct SDL_RWops *context, Sint64 offset, int whence) {
std::ios_base::seekdir seekdir;
std::tie(offset, seekdir) = translate_seekdir(offset, whence);
std::ostream *ofs = static_cast<std::ostream*>(context->hidden.unknown.data1);
const std::ios_base::iostate saved_state = ofs->rdstate();
ofs->seekp(offset, seekdir);
if(saved_state != ofs->rdstate() && offset < 0) {
ofs->clear(saved_state);
ofs->seekp(0, std::ios_base::beg);
}
std::streamsize pos = ofs->tellp();
return static_cast<int>(pos);
}
static size_t SDLCALL ifs_read(struct SDL_RWops *context, void *ptr, size_t size, size_t maxnum) {
std::istream *ifs = static_cast<std::istream*>(context->hidden.unknown.data1);
@ -114,11 +171,27 @@ static size_t SDLCALL ifs_read(struct SDL_RWops *context, void *ptr, size_t size
return static_cast<int>(num);
}
static size_t SDLCALL ofs_read(struct SDL_RWops * /*context*/, void * /*ptr*/, size_t /*size*/, size_t /*maxnum*/) {
SDL_SetError("Reading not implemented");
return 0;
}
static size_t SDLCALL ifs_write(struct SDL_RWops * /*context*/, const void * /*ptr*/, size_t /*size*/, size_t /*num*/) {
SDL_SetError("Writing not implemented");
return 0;
}
static size_t SDLCALL ofs_write(struct SDL_RWops *context, const void *ptr, size_t size, size_t num) {
std::ostream *ofs = static_cast<std::ostream*>(context->hidden.unknown.data1);
const std::streampos before = ofs->tellp();
ofs->write(static_cast<const char*>(ptr), num * size);
const std::streampos after = ofs->tellp();
const std::streamoff bytes_written = after - before;
const int num_written = bytes_written / size;
return num_written;
}
static int SDLCALL ifs_close(struct SDL_RWops *context) {
if (context) {
std::istream *ifs = static_cast<std::istream*>(context->hidden.unknown.data1);
@ -127,5 +200,13 @@ static int SDLCALL ifs_close(struct SDL_RWops *context) {
}
return 0;
}
static int SDLCALL ofs_close(struct SDL_RWops *context) {
if (context) {
std::ostream *ofs = static_cast<std::ostream*>(context->hidden.unknown.data1);
delete ofs;
SDL_FreeRW(context);
}
return 0;
}
}

View file

@ -184,7 +184,7 @@ static TTF_Font* open_font_impl(const std::string & fname, int size) {
}
}
filesystem::rwops_ptr rwops = filesystem::load_RWops(name);
filesystem::rwops_ptr rwops = filesystem::make_read_RWops(name);
TTF_Font* font = TTF_OpenFontRW(rwops.release(), true, size); // SDL takes ownership of rwops
if(font == nullptr) {
ERR_FT << "Failed opening font: '" << fname << "'\n";

View file

@ -513,7 +513,7 @@ static std::string get_localized_path(const std::string& file, const std::string
// Load overlay image and compose it with the original surface.
static void add_localized_overlay(const std::string& ovr_file, surface& orig_surf)
{
filesystem::rwops_ptr rwops = filesystem::load_RWops(ovr_file);
filesystem::rwops_ptr rwops = filesystem::make_read_RWops(ovr_file);
surface ovr_surf = IMG_Load_RW(rwops.release(), true); // SDL takes ownership of rwops
if(ovr_surf.null()) {
return;
@ -537,7 +537,7 @@ static surface load_image_file(const image::locator& loc)
if(!loc_location.empty()) {
location = loc_location;
}
filesystem::rwops_ptr rwops = filesystem::load_RWops(location);
filesystem::rwops_ptr rwops = filesystem::make_read_RWops(location);
res = IMG_Load_RW(rwops.release(), 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()) {
@ -1217,9 +1217,8 @@ bool save_image(const surface& surf, const std::string& filename)
LOG_DP << "Writing a png image to " << filename << std::endl;
surface tmp = SDL_PNGFormatAlpha(surf.get());
// SDL_SavePNG_RW(tmp, filesystem::load_RWops(filename).release(), 1); //1 means to close the file (RWops) when we finish
//^ This doesn't work, load_RWops is only for reading not writing
return SDL_SavePNG(tmp, filename.c_str()) == 0;
const int err = SDL_SavePNG_RW(tmp, filesystem::make_write_RWops(filename).release(), 1); //1 means SDL takes ownership of the RWops
return err == 0;
}
#endif

View file

@ -601,7 +601,7 @@ static void play_new_music()
if(itor == music_cache.end()) {
LOG_AUDIO << "attempting to insert track '" << filename << "' into cache\n";
filesystem::rwops_ptr rwops = filesystem::load_RWops(filename);
filesystem::rwops_ptr rwops = filesystem::make_read_RWops(filename);
// SDL takes ownership of rwops
const std::shared_ptr<Mix_Music> music(Mix_LoadMUSType_RW(rwops.release(), MUS_NONE, true), &Mix_FreeMusic);
@ -882,7 +882,7 @@ static Mix_Chunk* load_chunk(const std::string& file, channel_group group)
const std::string& filename = filesystem::get_binary_file_location("sounds", file);
if(!filename.empty()) {
filesystem::rwops_ptr rwops = filesystem::load_RWops(filename);
filesystem::rwops_ptr rwops = filesystem::make_read_RWops(filename);
temp_chunk.set_data(Mix_LoadWAV_RW(rwops.release(), true)); // SDL takes ownership of rwops
} else {
ERR_AUDIO << "Could not load sound file '" << file << "'." << std::endl;