ruby-miyako 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/README +275 -20
  2. data/extern.h +21 -1
  3. data/install_miyako.rb +5 -3
  4. data/lib/Miyako/API/audio.rb +11 -6
  5. data/lib/Miyako/API/basic_data.rb +0 -985
  6. data/lib/Miyako/API/bitmap.rb +19 -22
  7. data/lib/Miyako/API/choices.rb +203 -69
  8. data/lib/Miyako/API/collision.rb +451 -9
  9. data/lib/Miyako/API/color.rb +177 -0
  10. data/lib/Miyako/API/diagram.rb +18 -20
  11. data/lib/Miyako/API/fixedmap.rb +207 -73
  12. data/lib/Miyako/API/font.rb +111 -18
  13. data/lib/Miyako/API/i_yuki.rb +1201 -0
  14. data/lib/Miyako/API/input.rb +65 -0
  15. data/lib/Miyako/API/layout.rb +41 -29
  16. data/lib/Miyako/API/map.rb +202 -157
  17. data/lib/Miyako/API/map_event.rb +86 -19
  18. data/lib/Miyako/API/map_struct.rb +268 -0
  19. data/lib/Miyako/API/modules.rb +136 -37
  20. data/lib/Miyako/API/movie.rb +8 -8
  21. data/lib/Miyako/API/parts.rb +63 -20
  22. data/lib/Miyako/API/plane.rb +4 -4
  23. data/lib/Miyako/API/screen.rb +16 -8
  24. data/lib/Miyako/API/sprite.rb +290 -23
  25. data/lib/Miyako/API/sprite_animation.rb +23 -11
  26. data/lib/Miyako/API/sprite_list.rb +406 -183
  27. data/lib/Miyako/API/story.rb +4 -65
  28. data/lib/Miyako/API/struct_point.rb +157 -0
  29. data/lib/Miyako/API/struct_rect.rb +233 -0
  30. data/lib/Miyako/API/struct_segment.rb +641 -0
  31. data/lib/Miyako/API/struct_size.rb +158 -0
  32. data/lib/Miyako/API/struct_square.rb +253 -0
  33. data/lib/Miyako/API/textbox.rb +49 -35
  34. data/lib/Miyako/API/viewport.rb +5 -5
  35. data/lib/Miyako/API/wait_counter.rb +350 -0
  36. data/lib/Miyako/API/yuki.rb +95 -60
  37. data/lib/Miyako/EXT/raster_scroll.rb +30 -8
  38. data/lib/Miyako/EXT/slides.rb +6 -6
  39. data/lib/Miyako/miyako.rb +25 -11
  40. data/lib/miyako.rb +28 -0
  41. data/lib/miyako_require_only.rb +35 -0
  42. data/miyako_basicdata.c +201 -17
  43. data/miyako_collision.c +315 -6
  44. data/miyako_diagram.c +331 -0
  45. data/miyako_drawing.c +26 -7
  46. data/miyako_font.c +259 -129
  47. data/miyako_input_audio.c +24 -14
  48. data/miyako_layout.c +106 -8
  49. data/miyako_no_katana.c +398 -171
  50. data/miyako_sprite2.c +275 -38
  51. data/miyako_transform.c +113 -107
  52. data/miyako_utility.c +34 -48
  53. data/miyako_yuki.c +241 -0
  54. data/sample/Diagram_sample/diagram_sample_yuki2.rb +30 -30
  55. data/sample/Room3/blue.rb +19 -19
  56. data/sample/Room3/green.rb +9 -9
  57. data/sample/Room3/main.rb +12 -12
  58. data/sample/Room3/red.rb +12 -12
  59. data/sample/Room3/title.rb +15 -10
  60. data/sample/collision_test2.rb +2 -1
  61. data/sample/fixed_map_test/fixed_map_sample.rb +7 -6
  62. data/sample/map_test/main_scene.rb +12 -10
  63. data/sample/map_test/map_manager.rb +14 -13
  64. data/sample/rasterscroll.rb +5 -5
  65. data/sample/takahashi.rb +3 -3
  66. data/sample/textbox_sample.rb +7 -6
  67. data/sample/transform.rb +2 -1
  68. data/uninstall_miyako.rb +4 -1
  69. data/win/miyako_no_katana.so +0 -0
  70. metadata +15 -4
  71. data/lib/Miyako/EXT/miyako_cairo.rb +0 -62
  72. data/sample/cairo_sample.rb +0 -25
