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_sprite2.c CHANGED
@@ -32,7 +32,9 @@ static VALUE mSDL = Qnil;
32
32
  static VALUE mMiyako = Qnil;
33
33
  static VALUE mSpriteArray = Qnil;
34
34
  static VALUE mSpriteBase = Qnil;
35
+ static VALUE cSprite = Qnil;
35
36
  static VALUE cSpriteList = Qnil;
37
+ static VALUE cListPairStruct = Qnil;
36
38
  static VALUE nZero = Qnil;
37
39
  static VALUE nOne = Qnil;
38
40
  static volatile ID id_kakko = Qnil;
@@ -47,6 +49,106 @@ static volatile ID id_render_to = Qnil;
47
49
  static volatile ID id_sprite_only = Qnil;
48
50
  static volatile int zero = 0;
49
51
  static volatile int one = 1;
52
+ static char *str_list = "@list";
53
+ static char *str_visible = "@visible";
54
+
55
+ /*
56
+ :nodoc:
57
+ */
58
+ static VALUE lps_to_ary(VALUE self)
59
+ {
60
+ VALUE array = rb_ary_new();
61
+ rb_ary_push(array, *(RSTRUCT_PTR(self)+0));
62
+ rb_ary_push(array, *(RSTRUCT_PTR(self)+1));
63
+ return array;
64
+ }
65
+
66
+ /*
67
+ :nodoc:
68
+ */
69
+ static void lps_move_inner(VALUE value, ID id, VALUE x, VALUE y)
70
+ {
71
+ rb_funcall(*(RSTRUCT_PTR(value)+1), id, 2, x, y);
72
+ }
73
+
74
+ /*
75
+ :nodoc:
76
+ */
77
+ static VALUE lps_move(VALUE self, VALUE dx, VALUE dy)
78
+ {
79
+ lps_move_inner(self, id_move, dx, dy);
80
+ return self;
81
+ }
82
+
83
+ /*
84
+ :nodoc:
85
+ */
86
+ static VALUE lps_move_to(VALUE self, VALUE x, VALUE y)
87
+ {
88
+ lps_move_inner(self, id_move_to, x, y);
89
+ return self;
90
+ }
91
+
92
+ /*
93
+ :nodoc:
94
+ */
95
+ static void lps_inner(VALUE value, ID id)
96
+ {
97
+ rb_funcall(*(RSTRUCT_PTR(value)+1), id, 0);
98
+ }
99
+
100
+ /*
101
+ :nodoc:
102
+ */
103
+ static VALUE lps_start(VALUE self)
104
+ {
105
+ lps_inner(self, id_start);
106
+ return self;
107
+ }
108
+
109
+ /*
110
+ :nodoc:
111
+ */
112
+ static VALUE lps_stop(VALUE self)
113
+ {
114
+ lps_inner(self, id_stop);
115
+ return self;
116
+ }
117
+
118
+ /*
119
+ :nodoc:
120
+ */
121
+ static VALUE lps_reset(VALUE self)
122
+ {
123
+ lps_inner(self, id_reset);
124
+ return self;
125
+ }
126
+
127
+ /*
128
+ :nodoc:
129
+ */
130
+ static VALUE lps_update_animation(VALUE self)
131
+ {
132
+ return rb_funcall(*(RSTRUCT_PTR(self)+1), id_update_animation, 0);
133
+ }
134
+
135
+ /*
136
+ :nodoc:
137
+ */
138
+ static VALUE lps_render(VALUE self)
139
+ {
140
+ lps_inner(self, id_render);
141
+ return self;
142
+ }
143
+
144
+ /*
145
+ :nodoc:
146
+ */
147
+ static VALUE lps_render_to(VALUE self, VALUE dst)
148
+ {
149
+ rb_funcall(*(RSTRUCT_PTR(self)+1), id_render_to, 1, dst);
150
+ return self;
151
+ }
50
152
 
