ruby-miyako 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/README +275 -20
  2. data/extern.h +21 -1
  3. data/install_miyako.rb +5 -3
  4. data/lib/Miyako/API/audio.rb +11 -6
  5. data/lib/Miyako/API/basic_data.rb +0 -985
  6. data/lib/Miyako/API/bitmap.rb +19 -22
  7. data/lib/Miyako/API/choices.rb +203 -69
  8. data/lib/Miyako/API/collision.rb +451 -9
  9. data/lib/Miyako/API/color.rb +177 -0
  10. data/lib/Miyako/API/diagram.rb +18 -20
  11. data/lib/Miyako/API/fixedmap.rb +207 -73
  12. data/lib/Miyako/API/font.rb +111 -18
  13. data/lib/Miyako/API/i_yuki.rb +1201 -0
  14. data/lib/Miyako/API/input.rb +65 -0
  15. data/lib/Miyako/API/layout.rb +41 -29
  16. data/lib/Miyako/API/map.rb +202 -157
  17. data/lib/Miyako/API/map_event.rb +86 -19
  18. data/lib/Miyako/API/map_struct.rb +268 -0
  19. data/lib/Miyako/API/modules.rb +136 -37
  20. data/lib/Miyako/API/movie.rb +8 -8
  21. data/lib/Miyako/API/parts.rb +63 -20
  22. data/lib/Miyako/API/plane.rb +4 -4
  23. data/lib/Miyako/API/screen.rb +16 -8
  24. data/lib/Miyako/API/sprite.rb +290 -23
  25. data/lib/Miyako/API/sprite_animation.rb +23 -11
  26. data/lib/Miyako/API/sprite_list.rb +406 -183
  27. data/lib/Miyako/API/story.rb +4 -65
  28. data/lib/Miyako/API/struct_point.rb +157 -0
  29. data/lib/Miyako/API/struct_rect.rb +233 -0
  30. data/lib/Miyako/API/struct_segment.rb +641 -0
  31. data/lib/Miyako/API/struct_size.rb +158 -0
  32. data/lib/Miyako/API/struct_square.rb +253 -0
  33. data/lib/Miyako/API/textbox.rb +49 -35
  34. data/lib/Miyako/API/viewport.rb +5 -5
  35. data/lib/Miyako/API/wait_counter.rb +350 -0
  36. data/lib/Miyako/API/yuki.rb +95 -60
  37. data/lib/Miyako/EXT/raster_scroll.rb +30 -8
  38. data/lib/Miyako/EXT/slides.rb +6 -6
  39. data/lib/Miyako/miyako.rb +25 -11
  40. data/lib/miyako.rb +28 -0
  41. data/lib/miyako_require_only.rb +35 -0
  42. data/miyako_basicdata.c +201 -17
  43. data/miyako_collision.c +315 -6
  44. data/miyako_diagram.c +331 -0
  45. data/miyako_drawing.c +26 -7
  46. data/miyako_font.c +259 -129
  47. data/miyako_input_audio.c +24 -14
  48. data/miyako_layout.c +106 -8
  49. data/miyako_no_katana.c +398 -171
  50. data/miyako_sprite2.c +275 -38
  51. data/miyako_transform.c +113 -107
  52. data/miyako_utility.c +34 -48
  53. data/miyako_yuki.c +241 -0
  54. data/sample/Diagram_sample/diagram_sample_yuki2.rb +30 -30
  55. data/sample/Room3/blue.rb +19 -19
  56. data/sample/Room3/green.rb +9 -9
  57. data/sample/Room3/main.rb +12 -12
  58. data/sample/Room3/red.rb +12 -12
  59. data/sample/Room3/title.rb +15 -10
  60. data/sample/collision_test2.rb +2 -1
  61. data/sample/fixed_map_test/fixed_map_sample.rb +7 -6
  62. data/sample/map_test/main_scene.rb +12 -10
  63. data/sample/map_test/map_manager.rb +14 -13
  64. data/sample/rasterscroll.rb +5 -5
  65. data/sample/takahashi.rb +3 -3
  66. data/sample/textbox_sample.rb +7 -6
  67. data/sample/transform.rb +2 -1
  68. data/uninstall_miyako.rb +4 -1
  69. data/win/miyako_no_katana.so +0 -0
  70. metadata +15 -4
  71. data/lib/Miyako/EXT/miyako_cairo.rb +0 -62
  72. data/sample/cairo_sample.rb +0 -25
