ray 0.0.1 → 0.1.0.pre1
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.
- data/.gemtest +0 -0
- data/.yardopts +4 -0
- data/README.md +17 -21
- data/Rakefile +18 -139
- data/VERSION +1 -1
- data/ext/audio.cpp +723 -0
- data/ext/{color.c → color.cpp} +25 -13
- data/ext/drawable.cpp +91 -0
- data/ext/event.cpp +460 -0
- data/ext/extconf.rb +5 -104
- data/ext/font.cpp +190 -0
- data/ext/image.cpp +733 -0
- data/ext/input.cpp +74 -0
- data/ext/ray.cpp +168 -0
- data/ext/ray.hpp +356 -0
- data/ext/{rect.c → rect.cpp} +51 -37
- data/ext/shader.cpp +169 -0
- data/ext/shape.cpp +409 -0
- data/ext/sprite.cpp +306 -0
- data/ext/text.cpp +181 -0
- data/ext/vector.cpp +215 -0
- data/guide.md +619 -0
- data/lib/ray/audio.rb +0 -41
- data/lib/ray/color.rb +32 -10
- data/lib/ray/drawable.rb +16 -0
- data/lib/ray/dsl/event_listener.rb +25 -2
- data/lib/ray/dsl/event_runner.rb +33 -5
- data/lib/ray/dsl/event_translator.rb +66 -30
- data/lib/ray/dsl/handler.rb +3 -2
- data/lib/ray/dsl/matcher.rb +58 -14
- data/lib/ray/font.rb +38 -96
- data/lib/ray/font_set.rb +8 -8
- data/lib/ray/game.rb +87 -66
- data/lib/ray/helper.rb +105 -10
- data/lib/ray/image.rb +150 -24
- data/lib/ray/image_set.rb +3 -1
- data/lib/ray/input.rb +10 -0
- data/lib/ray/music_set.rb +5 -3
- data/lib/ray/ray.rb +21 -9
- data/lib/ray/rect.rb +48 -7
- data/lib/ray/rmagick.rb +41 -0
- data/lib/ray/scene.rb +99 -43
- data/lib/ray/scene_list.rb +67 -0
- data/lib/ray/shape.rb +132 -0
- data/lib/ray/sound_set.rb +4 -2
- data/lib/ray/sprite.rb +49 -111
- data/lib/ray/text.rb +101 -0
- data/lib/ray/text_helper.rb +37 -0
- data/lib/ray/turtle.rb +215 -0
- data/lib/ray/vector.rb +226 -0
- data/samples/audio/spacial.rb +44 -0
- data/samples/hello_world/hello.rb +9 -13
- data/samples/hello_world/hello_dsl.rb +8 -12
- data/samples/hello_world/text.rb +15 -0
- data/samples/opengl/binding.rb +38 -0
- data/samples/opengl/image.rb +32 -0
- data/samples/opengl/opengl.rb +34 -0
- data/samples/opengl/shader.rb +42 -0
- data/samples/pong/pong.rb +14 -10
- data/samples/run_scene.rb +53 -0
- data/samples/shaders/scene.rb +40 -0
- data/samples/shaders/shaders.rb +42 -0
- data/samples/shaders/shape.rb +34 -0
- data/samples/sokoban/sokoban.rb +18 -18
- data/samples/test/actual_scene.rb +41 -0
- data/samples/test/scene_riot.rb +39 -0
- data/samples/test/scene_spec.rb +32 -0
- data/samples/test/scene_test_unit.rb +25 -0
- data/samples/turtle/byzantium.rb +45 -0
- data/samples/turtle/hilbert.rb +48 -0
- data/samples/turtle/koch.rb +55 -0
- data/samples/turtle/mandala.rb +61 -0
- data/samples/turtle/tree.rb +57 -0
- data/test/audio_test.rb +69 -0
- data/test/color_test.rb +77 -0
- data/test/drawable_test.rb +19 -0
- data/test/dsl_test.rb +93 -0
- data/test/font_test.rb +57 -0
- data/test/helpers.rb +94 -0
- data/test/image_test.rb +82 -0
- data/test/ray_test.rb +25 -0
- data/test/rect_test.rb +121 -0
- data/{spec → test}/res/VeraMono.ttf +0 -0
- data/{spec → test}/res/aqua.bmp +0 -0
- data/{spec → test}/res/aqua.png +0 -0
- data/{spec → test}/res/aqua2.bmp +0 -0
- data/{spec → test}/res/not_a_jpeg.jpeg +0 -0
- data/{spec → test}/res/pop.wav +0 -0
- data/test/resource_set_test.rb +99 -0
- data/test/run_all.rb +7 -0
- data/test/shape_test.rb +101 -0
- data/test/sprite_test.rb +89 -0
- data/test/text_test.rb +78 -0
- data/test/turtle_test.rb +176 -0
- data/test/vector_test.rb +111 -0
- data/yard_ext.rb +0 -28
- metadata +95 -139
- data/.gitignore +0 -23
- data/.gitmodules +0 -3
- data/.rspec +0 -3
- data/ext/audio.c +0 -473
- data/ext/event.c +0 -557
- data/ext/font.c +0 -287
- data/ext/image.c +0 -933
- data/ext/joystick.c +0 -145
- data/ext/ray.c +0 -489
- data/ext/ray.h +0 -245
- data/ext/ray_osx.m +0 -161
- data/lib/ray/joystick.rb +0 -30
- data/psp/SDL_psp_main.c +0 -84
- data/psp/bigdecimal/README +0 -60
- data/psp/bigdecimal/bigdecimal.c +0 -4697
- data/psp/bigdecimal/bigdecimal.h +0 -216
- data/psp/bigdecimal/lib/bigdecimal/jacobian.rb +0 -85
- data/psp/bigdecimal/lib/bigdecimal/ludcmp.rb +0 -84
- data/psp/bigdecimal/lib/bigdecimal/math.rb +0 -235
- data/psp/bigdecimal/lib/bigdecimal/newton.rb +0 -77
- data/psp/bigdecimal/lib/bigdecimal/util.rb +0 -65
- data/psp/digest/bubblebabble/bubblebabble.c +0 -142
- data/psp/digest/defs.h +0 -20
- data/psp/digest/digest.c +0 -643
- data/psp/digest/digest.h +0 -32
- data/psp/digest/lib/digest.rb +0 -50
- data/psp/digest/lib/md5.rb +0 -27
- data/psp/digest/lib/sha1.rb +0 -27
- data/psp/digest/md5/md5.c +0 -420
- data/psp/digest/md5/md5.h +0 -80
- data/psp/digest/md5/md5init.c +0 -40
- data/psp/digest/rmd160/rmd160.c +0 -457
- data/psp/digest/rmd160/rmd160.h +0 -56
- data/psp/digest/rmd160/rmd160init.c +0 -40
- data/psp/digest/sha1/sha1.c +0 -269
- data/psp/digest/sha1/sha1.h +0 -39
- data/psp/digest/sha1/sha1init.c +0 -40
- data/psp/digest/sha2/lib/sha2.rb +0 -73
- data/psp/digest/sha2/sha2.c +0 -919
- data/psp/digest/sha2/sha2.h +0 -109
- data/psp/digest/sha2/sha2init.c +0 -52
- data/psp/enumerator/enumerator.c +0 -298
- data/psp/etc/etc.c +0 -559
- data/psp/ext.c +0 -289
- data/psp/fcntl/fcntl.c +0 -187
- data/psp/lib/rbconfig.rb +0 -178
- data/psp/nkf/lib/kconv.rb +0 -367
- data/psp/nkf/nkf-utf8/config.h +0 -88
- data/psp/nkf/nkf-utf8/nkf.c +0 -6040
- data/psp/nkf/nkf-utf8/utf8tbl.c +0 -8500
- data/psp/nkf/nkf-utf8/utf8tbl.h +0 -34
- data/psp/nkf/nkf.c +0 -654
- data/psp/socket/addrinfo.h +0 -173
- data/psp/socket/getaddrinfo.c +0 -676
- data/psp/socket/getnameinfo.c +0 -270
- data/psp/socket/pspsocket.c +0 -71
- data/psp/socket/pspsocket.h +0 -28
- data/psp/socket/socket.c +0 -4662
- data/psp/socket/sockport.h +0 -76
- data/psp/stringio/stringio.c +0 -1306
- data/psp/strscan/strscan.c +0 -1320
- data/psp/syck/bytecode.c +0 -1166
- data/psp/syck/emitter.c +0 -1242
- data/psp/syck/gram.c +0 -1894
- data/psp/syck/gram.h +0 -79
- data/psp/syck/handler.c +0 -174
- data/psp/syck/implicit.c +0 -2990
- data/psp/syck/node.c +0 -408
- data/psp/syck/rubyext.c +0 -2367
- data/psp/syck/syck.c +0 -504
- data/psp/syck/syck.h +0 -456
- data/psp/syck/token.c +0 -2725
- data/psp/syck/yaml2byte.c +0 -257
- data/psp/syck/yamlbyte.h +0 -170
- data/psp/thread/thread.c +0 -1175
- data/psp/zlib/zlib.c +0 -3547
- data/script.rb +0 -10
- data/spec/ray/audio_spec.rb +0 -146
- data/spec/ray/color_spec.rb +0 -57
- data/spec/ray/event_spec.rb +0 -80
- data/spec/ray/font_spec.rb +0 -93
- data/spec/ray/image_set_spec.rb +0 -48
- data/spec/ray/image_spec.rb +0 -162
- data/spec/ray/joystick_spec.rb +0 -21
- data/spec/ray/matcher_spec.rb +0 -50
- data/spec/ray/ray_spec.rb +0 -88
- data/spec/ray/rect_spec.rb +0 -154
- data/spec/ray/resource_set_spec.rb +0 -105
- data/spec/ray/sprite_spec.rb +0 -163
- data/spec/spec.opts +0 -4
- data/spec/spec_helper.rb +0 -8
data/ext/joystick.c
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
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
|
-
/* @return [true, false] true if the joystick is closed */
|
|
83
|
-
VALUE ray_joystick_closed(VALUE self) {
|
|
84
|
-
ray_joystick *joy = NULL;
|
|
85
|
-
Data_Get_Struct(self, ray_joystick, joy);
|
|
86
|
-
|
|
87
|
-
return joy->joystick == NULL ? Qtrue : Qfalse;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/* Closes the joystick. Can be called even if closed? is true. */
|
|
91
|
-
VALUE ray_joystick_close(VALUE self) {
|
|
92
|
-
if (ray_joystick_closed(self) == Qtrue)
|
|
93
|
-
return Qnil;
|
|
94
|
-
|
|
95
|
-
SDL_JoystickClose(ray_rb2joystick(self));
|
|
96
|
-
|
|
97
|
-
ray_joystick *joy = NULL;
|
|
98
|
-
Data_Get_Struct(self, ray_joystick, joy);
|
|
99
|
-
|
|
100
|
-
joy->joystick = NULL;
|
|
101
|
-
|
|
102
|
-
return Qnil;
|
|
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
DELETED
|
@@ -1,489 +0,0 @@
|
|
|
1
|
-
#include "ray.h"
|
|
2
|
-
|
|
3
|
-
#ifdef HAVE_COCOA
|
|
4
|
-
extern void ray_osx_init();
|
|
5
|
-
extern void ray_osx_close();
|
|
6
|
-
#endif
|
|
7
|
-
|
|
8
|
-
VALUE ray_mRay = Qnil;
|
|
9
|
-
|
|
10
|
-
/*
|
|
11
|
-
@overload init(opts = {})
|
|
12
|
-
Inits Ray.
|
|
13
|
-
|
|
14
|
-
@option opts [Integer] :frequency Audio frequency (defaults to 22050)
|
|
15
|
-
@option opts [Integer] :format A constant declared in Ray::Audio
|
|
16
|
-
@option opts [true] :mono or :stereo Set :mono or :stereo to true to enable
|
|
17
|
-
one of them.
|
|
18
|
-
@option opts [Integer] :chunk_size Size of a chunk (defaults to 1024)
|
|
19
|
-
*/
|
|
20
|
-
VALUE ray_init(int argc, VALUE *argv, VALUE self) {
|
|
21
|
-
VALUE hash = Qnil;
|
|
22
|
-
rb_scan_args(argc, argv, "01", &hash);
|
|
23
|
-
|
|
24
|
-
#ifdef HAVE_COCOA
|
|
25
|
-
ray_osx_init();
|
|
26
|
-
#endif
|
|
27
|
-
|
|
28
|
-
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) == -1) {
|
|
29
|
-
rb_raise(rb_eRuntimeError, "Couldn't init the SDL (%s)",
|
|
30
|
-
SDL_GetError());
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
#ifdef HAVE_SDL_TTF
|
|
34
|
-
if (!TTF_WasInit()) {
|
|
35
|
-
if (TTF_Init() == -1) {
|
|
36
|
-
rb_raise(rb_eRuntimeError, "Couldn't init SDL_TTF (%s)",
|
|
37
|
-
TTF_GetError());
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
#endif
|
|
41
|
-
|
|
42
|
-
#ifdef HAVE_SDL_MIXER
|
|
43
|
-
int frequency = MIX_DEFAULT_FREQUENCY;
|
|
44
|
-
uint16_t format = MIX_DEFAULT_FORMAT;
|
|
45
|
-
int channels = MIX_DEFAULT_CHANNELS;
|
|
46
|
-
int chunk_size = 1024;
|
|
47
|
-
|
|
48
|
-
if (!NIL_P(hash)) {
|
|
49
|
-
VALUE rb_freq, rb_format, rb_chunk_size;
|
|
50
|
-
if (!NIL_P(rb_freq = rb_hash_aref(hash, RAY_SYM("frequency"))))
|
|
51
|
-
frequency = NUM2INT(rb_freq);
|
|
52
|
-
|
|
53
|
-
if (!NIL_P(rb_format = rb_hash_aref(hash, RAY_SYM("format"))))
|
|
54
|
-
format = NUM2INT(rb_format);
|
|
55
|
-
|
|
56
|
-
if (RTEST(rb_hash_aref(hash, RAY_SYM("mono"))))
|
|
57
|
-
channels = 1;
|
|
58
|
-
else if (RTEST(rb_hash_aref(hash, RAY_SYM("stereo"))))
|
|
59
|
-
channels = 2;
|
|
60
|
-
|
|
61
|
-
if (!NIL_P(rb_chunk_size = rb_hash_aref(hash, RAY_SYM("chunk_size"))))
|
|
62
|
-
chunk_size = NUM2INT(rb_chunk_size);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (Mix_OpenAudio(frequency, format, channels, chunk_size) == -1) {
|
|
66
|
-
rb_raise(rb_eRuntimeError, "Couldn't open audio (%s)",
|
|
67
|
-
Mix_GetError());
|
|
68
|
-
}
|
|
69
|
-
#endif
|
|
70
|
-
|
|
71
|
-
return Qnil;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/* Stops ray */
|
|
75
|
-
VALUE ray_stop(VALUE self) {
|
|
76
|
-
#ifdef HAVE_SDL_MIXER
|
|
77
|
-
Mix_CloseAudio();
|
|
78
|
-
#endif
|
|
79
|
-
|
|
80
|
-
#ifdef HAVE_SDL_TTF
|
|
81
|
-
/*
|
|
82
|
-
Freeing a font after TTF_Quit causes a segfault, but, Ruby being
|
|
83
|
-
garbage called, we can't be sure a font won't be freed later.
|
|
84
|
-
*/
|
|
85
|
-
|
|
86
|
-
/* TTF_Quit(); */
|
|
87
|
-
#endif
|
|
88
|
-
|
|
89
|
-
SDL_Quit();
|
|
90
|
-
/* The pool is never drained on OSX */
|
|
91
|
-
return Qnil;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
ray_video_mode ray_parse_video_mode(VALUE hash) {
|
|
95
|
-
VALUE width = rb_hash_aref(hash, RAY_SYM("width"));
|
|
96
|
-
VALUE height = rb_hash_aref(hash, RAY_SYM("height"));
|
|
97
|
-
|
|
98
|
-
if (NIL_P(width)) width = rb_hash_aref(hash, RAY_SYM("w"));
|
|
99
|
-
if (NIL_P(height)) height = rb_hash_aref(hash, RAY_SYM("h"));
|
|
100
|
-
|
|
101
|
-
if (NIL_P(width) || NIL_P(height))
|
|
102
|
-
rb_raise(rb_eArgError, "Missing parameter: width or height");
|
|
103
|
-
|
|
104
|
-
VALUE bitsperpixel = rb_hash_aref(hash, RAY_SYM("bits_per_pixel"));
|
|
105
|
-
if (NIL_P(bitsperpixel)) bitsperpixel = rb_hash_aref(hash, RAY_SYM("bpp"));
|
|
106
|
-
|
|
107
|
-
if (NIL_P(bitsperpixel))
|
|
108
|
-
bitsperpixel = INT2FIX(32);
|
|
109
|
-
|
|
110
|
-
uint32_t flags = 0;
|
|
111
|
-
if (RTEST(rb_hash_aref(hash, RAY_SYM("sw_surface"))))
|
|
112
|
-
flags |= SDL_SWSURFACE;
|
|
113
|
-
else
|
|
114
|
-
flags |= SDL_HWSURFACE; /* even if hwsurface was false and not nil */
|
|
115
|
-
|
|
116
|
-
if (RTEST(rb_hash_aref(hash, RAY_SYM("async_blit"))))
|
|
117
|
-
flags |= SDL_ASYNCBLIT;
|
|
118
|
-
|
|
119
|
-
if (!(flags & SDL_SWSURFACE) &&
|
|
120
|
-
RTEST(rb_hash_aref(hash, RAY_SYM("double_buf")))) {
|
|
121
|
-
flags |= SDL_DOUBLEBUF;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (RTEST(rb_hash_aref(hash, RAY_SYM("fullscreen"))))
|
|
125
|
-
flags |= SDL_FULLSCREEN;
|
|
126
|
-
|
|
127
|
-
if (RTEST(rb_hash_aref(hash, RAY_SYM("no_frame"))))
|
|
128
|
-
flags |= SDL_NOFRAME;
|
|
129
|
-
|
|
130
|
-
if (RTEST(rb_hash_aref(hash, RAY_SYM("resizable"))))
|
|
131
|
-
flags |= SDL_RESIZABLE;
|
|
132
|
-
|
|
133
|
-
ray_video_mode mode = {
|
|
134
|
-
NUM2INT(width),
|
|
135
|
-
NUM2INT(height),
|
|
136
|
-
|
|
137
|
-
NUM2INT(bitsperpixel),
|
|
138
|
-
|
|
139
|
-
flags
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
return mode;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/*
|
|
146
|
-
@overload create_window(hash)
|
|
147
|
-
Creates a new window.
|
|
148
|
-
|
|
149
|
-
If both hw_surface and sws_urface are false, hw_surface
|
|
150
|
-
will be considered as true. :sw_surface should be true
|
|
151
|
-
if you want to acess
|
|
152
|
-
|
|
153
|
-
@return [Ray::Image] An image representing the window
|
|
154
|
-
|
|
155
|
-
@option hash [Integer] :width Width of the window
|
|
156
|
-
@option hash [Integer] :height Height of the window
|
|
157
|
-
|
|
158
|
-
@option hash [Integer] :w Alias for width
|
|
159
|
-
@option hash [Integer] :h Alias for height
|
|
160
|
-
|
|
161
|
-
@option hash [Integer] :bits_per_pixel Bits per pixel. Valid values are
|
|
162
|
-
8, 15, 16, 24, and 32.
|
|
163
|
-
@option hash [Integer] :bpp Alias for bits_per_pixel
|
|
164
|
-
|
|
165
|
-
@option hash [true, false] :hw_surface Creates the surface in video memory
|
|
166
|
-
(default)
|
|
167
|
-
@option hash [true, false] :sw_surface Creates the surface in system memory
|
|
168
|
-
@option hash [true, false] :async_blit Enables asynchronous updates of the
|
|
169
|
-
the surface
|
|
170
|
-
@option hash [true, false] :double_buf Enables double buffering. Ignored
|
|
171
|
-
if sw_surface is set.
|
|
172
|
-
@option hash [true, false] :fullscreen Creates a full screen window.
|
|
173
|
-
@option hash [true, false] :resizable Creates a resizable window.
|
|
174
|
-
@option hash [true, false] :no_frame Disables window decoration if
|
|
175
|
-
possible.
|
|
176
|
-
*/
|
|
177
|
-
VALUE ray_create_window(VALUE self, VALUE hash) {
|
|
178
|
-
ray_video_mode mode = ray_parse_video_mode(hash);
|
|
179
|
-
SDL_Surface *screen = SDL_SetVideoMode(mode.width, mode.height,
|
|
180
|
-
mode.bpp, mode.flags);
|
|
181
|
-
|
|
182
|
-
if (!screen) {
|
|
183
|
-
rb_raise(rb_eRuntimeError, "Could not create the window (%s)",
|
|
184
|
-
SDL_GetError());
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return ray_create_image(screen);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/*
|
|
191
|
-
@overload can_use_mode?(hash)
|
|
192
|
-
@param [Hash] hash Same options as in create_window
|
|
193
|
-
@return [true, false] True if the video mode described by hash
|
|
194
|
-
can be used.
|
|
195
|
-
*/
|
|
196
|
-
VALUE ray_can_use_mode(VALUE self, VALUE hash) {
|
|
197
|
-
ray_video_mode mode = ray_parse_video_mode(hash);
|
|
198
|
-
|
|
199
|
-
int res = SDL_VideoModeOK(mode.width, mode.height, mode.bpp, mode.flags);
|
|
200
|
-
return res ? Qtrue : Qfalse;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/*
|
|
204
|
-
@overload icon=(icon)
|
|
205
|
-
Sets the window icon
|
|
206
|
-
@param [Ray::Image] icon The icon to display
|
|
207
|
-
*/
|
|
208
|
-
VALUE ray_set_icon(VALUE self, VALUE icon) {
|
|
209
|
-
SDL_WM_SetIcon(ray_rb2surface(icon), NULL);
|
|
210
|
-
return icon;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/* @return [String, nil] The window title */
|
|
214
|
-
VALUE ray_window_title(VALUE self) {
|
|
215
|
-
char *title = NULL;
|
|
216
|
-
SDL_WM_GetCaption(&title, NULL);
|
|
217
|
-
|
|
218
|
-
if (!title)
|
|
219
|
-
return Qnil;
|
|
220
|
-
return rb_str_new2(title);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/*
|
|
224
|
-
@overload window_title=(title)
|
|
225
|
-
Sets the window title
|
|
226
|
-
*/
|
|
227
|
-
VALUE ray_set_window_title(VALUE self, VALUE title) {
|
|
228
|
-
char *icon = NULL;
|
|
229
|
-
|
|
230
|
-
if (!NIL_P(title)) title = rb_String(title);
|
|
231
|
-
|
|
232
|
-
SDL_WM_GetCaption(NULL, &icon);
|
|
233
|
-
SDL_WM_SetCaption(NIL_P(title) ? NULL : StringValuePtr(title), icon);
|
|
234
|
-
|
|
235
|
-
return title;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/* @return [String, nil] The window text icon */
|
|
239
|
-
VALUE ray_text_icon(VALUE self) {
|
|
240
|
-
char *icon = NULL;
|
|
241
|
-
SDL_WM_GetCaption(NULL, &icon);
|
|
242
|
-
|
|
243
|
-
if (!icon)
|
|
244
|
-
return Qnil;
|
|
245
|
-
return rb_str_new2(icon);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/*
|
|
249
|
-
@overload text_icon=(val)
|
|
250
|
-
Sets the window text icon
|
|
251
|
-
*/
|
|
252
|
-
VALUE ray_set_text_icon(VALUE self, VALUE icon) {
|
|
253
|
-
char *title;
|
|
254
|
-
|
|
255
|
-
if (!NIL_P(icon)) icon = rb_String(icon);
|
|
256
|
-
|
|
257
|
-
SDL_WM_GetCaption(&title, NULL);
|
|
258
|
-
SDL_WM_SetCaption(title, NIL_P(icon) ? NULL : StringValuePtr(icon));
|
|
259
|
-
|
|
260
|
-
return icon;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/*
|
|
264
|
-
@return [true, false] True if the input is grabbed, which means the mouse
|
|
265
|
-
is confined in the window, and keyboard input is sent
|
|
266
|
-
directly to the window.
|
|
267
|
-
*/
|
|
268
|
-
VALUE ray_grab_input(VALUE self) {
|
|
269
|
-
SDL_GrabMode mode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
|
|
270
|
-
return (mode == SDL_GRAB_ON) ? Qtrue : Qfalse;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/*
|
|
274
|
-
@overload grab_input=(grab)
|
|
275
|
-
Sets the grab input to true or false
|
|
276
|
-
*/
|
|
277
|
-
VALUE ray_set_grab_input(VALUE self, VALUE grab) {
|
|
278
|
-
SDL_WM_GrabInput(RTEST(grab) ? SDL_GRAB_ON : SDL_GRAB_OFF);
|
|
279
|
-
return grab;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/* @return [Ray::Image, nil] The current screen, created by create_window */
|
|
283
|
-
VALUE ray_screen(VALUE self) {
|
|
284
|
-
SDL_Surface *surf = SDL_GetVideoSurface();
|
|
285
|
-
|
|
286
|
-
if (!surf)
|
|
287
|
-
return Qnil;
|
|
288
|
-
return ray_create_image(surf);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/* @return [true, false] true if Ray supports other image formats than BMP */
|
|
292
|
-
VALUE ray_has_image_support(VALUE self) {
|
|
293
|
-
#ifdef HAVE_SDL_IMAGE
|
|
294
|
-
return Qtrue;
|
|
295
|
-
#else
|
|
296
|
-
return Qfalse;
|
|
297
|
-
#endif
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/* @return [true, false] true if Ray supports graphical effect like rotations */
|
|
301
|
-
VALUE ray_has_gfx_support(VALUE self) {
|
|
302
|
-
#ifdef HAVE_SDL_GFX
|
|
303
|
-
return Qtrue;
|
|
304
|
-
#else
|
|
305
|
-
return Qfalse;
|
|
306
|
-
#endif
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/* @return [true, false] true if Ray supports ttf fonts */
|
|
310
|
-
VALUE ray_has_font_support(VALUE self) {
|
|
311
|
-
#ifdef HAVE_SDL_TTF
|
|
312
|
-
return Qtrue;
|
|
313
|
-
#else
|
|
314
|
-
return Qfalse;
|
|
315
|
-
#endif
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/* @return [true, false] true if Ray supports audio playback */
|
|
319
|
-
VALUE ray_has_audio_support(VALUE self) {
|
|
320
|
-
#ifdef HAVE_SDL_MIXER
|
|
321
|
-
return Qtrue;
|
|
322
|
-
#else
|
|
323
|
-
return Qfalse;
|
|
324
|
-
#endif
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
void Init_ray_ext() {
|
|
328
|
-
ray_mRay = rb_define_module("Ray");
|
|
329
|
-
|
|
330
|
-
rb_define_module_function(ray_mRay, "init", ray_init, -1);
|
|
331
|
-
rb_define_module_function(ray_mRay, "stop", ray_stop, 0);
|
|
332
|
-
|
|
333
|
-
rb_define_module_function(ray_mRay, "create_window", ray_create_window, 1);
|
|
334
|
-
rb_define_module_function(ray_mRay, "can_use_mode?", ray_can_use_mode, 1);
|
|
335
|
-
rb_define_module_function(ray_mRay, "screen", ray_screen, 0);
|
|
336
|
-
|
|
337
|
-
rb_define_module_function(ray_mRay, "icon=", ray_set_icon, 1);
|
|
338
|
-
rb_define_module_function(ray_mRay, "window_title=", ray_set_window_title,
|
|
339
|
-
1);
|
|
340
|
-
rb_define_module_function(ray_mRay, "text_icon=", ray_set_text_icon, 1);
|
|
341
|
-
|
|
342
|
-
rb_define_module_function(ray_mRay, "window_title", ray_window_title, 0);
|
|
343
|
-
rb_define_module_function(ray_mRay, "text_icon", ray_text_icon, 0);
|
|
344
|
-
|
|
345
|
-
rb_define_module_function(ray_mRay, "grab_input", ray_grab_input, 0);
|
|
346
|
-
rb_define_module_function(ray_mRay, "grab_input=", ray_set_grab_input, 1);
|
|
347
|
-
|
|
348
|
-
rb_define_module_function(ray_mRay, "has_image_support?",
|
|
349
|
-
ray_has_image_support, 0);
|
|
350
|
-
rb_define_module_function(ray_mRay, "has_gfx_support?",
|
|
351
|
-
ray_has_gfx_support, 0);
|
|
352
|
-
rb_define_module_function(ray_mRay, "has_font_support?",
|
|
353
|
-
ray_has_font_support, 0);
|
|
354
|
-
rb_define_module_function(ray_mRay, "has_audio_support?",
|
|
355
|
-
ray_has_audio_support, 0);
|
|
356
|
-
|
|
357
|
-
Init_ray_image();
|
|
358
|
-
Init_ray_color();
|
|
359
|
-
Init_ray_rect();
|
|
360
|
-
Init_ray_event();
|
|
361
|
-
Init_ray_joystick();
|
|
362
|
-
|
|
363
|
-
#ifdef HAVE_SDL_TTF
|
|
364
|
-
Init_ray_font();
|
|
365
|
-
#endif
|
|
366
|
-
|
|
367
|
-
#ifdef HAVE_SDL_MIXER
|
|
368
|
-
Init_ray_audio();
|
|
369
|
-
#endif
|
|
370
|
-
|
|
371
|
-
#ifdef PSP
|
|
372
|
-
Init_ray_psp();
|
|
373
|
-
#endif
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
#ifdef PSP
|
|
377
|
-
|
|
378
|
-
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
|
|
379
|
-
PSP_HEAP_SIZE_KB(-512);
|
|
380
|
-
|
|
381
|
-
#include <unistd.h>
|
|
382
|
-
|
|
383
|
-
#define RGB(r, g, b) ((r) | ((g)<<8) | ((b)<<16) | (0xff<<24))
|
|
384
|
-
|
|
385
|
-
VALUE ray_safe_load(VALUE self) {
|
|
386
|
-
return rb_require("./script.rb");
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
int SDL_main(int argc, char *argv[]) {
|
|
390
|
-
ruby_init();
|
|
391
|
-
|
|
392
|
-
ruby_incpush("./ruby/1.8");
|
|
393
|
-
ruby_incpush("./ruby/site_ruby");
|
|
394
|
-
ruby_incpush("./ruby/site_ruby/1.8");
|
|
395
|
-
|
|
396
|
-
ruby_incpush("ms0:/ruby/1.8");
|
|
397
|
-
ruby_incpush("ms0:/ruby/site_ruby");
|
|
398
|
-
ruby_incpush("ms0:/ruby/site_ruby/1.8");
|
|
399
|
-
|
|
400
|
-
ruby_incpush(".");
|
|
401
|
-
|
|
402
|
-
ruby_script("ray");
|
|
403
|
-
|
|
404
|
-
Init_ray_ext();
|
|
405
|
-
|
|
406
|
-
int error = 0;
|
|
407
|
-
VALUE res = rb_protect(ray_safe_load, 0, &error);
|
|
408
|
-
|
|
409
|
-
if (error != 0) {
|
|
410
|
-
pspDebugScreenInit();
|
|
411
|
-
|
|
412
|
-
pspDebugScreenSetBackColor(RGB(0, 0, 0));
|
|
413
|
-
pspDebugScreenEnableBackColor(1);
|
|
414
|
-
|
|
415
|
-
pspDebugScreenClear();
|
|
416
|
-
pspDebugScreenSetXY(0, 0);
|
|
417
|
-
|
|
418
|
-
pspDebugScreenSetTextColor(RGB(255, 0, 0));
|
|
419
|
-
pspDebugScreenPrintf("Ray - error manager\n\n\n");
|
|
420
|
-
pspDebugScreenSetTextColor(RGB(255, 255, 255));
|
|
421
|
-
|
|
422
|
-
pspDebugScreenPrintf("This is Ray's error manager.An exception ");
|
|
423
|
-
pspDebugScreenPrintf("has been thrown, and the script ");
|
|
424
|
-
pspDebugScreenPrintf("cannot be run. If you're the developper of");
|
|
425
|
-
pspDebugScreenPrintf(" this application,\ncheck yout script.");
|
|
426
|
-
pspDebugScreenPrintf(" If it seems fine to you, consider ");
|
|
427
|
-
pspDebugScreenPrintf("filling a bug report.\n");
|
|
428
|
-
pspDebugScreenPrintf("If you're not the developper, consider");
|
|
429
|
-
pspDebugScreenPrintf(" contacting him.\n\n\n");
|
|
430
|
-
|
|
431
|
-
pspDebugScreenSetTextColor(RGB(255, 0, 0));
|
|
432
|
-
pspDebugScreenPrintf("Errors informations :\n\n\n");
|
|
433
|
-
pspDebugScreenSetTextColor(RGB(255, 255, 255));
|
|
434
|
-
|
|
435
|
-
// Now, we get the error.
|
|
436
|
-
VALUE error = rb_gv_get("$!");
|
|
437
|
-
|
|
438
|
-
// And the information we want to have about it.
|
|
439
|
-
VALUE backtrace = rb_funcall(error, RAY_METH("backtrace"), 0);
|
|
440
|
-
VALUE type = rb_funcall(error, RAY_METH("class"), 0);
|
|
441
|
-
VALUE msg = rb_funcall(error, RAY_METH("message"), 0);
|
|
442
|
-
|
|
443
|
-
type = rb_funcall(type, RAY_METH("to_s"), 0);
|
|
444
|
-
|
|
445
|
-
VALUE first = rb_ary_entry(backtrace, 0);
|
|
446
|
-
|
|
447
|
-
FILE *log = fopen("ray-error.log", "w");
|
|
448
|
-
if (!log) {
|
|
449
|
-
sceKernelExitGame();
|
|
450
|
-
return 1;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
pspDebugScreenPrintf("%s: %s: %s\n", StringValuePtr(first),
|
|
454
|
-
StringValuePtr(type),
|
|
455
|
-
StringValuePtr(msg));
|
|
456
|
-
fprintf(log, "%s: %s: %s\n", StringValuePtr(first), StringValuePtr(type),
|
|
457
|
-
StringValuePtr(msg));
|
|
458
|
-
|
|
459
|
-
int i = 1;
|
|
460
|
-
for (i = 1; i < RARRAY_LEN(backtrace); ++i) {
|
|
461
|
-
VALUE entry = rb_ary_entry(backtrace, i);
|
|
462
|
-
pspDebugScreenPrintf("%s\n", StringValuePtr(entry));
|
|
463
|
-
fprintf(log, "%s\n", StringValuePtr(entry));
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
fclose(log);
|
|
467
|
-
|
|
468
|
-
pspDebugScreenPrintf("\nThese informations can be found in ");
|
|
469
|
-
pspDebugScreenPrintf("ray-error.log\n\n");
|
|
470
|
-
|
|
471
|
-
pspDebugScreenPrintf("Press X to quit.");
|
|
472
|
-
|
|
473
|
-
SceCtrlData pad;
|
|
474
|
-
|
|
475
|
-
sceCtrlSetSamplingCycle(0);
|
|
476
|
-
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
|
|
477
|
-
sceCtrlReadBufferPositive(&pad, 1);
|
|
478
|
-
|
|
479
|
-
while (!(pad.Buttons & PSP_CTRL_CROSS))
|
|
480
|
-
sceCtrlReadBufferPositive(&pad, 1);
|
|
481
|
-
|
|
482
|
-
sceKernelExitGame();
|
|
483
|
-
return 0;
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
return res;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
#endif
|