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/lib/Miyako/miyako.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  #=コンテンツ作成ライブラリMiyako2.1
4
4
  #
5
5
  #Authors:: サイロス誠
6
- #Version:: 2.1.0
6
+ #Version:: 2.1.1
7
7
  #Copyright:: 2007-2009 Cyross Makoto
8
8
  #License:: LGPL2.1
9
9
  #
@@ -60,7 +60,7 @@ Thread.abort_on_exception = true
60
60
 
61
61
  #==Miyako基幹モジュール
62
62
  module Miyako
63
- VERSION = "2.1.0"
63
+ VERSION = "2.1.1"
64
64
 
65
65
  #===アプリケーション実行中に演奏する音楽のサンプリングレートを指定する
66
66
  #単位はHz(周波数)
@@ -77,7 +77,7 @@ module Miyako
77
77
  def Miyako::version
78
78
  return VERSION
79
79
  end
80
-
80
+
81
81
  osn = Config::CONFIG["target_os"].downcase
82
82
  @@osName = "other"
83
83
  case osn
@@ -88,7 +88,7 @@ module Miyako
88
88
  when /darwin/
89
89
  @@osName = "mac_osx"
90
90
  end
91
-
91
+
92
92
  #===実行しているOSの名前を取得する
93
93
  #(Windows 9x/Me/Xp/Vista, Cygwin/MinGW) : "win"
94
94
  #(Linux) : "linux"
@@ -98,7 +98,7 @@ module Miyako
98
98
  def Miyako::getOSName
99
99
  return @@osName
100
100
  end
101
-
101
+
102
102
  #===ウィンドウのタイトルを設定する
103
103
  #_title_:: 設定する文字列
104
104
  def Miyako::setTitle(title)
@@ -117,18 +117,26 @@ end
117
117
 
118
118
  require 'Miyako/API/exceptions'
119
119
  require 'Miyako/API/utility'
120
+ require 'Miyako/API/struct_point'
121
+ require 'Miyako/API/struct_size'
122
+ require 'Miyako/API/struct_rect'
123
+ require 'Miyako/API/struct_square'
124
+ require 'Miyako/API/struct_segment'
125
+ require 'Miyako/API/color'
126
+ require 'Miyako/API/wait_counter'
120
127
  require 'Miyako/API/basic_data'
121
128
  require 'Miyako/API/modules'
129
+ require 'Miyako/API/layout'
122
130
  require 'Miyako/API/yuki'
131
+ require 'Miyako/API/i_yuki'
123
132
  require 'Miyako/API/font'
124
133
  require 'Miyako/API/viewport'
125
- require 'Miyako/API/layout'
126
134
  require 'Miyako/API/bitmap'
127
135
  require 'Miyako/API/drawing'
128
136
  require 'Miyako/API/spriteunit'
129
137
  require 'Miyako/API/sprite_animation'
130
- require 'Miyako/API/sprite'
131
138
  require 'Miyako/API/sprite_list'
139
+ require 'Miyako/API/sprite'
132
140
  require 'Miyako/API/collision'
133
141
  require 'Miyako/API/screen'
134
142
  require 'Miyako/API/shape'
@@ -139,6 +147,7 @@ require 'Miyako/API/movie'
139
147
  require 'Miyako/API/parts'
140
148
  require 'Miyako/API/choices'
141
149
  require 'Miyako/API/textbox'
150
+ require 'Miyako/API/map_struct'
142
151
  require 'Miyako/API/map'
143
152
  require 'Miyako/API/fixedmap'
144
153
  require 'Miyako/API/map_event'
@@ -150,16 +159,21 @@ module Miyako
150
159
 
151
160
  #===Miyakoのメインループ
152
161
  #ブロックを受け取り、そのブロックを評価する
