mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-16 08:02:36 +00:00
Ran rubocop autocorrect
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class IMICFPS
|
||||
class CollisionManager
|
||||
attr_reader :map, :collisions
|
||||
|
||||
def initialize(map:)
|
||||
@map = map
|
||||
@collisions = {}
|
||||
@@ -48,13 +50,13 @@ class IMICFPS
|
||||
next if entity.manifest.collision_resolution == :static # Only dynamic entities can be resolved
|
||||
|
||||
search = @aabb_tree.search(entity.bounding_box)
|
||||
if search.size > 0
|
||||
search.reject! {|ent| ent == entity || !ent.collidable?}
|
||||
if search.size.positive?
|
||||
search.reject! { |ent| ent == entity || !ent.collidable? }
|
||||
broadphase[entity] = search
|
||||
end
|
||||
end
|
||||
|
||||
broadphase.each do |entity, _collisions|
|
||||
broadphase.each do |_entity, _collisions|
|
||||
_collisions.each do |ent|
|
||||
# aabb vs aabb
|
||||
# next unless entity.bounding_box.intersect?(ent.bounding_box)
|
||||
@@ -73,15 +75,15 @@ class IMICFPS
|
||||
|
||||
# AABBTree on entities is relative to model origin of 0,0,0
|
||||
def localize_entity_bounding_box(entity, target)
|
||||
return entity.bounding_box if target.position == 0 && target.orientation == 0
|
||||
return entity.bounding_box if target.position.zero? && target.orientation.zero?
|
||||
|
||||
# "tranform" entity bounding box into target's space
|
||||
local = (target.position) # needs tweaking, works well enough for now
|
||||
local = target.position # needs tweaking, works well enough for now
|
||||
box = entity.bounding_box.clone
|
||||
box.min -= local
|
||||
box.max -= local
|
||||
|
||||
return box
|
||||
box
|
||||
end
|
||||
|
||||
def on_ground?(entity) # TODO: Use some form of caching to speed this up
|
||||
@@ -96,7 +98,7 @@ class IMICFPS
|
||||
|
||||
broadphase.detect do |ent|
|
||||
ray = Ray.new(entity.position - ent.position, Vector.down)
|
||||
if ent.model.aabb_tree.search(ray).size > 0
|
||||
if ent.model.aabb_tree.search(ray).size.positive?
|
||||
on_ground = true
|
||||
return true
|
||||
end
|
||||
@@ -105,7 +107,7 @@ class IMICFPS
|
||||
break if on_ground
|
||||
end
|
||||
|
||||
return on_ground
|
||||
on_ground
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class IMICFPS
|
||||
module EntityManager # Get included into GameState context
|
||||
def add_entity(entity)
|
||||
@collision_manager.add(entity) if @collision_manager && entity.manifest.collision # Add every entity to collision manager
|
||||
if @collision_manager && entity.manifest.collision
|
||||
@collision_manager.add(entity)
|
||||
end # Add every entity to collision manager
|
||||
Publisher.instance.publish(:create, nil, entity)
|
||||
@entities << entity
|
||||
end
|
||||
|
||||
def insert_entity(package, name, position, orientation, data = {})
|
||||
def insert_entity(package, name, position, orientation, _data = {})
|
||||
ent = MapParser::Entity.new(package, name, position, orientation, Vector.new(1, 1, 1))
|
||||
add_entity(IMICFPS::Entity.new(map_entity: ent, manifest: Manifest.new(package: package, name: name)))
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class IMICFPS
|
||||
class InputMapper
|
||||
@@keymap = {}
|
||||
@@ -16,11 +17,12 @@ class IMICFPS
|
||||
if id_or_action.is_a?(Integer)
|
||||
@@keys[id_or_action] = true
|
||||
else
|
||||
query = @@keymap.dig(id_or_action)
|
||||
query = @@keymap[id_or_action]
|
||||
|
||||
if query.is_a?(Integer)
|
||||
query
|
||||
elsif query.is_a?(Array)
|
||||
case query
|
||||
when Integer
|
||||
query
|
||||
when Array
|
||||
query.each do |key|
|
||||
@@keys[key] = true
|
||||
end
|
||||
@@ -34,11 +36,12 @@ class IMICFPS
|
||||
if id_or_action.is_a?(Integer)
|
||||
@@keys[id_or_action] = false
|
||||
else
|
||||
query = @@keymap.dig(id_or_action)
|
||||
query = @@keymap[id_or_action]
|
||||
|
||||
if query.is_a?(Integer)
|
||||
case query
|
||||
when Integer
|
||||
query
|
||||
elsif query.is_a?(Array)
|
||||
when Array
|
||||
query.each do |key|
|
||||
@@keys[key] = false
|
||||
end
|
||||
@@ -49,12 +52,14 @@ class IMICFPS
|
||||
end
|
||||
|
||||
def self.get(action)
|
||||
@@keymap.dig(action)
|
||||
@@keymap[action]
|
||||
end
|
||||
|
||||
def self.set(action, key)
|
||||
raise "action must be a symbol" unless action.is_a?(Symbol)
|
||||
raise "key must be a whole number or Array of whole numbers, got #{key}" unless key.is_a?(Integer) || key.is_a?(Array)
|
||||
raise "action must be a symbol" unless action.is_a?(Symbol)
|
||||
unless key.is_a?(Integer) || key.is_a?(Array)
|
||||
raise "key must be a whole number or Array of whole numbers, got #{key}"
|
||||
end
|
||||
|
||||
warn "InputMapper.set(:#{action}) is already defined as #{@@keymap[action]}" if @@keymap[action]
|
||||
|
||||
@@ -74,7 +79,7 @@ class IMICFPS
|
||||
end
|
||||
|
||||
def self.is?(action, query_key)
|
||||
keys = @@keymap.dig(action)
|
||||
keys = @@keymap[action]
|
||||
|
||||
if keys.is_a?(Array)
|
||||
keys.include?(query_key)
|
||||
@@ -85,16 +90,17 @@ class IMICFPS
|
||||
|
||||
def self.actions(key)
|
||||
@@keymap.select do |action, value|
|
||||
if value.is_a?(Array)
|
||||
case value
|
||||
when Array
|
||||
action if value.include?(key)
|
||||
else
|
||||
action if value == key
|
||||
when key
|
||||
action
|
||||
end
|
||||
end.map { |keymap| keymap.first.is_a?(Symbol) ? keymap.first : keymap.first.first }
|
||||
end
|
||||
|
||||
def self.reset_keys
|
||||
@@keys.each do |key, value|
|
||||
@@keys.each do |key, _value|
|
||||
@@keys[key] = false
|
||||
end
|
||||
end
|
||||
@@ -125,4 +131,4 @@ IMICFPS::InputMapper.set(:decrease_mouse_sensitivity, Gosu::KB_NUMPAD_MINUS)
|
||||
IMICFPS::InputMapper.set(:reset_mouse_sensitivity, Gosu::KB_NUMPAD_MULTIPLY)
|
||||
|
||||
IMICFPS::InputMapper.set(:decrease_view_distance, Gosu::MsWheelDown)
|
||||
IMICFPS::InputMapper.set(:increase_view_distance, Gosu::MsWheelUp)
|
||||
IMICFPS::InputMapper.set(:increase_view_distance, Gosu::MsWheelUp)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class IMICFPS
|
||||
module LightManager
|
||||
MAX_LIGHTS = OpenGL::GL_MAX_LIGHTS
|
||||
@@ -7,7 +8,7 @@ class IMICFPS
|
||||
@lights << model
|
||||
end
|
||||
|
||||
def find_light()
|
||||
def find_light
|
||||
end
|
||||
|
||||
def lights
|
||||
@@ -15,7 +16,7 @@ class IMICFPS
|
||||
end
|
||||
|
||||
def light_count
|
||||
@lights.count+1
|
||||
@lights.count + 1
|
||||
end
|
||||
|
||||
def clear_lights
|
||||
@@ -24,6 +25,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 $window.config.get(:debug_options, :stats)
|
||||
Object.const_get "OpenGL::GL_LIGHT#{light_count}"
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class IMICFPS
|
||||
class PhysicsManager
|
||||
def initialize(collision_manager:)
|
||||
@@ -16,7 +17,7 @@ class IMICFPS
|
||||
end
|
||||
|
||||
def resolve(entity, other)
|
||||
entity.velocity.y = other.velocity.y if other.velocity.y < entity.velocity.y && entity.velocity.y < 0
|
||||
entity.velocity.y = other.velocity.y if other.velocity.y < entity.velocity.y && entity.velocity.y.negative?
|
||||
end
|
||||
|
||||
def simulate
|
||||
@@ -33,9 +34,9 @@ class IMICFPS
|
||||
entity.velocity.y = 0
|
||||
else
|
||||
entity.velocity.y -= @collision_manager.map.gravity * entity.delta_time if entity.manifest.physics
|
||||
entity.velocity.y = 0 if entity.velocity.y < 0
|
||||
entity.velocity.y = 0 if entity.velocity.y.negative?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class IMICFPS
|
||||
module SoundManager
|
||||
extend CyberarmEngine::Common
|
||||
|
||||
MASTERS = {}
|
||||
EFFECTS = []
|
||||
PLAYLISTS = {}
|
||||
MASTERS = {}.freeze
|
||||
EFFECTS = [].freeze
|
||||
PLAYLISTS = {}.freeze
|
||||
|
||||
def self.master_volume
|
||||
1.0
|
||||
@@ -20,15 +21,15 @@ class IMICFPS
|
||||
end
|
||||
|
||||
def self.load_master(package)
|
||||
return if MASTERS.dig(package)
|
||||
return if MASTERS[package]
|
||||
|
||||
yaml = YAML.load_file( "#{IMICFPS.assets_path}/#{package}/shared/sound/master.yaml" )
|
||||
yaml = YAML.load_file("#{IMICFPS.assets_path}/#{package}/shared/sound/master.yaml")
|
||||
MASTERS[package] = yaml
|
||||
end
|
||||
|
||||
def self.sound(package, name)
|
||||
if data = sound_data(package, name.to_s)
|
||||
get_sample("#{IMICFPS.assets_path}/#{package}/shared/sound/#{data["path"]}")
|
||||
get_sample("#{IMICFPS.assets_path}/#{package}/shared/sound/#{data['path']}")
|
||||
else
|
||||
raise "Missing sound: '#{name}' in package '#{package}'"
|
||||
end
|
||||
@@ -36,11 +37,11 @@ class IMICFPS
|
||||
|
||||
def self.sound_data(package, name)
|
||||
load_master(package)
|
||||
if master = MASTERS.dig(package)
|
||||
if master = MASTERS[package]
|
||||
return master["sounds"].find { |s| s["name"] == name }
|
||||
end
|
||||
|
||||
return nil
|
||||
nil
|
||||
end
|
||||
|
||||
def self.sound_effect(klass, options)
|
||||
@@ -51,4 +52,4 @@ class IMICFPS
|
||||
EFFECTS.each { |e| e.update; EFFECTS.delete(e) if e.done? }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user