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