153
- #ブロック評価前に<i>Audio::update</i>と<i>Input::update</i>、<i>Screen::clear</i>、評価後に<i>Screen::render</i>を呼び出す
162
+ #ブロック評価前に<i>Audio::update</i>と<i>Input::update</i>、<i>WaitCounter::update</i>、
163
+ #<i>Screen::clear</i>、評価後に<i>WaitCounter::post_update</i>、<i>Animation::update</i>、
164
+ #<i>Screen::render</i>を呼び出す
154
165
  #
155
166
  #ブロックを渡さないと例外が発生する
156
- def Miyako.main_loop
167
+ def Miyako.main_loop(is_clear = true)
157
168
  raise MiyakoError, "Miyako.main_loop needs brock!" unless block_given?
158
169
  loop do
159
170
  Audio.update
160
171
  Input.update
161
- Screen.clear
172
+ WaitCounter.update
173
+ Screen.clear if is_clear
162
174
  yield
175
+ WaitCounter.post_update
176
+ Animation.update
163
177
  Screen.render
164
178
  end
165
179
  end
@@ -179,7 +193,7 @@ module Miyako
179
193
  def Miyako.initialized?
180
194
  @@initialized
181
195
  end
182
-
196
+
183
197
  #===Miyakoの初期化
184
198
  #画面初期化や音声初期化などのメソッドを呼び出す。
185
199
  #グローバル変数$miyako_auto_openがtrueのときは最初に自動的に呼び出される。
data/lib/miyako.rb ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ #=コンテンツ作成ライブラリMiyako2.1
4
+ #
5
+ #Authors:: サイロス誠
6
+ #Version:: 2.1.0
7
+ #Copyright:: 2007-2009 Cyross Makoto
8
+ #License:: LGPL2.1
9
+ #
10
+ =begin
11
+ Miyako v2.1
12
+ Copyright (C) 2007-2008 Cyross Makoto
13
+
14
+ This library is free software; you can redistribute it and/or
15
+ modify it under the terms of the GNU Lesser General Public
16
+ License as published by the Free Software Foundation; either
17
+ version 2.1 of the License, or (at your option) any later version.
18
+
19
+ This library is distributed in the hope that it will be useful,
20
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22
+ Lesser General Public License for more details.
23
+
24
+ You should have received a copy of the GNU Lesser General Public
25
+ License along with this library; if not, write to the Free Software
26
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
+ =end
28
+ require 'Miyako/miyako'
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ #=コンテンツ作成ライブラリMiyako2.1
4
+ #
5
+ #Authors:: サイロス誠
6
+ #Version:: 2.1.0
7
+ #Copyright:: 2007-2009 Cyross Makoto
8
+ #License:: LGPL2.1
9
+ #
10
+ =begin
11
+ Miyako v2.1
12
+ Copyright (C) 2007-2008 Cyross Makoto
13
+
14
+ This library is free software; you can redistribute it and/or
15
+ modify it under the terms of the GNU Lesser General Public
16
+ License as published by the Free Software Foundation; either
17
+ version 2.1 of the License, or (at your option) any later version.
18
+
19
+ This library is distributed in the hope that it will be useful,
20
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22
+ Lesser General Public License for more details.
23
+
24
+ You should have received a copy of the GNU Lesser General Public
25
+ License along with this library; if not, write to the Free Software
26
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
+ =end
28
+
29
+ # 初期化を行わずにrequire 'Miyako/miyako'のみ行う
30
+
31
+ $miyako_auto_open = false
32
+
33
+ require 'Miyako/miyako'
34
+
35
+ $miyako_auto_open = nil
data/miyako_basicdata.c CHANGED
@@ -83,7 +83,8 @@ static void get_min_max(VALUE segment, VALUE *min, VALUE *max)
83
83
  */
84
84
  static VALUE counter_start(VALUE self)
85
85
  {
86
- rb_iv_set(self, "@st", rb_funcall(mSDL, rb_intern("getTicks"), 0));
86
+ rb_iv_set(self, "@st", INT2NUM(SDL_GetTicks()));
87
+ rb_iv_set(self, "@stop_tick", Qnil);
87
88
  rb_iv_set(self, "@counting", Qtrue);
88
89
  return self;
89
90
  }
