Module: PandaCanvas::DrawingWithCleanRoom
- Included in:
- DrawingCanvas
- Defined in:
- lib/panda_canvas/drawing_with_clean_room.rb
Overview
DrawingWithCleanRoom adds behavior to perform canvas updates using method capturing and delayed execution. This is faster, but somewhat ugly and should only be used in environments where resuming fibers in the Gosu draw loop results in a segfault.
Instance Method Summary collapse
-
#prepare(&block) ⇒ Object
Evaluates the drawing block in a DrawingCleanRoom instance and captures drawing method sequence.
-
#update ⇒ Object
Performs drawing until the next flush using the captured sequence.
Instance Method Details
#prepare(&block) ⇒ Object
Evaluates the drawing block in a DrawingCleanRoom instance and captures drawing method sequence.
11 12 13 14 15 |
# File 'lib/panda_canvas/drawing_with_clean_room.rb', line 11 def prepare(&block) clean_room = DrawingCleanRoom.new clean_room.instance_eval(&block) @calls = clean_room.calls end |
#update ⇒ Object
Performs drawing until the next flush using the captured sequence.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/panda_canvas/drawing_with_clean_room.rb', line 18 def update unless @calls.empty? DrawingMethods::CANVAS_UPDATE.each {|call| send call[0], *call[1..-1] } flush_index = @calls.index(DrawingCleanRoom::FLUSH) @calls.slice!(0...flush_index).each do |call| if DrawingMethods::CANVAS_CALLS.include? call[0] @canvas_calls << call else @image.send call[0], *call[1..-1] end end @calls.shift end end |