mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-14 18:49:07 +00:00
Make the game compile with SDL2.
This does the bare minimum to get the game compiling and running again with SDL 2. It fixes all of the compile errors, adds a missing seek operation to the SDL_RWops. The missing seek operation caused a NULL pointer dereference during game start.
This commit is contained in:
parent
ae2abf65e9
commit
aae2ad77e6
@ -43,6 +43,7 @@ Version 1.13.1+dev:
|
|||||||
Windows now display console output directly instead of using stdout.txt
|
Windows now display console output directly instead of using stdout.txt
|
||||||
and stderr.txt.
|
and stderr.txt.
|
||||||
* Remember last selected modifications separately for single and multiplayer.
|
* Remember last selected modifications separately for single and multiplayer.
|
||||||
|
* Fixed SDL2 compilation issues.
|
||||||
|
|
||||||
Version 1.13.1:
|
Version 1.13.1:
|
||||||
* Security fixes:
|
* Security fixes:
|
||||||
|
@ -984,6 +984,9 @@
|
|||||||
[entry]
|
[entry]
|
||||||
name = "Andrea Palmatè (afxgroup)"
|
name = "Andrea Palmatè (afxgroup)"
|
||||||
[/entry]
|
[/entry]
|
||||||
|
[entry]
|
||||||
|
name = "Andreas Löf (Aginor)"
|
||||||
|
[/entry]
|
||||||
[entry]
|
[entry]
|
||||||
name = "Andrius Šilinskas (thunderstruck)"
|
name = "Andrius Šilinskas (thunderstruck)"
|
||||||
[/entry]
|
[/entry]
|
||||||
|
@ -504,17 +504,31 @@ void battle_prediction_pane::get_hp_distrib_surface(const std::vector<std::pair<
|
|||||||
|
|
||||||
int bar_len = std::max<int>(static_cast<int>((prob * (bar_space - 4)) + 0.5), 2);
|
int bar_len = std::max<int>(static_cast<int>((prob * (bar_space - 4)) + 0.5), 2);
|
||||||
|
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
SDL_Rect bar_rect_1 = sdl::create_rect(hp_sep + 4, 6 + (fs + 2) * i, bar_len, 8);
|
SDL_Rect bar_rect_1 = sdl::create_rect(hp_sep + 4, 6 + (fs + 2) * i, bar_len, 8);
|
||||||
sdl::fill_rect(surf, &bar_rect_1, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 100));
|
sdl::fill_rect(surf, &bar_rect_1, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.a, 100));
|
||||||
|
|
||||||
SDL_Rect bar_rect_2 = sdl::create_rect(hp_sep + 4, 7 + (fs + 2) * i, bar_len, 6);
|
SDL_Rect bar_rect_2 = sdl::create_rect(hp_sep + 4, 7 + (fs + 2) * i, bar_len, 6);
|
||||||
sdl::fill_rect(surf, &bar_rect_2, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 66));
|
sdl::fill_rect(surf, &bar_rect_2, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.a, 66));
|
||||||
|
|
||||||
SDL_Rect bar_rect_3 = sdl::create_rect(hp_sep + 4, 8 + (fs + 2) * i, bar_len, 4);
|
SDL_Rect bar_rect_3 = sdl::create_rect(hp_sep + 4, 8 + (fs + 2) * i, bar_len, 4);
|
||||||
sdl::fill_rect(surf, &bar_rect_3, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 33));
|
sdl::fill_rect(surf, &bar_rect_3, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.a, 33));
|
||||||
|
|
||||||
SDL_Rect bar_rect_4 = sdl::create_rect(hp_sep + 4, 9 + (fs + 2) * i, bar_len, 2);
|
SDL_Rect bar_rect_4 = sdl::create_rect(hp_sep + 4, 9 + (fs + 2) * i, bar_len, 2);
|
||||||
sdl::fill_rect(surf, &bar_rect_4, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 0));
|
sdl::fill_rect(surf, &bar_rect_4, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.a, 0));
|
||||||
|
#else
|
||||||
|
SDL_Rect bar_rect_1 = sdl::create_rect(hp_sep + 4, 6 + (fs + 2) * i, bar_len, 8);
|
||||||
|
sdl::fill_rect(surf, &bar_rect_1, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 100));
|
||||||
|
|
||||||
|
SDL_Rect bar_rect_2 = sdl::create_rect(hp_sep + 4, 7 + (fs + 2) * i, bar_len, 6);
|
||||||
|
sdl::fill_rect(surf, &bar_rect_2, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 66));
|
||||||
|
|
||||||
|
SDL_Rect bar_rect_3 = sdl::create_rect(hp_sep + 4, 8 + (fs + 2) * i, bar_len, 4);
|
||||||
|
sdl::fill_rect(surf, &bar_rect_3, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 33));
|
||||||
|
|
||||||
|
SDL_Rect bar_rect_4 = sdl::create_rect(hp_sep + 4, 9 + (fs + 2) * i, bar_len, 2);
|
||||||
|
sdl::fill_rect(surf, &bar_rect_4, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 0));
|
||||||
|
#endif
|
||||||
|
|
||||||
// Draw probability percentage, aligned right.
|
// Draw probability percentage, aligned right.
|
||||||
format_prob(str_buf, prob);
|
format_prob(str_buf, prob);
|
||||||
|
@ -73,6 +73,7 @@ version_table_manager::version_table_manager()
|
|||||||
SDL_version sdl_version;
|
SDL_version sdl_version;
|
||||||
const SDL_version* sdl_rt_version = NULL;
|
const SDL_version* sdl_rt_version = NULL;
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// SDL
|
// SDL
|
||||||
//
|
//
|
||||||
@ -80,10 +81,15 @@ version_table_manager::version_table_manager()
|
|||||||
SDL_VERSION(&sdl_version);
|
SDL_VERSION(&sdl_version);
|
||||||
compiled[LIB_SDL] = format_version(sdl_version);
|
compiled[LIB_SDL] = format_version(sdl_version);
|
||||||
|
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
|
SDL_GetVersion(&sdl_version);
|
||||||
|
linked[LIB_SDL] = format_version(sdl_version);
|
||||||
|
#else
|
||||||
sdl_rt_version = SDL_Linked_Version();
|
sdl_rt_version = SDL_Linked_Version();
|
||||||
if(sdl_rt_version) {
|
if(sdl_rt_version) {
|
||||||
linked[LIB_SDL] = format_version(*sdl_rt_version);
|
linked[LIB_SDL] = format_version(*sdl_rt_version);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
names[LIB_SDL] = "SDL";
|
names[LIB_SDL] = "SDL";
|
||||||
|
|
||||||
|
@ -59,6 +59,11 @@ void handle_system_event(const SDL_Event& /*event*/)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool available()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
} // end namespace clipboard
|
} // end namespace clipboard
|
||||||
|
|
||||||
} // end namespace desktop
|
} // end namespace desktop
|
||||||
|
@ -201,15 +201,25 @@ const file_tree_checksum& data_tree_checksum(bool reset)
|
|||||||
return checksum;
|
return checksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
|
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);
|
||||||
|
#else
|
||||||
static int SDLCALL ifs_seek(struct SDL_RWops *context, int offset, int whence);
|
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_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_write(struct SDL_RWops *context, const void *ptr, int size, int num);
|
||||||
static int SDLCALL ifs_close(struct SDL_RWops *context);
|
static int SDLCALL ifs_close(struct SDL_RWops *context);
|
||||||
|
#endif
|
||||||
|
|
||||||
SDL_RWops* load_RWops(const std::string &path) {
|
SDL_RWops* load_RWops(const std::string &path) {
|
||||||
SDL_RWops *rw = SDL_AllocRW();
|
SDL_RWops *rw = SDL_AllocRW();
|
||||||
|
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
|
rw->size = &ifs_size;
|
||||||
|
#endif
|
||||||
rw->seek = &ifs_seek;
|
rw->seek = &ifs_seek;
|
||||||
rw->read = &ifs_read;
|
rw->read = &ifs_read;
|
||||||
rw->write = &ifs_write;
|
rw->write = &ifs_write;
|
||||||
@ -228,7 +238,29 @@ SDL_RWops* load_RWops(const std::string &path) {
|
|||||||
return rw;
|
return rw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
|
static Sint64 ifs_size (struct SDL_RWops * context) {
|
||||||
|
std::istream *ifs = static_cast<std::istream*>(context->hidden.unknown.data1);
|
||||||
|
std::streampos orig = ifs->tellg();
|
||||||
|
|
||||||
|
ifs->seekg(0, std::ios::end);
|
||||||
|
|
||||||
|
std::streampos len = ifs->tellg();
|
||||||
|
|
||||||
|
ifs->seekg(orig);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
|
static Sint64 SDLCALL ifs_seek(struct SDL_RWops *context, Sint64 offset, int whence) {
|
||||||
|
#else
|
||||||
static int SDLCALL ifs_seek(struct SDL_RWops *context, int offset, int whence) {
|
static int SDLCALL ifs_seek(struct SDL_RWops *context, int offset, int whence) {
|
||||||
|
#endif
|
||||||
|
|
||||||
std::ios_base::seekdir seekdir;
|
std::ios_base::seekdir seekdir;
|
||||||
switch(whence){
|
switch(whence){
|
||||||
case RW_SEEK_SET:
|
case RW_SEEK_SET:
|
||||||
@ -261,7 +293,12 @@ static int SDLCALL ifs_seek(struct SDL_RWops *context, int offset, int whence) {
|
|||||||
std::streamsize pos = ifs->tellg();
|
std::streamsize pos = ifs->tellg();
|
||||||
return static_cast<int>(pos);
|
return static_cast<int>(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
|
static size_t SDLCALL ifs_read(struct SDL_RWops *context, void *ptr, size_t size, size_t maxnum) {
|
||||||
|
#else
|
||||||
static int SDLCALL ifs_read(struct SDL_RWops *context, void *ptr, int size, int maxnum) {
|
static int SDLCALL ifs_read(struct SDL_RWops *context, void *ptr, int size, int maxnum) {
|
||||||
|
#endif
|
||||||
std::istream *ifs = static_cast<std::istream*>(context->hidden.unknown.data1);
|
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
|
// This seems overly simplistic, but it's the same as mem_read's implementation
|
||||||
@ -274,7 +311,12 @@ static int SDLCALL ifs_read(struct SDL_RWops *context, void *ptr, int size, int
|
|||||||
|
|
||||||
return static_cast<int>(num);
|
return static_cast<int>(num);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
|
static size_t SDLCALL ifs_write(struct SDL_RWops * /*context*/, const void * /*ptr*/, size_t /*size*/, size_t /*num*/) {
|
||||||
|
#else
|
||||||
static int SDLCALL ifs_write(struct SDL_RWops * /*context*/, const void * /*ptr*/, int /*size*/, int /*num*/) {
|
static int SDLCALL ifs_write(struct SDL_RWops * /*context*/, const void * /*ptr*/, int /*size*/, int /*num*/) {
|
||||||
|
#endif
|
||||||
SDL_SetError("Writing not implemented");
|
SDL_SetError("Writing not implemented");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,10 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
|
#include "sdl/alpha.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
static lg::log_domain log_font("font");
|
static lg::log_domain log_font("font");
|
||||||
#define DBG_FT LOG_STREAM(debug, log_font)
|
#define DBG_FT LOG_STREAM(debug, log_font)
|
||||||
#define LOG_FT LOG_STREAM(info, log_font)
|
#define LOG_FT LOG_STREAM(info, log_font)
|
||||||
|
@ -205,7 +205,13 @@ void loadscreen::draw_screen(const std::string &text)
|
|||||||
// Pump events and make sure to redraw the logo if there's a chance that it's been obscured
|
// Pump events and make sure to redraw the logo if there's a chance that it's been obscured
|
||||||
SDL_Event ev;
|
SDL_Event ev;
|
||||||
while(SDL_PollEvent(&ev)) {
|
while(SDL_PollEvent(&ev)) {
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
|
if (ev.type == SDL_WINDOWEVENT &&
|
||||||
|
(ev.window.type == SDL_WINDOWEVENT_RESIZED ||
|
||||||
|
ev.window.type == SDL_WINDOWEVENT_EXPOSED))
|
||||||
|
#else
|
||||||
if(ev.type == SDL_VIDEORESIZE || ev.type == SDL_VIDEOEXPOSE)
|
if(ev.type == SDL_VIDEORESIZE || ev.type == SDL_VIDEOEXPOSE)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
logo_drawn_ = false;
|
logo_drawn_ = false;
|
||||||
}
|
}
|
||||||
|
@ -99,6 +99,7 @@ void twindow::set_icon(const surface& icon)
|
|||||||
SDL_SetWindowIcon(window_, icon);
|
SDL_SetWindowIcon(window_, icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if TTEXTURE
|
||||||
ttexture twindow::create_texture(const int access, const int w, const int h)
|
ttexture twindow::create_texture(const int access, const int w, const int h)
|
||||||
{
|
{
|
||||||
return ttexture(*SDL_GetRenderer(window_), pixel_format_, access, w, h);
|
return ttexture(*SDL_GetRenderer(window_), pixel_format_, access, w, h);
|
||||||
@ -119,6 +120,7 @@ void twindow::draw(ttexture& texture, const int x, const int y)
|
|||||||
{
|
{
|
||||||
texture.draw(*SDL_GetRenderer(window_), x, y);
|
texture.draw(*SDL_GetRenderer(window_), x, y);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
twindow::operator SDL_Window*()
|
twindow::operator SDL_Window*()
|
||||||
{
|
{
|
||||||
|
@ -38,7 +38,9 @@ struct SDL_Renderer;
|
|||||||
namespace sdl
|
namespace sdl
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#if TTEXTURE
|
||||||
class ttexture;
|
class ttexture;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The wrapper class for the @ref SDL_Window class.
|
* The wrapper class for the @ref SDL_Window class.
|
||||||
@ -131,6 +133,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
void set_icon(const surface& icon);
|
void set_icon(const surface& icon);
|
||||||
|
|
||||||
|
#if TTEXTURE
|
||||||
/**
|
/**
|
||||||
* Creates a texture for the renderer of this object.
|
* Creates a texture for the renderer of this object.
|
||||||
*
|
*
|
||||||
@ -179,7 +182,7 @@ public:
|
|||||||
* @param y Forwarded to @ref ttexture::draw.
|
* @param y Forwarded to @ref ttexture::draw.
|
||||||
*/
|
*/
|
||||||
void draw(ttexture& texture, const int x, const int y);
|
void draw(ttexture& texture, const int x, const int y);
|
||||||
|
#endif
|
||||||
|
|
||||||
/***** ***** ***** Conversion operators. ***** ***** *****/
|
/***** ***** ***** Conversion operators. ***** ***** *****/
|
||||||
|
|
||||||
|
@ -315,6 +315,12 @@ void part_ui::prepare_floating_images()
|
|||||||
void part_ui::render_background()
|
void part_ui::render_background()
|
||||||
{
|
{
|
||||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
|
sdl::draw_solid_tinted_rectangle(
|
||||||
|
0, 0, video_.getx(), video_.gety(), 0, 0, 0, 1.0,
|
||||||
|
video_.getSurface()
|
||||||
|
);
|
||||||
|
sdl_blit(background_, NULL, video_.getSurface(), NULL);
|
||||||
|
#if 0
|
||||||
sdl::twindow *wnd = CVideo::get_window();
|
sdl::twindow *wnd = CVideo::get_window();
|
||||||
wnd->fill(0, 0, 0);
|
wnd->fill(0, 0, 0);
|
||||||
for (size_t i = 0; i<background_images_.size(); i++) {
|
for (size_t i = 0; i<background_images_.size(); i++) {
|
||||||
@ -323,6 +329,7 @@ void part_ui::render_background()
|
|||||||
|
|
||||||
wnd->draw(background_images_[i], x, y);
|
wnd->draw(background_images_[i], x, y);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#ifdef SDL_GPU
|
#ifdef SDL_GPU
|
||||||
GPU_Target *target = get_render_target();
|
GPU_Target *target = get_render_target();
|
||||||
|
@ -258,13 +258,8 @@ private:
|
|||||||
/** The surface to render upon used as a cache. */
|
/** The surface to render upon used as a cache. */
|
||||||
mutable surface surface_;
|
mutable surface surface_;
|
||||||
|
|
||||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
|
||||||
/** The texture to render upon used as a cache. */
|
|
||||||
mutable sdl::ttexture texture_;
|
|
||||||
#else
|
|
||||||
#ifdef SDL_GPU
|
#ifdef SDL_GPU
|
||||||
mutable sdl::timage texture_;
|
mutable sdl::timage texture_;
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** The text to draw (stored as UTF-8). */
|
/** The text to draw (stored as UTF-8). */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user