summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmir Rajan <[email protected]>2020-09-11 02:02:24 -0500
committerAmir Rajan <[email protected]>2020-09-11 02:02:57 -0500
commite28637fc73295b59181f3e105bb6f3dc753531eb (patch)
treedaff4f73049f3f670ce79231bdb16ecda463d517
parent33ec37b141e896b47ed642923fd33b0c658ae9fb (diff)
downloaddragonruby-game-toolkit-contrib-e28637fc73295b59181f3e105bb6f3dc753531eb.tar.gz
dragonruby-game-toolkit-contrib-e28637fc73295b59181f3e105bb6f3dc753531eb.zip
synced with v1.19
-rw-r--r--dragon/console.rb13
-rw-r--r--dragon/console_menu.rb39
-rw-r--r--dragon/framerate_diagnostics.rb165
-rw-r--r--dragon/readme_docs.rb35
4 files changed, 218 insertions, 34 deletions
diff --git a/dragon/console.rb b/dragon/console.rb
index c90755a..965a459 100644
--- a/dragon/console.rb
+++ b/dragon/console.rb
@@ -727,12 +727,11 @@ S
end
def include_header_marker? log_entry
- return false if log_entry.include? "NOTIFY:"
- return false if log_entry.include? "INFO:"
- return true if log_entry.include? "DOCS:"
- (log_entry.start_with? "* ") ||
- (log_entry.start_with? "** ") ||
- (log_entry.start_with? "*** ")
+ return false if (log_entry.strip.include? ".rb")
+ (log_entry.start_with? "* ") ||
+ (log_entry.start_with? "** ") ||
+ (log_entry.start_with? "*** ") ||
+ (log_entry.start_with? "**** ")
end
def color_for_log_entry(log_entry)
@@ -744,7 +743,7 @@ S
@text_color.mult_alpha(0.5)
elsif include_header_marker? log_entry
@header_color
- elsif log_entry.start_with?("====") || log_entry.include?("app") && !log_entry.include?("apple")
+ elsif log_entry.start_with?("====")
@header_color
else
@text_color
diff --git a/dragon/console_menu.rb b/dragon/console_menu.rb
index e8ce973..e7f43ce 100644
--- a/dragon/console_menu.rb
+++ b/dragon/console_menu.rb
@@ -29,22 +29,39 @@ module GTK
@console.scroll_down_half
end
+ def show_menu_clicked
+ @menu_shown = :visible
+ end
+
def close_clicked
+ @menu_shown = :hidden
@console.hide
end
+ def framerate_diagnostics_clicked
+ $gtk.framerate_diagnostics
+ end
+
def tick args
return unless @console.visible?
- # defaults
- @buttons = [
- (button id: :record, row: 0, col: 15, text: "record", method: :record_clicked),
- (button id: :replay, row: 0, col: 16, text: "replay", method: :replay_clicked),
- (button id: :reset, row: 0, col: 17, text: "reset", method: :reset_clicked),
- (button id: :scroll_up, row: 0, col: 18, text: "scroll up", method: :scroll_up_clicked),
- (button id: :scroll_down, row: 0, col: 19, text: "scroll down", method: :scroll_down_clicked),
- (button id: :close, row: 0, col: 20, text: "close", method: :close_clicked),
- ]
+ @menu_shown ||= :hidden
+
+ if @menu_shown == :hidden
+ @buttons = [
+ (button id: :show_menu, row: 0, col: 10, text: "show menu", method: :show_menu_clicked),
+ ]
+ else
+ @buttons = [
+ (button id: :record, row: 0, col: 4, text: "framerate diagnostics", method: :framerate_diagnostics_clicked),
+ (button id: :record, row: 0, col: 5, text: "record", method: :record_clicked),
+ (button id: :replay, row: 0, col: 6, text: "replay", method: :replay_clicked),
+ (button id: :reset, row: 0, col: 7, text: "reset", method: :reset_clicked),
+ (button id: :scroll_up, row: 0, col: 8, text: "scroll up", method: :scroll_up_clicked),
+ (button id: :scroll_down, row: 0, col: 9, text: "scroll down", method: :scroll_down_clicked),
+ (button id: :close, row: 0, col: 10, text: "close", method: :close_clicked),
+ ]
+ end
# render
args.outputs.reserved << @buttons.map { |b| b[:primitives] }
@@ -59,13 +76,13 @@ module GTK
end
def rect_for_layout row, col
- col_width = 50
+ col_width = 100
row_height = 50
col_margin = 5
row_margin = 5
x = (col_margin + (col * col_width) + (col * col_margin))
y = (row_margin + (row * row_height) + (row * row_margin) + row_height).from_top
- { x: x, y: y, w: row_height, h: col_width }
+ { x: x, y: y, w: col_width, h: row_height }
end
def button args
diff --git a/dragon/framerate_diagnostics.rb b/dragon/framerate_diagnostics.rb
new file mode 100644
index 0000000..6b952bd
--- /dev/null
+++ b/dragon/framerate_diagnostics.rb
@@ -0,0 +1,165 @@
+# Copyright 2019 DragonRuby LLC
+# MIT License
+# framerate_diagnostics.rb has been released under MIT (*only this file*).
+
+module GTK
+ class Runtime
+ # @visibility private
+ module FramerateDiagnostics
+ def framerate_get_diagnostics
+ <<-S
+* INFO: Framerate Diagnostics
+You can display these diagnostics using:
+
+#+begin_src
+ args.outputs.debug << args.gtk.framerate_diagnostics_primitives
+#+end_src
+
+** Draw Calls: ~<<~ Invocation Perf Counter
+Here is how many times ~args.outputs.PRIMITIVE_ARRAY <<~ was called:
+
+ #{$perf_counter_outputs_push_count} times invoked.
+
+If the number above is high, consider batching primitives so you can lower the invocation of ~<<~. For example.
+
+Instead of:
+
+#+begin_src
+ args.state.enemies.map do |e|
+ e.alpha = 128
+ args.outputs.sprites << e # <-- ~args.outputs.sprites <<~ is invoked a lot
+ end
+#+end_src
+
+Do this:
+
+#+begin_src
+ args.outputs.sprites << args.state
+ .enemies
+ .map do |e| # <-- ~args.outputs.sprites <<~ is only invoked once.
+ e.alpha = 128
+ e
+ end
+#+end_src
+
+** Array Primitives
+~Primitives~ represented as an ~Array~ (~Tuple~) are great for prototyping, but are not as performant as using a ~Hash~.
+
+Here is the number of ~Array~ primitives that were encountered:
+
+ #{$perf_counter_primitive_is_array} Array Primitives.
+
+If the number above is high, consider converting them to hashes. For example.
+
+Instead of:
+
+#+begin_src
+ args.outputs.sprites << [0, 0, 100, 100, 'sprites/enemy.png']
+#+begin_end
+
+Do this:
+
+#+begin_src
+ args.outputs.sprites << { x: 0,
+ y: 0,
+ w: 100,
+ h: 100,
+ path: 'sprites/enemy.png' }
+#+begin_end
+
+** Primitive Counts
+Here are the draw counts ordered by lowest to highest z order:
+
+PRIMITIVE COUNT, STATIC COUNT
+solids: #{@args.outputs.solids.length}, #{@args.outputs.static_solids.length}
+sprites: #{@args.outputs.sprites.length}, #{@args.outputs.static_sprites.length}
+primitives: #{@args.outputs.primitives.length}, #{@args.outputs.static_primitives.length}
+labels: #{@args.outputs.labels.length}, #{@args.outputs.static_labels.length}
+lines: #{@args.outputs.lines.length}, #{@args.outputs.static_lines.length}
+borders: #{@args.outputs.borders.length}, #{@args.outputs.static_borders.length}
+debug: #{@args.outputs.debug.length}, #{@args.outputs.static_debug.length}
+reserved: #{@args.outputs.reserved.length}, #{@args.outputs.static_reserved.length}
+
+** Additional Help
+Come to the DragonRuby Discord channel if you need help troubleshooting performance issues. http://discord.dragonruby.org.
+
+Source code for these diagnostics can be found at: [[https://github.com/dragonruby/dragonruby-game-toolkit-contrib/]]
+S
+ end
+
+ def framerate_warning_message
+ <<-S
+* WARNING:
+Your average framerate dropped below 60 fps for two seconds.
+
+The average FPS was #{current_framerate}.
+
+** How To Disable Warning
+If this warning is getting annoying put the following in your tick method:
+
+#+begin_src
+ args.gtk.log_level = :off
+#+end_src
+
+#{framerate_get_diagnostics}
+ S
+ end
+
+ def current_framerate_primitives
+ framerate_diagnostics_primitives
+ end
+
+ def framerate_diagnostics_primitives
+ [
+ { x: 0, y: 93.from_top, w: 500, h: 93, a: 128 }.solid,
+ {
+ x: 5,
+ y: 5.from_top,
+ text: "More Info via DragonRuby Console: $gtk.framerate_diagnostics",
+ r: 255,
+ g: 255,
+ b: 255,
+ size_enum: -2
+ }.label,
+ {
+ x: 5,
+ y: 20.from_top,
+ text: "FPS: %.2f" % args.gtk.current_framerate,
+ r: 255,
+ g: 255,
+ b: 255,
+ size_enum: -2
+ }.label,
+ {
+ x: 5,
+ y: 35.from_top,
+ text: "Draw Calls: #{$perf_counter_outputs_push_count}",
+ r: 255,
+ g: 255,
+ b: 255,
+ size_enum: -2
+ }.label,
+ {
+ x: 5,
+ y: 50.from_top,
+ text: "Array Primitives: #{$perf_counter_primitive_is_array}",
+ r: 255,
+ g: 255,
+ b: 255,
+ size_enum: -2
+ }.label,
+ {
+ x: 5,
+ y: 65.from_top,
+ text: "Mouse: #{@args.inputs.mouse.point}",
+ r: 255,
+ g: 255,
+ b: 255,
+ size_enum: -2
+ }.label,
+ ]
+ end
+
+ end
+ end
+end
diff --git a/dragon/readme_docs.rb b/dragon/readme_docs.rb
index 39fc283..92a23b0 100644
--- a/dragon/readme_docs.rb
+++ b/dragon/readme_docs.rb
@@ -240,13 +240,16 @@ Here's a fun Ruby thing: ~args.state.rotation ||= 0~ is shorthand for
nice way to embed your initialization code right next to where you
need the variable.
-~args.state~ is a place you can hang your own data and have it survive
-past the life of the function call. In this case, the current rotation
-of our sprite, which is happily spinning at 60 frames per second. If
-you don't specify rotation (or alpha, or color modulation, or a source
-rectangle, etc), DragonRuby picks a reasonable default, and the array
-is ordered by the most likely things you need to tell us: position,
-size, name.
+
+~args.state~ is a place you can hang your own data. It's an open data
+structure that allows you to define properties that are arbitrarily
+nested. You don't need to define any kind of class.
+
+In this case, the current rotation of our sprite, which is happily
+spinning at 60 frames per second. If you don't specify rotation (or
+alpha, or color modulation, or a source rectangle, etc), DragonRuby
+picks a reasonable default, and the array is ordered by the most
+likely things you need to tell us: position, size, name.
** There Is No Delta Time
@@ -894,25 +897,25 @@ sure_ you've initialized a default value.
#+begin_src
def tick args
# initialize your game state ONCE
- args.player.x ||= 0
- args.player.y ||= 0
- args.player.hp ||= 100
+ args.state.player.x ||= 0
+ args.state.player.y ||= 0
+ args.state.player.hp ||= 100
# increment the x position of the character by one every frame
- args.player.x += 1
+ args.state.player.x += 1
# Render a sprite with a label above the sprite
args.outputs.sprites << [
- args.player.x,
- args.player.y,
+ args.state.player.x,
+ args.state.player.y,
32, 32,
"player.png"
]
args.outputs.labels << [
- args.player.x,
- args.player.y - 50,
- args.player.hp
+ args.state.player.x,
+ args.state.player.y - 50,
+ args.state.player.hp
]
end
#+end_src