From f68c31f87c58c35c3dd0f31cf32b944c5aa19b38 Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Mon, 18 Jun 2018 12:17:32 -0500 Subject: [PATCH] Duct taping a cache bug, added test_object that uses sponza.obj. --- i-mic-fps.rb | 1 + lib/objects/model_loader.rb | 2 +- lib/objects/test_object.rb | 7 +++++++ lib/window.rb | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 lib/objects/test_object.rb diff --git a/i-mic-fps.rb b/i-mic-fps.rb index 7c37e3e..7b0b509 100644 --- a/i-mic-fps.rb +++ b/i-mic-fps.rb @@ -53,6 +53,7 @@ require_relative "lib/objects/camera" require_relative "lib/objects/player" require_relative "lib/objects/tree" require_relative "lib/objects/skydome" +require_relative "lib/objects/test_object" require_relative "lib/objects/model_loader" require_relative "lib/objects/terrain" diff --git a/lib/objects/model_loader.rb b/lib/objects/model_loader.rb index d7feedc..bcd46b7 100644 --- a/lib/objects/model_loader.rb +++ b/lib/objects/model_loader.rb @@ -35,7 +35,7 @@ class IMICFPS found = false if CACHE[@type].is_a?(Hash) if CACHE[@type][@file_path] - @model = 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}" found = true end diff --git a/lib/objects/test_object.rb b/lib/objects/test_object.rb new file mode 100644 index 0000000..6e25338 --- /dev/null +++ b/lib/objects/test_object.rb @@ -0,0 +1,7 @@ +class IMICFPS + class TestObject < GameObject + def setup + bind_model(ModelLoader.new(type: :obj, file_path: "objects/sponza.obj", game_object: self)) + end + end +end diff --git a/lib/window.rb b/lib/window.rb index b40f578..50dc389 100644 --- a/lib/window.rb +++ b/lib/window.rb @@ -24,6 +24,7 @@ class IMICFPS Tree.new(x: 1, y: 0, z: -5) Tree.new(x: 5, y: 0, z: 5) Tree.new(x: -5, y: 0, z: 1) + TestObject.new(scale: 1) p ObjectManager.objects.map {|o| o.name} # Model.new(type: :obj, file_path: "objects/tree.obj", z: -5) # Model.new(type: :obj, file_path: "objects/tree.obj", x: -2, z: -6)