sfml3-rb 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +9 -0
  3. data/CHANGELOG.md +67 -16
  4. data/README.md +123 -32
  5. data/TODO.md +18 -11
  6. data/ext/audio/audio_enums.c +58 -20
  7. data/ext/audio/listener.c +89 -6
  8. data/ext/audio/music.c +212 -5
  9. data/ext/audio/sound.c +218 -9
  10. data/ext/audio/sound_buffer.c +197 -47
  11. data/ext/audio/sound_buffer_recorder.c +90 -18
  12. data/ext/audio/sound_recorder.c +188 -58
  13. data/ext/audio/sound_source_cone.c +127 -33
  14. data/ext/audio/sound_stream.c +204 -21
  15. data/ext/core/exceptions.c +10 -8
  16. data/ext/core/unicode.c +12 -2
  17. data/ext/ext.c +8 -0
  18. data/ext/graphics/blend_mode.c +218 -60
  19. data/ext/graphics/circle.c +300 -16
  20. data/ext/graphics/color.c +253 -94
  21. data/ext/graphics/drawable.c +16 -4
  22. data/ext/graphics/font.c +144 -25
  23. data/ext/graphics/glyph.c +38 -8
  24. data/ext/graphics/image.c +205 -41
  25. data/ext/graphics/polygon.c +317 -30
  26. data/ext/graphics/rect.c +225 -60
  27. data/ext/graphics/rectangle.c +307 -35
  28. data/ext/graphics/render_state.c +124 -12
  29. data/ext/graphics/render_texture.c +191 -14
  30. data/ext/graphics/render_window.c +55 -0
  31. data/ext/graphics/render_window.h +10 -0
  32. data/ext/graphics/shader.c +289 -17
  33. data/ext/graphics/shape.c +265 -32
  34. data/ext/graphics/sprite.c +245 -30
  35. data/ext/graphics/stencil_mode.c +163 -46
  36. data/ext/graphics/target.c +121 -43
  37. data/ext/graphics/target.h +31 -17
  38. data/ext/graphics/text.c +339 -19
  39. data/ext/graphics/texture.c +291 -6
  40. data/ext/graphics/transform.c +178 -5
  41. data/ext/graphics/transformable.c +127 -12
  42. data/ext/graphics/vertex.c +98 -6
  43. data/ext/graphics/vertex_array.c +142 -21
  44. data/ext/graphics/vertex_buffer.c +154 -12
  45. data/ext/graphics/view.c +140 -6
  46. data/ext/network/ftp.c +278 -12
  47. data/ext/network/http.c +179 -44
  48. data/ext/network/ip_address.c +127 -35
  49. data/ext/network/network_enums.c +248 -141
  50. data/ext/network/packet.c +280 -41
  51. data/ext/network/socket_selector.c +98 -21
  52. data/ext/network/tcp_listener.c +82 -18
  53. data/ext/network/tcp_socket.c +135 -27
  54. data/ext/network/udp_socket.c +129 -28
  55. data/ext/ports.rb +7 -0
  56. data/ext/system/buffer.c +47 -16
  57. data/ext/system/clock.c +77 -12
  58. data/ext/system/input_stream.c +113 -51
  59. data/ext/system/sleep.c +10 -2
  60. data/ext/system/time.c +182 -40
  61. data/ext/system/vec2.c +166 -39
  62. data/ext/system/vec3.c +177 -39
  63. data/ext/window/clipboard.c +47 -17
  64. data/ext/window/context.c +66 -13
  65. data/ext/window/context_settings.c +132 -42
  66. data/ext/window/cursor.c +45 -9
  67. data/ext/window/event.c +164 -53
  68. data/ext/window/joystick.c +69 -3
  69. data/ext/window/keyboard.c +168 -116
  70. data/ext/window/mouse.c +64 -13
  71. data/ext/window/sensor.c +28 -2
  72. data/ext/window/touch.c +32 -12
  73. data/ext/window/video_mode.c +93 -31
  74. data/ext/window/vulkan.c +34 -6
  75. data/ext/window/window.c +228 -229
  76. data/ext/window/window.h +4 -4
  77. data/ext/window/window_base.c +251 -0
  78. data/ext/window/window_base.h +43 -0
  79. data/ext/window/window_base.inc +236 -0
  80. data/lib/sfml/version.rb +1 -1
  81. data/sig/audio/audio_enums.rbs +30 -0
  82. data/sig/audio/listener.rbs +16 -0
  83. data/sig/audio/music.rbs +56 -0
  84. data/sig/audio/sound.rbs +51 -0
  85. data/sig/audio/sound_buffer.rbs +17 -0
  86. data/sig/audio/sound_buffer_recorder.rbs +14 -0
  87. data/sig/audio/sound_recorder.rbs +17 -0
  88. data/sig/audio/sound_source_cone.rbs +14 -0
  89. data/sig/audio/sound_stream.rbs +51 -0
  90. data/sig/graphics/blend_mode.rbs +29 -0
  91. data/sig/graphics/circle.rbs +44 -0
  92. data/sig/graphics/color.rbs +39 -0
  93. data/sig/graphics/drawable.rbs +5 -0
  94. data/sig/graphics/font.rbs +20 -0
  95. data/sig/graphics/glyph.rbs +7 -0
  96. data/sig/graphics/image.rbs +22 -0
  97. data/sig/graphics/polygon.rbs +42 -0
  98. data/sig/graphics/rect.rbs +33 -0
  99. data/sig/graphics/rectangle.rbs +42 -0
  100. data/sig/graphics/render_state.rbs +21 -0
  101. data/sig/graphics/render_target.rbs +18 -0
  102. data/sig/graphics/render_texture.rbs +39 -0
  103. data/sig/graphics/render_window.rbs +7 -0
  104. data/sig/graphics/shader.rbs +39 -0
  105. data/sig/graphics/shape.rbs +38 -0
  106. data/sig/graphics/sprite.rbs +34 -0
  107. data/sig/graphics/stencil_mode.rbs +18 -0
  108. data/sig/graphics/target.rbs +8 -0
  109. data/sig/graphics/text.rbs +48 -0
  110. data/sig/graphics/texture.rbs +34 -0
  111. data/sig/graphics/transform.rbs +37 -0
  112. data/sig/graphics/transformable.rbs +25 -0
  113. data/sig/graphics/vertex.rbs +17 -0
  114. data/sig/graphics/vertex_array.rbs +17 -0
  115. data/sig/graphics/vertex_buffer.rbs +22 -0
  116. data/sig/graphics/view.rbs +23 -0
  117. data/sig/network/ftp.rbs +46 -0
  118. data/sig/network/http.rbs +27 -0
  119. data/sig/network/ip_address.rbs +22 -0
  120. data/sig/network/network_enums.rbs +95 -0
  121. data/sig/network/packet.rbs +40 -0
  122. data/sig/network/socket_selector.rbs +14 -0
  123. data/sig/network/tcp_listener.rbs +13 -0
  124. data/sig/network/tcp_socket.rbs +18 -0
  125. data/sig/network/udp_socket.rbs +17 -0
  126. data/sig/sfml/version.rbs +3 -0
  127. data/sig/system/buffer.rbs +11 -0
  128. data/sig/system/clock.rbs +13 -0
  129. data/sig/system/input_stream.rbs +7 -0
  130. data/sig/system/sleep.rbs +3 -0
  131. data/sig/system/time.rbs +28 -0
  132. data/sig/system/vec2.rbs +26 -0
  133. data/sig/system/vec3.rbs +27 -0
  134. data/sig/window/clipboard.rbs +8 -0
  135. data/sig/window/context.rbs +11 -0
  136. data/sig/window/context_settings.rbs +20 -0
  137. data/sig/window/cursor.rbs +6 -0
  138. data/sig/window/event.rbs +20 -0
  139. data/sig/window/joystick.rbs +15 -0
  140. data/sig/window/keyboard.rbs +10 -0
  141. data/sig/window/mouse.rbs +9 -0
  142. data/sig/window/sensor.rbs +8 -0
  143. data/sig/window/touch.rbs +6 -0
  144. data/sig/window/video_mode.rbs +16 -0
  145. data/sig/window/vulkan.rbs +7 -0
  146. data/sig/window/window.rbs +34 -0
  147. data/sig/window/window_base.rbs +33 -0
  148. metadata +76 -3