@@ -93,7 +94,7 @@ static VALUE counter_start(VALUE self)
93
94
  */
94
95
  static VALUE counter_stop(VALUE self)
95
96
  {
96
- rb_iv_set(self, "@st", INT2NUM(0));
97
+ rb_iv_set(self, "@stop_tick", INT2NUM(SDL_GetTicks()));
97
98
  rb_iv_set(self, "@counting", Qfalse);
98
99
  return self;
99
100
  }
@@ -101,19 +102,118 @@ static VALUE counter_stop(VALUE self)
101
102
  /*
102
103
  :nodoc:
103
104
  */
104
- static VALUE counter_wait_inner(VALUE self, VALUE f)
105
+ static VALUE counter_now(VALUE self)
105
106
  {
106
- VALUE counting = rb_iv_set(self, "@counting", Qtrue);
107
- if(counting == Qfalse){ return f == Qtrue ? Qfalse : Qtrue; }
107
+ VALUE stop_tick = rb_iv_get(self, "@stop_tick");
108
+ Uint32 cnt = 0;
109
+ Uint32 wait = NUM2INT(rb_iv_get(self, "@wait"));
110
+ if(stop_tick != Qnil)
111
+ {
112
+ cnt = NUM2INT(stop_tick) - NUM2INT(rb_iv_get(self, "@st"));
113
+ if(wait < cnt)
114
+ {
115
+ return INT2NUM(wait+1);
116
+ }
117
+ else
118
+ {
119
+ return INT2NUM(cnt);
120
+ }
121
+ }
122
+ if(rb_iv_get(self, "@counting") == Qfalse){ return NUM2INT(-1); }
123
+ cnt = SDL_GetTicks() - NUM2INT(rb_iv_get(self, "@st"));
124
+ if(wait < cnt)
125
+ {
126
+ return INT2NUM(wait+1);
127
+ }
128
+ else
129
+ {
130
+ return INT2NUM(cnt);
131
+ }
132
+ return self;
133
+ }
108
134
 
109
- int t = NUM2INT(rb_funcall(mSDL, rb_intern("getTicks"), 0));
110
- int st = NUM2INT(rb_iv_get(self, "@st"));
111
- int wait = NUM2INT(rb_iv_get(self, "@wait"));
112
- if((t - st) < wait){ return f; }
135
+ /*
136
+ :nodoc:
137
+ */
138
+ static VALUE counter_remain(VALUE self)
139
+ {
140
+ VALUE stop_tick = rb_iv_get(self, "@stop_tick");
141
+ Uint32 cnt = 0;
142
+ Uint32 wait = NUM2INT(rb_iv_get(self, "@wait"));
143
+ if(stop_tick != Qnil)
144
+ {
145
+ cnt = NUM2INT(stop_tick) - NUM2INT(rb_iv_get(self, "@st"));
146
+ if(wait < cnt)
147
+ {
148
+ return NUM2INT(-1);
149
+ }
150
+ else
151
+ {
152
+ return INT2NUM(wait-cnt);
153
+ }
154
+ }
155
+ if(rb_iv_get(self, "@counting") == Qfalse){ return INT2NUM(wait+1); }
156
+ cnt = SDL_GetTicks() - NUM2INT(rb_iv_get(self, "@st"));
157
+ if(wait < cnt)
158
+ {
159
+ return INT2NUM(-1);
160
+ }
161
+ else
162
+ {
163
+ return INT2NUM(wait-cnt);
164
+ }
165
+ return self;
166
+ }
167
+
168
+ /*
169
+ :nodoc:
170
+ */
171
+ static VALUE counter_reset(VALUE self)
172
+ {
173
+ if(rb_iv_get(self, "@counting") == Qtrue){ return self; }
174
+ rb_iv_set(self, "@st", INT2NUM(0));
175
+ rb_iv_set(self, "@stop_tick", Qnil);
176
+ rb_iv_set(self, "@counting", Qfalse);
177
+ return self;
178
+ }
179
+
180
+ /*
181
+ :nodoc:
182
+ */
183
+ static VALUE counter_resume(VALUE self)
184
+ {
185
+ VALUE stop_tick = rb_iv_get(self, "@stop_tick");
186
+ if(stop_tick == Qnil) return self;
187
+ Uint32 st = NUM2INT(rb_iv_get(self, "@st")) + SDL_GetTicks() - NUM2INT(stop_tick);
188
+ rb_iv_set(self, "@st", INT2NUM(st));
189
+ rb_iv_set(self, "@stop_tick", Qnil);
190
+ rb_iv_set(self, "@counting", Qtrue);
191
+ return self;
192
+ }
113
193
 
