sfml3-rb 0.3.0 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/README.md +36 -13
- data/TODO.md +18 -11
- data/ext/audio/music.c +6 -0
- data/ext/audio/sound.c +43 -4
- data/ext/audio/sound_buffer.c +8 -0
- data/ext/audio/sound_buffer_recorder.c +8 -3
- data/ext/audio/sound_recorder.c +21 -11
- data/ext/audio/sound_source_cone.c +18 -3
- data/ext/audio/sound_stream.c +25 -15
- data/ext/ext.c +4 -0
- data/ext/graphics/blend_mode.c +16 -8
- data/ext/graphics/circle.c +30 -13
- data/ext/graphics/color.c +17 -8
- data/ext/graphics/drawable.c +3 -2
- data/ext/graphics/font.c +6 -0
- data/ext/graphics/glyph.c +7 -0
- data/ext/graphics/image.c +25 -4
- data/ext/graphics/polygon.c +31 -11
- data/ext/graphics/rect.c +16 -8
- data/ext/graphics/rectangle.c +30 -11
- data/ext/graphics/render_state.c +8 -10
- data/ext/graphics/render_texture.c +27 -11
- data/ext/graphics/render_window.c +55 -0
- data/ext/graphics/render_window.h +10 -0
- data/ext/graphics/shader.c +6 -0
- data/ext/graphics/shape.c +23 -16
- data/ext/graphics/sprite.c +34 -10
- data/ext/graphics/stencil_mode.c +16 -8
- data/ext/graphics/target.c +60 -27
- data/ext/graphics/target.h +22 -8
- data/ext/graphics/text.c +33 -13
- data/ext/graphics/texture.c +34 -3
- data/ext/graphics/transformable.c +11 -20
- data/ext/graphics/vertex.c +18 -3
- data/ext/graphics/vertex_array.c +18 -9
- data/ext/graphics/vertex_buffer.c +30 -10
- data/ext/graphics/view.c +16 -10
- data/ext/network/ftp.c +30 -3
- data/ext/network/http.c +23 -6
- data/ext/network/ip_address.c +25 -14
- data/ext/network/packet.c +8 -3
- data/ext/network/socket_selector.c +8 -3
- data/ext/network/tcp_listener.c +8 -3
- data/ext/network/tcp_socket.c +8 -3
- data/ext/network/udp_socket.c +8 -3
- data/ext/system/buffer.c +13 -11
- data/ext/system/clock.c +11 -5
- data/ext/system/input_stream.c +21 -11
- data/ext/system/time.c +17 -13
- data/ext/system/vec2.c +17 -11
- data/ext/system/vec3.c +18 -11
- data/ext/window/context.c +14 -11
- data/ext/window/context_settings.c +16 -4
- data/ext/window/cursor.c +6 -0
- data/ext/window/event.c +15 -25
- data/ext/window/mouse.c +28 -11
- data/ext/window/touch.c +12 -10
- data/ext/window/video_mode.c +16 -25
- data/ext/window/window.c +110 -435
- data/ext/window/window.h +4 -4
- data/ext/window/window_base.c +251 -0
- data/ext/window/window_base.h +43 -0
- data/ext/window/window_base.inc +236 -0
- data/lib/sfml/version.rb +1 -1
- data/sig/audio/sound.rbs +1 -1
- data/sig/audio/sound_buffer_recorder.rbs +1 -1
- data/sig/audio/sound_recorder.rbs +1 -1
- data/sig/audio/sound_source_cone.rbs +1 -1
- data/sig/audio/sound_stream.rbs +1 -1
- data/sig/graphics/blend_mode.rbs +1 -1
- data/sig/graphics/circle.rbs +1 -1
- data/sig/graphics/color.rbs +5 -5
- data/sig/graphics/image.rbs +1 -1
- data/sig/graphics/polygon.rbs +1 -1
- data/sig/graphics/rect.rbs +5 -5
- data/sig/graphics/rectangle.rbs +1 -1
- data/sig/graphics/render_state.rbs +2 -2
- data/sig/graphics/render_target.rbs +18 -0
- data/sig/graphics/render_texture.rbs +4 -2
- data/sig/graphics/render_window.rbs +7 -0
- data/sig/graphics/shape.rbs +1 -1
- data/sig/graphics/sprite.rbs +2 -2
- data/sig/graphics/stencil_mode.rbs +2 -2
- data/sig/graphics/target.rbs +1 -3
- data/sig/graphics/text.rbs +4 -4
- data/sig/graphics/texture.rbs +1 -1
- data/sig/graphics/transformable.rbs +1 -1
- data/sig/graphics/vertex.rbs +4 -4
- data/sig/graphics/vertex_array.rbs +1 -1
- data/sig/graphics/vertex_buffer.rbs +4 -4
- data/sig/graphics/view.rbs +0 -1
- data/sig/network/ftp.rbs +1 -1
- data/sig/network/http.rbs +2 -2
- data/sig/network/ip_address.rbs +1 -1
- data/sig/network/packet.rbs +1 -1
- data/sig/network/socket_selector.rbs +1 -1
- data/sig/network/tcp_listener.rbs +1 -1
- data/sig/network/tcp_socket.rbs +1 -1
- data/sig/network/udp_socket.rbs +1 -1
- data/sig/sfml/version.rbs +3 -0
- data/sig/system/buffer.rbs +1 -1
- data/sig/system/clock.rbs +1 -1
- data/sig/system/input_stream.rbs +1 -1
- data/sig/system/time.rbs +4 -4
- data/sig/system/vec2.rbs +4 -4
- data/sig/system/vec3.rbs +4 -4
- data/sig/window/context.rbs +1 -1
- data/sig/window/context_settings.rbs +1 -1
- data/sig/window/event.rbs +1 -1
- data/sig/window/mouse.rbs +2 -2
- data/sig/window/touch.rbs +1 -1
- data/sig/window/video_mode.rbs +1 -1
- data/sig/window/window.rbs +2 -25
- data/sig/window/window_base.rbs +33 -0
- metadata +11 -2
data/ext/graphics/vertex.c
CHANGED
|
@@ -31,6 +31,18 @@ static VALUE Vertex_wrap(sfVertex vertex) {
|
|
|
31
31
|
return TypedData_Wrap_Struct(rb_cVertex, &Vertex_data_type, ptr);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
static VALUE Vertex_alloc(VALUE klass) {
|
|
35
|
+
Vertex* ptr = malloc(sizeof(Vertex));
|
|
36
|
+
|
|
37
|
+
if (ptr == NULL) {
|
|
38
|
+
rb_raise(rb_eNoMemError, "failed to allocate vertex");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
ptr->vertex = (sfVertex){{0, 0}, {0, 0, 0, 0}, {0, 0}};
|
|
42
|
+
|
|
43
|
+
return TypedData_Wrap_Struct(klass, &Vertex_data_type, ptr);
|
|
44
|
+
}
|
|
45
|
+
|
|
34
46
|
/* call-seq:
|
|
35
47
|
* Vertex.new -> Vertex
|
|
36
48
|
* Vertex.new(position) -> Vertex
|
|
@@ -42,7 +54,7 @@ static VALUE Vertex_wrap(sfVertex vertex) {
|
|
|
42
54
|
*
|
|
43
55
|
* @return [Vertex]
|
|
44
56
|
*/
|
|
45
|
-
static VALUE
|
|
57
|
+
static VALUE Vertex_initialize(int argc, VALUE* argv, VALUE self) {
|
|
46
58
|
VALUE rb_position, rb_color, rb_tex_coords;
|
|
47
59
|
sfVertex vertex = {{0, 0}, {255, 255, 255, 255}, {0, 0}};
|
|
48
60
|
|
|
@@ -60,7 +72,9 @@ static VALUE Vertex_new(int argc, VALUE* argv, VALUE klass) {
|
|
|
60
72
|
vertex.texCoords = vec2f_from_rb(rb_tex_coords);
|
|
61
73
|
}
|
|
62
74
|
|
|
63
|
-
|
|
75
|
+
((Vertex*)Get_Vertex_Struct(self))->vertex = vertex;
|
|
76
|
+
|
|
77
|
+
return self;
|
|
64
78
|
}
|
|
65
79
|
|
|
66
80
|
/* call-seq: position -> Vector2
|
|
@@ -181,7 +195,8 @@ static VALUE Vertex_eql(VALUE self, VALUE rb_other) {
|
|
|
181
195
|
void Init_Vertex(VALUE rb_mSFML) {
|
|
182
196
|
rb_cVertex = rb_define_class_under(rb_mSFML, "Vertex", rb_cObject);
|
|
183
197
|
|
|
184
|
-
|
|
198
|
+
rb_define_alloc_func(rb_cVertex, Vertex_alloc);
|
|
199
|
+
rb_define_method(rb_cVertex, "initialize", Vertex_initialize, -1);
|
|
185
200
|
|
|
186
201
|
rb_define_method(rb_cVertex, "position", Vertex_get_position, 0);
|
|
187
202
|
rb_define_method(rb_cVertex, "color", Vertex_get_color, 0);
|
data/ext/graphics/vertex_array.c
CHANGED
|
@@ -37,6 +37,16 @@ static sfVertexArray* Get_VertexArray_Struct(VALUE self) {
|
|
|
37
37
|
return ptr;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
static VALUE VertexArray_alloc(VALUE klass) {
|
|
41
|
+
sfVertexArray* array = sfVertexArray_create();
|
|
42
|
+
|
|
43
|
+
if (array == NULL) {
|
|
44
|
+
rb_raise(rb_eRuntimeError, "failed to create vertex array");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return TypedData_Wrap_Struct(klass, &VertexArray_data_type, array);
|
|
48
|
+
}
|
|
49
|
+
|
|
40
50
|
/* call-seq:
|
|
41
51
|
* VertexArray.new -> VertexArray
|
|
42
52
|
*
|
|
@@ -44,8 +54,8 @@ static sfVertexArray* Get_VertexArray_Struct(VALUE self) {
|
|
|
44
54
|
*
|
|
45
55
|
* @return [VertexArray] an empty array of :points primitives
|
|
46
56
|
*/
|
|
47
|
-
static VALUE
|
|
48
|
-
return
|
|
57
|
+
static VALUE VertexArray_initialize(VALUE self) {
|
|
58
|
+
return self;
|
|
49
59
|
}
|
|
50
60
|
|
|
51
61
|
/* call-seq: copy -> VertexArray
|
|
@@ -189,17 +199,14 @@ static VALUE VertexArray_get_bounds(VALUE self) {
|
|
|
189
199
|
* RenderState
|
|
190
200
|
*/
|
|
191
201
|
static VALUE VertexArray_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
|
|
192
|
-
|
|
193
|
-
raise_invalid_argument_class(Get_Klass_Target());
|
|
194
|
-
}
|
|
202
|
+
TargetView view = Get_RenderTarget_View(rb_target);
|
|
195
203
|
|
|
196
204
|
if (!rb_obj_is_kind_of(rb_state, Get_Klass_RenderState())) {
|
|
197
205
|
raise_invalid_argument_class(Get_Klass_RenderState());
|
|
198
206
|
}
|
|
199
207
|
|
|
200
|
-
TARGET_DRAW(
|
|
201
|
-
|
|
202
|
-
Get_RenderState_Struct(rb_state));
|
|
208
|
+
TARGET_DRAW(view, sfRenderWindow_drawVertexArray, sfRenderTexture_drawVertexArray,
|
|
209
|
+
Get_VertexArray_Struct(self), Get_RenderState_Struct(rb_state));
|
|
203
210
|
|
|
204
211
|
return Qnil;
|
|
205
212
|
}
|
|
@@ -217,9 +224,11 @@ static VALUE VertexArray_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
|
|
|
217
224
|
void Init_VertexArray(VALUE rb_mSFML) {
|
|
218
225
|
rb_cVertexArray = rb_define_class_under(rb_mSFML, "VertexArray", rb_cObject);
|
|
219
226
|
|
|
227
|
+
rb_define_alloc_func(rb_cVertexArray, VertexArray_alloc);
|
|
228
|
+
|
|
220
229
|
rb_include_module(rb_cVertexArray, Get_Module_Drawable());
|
|
221
230
|
|
|
222
|
-
|
|
231
|
+
rb_define_method(rb_cVertexArray, "initialize", VertexArray_initialize, 0);
|
|
223
232
|
|
|
224
233
|
rb_define_method(rb_cVertexArray, "copy", VertexArray_copy, 0);
|
|
225
234
|
rb_define_method(rb_cVertexArray, "vertex_count", VertexArray_get_vertex_count, 0);
|
|
@@ -17,7 +17,9 @@ static VALUE rb_cVertexBuffer;
|
|
|
17
17
|
static const char* usage_names[] = {"stream", "dynamic", "static"};
|
|
18
18
|
|
|
19
19
|
static void VertexBuffer_free(void* ptr) {
|
|
20
|
-
|
|
20
|
+
if (ptr != NULL) {
|
|
21
|
+
sfVertexBuffer_destroy(ptr);
|
|
22
|
+
}
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
static const rb_data_type_t VertexBuffer_data_type = {
|
|
@@ -60,6 +62,15 @@ static sfVertexBufferUsage usage_from_rb(VALUE rb_usage) {
|
|
|
60
62
|
return sfVertexBufferStatic;
|
|
61
63
|
}
|
|
62
64
|
|
|
65
|
+
static VALUE VertexBuffer_initialize_copy(VALUE self, VALUE other) {
|
|
66
|
+
(void)other;
|
|
67
|
+
rb_raise(rb_eTypeError, "can't copy a %s", rb_obj_classname(self));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static VALUE VertexBuffer_alloc(VALUE klass) {
|
|
71
|
+
return TypedData_Wrap_Struct(klass, &VertexBuffer_data_type, NULL);
|
|
72
|
+
}
|
|
73
|
+
|
|
63
74
|
/* call-seq:
|
|
64
75
|
* VertexBuffer.new -> VertexBuffer
|
|
65
76
|
* VertexBuffer.new(count) -> VertexBuffer
|
|
@@ -74,11 +85,12 @@ static sfVertexBufferUsage usage_from_rb(VALUE rb_usage) {
|
|
|
74
85
|
* @return [VertexBuffer]
|
|
75
86
|
* @raise [RuntimeError] if creation fails
|
|
76
87
|
*/
|
|
77
|
-
static VALUE
|
|
88
|
+
static VALUE VertexBuffer_initialize(int argc, VALUE* argv, VALUE self) {
|
|
78
89
|
VALUE rb_count, rb_primitive, rb_usage;
|
|
79
90
|
size_t count = 0;
|
|
80
91
|
sfPrimitiveType primitive = sfPoints;
|
|
81
92
|
sfVertexBufferUsage usage = sfVertexBufferStatic;
|
|
93
|
+
sfVertexBuffer* buffer;
|
|
82
94
|
|
|
83
95
|
rb_scan_args(argc, argv, "03", &rb_count, &rb_primitive, &rb_usage);
|
|
84
96
|
|
|
@@ -94,7 +106,15 @@ static VALUE VertexBuffer_new(int argc, VALUE* argv, VALUE klass) {
|
|
|
94
106
|
usage = usage_from_rb(rb_usage);
|
|
95
107
|
}
|
|
96
108
|
|
|
97
|
-
|
|
109
|
+
buffer = sfVertexBuffer_create(count, primitive, usage);
|
|
110
|
+
|
|
111
|
+
if (buffer == NULL) {
|
|
112
|
+
rb_raise(rb_eRuntimeError, "failed to create vertex buffer");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
DATA_PTR(self) = buffer;
|
|
116
|
+
|
|
117
|
+
return self;
|
|
98
118
|
}
|
|
99
119
|
|
|
100
120
|
/* call-seq: copy -> VertexBuffer
|
|
@@ -277,17 +297,14 @@ static VALUE VertexBuffer_is_available(VALUE klass) {
|
|
|
277
297
|
* RenderState
|
|
278
298
|
*/
|
|
279
299
|
static VALUE VertexBuffer_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
|
|
280
|
-
|
|
281
|
-
raise_invalid_argument_class(Get_Klass_Target());
|
|
282
|
-
}
|
|
300
|
+
TargetView view = Get_RenderTarget_View(rb_target);
|
|
283
301
|
|
|
284
302
|
if (!rb_obj_is_kind_of(rb_state, Get_Klass_RenderState())) {
|
|
285
303
|
raise_invalid_argument_class(Get_Klass_RenderState());
|
|
286
304
|
}
|
|
287
305
|
|
|
288
|
-
TARGET_DRAW(
|
|
289
|
-
|
|
290
|
-
Get_RenderState_Struct(rb_state));
|
|
306
|
+
TARGET_DRAW(view, sfRenderWindow_drawVertexBuffer, sfRenderTexture_drawVertexBuffer,
|
|
307
|
+
Get_VertexBuffer_Struct(self), Get_RenderState_Struct(rb_state));
|
|
291
308
|
|
|
292
309
|
return Qnil;
|
|
293
310
|
}
|
|
@@ -309,9 +326,12 @@ static VALUE VertexBuffer_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
|
|
|
309
326
|
void Init_VertexBuffer(VALUE rb_mSFML) {
|
|
310
327
|
rb_cVertexBuffer = rb_define_class_under(rb_mSFML, "VertexBuffer", rb_cObject);
|
|
311
328
|
|
|
329
|
+
rb_define_alloc_func(rb_cVertexBuffer, VertexBuffer_alloc);
|
|
330
|
+
|
|
312
331
|
rb_include_module(rb_cVertexBuffer, Get_Module_Drawable());
|
|
313
332
|
|
|
314
|
-
|
|
333
|
+
rb_define_method(rb_cVertexBuffer, "initialize", VertexBuffer_initialize, -1);
|
|
334
|
+
rb_define_private_method(rb_cVertexBuffer, "initialize_copy", VertexBuffer_initialize_copy, 1);
|
|
315
335
|
rb_define_singleton_method(rb_cVertexBuffer, "available?", VertexBuffer_is_available, 0);
|
|
316
336
|
|
|
317
337
|
rb_define_method(rb_cVertexBuffer, "copy", VertexBuffer_copy, 0);
|
data/ext/graphics/view.c
CHANGED
|
@@ -42,15 +42,14 @@ static VALUE View_new_from(VALUE klass, sfView* c_view) {
|
|
|
42
42
|
return self;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return View_new_from(klass, NULL);
|
|
45
|
+
static VALUE View_alloc(VALUE klass) {
|
|
46
|
+
sfView* view = View_create();
|
|
47
|
+
|
|
48
|
+
if (view == NULL) {
|
|
49
|
+
rb_raise(rb_eRuntimeError, "failed to create view");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return TypedData_Wrap_Struct(klass, &View_data_type, view);
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
/* The rect is the visible area: position is the top-left corner, not the
|
|
@@ -67,6 +66,13 @@ static VALUE View_s_from_rect(VALUE klass, VALUE rb_rect) {
|
|
|
67
66
|
return View_new_from(klass, sfView_createFromRect(rect_from_rb(rb_rect)));
|
|
68
67
|
}
|
|
69
68
|
|
|
69
|
+
/* call-seq:
|
|
70
|
+
* View.new -> View
|
|
71
|
+
*
|
|
72
|
+
* Creates a default view covering the (0, 0) - (1000, 1000) region.
|
|
73
|
+
*
|
|
74
|
+
* @return [View]
|
|
75
|
+
*/
|
|
70
76
|
static VALUE View_init(VALUE self) {
|
|
71
77
|
return self;
|
|
72
78
|
}
|
|
@@ -257,7 +263,7 @@ static VALUE View_copy(VALUE self) {
|
|
|
257
263
|
void Init_View(VALUE rb_mSFML) {
|
|
258
264
|
rb_cView = rb_define_class_under(rb_mSFML, "View", rb_cObject);
|
|
259
265
|
|
|
260
|
-
|
|
266
|
+
rb_define_alloc_func(rb_cView, View_alloc);
|
|
261
267
|
rb_define_singleton_method(rb_cView, "from_rect", View_s_from_rect, 1);
|
|
262
268
|
|
|
263
269
|
// methods
|
data/ext/network/ftp.c
CHANGED
|
@@ -130,6 +130,29 @@ static VALUE FtpListingResponse_wrap(sfFtpListingResponse* handle) {
|
|
|
130
130
|
return TypedData_Wrap_Struct(rb_cFtpListingResponse, &FtpListingResponse_data_type, ptr);
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
static VALUE Ftp_alloc(VALUE klass) {
|
|
134
|
+
(void)klass;
|
|
135
|
+
return Ftp_wrap(sfFtp_create());
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
static VALUE FtpResponse_alloc(VALUE klass) {
|
|
139
|
+
(void)klass;
|
|
140
|
+
rb_raise(rb_eNotImpError, "FTP response objects are returned by Ftp methods and cannot be "
|
|
141
|
+
"constructed directly");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
static VALUE FtpDirectoryResponse_alloc(VALUE klass) {
|
|
145
|
+
(void)klass;
|
|
146
|
+
rb_raise(rb_eNotImpError, "FTP response objects are returned by Ftp methods and cannot be "
|
|
147
|
+
"constructed directly");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
static VALUE FtpListingResponse_alloc(VALUE klass) {
|
|
151
|
+
(void)klass;
|
|
152
|
+
rb_raise(rb_eNotImpError, "FTP response objects are returned by Ftp methods and cannot be "
|
|
153
|
+
"constructed directly");
|
|
154
|
+
}
|
|
155
|
+
|
|
133
156
|
/* call-seq:
|
|
134
157
|
* Ftp.new -> Ftp
|
|
135
158
|
*
|
|
@@ -137,8 +160,8 @@ static VALUE FtpListingResponse_wrap(sfFtpListingResponse* handle) {
|
|
|
137
160
|
*
|
|
138
161
|
* @return [Ftp]
|
|
139
162
|
*/
|
|
140
|
-
static VALUE
|
|
141
|
-
return
|
|
163
|
+
static VALUE Ftp_initialize(VALUE self) {
|
|
164
|
+
return self;
|
|
142
165
|
}
|
|
143
166
|
|
|
144
167
|
/* call-seq:
|
|
@@ -550,22 +573,26 @@ static VALUE FtpListingResponse_name(VALUE self, VALUE rb_index) {
|
|
|
550
573
|
*/
|
|
551
574
|
void Init_Ftp(VALUE rb_mSFML) {
|
|
552
575
|
rb_cFtp = rb_define_class_under(rb_mSFML, "Ftp", rb_cObject);
|
|
576
|
+
rb_define_alloc_func(rb_cFtp, Ftp_alloc);
|
|
553
577
|
/* Document-class: SFML::FtpResponse
|
|
554
578
|
* The status and message returned by most Ftp commands.
|
|
555
579
|
*/
|
|
556
580
|
rb_cFtpResponse = rb_define_class_under(rb_mSFML, "FtpResponse", rb_cObject);
|
|
581
|
+
rb_define_alloc_func(rb_cFtpResponse, FtpResponse_alloc);
|
|
557
582
|
/* Document-class: SFML::FtpDirectoryResponse
|
|
558
583
|
* An FtpResponse specialization returned by Ftp#working_directory,
|
|
559
584
|
* additionally carrying the directory path.
|
|
560
585
|
*/
|
|
561
586
|
rb_cFtpDirectoryResponse = rb_define_class_under(rb_mSFML, "FtpDirectoryResponse", rb_cObject);
|
|
587
|
+
rb_define_alloc_func(rb_cFtpDirectoryResponse, FtpDirectoryResponse_alloc);
|
|
562
588
|
/* Document-class: SFML::FtpListingResponse
|
|
563
589
|
* An FtpResponse specialization returned by Ftp#directory_listing,
|
|
564
590
|
* additionally carrying the list of filenames.
|
|
565
591
|
*/
|
|
566
592
|
rb_cFtpListingResponse = rb_define_class_under(rb_mSFML, "FtpListingResponse", rb_cObject);
|
|
593
|
+
rb_define_alloc_func(rb_cFtpListingResponse, FtpListingResponse_alloc);
|
|
567
594
|
|
|
568
|
-
|
|
595
|
+
rb_define_method(rb_cFtp, "initialize", Ftp_initialize, 0);
|
|
569
596
|
|
|
570
597
|
rb_define_method(rb_cFtp, "connect", Ftp_connect, -1);
|
|
571
598
|
rb_define_method(rb_cFtp, "login_anonymous", Ftp_login_anonymous, 0);
|
data/ext/network/http.c
CHANGED
|
@@ -98,6 +98,20 @@ static VALUE HttpResponse_wrap(sfHttpResponse* handle) {
|
|
|
98
98
|
return TypedData_Wrap_Struct(rb_cHttpResponse, &HttpResponse_data_type, ptr);
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
static VALUE Http_alloc(VALUE klass) {
|
|
102
|
+
return Http_wrap(klass, sfHttp_create());
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static VALUE HttpRequest_alloc(VALUE klass) {
|
|
106
|
+
return HttpRequest_wrap(klass, sfHttpRequest_create());
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static VALUE HttpResponse_alloc(VALUE klass) {
|
|
110
|
+
(void)klass;
|
|
111
|
+
rb_raise(rb_eNotImpError, "HTTP responses are returned by Http#send_request and cannot be "
|
|
112
|
+
"constructed directly");
|
|
113
|
+
}
|
|
114
|
+
|
|
101
115
|
/* call-seq:
|
|
102
116
|
* Http.new -> Http
|
|
103
117
|
*
|
|
@@ -105,8 +119,8 @@ static VALUE HttpResponse_wrap(sfHttpResponse* handle) {
|
|
|
105
119
|
*
|
|
106
120
|
* @return [Http]
|
|
107
121
|
*/
|
|
108
|
-
static VALUE
|
|
109
|
-
return
|
|
122
|
+
static VALUE Http_initialize(VALUE self) {
|
|
123
|
+
return self;
|
|
110
124
|
}
|
|
111
125
|
|
|
112
126
|
/* call-seq:
|
|
@@ -159,8 +173,8 @@ static VALUE Http_send_request(int argc, VALUE* argv, VALUE self) {
|
|
|
159
173
|
* @return [HttpRequest] a new request, defaulting to a GET of +"/"+ over
|
|
160
174
|
* HTTP/1.0 with no fields or body
|
|
161
175
|
*/
|
|
162
|
-
static VALUE
|
|
163
|
-
return
|
|
176
|
+
static VALUE HttpRequest_initialize(VALUE self) {
|
|
177
|
+
return self;
|
|
164
178
|
}
|
|
165
179
|
|
|
166
180
|
/* call-seq:
|
|
@@ -301,17 +315,20 @@ static VALUE HttpResponse_body(VALUE self) {
|
|
|
301
315
|
*/
|
|
302
316
|
void Init_Http(VALUE rb_mSFML) {
|
|
303
317
|
rb_cHttp = rb_define_class_under(rb_mSFML, "Http", rb_cObject);
|
|
318
|
+
rb_define_alloc_func(rb_cHttp, Http_alloc);
|
|
304
319
|
/* Document-class: SFML::HttpRequest
|
|
305
320
|
* An HTTP request to send via Http#send_request.
|
|
306
321
|
*/
|
|
307
322
|
rb_cHttpRequest = rb_define_class_under(rb_mSFML, "HttpRequest", rb_cObject);
|
|
323
|
+
rb_define_alloc_func(rb_cHttpRequest, HttpRequest_alloc);
|
|
308
324
|
/* Document-class: SFML::HttpResponse
|
|
309
325
|
* The status, headers and body returned by Http#send_request.
|
|
310
326
|
*/
|
|
311
327
|
rb_cHttpResponse = rb_define_class_under(rb_mSFML, "HttpResponse", rb_cObject);
|
|
328
|
+
rb_define_alloc_func(rb_cHttpResponse, HttpResponse_alloc);
|
|
312
329
|
|
|
313
|
-
|
|
314
|
-
|
|
330
|
+
rb_define_method(rb_cHttp, "initialize", Http_initialize, 0);
|
|
331
|
+
rb_define_method(rb_cHttpRequest, "initialize", HttpRequest_initialize, 0);
|
|
315
332
|
|
|
316
333
|
rb_define_method(rb_cHttp, "set_host", Http_set_host, 2);
|
|
317
334
|
rb_define_method(rb_cHttp, "send_request", Http_send_request, -1);
|
data/ext/network/ip_address.c
CHANGED
|
@@ -66,6 +66,18 @@ static VALUE IpAddress_from_integer(VALUE klass, VALUE rb_integer) {
|
|
|
66
66
|
return ip_address_to_rb(sfIpAddress_fromInteger((uint32_t)NUM2UINT(rb_integer)));
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
static VALUE IpAddress_alloc(VALUE klass) {
|
|
70
|
+
IpAddress* ptr = malloc(sizeof(IpAddress));
|
|
71
|
+
|
|
72
|
+
if (ptr == NULL) {
|
|
73
|
+
rb_raise(rb_eNoMemError, "failed to allocate IP address");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
ptr->address = sfIpAddress_None;
|
|
77
|
+
|
|
78
|
+
return TypedData_Wrap_Struct(klass, &IpAddress_data_type, ptr);
|
|
79
|
+
}
|
|
80
|
+
|
|
69
81
|
/* call-seq:
|
|
70
82
|
* IpAddress.new(address) -> IpAddress
|
|
71
83
|
*
|
|
@@ -75,22 +87,20 @@ static VALUE IpAddress_from_integer(VALUE klass, VALUE rb_integer) {
|
|
|
75
87
|
* @return [IpAddress]
|
|
76
88
|
* @raise [TypeError] if +address+ is none of the above
|
|
77
89
|
*/
|
|
78
|
-
static VALUE
|
|
79
|
-
|
|
80
|
-
return IpAddress_from_integer(klass, rb_address);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (RB_TYPE_P(rb_address, T_STRING)) {
|
|
84
|
-
return IpAddress_from_string(klass, rb_address);
|
|
85
|
-
}
|
|
90
|
+
static VALUE IpAddress_initialize(VALUE self, VALUE rb_address) {
|
|
91
|
+
IpAddress* ptr = (IpAddress*)Get_IpAddress_Struct(self);
|
|
86
92
|
|
|
87
|
-
if (
|
|
88
|
-
|
|
93
|
+
if (RB_INTEGER_TYPE_P(rb_address)) {
|
|
94
|
+
ptr->address = sfIpAddress_fromInteger((uint32_t)NUM2UINT(rb_address));
|
|
95
|
+
} else if (RB_TYPE_P(rb_address, T_STRING)) {
|
|
96
|
+
ptr->address = sfIpAddress_fromString(StringValueCStr(rb_address));
|
|
97
|
+
} else if (rb_obj_is_kind_of(rb_address, rb_cIpAddress)) {
|
|
98
|
+
ptr->address = ((IpAddress*)Get_IpAddress_Struct(rb_address))->address;
|
|
99
|
+
} else {
|
|
100
|
+
raise_invalid_argument_class(rb_cIpAddress);
|
|
89
101
|
}
|
|
90
102
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return Qnil;
|
|
103
|
+
return self;
|
|
94
104
|
}
|
|
95
105
|
|
|
96
106
|
/* call-seq:
|
|
@@ -185,8 +195,9 @@ static VALUE IpAddress_hash(VALUE self) {
|
|
|
185
195
|
*/
|
|
186
196
|
void Init_IpAddress(VALUE rb_mSFML) {
|
|
187
197
|
rb_cIpAddress = rb_define_class_under(rb_mSFML, "IpAddress", rb_cObject);
|
|
198
|
+
rb_define_alloc_func(rb_cIpAddress, IpAddress_alloc);
|
|
188
199
|
|
|
189
|
-
|
|
200
|
+
rb_define_method(rb_cIpAddress, "initialize", IpAddress_initialize, 1);
|
|
190
201
|
rb_define_singleton_method(rb_cIpAddress, "from_string", IpAddress_from_string, 1);
|
|
191
202
|
rb_define_singleton_method(rb_cIpAddress, "from_bytes", IpAddress_from_bytes, 4);
|
|
192
203
|
rb_define_singleton_method(rb_cIpAddress, "from_integer", IpAddress_from_integer, 1);
|
data/ext/network/packet.c
CHANGED
|
@@ -38,6 +38,10 @@ static VALUE Packet_wrap(VALUE klass, sfPacket* packet) {
|
|
|
38
38
|
return TypedData_Wrap_Struct(klass, &Packet_data_type, ptr);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
static VALUE Packet_alloc(VALUE klass) {
|
|
42
|
+
return Packet_wrap(klass, sfPacket_create());
|
|
43
|
+
}
|
|
44
|
+
|
|
41
45
|
/* call-seq:
|
|
42
46
|
* Packet.new -> Packet
|
|
43
47
|
*
|
|
@@ -45,8 +49,8 @@ static VALUE Packet_wrap(VALUE klass, sfPacket* packet) {
|
|
|
45
49
|
*
|
|
46
50
|
* @return [Packet] a new, empty packet
|
|
47
51
|
*/
|
|
48
|
-
static VALUE
|
|
49
|
-
return
|
|
52
|
+
static VALUE Packet_initialize(VALUE self) {
|
|
53
|
+
return self;
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
/* call-seq: copy -> Packet
|
|
@@ -230,8 +234,9 @@ static VALUE Packet_write_string(VALUE self, VALUE rb_value) {
|
|
|
230
234
|
*/
|
|
231
235
|
void Init_Packet(VALUE rb_mSFML) {
|
|
232
236
|
rb_cPacket = rb_define_class_under(rb_mSFML, "Packet", rb_cObject);
|
|
237
|
+
rb_define_alloc_func(rb_cPacket, Packet_alloc);
|
|
233
238
|
|
|
234
|
-
|
|
239
|
+
rb_define_method(rb_cPacket, "initialize", Packet_initialize, 0);
|
|
235
240
|
|
|
236
241
|
rb_define_method(rb_cPacket, "copy", Packet_copy, 0);
|
|
237
242
|
rb_define_method(rb_cPacket, "append", Packet_append, 1);
|
|
@@ -41,6 +41,10 @@ static VALUE SocketSelector_wrap(VALUE klass, sfSocketSelector* handle) {
|
|
|
41
41
|
return TypedData_Wrap_Struct(klass, &SocketSelector_data_type, ptr);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
static VALUE SocketSelector_alloc(VALUE klass) {
|
|
45
|
+
return SocketSelector_wrap(klass, sfSocketSelector_create());
|
|
46
|
+
}
|
|
47
|
+
|
|
44
48
|
/* call-seq:
|
|
45
49
|
* SocketSelector.new -> SocketSelector
|
|
46
50
|
*
|
|
@@ -48,8 +52,8 @@ static VALUE SocketSelector_wrap(VALUE klass, sfSocketSelector* handle) {
|
|
|
48
52
|
*
|
|
49
53
|
* @return [SocketSelector]
|
|
50
54
|
*/
|
|
51
|
-
static VALUE
|
|
52
|
-
return
|
|
55
|
+
static VALUE SocketSelector_initialize(VALUE self) {
|
|
56
|
+
return self;
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
/* call-seq: copy -> SocketSelector
|
|
@@ -189,8 +193,9 @@ static VALUE SocketSelector_udp_socket_ready(VALUE self, VALUE rb_socket) {
|
|
|
189
193
|
*/
|
|
190
194
|
void Init_SocketSelector(VALUE rb_mSFML) {
|
|
191
195
|
rb_cSocketSelector = rb_define_class_under(rb_mSFML, "SocketSelector", rb_cObject);
|
|
196
|
+
rb_define_alloc_func(rb_cSocketSelector, SocketSelector_alloc);
|
|
192
197
|
|
|
193
|
-
|
|
198
|
+
rb_define_method(rb_cSocketSelector, "initialize", SocketSelector_initialize, 0);
|
|
194
199
|
|
|
195
200
|
rb_define_method(rb_cSocketSelector, "copy", SocketSelector_copy, 0);
|
|
196
201
|
rb_define_method(rb_cSocketSelector, "add", SocketSelector_add, 1);
|
data/ext/network/tcp_listener.c
CHANGED
|
@@ -42,6 +42,10 @@ static VALUE TcpListener_wrap(VALUE klass, sfTcpListener* handle) {
|
|
|
42
42
|
return TypedData_Wrap_Struct(klass, &TcpListener_data_type, ptr);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
static VALUE TcpListener_alloc(VALUE klass) {
|
|
46
|
+
return TcpListener_wrap(klass, sfTcpListener_create());
|
|
47
|
+
}
|
|
48
|
+
|
|
45
49
|
/* call-seq:
|
|
46
50
|
* TcpListener.new -> TcpListener
|
|
47
51
|
*
|
|
@@ -49,8 +53,8 @@ static VALUE TcpListener_wrap(VALUE klass, sfTcpListener* handle) {
|
|
|
49
53
|
*
|
|
50
54
|
* @return [TcpListener]
|
|
51
55
|
*/
|
|
52
|
-
static VALUE
|
|
53
|
-
return
|
|
56
|
+
static VALUE TcpListener_initialize(VALUE self) {
|
|
57
|
+
return self;
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
/* call-seq:
|
|
@@ -151,8 +155,9 @@ static VALUE TcpListener_accept(VALUE self) {
|
|
|
151
155
|
*/
|
|
152
156
|
void Init_TcpListener(VALUE rb_mSFML) {
|
|
153
157
|
rb_cTcpListener = rb_define_class_under(rb_mSFML, "TcpListener", rb_cObject);
|
|
158
|
+
rb_define_alloc_func(rb_cTcpListener, TcpListener_alloc);
|
|
154
159
|
|
|
155
|
-
|
|
160
|
+
rb_define_method(rb_cTcpListener, "initialize", TcpListener_initialize, 0);
|
|
156
161
|
rb_define_singleton_method(rb_cTcpListener, "any_port", TcpListener_any_port, 0);
|
|
157
162
|
|
|
158
163
|
rb_define_method(rb_cTcpListener, "blocking?", TcpListener_blocking, 0);
|
data/ext/network/tcp_socket.c
CHANGED
|
@@ -47,6 +47,10 @@ VALUE tcp_socket_from_handle(sfTcpSocket* socket) {
|
|
|
47
47
|
return TcpSocket_wrap(rb_cTcpSocket, socket);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
static VALUE TcpSocket_alloc(VALUE klass) {
|
|
51
|
+
return TcpSocket_wrap(klass, sfTcpSocket_create());
|
|
52
|
+
}
|
|
53
|
+
|
|
50
54
|
/* call-seq:
|
|
51
55
|
* TcpSocket.new -> TcpSocket
|
|
52
56
|
*
|
|
@@ -54,8 +58,8 @@ VALUE tcp_socket_from_handle(sfTcpSocket* socket) {
|
|
|
54
58
|
*
|
|
55
59
|
* @return [TcpSocket] a new, unconnected socket
|
|
56
60
|
*/
|
|
57
|
-
static VALUE
|
|
58
|
-
return
|
|
61
|
+
static VALUE TcpSocket_initialize(VALUE self) {
|
|
62
|
+
return self;
|
|
59
63
|
}
|
|
60
64
|
|
|
61
65
|
/* call-seq: blocking? -> true or false
|
|
@@ -274,8 +278,9 @@ static VALUE TcpSocket_receive_packet(VALUE self, VALUE rb_packet) {
|
|
|
274
278
|
*/
|
|
275
279
|
void Init_TcpSocket(VALUE rb_mSFML) {
|
|
276
280
|
rb_cTcpSocket = rb_define_class_under(rb_mSFML, "TcpSocket", rb_cObject);
|
|
281
|
+
rb_define_alloc_func(rb_cTcpSocket, TcpSocket_alloc);
|
|
277
282
|
|
|
278
|
-
|
|
283
|
+
rb_define_method(rb_cTcpSocket, "initialize", TcpSocket_initialize, 0);
|
|
279
284
|
|
|
280
285
|
rb_define_method(rb_cTcpSocket, "blocking?", TcpSocket_blocking, 0);
|
|
281
286
|
rb_define_method(rb_cTcpSocket, "blocking=", TcpSocket_set_blocking, 1);
|
data/ext/network/udp_socket.c
CHANGED
|
@@ -42,6 +42,10 @@ static VALUE UdpSocket_wrap(VALUE klass, sfUdpSocket* handle) {
|
|
|
42
42
|
return TypedData_Wrap_Struct(klass, &UdpSocket_data_type, ptr);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
static VALUE UdpSocket_alloc(VALUE klass) {
|
|
46
|
+
return UdpSocket_wrap(klass, sfUdpSocket_create());
|
|
47
|
+
}
|
|
48
|
+
|
|
45
49
|
/* call-seq:
|
|
46
50
|
* UdpSocket.new -> UdpSocket
|
|
47
51
|
*
|
|
@@ -49,8 +53,8 @@ static VALUE UdpSocket_wrap(VALUE klass, sfUdpSocket* handle) {
|
|
|
49
53
|
*
|
|
50
54
|
* @return [UdpSocket] a new, unbound socket
|
|
51
55
|
*/
|
|
52
|
-
static VALUE
|
|
53
|
-
return
|
|
56
|
+
static VALUE UdpSocket_initialize(VALUE self) {
|
|
57
|
+
return self;
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
/* call-seq:
|
|
@@ -259,8 +263,9 @@ static VALUE UdpSocket_receive_packet(VALUE self, VALUE rb_packet) {
|
|
|
259
263
|
*/
|
|
260
264
|
void Init_UdpSocket(VALUE rb_mSFML) {
|
|
261
265
|
rb_cUdpSocket = rb_define_class_under(rb_mSFML, "UdpSocket", rb_cObject);
|
|
266
|
+
rb_define_alloc_func(rb_cUdpSocket, UdpSocket_alloc);
|
|
262
267
|
|
|
263
|
-
|
|
268
|
+
rb_define_method(rb_cUdpSocket, "initialize", UdpSocket_initialize, 0);
|
|
264
269
|
rb_define_singleton_method(rb_cUdpSocket, "any_port", UdpSocket_any_port, 0);
|
|
265
270
|
rb_define_singleton_method(rb_cUdpSocket, "max_datagram_size", UdpSocket_max_datagram_size, 0);
|
|
266
271
|
|
data/ext/system/buffer.c
CHANGED
|
@@ -20,6 +20,16 @@ static VALUE Buffer_wrap(VALUE klass, sfBuffer* buffer) {
|
|
|
20
20
|
return TypedData_Wrap_Struct(klass, &Buffer_data_type, buffer);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
static VALUE Buffer_alloc(VALUE klass) {
|
|
24
|
+
sfBuffer* buffer = sfBuffer_create();
|
|
25
|
+
|
|
26
|
+
if (buffer == NULL) {
|
|
27
|
+
rb_raise(rb_eNoMemError, "could not create buffer");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return Buffer_wrap(klass, buffer);
|
|
31
|
+
}
|
|
32
|
+
|
|
23
33
|
/* call-seq:
|
|
24
34
|
* Buffer.new -> Buffer
|
|
25
35
|
*
|
|
@@ -28,16 +38,7 @@ static VALUE Buffer_wrap(VALUE klass, sfBuffer* buffer) {
|
|
|
28
38
|
* @return [Buffer] a new, empty buffer
|
|
29
39
|
* @raise [NoMemoryError] if the underlying buffer could not be allocated
|
|
30
40
|
*/
|
|
31
|
-
static VALUE
|
|
32
|
-
VALUE self;
|
|
33
|
-
sfBuffer* buffer = sfBuffer_create();
|
|
34
|
-
|
|
35
|
-
if (buffer == NULL) {
|
|
36
|
-
rb_raise(rb_eNoMemError, "could not create buffer");
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
self = Buffer_wrap(klass, buffer);
|
|
40
|
-
|
|
41
|
+
static VALUE Buffer_initialize(VALUE self) {
|
|
41
42
|
return self;
|
|
42
43
|
}
|
|
43
44
|
|
|
@@ -86,7 +87,8 @@ static VALUE Buffer_is_empty(VALUE self) {
|
|
|
86
87
|
void Init_Buffer(VALUE rb_mSFML) {
|
|
87
88
|
rb_cBuffer = rb_define_class_under(rb_mSFML, "Buffer", rb_cObject);
|
|
88
89
|
|
|
89
|
-
|
|
90
|
+
rb_define_alloc_func(rb_cBuffer, Buffer_alloc);
|
|
91
|
+
rb_define_method(rb_cBuffer, "initialize", Buffer_initialize, 0);
|
|
90
92
|
|
|
91
93
|
rb_define_method(rb_cBuffer, "size", Buffer_get_size, 0);
|
|
92
94
|
rb_define_method(rb_cBuffer, "length", Buffer_get_size, 0);
|