Use persistent hash for config

This commit is contained in:
2020-01-29 18:18:46 -06:00
parent 201ddabbcc
commit 4f1b490600
14 changed files with 40 additions and 31 deletions

4
.gitignore vendored
View File

@@ -1,3 +1,5 @@
*.dat *.dat
profile.* profile.*
pkg/* pkg/*
data/*
!data/.gitkeep

1
data/.gitkeep Normal file
View File

@@ -0,0 +1 @@

View File

@@ -48,7 +48,7 @@ class IMICFPS
if e != GL_NO_ERROR if e != GL_NO_ERROR
$stderr.puts "OpenGL error detected by handler at: #{caller[0]}" $stderr.puts "OpenGL error detected by handler at: #{caller[0]}"
$stderr.puts " #{gluErrorString(e)} (#{e})\n" $stderr.puts " #{gluErrorString(e)} (#{e})\n"
exit if $debug && $debug.get(:opengl_error_panic) exit if window.config.get(:debug_options, :opengl_error_panic)
end end
end end
end end

View File

@@ -38,7 +38,7 @@ class IMICFPS
if CACHE[@type].is_a?(Hash) if CACHE[@type].is_a?(Hash)
if CACHE[@type][@model_file] if CACHE[@type][@model_file]
@model = CACHE[@type][@model_file]#.dup # Don't know why, but adding .dup improves performance with Sponza (1 fps -> 20 fps) @model = CACHE[@type][@model_file]#.dup # Don't know why, but adding .dup improves performance with Sponza (1 fps -> 20 fps)
puts "Used cached model for: #{@model_file.split('/').last}" if $debug.get(:stats) puts "Used cached model for: #{@model_file.split('/').last}" if $window.config.get(:debug_options, :stats)
found = true found = true
end end
end end

View File

@@ -23,7 +23,7 @@ class IMICFPS
def available_light def available_light
raise "Using to many lights, #{light_count}/#{LightManager::MAX_LIGHTS}" if light_count > LightManager::MAX_LIGHTS raise "Using to many lights, #{light_count}/#{LightManager::MAX_LIGHTS}" if light_count > LightManager::MAX_LIGHTS
puts "OpenGL::GL_LIGHT#{light_count}" if $debug.get(:stats) puts "OpenGL::GL_LIGHT#{light_count}" if $window.config.get(:debug_options, :stats)
Object.const_get "OpenGL::GL_LIGHT#{light_count}" Object.const_get "OpenGL::GL_LIGHT#{light_count}"
end end
end end

View File

@@ -33,7 +33,7 @@ class IMICFPS
parse(parser) parse(parser)
puts "#{@file_path.split('/').last} took #{((Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)-start_time)/1000.0).round(2)} seconds to parse" if $debug.get(:stats) puts "#{@file_path.split('/').last} took #{((Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)-start_time)/1000.0).round(2)} seconds to parse" if window.config.get(:debug_options, :stats)
if Shader.available?("default") if Shader.available?("default")
allocate_gl_objects allocate_gl_objects
@@ -43,7 +43,7 @@ class IMICFPS
@objects.each {|o| @vertex_count+=o.vertices.size} @objects.each {|o| @vertex_count+=o.vertices.size}
@objects.each_with_index do |o, i| @objects.each_with_index do |o, i|
puts " Model::Object Name: #{o.name}, Vertices: #{o.vertices.size}" if $debug.get(:stats) puts " Model::Object Name: #{o.name}, Vertices: #{o.vertices.size}" if window.config.get(:debug_options, :stats)
end end
window.number_of_vertices+=@vertex_count window.number_of_vertices+=@vertex_count
@has_texture = false @has_texture = false
@@ -56,7 +56,7 @@ class IMICFPS
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond) start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
# build_collision_tree # build_collision_tree
puts " Building mesh collision tree took #{((Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)-start_time)/1000.0).round(2)} seconds" if $debug.get(:stats) puts " Building mesh collision tree took #{((Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)-start_time)/1000.0).round(2)} seconds" if window.config.get(:debug_options, :stats)
end end
def parse(parser) def parse(parser)
@@ -214,7 +214,7 @@ class IMICFPS
@aabb_tree.insert(face, box) @aabb_tree.insert(face, box)
end end
puts @aabb_tree.inspect if $debug.get(:stats) puts @aabb_tree.inspect if window.config.get(:debug_options, :stats)
end end
def update def update

View File

@@ -102,7 +102,7 @@ class IMICFPS
glColorPointer(3, GL_FLOAT, 0, o.flattened_materials) glColorPointer(3, GL_FLOAT, 0, o.flattened_materials)
glNormalPointer(GL_FLOAT, 0, o.flattened_normals) glNormalPointer(GL_FLOAT, 0, o.flattened_normals)
if $debug.get(:wireframe) # This is kinda expensive if window.config.get(:debug_options, :wireframe) # This is kinda expensive
glDisable(GL_LIGHTING) glDisable(GL_LIGHTING)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
glPolygonOffset(2, 0.5) glPolygonOffset(2, 0.5)

View File

@@ -16,14 +16,14 @@ class IMICFPS
entities.each do |object| entities.each do |object|
if object.visible && object.renderable if object.visible && object.renderable
# Render bounding boxes before transformation is applied # Render bounding boxes before transformation is applied
# @bounding_box_renderer.create_bounding_box(object, object.model.bounding_box, object.debug_color, object.object_id) if $debug.get(:boundingboxes) # @bounding_box_renderer.create_bounding_box(object, object.model.bounding_box, object.debug_color, object.object_id) if window.config.get(:debug_options, :boundingboxes)
@opengl_renderer.draw_object(camera, lights, object) @opengl_renderer.draw_object(camera, lights, object)
end end
end end
# @bounding_box_renderer.draw_bounding_boxes if $debug.get(:boundingboxes) # @bounding_box_renderer.draw_bounding_boxes if window.config.get(:debug_options, :boundingboxes)
# window.number_of_vertices+=@bounding_box_renderer.vertex_count if $debug.get(:boundingboxes) # window.number_of_vertices+=@bounding_box_renderer.vertex_count if window.config.get(:debug_options, :boundingboxes)
# @bounding_box_renderer.bounding_boxes.clear # @bounding_box_renderer.bounding_boxes.clear
end end

View File

@@ -40,9 +40,9 @@ class IMICFPS
@camera.update @camera.update
if $debug.get(:stats) if window.config.get(:debug_options, :stats)
@text.text = update_text @text.text = update_text
elsif $debug.get(:fps) elsif window.config.get(:options, :fps)
@text.text = "FPS: #{Gosu.fps}" @text.text = "FPS: #{Gosu.fps}"
else else
@text.text = "" @text.text = ""

View File

@@ -55,7 +55,7 @@ class IMICFPS
when :model when :model
ModelLoader.new(manifest: hash[:manifest], entity: @dummy_entity) ModelLoader.new(manifest: hash[:manifest], entity: @dummy_entity)
when :shader when :shader
if $debug.get(:use_shaders) if window.config.get(:debug_options, :use_shaders)
shader = Shader.new(name: hash[:name], includes_dir: "shaders/include", vertex: "shaders/vertex/#{hash[:name]}.glsl", fragment: "shaders/fragment/#{hash[:name]}.glsl") shader = Shader.new(name: hash[:name], includes_dir: "shaders/include", vertex: "shaders/vertex/#{hash[:name]}.glsl", fragment: "shaders/fragment/#{hash[:name]}.glsl")
else else
warn "Skipping shader: #{hash[:name]}..." warn "Skipping shader: #{hash[:name]}..."

View File

@@ -9,16 +9,17 @@ class IMICFPS
:debug :debug
end end
def setup def set(key, value)
$debug = self $window.config[:debug_options, key] = value
end
set(:boundingboxes, false) def setup
set(:wireframe, false) set(:boundingboxes, false) if $window.config.get(:debug_options, :boundingboxes).nil?
set(:stats, false) set(:wireframe, false) if $window.config.get(:debug_options, :wireframe).nil?
set(:fps, false) set(:stats, false) if $window.config.get(:debug_options, :stats).nil?
set(:skydome, true) set(:skydome, true) if $window.config.get(:debug_options, :skydome).nil?
set(:use_shaders, true) set(:use_shaders, true) if $window.config.get(:debug_options, :use_shaders).nil?
set(:opengl_error_panic, false) set(:opengl_error_panic, false) if $window.config.get(:debug_options, :opengl_error_panic).nil?
subcommand(:boundingboxes, :boolean) subcommand(:boundingboxes, :boolean)
subcommand(:wireframe, :boolean) subcommand(:wireframe, :boolean)

View File

@@ -17,12 +17,12 @@ class IMICFPS
case arguments.last case arguments.last
when "", nil when "", nil
console.stdin("#{Style.highlight("fps")}: #{$debug.get(:fps)}") console.stdin("#{Style.highlight("fps")}: #{$window.config.get(:options, :fps)}")
when "on" when "on"
var = $debug.set(:fps, true) var = $window.config[:options, :fps] = true
console.stdin("fps => #{Style.highlight(var)}") console.stdin("fps => #{Style.highlight(var)}")
when "off" when "off"
var = $debug.set(:fps, false) var = $window.config[:options, :fps] = false
console.stdin("fps => #{Style.highlight(var)}") console.stdin("fps => #{Style.highlight(var)}")
else else
console.stdin("Invalid argument for #{Style.highlight("#{command}")}, got #{Style.error(arguments.last)} expected #{Style.notice("on")}, or #{Style.notice("off")}.") console.stdin("Invalid argument for #{Style.highlight("#{command}")}, got #{Style.error(arguments.last)} expected #{Style.notice("on")}, or #{Style.notice("off")}.")
@@ -34,4 +34,4 @@ class IMICFPS
end end
end end
end end
end end

View File

@@ -72,7 +72,7 @@ class IMICFPS
end end
end end
puts "Total Lines: #{lines}" if $debug.get(:stats) puts "Total Lines: #{lines}" if $window.config.get(:debug_options, :stats)
@model.calculate_bounding_box(@model.vertices, @model.bounding_box) @model.calculate_bounding_box(@model.vertices, @model.bounding_box)
@model.objects.each do |o| @model.objects.each do |o|
@model.calculate_bounding_box(o.vertices, o.bounding_box) @model.calculate_bounding_box(o.vertices, o.bounding_box)

View File

@@ -1,7 +1,7 @@
class IMICFPS class IMICFPS
class Window < CyberarmEngine::Engine class Window < CyberarmEngine::Engine
attr_accessor :number_of_vertices, :needs_cursor attr_accessor :number_of_vertices, :needs_cursor
attr_reader :camera attr_reader :camera, :config
attr_reader :console, :delta_time attr_reader :console, :delta_time
def initialize(window_width = 1280, window_height = 720, fullscreen = false) def initialize(window_width = 1280, window_height = 720, fullscreen = false)
@@ -18,10 +18,15 @@ class IMICFPS
self.caption = "#{IMICFPS::NAME} v#{IMICFPS::VERSION} (#{IMICFPS::RELEASE_NAME})" self.caption = "#{IMICFPS::NAME} v#{IMICFPS::VERSION} (#{IMICFPS::RELEASE_NAME})"
@config = CyberarmEngine::ConfigFile.new(file: IMICFPS::GAME_ROOT_PATH + "/data/config.json")
@show_console = false @show_console = false
@console = Console.new @console = Console.new
Commands::Command.setup Commands::Command.setup
at_exit do
@config.save!
end
push_state(MainMenu) push_state(MainMenu)
@delta_time = Gosu.milliseconds @delta_time = Gosu.milliseconds
@@ -39,7 +44,7 @@ class IMICFPS
def draw_cursor def draw_cursor
size = 16 size = 16
if needs_cursor if needs_cursor
@cursor.draw(mouse_x, mouse_y, Float::INFINITY) @cursor.draw(mouse_x, mouse_y, Float::INFINITY)
end end