Moved renderer stats to Overlay

This commit is contained in:
2020-05-03 09:40:51 -05:00
parent 9593d341bf
commit c05009a000
4 changed files with 52 additions and 16 deletions

View File

@@ -1,17 +1,59 @@
class IMICFPS class IMICFPS
class Overlay class Overlay
include CommonMethods include CommonMethods
Slot = Struct.new(:value, :width)
def initialize def initialize
@text = CyberarmEngine::Text.new("") @text = CyberarmEngine::Text.new("", x: 3, y: 3, shadow_color: Gosu::Color::BLACK)
@slots = []
@space_width = @text.textobject.text_width(" ")
end end
def draw def draw
Gosu.draw_rect(0, 0, 256, 20, Gosu::Color.rgba(0, 0, 0, 100)) return if @text.text.empty?
Gosu.draw_rect(2, 2, 256 - 4, 20 - 4, Gosu::Color.rgba(100, 100, 100, 100)) width = @text.width + 8
@text.x = 3
@text.y = 3 Gosu.draw_rect(0, 0, width, (@text.height + 4), Gosu::Color.rgba(0, 0, 0, 100))
@text.text = "FPS: #{Gosu.fps}" Gosu.draw_rect(2, 2, width - 4, (@text.height + 4) - 4, Gosu::Color.rgba(100, 100, 100, 100))
@text.draw @text.draw
end end
def update
rebuild_slots
end
def rebuild_slots
@slots.clear
if window.config.get(:options, :fps)
create_slot "FPS: #{Gosu.fps}"
create_slot "Frame time: #{Gosu.milliseconds - window.delta_time}ms" if window.config.get(:debug_options, :stats)
end
if window.config.get(:debug_options, :stats)
create_slot "Vertices: #{formatted_number(window.number_of_vertices)}"
create_slot "Face: #{formatted_number(window.number_of_vertices / 3)}"
end
if window.config.get(:debug_options, :boundingboxes)
create_slot "Boundingboxes: #{window.config.get(:debug_options, :boundingboxes) ? 'On' : 'Off'}"
end
if window.config.get(:debug_options, :wireframe)
create_slot "Wireframes: #{window.config.get(:debug_options, :wireframe) ? 'On' : 'Off'}"
end
@text.text = ""
@slots.each_with_index do |slot, i|
@text.text += "#{slot.value} <c=ff000000>|</c> " unless i == @slots.size - 1
@text.text += "#{slot.value}" if i == @slots.size - 1
end
end
def create_slot(string)
@slots << Slot.new(string, @text.textobject.text_width(string))
end
end end
end end

View File

@@ -12,7 +12,7 @@ class IMICFPS
@crosshair = Crosshair.new @crosshair = Crosshair.new
@text = Text.new("Pending...", x: 10, y: 10, z: 1, size: 18, font: "DejaVu Sans", shadow_color: Gosu::Color::BLACK) @text = Text.new("Pending...", x: 10, y: 22, z: 1, size: 18, font: "DejaVu Sans", shadow_color: Gosu::Color::BLACK)
if ARGV.join.include?("--playdemo") if ARGV.join.include?("--playdemo")
@demo = Demo.new(camera: @camera, player: @player, demo: "./demo.dat", mode: :play) if File.exist?("./demo.dat") @demo = Demo.new(camera: @camera, player: @player, demo: "./demo.dat", mode: :play) if File.exist?("./demo.dat")
@@ -42,15 +42,11 @@ class IMICFPS
if window.config.get(:debug_options, :stats) if window.config.get(:debug_options, :stats)
@text.text = update_text @text.text = update_text
elsif window.config.get(:options, :fps)
@text.text = "FPS: #{Gosu.fps}"
else else
@text.text = "" @text.text = ""
end end
@demo.update if @demo @demo.update if @demo
window.number_of_vertices = 0
end end
def update_text def update_text
@@ -66,10 +62,6 @@ Camera Field Of View: #{@camera.field_of_view}
Camera Mouse Sesitivity: #{@camera.mouse_sensitivity} Camera Mouse Sesitivity: #{@camera.mouse_sensitivity}
#{if @camera.entity then "Actor X: #{@camera.entity.position.x.round(2)} Y: #{@camera.entity.position.y.round(2)} Z: #{@camera.entity.position.z.round(2)}";end} #{if @camera.entity then "Actor X: #{@camera.entity.position.x.round(2)} Y: #{@camera.entity.position.y.round(2)} Z: #{@camera.entity.position.z.round(2)}";end}
Last Frame: #{Gosu.milliseconds - window.delta_time}ms (#{Gosu.fps} fps)
Vertices: #{formatted_number(window.number_of_vertices)}
Faces: #{formatted_number(window.number_of_vertices/3)}
eos eos
end end

View File

@@ -30,7 +30,6 @@ class IMICFPS
@maps.each do |map| @maps.each do |map|
button map.metadata.name do button map.metadata.name do
push_state(Editor, map_parser: map) push_state(Editor, map_parser: map)
# push_state(TurnTable, manifest: manifest)
end end
end end
end end

View File

@@ -67,6 +67,9 @@ class IMICFPS
super super
@console.update if @show_console @console.update if @show_console
@overlay.update
@number_of_vertices = 0
@delta_time = Gosu.milliseconds @delta_time = Gosu.milliseconds
end end