ray 0.0.0.pre1 → 0.0.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +15 -0
- data/.gitmodules +3 -0
- data/Rakefile +148 -5
- data/VERSION +1 -1
- data/ext/event.c +535 -0
- data/ext/extconf.rb +7 -1
- data/ext/image.c +110 -18
- data/ext/joystick.c +145 -0
- data/ext/ray.c +288 -35
- data/ext/ray.h +54 -2
- data/lib/ray/config.rb +84 -0
- data/lib/ray/dsl.rb +19 -0
- data/lib/ray/dsl/converter.rb +65 -0
- data/lib/ray/dsl/event.rb +52 -0
- data/lib/ray/dsl/event_raiser.rb +21 -0
- data/lib/ray/dsl/event_runner.rb +39 -0
- data/lib/ray/dsl/event_translator.rb +38 -0
- data/lib/ray/dsl/handler.rb +71 -0
- data/lib/ray/dsl/listener.rb +30 -0
- data/lib/ray/dsl/matcher.rb +60 -0
- data/lib/ray/dsl/type.rb +58 -0
- data/lib/ray/game.rb +107 -0
- data/lib/ray/helper.rb +17 -0
- data/lib/ray/image.rb +11 -0
- data/lib/ray/ray.rb +8 -0
- data/lib/ray/scene.rb +102 -0
- data/psp/SDL_psp_main.c +84 -0
- data/psp/bigdecimal/README +60 -0
- data/psp/bigdecimal/bigdecimal.c +4697 -0
- data/psp/bigdecimal/bigdecimal.h +216 -0
- data/psp/bigdecimal/lib/bigdecimal/jacobian.rb +85 -0
- data/psp/bigdecimal/lib/bigdecimal/ludcmp.rb +84 -0
- data/psp/bigdecimal/lib/bigdecimal/math.rb +235 -0
- data/psp/bigdecimal/lib/bigdecimal/newton.rb +77 -0
- data/psp/bigdecimal/lib/bigdecimal/util.rb +65 -0
- data/psp/digest/bubblebabble/bubblebabble.c +142 -0
- data/psp/digest/defs.h +20 -0
- data/psp/digest/digest.c +643 -0
- data/psp/digest/digest.h +32 -0
- data/psp/digest/lib/digest.rb +50 -0
- data/psp/digest/lib/md5.rb +27 -0
- data/psp/digest/lib/sha1.rb +27 -0
- data/psp/digest/md5/md5.c +420 -0
- data/psp/digest/md5/md5.h +80 -0
- data/psp/digest/md5/md5init.c +40 -0
- data/psp/digest/rmd160/rmd160.c +457 -0
- data/psp/digest/rmd160/rmd160.h +56 -0
- data/psp/digest/rmd160/rmd160init.c +40 -0
- data/psp/digest/sha1/sha1.c +269 -0
- data/psp/digest/sha1/sha1.h +39 -0
- data/psp/digest/sha1/sha1init.c +40 -0
- data/psp/digest/sha2/lib/sha2.rb +73 -0
- data/psp/digest/sha2/sha2.c +919 -0
- data/psp/digest/sha2/sha2.h +109 -0
- data/psp/digest/sha2/sha2init.c +52 -0
- data/psp/enumerator/enumerator.c +298 -0
- data/psp/etc/etc.c +559 -0
- data/psp/ext.c +285 -0
- data/psp/fcntl/fcntl.c +187 -0
- data/psp/lib/rbconfig.rb +178 -0
- data/psp/nkf/lib/kconv.rb +367 -0
- data/psp/nkf/nkf-utf8/config.h +88 -0
- data/psp/nkf/nkf-utf8/nkf.c +6040 -0
- data/psp/nkf/nkf-utf8/utf8tbl.c +8500 -0
- data/psp/nkf/nkf-utf8/utf8tbl.h +34 -0
- data/psp/nkf/nkf.c +654 -0
- data/psp/socket/addrinfo.h +173 -0
- data/psp/socket/getaddrinfo.c +676 -0
- data/psp/socket/getnameinfo.c +270 -0
- data/psp/socket/pspsocket.c +71 -0
- data/psp/socket/pspsocket.h +28 -0
- data/psp/socket/socket.c +4662 -0
- data/psp/socket/sockport.h +76 -0
- data/psp/stringio/stringio.c +1306 -0
- data/psp/strscan/strscan.c +1320 -0
- data/psp/syck/bytecode.c +1166 -0
- data/psp/syck/emitter.c +1242 -0
- data/psp/syck/gram.c +1894 -0
- data/psp/syck/gram.h +79 -0
- data/psp/syck/handler.c +174 -0
- data/psp/syck/implicit.c +2990 -0
- data/psp/syck/node.c +408 -0
- data/psp/syck/rubyext.c +2367 -0
- data/psp/syck/syck.c +504 -0
- data/psp/syck/syck.h +456 -0
- data/psp/syck/token.c +2725 -0
- data/psp/syck/yaml2byte.c +257 -0
- data/psp/syck/yamlbyte.h +170 -0
- data/psp/thread/thread.c +1175 -0
- data/psp/zlib/zlib.c +3547 -0
- data/script.rb +10 -0
- data/spec/ray/config_spec.rb +90 -0
- data/spec/ray/conversion_spec.rb +43 -0
- data/spec/ray/event_spec.rb +191 -0
- data/spec/ray/image_spec.rb +43 -1
- data/spec/ray/joystick_spec.rb +17 -0
- data/spec/ray/matcher_spec.rb +73 -0
- data/spec/ray/ray_spec.rb +72 -1
- data/spec/ray/type_spec.rb +17 -0
- data/spec/res/aqua.bmp +0 -0
- data/spec/res/aqua.png +0 -0
- data/spec/res/not_a_jpeg.jpeg +0 -0
- data/spec_runner.rb +4 -0
- metadata +101 -9
- data/ext/Makefile +0 -189
- data/ext/ray +0 -0
- data/ext/ray.bundle +0 -0
- data/ext/ray_ext.bundle +0 -0
- data/ext/ray_ext.so +0 -0
- data/ext/test.rb +0 -21
data/ext/extconf.rb
CHANGED
@@ -29,7 +29,7 @@ def have_framework(name)
|
|
29
29
|
$LDFLAGS << " -F#{File.dirname(ret)}"
|
30
30
|
$LDFLAGS << " -framework #{name}"
|
31
31
|
$CFLAGS << " -I#{File.join(ret, "Headers")}"
|
32
|
-
$CFLAGS << " -
|
32
|
+
$CFLAGS << " -DHAVE_#{name.upcase}"
|
33
33
|
else
|
34
34
|
puts "no"
|
35
35
|
end
|
@@ -56,6 +56,10 @@ unless RUBY_PLATFORM =~ /darwin/
|
|
56
56
|
exit 1
|
57
57
|
end
|
58
58
|
|
59
|
+
if have_library("SDL_image")
|
60
|
+
have_header("SDL/SDL_image.h") or have_header("SDL_image.h")
|
61
|
+
end
|
62
|
+
|
59
63
|
create_makefile("ray_ext")
|
60
64
|
|
61
65
|
data = File.read("Makefile").gsub("SDLMain.o", "")
|
@@ -75,6 +79,8 @@ else
|
|
75
79
|
exit 1
|
76
80
|
end
|
77
81
|
|
82
|
+
have_framework("SDL_image")
|
83
|
+
|
78
84
|
have_library("ruby", "ruby_init")
|
79
85
|
|
80
86
|
create_makefile("ray_ext")
|
data/ext/image.c
CHANGED
@@ -18,24 +18,7 @@ SDL_Surface *ray_rb2surface(VALUE object) {
|
|
18
18
|
return ray_rb2image(object)->surface;
|
19
19
|
}
|
20
20
|
|
21
|
-
|
22
|
-
Creates a new image. You must call Ray.create_window before
|
23
|
-
this function.
|
24
|
-
|
25
|
-
@overload initialize(hash)
|
26
|
-
@option hash [Integer] :width Width of the surface
|
27
|
-
@option hash [Integer] :height Height of the surface
|
28
|
-
|
29
|
-
@option hash [Integer] :w Alias for width
|
30
|
-
@option hash [Integer] :h Alias for height
|
31
|
-
|
32
|
-
@option hash [Integer] :bits_per_pixel See Ray.create_window
|
33
|
-
@option hash [Integer] :pp Alias for bits_per_pixel
|
34
|
-
|
35
|
-
@option hash [true, false] :hw_surface See Ray.create_window
|
36
|
-
@option hash [true, false] :sw_surface See Ray.create_window
|
37
|
-
*/
|
38
|
-
VALUE ray_init_image(VALUE self, VALUE arg) {
|
21
|
+
void ray_init_image_with_hash(VALUE self, VALUE arg) {
|
39
22
|
VALUE width = rb_hash_aref(arg, RAY_SYM("width"));
|
40
23
|
if (NIL_P(width)) width = rb_hash_aref(arg, RAY_SYM("w"));
|
41
24
|
|
@@ -63,7 +46,59 @@ VALUE ray_init_image(VALUE self, VALUE arg) {
|
|
63
46
|
rb_raise(rb_eRuntimeError, "Could not create the image (%s)",
|
64
47
|
SDL_GetError());
|
65
48
|
}
|
49
|
+
}
|
50
|
+
|
51
|
+
void ray_init_image_with_filename(VALUE self, VALUE filename) {
|
52
|
+
char *c_filename = StringValuePtr(filename);
|
53
|
+
ray_image *image = ray_rb2image(self);
|
54
|
+
|
55
|
+
#ifdef HAVE_SDL_IMAGE
|
56
|
+
image->surface = IMG_Load(c_filename);
|
57
|
+
|
58
|
+
if (!image->surface) {
|
59
|
+
rb_raise(rb_eRuntimeError, "Could not create the image (%s)",
|
60
|
+
IMG_GetError());
|
61
|
+
}
|
62
|
+
#else
|
63
|
+
image->surface = SDL_LoadBMP(c_filename);
|
66
64
|
|
65
|
+
if (!image->surface) {
|
66
|
+
rb_raise(rb_eRuntimeError, "Could not create the image (%s)",
|
67
|
+
SDL_GetError());
|
68
|
+
}
|
69
|
+
#endif
|
70
|
+
}
|
71
|
+
|
72
|
+
/*
|
73
|
+
Creates a new image.
|
74
|
+
|
75
|
+
@overload initialize(hash)
|
76
|
+
@option hash [Integer] :width Width of the surface
|
77
|
+
@option hash [Integer] :height Height of the surface
|
78
|
+
|
79
|
+
@option hash [Integer] :w Alias for width
|
80
|
+
@option hash [Integer] :h Alias for height
|
81
|
+
|
82
|
+
@option hash [Integer] :bits_per_pixel See Ray.create_window
|
83
|
+
@option hash [Integer] :pp Alias for bits_per_pixel
|
84
|
+
|
85
|
+
@option hash [true, false] :hw_surface See Ray.create_window
|
86
|
+
@option hash [true, false] :sw_surface See Ray.create_window
|
87
|
+
|
88
|
+
@overload initialize(filename)
|
89
|
+
Loads the image from a file.
|
90
|
+
@param [String, #to_str] filename The name of the file to open
|
91
|
+
*/
|
92
|
+
VALUE ray_init_image(VALUE self, VALUE arg) {
|
93
|
+
if (RAY_IS_A(arg, rb_cHash))
|
94
|
+
ray_init_image_with_hash(self, arg);
|
95
|
+
else if (rb_respond_to(arg, RAY_METH("to_str")))
|
96
|
+
ray_init_image_with_filename(self, rb_String(arg));
|
97
|
+
else {
|
98
|
+
rb_raise(rb_eTypeError, "Can't convert %s into Hash",
|
99
|
+
RAY_OBJ_CLASSNAME(arg));
|
100
|
+
}
|
101
|
+
|
67
102
|
return Qnil;
|
68
103
|
}
|
69
104
|
|
@@ -179,6 +214,40 @@ VALUE ray_image_blit(VALUE self, VALUE hash) {
|
|
179
214
|
return surf;
|
180
215
|
}
|
181
216
|
|
217
|
+
/*
|
218
|
+
Sets the alpha transparency.
|
219
|
+
@param [Integer, 0..255] alpha the new transparency
|
220
|
+
*/
|
221
|
+
VALUE ray_image_set_alpha(VALUE self, VALUE alpha) {
|
222
|
+
SDL_SetAlpha(ray_rb2surface(self), SDL_SRCALPHA | SDL_RLEACCEL,
|
223
|
+
NUM2INT(alpha));
|
224
|
+
return alpha;
|
225
|
+
}
|
226
|
+
|
227
|
+
/*
|
228
|
+
Returns the flags of an image (an OR'd combination of the Ray::Image::FLAG_*
|
229
|
+
constants)
|
230
|
+
*/
|
231
|
+
VALUE ray_image_flags(VALUE self) {
|
232
|
+
uint32_t flags = ray_rb2surface(self)->flags;
|
233
|
+
return INT2NUM(flags);
|
234
|
+
}
|
235
|
+
|
236
|
+
/* @return [Integer] Width of the surface */
|
237
|
+
VALUE ray_image_width(VALUE self) {
|
238
|
+
return INT2FIX(ray_rb2surface(self)->w);
|
239
|
+
}
|
240
|
+
|
241
|
+
/* @return [Integer] Height of the surface */
|
242
|
+
VALUE ray_image_height(VALUE self) {
|
243
|
+
return INT2FIX(ray_rb2surface(self)->h);
|
244
|
+
}
|
245
|
+
|
246
|
+
/* @return [Integer] Bits per pixel */
|
247
|
+
VALUE ray_image_bpp(VALUE self) {
|
248
|
+
return INT2FIX(ray_rb2surface(self)->format->BitsPerPixel);
|
249
|
+
}
|
250
|
+
|
182
251
|
void Init_ray_image() {
|
183
252
|
ray_cImage = rb_define_class_under(ray_mRay, "Image", rb_cObject);
|
184
253
|
|
@@ -189,4 +258,27 @@ void Init_ray_image() {
|
|
189
258
|
rb_define_method(ray_cImage, "flip", ray_image_flip, 0);
|
190
259
|
|
191
260
|
rb_define_method(ray_cImage, "blit", ray_image_blit, 1);
|
261
|
+
|
262
|
+
rb_define_method(ray_cImage, "alpha=", ray_image_set_alpha, 1);
|
263
|
+
|
264
|
+
rb_define_method(ray_cImage, "flags", ray_image_flags, 0);
|
265
|
+
|
266
|
+
rb_define_method(ray_cImage, "width", ray_image_width, 0);
|
267
|
+
rb_define_method(ray_cImage, "height", ray_image_height, 0);
|
268
|
+
rb_define_method(ray_cImage, "bpp", ray_image_bpp, 0);
|
269
|
+
|
270
|
+
rb_define_const(ray_cImage, "FLAG_ANYFORMAT", INT2FIX(SDL_ANYFORMAT));
|
271
|
+
rb_define_const(ray_cImage, "FLAG_ASYNCBLIT", INT2FIX(SDL_ASYNCBLIT));
|
272
|
+
rb_define_const(ray_cImage, "FLAG_DOUBLEBUF", INT2FIX(SDL_DOUBLEBUF));
|
273
|
+
rb_define_const(ray_cImage, "FLAG_HWPALETTE", INT2FIX(SDL_HWPALETTE));
|
274
|
+
rb_define_const(ray_cImage, "FLAG_HWACCEL", INT2FIX(SDL_HWACCEL));
|
275
|
+
rb_define_const(ray_cImage, "FLAG_HWSURFACE", INT2FIX(SDL_HWSURFACE));
|
276
|
+
rb_define_const(ray_cImage, "FLAG_FULLSCREEN", INT2FIX(SDL_FULLSCREEN));
|
277
|
+
rb_define_const(ray_cImage, "FLAG_OPENGL", INT2FIX(SDL_OPENGL));
|
278
|
+
rb_define_const(ray_cImage, "FLAG_OPENGLBLIT", INT2FIX(SDL_OPENGLBLIT));
|
279
|
+
rb_define_const(ray_cImage, "FLAG_RESIZABLE", INT2FIX(SDL_RESIZABLE));
|
280
|
+
rb_define_const(ray_cImage, "FLAG_RLEACCEL", INT2FIX(SDL_RLEACCEL));
|
281
|
+
rb_define_const(ray_cImage, "FLAG_SRCALPHA", INT2FIX(SDL_SRCALPHA));
|
282
|
+
rb_define_const(ray_cImage, "FLAG_SRCCOLORKEY", INT2FIX(SDL_SRCCOLORKEY));
|
283
|
+
rb_define_const(ray_cImage, "FLAG_PREALLOC", INT2FIX(SDL_PREALLOC));
|
192
284
|
}
|
data/ext/joystick.c
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
#include "ray.h"
|
2
|
+
|
3
|
+
VALUE ray_cJoystick = Qnil;
|
4
|
+
|
5
|
+
SDL_Joystick *ray_rb2joystick(VALUE object) {
|
6
|
+
if (!RAY_IS_A(object, ray_cJoystick)) {
|
7
|
+
rb_raise(rb_eTypeError, "Can't convert %s into Ray::Joystick",
|
8
|
+
RAY_OBJ_CLASSNAME(object));
|
9
|
+
}
|
10
|
+
|
11
|
+
ray_joystick *joy = NULL;
|
12
|
+
Data_Get_Struct(object, ray_joystick, joy);
|
13
|
+
|
14
|
+
if (!joy->joystick)
|
15
|
+
rb_raise(rb_eRuntimeError, "Trying to get a joystick that is not opened.");
|
16
|
+
|
17
|
+
return joy->joystick;
|
18
|
+
}
|
19
|
+
|
20
|
+
void ray_free_joystick(ray_joystick *ptr) {
|
21
|
+
if (ptr->joystick) SDL_JoystickClose(ptr->joystick);
|
22
|
+
free(ptr);
|
23
|
+
}
|
24
|
+
|
25
|
+
VALUE ray_alloc_joystick(VALUE self) {
|
26
|
+
ray_joystick *ptr = malloc(sizeof(ray_joystick));
|
27
|
+
ptr->joystick = NULL;
|
28
|
+
|
29
|
+
return Data_Wrap_Struct(self, NULL, ray_free_joystick, ptr);
|
30
|
+
}
|
31
|
+
|
32
|
+
/*
|
33
|
+
Creates a new joystick, and open it. You don't need to close it explictly,
|
34
|
+
although doing multiple call to
|
35
|
+
@param [Integer] stick_id Identifier for this stick. Should be smaller
|
36
|
+
than Ray::Joystick.count.
|
37
|
+
*/
|
38
|
+
VALUE ray_init_joystick(VALUE self, VALUE stick_id) {
|
39
|
+
rb_iv_set(self, "@id", stick_id);
|
40
|
+
rb_funcall2(self, RAY_METH("open"), 0, NULL);
|
41
|
+
return Qnil;
|
42
|
+
}
|
43
|
+
|
44
|
+
/* @return [Integer] the number of joysticks available */
|
45
|
+
VALUE ray_joystick_count(VALUE self) {
|
46
|
+
return INT2FIX(SDL_NumJoysticks());
|
47
|
+
}
|
48
|
+
|
49
|
+
/*
|
50
|
+
@return [true, false] True if events coming from the joystick are handled.
|
51
|
+
*/
|
52
|
+
VALUE ray_joystick_handle_event(VALUE self) {
|
53
|
+
return SDL_JoystickEventState(SDL_QUERY) ? Qtrue : Qfalse;
|
54
|
+
}
|
55
|
+
|
56
|
+
/*
|
57
|
+
Sets whether we should handle events coming from the joystick.
|
58
|
+
*/
|
59
|
+
VALUE ray_joystick_set_handle_event(VALUE self, VALUE val) {
|
60
|
+
SDL_JoystickEventState(RTEST(val) ? SDL_ENABLE : SDL_DISABLE);
|
61
|
+
return val;
|
62
|
+
}
|
63
|
+
|
64
|
+
/* Opens the joystick */
|
65
|
+
VALUE ray_joystick_open(VALUE self) {
|
66
|
+
int id = NUM2INT(rb_iv_get(self, "@id"));
|
67
|
+
SDL_Joystick *ptr = SDL_JoystickOpen(id);
|
68
|
+
|
69
|
+
if (!ptr) {
|
70
|
+
rb_raise(rb_eArgError, "Failled to open joystick %d (%s)",
|
71
|
+
id, SDL_GetError());
|
72
|
+
}
|
73
|
+
|
74
|
+
ray_joystick *joy = NULL;
|
75
|
+
Data_Get_Struct(self, ray_joystick, joy);
|
76
|
+
|
77
|
+
joy->joystick = ptr;
|
78
|
+
|
79
|
+
return self;
|
80
|
+
}
|
81
|
+
|
82
|
+
/* Closes the joystick. Can be called even if closed? is true. */
|
83
|
+
VALUE ray_joystick_close(VALUE self) {
|
84
|
+
if (ray_joystick_close(self) == Qtrue)
|
85
|
+
return Qnil;
|
86
|
+
|
87
|
+
SDL_JoystickClose(ray_rb2joystick(self));
|
88
|
+
|
89
|
+
ray_joystick *joy = NULL;
|
90
|
+
Data_Get_Struct(self, ray_joystick, joy);
|
91
|
+
|
92
|
+
joy->joystick = NULL;
|
93
|
+
|
94
|
+
return Qnil;
|
95
|
+
}
|
96
|
+
|
97
|
+
/* @return [true, false] true if the joystick is closed */
|
98
|
+
VALUE ray_joystick_closed(VALUE self) {
|
99
|
+
ray_joystick *joy = NULL;
|
100
|
+
Data_Get_Struct(self, ray_joystick, joy);
|
101
|
+
|
102
|
+
return joy->joystick == NULL ? Qtrue : Qfalse;
|
103
|
+
}
|
104
|
+
|
105
|
+
/* @return [Integer] The number of buttons on this joystick */
|
106
|
+
VALUE ray_joystick_button_count(VALUE self) {
|
107
|
+
return INT2FIX(SDL_JoystickNumButtons(ray_rb2joystick(self)));
|
108
|
+
}
|
109
|
+
|
110
|
+
/* @return [Integer] The number of axes on this joystick */
|
111
|
+
VALUE ray_joystick_axe_count(VALUE self) {
|
112
|
+
return INT2FIX(SDL_JoystickNumAxes(ray_rb2joystick(self)));
|
113
|
+
}
|
114
|
+
|
115
|
+
/* @return [Integer] The number of trackballs on this joystick */
|
116
|
+
VALUE ray_joystick_ball_count(VALUE self) {
|
117
|
+
return INT2FIX(SDL_JoystickNumBalls(ray_rb2joystick(self)));
|
118
|
+
}
|
119
|
+
|
120
|
+
/* @return [Integer] The number of hats on this joystick */
|
121
|
+
VALUE ray_joystick_hat_count(VALUE self) {
|
122
|
+
return INT2FIX(SDL_JoystickNumHats(ray_rb2joystick(self)));
|
123
|
+
}
|
124
|
+
|
125
|
+
void Init_ray_joystick() {
|
126
|
+
ray_cJoystick = rb_define_class_under(ray_mRay, "Joystick", rb_cObject);
|
127
|
+
rb_define_alloc_func(ray_cJoystick, ray_alloc_joystick);
|
128
|
+
rb_define_method(ray_cJoystick, "initialize", ray_init_joystick, 1);
|
129
|
+
|
130
|
+
rb_define_module_function(ray_cJoystick, "count", ray_joystick_count, 0);
|
131
|
+
|
132
|
+
rb_define_module_function(ray_cJoystick, "handle_event=",
|
133
|
+
ray_joystick_set_handle_event, 1);
|
134
|
+
rb_define_module_function(ray_cJoystick, "handle_event",
|
135
|
+
ray_joystick_handle_event, 0);
|
136
|
+
|
137
|
+
rb_define_method(ray_cJoystick, "open", ray_joystick_open, 0);
|
138
|
+
rb_define_method(ray_cJoystick, "close", ray_joystick_close, 0);
|
139
|
+
rb_define_method(ray_cJoystick, "closed?", ray_joystick_closed, 0);
|
140
|
+
|
141
|
+
rb_define_method(ray_cJoystick, "button_count", ray_joystick_button_count, 0);
|
142
|
+
rb_define_method(ray_cJoystick, "axe_count", ray_joystick_axe_count, 0);
|
143
|
+
rb_define_method(ray_cJoystick, "hat_count", ray_joystick_hat_count, 0);
|
144
|
+
rb_define_method(ray_cJoystick, "ball_count", ray_joystick_ball_count, 0);
|
145
|
+
}
|
data/ext/ray.c
CHANGED
@@ -4,7 +4,7 @@ VALUE ray_mRay = Qnil;
|
|
4
4
|
|
5
5
|
/* Inits ray */
|
6
6
|
VALUE ray_init(VALUE self) {
|
7
|
-
SDL_Init(SDL_INIT_VIDEO);
|
7
|
+
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
|
8
8
|
return Qnil;
|
9
9
|
}
|
10
10
|
|
@@ -14,6 +14,54 @@ VALUE ray_stop(VALUE self) {
|
|
14
14
|
return Qnil;
|
15
15
|
}
|
16
16
|
|
17
|
+
ray_video_mode ray_parse_video_mode(VALUE hash) {
|
18
|
+
VALUE width = rb_hash_aref(hash, RAY_SYM("width"));
|
19
|
+
VALUE height = rb_hash_aref(hash, RAY_SYM("height"));
|
20
|
+
|
21
|
+
if (NIL_P(width)) width = rb_hash_aref(hash, RAY_SYM("w"));
|
22
|
+
if (NIL_P(height)) height = rb_hash_aref(hash, RAY_SYM("h"));
|
23
|
+
|
24
|
+
if (NIL_P(width) || NIL_P(height))
|
25
|
+
rb_raise(rb_eArgError, "Missing parameter: width or height");
|
26
|
+
|
27
|
+
VALUE bitsperpixel = rb_hash_aref(hash, RAY_SYM("bits_per_pixel"));
|
28
|
+
if (NIL_P(bitsperpixel)) bitsperpixel = rb_hash_aref(hash, RAY_SYM("bpp"));
|
29
|
+
|
30
|
+
if (NIL_P(bitsperpixel))
|
31
|
+
bitsperpixel = INT2FIX(32);
|
32
|
+
|
33
|
+
uint32_t flags = 0;
|
34
|
+
if (RTEST(rb_hash_aref(hash, RAY_SYM("sw_surface"))))
|
35
|
+
flags |= SDL_SWSURFACE;
|
36
|
+
else
|
37
|
+
flags |= SDL_HWSURFACE; /* even if hwsurface was false and not nil */
|
38
|
+
|
39
|
+
if (RTEST(rb_hash_aref(hash, RAY_SYM("async_blit"))))
|
40
|
+
flags |= SDL_ASYNCBLIT;
|
41
|
+
|
42
|
+
if (!(flags & SDL_SWSURFACE) &&
|
43
|
+
RTEST(rb_hash_aref(hash, RAY_SYM("double_buf")))) {
|
44
|
+
flags |= SDL_DOUBLEBUF;
|
45
|
+
}
|
46
|
+
|
47
|
+
if (RTEST(rb_hash_aref(hash, RAY_SYM("fullscreen"))))
|
48
|
+
flags |= SDL_FULLSCREEN;
|
49
|
+
|
50
|
+
if (RTEST(rb_hash_aref(hash, RAY_SYM("no_frame"))))
|
51
|
+
flags |= SDL_NOFRAME;
|
52
|
+
|
53
|
+
ray_video_mode mode = {
|
54
|
+
NUM2INT(width),
|
55
|
+
NUM2INT(height),
|
56
|
+
|
57
|
+
NUM2INT(bitsperpixel),
|
58
|
+
|
59
|
+
flags
|
60
|
+
};
|
61
|
+
|
62
|
+
return mode;
|
63
|
+
}
|
64
|
+
|
17
65
|
/*
|
18
66
|
Creates a new window.
|
19
67
|
|
@@ -46,51 +94,114 @@ VALUE ray_stop(VALUE self) {
|
|
46
94
|
possible.
|
47
95
|
*/
|
48
96
|
VALUE ray_create_window(VALUE self, VALUE hash) {
|
49
|
-
|
50
|
-
|
97
|
+
ray_video_mode mode = ray_parse_video_mode(hash);
|
98
|
+
SDL_Surface *screen = SDL_SetVideoMode(mode.width, mode.height,
|
99
|
+
mode.bpp, mode.flags);
|
100
|
+
|
101
|
+
if (!screen) {
|
102
|
+
rb_raise(rb_eRuntimeError, "Could not create the window (%s)",
|
103
|
+
SDL_GetError());
|
104
|
+
}
|
51
105
|
|
52
|
-
|
53
|
-
|
106
|
+
return ray_create_image(screen);
|
107
|
+
}
|
54
108
|
|
55
|
-
|
56
|
-
|
109
|
+
/*
|
110
|
+
@return [true, false] True if the video mode described by hash
|
111
|
+
can be used.
|
112
|
+
*/
|
113
|
+
VALUE ray_can_use_mode(VALUE self, VALUE hash) {
|
114
|
+
ray_video_mode mode = ray_parse_video_mode(hash);
|
115
|
+
|
116
|
+
int res = SDL_VideoModeOK(mode.width, mode.height, mode.bpp, mode.flags);
|
117
|
+
return res ? Qtrue : Qfalse;
|
118
|
+
}
|
57
119
|
|
58
|
-
|
59
|
-
|
120
|
+
/*
|
121
|
+
Sets the window icon
|
122
|
+
@param [Ray::Image] icon The icon to display
|
123
|
+
*/
|
124
|
+
VALUE ray_set_icon(VALUE self, VALUE icon) {
|
125
|
+
SDL_WM_SetIcon(ray_rb2surface(icon), NULL);
|
126
|
+
return icon;
|
127
|
+
}
|
60
128
|
|
61
|
-
|
62
|
-
|
129
|
+
/* @return [String, nil] The window title */
|
130
|
+
VALUE ray_window_title(VALUE self) {
|
131
|
+
char *title = NULL;
|
132
|
+
SDL_WM_GetCaption(&title, NULL);
|
63
133
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
flags |= SDL_HWSURFACE; /* even if hwsurface was false and not nil */
|
134
|
+
if (!title)
|
135
|
+
return Qnil;
|
136
|
+
return rb_str_new2(title);
|
137
|
+
}
|
69
138
|
|
70
|
-
|
71
|
-
|
139
|
+
/* Sets the window title */
|
140
|
+
VALUE ray_set_window_title(VALUE self, VALUE title) {
|
141
|
+
char *icon = NULL;
|
72
142
|
|
73
|
-
if (!(
|
74
|
-
RTEST(rb_hash_aref(hash, RAY_SYM("double_buf")))) {
|
75
|
-
flags |= SDL_DOUBLEBUF;
|
76
|
-
}
|
143
|
+
if (!NIL_P(title)) title = rb_String(title);
|
77
144
|
|
78
|
-
|
79
|
-
|
145
|
+
SDL_WM_GetCaption(NULL, &icon);
|
146
|
+
SDL_WM_SetCaption(NIL_P(title) ? NULL : StringValuePtr(title), icon);
|
80
147
|
|
81
|
-
|
82
|
-
|
148
|
+
return title;
|
149
|
+
}
|
83
150
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
if (!screen) {
|
89
|
-
rb_raise(rb_eRuntimeError, "Could not create the window (%s)",
|
90
|
-
SDL_GetError());
|
91
|
-
}
|
151
|
+
/* @return [String, nil] The window text icon */
|
152
|
+
VALUE ray_text_icon(VALUE self) {
|
153
|
+
char *icon = NULL;
|
154
|
+
SDL_WM_GetCaption(NULL, &icon);
|
92
155
|
|
93
|
-
|
156
|
+
if (!icon)
|
157
|
+
return Qnil;
|
158
|
+
return rb_str_new2(icon);
|
159
|
+
}
|
160
|
+
|
161
|
+
/* Sets the window title */
|
162
|
+
VALUE ray_set_text_icon(VALUE self, VALUE icon) {
|
163
|
+
char *title;
|
164
|
+
|
165
|
+
if (!NIL_P(icon)) icon = rb_String(icon);
|
166
|
+
|
167
|
+
SDL_WM_GetCaption(&title, NULL);
|
168
|
+
SDL_WM_SetCaption(title, NIL_P(icon) ? NULL : StringValuePtr(icon));
|
169
|
+
|
170
|
+
return icon;
|
171
|
+
}
|
172
|
+
|
173
|
+
/*
|
174
|
+
@return [true, false] True if the input is grabbed, which means the mouse
|
175
|
+
is confined in the window, and keyboard input is sent
|
176
|
+
directly to the window.
|
177
|
+
*/
|
178
|
+
VALUE ray_grab_input(VALUE self) {
|
179
|
+
SDL_GrabMode mode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
|
180
|
+
return (mode == SDL_GRAB_ON) ? Qtrue : Qfalse;
|
181
|
+
}
|
182
|
+
|
183
|
+
/* Sets the grab input to true or false */
|
184
|
+
VALUE ray_set_grab_input(VALUE self, VALUE grab) {
|
185
|
+
SDL_WM_GrabInput(RTEST(grab) ? SDL_GRAB_ON : SDL_GRAB_OFF);
|
186
|
+
return grab;
|
187
|
+
}
|
188
|
+
|
189
|
+
/* @return [Ray::Image, nil] The current screen, created by create_window */
|
190
|
+
VALUE ray_screen(VALUE self) {
|
191
|
+
SDL_Surface *surf = SDL_GetVideoSurface();
|
192
|
+
|
193
|
+
if (!surf)
|
194
|
+
return Qnil;
|
195
|
+
return ray_create_image(surf);
|
196
|
+
}
|
197
|
+
|
198
|
+
/* @return [true, false] true if Ray supports other image formats than BMP */
|
199
|
+
VALUE ray_has_image_support(VALUE self) {
|
200
|
+
#ifdef HAVE_SDL_IMAGE
|
201
|
+
return Qtrue;
|
202
|
+
#else
|
203
|
+
return Qfalse;
|
204
|
+
#endif
|
94
205
|
}
|
95
206
|
|
96
207
|
void Init_ray_ext() {
|
@@ -98,13 +209,38 @@ void Init_ray_ext() {
|
|
98
209
|
|
99
210
|
rb_define_module_function(ray_mRay, "init", ray_init, 0);
|
100
211
|
rb_define_module_function(ray_mRay, "stop", ray_stop, 0);
|
212
|
+
|
101
213
|
rb_define_module_function(ray_mRay, "create_window", ray_create_window, 1);
|
214
|
+
rb_define_module_function(ray_mRay, "can_use_mode?", ray_can_use_mode, 1);
|
215
|
+
rb_define_module_function(ray_mRay, "screen", ray_screen, 0);
|
216
|
+
|
217
|
+
rb_define_module_function(ray_mRay, "icon=", ray_set_icon, 1);
|
218
|
+
rb_define_module_function(ray_mRay, "window_title=", ray_set_window_title,
|
219
|
+
1);
|
220
|
+
rb_define_module_function(ray_mRay, "text_icon=", ray_set_text_icon, 1);
|
221
|
+
|
222
|
+
rb_define_module_function(ray_mRay, "window_title", ray_window_title, 0);
|
223
|
+
rb_define_module_function(ray_mRay, "text_icon", ray_text_icon, 0);
|
224
|
+
|
225
|
+
rb_define_module_function(ray_mRay, "grab_input", ray_grab_input, 0);
|
226
|
+
rb_define_module_function(ray_mRay, "grab_input=", ray_set_grab_input, 1);
|
227
|
+
|
228
|
+
rb_define_module_function(ray_mRay, "has_image_support?",
|
229
|
+
ray_has_image_support, 0);
|
102
230
|
|
103
231
|
Init_ray_image();
|
104
232
|
Init_ray_color();
|
105
233
|
Init_ray_rect();
|
234
|
+
Init_ray_event();
|
235
|
+
Init_ray_joystick();
|
236
|
+
|
237
|
+
#ifdef PSP
|
238
|
+
Init_ray_psp();
|
239
|
+
#endif
|
106
240
|
}
|
107
241
|
|
242
|
+
#ifndef PSP
|
243
|
+
|
108
244
|
int main(int argc, char *argv[]) {
|
109
245
|
#if defined(HAVE_RUBY_RUN_NODE)
|
110
246
|
ruby_init();
|
@@ -123,3 +259,120 @@ int main(int argc, char *argv[]) {
|
|
123
259
|
|
124
260
|
return 0;
|
125
261
|
}
|
262
|
+
|
263
|
+
#endif
|
264
|
+
|
265
|
+
#ifdef PSP
|
266
|
+
|
267
|
+
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
|
268
|
+
PSP_HEAP_SIZE_KB(-512);
|
269
|
+
|
270
|
+
#include <unistd.h>
|
271
|
+
|
272
|
+
#define RGB(r, g, b) ((r) | ((g)<<8) | ((b)<<16) | (0xff<<24))
|
273
|
+
|
274
|
+
VALUE ray_safe_load(VALUE self) {
|
275
|
+
return rb_require("./script.rb");
|
276
|
+
}
|
277
|
+
|
278
|
+
int SDL_main(int argc, char *argv[]) {
|
279
|
+
ruby_init();
|
280
|
+
|
281
|
+
ruby_incpush("./ruby/1.8");
|
282
|
+
ruby_incpush("./ruby/site_ruby");
|
283
|
+
ruby_incpush("./ruby/site_ruby/1.8");
|
284
|
+
|
285
|
+
ruby_incpush("ms0:/ruby/1.8");
|
286
|
+
ruby_incpush("ms0:/ruby/site_ruby");
|
287
|
+
ruby_incpush("ms0:/ruby/site_ruby/1.8");
|
288
|
+
|
289
|
+
ruby_incpush(".");
|
290
|
+
|
291
|
+
ruby_script("ray");
|
292
|
+
|
293
|
+
Init_ray_ext();
|
294
|
+
|
295
|
+
int error = 0;
|
296
|
+
VALUE res = rb_protect(ray_safe_load, 0, &error);
|
297
|
+
|
298
|
+
if (error != 0) {
|
299
|
+
pspDebugScreenInit();
|
300
|
+
|
301
|
+
pspDebugScreenSetBackColor(RGB(0, 0, 0));
|
302
|
+
pspDebugScreenEnableBackColor(1);
|
303
|
+
|
304
|
+
pspDebugScreenClear();
|
305
|
+
pspDebugScreenSetXY(0, 0);
|
306
|
+
|
307
|
+
pspDebugScreenSetTextColor(RGB(255, 0, 0));
|
308
|
+
pspDebugScreenPrintf("Ray - error manager\n\n\n");
|
309
|
+
pspDebugScreenSetTextColor(RGB(255, 255, 255));
|
310
|
+
|
311
|
+
pspDebugScreenPrintf("This is Ray's error manager.An exception ");
|
312
|
+
pspDebugScreenPrintf("has been thrown, and the script ");
|
313
|
+
pspDebugScreenPrintf("cannot be run. If you're the developper of");
|
314
|
+
pspDebugScreenPrintf(" this application,\ncheck yout script.");
|
315
|
+
pspDebugScreenPrintf(" If it seems fine to you, consider ");
|
316
|
+
pspDebugScreenPrintf("filling a bug report.\n");
|
317
|
+
pspDebugScreenPrintf("If you're not the developper, consider");
|
318
|
+
pspDebugScreenPrintf(" contacting him.\n\n\n");
|
319
|
+
|
320
|
+
pspDebugScreenSetTextColor(RGB(255, 0, 0));
|
321
|
+
pspDebugScreenPrintf("Errors informations :\n\n\n");
|
322
|
+
pspDebugScreenSetTextColor(RGB(255, 255, 255));
|
323
|
+
|
324
|
+
// Now, we get the error.
|
325
|
+
VALUE error = rb_gv_get("$!");
|
326
|
+
|
327
|
+
// And the information we want to have about it.
|
328
|
+
VALUE backtrace = rb_funcall(error, RAY_METH("backtrace"), 0);
|
329
|
+
VALUE type = rb_funcall(error, RAY_METH("class"), 0);
|
330
|
+
VALUE msg = rb_funcall(error, RAY_METH("message"), 0);
|
331
|
+
|
332
|
+
type = rb_funcall(type, RAY_METH("to_s"), 0);
|
333
|
+
|
334
|
+
VALUE first = rb_ary_entry(backtrace, 0);
|
335
|
+
|
336
|
+
FILE *log = fopen("ray-error.log", "w");
|
337
|
+
if (!log) {
|
338
|
+
sceKernelExitGame();
|
339
|
+
return 1;
|
340
|
+
}
|
341
|
+
|
342
|
+
pspDebugScreenPrintf("%s: %s: %s\n", StringValuePtr(first),
|
343
|
+
StringValuePtr(type),
|
344
|
+
StringValuePtr(msg));
|
345
|
+
fprintf(log, "%s: %s: %s\n", StringValuePtr(first), StringValuePtr(type),
|
346
|
+
StringValuePtr(msg));
|
347
|
+
|
348
|
+
int i = 1;
|
349
|
+
for (i = 1; i < RARRAY_LEN(backtrace); ++i) {
|
350
|
+
VALUE entry = rb_ary_entry(backtrace, i);
|
351
|
+
pspDebugScreenPrintf("%s\n", StringValuePtr(entry));
|
352
|
+
fprintf(log, "%s\n", StringValuePtr(entry));
|
353
|
+
}
|
354
|
+
|
355
|
+
fclose(log);
|
356
|
+
|
357
|
+
pspDebugScreenPrintf("\nThese informations can be found in ");
|
358
|
+
pspDebugScreenPrintf("ray-error.log\n\n");
|
359
|
+
|
360
|
+
pspDebugScreenPrintf("Press X to quit.");
|
361
|
+
|
362
|
+
SceCtrlData pad;
|
363
|
+
|
364
|
+
sceCtrlSetSamplingCycle(0);
|
365
|
+
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
|
366
|
+
sceCtrlReadBufferPositive(&pad, 1);
|
367
|
+
|
368
|
+
while (!(pad.Buttons & PSP_CTRL_CROSS))
|
369
|
+
sceCtrlReadBufferPositive(&pad, 1);
|
370
|
+
|
371
|
+
sceKernelExitGame();
|
372
|
+
return 0;
|
373
|
+
}
|
374
|
+
|
375
|
+
return res;
|
376
|
+
}
|
377
|
+
|
378
|
+
#endif
|