data/miyako_transform.c CHANGED
@@ -60,9 +60,9 @@ static VALUE bitmap_miyako_rotate(VALUE self, VALUE vsrc, VALUE vdst, VALUE radi
60
60
 
61
61
  size.w = dst.rect.w;
62
62
  size.h = dst.rect.h;
63
-
63
+
64
64
  if(src.surface == dst.surface){ return Qnil; }
65
-
65
+
66
66
  if(dst.rect.w >= 32768 || dst.rect.h >= 32768){ return Qnil; }
67
67
 
68
68
  double rad = NUM2DBL(radian) * -1.0;
@@ -77,6 +77,8 @@ static VALUE bitmap_miyako_rotate(VALUE self, VALUE vsrc, VALUE vdst, VALUE radi
77
77
  int qy = -(NUM2INT(*(RSTRUCT_PTR(dst.unit)+8)));
78
78
  int qr = dst.rect.w + qx;
79
79
  int qb = dst.rect.h + qy;
80
+ Uint32 sr, sg, sb, sa;
81
+ Uint32 dr, dg, db, da;
80
82
 
81
83
  SDL_LockSurface(src.surface);
82
84
  SDL_LockSurface(dst.surface);
@@ -92,50 +94,50 @@ static VALUE bitmap_miyako_rotate(VALUE self, VALUE vsrc, VALUE vdst, VALUE radi
92
94
  int ny = (x*isin+y*icos) >> 12;
93
95
  if(ny < py || ny >= pb){ tp++; continue; }
94
96
  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
95
- dst.color.r = (*tp >> 16) & 0xff;
96
- dst.color.g = (*tp >> 8) & 0xff;
97
- dst.color.b = (*tp ) & 0xff;
98
- dst.color.a = (*tp >> 24) & 0xff | dst.a255;
99
- Uint32 *psrc = src.ptr + (src.rect.x + ny - py) * src.surface->w + src.rect.x + nx - px;
100
- src.color.a = (*psrc >> 24) & 0xff | src.a255;
101
- if(src.color.a == 0){ tp++; continue; }
102
- if(dst.color.a == 0 || src.color.a == 255)
97
+ da = (*tp >> 24) | dst.a255;
98
+ Uint32 *psrc = src.ptr + (src.rect.x + ny - py) * src.surface->w + src.rect.x + nx - px;
99
+ sa = (*psrc >> 24) | src.a255;
100
+ if(sa == 0){ tp++; continue; }
101
+ if(da == 0 || sa == 255)
103
102
  {
104
103
  *tp = *psrc;
105
104
  tp++;
106
105
  continue;
107
106
  }
108
- int a1 = src.color.a + 1;
109
- int a2 = 256 - src.color.a;
110
- src.color.r = (*psrc >> 16) & 0xff;
111
- src.color.g = (*psrc >> 8) & 0xff;
112
- src.color.b = (*psrc ) & 0xff;
113
- *tp = ((src.color.r * a1 + dst.color.r * a2) >> 8) << 16 |
114
- ((src.color.g * a1 + dst.color.g * a2) >> 8) << 8 |
115
- ((src.color.b * a1 + dst.color.b * a2) >> 8) |
116
- 0xff << 24;
107
+ int a1 = sa + 1;
108
+ int a2 = 256 - sa;
109
+ dr = *tp & 0xff0000;
110
+ dg = *tp & 0xff00;
111
+ db = *tp & 0xff;
112
+ sr = *psrc & 0xff0000;
113
+ sg = *psrc & 0xff00;
114
+ sb = *psrc & 0xff;
115
+ *tp = ((sr * a1 + dr * a2) & 0xff000000 |
116
+ (sg * a1 + dg * a2) & 0xff0000 |
117
+ (sb * a1 + db * a2)) >> 8 |
118
+ 0xff000000;
117
119
  #else
118
- dst.color.r = (*tp & dst.fmt->Rmask) >> dst.fmt->Rshift;
119
- dst.color.g = (*tp & dst.fmt->Gmask) >> dst.fmt->Gshift;
120
- dst.color.b = (*tp & dst.fmt->Bmask) >> dst.fmt->Bshift;
121
- dst.color.a = (*tp & dst.fmt->Amask) | dst.a255;
120
+ dr = (*tp & dst.fmt->Rmask) >> dst.fmt->Rshift;
121
+ dg = (*tp & dst.fmt->Gmask) >> dst.fmt->Gshift;
122
+ db = (*tp & dst.fmt->Bmask) >> dst.fmt->Bshift;
123
+ da = (*tp & dst.fmt->Amask) | dst.a255;
122
124
  Uint32 *psrc = src.ptr + (src.rect.x + ny - py) * src.surface->w + src.rect.x + nx - px;
123
- src.color.a = (*psrc & src.fmt->Amask) | src.a255;
124
- if(src.color.a == 0){ tp++; continue; }
125
- if(dst.color.a == 0 || src.color.a == 255)
125
+ sa = (*psrc & src.fmt->Amask) | src.a255;
126
+ if(sa == 0){ tp++; continue; }
127
+ if(da == 0 || sa == 255)
126
128
  {
127
129
  *tp = *psrc;
128
130
  tp++;
129
131
  continue;
130
132
  }
131
- int a1 = src.color.a + 1;
132
- int a2 = 256 - src.color.a;
133
- src.color.r = (*psrc & src.fmt->Rmask) >> src.fmt->Rshift;
134
- src.color.g = (*psrc & src.fmt->Gmask) >> src.fmt->Gshift;
135
- src.color.b = (*psrc & src.fmt->Bmask) >> src.fmt->Bshift;
136
- *tp = (((src.color.r * a1 + dst.color.r * a2) >> 8)) << dst.fmt->Rshift |
137
- (((src.color.g * a1 + dst.color.g * a2) >> 8)) << dst.fmt->Gshift |
138
- (((src.color.b * a1 + dst.color.b * a2) >> 8)) << dst.fmt->Bshift |
133
+ int a1 = sa + 1;
134
+ int a2 = 256 - sa;
135
+ sr = (*psrc & src.fmt->Rmask) >> src.fmt->Rshift;
136
+ sg = (*psrc & src.fmt->Gmask) >> src.fmt->Gshift;
137
+ sb = (*psrc & src.fmt->Bmask) >> src.fmt->Bshift;
138
+ *tp = (((sr * a1 + dr * a2) >> 8)) << dst.fmt->Rshift |
139
+ (((sg * a1 + dg * a2) >> 8)) << dst.fmt->Gshift |
140
+ (((sb * a1 + db * a2) >> 8)) << dst.fmt->Bshift |
139
141
  0xff;
140
142
  #endif
141
143
  tp++;
@@ -144,7 +146,7 @@ static VALUE bitmap_miyako_rotate(VALUE self, VALUE vsrc, VALUE vdst, VALUE radi
144
146
 
145
147
  SDL_UnlockSurface(src.surface);
146
148
  SDL_UnlockSurface(dst.surface);
147
-
149
+
148
150
  return vdst;
149
151
  }
150
152
 
@@ -156,13 +158,15 @@ static VALUE bitmap_miyako_scale(VALUE self, VALUE vsrc, VALUE vdst, VALUE xscal
156
158
  MiyakoBitmap src, dst;
157
159
  MiyakoSize size;
158
160
  SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
161
+ Uint32 sr, sg, sb, sa;
162
+ Uint32 dr, dg, db, da;
159
163
 
160
164
  _miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
161
165
 
162
166
  if(_miyako_init_rect(&src, &dst, &size) == 0) return Qnil;
163
-
167
+
164
168
  if(src.surface == dst.surface){ return Qnil; }
165
-
169
+
166
170
  if(dst.rect.w >= 32768 || dst.rect.h >= 32768){ return Qnil; }
167
171
 
168
172
  double tscx = NUM2DBL(xscale);
@@ -199,50 +203,50 @@ static VALUE bitmap_miyako_scale(VALUE self, VALUE vsrc, VALUE vdst, VALUE xscal
199
203
  int ny = (y*scy) >> 12 - off_y;
200
204
  if(ny < py || ny >= pb){ tp++; continue; }
201
205
  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
202
- dst.color.r = (*tp >> 16) & 0xff;
203
- dst.color.g = (*tp >> 8) & 0xff;
204
- dst.color.b = (*tp ) & 0xff;
205
- dst.color.a = (*tp >> 24) & 0xff | dst.a255;
206
+ da = (*tp >> 24) | dst.a255;
206
207
  Uint32 *psrc = src.ptr + (src.rect.x + ny - py) * src.surface->w + src.rect.x + nx - px;
207
- src.color.a = (*psrc >> 24) & 0xff | src.a255;
208
- if(src.color.a == 0){ tp++; continue; }
209
- if(dst.color.a == 0 || src.color.a == 255)
208
+ sa = (*psrc >> 24) | src.a255;
209
+ if(sa == 0){ tp++; continue; }
210
+ if(da == 0 || sa == 255)
210
211
  {
211
212
  *tp = *psrc;
212
213
  tp++;
213
214
  continue;
214
215
  }
215
- int a1 = src.color.a + 1;
216
- int a2 = 256 - src.color.a;
217
- src.color.r = (*psrc >> 16) & 0xff;
218
- src.color.g = (*psrc >> 8) & 0xff;
219
- src.color.b = (*psrc ) & 0xff;
220
- *tp = ((src.color.r * a1 + dst.color.r * a2) >> 8) << 16 |
221
- ((src.color.g * a1 + dst.color.g * a2) >> 8) << 8 |
222
- ((src.color.b * a1 + dst.color.b * a2) >> 8) |
223
- 0xff << 24;
216
+ int a1 = sa + 1;
217
+ int a2 = 256 - sa;
218
+ dr = *tp & 0xff0000;
219
+ dg = *tp & 0xff00;
220
+ db = *tp & 0xff;
221
+ sr = *psrc & 0xff0000;
222
+ sg = *psrc & 0xff00;
223
+ sb = *psrc & 0xff;
224
+ *tp = ((sr * a1 + dr * a2) & 0xff000000 |
225
+ (sg * a1 + dg * a2) & 0xff0000 |
226
+ (sb * a1 + db * a2)) >> 8 |
227
+ 0xff000000;
224
228
  #else
225
- dst.color.r = (*tp & dst.fmt->Rmask) >> dst.fmt->Rshift;
226
- dst.color.g = (*tp & dst.fmt->Gmask) >> dst.fmt->Gshift;
227
- dst.color.b = (*tp & dst.fmt->Bmask) >> dst.fmt->Bshift;
228
- dst.color.a = (*tp & dst.fmt->Amask) | dst.a255;
229
+ dr = (*tp & dst.fmt->Rmask) >> dst.fmt->Rshift;
230
+ dg = (*tp & dst.fmt->Gmask) >> dst.fmt->Gshift;
231
+ db = (*tp & dst.fmt->Bmask) >> dst.fmt->Bshift;
232
+ da = (*tp & dst.fmt->Amask) | dst.a255;
229
233
  Uint32 *psrc = src.ptr + (src.rect.x + ny - py) * src.surface->w + src.rect.x + nx - px;
230
- src.color.a = (*psrc & src.fmt->Amask) | src.a255;
231
- if(src.color.a == 0){ tp++; continue; }
232
- if(dst.color.a == 0 || src.color.a == 255)
234
+ sa = (*psrc & src.fmt->Amask) | src.a255;
235
+ if(sa == 0){ tp++; continue; }
236
+ if(da == 0 || sa == 255)
233
237
  {
234
238
  *tp = *psrc;
235
239
  tp++;
236
240
  continue;
237
241
  }
238
- int a1 = src.color.a + 1;
239
- int a2 = 256 - src.color.a;
240
- src.color.r = (*psrc & src.fmt->Rmask) >> src.fmt->Rshift;
241
- src.color.g = (*psrc & src.fmt->Gmask) >> src.fmt->Gshift;
242
- src.color.b = (*psrc & src.fmt->Bmask) >> src.fmt->Bshift;
243
- *tp = ((src.color.r * a1 + dst.color.r * a2) >> 8) << dst.fmt->Rshift |
244
- ((src.color.g * a1 + dst.color.g * a2) >> 8) << dst.fmt->Gshift |
245
- ((src.color.b * a1 + dst.color.b * a2) >> 8) << dst.fmt->Bshift |
242
+ int a1 = sa + 1;
243
+ int a2 = 256 - sa;
244
+ sr = (*psrc & src.fmt->Rmask) >> src.fmt->Rshift;
245
+ sg = (*psrc & src.fmt->Gmask) >> src.fmt->Gshift;
246
+ sb = (*psrc & src.fmt->Bmask) >> src.fmt->Bshift;
247
+ *tp = ((sr * a1 + dr * a2) >> 8) << dst.fmt->Rshift |
248
+ ((sg * a1 + dg * a2) >> 8) << dst.fmt->Gshift |
249
+ ((sb * a1 + db * a2) >> 8) << dst.fmt->Bshift |
246
250
  0xff;
247
251
  #endif
248
252
  tp++;
@@ -251,7 +255,7 @@ static VALUE bitmap_miyako_scale(VALUE self, VALUE vsrc, VALUE vdst, VALUE xscal
251
255
 
252
256
  SDL_UnlockSurface(src.surface);
253
257
  SDL_UnlockSurface(dst.surface);
254
-
258
+
255
259
  return vdst;
256
260
  }
257
261
 
@@ -265,7 +269,7 @@ static void transform_inner(MiyakoBitmap *src, MiyakoBitmap *dst, VALUE radian,
265
269
  MiyakoSize size;
266
270
 
267
271
  if(_miyako_init_rect(src, dst, &size) == 0) return;
268
-
272
+
269
273
  double rad = NUM2DBL(radian) * -1.0;
270
274
  long isin = (long)(sin(rad)*4096.0);
271
275
  long icos = (long)(cos(rad)*4096.0);
@@ -289,6 +293,8 @@ static void transform_inner(MiyakoBitmap *src, MiyakoBitmap *dst, VALUE radian,
289
293
  int qy = -(NUM2INT(*(RSTRUCT_PTR(dst->unit)+8)));
290
294
  int qr = dst->rect.w + qx;
291
295
  int qb = dst->rect.h + qy;
296
+ Uint32 sr, sg, sb, sa;
297
+ Uint32 dr, dg, db, da;
292
298
 
293
299
  SDL_LockSurface(src->surface);
294
300
  SDL_LockSurface(dst->surface);
@@ -304,50 +310,50 @@ static void transform_inner(MiyakoBitmap *src, MiyakoBitmap *dst, VALUE radian,
304
310
  int ny = (((x*isin+y*icos) >> 12) * scy) >> 12 - off_y;
305
311
  if(ny < py || ny >= pb){ tp++; continue; }
306
312
  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
307
- dst->color.r = (*tp >> 16) & 0xff;
308
- dst->color.g = (*tp >> 8) & 0xff;
309
- dst->color.b = (*tp ) & 0xff;
310
- dst->color.a = (*tp >> 24) & 0xff | dst->a255;
311
- Uint32 *psrc = src->ptr + (src->rect.x + ny - py) * src->surface->w + src->rect.x + nx - px;
312
- src->color.a = (*psrc >> 24) & 0xff | src->a255;
313
- if(src->color.a == 0){ tp++; continue; }
314
- if(dst->color.a == 0 || src->color.a == 255)
313
+ da = (*tp >> 24) | dst->a255;
314
+ Uint32 *psrc = src->ptr + (src->rect.x + ny - py) * src->surface->w + src->rect.x + nx - px;
315
+ sa = (*psrc >> 24) | src->a255;
316
+ if(sa == 0){ tp++; continue; }
317
+ if(da == 0 || sa == 255)
315
318
  {
316
319
  *tp = *psrc;
317
320
  tp++;
318
321
  continue;
319
322
  }
320
- int a1 = src->color.a + 1;
321
- int a2 = 256 - src->color.a;
322
- src->color.r = (*psrc >> 16) & 0xff;
323
- src->color.g = (*psrc >> 8) & 0xff;
324
- src->color.b = (*psrc ) & 0xff;
325
- *tp = ((src->color.r * a1 + dst->color.r * a2) >> 8) << 16 |
326
- ((src->color.g * a1 + dst->color.g * a2) >> 8) << 8 |
327
- ((src->color.b * a1 + dst->color.b * a2) >> 8) |
328
- 0xff << 24;
323
+ int a1 = sa + 1;
324
+ int a2 = 256 - sa;
325
+ dr = *tp & 0xff0000;
326
+ dg = *tp & 0xff00;
327
+ db = *tp & 0xff;
328
+ sr = *psrc & 0xff0000;
329
+ sg = *psrc & 0xff00;
330
+ sb = *psrc & 0xff;
331
+ *tp = ((sr * a1 + dr * a2) & 0xff000000 |
332
+ (sg * a1 + dg * a2) & 0xff0000 |
333
+ (sb * a1 + db * a2)) >> 8 |
334
+ 0xff000000;
329
335
  #else
330
- dst->color.r = (*tp & dst->fmt->Rmask) >> dst->fmt->Rshift;
331
- dst->color.g = (*tp & dst->fmt->Gmask) >> dst->fmt->Gshift;
332
- dst->color.b = (*tp & dst->fmt->Bmask) >> dst->fmt->Bshift;
333
- dst->color.a = (*tp & dst->fmt->Amask) | dst->a255;
336
+ dr = (*tp & dst->fmt->Rmask) >> dst->fmt->Rshift;
337
+ dg = (*tp & dst->fmt->Gmask) >> dst->fmt->Gshift;
338
+ db = (*tp & dst->fmt->Bmask) >> dst->fmt->Bshift;
339
+ da = (*tp & dst->fmt->Amask) | dst->a255;
334
340
  Uint32 *psrc = src->ptr + (src->rect.x + ny - py) * src->surface->w + src->rect.x + nx - px;
335
- src->color.a = (*psrc & src->fmt->Amask) | src->a255;
336
- if(src->color.a == 0){ tp++; continue; }
337
- if(dst->color.a == 0 || src->color.a == 255)
341
+ sa = (*psrc & src->fmt->Amask) | src->a255;
342
+ if(sa == 0){ tp++; continue; }
343
+ if(da == 0 || sa == 255)
338
344
  {
339
345
  *tp = *psrc;
340
346
  tp++;
341
347
  continue;
342
348
  }
343
- int a1 = src->color.a + 1;
344
- int a2 = 256 - src->color.a;
345
- src->color.r = (*psrc & src->fmt->Rmask) >> src->fmt->Rshift;
346
- src->color.g = (*psrc & src->fmt->Gmask) >> src->fmt->Gshift;
347
- src->color.b = (*psrc & src->fmt->Bmask) >> src->fmt->Bshift;
348
- *tp = ((src->color.r * a1 + dst->color.r * a2) >> 8) << dst->fmt->Rshift |
349
- ((src->color.g * a1 + dst->color.g * a2) >> 8) << dst->fmt->Gshift |
350
- ((src->color.b * a1 + dst->color.b * a2) >> 8) << dst->fmt->Bshift |
349
+ int a1 = sa + 1;
350
+ int a2 = 256 - sa;
351
+ sr = (*psrc & src->fmt->Rmask) >> src->fmt->Rshift;
352
+ sg = (*psrc & src->fmt->Gmask) >> src->fmt->Gshift;
353
+ sb = (*psrc & src->fmt->Bmask) >> src->fmt->Bshift;
354
+ *tp = ((sr * a1 + dr * a2) >> 8) << dst->fmt->Rshift |
355
+ ((sg * a1 + dg * a2) >> 8) << dst->fmt->Gshift |
356
+ ((sb * a1 + db * a2) >> 8) << dst->fmt->Bshift |
351
357
  0xff;
352
358
  #endif
353
359
  tp++;
@@ -369,7 +375,7 @@ static VALUE bitmap_miyako_transform(VALUE self, VALUE vsrc, VALUE vdst, VALUE r
369
375
  _miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
370
376
 
371
377
  if(src.surface == dst.surface){ return Qnil; }
372
-
378
+
373
379
  transform_inner(&src, &dst, radian, xscale, yscale);
374
380
  return vdst;
375
381
  }
@@ -387,7 +393,7 @@ static VALUE sprite_render_transform(VALUE self, VALUE radian, VALUE xscale, VAL
387
393
  _miyako_setup_unit_2(self, mScreen, scr, &src, &dst, Qnil, Qnil, 1);
388
394
 
389
395
  if(src.surface == dst.surface){ return Qnil; }
390
-
396
+
391
397
  transform_inner(&src, &dst, radian, xscale, yscale);
392
398
  return self;
393
399
  }
@@ -403,9 +409,9 @@ static VALUE sprite_render_to_sprite_transform(VALUE self, VALUE vdst, VALUE rad
403
409
  SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
404
410
 
405
411
  _miyako_setup_unit_2(self, vdst, scr, &src, &dst, Qnil, Qnil, 1);
406
-
412
+
407
413
  if(src.surface == dst.surface){ return Qnil; }
408
-
414
+
409
415
  transform_inner(&src, &dst, radian, xscale, yscale);
410
416
  return self;
411
417
  }
@@ -421,7 +427,7 @@ void Init_miyako_transform()
421
427
 
422
428
  rb_define_method(cSprite, "render_transform", sprite_render_transform, 3);
423
429
  rb_define_method(cSprite, "render_to_transform", sprite_render_to_sprite_transform, 4);
424
-
430
+
425
431
  id_update = rb_intern("update");
426
432
  id_kakko = rb_intern("[]");
427
433
  id_render = rb_intern("render");
data/miyako_utility.c CHANGED
@@ -37,22 +37,7 @@ static VALUE sSpriteUnit = Qnil;
37
37
  // from rubysdl_video.c
38
38
  static GLOBAL_DEFINE_GET_STRUCT(Surface, GetSurface, cSurface, "SDL::Surface");
39
39
 
40
- void _miyako_yield_unit_1(MiyakoBitmap *src)
41
- {
42
- if(rb_block_given_p() == Qtrue){ src->unit = rb_obj_dup(src->unit); rb_yield(src->unit); }
43
- }
44
-
45
- void _miyako_yield_unit_2(MiyakoBitmap *src, MiyakoBitmap *dst)
46
- {
47
- if(rb_block_given_p() == Qtrue)
48
- {
49
- src->unit = rb_obj_dup(src->unit);
50
- dst->unit = rb_obj_dup(dst->unit);
51
- rb_yield_values(2, src->unit, dst->unit);
52
- }
53
- }
54
-
55
- void _miyako_setup_unit(VALUE unit, SDL_Surface *screen, MiyakoBitmap *mb, VALUE x, VALUE y, int use_yield)
40
+ void _miyako_setup_unit(VALUE unit, SDL_Surface *screen, MiyakoBitmap *mb, VALUE x, VALUE y)
56
41
  {
57
42
  mb->unit = unit;
58
43
  if(rb_obj_is_kind_of(mb->unit, sSpriteUnit) == Qfalse){
@@ -60,13 +45,13 @@ void _miyako_setup_unit(VALUE unit, SDL_Surface *screen, MiyakoBitmap *mb, VALUE
60
45
  if(mb->unit == Qnil){ rb_raise(eMiyakoError, "Source instance has not SpriteUnit!"); }
61
46
  }
62
47
 
63
- if(use_yield) _miyako_yield_unit_1(mb);
48
+ VALUE *mb_p = RSTRUCT_PTR(mb->unit);
49
+
50
+ mb->rect.x = NUM2INT(*(mb_p + 1));
51
+ mb->rect.y = NUM2INT(*(mb_p + 2));
52
+ mb->rect.w = NUM2INT(*(mb_p + 3));
53
+ mb->rect.h = NUM2INT(*(mb_p + 4));
64
54
 
65
- mb->rect.x = NUM2INT(*(RSTRUCT_PTR(mb->unit) + 1));
66
- mb->rect.y = NUM2INT(*(RSTRUCT_PTR(mb->unit) + 2));
67
- mb->rect.w = NUM2INT(*(RSTRUCT_PTR(mb->unit) + 3));
68
- mb->rect.h = NUM2INT(*(RSTRUCT_PTR(mb->unit) + 4));
69
-
70
55
  mb->surface = GetSurface(*(RSTRUCT_PTR(mb->unit)))->surface;
71
56
  mb->ptr = (Uint32 *)(mb->surface->pixels);
72
57
  mb->fmt = mb->surface->format;
@@ -92,17 +77,17 @@ void _miyako_setup_unit(VALUE unit, SDL_Surface *screen, MiyakoBitmap *mb, VALUE
92
77
  if(mb->rect.y + mb->rect.h > mb->surface->h)
93
78
  mb->rect.h = mb->surface->h - mb->rect.y;
94
79
  }
95
-
80
+
96
81
  mb->a255 = (mb->surface == screen) ? 0xff : 0;
97
-
98
- mb->x = (x == Qnil ? NUM2INT(*(RSTRUCT_PTR(mb->unit) + 5)) : NUM2INT(x));
99
- mb->y = (y == Qnil ? NUM2INT(*(RSTRUCT_PTR(mb->unit) + 6)) : NUM2INT(y));
82
+
83
+ mb->x = (x == Qnil ? NUM2INT(*(mb_p + 5)) : NUM2INT(x));
84
+ mb->y = (y == Qnil ? NUM2INT(*(mb_p+ 6)) : NUM2INT(y));
100
85
  }
101
86
 
102
- void _miyako_setup_unit_2(VALUE unit_s, VALUE unit_d,
87
+ void _miyako_setup_unit_2(VALUE unit_s, VALUE unit_d,
103
88
  SDL_Surface *screen,
104
89
  MiyakoBitmap *mb_s, MiyakoBitmap *mb_d,
105
- VALUE x, VALUE y, int use_yield)
90
+ VALUE x, VALUE y)
106
91
  {
107
92
  mb_s->unit = unit_s;
108
93
  if(rb_obj_is_kind_of(mb_s->unit, sSpriteUnit) == Qfalse){
@@ -116,16 +101,17 @@ void _miyako_setup_unit_2(VALUE unit_s, VALUE unit_d,
116
101
  if(mb_d->unit == Qnil){ rb_raise(eMiyakoError, "Source instance has not SpriteUnit!"); }
117
102
  }
118
103
 
119
- if(use_yield) _miyako_yield_unit_2(mb_s, mb_d);
120
-
121
104
  mb_s->surface = GetSurface(*(RSTRUCT_PTR(mb_s->unit)))->surface;
122
105
  mb_s->ptr = (Uint32 *)(mb_s->surface->pixels);
123
106
  mb_s->fmt = mb_s->surface->format;
124
107
 
125
- mb_s->rect.x = NUM2INT(*(RSTRUCT_PTR(mb_s->unit) + 1));
126
- mb_s->rect.y = NUM2INT(*(RSTRUCT_PTR(mb_s->unit) + 2));
127
- mb_s->rect.w = NUM2INT(*(RSTRUCT_PTR(mb_s->unit) + 3));
128
- mb_s->rect.h = NUM2INT(*(RSTRUCT_PTR(mb_s->unit) + 4));
108
+ VALUE *ms_p = RSTRUCT_PTR(mb_s->unit);
109
+ VALUE *md_p = RSTRUCT_PTR(mb_d->unit);
110
+
111
+ mb_s->rect.x = NUM2INT(*(ms_p + 1));
112
+ mb_s->rect.y = NUM2INT(*(ms_p + 2));
113
+ mb_s->rect.w = NUM2INT(*(ms_p + 3));
114
+ mb_s->rect.h = NUM2INT(*(ms_p + 4));
129
115
 
130
116
  // adjust clip_rect
131
117
  if(mb_s->surface == screen)
@@ -150,18 +136,18 @@ void _miyako_setup_unit_2(VALUE unit_s, VALUE unit_d,
150
136
  }
151
137
 
152
138
  mb_s->a255 = (mb_s->surface == screen) ? 0xff : 0;
153
-
154
- mb_s->x = (x == Qnil ? NUM2INT(*(RSTRUCT_PTR(mb_s->unit) + 5)) : NUM2INT(x));
155
- mb_s->y = (y == Qnil ? NUM2INT(*(RSTRUCT_PTR(mb_s->unit) + 6)) : NUM2INT(y));
139
+
140
+ mb_s->x = (x == Qnil ? NUM2INT(*(ms_p + 5)) : NUM2INT(x));
141
+ mb_s->y = (y == Qnil ? NUM2INT(*(ms_p + 6)) : NUM2INT(y));
156
142
 
157
143
  mb_d->surface = GetSurface(*(RSTRUCT_PTR(mb_d->unit)))->surface;
158
144
  mb_d->ptr = (Uint32 *)(mb_d->surface->pixels);
159
145
  mb_d->fmt = mb_d->surface->format;
160
146
 
161
- mb_d->rect.x = NUM2INT(*(RSTRUCT_PTR(mb_d->unit) + 1));
162
- mb_d->rect.y = NUM2INT(*(RSTRUCT_PTR(mb_d->unit) + 2));
163
- mb_d->rect.w = NUM2INT(*(RSTRUCT_PTR(mb_d->unit) + 3));
164
- mb_d->rect.h = NUM2INT(*(RSTRUCT_PTR(mb_d->unit) + 4));
147
+ mb_d->rect.x = NUM2INT(*(md_p + 1));
148
+ mb_d->rect.y = NUM2INT(*(md_p + 2));
149
+ mb_d->rect.w = NUM2INT(*(md_p + 3));
150
+ mb_d->rect.h = NUM2INT(*(md_p + 4));
165
151
 
166
152
  // adjust clip_rect
167
153
  if(mb_d->surface == screen)
@@ -186,7 +172,7 @@ void _miyako_setup_unit_2(VALUE unit_s, VALUE unit_d,
186
172
  }
187
173
 
188
174
  mb_d->a255 = (mb_d->surface == screen) ? 0xff : 0;
189
-
175
+
190
176
  mb_d->x = NUM2INT(*(RSTRUCT_PTR(mb_d->unit) + 5));
191
177
  mb_d->y = NUM2INT(*(RSTRUCT_PTR(mb_d->unit) + 6));
192
178
  }
@@ -199,13 +185,13 @@ int _miyako_init_rect(MiyakoBitmap *src, MiyakoBitmap *dst, MiyakoSize *size)
199
185
  int dh = dst->rect.h;
200
186
 
201
187
  // ox(oy)が画像のw(h)以上の時は転送不可
202
-
188
+
203
189
  if(src->rect.x >= src->surface->w || src->rect.y >= src->surface->h) return 0;
204
190
  if(dst->rect.x >= dst->surface->w || dst->rect.y >= dst->surface->h) return 0;
205
191
 
206
192
  // ox(oy)がマイナスの時は、ow(oh)を減らしておいて、ox, oyをゼロにしておく
207
193
  // 0以下になったら転送不可
208
-
194
+
209
195
  if(src->rect.x < 0){
210
196
  sw += src->rect.x;
211
197
  src->rect.x = 0;
@@ -229,7 +215,7 @@ int _miyako_init_rect(MiyakoBitmap *src, MiyakoBitmap *dst, MiyakoSize *size)
229
215
 
230
216
  // ox(oy)+ow(oh)が、w(h)を越える場合は、ow(oh)を減らしておく
231
217
  // 0以下になったら転送不可
232
-
218
+
233
219
  if(src->rect.x + sw > src->surface->w)
234
220
  {
235
221
  sw += (src->surface->w - src->rect.x - sw);
@@ -252,13 +238,13 @@ int _miyako_init_rect(MiyakoBitmap *src, MiyakoBitmap *dst, MiyakoSize *size)
252
238
  }
253
239
 
254
240
  // ox(oy)が画像のw(h)以上、-w(-h)以下の時は転送不可
255
-
241
+
256
242
  if(src->x >= dw || src->x <= -dw) return 0;
257
243
  if(src->y >= dh || src->y <= -dh) return 0;
258
244
 
259
245
  // x(y)がマイナスの時は、ow(oh)を減らしておいて、x, yをゼロにしておく
260
246
  // 0以下になったら転送不可
261
-
247
+
262
248
  if(src->x < 0){
263
249
  dw += src->x;
264
250
  src->x = 0;
@@ -274,7 +260,7 @@ int _miyako_init_rect(MiyakoBitmap *src, MiyakoBitmap *dst, MiyakoSize *size)
274
260
 
275
261
  size->w = (dw > sw ? sw : dw);
276
262
  size->h = (dh > sh ? sh : dh);
277
-
263
+
278
264
  return 1;
279
265
  }
280
266