SDLRuby 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -19
- data/LICENSE.txt +21 -21
- data/README.md +31 -31
- data/Rakefile +12 -12
- data/SDLRuby.gemspec +38 -0
- data/examples/alert.rb +8 -0
- data/examples/window.rb +7 -0
- data/lib/SDLRuby/event/accessor.rb +2 -2
- data/lib/SDLRuby/event.rb +101 -101
- data/lib/SDLRuby/image/include/SDL_image.h.rb +61 -61
- data/lib/SDLRuby/mixer/include/SDL_mixer.h.rb +95 -95
- data/lib/SDLRuby/rw/operational.rb +116 -0
- data/lib/SDLRuby/rw/read_closure.rb +28 -0
- data/lib/SDLRuby/rw/seek_closure.rb +22 -0
- data/lib/SDLRuby/rw/size_closure.rb +21 -0
- data/lib/SDLRuby/rw/write_closure.rb +21 -0
- data/lib/SDLRuby/rw_ops/mem_close.rb +27 -0
- data/lib/SDLRuby/rw_ops/rw_object.rb +13 -107
- data/lib/SDLRuby/rw_ops.rb +40 -165
- data/lib/SDLRuby/sdl/include/SDL.h.rb +44 -44
- data/lib/SDLRuby/sdl/include/SDL_audio.h.rb +160 -160
- data/lib/SDLRuby/sdl/include/SDL_blendmode.h.rb +30 -30
- data/lib/SDLRuby/sdl/include/SDL_clipboard.h.rb +10 -10
- data/lib/SDLRuby/sdl/include/SDL_config.h.rb +13 -13
- data/lib/SDLRuby/sdl/include/SDL_cpuinfo.h.rb +27 -27
- data/lib/SDLRuby/sdl/include/SDL_endian.h.rb +12 -12
- data/lib/SDLRuby/sdl/include/SDL_error.h.rb +28 -28
- data/lib/SDLRuby/sdl/include/SDL_events.h.rb +472 -472
- data/lib/SDLRuby/sdl/include/SDL_filesystem.h.rb +6 -6
- data/lib/SDLRuby/sdl/include/SDL_gamecontroller.h.rb +147 -147
- data/lib/SDLRuby/sdl/include/SDL_gesture.h.rb +12 -12
- data/lib/SDLRuby/sdl/include/SDL_guid.h.rb +13 -13
- data/lib/SDLRuby/sdl/include/SDL_hints.h.rb +199 -199
- data/lib/SDLRuby/sdl/include/SDL_joystick.h.rb +131 -131
- data/lib/SDLRuby/sdl/include/SDL_keyboard.h.rb +35 -35
- data/lib/SDLRuby/sdl/include/SDL_keycode.h.rb +292 -292
- data/lib/SDLRuby/sdl/include/SDL_locale.h.rb +13 -13
- data/lib/SDLRuby/sdl/include/SDL_main.h.rb +3 -3
- data/lib/SDLRuby/sdl/include/SDL_messagebox.h.rb +58 -58
- data/lib/SDLRuby/sdl/include/SDL_misc.h.rb +5 -5
- data/lib/SDLRuby/sdl/include/SDL_mouse.h.rb +57 -57
- data/lib/SDLRuby/sdl/include/SDL_pixels.h.rb +285 -285
- data/lib/SDLRuby/sdl/include/SDL_platform.h.rb +3 -3
- data/lib/SDLRuby/sdl/include/SDL_power.h.rb +6 -6
- data/lib/SDLRuby/sdl/include/SDL_rect.h.rb +46 -46
- data/lib/SDLRuby/sdl/include/SDL_render.h.rb +131 -131
- data/lib/SDLRuby/sdl/include/SDL_revision.h.rb +2 -2
- data/lib/SDLRuby/sdl/include/SDL_rwops.h.rb +78 -78
- data/lib/SDLRuby/sdl/include/SDL_scancode.h.rb +252 -252
- data/lib/SDLRuby/sdl/include/SDL_sensor.h.rb +25 -25
- data/lib/SDLRuby/sdl/include/SDL_shape.h.rb +40 -40
- data/lib/SDLRuby/sdl/include/SDL_stdinc.h.rb +62 -62
- data/lib/SDLRuby/sdl/include/SDL_surface.h.rb +100 -100
- data/lib/SDLRuby/sdl/include/SDL_system.h.rb +6 -6
- data/lib/SDLRuby/sdl/include/SDL_syswm.h.rb +10 -10
- data/lib/SDLRuby/sdl/include/SDL_timer.h.rb +21 -21
- data/lib/SDLRuby/sdl/include/SDL_touch.h.rb +15 -15
- data/lib/SDLRuby/sdl/include/SDL_types.h.rb +3 -3
- data/lib/SDLRuby/sdl/include/SDL_version.h.rb +14 -14
- data/lib/SDLRuby/sdl/include/SDL_video.h.rb +264 -264
- data/lib/SDLRuby/sdl.rb +6 -6
- data/lib/SDLRuby/ttf/include/SDL_ttf.h.rb +54 -54
- data/lib/SDLRuby/version.rb +5 -5
- data/lib/SDLRuby/window/surfacer.rb +37 -37
- data/lib/SDLRuby.rb +32 -16
- data/sig/SDLRuby.rbs +4 -4
- data/sig/lib/SDLRuby/event/accessor.rbs +157 -157
- data/sig/lib/SDLRuby/event/type.rbs +67 -67
- data/sig/lib/SDLRuby/event.rbs +47 -47
- data/sig/lib/SDLRuby/keyboard.rbs +25 -25
- data/sig/lib/SDLRuby/mouse.rbs +35 -35
- data/sig/lib/SDLRuby/sdl.rbs +655 -655
- data/sig/lib/SDLRuby/timer.rbs +7 -7
- metadata +12 -3
@@ -1,95 +1,95 @@
|
|
1
|
-
module SDLRuby::Mixer
|
2
|
-
typealias "Mix_Music", "struct _Mix_Music"
|
3
|
-
typealias "MIX_InitFlags", "int"
|
4
|
-
typealias "Mix_Fading", "int"
|
5
|
-
typealias "Mix_MusicType", "int"
|
6
|
-
extern "const SDL_version * Mix_Linked_Version(void)"
|
7
|
-
extern "int Mix_Init(int flags)"
|
8
|
-
extern "void Mix_Quit(void)"
|
9
|
-
extern "int Mix_OpenAudio(int frequency, Uint16 format, int channels, int chunksize)"
|
10
|
-
extern "int Mix_OpenAudioDevice(int frequency, Uint16 format, int channels, int chunksize, const char*device, int allowed_changes)"
|
11
|
-
extern "int Mix_QuerySpec(int *frequency, Uint16 *format, int *channels)"
|
12
|
-
extern "int Mix_AllocateChannels(int numchans)"
|
13
|
-
extern "Mix_Chunk * Mix_LoadWAV_RW(SDL_RWops *src, int freesrc)"
|
14
|
-
extern "Mix_Chunk * Mix_LoadWAV(const char *file)"
|
15
|
-
extern "Mix_Music * Mix_LoadMUS(const char *file)"
|
16
|
-
extern "Mix_Music * Mix_LoadMUS_RW(SDL_RWops *src, int freesrc)"
|
17
|
-
extern "Mix_Music * Mix_LoadMUSType_RW(SDL_RWops *src, Mix_MusicType type, int freesrc)"
|
18
|
-
extern "Mix_Chunk * Mix_QuickLoad_WAV(Uint8 *mem)"
|
19
|
-
extern "Mix_Chunk * Mix_QuickLoad_RAW(Uint8 *mem, Uint32 len)"
|
20
|
-
extern "void Mix_FreeChunk(Mix_Chunk *chunk)"
|
21
|
-
extern "void Mix_FreeMusic(Mix_Music *music)"
|
22
|
-
extern "int Mix_GetNumChunkDecoders(void)"
|
23
|
-
extern "const char * Mix_GetChunkDecoder(int index)"
|
24
|
-
extern "SDL_bool Mix_HasChunkDecoder(const char *name)"
|
25
|
-
extern "int Mix_GetNumMusicDecoders(void)"
|
26
|
-
extern "const char * Mix_GetMusicDecoder(int index)"
|
27
|
-
extern "SDL_bool Mix_HasMusicDecoder(const char *name)"
|
28
|
-
extern "Mix_MusicType Mix_GetMusicType(const Mix_Music *music)"
|
29
|
-
extern "const char * Mix_GetMusicTitle(const Mix_Music *music)"
|
30
|
-
extern "const char * Mix_GetMusicTitleTag(const Mix_Music *music)"
|
31
|
-
extern "const char * Mix_GetMusicArtistTag(const Mix_Music *music)"
|
32
|
-
extern "const char * Mix_GetMusicAlbumTag(const Mix_Music *music)"
|
33
|
-
extern "const char * Mix_GetMusicCopyrightTag(const Mix_Music *music)"
|
34
|
-
extern "void * Mix_GetMusicHookData(void)"
|
35
|
-
extern "int Mix_RegisterEffect(int chan, Mix_EffectFunc_t f, Mix_EffectDone_t d, void *arg)"
|
36
|
-
extern "int Mix_UnregisterEffect(int channel, Mix_EffectFunc_t f)"
|
37
|
-
extern "int Mix_UnregisterAllEffects(int channel)"
|
38
|
-
extern "int Mix_SetPanning(int channel, Uint8 left, Uint8 right)"
|
39
|
-
extern "int Mix_SetPosition(int channel, Sint16 angle, Uint8 distance)"
|
40
|
-
extern "int Mix_SetDistance(int channel, Uint8 distance)"
|
41
|
-
extern "int Mix_SetReverseStereo(int channel, int flip)"
|
42
|
-
extern "int Mix_ReserveChannels(int num)"
|
43
|
-
extern "int Mix_GroupChannel(int which, int tag)"
|
44
|
-
extern "int Mix_GroupChannels(int from, int to, int tag)"
|
45
|
-
extern "int Mix_GroupAvailable(int tag)"
|
46
|
-
extern "int Mix_GroupCount(int tag)"
|
47
|
-
extern "int Mix_GroupOldest(int tag)"
|
48
|
-
extern "int Mix_GroupNewer(int tag)"
|
49
|
-
extern "int Mix_PlayChannel(int channel, Mix_Chunk *chunk, int loops)"
|
50
|
-
extern "int Mix_PlayChannelTimed(int channel, Mix_Chunk *chunk, int loops, int ticks)"
|
51
|
-
extern "int Mix_PlayMusic(Mix_Music *music, int loops)"
|
52
|
-
extern "int Mix_FadeInMusic(Mix_Music *music, int loops, int ms)"
|
53
|
-
extern "int Mix_FadeInMusicPos(Mix_Music *music, int loops, int ms, double position)"
|
54
|
-
extern "int Mix_FadeInChannel(int channel, Mix_Chunk *chunk, int loops, int ms)"
|
55
|
-
extern "int Mix_FadeInChannelTimed(int channel, Mix_Chunk *chunk, int loops, int ms, int ticks)"
|
56
|
-
extern "int Mix_Volume(int channel, int volume)"
|
57
|
-
extern "int Mix_VolumeChunk(Mix_Chunk *chunk, int volume)"
|
58
|
-
extern "int Mix_VolumeMusic(int volume)"
|
59
|
-
extern "int Mix_GetMusicVolume(Mix_Music *music)"
|
60
|
-
extern "int Mix_MasterVolume(int volume)"
|
61
|
-
extern "int Mix_HaltChannel(int channel)"
|
62
|
-
extern "int Mix_HaltGroup(int tag)"
|
63
|
-
extern "int Mix_HaltMusic(void)"
|
64
|
-
extern "int Mix_ExpireChannel(int channel, int ticks)"
|
65
|
-
extern "int Mix_FadeOutChannel(int which, int ms)"
|
66
|
-
extern "int Mix_FadeOutGroup(int tag, int ms)"
|
67
|
-
extern "int Mix_FadeOutMusic(int ms)"
|
68
|
-
extern "Mix_Fading Mix_FadingMusic(void)"
|
69
|
-
extern "Mix_Fading Mix_FadingChannel(int which)"
|
70
|
-
extern "void Mix_Pause(int channel)"
|
71
|
-
extern "void Mix_Resume(int channel)"
|
72
|
-
extern "int Mix_Paused(int channel)"
|
73
|
-
extern "void Mix_PauseMusic(void)"
|
74
|
-
extern "void Mix_ResumeMusic(void)"
|
75
|
-
extern "void Mix_RewindMusic(void)"
|
76
|
-
extern "int Mix_PausedMusic(void)"
|
77
|
-
extern "int Mix_ModMusicJumpToOrder(int order)"
|
78
|
-
extern "int Mix_SetMusicPosition(double position)"
|
79
|
-
extern "double Mix_GetMusicPosition(Mix_Music *music)"
|
80
|
-
extern "double Mix_MusicDuration(Mix_Music *music)"
|
81
|
-
extern "double Mix_GetMusicLoopStartTime(Mix_Music *music)"
|
82
|
-
extern "double Mix_GetMusicLoopEndTime(Mix_Music *music)"
|
83
|
-
extern "double Mix_GetMusicLoopLengthTime(Mix_Music *music)"
|
84
|
-
extern "int Mix_Playing(int channel)"
|
85
|
-
extern "int Mix_PlayingMusic(void)"
|
86
|
-
extern "int Mix_SetMusicCMD(const char *command)"
|
87
|
-
extern "int Mix_SetSynchroValue(int value)"
|
88
|
-
extern "int Mix_GetSynchroValue(void)"
|
89
|
-
extern "int Mix_SetSoundFonts(const char *paths)"
|
90
|
-
extern "const char* Mix_GetSoundFonts(void)"
|
91
|
-
extern "int Mix_SetTimidityCfg(const char *path)"
|
92
|
-
extern "const char* Mix_GetTimidityCfg(void)"
|
93
|
-
extern "Mix_Chunk * Mix_GetChunk(int channel)"
|
94
|
-
extern "void Mix_CloseAudio(void)"
|
95
|
-
end
|
1
|
+
module SDLRuby::Mixer
|
2
|
+
typealias "Mix_Music", "struct _Mix_Music"
|
3
|
+
typealias "MIX_InitFlags", "int"
|
4
|
+
typealias "Mix_Fading", "int"
|
5
|
+
typealias "Mix_MusicType", "int"
|
6
|
+
extern "const SDL_version * Mix_Linked_Version(void)"
|
7
|
+
extern "int Mix_Init(int flags)"
|
8
|
+
extern "void Mix_Quit(void)"
|
9
|
+
extern "int Mix_OpenAudio(int frequency, Uint16 format, int channels, int chunksize)"
|
10
|
+
extern "int Mix_OpenAudioDevice(int frequency, Uint16 format, int channels, int chunksize, const char*device, int allowed_changes)"
|
11
|
+
extern "int Mix_QuerySpec(int *frequency, Uint16 *format, int *channels)"
|
12
|
+
extern "int Mix_AllocateChannels(int numchans)"
|
13
|
+
extern "Mix_Chunk * Mix_LoadWAV_RW(SDL_RWops *src, int freesrc)"
|
14
|
+
extern "Mix_Chunk * Mix_LoadWAV(const char *file)"
|
15
|
+
extern "Mix_Music * Mix_LoadMUS(const char *file)"
|
16
|
+
extern "Mix_Music * Mix_LoadMUS_RW(SDL_RWops *src, int freesrc)"
|
17
|
+
extern "Mix_Music * Mix_LoadMUSType_RW(SDL_RWops *src, Mix_MusicType type, int freesrc)"
|
18
|
+
extern "Mix_Chunk * Mix_QuickLoad_WAV(Uint8 *mem)"
|
19
|
+
extern "Mix_Chunk * Mix_QuickLoad_RAW(Uint8 *mem, Uint32 len)"
|
20
|
+
extern "void Mix_FreeChunk(Mix_Chunk *chunk)"
|
21
|
+
extern "void Mix_FreeMusic(Mix_Music *music)"
|
22
|
+
extern "int Mix_GetNumChunkDecoders(void)"
|
23
|
+
extern "const char * Mix_GetChunkDecoder(int index)"
|
24
|
+
extern "SDL_bool Mix_HasChunkDecoder(const char *name)"
|
25
|
+
extern "int Mix_GetNumMusicDecoders(void)"
|
26
|
+
extern "const char * Mix_GetMusicDecoder(int index)"
|
27
|
+
extern "SDL_bool Mix_HasMusicDecoder(const char *name)"
|
28
|
+
extern "Mix_MusicType Mix_GetMusicType(const Mix_Music *music)"
|
29
|
+
extern "const char * Mix_GetMusicTitle(const Mix_Music *music)"
|
30
|
+
extern "const char * Mix_GetMusicTitleTag(const Mix_Music *music)"
|
31
|
+
extern "const char * Mix_GetMusicArtistTag(const Mix_Music *music)"
|
32
|
+
extern "const char * Mix_GetMusicAlbumTag(const Mix_Music *music)"
|
33
|
+
extern "const char * Mix_GetMusicCopyrightTag(const Mix_Music *music)"
|
34
|
+
extern "void * Mix_GetMusicHookData(void)"
|
35
|
+
extern "int Mix_RegisterEffect(int chan, Mix_EffectFunc_t f, Mix_EffectDone_t d, void *arg)"
|
36
|
+
extern "int Mix_UnregisterEffect(int channel, Mix_EffectFunc_t f)"
|
37
|
+
extern "int Mix_UnregisterAllEffects(int channel)"
|
38
|
+
extern "int Mix_SetPanning(int channel, Uint8 left, Uint8 right)"
|
39
|
+
extern "int Mix_SetPosition(int channel, Sint16 angle, Uint8 distance)"
|
40
|
+
extern "int Mix_SetDistance(int channel, Uint8 distance)"
|
41
|
+
extern "int Mix_SetReverseStereo(int channel, int flip)"
|
42
|
+
extern "int Mix_ReserveChannels(int num)"
|
43
|
+
extern "int Mix_GroupChannel(int which, int tag)"
|
44
|
+
extern "int Mix_GroupChannels(int from, int to, int tag)"
|
45
|
+
extern "int Mix_GroupAvailable(int tag)"
|
46
|
+
extern "int Mix_GroupCount(int tag)"
|
47
|
+
extern "int Mix_GroupOldest(int tag)"
|
48
|
+
extern "int Mix_GroupNewer(int tag)"
|
49
|
+
extern "int Mix_PlayChannel(int channel, Mix_Chunk *chunk, int loops)"
|
50
|
+
extern "int Mix_PlayChannelTimed(int channel, Mix_Chunk *chunk, int loops, int ticks)"
|
51
|
+
extern "int Mix_PlayMusic(Mix_Music *music, int loops)"
|
52
|
+
extern "int Mix_FadeInMusic(Mix_Music *music, int loops, int ms)"
|
53
|
+
extern "int Mix_FadeInMusicPos(Mix_Music *music, int loops, int ms, double position)"
|
54
|
+
extern "int Mix_FadeInChannel(int channel, Mix_Chunk *chunk, int loops, int ms)"
|
55
|
+
extern "int Mix_FadeInChannelTimed(int channel, Mix_Chunk *chunk, int loops, int ms, int ticks)"
|
56
|
+
extern "int Mix_Volume(int channel, int volume)"
|
57
|
+
extern "int Mix_VolumeChunk(Mix_Chunk *chunk, int volume)"
|
58
|
+
extern "int Mix_VolumeMusic(int volume)"
|
59
|
+
extern "int Mix_GetMusicVolume(Mix_Music *music)"
|
60
|
+
extern "int Mix_MasterVolume(int volume)"
|
61
|
+
extern "int Mix_HaltChannel(int channel)"
|
62
|
+
extern "int Mix_HaltGroup(int tag)"
|
63
|
+
extern "int Mix_HaltMusic(void)"
|
64
|
+
extern "int Mix_ExpireChannel(int channel, int ticks)"
|
65
|
+
extern "int Mix_FadeOutChannel(int which, int ms)"
|
66
|
+
extern "int Mix_FadeOutGroup(int tag, int ms)"
|
67
|
+
extern "int Mix_FadeOutMusic(int ms)"
|
68
|
+
extern "Mix_Fading Mix_FadingMusic(void)"
|
69
|
+
extern "Mix_Fading Mix_FadingChannel(int which)"
|
70
|
+
extern "void Mix_Pause(int channel)"
|
71
|
+
extern "void Mix_Resume(int channel)"
|
72
|
+
extern "int Mix_Paused(int channel)"
|
73
|
+
extern "void Mix_PauseMusic(void)"
|
74
|
+
extern "void Mix_ResumeMusic(void)"
|
75
|
+
extern "void Mix_RewindMusic(void)"
|
76
|
+
extern "int Mix_PausedMusic(void)"
|
77
|
+
extern "int Mix_ModMusicJumpToOrder(int order)"
|
78
|
+
extern "int Mix_SetMusicPosition(double position)"
|
79
|
+
extern "double Mix_GetMusicPosition(Mix_Music *music)"
|
80
|
+
extern "double Mix_MusicDuration(Mix_Music *music)"
|
81
|
+
extern "double Mix_GetMusicLoopStartTime(Mix_Music *music)"
|
82
|
+
extern "double Mix_GetMusicLoopEndTime(Mix_Music *music)"
|
83
|
+
extern "double Mix_GetMusicLoopLengthTime(Mix_Music *music)"
|
84
|
+
extern "int Mix_Playing(int channel)"
|
85
|
+
extern "int Mix_PlayingMusic(void)"
|
86
|
+
extern "int Mix_SetMusicCMD(const char *command)"
|
87
|
+
extern "int Mix_SetSynchroValue(int value)"
|
88
|
+
extern "int Mix_GetSynchroValue(void)"
|
89
|
+
extern "int Mix_SetSoundFonts(const char *paths)"
|
90
|
+
extern "const char* Mix_GetSoundFonts(void)"
|
91
|
+
extern "int Mix_SetTimidityCfg(const char *path)"
|
92
|
+
extern "const char* Mix_GetTimidityCfg(void)"
|
93
|
+
extern "Mix_Chunk * Mix_GetChunk(int channel)"
|
94
|
+
extern "void Mix_CloseAudio(void)"
|
95
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module SDLRuby
|
2
|
+
class RW
|
3
|
+
module Operational
|
4
|
+
def close
|
5
|
+
unless closed?
|
6
|
+
err = SDL.SDL_RWclose(to_ptr)
|
7
|
+
|
8
|
+
raise SDLError if err < 0
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def closed? = to_ptr.freed?
|
13
|
+
|
14
|
+
def eof?
|
15
|
+
raise SDLError, "closed and freed rw" if closed?
|
16
|
+
|
17
|
+
s = SDL.SDL_RWsize(to_ptr)
|
18
|
+
raise SDLError if s < 0
|
19
|
+
|
20
|
+
t = SDL.SDL_RWtell(to_ptr)
|
21
|
+
raise SDLError if t < 0
|
22
|
+
|
23
|
+
s == t
|
24
|
+
end
|
25
|
+
|
26
|
+
def read(length = nil, buffer = nil)
|
27
|
+
raise SDLError, "closed and freed rw" if closed?
|
28
|
+
|
29
|
+
if length.nil?
|
30
|
+
len = size - tell
|
31
|
+
else
|
32
|
+
len = Integer.try_convert(length)
|
33
|
+
if len.nil?
|
34
|
+
raise TypeError,
|
35
|
+
"no implicit conversion of #{length.class} into Integer"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
if len < 0
|
40
|
+
raise ArgumentError, "negative length #{len} given"
|
41
|
+
end
|
42
|
+
|
43
|
+
if buffer.nil?
|
44
|
+
buffer = ""
|
45
|
+
else
|
46
|
+
buffer = String.try_convert(buffer)
|
47
|
+
if buffer.nil?
|
48
|
+
raise TypeError,
|
49
|
+
"no implicit conversion of #{buffer.class} into String"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
if eof? || len == 0
|
54
|
+
buffer.clear
|
55
|
+
return len == 0 ? buffer : nil
|
56
|
+
end
|
57
|
+
|
58
|
+
bytesize = buffer.bytesize
|
59
|
+
if len == bytesize
|
60
|
+
buffer
|
61
|
+
elsif len > bytesize
|
62
|
+
buffer.gsub!(/\z/nm, "\x00" * (len - bytesize))
|
63
|
+
elsif len < bytesize
|
64
|
+
buffer.gsub!(/[\x00-\xFF]{#{bytesize - len}}\z/nm, "")
|
65
|
+
end
|
66
|
+
|
67
|
+
n = SDL.SDL_RWread(to_ptr, buffer, 1, len)
|
68
|
+
if n < len
|
69
|
+
buffer.gsub!(/[\x00-\xFF]{#{n}}$/nm, "")
|
70
|
+
end
|
71
|
+
raise SDLError if n == 0
|
72
|
+
|
73
|
+
buffer
|
74
|
+
end
|
75
|
+
|
76
|
+
def seek(offset, whence = IO::SEEK_SET)
|
77
|
+
raise SDLError, "closed and freed rw" if closed?
|
78
|
+
|
79
|
+
n = SDL.SDL_RWseek(to_ptr, offset, whence)
|
80
|
+
raise SDLError if n < 0
|
81
|
+
0
|
82
|
+
end
|
83
|
+
|
84
|
+
alias pos= seek
|
85
|
+
|
86
|
+
def size
|
87
|
+
raise SDLError, "closed and freed rw" if closed?
|
88
|
+
|
89
|
+
n = SDL.SDL_RWsize(to_ptr)
|
90
|
+
raise SDLError if n < 0
|
91
|
+
n
|
92
|
+
end
|
93
|
+
|
94
|
+
def tell
|
95
|
+
raise SDLError, "closed and freed rw" if closed?
|
96
|
+
|
97
|
+
n = SDL.SDL_RWtell(to_ptr)
|
98
|
+
raise SDLError if n < 0
|
99
|
+
n
|
100
|
+
end
|
101
|
+
|
102
|
+
alias pos tell
|
103
|
+
|
104
|
+
def write(obj)
|
105
|
+
raise SDLError, "closed and freed rw" if closed?
|
106
|
+
|
107
|
+
ptr = obj.to_s
|
108
|
+
len = ptr.bytesize
|
109
|
+
|
110
|
+
n = SDL.SDL_RWwrite(to_ptr, ptr, 1, len)
|
111
|
+
raise SDLError if n < len
|
112
|
+
n
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module SDLRuby
|
2
|
+
class RW
|
3
|
+
class ReadClosure < Fiddle::Closure
|
4
|
+
include Fiddle
|
5
|
+
|
6
|
+
def initialize(obj)
|
7
|
+
# size_t (*read) (SDL_RWops *context, void *ptr, size_t size, size_t maxnum)
|
8
|
+
#
|
9
|
+
super(TYPE_SIZE_T, [TYPE_VOIDP, TYPE_VOIDP, TYPE_SIZE_T, TYPE_SIZE_T])
|
10
|
+
@obj = obj
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(_, ptr, size, maxnum)
|
14
|
+
len = size * maxnum
|
15
|
+
return 0 if len.zero?
|
16
|
+
|
17
|
+
s = @obj.read(len)
|
18
|
+
return 0 if s.nil? || s.empty? # EOF
|
19
|
+
|
20
|
+
ptr[0, s.size] = s
|
21
|
+
s.size / size
|
22
|
+
rescue => e
|
23
|
+
SDL.last_error_message = e.message
|
24
|
+
0
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module SDLRuby
|
2
|
+
class RW
|
3
|
+
class SeekClosure < Fiddle::Closure
|
4
|
+
include Fiddle
|
5
|
+
|
6
|
+
def initialize(obj)
|
7
|
+
# Sint64 (*seek) (SDL_RWops *context, Sint64 offset, int whence)
|
8
|
+
#
|
9
|
+
super(TYPE_INT64_T, [TYPE_VOIDP, TYPE_INT64_T, TYPE_INT])
|
10
|
+
@obj = obj
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(_, offset, whence)
|
14
|
+
@obj.seek(offset, whence)
|
15
|
+
@obj.tell
|
16
|
+
rescue => e
|
17
|
+
SDL.last_error_message = e.message
|
18
|
+
-1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module SDLRuby
|
2
|
+
class RW
|
3
|
+
class SizeClosure < Fiddle::Closure
|
4
|
+
include Fiddle
|
5
|
+
|
6
|
+
def initialize(obj)
|
7
|
+
# Sint64 (*size) (SDL_RWops *context)
|
8
|
+
#
|
9
|
+
super(TYPE_INT64_T, [TYPE_VOIDP])
|
10
|
+
@obj = obj
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(_)
|
14
|
+
@obj.size
|
15
|
+
rescue => e
|
16
|
+
SDL.last_error_message = e.message
|
17
|
+
-1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module SDLRuby
|
2
|
+
class RW
|
3
|
+
class WriteClosure < Fiddle::Closure
|
4
|
+
include Fiddle
|
5
|
+
|
6
|
+
def initialize(obj)
|
7
|
+
# size_t (*write) (SDL_RWops *context, const void *ptr, size_t size, size_t num)
|
8
|
+
#
|
9
|
+
super(TYPE_SIZE_T, [TYPE_VOIDP, TYPE_VOIDP, TYPE_SIZE_T, TYPE_SIZE_T])
|
10
|
+
@obj = obj
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(_, ptr, size, num)
|
14
|
+
@obj.write(ptr.to_str(size * num)) / size
|
15
|
+
rescue => e
|
16
|
+
SDL.last_error_message = e.message
|
17
|
+
0
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module SDLRuby
|
2
|
+
class RWOps
|
3
|
+
include Fiddle, SDL
|
4
|
+
|
5
|
+
# これはSDL3では不要になります。
|
6
|
+
# SDL3ではメンバーの関数ポインターにNULLを設定できます。
|
7
|
+
# それは”適切な”デフォルトの動作を意味します。
|
8
|
+
#
|
9
|
+
#
|
10
|
+
#
|
11
|
+
# SDL2ではcloseにはC関数ポインターを設定する必要がある。
|
12
|
+
# Rubyのクロージャ―を設定するとGCが動作時に該当のクロージャ―が既に回収されているため
|
13
|
+
# コアダンプする。
|
14
|
+
# また、NULLに設定するとSDL_RWclose関数の呼び出し時にコアダンプする。
|
15
|
+
# ここではSDLをハックしてmem_close関数を割り当てた。
|
16
|
+
# この関数は内部でSDL_FreeRW関数を呼び出すだけである。
|
17
|
+
#
|
18
|
+
# int (*close) (SDL_RWops *context)
|
19
|
+
#
|
20
|
+
MEM_CLOSE = module_eval do
|
21
|
+
ptr = Pointer.malloc(1, RUBY_FREE)
|
22
|
+
rw = SDL.SDL_RWFromMem(ptr, ptr.size)
|
23
|
+
raise SDLError if rw.null?
|
24
|
+
SDL_RWops.new(rw, SDL_FREE_RW)["close"].to_int
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,108 +1,15 @@
|
|
1
|
+
require_relative '../rw/read_closure'
|
2
|
+
require_relative '../rw/seek_closure'
|
3
|
+
require_relative '../rw/size_closure'
|
4
|
+
require_relative '../rw/write_closure'
|
5
|
+
require_relative 'mem_close'
|
6
|
+
|
1
7
|
module SDLRuby
|
2
8
|
class RWOps
|
3
9
|
class RWObject
|
4
10
|
include Fiddle, SDL
|
5
11
|
|
6
|
-
#
|
7
|
-
#
|
8
|
-
class ReadClosure < Fiddle::Closure
|
9
|
-
include Fiddle
|
10
|
-
|
11
|
-
def initialize(obj)
|
12
|
-
super(TYPE_SIZE_T, [TYPE_VOIDP, TYPE_VOIDP, TYPE_SIZE_T, TYPE_SIZE_T])
|
13
|
-
@obj = obj
|
14
|
-
end
|
15
|
-
|
16
|
-
def call(_, ptr, size, maxnum)
|
17
|
-
len = size * maxnum
|
18
|
-
return 0 if len.zero?
|
19
|
-
|
20
|
-
s = @obj.read(len)
|
21
|
-
return 0 if s.nil? || s.empty? # EOF
|
22
|
-
|
23
|
-
ptr[0, s.size] = s
|
24
|
-
s.size / size
|
25
|
-
rescue => e
|
26
|
-
SDL.last_error_message = e.full_message
|
27
|
-
0
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# Sint64 (*seek) (SDL_RWops *context, Sint64 offset, int whence)
|
32
|
-
#
|
33
|
-
class SeekClosure < Fiddle::Closure
|
34
|
-
include Fiddle
|
35
|
-
|
36
|
-
def initialize(obj)
|
37
|
-
super(TYPE_INT64_T, [TYPE_VOIDP, TYPE_INT64_T, TYPE_INT])
|
38
|
-
@obj = obj
|
39
|
-
end
|
40
|
-
|
41
|
-
def call(_, offset, whence)
|
42
|
-
@obj.seek(offset, whence)
|
43
|
-
@obj.tell
|
44
|
-
rescue => e
|
45
|
-
SDL.last_error_message = e.full_message
|
46
|
-
-1
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# Sint64 (*size) (SDL_RWops *context)
|
51
|
-
#
|
52
|
-
class SizeClosure < Fiddle::Closure
|
53
|
-
include Fiddle
|
54
|
-
|
55
|
-
def initialize(obj)
|
56
|
-
super(TYPE_INT64_T, [TYPE_VOIDP])
|
57
|
-
@obj = obj
|
58
|
-
end
|
59
|
-
|
60
|
-
def call(_)
|
61
|
-
@obj.size
|
62
|
-
rescue => e
|
63
|
-
raise e if $DEBUG
|
64
|
-
SDL.last_error_message = e.full_message
|
65
|
-
-1
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# size_t (*write) (SDL_RWops *context, const void *ptr, size_t size, size_t num)
|
70
|
-
#
|
71
|
-
class WriteClosure < Fiddle::Closure
|
72
|
-
include Fiddle
|
73
|
-
|
74
|
-
def initialize(obj)
|
75
|
-
super(TYPE_SIZE_T, [TYPE_VOIDP, TYPE_VOIDP, TYPE_SIZE_T, TYPE_SIZE_T])
|
76
|
-
@obj = obj
|
77
|
-
end
|
78
|
-
|
79
|
-
def call(_, ptr, size, num)
|
80
|
-
@obj.write(ptr.to_str(size * num)) / size
|
81
|
-
rescue => e
|
82
|
-
SDL.last_error_message = e.full_message
|
83
|
-
0
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
# closeにはC関数を設定する必要がある。
|
88
|
-
# クロージャ―を設定するとGCによる回収の際に
|
89
|
-
# 該当のクロージャ―が既に回収されているためコアダンプする。
|
90
|
-
# また、NULLに設定するとSDL_RWclose関数の呼び出し時にコアダンプする。
|
91
|
-
# SDLをハックしてmem_close関数を割り当てた。
|
92
|
-
# この関数は内部でSDL_FreeRW関数を呼び出すだけである。
|
93
|
-
#
|
94
|
-
# int (*close) (SDL_RWops *context)
|
95
|
-
#
|
96
|
-
MEM_CLOSE = module_eval do
|
97
|
-
_ptr = Pointer.malloc(1, RUBY_FREE)
|
98
|
-
rw = SDL.SDL_RWFromMem(_ptr, _ptr.size)
|
99
|
-
raise SDLError if rw.null?
|
100
|
-
st = SDL_RWops.new(rw)
|
101
|
-
|
102
|
-
st.close.freeze
|
103
|
-
end
|
104
|
-
|
105
|
-
# 引数 obj に与えたオブジェクトは SDL から close を呼び出されてもクローズしない。
|
12
|
+
# 引数objに与えたオブジェクトはSDLからcloseを呼び出されてもクローズしない。
|
106
13
|
# このインスタンスを単独で扱う場合は使い終わったらclose関数を呼び出す必要がある。
|
107
14
|
# そうしなければポインターは開放されずメモリーリークする。
|
108
15
|
#
|
@@ -110,16 +17,15 @@ module SDLRuby
|
|
110
17
|
ptr = SDL.SDL_AllocRW
|
111
18
|
raise SDLError if ptr.null?
|
112
19
|
|
113
|
-
# SDLではSDL_RWopsポインターの開放はclose関数から行うように実装されている。
|
114
|
-
# これと同じ仕様とするため、このインスタンスではfreeの設定を行わない。
|
115
|
-
#
|
116
20
|
@st = SDL_RWops.new(ptr)
|
117
21
|
|
22
|
+
# SDLではSDL_RWopsポインターの開放はclose関数ポインターを呼び出して行う仕様となっている。
|
23
|
+
#
|
118
24
|
@st.close = MEM_CLOSE
|
119
|
-
@st.read
|
120
|
-
@st.seek
|
121
|
-
@st.size
|
122
|
-
@st.write = @write = WriteClosure.new(obj)
|
25
|
+
@st.read = @read = RW::ReadClosure.new(obj)
|
26
|
+
@st.seek = @seek = RW::SeekClosure.new(obj)
|
27
|
+
@st.size = @size = RW::SizeClosure.new(obj)
|
28
|
+
@st.write = @write = RW::WriteClosure.new(obj)
|
123
29
|
end
|
124
30
|
|
125
31
|
def to_ptr = @st.to_ptr
|