ruby-miyako 2.1.0

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