cyross-ruby-miyako 2.0.0 → 2.0.5.1.0

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.
Files changed (102) hide show
  1. data/README +106 -154
  2. data/defines.h +144 -0
  3. data/{miyako_no_katana/extconf.rb → extconf.rb} +10 -0
  4. data/extern.h +29 -0
  5. data/install_miyako.rb +26 -14
  6. data/lib/Miyako/API/audio.rb +2 -2
  7. data/lib/Miyako/API/basic_data.rb +183 -41
  8. data/lib/Miyako/API/bitmap.rb +474 -2
  9. data/lib/Miyako/API/choices.rb +215 -48
  10. data/lib/Miyako/API/collision.rb +267 -251
  11. data/lib/Miyako/API/diagram.rb +58 -70
  12. data/lib/Miyako/API/drawing.rb +93 -52
  13. data/lib/Miyako/API/fixedmap.rb +233 -120
  14. data/lib/Miyako/API/font.rb +59 -40
  15. data/lib/Miyako/API/input.rb +34 -27
  16. data/lib/Miyako/API/layout.rb +154 -172
  17. data/lib/Miyako/API/map.rb +285 -159
  18. data/lib/Miyako/API/map_event.rb +4 -4
  19. data/lib/Miyako/API/modules.rb +1 -1
  20. data/lib/Miyako/API/movie.rb +8 -5
  21. data/lib/Miyako/API/parts.rb +44 -9
  22. data/lib/Miyako/API/plane.rb +37 -2
  23. data/lib/Miyako/API/screen.rb +90 -22
  24. data/lib/Miyako/API/shape.rb +118 -37
  25. data/lib/Miyako/API/sprite.rb +475 -61
  26. data/lib/Miyako/API/sprite_animation.rb +83 -63
  27. data/lib/Miyako/API/spriteunit.rb +47 -13
  28. data/lib/Miyako/API/story.rb +123 -47
  29. data/lib/Miyako/API/textbox.rb +361 -132
  30. data/lib/Miyako/API/utility.rb +388 -0
  31. data/lib/Miyako/API/viewport.rb +54 -349
  32. data/lib/Miyako/API/yuki.rb +570 -353
  33. data/lib/Miyako/EXT/miyako_cairo.rb +5 -3
  34. data/lib/Miyako/EXT/slides.rb +22 -1
  35. data/lib/Miyako/miyako.rb +12 -13
  36. data/logo/EGSR_logo.png +0 -0
  37. data/logo/EGSR_logo_bg.png +0 -0
  38. data/logo/EGSR_logo_fg.png +0 -0
  39. data/logo/EGSR_title_banner.png +0 -0
  40. data/logo/EGSR_title_logo.png +0 -0
  41. data/logo/miyako.png +0 -0
  42. data/logo/miyako_banner.png +0 -0
  43. data/logo/space.png +0 -0
  44. data/miyako_basicdata.c +590 -0
  45. data/miyako_bitmap.c +1225 -0
  46. data/miyako_collision.c +403 -0
  47. data/miyako_drawing.c +187 -0
  48. data/miyako_font.c +334 -0
  49. data/miyako_hsv.c +830 -0
  50. data/miyako_layout.c +191 -0
  51. data/miyako_no_katana.c +1074 -0
  52. data/miyako_transform.c +438 -0
  53. data/miyako_utility.c +288 -0
  54. data/sample/Animation1/m1ku.rb +10 -31
  55. data/sample/Animation1/readme.txt +6 -6
  56. data/sample/Animation2/lex.rb +1 -0
  57. data/sample/Animation2/readme.txt +6 -6
  58. data/sample/Diagram_sample/diagram_sample_yuki2.rb +152 -48
  59. data/sample/Diagram_sample/readme.txt +9 -6
  60. data/sample/Room3/blue.rb +234 -187
  61. data/sample/Room3/ending.rb +68 -63
  62. data/sample/Room3/green.rb +159 -124
  63. data/sample/Room3/main.rb +50 -32
  64. data/sample/Room3/main_component.rb +3 -2
  65. data/sample/Room3/readme.txt +6 -6
  66. data/sample/Room3/red.rb +161 -134
  67. data/sample/Room3/room3.rb +1 -0
  68. data/sample/Room3/title.rb +75 -62
  69. data/sample/ball_action_sample.rb +204 -0
  70. data/sample/blit_rop.rb +70 -0
  71. data/sample/cairo_sample.rb +25 -0
  72. data/sample/circle_collision_test.rb +66 -0
  73. data/sample/collision_test.rb +33 -0
  74. data/sample/collision_test2.rb +108 -0
  75. data/sample/fixed_map_test/fixed_map_sample.rb +23 -32
  76. data/sample/fixed_map_test/readme.txt +38 -38
  77. data/sample/map_test/chara.rb +17 -9
  78. data/sample/map_test/main_parts.rb +30 -9
  79. data/sample/map_test/main_scene.rb +57 -41
  80. data/sample/map_test/map_manager.rb +13 -30
  81. data/sample/map_test/map_test.rb +2 -2
  82. data/sample/map_test/oasis.rb +17 -11
  83. data/sample/map_test/readme.txt +50 -48
  84. data/sample/map_test/route.rb +46 -33
  85. data/sample/map_test/town.rb +19 -13
  86. data/sample/polygon_test.rb +35 -0
  87. data/sample/rasterscroll.rb +25 -0
  88. data/sample/takahashi.rb +42 -0
  89. data/sample/text.png +0 -0
  90. data/sample/textbox_sample.rb +190 -0
  91. data/sample/transform.rb +54 -0
  92. data/sample/utility_test.rb +73 -0
  93. data/sample/utility_test2.rb +61 -0
  94. data/sample/utility_test3.rb +64 -0
  95. data/sample/utility_test4.rb +73 -0
  96. data/uninstall_miyako.rb +19 -0
  97. data/win/miyako_no_katana.so +0 -0
  98. metadata +165 -148
  99. data/miyako.png +0 -0
  100. data/miyako_banner.png +0 -0
  101. data/miyako_no_katana/miyako_no_katana.c +0 -3301
  102. data/sample/fixed_map_test/map_sample.rb +0 -121
