mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 15:42:35 +00:00
Removed global state for LightManager and ObjectManager, they're now inside GameState. Simplified terrain mesh.
This commit is contained in:
@@ -3,8 +3,8 @@ GEM
|
|||||||
specs:
|
specs:
|
||||||
glu (8.2.2)
|
glu (8.2.2)
|
||||||
glu (8.2.2-x86-mingw32)
|
glu (8.2.2-x86-mingw32)
|
||||||
gosu (0.14.4)
|
gosu (0.14.5)
|
||||||
gosu (0.14.4-x86-mingw32)
|
gosu (0.14.5-x86-mingw32)
|
||||||
opengl-bindings (1.6.7)
|
opengl-bindings (1.6.7)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
@@ -17,4 +17,4 @@ DEPENDENCIES
|
|||||||
opengl-bindings
|
opengl-bindings
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
1.17.2
|
1.17.3
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,8 @@
|
|||||||
class IMICFPS
|
class IMICFPS
|
||||||
module CommonMethods
|
module CommonMethods
|
||||||
|
|
||||||
|
def window; $window; end
|
||||||
|
|
||||||
def delta_time
|
def delta_time
|
||||||
(Gosu.milliseconds-@delta_time)/1000.0
|
(Gosu.milliseconds-@delta_time)/1000.0
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,25 +1,24 @@
|
|||||||
class IMICFPS
|
class IMICFPS
|
||||||
class LightManager
|
module LightManager
|
||||||
MAX_LIGHTS = OpenGL::GL_MAX_LIGHTS
|
MAX_LIGHTS = OpenGL::GL_MAX_LIGHTS
|
||||||
LIGHTS = []
|
|
||||||
|
|
||||||
def self.add_light(model)
|
def add_light(model)
|
||||||
LIGHTS << model
|
@lights << model
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_light()
|
def find_light()
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.lights
|
def lights
|
||||||
LIGHTS
|
@lights
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.light_count
|
def light_count
|
||||||
LIGHTS.count+1
|
@lights.count+1
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.clear_lights
|
def clear_lights
|
||||||
LIGHTS.clear
|
@lights.clear
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,17 +4,19 @@ class IMICFPS
|
|||||||
Point = Struct.new(:x, :y)
|
Point = Struct.new(:x, :y)
|
||||||
Color = Struct.new(:red, :green, :blue, :alpha)
|
Color = Struct.new(:red, :green, :blue, :alpha)
|
||||||
|
|
||||||
class ObjectManager
|
module ObjectManager # Get included into GameState context
|
||||||
OBJECTS = []
|
def add_object(model)
|
||||||
def self.add_object(model)
|
@game_objects << model
|
||||||
OBJECTS << model
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_object()
|
def find_object()
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.objects
|
def remove_object()
|
||||||
OBJECTS
|
end
|
||||||
|
|
||||||
|
def game_objects
|
||||||
|
@game_objects
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class IMICFPS
|
|||||||
attr_accessor :visible, :renderable, :backface_culling
|
attr_accessor :visible, :renderable, :backface_culling
|
||||||
attr_accessor :x_rotation, :y_rotation, :z_rotation
|
attr_accessor :x_rotation, :y_rotation, :z_rotation
|
||||||
attr_reader :model, :name, :debug_color, :terrain, :width, :height, :depth, :last_x, :last_y, :last_z, :normalized_bounding_box
|
attr_reader :model, :name, :debug_color, :terrain, :width, :height, :depth, :last_x, :last_y, :last_z, :normalized_bounding_box
|
||||||
def initialize(x: 0, y: 0, z: 0, bound_model: nil, scale: MODEL_METER_SCALE, backface_culling: true, auto_manage: true, terrain: nil)
|
def initialize(x: 0, y: 0, z: 0, bound_model: nil, scale: MODEL_METER_SCALE, backface_culling: true, auto_manage: true, terrain: nil, game_state: nil)
|
||||||
@x,@y,@z,@scale = x,y,z,scale
|
@x,@y,@z,@scale = x,y,z,scale
|
||||||
@bound_model = bound_model
|
@bound_model = bound_model
|
||||||
@backface_culling = backface_culling
|
@backface_culling = backface_culling
|
||||||
@@ -20,11 +20,13 @@ class IMICFPS
|
|||||||
@debug_color = Color.new(0.0, 1.0, 0.0)
|
@debug_color = Color.new(0.0, 1.0, 0.0)
|
||||||
@terrain = terrain
|
@terrain = terrain
|
||||||
|
|
||||||
|
@game_state = game_state
|
||||||
|
|
||||||
@width, @height, @depth = 0,0,0
|
@width, @height, @depth = 0,0,0
|
||||||
@delta_time = Gosu.milliseconds
|
@delta_time = Gosu.milliseconds
|
||||||
@last_x, @last_y, @last_z = @x, @y, @z
|
@last_x, @last_y, @last_z = @x, @y, @z
|
||||||
|
|
||||||
ObjectManager.add_object(self) if auto_manage
|
game_state.add_object(self) if auto_manage && game_state
|
||||||
setup
|
setup
|
||||||
|
|
||||||
if @bound_model
|
if @bound_model
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ class IMICFPS
|
|||||||
include OpenGL
|
include OpenGL
|
||||||
attr_reader :ambient, :diffuse, :specular, :position, :light_id
|
attr_reader :ambient, :diffuse, :specular, :position, :light_id
|
||||||
attr_accessor :x, :y, :z, :intensity
|
attr_accessor :x, :y, :z, :intensity
|
||||||
def initialize(x:,y:,z:, ambient: Vertex.new(0.5, 0.5, 0.5, 1),
|
def initialize(x:,y:,z:, game_state:,
|
||||||
|
ambient: Vertex.new(0.5, 0.5, 0.5, 1),
|
||||||
diffuse: Vertex.new(1, 0.5, 0, 1), specular: Vertex.new(0.2, 0.2, 0.2, 1),
|
diffuse: Vertex.new(1, 0.5, 0, 1), specular: Vertex.new(0.2, 0.2, 0.2, 1),
|
||||||
position: Vertex.new(x, y, z, 0), intensity: 1)
|
position: Vertex.new(x, y, z, 0), intensity: 1)
|
||||||
@x,@y,@z = x,y,z
|
@x,@y,@z = x,y,z
|
||||||
|
@game_state = game_state
|
||||||
@intensity = intensity
|
@intensity = intensity
|
||||||
|
|
||||||
self.ambient = ambient
|
self.ambient = ambient
|
||||||
@@ -15,13 +17,13 @@ class IMICFPS
|
|||||||
self.position = position
|
self.position = position
|
||||||
@light_id = available_light
|
@light_id = available_light
|
||||||
|
|
||||||
LightManager.add_light(self)
|
@game_state.add_light(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def available_light
|
def available_light
|
||||||
raise "Using to many lights, #{LightManager.light_count}/#{LightManager::MAX_LIGHTS}" if LightManager.light_count > LightManager::MAX_LIGHTS
|
raise "Using to many lights, #{@game_state.light_count}/#{LightManager::MAX_LIGHTS}" if @game_state.light_count > LightManager::MAX_LIGHTS
|
||||||
puts "OpenGL::GL_LIGHT#{LightManager.light_count}" if $debug
|
puts "OpenGL::GL_LIGHT#{@game_state.light_count}" if $debug
|
||||||
@light_id = Object.const_get "OpenGL::GL_LIGHT#{LightManager.light_count}"
|
@light_id = Object.const_get "OpenGL::GL_LIGHT#{@game_state.light_count}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def ambient=(color)
|
def ambient=(color)
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ class IMICFPS
|
|||||||
include GLU
|
include GLU
|
||||||
|
|
||||||
attr_reader :bounding_boxes, :vertex_count
|
attr_reader :bounding_boxes, :vertex_count
|
||||||
def initialize
|
def initialize(game_state:)
|
||||||
|
@game_state = game_state
|
||||||
|
|
||||||
@bounding_boxes = {}
|
@bounding_boxes = {}
|
||||||
@vertex_count = 0
|
@vertex_count = 0
|
||||||
end
|
end
|
||||||
@@ -215,7 +217,7 @@ class IMICFPS
|
|||||||
|
|
||||||
glPopMatrix
|
glPopMatrix
|
||||||
|
|
||||||
found = ObjectManager.objects.detect { |o| o == bounding_box[:object] }
|
found = @game_state.game_objects.detect { |o| o == bounding_box[:object] }
|
||||||
|
|
||||||
unless found
|
unless found
|
||||||
@vertex_count -= @bounding_boxes[key][:vertices_size]
|
@vertex_count -= @bounding_boxes[key][:vertices_size]
|
||||||
|
|||||||
@@ -5,13 +5,15 @@ class IMICFPS
|
|||||||
|
|
||||||
attr_reader :opengl_renderer, :bounding_box_renderer
|
attr_reader :opengl_renderer, :bounding_box_renderer
|
||||||
|
|
||||||
def initialize
|
def initialize(game_state:)
|
||||||
@bounding_box_renderer = BoundingBoxRenderer.new
|
@game_state = game_state
|
||||||
|
|
||||||
|
@bounding_box_renderer = BoundingBoxRenderer.new(game_state: game_state)
|
||||||
@opengl_renderer = OpenGLRenderer.new
|
@opengl_renderer = OpenGLRenderer.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
ObjectManager.objects.each do |object|
|
@game_state.game_objects.each do |object|
|
||||||
if object.visible && object.renderable
|
if object.visible && object.renderable
|
||||||
# Render bounding boxes before transformation is applied
|
# Render bounding boxes before transformation is applied
|
||||||
@bounding_box_renderer.create_bounding_box(object, object.model.bounding_box, object.debug_color, object.object_id) if $debug
|
@bounding_box_renderer.create_bounding_box(object, object.model.bounding_box, object.debug_color, object.object_id) if $debug
|
||||||
|
|||||||
@@ -1,15 +1,21 @@
|
|||||||
class IMICFPS
|
class IMICFPS
|
||||||
class GameState
|
class GameState
|
||||||
include CommonMethods
|
include CommonMethods
|
||||||
|
include ObjectManager
|
||||||
|
include LightManager
|
||||||
|
|
||||||
attr_reader :options
|
attr_reader :options
|
||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
@options = options
|
@options = options
|
||||||
@delta_time = Gosu.milliseconds
|
@delta_time = Gosu.milliseconds
|
||||||
|
@game_objects = []
|
||||||
|
@lights = []
|
||||||
|
|
||||||
setup
|
setup
|
||||||
end
|
end
|
||||||
|
|
||||||
def push_game_state(klass_or_instance)
|
def push_game_state(klass_or_instance)
|
||||||
$window.push_game_state(klass_or_instance)
|
window.push_game_state(klass_or_instance)
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@@ -21,6 +27,9 @@ class IMICFPS
|
|||||||
def update
|
def update
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def button_down(id)
|
||||||
|
end
|
||||||
|
|
||||||
def button_up(id)
|
def button_up(id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,16 +4,16 @@ class IMICFPS
|
|||||||
include GLU
|
include GLU
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@renderer = Renderer.new
|
@renderer = Renderer.new(game_state: self)
|
||||||
@terrain = Terrain.new#(size: 170, height: 0)
|
@terrain = Terrain.new(game_state: self)#(size: 170, height: 0)
|
||||||
@draw_skydome = true
|
@draw_skydome = true
|
||||||
@skydome = Skydome.new(scale: 0.08, backface_culling: false, auto_manage: false)
|
@skydome = Skydome.new(scale: 0.08, backface_culling: false, auto_manage: false)
|
||||||
|
|
||||||
25.times do
|
25.times do
|
||||||
Tree.new(x: rand(@terrain.width)-(@terrain.width/2.0), z: rand(@terrain.depth)-(@terrain.depth/2.0), terrain: @terrain)
|
Tree.new(x: rand(@terrain.width)-(@terrain.width/2.0), z: rand(@terrain.depth)-(@terrain.depth/2.0), terrain: @terrain, game_state: self)
|
||||||
end
|
end
|
||||||
|
|
||||||
@player = Player.new(x: 1, y: 0, z: -1, terrain: @terrain)
|
@player = Player.new(x: 1, y: 0, z: -1, terrain: @terrain, game_state: self)
|
||||||
@camera = Camera.new(x: 0, y: -2, z: 1)
|
@camera = Camera.new(x: 0, y: -2, z: 1)
|
||||||
@camera.attach_to(@player)
|
@camera.attach_to(@player)
|
||||||
|
|
||||||
@@ -24,8 +24,8 @@ class IMICFPS
|
|||||||
# @font = Gosu::Font.new(18, name: "DejaVu Sans")
|
# @font = Gosu::Font.new(18, name: "DejaVu Sans")
|
||||||
@text = MultiLineText.new("Pending...", x: 10, y: 10, z: 1, size: 18, font: "DejaVu Sans")
|
@text = MultiLineText.new("Pending...", x: 10, y: 10, z: 1, size: 18, font: "DejaVu Sans")
|
||||||
|
|
||||||
Light.new(x: 3, y: -6, z: 6)
|
Light.new(x: 3, y: -6, z: 6, game_state: self)
|
||||||
Light.new(x: 0, y: 100, z: 0, diffuse: Color.new(1.0, 0.5, 0.1))
|
Light.new(x: 0, y: 100, z: 0, diffuse: Color.new(1.0, 0.5, 0.1), game_state: self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def glError?
|
def glError?
|
||||||
@@ -46,7 +46,7 @@ class IMICFPS
|
|||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # clear the screen and the depth buffer
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # clear the screen and the depth buffer
|
||||||
glError?
|
glError?
|
||||||
|
|
||||||
LightManager.lights.each(&:draw)
|
@lights.each(&:draw)
|
||||||
|
|
||||||
@camera.draw
|
@camera.draw
|
||||||
@renderer.opengl_renderer.draw_object(@skydome) if @skydome.renderable
|
@renderer.opengl_renderer.draw_object(@skydome) if @skydome.renderable
|
||||||
@@ -106,8 +106,8 @@ eos
|
|||||||
@text.text = string
|
@text.text = string
|
||||||
|
|
||||||
# Expensive AABB collision detection
|
# Expensive AABB collision detection
|
||||||
ObjectManager.objects.each do |object|
|
@game_objects.each do |object|
|
||||||
ObjectManager.objects.each do |b|
|
@game_objects.each do |b|
|
||||||
next if object == b
|
next if object == b
|
||||||
next if object.is_a?(Terrain) || b.is_a?(Terrain)
|
next if object.is_a?(Terrain) || b.is_a?(Terrain)
|
||||||
|
|
||||||
@@ -124,7 +124,7 @@ eos
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ObjectManager.objects.each(&:update)
|
@game_objects.each(&:update)
|
||||||
|
|
||||||
@skydome.update if @skydome.renderable
|
@skydome.update if @skydome.renderable
|
||||||
|
|
||||||
@@ -136,7 +136,7 @@ eos
|
|||||||
end
|
end
|
||||||
|
|
||||||
def button_up(id)
|
def button_up(id)
|
||||||
ObjectManager.objects.each do |object|
|
@game_objects.each do |object|
|
||||||
object.button_up(id) if defined?(object.button_up)
|
object.button_up(id) if defined?(object.button_up)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ class IMICFPS
|
|||||||
def setup
|
def setup
|
||||||
@header = Text.new("I-MIC FPS", y: 10, size: 100, alignment: :center)
|
@header = Text.new("I-MIC FPS", y: 10, size: 100, alignment: :center)
|
||||||
@subheading = Text.new("Loading Assets", y: 100, size: 50, alignment: :center)
|
@subheading = Text.new("Loading Assets", y: 100, size: 50, alignment: :center)
|
||||||
@state = Text.new("Preparing...", y: $window.height/2-40, size: 40, alignment: :center)
|
@state = Text.new("Preparing...", y: window.height/2-40, size: 40, alignment: :center)
|
||||||
@percentage = Text.new("0%", y: $window.height-50-25, size: 50, alignment: :center)
|
@percentage = Text.new("0%", y: window.height-50-25, size: 50, alignment: :center)
|
||||||
|
|
||||||
@dummy_game_object = nil
|
@dummy_game_object = nil
|
||||||
@assets = []
|
@assets = []
|
||||||
@@ -15,7 +15,7 @@ class IMICFPS
|
|||||||
add_asset(:obj, "objects/biped.obj")
|
add_asset(:obj, "objects/biped.obj")
|
||||||
|
|
||||||
# Currently broken
|
# Currently broken
|
||||||
Shader.new(name: "lighting", vertex_file: "shaders/vertex/lighting.glsl", fragment_file: "shaders/fragment/lighting.glsl")
|
# Shader.new(name: "lighting", vertex_file: "shaders/vertex/lighting.glsl", fragment_file: "shaders/fragment/lighting.glsl")
|
||||||
|
|
||||||
@act = false
|
@act = false
|
||||||
@cycled = false
|
@cycled = false
|
||||||
@@ -29,7 +29,15 @@ class IMICFPS
|
|||||||
@subheading.draw
|
@subheading.draw
|
||||||
@state.draw
|
@state.draw
|
||||||
|
|
||||||
fill(Gosu::Color.rgba(127, 64, 0, 150))
|
# fill()
|
||||||
|
color = Gosu::Color.rgb(255, 127, 0)
|
||||||
|
color_two = Gosu::Color.rgb(200, 100, 0)
|
||||||
|
Gosu.draw_quad(
|
||||||
|
0, 0, color,
|
||||||
|
window.width, 0, color_two,
|
||||||
|
0, window.height, color,
|
||||||
|
window.width, window.height, color_two
|
||||||
|
)
|
||||||
progressbar
|
progressbar
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -58,7 +66,7 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
@state.text = "Loading #{@assets[@asset_index][:path].split('/').last}..."
|
@state.text = "Loading #{@assets[@asset_index][:path].split('/').last}..."
|
||||||
@state.x = ($window.width/2)-(@state.width/2)
|
@state.x = (window.width/2)-(@state.width/2)
|
||||||
@cycled = true
|
@cycled = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -69,8 +77,8 @@ class IMICFPS
|
|||||||
|
|
||||||
def progressbar
|
def progressbar
|
||||||
@percentage.draw
|
@percentage.draw
|
||||||
progress = (@asset_index.to_f/@assets.count)*$window.width
|
progress = (@asset_index.to_f/@assets.count)*window.width
|
||||||
draw_rect(0, $window.height-100, progress, 100, Gosu::Color.rgb(255,127,0))
|
draw_rect(0, window.height-100, progress, 100, Gosu::Color.rgb(255,127,0))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -6,7 +6,7 @@ class IMICFPS
|
|||||||
push_game_state(LoadingState.new(forward: Game))
|
push_game_state(LoadingState.new(forward: Game))
|
||||||
end
|
end
|
||||||
link "Exit" do
|
link "Exit" do
|
||||||
$window.close
|
window.close
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ class IMICFPS
|
|||||||
def initialize(window_width = 1280, window_height = 800, fullscreen = false)
|
def initialize(window_width = 1280, window_height = 800, fullscreen = false)
|
||||||
fps_target = (ARGV.first.to_i != 0) ? ARGV.first.to_i : 60
|
fps_target = (ARGV.first.to_i != 0) ? ARGV.first.to_i : 60
|
||||||
if ARGV.join.include?("--native")
|
if ARGV.join.include?("--native")
|
||||||
super(Gosu.screen_width, Gosu.screen_height, fullscreen: true, resizable: false, update_interval: 1000.0/fps_target)
|
super(Gosu.screen_width, Gosu.screen_height, fullscreen: true, resizable: true, update_interval: 1000.0/fps_target)
|
||||||
else
|
else
|
||||||
super(window_width, window_height, fullscreen: fullscreen, resizable: false, update_interval: 1000.0/fps_target)
|
super(window_width, window_height, fullscreen: fullscreen, resizable: true, update_interval: 1000.0/fps_target)
|
||||||
end
|
end
|
||||||
$window = self
|
$window = self
|
||||||
@needs_cursor = false
|
@needs_cursor = false
|
||||||
|
|||||||
@@ -10,4 +10,4 @@ Ke 0.000000 0.000000 0.000000
|
|||||||
Ni 1.000000
|
Ni 1.000000
|
||||||
d 1.000000
|
d 1.000000
|
||||||
illum 2
|
illum 2
|
||||||
map_Kd objects/randomish_terrain.png
|
map_Kd /home/cyberarm/Code/i-mic-fps/blends/randomish_terrain.png
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user