mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 15:42:35 +00:00
Added Asset Viewer
This commit is contained in:
19
i-mic-fps.rb
19
i-mic-fps.rb
@@ -101,6 +101,25 @@ require_relative "lib/demo"
|
|||||||
|
|
||||||
require_relative "lib/window"
|
require_relative "lib/window"
|
||||||
|
|
||||||
|
if ARGV[0] == "tool"
|
||||||
|
case ARGV[1]
|
||||||
|
when "viewer" # Turn Table
|
||||||
|
require_relative "lib/tools/asset_viewer/asset_viewer"
|
||||||
|
when "editor" # Level Editor
|
||||||
|
raise NotImplementedError
|
||||||
|
else
|
||||||
|
if ARGV[1].nil?
|
||||||
|
puts "### I-MIC FPS Tools ###"
|
||||||
|
puts "viewer - 3D Turn Table"
|
||||||
|
puts "editor - Level Editor"
|
||||||
|
else
|
||||||
|
raise "No such tool: #{ARGV[1]}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return # Don't launch game, but load all required files
|
||||||
|
end
|
||||||
|
|
||||||
if ARGV.join.include?("--profile")
|
if ARGV.join.include?("--profile")
|
||||||
begin
|
begin
|
||||||
require "ruby-prof"
|
require "ruby-prof"
|
||||||
|
|||||||
@@ -111,26 +111,29 @@ class IMICFPS
|
|||||||
|
|
||||||
def free_move
|
def free_move
|
||||||
relative_y_rotation = (@orientation.y + 180)
|
relative_y_rotation = (@orientation.y + 180)
|
||||||
relative_speed = 0.25
|
relative_speed = 2.5
|
||||||
|
relative_speed = 1.5 if InputMapper.down?(:sneak)
|
||||||
|
relative_speed = 10.0 if InputMapper.down?(:sprint)
|
||||||
|
relative_speed *= window.dt
|
||||||
|
|
||||||
if InputMapper.down?( :forward)
|
if InputMapper.down?( :forward)
|
||||||
@position.z+=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
@position.z+=Math.cos(relative_y_rotation * Math::PI / 180) * relative_speed
|
||||||
@position.x-=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
@position.x-=Math.sin(relative_y_rotation * Math::PI / 180) * relative_speed
|
||||||
end
|
end
|
||||||
|
|
||||||
if InputMapper.down?(:backward)
|
if InputMapper.down?(:backward)
|
||||||
@position.z-=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
@position.z-=Math.cos(relative_y_rotation * Math::PI / 180) * relative_speed
|
||||||
@position.x+=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
@position.x+=Math.sin(relative_y_rotation * Math::PI / 180) * relative_speed
|
||||||
end
|
end
|
||||||
|
|
||||||
if InputMapper.down?(:strife_left)
|
if InputMapper.down?(:strife_left)
|
||||||
@position.z+=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
@position.z+=Math.sin(relative_y_rotation * Math::PI / 180) * relative_speed
|
||||||
@position.x+=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
@position.x+=Math.cos(relative_y_rotation * Math::PI / 180) * relative_speed
|
||||||
end
|
end
|
||||||
|
|
||||||
if InputMapper.down?(:strife_right)
|
if InputMapper.down?(:strife_right)
|
||||||
@position.z-=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
@position.z-=Math.sin(relative_y_rotation * Math::PI / 180) * relative_speed
|
||||||
@position.x-=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
@position.x-=Math.cos(relative_y_rotation * Math::PI / 180) * relative_speed
|
||||||
end
|
end
|
||||||
|
|
||||||
if InputMapper.down?(:ascend)
|
if InputMapper.down?(:ascend)
|
||||||
|
|||||||
@@ -11,13 +11,24 @@ class IMICFPS
|
|||||||
|
|
||||||
def initialize(manifest:, map_entity: nil, spawnpoint: nil, backface_culling: true, auto_manage: true)
|
def initialize(manifest:, map_entity: nil, spawnpoint: nil, backface_culling: true, auto_manage: true)
|
||||||
@manifest = manifest
|
@manifest = manifest
|
||||||
@position = map_entity ? map_entity.position.clone : spawnpoint.position.clone
|
|
||||||
@orientation = map_entity ? map_entity.orientation.clone : spawnpoint.orientation.clone
|
if map_entity
|
||||||
@scale = map_entity ? map_entity.scale.clone : Vector.new(1, 1, 1)
|
@position = map_entity.position.clone
|
||||||
|
@orientation = map_entity.orientation.clone
|
||||||
|
@scale = map_entity.scale.clone
|
||||||
|
@bound_model = bind_model
|
||||||
|
elsif spawnpoint
|
||||||
|
@position = spawnpoint.position.clone
|
||||||
|
@orientation = spawnpoint.orientation.clone
|
||||||
|
@scale = Vector.new(1, 1, 1)
|
||||||
|
else
|
||||||
|
@position = Vector.new
|
||||||
|
@orientation = Vector.up
|
||||||
|
@scale = Vector.new(1, 1, 1)
|
||||||
|
end
|
||||||
|
|
||||||
@backface_culling = backface_culling
|
@backface_culling = backface_culling
|
||||||
@name = @manifest.name
|
@name = @manifest.name
|
||||||
@bound_model = map_entity ? bind_model : nil
|
|
||||||
|
|
||||||
@visible = true
|
@visible = true
|
||||||
@renderable = true
|
@renderable = true
|
||||||
@@ -57,7 +68,7 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def bind_model
|
def bind_model
|
||||||
model = ModelCache.new(manifest: @manifest, entity: @dummy_entity)
|
model = ModelCache.new(manifest: @manifest)
|
||||||
|
|
||||||
raise "model isn't a model!" unless model.is_a?(ModelCache)
|
raise "model isn't a model!" unless model.is_a?(ModelCache)
|
||||||
@bound_model = model
|
@bound_model = model
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class IMICFPS
|
class IMICFPS
|
||||||
module EntityManager # Get included into GameState context
|
module EntityManager # Get included into GameState context
|
||||||
def add_entity(entity)
|
def add_entity(entity)
|
||||||
@collision_manager.add(entity) if entity.manifest.collision# Add every entity to collision manager
|
@collision_manager.add(entity) if @collision_manager && entity.manifest.collision# Add every entity to collision manager
|
||||||
Publisher.instance.publish(:create, nil, entity)
|
Publisher.instance.publish(:create, nil, entity)
|
||||||
@entities << entity
|
@entities << entity
|
||||||
end
|
end
|
||||||
@@ -22,7 +22,7 @@ class IMICFPS
|
|||||||
def remove_entity(entity)
|
def remove_entity(entity)
|
||||||
ent = @entities.detect {|entity| entity == entity}
|
ent = @entities.detect {|entity| entity == entity}
|
||||||
if ent
|
if ent
|
||||||
@collision_manager.remove(entity) if entity.manifest.collision
|
@collision_manager.remove(entity) if @collision_manager && entity.manifest.collision
|
||||||
@publisher.publish(:destroy, nil, entity)
|
@publisher.publish(:destroy, nil, entity)
|
||||||
@entities.delete(ent)
|
@entities.delete(ent)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ IMICFPS::InputMapper.set(:strife_right, Gosu::KbD)
|
|||||||
IMICFPS::InputMapper.set(:turn_left, Gosu::KbLeft)
|
IMICFPS::InputMapper.set(:turn_left, Gosu::KbLeft)
|
||||||
IMICFPS::InputMapper.set(:turn_right, Gosu::KbRight)
|
IMICFPS::InputMapper.set(:turn_right, Gosu::KbRight)
|
||||||
IMICFPS::InputMapper.set(:jump, Gosu::KbSpace)
|
IMICFPS::InputMapper.set(:jump, Gosu::KbSpace)
|
||||||
|
IMICFPS::InputMapper.set(:sneak, [Gosu::KbLeftShift])
|
||||||
IMICFPS::InputMapper.set(:sprint, [Gosu::KbLeftControl])
|
IMICFPS::InputMapper.set(:sprint, [Gosu::KbLeftControl])
|
||||||
IMICFPS::InputMapper.set(:turn_180, Gosu::KbX)
|
IMICFPS::InputMapper.set(:turn_180, Gosu::KbX)
|
||||||
|
|
||||||
|
|||||||
12
lib/tools/asset_viewer/asset_viewer.rb
Normal file
12
lib/tools/asset_viewer/asset_viewer.rb
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
require_relative "lib/main_menu"
|
||||||
|
require_relative "lib/turn_table"
|
||||||
|
|
||||||
|
class AssetViewerWindow < IMICFPS::Window
|
||||||
|
def initialize(*args)
|
||||||
|
super(*args)
|
||||||
|
|
||||||
|
push_state(IMICFPS::AssetViewerTool::MainMenu)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
AssetViewerWindow.new.show
|
||||||
33
lib/tools/asset_viewer/lib/main_menu.rb
Normal file
33
lib/tools/asset_viewer/lib/main_menu.rb
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
class IMICFPS
|
||||||
|
class AssetViewerTool
|
||||||
|
class MainMenu < CyberarmEngine::GuiState
|
||||||
|
def setup
|
||||||
|
window.needs_cursor = true
|
||||||
|
|
||||||
|
label "#{IMICFPS::NAME}", text_size: 50
|
||||||
|
label "Asset Viewer", text_size: 28
|
||||||
|
|
||||||
|
@manifests = []
|
||||||
|
Dir.glob(GAME_ROOT_PATH + "/assets/**/manifest.yaml").each do |manifest|
|
||||||
|
begin
|
||||||
|
@manifests << Manifest.new(manifest_file: manifest)
|
||||||
|
rescue
|
||||||
|
warn "Broken manifest: #{manifest}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
flow(margin: 10) do
|
||||||
|
@manifests.each do |manifest|
|
||||||
|
button manifest.name do
|
||||||
|
push_state(TurnTable, manifest: manifest)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
button "Exit", margin_top: 25 do
|
||||||
|
window.close
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
100
lib/tools/asset_viewer/lib/turn_table.rb
Normal file
100
lib/tools/asset_viewer/lib/turn_table.rb
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
class IMICFPS
|
||||||
|
class AssetViewerTool
|
||||||
|
class TurnTable < CyberarmEngine::GuiState
|
||||||
|
include LightManager
|
||||||
|
|
||||||
|
attr_reader :map
|
||||||
|
def setup
|
||||||
|
@manifest = @options[:manifest]
|
||||||
|
|
||||||
|
if window.config.get(:debug, :use_shaders)
|
||||||
|
Shader.new(
|
||||||
|
name: "default",
|
||||||
|
includes_dir: "shaders/include",
|
||||||
|
vertex: "shaders/vertex/default.glsl",
|
||||||
|
fragment: "shaders/fragment/default.glsl"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
@map = ProtoMap.new
|
||||||
|
Publisher.new
|
||||||
|
|
||||||
|
@entity = Entity.new(manifest: @manifest, auto_manage: false)
|
||||||
|
@entity.bind_model
|
||||||
|
@map.add_entity(@entity)
|
||||||
|
@map.entities.each { |e| e.backface_culling = false }
|
||||||
|
|
||||||
|
@lights = []
|
||||||
|
@light = Light.new(id: available_light, position: Vector.new, diffuse: Vector.new(1, 1, 1, 1))
|
||||||
|
@lights << @light
|
||||||
|
|
||||||
|
@camera = Camera.new(position: Vector.new(0, 1.5, 5), orientation: Vector.forward)
|
||||||
|
@renderer = Renderer.new
|
||||||
|
|
||||||
|
label @manifest.name, text_size: 50
|
||||||
|
label @manifest.model
|
||||||
|
@camera_position = label ""
|
||||||
|
@camera_orientation = label ""
|
||||||
|
|
||||||
|
button "Back" do
|
||||||
|
pop_state
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def draw
|
||||||
|
window.show_cursor = true
|
||||||
|
|
||||||
|
color_top = Gosu::Color::GRAY
|
||||||
|
color_bottom = Gosu::Color::BLACK
|
||||||
|
|
||||||
|
Gosu.draw_quad(
|
||||||
|
0, 0, color_top,
|
||||||
|
window.width, 0, color_top,
|
||||||
|
window.width, window.height, color_bottom,
|
||||||
|
0, window.height, color_bottom,
|
||||||
|
)
|
||||||
|
|
||||||
|
Gosu.gl do
|
||||||
|
@renderer.draw(@camera, [@light], @map.entities)
|
||||||
|
end
|
||||||
|
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
super
|
||||||
|
|
||||||
|
@camera.update
|
||||||
|
@light.position = @camera.position.clone
|
||||||
|
@light.position.y += 1.5
|
||||||
|
@camera_position.value = "Camera Position: X #{@camera.position.x.round(2)}, Y #{@camera.position.y.round(2)}, Z #{@camera.position.z.round(2)}"
|
||||||
|
@camera_orientation.value = "Camera Orientation: X #{@camera.orientation.x.round(2)}, Y #{@camera.orientation.y.round(2)}, Z #{@camera.orientation.z.round(2)}\nEntities: #{@map.entities.count}"
|
||||||
|
|
||||||
|
@map.entities.each(&:update)
|
||||||
|
end
|
||||||
|
|
||||||
|
def button_down(id)
|
||||||
|
super
|
||||||
|
|
||||||
|
InputMapper.keydown(id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def button_up(id)
|
||||||
|
super
|
||||||
|
|
||||||
|
InputMapper.keyup(id)
|
||||||
|
@camera.button_up(id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Stub for enabling scripted models to load properly
|
||||||
|
class ProtoMap
|
||||||
|
include EntityManager
|
||||||
|
|
||||||
|
attr_reader :entities
|
||||||
|
def initialize
|
||||||
|
@entities = []
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -30,7 +30,6 @@ class IMICFPS
|
|||||||
draw_background
|
draw_background
|
||||||
draw_menu_box
|
draw_menu_box
|
||||||
draw_menu
|
draw_menu
|
||||||
window.draw_cursor
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw_background
|
def draw_background
|
||||||
|
|||||||
@@ -40,14 +40,13 @@ class IMICFPS
|
|||||||
super
|
super
|
||||||
|
|
||||||
@console.draw if @show_console
|
@console.draw if @show_console
|
||||||
|
draw_cursor if needs_cursor
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw_cursor
|
def draw_cursor
|
||||||
size = 16
|
size = 16
|
||||||
|
|
||||||
if needs_cursor
|
@cursor.draw(mouse_x, mouse_y, Float::INFINITY)
|
||||||
@cursor.draw(mouse_x, mouse_y, Float::INFINITY)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
|||||||
Reference in New Issue
Block a user