mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-17 00:22:36 +00:00
Compare commits
5 Commits
deferred_s
...
map_editor
| Author | SHA1 | Date | |
|---|---|---|---|
| bb21de2e2a | |||
| c53d42166b | |||
| c05009a000 | |||
| 9593d341bf | |||
| 27de5667be |
15
Gemfile.lock
15
Gemfile.lock
@@ -1,22 +1,23 @@
|
|||||||
GIT
|
GIT
|
||||||
remote: https://github.com/cyberarm/cyberarm_engine
|
remote: https://github.com/cyberarm/cyberarm_engine
|
||||||
revision: d8551c7428da98bb7da76c138e5fbde50ef0137f
|
revision: 4055f645f3446c61f57ad1c7748284106c1516ff
|
||||||
specs:
|
specs:
|
||||||
cyberarm_engine (0.13.1)
|
cyberarm_engine (0.13.1)
|
||||||
gosu (~> 0.15.0)
|
gosu (~> 0.15.0)
|
||||||
|
gosu_more_drawables (~> 0.3)
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
gosu (0.15.1)
|
gosu (0.15.1)
|
||||||
gosu (0.15.1-x64-mingw32)
|
gosu (0.15.1-x64-mingw32)
|
||||||
mini_portile2 (2.4.0)
|
gosu_more_drawables (0.3.0)
|
||||||
nokogiri (1.11.0.rc1)
|
mini_portile2 (2.5.0)
|
||||||
mini_portile2 (~> 2.4.0)
|
nokogiri (1.11.0.rc2)
|
||||||
nokogiri (1.11.0.rc1-x64-mingw32)
|
mini_portile2 (~> 2.5.0)
|
||||||
mini_portile2 (~> 2.4.0)
|
nokogiri (1.11.0.rc2-x64-mingw32)
|
||||||
ocra (1.3.11)
|
ocra (1.3.11)
|
||||||
opengl-bindings (1.6.9)
|
opengl-bindings (1.6.10)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
ruby
|
ruby
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ require_relative "lib/scenes/turn_table"
|
|||||||
require_relative "lib/crosshair"
|
require_relative "lib/crosshair"
|
||||||
require_relative "lib/demo"
|
require_relative "lib/demo"
|
||||||
|
|
||||||
|
require_relative "lib/overlay"
|
||||||
require_relative "lib/window"
|
require_relative "lib/window"
|
||||||
|
|
||||||
require_relative "lib/tools/asset_viewer"
|
require_relative "lib/tools/asset_viewer"
|
||||||
|
|||||||
10
lib/map.rb
10
lib/map.rb
@@ -14,7 +14,6 @@ class IMICFPS
|
|||||||
@lights = []
|
@lights = []
|
||||||
|
|
||||||
@collision_manager = CollisionManager.new(map: self)
|
@collision_manager = CollisionManager.new(map: self)
|
||||||
@renderer = window.renderer
|
|
||||||
Publisher.new
|
Publisher.new
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -33,8 +32,11 @@ class IMICFPS
|
|||||||
|
|
||||||
add_entity(Player.new(spawnpoint: @map_parser.spawnpoints.sample, manifest: Manifest.new(package: "base", name: "character")))
|
add_entity(Player.new(spawnpoint: @map_parser.spawnpoints.sample, manifest: Manifest.new(package: "base", name: "character")))
|
||||||
|
|
||||||
# add_light(Light.new(id: available_light, position: Vector.new(30, 10.0, 30)))
|
# Default lights if non are defined
|
||||||
# add_light(Light.new(id: available_light, position: Vector.new(0, 100, 0), diffuse: Color.new(1.0, 0.5, 0.1)))
|
if @map_parser.lights.size == 0
|
||||||
|
add_light(Light.new(id: available_light, position: Vector.new(30, 10.0, 30)))
|
||||||
|
add_light(Light.new(id: available_light, position: Vector.new(0, 100, 0), diffuse: Color.new(1.0, 0.5, 0.1)))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def data
|
def data
|
||||||
@@ -51,7 +53,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
|
||||||
gl_error?
|
gl_error?
|
||||||
|
|
||||||
@renderer.draw(camera, @lights, @entities)
|
window.renderer.draw(camera, @lights, @entities)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
59
lib/overlay.rb
Normal file
59
lib/overlay.rb
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
class IMICFPS
|
||||||
|
class Overlay
|
||||||
|
include CommonMethods
|
||||||
|
|
||||||
|
Slot = Struct.new(:value, :width)
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
@text = CyberarmEngine::Text.new("", x: 3, y: 3, shadow_color: Gosu::Color::BLACK)
|
||||||
|
@slots = []
|
||||||
|
@space_width = @text.textobject.text_width(" ")
|
||||||
|
end
|
||||||
|
|
||||||
|
def draw
|
||||||
|
return if @text.text.empty?
|
||||||
|
width = @text.width + 8
|
||||||
|
|
||||||
|
Gosu.draw_rect(0, 0, width, (@text.height + 4), Gosu::Color.rgba(0, 0, 0, 100))
|
||||||
|
Gosu.draw_rect(2, 2, width - 4, (@text.height + 4) - 4, Gosu::Color.rgba(100, 100, 100, 100))
|
||||||
|
|
||||||
|
@text.draw
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
rebuild_slots
|
||||||
|
end
|
||||||
|
|
||||||
|
def rebuild_slots
|
||||||
|
@slots.clear
|
||||||
|
|
||||||
|
if window.config.get(:options, :fps)
|
||||||
|
create_slot "FPS: #{Gosu.fps}"
|
||||||
|
create_slot "Frame time: #{Gosu.milliseconds - window.delta_time}ms" if window.config.get(:debug_options, :stats)
|
||||||
|
end
|
||||||
|
|
||||||
|
if window.config.get(:debug_options, :stats)
|
||||||
|
create_slot "Vertices: #{formatted_number(window.number_of_vertices)}"
|
||||||
|
create_slot "Face: #{formatted_number(window.number_of_vertices / 3)}"
|
||||||
|
end
|
||||||
|
|
||||||
|
if window.config.get(:debug_options, :boundingboxes)
|
||||||
|
create_slot "Boundingboxes: #{window.config.get(:debug_options, :boundingboxes) ? 'On' : 'Off'}"
|
||||||
|
end
|
||||||
|
|
||||||
|
if window.config.get(:debug_options, :wireframe)
|
||||||
|
create_slot "Wireframes: #{window.config.get(:debug_options, :wireframe) ? 'On' : 'Off'}"
|
||||||
|
end
|
||||||
|
|
||||||
|
@text.text = ""
|
||||||
|
@slots.each_with_index do |slot, i|
|
||||||
|
@text.text += "#{slot.value} <c=ff000000>•</c> " unless i == @slots.size - 1
|
||||||
|
@text.text += "#{slot.value}" if i == @slots.size - 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_slot(string)
|
||||||
|
@slots << Slot.new(string, @text.textobject.text_width(string))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -5,7 +5,7 @@ class IMICFPS
|
|||||||
attr_reader :screen_vbo, :vertices, :uvs
|
attr_reader :screen_vbo, :vertices, :uvs
|
||||||
def initialize
|
def initialize
|
||||||
@framebuffer = nil
|
@framebuffer = nil
|
||||||
@buffers = [:position, :diffuse, :normal, :texcoord, :scene]
|
@buffers = [:position, :diffuse, :normal, :texcoord]
|
||||||
@textures = {}
|
@textures = {}
|
||||||
@screen_vbo = nil
|
@screen_vbo = nil
|
||||||
@ready = false
|
@ready = false
|
||||||
@@ -86,9 +86,9 @@ class IMICFPS
|
|||||||
@textures[@buffers[i]] = texture_id
|
@textures[@buffers[i]] = texture_id
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, texture_id)
|
glBindTexture(GL_TEXTURE_2D, texture_id)
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA, GL_FLOAT, nil)
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, nil)
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, texture_id, 0)
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, texture_id, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ class IMICFPS
|
|||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nil)
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nil)
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, texture_id, 0)
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, texture_id, 0)
|
||||||
|
|
||||||
draw_buffers = @buffers.each_with_index.map { |b ,i| Object.const_get("GL_COLOR_ATTACHMENT#{i}") }
|
draw_buffers = [ GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 ]
|
||||||
glDrawBuffers(draw_buffers.size, draw_buffers.pack("I*"))
|
glDrawBuffers(draw_buffers.size, draw_buffers.pack("I*"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def render(camera, lights, entities)
|
def render(camera, lights, entities)
|
||||||
if Shader.available?("default") && Shader.available?("render_screen") && Shader.available?("lighting")
|
if Shader.available?("default") && Shader.available?("render_screen")
|
||||||
@g_buffer.bind_for_writing
|
@g_buffer.bind_for_writing
|
||||||
gl_error?
|
gl_error?
|
||||||
|
|
||||||
@@ -24,6 +24,19 @@ class IMICFPS
|
|||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
||||||
|
|
||||||
Shader.use("default") do |shader|
|
Shader.use("default") do |shader|
|
||||||
|
lights.each_with_index do |light, i|
|
||||||
|
shader.uniform_float("lights[#{i}.end", -1.0);
|
||||||
|
shader.uniform_float("lights[#{i}.type", light.type);
|
||||||
|
shader.uniform_vec3("lights[#{i}].position", light.position)
|
||||||
|
shader.uniform_vec3("lights[#{i}].ambient", light.ambient)
|
||||||
|
shader.uniform_vec3("lights[#{i}].diffuse", light.diffuse)
|
||||||
|
shader.uniform_vec3("lights[#{i}].specular", light.specular)
|
||||||
|
end
|
||||||
|
gl_error?
|
||||||
|
|
||||||
|
|
||||||
|
shader.uniform_integer("totalLights", lights.size)
|
||||||
|
|
||||||
entities.each do |entity|
|
entities.each do |entity|
|
||||||
next unless entity.visible && entity.renderable
|
next unless entity.visible && entity.renderable
|
||||||
|
|
||||||
@@ -39,9 +52,6 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
lighting(lights)
|
|
||||||
post_processing
|
|
||||||
|
|
||||||
@g_buffer.unbind_framebuffer
|
@g_buffer.unbind_framebuffer
|
||||||
gl_error?
|
gl_error?
|
||||||
|
|
||||||
@@ -49,6 +59,8 @@ class IMICFPS
|
|||||||
@g_buffer.bind_for_reading
|
@g_buffer.bind_for_reading
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0)
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0)
|
||||||
|
|
||||||
|
# lighting(lights)
|
||||||
|
post_processing
|
||||||
render_framebuffer
|
render_framebuffer
|
||||||
|
|
||||||
@g_buffer.unbind_framebuffer
|
@g_buffer.unbind_framebuffer
|
||||||
@@ -84,32 +96,25 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def lighting(lights)
|
def lighting(lights)
|
||||||
if Shader.available?("lighting")
|
@g_buffer.set_read_buffer(:position)
|
||||||
Shader.use("lighting") do |shader|
|
glBlitFramebuffer(0, 0, @g_buffer.width, @g_buffer.height,
|
||||||
lights.each do |light|
|
0, 0, @g_buffer.width / 2, @g_buffer.height / 2,
|
||||||
shader.uniform_integer("inLightType", light.type);
|
GL_COLOR_BUFFER_BIT, GL_LINEAR)
|
||||||
shader.uniform_vec3("inLightPosition", light.position)
|
|
||||||
shader.uniform_vec3("inLightAmbient", light.ambient)
|
|
||||||
shader.uniform_vec3("inLightDiffuse", light.diffuse)
|
|
||||||
shader.uniform_vec3("inLightSpecular", light.specular)
|
|
||||||
|
|
||||||
glBindVertexArray(@g_buffer.screen_vbo)
|
@g_buffer.set_read_buffer(:diffuse)
|
||||||
glEnableVertexAttribArray(0)
|
glBlitFramebuffer(0, 0, @g_buffer.width, @g_buffer.height,
|
||||||
glEnableVertexAttribArray(1)
|
0, @g_buffer.height / 2, @g_buffer.width / 2, @g_buffer.height,
|
||||||
|
GL_COLOR_BUFFER_BIT, GL_LINEAR)
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST)
|
@g_buffer.set_read_buffer(:normal)
|
||||||
glEnable(GL_BLEND)
|
glBlitFramebuffer(0, 0, @g_buffer.width, @g_buffer.height,
|
||||||
|
@g_buffer.width / 2, @g_buffer.height / 2, @g_buffer.width, @g_buffer.height,
|
||||||
|
GL_COLOR_BUFFER_BIT, GL_LINEAR)
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, @g_buffer.vertices.size)
|
@g_buffer.set_read_buffer(:texcoord)
|
||||||
|
glBlitFramebuffer(0, 0, @g_buffer.width, @g_buffer.height,
|
||||||
glDisableVertexAttribArray(1)
|
@g_buffer.width / 2, 0, @g_buffer.width, @g_buffer.height / 2,
|
||||||
glDisableVertexAttribArray(0)
|
GL_COLOR_BUFFER_BIT, GL_LINEAR)
|
||||||
glBindVertexArray(0)
|
|
||||||
end
|
|
||||||
|
|
||||||
gl_error?
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def post_processing
|
def post_processing
|
||||||
@@ -126,7 +131,7 @@ class IMICFPS
|
|||||||
glEnable(GL_BLEND)
|
glEnable(GL_BLEND)
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0)
|
glActiveTexture(GL_TEXTURE0)
|
||||||
glBindTexture(GL_TEXTURE_2D, @g_buffer.texture(:scene))
|
glBindTexture(GL_TEXTURE_2D, @g_buffer.texture(:diffuse))
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, @g_buffer.vertices.size)
|
glDrawArrays(GL_TRIANGLES, 0, @g_buffer.vertices.size)
|
||||||
|
|
||||||
@@ -150,6 +155,7 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
if window.config.get(:debug_options, :wireframe)
|
if window.config.get(:debug_options, :wireframe)
|
||||||
|
glLineWidth(2)
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
|
||||||
Shader.active_shader.uniform_boolean("disableLighting", true)
|
Shader.active_shader.uniform_boolean("disableLighting", true)
|
||||||
|
|
||||||
@@ -158,6 +164,7 @@ class IMICFPS
|
|||||||
|
|
||||||
Shader.active_shader.uniform_boolean("disableLighting", false)
|
Shader.active_shader.uniform_boolean("disableLighting", false)
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
|
||||||
|
glLineWidth(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, model.faces.count * 3)
|
glDrawArrays(GL_TRIANGLES, 0, model.faces.count * 3)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def preload_default_shaders
|
def preload_default_shaders
|
||||||
shaders = ["default", "render_screen", "lighting"]
|
shaders = ["default", "render_screen"]
|
||||||
shaders.each do |shader|
|
shaders.each do |shader|
|
||||||
Shader.new(
|
Shader.new(
|
||||||
name: shader,
|
name: shader,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class IMICFPS
|
|||||||
|
|
||||||
@crosshair = Crosshair.new
|
@crosshair = Crosshair.new
|
||||||
|
|
||||||
@text = Text.new("Pending...", x: 10, y: 10, z: 1, size: 18, font: "DejaVu Sans", shadow_color: Gosu::Color::BLACK)
|
@text = Text.new("Pending...", x: 10, y: 22, z: 1, size: 18, font: "DejaVu Sans", shadow_color: Gosu::Color::BLACK)
|
||||||
|
|
||||||
if ARGV.join.include?("--playdemo")
|
if ARGV.join.include?("--playdemo")
|
||||||
@demo = Demo.new(camera: @camera, player: @player, demo: "./demo.dat", mode: :play) if File.exist?("./demo.dat")
|
@demo = Demo.new(camera: @camera, player: @player, demo: "./demo.dat", mode: :play) if File.exist?("./demo.dat")
|
||||||
@@ -42,15 +42,11 @@ class IMICFPS
|
|||||||
|
|
||||||
if window.config.get(:debug_options, :stats)
|
if window.config.get(:debug_options, :stats)
|
||||||
@text.text = update_text
|
@text.text = update_text
|
||||||
elsif window.config.get(:options, :fps)
|
|
||||||
@text.text = "FPS: #{Gosu.fps}"
|
|
||||||
else
|
else
|
||||||
@text.text = ""
|
@text.text = ""
|
||||||
end
|
end
|
||||||
|
|
||||||
@demo.update if @demo
|
@demo.update if @demo
|
||||||
|
|
||||||
window.number_of_vertices = 0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_text
|
def update_text
|
||||||
@@ -66,10 +62,6 @@ Camera Field Of View: #{@camera.field_of_view}
|
|||||||
Camera Mouse Sesitivity: #{@camera.mouse_sensitivity}
|
Camera Mouse Sesitivity: #{@camera.mouse_sensitivity}
|
||||||
|
|
||||||
#{if @camera.entity then "Actor X: #{@camera.entity.position.x.round(2)} Y: #{@camera.entity.position.y.round(2)} Z: #{@camera.entity.position.z.round(2)}";end}
|
#{if @camera.entity then "Actor X: #{@camera.entity.position.x.round(2)} Y: #{@camera.entity.position.y.round(2)} Z: #{@camera.entity.position.z.round(2)}";end}
|
||||||
Last Frame: #{Gosu.milliseconds - window.delta_time}ms (#{Gosu.fps} fps)
|
|
||||||
|
|
||||||
Vertices: #{formatted_number(window.number_of_vertices)}
|
|
||||||
Faces: #{formatted_number(window.number_of_vertices/3)}
|
|
||||||
eos
|
eos
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,13 @@ class IMICFPS
|
|||||||
class LoadingState < Menu
|
class LoadingState < Menu
|
||||||
def setup
|
def setup
|
||||||
window.needs_cursor = false
|
window.needs_cursor = false
|
||||||
@map_parser = MapParser.new(map_file: @options[:map_file])
|
if @options[:map_file]
|
||||||
|
@map_parser = MapParser.new(map_file: @options[:map_file])
|
||||||
|
elsif @options[:map_parser]
|
||||||
|
@map_parser = @options[:map_parser]
|
||||||
|
else
|
||||||
|
raise "Unable to load map, missing :map_file or :map_parser"
|
||||||
|
end
|
||||||
|
|
||||||
title "I-MIC FPS"
|
title "I-MIC FPS"
|
||||||
@subheading = Text.new("Loading Map: #{@map_parser.metadata.name}", y: 100, size: 50, alignment: :center)
|
@subheading = Text.new("Loading Map: #{@map_parser.metadata.name}", y: 100, size: 50, alignment: :center)
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ class IMICFPS
|
|||||||
@lights << @light
|
@lights << @light
|
||||||
|
|
||||||
@camera = Camera.new(position: Vector.new(0, 1.5, 5), orientation: Vector.forward)
|
@camera = Camera.new(position: Vector.new(0, 1.5, 5), orientation: Vector.forward)
|
||||||
@renderer = Renderer.new
|
|
||||||
|
|
||||||
label @manifest.name, text_size: 50
|
label @manifest.name, text_size: 50
|
||||||
label @manifest.model
|
label @manifest.model
|
||||||
@@ -55,7 +54,7 @@ class IMICFPS
|
|||||||
)
|
)
|
||||||
|
|
||||||
Gosu.gl do
|
Gosu.gl do
|
||||||
@renderer.draw(@camera, [@light], @map.entities)
|
window.renderer.draw(@camera, [@light], @map.entities)
|
||||||
end
|
end
|
||||||
|
|
||||||
@crosshair.draw
|
@crosshair.draw
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
require_relative "map_editor/lib/main_menu"
|
require_relative "map_editor/lib/main_menu"
|
||||||
|
require_relative "map_editor/lib/editor"
|
||||||
59
lib/tools/map_editor/lib/editor.rb
Normal file
59
lib/tools/map_editor/lib/editor.rb
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
class IMICFPS
|
||||||
|
class MapEditorTool
|
||||||
|
class Editor < CyberarmEngine::GuiState
|
||||||
|
|
||||||
|
attr_reader :map
|
||||||
|
def setup
|
||||||
|
# TODO: Move everything required for a playable game map
|
||||||
|
# in to a Scene or Scene3D container object
|
||||||
|
# and refactor Game to use it.
|
||||||
|
Publisher.new
|
||||||
|
@map = Map.new( map_parser: @options[:map_parser] )
|
||||||
|
@camera = Camera.new( position: Vector.new )
|
||||||
|
@crosshair = Crosshair.new
|
||||||
|
|
||||||
|
@map.setup
|
||||||
|
end
|
||||||
|
|
||||||
|
def draw
|
||||||
|
super
|
||||||
|
@map.render(@camera)
|
||||||
|
@crosshair.draw
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
super
|
||||||
|
Publisher.instance.publish(:tick, Gosu.milliseconds - window.delta_time)
|
||||||
|
@map.update
|
||||||
|
@camera.update
|
||||||
|
end
|
||||||
|
|
||||||
|
def button_down(id)
|
||||||
|
if id == Gosu::KB_ESCAPE
|
||||||
|
# TODO: Use Editor specific menu
|
||||||
|
push_state(GamePauseMenu)
|
||||||
|
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
InputMapper.keydown(id)
|
||||||
|
Publisher.instance.publish(:button_down, nil, id)
|
||||||
|
|
||||||
|
@map.entities.each do |entity|
|
||||||
|
entity.button_down(id) if defined?(entity.button_down)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def button_up(id)
|
||||||
|
InputMapper.keyup(id)
|
||||||
|
Publisher.instance.publish(:button_up, nil, id)
|
||||||
|
|
||||||
|
@map.entities.each do |entity|
|
||||||
|
entity.button_up(id) if defined?(entity.button_up)
|
||||||
|
end
|
||||||
|
|
||||||
|
@camera.button_up(id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -29,7 +29,7 @@ class IMICFPS
|
|||||||
flow(margin: 10) do
|
flow(margin: 10) do
|
||||||
@maps.each do |map|
|
@maps.each do |map|
|
||||||
button map.metadata.name do
|
button map.metadata.name do
|
||||||
# push_state(TurnTable, manifest: manifest)
|
push_state(LoadingState, map_parser: map, forward: Editor)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class IMICFPS
|
|||||||
push_state(ExtrasMenu)
|
push_state(ExtrasMenu)
|
||||||
end
|
end
|
||||||
|
|
||||||
link "Exit" do
|
link "Exit Game" do
|
||||||
window.close
|
window.close
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ class IMICFPS
|
|||||||
@renderer = Renderer.new
|
@renderer = Renderer.new
|
||||||
@renderer.preload_default_shaders
|
@renderer.preload_default_shaders
|
||||||
@scene = TurnTableScene.new
|
@scene = TurnTableScene.new
|
||||||
|
@overlay = Overlay.new
|
||||||
|
|
||||||
@canvas_size = Vector.new(self.width, self.height)
|
@canvas_size = Vector.new(self.width, self.height)
|
||||||
|
|
||||||
@@ -46,6 +47,7 @@ class IMICFPS
|
|||||||
super
|
super
|
||||||
|
|
||||||
@console.draw if @show_console
|
@console.draw if @show_console
|
||||||
|
@overlay.draw
|
||||||
draw_cursor if needs_cursor
|
draw_cursor if needs_cursor
|
||||||
|
|
||||||
_canvas_size = Vector.new(self.width, self.height)
|
_canvas_size = Vector.new(self.width, self.height)
|
||||||
@@ -65,6 +67,9 @@ class IMICFPS
|
|||||||
super
|
super
|
||||||
|
|
||||||
@console.update if @show_console
|
@console.update if @show_console
|
||||||
|
@overlay.update
|
||||||
|
|
||||||
|
@number_of_vertices = 0
|
||||||
@delta_time = Gosu.milliseconds
|
@delta_time = Gosu.milliseconds
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
# version 330 core
|
# version 330 core
|
||||||
|
|
||||||
layout (location = 0) out vec4 fragPosition;
|
@include "light_struct"
|
||||||
|
|
||||||
|
layout(location = 0) out vec3 fragPosition;
|
||||||
layout (location = 1) out vec4 fragColor;
|
layout (location = 1) out vec4 fragColor;
|
||||||
layout (location = 2) out vec4 fragNormal;
|
layout (location = 2) out vec3 fragNormal;
|
||||||
layout (location = 3) out vec4 fragUV;
|
layout (location = 3) out vec3 fragUV;
|
||||||
|
|
||||||
in vec3 outPosition;
|
in vec3 outPosition;
|
||||||
in vec3 outColor;
|
in vec3 outColor;
|
||||||
in vec3 outNormal;
|
in vec3 outNormal;
|
||||||
in vec3 outUV;
|
in vec3 outUV;
|
||||||
in float outTextureID;
|
in float outTextureID;
|
||||||
|
in Light outLights[MAX_LIGHTS];
|
||||||
|
flat in int outTotalLights;
|
||||||
in vec3 outFragPos;
|
in vec3 outFragPos;
|
||||||
in vec3 outCameraPos;
|
in vec3 outCameraPos;
|
||||||
flat in int outHasTexture;
|
flat in int outHasTexture;
|
||||||
@@ -17,17 +21,88 @@ flat in int outDisableLighting;
|
|||||||
|
|
||||||
uniform sampler2D diffuse_texture;
|
uniform sampler2D diffuse_texture;
|
||||||
|
|
||||||
|
// optimizing compilers are annoying at this stage of my understanding of GLSL
|
||||||
|
vec4 lokiVar;
|
||||||
|
|
||||||
|
// https://learnopengl.com/Lighting/Multiple-lights
|
||||||
|
vec3 calculatePointLight(Light light) {
|
||||||
|
vec3 viewDir = normalize(outCameraPos - outFragPos);
|
||||||
|
vec3 lightDir = normalize(light.position - outFragPos);
|
||||||
|
float diff = max(dot(vec3(outNormal), lightDir), 0.0);
|
||||||
|
vec3 reflectDir = reflect(-lightDir, vec3(outNormal));
|
||||||
|
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 16.0);
|
||||||
|
|
||||||
|
float distance = length(light.position - outFragPos);
|
||||||
|
float attenuation = 1.0 / (1.0 + 0.09 * distance +
|
||||||
|
0.032 * (distance * distance));
|
||||||
|
|
||||||
|
vec3 ambient = light.ambient * outColor;
|
||||||
|
vec3 diffuse = light.diffuse * outColor;
|
||||||
|
vec3 specular = light.specular * spec * vec3(1.0, 1.0, 1.0);
|
||||||
|
|
||||||
|
ambient *= attenuation;
|
||||||
|
diffuse *= attenuation;
|
||||||
|
specular *= attenuation;
|
||||||
|
|
||||||
|
return (ambient + diffuse + specular);
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://learnopengl.com/Lighting/Basic-Lighting
|
||||||
|
vec3 calculateBasicLight(Light light) {
|
||||||
|
vec3 lightDir = normalize(light.position - outFragPos);
|
||||||
|
|
||||||
|
float ambientStrength = 0.25;
|
||||||
|
vec3 ambient = ambientStrength * light.ambient;
|
||||||
|
|
||||||
|
float diff = max(dot(normalize(vec3(outNormal)), lightDir), 0.0);
|
||||||
|
vec3 diffuse = diff * light.diffuse;
|
||||||
|
|
||||||
|
float specularStrength = 0.5;
|
||||||
|
vec3 viewDir = normalize(outCameraPos - outFragPos);
|
||||||
|
vec3 reflectDir = reflect(-lightDir, outNormal);
|
||||||
|
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
|
||||||
|
vec3 specular = specularStrength * spec * light.specular;
|
||||||
|
|
||||||
|
return vec3(ambient + diffuse + specular);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 calculateLighting() {
|
||||||
|
vec3 result = vec3(0.0, 0.0, 0.0);
|
||||||
|
|
||||||
|
for (int i = 0; i < min(outTotalLights, MAX_LIGHTS); i++) {
|
||||||
|
if (int(outLights[i].type) == 0) {
|
||||||
|
result += calculateBasicLight(outLights[i]);
|
||||||
|
} else if (int(outLights[i].type) == 1) {
|
||||||
|
result += calculateBasicLight(outLights[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
lokiVar = vec4(outColor, 1.0) + vec4(outNormal, 1.0) + vec4(outUV, 1.0) + vec4(outTextureID, 1.0, 1.0, 1.0);
|
||||||
|
lokiVar = normalize(lokiVar);
|
||||||
|
|
||||||
vec3 result;
|
vec3 result;
|
||||||
|
|
||||||
if (outHasTexture == 0) {
|
if (outHasTexture == 0) {
|
||||||
result = outColor;
|
if (outDisableLighting == 1.0) {
|
||||||
|
result = outColor + 0.25;
|
||||||
|
} else {
|
||||||
|
result = calculateLighting() * outColor;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = texture(diffuse_texture, outUV.xy).xyz;
|
if (outDisableLighting == 1.0) {
|
||||||
|
result = texture(diffuse_texture, outUV.xy).xyz + 0.25;
|
||||||
|
} else {
|
||||||
|
result = calculateLighting() * texture(diffuse_texture, outUV.xy).xyz;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fragPosition = vec4(outPosition, 1.0);
|
fragPosition = outPosition;
|
||||||
fragColor = vec4(result, 1.0);
|
fragColor = vec4(result, 1.0);
|
||||||
fragNormal = vec4(outNormal, 1.0);
|
fragNormal = outNormal;
|
||||||
fragUV = vec4(outUV, 1.0);
|
fragUV = outUV;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
# version 330 core
|
|
||||||
|
|
||||||
layout (location = 4) out vec4 sceneColor;
|
|
||||||
|
|
||||||
flat in int outLightType;
|
|
||||||
in vec3 outLightPosition;
|
|
||||||
in vec3 outLightAmbient;
|
|
||||||
in vec3 outLightDiffuse;
|
|
||||||
in vec3 outLightSpecular;
|
|
||||||
|
|
||||||
in vec2 outTexCoords;
|
|
||||||
|
|
||||||
@include "light_struct"
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
sceneColor = vec4(1.0, 0.5, 0.25, 1.0);
|
|
||||||
}
|
|
||||||
@@ -39,6 +39,8 @@ void main() {
|
|||||||
outUV = inUV;
|
outUV = inUV;
|
||||||
outTextureID = inTextureID;
|
outTextureID = inTextureID;
|
||||||
outHasTexture = hasTexture;
|
outHasTexture = hasTexture;
|
||||||
|
outLights = lights;
|
||||||
|
outTotalLights = totalLights;
|
||||||
outCameraPos = cameraPos;
|
outCameraPos = cameraPos;
|
||||||
outDisableLighting = disableLighting;
|
outDisableLighting = disableLighting;
|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
#version 330 core
|
|
||||||
layout (location = 0) in vec3 inPosition;
|
|
||||||
layout (location = 1) in vec2 inTexCoords;
|
|
||||||
|
|
||||||
in int inLightType;
|
|
||||||
in vec3 inLightPosition;
|
|
||||||
in vec3 inLightAmbient;
|
|
||||||
in vec3 inLightDiffuse;
|
|
||||||
in vec3 inLightSpecular;
|
|
||||||
|
|
||||||
flat out int outLightType;
|
|
||||||
out vec3 outLightPosition;
|
|
||||||
out vec3 outLightAmbient;
|
|
||||||
out vec3 outLightDiffuse;
|
|
||||||
out vec3 outLightSpecular;
|
|
||||||
|
|
||||||
out vec2 outTexCoords;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
gl_Position = vec4(inPosition.x, inPosition.y, inPosition.z, 1.0);
|
|
||||||
|
|
||||||
outLightType = inLightType;
|
|
||||||
outLightPosition = inLightPosition;
|
|
||||||
outLightAmbient = inLightAmbient;
|
|
||||||
outLightDiffuse = inLightDiffuse;
|
|
||||||
outLightSpecular = inLightSpecular;
|
|
||||||
outTexCoords = inTexCoords;
|
|
||||||
}
|
|
||||||
@@ -5,6 +5,6 @@ layout (location = 1) in vec2 inTexCoords;
|
|||||||
out vec2 outTexCoords;
|
out vec2 outTexCoords;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = vec4(inPosition.x, inPosition.y, inPosition.z, 1.0);
|
gl_Position = vec4(inPosition.x, inPosition.y, inPosition.z, 1.0);
|
||||||
outTexCoords = inTexCoords;
|
outTexCoords = inTexCoords;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user