data/miyako_diagram.c ADDED
@@ -0,0 +1,331 @@
1
+ /*
2
+ --
3
+ Miyako v2.0 Extend Library "Miyako no Katana"
4
+ Copyright (C) 2008 Cyross Makoto
5
+
6
+ This library is free software; you can redistribute it and/or
7
+ modify it under the terms of the GNU Lesser General Public
8
+ License as published by the Free Software Foundation; either
9
+ version 2.1 of the License, or (at your option) any later version.
10
+
11
+ This library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public
17
+ License along with this library; if not, write to the Free Software
18
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ ++
20
+ */
21
+
22
+ /*
23
+ =拡張ライブラリmiyako_no_katana
24
+ Authors:: サイロス誠
25
+ Version:: 2.0
26
+ Copyright:: 2007-2008 Cyross Makoto
27
+ License:: LGPL2.1
28
+ */
29
+ #include "defines.h"
30
+ #include "extern.h"
31
+
32
+ static VALUE mMiyako = Qnil;
33
+ static VALUE mDiagram = Qnil;
34
+ static VALUE eMiyakoError = Qnil;
35
+ static VALUE cDiagramBody = Qnil;
36
+ static VALUE cManager = Qnil;
37
+ static VALUE cProcessor = Qnil;
38
+ static VALUE nZero = Qnil;
39
+ static VALUE nOne = Qnil;
40
+ static VALUE symExecute = Qnil;
41
+ static VALUE symPause = Qnil;
42
+ static VALUE symImm = Qnil;
43
+ static VALUE symNext = Qnil;
44
+ static volatile ID id_start = Qnil;
45
+ static volatile ID id_stop = Qnil;
46
+ static volatile ID id_finish = Qnil;
47
+ static volatile ID id_update = Qnil;
48
+ static volatile ID id_update_input = Qnil;
49
+ static volatile ID id_render = Qnil;
50
+ static volatile ID id_render_to = Qnil;
51
+ static volatile ID id_post_render = Qnil;
52
+ static volatile ID id_is_render = Qnil;
53
+ static volatile ID id_go_next = Qnil;
54
+ static volatile ID id_is_update = Qnil;
55
+ static volatile ID id_post_update = Qnil;
56
+ static volatile ID id_reset_input = Qnil;
57
+ static volatile ID id_trigger = Qnil;
58
+ static volatile ID id_to = Qnil;
59
+ static volatile ID id_post_process = Qnil;
60
+ static volatile ID id_pre_process = Qnil;
61
+ static volatile int zero = Qnil;
62
+ static volatile int one = Qnil;
63
+ static const char *str_visible = "@visible";
64
+ static const char *str_diagram = "@diagram";
65
+ static const char *str_states = "@states";
66
+ static const char *str_ptr = "@ptr";
67
+ static const char *str_node = "@node";
68
+ static const char *str_trigger = "@trigger";
69
+ static const char *str_next_trigger = "@next_trigger";
70
+ static const char *str_arrow = "@arrow";
71
+
72
+ /*
73
+ :nodoc:
74
+ */
75
+ static VALUE dbody_update_input(int argc, VALUE *argv, VALUE self)
76
+ {
77
+ VALUE params;
78
+ rb_scan_args(argc, argv, "00*", &params);
79
+
80
+ VALUE node = rb_iv_get(self, str_node);
81
+ if(node == Qnil) return Qnil;
82
+ rb_funcall2(node, id_update_input, argc, argv);
83
+ return Qnil;
84
+ }
85
+
86
+ /*
87
+ :nodoc:
88
+ */
89
+ static VALUE dbody_update(int argc, VALUE *argv, VALUE self)
90
+ {
91
+ VALUE params;
92
+ rb_scan_args(argc, argv, "00*", &params);
93
+
94
+ VALUE trigger = rb_iv_get(self, str_trigger);
95
+ if(rb_funcall(trigger, id_is_update, 0) == Qfalse) return Qnil;
96
+
97
+ VALUE node = rb_iv_get(self, str_node);
98
+ rb_funcall2(node, id_update, argc, argv);
99
+ rb_funcall(trigger, id_post_update, 0);
100
+ rb_funcall(node, id_reset_input, 0);
101
+
102
+ VALUE ntrigger = rb_iv_get(self, str_next_trigger);
103
+
104
+ if(ntrigger == Qnil) return Qnil;
105
+
106
+ rb_iv_set(self, str_trigger, ntrigger);
107
+ rb_iv_set(self, str_next_trigger, Qnil);
108
+ return Qnil;
109
+ }
110
+
111
+ /*
112
+ :nodoc:
113
+ */
114
+ static VALUE dbody_render(VALUE self)
115
+ {
116
+ VALUE trigger = rb_iv_get(self, str_trigger);
117
+ if(rb_funcall(trigger, id_is_render, 0) == Qfalse) return Qnil;
118
+ VALUE node = rb_iv_get(self, str_node);
119
+ rb_funcall(node, id_render, 0);
120
+ rb_funcall(trigger, id_post_render, 0);
121
+ return Qnil;
122
+ }
123
+
124
+ /*
125
+ :nodoc:
126
+ */
127
+ static VALUE dbody_go_next(VALUE self)
128
+ {
129
+ VALUE next_obj = self;
130
+ VALUE arrows = rb_iv_get(self, str_arrow);
131
+ VALUE *arrows_p = RARRAY_PTR(arrows);
132
+ VALUE node = rb_iv_get(self, str_node);
133
+ VALUE call_arg = rb_ary_new();
134
+ rb_ary_push(call_arg, node);
135
+ int i;
136
+ for(i=0;i<RARRAY_LEN(arrows);i++)
137
+ {
138
+ VALUE arrow = *(arrows_p+i);
139
+ VALUE trigger = rb_funcall(arrow, id_trigger, 0);
140
+ if((trigger != Qnil && rb_proc_call(trigger, call_arg)) || rb_funcall(node, id_finish, 0))
141
+ {
142
+ next_obj = rb_funcall(arrow, id_to, 0);
143
+ break;
144
+ }
145
+ }
146
+ if(!rb_eql(self, next_obj)){
147
+ VALUE trigger = rb_iv_get(self, str_trigger);
148
+ rb_funcall(trigger, id_post_process, 0);
149
+ }
150
+ return next_obj;
151
+ }
152
+
153
+ /*
154
+ :nodoc:
155
+ */
156
+ static VALUE dbody_replace_trigger(int argc, VALUE *argv, VALUE self)
157
+ {
158
+ VALUE new_trigger;
159
+ VALUE timing;
160
+ rb_scan_args(argc, argv, "11", &new_trigger, &timing);
161
+ if(timing == Qnil) timing = symNext;
162
+ else if(timing != symImm || timing != symNext)
163
+ {
164
+ char str[256];
165
+ VALUE timing_str = StringValue(timing);
166
+ sprintf(str, "I can't understand Timing Type! : %s", rb_string_value_ptr(&timing_str));
167
+ rb_raise(eMiyakoError, str);
168
+ }
169
+ if(timing == symImm)
170
+ {
171
+ VALUE trigger = rb_iv_get(self, str_trigger);
172
+ rb_funcall(trigger, id_post_process, 0);
173
+ rb_iv_set(self, str_trigger, new_trigger);
174
+ rb_funcall(trigger, id_pre_process, 0);
175
+
176
+ }
177
+ else if(timing == symNext)
178
+ {
179
+ rb_iv_set(self, str_next_trigger, new_trigger);
180
+ }
181
+ return Qnil;
182
+ }
183
+
184
+ /*
185
+ :nodoc:
186
+ */
187
+ static VALUE manager_update_input(int argc, VALUE *argv, VALUE self)
188
+ {
189
+ VALUE params;
190
+ rb_scan_args(argc, argv, "00*", &params);
191
+
192
+ VALUE ptr = rb_iv_get(self, str_ptr);
193
+ if(ptr == Qnil) return Qnil;
194
+ dbody_update_input(argc, argv, ptr);
195
+ return Qnil;
196
+ }
197
+
198
+ /*
199
+ :nodoc:
200
+ */
201
+ static VALUE manager_update(int argc, VALUE *argv, VALUE self)
202
+ {
203
+ VALUE params;
204
+ rb_scan_args(argc, argv, "00*", &params);
205
+
206
+ VALUE ptr = rb_iv_get(self, str_ptr);
207
+ if(ptr == Qnil) return Qnil;
208
+
209
+ dbody_update(argc, argv, ptr);
210
+
211
+ VALUE nxt = rb_funcall(ptr, id_go_next, 0);
212
+
213
+ if(!rb_eql(ptr, nxt))
214
+ {
215
+ rb_funcall(ptr, id_stop, 0);
216
+ rb_iv_set(self, str_ptr, nxt);
217
+ ptr = rb_iv_get(self, str_ptr);
218
+ if(ptr != Qnil) rb_funcall(ptr, id_start, 0);
219
+ }
220
+ return Qnil;
221
+ }
222
+
223
+ /*
224
+ :nodoc:
225
+ */
226
+ static VALUE manager_render(VALUE self)
227
+ {
228
+ VALUE ptr = rb_iv_get(self, str_ptr);
229
+ if(ptr == Qnil) return Qnil;
230
+ dbody_render(ptr);
231
+ return Qnil;
232
+ }
233
+
234
+ /*
235
+ :nodoc:
236
+ */
237
+ static VALUE processor_update_input(int argc, VALUE *argv, VALUE self)
238
+ {
239
+ VALUE params;
240
+ rb_scan_args(argc, argv, "00*", &params);
241
+
242
+ VALUE states = rb_iv_get(self, str_states);
243
+ if(rb_hash_lookup(states, symPause) == Qtrue) return Qnil;
244
+
245
+ VALUE diagram = rb_iv_get(self, str_diagram);
246
+ manager_update_input(argc, argv, diagram);
247
+ return Qnil;
248
+ }
249
+
250
+ /*
251
+ :nodoc:
252
+ */
253
+ static VALUE processor_update(int argc, VALUE *argv, VALUE self)
254
+ {
255
+ VALUE params;
256
+ rb_scan_args(argc, argv, "00*", &params);
257
+
258
+ VALUE states = rb_iv_get(self, str_states);
259
+
260
+ if(rb_hash_lookup(states, symPause) == Qtrue) return Qnil;
261
+
262
+ VALUE diagram = rb_iv_get(self, str_diagram);
263
+ manager_update(argc, argv, diagram);
264
+
265
+ if(rb_funcall(diagram, id_finish, 0) == Qtrue){
266
+ rb_hash_aset(states, symExecute, Qfalse);
267
+ }
268
+ return Qnil;
269
+ }
270
+
271
+ /*
272
+ :nodoc:
273
+ */
274
+ static VALUE processor_render(VALUE self)
275
+ {
276
+ if(rb_iv_get(self, str_visible) == Qfalse) return Qnil;
277
+ manager_render(rb_iv_get(self, str_diagram));
278
+ return Qnil;
279
+ }
280
+
281
+ void Init_miyako_diagram()
282
+ {
283
+ mMiyako = rb_define_module("Miyako");
284
+ mDiagram = rb_define_module_under(mMiyako, "Diagram");
285
+ eMiyakoError = rb_define_class_under(mMiyako, "MiyakoError", rb_eException);
286
+ cProcessor = rb_define_class_under(mDiagram, "Processor", rb_cObject);
287
+ cManager = rb_define_class_under(mDiagram, "Manager", rb_cObject);
288
+ cDiagramBody = rb_define_class_under(mDiagram, "DiagramBody", rb_cObject);
289
+
290
+ id_start = rb_intern("start");
291
+ id_stop = rb_intern("stop");
292
+ id_finish = rb_intern("finish?");
293
+ id_update = rb_intern("update");
294
+ id_update_input = rb_intern("update_input");
295
+ id_render = rb_intern("render");
296
+ id_render_to = rb_intern("render_to");
297
+ id_post_render = rb_intern("post_render");
298
+ id_is_render = rb_intern("render?");
299
+ id_go_next = rb_intern("go_next");
300
+ id_is_update = rb_intern("update?");
301
+ id_post_update = rb_intern("post_update");
302
+ id_reset_input = rb_intern("reset_input");
303
+ id_trigger = rb_intern("trigger");
304
+ id_to = rb_intern("to");
305
+ id_post_process = rb_intern("post_process");
306
+ id_pre_process = rb_intern("pre_process");
307
+
308
+ symExecute = ID2SYM(rb_intern("execute"));
309
+ symPause = ID2SYM(rb_intern("pause"));
310
+ symImm = ID2SYM(rb_intern("immediate"));
311
+ symNext = ID2SYM(rb_intern("next"));
312
+
313
+ zero = 0;
314
+ nZero = INT2NUM(zero);
315
+ one = 1;
316
+ nOne = INT2NUM(one);
317
+
318
+ rb_define_method(cDiagramBody, "update_input", dbody_update_input, -1);
319
+ rb_define_method(cDiagramBody, "update", dbody_update, -1);
320
+ rb_define_method(cDiagramBody, "render", dbody_render, 0);
321
+ rb_define_method(cDiagramBody, "go_next", dbody_go_next, 0);
322
+ rb_define_method(cDiagramBody, "replace_trigger", dbody_replace_trigger, -1);
323
+
324
+ rb_define_method(cManager, "update_input", manager_update_input, -1);
325
+ rb_define_method(cManager, "update", manager_update, -1);
326
+ rb_define_method(cManager, "render", manager_render, 0);
327
+
328
+ rb_define_method(cProcessor, "update_input", processor_update_input, -1);
329
+ rb_define_method(cProcessor, "update", processor_update, -1);
330
+ rb_define_method(cProcessor, "render", processor_render, 0);
331
+ }
data/miyako_drawing.c CHANGED
@@ -95,9 +95,9 @@ static VALUE drawing_draw_polygon(int argc, VALUE *argv, VALUE self)
95
95
  Uint8 alpha;