114
- rb_iv_set(cWaitCounter, "@counting", Qfalse);
194
+ /*
195
+ :nodoc:
196
+ */
197
+ static VALUE counter_wait_inner(VALUE self, VALUE f)
198
+ {
199
+ Uint32 st = NUM2INT(rb_iv_get(self, "@st"));
200
+ Uint32 wait = NUM2INT(rb_iv_get(self, "@wait"));
201
+ Uint32 cnt = 0;
115
202
 
116
- return f == Qtrue ? Qfalse : Qtrue;
203
+ VALUE stop_tick = rb_iv_get(self, "@stop_tick");
204
+ if(stop_tick != Qnil)
205
+ {
206
+ cnt = NUM2INT(stop_tick) - st;
207
+ }
208
+ else
209
+ {
210
+ cnt = SDL_GetTicks() - st;
211
+ }
212
+ if(cnt >= wait)
213
+ {
214
+ return f == Qtrue ? Qfalse : Qtrue;
215
+ }
216
+ return f;
117
217
  }
118
218
 
119
219
  /*
@@ -137,15 +237,91 @@ static VALUE counter_finish(VALUE self)
137
237
  */
138
238
  static VALUE counter_wait(VALUE self)
139
239
  {
140
- int t = NUM2INT(rb_funcall(mSDL, rb_intern("getTicks"), 0));
141
- int st = NUM2INT(rb_funcall(mSDL, rb_intern("getTicks"), 0));
142
- int wait = NUM2INT(rb_iv_get(self, "@wait"));
240
+ Uint32 t = SDL_GetTicks();
241
+ Uint32 st = NUM2INT(rb_iv_get(self, "@st"));
242
+ Uint32 wait = NUM2INT(rb_iv_get(self, "@wait"));
143
243
  while((t - st) < wait){
144
244
  t = NUM2INT(rb_funcall(mSDL, rb_intern("getTicks"), 0));
145
245
  }
146
246
  return self;
147
247
  }
148
248
 
