cyross-ruby-miyako 2.0.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 (125) hide show
  1. data/README +977 -0
  2. data/Rakefile +7 -0
  3. data/img/cursor.png +0 -0
  4. data/img/cursors.png +0 -0
  5. data/img/dice.png +0 -0
  6. data/img/wait_cursor.png +0 -0
  7. data/img/win_base.png +0 -0
  8. data/img/window.png +0 -0
  9. data/install_miyako.rb +75 -0
  10. data/lib/Miyako/API/audio.rb +198 -0
  11. data/lib/Miyako/API/basic_data.rb +431 -0
  12. data/lib/Miyako/API/bitmap.rb +35 -0
  13. data/lib/Miyako/API/choices.rb +308 -0
  14. data/lib/Miyako/API/collision.rb +444 -0
  15. data/lib/Miyako/API/diagram.rb +573 -0
  16. data/lib/Miyako/API/drawing.rb +110 -0
  17. data/lib/Miyako/API/fixedmap.rb +315 -0
  18. data/lib/Miyako/API/font.rb +384 -0
  19. data/lib/Miyako/API/input.rb +440 -0
  20. data/lib/Miyako/API/layout.rb +451 -0
  21. data/lib/Miyako/API/map.rb +403 -0
  22. data/lib/Miyako/API/map_event.rb +198 -0
  23. data/lib/Miyako/API/modules.rb +109 -0
  24. data/lib/Miyako/API/movie.rb +151 -0
  25. data/lib/Miyako/API/parts.rb +154 -0
  26. data/lib/Miyako/API/plane.rb +131 -0
  27. data/lib/Miyako/API/screen.rb +257 -0
  28. data/lib/Miyako/API/shape.rb +362 -0
  29. data/lib/Miyako/API/sprite.rb +338 -0
  30. data/lib/Miyako/API/sprite_animation.rb +461 -0
  31. data/lib/Miyako/API/spriteunit.rb +113 -0
  32. data/lib/Miyako/API/story.rb +224 -0
  33. data/lib/Miyako/API/textbox.rb +496 -0
  34. data/lib/Miyako/API/viewport.rb +435 -0
  35. data/lib/Miyako/API/yuki.rb +779 -0
  36. data/lib/Miyako/EXT/miyako_cairo.rb +60 -0
  37. data/lib/Miyako/EXT/raster_scroll.rb +138 -0
  38. data/lib/Miyako/EXT/slides.rb +136 -0
  39. data/lib/Miyako/miyako.rb +172 -0
  40. data/miyako.png +0 -0
  41. data/miyako_banner.png +0 -0
  42. data/miyako_no_katana/extconf.rb +34 -0
  43. data/miyako_no_katana/miyako_no_katana.c +3301 -0
  44. data/sample/Animation1/m1ku.rb +89 -0
  45. data/sample/Animation1/m1ku_arm_0.png +0 -0
  46. data/sample/Animation1/m1ku_arm_1.png +0 -0
  47. data/sample/Animation1/m1ku_arm_2.png +0 -0
  48. data/sample/Animation1/m1ku_arm_3.png +0 -0
  49. data/sample/Animation1/m1ku_back.jpg +0 -0
  50. data/sample/Animation1/m1ku_body.png +0 -0
  51. data/sample/Animation1/m1ku_eye_0.png +0 -0
  52. data/sample/Animation1/m1ku_eye_1.png +0 -0
  53. data/sample/Animation1/m1ku_eye_2.png +0 -0
  54. data/sample/Animation1/m1ku_eye_3.png +0 -0
  55. data/sample/Animation1/m1ku_hair_front.png +0 -0
  56. data/sample/Animation1/m1ku_hair_rear.png +0 -0
  57. data/sample/Animation1/readme.txt +72 -0
  58. data/sample/Animation2/lex.rb +95 -0
  59. data/sample/Animation2/lex_back.png +0 -0
  60. data/sample/Animation2/lex_body.png +0 -0
  61. data/sample/Animation2/lex_roadroller.png +0 -0
  62. data/sample/Animation2/lex_wheel_0.png +0 -0
  63. data/sample/Animation2/lex_wheel_1.png +0 -0
  64. data/sample/Animation2/lex_wheel_2.png +0 -0
  65. data/sample/Animation2/readme.txt +72 -0
  66. data/sample/Animation2/song_title.png +0 -0
  67. data/sample/Diagram_sample/back.png +0 -0
  68. data/sample/Diagram_sample/chr01.png +0 -0
  69. data/sample/Diagram_sample/chr02.png +0 -0
  70. data/sample/Diagram_sample/cursor.png +0 -0
  71. data/sample/Diagram_sample/diagram_sample_yuki2.rb +283 -0
  72. data/sample/Diagram_sample/readme.txt +87 -0
  73. data/sample/Diagram_sample/wait_cursor.png +0 -0
  74. data/sample/Room3/blue.rb +250 -0
  75. data/sample/Room3/ending.rb +175 -0
  76. data/sample/Room3/green.rb +185 -0
  77. data/sample/Room3/image/akamatsu.png +0 -0
  78. data/sample/Room3/image/aoyama.png +0 -0
  79. data/sample/Room3/image/congra.png +0 -0
  80. data/sample/Room3/image/congratulation.png +0 -0
  81. data/sample/Room3/image/congratulation_bg.png +0 -0
  82. data/sample/Room3/image/cursor.png +0 -0
  83. data/sample/Room3/image/midori.png +0 -0
  84. data/sample/Room3/image/mittsu_no_oheya.png +0 -0
  85. data/sample/Room3/image/mittsu_no_oheya_logo.png +0 -0
  86. data/sample/Room3/image/room_blue.png +0 -0
  87. data/sample/Room3/image/room_green.png +0 -0
  88. data/sample/Room3/image/room_red.png +0 -0
  89. data/sample/Room3/image/start.png +0 -0
  90. data/sample/Room3/image/three_doors.png +0 -0
  91. data/sample/Room3/image/wait_cursor.png +0 -0
  92. data/sample/Room3/main.rb +102 -0
  93. data/sample/Room3/main_component.rb +58 -0
  94. data/sample/Room3/readme.txt +76 -0
  95. data/sample/Room3/red.rb +200 -0
  96. data/sample/Room3/room3.rb +26 -0
  97. data/sample/Room3/title.rb +171 -0
  98. data/sample/fixed_map_test/cursor.png +0 -0
  99. data/sample/fixed_map_test/fixed_map_sample.rb +149 -0
  100. data/sample/fixed_map_test/map.csv +19 -0
  101. data/sample/fixed_map_test/map_01.png +0 -0
  102. data/sample/fixed_map_test/map_sample.rb +121 -0
  103. data/sample/fixed_map_test/mapchip.csv +23 -0
  104. data/sample/fixed_map_test/monster.png +0 -0
  105. data/sample/fixed_map_test/readme.txt +72 -0
  106. data/sample/map_test/chara.rb +50 -0
  107. data/sample/map_test/chr1.png +0 -0
  108. data/sample/map_test/cursor.png +0 -0
  109. data/sample/map_test/main_parts.rb +48 -0
  110. data/sample/map_test/main_scene.rb +137 -0
  111. data/sample/map_test/map.png +0 -0
  112. data/sample/map_test/map2.png +0 -0
  113. data/sample/map_test/map_layer.csv +127 -0
  114. data/sample/map_test/map_manager.rb +92 -0
  115. data/sample/map_test/map_test.rb +23 -0
  116. data/sample/map_test/mapchip.csv +21 -0
  117. data/sample/map_test/oasis.rb +65 -0
  118. data/sample/map_test/readme.txt +87 -0
  119. data/sample/map_test/route.rb +144 -0
  120. data/sample/map_test/sea.png +0 -0
  121. data/sample/map_test/town.rb +68 -0
  122. data/sample/map_test/wait_cursor.png +0 -0
  123. data/sample/map_test/window.png +0 -0
  124. data/win/miyako_no_katana.so +0 -0
  125. metadata +194 -0
