5 Commits

13 changed files with 153 additions and 26 deletions

View File

@@ -1,22 +1,23 @@
GIT
remote: https://github.com/cyberarm/cyberarm_engine
revision: d8551c7428da98bb7da76c138e5fbde50ef0137f
revision: 4055f645f3446c61f57ad1c7748284106c1516ff
specs:
cyberarm_engine (0.13.1)
gosu (~> 0.15.0)
gosu_more_drawables (~> 0.3)
GEM
remote: https://rubygems.org/
specs:
gosu (0.15.1)
gosu (0.15.1-x64-mingw32)
mini_portile2 (2.4.0)
nokogiri (1.11.0.rc1)
mini_portile2 (~> 2.4.0)
nokogiri (1.11.0.rc1-x64-mingw32)
mini_portile2 (~> 2.4.0)
gosu_more_drawables (0.3.0)
mini_portile2 (2.5.0)
nokogiri (1.11.0.rc2)
mini_portile2 (~> 2.5.0)
nokogiri (1.11.0.rc2-x64-mingw32)
ocra (1.3.11)
opengl-bindings (1.6.9)
opengl-bindings (1.6.10)
PLATFORMS
ruby

View File

@@ -106,6 +106,7 @@ require_relative "lib/scenes/turn_table"
require_relative "lib/crosshair"
require_relative "lib/demo"
require_relative "lib/overlay"
require_relative "lib/window"
require_relative "lib/tools/asset_viewer"

View File

@@ -14,7 +14,6 @@ class IMICFPS
@lights = []
@collision_manager = CollisionManager.new(map: self)
@renderer = window.renderer
Publisher.new
end
@@ -33,8 +32,11 @@ class IMICFPS
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)))
# add_light(Light.new(id: available_light, position: Vector.new(0, 100, 0), diffuse: Color.new(1.0, 0.5, 0.1)))
# Default lights if non are defined
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
def data
@@ -51,7 +53,7 @@ class IMICFPS
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # clear the screen and the depth buffer
gl_error?
@renderer.draw(camera, @lights, @entities)
window.renderer.draw(camera, @lights, @entities)
end
end

59
lib/overlay.rb Normal file
View 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

View File

@@ -155,6 +155,7 @@ class IMICFPS
end
if window.config.get(:debug_options, :wireframe)
glLineWidth(2)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
Shader.active_shader.uniform_boolean("disableLighting", true)
@@ -163,6 +164,7 @@ class IMICFPS
Shader.active_shader.uniform_boolean("disableLighting", false)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
glLineWidth(1)
end
glDrawArrays(GL_TRIANGLES, 0, model.faces.count * 3)

View File

@@ -12,7 +12,7 @@ class IMICFPS
@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")
@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)
@text.text = update_text
elsif window.config.get(:options, :fps)
@text.text = "FPS: #{Gosu.fps}"
else
@text.text = ""
end
@demo.update if @demo
window.number_of_vertices = 0
end
def update_text
@@ -66,10 +62,6 @@ Camera Field Of View: #{@camera.field_of_view}
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}
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
end

View File

@@ -2,7 +2,13 @@ class IMICFPS
class LoadingState < Menu
def setup
window.needs_cursor = false
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"
@subheading = Text.new("Loading Map: #{@map_parser.metadata.name}", y: 100, size: 50, alignment: :center)

View File

@@ -31,7 +31,6 @@ class IMICFPS
@lights << @light
@camera = Camera.new(position: Vector.new(0, 1.5, 5), orientation: Vector.forward)
@renderer = Renderer.new
label @manifest.name, text_size: 50
label @manifest.model
@@ -55,7 +54,7 @@ class IMICFPS
)
Gosu.gl do
@renderer.draw(@camera, [@light], @map.entities)
window.renderer.draw(@camera, [@light], @map.entities)
end
@crosshair.draw

View File

@@ -1 +1,2 @@
require_relative "map_editor/lib/main_menu"
require_relative "map_editor/lib/editor"

View 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

View File

@@ -29,7 +29,7 @@ class IMICFPS
flow(margin: 10) do
@maps.each do |map|
button map.metadata.name do
# push_state(TurnTable, manifest: manifest)
push_state(LoadingState, map_parser: map, forward: Editor)
end
end
end

View File

@@ -16,7 +16,7 @@ class IMICFPS
push_state(ExtrasMenu)
end
link "Exit" do
link "Exit Game" do
window.close
end

View File

@@ -26,6 +26,7 @@ class IMICFPS
@renderer = Renderer.new
@renderer.preload_default_shaders
@scene = TurnTableScene.new
@overlay = Overlay.new
@canvas_size = Vector.new(self.width, self.height)
@@ -46,6 +47,7 @@ class IMICFPS
super
@console.draw if @show_console
@overlay.draw
draw_cursor if needs_cursor
_canvas_size = Vector.new(self.width, self.height)
@@ -65,6 +67,9 @@ class IMICFPS
super
@console.update if @show_console
@overlay.update
@number_of_vertices = 0
@delta_time = Gosu.milliseconds
end