96
96
  Uint32 color;
97
97
  int i, vertexes;
98
-
98
+
99
99
  rb_scan_args(argc, argv, "32", &vdst, &pairs, &mcolor, &fill, &aa);
100
-
100
+
101
101
  // bitmapメソッドを持っていれば、メソッドの値をvdstとする
102
102
  VALUE methods = rb_funcall(vdst, rb_intern("methods"), 0);
103
103
  if(rb_ary_includes(methods, rb_str_intern(rb_str_new2("to_unit"))) == Qfalse &&
@@ -112,7 +112,7 @@ static VALUE drawing_draw_polygon(int argc, VALUE *argv, VALUE self)
112
112
  // 頂点数チェック
113
113
  if(vertexes > 65536)
114
114
  rb_raise(eMiyakoError, "too many pairs. pairs is less than 65536.");
115
-
115
+
116
116
  // 範囲チェック
117
117
  for(i=0; i<vertexes; i++)
118
118
  {
@@ -120,7 +120,7 @@ static VALUE drawing_draw_polygon(int argc, VALUE *argv, VALUE self)
120
120
  Sint16 x, y;
121
121
  get_position(vertex, &x, &y);
122
122
  }
123
-
123
+
124
124
  SDL_Surface *dst = GetSurface(vdst)->surface;
125
125
 
126
126
  color = value_2_color(rb_funcall(cColor, rb_intern("to_rgb"), 1, mcolor), dst->format, &alpha);
@@ -135,7 +135,7 @@ static VALUE drawing_draw_polygon(int argc, VALUE *argv, VALUE self)
135
135
  VALUE vertex = *(RARRAY_PTR(pairs)+i);
136
136
  get_position(vertex, px+i, py+i);
137
137
  }