@@ -0,0 +1,573 @@
1
+ # -*- encoding: utf-8 -*-
2
+ =begin
3
+ --
4
+ Miyako v2.0
5
+ Copyright (C) 2007-2008 Cyross Makoto
6
+
7
+ This library is free software; you can redistribute it and/or
8
+ modify it under the terms of the GNU Lesser General Public
9
+ License as published by the Free Software Foundation; either
10
+ version 2.1 of the License, or (at your option) any later version.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General Public
18
+ License along with this library; if not, write to the Free Software
19
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ ++
21
+ =end
22
+
23
+ require 'thread'
24
+
25
+ module Miyako
26
+ #==遷移図モジュール群
27
+ module Diagram
28
+
29
+ #==遷移図矢印構造体
30
+ #ノードの移動先とトリガー(遷移条件)を収めている。
31
+ #to::移動先ノードのインスタンス
32
+ #trigger::遷移条件オブジェクトのインスタンス
33
+ Arrow = Struct.new(:to, :trigger)
34
+
35
+ #==遷移ノードモジュール
36
+ #遷移図のノードを構成するモジュール。
37
+ #
38
+ #mixinすることで、ノード構成に必要なメソッドを定義できる。
39
+ #あとは、initializeメソッドなどで、必要なインスタンスを作成することができる。
40
+ #なお、本モジュールでは、値の格納用に @@node_var を予約しているため、注意が必要
41
+ module NodeBase
42
+ @@node_var = {}
43
+ @@node_var.default = nil
44
+
45
+ #===ノードでの開始処理を実装する
46
+ #Processor#start メソッドが呼ばれたとき、ノードの移動があった直後の処理を実装する
47
+ def start
48
+ end
49
+
50
+ #===ノードでの中断処理を実装する
51
+ #Processor#stop メソッドが呼ばれたとき、ノードの移動する直前の処理を実装する
52
+ def stop
53
+ end
54
+
55
+ #===ノードでの停止処理を実装する
56
+ #停止処理を実装しないときは、本メソッドを実装する必要はない
57
+ #Processor#pause メソッドが呼ばれたときの処理を実装する
58
+ def pause
59
+ end
60
+
61
+ #===ノードでの復帰処理を実装する
62
+ #停止処理を実装しないときは、本メソッドを実装する必要はない
63
+ #Processor#resume メソッドが呼ばれたときの処理を実装する
64
+ def resume
65
+ end
66
+
67
+ #===ノードでの入力デバイス処理を実装する
68
+ #入力デバイス処理が必要ないときは、本メソッドを実装する必要はない
69
+ #Processor#update_input メソッドが呼ばれたときの処理を実装する
70
+ def update_input
71
+ end
72
+
73
+ #===ノードでの更新処理を実装する
74
+ #Processor#update メソッドが呼ばれたときの処理を実装する
75
+ def update
76
+ end
77
+
78
+ #===ノードでの入力デバイス処理の後始末を実装する
79
+ #入力デバイス処理が必要ないときは、本メソッドを実装する必要はない
80
+ #Processor#reset_input メソッドが呼ばれたときの処理を実装する
81
+ def reset_input
82
+ end
83
+
84
+ #===ノードでのレンダリング処理を実装する
85
+ #Screen.update メソッドを呼び出しているときは、本メソッドを実装する必要はない
86
+ #Processor#render メソッドが呼ばれたときの処理を実装する
87
+ def render
88
+ end
89
+
90
+ #===ノードでの実行が終了しているかを示すフラグを返すテンプレートメソッド
91
+ #Manager#add_arrow メソッドの呼び出しで、移動条件を指定しなければ、このメソッドが呼ばれる。
92
+ #
93
+ #ノードの終了を問い合わせる内容を本メソッドに実装する。
94
+ #返却値:: ノードの実行が終了していれば true を返す(デフォルトは無条件で false を返す)
95
+ def finish?
96
+ return false
97
+ end
98
+
99
+ #===現在実行しているノードの変数の値を取得するテンプレートメソッド
100
+ #Diagram#[] メソッドが呼ばれたときの処理を実装する
101
+ #
102
+ #mixin されたクラス内でアクセスする際は、便宜上、"self[...]"を使用する
103
+ #_name_:: 変数名(文字列・シンボル)
104
+ #返却値:: 変数の値(デフォルトはnil)
105
+ def [](name)
106
+ unless @@node_var[self.object_id]
107
+ @@node_var[self.object_id] = {}
108
+ @@node_var[self.object_id].default = nil
109
+ end
110
+ return @@node_var[self.object_id][name]
111
+ end
112
+
113
+ #===現在実行中のノードの変数に値を設定する
114
+ #Diagram#[]= メソッドが呼ばれたときの処理を実装する
115
+ #
116
+ #mixin されたクラス内でアクセスする際は、便宜上、"self[...]=..."を使用する
117
+ #_name_:: 変数名(文字列・シンボル)
118
+ #_value_:: 設定したい値
119
+ def []=(name, value)
120
+ unless @@node_var[self.object_id]
121
+ @@node_var[self.object_id] = {}
122
+ @@node_var[self.object_id].default = nil
123
+ end
124
+ @@node_var[self.object_id][name] = value
125
+ end
126
+
127
+ #===ノードのインスタンスを解放させるテンプレートメソッド
128
+ #Processor#dispose メソッドの呼び出したときに呼び出さされる
129
+ def dispose
130
+ end
131
+ end
132
+
133
+ #==遷移条件モジュール
134
+ #遷移図の移動条件を構成するモジュール。
135
+ #
136
+ #mixinすることで、遷移条件構成に必要なメソッドを定義できる。
137
+ #各メソッドは、前処理・後処理と、遷移条件の判別式を定義できる。
138
+ #判別式をあらわすメソッドは、必ずtrue/falseをかえすように設計する。
139
+ #判別式を用意できるのは、updateとrenderの処理のみ。
140
+ #あとは、initializeメソッドなどで、必要なインスタンスを作成することができる。
141
+ module TriggerBase
142
+ #===前処理を実装する
143
+ #Processor#start メソッドが呼び出されたときの処理を実装する
144
+ def pre_process
145
+ end
146
+
147
+ #===後始末を実装する
148
+ #Processor#stop メソッドが呼び出されたときの処理を実装する
149
+ def post_process
150
+ end
151
+
152
+ #===ノードの更新処理を行うかどうかの問い合わせメソッドを実装する
153
+ #NodeBase#update を呼び出すかどうかを返す処理を実装する
154
+ #デフォルトでは、無条件で true を返す
155
+ #返却値:: NodeBase#update メソッドを呼び出したいときは true を返す
156
+ def update?
157
+ return true
158
+ end
159
+
160
+ #===ノードの更新処理が終わった後の後始末を行う
161
+ #NodeBase#update を呼び出された後の処理を実装する
162
+ def post_update
163
+ end
164
+
165
+ #===ノードのレンダリング処理を行うかどうかの問い合わせメソッドを実装する
166
+ #NodeBase#render を呼び出すかどうかを返す処理を実装する
167
+ #デフォルトでは、無条件で true を返す
168
+ #Screen.update メソッドを呼び出しているときは、本メソッドを実装する必要はない
169
+ #返却値:: NodeBase#render メソッドを呼び出したいときは true を返す
170
+ def render?
171
+ return true
172
+ end
173
+
174
+ #===ノードのレンダリング処理が終わった後の後始末を行う
175
+ #Screen.update メソッドを呼び出しているときは、本メソッドを実装する必要はない
176
+ #NodeBase#render を呼び出された後の処理を実装する
177
+ def post_render
178
+ end
179
+ end
180
+
181
+ #==デフォルト遷移条件クラス
182
+ #デフォルトの遷移条件を構成したクラス。
183
+ #
184
+ #遷移条件が無条件のときにインスタンスを作成するだけで使用できる。
185
+ #すべての条件式が「true」を返すのみとなっている。
186
+ class DefaultTrigger
187
+ include Miyako::Diagram::TriggerBase
188
+ end
189
+
190
+ #==遷移図クラス本体
191
+ #但し、実質的にメソッドを呼び出すのはDiagramFacadeクラスから呼び出す
192
+ class DiagramBody
193
+ attr_reader :name #:nodoc:
194
+ TRIGGER_TYPES=[:immediate, :next]
195
+
196
+ def initialize(name, body, trigger = nil) #:nodoc:
197
+ @name = name # デバッグ用
198
+ @node = body
199
+ @trigger = trigger ? trigger : Miyako::Diagram::DefaultTrigger.new
200
+ @arrow = []
201
+ @next_trigger = nil
202
+ end
203
+
204
+ def add_arrow(to, trigger) #:nodoc:
205
+ @arrow.push(Miyako::Diagram::Arrow.new(to, trigger))
206
+ end
207
+
208
+ def start #:nodoc:
209
+ @trigger.pre_process
210
+ @node.start
211
+ end
212
+
213
+ def stop #:nodoc:
214
+ @node.stop
215
+ @trigger.post_process
216
+ end
217
+
218
+ def pause #:nodoc:
219
+ @node.pause
220
+ end
221
+
222
+ def resume #:nodoc:
223
+ @node.resume
224
+ end
225
+
226
+ def update_input #:nodoc:
227
+ @node.update_input
228
+ end
229
+
230
+ def update #:nodoc:
231
+ if @trigger.update?
232
+ @node.update
233
+ @trigger.post_update
234
+ @node.reset_input
235
+ if @next_trigger
236
+ @trigger = @next_trigger
237
+ @next_trigger = nil
238
+ end
239
+ end
240
+ end
241
+
242
+ def render #:nodoc:
243
+ if @trigger.render?
244
+ @node.render
245
+ @trigger.post_render
246
+ end
247
+ end
248
+
249
+ def [](name) #:nodoc:
250
+ return @node[name]
251
+ end
252
+
253
+ def []=(name, value) #:nodoc:
254
+ @node[name] = value
255
+ end
256
+
257
+ #===更新タイミングを計るトリガーオブジェクトを置き換える
258
+ #現在実行しているトリガーを新しいトリガーオブジェクトに置き換える。
259
+ #置き換えのタイミングは、以下の2種が選択可能(シンボルで指定)
260
+ #:immediate:: 即時に置き換え。現在実行中のトリガーを停止して、引数で指定したトリガーに置き換えて実行を開始する
261
+ #:next:: 次回更新時に置き換え。本メソッドが呼ばれた次の更新(updateメソッドが呼ばれた時)にトリガーを置き換える
262
+ #_new_trigger_:: 置き換え対象のトリガーオブジェクト
263
+ #_timing_:: 置き換えのタイミング。:immediateと:nextの2種類がある
264
+ def replace_trigger(new_trigger, timing=:next)
265
+ raise MiyakoError, "I can't understand Timing Typ! : #{timing}" unless TRIGGER_TYPES.include?(timing)
266
+ case timing
267
+ when :immediate
268
+ @trigger.stop
269
+ @trigger.post_process
270
+ @trigger = new_trigger
271
+ @trigger.pre_process
272
+ when :next
273
+ @next_trigger = new_trigger
274
+ end
275
+ end
276
+
277
+ def dispose #:nodoc:
278
+ @node.dispose
279
+ end
280
+
281
+ def go_next #:nodoc:
282
+ next_obj = self
283
+ @arrow.each{|arrow|
284
+ break (next_obj = arrow.to) if (arrow.trigger && arrow.trigger.call(@node))
285
+ break (next_obj = arrow.to) if @node.finish?
286
+ }
287
+ @trigger.post_process unless self.equal?(next_obj)
288
+ return next_obj
289
+ end
290
+ end
291
+
292
+ #==遷移図管理クラス
293
+ #遷移図クラス本体(Diagramクラス)を管理するクラス。
294
+ class Manager
295
+ def initialize #:nodoc:
296
+ @name2idx = {}
297
+ @list = []
298
+ @ptr = nil
299
+ @first = nil
300
+ @executing = false
301
+ end
302
+
303
+ #===遷移図にノードを追加する
304
+ #_name_:: ノード名。文字列かシンボルを使用
305
+ #_body_:: ノード本体。DiagramNodeBase モジュールを mixin したクラスのインスタンス
306
+ #_trigger_:: NodeTriggerBase モジュールを mixin したクラスのインスタンス。デフォルトは NpdeTrogger クラスのインスタンス
307
+ def add(name, body, trigger = nil)
308
+ @list << Miyako::Diagram::DiagramBody.new(name, body, trigger)
309
+ @name2idx[name] = @list.last
310
+ @first = @list.first unless @first
311
+ return self
312
+ end
313
+
314
+ #===ノード間移動のアローを追加する
315
+ #trigger のブロックを実行した結果、true のときは、to_name で示したノードへ移動する。
316
+ #false のときは、ノード間移動をせずに直前に実行したノードを再実行する
317
+ #_from_name_:: 移動元ノード名。文字列かシンボルを使用
318
+ #_to_name_:: 移動先ノード名。文字列かシンボルを使用
319
+ #_trigger_:: ノード間移動するかどうかを返すブロック。ブロックは引数を一つ取る(from_name で示したノードのインスタンス)
320
+ def add_arrow(from_name, to_name, &trigger)
321
+ @name2idx[from_name].add_arrow(to_name ? @name2idx[to_name] : nil, trigger)
322
+ return self
323
+ end
324
+
325
+ #===対象の名前を持つノードを取得する
326
+ #ノード内の変数にアクセスするときに使う
327
+ #_name_:: ノード名
328
+ #返却値:: 指定のノード
329
+ def [](name)
330
+ raise MiyakoError, "Don't set undefined node name!" unless @name2idx.has_key?(name)
331
+ return @name2idx[name]
332
+ end
333
+
334
+ #===実行開始ノードを変更する
335
+ #但し、遷移図処理が行われていないときに変更可能
336
+ #_name_:: ノード名
337
+ def move(name)
338
+ raise MiyakoError, "Don't set undefined node name!" unless @name2idx.has_key?(name)
339
+ return if @executing
340
+ @ptr = @name2idx[name]
341
+ end
342
+
343
+ #===実行開始ノードを、最初に登録したノードに変更する
344
+ #但し、遷移図処理が行われていないときに変更可能
345
+ def first
346
+ return if @executing
347
+ @ptr = @first
348
+ end
349
+
350
+ def now #:nodoc
351
+ return @ptr ? @ptr.name : nil
352
+ end
353
+
354
+ def now_node #:nodoc
355
+ return @ptr
356
+ end
357
+
358
+ def start #:nodoc:
359
+ @ptr = @first unless @ptr
360
+ return unless @ptr
361
+ @ptr.start
362
+ @executing = true
363
+ end
364
+
365
+ def stop #:nodoc:
366
+ @ptr.stop if @ptr
367
+ @ptr = nil
368
+ @executing = false
369
+ end
370
+
371
+ def pause #:nodoc:
372
+ @ptr.pause if @ptr
373
+ end
374
+
375
+ def resume #:nodoc:
376
+ @ptr.resume if @ptr
377
+ end
378
+
379
+ def update_input #:nodoc:
380
+ @ptr.update_input if @ptr
381
+ end
382
+
383
+ def update #:nodoc:
384
+ return unless @ptr
385
+ @ptr.update
386
+ nxt = @ptr.go_next
387
+ unless @ptr.equal?(nxt)
388
+ @ptr.stop
389
+ @ptr = nxt
390
+ @ptr.start if @ptr
391
+ end
392
+ end
393
+
394
+ def render #:nodoc:
395
+ @ptr.render if @ptr
396
+ end
397
+
398
+ def finish? #:nodoc:
399
+ return @ptr == nil
400
+ end
401
+
402
+ def dispose #:nodoc:
403
+ @name2idx.keys.each{|k|
404
+ @name2idx[k].dispose
405
+ }
406
+ end
407
+ end
408
+
409
+ #==レンダラクラス
410
+ #レンダリングのみを行うクラス
411
+ #Processor#render メソッドのみを呼び出せる
412
+ #インスタンス生成は、Processor#renderer メソッドを呼び出して行う
413
+ class Renderer
414
+ def initialize(obj) #:nodoc:
415
+ @renderer = obj
416
+ end
417
+
418
+ #===レンダリングを行う
419
+ #Processor#render メソッドを呼び出す
420
+ def render
421
+ @renderer.call
422
+ end
423
+ end
424
+
425
+ #==遷移図操作クラス
426
+ #遷移図形式の処理を制御するクラス
427
+ class Processor
428
+ #遷移図本体。Manager クラスのインスタンス
429
+ attr_reader :diagram
430
+
431
+ #===インスタンスを生成する
432
+ #遷移図形式のインスタンス群を生成する
433
+ #ブロックを必ず取り(取らないとエラー)、ブロック内では、遷移図の構成を実装する
434
+ #(Manager#add, Manager#add_arrow の各メソッドを参照)
435
+ #_sync_:: 同期実行かどうかを示すフラグ。同期実行(明示的にupdateメソッドを呼び出す)のときは true 、非同期実行の場合は false を渡す(デフォルトは false )
436
+ #返却値:: 生成されたインスタンス
437
+ def initialize(sync=false)
438
+ @loop = self.method(:main_loop)
439
+ @states = {:execute => false, :pause => false, :type1 => false }
440
+ @thread = nil
441
+ @mutex = Mutex.new
442
+ @diagram = Miyako::Diagram::Manager.new
443
+ @sync = sync
444
+ yield @diagram if block_given?
445
+ end
446
+
447
+ #===同期実行かどうかの問い合わせメソッド
448
+ #返却値: 同期実行のときはtrue
449
+ def sync?
450
+ return @sync
451
+ end
452
+
453
+ #===遷移図形式の処理を開始する
454
+ def start
455
+ return if @states[:execute]
456
+ @mutex.lock unless @sync
457
+ @states[:execute] = true
458
+ unless @sync
459
+ @mutex.unlock
460
+ @thread = Thread.new{ @loop.call }
461
+ end
462
+ end
463
+
464
+ #===実行中の処理を中断させる
465
+ def stop
466
+ return unless @states[:execute]
467
+ @mutex.lock unless @sync
468
+ @states[:execute] = false
469
+ unless @sync
470
+ @mutex.unlock
471
+ @thread.join
472
+ @thread = nil
473
+ end
474
+ end
475
+
476
+ #===実行中の処理を停止させる
477
+ #resume メソッドが呼び出されるまで停止は復帰されない
478
+ def pause
479
+ return unless @states[:execute]
480
+ @mutex.lock unless @sync
481
+ @states[:pause] = true
482
+ @mutex.unlock unless @sync
483
+ end
484
+
485
+ #===停止状態から復帰する
486
+ #このメソッドを呼び出すまで停止状態を保つ
487
+ def resume
488
+ return unless @states[:execute]
489
+ @mutex.lock unless @sync
490
+ @states[:pause] = false
491
+ @mutex.unlock unless @sync
492
+ end
493
+
494
+ #===入力デバイスに関わる処理を行う
495
+ #(注)必ずメインスレッドから呼び出すこと!
496
+ def update_input
497
+ return if @states[:pause]
498
+ @diagram.update_input
499
+ end
500
+
501
+ #===処理の更新を行う
502
+ #(注)このメソッドを使う際は、同期モード(インスタンス生成時に引数として true を渡す)にする必要がある
503
+ def update
504
+ return if @states[:pause]
505
+ @diagram.update
506
+ @states[:execute] = false if @diagram.finish?
507
+ end
508
+
509
+ #===レンダリング処理を行う
510
+ #Screen.update メソッドを使用している場合は使う必要はない
511
+ def render
512
+ @mutex.lock unless @sync
513
+ @diagram.render
514
+ unless @sync
515
+ @mutex.unlock
516
+ Thread.pass
517
+ end
518
+ end
519
+
520
+ #===遷移図形式の処理が終了しているかどうかを取得する
521
+ #遷移図処理が終了したときと停止(Diagram::Processor#stop メソッドを実行)した時に finish? メソッドは true を返す
522
+ #返却値:: 処理が終了していれば(開始前ならば) true を返す
523
+ def finish?
524
+ @diagram.finish?
525
+ end
526
+
527
+ #===各ノードに格納されているインスタンスを解放する
528
+ def dispose
529
+ @diagram.dispose
530
+ end
531
+
532
+ #===レンダリングのみのインスタンスを生成する
533
+ #MVCを推し進めるため、別の場所でレンダリングを行いたい場合に生成する。
534
+ #返却値:: DiagramRenderer クラスのインスタンス
535
+ def renderer
536
+ return Miyako::Diagram::Renderer.new(self.method(:render))
537
+ end
538
+
539
+ #===指定した名前のノードを取得する
540
+ #_name_:: ノード名(文字列・シンボル)
541
+ #返却値:: ノード名に対応したノードのインスタンス
542
+ def [](name)
543
+ return @diagram[name]
544
+ end
545
+
546
+ #===現在実行しているノード名を取得する
547
+ #返却値:: ノード名(文字列・シンボル)
548
+ def now
549
+ return @diagram.now
550
+ end
551
+
552
+ #===現在実行しているノードを取得する
553
+ #返却値:: ノードのインスタンス
554
+ def now_node
555
+ return @diagram.now_node
556
+ end
557
+
558
+ def main_loop #:nodoc:
559
+ @diagram.start
560
+ while @states[:execute] do
561
+ unless @states[:pause]
562
+ @mutex.lock
563
+ @diagram.update
564
+ @mutex.unlock
565
+ end
566
+ Thread.pass
567
+ @states[:execute] = false if @diagram.finish?
568
+ end
569
+ @diagram.stop
570
+ end
571
+ end
572
+ end
573
+ end
@@ -0,0 +1,110 @@
1
+ # -*- encoding: utf-8 -*-
2
+ =begin
3
+ --
4
+ Miyako v2.0
5
+ Copyright (C) 2007-2008 Cyross Makoto
6
+
7
+ This library is free software; you can redistribute it and/or
8
+ modify it under the terms of the GNU Lesser General Public
9
+ License as published by the Free Software Foundation; either
10
+ version 2.1 of the License, or (at your option) any later version.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General Public
18
+ License along with this library; if not, write to the Free Software
19
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ ++
21
+ =end
22
+
23
+ # 線形描画モジュール
24
+ module Miyako
25
+ #==線形描画モジュール
26
+ module Drawing
27
+ @@draw_list = {:line => {:normal => {:solid => lambda{|b, l| b.draw_line(*l)},
28
+ :anti_aliasing => lambda{|b, l| b.draw_aa_line(*l)}},
29
+ :fill => {:solid => lambda{|b, l| b.draw_line(*l)},
30
+ :anti_aliasing => lambda{|b, l| b.draw_aa_line(*l)}}},
31
+ :rect => {:normal => {:solid => lambda{|b, l| b.draw_rect(*l)},
32
+ :anti_aliasing => lambda{|b, l| b.draw_rect(*l)}},
33
+ :fill => {:solid => lambda{|b, l| b.fill_rect(*l)},
34
+ :anti_aliasing => lambda{|b, l| b.fill_rect(*l)}}},
35
+ :circle => {:normal => {:solid => lambda{|b, l| b.draw_circle(*l)},
36
+ :anti_aliasing => lambda{|b, l| b.draw_aa_circle(*l)}},
37
+ :fill => {:solid => lambda{|b, l| b.draw_filled_circle(*l)},
38
+ :anti_aliasing => lambda{|b, l| b.draw_aa_filled_circle(*l)}}},
39
+ :ellipse => {:normal => {:solid => lambda{|b, l| b.draw_ellipse(*l)},
40
+ :anti_aliasing => lambda{|b, l| b.draw_aa_ellipse(*l)}},
41
+ :fill => {:solid => lambda{|b, l| b.draw_filled_ellipse(*l)},
42
+ :anti_aliasing => lambda{|b, l| b.drawAAFilledEllipse(*l)}}}}
43
+
44
+ #===画像全体を指定の色で塗りつぶす
45
+ #_bitmap_:: 描画対象のビットマップ(Sprite.bitmapやSpriteUnit#bitmapの返り値など)
46
+ #_color_:: 塗りつぶす色。Color.to_rgbメソッドのパラメータでの指定が可能
47
+ #返却値:: 自分自身を返す
48
+ def Drawing.fill(bitmap, color)
49
+ bitmap.fill_rect(0,0,self.w,self.h, Color.to_rgb(color))
50
+ return self
51
+ end
52
+
53
+ #===画像内に直線を引く
54
+ #_bitmap_:: 描画対象のビットマップ(Sprite.bitmapやSpriteUnit#bitmapの返り値など)
55
+ #_rect_:: 描画する矩形。画像の左上を[0,0]とする。4要素の整数の配列かRect構造体を使用
56
+ #_color_:: 描画色。Color.to_rgbメソッドのパラメータでの指定が可能
57
+ #_attribute_:: 描画の属性。:normal固定。
58
+ #_aa_:: アンチエイリアスの指定。:solidでオフ、:anti_aliasingでオン
59
+ #返却値:: 自分自身を返す
60
+ def Drawing.line(bitmap, rect, color, attribute = :normal, aa = :solid)
61
+ raise MiyakoError, "not have Drawing attribute! #{attribute}" unless @@draw_list[:line].has_key?(attribute)
62
+ raise MiyakoError, "not have Drawing aaa! #{aa}" unless @@draw_list[:line][:attribute].has_key?(aa)
63
+ color =
64
+ @@draw_list[:line][attribute][aa].call(bitmap, rect.to_a << Color.to_rgb(color))
65
+ return self
66
+ end
67
+
68
+ #===画像内に矩形を描画する
69
+ #_bitmap_:: 描画対象のビットマップ(Sprite.bitmapやSpriteUnit#bitmapの返り値など)
70
+ #_rect_:: 描画する矩形。画像の左上を[0,0]とする。4要素の整数の配列かRect構造体を使用
71
+ #_color_:: 描画色。Color.to_rgbメソッドのパラメータでの指定が可能
72
+ #_attribute_:: 描画の属性。:normalで縁のみ描画、:fillで内部も塗りつぶす
73
+ #_aa_:: アンチエイリアスの指定。:solidでオフ、:anti_aliasingでオン
74
+ #返却値:: 自分自身を返す
75
+ def Drawing.rect(bitmap, rect, color, attribute = :normal, aa = :solid)
76
+ raise MiyakoError, "not have Drawing attribute! #{attribute}" unless @@draw_list[:line].has_key?(attribute)
77
+ raise MiyakoError, "not have Drawing aaa! #{aa}" unless @@draw_list[:line][:attribute].has_key?(aa)
78
+ @@draw_list[:rect][attribute][aa].call(bitmap, rect.to_a << Color.to_rgb(color))
79
+ return self
80
+ end
81
+
82
+ #===画像内に円を描画する
83
+ #_bitmap_:: 描画対象のビットマップ(Sprite.bitmapやSpriteUnit#bitmapの返り値など)
84
+ #_point_:: 中心の位置。2要素の整数の配列、もしくはPoint構造体を使用可能
85
+ #_r_:: 円の半径。整数を使用可能。
86
+ #_color_:: 描画色。Color.to_rgbメソッドのパラメータでの指定が可能
87
+ #_attribute_:: 描画の属性。:normalで縁のみ描画、:fillで内部も塗りつぶす
88
+ #_aa_:: アンチエイリアスの指定。:solidでオフ、:anti_aliasingでオン
89
+ #返却値:: 自分自身を返す
90
+ def Drawing.circle(bitmap, point, r, color, attribute = :normal, aa = :solid)
91
+ raise MiyakoError, "not have Drawing attribute! #{attribute}" unless @@draw_list[:line].has_key?(attribute)
92
+ raise MiyakoError, "not have Drawing aaa! #{aa}" unless @@draw_list[:line][:attribute].has_key?(aa)
93
+ @@draw_list[:circle][attribute][aa].call(bitmap, point.to_a << r << Color.to_rgb(color))
94
+ return self
95
+ end
96
+
97
+ #===画像内に楕円を描画する
98
+ #_bitmap_:: 描画対象のビットマップ(Sprite.bitmapやSpriteUnit#bitmapの返り値など)
99
+ #_rect_:: 描画する矩形。画像の左上を[0,0]とする。4要素の整数の配列かRect構造体を使用
100
+ #_color_:: 描画色。Color.to_rgbメソッドのパラメータでの指定が可能
101
+ #_attribute_:: 描画の属性。:normalで縁のみ描画、:fillで内部も塗りつぶす
102
+ #_aa_:: アンチエイリアスの指定。:solidでオフ、:anti_aliasingでオン
103
+ #返却値:: 自分自身を返す
104
+ def Drawing.ellipse(bitmap, rect, color, attribute = :normal, aa = :solid)
105
+ raise MiyakoError, "not have Drawing attribute! #{attribute}" unless @@draw_list[:line].has_key?(attribute)
106
+ raise MiyakoError, "not have Drawing aaa! #{aa}" unless @@draw_list[:line][:attribute].has_key?(aa)
107
+ @@draw_list[:ellipse][attribute][aa].call(bitmap, rect.to_a << Color.to_rgb(color))
108
+ end
109
+ end
110
+ end