gosu 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/dependencies/SDL/include/SDL.h +108 -14
- data/dependencies/SDL/include/SDL_assert.h +81 -50
- data/dependencies/SDL/include/SDL_atomic.h +135 -35
- data/dependencies/SDL/include/SDL_audio.h +960 -355
- data/dependencies/SDL/include/SDL_bits.h +11 -6
- data/dependencies/SDL/include/SDL_blendmode.h +91 -14
- data/dependencies/SDL/include/SDL_clipboard.h +30 -7
- data/dependencies/SDL/include/SDL_config.h +277 -27
- data/dependencies/SDL/include/SDL_config_android.h +13 -38
- data/dependencies/SDL/include/SDL_config_iphoneos.h +21 -62
- data/dependencies/SDL/include/SDL_config_macosx.h +23 -92
- data/dependencies/SDL/include/SDL_config_minimal.h +1 -4
- data/dependencies/SDL/include/SDL_config_pandora.h +15 -22
- data/dependencies/SDL/include/SDL_config_psp.h +16 -37
- data/dependencies/SDL/include/SDL_config_windows.h +28 -91
- data/dependencies/SDL/include/SDL_config_winrt.h +33 -61
- data/dependencies/SDL/include/SDL_config_wiz.h +28 -56
- data/dependencies/SDL/include/SDL_copying.h +1 -1
- data/dependencies/SDL/include/SDL_cpuinfo.h +331 -71
- data/dependencies/SDL/include/SDL_egl.h +906 -280
- data/dependencies/SDL/include/SDL_endian.h +101 -47
- data/dependencies/SDL/include/SDL_error.h +70 -19
- data/dependencies/SDL/include/SDL_events.h +387 -79
- data/dependencies/SDL/include/SDL_filesystem.h +73 -64
- data/dependencies/SDL/include/SDL_gamecontroller.h +585 -125
- data/dependencies/SDL/include/SDL_gesture.h +36 -6
- data/dependencies/SDL/include/SDL_haptic.h +304 -210
- data/dependencies/SDL/include/SDL_hidapi.h +451 -0
- data/dependencies/SDL/include/SDL_hints.h +1286 -897
- data/dependencies/SDL/include/SDL_joystick.h +577 -130
- data/dependencies/SDL/include/SDL_keyboard.h +162 -63
- data/dependencies/SDL/include/SDL_keycode.h +7 -5
- data/dependencies/SDL/include/SDL_loadso.h +42 -8
- data/dependencies/SDL/include/SDL_locale.h +34 -32
- data/dependencies/SDL/include/SDL_log.h +212 -19
- data/dependencies/SDL/include/SDL_main.h +72 -17
- data/dependencies/SDL/include/SDL_messagebox.h +70 -23
- data/dependencies/SDL/include/SDL_metal.h +27 -32
- data/dependencies/SDL/include/SDL_misc.h +19 -15
- data/dependencies/SDL/include/SDL_mouse.h +262 -110
- data/dependencies/SDL/include/SDL_mutex.h +286 -66
- data/dependencies/SDL/include/SDL_name.h +1 -1
- data/dependencies/SDL/include/SDL_opengl.h +1 -1
- data/dependencies/SDL/include/SDL_opengles.h +1 -1
- data/dependencies/SDL/include/SDL_opengles2.h +2 -2
- data/dependencies/SDL/include/SDL_pixels.h +199 -34
- data/dependencies/SDL/include/SDL_platform.h +39 -2
- data/dependencies/SDL/include/SDL_power.h +23 -10
- data/dependencies/SDL/include/SDL_quit.h +1 -1
- data/dependencies/SDL/include/SDL_rect.h +78 -28
- data/dependencies/SDL/include/SDL_render.h +1204 -472
- data/dependencies/SDL/include/SDL_revision.h +2 -2
- data/dependencies/SDL/include/SDL_rwops.h +605 -33
- data/dependencies/SDL/include/SDL_scancode.h +1 -1
- data/dependencies/SDL/include/SDL_sensor.h +76 -42
- data/dependencies/SDL/include/SDL_shape.h +38 -27
- data/dependencies/SDL/include/SDL_stdinc.h +96 -24
- data/dependencies/SDL/include/SDL_surface.h +571 -139
- data/dependencies/SDL/include/SDL_system.h +339 -101
- data/dependencies/SDL/include/SDL_syswm.h +50 -20
- data/dependencies/SDL/include/SDL_test.h +1 -1
- data/dependencies/SDL/include/SDL_test_assert.h +2 -2
- data/dependencies/SDL/include/SDL_test_common.h +23 -6
- data/dependencies/SDL/include/SDL_test_compare.h +1 -1
- data/dependencies/SDL/include/SDL_test_crc32.h +1 -1
- data/dependencies/SDL/include/SDL_test_font.h +3 -3
- data/dependencies/SDL/include/SDL_test_fuzzer.h +28 -26
- data/dependencies/SDL/include/SDL_test_harness.h +6 -6
- data/dependencies/SDL/include/SDL_test_images.h +1 -1
- data/dependencies/SDL/include/SDL_test_log.h +1 -1
- data/dependencies/SDL/include/SDL_test_md5.h +1 -1
- data/dependencies/SDL/include/SDL_test_memory.h +1 -1
- data/dependencies/SDL/include/SDL_test_random.h +2 -2
- data/dependencies/SDL/include/SDL_thread.h +226 -128
- data/dependencies/SDL/include/SDL_timer.h +129 -22
- data/dependencies/SDL/include/SDL_touch.h +48 -8
- data/dependencies/SDL/include/SDL_types.h +1 -1
- data/dependencies/SDL/include/SDL_version.h +72 -46
- data/dependencies/SDL/include/SDL_video.h +1266 -460
- data/dependencies/SDL/include/SDL_vulkan.h +100 -161
- data/dependencies/SDL/include/begin_code.h +22 -1
- data/dependencies/SDL/include/close_code.h +1 -1
- data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
- data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
- data/dependencies/SDL_sound/SDL_sound.c +83 -7
- data/dependencies/SDL_sound/SDL_sound.h +4 -4
- data/dependencies/SDL_sound/SDL_sound_aiff.c +9 -12
- data/dependencies/SDL_sound/SDL_sound_au.c +7 -7
- data/dependencies/SDL_sound/SDL_sound_coreaudio.c +3 -3
- data/dependencies/SDL_sound/SDL_sound_flac.c +1 -1
- data/dependencies/SDL_sound/SDL_sound_internal.h +17 -10
- data/dependencies/SDL_sound/SDL_sound_modplug.c +25 -27
- data/dependencies/SDL_sound/SDL_sound_mp3.c +5 -17
- data/dependencies/SDL_sound/SDL_sound_raw.c +11 -11
- data/dependencies/SDL_sound/SDL_sound_shn.c +8 -7
- data/dependencies/SDL_sound/SDL_sound_voc.c +6 -4
- data/dependencies/SDL_sound/SDL_sound_vorbis.c +6 -11
- data/dependencies/SDL_sound/SDL_sound_wav.c +35 -29
- data/dependencies/SDL_sound/dr_flac.h +618 -220
- data/dependencies/SDL_sound/dr_mp3.h +263 -94
- data/dependencies/SDL_sound/libmodplug/fastmix.c +58 -64
- data/dependencies/SDL_sound/libmodplug/libmodplug.h +25 -103
- data/dependencies/SDL_sound/libmodplug/load_669.c +14 -17
- data/dependencies/SDL_sound/libmodplug/load_amf.c +11 -7
- data/dependencies/SDL_sound/libmodplug/load_ams.c +65 -22
- data/dependencies/SDL_sound/libmodplug/load_dbm.c +8 -4
- data/dependencies/SDL_sound/libmodplug/load_dmf.c +55 -25
- data/dependencies/SDL_sound/libmodplug/load_far.c +9 -13
- data/dependencies/SDL_sound/libmodplug/load_gdm.c +448 -0
- data/dependencies/SDL_sound/libmodplug/load_it.c +45 -49
- data/dependencies/SDL_sound/libmodplug/load_mdl.c +80 -53
- data/dependencies/SDL_sound/libmodplug/load_med.c +20 -12
- data/dependencies/SDL_sound/libmodplug/load_mod.c +40 -15
- data/dependencies/SDL_sound/libmodplug/load_mt2.c +29 -17
- data/dependencies/SDL_sound/libmodplug/load_okt.c +12 -8
- data/dependencies/SDL_sound/libmodplug/load_psm.c +101 -78
- data/dependencies/SDL_sound/libmodplug/load_ptm.c +18 -17
- data/dependencies/SDL_sound/libmodplug/load_s3m.c +9 -7
- data/dependencies/SDL_sound/libmodplug/load_stm.c +3 -2
- data/dependencies/SDL_sound/libmodplug/load_ult.c +2 -2
- data/dependencies/SDL_sound/libmodplug/load_umx.c +315 -35
- data/dependencies/SDL_sound/libmodplug/load_xm.c +25 -21
- data/dependencies/SDL_sound/libmodplug/mmcmp.c +295 -149
- data/dependencies/SDL_sound/libmodplug/modplug.c +7 -123
- data/dependencies/SDL_sound/libmodplug/modplug.h +32 -29
- data/dependencies/SDL_sound/libmodplug/snd_dsp.c +0 -1
- data/dependencies/SDL_sound/libmodplug/snd_flt.c +2 -2
- data/dependencies/SDL_sound/libmodplug/snd_fx.c +24 -18
- data/dependencies/SDL_sound/libmodplug/sndfile.c +55 -156
- data/dependencies/SDL_sound/libmodplug/sndmix.c +7 -12
- data/dependencies/SDL_sound/libmodplug/tables.h +10 -15
- data/dependencies/SDL_sound/stb_vorbis.h +508 -325
- data/dependencies/{al_soft → mojoAL}/AL/al.h +38 -30
- data/dependencies/{al_soft → mojoAL}/AL/alc.h +27 -56
- data/dependencies/mojoAL/mojoal.c +4594 -0
- data/ext/gosu/extconf.rb +29 -30
- data/include/Gosu/Audio.hpp +70 -85
- data/include/Gosu/Color.hpp +19 -11
- data/include/Gosu/Font.hpp +40 -44
- data/include/Gosu/Graphics.hpp +58 -71
- data/include/Gosu/GraphicsBase.hpp +26 -33
- data/include/Gosu/Image.hpp +56 -62
- data/include/Gosu/ImageData.hpp +23 -27
- data/include/Gosu/Inspection.hpp +1 -4
- data/include/Gosu/TextInput.hpp +34 -40
- data/include/Gosu/Version.hpp +1 -1
- data/include/Gosu/Window.hpp +71 -70
- data/lib/SDL2.dll +0 -0
- data/lib/gosu/compat.rb +24 -37
- data/lib/gosu.rb +2 -2
- data/lib64/SDL2.dll +0 -0
- data/src/Audio.cpp +86 -86
- data/src/AudioFile.hpp +6 -6
- data/src/AudioFileAudioToolbox.cpp +1 -1
- data/src/AudioFileSDLSound.cpp +1 -1
- data/src/AudioImpl.hpp +5 -5
- data/src/BitmapIO.cpp +0 -20
- data/src/BlockAllocator.cpp +2 -1
- data/src/Channel.cpp +22 -20
- data/src/Color.cpp +12 -9
- data/src/EmptyImageData.hpp +15 -17
- data/src/FileUnix.cpp +1 -1
- data/src/FileWin.cpp +1 -1
- data/src/Font.cpp +48 -53
- data/src/Graphics.cpp +135 -143
- data/src/Image.cpp +41 -42
- data/src/Input.cpp +1 -1
- data/src/InputUIKit.cpp +1 -1
- data/src/LargeImageData.cpp +108 -101
- data/src/LargeImageData.hpp +17 -15
- data/src/Log.hpp +6 -6
- data/src/Macro.cpp +35 -37
- data/src/Macro.hpp +11 -11
- data/src/Math.cpp +8 -1
- data/src/Resolution.cpp +12 -7
- data/src/RubyGosu.cxx +5 -5
- data/src/TexChunk.cpp +50 -41
- data/src/TexChunk.hpp +22 -22
- data/src/Text.cpp +37 -37
- data/src/TextBuilder.cpp +60 -57
- data/src/TextBuilder.hpp +20 -20
- data/src/TextInput.cpp +127 -135
- data/src/TrueTypeFont.cpp +107 -107
- data/src/TrueTypeFont.hpp +39 -38
- data/src/TrueTypeFontApple.cpp +19 -22
- data/src/TrueTypeFontUnix.cpp +21 -26
- data/src/TrueTypeFontWin.cpp +30 -30
- data/src/Window.cpp +95 -86
- data/src/WindowUIKit.cpp +46 -49
- metadata +7 -17
- data/dependencies/SDL/include/SDL_config_os2.h +0 -188
- data/dependencies/SDL_sound/libmodplug/load_abc.c +0 -4725
- data/dependencies/SDL_sound/libmodplug/load_mid.c +0 -1405
- data/dependencies/SDL_sound/libmodplug/load_pat.c +0 -1143
- data/dependencies/SDL_sound/libmodplug/load_pat.h +0 -25
- data/dependencies/al_soft/AL/alext.h +0 -585
- data/dependencies/al_soft/AL/efx-creative.h +0 -3
- data/dependencies/al_soft/AL/efx-presets.h +0 -402
- data/dependencies/al_soft/AL/efx.h +0 -762
- data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
- data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
- data/lib/OpenAL32.dll +0 -0
- data/lib64/OpenAL32.dll +0 -0
data/src/Image.cpp
CHANGED
@@ -1,81 +1,80 @@
|
|
1
|
-
#include <Gosu/Image.hpp>
|
2
1
|
#include <Gosu/Bitmap.hpp>
|
3
2
|
#include <Gosu/Graphics.hpp>
|
4
3
|
#include <Gosu/IO.hpp>
|
4
|
+
#include <Gosu/Image.hpp>
|
5
5
|
#include <Gosu/ImageData.hpp>
|
6
6
|
#include <Gosu/Math.hpp>
|
7
|
-
#include <stdexcept>
|
8
7
|
#include "EmptyImageData.hpp"
|
9
|
-
|
8
|
+
#include <stdexcept>
|
10
9
|
|
11
10
|
Gosu::Image::Image()
|
12
|
-
:
|
11
|
+
: m_data(EmptyImageData::instance_ptr())
|
13
12
|
{
|
14
13
|
}
|
15
14
|
|
16
|
-
Gosu::Image::Image(const string& filename, unsigned image_flags)
|
15
|
+
Gosu::Image::Image(const std::string& filename, unsigned image_flags)
|
17
16
|
{
|
18
17
|
// Forward.
|
19
18
|
Bitmap bitmap = load_image_file(filename);
|
20
|
-
Image{bitmap, image_flags}.
|
19
|
+
Image{bitmap, image_flags}.m_data.swap(m_data);
|
21
20
|
}
|
22
21
|
|
23
|
-
Gosu::Image::Image(const string& filename, int src_x, int src_y, int src_width, int src_height,
|
22
|
+
Gosu::Image::Image(const std::string& filename, int src_x, int src_y, int src_width, int src_height,
|
24
23
|
unsigned image_flags)
|
25
24
|
{
|
26
25
|
// Forward.
|
27
26
|
Bitmap bitmap = load_image_file(filename);
|
28
|
-
Image{bitmap, src_x, src_y, src_width, src_height, image_flags}.
|
27
|
+
Image{bitmap, src_x, src_y, src_width, src_height, image_flags}.m_data.swap(m_data);
|
29
28
|
}
|
30
29
|
|
31
30
|
Gosu::Image::Image(const Bitmap& source, unsigned image_flags)
|
32
31
|
{
|
33
32
|
// Forward.
|
34
|
-
Image{source, 0, 0, source.width(), source.height(), image_flags}.
|
33
|
+
Image{source, 0, 0, source.width(), source.height(), image_flags}.m_data.swap(m_data);
|
35
34
|
}
|
36
35
|
|
37
36
|
Gosu::Image::Image(const Bitmap& source, int src_x, int src_y, int src_width, int src_height,
|
38
37
|
unsigned image_flags)
|
39
|
-
:
|
38
|
+
: m_data(Graphics::create_image(source, src_x, src_y, src_width, src_height, image_flags))
|
40
39
|
{
|
41
40
|
}
|
42
41
|
|
43
|
-
Gosu::Image::Image(unique_ptr<ImageData>&& data)
|
44
|
-
:
|
42
|
+
Gosu::Image::Image(std::unique_ptr<ImageData>&& data)
|
43
|
+
: m_data(data.release())
|
45
44
|
{
|
46
|
-
if (!
|
45
|
+
if (!m_data) throw std::invalid_argument("Gosu::Image cannot be initialized with nullptr");
|
47
46
|
}
|
48
47
|
|
49
48
|
unsigned Gosu::Image::width() const
|
50
49
|
{
|
51
|
-
return
|
50
|
+
return m_data->width();
|
52
51
|
}
|
53
52
|
|
54
53
|
unsigned Gosu::Image::height() const
|
55
54
|
{
|
56
|
-
return
|
55
|
+
return m_data->height();
|
57
56
|
}
|
58
57
|
|
59
58
|
void Gosu::Image::draw(double x, double y, ZPos z, double scale_x, double scale_y, Color c,
|
60
|
-
|
59
|
+
BlendMode mode) const
|
61
60
|
{
|
62
61
|
double x2 = x + width() * scale_x;
|
63
62
|
double y2 = y + height() * scale_y;
|
64
63
|
|
65
|
-
|
64
|
+
m_data->draw(x, y, c, x2, y, c, x, y2, c, x2, y2, c, z, mode);
|
66
65
|
}
|
67
66
|
|
68
67
|
void Gosu::Image::draw_mod(double x, double y, ZPos z, double scale_x, double scale_y, Color c1,
|
69
|
-
|
68
|
+
Color c2, Color c3, Color c4, BlendMode mode) const
|
70
69
|
{
|
71
70
|
double x2 = x + width() * scale_x;
|
72
71
|
double y2 = y + height() * scale_y;
|
73
72
|
|
74
|
-
|
73
|
+
m_data->draw(x, y, c1, x2, y, c2, x, y2, c3, x2, y2, c4, z, mode);
|
75
74
|
}
|
76
75
|
|
77
|
-
void Gosu::Image::draw_rot(double x, double y, ZPos z, double angle,
|
78
|
-
|
76
|
+
void Gosu::Image::draw_rot(double x, double y, ZPos z, double angle, double center_x,
|
77
|
+
double center_y, double scale_x, double scale_y, Color c,
|
79
78
|
BlendMode mode) const
|
80
79
|
{
|
81
80
|
double size_x = width() * scale_x;
|
@@ -84,33 +83,33 @@ void Gosu::Image::draw_rot(double x, double y, ZPos z, double angle,
|
|
84
83
|
double offs_y = offset_y(angle, 1);
|
85
84
|
|
86
85
|
// Offset to the centers of the original Image's edges after rotation.
|
87
|
-
double dist_to_left_x
|
88
|
-
double dist_to_left_y
|
89
|
-
double dist_to_right_x
|
90
|
-
double dist_to_right_y
|
91
|
-
double dist_to_top_x
|
92
|
-
double dist_to_top_y
|
86
|
+
double dist_to_left_x = +offs_y * size_x * center_x;
|
87
|
+
double dist_to_left_y = -offs_x * size_x * center_x;
|
88
|
+
double dist_to_right_x = -offs_y * size_x * (1 - center_x);
|
89
|
+
double dist_to_right_y = +offs_x * size_x * (1 - center_x);
|
90
|
+
double dist_to_top_x = +offs_x * size_y * center_y;
|
91
|
+
double dist_to_top_y = +offs_y * size_y * center_y;
|
93
92
|
double dist_to_bottom_x = -offs_x * size_y * (1 - center_y);
|
94
93
|
double dist_to_bottom_y = -offs_y * size_y * (1 - center_y);
|
95
94
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
95
|
+
m_data->draw(x + dist_to_left_x + dist_to_top_x, y + dist_to_left_y + dist_to_top_y, c,
|
96
|
+
x + dist_to_right_x + dist_to_top_x, y + dist_to_right_y + dist_to_top_y, c,
|
97
|
+
x + dist_to_left_x + dist_to_bottom_x, y + dist_to_left_y + dist_to_bottom_y, c,
|
98
|
+
x + dist_to_right_x + dist_to_bottom_x, y + dist_to_right_y + dist_to_bottom_y, c,
|
99
|
+
z, mode);
|
101
100
|
}
|
102
101
|
|
103
102
|
Gosu::ImageData& Gosu::Image::data() const
|
104
103
|
{
|
105
|
-
return *
|
104
|
+
return *m_data;
|
106
105
|
}
|
107
106
|
|
108
|
-
vector<Gosu::Image> Gosu::load_tiles(const Bitmap& bmp, int tile_width, int tile_height,
|
109
|
-
|
107
|
+
std::vector<Gosu::Image> Gosu::load_tiles(const Bitmap& bmp, int tile_width, int tile_height,
|
108
|
+
unsigned flags)
|
110
109
|
{
|
111
110
|
int tiles_x, tiles_y;
|
112
|
-
vector<Image> images;
|
113
|
-
|
111
|
+
std::vector<Image> images;
|
112
|
+
|
114
113
|
if (tile_width > 0) {
|
115
114
|
tiles_x = bmp.width() / tile_width;
|
116
115
|
}
|
@@ -118,7 +117,7 @@ vector<Gosu::Image> Gosu::load_tiles(const Bitmap& bmp, int tile_width, int tile
|
|
118
117
|
tiles_x = -tile_width;
|
119
118
|
tile_width = bmp.width() / tiles_x;
|
120
119
|
}
|
121
|
-
|
120
|
+
|
122
121
|
if (tile_height > 0) {
|
123
122
|
tiles_y = bmp.height() / tile_height;
|
124
123
|
}
|
@@ -126,19 +125,19 @@ vector<Gosu::Image> Gosu::load_tiles(const Bitmap& bmp, int tile_width, int tile
|
|
126
125
|
tiles_y = -tile_height;
|
127
126
|
tile_height = bmp.height() / tiles_y;
|
128
127
|
}
|
129
|
-
|
128
|
+
|
130
129
|
for (int y = 0; y < tiles_y; ++y) {
|
131
130
|
for (int x = 0; x < tiles_x; ++x) {
|
132
131
|
images.emplace_back(bmp, x * tile_width, y * tile_height, tile_width, tile_height,
|
133
132
|
flags);
|
134
133
|
}
|
135
134
|
}
|
136
|
-
|
135
|
+
|
137
136
|
return images;
|
138
137
|
}
|
139
138
|
|
140
|
-
vector<Gosu::Image> Gosu::load_tiles(const string& filename, int tile_width,
|
141
|
-
|
139
|
+
std::vector<Gosu::Image> Gosu::load_tiles(const std::string& filename, int tile_width,
|
140
|
+
int tile_height, unsigned flags)
|
142
141
|
{
|
143
142
|
Bitmap bmp = load_image_file(filename);
|
144
143
|
return load_tiles(bmp, tile_width, tile_height, flags);
|
data/src/Input.cpp
CHANGED
@@ -36,7 +36,7 @@ static vector<shared_ptr<SDL_GameController>> open_game_controllers;
|
|
36
36
|
// Stores joystick instance id or -1 if empty
|
37
37
|
static array<int, Gosu::NUM_GAMEPADS> gamepad_slots = {-1, -1, -1, -1};
|
38
38
|
|
39
|
-
struct Gosu::Input::Impl
|
39
|
+
struct Gosu::Input::Impl : Gosu::Noncopyable
|
40
40
|
{
|
41
41
|
struct InputEvent
|
42
42
|
{
|
data/src/InputUIKit.cpp
CHANGED
data/src/LargeImageData.cpp
CHANGED
@@ -4,46 +4,51 @@
|
|
4
4
|
#include <Gosu/Math.hpp>
|
5
5
|
#include <cmath>
|
6
6
|
#include <stdexcept>
|
7
|
-
|
7
|
+
|
8
|
+
const Gosu::ImageData& Gosu::LargeImageData::tile(int x, int y) const
|
9
|
+
{
|
10
|
+
return *m_tiles.at(static_cast<std::size_t>(y * m_tiles_x + x));
|
11
|
+
}
|
8
12
|
|
9
13
|
Gosu::LargeImageData::LargeImageData(const Bitmap& source, int tile_width, int tile_height,
|
10
14
|
unsigned image_flags)
|
11
15
|
{
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
m_w = source.width();
|
17
|
+
m_h = source.height();
|
18
|
+
// Manual ceil() for integer division.
|
19
|
+
m_tiles_x = (m_w + tile_width - 1) / tile_width;
|
20
|
+
m_tiles_y = (m_h + tile_height - 1) / tile_height;
|
16
21
|
|
17
22
|
// When there are no tiles, set both fields to 0 to avoid entering any for () loop in this class.
|
18
|
-
if (
|
19
|
-
|
23
|
+
if (m_tiles_x == 0 || m_tiles_y == 0) {
|
24
|
+
m_tiles_x = m_tiles_y = 0;
|
20
25
|
}
|
21
26
|
|
22
|
-
|
27
|
+
m_tiles.reserve(m_tiles_x * m_tiles_y);
|
23
28
|
|
24
|
-
for (int y = 0; y <
|
25
|
-
for (int x = 0; x <
|
29
|
+
for (int y = 0; y < m_tiles_y; ++y) {
|
30
|
+
for (int x = 0; x < m_tiles_x; ++x) {
|
26
31
|
int src_width = tile_width;
|
27
|
-
if (x ==
|
32
|
+
if (x == m_tiles_x - 1 && m_w % tile_width != 0) {
|
28
33
|
// The right-most parts don't necessarily have the full width.
|
29
|
-
src_width =
|
34
|
+
src_width = m_w % tile_width;
|
30
35
|
}
|
31
36
|
|
32
37
|
int src_height = tile_height;
|
33
|
-
if (y ==
|
38
|
+
if (y == m_tiles_y - 1 && m_h % tile_height != 0) {
|
34
39
|
// Same for the parts on the bottom.
|
35
|
-
src_height =
|
40
|
+
src_height = m_h % tile_height;
|
36
41
|
}
|
37
42
|
|
38
43
|
unsigned local_flags = IF_TILEABLE | image_flags;
|
39
|
-
|
44
|
+
|
40
45
|
// Left edge, only tileable if requested in image_flags.
|
41
46
|
if (x == 0) {
|
42
47
|
local_flags &= ~IF_TILEABLE_LEFT;
|
43
48
|
local_flags |= (image_flags & IF_TILEABLE_LEFT);
|
44
49
|
}
|
45
50
|
// Right edge, only tileable if requested in image_flags.
|
46
|
-
if (x ==
|
51
|
+
if (x == m_tiles_x - 1) {
|
47
52
|
local_flags &= ~IF_TILEABLE_RIGHT;
|
48
53
|
local_flags |= (image_flags & IF_TILEABLE_RIGHT);
|
49
54
|
}
|
@@ -53,41 +58,37 @@ Gosu::LargeImageData::LargeImageData(const Bitmap& source, int tile_width, int t
|
|
53
58
|
local_flags |= (image_flags & IF_TILEABLE_TOP);
|
54
59
|
}
|
55
60
|
// Bottom edge, only tileable if requested in image_flags.
|
56
|
-
if (y ==
|
61
|
+
if (y == m_tiles_y - 1) {
|
57
62
|
local_flags &= ~IF_TILEABLE_BOTTOM;
|
58
63
|
local_flags |= (image_flags & IF_TILEABLE_BOTTOM);
|
59
64
|
}
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
src_width, src_height, local_flags));
|
65
|
+
|
66
|
+
m_tiles.emplace_back(Graphics::create_image(source, x * tile_width, y * tile_height,
|
67
|
+
src_width, src_height, local_flags));
|
64
68
|
}
|
65
69
|
}
|
66
70
|
}
|
67
71
|
|
68
|
-
void Gosu::LargeImageData::draw(double x1, double y1, Color c1,
|
69
|
-
double
|
70
|
-
double x3, double y3, Color c3,
|
71
|
-
double x4, double y4, Color c4,
|
72
|
+
void Gosu::LargeImageData::draw(double x1, double y1, Color c1, double x2, double y2, Color c2,
|
73
|
+
double x3, double y3, Color c3, double x4, double y4, Color c4,
|
72
74
|
ZPos z, BlendMode mode) const
|
73
75
|
{
|
74
76
|
normalize_coordinates(x1, y1, x2, y2, x3, y3, c3, x4, y4, c4);
|
75
|
-
|
77
|
+
|
76
78
|
double y = 0;
|
77
|
-
for (int ty = 0; ty <
|
79
|
+
for (int ty = 0; ty < m_tiles_y; ++ty) {
|
78
80
|
double x = 0;
|
79
|
-
for (int tx = 0; tx <
|
80
|
-
ImageData&
|
81
|
-
|
82
|
-
double rel_x_l = x /
|
83
|
-
double rel_x_r = (x +
|
84
|
-
double rel_y_t = y /
|
85
|
-
double rel_y_b = (y +
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
x_weight);
|
81
|
+
for (int tx = 0; tx < m_tiles_x; ++tx) {
|
82
|
+
const ImageData& image = tile(tx, ty);
|
83
|
+
|
84
|
+
double rel_x_l = x / m_w;
|
85
|
+
double rel_x_r = (x + image.width()) / m_w;
|
86
|
+
double rel_y_t = y / m_h;
|
87
|
+
double rel_y_b = (y + image.height()) / m_h;
|
88
|
+
|
89
|
+
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
90
|
+
#define LERP2D(what, x_weight, y_weight) \
|
91
|
+
lerp(lerp(what##1, what##3, y_weight), lerp(what##2, what##4, y_weight), x_weight);
|
91
92
|
|
92
93
|
double x_t_l = LERP2D(x, rel_x_l, rel_y_t);
|
93
94
|
double x_t_r = LERP2D(x, rel_x_r, rel_y_t);
|
@@ -99,80 +100,86 @@ void Gosu::LargeImageData::draw(double x1, double y1, Color c1,
|
|
99
100
|
double y_b_l = LERP2D(y, rel_x_l, rel_y_b);
|
100
101
|
double y_b_r = LERP2D(y, rel_x_r, rel_y_b);
|
101
102
|
|
102
|
-
Color
|
103
|
-
Color
|
104
|
-
Color
|
105
|
-
Color
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
z, mode);
|
112
|
-
|
113
|
-
x += tile.width();
|
103
|
+
Color c_t_l = LERP2D(c, rel_x_l, rel_y_t);
|
104
|
+
Color c_t_r = LERP2D(c, rel_x_r, rel_y_t);
|
105
|
+
Color c_b_l = LERP2D(c, rel_x_l, rel_y_b);
|
106
|
+
Color c_b_r = LERP2D(c, rel_x_r, rel_y_b);
|
107
|
+
|
108
|
+
image.draw(x_t_l, y_t_l, c_t_l, x_t_r, y_t_r, c_t_r, x_b_l, y_b_l, c_b_l, x_b_r, y_b_r,
|
109
|
+
c_b_r, z, mode);
|
110
|
+
|
111
|
+
x += image.width();
|
114
112
|
}
|
115
|
-
y +=
|
113
|
+
y += tile(0, ty).height();
|
116
114
|
}
|
117
115
|
}
|
118
116
|
|
119
|
-
unique_ptr<Gosu::ImageData>
|
120
|
-
|
117
|
+
std::unique_ptr<Gosu::ImageData> Gosu::LargeImageData::subimage(int left, int top, int width,
|
118
|
+
int height) const
|
121
119
|
{
|
122
|
-
if (left < 0 || top < 0 || left + width >
|
123
|
-
throw invalid_argument
|
120
|
+
if (left < 0 || top < 0 || left + width > m_w || top + height > m_h) {
|
121
|
+
throw std::invalid_argument{"subimage bounds exceed those of its parent"};
|
124
122
|
}
|
125
123
|
if (width <= 0 || height <= 0) {
|
126
|
-
throw invalid_argument
|
124
|
+
throw std::invalid_argument{"cannot create empty subimage"};
|
127
125
|
}
|
128
|
-
|
126
|
+
|
129
127
|
int sub_tiles_y = 0;
|
130
|
-
vector<unique_ptr<ImageData>> sub_tiles;
|
131
|
-
|
128
|
+
std::vector<std::unique_ptr<ImageData>> sub_tiles;
|
129
|
+
|
132
130
|
int y = 0;
|
133
|
-
for (int ty = 0; ty <
|
134
|
-
int row_height =
|
135
|
-
|
131
|
+
for (int ty = 0; ty < m_tiles_y; ++ty) {
|
132
|
+
int row_height = tile(0, ty).height();
|
133
|
+
|
136
134
|
if (y + row_height <= top) {
|
137
|
-
|
135
|
+
// Skip rows until we are at the requested Y coordinate.
|
136
|
+
y += row_height;
|
138
137
|
continue;
|
139
138
|
}
|
140
|
-
if (y >= top + height)
|
141
|
-
|
139
|
+
if (y >= top + height) {
|
140
|
+
// Also skip all rows after reaching the bottom requested Y coordinate.
|
141
|
+
break;
|
142
|
+
}
|
143
|
+
|
142
144
|
sub_tiles_y += 1;
|
143
145
|
|
144
146
|
int x = 0;
|
145
|
-
for (int tx = 0; tx <
|
146
|
-
ImageData&
|
147
|
-
|
148
|
-
if (x +
|
149
|
-
|
147
|
+
for (int tx = 0; tx < m_tiles_x; ++tx) {
|
148
|
+
const ImageData& image = tile(tx, ty);
|
149
|
+
|
150
|
+
if (x + image.width() <= left) {
|
151
|
+
// Skip columns until we are at the requested X coordinate.
|
152
|
+
x += image.width();
|
150
153
|
continue;
|
151
154
|
}
|
152
|
-
if (x >= left + width)
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
int
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
155
|
+
if (x >= left + width) {
|
156
|
+
// Also skip all columns after reaching the right-most requested Y coordinate.
|
157
|
+
break;
|
158
|
+
}
|
159
|
+
|
160
|
+
int sub_left = std::max(0, left - x);
|
161
|
+
int sub_top = std::max(0, top - y);
|
162
|
+
int sub_right = std::min(image.width(), left + width - x);
|
163
|
+
int sub_bottom = std::min(image.height(), top + height - y);
|
164
|
+
|
165
|
+
sub_tiles.emplace_back(
|
166
|
+
image.subimage(sub_left, sub_top, sub_right - sub_left, sub_bottom - sub_top));
|
167
|
+
|
168
|
+
x += image.width();
|
162
169
|
}
|
163
|
-
y +=
|
170
|
+
y += tile(0, ty).height();
|
164
171
|
}
|
165
|
-
|
172
|
+
|
166
173
|
if (sub_tiles.size() == 1) {
|
167
174
|
return move(sub_tiles[0]);
|
168
175
|
}
|
169
176
|
else {
|
170
|
-
unique_ptr<LargeImageData> result(new LargeImageData());
|
171
|
-
result->
|
172
|
-
result->
|
173
|
-
result->
|
174
|
-
result->
|
175
|
-
result->
|
177
|
+
std::unique_ptr<LargeImageData> result(new LargeImageData());
|
178
|
+
result->m_w = width;
|
179
|
+
result->m_h = height;
|
180
|
+
result->m_tiles_x = static_cast<int>(sub_tiles.size()) / sub_tiles_y;
|
181
|
+
result->m_tiles_y = sub_tiles_y;
|
182
|
+
result->m_tiles.swap(sub_tiles);
|
176
183
|
return move(result);
|
177
184
|
}
|
178
185
|
}
|
@@ -181,14 +188,14 @@ Gosu::Bitmap Gosu::LargeImageData::to_bitmap() const
|
|
181
188
|
{
|
182
189
|
Bitmap bitmap(width(), height());
|
183
190
|
int y = 0;
|
184
|
-
for (int ty = 0; ty <
|
191
|
+
for (int ty = 0; ty < m_tiles_y; ++ty) {
|
185
192
|
int x = 0;
|
186
|
-
for (int tx = 0; tx <
|
187
|
-
ImageData&
|
188
|
-
bitmap.insert(x, y,
|
189
|
-
x +=
|
193
|
+
for (int tx = 0; tx < m_tiles_x; ++tx) {
|
194
|
+
const ImageData& image = tile(tx, ty);
|
195
|
+
bitmap.insert(x, y, image.to_bitmap());
|
196
|
+
x += image.width();
|
190
197
|
}
|
191
|
-
y +=
|
198
|
+
y += tile(0, ty).height();
|
192
199
|
}
|
193
200
|
return bitmap;
|
194
201
|
}
|
@@ -196,13 +203,13 @@ Gosu::Bitmap Gosu::LargeImageData::to_bitmap() const
|
|
196
203
|
void Gosu::LargeImageData::insert(const Bitmap& bitmap, int at_x, int at_y)
|
197
204
|
{
|
198
205
|
int y = 0;
|
199
|
-
for (int ty = 0; ty <
|
206
|
+
for (int ty = 0; ty < m_tiles_y; ++ty) {
|
200
207
|
int x = 0;
|
201
|
-
for (int tx = 0; tx <
|
202
|
-
ImageData&
|
203
|
-
|
204
|
-
x +=
|
208
|
+
for (int tx = 0; tx < m_tiles_x; ++tx) {
|
209
|
+
ImageData& image = *m_tiles[static_cast<std::size_t>(ty * m_tiles_x + tx)];
|
210
|
+
image.insert(bitmap, at_x - x, at_y - y);
|
211
|
+
x += image.width();
|
205
212
|
}
|
206
|
-
y +=
|
213
|
+
y += tile(0, ty).height();
|
207
214
|
}
|
208
215
|
}
|
data/src/LargeImageData.hpp
CHANGED
@@ -1,37 +1,39 @@
|
|
1
1
|
#pragma once
|
2
2
|
|
3
|
-
#include "GraphicsImpl.hpp"
|
4
3
|
#include <Gosu/Fwd.hpp>
|
5
4
|
#include <Gosu/ImageData.hpp>
|
6
5
|
#include <Gosu/Platform.hpp>
|
6
|
+
#include "GraphicsImpl.hpp"
|
7
7
|
#include <memory>
|
8
8
|
#include <vector>
|
9
9
|
|
10
10
|
class Gosu::LargeImageData : public Gosu::ImageData
|
11
11
|
{
|
12
|
-
int
|
13
|
-
int
|
14
|
-
std::vector<std::unique_ptr<ImageData>>
|
15
|
-
|
16
|
-
LargeImageData()
|
12
|
+
int m_w, m_h;
|
13
|
+
int m_tiles_x, m_tiles_y;
|
14
|
+
std::vector<std::unique_ptr<ImageData>> m_tiles;
|
15
|
+
|
16
|
+
LargeImageData() = default;
|
17
|
+
|
18
|
+
const ImageData& tile(int x, int y) const;
|
17
19
|
|
18
20
|
public:
|
19
21
|
LargeImageData(const Bitmap& source, int tile_width, int tile_height, unsigned image_flags);
|
20
22
|
|
21
|
-
int width() const override
|
22
|
-
int height() const override { return
|
23
|
+
int width() const override { return m_w; }
|
24
|
+
int height() const override { return m_h; }
|
23
25
|
|
24
|
-
void draw(double x1, double y1, Color c1,
|
25
|
-
double x2, double y2, Color c2,
|
26
|
-
double x3, double y3, Color c3,
|
27
|
-
double x4, double y4, Color c4,
|
26
|
+
void draw(double x1, double y1, Color c1, //
|
27
|
+
double x2, double y2, Color c2, //
|
28
|
+
double x3, double y3, Color c3, //
|
29
|
+
double x4, double y4, Color c4, //
|
28
30
|
ZPos z, BlendMode mode) const override;
|
29
31
|
|
30
32
|
const GLTexInfo* gl_tex_info() const override { return nullptr; }
|
31
|
-
|
33
|
+
|
32
34
|
std::unique_ptr<ImageData> subimage(int x, int y, int width, int height) const override;
|
33
|
-
|
35
|
+
|
34
36
|
Bitmap to_bitmap() const override;
|
35
|
-
|
37
|
+
|
36
38
|
void insert(const Bitmap& bitmap, int x, int y) override;
|
37
39
|
};
|
data/src/Log.hpp
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#pragma once
|
2
2
|
|
3
|
+
#include <cstdio>
|
3
4
|
#include <cstdlib>
|
4
5
|
#include <utility>
|
5
6
|
|
@@ -8,12 +9,11 @@ namespace Gosu
|
|
8
9
|
template<class... Args>
|
9
10
|
void log(const char* format, Args&&... args)
|
10
11
|
{
|
11
|
-
|
12
|
-
|
13
|
-
if (
|
14
|
-
fprintf(stderr, format, std::forward<Args>(args)...);
|
15
|
-
fprintf(stderr, "\n");
|
12
|
+
// NOLINTNEXTLINE(concurrency-mt-unsafe) - we don't even follow the pointer
|
13
|
+
static bool enable_log = (std::getenv("GOSU_DEBUG") != nullptr);
|
14
|
+
if (enable_log) {
|
15
|
+
std::fprintf(stderr, format, std::forward<Args>(args)...);
|
16
|
+
std::fprintf(stderr, "\n");
|
16
17
|
}
|
17
18
|
}
|
18
19
|
}
|
19
|
-
|