cyross-ruby-miyako 2.0.5.1.0 → 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.
- data/README +1092 -929
- data/Rakefile +7 -7
- data/defines.h +144 -144
- data/extern.h +29 -29
- data/install_miyako.rb +87 -87
- data/lib/Miyako/API/audio.rb +572 -198
- data/lib/Miyako/API/basic_data.rb +825 -573
- data/lib/Miyako/API/bitmap.rb +534 -507
- data/lib/Miyako/API/choices.rb +481 -475
- data/lib/Miyako/API/collision.rb +486 -460
- data/lib/Miyako/API/diagram.rb +586 -561
- data/lib/Miyako/API/drawing.rb +151 -151
- data/lib/Miyako/API/exceptions.rb +105 -0
- data/lib/Miyako/API/fixedmap.rb +462 -428
- data/lib/Miyako/API/font.rb +430 -403
- data/lib/Miyako/API/input.rb +456 -447
- data/lib/Miyako/API/layout.rb +636 -433
- data/lib/Miyako/API/map.rb +583 -529
- data/lib/Miyako/API/map_event.rb +222 -198
- data/lib/Miyako/API/modules.rb +357 -109
- data/lib/Miyako/API/movie.rb +166 -154
- data/lib/Miyako/API/parts.rb +276 -189
- data/lib/Miyako/API/plane.rb +205 -166
- data/lib/Miyako/API/screen.rb +341 -325
- data/lib/Miyako/API/shape.rb +443 -443
- data/lib/Miyako/API/sprite.rb +771 -752
- data/lib/Miyako/API/sprite_animation.rb +490 -481
- data/lib/Miyako/API/sprite_list.rb +1135 -0
- data/lib/Miyako/API/spriteunit.rb +168 -147
- data/lib/Miyako/API/story.rb +350 -300
- data/lib/Miyako/API/textbox.rb +770 -725
- data/lib/Miyako/API/utility.rb +419 -388
- data/lib/Miyako/API/viewport.rb +189 -139
- data/lib/Miyako/API/yuki.rb +1226 -996
- data/lib/Miyako/EXT/miyako_cairo.rb +62 -62
- data/lib/Miyako/EXT/raster_scroll.rb +138 -138
- data/lib/Miyako/EXT/slides.rb +157 -157
- data/lib/Miyako/miyako.rb +201 -171
- data/lib/Miyako/miyako_require_only.rb +35 -0
- data/miyako_basicdata.c +590 -590
- data/miyako_bitmap.c +1225 -1225
- data/miyako_collision.c +403 -403
- data/miyako_drawing.c +187 -187
- data/miyako_font.c +334 -334
- data/miyako_hsv.c +830 -830
- data/miyako_input_audio.c +254 -0
- data/miyako_layout.c +191 -191
- data/miyako_no_katana.c +1078 -1074
- data/miyako_sprite2.c +431 -0
- data/miyako_transform.c +438 -438
- data/miyako_utility.c +288 -288
- data/sample/Animation1/m1ku.rb +68 -68
- data/sample/Animation2/lex.rb +96 -96
- data/sample/Diagram_sample/diagram_sample_yuki2.rb +328 -386
- data/sample/Room3/blue.rb +297 -297
- data/sample/Room3/ending.rb +180 -180
- data/sample/Room3/green.rb +220 -220
- data/sample/Room3/main.rb +119 -119
- data/sample/Room3/main_component.rb +59 -59
- data/sample/Room3/red.rb +227 -227
- data/sample/Room3/room3.rb +25 -27
- data/sample/Room3/title.rb +184 -184
- data/sample/ball_action_sample.rb +204 -204
- data/sample/blit_rop.rb +70 -70
- data/sample/cairo_sample.rb +25 -25
- data/sample/circle_collision_test.rb +66 -66
- data/sample/collision_test.rb +33 -33
- data/sample/collision_test2.rb +108 -108
- data/sample/fixed_map_test/fixed_map_sample.rb +140 -140
- data/sample/fixed_map_test/readme.txt +72 -72
- data/sample/map_test/chara.rb +58 -58
- data/sample/map_test/main_parts.rb +69 -69
- data/sample/map_test/main_scene.rb +153 -153
- data/sample/map_test/map_manager.rb +75 -75
- data/sample/map_test/map_test.rb +23 -23
- data/sample/map_test/oasis.rb +71 -71
- data/sample/map_test/readme.txt +89 -89
- data/sample/map_test/route.rb +157 -157
- data/sample/map_test/town.rb +74 -74
- data/sample/polygon_test.rb +35 -35
- data/sample/rasterscroll.rb +24 -24
- data/sample/takahashi.rb +42 -42
- data/sample/textbox_sample.rb +189 -189
- data/sample/transform.rb +54 -54
- data/sample/utility_test.rb +73 -73
- data/sample/utility_test2.rb +61 -61
- data/sample/utility_test3.rb +64 -64
- data/sample/utility_test4.rb +73 -73
- data/uninstall_miyako.rb +19 -19
- data/win/miyako_no_katana.so +0 -0
- metadata +7 -2
data/miyako_basicdata.c
CHANGED
@@ -1,590 +1,590 @@
|
|
1
|
-
/*
|
2
|
-
--
|
3
|
-
Miyako v2.0 Extend Library "Miyako no Katana"
|
4
|
-
Copyright (C) 2008 Cyross Makoto
|
5
|
-
|
6
|
-
This library is free software; you can redistribute it and/or
|
7
|
-
modify it under the terms of the GNU Lesser General Public
|
8
|
-
License as published by the Free Software Foundation; either
|
9
|
-
version 2.1 of the License, or (at your option) any later version.
|
10
|
-
|
11
|
-
This library is distributed in the hope that it will be useful,
|
12
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
-
Lesser General Public License for more details.
|
15
|
-
|
16
|
-
You should have received a copy of the GNU Lesser General Public
|
17
|
-
License along with this library; if not, write to the Free Software
|
18
|
-
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
-
++
|
20
|
-
*/
|
21
|
-
|
22
|
-
/*
|
23
|
-
=拡張ライブラリmiyako_no_katana
|
24
|
-
Authors:: サイロス誠
|
25
|
-
Version:: 2.0
|
26
|
-
Copyright:: 2007-2008 Cyross Makoto
|
27
|
-
License:: LGPL2.1
|
28
|
-
*/
|
29
|
-
#include "defines.h"
|
30
|
-
|
31
|
-
static VALUE mSDL = Qnil;
|
32
|
-
static VALUE mMiyako = Qnil;
|
33
|
-
static VALUE eMiyakoError = Qnil;
|
34
|
-
static VALUE cWaitCounter = Qnil;
|
35
|
-
static VALUE sSpriteUnit = Qnil;
|
36
|
-
static VALUE sPoint = Qnil;
|
37
|
-
static VALUE sSize = Qnil;
|
38
|
-
static VALUE sRect = Qnil;
|
39
|
-
static VALUE sSquare = Qnil;
|
40
|
-
static VALUE sSegment = Qnil;
|
41
|
-
static VALUE nZero = Qnil;
|
42
|
-
static VALUE nOne = Qnil;
|
43
|
-
static volatile ID id_update = Qnil;
|
44
|
-
static volatile ID id_kakko = Qnil;
|
45
|
-
static volatile ID id_render = Qnil;
|
46
|
-
static volatile ID id_to_a = Qnil;
|
47
|
-
static volatile int zero = Qnil;
|
48
|
-
static volatile int one = Qnil;
|
49
|
-
|
50
|
-
/*
|
51
|
-
:nodoc:
|
52
|
-
*/
|
53
|
-
static void get_min_max(VALUE segment, VALUE *min, VALUE *max)
|
54
|
-
{
|
55
|
-
VALUE *tmp;
|
56
|
-
switch(TYPE(segment))
|
57
|
-
{
|
58
|
-
case T_ARRAY:
|
59
|
-
if(RARRAY_LEN(segment) < 2)
|
60
|
-
rb_raise(eMiyakoError, "pairs have illegal array! (above 2 elements)");
|
61
|
-
tmp = RARRAY_PTR(segment);
|
62
|
-
*min = *tmp++;
|
63
|
-
*max = *tmp;
|
64
|
-
break;
|
65
|
-
case T_STRUCT:
|
66
|
-
if(RSTRUCT_LEN(segment) < 2)
|
67
|
-
rb_raise(eMiyakoError, "pairs have illegal struct! (above 2 attributes)");
|
68
|
-
tmp = RSTRUCT_PTR(segment);
|
69
|
-
*min = *tmp++;
|
70
|
-
*max = *tmp;
|
71
|
-
break;
|
72
|
-
default:
|
73
|
-
*min = rb_funcall(segment, rb_intern("min"), 0);
|
74
|
-
*max = rb_funcall(segment, rb_intern("max"), 0);
|
75
|
-
break;
|
76
|
-
}
|
77
|
-
}
|
78
|
-
|
79
|
-
/*
|
80
|
-
:nodoc:
|
81
|
-
*/
|
82
|
-
static VALUE counter_start(VALUE self)
|
83
|
-
{
|
84
|
-
rb_iv_set(self, "@st", rb_funcall(mSDL, rb_intern("getTicks"), 0));
|
85
|
-
rb_iv_set(self, "@counting", Qtrue);
|
86
|
-
return self;
|
87
|
-
}
|
88
|
-
|
89
|
-
/*
|
90
|
-
:nodoc:
|
91
|
-
*/
|
92
|
-
static VALUE counter_stop(VALUE self)
|
93
|
-
{
|
94
|
-
rb_iv_set(self, "@st", INT2NUM(0));
|
95
|
-
rb_iv_set(self, "@counting", Qfalse);
|
96
|
-
return self;
|
97
|
-
}
|
98
|
-
|
99
|
-
/*
|
100
|
-
:nodoc:
|
101
|
-
*/
|
102
|
-
static VALUE counter_wait_inner(VALUE self, VALUE f)
|
103
|
-
{
|
104
|
-
VALUE counting = rb_iv_set(self, "@counting", Qtrue);
|
105
|
-
if(counting == Qfalse){ return f == Qtrue ? Qfalse : Qtrue; }
|
106
|
-
|
107
|
-
int t = NUM2INT(rb_funcall(mSDL, rb_intern("getTicks"), 0));
|
108
|
-
int st = NUM2INT(rb_iv_get(self, "@st"));
|
109
|
-
int wait = NUM2INT(rb_iv_get(self, "@wait"));
|
110
|
-
if((t - st) < wait){ return f; }
|
111
|
-
|
112
|
-
rb_iv_set(cWaitCounter, "@counting", Qfalse);
|
113
|
-
|
114
|
-
return f == Qtrue ? Qfalse : Qtrue;
|
115
|
-
}
|
116
|
-
|
117
|
-
/*
|
118
|
-
:nodoc:
|
119
|
-
*/
|
120
|
-
static VALUE counter_waiting(VALUE self)
|
121
|
-
{
|
122
|
-
return counter_wait_inner(self, Qtrue);
|
123
|
-
}
|
124
|
-
|
125
|
-
/*
|
126
|
-
:nodoc:
|
127
|
-
*/
|
128
|
-
static VALUE counter_finish(VALUE self)
|
129
|
-
{
|
130
|
-
return counter_wait_inner(self, Qfalse);
|
131
|
-
}
|
132
|
-
|
133
|
-
/*
|
134
|
-
:nodoc:
|
135
|
-
*/
|
136
|
-
static VALUE counter_wait(VALUE self)
|
137
|
-
{
|
138
|
-
int t = NUM2INT(rb_funcall(mSDL, rb_intern("getTicks"), 0));
|
139
|
-
int st = NUM2INT(rb_funcall(mSDL, rb_intern("getTicks"), 0));
|
140
|
-
int wait = NUM2INT(rb_iv_get(self, "@wait"));
|
141
|
-
while((t - st) < wait){
|
142
|
-
t = NUM2INT(rb_funcall(mSDL, rb_intern("getTicks"), 0));
|
143
|
-
}
|
144
|
-
return self;
|
145
|
-
}
|
146
|
-
|
147
|
-
static VALUE su_move(VALUE self, VALUE dx, VALUE dy)
|
148
|
-
{
|
149
|
-
VALUE *st = RSTRUCT_PTR(self);
|
150
|
-
VALUE *px = st+5;
|
151
|
-
VALUE *py = st+6;
|
152
|
-
VALUE tx = *px;
|
153
|
-
VALUE ty = *py;
|
154
|
-
*px = INT2NUM(NUM2INT(tx)+NUM2INT(dx));
|
155
|
-
*py = INT2NUM(NUM2INT(ty)+NUM2INT(dy));
|
156
|
-
if(rb_block_given_p() == Qtrue){
|
157
|
-
VALUE ret = rb_yield(self);
|
158
|
-
if(ret == Qfalse || ret == Qnil)
|
159
|
-
{
|
160
|
-
*px = tx;
|
161
|
-
*py = ty;
|
162
|
-
}
|
163
|
-
}
|
164
|
-
return self;
|
165
|
-
}
|
166
|
-
|
167
|
-
static VALUE su_move_to(VALUE self, VALUE x, VALUE y)
|
168
|
-
{
|
169
|
-
VALUE *st = RSTRUCT_PTR(self);
|
170
|
-
VALUE *px = st+5;
|
171
|
-
VALUE *py = st+6;
|
172
|
-
VALUE tx = *px;
|
173
|
-
VALUE ty = *py;
|
174
|
-
*px = x;
|
175
|
-
*py = y;
|
176
|
-
if(rb_block_given_p() == Qtrue){
|
177
|
-
VALUE ret = rb_yield(self);
|
178
|
-
if(ret == Qfalse || ret == Qnil)
|
179
|
-
{
|
180
|
-
*px = tx;
|
181
|
-
*py = ty;
|
182
|
-
}
|
183
|
-
}
|
184
|
-
return self;
|
185
|
-
}
|
186
|
-
|
187
|
-
static VALUE point_move(VALUE self, VALUE dx, VALUE dy)
|
188
|
-
{
|
189
|
-
VALUE *st = RSTRUCT_PTR(self);
|
190
|
-
VALUE *px = st+0;
|
191
|
-
VALUE *py = st+1;
|
192
|
-
VALUE tx = *px;
|
193
|
-
VALUE ty = *py;
|
194
|
-
*px = INT2NUM(NUM2INT(tx)+NUM2INT(dx));
|
195
|
-
*py = INT2NUM(NUM2INT(ty)+NUM2INT(dy));
|
196
|
-
if(rb_block_given_p() == Qtrue){
|
197
|
-
VALUE ret = rb_yield(self);
|
198
|
-
if(ret == Qfalse || ret == Qnil)
|
199
|
-
{
|
200
|
-
*px = tx;
|
201
|
-
*py = ty;
|
202
|
-
}
|
203
|
-
}
|
204
|
-
return self;
|
205
|
-
}
|
206
|
-
|
207
|
-
static VALUE point_move_to(VALUE self, VALUE x, VALUE y)
|
208
|
-
{
|
209
|
-
VALUE *st = RSTRUCT_PTR(self);
|
210
|
-
VALUE *px = st+0;
|
211
|
-
VALUE *py = st+1;
|
212
|
-
VALUE tx = *px;
|
213
|
-
VALUE ty = *py;
|
214
|
-
*px = x;
|
215
|
-
*py = y;
|
216
|
-
if(rb_block_given_p() == Qtrue){
|
217
|
-
VALUE ret = rb_yield(self);
|
218
|
-
if(ret == Qfalse || ret == Qnil)
|
219
|
-
{
|
220
|
-
*px = tx;
|
221
|
-
*py = ty;
|
222
|
-
}
|
223
|
-
}
|
224
|
-
return self;
|
225
|
-
}
|
226
|
-
|
227
|
-
static VALUE size_resize(VALUE self, VALUE dw, VALUE dh)
|
228
|
-
{
|
229
|
-
VALUE *st = RSTRUCT_PTR(self);
|
230
|
-
VALUE *pw = st+0;
|
231
|
-
VALUE *ph = st+1;
|
232
|
-
VALUE tw = *pw;
|
233
|
-
VALUE th = *ph;
|
234
|
-
*pw = INT2NUM(NUM2INT(tw)+NUM2INT(dw));
|
235
|
-
*ph = INT2NUM(NUM2INT(th)+NUM2INT(dh));
|
236
|
-
if(rb_block_given_p() == Qtrue){
|
237
|
-
VALUE ret = rb_yield(self);
|
238
|
-
if(ret == Qfalse || ret == Qnil)
|
239
|
-
{
|
240
|
-
*pw = tw;
|
241
|
-
*ph = th;
|
242
|
-
}
|
243
|
-
}
|
244
|
-
return self;
|
245
|
-
}
|
246
|
-
|
247
|
-
static VALUE size_resize_to(VALUE self, VALUE w, VALUE h)
|
248
|
-
{
|
249
|
-
VALUE *st = RSTRUCT_PTR(self);
|
250
|
-
VALUE *pw = st+0;
|
251
|
-
VALUE *ph = st+1;
|
252
|
-
VALUE tw = *pw;
|
253
|
-
VALUE th = *ph;
|
254
|
-
*pw = w;
|
255
|
-
*ph = h;
|
256
|
-
if(rb_block_given_p() == Qtrue){
|
257
|
-
VALUE ret = rb_yield(self);
|
258
|
-
if(ret == Qfalse || ret == Qnil)
|
259
|
-
{
|
260
|
-
*pw = tw;
|
261
|
-
*ph = th;
|
262
|
-
}
|
263
|
-
}
|
264
|
-
return self;
|
265
|
-
}
|
266
|
-
|
267
|
-
static VALUE rect_resize(VALUE self, VALUE dw, VALUE dh)
|
268
|
-
{
|
269
|
-
VALUE *st = RSTRUCT_PTR(self);
|
270
|
-
VALUE *pw = st+2;
|
271
|
-
VALUE *ph = st+3;
|
272
|
-
VALUE tw = *pw;
|
273
|
-
VALUE th = *ph;
|
274
|
-
*pw = INT2NUM(NUM2INT(*pw) + NUM2INT(dw));
|
275
|
-
*ph = INT2NUM(NUM2INT(*pw) + NUM2INT(dh));
|
276
|
-
if(rb_block_given_p() == Qtrue){
|
277
|
-
VALUE ret = rb_yield(self);
|
278
|
-
if(ret == Qfalse || ret == Qnil)
|
279
|
-
{
|
280
|
-
*pw = tw;
|
281
|
-
*ph = th;
|
282
|
-
}
|
283
|
-
}
|
284
|
-
return self;
|
285
|
-
}
|
286
|
-
|
287
|
-
static VALUE rect_resize_to(VALUE self, VALUE w, VALUE h)
|
288
|
-
{
|
289
|
-
VALUE *st = RSTRUCT_PTR(self);
|
290
|
-
VALUE *pw = st+2;
|
291
|
-
VALUE *ph = st+3;
|
292
|
-
VALUE tw = *pw;
|
293
|
-
VALUE th = *ph;
|
294
|
-
*pw = w;
|
295
|
-
*ph = h;
|
296
|
-
if(rb_block_given_p() == Qtrue){
|
297
|
-
VALUE ret = rb_yield(self);
|
298
|
-
if(ret == Qfalse || ret == Qnil)
|
299
|
-
{
|
300
|
-
*pw = tw;
|
301
|
-
*ph = th;
|
302
|
-
}
|
303
|
-
}
|
304
|
-
return self;
|
305
|
-
}
|
306
|
-
|
307
|
-
static VALUE rect_in_range(VALUE self, VALUE vx, VALUE vy)
|
308
|
-
{
|
309
|
-
VALUE *st = RSTRUCT_PTR(self);
|
310
|
-
int l = NUM2INT(*(st+0));
|
311
|
-
int t = NUM2INT(*(st+1));
|
312
|
-
int w = NUM2INT(*(st+2));
|
313
|
-
int h = NUM2INT(*(st+3));
|
314
|
-
int x = NUM2INT(vx);
|
315
|
-
int y = NUM2INT(vy);
|
316
|
-
|
317
|
-
if(x >= l && y >= t && x < (l+w) && y < (t+h)){ return Qtrue; }
|
318
|
-
return Qfalse;
|
319
|
-
}
|
320
|
-
|
321
|
-
static VALUE square_move(VALUE self, VALUE dx, VALUE dy)
|
322
|
-
{
|
323
|
-
VALUE *st = RSTRUCT_PTR(self);
|
324
|
-
VALUE *pl = st+0;
|
325
|
-
VALUE *pt = st+1;
|
326
|
-
VALUE *pr = st+2;
|
327
|
-
VALUE *pb = st+3;
|
328
|
-
VALUE tl = *pl;
|
329
|
-
VALUE tt = *pt;
|
330
|
-
VALUE tr = *pr;
|
331
|
-
VALUE tb = *pb;
|
332
|
-
*pl = INT2NUM(NUM2INT(tl)+NUM2INT(dx));
|
333
|
-
*pt = INT2NUM(NUM2INT(tt)+NUM2INT(dy));
|
334
|
-
*pr = INT2NUM(NUM2INT(tr)+NUM2INT(dx));
|
335
|
-
*pb = INT2NUM(NUM2INT(tb)+NUM2INT(dy));
|
336
|
-
if(rb_block_given_p() == Qtrue){
|
337
|
-
VALUE ret = rb_yield(self);
|
338
|
-
if(ret == Qfalse || ret == Qnil)
|
339
|
-
{
|
340
|
-
*pl = tl;
|
341
|
-
*pt = tt;
|
342
|
-
*pr = tr;
|
343
|
-
*pb = tb;
|
344
|
-
}
|
345
|
-
}
|
346
|
-
return self;
|
347
|
-
}
|
348
|
-
|
349
|
-
static VALUE square_move_to(VALUE self, VALUE x, VALUE y)
|
350
|
-
{
|
351
|
-
VALUE *st = RSTRUCT_PTR(self);
|
352
|
-
VALUE *pl = st+0;
|
353
|
-
VALUE *pt = st+1;
|
354
|
-
VALUE *pr = st+2;
|
355
|
-
VALUE *pb = st+3;
|
356
|
-
VALUE tl = *pl;
|
357
|
-
VALUE tt = *pt;
|
358
|
-
VALUE tr = *pr;
|
359
|
-
VALUE tb = *pb;
|
360
|
-
int w = NUM2INT(tr)-NUM2INT(tl);
|
361
|
-
int h = NUM2INT(tb)-NUM2INT(tt);
|
362
|
-
*pl = x;
|
363
|
-
*pt = y;
|
364
|
-
*pr = INT2NUM(NUM2INT(x)+w);
|
365
|
-
*pb = INT2NUM(NUM2INT(y)+h);
|
366
|
-
if(rb_block_given_p() == Qtrue){
|
367
|
-
VALUE ret = rb_yield(self);
|
368
|
-
if(ret == Qfalse || ret == Qnil)
|
369
|
-
{
|
370
|
-
*pl = tl;
|
371
|
-
*pt = tt;
|
372
|
-
*pr = tr;
|
373
|
-
*pb = tb;
|
374
|
-
}
|
375
|
-
}
|
376
|
-
return self;
|
377
|
-
}
|
378
|
-
|
379
|
-
static VALUE square_resize(VALUE self, VALUE dw, VALUE dh)
|
380
|
-
{
|
381
|
-
VALUE *st = RSTRUCT_PTR(self);
|
382
|
-
VALUE *pr = st+2;
|
383
|
-
VALUE *pb = st+3;
|
384
|
-
VALUE tr = *pr;
|
385
|
-
VALUE tb = *pb;
|
386
|
-
*pr = INT2NUM(NUM2INT(*pr) + NUM2INT(dw));
|
387
|
-
*pb = INT2NUM(NUM2INT(*pb) + NUM2INT(dh));
|
388
|
-
if(rb_block_given_p() == Qtrue){
|
389
|
-
VALUE ret = rb_yield(self);
|
390
|
-
if(ret == Qfalse || ret == Qnil)
|
391
|
-
{
|
392
|
-
*pr = tr;
|
393
|
-
*pb = tb;
|
394
|
-
}
|
395
|
-
}
|
396
|
-
return self;
|
397
|
-
}
|
398
|
-
|
399
|
-
static VALUE square_resize_to(VALUE self, VALUE w, VALUE h)
|
400
|
-
{
|
401
|
-
VALUE *st = RSTRUCT_PTR(self);
|
402
|
-
VALUE *pl = st+0;
|
403
|
-
VALUE *pt = st+1;
|
404
|
-
VALUE *pr = st+2;
|
405
|
-
VALUE *pb = st+3;
|
406
|
-
VALUE tr = *pr;
|
407
|
-
VALUE tb = *pb;
|
408
|
-
*pr = INT2NUM(NUM2INT(*pl) + NUM2INT(w) - 1);
|
409
|
-
*pb = INT2NUM(NUM2INT(*pt) + NUM2INT(h) - 1);
|
410
|
-
if(rb_block_given_p() == Qtrue){
|
411
|
-
VALUE ret = rb_yield(self);
|
412
|
-
if(ret == Qfalse || ret == Qnil)
|
413
|
-
{
|
414
|
-
*pr = tr;
|
415
|
-
*pb = tb;
|
416
|
-
}
|
417
|
-
}
|
418
|
-
return self;
|
419
|
-
}
|
420
|
-
|
421
|
-
static VALUE square_in_range(VALUE self, VALUE vx, VALUE vy)
|
422
|
-
{
|
423
|
-
VALUE *st = RSTRUCT_PTR(self);
|
424
|
-
int l = NUM2INT(*(st+0));
|
425
|
-
int t = NUM2INT(*(st+1));
|
426
|
-
int r = NUM2INT(*(st+2));
|
427
|
-
int b = NUM2INT(*(st+3));
|
428
|
-
int x = NUM2INT(vx);
|
429
|
-
int y = NUM2INT(vy);
|
430
|
-
|
431
|
-
if(x >= l && y >= t && x <= r && y <= b){ return Qtrue; }
|
432
|
-
return Qfalse;
|
433
|
-
}
|
434
|
-
|
435
|
-
static VALUE segment_move(VALUE self, VALUE dx, VALUE dy)
|
436
|
-
{
|
437
|
-
VALUE min_x, max_x, min_y, max_y;
|
438
|
-
VALUE *st = RSTRUCT_PTR(self);
|
439
|
-
|
440
|
-
get_min_max(*(st+0), &min_x, &max_x);
|
441
|
-
get_min_max(*(st+1), &min_y, &max_y);
|
442
|
-
|
443
|
-
rb_funcall(self, rb_intern("reset"), 4, INT2NUM(NUM2INT(min_x)+NUM2INT(dx)),
|
444
|
-
INT2NUM(NUM2INT(min_y)+NUM2INT(dy)),
|
445
|
-
INT2NUM(NUM2INT(max_x)+NUM2INT(dx)),
|
446
|
-
INT2NUM(NUM2INT(max_y)+NUM2INT(dy)));
|
447
|
-
|
448
|
-
if(rb_block_given_p() == Qtrue){
|
449
|
-
VALUE ret = rb_yield(self);
|
450
|
-
if(ret == Qfalse || ret == Qnil)
|
451
|
-
rb_funcall(self, rb_intern("reset"), 4, min_x, max_x, min_y, max_y);
|
452
|
-
}
|
453
|
-
|
454
|
-
return self;
|
455
|
-
}
|
456
|
-
|
457
|
-
static VALUE segment_move_to(VALUE self, VALUE x, VALUE y)
|
458
|
-
{
|
459
|
-
VALUE min_x, max_x, min_y, max_y;
|
460
|
-
VALUE *st = RSTRUCT_PTR(self);
|
461
|
-
|
462
|
-
get_min_max(*(st+0), &min_x, &max_x);
|
463
|
-
get_min_max(*(st+1), &min_y, &max_y);
|
464
|
-
|
465
|
-
int w = NUM2INT(max_x)-NUM2INT(min_x);
|
466
|
-
int h = NUM2INT(max_y)-NUM2INT(min_y);
|
467
|
-
|
468
|
-
rb_funcall(self, rb_intern("reset"), 4, x, y, INT2NUM(NUM2INT(x)+w), INT2NUM(NUM2INT(y)+h));
|
469
|
-
|
470
|
-
if(rb_block_given_p() == Qtrue){
|
471
|
-
VALUE ret = rb_yield(self);
|
472
|
-
if(ret == Qfalse || ret == Qnil)
|
473
|
-
rb_funcall(self, rb_intern("reset"), 4, min_x, max_x, min_y, max_y);
|
474
|
-
}
|
475
|
-
|
476
|
-
return self;
|
477
|
-
}
|
478
|
-
|
479
|
-
static VALUE segment_resize(VALUE self, VALUE dw, VALUE dh)
|
480
|
-
{
|
481
|
-
VALUE min_x, max_x, min_y, max_y;
|
482
|
-
VALUE *st = RSTRUCT_PTR(self);
|
483
|
-
|
484
|
-
get_min_max(*(st+0), &min_x, &max_x);
|
485
|
-
get_min_max(*(st+1), &min_y, &max_y);
|
486
|
-
|
487
|
-
int w = NUM2INT(max_x) + NUM2INT(dw);
|
488
|
-
int h = NUM2INT(max_y) + NUM2INT(dh);
|
489
|
-
|
490
|
-
if(w <= 0)
|
491
|
-
rb_raise(eMiyakoError, "illegal width(result is 0 or minus)");
|
492
|
-
if(h <= 0)
|
493
|
-
rb_raise(eMiyakoError, "illegal height(result is 0 or minus)");
|
494
|
-
|
495
|
-
rb_funcall(self, rb_intern("reset"), 4, INT2NUM(NUM2INT(min_x)),
|
496
|
-
INT2NUM(NUM2INT(min_y)),
|
497
|
-
INT2NUM(w),
|
498
|
-
INT2NUM(h));
|
499
|
-
|
500
|
-
if(rb_block_given_p() == Qtrue){
|
501
|
-
VALUE ret = rb_yield(self);
|
502
|
-
if(ret == Qfalse || ret == Qnil)
|
503
|
-
rb_funcall(self, rb_intern("reset"), 4, min_x, max_x, min_y, max_y);
|
504
|
-
}
|
505
|
-
|
506
|
-
return self;
|
507
|
-
}
|
508
|
-
|
509
|
-
static VALUE segment_resize_to(VALUE self, VALUE w, VALUE h)
|
510
|
-
{
|
511
|
-
VALUE min_x, max_x, min_y, max_y;
|
512
|
-
VALUE *st = RSTRUCT_PTR(self);
|
513
|
-
|
514
|
-
get_min_max(*(st+0), &min_x, &max_x);
|
515
|
-
get_min_max(*(st+1), &min_y, &max_y);
|
516
|
-
|
517
|
-
int nw = NUM2INT(w);
|
518
|
-
int nh = NUM2INT(h);
|
519
|
-
|
520
|
-
if(nw <= 0)
|
521
|
-
rb_raise(eMiyakoError, "illegal width(result is 0 or minus)");
|
522
|
-
if(nh <= 0)
|
523
|
-
rb_raise(eMiyakoError, "illegal height(result is 0 or minus)");
|
524
|
-
|
525
|
-
rb_funcall(self, rb_intern("reset"), 4, INT2NUM(NUM2INT(min_x)),
|
526
|
-
INT2NUM(NUM2INT(min_y)),
|
527
|
-
INT2NUM(NUM2INT(min_x)+nw-1),
|
528
|
-
INT2NUM(NUM2INT(min_y)+nh-1));
|
529
|
-
|
530
|
-
if(rb_block_given_p() == Qtrue){
|
531
|
-
VALUE ret = rb_yield(self);
|
532
|
-
if(ret == Qfalse || ret == Qnil)
|
533
|
-
rb_funcall(self, rb_intern("reset"), 4, min_x, max_x, min_y, max_y);
|
534
|
-
}
|
535
|
-
|
536
|
-
return self;
|
537
|
-
}
|
538
|
-
|
539
|
-
void Init_miyako_basicdata()
|
540
|
-
{
|
541
|
-
mSDL = rb_define_module("SDL");
|
542
|
-
mMiyako = rb_define_module("Miyako");
|
543
|
-
eMiyakoError = rb_define_class_under(mMiyako, "MiyakoError", rb_eException);
|
544
|
-
cWaitCounter = rb_define_class_under(mMiyako, "WaitCounter", rb_cObject);
|
545
|
-
sSpriteUnit = rb_define_class_under(mMiyako, "SpriteUnitBase", rb_cStruct);
|
546
|
-
sPoint = rb_define_class_under(mMiyako, "PointStruct", rb_cStruct);
|
547
|
-
sSize = rb_define_class_under(mMiyako, "SizeStruct", rb_cStruct);
|
548
|
-
sRect = rb_define_class_under(mMiyako, "RectStruct", rb_cStruct);
|
549
|
-
sSquare = rb_define_class_under(mMiyako, "SquareStruct", rb_cStruct);
|
550
|
-
sSegment = rb_define_class_under(mMiyako, "SegmentStruct", rb_cStruct);
|
551
|
-
|
552
|
-
id_update = rb_intern("update");
|
553
|
-
id_kakko = rb_intern("[]");
|
554
|
-
id_render = rb_intern("render");
|
555
|
-
id_to_a = rb_intern("to_a");
|
556
|
-
|
557
|
-
zero = 0;
|
558
|
-
nZero = INT2NUM(zero);
|
559
|
-
one = 1;
|
560
|
-
nOne = INT2NUM(one);
|
561
|
-
|
562
|
-
rb_define_method(cWaitCounter, "start", counter_start, 0);
|
563
|
-
rb_define_method(cWaitCounter, "stop", counter_stop, 0);
|
564
|
-
rb_define_method(cWaitCounter, "wait_inner", counter_wait_inner, 1);
|
565
|
-
rb_define_method(cWaitCounter, "waiting?", counter_waiting, 0);
|
566
|
-
rb_define_method(cWaitCounter, "finish?", counter_finish, 0);
|
567
|
-
rb_define_method(cWaitCounter, "wait", counter_wait, 0);
|
568
|
-
|
569
|
-
rb_define_method(sSpriteUnit, "move", su_move, 2);
|
570
|
-
rb_define_method(sSpriteUnit, "move_to", su_move_to, 2);
|
571
|
-
|
572
|
-
rb_define_method(sPoint, "move", point_move, 2);
|
573
|
-
rb_define_method(sPoint, "move_to", point_move_to, 2);
|
574
|
-
rb_define_method(sSize, "resize", size_resize, 2);
|
575
|
-
rb_define_method(sSize, "resize_to", size_resize_to, 2);
|
576
|
-
rb_define_method(sRect, "move", point_move, 2);
|
577
|
-
rb_define_method(sRect, "move_to", point_move_to, 2);
|
578
|
-
rb_define_method(sRect, "resize", rect_resize, 2);
|
579
|
-
rb_define_method(sRect, "resize_to", rect_resize_to, 2);
|
580
|
-
rb_define_method(sRect, "in_range?", rect_in_range, 2);
|
581
|
-
rb_define_method(sSquare, "move", square_move, 2);
|
582
|
-
rb_define_method(sSquare, "move_to", square_move_to, 2);
|
583
|
-
rb_define_method(sSquare, "resize", square_resize, 2);
|
584
|
-
rb_define_method(sSquare, "resize_to", square_resize_to, 2);
|
585
|
-
rb_define_method(sSquare, "in_range?", square_in_range, 2);
|
586
|
-
rb_define_method(sSegment, "move", segment_move, 2);
|
587
|
-
rb_define_method(sSegment, "move_to", segment_move_to, 2);
|
588
|
-
rb_define_method(sSegment, "resize", segment_resize, 2);
|
589
|
-
rb_define_method(sSegment, "resize_to", segment_resize_to, 2);
|
590
|
-
}
|
1
|
+
/*
|
2
|
+
--
|
3
|
+
Miyako v2.0 Extend Library "Miyako no Katana"
|
4
|
+
Copyright (C) 2008 Cyross Makoto
|
5
|
+
|
6
|
+
This library is free software; you can redistribute it and/or
|
7
|
+
modify it under the terms of the GNU Lesser General Public
|
8
|
+
License as published by the Free Software Foundation; either
|
9
|
+
version 2.1 of the License, or (at your option) any later version.
|
10
|
+
|
11
|
+
This library is distributed in the hope that it will be useful,
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
Lesser General Public License for more details.
|
15
|
+
|
16
|
+
You should have received a copy of the GNU Lesser General Public
|
17
|
+
License along with this library; if not, write to the Free Software
|
18
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
++
|
20
|
+
*/
|
21
|
+
|
22
|
+
/*
|
23
|
+
=拡張ライブラリmiyako_no_katana
|
24
|
+
Authors:: サイロス誠
|
25
|
+
Version:: 2.0
|
26
|
+
Copyright:: 2007-2008 Cyross Makoto
|
27
|
+
License:: LGPL2.1
|
28
|
+
*/
|
29
|
+
#include "defines.h"
|
30
|
+
|
31
|
+
static VALUE mSDL = Qnil;
|
32
|
+
static VALUE mMiyako = Qnil;
|
33
|
+
static VALUE eMiyakoError = Qnil;
|
34
|
+
static VALUE cWaitCounter = Qnil;
|
35
|
+
static VALUE sSpriteUnit = Qnil;
|
36
|
+
static VALUE sPoint = Qnil;
|
37
|
+
static VALUE sSize = Qnil;
|
38
|
+
static VALUE sRect = Qnil;
|
39
|
+
static VALUE sSquare = Qnil;
|
40
|
+
static VALUE sSegment = Qnil;
|
41
|
+
static VALUE nZero = Qnil;
|
42
|
+
static VALUE nOne = Qnil;
|
43
|
+
static volatile ID id_update = Qnil;
|
44
|
+
static volatile ID id_kakko = Qnil;
|
45
|
+
static volatile ID id_render = Qnil;
|
46
|
+
static volatile ID id_to_a = Qnil;
|
47
|
+
static volatile int zero = Qnil;
|
48
|
+
static volatile int one = Qnil;
|
49
|
+
|
50
|
+
/*
|
51
|
+
:nodoc:
|
52
|
+
*/
|
53
|
+
static void get_min_max(VALUE segment, VALUE *min, VALUE *max)
|
54
|
+
{
|
55
|
+
VALUE *tmp;
|
56
|
+
switch(TYPE(segment))
|
57
|
+
{
|
58
|
+
case T_ARRAY:
|
59
|
+
if(RARRAY_LEN(segment) < 2)
|
60
|
+
rb_raise(eMiyakoError, "pairs have illegal array! (above 2 elements)");
|
61
|
+
tmp = RARRAY_PTR(segment);
|
62
|
+
*min = *tmp++;
|
63
|
+
*max = *tmp;
|
64
|
+
break;
|
65
|
+
case T_STRUCT:
|
66
|
+
if(RSTRUCT_LEN(segment) < 2)
|
67
|
+
rb_raise(eMiyakoError, "pairs have illegal struct! (above 2 attributes)");
|
68
|
+
tmp = RSTRUCT_PTR(segment);
|
69
|
+
*min = *tmp++;
|
70
|
+
*max = *tmp;
|
71
|
+
break;
|
72
|
+
default:
|
73
|
+
*min = rb_funcall(segment, rb_intern("min"), 0);
|
74
|
+
*max = rb_funcall(segment, rb_intern("max"), 0);
|
75
|
+
break;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
/*
|
80
|
+
:nodoc:
|
81
|
+
*/
|
82
|
+
static VALUE counter_start(VALUE self)
|
83
|
+
{
|
84
|
+
rb_iv_set(self, "@st", rb_funcall(mSDL, rb_intern("getTicks"), 0));
|
85
|
+
rb_iv_set(self, "@counting", Qtrue);
|
86
|
+
return self;
|
87
|
+
}
|
88
|
+
|
89
|
+
/*
|
90
|
+
:nodoc:
|
91
|
+
*/
|
92
|
+
static VALUE counter_stop(VALUE self)
|
93
|
+
{
|
94
|
+
rb_iv_set(self, "@st", INT2NUM(0));
|
95
|
+
rb_iv_set(self, "@counting", Qfalse);
|
96
|
+
return self;
|
97
|
+
}
|
98
|
+
|
99
|
+
/*
|
100
|
+
:nodoc:
|
101
|
+
*/
|
102
|
+
static VALUE counter_wait_inner(VALUE self, VALUE f)
|
103
|
+
{
|
104
|
+
VALUE counting = rb_iv_set(self, "@counting", Qtrue);
|
105
|
+
if(counting == Qfalse){ return f == Qtrue ? Qfalse : Qtrue; }
|
106
|
+
|
107
|
+
int t = NUM2INT(rb_funcall(mSDL, rb_intern("getTicks"), 0));
|
108
|
+
int st = NUM2INT(rb_iv_get(self, "@st"));
|
109
|
+
int wait = NUM2INT(rb_iv_get(self, "@wait"));
|
110
|
+
if((t - st) < wait){ return f; }
|
111
|
+
|
112
|
+
rb_iv_set(cWaitCounter, "@counting", Qfalse);
|
113
|
+
|
114
|
+
return f == Qtrue ? Qfalse : Qtrue;
|
115
|
+
}
|
116
|
+
|
117
|
+
/*
|
118
|
+
:nodoc:
|
119
|
+
*/
|
120
|
+
static VALUE counter_waiting(VALUE self)
|
121
|
+
{
|
122
|
+
return counter_wait_inner(self, Qtrue);
|
123
|
+
}
|
124
|
+
|
125
|
+
/*
|
126
|
+
:nodoc:
|
127
|
+
*/
|
128
|
+
static VALUE counter_finish(VALUE self)
|
129
|
+
{
|
130
|
+
return counter_wait_inner(self, Qfalse);
|
131
|
+
}
|
132
|
+
|
133
|
+
/*
|
134
|
+
:nodoc:
|
135
|
+
*/
|
136
|
+
static VALUE counter_wait(VALUE self)
|
137
|
+
{
|
138
|
+
int t = NUM2INT(rb_funcall(mSDL, rb_intern("getTicks"), 0));
|
139
|
+
int st = NUM2INT(rb_funcall(mSDL, rb_intern("getTicks"), 0));
|
140
|
+
int wait = NUM2INT(rb_iv_get(self, "@wait"));
|
141
|
+
while((t - st) < wait){
|
142
|
+
t = NUM2INT(rb_funcall(mSDL, rb_intern("getTicks"), 0));
|
143
|
+
}
|
144
|
+
return self;
|
145
|
+
}
|
146
|
+
|
147
|
+
static VALUE su_move(VALUE self, VALUE dx, VALUE dy)
|
148
|
+
{
|
149
|
+
VALUE *st = RSTRUCT_PTR(self);
|
150
|
+
VALUE *px = st+5;
|
151
|
+
VALUE *py = st+6;
|
152
|
+
VALUE tx = *px;
|
153
|
+
VALUE ty = *py;
|
154
|
+
*px = INT2NUM(NUM2INT(tx)+NUM2INT(dx));
|
155
|
+
*py = INT2NUM(NUM2INT(ty)+NUM2INT(dy));
|
156
|
+
if(rb_block_given_p() == Qtrue){
|
157
|
+
VALUE ret = rb_yield(self);
|
158
|
+
if(ret == Qfalse || ret == Qnil)
|
159
|
+
{
|
160
|
+
*px = tx;
|
161
|
+
*py = ty;
|
162
|
+
}
|
163
|
+
}
|
164
|
+
return self;
|
165
|
+
}
|
166
|
+
|
167
|
+
static VALUE su_move_to(VALUE self, VALUE x, VALUE y)
|
168
|
+
{
|
169
|
+
VALUE *st = RSTRUCT_PTR(self);
|
170
|
+
VALUE *px = st+5;
|
171
|
+
VALUE *py = st+6;
|
172
|
+
VALUE tx = *px;
|
173
|
+
VALUE ty = *py;
|
174
|
+
*px = x;
|
175
|
+
*py = y;
|
176
|
+
if(rb_block_given_p() == Qtrue){
|
177
|
+
VALUE ret = rb_yield(self);
|
178
|
+
if(ret == Qfalse || ret == Qnil)
|
179
|
+
{
|
180
|
+
*px = tx;
|
181
|
+
*py = ty;
|
182
|
+
}
|
183
|
+
}
|
184
|
+
return self;
|
185
|
+
}
|
186
|
+
|
187
|
+
static VALUE point_move(VALUE self, VALUE dx, VALUE dy)
|
188
|
+
{
|
189
|
+
VALUE *st = RSTRUCT_PTR(self);
|
190
|
+
VALUE *px = st+0;
|
191
|
+
VALUE *py = st+1;
|
192
|
+
VALUE tx = *px;
|
193
|
+
VALUE ty = *py;
|
194
|
+
*px = INT2NUM(NUM2INT(tx)+NUM2INT(dx));
|
195
|
+
*py = INT2NUM(NUM2INT(ty)+NUM2INT(dy));
|
196
|
+
if(rb_block_given_p() == Qtrue){
|
197
|
+
VALUE ret = rb_yield(self);
|
198
|
+
if(ret == Qfalse || ret == Qnil)
|
199
|
+
{
|
200
|
+
*px = tx;
|
201
|
+
*py = ty;
|
202
|
+
}
|
203
|
+
}
|
204
|
+
return self;
|
205
|
+
}
|
206
|
+
|
207
|
+
static VALUE point_move_to(VALUE self, VALUE x, VALUE y)
|
208
|
+
{
|
209
|
+
VALUE *st = RSTRUCT_PTR(self);
|
210
|
+
VALUE *px = st+0;
|
211
|
+
VALUE *py = st+1;
|
212
|
+
VALUE tx = *px;
|
213
|
+
VALUE ty = *py;
|
214
|
+
*px = x;
|
215
|
+
*py = y;
|
216
|
+
if(rb_block_given_p() == Qtrue){
|
217
|
+
VALUE ret = rb_yield(self);
|
218
|
+
if(ret == Qfalse || ret == Qnil)
|
219
|
+
{
|
220
|
+
*px = tx;
|
221
|
+
*py = ty;
|
222
|
+
}
|
223
|
+
}
|
224
|
+
return self;
|
225
|
+
}
|
226
|
+
|
227
|
+
static VALUE size_resize(VALUE self, VALUE dw, VALUE dh)
|
228
|
+
{
|
229
|
+
VALUE *st = RSTRUCT_PTR(self);
|
230
|
+
VALUE *pw = st+0;
|
231
|
+
VALUE *ph = st+1;
|
232
|
+
VALUE tw = *pw;
|
233
|
+
VALUE th = *ph;
|
234
|
+
*pw = INT2NUM(NUM2INT(tw)+NUM2INT(dw));
|
235
|
+
*ph = INT2NUM(NUM2INT(th)+NUM2INT(dh));
|
236
|
+
if(rb_block_given_p() == Qtrue){
|
237
|
+
VALUE ret = rb_yield(self);
|
238
|
+
if(ret == Qfalse || ret == Qnil)
|
239
|
+
{
|
240
|
+
*pw = tw;
|
241
|
+
*ph = th;
|
242
|
+
}
|
243
|
+
}
|
244
|
+
return self;
|
245
|
+
}
|
246
|
+
|
247
|
+
static VALUE size_resize_to(VALUE self, VALUE w, VALUE h)
|
248
|
+
{
|
249
|
+
VALUE *st = RSTRUCT_PTR(self);
|
250
|
+
VALUE *pw = st+0;
|
251
|
+
VALUE *ph = st+1;
|
252
|
+
VALUE tw = *pw;
|
253
|
+
VALUE th = *ph;
|
254
|
+
*pw = w;
|
255
|
+
*ph = h;
|
256
|
+
if(rb_block_given_p() == Qtrue){
|
257
|
+
VALUE ret = rb_yield(self);
|
258
|
+
if(ret == Qfalse || ret == Qnil)
|
259
|
+
{
|
260
|
+
*pw = tw;
|
261
|
+
*ph = th;
|
262
|
+
}
|
263
|
+
}
|
264
|
+
return self;
|
265
|
+
}
|
266
|
+
|
267
|
+
static VALUE rect_resize(VALUE self, VALUE dw, VALUE dh)
|
268
|
+
{
|
269
|
+
VALUE *st = RSTRUCT_PTR(self);
|
270
|
+
VALUE *pw = st+2;
|
271
|
+
VALUE *ph = st+3;
|
272
|
+
VALUE tw = *pw;
|
273
|
+
VALUE th = *ph;
|
274
|
+
*pw = INT2NUM(NUM2INT(*pw) + NUM2INT(dw));
|
275
|
+
*ph = INT2NUM(NUM2INT(*pw) + NUM2INT(dh));
|
276
|
+
if(rb_block_given_p() == Qtrue){
|
277
|
+
VALUE ret = rb_yield(self);
|
278
|
+
if(ret == Qfalse || ret == Qnil)
|
279
|
+
{
|
280
|
+
*pw = tw;
|
281
|
+
*ph = th;
|
282
|
+
}
|
283
|
+
}
|
284
|
+
return self;
|
285
|
+
}
|
286
|
+
|
287
|
+
static VALUE rect_resize_to(VALUE self, VALUE w, VALUE h)
|
288
|
+
{
|
289
|
+
VALUE *st = RSTRUCT_PTR(self);
|
290
|
+
VALUE *pw = st+2;
|
291
|
+
VALUE *ph = st+3;
|
292
|
+
VALUE tw = *pw;
|
293
|
+
VALUE th = *ph;
|
294
|
+
*pw = w;
|
295
|
+
*ph = h;
|
296
|
+
if(rb_block_given_p() == Qtrue){
|
297
|
+
VALUE ret = rb_yield(self);
|
298
|
+
if(ret == Qfalse || ret == Qnil)
|
299
|
+
{
|
300
|
+
*pw = tw;
|
301
|
+
*ph = th;
|
302
|
+
}
|
303
|
+
}
|
304
|
+
return self;
|
305
|
+
}
|
306
|
+
|
307
|
+
static VALUE rect_in_range(VALUE self, VALUE vx, VALUE vy)
|
308
|
+
{
|
309
|
+
VALUE *st = RSTRUCT_PTR(self);
|
310
|
+
int l = NUM2INT(*(st+0));
|
311
|
+
int t = NUM2INT(*(st+1));
|
312
|
+
int w = NUM2INT(*(st+2));
|
313
|
+
int h = NUM2INT(*(st+3));
|
314
|
+
int x = NUM2INT(vx);
|
315
|
+
int y = NUM2INT(vy);
|
316
|
+
|
317
|
+
if(x >= l && y >= t && x < (l+w) && y < (t+h)){ return Qtrue; }
|
318
|
+
return Qfalse;
|
319
|
+
}
|
320
|
+
|
321
|
+
static VALUE square_move(VALUE self, VALUE dx, VALUE dy)
|
322
|
+
{
|
323
|
+
VALUE *st = RSTRUCT_PTR(self);
|
324
|
+
VALUE *pl = st+0;
|
325
|
+
VALUE *pt = st+1;
|
326
|
+
VALUE *pr = st+2;
|
327
|
+
VALUE *pb = st+3;
|
328
|
+
VALUE tl = *pl;
|
329
|
+
VALUE tt = *pt;
|
330
|
+
VALUE tr = *pr;
|
331
|
+
VALUE tb = *pb;
|
332
|
+
*pl = INT2NUM(NUM2INT(tl)+NUM2INT(dx));
|
333
|
+
*pt = INT2NUM(NUM2INT(tt)+NUM2INT(dy));
|
334
|
+
*pr = INT2NUM(NUM2INT(tr)+NUM2INT(dx));
|
335
|
+
*pb = INT2NUM(NUM2INT(tb)+NUM2INT(dy));
|
336
|
+
if(rb_block_given_p() == Qtrue){
|
337
|
+
VALUE ret = rb_yield(self);
|
338
|
+
if(ret == Qfalse || ret == Qnil)
|
339
|
+
{
|
340
|
+
*pl = tl;
|
341
|
+
*pt = tt;
|
342
|
+
*pr = tr;
|
343
|
+
*pb = tb;
|
344
|
+
}
|
345
|
+
}
|
346
|
+
return self;
|
347
|
+
}
|
348
|
+
|
349
|
+
static VALUE square_move_to(VALUE self, VALUE x, VALUE y)
|
350
|
+
{
|
351
|
+
VALUE *st = RSTRUCT_PTR(self);
|
352
|
+
VALUE *pl = st+0;
|
353
|
+
VALUE *pt = st+1;
|
354
|
+
VALUE *pr = st+2;
|
355
|
+
VALUE *pb = st+3;
|
356
|
+
VALUE tl = *pl;
|
357
|
+
VALUE tt = *pt;
|
358
|
+
VALUE tr = *pr;
|
359
|
+
VALUE tb = *pb;
|
360
|
+
int w = NUM2INT(tr)-NUM2INT(tl);
|
361
|
+
int h = NUM2INT(tb)-NUM2INT(tt);
|
362
|
+
*pl = x;
|
363
|
+
*pt = y;
|
364
|
+
*pr = INT2NUM(NUM2INT(x)+w);
|
365
|
+
*pb = INT2NUM(NUM2INT(y)+h);
|
366
|
+
if(rb_block_given_p() == Qtrue){
|
367
|
+
VALUE ret = rb_yield(self);
|
368
|
+
if(ret == Qfalse || ret == Qnil)
|
369
|
+
{
|
370
|
+
*pl = tl;
|
371
|
+
*pt = tt;
|
372
|
+
*pr = tr;
|
373
|
+
*pb = tb;
|
374
|
+
}
|
375
|
+
}
|
376
|
+
return self;
|
377
|
+
}
|
378
|
+
|
379
|
+
static VALUE square_resize(VALUE self, VALUE dw, VALUE dh)
|
380
|
+
{
|
381
|
+
VALUE *st = RSTRUCT_PTR(self);
|
382
|
+
VALUE *pr = st+2;
|
383
|
+
VALUE *pb = st+3;
|
384
|
+
VALUE tr = *pr;
|
385
|
+
VALUE tb = *pb;
|
386
|
+
*pr = INT2NUM(NUM2INT(*pr) + NUM2INT(dw));
|
387
|
+
*pb = INT2NUM(NUM2INT(*pb) + NUM2INT(dh));
|
388
|
+
if(rb_block_given_p() == Qtrue){
|
389
|
+
VALUE ret = rb_yield(self);
|
390
|
+
if(ret == Qfalse || ret == Qnil)
|
391
|
+
{
|
392
|
+
*pr = tr;
|
393
|
+
*pb = tb;
|
394
|
+
}
|
395
|
+
}
|
396
|
+
return self;
|
397
|
+
}
|
398
|
+
|
399
|
+
static VALUE square_resize_to(VALUE self, VALUE w, VALUE h)
|
400
|
+
{
|
401
|
+
VALUE *st = RSTRUCT_PTR(self);
|
402
|
+
VALUE *pl = st+0;
|
403
|
+
VALUE *pt = st+1;
|
404
|
+
VALUE *pr = st+2;
|
405
|
+
VALUE *pb = st+3;
|
406
|
+
VALUE tr = *pr;
|
407
|
+
VALUE tb = *pb;
|
408
|
+
*pr = INT2NUM(NUM2INT(*pl) + NUM2INT(w) - 1);
|
409
|
+
*pb = INT2NUM(NUM2INT(*pt) + NUM2INT(h) - 1);
|
410
|
+
if(rb_block_given_p() == Qtrue){
|
411
|
+
VALUE ret = rb_yield(self);
|
412
|
+
if(ret == Qfalse || ret == Qnil)
|
413
|
+
{
|
414
|
+
*pr = tr;
|
415
|
+
*pb = tb;
|
416
|
+
}
|
417
|
+
}
|
418
|
+
return self;
|
419
|
+
}
|
420
|
+
|
421
|
+
static VALUE square_in_range(VALUE self, VALUE vx, VALUE vy)
|
422
|
+
{
|
423
|
+
VALUE *st = RSTRUCT_PTR(self);
|
424
|
+
int l = NUM2INT(*(st+0));
|
425
|
+
int t = NUM2INT(*(st+1));
|
426
|
+
int r = NUM2INT(*(st+2));
|
427
|
+
int b = NUM2INT(*(st+3));
|
428
|
+
int x = NUM2INT(vx);
|
429
|
+
int y = NUM2INT(vy);
|
430
|
+
|
431
|
+
if(x >= l && y >= t && x <= r && y <= b){ return Qtrue; }
|
432
|
+
return Qfalse;
|
433
|
+
}
|
434
|
+
|
435
|
+
static VALUE segment_move(VALUE self, VALUE dx, VALUE dy)
|
436
|
+
{
|
437
|
+
VALUE min_x, max_x, min_y, max_y;
|
438
|
+
VALUE *st = RSTRUCT_PTR(self);
|
439
|
+
|
440
|
+
get_min_max(*(st+0), &min_x, &max_x);
|
441
|
+
get_min_max(*(st+1), &min_y, &max_y);
|
442
|
+
|
443
|
+
rb_funcall(self, rb_intern("reset"), 4, INT2NUM(NUM2INT(min_x)+NUM2INT(dx)),
|
444
|
+
INT2NUM(NUM2INT(min_y)+NUM2INT(dy)),
|
445
|
+
INT2NUM(NUM2INT(max_x)+NUM2INT(dx)),
|
446
|
+
INT2NUM(NUM2INT(max_y)+NUM2INT(dy)));
|
447
|
+
|
448
|
+
if(rb_block_given_p() == Qtrue){
|
449
|
+
VALUE ret = rb_yield(self);
|
450
|
+
if(ret == Qfalse || ret == Qnil)
|
451
|
+
rb_funcall(self, rb_intern("reset"), 4, min_x, max_x, min_y, max_y);
|
452
|
+
}
|
453
|
+
|
454
|
+
return self;
|
455
|
+
}
|
456
|
+
|
457
|
+
static VALUE segment_move_to(VALUE self, VALUE x, VALUE y)
|
458
|
+
{
|
459
|
+
VALUE min_x, max_x, min_y, max_y;
|
460
|
+
VALUE *st = RSTRUCT_PTR(self);
|
461
|
+
|
462
|
+
get_min_max(*(st+0), &min_x, &max_x);
|
463
|
+
get_min_max(*(st+1), &min_y, &max_y);
|
464
|
+
|
465
|
+
int w = NUM2INT(max_x)-NUM2INT(min_x);
|
466
|
+
int h = NUM2INT(max_y)-NUM2INT(min_y);
|
467
|
+
|
468
|
+
rb_funcall(self, rb_intern("reset"), 4, x, y, INT2NUM(NUM2INT(x)+w), INT2NUM(NUM2INT(y)+h));
|
469
|
+
|
470
|
+
if(rb_block_given_p() == Qtrue){
|
471
|
+
VALUE ret = rb_yield(self);
|
472
|
+
if(ret == Qfalse || ret == Qnil)
|
473
|
+
rb_funcall(self, rb_intern("reset"), 4, min_x, max_x, min_y, max_y);
|
474
|
+
}
|
475
|
+
|
476
|
+
return self;
|
477
|
+
}
|
478
|
+
|
479
|
+
static VALUE segment_resize(VALUE self, VALUE dw, VALUE dh)
|
480
|
+
{
|
481
|
+
VALUE min_x, max_x, min_y, max_y;
|
482
|
+
VALUE *st = RSTRUCT_PTR(self);
|
483
|
+
|
484
|
+
get_min_max(*(st+0), &min_x, &max_x);
|
485
|
+
get_min_max(*(st+1), &min_y, &max_y);
|
486
|
+
|
487
|
+
int w = NUM2INT(max_x) + NUM2INT(dw);
|
488
|
+
int h = NUM2INT(max_y) + NUM2INT(dh);
|
489
|
+
|
490
|
+
if(w <= 0)
|
491
|
+
rb_raise(eMiyakoError, "illegal width(result is 0 or minus)");
|
492
|
+
if(h <= 0)
|
493
|
+
rb_raise(eMiyakoError, "illegal height(result is 0 or minus)");
|
494
|
+
|
495
|
+
rb_funcall(self, rb_intern("reset"), 4, INT2NUM(NUM2INT(min_x)),
|
496
|
+
INT2NUM(NUM2INT(min_y)),
|
497
|
+
INT2NUM(w),
|
498
|
+
INT2NUM(h));
|
499
|
+
|
500
|
+
if(rb_block_given_p() == Qtrue){
|
501
|
+
VALUE ret = rb_yield(self);
|
502
|
+
if(ret == Qfalse || ret == Qnil)
|
503
|
+
rb_funcall(self, rb_intern("reset"), 4, min_x, max_x, min_y, max_y);
|
504
|
+
}
|
505
|
+
|
506
|
+
return self;
|
507
|
+
}
|
508
|
+
|
509
|
+
static VALUE segment_resize_to(VALUE self, VALUE w, VALUE h)
|
510
|
+
{
|
511
|
+
VALUE min_x, max_x, min_y, max_y;
|
512
|
+
VALUE *st = RSTRUCT_PTR(self);
|
513
|
+
|
514
|
+
get_min_max(*(st+0), &min_x, &max_x);
|
515
|
+
get_min_max(*(st+1), &min_y, &max_y);
|
516
|
+
|
517
|
+
int nw = NUM2INT(w);
|
518
|
+
int nh = NUM2INT(h);
|
519
|
+
|
520
|
+
if(nw <= 0)
|
521
|
+
rb_raise(eMiyakoError, "illegal width(result is 0 or minus)");
|
522
|
+
if(nh <= 0)
|
523
|
+
rb_raise(eMiyakoError, "illegal height(result is 0 or minus)");
|
524
|
+
|
525
|
+
rb_funcall(self, rb_intern("reset"), 4, INT2NUM(NUM2INT(min_x)),
|
526
|
+
INT2NUM(NUM2INT(min_y)),
|
527
|
+
INT2NUM(NUM2INT(min_x)+nw-1),
|
528
|
+
INT2NUM(NUM2INT(min_y)+nh-1));
|
529
|
+
|
530
|
+
if(rb_block_given_p() == Qtrue){
|
531
|
+
VALUE ret = rb_yield(self);
|
532
|
+
if(ret == Qfalse || ret == Qnil)
|
533
|
+
rb_funcall(self, rb_intern("reset"), 4, min_x, max_x, min_y, max_y);
|
534
|
+
}
|
535
|
+
|
536
|
+
return self;
|
537
|
+
}
|
538
|
+
|
539
|
+
void Init_miyako_basicdata()
|
540
|
+
{
|
541
|
+
mSDL = rb_define_module("SDL");
|
542
|
+
mMiyako = rb_define_module("Miyako");
|
543
|
+
eMiyakoError = rb_define_class_under(mMiyako, "MiyakoError", rb_eException);
|
544
|
+
cWaitCounter = rb_define_class_under(mMiyako, "WaitCounter", rb_cObject);
|
545
|
+
sSpriteUnit = rb_define_class_under(mMiyako, "SpriteUnitBase", rb_cStruct);
|
546
|
+
sPoint = rb_define_class_under(mMiyako, "PointStruct", rb_cStruct);
|
547
|
+
sSize = rb_define_class_under(mMiyako, "SizeStruct", rb_cStruct);
|
548
|
+
sRect = rb_define_class_under(mMiyako, "RectStruct", rb_cStruct);
|
549
|
+
sSquare = rb_define_class_under(mMiyako, "SquareStruct", rb_cStruct);
|
550
|
+
sSegment = rb_define_class_under(mMiyako, "SegmentStruct", rb_cStruct);
|
551
|
+
|
552
|
+
id_update = rb_intern("update");
|
553
|
+
id_kakko = rb_intern("[]");
|
554
|
+
id_render = rb_intern("render");
|
555
|
+
id_to_a = rb_intern("to_a");
|
556
|
+
|
557
|
+
zero = 0;
|
558
|
+
nZero = INT2NUM(zero);
|
559
|
+
one = 1;
|
560
|
+
nOne = INT2NUM(one);
|
561
|
+
|
562
|
+
rb_define_method(cWaitCounter, "start", counter_start, 0);
|
563
|
+
rb_define_method(cWaitCounter, "stop", counter_stop, 0);
|
564
|
+
rb_define_method(cWaitCounter, "wait_inner", counter_wait_inner, 1);
|
565
|
+
rb_define_method(cWaitCounter, "waiting?", counter_waiting, 0);
|
566
|
+
rb_define_method(cWaitCounter, "finish?", counter_finish, 0);
|
567
|
+
rb_define_method(cWaitCounter, "wait", counter_wait, 0);
|
568
|
+
|
569
|
+
rb_define_method(sSpriteUnit, "move!", su_move, 2);
|
570
|
+
rb_define_method(sSpriteUnit, "move_to!", su_move_to, 2);
|
571
|
+
|
572
|
+
rb_define_method(sPoint, "move!", point_move, 2);
|
573
|
+
rb_define_method(sPoint, "move_to!", point_move_to, 2);
|
574
|
+
rb_define_method(sSize, "resize!", size_resize, 2);
|
575
|
+
rb_define_method(sSize, "resize_to!", size_resize_to, 2);
|
576
|
+
rb_define_method(sRect, "move!", point_move, 2);
|
577
|
+
rb_define_method(sRect, "move_to!", point_move_to, 2);
|
578
|
+
rb_define_method(sRect, "resize!", rect_resize, 2);
|
579
|
+
rb_define_method(sRect, "resize_to!", rect_resize_to, 2);
|
580
|
+
rb_define_method(sRect, "in_range?", rect_in_range, 2);
|
581
|
+
rb_define_method(sSquare, "move!", square_move, 2);
|
582
|
+
rb_define_method(sSquare, "move_to!", square_move_to, 2);
|
583
|
+
rb_define_method(sSquare, "resize!", square_resize, 2);
|
584
|
+
rb_define_method(sSquare, "resize_to!", square_resize_to, 2);
|
585
|
+
rb_define_method(sSquare, "in_range?", square_in_range, 2);
|
586
|
+
rb_define_method(sSegment, "move!", segment_move, 2);
|
587
|
+
rb_define_method(sSegment, "move_to!", segment_move_to, 2);
|
588
|
+
rb_define_method(sSegment, "resize!", segment_resize, 2);
|
589
|
+
rb_define_method(sSegment, "resize_to!", segment_resize_to, 2);
|
590
|
+
}
|