51
153
  /*
52
154
  :nodoc:
@@ -54,16 +156,18 @@ static volatile int one = 1;
54
156
  static VALUE sprite_array_sprite_only(VALUE self)
55
157
  {
56
158
  VALUE array = rb_ary_new();
57
-
159
+
58
160
  int i;
59
161
  VALUE *ptr = RARRAY_PTR(self);
60
162
  for(i=0; i<RARRAY_LEN(self); i++)
61
163
  {
62
164
  VALUE e = *(ptr+i);
63
- VALUE c = CLASS_OF(e);
165
+ VALUE c = rb_obj_class(e);
64
166
  if(rb_mod_include_p(c, mSpriteBase) == Qtrue ||
65
167
  rb_mod_include_p(c, mSpriteArray) == Qtrue)
168
+ {
66
169
  rb_ary_push(array, e);
170
+ }
67
171
  }
68
172
  return array;
69
173
  }
@@ -166,7 +270,9 @@ static VALUE sprite_array_update_animation(VALUE self)
166
270
  int i;
167
271
  for(i=0; i<RARRAY_LEN(array); i++)
168
272
  {
169
- rb_ary_push(ret, rb_funcall(*(RARRAY_PTR(array)+i), id_update_animation, 0));
273
+ VALUE v = *(RARRAY_PTR(array)+i);
274
+ VALUE r = rb_funcall(v, id_update_animation, 0);
275
+ rb_ary_push(ret, r);
170
276
  }
171
277
  return ret;
172
278
  }
@@ -202,20 +308,21 @@ static VALUE sprite_array_render_to(VALUE self, VALUE dst)
202
308
  static VALUE sprite_list_sprite_only(VALUE self)
203
309
  {
204
310
  VALUE hash = rb_hash_new();
205
- VALUE names = rb_iv_get(self, "@names");
206
- VALUE n2v = rb_iv_get(self, "@n2v");
207
-
311
+ VALUE list = rb_iv_get(self, str_list);
312
+
208
313
  int i;
209
- VALUE *ptr = RARRAY_PTR(names);
210
- for(i=0; i<RARRAY_LEN(names); i++)
314
+ VALUE *ptr = RARRAY_PTR(list);
315
+ for(i=0; i<RARRAY_LEN(list); i++)
211
316
  {
212
- VALUE *p2 = RSTRUCT_PTR(rb_hash_lookup(n2v, *(ptr+i)));
317
+ VALUE *p2 = RSTRUCT_PTR(*(ptr+i));
213
318
  VALUE n = *(p2+0);
214
319
  VALUE v = *(p2+1);
215
320
  VALUE c = CLASS_OF(v);
216
321
  if(rb_mod_include_p(c, mSpriteBase) == Qtrue ||
217
322
  rb_mod_include_p(c, mSpriteArray) == Qtrue)
323
+ {
218
324
  rb_hash_aset(hash, n, v);
325
+ }
219
326
  }
220
327
  return rb_funcall(cSpriteList, rb_intern("new"), 1, hash);
221
328
  }
@@ -223,17 +330,16 @@ static VALUE sprite_list_sprite_only(VALUE self)
223
330
  /*
224
331
  :nodoc:
225
332
  */
