Moved collision/physics information into manifest, made real mouse cursor always invisible and use 'virtual' cursor when needed.

This commit is contained in:
2019-09-28 13:29:21 -05:00
parent e038dcbe24
commit 40d1105fb8
13 changed files with 32 additions and 30 deletions

View File

@@ -1,4 +1,6 @@
name: "biped" name: "biped"
model: "biped.obj" model: "biped.obj"
collision: "mesh" collision: "mesh"
collision_mesh: null collision_mesh: null
collision_resolution: "dynamic"
physics: true

View File

@@ -1,2 +1,3 @@
name: "randomish_terrain" name: "randomish_terrain"
model: "randomish_terrain.obj" model: "randomish_terrain.obj"
collision: "mesh"

View File

@@ -1,2 +1,3 @@
name: "river_terrain" name: "river_terrain"
model: "river_terrain.obj" model: "river_terrain.obj"
collision: "mesh"

View File

@@ -8,9 +8,6 @@ class IMICFPS
def setup def setup
bind_model bind_model
@collision = :dynamic
@physics = true
@speed = 2.5 # meter's per second @speed = 2.5 # meter's per second
@running_speed = 5.0 # meter's per second @running_speed = 5.0 # meter's per second
@turn_speed = 50.0 @turn_speed = 50.0

View File

@@ -7,7 +7,7 @@ class IMICFPS
attr_accessor :scale, :visible, :renderable, :backface_culling attr_accessor :scale, :visible, :renderable, :backface_culling
attr_accessor :position, :orientation, :velocity attr_accessor :position, :orientation, :velocity
attr_reader :name, :debug_color, :bounding_box, :collision, :physics, :mass, :drag, :camera attr_reader :name, :debug_color, :bounding_box, :drag, :camera, :manifest
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
@@ -27,14 +27,6 @@ class IMICFPS
@debug_color = Color.new(0.0, 1.0, 0.0) @debug_color = Color.new(0.0, 1.0, 0.0)
@collidable = [:static, :dynamic]
# :dynamic => moves in response,
# :static => does not move ever,
# :none => no collision check, entities can pass through
@collision = :static
@physics = @manifest.physics # Entity affected by gravity and what not
@mass = 100 # kg
@last_position = Vector.new(@position.x, @position.y, @position.z) @last_position = Vector.new(@position.x, @position.y, @position.z)
@sandboxes = [] @sandboxes = []
@@ -61,7 +53,7 @@ class IMICFPS
end end
def collidable? def collidable?
@collidable.include?(@collision) @manifest.collision
end end
def bind_model def bind_model

View File

@@ -44,7 +44,7 @@ class IMICFPS
@map.entities.each do |entity| @map.entities.each do |entity|
next unless entity.collidable? next unless entity.collidable?
next if entity.collision == :static # Only dynamic entities can be resolved next if entity.manifest.collision_resolution == :static # Only dynamic entities can be resolved
search = @aabb_tree.search(entity.bounding_box) search = @aabb_tree.search(entity.bounding_box)
if search.size > 0 if search.size > 0

View File

@@ -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)# Add every entity to collision manager @collision_manager.add(entity) if 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) @collision_manager.remove(entity) if entity.manifest.collision
@publisher.publish(:destroy, nil, entity) @publisher.publish(:destroy, nil, entity)
@entities.delete(ent) @entities.delete(ent)
end end

View File

@@ -31,7 +31,7 @@ class IMICFPS
if on_ground if on_ground
entity.velocity.y = 0 entity.velocity.y = 0
else else
entity.velocity.y -= @collision_manager.map.gravity * entity.delta_time if entity.physics entity.velocity.y -= @collision_manager.map.gravity * entity.delta_time if entity.manifest.physics
end end
end end
end end

View File

@@ -1,6 +1,6 @@
class IMICFPS class IMICFPS
class Manifest class Manifest
attr_reader :name, :model, :collision, :collision_mesh, :physics, :scripts, :uses attr_reader :name, :model, :collision, :collision_mesh, :collision_resolution, :physics, :scripts, :uses
def initialize(manifest_file: nil, package: nil, name: nil) def initialize(manifest_file: nil, package: nil, name: nil)
unless manifest_file unless manifest_file
raise "Entity package not specified!" unless package raise "Entity package not specified!" unless package
@@ -24,6 +24,7 @@ class IMICFPS
# optional # optional
@collision = data["collision"] ? data["collision"] : nil @collision = data["collision"] ? data["collision"] : nil
@collision_mesh = data["collision_mesh"] ? data["collision_mesh"] : nil @collision_mesh = data["collision_mesh"] ? data["collision_mesh"] : nil
@collision_resolution = data["collision_resolution"] ? data["collision_resolution"].to_sym : :static
@physics = data["physics"] ? data["physics"] : false @physics = data["physics"] ? data["physics"] : false
@scripts = data["scripts"] ? parse_scripts(data["scripts"]) : [] @scripts = data["scripts"] ? parse_scripts(data["scripts"]) : []
@uses = data["uses"] ? parse_dependencies(data["uses"]) : [] # List of entities that this Entity uses @uses = data["uses"] ? parse_dependencies(data["uses"]) : [] # List of entities that this Entity uses

View File

@@ -1,6 +1,7 @@
class IMICFPS class IMICFPS
class LoadingState < Menu class LoadingState < Menu
def setup def setup
window.needs_cursor = false
@map_loader = MapLoader.new(map_file: @options[:map_file]) @map_loader = MapLoader.new(map_file: @options[:map_file])
title "I-MIC FPS" title "I-MIC FPS"

View File

@@ -226,8 +226,8 @@ class IMICFPS
@active_text_input = window.text_input @active_text_input = window.text_input
window.text_input = @text_input window.text_input = @text_input
@showing_cursor = window.show_cursor @showing_cursor = window.needs_cursor
window.show_cursor = true window.needs_cursor = true
@show_caret = true @show_caret = true
@caret_last_change = Gosu.milliseconds @caret_last_change = Gosu.milliseconds
@@ -235,7 +235,7 @@ class IMICFPS
def blur def blur
window.text_input = @active_text_input window.text_input = @active_text_input
window.show_cursor = @showing_cursor window.needs_cursor = @showing_cursor
end end
end end
end end

View File

@@ -6,6 +6,7 @@ class IMICFPS
@slope = 250 @slope = 250
@color_step = 10 @color_step = 10
@base_color = Gosu::Color.rgb(255, 127, 0) @base_color = Gosu::Color.rgb(255, 127, 0)
window.needs_cursor = true
super(*args) super(*args)
end end
@@ -55,13 +56,15 @@ class IMICFPS
end end
# Cursor # Cursor
fill_quad( if window.needs_cursor
mouse_x, mouse_y, fill_quad(
mouse_x+16, mouse_y, mouse_x, mouse_y,
mouse_x, mouse_y+16, mouse_x+16, mouse_y,
mouse_x, mouse_y+16, mouse_x, mouse_y+16,
Gosu::Color::WHITE, Float::INFINITY mouse_x, mouse_y+16,
) Gosu::Color::WHITE, Float::INFINITY
)
end
end end
def update def update

View File

@@ -26,6 +26,10 @@ class IMICFPS
@delta_time = Gosu.milliseconds @delta_time = Gosu.milliseconds
end end
def needs_cursor?
false
end
def draw def draw
super super