mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-13 06:42:35 +00:00
Use persistent hash for config
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
*.dat
|
||||
profile.*
|
||||
pkg/*
|
||||
pkg/*
|
||||
data/*
|
||||
!data/.gitkeep
|
||||
|
||||
1
data/.gitkeep
Normal file
1
data/.gitkeep
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
@@ -48,7 +48,7 @@ class IMICFPS
|
||||
if e != GL_NO_ERROR
|
||||
$stderr.puts "OpenGL error detected by handler at: #{caller[0]}"
|
||||
$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
|
||||
|
||||
@@ -38,7 +38,7 @@ class IMICFPS
|
||||
if CACHE[@type].is_a?(Hash)
|
||||
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)
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
@@ -23,7 +23,7 @@ class IMICFPS
|
||||
|
||||
def available_light
|
||||
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}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -33,7 +33,7 @@ class IMICFPS
|
||||
|
||||
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")
|
||||
allocate_gl_objects
|
||||
@@ -43,7 +43,7 @@ class IMICFPS
|
||||
|
||||
@objects.each {|o| @vertex_count+=o.vertices.size}
|
||||
@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
|
||||
window.number_of_vertices+=@vertex_count
|
||||
@has_texture = false
|
||||
@@ -56,7 +56,7 @@ class IMICFPS
|
||||
|
||||
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
|
||||
# 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
|
||||
|
||||
def parse(parser)
|
||||
@@ -214,7 +214,7 @@ class IMICFPS
|
||||
@aabb_tree.insert(face, box)
|
||||
end
|
||||
|
||||
puts @aabb_tree.inspect if $debug.get(:stats)
|
||||
puts @aabb_tree.inspect if window.config.get(:debug_options, :stats)
|
||||
end
|
||||
|
||||
def update
|
||||
|
||||
@@ -102,7 +102,7 @@ class IMICFPS
|
||||
glColorPointer(3, GL_FLOAT, 0, o.flattened_materials)
|
||||
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)
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
|
||||
glPolygonOffset(2, 0.5)
|
||||
|
||||
@@ -16,14 +16,14 @@ class IMICFPS
|
||||
entities.each do |object|
|
||||
if object.visible && object.renderable
|
||||
# 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)
|
||||
end
|
||||
end
|
||||
|
||||
# @bounding_box_renderer.draw_bounding_boxes if $debug.get(:boundingboxes)
|
||||
# window.number_of_vertices+=@bounding_box_renderer.vertex_count 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 window.config.get(:debug_options, :boundingboxes)
|
||||
# @bounding_box_renderer.bounding_boxes.clear
|
||||
end
|
||||
|
||||
|
||||
@@ -40,9 +40,9 @@ class IMICFPS
|
||||
|
||||
@camera.update
|
||||
|
||||
if $debug.get(:stats)
|
||||
if window.config.get(:debug_options, :stats)
|
||||
@text.text = update_text
|
||||
elsif $debug.get(:fps)
|
||||
elsif window.config.get(:options, :fps)
|
||||
@text.text = "FPS: #{Gosu.fps}"
|
||||
else
|
||||
@text.text = ""
|
||||
|
||||
@@ -55,7 +55,7 @@ class IMICFPS
|
||||
when :model
|
||||
ModelLoader.new(manifest: hash[:manifest], entity: @dummy_entity)
|
||||
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")
|
||||
else
|
||||
warn "Skipping shader: #{hash[:name]}..."
|
||||
|
||||
@@ -9,16 +9,17 @@ class IMICFPS
|
||||
:debug
|
||||
end
|
||||
|
||||
def setup
|
||||
$debug = self
|
||||
def set(key, value)
|
||||
$window.config[:debug_options, key] = value
|
||||
end
|
||||
|
||||
set(:boundingboxes, false)
|
||||
set(:wireframe, false)
|
||||
set(:stats, false)
|
||||
set(:fps, false)
|
||||
set(:skydome, true)
|
||||
set(:use_shaders, true)
|
||||
set(:opengl_error_panic, false)
|
||||
def setup
|
||||
set(:boundingboxes, false) if $window.config.get(:debug_options, :boundingboxes).nil?
|
||||
set(:wireframe, false) if $window.config.get(:debug_options, :wireframe).nil?
|
||||
set(:stats, false) if $window.config.get(:debug_options, :stats).nil?
|
||||
set(:skydome, true) if $window.config.get(:debug_options, :skydome).nil?
|
||||
set(:use_shaders, true) if $window.config.get(:debug_options, :use_shaders).nil?
|
||||
set(:opengl_error_panic, false) if $window.config.get(:debug_options, :opengl_error_panic).nil?
|
||||
|
||||
subcommand(:boundingboxes, :boolean)
|
||||
subcommand(:wireframe, :boolean)
|
||||
|
||||
@@ -17,12 +17,12 @@ class IMICFPS
|
||||
|
||||
case arguments.last
|
||||
when "", nil
|
||||
console.stdin("#{Style.highlight("fps")}: #{$debug.get(:fps)}")
|
||||
console.stdin("#{Style.highlight("fps")}: #{$window.config.get(:options, :fps)}")
|
||||
when "on"
|
||||
var = $debug.set(:fps, true)
|
||||
var = $window.config[:options, :fps] = true
|
||||
console.stdin("fps => #{Style.highlight(var)}")
|
||||
when "off"
|
||||
var = $debug.set(:fps, false)
|
||||
var = $window.config[:options, :fps] = false
|
||||
console.stdin("fps => #{Style.highlight(var)}")
|
||||
else
|
||||
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
|
||||
|
||||
@@ -72,7 +72,7 @@ class IMICFPS
|
||||
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.objects.each do |o|
|
||||
@model.calculate_bounding_box(o.vertices, o.bounding_box)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class IMICFPS
|
||||
class Window < CyberarmEngine::Engine
|
||||
attr_accessor :number_of_vertices, :needs_cursor
|
||||
attr_reader :camera
|
||||
attr_reader :camera, :config
|
||||
|
||||
attr_reader :console, :delta_time
|
||||
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})"
|
||||
|
||||
@config = CyberarmEngine::ConfigFile.new(file: IMICFPS::GAME_ROOT_PATH + "/data/config.json")
|
||||
@show_console = false
|
||||
@console = Console.new
|
||||
Commands::Command.setup
|
||||
|
||||
at_exit do
|
||||
@config.save!
|
||||
end
|
||||
|
||||
push_state(MainMenu)
|
||||
|
||||
@delta_time = Gosu.milliseconds
|
||||
@@ -39,7 +44,7 @@ class IMICFPS
|
||||
|
||||
def draw_cursor
|
||||
size = 16
|
||||
|
||||
|
||||
if needs_cursor
|
||||
@cursor.draw(mouse_x, mouse_y, Float::INFINITY)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user