diff --git a/lib/overlay.rb b/lib/overlay.rb index b36b99f..b1d669a 100644 --- a/lib/overlay.rb +++ b/lib/overlay.rb @@ -1,17 +1,59 @@ class IMICFPS class Overlay include CommonMethods + + Slot = Struct.new(:value, :width) + 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 def draw - Gosu.draw_rect(0, 0, 256, 20, Gosu::Color.rgba(0, 0, 0, 100)) - Gosu.draw_rect(2, 2, 256 - 4, 20 - 4, Gosu::Color.rgba(100, 100, 100, 100)) - @text.x = 3 - @text.y = 3 - @text.text = "FPS: #{Gosu.fps}" + return if @text.text.empty? + width = @text.width + 8 + + Gosu.draw_rect(0, 0, width, (@text.height + 4), Gosu::Color.rgba(0, 0, 0, 100)) + Gosu.draw_rect(2, 2, width - 4, (@text.height + 4) - 4, Gosu::Color.rgba(100, 100, 100, 100)) + @text.draw 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} | " 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 \ No newline at end of file diff --git a/lib/states/game_states/game.rb b/lib/states/game_states/game.rb index 0aa1e1b..2b687eb 100644 --- a/lib/states/game_states/game.rb +++ b/lib/states/game_states/game.rb @@ -12,7 +12,7 @@ class IMICFPS @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") @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) @text.text = update_text - elsif window.config.get(:options, :fps) - @text.text = "FPS: #{Gosu.fps}" else @text.text = "" end @demo.update if @demo - - window.number_of_vertices = 0 end def update_text @@ -66,10 +62,6 @@ Camera Field Of View: #{@camera.field_of_view} 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} -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 end diff --git a/lib/tools/map_editor/lib/main_menu.rb b/lib/tools/map_editor/lib/main_menu.rb index d61d43f..63c39d2 100644 --- a/lib/tools/map_editor/lib/main_menu.rb +++ b/lib/tools/map_editor/lib/main_menu.rb @@ -30,7 +30,6 @@ class IMICFPS @maps.each do |map| button map.metadata.name do push_state(Editor, map_parser: map) - # push_state(TurnTable, manifest: manifest) end end end diff --git a/lib/window.rb b/lib/window.rb index 2502b2c..fa91cdc 100644 --- a/lib/window.rb +++ b/lib/window.rb @@ -67,6 +67,9 @@ class IMICFPS super @console.update if @show_console + @overlay.update + + @number_of_vertices = 0 @delta_time = Gosu.milliseconds end