226
- static void sprite_list_move_inner(VALUE list, ID id, VALUE x, VALUE y)
333
+ static void sprite_list_move_inner(VALUE vlist, ID id, VALUE x, VALUE y)
227
334
  {
228
- VALUE names = rb_iv_get(list, "@names");
229
- VALUE n2v = rb_iv_get(list, "@n2v");
335
+ VALUE list = rb_iv_get(vlist, str_list);
230
336
  int i;
231
- VALUE *ptr = RARRAY_PTR(names);
337
+ VALUE *ptr = RARRAY_PTR(list);
232
338
  if(rb_block_given_p() == Qtrue)
233
339
  {
234
- for(i=0; i<RARRAY_LEN(names); i++)
340
+ for(i=0; i<RARRAY_LEN(list); i++)
235
341
  {
236
- VALUE e = rb_hash_lookup(n2v, *(ptr+i));
342
+ VALUE e = *(ptr+i);
237
343
  VALUE ret = rb_yield_values(4, e, INT2NUM(i), x, y);
238
344
  VALUE r1 = rb_funcall(ret, id_kakko, 1, nZero);
239
345
  VALUE r2 = rb_funcall(ret, id_kakko, 1, nOne);
@@ -242,9 +348,9 @@ static void sprite_list_move_inner(VALUE list, ID id, VALUE x, VALUE y)
242
348
  }
243
349
  else
244
350
  {
245
- for(i=0; i<RARRAY_LEN(names); i++)
351
+ for(i=0; i<RARRAY_LEN(list); i++)
246
352
  {
247
- VALUE v = *(RSTRUCT_PTR(rb_hash_lookup(n2v, *(ptr+i)))+1);
353
+ VALUE v = *(RSTRUCT_PTR(*(ptr+i))+1);
248
354
  rb_funcall(v, id, 2, x, y);
249
355
  }
250
356
  }
@@ -273,31 +379,86 @@ static VALUE sprite_list_move_to(VALUE self, VALUE x, VALUE y)
273
379
  /*
274
380
  :nodoc:
275
381
  */
276
- static VALUE sprite_list_to_ary(VALUE self)
382
+ static VALUE sprite_list_each(VALUE self)
277
383
  {
278
- VALUE ret = rb_ary_new();
279
- VALUE names = rb_iv_get(self, "@names");
280
- VALUE n2v = rb_iv_get(self, "@n2v");
281
-
384
+ RETURN_ENUMERATOR(self, 0, 0);
385
+
386
+ VALUE array = rb_iv_get(self, str_list);
387
+
282
388
  int i;
283
- VALUE *ptr = RARRAY_PTR(names);
284
- for(i=0; i<RARRAY_LEN(names); i++)
285
- rb_ary_push(ret, rb_hash_lookup(n2v, *(ptr+i)));
389
+ VALUE *ptr = RARRAY_PTR(array);
390
+ for(i=0; i<RARRAY_LEN(array); i++)
391
+ rb_yield_values(1, *(ptr+i));
286
392
 
287
- return ret;
393
+ return self;
288
394
  }
289
395
 
290
396
  /*
291
397
  :nodoc:
292
398
  */
293
- static VALUE sprite_list_each(VALUE self)
399
+ static VALUE sprite_list_each_pair(VALUE self)
294
400
  {
295
- VALUE array = sprite_list_to_ary(self);
296
-
401
+ RETURN_ENUMERATOR(self, 0, 0);
402
+
403
+ VALUE array = rb_iv_get(self, str_list);
404
+
297
405
  int i;
298
406
  VALUE *ptr = RARRAY_PTR(array);
299
407
  for(i=0; i<RARRAY_LEN(array); i++)
300
- rb_yield_values(1, *(ptr+i));
408
+ {
409
+ VALUE *sptr = RSTRUCT_PTR(*(ptr+i));
410
+ rb_yield_values(2, *(sptr+0), *(sptr+1));
411
+ }
412
+
413
+ return self;
414
+ }
415
+
416
+ /*
417
+ :nodoc:
418
+ */
419
+ static VALUE sprite_list_each_name(VALUE self)
420
+ {
421
+ RETURN_ENUMERATOR(self, 0, 0);
422
+
423
+ VALUE array = rb_iv_get(self, str_list);
424
+
425
+ int i;
426
+ VALUE *ptr = RARRAY_PTR(array);
427
+ for(i=0; i<RARRAY_LEN(array); i++)
428
+ rb_yield_values(1, *(RSTRUCT_PTR(*(ptr+i))+0));
429
+
430
+ return self;
431
+ }
432
+
433
+ /*
434
+ :nodoc:
435
+ */
436
+ static VALUE sprite_list_each_value(VALUE self)
437
+ {
438
+ RETURN_ENUMERATOR(self, 0, 0);
439
+
440
+ VALUE array = rb_iv_get(self, str_list);
441
+
442
+ int i;
443
+ VALUE *ptr = RARRAY_PTR(array);
444
+ for(i=0; i<RARRAY_LEN(array); i++)
445
+ rb_yield_values(1, *(RSTRUCT_PTR(*(ptr+i))+1));
446
+
447
+ return self;
448
+ }
449
+
450
+ /*
451
+ :nodoc:
452
+ */
453
+ static VALUE sprite_list_each_index(VALUE self)
454
+ {
455
+ RETURN_ENUMERATOR(self, 0, 0);
456
+
457
+ VALUE array = rb_iv_get(self, str_list);
458
+
459
+ int i;
460
+ for(i=0; i<RARRAY_LEN(array); i++)
461
+ rb_yield_values(1, INT2NUM(i));
301
462
 
302
463
  return self;
303
464
  }
@@ -307,12 +468,11 @@ static VALUE sprite_list_each(VALUE self)
307
468
  */
308
469
  static void sprite_list_inner(VALUE list, ID id)
309
470
  {
310
- VALUE array = sprite_list_to_ary(list);
471
+ VALUE array = rb_iv_get(list, str_list);
311
472
  int i;
312
473
  for(i=0; i<RARRAY_LEN(array); i++)
313
474
  {
314
- VALUE pair = *(RARRAY_PTR(array)+i);
315
- rb_funcall(*(RSTRUCT_PTR(pair)+1), id ,0);
475
+ lps_inner(*(RARRAY_PTR(array)+i), id);
316
476
  }
317
477
  }
318
478
 
@@ -348,32 +508,51 @@ static VALUE sprite_list_reset(VALUE self)
348
508
  */
349
509
  static VALUE sprite_list_update_animation(VALUE self)
350
510
  {
351
- VALUE array = sprite_list_to_ary(self);
511
+ VALUE array = rb_iv_get(self, str_list);
352
512
  VALUE ret = rb_ary_new();
353
513
  int i;
354
514
  for(i=0; i<RARRAY_LEN(array); i++)
355
515
  {
356
- VALUE pair = *(RARRAY_PTR(array)+i);
357
- rb_ary_push(ret, rb_funcall(*(RSTRUCT_PTR(pair)+1), id_update_animation, 0));
516
+ rb_ary_push(ret, lps_update_animation(*(RARRAY_PTR(array)+i)));
358
517
  }
359
518
  return ret;
360
519
  }
361
520
 
521
+ /*
522
+ :nodoc:
523
+ */
524
+ VALUE _miyako_sprite_list_update_animation(VALUE splist)
525
+ {
526
+ sprite_list_update_animation(splist);
527
+ return splist;
528
+ }
529
+
362
530
  /*
363
531
  :nodoc:
364
532
  */
365
533
  static VALUE sprite_list_render(VALUE self)
366
534
  {
535
+ if(rb_iv_get(self, str_visible) == Qfalse) return self;
367
536
  sprite_list_inner(self, id_render);
368
537
  return self;
369
538
  }
370
539
 
540
+ /*
541
+ :nodoc:
542
+ */
543
+ VALUE _miyako_sprite_list_render(VALUE splist)
544
+ {
545
+ sprite_list_inner(splist, id_render);
546
+ return splist;
547
+ }
548
+
371
549
  /*
372
550
  :nodoc:
373
551
  */
374
552
  static VALUE sprite_list_render_to(VALUE self, VALUE dst)
375
553
  {
376
- VALUE array = sprite_list_to_ary(self);
554
+ if(rb_iv_get(self, str_visible) == Qfalse) return self;
555
+ VALUE array = rb_iv_get(self, str_list);
377
556
  int i;
378
557
  for(i=0; i<RARRAY_LEN(array); i++)
379
558
  {
@@ -384,13 +563,56 @@ static VALUE sprite_list_render_to(VALUE self, VALUE dst)
384
563
  return self;
385
564
  }
386
565
 
566
+ /*
567
+ :nodoc:
568
+ */
569
+ VALUE _miyako_sprite_list_render_to(VALUE splist, VALUE dst)
570
+ {
571
+ sprite_list_render_to(splist, dst);
572
+ return splist;
573
+ }
574
+
575
+ /*
576
+ :nodoc:
577
+ */
578
+ static VALUE sprite_list_map_inner(VALUE self, int idx)
579
+ {
580
+ VALUE array = rb_iv_get(self, str_list);
581
+ int i;
582
+ VALUE ret = rb_ary_new();
583
+ VALUE *ptr = RARRAY_PTR(array);
584
+ for(i=0; i<RARRAY_LEN(array); i++)
585
+ {
586
+ rb_ary_push(ret, *(RSTRUCT_PTR(*(ptr+i))+idx));
587
+ }
588
+ return ret;
589
+ }
590
+
591
+ /*
592
+ :nodoc:
593
+ */
594
+ static VALUE sprite_list_names(VALUE self)
595
+ {
596
+ return sprite_list_map_inner(self, 0);
597
+ }
598
+
599
+ /*
600
+ :nodoc:
601
+ */
602
+ static VALUE sprite_list_values(VALUE self)
603
+ {
604
+ return sprite_list_map_inner(self, 1);
605
+ }
606
+
387
607
  void Init_miyako_sprite2()
388
608
  {
389
609
  mSDL = rb_define_module("SDL");
390
610
  mMiyako = rb_define_module("Miyako");
391
611
  mSpriteArray = rb_define_module_under(mMiyako, "SpriteArray");
392
612
  mSpriteBase = rb_define_module_under(mMiyako, "SpriteBase");
613
+ cSprite = rb_define_class_under(mMiyako, "Sprite", rb_cObject);
393
614
  cSpriteList = rb_define_class_under(mMiyako, "SpriteList", rb_cObject);
615
+ cListPairStruct = rb_define_class_under(mMiyako, "ListPairStruct", rb_cStruct);
394
616
 
395
617
  id_kakko = rb_intern("[]");
396
618
  id_start = rb_intern("start");
@@ -408,6 +630,16 @@ void Init_miyako_sprite2()
408
630
  one = 1;
409
631
  nOne = INT2NUM(one);
410
632
 
633
+ rb_define_method(cListPairStruct, "to_ary", lps_to_ary, 0);
634
+ rb_define_method(cListPairStruct, "to_a", lps_to_ary, 0);
635
+ rb_define_method(cListPairStruct, "start", lps_start, 0);
636
+ rb_define_method(cListPairStruct, "stop", lps_stop, 0);
637
+ rb_define_method(cListPairStruct, "reset", lps_reset, 0);
638
+ rb_define_method(cListPairStruct, "update_animation", lps_update_animation, 0);
639
+ rb_define_method(cListPairStruct, "move!", lps_move, 2);
640
+ rb_define_method(cListPairStruct, "move_to!", lps_move_to, 2);
641
+ rb_define_method(cListPairStruct, "render", lps_render, 0);
642
+ rb_define_method(cListPairStruct, "render_to", lps_render_to, 1);
411
643
  rb_define_method(mSpriteArray, "sprite_only", sprite_array_sprite_only, 0);
412
644
  rb_define_method(mSpriteArray, "start", sprite_array_start, 0);
413
645
  rb_define_method(mSpriteArray, "stop", sprite_array_stop, 0);
@@ -424,8 +656,13 @@ void Init_miyako_sprite2()
424
656
  rb_define_method(cSpriteList, "update_animation", sprite_list_update_animation, 0);
425
657
  rb_define_method(cSpriteList, "move!", sprite_list_move, 2);
426
658
  rb_define_method(cSpriteList, "move_to!", sprite_list_move_to, 2);
427
- rb_define_method(cSpriteList, "to_ary", sprite_list_to_ary, 0);
428
659
  rb_define_method(cSpriteList, "each", sprite_list_each, 0);
660
+ rb_define_method(cSpriteList, "each_pair", sprite_list_each_pair, 0);
661
+ rb_define_method(cSpriteList, "each_name", sprite_list_each_name, 0);
662
+ rb_define_method(cSpriteList, "each_value", sprite_list_each_value, 0);
663
+ rb_define_method(cSpriteList, "each_index", sprite_list_each_index, 0);
664
+ rb_define_method(cSpriteList, "names", sprite_list_names, 0);
665
+ rb_define_method(cSpriteList, "values", sprite_list_values, 0);
429
666
  rb_define_method(cSpriteList, "render", sprite_list_render, 0);
430
667
  rb_define_method(cSpriteList, "render_to", sprite_list_render_to, 1);
431
668
  }