249
+ /*
250
+ :nodoc:
251
+ */
252
+ static int counter_update_inner(VALUE key, VALUE val)
253
+ {
254
+ if(rb_iv_get(key, "@counting") == Qfalse){ return 0; }
255
+ if(counter_finish(key) == Qtrue)
256
+ {
257
+ VALUE call_arg = rb_ary_new();
258
+
259
+ VALUE *array_ptr = RARRAY_PTR(val);
260
+
261
+ rb_ary_push(call_arg, key);
262
+ rb_ary_push(call_arg, *(array_ptr+1));
263
+ rb_ary_push(call_arg, *(array_ptr+2));
264
+ rb_proc_call(*array_ptr, call_arg);
265
+
266
+ int count = NUM2INT(*(array_ptr+1));
267
+ int ncount = NUM2INT(*(array_ptr+2));
268
+
269
+ if(ncount > count)
270
+ {
271
+ counter_start(key);
272
+ }
273
+ else if(count == ncount)
274
+ {
275
+ counter_stop(key);
276
+ }
277
+ else
278
+ {
279
+ *(array_ptr+2) = INT2NUM(ncount + 1);
280
+ counter_start(key);
281
+ }
282
+ }
283
+
284
+ return 0;
285
+ }
286
+
287
+ /*
288
+ :nodoc:
289
+ */
290
+ static VALUE counter_update(VALUE self)
291
+ {
292
+ VALUE callbacks = rb_iv_get(self, "@@callbacks");
293
+ rb_hash_foreach(callbacks, counter_update_inner, Qnil);
294
+
295
+ return Qnil;
296
+ }
297
+
298
+ /*
299
+ :nodoc:
300
+ */
301
+ void _miyako_counter_update()
302
+ {
303
+ counter_update(cWaitCounter);
304
+ }
305
+
306
+ /*
307
+ :nodoc:
308
+ */
309
+ static VALUE counter_post_update(VALUE self)
310
+ {
311
+ VALUE callbacks = rb_iv_get(self, "@@post_callbacks");
312
+ rb_hash_foreach(callbacks, counter_update_inner, Qnil);
313
+
314
+ return Qnil;
315
+ }
316
+
317
+ /*
318
+ :nodoc:
319
+ */
320
+ void _miyako_counter_post_update()
321
+ {
322
+ counter_post_update(cWaitCounter);
323
+ }
324
+
149
325
  static VALUE su_move(VALUE self, VALUE dx, VALUE dy)
150
326
  {
151
327
  VALUE *st = RSTRUCT_PTR(self);
@@ -315,7 +491,7 @@ static VALUE rect_in_range(VALUE self, VALUE vx, VALUE vy)
315
491
  int h = NUM2INT(*(st+3));
316
492
  int x = NUM2INT(vx);
317
493
  int y = NUM2INT(vy);
318
-
494
+
319
495
  if(x >= l && y >= t && x < (l+w) && y < (t+h)){ return Qtrue; }
320
496
  return Qfalse;
321
497
  }
@@ -429,7 +605,7 @@ static VALUE square_in_range(VALUE self, VALUE vx, VALUE vy)
429
605
  int b = NUM2INT(*(st+3));
430
606
  int x = NUM2INT(vx);
431
607
  int y = NUM2INT(vy);
432
-
608
+
433
609
  if(x >= l && y >= t && x <= r && y <= b){ return Qtrue; }
434
610
  return Qfalse;
435
611
  }
@@ -457,13 +633,21 @@ void Init_miyako_basicdata()
457
633
  one = 1;
458
634
  nOne = INT2NUM(one);
459
635
 
636
+ rb_define_singleton_method(cWaitCounter, "update", counter_update, 0);
637
+ rb_define_singleton_method(cWaitCounter, "post_update", counter_post_update, 0);
460
638
  rb_define_method(cWaitCounter, "start", counter_start, 0);
461
639
  rb_define_method(cWaitCounter, "stop", counter_stop, 0);
640
+ rb_define_method(cWaitCounter, "reset", counter_reset, 0);
641
+ rb_define_method(cWaitCounter, "resume", counter_resume, 0);
642
+ rb_define_method(cWaitCounter, "now", counter_now, 0);
643
+ rb_define_method(cWaitCounter, "remain", counter_remain, 0);
644
+ rb_define_method(cWaitCounter, "remind", counter_remain, 0);
462
645
  rb_define_method(cWaitCounter, "wait_inner", counter_wait_inner, 1);
463
646
  rb_define_method(cWaitCounter, "waiting?", counter_waiting, 0);
464
647
  rb_define_method(cWaitCounter, "finish?", counter_finish, 0);
648
+ rb_define_method(cWaitCounter, "finished?", counter_finish, 0);
465
649
  rb_define_method(cWaitCounter, "wait", counter_wait, 0);
466
-
650
+
467
651
  rb_define_method(sSpriteUnit, "move!", su_move, 2);
468
652
  rb_define_method(sSpriteUnit, "move_to!", su_move_to, 2);
469
653