data/miyako_layout.c ADDED
@@ -0,0 +1,191 @@
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
+
31
+ static VALUE mSDL = Qnil;
32
+ static VALUE mMiyako = Qnil;
33
+ static VALUE mScreen = Qnil;
34
+ static VALUE mLayout = Qnil;
35
+ static VALUE nZero = Qnil;
36
+ static VALUE nOne = Qnil;
37
+ static volatile ID id_update = Qnil;
38
+ static volatile ID id_kakko = Qnil;
39
+ static volatile ID id_render = Qnil;
40
+ static volatile ID id_to_a = Qnil;
41
+ static volatile int zero = Qnil;
42
+ static volatile int one = Qnil;
43
+
44
+ static VALUE layout_snap(int argc, VALUE *argv, VALUE self);
45
+ static VALUE layout_move(VALUE self, VALUE dx, VALUE dy);
46
+
47
+ static VALUE layout_update_layout(VALUE self, VALUE dx, VALUE dy)
48
+ {
49
+ rb_funcall(self, rb_intern("update_layout_position"), 0);
50
+ VALUE layout = rb_iv_get(self, "@layout");
51
+ VALUE children = *(RSTRUCT_PTR(*(RSTRUCT_PTR(layout)+3))+1);
52
+ int i;
53
+ for(i=0; i<RARRAY_LEN(children); i++)
54
+ {
55
+ layout_move(*(RARRAY_PTR(children) + i), dx, dy);
56
+ }
57
+ return Qnil;
58
+ }
59
+
60
+ static VALUE layout_move(VALUE self, VALUE dx, VALUE dy)
61
+ {
62
+ VALUE *pos = RSTRUCT_PTR(*(RSTRUCT_PTR(rb_iv_get(self, "@layout"))));
63
+ VALUE *pox = pos+0;
64
+ VALUE *poy = pos+1;
65
+ VALUE tx = *pox;
66
+ VALUE ty = *poy;
67
+ *pox = INT2NUM(NUM2INT(tx)+NUM2INT(dx));
68
+ *poy = INT2NUM(NUM2INT(ty)+NUM2INT(dy));
69
+ layout_update_layout(self, dx, dy);
70
+ VALUE on_move = *(RSTRUCT_PTR(rb_iv_get(self, "@layout")) + 4);
71
+ int i;
72
+ for(i=0; i<RARRAY_LEN(on_move); i++)
73
+ {
74
+ rb_funcall(*(RARRAY_PTR(on_move) + i), rb_intern("call"), 5, self, *pox, *poy, dx, dy);
75
+ }
76
+ if(rb_block_given_p() == Qtrue){
77
+ VALUE ret = rb_yield(self);
78
+ if(ret == Qnil || ret == Qfalse)
79
+ {
80
+ *pox = tx;
81
+ *poy = ty;
82
+ layout_update_layout(self, INT2NUM(-(NUM2INT(dx))), INT2NUM(-(NUM2INT(dy))));
83
+ }
84
+ }
85
+ return self;
86
+ }
87
+
88
+ static VALUE layout_move_to(VALUE self, VALUE x, VALUE y)
89
+ {
90
+ VALUE *pos = RSTRUCT_PTR(*(RSTRUCT_PTR(rb_iv_get(self, "@layout"))));
91
+ VALUE *pox = pos+0;
92
+ VALUE *poy = pos+1;
93
+ VALUE tx = *pox;
94
+ VALUE ty = *poy;
95
+ *pox = x;
96
+ *poy = y;
97
+ VALUE dx = INT2NUM((NUM2INT(x))-(NUM2INT(tx)));
98
+ VALUE dy = INT2NUM((NUM2INT(y))-(NUM2INT(ty)));
99
+ layout_update_layout(self, dx, dy);
100
+ VALUE on_move = *(RSTRUCT_PTR(rb_iv_get(self, "@layout")) + 4);
101
+ int i;
102
+ for(i=0; i<RARRAY_LEN(on_move); i++)
103
+ {
104
+ rb_funcall(*(RARRAY_PTR(on_move) + i), rb_intern("call"), 5, self, *pox, *poy, dx, dy);
105
+ }
106
+ if(rb_block_given_p() == Qtrue){
107
+ VALUE ret = rb_yield(self);
108
+ if(ret == Qnil || ret == Qfalse)
109
+ {
110
+ *pox = tx;
111
+ *poy = ty;
112
+ layout_update_layout(self, INT2NUM(-(NUM2INT(dx))), INT2NUM(-(NUM2INT(dy))));
113
+ }
114
+ }
115
+ return self;
116
+ }
117
+
118
+ static VALUE layout_add_snap_child(VALUE self, VALUE spr)
119
+ {
120
+ VALUE layout = rb_iv_get(self, "@layout");
121
+ VALUE snap = *(RSTRUCT_PTR(layout)+3);
122
+ VALUE children = *(RSTRUCT_PTR(snap)+1);
123
+ if(rb_ary_includes(children, spr)==Qfalse){ rb_ary_push(children, spr); }
124
+ return self;
125
+ }
126
+
127
+ static VALUE layout_delete_snap_child(VALUE self, VALUE spr)
128
+ {
129
+ VALUE layout = rb_iv_get(self, "@layout");
130
+ VALUE snap = *(RSTRUCT_PTR(layout)+3);
131
+ VALUE children = *(RSTRUCT_PTR(snap)+1);
132
+ if(TYPE(spr) == T_ARRAY)
133
+ {
134
+ int i;
135
+ for(i=0; i<RARRAY_LEN(spr); i++){ rb_ary_delete(children, *(RARRAY_PTR(spr) + i)); }
136
+ }
137
+ else
138
+ {
139
+ rb_ary_delete(children, spr);
140
+ }
141
+ return self;
142
+ }
143
+
144
+ static VALUE layout_snap(int argc, VALUE *argv, VALUE self)
145
+ {
146
+ VALUE spr = Qnil;
147
+ rb_scan_args(argc, argv, "01", &spr);
148
+ VALUE layout = rb_iv_get(self, "@layout");
149
+ VALUE *sprite = RSTRUCT_PTR(*(RSTRUCT_PTR(layout)+3));
150
+ VALUE *base = RSTRUCT_PTR(layout)+2;
151
+ if(spr != Qnil)
152
+ {
153
+ if(*sprite != Qnil){ layout_delete_snap_child(*sprite, self); }
154
+ *sprite = spr;
155
+ layout_add_snap_child(spr, self);
156
+ }
157
+ if(*sprite != Qnil)
158
+ {
159
+ *base = *sprite;
160
+ }
161
+ else
162
+ {
163
+ *base = mScreen;
164
+ }
165
+ return self;
166
+ }
167
+
168
+ void Init_miyako_layout()
169
+ {
170
+ mSDL = rb_define_module("SDL");
171
+ mMiyako = rb_define_module("Miyako");
172
+ mScreen = rb_define_module_under(mMiyako, "Screen");
173
+ mLayout = rb_define_module_under(mMiyako, "Layout");
174
+
175
+ id_update = rb_intern("update");
176
+ id_kakko = rb_intern("[]");
177
+ id_render = rb_intern("render");
178
+ id_to_a = rb_intern("to_a");
179
+
180
+ zero = 0;
181
+ nZero = INT2NUM(zero);
182
+ one = 1;
183
+ nOne = INT2NUM(one);
184
+
185
+ rb_define_method(mLayout, "move", layout_move, 2);
186
+ rb_define_method(mLayout, "move_to", layout_move_to, 2);
187
+ rb_define_method(mLayout, "update_layout", layout_update_layout, 2);
188
+ rb_define_method(mLayout, "snap", layout_snap, -1);
189
+ rb_define_method(mLayout, "add_snap_child", layout_add_snap_child, 1);
190
+ rb_define_method(mLayout, "delete_snap_child", layout_delete_snap_child, 1);
191
+ }
@@ -0,0 +1,1074 @@
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 mSDL = Qnil;
33
+ static VALUE mMiyako = Qnil;
34
+ static VALUE mScreen = Qnil;
35
+ static VALUE mDiagram = Qnil;
36
+ static VALUE cSurface = Qnil;
37
+ static VALUE cGL = Qnil;
38
+ static VALUE cFont = Qnil;
39
+ static VALUE cThread = Qnil;
40
+ static VALUE cSprite = Qnil;
41
+ static VALUE cSpriteAnimation = Qnil;
42
+ static VALUE cPlane = Qnil;
43
+ static VALUE cParts = Qnil;
44
+ static VALUE cMap = Qnil;
45
+ static VALUE cMapLayer = Qnil;
46
+ static VALUE cFixedMap = Qnil;
47
+ static VALUE cFixedMapLayer = Qnil;
48
+ static VALUE cProcessor = Qnil;
49
+ static VALUE nZero = Qnil;
50
+ static VALUE nOne = Qnil;
51
+ static volatile ID id_update = Qnil;
52
+ static volatile ID id_kakko = Qnil;
53
+ static volatile ID id_render = Qnil;
54
+ static volatile ID id_to_a = Qnil;
55
+ static volatile int zero = Qnil;
56
+ static volatile int one = Qnil;
57
+
58
+ // from rubysdl_video.c
59
+ static GLOBAL_DEFINE_GET_STRUCT(Surface, GetSurface, cSurface, "SDL::Surface");
60
+
61
+ static VALUE use_opengl = Qnil;
62
+
63
+ extern void Init_miyako_bitmap();
64
+ extern void Init_miyako_transform();
65
+ extern void Init_miyako_hsv();
66
+ extern void Init_miyako_drawing();
67
+ extern void Init_miyako_layout();
68
+ extern void Init_miyako_collision();
69
+ extern void Init_miyako_basicdata();
70
+ extern void Init_miyako_font();
71
+ extern void Init_miyako_utility();
72
+
73
+ /*
74
+ ===内部用レンダメソッド
75
+ */
76
+ static void render_to_inner(MiyakoBitmap *sb, MiyakoBitmap *db)
77
+ {
78
+ if(sb->ptr == db->ptr){ return; }
79
+
80
+ MiyakoSize size;
81
+ if(_miyako_init_rect(sb, db, &size) == 0) return;
82
+
83
+ SDL_LockSurface(sb->surface);
84
+ SDL_LockSurface(db->surface);
85
+
86
+ int x, y;
87
+ for(y = 0; y < size.h; y++)
88
+ {
89
+ Uint32 *psrc = sb->ptr + (sb->rect.y + y) * sb->surface->w + sb->rect.x;
90
+ Uint32 *pdst = db->ptr + (db->rect.y + sb->y + y) * db->surface->w + db->rect.x + sb->x;
91
+ for(x = 0; x < size.w; x++)
92
+ {
93
+ #if SDL_BYTEORDER == SDL_LIL_ENDIAN
94
+ sb->color.a = (*psrc >> 24) & 0xff | sb->a255;
95
+ if(sb->color.a == 0){ psrc++; pdst++; continue; }
96
+ db->color.a = (*pdst >> 24) & 0xff | db->a255;
97
+ if(db->color.a == 0 || sb->color.a == 255){
98
+ *pdst = *psrc | (sb->a255 << 24);
99
+ psrc++;
100
+ pdst++;
101
+ continue;
102
+ }
103
+ int a1 = sb->color.a + 1;
104
+ int a2 = 256 - sb->color.a;
105
+ sb->color.r = (*psrc >> 16) & 0xff;
106
+ sb->color.g = (*psrc >> 8) & 0xff;
107
+ sb->color.b = (*psrc ) & 0xff;
108
+ db->color.r = (*pdst >> 16) & 0xff;
109
+ db->color.g = (*pdst >> 8) & 0xff;
110
+ db->color.b = (*pdst ) & 0xff;
111
+ *pdst = ((sb->color.r * a1 + db->color.r * a2) >> 8) << 16 |
112
+ ((sb->color.g * a1 + db->color.g * a2) >> 8) << 8 |
113
+ ((sb->color.b * a1 + db->color.b * a2) >> 8) |
114
+ 0xff << 24;
115
+ #else
116
+ sb->color.a = (*psrc & sb->fmt->Amask) | sb->a255;
117
+ if(sb->color.a == 0){ psrc++; pdst++; continue; }
118
+ db->color.a = (*pdst & db->fmt->Amask) | db->a255;
119
+ if(db->color.a == 0 || sb->color.a == 255){
120
+ *pdst = *psrc | sb->a255;
121
+ psrc++;
122
+ pdst++;
123
+ continue;
124
+ }
125
+ int a1 = sb->color.a + 1;
126
+ int a2 = 256 - sb->color.a;
127
+ sb->color.r = (*psrc & sb->fmt->Rmask) >> sb->fmt->Rshift;
128
+ sb->color.g = (*psrc & sb->fmt->Gmask) >> sb->fmt->Gshift;
129
+ sb->color.b = (*psrc & sb->fmt->Bmask) >> sb->fmt->Bshift;
130
+ db->color.r = (*pdst & db->fmt->Rmask) >> db->fmt->Rshift;
131
+ db->color.g = (*pdst & db->fmt->Gmask) >> db->fmt->Gshift;
132
+ db->color.b = (*pdst & db->fmt->Bmask) >> db->fmt->Bshift;
133
+ *pdst = ((sb->color.r * a1 + db->color.r * a2) >> 8) << db->fmt->Rshift |
134
+ ((sb->color.g * a1 + db->color.g * a2) >> 8) << db->fmt->Gshift |
135
+ ((sb->color.b * a1 + db->color.b * a2) >> 8) << db->fmt->Bshift |
136
+ 0xff;
137
+ #endif
138
+ psrc++;
139
+ pdst++;
140
+ }
141
+ }
142
+
143
+ SDL_UnlockSurface(sb->surface);
144
+ SDL_UnlockSurface(db->surface);
145
+ }
146
+
147
+ /*
148
+ ===内部用レンダメソッド
149
+ */
150
+ static void render_inner(MiyakoBitmap *sb, MiyakoBitmap *db)
151
+ {
152
+ db->rect.x += sb->x;
153
+ db->rect.y += sb->y;
154
+ SDL_BlitSurface(sb->surface, &(sb->rect), db->surface, &(db->rect));
155
+ }
156
+
157
+ /*
158
+ インスタンスの内容を別のインスタンスに描画する
159
+ */
160
+ static VALUE sprite_c_render_to_sprite(VALUE self, VALUE vsrc, VALUE vdst)
161
+ {
162
+ MiyakoBitmap src, dst;
163
+ SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
164
+ _miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
165
+ render_to_inner(&src, &dst);
166
+ return self;
167
+ }
168
+
169
+ /*
170
+ インスタンスの内容を画面に描画する
171
+ */
172
+ static VALUE sprite_render(VALUE self)
173
+ {
174
+ VALUE visible = rb_iv_get(self, "@visible");
175
+ if(visible == Qfalse) return self;
176
+ MiyakoBitmap src, dst;
177
+ SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
178
+ _miyako_setup_unit_2(self, mScreen, scr, &src, &dst, Qnil, Qnil, 1);
179
+ render_inner(&src, &dst);
180
+ return self;
181
+ }
182
+
183
+ /*
184
+ インスタンスの内容を別のインスタンスに描画する
185
+ */
186
+ static VALUE sprite_render_to_sprite(VALUE self, VALUE vdst)
187
+ {
188
+ VALUE visible = rb_iv_get(self, "@visible");
189
+ if(visible == Qfalse) return self;
190
+ MiyakoBitmap src, dst;
191
+ SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
192
+ _miyako_setup_unit_2(self, vdst, scr, &src, &dst, Qnil, Qnil, 1);
193
+ render_to_inner(&src, &dst);
194
+ return self;
195
+ }
196
+
197
+ /*
198
+ :nodoc:
199
+ */
200
+ static VALUE screen_update_tick(VALUE self)
201
+ {
202
+ int t = NUM2INT(rb_funcall(mSDL, rb_intern("getTicks"), 0));
203
+ int tt = NUM2INT(rb_iv_get(mScreen, "@@t"));
204
+ int interval = t - tt;
205
+ int fps_cnt = NUM2INT(rb_iv_get(mScreen, "@@fpscnt"));
206
+
207
+ while(interval < fps_cnt){
208
+ t = NUM2INT(rb_funcall(mSDL, rb_intern("getTicks"), 0));
209
+ interval = t - tt;
210
+ }
211
+
212
+ rb_iv_set(mScreen, "@@t", INT2NUM(t));
213
+ rb_iv_set(mScreen, "@@interval", INT2NUM(interval));
214
+
215
+ return Qnil;
216
+ }
217
+
218
+ /*
219
+ :nodoc:
220
+ */
221
+ static VALUE render_auto_render_array(VALUE array)
222
+ {
223
+ int len = RARRAY_LEN(array);
224
+ if(len == 0){ return Qnil; }
225
+ VALUE *ptr = RARRAY_PTR(array);
226
+
227
+ int i;
228
+ for(i=0; i<len; i++)
229
+ {
230
+ VALUE v = *ptr;
231
+ if(v == Qnil)
232
+ {
233
+ ptr++;
234
+ continue;
235
+ }
236
+ else if(TYPE(v) == T_ARRAY)
237
+ {
238
+ render_auto_render_array(v);
239
+ }
240
+ else
241
+ {
242
+ rb_funcall(v, id_render, 0);
243
+ }
244
+ ptr++;
245
+ }
246
+
247
+ return Qnil;
248
+ }
249
+
250
+ /*
251
+ :nodoc:
252
+ */
253
+ static VALUE screen_pre_render(VALUE self)
254
+ {
255
+ VALUE pre_render_array = rb_iv_get(mScreen, "@@pre_render_array");
256
+ if(RARRAY_LEN(pre_render_array) > 0)
257
+ {
258
+ render_auto_render_array(pre_render_array);
259
+ }
260
+ return Qnil;
261
+ }
262
+
263
+ /*
264
+ 画面を更新する
265
+ */
266
+ static VALUE screen_render(VALUE self)
267
+ {
268
+ VALUE dst = rb_iv_get(mScreen, "@@unit");
269
+ SDL_Surface *pdst = GetSurface(*(RSTRUCT_PTR(dst)))->surface;
270
+ VALUE fps_view = rb_iv_get(mScreen, "@@fpsView");
271
+
272
+ VALUE auto_render_array = rb_iv_get(mScreen, "@@auto_render_array");
273
+ if(RARRAY_LEN(auto_render_array) > 0)
274
+ {
275
+ render_auto_render_array(auto_render_array);
276
+ }
277
+
278
+ if(fps_view == Qtrue){
279
+ char str[256];
280
+ int interval = NUM2INT(rb_iv_get(mScreen, "@@interval"));
281
+ int fps_max = NUM2INT(rb_const_get(mScreen, rb_intern("FpsMax")));
282
+ VALUE sans_serif = rb_funcall(cFont, rb_intern("sans_serif"), 0);
283
+ VALUE fps_sprite = Qnil;
284
+
285
+ if(interval == 0){ interval = 1; }
286
+
287
+ sprintf(str, "%d fps", fps_max / interval);
288
+ VALUE fps_str = rb_str_new2((const char *)str);
289
+
290
+ fps_sprite = rb_funcall(fps_str, rb_intern("to_sprite"), 1, sans_serif);
291
+ sprite_render(fps_sprite);
292
+ }
293
+
294
+ screen_update_tick(self);
295
+
296
+ if(use_opengl == Qfalse)
297
+ {
298
+ SDL_Flip(pdst);
299
+ return Qnil;
300
+ }
301
+ rb_funcall(cGL, rb_intern("swap_buffers"), 0);
302
+
303
+ return Qnil;
304
+ }
305
+
306
+ /*
307
+ インスタンスの内容を画面に描画する
308
+ */
309
+ static VALUE screen_render_screen(VALUE self, VALUE vsrc)
310
+ {
311
+ MiyakoBitmap src, dst;
312
+ SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
313
+ _miyako_setup_unit_2(vsrc, mScreen, scr, &src, &dst, Qnil, Qnil, 1);
314
+ render_inner(&src, &dst);
315
+ return self;
316
+ }
317
+
318
+
319
+ /*
320
+ ===マップレイヤー転送インナーメソッド
321
+ */
322
+ static void maplayer_render_inner(VALUE self, MiyakoBitmap *dst)
323
+ {
324
+ int cw = NUM2INT(rb_iv_get(self, "@cw"));
325
+ int ch = NUM2INT(rb_iv_get(self, "@ch"));
326
+ int ow = NUM2INT(rb_iv_get(self, "@ow"));
327
+ int oh = NUM2INT(rb_iv_get(self, "@oh"));
328
+
329
+ VALUE margin = rb_iv_get(self, "@pos");
330
+ int pos_x = NUM2INT(*(RSTRUCT_PTR(margin) + 0));
331
+ int pos_y = NUM2INT(*(RSTRUCT_PTR(margin) + 1));
332
+
333
+ VALUE size = rb_iv_get(self, "@size");
334
+ int size_w = NUM2INT(*(RSTRUCT_PTR(size) + 0));
335
+ int size_h = NUM2INT(*(RSTRUCT_PTR(size) + 1));
336
+
337
+ VALUE real_size = rb_iv_get(self, "@real_size");
338
+ int real_size_w = NUM2INT(*(RSTRUCT_PTR(real_size) + 0));
339
+ int real_size_h = NUM2INT(*(RSTRUCT_PTR(real_size) + 1));
340
+
341
+ VALUE param = rb_iv_get(self, "@mapchip");
342
+ VALUE mc_chip_size = *(RSTRUCT_PTR(param) + 3);
343
+ int mc_chip_size_w = NUM2INT(*(RSTRUCT_PTR(mc_chip_size) + 0));
344
+ int mc_chip_size_h = NUM2INT(*(RSTRUCT_PTR(mc_chip_size) + 1));
345
+
346
+ VALUE munits = rb_iv_get(self, "@mapchip_units");
347
+ VALUE mapdat = rb_iv_get(self, "@mapdat");
348
+
349
+ if(pos_x < 0){ pos_x = real_size_w + (pos_x % real_size_w); }
350
+ if(pos_y < 0){ pos_y = real_size_h + (pos_y % real_size_h); }
351
+ if(pos_x >= real_size_w){ pos_x %= real_size_w; }
352
+ if(pos_y >= real_size_h){ pos_y %= real_size_h; }
353
+
354
+ int dx = pos_x / mc_chip_size_w;
355
+ int mx = pos_x % mc_chip_size_w;
356
+ int dy = pos_y / mc_chip_size_h;
357
+ int my = pos_y % mc_chip_size_h;
358
+
359
+ MiyakoBitmap src;
360
+ SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
361
+
362
+ int bx = dst->rect.x;
363
+ int by = dst->rect.y;
364
+
365
+ int x, y, idx1, idx2;
366
+ for(y = 0; y < ch; y++){
367
+ idx1 = (y + dy) % size_h;
368
+ VALUE mapdat2 = *(RARRAY_PTR(mapdat) + idx1);
369
+ for(x = 0; x < cw; x++){
370
+ idx2 = (x + dx) % size_w;
371
+ int code = NUM2INT(*(RARRAY_PTR(mapdat2) + idx2));
372
+ if(code == -1){ continue; }
373
+ _miyako_setup_unit(
374
+ rb_funcall(*(RARRAY_PTR(munits) + code),
375
+ rb_intern("to_unit"), 0),
376
+ scr, &src,
377
+ INT2NUM(x * ow - mx), INT2NUM(y * oh - my), 0);
378
+ render_inner(&src, dst);
379
+ dst->rect.x = bx;
380
+ dst->rect.y = by;
381
+ }
382
+ }
383
+ }
384
+
385
+ /*
386
+ ===固定マップレイヤー転送インナーメソッド
387
+ */
388
+ static void fixedmaplayer_render_inner(VALUE self, MiyakoBitmap *dst)
389
+ {
390
+ int cw = NUM2INT(rb_iv_get(self, "@cw"));
391
+ int ch = NUM2INT(rb_iv_get(self, "@ch"));
392
+ int ow = NUM2INT(rb_iv_get(self, "@ow"));
393
+ int oh = NUM2INT(rb_iv_get(self, "@oh"));
394
+
395
+ VALUE pos = rb_iv_get(self, "@pos");
396
+ int pos_x = NUM2INT(*(RSTRUCT_PTR(pos) + 0));
397
+ int pos_y = NUM2INT(*(RSTRUCT_PTR(pos) + 1));
398
+
399
+ VALUE size = rb_iv_get(self, "@size");
400
+ int size_w = NUM2INT(*(RSTRUCT_PTR(size) + 0));
401
+ int size_h = NUM2INT(*(RSTRUCT_PTR(size) + 1));
402
+
403
+ VALUE munits = rb_iv_get(self, "@mapchip_units");
404
+ VALUE mapdat = rb_iv_get(self, "@mapdat");
405
+
406
+ MiyakoBitmap src;
407
+ SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
408
+
409
+ int bx = dst->rect.x;
410
+ int by = dst->rect.y;
411
+
412
+ int x, y, idx1, idx2;
413
+ for(y = 0; y < ch; y++){
414
+ idx1 = y % size_h;
415
+ VALUE mapdat2 = *(RARRAY_PTR(mapdat) + idx1);
416
+ for(x = 0; x < cw; x++){
417
+ idx2 = x % size_w;
418
+ int code = NUM2INT(*(RARRAY_PTR(mapdat2) + idx2));
419
+ if(code == -1){ continue; }
420
+ _miyako_setup_unit(rb_funcall(*(RARRAY_PTR(munits) + code), rb_intern("to_unit"), 0),
421
+ scr, &src, INT2NUM(pos_x + x * ow), INT2NUM(pos_y + y * oh), 0);
422
+ render_inner(&src, dst);
423
+ dst->rect.x = bx;
424
+ dst->rect.y = by;
425
+ }
426
+ }
427
+ }
428
+
429
+ /*
430
+ ===マップレイヤー転送インナーメソッド
431
+ */
432
+ static void maplayer_render_to_inner(VALUE self, MiyakoBitmap *dst)
433
+ {
434
+ int cw = NUM2INT(rb_iv_get(self, "@cw"));
435
+ int ch = NUM2INT(rb_iv_get(self, "@ch"));
436
+ int ow = NUM2INT(rb_iv_get(self, "@ow"));
437
+ int oh = NUM2INT(rb_iv_get(self, "@oh"));
438
+
439
+ VALUE margin = rb_iv_get(self, "@pos");
440
+ int pos_x = NUM2INT(*(RSTRUCT_PTR(margin) + 0));
441
+ int pos_y = NUM2INT(*(RSTRUCT_PTR(margin) + 1));
442
+
443
+ VALUE size = rb_iv_get(self, "@size");
444
+ int size_w = NUM2INT(*(RSTRUCT_PTR(size) + 0));
445
+ int size_h = NUM2INT(*(RSTRUCT_PTR(size) + 1));
446
+
447
+ VALUE real_size = rb_iv_get(self, "@real_size");
448
+ int real_size_w = NUM2INT(*(RSTRUCT_PTR(real_size) + 0));
449
+ int real_size_h = NUM2INT(*(RSTRUCT_PTR(real_size) + 1));
450
+
451
+ VALUE param = rb_iv_get(self, "@mapchip");
452
+ VALUE mc_chip_size = *(RSTRUCT_PTR(param) + 3);
453
+ int mc_chip_size_w = NUM2INT(*(RSTRUCT_PTR(mc_chip_size) + 0));
454
+ int mc_chip_size_h = NUM2INT(*(RSTRUCT_PTR(mc_chip_size) + 1));
455
+
456
+ VALUE munits = rb_iv_get(self, "@mapchip_units");
457
+ VALUE mapdat = rb_iv_get(self, "@mapdat");
458
+
459
+ if(pos_x < 0){ pos_x = real_size_w + (pos_x % real_size_w); }
460
+ if(pos_y < 0){ pos_y = real_size_h + (pos_y % real_size_h); }
461
+ if(pos_x >= real_size_w){ pos_x %= real_size_w; }
462
+ if(pos_y >= real_size_h){ pos_y %= real_size_h; }
463
+
464
+ int dx = pos_x / mc_chip_size_w;
465
+ int mx = pos_x % mc_chip_size_w;
466
+ int dy = pos_y / mc_chip_size_h;
467
+ int my = pos_y % mc_chip_size_h;
468
+
469
+ MiyakoBitmap src;
470
+ SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
471
+
472
+ int bx = dst->rect.x;
473
+ int by = dst->rect.y;
474
+
475
+ int x, y, idx1, idx2;
476
+ for(y = 0; y < ch; y++){
477
+ idx1 = (y + dy) % size_h;
478
+ VALUE mapdat2 = *(RARRAY_PTR(mapdat) + idx1);
479
+ for(x = 0; x < cw; x++){
480
+ idx2 = (x + dx) % size_w;
481
+ int code = NUM2INT(*(RARRAY_PTR(mapdat2) + idx2));
482
+ if(code == -1){ continue; }
483
+ _miyako_setup_unit(rb_funcall(*(RARRAY_PTR(munits) + code), rb_intern("to_unit"), 0),
484
+ scr, &src, INT2NUM(x * ow - mx), INT2NUM(y * oh - my), 0);
485
+ render_inner(&src, dst);
486
+ dst->rect.x = bx;
487
+ dst->rect.y = by;
488
+ }
489
+ }
490
+ }
491
+
492
+ /*
493
+ ===固定マップレイヤー転送インナーメソッド
494
+ */
495
+ static void fixedmaplayer_render_to_inner(VALUE self, MiyakoBitmap *dst)
496
+ {
497
+ int cw = NUM2INT(rb_iv_get(self, "@cw"));
498
+ int ch = NUM2INT(rb_iv_get(self, "@ch"));
499
+ int ow = NUM2INT(rb_iv_get(self, "@ow"));
500
+ int oh = NUM2INT(rb_iv_get(self, "@oh"));
501
+
502
+ VALUE pos = rb_iv_get(self, "@pos");
503
+ int pos_x = NUM2INT(*(RSTRUCT_PTR(pos) + 0));
504
+ int pos_y = NUM2INT(*(RSTRUCT_PTR(pos) + 1));
505
+
506
+ VALUE size = rb_iv_get(self, "@size");
507
+ int size_w = NUM2INT(*(RSTRUCT_PTR(size) + 0));
508
+ int size_h = NUM2INT(*(RSTRUCT_PTR(size) + 1));
509
+
510
+ VALUE munits = rb_iv_get(self, "@mapchip_units");
511
+ VALUE mapdat = rb_iv_get(self, "@mapdat");
512
+
513
+ MiyakoBitmap src;
514
+ SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
515
+
516
+ int bx = dst->rect.x;
517
+ int by = dst->rect.y;
518
+
519
+ int x, y, idx1, idx2;
520
+ for(y = 0; y < ch; y++){
521
+ idx1 = y % size_h;
522
+ VALUE mapdat2 = *(RARRAY_PTR(mapdat) + idx1);
523
+ for(x = 0; x < cw; x++){
524
+ idx2 = x % size_w;
525
+ int code = NUM2INT(*(RARRAY_PTR(mapdat2) + idx2));
526
+ if(code == -1){ continue; }
527
+ _miyako_setup_unit(rb_funcall(*(RARRAY_PTR(munits) + code), rb_intern("to_unit"), 0),
528
+ scr, &src, INT2NUM(pos_x + x * ow), INT2NUM(pos_y + y * oh), 0);
529
+ render_inner(&src, dst);
530
+ dst->rect.x = bx;
531
+ dst->rect.y = by;
532
+ }
533
+ }
534
+ }
535
+
536
+ /*
537
+ マップレイヤーを画面に描画する
538
+ */
539
+ static VALUE maplayer_render(VALUE self)
540
+ {
541
+ VALUE visible = rb_iv_get(self, "@visible");
542
+ if(visible == Qfalse) return self;
543
+ MiyakoBitmap dst;
544
+ SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
545
+ _miyako_setup_unit(mScreen, scr, &dst, Qnil, Qnil, 1);
546
+ maplayer_render_inner(self, &dst);
547
+ return self;
548
+ }
549
+
550
+ /*
551
+ マップレイヤーを画面に描画する
552
+ */
553
+ static VALUE fixedmaplayer_render(VALUE self)
554
+ {
555
+ VALUE visible = rb_iv_get(self, "@visible");
556
+ if(visible == Qfalse) return self;
557
+ MiyakoBitmap dst;
558
+ SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
559
+ _miyako_setup_unit(mScreen, scr, &dst, Qnil, Qnil, 1);
560
+ fixedmaplayer_render_inner(self, &dst);
561
+ return self;
562
+ }
563
+
564
+ /*
565
+ マップレイヤーを画像に転送する
566
+ */
567
+ static VALUE maplayer_render_to_sprite(VALUE self, VALUE vdst)
568
+ {
569
+ VALUE visible = rb_iv_get(self, "@visible");
570
+ if(visible == Qfalse) return self;
571
+ MiyakoBitmap dst;
572
+ SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
573
+ _miyako_setup_unit(vdst, scr, &dst, Qnil, Qnil, 1);
574
+ maplayer_render_to_inner(self, &dst);
575
+ return self;
576
+ }
577
+
578
+ /*
579
+ マップレイヤーを画像に転送する
580
+ */
581
+ static VALUE fixedmaplayer_render_to_sprite(VALUE self, VALUE vdst)
582
+ {
583
+ VALUE visible = rb_iv_get(self, "@visible");
584
+ if(visible == Qfalse) return self;
585
+ MiyakoBitmap dst;
586
+ SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
587
+ _miyako_setup_unit(vdst, scr, &dst, Qnil, Qnil, 1);
588
+ maplayer_render_inner(self, &dst);
589
+ return self;
590
+ }
591
+
592
+ /*
593
+ マップを画面に描画する
594
+ */
595
+ static VALUE map_render(VALUE self)
596
+ {
597
+ VALUE visible = rb_iv_get(self, "@visible");
598
+ if(visible == Qfalse) return self;
599
+ MiyakoBitmap dst;
600
+ SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
601
+ _miyako_setup_unit(mScreen, scr, &dst, Qnil, Qnil, 1);
602
+ VALUE map_layers = rb_iv_get(self, "@map_layers");
603
+ int i;
604
+ for(i=0; i<RARRAY_LEN(map_layers); i++){
605
+ maplayer_render_inner(*(RARRAY_PTR(map_layers) + i), &dst);
606
+ }
607
+
608
+ return self;
609
+ }
610
+
611
+ /*
612
+ マップを画面に描画する
613
+ */
614
+ static VALUE fixedmap_render(VALUE self)
615
+ {
616
+ VALUE visible = rb_iv_get(self, "@visible");
617
+ if(visible == Qfalse) return self;
618
+ MiyakoBitmap dst;
619
+ SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
620
+ _miyako_setup_unit(mScreen, scr, &dst, Qnil, Qnil, 1);
621
+ VALUE map_layers = rb_iv_get(self, "@map_layers");
622
+ int i;
623
+ for(i=0; i<RARRAY_LEN(map_layers); i++){
624
+ fixedmaplayer_render_inner(*(RARRAY_PTR(map_layers) + i), &dst);
625
+ }
626
+
627
+ return self;
628
+ }
629
+
630
+ /*
631
+ マップを画像に描画する
632
+ */
633
+ static VALUE map_render_to_sprite(VALUE self, VALUE vdst)
634
+ {
635
+ VALUE visible = rb_iv_get(self, "@visible");
636
+ if(visible == Qfalse) return self;
637
+ MiyakoBitmap dst;
638
+ SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
639
+ _miyako_setup_unit(vdst, scr, &dst, Qnil, Qnil, 1);
640
+
641
+ VALUE map_layers = rb_iv_get(self, "@map_layers");
642
+ int i;
643
+ for(i=0; i<RARRAY_LEN(map_layers); i++){
644
+ maplayer_render_to_inner(*(RARRAY_PTR(map_layers) + i), &dst);
645
+ }
646
+
647
+ return self;
648
+ }
649
+
650
+ /*
651
+ マップを画像に描画する
652
+ */
653
+ static VALUE fixedmap_render_to_sprite(VALUE self, VALUE vdst)
654
+ {
655
+ VALUE visible = rb_iv_get(self, "@visible");
656
+ if(visible == Qfalse) return self;
657
+ MiyakoBitmap dst;
658
+ SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
659
+ _miyako_setup_unit(vdst, scr, &dst, Qnil, Qnil, 1);
660
+
661
+ VALUE map_layers = rb_iv_get(self, "@map_layers");
662
+ int i;
663
+ for(i=0; i<RARRAY_LEN(map_layers); i++){
664
+ fixedmaplayer_render_to_inner(*(RARRAY_PTR(map_layers) + i), &dst);
665
+ }
666
+
667
+ return self;
668
+ }
669
+
670
+ /*
671
+ :nodoc:
672
+ */
673
+ static VALUE sa_set_pat(VALUE self)
674
+ {
675
+ VALUE num = rb_iv_get(self, "@pnum");
676
+ VALUE plist = rb_iv_get(self, "@plist");
677
+ VALUE units = rb_iv_get(self, "@units");
678
+ rb_iv_set(self, "@now", *(RARRAY_PTR(units) + NUM2INT(*(RARRAY_PTR(plist) + NUM2INT(num)))));
679
+ return self;
680
+ }
681
+
682
+ /*
683
+ :nodoc:
684
+ */
685
+ static VALUE sa_update_frame(VALUE self)
686
+ {
687
+ int cnt = NUM2INT(rb_iv_get(self, "@cnt"));
688
+
689
+ if(cnt > 0){
690
+ cnt--;
691
+ rb_iv_set(self, "@cnt", INT2NUM(cnt));
692
+ return Qfalse;
693
+ }
694
+
695
+ VALUE num = rb_iv_get(self, "@pnum");
696
+ VALUE loop = rb_iv_get(self, "@loop");
697
+
698
+ int pnum = NUM2INT(num);
699
+ int pats = NUM2INT(rb_iv_get(self, "@pats"));
700
+ pnum = (pnum + 1) % pats;
701
+
702
+ rb_iv_set(self, "@pnum", INT2NUM(pnum));
703
+
704
+ if(loop == Qfalse && pnum == 0){
705
+ rb_funcall(self, rb_intern("stop"), 0);
706
+ return Qfalse;
707
+ }
708
+
709
+ sa_set_pat(self);
710
+ VALUE plist = rb_iv_get(self, "@plist");
711
+ VALUE waits = rb_iv_get(self, "@waits");
712
+ rb_iv_set(self, "@cnt", *(RARRAY_PTR(waits) + NUM2INT(*(RARRAY_PTR(plist) + pnum))));
713
+
714
+ return Qtrue;
715
+ }
716
+
717
+ /*
718
+ :nodoc:
719
+ */
720
+ static VALUE sa_update_wait_counter(VALUE self)
721
+ {
722
+ VALUE cnt = rb_iv_get(self, "@cnt");
723
+ VALUE waiting = rb_funcall(cnt, rb_intern("waiting?"), 0);
724
+
725
+ if(waiting == Qtrue) return Qfalse;
726
+
727
+ VALUE num = rb_iv_get(self, "@pnum");
728
+ VALUE loop = rb_iv_get(self, "@loop");
729
+
730
+ int pnum = NUM2INT(num);
731
+ int pats = NUM2INT(rb_iv_get(self, "@pats"));
732
+ pnum = (pnum + 1) % pats;
733
+
734
+ rb_iv_set(self, "@pnum", INT2NUM(pnum));
735
+
736
+ if(loop == Qfalse && pnum == 0){
737
+ rb_funcall(self, rb_intern("stop"), 0);
738
+ return Qfalse;
739
+ }
740
+
741
+ sa_set_pat(self);
742
+ VALUE plist = rb_iv_get(self, "@plist");
743
+ VALUE waits = rb_iv_get(self, "@waits");
744
+ cnt = *(RARRAY_PTR(waits) + NUM2INT(*(RARRAY_PTR(plist) + pnum)));
745
+ rb_iv_set(self, "@cnt", cnt);
746
+ rb_funcall(cnt, rb_intern("start"), 0);
747
+ return Qtrue;
748
+ }
749
+
750
+ /*
751
+ :nodoc:
752
+ */
753
+ static VALUE sa_update(VALUE self)
754
+ {
755
+ VALUE is_change = Qfalse;
756
+ VALUE exec = rb_iv_get(self, "@exec");
757
+ if(exec == Qfalse){ return is_change; }
758
+
759
+ if(rb_obj_is_kind_of(rb_iv_get(self, "@cnt"), rb_cInteger) == Qtrue)
760
+ is_change = sa_update_frame(self);
761
+ else
762
+ is_change = sa_update_wait_counter(self);
763
+
764
+ return is_change;
765
+ }
766
+
767
+ /*
768
+ アニメーションの現在の画像を画面に描画する
769
+ */
770
+ static VALUE sa_render(VALUE self)
771
+ {
772
+ VALUE visible = rb_iv_get(self, "@visible");
773
+ if(visible == Qfalse) return self;
774
+ VALUE vsrc = rb_iv_get(self, "@now");
775
+ VALUE *runit = RSTRUCT_PTR(vsrc);
776
+ VALUE polist = rb_iv_get(self, "@pos_offset");
777
+ VALUE dir = rb_iv_get(self, "@dir");
778
+
779
+ int num = NUM2INT(rb_iv_get(self, "@pnum"));
780
+
781
+ VALUE *move_off = RARRAY_PTR(rb_funcall(*(RARRAY_PTR(rb_iv_get(self, "@move_offset")) + num), id_to_a, 0));
782
+
783
+ int pos_off = NUM2INT(*(RARRAY_PTR(polist) + num));
784
+
785
+ int didx = (rb_to_id(dir) == rb_intern("h") ? 2 : 1);
786
+
787
+ VALUE tmp_oxy = *(runit + didx);
788
+ VALUE tmp_x = *(runit + 5);
789
+ VALUE tmp_y = *(runit + 6);
790
+
791
+ *(runit + didx) = INT2NUM(NUM2INT(tmp_oxy) - pos_off);
792
+ *(runit + 5) = INT2NUM(NUM2INT(tmp_x) + NUM2INT(*(move_off+0)));
793
+ *(runit + 6) = INT2NUM(NUM2INT(tmp_y) + NUM2INT(*(move_off+1)));
794
+
795
+ MiyakoBitmap src, dst;
796
+ SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
797
+ _miyako_setup_unit_2(vsrc, mScreen, scr, &src, &dst, Qnil, Qnil, 1);
798
+ render_inner(&src, &dst);
799
+
800
+ *(runit + 5) = tmp_x;
801
+ *(runit + 6) = tmp_y;
802
+ *(runit + didx) = tmp_oxy;
803
+
804
+ return Qnil;
805
+ }
806
+
807
+ /*
808
+ アニメーションの現在の画像を画像に描画する
809
+ */
810
+ static VALUE sa_render_to_sprite(VALUE self, VALUE vdst)
811
+ {
812
+ VALUE visible = rb_iv_get(self, "@visible");
813
+ if(visible == Qfalse) return self;
814
+ VALUE vsrc = rb_iv_get(self, "@now");
815
+ VALUE *runit = RSTRUCT_PTR(vsrc);
816
+ VALUE polist = rb_iv_get(self, "@pos_offset");
817
+ VALUE dir = rb_iv_get(self, "@dir");
818
+
819
+ int num = NUM2INT(rb_iv_get(self, "@pnum"));
820
+
821
+ int pos_off = NUM2INT(*(RARRAY_PTR(polist) + num));
822
+
823
+ VALUE molist = rb_iv_get(self, "@move_offset");
824
+ VALUE move_off = *(RARRAY_PTR(molist) + num);
825
+
826
+ int didx = (rb_to_id(dir) == rb_intern("h") ? 3 : 2);
827
+
828
+ VALUE tmp_oxy = *(runit + didx);
829
+ VALUE tmp_x = *(runit + 5);
830
+ VALUE tmp_y = *(runit + 6);
831
+
832
+ *(runit + didx) = INT2NUM(NUM2INT(tmp_oxy) - pos_off);
833
+ *(runit + 5) = INT2NUM(NUM2INT(tmp_x) + NUM2INT(rb_funcall(move_off, id_kakko, 1, nZero)));
834
+ *(runit + 6) = INT2NUM(NUM2INT(tmp_y) + NUM2INT(rb_funcall(move_off, id_kakko, 1, nOne )));
835
+
836
+ MiyakoBitmap src, dst;
837
+ SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
838
+ _miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
839
+ render_to_inner(&src, &dst);
840
+
841
+ *(runit + 5) = tmp_x;
842
+ *(runit + 6) = tmp_y;
843
+ *(runit + didx) = tmp_oxy;
844
+
845
+ return Qnil;
846
+ }
847
+
848
+ /*
849
+ プレーンを画面に描画する
850
+ */
851
+ static VALUE plane_render(VALUE self)
852
+ {
853
+ VALUE visible = rb_iv_get(self, "@visible");
854
+ if(visible == Qfalse) return self;
855
+ VALUE sprite = rb_iv_get(self, "@sprite");
856
+
857
+ VALUE ssize = rb_iv_get(mScreen, "@@size");
858
+ int ssw = NUM2INT(*(RSTRUCT_PTR(ssize) + 0));
859
+ int ssh = NUM2INT(*(RSTRUCT_PTR(ssize) + 1));
860
+ VALUE pos = rb_iv_get(self, "@pos");
861
+ VALUE size = rb_iv_get(self, "@size");
862
+ int w = NUM2INT(*(RSTRUCT_PTR(size) + 0));
863
+ int h = NUM2INT(*(RSTRUCT_PTR(size) + 1));
864
+ int pos_x = NUM2INT(*(RSTRUCT_PTR(pos) + 0));
865
+ int pos_y = NUM2INT(*(RSTRUCT_PTR(pos) + 1));
866
+
867
+ MiyakoBitmap src, dst;
868
+ SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
869
+ _miyako_setup_unit_2(sprite, mScreen, scr, &src, &dst, Qnil, Qnil, 1);
870
+
871
+ int sw = src.rect.w;
872
+ int sh = src.rect.h;
873
+
874
+ int x, y;
875
+ for(y = 0; y < h; y++){
876
+ for(x = 0; x < w; x++){
877
+ src.x = (x-1) * sw + pos_x;
878
+ src.y = (y-1) * sh + pos_y;
879
+ if(src.x > 0 || src.y > 0
880
+ || (src.x+sw) <= ssw || (src.y+sh) <= ssh){
881
+ render_inner(&src, &dst);
882
+ }
883
+ }
884
+ }
885
+
886
+ return Qnil;
887
+ }
888
+
889
+ /*
890
+ プレーンを画像に描画する
891
+ */
892
+ static VALUE plane_render_to_sprite(VALUE self, VALUE vdst)
893
+ {
894
+ VALUE visible = rb_iv_get(self, "@visible");
895
+ if(visible == Qfalse) return self;
896
+ VALUE sprite = rb_iv_get(self, "@sprite");
897
+
898
+ VALUE ssize = rb_iv_get(mScreen, "@@size");
899
+ int ssw = NUM2INT(*(RSTRUCT_PTR(ssize) + 0));
900
+ int ssh = NUM2INT(*(RSTRUCT_PTR(ssize) + 1));
901
+ VALUE pos = rb_iv_get(self, "@pos");
902
+ VALUE size = rb_iv_get(self, "@size");
903
+ int w = NUM2INT(*(RSTRUCT_PTR(size) + 0));
904
+ int h = NUM2INT(*(RSTRUCT_PTR(size) + 1));
905
+ int pos_x = NUM2INT(*(RSTRUCT_PTR(pos) + 0));
906
+ int pos_y = NUM2INT(*(RSTRUCT_PTR(pos) + 1));
907
+
908
+ MiyakoBitmap src, dst;
909
+ SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
910
+ _miyako_setup_unit_2(sprite, vdst, scr, &src, &dst, Qnil, Qnil, 1);
911
+
912
+ int sw = src.rect.w;
913
+ int sh = src.rect.h;
914
+
915
+ int x, y;
916
+ for(y = 0; y < h; y++){
917
+ for(x = 0; x < w; x++){
918
+ src.x = (x-1) * sw + pos_x;
919
+ src.y = (y-1) * sh + pos_y;
920
+ if(src.x > 0 || src.y > 0
921
+ || (src.x+sw) <= ssw || (src.y+sh) <= ssh){
922
+ render_to_inner(&src, &dst);
923
+ }
924
+ }
925
+ }
926
+
927
+ return Qnil;
928
+ }
929
+
930
+ /*
931
+ パーツを画面に描画する
932
+ */
933
+ static VALUE parts_render(VALUE self)
934
+ {
935
+ VALUE visible = rb_iv_get(self, "@visible");
936
+ if(visible == Qfalse) return self;
937
+ VALUE parts_list = rb_iv_get(self, "@parts_list");
938
+ VALUE parts_hash = rb_iv_get(self, "@parts");
939
+
940
+ int i;
941
+ for(i=0; i<RARRAY_LEN(parts_list); i++)
942
+ {
943
+ VALUE parts = rb_hash_aref(parts_hash, *(RARRAY_PTR(parts_list) + i));
944
+ rb_funcall(parts, id_render, 0);
945
+ }
946
+
947
+ return Qnil;
948
+ }
949
+
950
+ /*
951
+ パーツを画面に描画する
952
+ */
953
+ static VALUE parts_render_to_sprite(VALUE self, VALUE vdst)
954
+ {
955
+ VALUE visible = rb_iv_get(self, "@visible");
956
+ if(visible == Qfalse) return self;
957
+ VALUE parts_list = rb_iv_get(self, "@parts_list");
958
+ VALUE parts_hash = rb_iv_get(self, "@parts");
959
+
960
+ int i;
961
+ for(i=0; i<RARRAY_LEN(parts_list); i++)
962
+ {
963
+ VALUE parts = rb_hash_aref(parts_hash, *(RARRAY_PTR(parts_list) + i));
964
+ rb_funcall(parts, rb_intern("render_to"), 1, vdst);
965
+ }
966
+
967
+ return Qnil;
968
+ }
969
+
970
+ /*
971
+ :nodoc:
972
+ */
973
+ static VALUE processor_mainloop(VALUE self)
974
+ {
975
+ VALUE diagram = rb_iv_get(self, "@diagram");
976
+ VALUE states = rb_iv_get(self, "@states");
977
+ VALUE mutex = rb_iv_get(self, "@mutex");
978
+ VALUE str_execute = rb_str_new2("execute");
979
+ VALUE sym_execute = rb_funcall(str_execute, rb_intern("to_sym"), 0);
980
+ VALUE str_pause = rb_str_new2("pause");
981
+ VALUE sym_pause = rb_funcall(str_pause, rb_intern("to_sym"), 0);
982
+ rb_funcall(diagram, rb_intern("start"), 0);
983
+ VALUE executing = rb_funcall(states, id_kakko, 1, sym_execute);
984
+ while(executing == Qtrue){
985
+ VALUE pausing = rb_funcall(states, id_kakko, 1, sym_pause);
986
+ if(pausing == Qfalse){
987
+ rb_funcall(mutex, rb_intern("lock"), 0);
988
+ rb_funcall(diagram, id_update, 0);
989
+ rb_funcall(mutex, rb_intern("unlock"), 0);
990
+ rb_funcall(cThread, rb_intern("pass"), 0);
991
+ VALUE is_finish = rb_funcall(diagram, rb_intern("finish?"), 0);
992
+ if(is_finish == Qtrue){ rb_funcall(states, rb_intern("[]="), 2, sym_execute, Qfalse); }
993
+ }
994
+ executing = rb_funcall(states, id_kakko, 1, sym_execute);
995
+ }
996
+ rb_funcall(diagram, rb_intern("stop"), 0);
997
+ return self;
998
+ }
999
+
1000
+ void Init_miyako_no_katana()
1001
+ {
1002
+ mSDL = rb_define_module("SDL");
1003
+ mMiyako = rb_define_module("Miyako");
1004
+ mScreen = rb_define_module_under(mMiyako, "Screen");
1005
+ mDiagram = rb_define_module_under(mMiyako, "Diagram");
1006
+ cSurface = rb_define_class_under(mSDL, "Surface", rb_cObject);
1007
+ cGL = rb_define_module_under(mSDL, "GL");
1008
+ cFont = rb_define_class_under(mMiyako, "Font", rb_cObject);
1009
+ cThread = rb_define_class("Thread", rb_cObject);
1010
+ cSprite = rb_define_class_under(mMiyako, "Sprite", rb_cObject);
1011
+ cSpriteAnimation = rb_define_class_under(mMiyako, "SpriteAnimation", rb_cObject);
1012
+ cPlane = rb_define_class_under(mMiyako, "Plane", rb_cObject);
1013
+ cParts = rb_define_class_under(mMiyako, "Parts", rb_cObject);
1014
+ cMap = rb_define_class_under(mMiyako, "Map", rb_cObject);
1015
+ cMapLayer = rb_define_class_under(cMap, "MapLayer", rb_cObject);
1016
+ cFixedMap = rb_define_class_under(mMiyako, "FixedMap", rb_cObject);
1017
+ cFixedMapLayer = rb_define_class_under(cFixedMap, "FixedMapLayer", rb_cObject);
1018
+ cProcessor = rb_define_class_under(mDiagram, "Processor", rb_cObject);
1019
+
1020
+ id_update = rb_intern("update");
1021
+ id_kakko = rb_intern("[]");
1022
+ id_render = rb_intern("render");
1023
+ id_to_a = rb_intern("to_a");
1024
+
1025
+ zero = 0;
1026
+ nZero = INT2NUM(zero);
1027
+ one = 1;
1028
+ nOne = INT2NUM(one);
1029
+
1030
+ rb_define_module_function(mScreen, "update_tick", screen_update_tick, 0);
1031
+ rb_define_module_function(mScreen, "pre_render", screen_pre_render, 0);
1032
+ rb_define_module_function(mScreen, "render", screen_render, 0);
1033
+ rb_define_module_function(mScreen, "render_screen", screen_render_screen, 1);
1034
+
1035
+ rb_define_method(cSpriteAnimation, "update_animation", sa_update, 0);
1036
+ rb_define_method(cSpriteAnimation, "update_frame", sa_update_frame, 0);
1037
+ rb_define_method(cSpriteAnimation, "update_wait_counter", sa_update_wait_counter, 0);
1038
+ rb_define_method(cSpriteAnimation, "set_pat", sa_set_pat, 0);
1039
+ rb_define_method(cSpriteAnimation, "render", sa_render, 0);
1040
+ rb_define_method(cSpriteAnimation, "render_to", sa_render_to_sprite, 1);
1041
+
1042
+ rb_define_singleton_method(cSprite, "render_to", sprite_c_render_to_sprite, 2);
1043
+ rb_define_method(cSprite, "render", sprite_render, 0);
1044
+ rb_define_method(cSprite, "render_to", sprite_render_to_sprite, 1);
1045
+
1046
+ rb_define_method(cPlane, "render", plane_render, 0);
1047
+ rb_define_method(cPlane, "render_to", plane_render_to_sprite, 1);
1048
+
1049
+ rb_define_method(cParts, "render", parts_render, 0);
1050
+ rb_define_method(cParts, "render_to", parts_render_to_sprite, 1);
1051
+
1052
+ rb_define_method(cProcessor, "main_loop", processor_mainloop, 0);
1053
+
1054
+ rb_define_method(cMapLayer, "render", maplayer_render, 0);
1055
+ rb_define_method(cFixedMapLayer, "render", fixedmaplayer_render, 0);
1056
+ rb_define_method(cMap, "render", map_render, 0);
1057
+ rb_define_method(cFixedMap, "render", fixedmap_render, 0);
1058
+ rb_define_method(cMap, "render_to", map_render_to_sprite, 1);
1059
+ rb_define_method(cFixedMap, "render_to", fixedmap_render_to_sprite, 1);
1060
+ rb_define_method(cMapLayer, "render_to", maplayer_render_to_sprite, 1);
1061
+ rb_define_method(cFixedMapLayer, "render_to", fixedmaplayer_render_to_sprite, 1);
1062
+
1063
+ use_opengl = rb_gv_get("$miyako_use_opengl");
1064
+
1065
+ Init_miyako_bitmap();
1066
+ Init_miyako_transform();
1067
+ Init_miyako_hsv();
1068
+ Init_miyako_drawing();
1069
+ Init_miyako_layout();
1070
+ Init_miyako_collision();
1071
+ Init_miyako_basicdata();
1072
+ Init_miyako_font();
1073
+ Init_miyako_utility();
1074
+ }