gosu 1.4.6 → 2.0.0.pre7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/COPYING +2 -1
- data/dependencies/SDL/include/SDL_assert.h +2 -0
- data/dependencies/SDL/include/SDL_atomic.h +2 -3
- data/dependencies/SDL/include/SDL_audio.h +7 -7
- data/dependencies/SDL/include/SDL_blendmode.h +1 -1
- data/dependencies/SDL/include/SDL_endian.h +3 -3
- data/dependencies/SDL/include/SDL_gamecontroller.h +4 -4
- data/dependencies/SDL/include/SDL_hints.h +83 -28
- data/dependencies/SDL/include/SDL_joystick.h +8 -5
- data/dependencies/SDL/include/SDL_keycode.h +1 -1
- data/dependencies/SDL/include/SDL_main.h +7 -0
- data/dependencies/SDL/include/SDL_mouse.h +6 -7
- data/dependencies/SDL/include/SDL_mutex.h +79 -5
- data/dependencies/SDL/include/SDL_opengl_glext.h +5 -1
- data/dependencies/SDL/include/SDL_power.h +7 -8
- data/dependencies/SDL/include/SDL_render.h +6 -1
- data/dependencies/SDL/include/SDL_revision.h +2 -2
- data/dependencies/SDL/include/SDL_sensor.h +1 -1
- data/dependencies/SDL/include/SDL_stdinc.h +19 -11
- data/dependencies/SDL/include/SDL_thread.h +2 -2
- data/dependencies/SDL/include/SDL_version.h +2 -2
- data/dependencies/SDL/include/SDL_video.h +30 -2
- data/dependencies/SDL/include/begin_code.h +7 -7
- data/dependencies/SDL/include/close_code.h +2 -2
- 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.h +1 -1
- data/dependencies/SDL_sound/dr_flac.h +48 -23
- data/dependencies/SDL_sound/dr_mp3.h +34 -14
- data/dependencies/SDL_sound/stb_vorbis.h +3 -2
- data/dependencies/mojoAL/mojoal.c +1 -1
- data/ext/{gosu → gosu-ffi}/extconf.rb +34 -33
- data/ext/gosu-ffi/gosu-ffi.def +465 -0
- data/ffi/Gosu.cpp +307 -0
- data/ffi/Gosu.h +84 -0
- data/ffi/Gosu_Channel.cpp +62 -0
- data/ffi/Gosu_Channel.h +17 -0
- data/ffi/Gosu_Color.cpp +132 -0
- data/ffi/Gosu_Color.h +31 -0
- data/ffi/Gosu_Constants.cpp +334 -0
- data/ffi/Gosu_FFI.h +34 -0
- data/ffi/Gosu_FFI_internal.h +161 -0
- data/ffi/Gosu_Font.cpp +92 -0
- data/ffi/Gosu_Font.h +32 -0
- data/ffi/Gosu_Image.cpp +218 -0
- data/ffi/Gosu_Image.h +66 -0
- data/ffi/Gosu_Sample.cpp +29 -0
- data/ffi/Gosu_Sample.h +14 -0
- data/ffi/Gosu_Song.cpp +69 -0
- data/ffi/Gosu_Song.h +18 -0
- data/ffi/Gosu_TextInput.cpp +94 -0
- data/ffi/Gosu_TextInput.h +25 -0
- data/ffi/Gosu_Window.cpp +314 -0
- data/ffi/Gosu_Window.h +78 -0
- data/include/Gosu/Audio.hpp +6 -11
- data/include/Gosu/Bitmap.hpp +38 -53
- data/include/Gosu/Buffer.hpp +54 -0
- data/include/Gosu/Color.hpp +27 -35
- data/include/Gosu/Directories.hpp +25 -28
- data/include/Gosu/Drawable.hpp +58 -0
- data/include/Gosu/Font.hpp +6 -5
- data/include/Gosu/Fwd.hpp +4 -6
- data/include/Gosu/Gosu.hpp +5 -5
- data/include/Gosu/Graphics.hpp +51 -61
- data/include/Gosu/GraphicsBase.hpp +1 -11
- data/include/Gosu/Image.hpp +12 -15
- data/include/Gosu/Math.hpp +50 -72
- data/include/Gosu/Transform.hpp +32 -0
- data/include/Gosu/Utility.hpp +51 -1
- data/include/Gosu/Version.hpp +3 -3
- data/include/Gosu/Window.hpp +15 -9
- data/lib/SDL2.dll +0 -0
- data/lib/gosu/channel.rb +49 -0
- data/lib/gosu/color.rb +150 -0
- data/lib/gosu/compat.rb +29 -8
- data/lib/gosu/constants.rb +386 -0
- data/lib/gosu/ffi.rb +259 -0
- data/lib/gosu/font.rb +56 -0
- data/lib/gosu/gl_tex_info.rb +33 -0
- data/lib/gosu/gosu.rb +210 -0
- data/lib/gosu/image.rb +153 -0
- data/lib/gosu/numeric.rb +17 -0
- data/lib/gosu/preview.rb +6 -6
- data/lib/gosu/sample.rb +24 -0
- data/lib/gosu/song.rb +56 -0
- data/lib/gosu/text_input.rb +69 -0
- data/lib/gosu/window.rb +228 -0
- data/lib/gosu.rb +29 -8
- data/lib64/SDL2.dll +0 -0
- data/rdoc/gosu.rb +0 -2
- data/src/Audio.cpp +12 -12
- data/src/AudioFile.hpp +5 -4
- data/src/AudioFileAudioToolbox.cpp +8 -8
- data/src/AudioFileSDLSound.cpp +7 -10
- data/src/BinPacker.cpp +187 -0
- data/src/BinPacker.hpp +55 -0
- data/src/Bitmap.cpp +166 -144
- data/src/BitmapIO.cpp +60 -86
- data/src/Buffer.cpp +159 -0
- data/src/ClipRectStack.cpp +38 -0
- data/src/ClipRectStack.hpp +17 -83
- data/src/Color.cpp +75 -80
- data/src/Directories.cpp +47 -0
- data/src/DirectoriesUIKit.cpp +50 -0
- data/src/DrawOp.hpp +9 -9
- data/src/DrawOpQueue.hpp +26 -32
- data/src/Drawable.cpp +95 -0
- data/src/EmptyDrawable.hpp +38 -0
- data/src/FPS.cpp +31 -0
- data/src/Font.cpp +104 -74
- data/src/GosuGLView.cpp +13 -11
- data/src/GosuViewController.cpp +2 -10
- data/src/Graphics.cpp +66 -129
- data/src/GraphicsImpl.hpp +14 -67
- data/src/Image.cpp +41 -35
- data/src/Input.cpp +7 -8
- data/src/Macro.cpp +6 -6
- data/src/Macro.hpp +4 -4
- data/src/MarkupParser.cpp +5 -5
- data/src/Math.cpp +35 -22
- data/src/OffScreenTarget.cpp +53 -49
- data/src/OffScreenTarget.hpp +13 -11
- data/src/OpenGLContext.cpp +117 -0
- data/src/OpenGLContext.hpp +41 -0
- data/src/RenderState.hpp +45 -56
- data/src/Resolution.cpp +23 -21
- data/src/TexChunk.cpp +35 -80
- data/src/TexChunk.hpp +44 -35
- data/src/Text.cpp +1 -1
- data/src/TextBuilder.cpp +35 -21
- data/src/TextBuilder.hpp +6 -9
- data/src/Texture.cpp +62 -80
- data/src/Texture.hpp +25 -23
- data/src/TiledDrawable.cpp +150 -0
- data/src/TiledDrawable.hpp +47 -0
- data/src/TimingApple.cpp +1 -1
- data/src/Transform.cpp +45 -50
- data/src/TransformStack.hpp +16 -16
- data/src/TrueTypeFont.cpp +59 -51
- data/src/TrueTypeFont.hpp +6 -7
- data/src/TrueTypeFontApple.cpp +28 -19
- data/src/TrueTypeFontUnix.cpp +27 -23
- data/src/TrueTypeFontWin.cpp +30 -30
- data/src/Utility.cpp +84 -21
- data/src/UtilityWin.cpp +45 -0
- data/src/Window.cpp +92 -142
- data/src/WindowUIKit.cpp +14 -14
- metadata +74 -32
- data/include/Gosu/IO.hpp +0 -254
- data/include/Gosu/ImageData.hpp +0 -53
- data/include/Gosu/Inspection.hpp +0 -7
- data/lib/gosu/patches.rb +0 -66
- data/lib/gosu/run.rb +0 -20
- data/lib/gosu/swig_patches.rb +0 -110
- data/src/BlockAllocator.cpp +0 -131
- data/src/BlockAllocator.hpp +0 -32
- data/src/DirectoriesApple.cpp +0 -69
- data/src/DirectoriesUnix.cpp +0 -46
- data/src/DirectoriesWin.cpp +0 -65
- data/src/EmptyImageData.hpp +0 -52
- data/src/FileUnix.cpp +0 -99
- data/src/FileWin.cpp +0 -88
- data/src/IO.cpp +0 -60
- data/src/Iconv.hpp +0 -51
- data/src/Inspection.cpp +0 -27
- data/src/LargeImageData.cpp +0 -215
- data/src/LargeImageData.hpp +0 -39
- data/src/Log.hpp +0 -19
- data/src/RubyGosu.cxx +0 -13100
- data/src/RubyGosu.h +0 -49
- data/src/WinUtility.cpp +0 -61
- data/src/WinUtility.hpp +0 -27
data/src/Image.cpp
CHANGED
@@ -1,53 +1,54 @@
|
|
1
1
|
#include <Gosu/Bitmap.hpp>
|
2
|
+
#include <Gosu/Buffer.hpp>
|
3
|
+
#include <Gosu/Drawable.hpp>
|
2
4
|
#include <Gosu/Graphics.hpp>
|
3
|
-
#include <Gosu/IO.hpp>
|
4
5
|
#include <Gosu/Image.hpp>
|
5
|
-
#include <Gosu/ImageData.hpp>
|
6
6
|
#include <Gosu/Math.hpp>
|
7
|
-
#include "
|
7
|
+
#include "EmptyDrawable.hpp"
|
8
8
|
#include <stdexcept>
|
9
9
|
|
10
10
|
Gosu::Image::Image()
|
11
|
-
: m_data{EmptyImageData::instance_ptr()}
|
12
11
|
{
|
12
|
+
static const auto default_data_ptr = std::make_shared<EmptyDrawable>(0, 0);
|
13
|
+
m_drawable = default_data_ptr;
|
13
14
|
}
|
14
15
|
|
15
16
|
Gosu::Image::Image(const std::string& filename, unsigned image_flags)
|
16
|
-
: Image(load_image_file(filename), image_flags)
|
17
|
+
: Image(load_image_file(filename), image_flags)
|
17
18
|
{
|
18
19
|
}
|
19
20
|
|
20
|
-
Gosu::Image::Image(const std::string& filename,
|
21
|
-
|
22
|
-
: Image(load_image_file(filename), src_x, src_y, src_width, src_height, image_flags)
|
21
|
+
Gosu::Image::Image(const std::string& filename, const Rect& source_rect, unsigned image_flags)
|
22
|
+
: Image(load_image_file(filename), source_rect, image_flags)
|
23
23
|
{
|
24
24
|
}
|
25
25
|
|
26
26
|
Gosu::Image::Image(const Bitmap& source, unsigned image_flags)
|
27
|
-
: Image(source,
|
27
|
+
: Image(source, Rect::covering(source), image_flags)
|
28
28
|
{
|
29
29
|
}
|
30
30
|
|
31
|
-
Gosu::Image::Image(const Bitmap& source,
|
32
|
-
|
33
|
-
: m_data{Graphics::create_image(source, src_x, src_y, src_width, src_height, image_flags)}
|
31
|
+
Gosu::Image::Image(const Bitmap& source, const Rect& source_rect, unsigned image_flags)
|
32
|
+
: m_drawable(create_drawable(source, source_rect, image_flags))
|
34
33
|
{
|
35
34
|
}
|
36
35
|
|
37
|
-
Gosu::Image::Image(std::unique_ptr<
|
38
|
-
:
|
36
|
+
Gosu::Image::Image(std::unique_ptr<Drawable> data)
|
37
|
+
: m_drawable(std::move(data))
|
39
38
|
{
|
40
|
-
if (!
|
39
|
+
if (!m_drawable) {
|
40
|
+
throw std::invalid_argument("Gosu::Image cannot be initialized with nullptr");
|
41
|
+
}
|
41
42
|
}
|
42
43
|
|
43
44
|
unsigned Gosu::Image::width() const
|
44
45
|
{
|
45
|
-
return
|
46
|
+
return m_drawable->width();
|
46
47
|
}
|
47
48
|
|
48
49
|
unsigned Gosu::Image::height() const
|
49
50
|
{
|
50
|
-
return
|
51
|
+
return m_drawable->height();
|
51
52
|
}
|
52
53
|
|
53
54
|
void Gosu::Image::draw(double x, double y, ZPos z, double scale_x, double scale_y, Color c,
|
@@ -56,7 +57,7 @@ void Gosu::Image::draw(double x, double y, ZPos z, double scale_x, double scale_
|
|
56
57
|
double x2 = x + width() * scale_x;
|
57
58
|
double y2 = y + height() * scale_y;
|
58
59
|
|
59
|
-
|
60
|
+
m_drawable->draw(x, y, c, x2, y, c, x, y2, c, x2, y2, c, z, mode);
|
60
61
|
}
|
61
62
|
|
62
63
|
void Gosu::Image::draw_mod(double x, double y, ZPos z, double scale_x, double scale_y, Color c1,
|
@@ -65,7 +66,7 @@ void Gosu::Image::draw_mod(double x, double y, ZPos z, double scale_x, double sc
|
|
65
66
|
double x2 = x + width() * scale_x;
|
66
67
|
double y2 = y + height() * scale_y;
|
67
68
|
|
68
|
-
|
69
|
+
m_drawable->draw(x, y, c1, x2, y, c2, x, y2, c3, x2, y2, c4, z, mode);
|
69
70
|
}
|
70
71
|
|
71
72
|
void Gosu::Image::draw_rot(double x, double y, ZPos z, double angle, double center_x,
|
@@ -87,44 +88,49 @@ void Gosu::Image::draw_rot(double x, double y, ZPos z, double angle, double cent
|
|
87
88
|
double dist_to_bottom_x = -offs_x * size_y * (1 - center_y);
|
88
89
|
double dist_to_bottom_y = -offs_y * size_y * (1 - center_y);
|
89
90
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
91
|
+
m_drawable->draw( //
|
92
|
+
x + dist_to_left_x + dist_to_top_x, y + dist_to_left_y + dist_to_top_y, c,
|
93
|
+
x + dist_to_right_x + dist_to_top_x, y + dist_to_right_y + dist_to_top_y, c,
|
94
|
+
x + dist_to_left_x + dist_to_bottom_x, y + dist_to_left_y + dist_to_bottom_y, c,
|
95
|
+
x + dist_to_right_x + dist_to_bottom_x, y + dist_to_right_y + dist_to_bottom_y, c, //
|
96
|
+
z, mode);
|
95
97
|
}
|
96
98
|
|
97
|
-
Gosu::
|
99
|
+
Gosu::Drawable& Gosu::Image::drawable() const
|
98
100
|
{
|
99
|
-
return *
|
101
|
+
return *m_drawable;
|
100
102
|
}
|
101
103
|
|
102
|
-
std::vector<Gosu::Image> Gosu::load_tiles(const Bitmap&
|
104
|
+
std::vector<Gosu::Image> Gosu::load_tiles(const Bitmap& bitmap, //
|
103
105
|
int tile_width, int tile_height, unsigned flags)
|
104
106
|
{
|
107
|
+
if (tile_width == 0 || tile_height == 0) {
|
108
|
+
throw std::invalid_argument("Gosu::load_tiles does not support empty tiles");
|
109
|
+
}
|
110
|
+
|
105
111
|
int tiles_x, tiles_y;
|
106
112
|
std::vector<Image> images;
|
107
113
|
|
108
114
|
if (tile_width > 0) {
|
109
|
-
tiles_x =
|
115
|
+
tiles_x = bitmap.width() / tile_width;
|
110
116
|
}
|
111
117
|
else {
|
112
118
|
tiles_x = -tile_width;
|
113
|
-
tile_width =
|
119
|
+
tile_width = bitmap.width() / tiles_x;
|
114
120
|
}
|
115
121
|
|
116
122
|
if (tile_height > 0) {
|
117
|
-
tiles_y =
|
123
|
+
tiles_y = bitmap.height() / tile_height;
|
118
124
|
}
|
119
125
|
else {
|
120
126
|
tiles_y = -tile_height;
|
121
|
-
tile_height =
|
127
|
+
tile_height = bitmap.height() / tiles_y;
|
122
128
|
}
|
123
129
|
|
124
130
|
for (int y = 0; y < tiles_y; ++y) {
|
125
131
|
for (int x = 0; x < tiles_x; ++x) {
|
126
|
-
images.emplace_back(
|
127
|
-
|
132
|
+
images.emplace_back(
|
133
|
+
bitmap, Rect { x * tile_width, y * tile_height, tile_width, tile_height }, flags);
|
128
134
|
}
|
129
135
|
}
|
130
136
|
|
@@ -134,6 +140,6 @@ std::vector<Gosu::Image> Gosu::load_tiles(const Bitmap& bmp, //
|
|
134
140
|
std::vector<Gosu::Image> Gosu::load_tiles(const std::string& filename, //
|
135
141
|
int tile_width, int tile_height, unsigned flags)
|
136
142
|
{
|
137
|
-
Bitmap
|
138
|
-
return load_tiles(
|
143
|
+
const Bitmap bitmap = load_image_file(filename);
|
144
|
+
return load_tiles(bitmap, tile_width, tile_height, flags);
|
139
145
|
}
|
data/src/Input.cpp
CHANGED
@@ -8,21 +8,20 @@
|
|
8
8
|
#include <SDL.h>
|
9
9
|
#include <utf8proc.h>
|
10
10
|
|
11
|
-
#include <cwctype>
|
12
11
|
#include <cstdlib>
|
13
12
|
#include <algorithm>
|
14
13
|
#include <array>
|
15
|
-
#include <mutex>
|
16
14
|
#include <stdexcept>
|
17
15
|
using namespace std;
|
18
16
|
|
19
17
|
static void require_sdl_video()
|
20
18
|
{
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
// Don't bother shutting down the SDL video subsystem because OpenGLContext.cpp keeps it alive
|
20
|
+
// forever as well, and it is hard to know when to free things in a Ruby C extension.
|
21
|
+
static const int initialized = SDL_Init(SDL_INIT_VIDEO);
|
22
|
+
if (initialized < 0) {
|
23
|
+
throw std::runtime_error(SDL_GetError());
|
24
|
+
}
|
26
25
|
}
|
27
26
|
|
28
27
|
static const unsigned NUM_BUTTONS_PER_GAMEPAD =
|
@@ -602,7 +601,7 @@ bool Gosu::Input::down(Gosu::Button btn)
|
|
602
601
|
|
603
602
|
double Gosu::Input::axis(Gosu::Button btn)
|
604
603
|
{
|
605
|
-
unsigned axis_id = btn - GP_LEFT_STICK_X_AXIS;
|
604
|
+
unsigned axis_id = btn - static_cast<unsigned>(GP_LEFT_STICK_X_AXIS);
|
606
605
|
|
607
606
|
if (axis_id >= axis_states.size()) {
|
608
607
|
throw std::out_of_range("Invalid axis ID: " + std::to_string(btn));
|
data/src/Macro.cpp
CHANGED
@@ -132,7 +132,7 @@ struct Gosu::Macro::Impl : private Gosu::Noncopyable
|
|
132
132
|
for (const auto& vertex_array : vertex_arrays) {
|
133
133
|
glPushMatrix();
|
134
134
|
vertex_array.render_state.apply();
|
135
|
-
glMultMatrixd(
|
135
|
+
glMultMatrixd(transform.matrix.data());
|
136
136
|
glInterleavedArrays(GL_T2F_C4UB_V3F, 0, &vertex_array.vertices[0]);
|
137
137
|
glDrawArrays(GL_QUADS, 0, (GLsizei) vertex_array.vertices.size());
|
138
138
|
glPopMatrix();
|
@@ -169,7 +169,7 @@ void Gosu::Macro::draw(double x1, double y1, Color c1, double x2, double y2, Col
|
|
169
169
|
|
170
170
|
normalize_coordinates(x1, y1, x2, y2, x3, y3, c3, x4, y4, c4);
|
171
171
|
|
172
|
-
Gosu::
|
172
|
+
Gosu::gl(z, [=, this] { pimpl->draw_vertex_arrays(x1, y1, x2, y2, x3, y3, x4, y4); });
|
173
173
|
}
|
174
174
|
|
175
175
|
const Gosu::GLTexInfo* Gosu::Macro::gl_tex_info() const
|
@@ -184,15 +184,15 @@ Gosu::Bitmap Gosu::Macro::to_bitmap() const
|
|
184
184
|
pimpl->width, pimpl->height, Color::WHITE, 0, BM_DEFAULT);
|
185
185
|
};
|
186
186
|
|
187
|
-
return Gosu::
|
187
|
+
return Gosu::render(pimpl->width, pimpl->height, render_this).drawable().to_bitmap();
|
188
188
|
}
|
189
189
|
|
190
|
-
std::unique_ptr<Gosu::
|
190
|
+
std::unique_ptr<Gosu::Drawable> Gosu::Macro::subimage(const Rect&) const
|
191
191
|
{
|
192
|
-
return
|
192
|
+
return nullptr;
|
193
193
|
}
|
194
194
|
|
195
|
-
void Gosu::Macro::insert(const Bitmap
|
195
|
+
void Gosu::Macro::insert(const Bitmap&, int, int)
|
196
196
|
{
|
197
197
|
throw std::logic_error{"Gosu::Macro cannot be updated with a Gosu::Bitmap yet"};
|
198
198
|
}
|
data/src/Macro.hpp
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
#pragma once
|
2
2
|
|
3
3
|
#include <Gosu/Fwd.hpp>
|
4
|
-
#include <Gosu/
|
4
|
+
#include <Gosu/Drawable.hpp>
|
5
5
|
#include "GraphicsImpl.hpp"
|
6
6
|
#include <memory>
|
7
7
|
|
8
|
-
class Gosu::Macro : public Gosu::
|
8
|
+
class Gosu::Macro : public Gosu::Drawable
|
9
9
|
{
|
10
10
|
struct Impl;
|
11
11
|
std::shared_ptr<Impl> pimpl;
|
@@ -24,7 +24,7 @@ public:
|
|
24
24
|
|
25
25
|
Gosu::Bitmap to_bitmap() const override;
|
26
26
|
|
27
|
-
std::unique_ptr<
|
27
|
+
std::unique_ptr<Drawable> subimage(const Rect&) const override;
|
28
28
|
|
29
|
-
void insert(const Bitmap
|
29
|
+
void insert(const Bitmap&, int x, int y) override;
|
30
30
|
};
|
data/src/MarkupParser.cpp
CHANGED
@@ -157,29 +157,29 @@ void Gosu::MarkupParser::add_current_substring()
|
|
157
157
|
void Gosu::MarkupParser::add_composed_substring(u32string&& substring)
|
158
158
|
{
|
159
159
|
FormattedString fstr;
|
160
|
-
fstr.text = substring;
|
160
|
+
fstr.text = std::move(substring);
|
161
161
|
fstr.flags = flags();
|
162
162
|
fstr.color = c.back();
|
163
163
|
|
164
164
|
if (!substrings.empty() && substrings.back().can_be_merged_with(fstr)) {
|
165
|
-
substrings.back().text.append(
|
165
|
+
substrings.back().text.append(fstr.text);
|
166
166
|
}
|
167
167
|
else {
|
168
|
-
substrings.emplace_back(move(fstr));
|
168
|
+
substrings.emplace_back(std::move(fstr));
|
169
169
|
}
|
170
170
|
}
|
171
171
|
|
172
172
|
void Gosu::MarkupParser::flush_to_consumer()
|
173
173
|
{
|
174
174
|
if (!substrings.empty()) {
|
175
|
-
consumer(move(substrings));
|
175
|
+
consumer(std::move(substrings));
|
176
176
|
substrings.clear();
|
177
177
|
}
|
178
178
|
}
|
179
179
|
|
180
180
|
Gosu::MarkupParser::MarkupParser(unsigned base_flags, bool split_words,
|
181
181
|
function<void (vector<FormattedString>)> consumer)
|
182
|
-
: consumer(move(consumer))
|
182
|
+
: consumer(std::move(consumer))
|
183
183
|
{
|
184
184
|
word_state = (split_words ? ADDING_WORD : IGNORE_WORDS);
|
185
185
|
|
data/src/Math.cpp
CHANGED
@@ -1,38 +1,55 @@
|
|
1
1
|
#include <Gosu/Math.hpp>
|
2
|
-
#include <
|
3
|
-
|
2
|
+
#include <cmath>
|
3
|
+
#include <limits> // for std::numeric_limits::quiet_NaN
|
4
|
+
#include <random>
|
4
5
|
|
5
6
|
double Gosu::random(double min, double max)
|
6
7
|
{
|
7
|
-
|
8
|
-
|
8
|
+
if (std::isnan(min) || std::isnan(max)) {
|
9
|
+
return std::numeric_limits<double>::quiet_NaN();
|
10
|
+
}
|
11
|
+
|
12
|
+
if (min == max) {
|
13
|
+
return min;
|
14
|
+
}
|
15
|
+
|
16
|
+
thread_local std::mt19937_64 generator(std::random_device {}());
|
17
|
+
std::uniform_real_distribution<double> distribution(min, max);
|
18
|
+
const double result = distribution(generator);
|
19
|
+
// Make sure that we do not return "max" even when uniform_real_distribution is buggy.
|
20
|
+
// See "Notes": https://en.cppreference.com/w/cpp/numeric/random/uniform_real_distribution
|
21
|
+
return result == max ? min : result;
|
9
22
|
}
|
10
23
|
|
11
24
|
double Gosu::offset_x(double angle, double radius)
|
12
25
|
{
|
13
|
-
return +sin(angle / 180 *
|
26
|
+
return +std::sin(angle / 180 * std::numbers::pi) * radius;
|
14
27
|
}
|
15
28
|
|
16
29
|
double Gosu::offset_y(double angle, double radius)
|
17
30
|
{
|
18
|
-
return -cos(angle / 180 *
|
31
|
+
return -std::cos(angle / 180 * std::numbers::pi) * radius;
|
19
32
|
}
|
20
33
|
|
21
|
-
double Gosu::angle(double from_x, double from_y, double to_x, double to_y, double
|
34
|
+
double Gosu::angle(double from_x, double from_y, double to_x, double to_y, double fallback)
|
22
35
|
{
|
23
36
|
double dist_x = to_x - from_x;
|
24
37
|
double dist_y = to_y - from_y;
|
25
38
|
|
39
|
+
// Special-case the four cardinal directions values so that we don't run into subtle rounding
|
40
|
+
// errors for these obvious values.
|
26
41
|
if (dist_x == 0) {
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
42
|
+
if (dist_y == 0) {
|
43
|
+
return fallback;
|
44
|
+
}
|
45
|
+
|
46
|
+
return dist_y < 0 ? 0 : 180;
|
47
|
+
}
|
48
|
+
else if (dist_y == 0) {
|
49
|
+
return dist_x < 0 ? 270 : 90;
|
33
50
|
}
|
34
51
|
|
35
|
-
return normalize_angle(
|
52
|
+
return normalize_angle(radians_to_angle(std::atan2(dist_y, dist_x)));
|
36
53
|
}
|
37
54
|
|
38
55
|
double Gosu::angle_diff(double from, double to)
|
@@ -51,19 +68,15 @@ int Gosu::wrap(int value, int min, int max)
|
|
51
68
|
return result < 0 ? result + max : result + min;
|
52
69
|
}
|
53
70
|
|
54
|
-
float Gosu::wrap(float value, float min, float max)
|
55
|
-
{
|
56
|
-
float result = fmodf(value - min, max - min);
|
57
|
-
return result < 0 ? result + max : result + min;
|
58
|
-
}
|
59
|
-
|
60
71
|
double Gosu::wrap(double value, double min, double max)
|
61
72
|
{
|
62
|
-
double result = fmod(value - min, max - min);
|
73
|
+
double result = std::fmod(value - min, max - min);
|
63
74
|
return result < 0 ? result + max : result + min;
|
64
75
|
}
|
65
76
|
|
66
77
|
double Gosu::distance(double x1, double y1, double x2, double y2)
|
67
78
|
{
|
68
|
-
|
79
|
+
double dist_x = (x2 - x1);
|
80
|
+
double dist_y = (y2 - y1);
|
81
|
+
return std::sqrt(dist_x * dist_x + dist_y * dist_y);
|
69
82
|
}
|
data/src/OffScreenTarget.cpp
CHANGED
@@ -1,99 +1,103 @@
|
|
1
1
|
#include "OffScreenTarget.hpp"
|
2
|
-
#include "Texture.hpp"
|
3
2
|
#include <Gosu/Image.hpp>
|
4
3
|
#include <Gosu/Platform.hpp>
|
4
|
+
#include "OpenGLContext.hpp"
|
5
|
+
#include "Texture.hpp"
|
5
6
|
#ifndef GOSU_IS_IPHONE
|
6
|
-
#include <SDL.h>
|
7
|
+
#include <SDL.h> // for SDL_GL_GetProcAddress
|
7
8
|
#endif
|
8
|
-
using namespace std;
|
9
9
|
|
10
10
|
#ifdef GOSU_IS_OPENGLES
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
#define GOSU_GL_CONST(name) \
|
15
|
-
name ## _OES
|
16
|
-
|
17
|
-
#define GOSU_GL_DEPTH_COMPONENT \
|
18
|
-
GL_DEPTH_COMPONENT16_OES
|
11
|
+
#define GOSU_LOAD_GL_EXT(fn, type) static auto fn = fn##OES
|
12
|
+
#define GOSU_GL_CONST(name) name##_OES
|
13
|
+
#define GOSU_GL_DEPTH_COMPONENT GL_DEPTH_COMPONENT16_OES
|
19
14
|
#else
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
#define GOSU_GL_DEPTH_COMPONENT \
|
28
|
-
GL_DEPTH_COMPONENT
|
15
|
+
#define GOSU_LOAD_GL_EXT(fn, type) \
|
16
|
+
static auto fn = reinterpret_cast<type>(SDL_GL_GetProcAddress(#fn)); \
|
17
|
+
if ((fn) == nullptr) { \
|
18
|
+
throw std::runtime_error("Unable to load " #fn); \
|
19
|
+
}
|
20
|
+
#define GOSU_GL_CONST(name) name
|
21
|
+
#define GOSU_GL_DEPTH_COMPONENT GL_DEPTH_COMPONENT
|
29
22
|
#endif
|
30
23
|
|
31
24
|
Gosu::OffScreenTarget::OffScreenTarget(int width, int height, unsigned image_flags)
|
25
|
+
: r_renderbuffer(static_cast<GLuint>(-1)),
|
26
|
+
m_framebuffer(static_cast<GLuint>(-1))
|
32
27
|
{
|
33
28
|
#ifndef GOSU_IS_IPHONE
|
29
|
+
// GCOV_EXCL_START
|
34
30
|
if (!SDL_GL_ExtensionSupported("GL_EXT_framebuffer_object")) {
|
35
|
-
throw runtime_error("Missing GL_EXT_framebuffer_object extension");
|
31
|
+
throw std::runtime_error("Missing GL_EXT_framebuffer_object extension");
|
36
32
|
}
|
33
|
+
// GCOV_EXCL_end
|
37
34
|
#endif
|
38
|
-
|
35
|
+
|
39
36
|
// Create a new texture that will be our rendering target.
|
40
|
-
|
41
|
-
|
42
|
-
texture->block(0, 0, width, height);
|
43
|
-
|
37
|
+
m_texture = std::make_shared<Texture>(width, height, image_flags & IF_RETRO);
|
38
|
+
|
44
39
|
// Besides the texture, also create a renderbuffer for depth information.
|
45
|
-
// Gosu doesn't use this, but custom OpenGL code
|
40
|
+
// Gosu doesn't use this, but custom OpenGL code might.
|
46
41
|
GOSU_LOAD_GL_EXT(glGenRenderbuffers, PFNGLGENRENDERBUFFERSPROC);
|
47
|
-
glGenRenderbuffers(1, &
|
48
|
-
|
42
|
+
glGenRenderbuffers(1, &r_renderbuffer);
|
43
|
+
|
49
44
|
GOSU_LOAD_GL_EXT(glBindRenderbuffer, PFNGLBINDRENDERBUFFERPROC);
|
50
|
-
glBindRenderbuffer(GOSU_GL_CONST(GL_RENDERBUFFER),
|
51
|
-
|
45
|
+
glBindRenderbuffer(GOSU_GL_CONST(GL_RENDERBUFFER), r_renderbuffer);
|
46
|
+
|
52
47
|
GOSU_LOAD_GL_EXT(glRenderbufferStorage, PFNGLRENDERBUFFERSTORAGEPROC);
|
53
48
|
glRenderbufferStorage(GOSU_GL_CONST(GL_RENDERBUFFER), GOSU_GL_DEPTH_COMPONENT, width, height);
|
54
49
|
glBindRenderbuffer(GOSU_GL_CONST(GL_RENDERBUFFER), 0);
|
55
|
-
|
50
|
+
|
56
51
|
// Now tie everything together.
|
57
52
|
GOSU_LOAD_GL_EXT(glGenFramebuffers, PFNGLGENFRAMEBUFFERSPROC);
|
58
|
-
glGenFramebuffers(1, &
|
59
|
-
|
53
|
+
glGenFramebuffers(1, &m_framebuffer);
|
54
|
+
|
60
55
|
GOSU_LOAD_GL_EXT(glBindFramebuffer, PFNGLBINDFRAMEBUFFERPROC);
|
61
|
-
glBindFramebuffer(GOSU_GL_CONST(GL_FRAMEBUFFER),
|
62
|
-
|
56
|
+
glBindFramebuffer(GOSU_GL_CONST(GL_FRAMEBUFFER), m_framebuffer);
|
57
|
+
|
63
58
|
GOSU_LOAD_GL_EXT(glFramebufferTexture2D, PFNGLFRAMEBUFFERTEXTURE2DPROC);
|
64
59
|
glFramebufferTexture2D(GOSU_GL_CONST(GL_FRAMEBUFFER), GOSU_GL_CONST(GL_COLOR_ATTACHMENT0),
|
65
|
-
GL_TEXTURE_2D,
|
66
|
-
|
60
|
+
GL_TEXTURE_2D, m_texture->tex_name(), 0);
|
61
|
+
|
67
62
|
GOSU_LOAD_GL_EXT(glFramebufferRenderbuffer, PFNGLFRAMEBUFFERRENDERBUFFERPROC);
|
68
63
|
glFramebufferRenderbuffer(GOSU_GL_CONST(GL_FRAMEBUFFER), GOSU_GL_CONST(GL_DEPTH_ATTACHMENT),
|
69
|
-
GOSU_GL_CONST(GL_RENDERBUFFER),
|
64
|
+
GOSU_GL_CONST(GL_RENDERBUFFER), r_renderbuffer);
|
70
65
|
}
|
71
66
|
|
72
67
|
Gosu::OffScreenTarget::~OffScreenTarget()
|
73
68
|
{
|
74
69
|
try {
|
75
70
|
GOSU_LOAD_GL_EXT(glDeleteRenderbuffers, PFNGLDELETERENDERBUFFERSPROC);
|
76
|
-
glDeleteRenderbuffers(1, &
|
77
|
-
|
71
|
+
glDeleteRenderbuffers(1, &r_renderbuffer);
|
72
|
+
|
78
73
|
GOSU_LOAD_GL_EXT(glDeleteFramebuffers, PFNGLDELETEFRAMEBUFFERSPROC);
|
79
|
-
glDeleteFramebuffers(1, &
|
74
|
+
glDeleteFramebuffers(1, &m_framebuffer);
|
75
|
+
// GCOV_EXCL_START
|
80
76
|
} catch (...) {
|
81
77
|
// If we can't load these functions, just accept the resource leak.
|
82
78
|
}
|
79
|
+
// GCOV_EXCL_END
|
83
80
|
}
|
84
81
|
|
85
82
|
Gosu::Image Gosu::OffScreenTarget::render(const std::function<void ()>& f)
|
86
83
|
{
|
87
84
|
GOSU_LOAD_GL_EXT(glBindFramebuffer, PFNGLBINDFRAMEBUFFERPROC);
|
88
|
-
glBindFramebuffer(GOSU_GL_CONST(GL_FRAMEBUFFER),
|
89
|
-
|
85
|
+
glBindFramebuffer(GOSU_GL_CONST(GL_FRAMEBUFFER), m_framebuffer);
|
86
|
+
|
90
87
|
GOSU_LOAD_GL_EXT(glCheckFramebufferStatus, PFNGLCHECKFRAMEBUFFERSTATUSPROC);
|
91
88
|
GLenum status = glCheckFramebufferStatus(GOSU_GL_CONST(GL_FRAMEBUFFER));
|
92
|
-
if (status != GOSU_GL_CONST(GL_FRAMEBUFFER_COMPLETE))
|
93
|
-
|
94
|
-
|
89
|
+
if (status != GOSU_GL_CONST(GL_FRAMEBUFFER_COMPLETE)) {
|
90
|
+
throw std::runtime_error("Incomplete framebuffer");
|
91
|
+
}
|
92
|
+
|
93
|
+
try {
|
94
|
+
f();
|
95
|
+
|
96
|
+
} catch (...) {
|
97
|
+
glBindFramebuffer(GOSU_GL_CONST(GL_FRAMEBUFFER), 0);
|
98
|
+
throw;
|
99
|
+
}
|
95
100
|
glBindFramebuffer(GOSU_GL_CONST(GL_FRAMEBUFFER), 0);
|
96
101
|
|
97
|
-
|
98
|
-
return Image(move(tex_chunk));
|
102
|
+
return Image(std::make_unique<TexChunk>(m_texture, Rect::covering(*m_texture), nullptr));
|
99
103
|
}
|
data/src/OffScreenTarget.hpp
CHANGED
@@ -1,23 +1,25 @@
|
|
1
1
|
#pragma once
|
2
2
|
|
3
|
-
#include
|
3
|
+
#include <Gosu/Utility.hpp>
|
4
|
+
#include <cstdint>
|
5
|
+
#include <functional>
|
6
|
+
#include <memory>
|
4
7
|
|
5
8
|
namespace Gosu
|
6
9
|
{
|
7
|
-
class
|
10
|
+
class Image;
|
11
|
+
class Texture;
|
12
|
+
|
13
|
+
class OffScreenTarget : private Noncopyable
|
8
14
|
{
|
9
|
-
std::shared_ptr<Texture>
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
OffScreenTarget(const OffScreenTarget& other) = delete;
|
14
|
-
OffScreenTarget& operator=(const OffScreenTarget& other) = delete;
|
15
|
-
OffScreenTarget(OffScreenTarget&& other) = delete;
|
16
|
-
OffScreenTarget& operator=(OffScreenTarget&& other) = delete;
|
17
|
-
|
15
|
+
std::shared_ptr<Texture> m_texture;
|
16
|
+
std::uint32_t r_renderbuffer;
|
17
|
+
std::uint32_t m_framebuffer;
|
18
|
+
|
18
19
|
public:
|
19
20
|
OffScreenTarget(int width, int height, unsigned image_flags);
|
20
21
|
~OffScreenTarget();
|
22
|
+
|
21
23
|
Gosu::Image render(const std::function<void ()>& f);
|
22
24
|
};
|
23
25
|
}
|