-
Notifications
You must be signed in to change notification settings - Fork 0
/
i-mic-fps.rb
114 lines (93 loc) · 2.5 KB
/
i-mic-fps.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# frozen_string_literal: true
require "fiddle"
require "yaml"
require "json"
require "abbrev"
require "time"
require "socket"
require "tmpdir"
require "securerandom"
require "opengl"
require "glu"
require "nokogiri"
require "i18n"
begin
require_relative "../cyberarm_engine/lib/cyberarm_engine"
require_relative "../cyberarm_engine/lib/cyberarm_engine/opengl"
rescue LoadError => e
pp e
require "cyberarm_engine"
require "cyberarm_engine/opengl"
end
Dir.chdir(File.dirname(__FILE__))
include CyberarmEngine
include OpenGL
include GLU
def require_all(directory)
files = Dir["#{directory}/**/*.rb"].sort!
file_order = []
loop do
failed = []
first_name_error = nil
files.each do |file|
begin
require_relative file
file_order << file
rescue NameError => e
failed << file
first_name_error ||= e
end
end
if failed.size == files.size
raise first_name_error
else
files = failed
end
break if failed.empty?
end
# pp file_order.map { |f| f.gsub(".rb", "")}
end
require_all "lib"
# Don't launch game if IMICFPS_SERVER_MODE is defined
# or if game is being packaged
def prevent_launch?
packaging_lockfile = File.expand_path("i-mic-fps-packaging.lock", Dir.tmpdir)
m = "Game client not launched"
return [true, "#{m}: Server is running"] if defined?(IMICFPS_SERVER_MODE) && IMICFPS_SERVER_MODE
return [true, "#{m}: Packaging is running"] if defined?(Ocra)
if File.exist?(packaging_lockfile) && File.read(packaging_lockfile).strip == IMICFPS::VERSION
return [true, "#{m}: Packaging lockfile is present (#{packaging_lockfile})"]
end
[false, ""]
end
if prevent_launch?[0]
puts prevent_launch?[1]
else
native = ARGV.join.include?("--native")
fps_target = ARGV.first.to_i != 0 ? ARGV.first.to_i : 60
window_width = native ? Gosu.screen_width : 1280
window_height = native ? Gosu.screen_height : 720
window_fullscreen = native ? true : false
window = IMICFPS::Window.new(
width: window_width,
height: window_height,
fullscreen: window_fullscreen,
resizable: !window_fullscreen,
update_interval: 1000.0 / fps_target
)
if ARGV.join.include?("--profile")
begin
require "ruby-prof"
RubyProf.start
window.show
result = RubyProf.stop
printer = RubyProf::MultiPrinter.new(result)
printer.print(path: ".", profile: "profile", min_percent: 2)
rescue LoadError
puts "ruby-prof not installed!"
raise
end
else
window.show
end
end