138
-
138
+
139
139
  if(!RTEST(fill) && !RTEST(aa) && alpha == 255)
140
140
  {
141
141
  for(i=0; i<vertexes-1; i++)
@@ -166,13 +166,31 @@ static VALUE drawing_draw_polygon(int argc, VALUE *argv, VALUE self)
166
166
  sge_FilledPolygonAlpha(dst, (Uint16)vertexes, px, py, color, alpha);
167
167
  else if(RTEST(fill) && RTEST(aa) && alpha == 255)
168
168
  sge_AAFilledPolygon(dst, (Uint16)vertexes, px, py, color);
169
-
169
+
170
170
  free(py);
171
171
  free(px);
172
172
 
173
173
  return Qnil;
174
174
  }
175
175
 
176
+ /*
177
+ ポリゴン描画
178
+ */
179
+ static VALUE screen_clear(VALUE self)
180
+ {
181
+ VALUE dst = rb_iv_get(mScreen, "@@unit");
182
+ SDL_Surface *pdst = GetSurface(*(RSTRUCT_PTR(dst)))->surface;
183
+
184
+ sge_ClearSurface(pdst, 0);
185
+
186
+ return self;
187
+ }
188
+
189
+ void _miyako_screen_clear()
190
+ {
191
+ screen_clear(mScreen);
192
+ }
193
+
176
194
  void Init_miyako_drawing()
177
195
  {
178
196
  mSDL = rb_define_module("SDL");
@@ -182,6 +200,7 @@ void Init_miyako_drawing()
182
200
  eMiyakoError = rb_define_class_under(mMiyako, "MiyakoError", rb_eException);
183
201
  cSurface = rb_define_class_under(mSDL, "Surface", rb_cObject);
184
202
  cColor = rb_define_class_under(mMiyako, "Color", rb_cObject);
185
-
203
+
186
204
  rb_define_singleton_method(mDrawing, "polygon", drawing_draw_polygon, -1);
205
+ rb_define_singleton_method(mScreen, "clear", screen_clear, 0);
187
206
  }