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:
|
||||
glu (8.2.2)
|
||||
glu (8.2.2-x86-mingw32)
|
||||
gosu (0.14.4)
|
||||
gosu (0.14.4-x86-mingw32)
|
||||
gosu (0.14.5)
|
||||
gosu (0.14.5-x86-mingw32)
|
||||
opengl-bindings (1.6.7)
|
||||
|
||||
PLATFORMS
|
||||
@@ -17,4 +17,4 @@ DEPENDENCIES
|
||||
opengl-bindings
|
||||
|
||||
BUNDLED WITH
|
||||
1.17.2
|
||||
1.17.3
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,8 @@
|
||||
class IMICFPS
|
||||
module CommonMethods
|
||||
|
||||
def window; $window; end
|
||||
|
||||
def delta_time
|
||||
(Gosu.milliseconds-@delta_time)/1000.0
|
||||
end
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
class IMICFPS
|
||||
class LightManager
|
||||
module LightManager
|
||||
MAX_LIGHTS = OpenGL::GL_MAX_LIGHTS
|
||||
LIGHTS = []
|
||||
|
||||
def self.add_light(model)
|
||||
LIGHTS << model
|
||||
def add_light(model)
|
||||
@lights << model
|
||||
end
|
||||
|
||||
def self.find_light()
|
||||
def find_light()
|
||||
end
|
||||
|
||||
def self.lights
|
||||
LIGHTS
|
||||
def lights
|
||||
@lights
|
||||
end
|
||||
|
||||
def self.light_count
|
||||
LIGHTS.count+1
|
||||
def light_count
|
||||
@lights.count+1
|
||||
end
|
||||
|
||||
def self.clear_lights
|
||||
LIGHTS.clear
|
||||
def clear_lights
|
||||
@lights.clear
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,17 +4,19 @@ class IMICFPS
|
||||
Point = Struct.new(:x, :y)
|
||||
Color = Struct.new(:red, :green, :blue, :alpha)
|
||||
|
||||
class ObjectManager
|
||||
OBJECTS = []
|
||||
def self.add_object(model)
|
||||
OBJECTS << model
|
||||
module ObjectManager # Get included into GameState context
|
||||
def add_object(model)
|
||||
@game_objects << model
|
||||
end
|
||||
|
||||
def self.find_object()
|
||||
def find_object()
|
||||
end
|
||||
|
||||
def self.objects
|
||||
OBJECTS
|
||||
def remove_object()
|
||||
end
|
||||
|
||||
def game_objects
|
||||
@game_objects
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,7 +10,7 @@ class IMICFPS
|
||||
attr_accessor :visible, :renderable, :backface_culling
|
||||
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
|
||||
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
|
||||
@bound_model = bound_model
|
||||
@backface_culling = backface_culling
|
||||
@@ -20,11 +20,13 @@ class IMICFPS
|
||||
@debug_color = Color.new(0.0, 1.0, 0.0)
|
||||
@terrain = terrain
|
||||
|
||||
@game_state = game_state
|
||||
|
||||
@width, @height, @depth = 0,0,0
|
||||
@delta_time = Gosu.milliseconds
|
||||
@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
|
||||
|
||||
if @bound_model
|
||||
|
||||
@@ -3,10 +3,12 @@ class IMICFPS
|
||||
include OpenGL
|
||||
attr_reader :ambient, :diffuse, :specular, :position, :light_id
|
||||
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),
|
||||
position: Vertex.new(x, y, z, 0), intensity: 1)
|
||||
@x,@y,@z = x,y,z
|
||||
@game_state = game_state
|
||||
@intensity = intensity
|
||||
|
||||
self.ambient = ambient
|
||||
@@ -15,13 +17,13 @@ class IMICFPS
|
||||
self.position = position
|
||||
@light_id = available_light
|
||||
|
||||
LightManager.add_light(self)
|
||||
@game_state.add_light(self)
|
||||
end
|
||||
|
||||
def available_light
|
||||
raise "Using to many lights, #{LightManager.light_count}/#{LightManager::MAX_LIGHTS}" if LightManager.light_count > LightManager::MAX_LIGHTS
|
||||
puts "OpenGL::GL_LIGHT#{LightManager.light_count}" if $debug
|
||||
@light_id = Object.const_get "OpenGL::GL_LIGHT#{LightManager.light_count}"
|
||||
raise "Using to many lights, #{@game_state.light_count}/#{LightManager::MAX_LIGHTS}" if @game_state.light_count > LightManager::MAX_LIGHTS
|
||||
puts "OpenGL::GL_LIGHT#{@game_state.light_count}" if $debug
|
||||
@light_id = Object.const_get "OpenGL::GL_LIGHT#{@game_state.light_count}"
|
||||
end
|
||||
|
||||
def ambient=(color)
|
||||
|
||||
@@ -4,7 +4,9 @@ class IMICFPS
|
||||
include GLU
|
||||
|
||||
attr_reader :bounding_boxes, :vertex_count
|
||||
def initialize
|
||||
def initialize(game_state:)
|
||||
@game_state = game_state
|
||||
|
||||
@bounding_boxes = {}
|
||||
@vertex_count = 0
|
||||
end
|
||||
@@ -215,7 +217,7 @@ class IMICFPS
|
||||
|
||||
glPopMatrix
|
||||
|
||||
found = ObjectManager.objects.detect { |o| o == bounding_box[:object] }
|
||||
found = @game_state.game_objects.detect { |o| o == bounding_box[:object] }
|
||||
|
||||
unless found
|
||||
@vertex_count -= @bounding_boxes[key][:vertices_size]
|
||||
|
||||
@@ -5,13 +5,15 @@ class IMICFPS
|
||||
|
||||
attr_reader :opengl_renderer, :bounding_box_renderer
|
||||
|
||||
def initialize
|
||||
@bounding_box_renderer = BoundingBoxRenderer.new
|
||||
def initialize(game_state:)
|
||||
@game_state = game_state
|
||||
|
||||
@bounding_box_renderer = BoundingBoxRenderer.new(game_state: game_state)
|
||||
@opengl_renderer = OpenGLRenderer.new
|
||||
end
|
||||
|
||||
def draw
|
||||
ObjectManager.objects.each do |object|
|
||||
@game_state.game_objects.each do |object|
|
||||
if object.visible && object.renderable
|
||||
# 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
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
class IMICFPS
|
||||
class GameState
|
||||
include CommonMethods
|
||||
include ObjectManager
|
||||
include LightManager
|
||||
|
||||
attr_reader :options
|
||||
def initialize(options = {})
|
||||
@options = options
|
||||
@delta_time = Gosu.milliseconds
|
||||
@game_objects = []
|
||||
@lights = []
|
||||
|
||||
setup
|
||||
end
|
||||
|
||||
def push_game_state(klass_or_instance)
|
||||
$window.push_game_state(klass_or_instance)
|
||||
window.push_game_state(klass_or_instance)
|
||||
end
|
||||
|
||||
def setup
|
||||
@@ -21,6 +27,9 @@ class IMICFPS
|
||||
def update
|
||||
end
|
||||
|
||||
def button_down(id)
|
||||
end
|
||||
|
||||
def button_up(id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,16 +4,16 @@ class IMICFPS
|
||||
include GLU
|
||||
|
||||
def setup
|
||||
@renderer = Renderer.new
|
||||
@terrain = Terrain.new#(size: 170, height: 0)
|
||||
@renderer = Renderer.new(game_state: self)
|
||||
@terrain = Terrain.new(game_state: self)#(size: 170, height: 0)
|
||||
@draw_skydome = true
|
||||
@skydome = Skydome.new(scale: 0.08, backface_culling: false, auto_manage: false)
|
||||
|
||||
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
|
||||
|
||||
@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.attach_to(@player)
|
||||
|
||||
@@ -24,8 +24,8 @@ class IMICFPS
|
||||
# @font = Gosu::Font.new(18, name: "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: 0, y: 100, z: 0, diffuse: Color.new(1.0, 0.5, 0.1))
|
||||
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), game_state: self)
|
||||
end
|
||||
|
||||
def glError?
|
||||
@@ -46,7 +46,7 @@ class IMICFPS
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # clear the screen and the depth buffer
|
||||
glError?
|
||||
|
||||
LightManager.lights.each(&:draw)
|
||||
@lights.each(&:draw)
|
||||
|
||||
@camera.draw
|
||||
@renderer.opengl_renderer.draw_object(@skydome) if @skydome.renderable
|
||||
@@ -106,8 +106,8 @@ eos
|
||||
@text.text = string
|
||||
|
||||
# Expensive AABB collision detection
|
||||
ObjectManager.objects.each do |object|
|
||||
ObjectManager.objects.each do |b|
|
||||
@game_objects.each do |object|
|
||||
@game_objects.each do |b|
|
||||
next if object == b
|
||||
next if object.is_a?(Terrain) || b.is_a?(Terrain)
|
||||
|
||||
@@ -124,7 +124,7 @@ eos
|
||||
end
|
||||
end
|
||||
|
||||
ObjectManager.objects.each(&:update)
|
||||
@game_objects.each(&:update)
|
||||
|
||||
@skydome.update if @skydome.renderable
|
||||
|
||||
@@ -136,7 +136,7 @@ eos
|
||||
end
|
||||
|
||||
def button_up(id)
|
||||
ObjectManager.objects.each do |object|
|
||||
@game_objects.each do |object|
|
||||
object.button_up(id) if defined?(object.button_up)
|
||||
end
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ class IMICFPS
|
||||
def setup
|
||||
@header = Text.new("I-MIC FPS", y: 10, size: 100, 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)
|
||||
@percentage = Text.new("0%", y: $window.height-50-25, size: 50, 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)
|
||||
|
||||
@dummy_game_object = nil
|
||||
@assets = []
|
||||
@@ -15,7 +15,7 @@ class IMICFPS
|
||||
add_asset(:obj, "objects/biped.obj")
|
||||
|
||||
# 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
|
||||
@cycled = false
|
||||
@@ -29,7 +29,15 @@ class IMICFPS
|
||||
@subheading.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
|
||||
end
|
||||
|
||||
@@ -58,7 +66,7 @@ class IMICFPS
|
||||
end
|
||||
else
|
||||
@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
|
||||
end
|
||||
end
|
||||
@@ -69,8 +77,8 @@ class IMICFPS
|
||||
|
||||
def progressbar
|
||||
@percentage.draw
|
||||
progress = (@asset_index.to_f/@assets.count)*$window.width
|
||||
draw_rect(0, $window.height-100, progress, 100, Gosu::Color.rgb(255,127,0))
|
||||
progress = (@asset_index.to_f/@assets.count)*window.width
|
||||
draw_rect(0, window.height-100, progress, 100, Gosu::Color.rgb(255,127,0))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -6,7 +6,7 @@ class IMICFPS
|
||||
push_game_state(LoadingState.new(forward: Game))
|
||||
end
|
||||
link "Exit" do
|
||||
$window.close
|
||||
window.close
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,9 +7,9 @@ class IMICFPS
|
||||
def initialize(window_width = 1280, window_height = 800, fullscreen = false)
|
||||
fps_target = (ARGV.first.to_i != 0) ? ARGV.first.to_i : 60
|
||||
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
|
||||
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
|
||||
$window = self
|
||||
@needs_cursor = false
|
||||
|
||||
@@ -10,4 +10,4 @@ Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
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