@@ -9,8 +9,12 @@
9
9
 
10
10
  static VALUE rb_cMode;
11
11
 
12
- static sfVideoMode *VideoMode_alloc(unsigned width, unsigned height, unsigned bits, int *created) {
13
- sfVideoMode *mode = malloc(sizeof(sfVideoMode));
12
+ static sfVideoMode* VideoMode_create(unsigned width, unsigned height, unsigned bits, int* created) {
13
+ sfVideoMode* mode = malloc(sizeof(sfVideoMode));
14
+
15
+ if (mode == NULL) {
16
+ rb_raise(rb_eNoMemError, "failed to allocate video mode");
17
+ }
14
18
 
15
19
  if (created != NULL) {
16
20
  *created = 1;
@@ -23,18 +27,23 @@ static sfVideoMode *VideoMode_alloc(unsigned width, unsigned height, unsigned bi
23
27
  return mode;
24
28
  }
25
29
 
26
- static void VideoMode_free(void *ptr) {
30
+ static void VideoMode_free(void* ptr) {
27
31
  free(ptr);
28
32
  }
29
33
 
30
34
  static const rb_data_type_t VideoMode_data_type = {
31
35
  .wrap_struct_name = "SFML::VideoMode",
32
36
  .function = {.dmark = NULL, .dfree = VideoMode_free, .dsize = NULL},
33
- .flags = RUBY_TYPED_FREE_IMMEDIATELY
34
- };
37
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY};
38
+
39
+ static VALUE VideoMode_alloc(VALUE klass) {
40
+ sfVideoMode* ptr = VideoMode_create(0, 0, 0, NULL);
41
+
42
+ return TypedData_Wrap_Struct(klass, &VideoMode_data_type, ptr);
43
+ }
35
44
 
36
45
  static VALUE VideoMode_from_c(sfVideoMode mode) {
37
- sfVideoMode *ptr = VideoMode_alloc(mode.size.x, mode.size.y, mode.bitsPerPixel, NULL);
46
+ sfVideoMode* ptr = VideoMode_create(mode.size.x, mode.size.y, mode.bitsPerPixel, NULL);
38
47
  VALUE self = TypedData_Wrap_Struct(rb_cMode, &VideoMode_data_type, ptr);
39
48
 
40
49
  rb_iv_set(self, "@width", UINT2NUM(mode.size.x));
@@ -44,21 +53,20 @@ static VALUE VideoMode_from_c(sfVideoMode mode) {
44
53
  return self;
45
54
  }
46
55
 
47
- static VALUE VideoMode_new(VALUE klass, VALUE rb_width, VALUE rb_height, VALUE rb_bits) {
48
- VALUE self;
49
- VALUE argv[] = {rb_width, rb_height, rb_bits};
56
+ /* call-seq:
57
+ * VideoMode.new(width, height, bits_per_pixel) -> VideoMode
58
+ *
59
+ * Creates a video mode with the given +width+, +height+ and +bits_per_pixel+.
60
+ *
61
+ * @return [VideoMode]
62
+ */
63
+ static VALUE VideoMode_initialize(VALUE self, VALUE rb_width, VALUE rb_height, VALUE rb_bits) {
64
+ sfVideoMode* mode = Get_Mode_Struct(self);
50
65
 
51
- self = VideoMode_from_c((sfVideoMode) {
52
- {(unsigned) NUM2UINT(rb_width), (unsigned) NUM2UINT(rb_height)},
53
- (unsigned) NUM2UINT(rb_bits)
54
- });
66
+ mode->size.x = (unsigned)NUM2UINT(rb_width);
67
+ mode->size.y = (unsigned)NUM2UINT(rb_height);
68
+ mode->bitsPerPixel = (unsigned)NUM2UINT(rb_bits);
55
69
 
56
- rb_obj_call_init(self, 3, argv);
57
-
58
- return self;
59
- }
60
-
61
- static VALUE VideoMode_init(VALUE self, VALUE rb_width, VALUE rb_height, VALUE rb_bits) {
62
70
  rb_iv_set(self, "@width", rb_width);
63
71
  rb_iv_set(self, "@height", rb_height);
64
72
  rb_iv_set(self, "@bits", rb_bits);
@@ -66,14 +74,27 @@ static VALUE VideoMode_init(VALUE self, VALUE rb_width, VALUE rb_height, VALUE r
66
74
  return self;
67
75
  }
68
76
 
77
+ /* call-seq: desktop_mode -> VideoMode
78
+ *
79
+ * Returns the current desktop video mode.
80
+ *
81
+ * @return [VideoMode] the current desktop video mode
82
+ */
69
83
  static VALUE VideoMode_desktop_mode(VALUE klass) {
70
84
  return VideoMode_from_c(sfVideoMode_getDesktopMode());
71
85
  }
72
86
 
87
+ /* call-seq: fullscreen_modes -> Array<VideoMode>
88
+ *
89
+ * Returns all fullscreen video modes supported by the current desktop.
90
+ *
91
+ * @return [Array<VideoMode>] all video modes supported in fullscreen mode,
92
+ * sorted from best to worst
93
+ */
73
94
  static VALUE VideoMode_fullscreen_modes(VALUE klass) {
74
95
  size_t count = 0;
75
- const sfVideoMode *modes = sfVideoMode_getFullscreenModes(&count);
76
- VALUE array = rb_ary_new_capa((long) count);
96
+ const sfVideoMode* modes = sfVideoMode_getFullscreenModes(&count);
97
+ VALUE array = rb_ary_new_capa((long)count);
77
98
 
78
99
  for (size_t i = 0; i < count; i++) {
79
100
  rb_ary_push(array, VideoMode_from_c(modes[i]));
@@ -82,16 +103,36 @@ static VALUE VideoMode_fullscreen_modes(VALUE klass) {
82
103
  return array;
83
104
  }
84
105
 
106
+ /* call-seq: valid? -> true or false
107
+ *
108
+ * Returns +true+ if this mode is valid for fullscreen use.
109
+ *
110
+ * @return [Boolean] whether this mode is valid for fullscreen use on the
111
+ * current desktop
112
+ */
85
113
  static VALUE VideoMode_is_available(VALUE self) {
86
114
  return BOOL2RB(sfVideoMode_isValid(*Get_Mode_Struct(self)));
87
115
  }
88
116
 
117
+ /* call-seq: size -> Vector2
118
+ *
119
+ * Returns +width+ and +height+ as a Vector2.
120
+ *
121
+ * @return [Vector2] +width+ and +height+ as a vector
122
+ */
89
123
  static VALUE VideoMode_get_size(VALUE self) {
90
- sfVideoMode *mode = Get_Mode_Struct(self);
124
+ sfVideoMode* mode = Get_Mode_Struct(self);
91
125
 
92
- return vec2f_to_rb((sfVector2f) {(float) mode->size.x, (float) mode->size.y});
126
+ return vec2f_to_rb((sfVector2f){(float)mode->size.x, (float)mode->size.y});
93
127
  }
94
128
 
129
+ /* call-seq:
130
+ * self == other -> true or false
131
+ *
132
+ * Returns +true+ if +other+ has the same size and bit depth.
133
+ *
134
+ * @return [Boolean]
135
+ */
95
136
  static VALUE VideoMode_eql(VALUE self, VALUE rb_other) {
96
137
  sfVideoMode a = *Get_Mode_Struct(self);
97
138
  sfVideoMode b;
@@ -102,17 +143,38 @@ static VALUE VideoMode_eql(VALUE self, VALUE rb_other) {
102
143
 
103
144
  b = *Get_Mode_Struct(rb_other);
104
145
 
105
- return BOOL2RB(a.size.x == b.size.x && a.size.y == b.size.y && a.bitsPerPixel == b.bitsPerPixel);
146
+ return BOOL2RB(a.size.x == b.size.x && a.size.y == b.size.y &&
147
+ a.bitsPerPixel == b.bitsPerPixel);
106
148
  }
107
149
 
108
- void Init_VideoMode(VALUE rb_module) {
109
- rb_cMode = rb_define_class_under(rb_module, "VideoMode", rb_cObject);
150
+ /* Document-class: SFML::VideoMode
151
+ * A width/height/bits-per-pixel triple describing a display mode, as used
152
+ * for fullscreen windows.
153
+ *
154
+ * The +width+/+height+/+bits+ accessors below are declared with
155
+ * +rb_define_attr+ rather than +rb_define_method+; YARD's C parser cannot
156
+ * handle that declaration form (a confirmed YARD bug), so they are
157
+ * documented here instead of above their (nonexistent, ivar-backed)
158
+ * definitions.
159
+ *
160
+ * @!attribute [r] width
161
+ * Width in pixels.
162
+ * @return [Integer] width in pixels
163
+ * @!attribute [r] height
164
+ * Height in pixels.
165
+ * @return [Integer] height in pixels
166
+ * @!attribute [r] bits
167
+ * Bits per pixel.
168
+ * @return [Integer] bits per pixel
169
+ */
170
+ void Init_VideoMode(VALUE rb_mSFML) {
171
+ rb_cMode = rb_define_class_under(rb_mSFML, "VideoMode", rb_cObject);
172
+
173
+ rb_define_alloc_func(rb_cMode, VideoMode_alloc);
174
+ rb_define_method(rb_cMode, "initialize", VideoMode_initialize, 3);
110
175
 
111
- rb_define_singleton_method(rb_cMode, "new", VideoMode_new, 3);
112
176
  rb_define_singleton_method(rb_cMode, "desktop_mode", VideoMode_desktop_mode, 0);
113
177
  rb_define_singleton_method(rb_cMode, "fullscreen_modes", VideoMode_fullscreen_modes, 0);
114
-
115
- rb_define_method(rb_cMode, "initialize", VideoMode_init, 3);
116
178
  rb_define_method(rb_cMode, "available?", VideoMode_is_available, 0);
117
179
  rb_define_method(rb_cMode, "valid?", VideoMode_is_available, 0);
118
180
  rb_define_method(rb_cMode, "size", VideoMode_get_size, 0);
@@ -122,8 +184,8 @@ void Init_VideoMode(VALUE rb_module) {
122
184
  rb_define_attr(rb_cMode, "bits", 1, 0);
123
185
  }
124
186
 
125
- sfVideoMode *Get_Mode_Struct(VALUE self) {
126
- sfVideoMode *ptr;
187
+ sfVideoMode* Get_Mode_Struct(VALUE self) {
188
+ sfVideoMode* ptr;
127
189
  TypedData_Get_Struct(self, sfVideoMode, &VideoMode_data_type, ptr);
128
190
  return ptr;
129
191
  }
data/ext/window/vulkan.c CHANGED
@@ -5,7 +5,15 @@
5
5
  #include "core/macros.h"
6
6
  #include "core/sfml.h"
7
7
 
8
- static VALUE Vulkan_is_available(int argc, VALUE *argv, VALUE module) {
8
+ /* call-seq:
9
+ * available?(require_graphics = false) -> true or false
10
+ *
11
+ * Returns +true+ if Vulkan is available, optionally requiring graphics support.
12
+ *
13
+ * @return [Boolean] whether Vulkan is available, optionally also requiring
14
+ * graphics-capable support when +require_graphics+ is true
15
+ */
16
+ static VALUE Vulkan_is_available(int argc, VALUE* argv, VALUE module) {
9
17
  VALUE rb_require_graphics;
10
18
  bool require_graphics = false;
11
19
 
@@ -18,14 +26,30 @@ static VALUE Vulkan_is_available(int argc, VALUE *argv, VALUE module) {
18
26
  return BOOL2RB(sfVulkan_isAvailable(require_graphics));
19
27
  }
20
28
 
29
+ /* call-seq:
30
+ * function(name) -> Integer
31
+ *
32
+ * Returns the address of the Vulkan function or extension +name+ as an
33
+ * Integer, or 0 when it is not available.
34
+ *
35
+ * @return [Integer] the address of the Vulkan function/extension +name+, as
36
+ * a raw pointer value, or 0 if it is not available
37
+ */
21
38
  static VALUE Vulkan_get_function(VALUE module, VALUE rb_name) {
22
- return ULL2NUM((unsigned long long) (uintptr_t) sfVulkan_getFunction(StringValueCStr(rb_name)));
39
+ return ULL2NUM((unsigned long long)(uintptr_t)sfVulkan_getFunction(StringValueCStr(rb_name)));
23
40
  }
24
41
 
42
+ /* call-seq: graphics_required_instance_extensions -> Array<String>
43
+ *
44
+ * Returns the Vulkan instance extensions needed to create a window surface.
45
+ *
46
+ * @return [Array<String>] the Vulkan instance extensions required to create
47
+ * a Vulkan surface for a Window
48
+ */
25
49
  static VALUE Vulkan_get_graphics_required_instance_extensions(VALUE module) {
26
50
  size_t count = 0;
27
- const char *const *extensions = sfVulkan_getGraphicsRequiredInstanceExtensions(&count);
28
- VALUE array = rb_ary_new_capa((long) count);
51
+ const char* const* extensions = sfVulkan_getGraphicsRequiredInstanceExtensions(&count);
52
+ VALUE array = rb_ary_new_capa((long)count);
29
53
 
30
54
  for (size_t i = 0; i < count; i++) {
31
55
  rb_ary_push(array, rb_str_new_cstr(extensions[i]));
@@ -34,8 +58,12 @@ static VALUE Vulkan_get_graphics_required_instance_extensions(VALUE module) {
34
58
  return array;
35
59
  }
36
60
 
37
- void Init_Vulkan(VALUE rb_module) {
38
- VALUE rb_mVulkan = rb_define_module_under(rb_module, "Vulkan");
61
+ /* Document-module: SFML::Vulkan
62
+ * Vulkan support queries. Vulkan handles (instances, surfaces, allocators)
63
+ * cross this binding as plain Integers; see Window#create_vulkan_surface.
64
+ */
65
+ void Init_Vulkan(VALUE rb_mSFML) {
66
+ VALUE rb_mVulkan = rb_define_module_under(rb_mSFML, "Vulkan");
39
67
 
40
68
  rb_define_module_function(rb_mVulkan, "available?", Vulkan_is_available, -1);
41
69
  rb_define_module_function(rb_mVulkan, "function", Vulkan_get_function, 1);