Renamed objects/ to game_objects/ removed redundant entities, added Map loader and test map, made LoadingState use Map for entity asset loading.

This commit is contained in:
2019-09-25 10:09:05 -05:00
parent 42191729ae
commit ee844f256f
18 changed files with 246 additions and 82 deletions

View File

@@ -0,0 +1,56 @@
class IMICFPS
class ModelLoader
def self.supported_models
["Wavefront OBJ"]
end
CACHE = {}
attr_reader :model, :name, :debug_color
def initialize(manifest_file:, entity: nil)
@manifest = YAML.load(File.read(manifest_file))
# pp @manifest
@file_path = File.expand_path("./../model/", manifest_file) + "/#{@manifest["model"]}"
@name = @manifest["name"]
@type = File.basename(@file_path).split(".").last.to_sym
@debug_color = Color.new(0.0, 1.0, 0.0)
@model = nil
@supported_models = ["OBJ"]
unless load_model_from_cache
case @type
when :obj
@model = Wavefront::Model.new(file_path: @file_path, entity: entity)
else
raise "Unsupported model type, supported models are: #{@supported_models.join(', ')}"
end
cache_model
end
return self
end
def load_model_from_cache
found = false
if CACHE[@type].is_a?(Hash)
if CACHE[@type][@file_path]
@model = CACHE[@type][@file_path]#.dup # Don't know why, but adding .dup improves performance with Sponza (1 fps -> 20 fps)
puts "Used cached model for: #{@file_path.split('/').last}" if $debug.get(:stats)
found = true
end
end
return found
end
def cache_model
CACHE[@type] = {} unless CACHE[@type].is_a?(Hash)
CACHE[@type][@file_path] = @model
end
end
end