diff options
| author | Nick Sandberg <[email protected]> | 2021-02-24 05:54:08 -0700 |
|---|---|---|
| committer | Amir Rajan <[email protected]> | 2021-02-24 18:03:07 -0800 |
| commit | 5bc6d6fa16bcf1da4485e4ccc870f046cc48a522 (patch) | |
| tree | 0eb1fa4c834bd1b770cce32621a03162e56e15f5 | |
| parent | 1d5be9636eff12faeb1f42e1adeaf62c1683347e (diff) | |
| download | dragonruby-game-toolkit-contrib-5bc6d6fa16bcf1da4485e4ccc870f046cc48a522.tar.gz dragonruby-game-toolkit-contrib-5bc6d6fa16bcf1da4485e4ccc870f046cc48a522.zip | |
updated GTK::Runtime::Draw to include an execute_draw_order method to make rearranging draw order easier to override and adding resilience to the primitives method
| -rw-r--r-- | dragon/draw.rb | 123 |
1 files changed, 83 insertions, 40 deletions
diff --git a/dragon/draw.rb b/dragon/draw.rb index 0afea16..7f2df9a 100644 --- a/dragon/draw.rb +++ b/dragon/draw.rb @@ -1,3 +1,4 @@ +# Contributors outside of DragonRuby who also hold Copyright: Nick Sandberg # Copyright 2019 DragonRuby LLC # MIT License # draw.rb has been released under MIT (*only this file*). @@ -5,14 +6,71 @@ module GTK class Runtime module Draw + + def execute_draw_order pass + # Don't change this draw order unless you understand + # the implications. + render_static_sprites pass + render_solids pass + render_sprites pass + render_static_solids pass + render_primitives pass + render_static_primitives pass + render_labels pass + render_static_labels pass + render_lines pass + render_static_lines pass + render_borders pass + render_static_borders pass + end + def primitives pass if $top_level.respond_to? :primitives_override return $top_level.tick_render @args, pass end - # Don't change this draw order unless you understand - # the implications. + execute_draw_order pass + + if !$gtk.production + # pass.debug.each { |r| draw_primitive r } + idx = 0 + length = pass.debug.length + while idx < length + draw_primitive (pass.debug.at idx) + idx += 1 + end + + # pass.static_debug.each { |r| draw_primitive r } + idx = 0 + length = pass.static_debug.length + while idx < length + draw_primitive (pass.static_debug.at idx) + idx += 1 + end + end + + # pass.reserved.each { |r| draw_primitive r } + idx = 0 + length = pass.reserved.length + while idx < length + draw_primitive (pass.reserved.at idx) + idx += 1 + end + + # pass.static_reserved.each { |r| draw_primitive r } + idx = 0 + length = pass.static_reserved.length + while idx < length + draw_primitive (pass.static_reserved.at idx) + idx += 1 + end + rescue Exception => e + pause! + pretty_print_exception_and_export! e + end + + def render_solids pass # pass.solids.each { |s| draw_solid s } # while loops are faster than each with block idx = 0 @@ -21,7 +79,9 @@ module GTK draw_solid (pass.solids.at idx) # accessing an array using .value instead of [] is faster idx += 1 end + end + def render_static_solids pass # pass.static_solids.each { |s| draw_solid s } idx = 0 length = pass.static_solids.length @@ -29,7 +89,9 @@ module GTK draw_solid (pass.static_solids.at idx) idx += 1 end + end + def render_sprites pass # pass.sprites.each { |s| draw_sprite s } idx = 0 length = pass.sprites.length @@ -37,7 +99,9 @@ module GTK draw_sprite (pass.sprites.at idx) idx += 1 end + end + def render_static_sprites pass # pass.static_sprites.each { |s| draw_sprite s } idx = 0 length = pass.static_sprites.length @@ -45,7 +109,9 @@ module GTK draw_sprite (pass.static_sprites.at idx) idx += 1 end + end + def render_primitives pass # pass.primitives.each { |p| draw_primitive p } idx = 0 length = pass.primitives.length @@ -53,7 +119,9 @@ module GTK draw_primitive (pass.primitives.at idx) idx += 1 end + end + def render_static_primitives pass # pass.static_primitives.each { |p| draw_primitive p } idx = 0 length = pass.static_primitives.length @@ -61,7 +129,9 @@ module GTK draw_primitive (pass.static_primitives.at idx) idx += 1 end + end + def render_labels pass # pass.labels.each { |l| draw_label l } idx = 0 length = pass.labels.length @@ -69,7 +139,9 @@ module GTK draw_label (pass.labels.at idx) idx += 1 end + end + def render_static_labels pass # pass.static_labels.each { |l| draw_label l } idx = 0 length = pass.static_labels.length @@ -77,7 +149,9 @@ module GTK draw_label (pass.static_labels.at idx) idx += 1 end + end + def render_lines pass # pass.lines.each { |l| draw_line l } idx = 0 length = pass.lines.length @@ -85,7 +159,9 @@ module GTK draw_line (pass.lines.at idx) idx += 1 end - + end + + def render_static_lines pass # pass.static_lines.each { |l| draw_line l } idx = 0 length = pass.static_lines.length @@ -93,7 +169,9 @@ module GTK draw_line (pass.static_lines.at idx) idx += 1 end + end + def render_borders pass # pass.borders.each { |b| draw_border b } idx = 0 length = pass.borders.length @@ -101,7 +179,9 @@ module GTK draw_border (pass.borders.at idx) idx += 1 end + end + def render_static_borders pass # pass.static_borders.each { |b| draw_border b } idx = 0 length = pass.static_borders.length @@ -109,43 +189,6 @@ module GTK draw_border (pass.static_borders.at idx) idx += 1 end - - if !$gtk.production - # pass.debug.each { |r| draw_primitive r } - idx = 0 - length = pass.debug.length - while idx < length - draw_primitive (pass.debug.at idx) - idx += 1 - end - - # pass.static_debug.each { |r| draw_primitive r } - idx = 0 - length = pass.static_debug.length - while idx < length - draw_primitive (pass.static_debug.at idx) - idx += 1 - end - end - - # pass.reserved.each { |r| draw_primitive r } - idx = 0 - length = pass.reserved.length - while idx < length - draw_primitive (pass.reserved.at idx) - idx += 1 - end - - # pass.static_reserved.each { |r| draw_primitive r } - idx = 0 - length = pass.static_reserved.length - while idx < length - draw_primitive (pass.static_reserved.at idx) - idx += 1 - end - rescue Exception => e - pause! - pretty_print_exception_and_export! e end def draw_solid s |
