mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-17 05:22:35 +00:00
Added a large portion of I-MIC-FPS's opengl rendering and model loading systems
This commit is contained in:
35
lib/cyberarm_engine/model_cache.rb
Normal file
35
lib/cyberarm_engine/model_cache.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
module CyberarmEngine
|
||||
module ModelCache
|
||||
CACHE = {}
|
||||
|
||||
def self.find_or_cache(manifest:)
|
||||
model_file = manifest.file_path + "/model/#{manifest.model}"
|
||||
|
||||
type = File.basename(model_file).split(".").last.to_sym
|
||||
|
||||
if model = load_model_from_cache(type, model_file)
|
||||
return model
|
||||
else
|
||||
model = CyberarmEngine::Model.new(file_path: model_file)
|
||||
cache_model(type, model_file, model)
|
||||
|
||||
return model
|
||||
end
|
||||
end
|
||||
|
||||
def self.load_model_from_cache(type, model_file)
|
||||
if CACHE[type].is_a?(Hash)
|
||||
if CACHE[type][model_file]
|
||||
return CACHE[type][model_file]
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
def self.cache_model(type, model_file, model)
|
||||
CACHE[type] = {} unless CACHE[type].is_a?(Hash)
|
||||
CACHE[type][model_file] = model
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user