gosu 1.1.1.1 → 1.4.1
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 +63 -107
- data/include/Gosu/Font.hpp +44 -48
- data/include/Gosu/Fwd.hpp +1 -1
- data/include/Gosu/Graphics.hpp +64 -75
- data/include/Gosu/GraphicsBase.hpp +32 -39
- data/include/Gosu/Image.hpp +56 -62
- data/include/Gosu/ImageData.hpp +23 -27
- data/include/Gosu/Inspection.hpp +1 -4
- data/include/Gosu/Math.hpp +4 -16
- data/include/Gosu/Platform.hpp +1 -51
- data/include/Gosu/Text.hpp +37 -40
- data/include/Gosu/TextInput.hpp +34 -40
- data/include/Gosu/Utility.hpp +10 -8
- data/include/Gosu/Version.hpp +1 -1
- data/include/Gosu/Window.hpp +73 -70
- data/lib/SDL2.dll +0 -0
- data/lib/gosu/compat.rb +28 -37
- data/lib/gosu/swig_patches.rb +31 -3
- data/lib/gosu.rb +2 -2
- data/lib64/SDL2.dll +0 -0
- data/rdoc/gosu.rb +9 -1
- data/src/Audio.cpp +88 -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/Bitmap.cpp +13 -13
- data/src/BitmapIO.cpp +0 -20
- data/src/BlockAllocator.cpp +2 -1
- data/src/Channel.cpp +22 -20
- data/src/Color.cpp +62 -55
- data/src/EmptyImageData.hpp +16 -18
- data/src/FileUnix.cpp +1 -1
- data/src/FileWin.cpp +1 -1
- data/src/Font.cpp +52 -57
- data/src/GosuViewController.cpp +2 -0
- data/src/Graphics.cpp +135 -143
- data/src/Image.cpp +42 -42
- data/src/Input.cpp +1 -1
- data/src/InputUIKit.cpp +1 -1
- data/src/LargeImageData.cpp +120 -113
- data/src/LargeImageData.hpp +18 -16
- 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/RenderState.hpp +5 -5
- data/src/Resolution.cpp +12 -7
- data/src/RubyGosu.cxx +471 -502
- data/src/RubyGosu.h +3 -2
- data/src/TexChunk.cpp +50 -41
- data/src/TexChunk.hpp +22 -22
- data/src/Text.cpp +58 -59
- data/src/TextBuilder.cpp +60 -57
- data/src/TextBuilder.hpp +20 -20
- data/src/TextInput.cpp +127 -135
- data/src/TrueTypeFont.cpp +108 -108
- data/src/TrueTypeFont.hpp +39 -38
- data/src/TrueTypeFontApple.cpp +27 -23
- data/src/TrueTypeFontUnix.cpp +21 -26
- data/src/TrueTypeFontWin.cpp +30 -30
- data/src/Utility.cpp +82 -23
- data/src/WinUtility.hpp +2 -1
- data/src/Window.cpp +103 -86
- data/src/WindowUIKit.cpp +48 -51
- metadata +8 -20
- 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/UtilityApple.cpp +0 -16
- data/src/UtilityWin.cpp +0 -17
data/ext/gosu/extconf.rb
CHANGED
@@ -8,17 +8,17 @@ when /^darwin/
|
|
8
8
|
end
|
9
9
|
|
10
10
|
if not windows
|
11
|
-
puts
|
12
|
-
puts
|
11
|
+
puts "The Gosu gem requires some libraries to be installed system-wide."
|
12
|
+
puts "See the following site for a list:"
|
13
13
|
if macos
|
14
|
-
puts
|
14
|
+
puts "https://github.com/gosu/gosu/wiki/Getting-Started-on-OS-X"
|
15
15
|
else
|
16
|
-
puts
|
16
|
+
puts "https://github.com/gosu/gosu/wiki/Getting-Started-on-Linux"
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
require
|
21
|
-
require
|
20
|
+
require "mkmf"
|
21
|
+
require "fileutils"
|
22
22
|
|
23
23
|
# Silence internal deprecation warnings in Gosu.
|
24
24
|
$CFLAGS << " -DGOSU_DEPRECATED="
|
@@ -33,25 +33,25 @@ $CXXFLAGS ||= ""
|
|
33
33
|
$CXXFLAGS << " -std=gnu++17 -Dregister="
|
34
34
|
|
35
35
|
# Make Gosu's own header files and all of its dependencies available to C++ source files.
|
36
|
-
$INCFLAGS << " -I../../include -I../../dependencies/stb -I../../dependencies/utf8proc -I../../dependencies/SDL_sound"
|
36
|
+
$INCFLAGS << " -I../../include -I../../dependencies/stb -I../../dependencies/utf8proc -I../../dependencies/SDL_sound -I../../dependencies/mojoAL"
|
37
37
|
|
38
38
|
if windows
|
39
39
|
# We statically compile utf8proc into the Gosu binary.
|
40
40
|
# This macro is required to avoid errors about dllexport/dllimport mismatches.
|
41
|
-
$CFLAGS << " -DUTF8PROC_STATIC"
|
42
|
-
$CXXFLAGS << " -DUTF8PROC_STATIC"
|
41
|
+
$CFLAGS << " -DUTF8PROC_STATIC -DAL_LIBTYPE_STATIC"
|
42
|
+
$CXXFLAGS << " -DUTF8PROC_STATIC -DAL_LIBTYPE_STATIC"
|
43
43
|
|
44
44
|
# Define UNICODE to use the Unicode-aware variants of all Win32 API functions.
|
45
45
|
$CXXFLAGS << " -DUNICODE"
|
46
46
|
|
47
47
|
# Use the bundled versions of SDL 2 and open_al.
|
48
|
-
$INCFLAGS << " -I../../dependencies/
|
49
|
-
if RbConfig::CONFIG[
|
50
|
-
$LDFLAGS << " -L../../dependencies/
|
48
|
+
$INCFLAGS << " -I../../dependencies/SDL/include"
|
49
|
+
if RbConfig::CONFIG["arch"] =~ /x64-/
|
50
|
+
$LDFLAGS << " -L../../dependencies/SDL/lib/x64"
|
51
51
|
else
|
52
|
-
$LDFLAGS << " -L../../dependencies/
|
52
|
+
$LDFLAGS << " -L../../dependencies/SDL/lib/x86"
|
53
53
|
end
|
54
|
-
$LDFLAGS << " -lgdi32 -lwinmm -ldwmapi -lOpenGL32 -
|
54
|
+
$LDFLAGS << " -lgdi32 -lwinmm -ldwmapi -lOpenGL32 -lSDL2"
|
55
55
|
# Link libstdc++ statically to avoid having another DLL dependency when using Ocra.
|
56
56
|
$LDFLAGS << " -static-libstdc++"
|
57
57
|
elsif macos
|
@@ -66,49 +66,48 @@ elsif macos
|
|
66
66
|
# Disable an error that is disabled by default and prevents Gosu from building with universal Ruby:
|
67
67
|
# https://trac.macports.org/ticket/58255 / https://github.com/gosu/gosu/issues/424
|
68
68
|
$CXXFLAGS << " -Wno-reserved-user-defined-literal"
|
69
|
-
|
69
|
+
|
70
70
|
# Dependencies.
|
71
71
|
$CFLAGS << " #{`sdl2-config --cflags`.chomp}"
|
72
72
|
$CXXFLAGS << " #{`sdl2-config --cflags`.chomp}"
|
73
73
|
# Prefer statically linking SDL 2.
|
74
|
-
$LDFLAGS
|
74
|
+
$LDFLAGS << " #{`sdl2-config --static-libs`.chomp} -framework OpenGL -framework Metal"
|
75
75
|
# And yet another hack: `sdl2-config --static-libs` uses `-lSDL2` instead of linking to the static library,
|
76
76
|
# even if it exists. -> Manually replace it. (Ugh!)
|
77
|
-
|
78
|
-
|
77
|
+
%w(/usr/local/lib/libSDL2.a /opt/homebrew/opt/sdl2/lib/libSDL2.a).each do |static_lib|
|
78
|
+
$LDFLAGS.sub! " -lSDL2 ", " #{static_lib} " if File.exist? static_lib
|
79
|
+
end
|
80
|
+
|
79
81
|
# Disable building of 32-bit slices in Apple's Ruby.
|
80
82
|
# (RbConfig::CONFIG['CXXFLAGS'] on 10.11: -arch x86_64 -arch i386 -g -Os -pipe)
|
81
83
|
$CFLAGS.gsub! "-arch i386", ""
|
82
84
|
$CXXFLAGS.gsub! "-arch i386", ""
|
83
85
|
$LDFLAGS.gsub! "-arch i386", ""
|
84
86
|
$ARCH_FLAG.gsub! "-arch i386", ""
|
85
|
-
CONFIG[
|
87
|
+
CONFIG["LDSHARED"].gsub! "-arch i386", ""
|
86
88
|
else
|
87
89
|
if /BCM2708/ =~ `cat /proc/cpuinfo`
|
88
90
|
$INCFLAGS << " -I/opt/vc/include/GLES"
|
89
91
|
$INCFLAGS << " -I/opt/vc/include"
|
90
92
|
$LDFLAGS << " -L/opt/vc/lib"
|
91
93
|
$LDFLAGS << " -lGLESv1_CM"
|
92
|
-
$CFLAGS
|
94
|
+
$CFLAGS << " -DGOSU_IS_OPENGLES"
|
93
95
|
$CXXFLAGS << " -DGOSU_IS_OPENGLES"
|
94
96
|
else
|
95
|
-
pkg_config
|
97
|
+
pkg_config "gl"
|
96
98
|
end
|
97
99
|
|
98
|
-
pkg_config
|
99
|
-
pkg_config
|
100
|
-
pkg_config
|
101
|
-
pkg_config
|
102
|
-
pkg_config
|
103
|
-
pkg_config 'fontconfig'
|
104
|
-
|
105
|
-
have_header 'AL/al.h' if have_library('openal')
|
100
|
+
pkg_config "sdl2"
|
101
|
+
pkg_config "vorbisfile"
|
102
|
+
pkg_config "sndfile"
|
103
|
+
pkg_config "libmpg123"
|
104
|
+
pkg_config "fontconfig"
|
106
105
|
end
|
107
106
|
|
108
107
|
# Because Ruby will only compile source file in the src/ folder, but our dependencies are
|
109
108
|
# stored in dependencies/, we need to create symlinks for all the .c files. This is terrible,
|
110
109
|
# but still seems better than putting everything into the same folder to begin with.
|
111
|
-
Dir.glob(
|
110
|
+
Dir.glob("../../dependencies/**/*.c").each do |dep|
|
112
111
|
File.open("../../src/#{File.basename dep}", "w") do |shim|
|
113
112
|
shim.puts "#include \"#{File.expand_path dep}\""
|
114
113
|
end
|
data/include/Gosu/Audio.hpp
CHANGED
@@ -1,141 +1,126 @@
|
|
1
|
-
//! \file Audio.hpp
|
2
|
-
//! Contains all the classes of Gosu's audio system.
|
3
|
-
|
4
1
|
#pragma once
|
5
2
|
|
6
3
|
#include <Gosu/Fwd.hpp>
|
7
4
|
#include <Gosu/IO.hpp>
|
8
5
|
#include <Gosu/Platform.hpp>
|
6
|
+
#include <Gosu/Utility.hpp>
|
9
7
|
#include <memory>
|
10
8
|
#include <string>
|
11
9
|
|
12
10
|
namespace Gosu
|
13
11
|
{
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
/// Sample::play returns a Channel that represents the sound being played.
|
13
|
+
/// This object can be used to stop or influence sounds as they are played, or to check whether
|
14
|
+
/// playback has finished.
|
17
15
|
class Channel
|
18
16
|
{
|
19
|
-
mutable int
|
17
|
+
mutable int m_channel, m_token;
|
20
18
|
|
21
19
|
public:
|
22
|
-
|
20
|
+
/// This creates an "empty" Channel which is expired and cannot be resumed.
|
23
21
|
Channel();
|
24
|
-
|
22
|
+
/// For internal use only.
|
25
23
|
Channel(int channel, int token);
|
26
|
-
|
27
|
-
|
24
|
+
|
25
|
+
/// For internal use only.
|
28
26
|
int current_channel() const;
|
29
|
-
|
27
|
+
|
30
28
|
bool playing() const;
|
31
29
|
bool paused() const;
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
/// Pauses this instance to be resumed afterwards.
|
31
|
+
/// Avoid leaving samples paused for too long, as they will still occupy one of Gosu's
|
32
|
+
/// limited channels.
|
35
33
|
void pause();
|
36
34
|
void resume();
|
37
|
-
|
38
|
-
|
35
|
+
/// Stops this m_channel if the sample is still being played.
|
36
|
+
/// If this method is called when playback has finished, it has no effect.
|
39
37
|
void stop();
|
40
38
|
|
41
|
-
|
39
|
+
/// @param volume Can be anything from 0.0 (silence) to 1.0 (full volume).
|
42
40
|
void set_volume(double volume);
|
43
|
-
|
41
|
+
/// @param pan Can be anything from -1.0 (left) to 1.0 (right).
|
44
42
|
void set_pan(double pan);
|
45
|
-
|
43
|
+
/// @param speed Use 1.0 for normal playback speed.
|
46
44
|
void set_speed(double speed);
|
47
45
|
};
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
//! parameters. Use samples for everything that's not music.
|
46
|
+
|
47
|
+
/// A sample is a short sound that is completely loaded in memory, can be played multiple times
|
48
|
+
/// at once, and offers very flexible playback parameters.
|
52
49
|
class Sample
|
53
50
|
{
|
54
51
|
struct Impl;
|
55
|
-
std::shared_ptr<Impl>
|
52
|
+
std::shared_ptr<Impl> m_impl;
|
56
53
|
|
57
54
|
public:
|
58
|
-
|
55
|
+
/// Constructs an empty sample that is inaudible when played.
|
59
56
|
Sample();
|
60
|
-
|
61
|
-
|
62
|
-
|
57
|
+
|
58
|
+
/// Constructs a sample that can be played on the specified audio
|
59
|
+
/// system and loads the sample from a file.
|
63
60
|
explicit Sample(const std::string& filename);
|
64
|
-
|
65
|
-
|
66
|
-
|
61
|
+
|
62
|
+
/// Constructs a sample that can be played on the specified audio
|
63
|
+
/// system and loads the sample data from a stream.
|
67
64
|
explicit Sample(Reader reader);
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
//! and can accept very high
|
85
|
-
//! or low values. Use 1.0 for normal playback speed.
|
86
|
-
Channel play_pan(double pan, double volume = 1, double speed = 1,
|
87
|
-
bool looping = false) const;
|
65
|
+
|
66
|
+
/// Plays the sample without panning.
|
67
|
+
/// @param volume Can be anything from 0.0 (silence) to 1.0 (full volume).
|
68
|
+
/// @param speed Playback speed is only limited by the underlying audio library,
|
69
|
+
/// and can accept very high or low values. Use 1.0 for normal playback speed.
|
70
|
+
Channel play(double volume = 1.0, double speed = 1.0, bool looping = false) const;
|
71
|
+
|
72
|
+
/// Plays the sample with panning. Even if pan is 0.0, the sample will
|
73
|
+
/// not be as loud as if it were played by calling play() due to the
|
74
|
+
/// way the panning works.
|
75
|
+
/// @param pan Can be anything from -1.0 (left) to 1.0 (right).
|
76
|
+
/// @param volume Can be anything from 0.0 (silence) to 1.0 (full volume).
|
77
|
+
/// @param speed Playback speed is only limited by by the underlying audio library,
|
78
|
+
/// and can accept very high or low values. Use 1.0 for normal playback speed.
|
79
|
+
Channel play_pan(double pan, double volume = 1.0, double speed = 1.0,
|
80
|
+
bool looping = false) const;
|
88
81
|
};
|
89
82
|
|
90
|
-
|
91
|
-
|
92
|
-
class Song
|
83
|
+
/// Songs are less flexible than Samples. Only one Song can be played at any given time,
|
84
|
+
/// and there is no way to control its pan (stereo position) or speed.
|
85
|
+
class Song : private Noncopyable
|
93
86
|
{
|
94
87
|
struct Impl;
|
95
|
-
std::unique_ptr<Impl>
|
96
|
-
|
97
|
-
// Non-movable to avoid dangling internal references.
|
98
|
-
Song(Song&&) = delete;
|
99
|
-
// Non-movable to avoid dangling internal references.
|
100
|
-
Song& operator=(Song&&) = delete;
|
88
|
+
std::unique_ptr<Impl> m_impl;
|
101
89
|
|
102
90
|
public:
|
103
|
-
|
104
|
-
|
105
|
-
//! The file type is determined by the filename.
|
91
|
+
/// Constructs a song that can be played on the provided audio system and loads the song
|
92
|
+
/// from a file. The file type is determined by the filename.
|
106
93
|
explicit Song(const std::string& filename);
|
107
|
-
|
108
|
-
|
109
|
-
|
94
|
+
|
95
|
+
/// Constructs a song of the specified type that can be played on the
|
96
|
+
/// provided audio system and loads the song data from a stream.
|
110
97
|
explicit Song(Reader reader);
|
111
|
-
|
98
|
+
|
112
99
|
~Song();
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
//! playing.
|
100
|
+
|
101
|
+
/// Returns the song currently being played or paused, or 0 if no song has been played yet
|
102
|
+
/// or the last song has finished playing.
|
117
103
|
static Song* current_song();
|
118
104
|
|
119
|
-
|
120
|
-
|
105
|
+
/// Starts or resumes playback of the song. This will stop all other songs and set the
|
106
|
+
/// current song to this object.
|
121
107
|
void play(bool looping = false);
|
122
|
-
|
123
|
-
|
108
|
+
/// Pauses playback of the song. Song::current_song() will still refer to this song, but
|
109
|
+
/// playing() will return false.
|
124
110
|
void pause();
|
125
|
-
|
126
|
-
//! mode.
|
111
|
+
/// Returns true if the song is the current song, but in paused mode.
|
127
112
|
bool paused() const;
|
128
|
-
|
129
|
-
|
113
|
+
/// Stops playback of this song if it is currently played or paused.
|
114
|
+
/// Afterwards, current_song will return nullptr.
|
130
115
|
void stop();
|
131
|
-
|
116
|
+
/// Returns true if the song is currently playing.
|
132
117
|
bool playing() const;
|
133
|
-
|
118
|
+
/// Returns the current volume of the song.
|
134
119
|
double volume() const;
|
135
|
-
|
120
|
+
/// @param volume Can be anything from 0.0 (silence) to 1.0 (full volume).
|
136
121
|
void set_volume(double volume);
|
137
|
-
|
138
|
-
|
122
|
+
|
123
|
+
/// Called every tick by Window to feed new audio data to OpenAL.
|
139
124
|
static void update();
|
140
125
|
};
|
141
126
|
}
|
data/include/Gosu/Color.hpp
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
//! \file Color.hpp
|
2
|
-
//! Interface of the Color class.
|
3
|
-
|
4
1
|
#pragma once
|
5
2
|
|
6
3
|
#include <Gosu/Platform.hpp>
|
@@ -8,154 +5,113 @@
|
|
8
5
|
|
9
6
|
namespace Gosu
|
10
7
|
{
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
//! The four-byte layout in memory is RGBA. On Big-Endian machines the unsigned int will look
|
15
|
-
//! like 0xrrggbbaa, on Little-Endian machines it is 0xaabbggrr.
|
16
|
-
class Color
|
8
|
+
/// Represents an RGBA color value with 8 bit for each channel.
|
9
|
+
/// Can be implicitly constructed from literals of the form 0xaarrggbb.
|
10
|
+
struct Color
|
17
11
|
{
|
18
|
-
std::uint32_t rep;
|
19
|
-
#ifdef GOSU_IS_LITTLE_ENDIAN
|
20
|
-
enum { RED_OFFSET = 0, GREEN_OFFSET = 8, BLUE_OFFSET = 16, ALPHA_OFFSET = 24 };
|
21
|
-
#else
|
22
|
-
enum { RED_OFFSET = 24, GREEN_OFFSET = 16, BLUE_OFFSET = 8, ALPHA_OFFSET = 0 };
|
23
|
-
#endif
|
24
|
-
|
25
|
-
public:
|
26
|
-
typedef std::uint8_t Channel;
|
27
12
|
static const unsigned GL_FORMAT = 0x1908; // GL_RGBA
|
28
|
-
|
29
|
-
//! The default constructor does not initialize the color to any value.
|
30
|
-
Color()
|
31
|
-
{
|
32
|
-
}
|
33
|
-
|
34
|
-
//! Conversion constructor for literals of the form 0xaarrggbb.
|
35
|
-
Color(unsigned argb)
|
36
|
-
: Color((argb >> 24) & 0xff, (argb >> 16) & 0xff, (argb >> 8) & 0xff, (argb >> 0) & 0xff)
|
37
|
-
{
|
38
|
-
}
|
39
|
-
|
40
|
-
Color(Channel red, Channel green, Channel blue)
|
41
|
-
: Color(0xff, red, green, blue)
|
42
|
-
{
|
43
|
-
}
|
44
|
-
|
45
|
-
Color(Channel alpha, Channel red, Channel green, Channel blue)
|
46
|
-
{
|
47
|
-
rep = (alpha << ALPHA_OFFSET) | (red << RED_OFFSET) |
|
48
|
-
(green << GREEN_OFFSET) | (blue << BLUE_OFFSET);
|
49
|
-
}
|
50
|
-
|
51
|
-
//! Constructs a color from the given hue/saturation/value triple.
|
52
|
-
//! Ranges of these values are given as 0..360, 0..1, and 0..1, respectively.
|
53
|
-
static Color from_hsv(double h, double s, double v);
|
54
|
-
|
55
|
-
//! Constructs a color from the given hue/saturation/value triple.
|
56
|
-
//! Ranges of these values are given as 0..360, 0..1, and 0..1, respectively.
|
57
|
-
static Color from_ahsv(Channel alpha, double h, double s, double v);
|
58
13
|
|
59
|
-
|
60
|
-
{
|
61
|
-
return static_cast<Channel>(rep >> RED_OFFSET);
|
62
|
-
}
|
14
|
+
typedef std::uint8_t Channel;
|
63
15
|
|
64
|
-
Channel green
|
65
|
-
{
|
66
|
-
return static_cast<Channel>(rep >> GREEN_OFFSET);
|
67
|
-
}
|
16
|
+
Channel red, green, blue, alpha;
|
68
17
|
|
69
|
-
|
18
|
+
constexpr Color()
|
19
|
+
: red{0},
|
20
|
+
green{0},
|
21
|
+
blue{0},
|
22
|
+
alpha{0}
|
70
23
|
{
|
71
|
-
return static_cast<Channel>(rep >> BLUE_OFFSET);
|
72
24
|
}
|
73
25
|
|
74
|
-
|
26
|
+
/// Conversion constructor for literals of the form 0xaarrggbb.
|
27
|
+
// NOLINTNEXTLINE: We want to allow implicit conversions.
|
28
|
+
constexpr Color(std::uint32_t argb)
|
29
|
+
: red{static_cast<Channel>(argb >> 16)},
|
30
|
+
green{static_cast<Channel>(argb >> 8)},
|
31
|
+
blue{static_cast<Channel>(argb >> 0)},
|
32
|
+
alpha{static_cast<Channel>(argb >> 24)}
|
75
33
|
{
|
76
|
-
return static_cast<Channel>(rep >> ALPHA_OFFSET);
|
77
34
|
}
|
78
35
|
|
79
|
-
|
36
|
+
constexpr Color(Channel red, Channel green, Channel blue)
|
37
|
+
: red{red},
|
38
|
+
green{green},
|
39
|
+
blue{blue},
|
40
|
+
alpha{255}
|
80
41
|
{
|
81
|
-
rep &= ~(0xff << RED_OFFSET);
|
82
|
-
rep |= value << RED_OFFSET;
|
83
42
|
}
|
84
43
|
|
85
|
-
|
44
|
+
Color with_alpha(Channel new_alpha)
|
86
45
|
{
|
87
|
-
|
88
|
-
|
46
|
+
Color result = *this;
|
47
|
+
result.alpha = new_alpha;
|
48
|
+
return result;
|
89
49
|
}
|
90
50
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
rep |= value << BLUE_OFFSET;
|
95
|
-
}
|
96
|
-
|
97
|
-
void set_alpha(Channel value)
|
98
|
-
{
|
99
|
-
rep &= ~(0xff << ALPHA_OFFSET);
|
100
|
-
rep |= value << ALPHA_OFFSET;
|
101
|
-
}
|
51
|
+
/// Constructs a color from the given hue/saturation/value triple.
|
52
|
+
/// Ranges of these values are given as 0..360, 0..1, and 0..1, respectively.
|
53
|
+
static Color from_hsv(double h, double s, double v);
|
102
54
|
|
103
|
-
|
55
|
+
/// Returns the hue of the color, in the usual range of 0..360.
|
104
56
|
double hue() const;
|
105
|
-
|
106
|
-
|
57
|
+
|
58
|
+
/// Changes the current color so hue() will return h.
|
107
59
|
void set_hue(double h);
|
108
|
-
|
109
|
-
|
60
|
+
|
61
|
+
/// Returns the saturation of the color, in the range of 0..1.
|
110
62
|
double saturation() const;
|
111
|
-
|
112
|
-
|
63
|
+
|
64
|
+
/// Changes the current color so saturation() will return s.
|
113
65
|
void set_saturation(double s);
|
114
|
-
|
115
|
-
|
66
|
+
|
67
|
+
/// Returns the value (brightness) of the color, in the range of 0..1.
|
116
68
|
double value() const;
|
117
|
-
|
118
|
-
|
69
|
+
|
70
|
+
/// Changes the current color so value() will return v.
|
119
71
|
void set_value(double v);
|
120
72
|
|
121
|
-
|
122
|
-
std::uint32_t argb() const { return alpha
|
73
|
+
/// Returns the color in 0xaarrggbb representation.
|
74
|
+
std::uint32_t argb() const { return alpha << 24 | red << 16 | green << 8 | blue; }
|
75
|
+
|
76
|
+
/// Returns the color in 0x00bbggrr representation. Useful for Win32 programming.
|
77
|
+
std::uint32_t bgr() const { return blue << 16 | green << 8 | red; }
|
78
|
+
|
79
|
+
/// Returns the color in 0xaabbggrr representation.
|
80
|
+
std::uint32_t abgr() const { return alpha << 24 | blue << 16 | green << 8 | red; }
|
123
81
|
|
124
|
-
|
125
|
-
std::uint32_t
|
82
|
+
/// Returns the internal representation of the color (RGBA in memory).
|
83
|
+
std::uint32_t gl() const { return *reinterpret_cast<const std::uint32_t*>(this); }
|
126
84
|
|
127
|
-
//! Returns the color in 0xaabbggrr representation.
|
128
|
-
std::uint32_t abgr() const { return alpha() << 24 | blue() << 16 | green() << 8 | red(); }
|
129
|
-
|
130
|
-
//! Returns the internal representation of the color (RGBA in memory).
|
131
|
-
std::uint32_t gl() const { return rep; }
|
132
|
-
|
133
85
|
static const Color NONE;
|
134
86
|
static const Color BLACK;
|
135
87
|
static const Color GRAY;
|
136
88
|
static const Color WHITE;
|
137
|
-
|
89
|
+
|
90
|
+
/// Same as Color::CYAN.
|
138
91
|
static const Color AQUA;
|
139
92
|
static const Color RED;
|
140
93
|
static const Color GREEN;
|
141
94
|
static const Color BLUE;
|
142
95
|
static const Color YELLOW;
|
143
96
|
static const Color FUCHSIA;
|
97
|
+
/// Same as Color::AQUA.
|
144
98
|
static const Color CYAN;
|
145
99
|
};
|
146
|
-
|
100
|
+
|
101
|
+
// Ensure that we can pass vectors of Gosu::Color straight to OpenGL and back.
|
102
|
+
static_assert(sizeof(Color) == sizeof(std::uint32_t));
|
103
|
+
|
147
104
|
#ifndef SWIG
|
148
105
|
inline bool operator<(Color a, Color b) { return a.gl() < b.gl(); }
|
149
106
|
inline bool operator==(Color a, Color b) { return a.gl() == b.gl(); }
|
150
107
|
inline bool operator!=(Color a, Color b) { return a.gl() != b.gl(); }
|
151
108
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
//! and then multiplied with each other.
|
109
|
+
/// Interpolates linearly between two colors, with a given weight towards
|
110
|
+
/// the second color.
|
111
|
+
Color lerp(Color a, Color b, double t = 0.5);
|
112
|
+
|
113
|
+
/// Combines two colors as if their channels were mapped to the 0..1 range
|
114
|
+
/// and then multiplied with each other.
|
159
115
|
Color multiply(Color a, Color b);
|
160
116
|
#endif
|
161
117
|
}
|