cyberarm_engine 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -0
- data/Gemfile +1 -1
- data/Rakefile +1 -1
- data/assets/textures/default.png +0 -0
- data/cyberarm_engine.gemspec +10 -8
- data/lib/cyberarm_engine.rb +13 -2
- data/lib/cyberarm_engine/animator.rb +6 -4
- data/lib/cyberarm_engine/background.rb +19 -15
- data/lib/cyberarm_engine/background_nine_slice.rb +125 -0
- data/lib/cyberarm_engine/bounding_box.rb +18 -18
- data/lib/cyberarm_engine/cache.rb +4 -0
- data/lib/cyberarm_engine/cache/download_manager.rb +121 -0
- data/lib/cyberarm_engine/common.rb +13 -13
- data/lib/cyberarm_engine/config_file.rb +2 -2
- data/lib/cyberarm_engine/game_object.rb +63 -72
- data/lib/cyberarm_engine/game_state.rb +6 -3
- data/lib/cyberarm_engine/model.rb +207 -0
- data/lib/cyberarm_engine/model/material.rb +21 -0
- data/lib/cyberarm_engine/model/model_object.rb +131 -0
- data/lib/cyberarm_engine/model/parser.rb +74 -0
- data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -0
- data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -0
- data/lib/cyberarm_engine/model_cache.rb +31 -0
- data/lib/cyberarm_engine/opengl.rb +28 -0
- data/lib/cyberarm_engine/opengl/light.rb +50 -0
- data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -0
- data/lib/cyberarm_engine/opengl/perspective_camera.rb +38 -0
- data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -0
- data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +164 -0
- data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +289 -0
- data/lib/cyberarm_engine/opengl/renderer/renderer.rb +22 -0
- data/lib/cyberarm_engine/{shader.rb → opengl/shader.rb} +51 -43
- data/lib/cyberarm_engine/opengl/texture.rb +69 -0
- data/lib/cyberarm_engine/ray.rb +5 -5
- data/lib/cyberarm_engine/stats.rb +2 -2
- data/lib/cyberarm_engine/text.rb +41 -27
- data/lib/cyberarm_engine/timer.rb +1 -1
- data/lib/cyberarm_engine/transform.rb +43 -20
- data/lib/cyberarm_engine/ui/border_canvas.rb +4 -3
- data/lib/cyberarm_engine/ui/dsl.rb +25 -11
- data/lib/cyberarm_engine/ui/element.rb +30 -20
- data/lib/cyberarm_engine/ui/elements/button.rb +86 -16
- data/lib/cyberarm_engine/ui/elements/check_box.rb +1 -1
- data/lib/cyberarm_engine/ui/elements/container.rb +44 -20
- data/lib/cyberarm_engine/ui/elements/edit_box.rb +175 -2
- data/lib/cyberarm_engine/ui/elements/edit_line.rb +121 -37
- data/lib/cyberarm_engine/ui/elements/flow.rb +1 -1
- data/lib/cyberarm_engine/ui/elements/image.rb +12 -9
- data/lib/cyberarm_engine/ui/elements/label.rb +93 -14
- data/lib/cyberarm_engine/ui/elements/list_box.rb +64 -2
- data/lib/cyberarm_engine/ui/elements/progress.rb +5 -5
- data/lib/cyberarm_engine/ui/elements/radio.rb +1 -1
- data/lib/cyberarm_engine/ui/elements/slider.rb +13 -16
- data/lib/cyberarm_engine/ui/elements/stack.rb +1 -1
- data/lib/cyberarm_engine/ui/elements/toggle_button.rb +27 -19
- data/lib/cyberarm_engine/ui/event.rb +7 -7
- data/lib/cyberarm_engine/ui/gui_state.rb +44 -10
- data/lib/cyberarm_engine/ui/style.rb +10 -9
- data/lib/cyberarm_engine/ui/theme.rb +28 -20
- data/lib/cyberarm_engine/vector.rb +33 -30
- data/lib/cyberarm_engine/version.rb +2 -2
- data/lib/cyberarm_engine/window.rb +27 -18
- metadata +65 -15
@@ -17,10 +17,13 @@ module CyberarmEngine
|
|
17
17
|
@active_width = window.width
|
18
18
|
@active_height = window.height
|
19
19
|
|
20
|
+
@menu = nil
|
20
21
|
@focus = nil
|
21
22
|
@mouse_over = nil
|
22
23
|
@mouse_down_on = {}
|
23
24
|
@mouse_down_position = {}
|
25
|
+
@last_mouse_pos = nil
|
26
|
+
@dragging_element = nil
|
24
27
|
@pending_recalculate_request = false
|
25
28
|
|
26
29
|
@tip = CyberarmEngine::Text.new("", size: 22, z: Float::INFINITY)
|
@@ -32,7 +35,7 @@ module CyberarmEngine
|
|
32
35
|
# throws :blur event to focused element and sets GuiState focused element
|
33
36
|
# Does NOT throw :focus event at element or set element as focused
|
34
37
|
def focus=(element)
|
35
|
-
@focus.publish(:blur) if @focus
|
38
|
+
@focus.publish(:blur) if @focus && element && @focus != element
|
36
39
|
@focus = element
|
37
40
|
end
|
38
41
|
|
@@ -43,7 +46,13 @@ module CyberarmEngine
|
|
43
46
|
def draw
|
44
47
|
super
|
45
48
|
|
46
|
-
if @
|
49
|
+
if @menu
|
50
|
+
Gosu.flush
|
51
|
+
@menu.draw
|
52
|
+
end
|
53
|
+
|
54
|
+
if @tip.text.length.positive?
|
55
|
+
Gosu.flush
|
47
56
|
Gosu.draw_rect(@tip.x - 2, @tip.y - 2, @tip.width + 4, @tip.height + 4, 0xff020202, Float::INFINITY)
|
48
57
|
@tip.draw
|
49
58
|
end
|
@@ -53,12 +62,17 @@ module CyberarmEngine
|
|
53
62
|
if @pending_recalculate_request
|
54
63
|
@root_container.recalculate
|
55
64
|
@root_container.recalculate
|
65
|
+
@root_container.recalculate
|
66
|
+
|
56
67
|
@pending_recalculate_request = false
|
57
68
|
end
|
58
69
|
|
70
|
+
@menu&.update
|
59
71
|
super
|
60
72
|
|
61
|
-
new_mouse_over = @
|
73
|
+
new_mouse_over = @menu.hit_element?(window.mouse_x, window.mouse_y) if @menu
|
74
|
+
new_mouse_over ||= @root_container.hit_element?(window.mouse_x, window.mouse_y)
|
75
|
+
|
62
76
|
if new_mouse_over
|
63
77
|
new_mouse_over.publish(:enter) if new_mouse_over != @mouse_over
|
64
78
|
new_mouse_over.publish(:hover)
|
@@ -74,7 +88,8 @@ module CyberarmEngine
|
|
74
88
|
if Vector.new(window.mouse_x, window.mouse_y) == @last_mouse_pos
|
75
89
|
if @mouse_over && (Gosu.milliseconds - @mouse_moved_at) > tool_tip_delay
|
76
90
|
@tip.text = @mouse_over.tip if @mouse_over
|
77
|
-
@tip.x
|
91
|
+
@tip.x = window.mouse_x - @tip.width / 2
|
92
|
+
@tip.y = window.mouse_y - @tip.height - 4
|
78
93
|
else
|
79
94
|
@tip.text = ""
|
80
95
|
end
|
@@ -108,6 +123,8 @@ module CyberarmEngine
|
|
108
123
|
when Gosu::KbF5
|
109
124
|
request_recalculate
|
110
125
|
end
|
126
|
+
|
127
|
+
@focus.button_down(id) if @focus.respond_to?(:button_down)
|
111
128
|
end
|
112
129
|
|
113
130
|
def button_up(id)
|
@@ -125,9 +142,13 @@ module CyberarmEngine
|
|
125
142
|
when Gosu::MsWheelDown
|
126
143
|
redirect_mouse_wheel(:down)
|
127
144
|
end
|
145
|
+
|
146
|
+
@focus.button_up(id) if @focus.respond_to?(:button_up)
|
128
147
|
end
|
129
148
|
|
130
149
|
def redirect_mouse_button(button)
|
150
|
+
hide_menu unless @menu && (@menu == @mouse_over) || (@mouse_over&.parent == @menu)
|
151
|
+
|
131
152
|
if @focus && @mouse_over != @focus
|
132
153
|
@focus.publish(:blur)
|
133
154
|
@focus = nil
|
@@ -145,9 +166,14 @@ module CyberarmEngine
|
|
145
166
|
end
|
146
167
|
|
147
168
|
def redirect_released_mouse_button(button)
|
169
|
+
hide_menu if @menu && (@menu == @mouse_over) || (@mouse_over&.parent == @menu)
|
170
|
+
|
148
171
|
if @mouse_over
|
149
172
|
@mouse_over.publish(:"released_#{button}_mouse_button", window.mouse_x, window.mouse_y)
|
150
|
-
|
173
|
+
if @mouse_over == @mouse_down_on[button]
|
174
|
+
@mouse_over.publish(:"clicked_#{button}_mouse_button", window.mouse_x,
|
175
|
+
window.mouse_y)
|
176
|
+
end
|
151
177
|
end
|
152
178
|
|
153
179
|
if @dragging_element
|
@@ -162,13 +188,13 @@ module CyberarmEngine
|
|
162
188
|
def redirect_holding_mouse_button(button)
|
163
189
|
if !@dragging_element && @mouse_down_on[button] && @mouse_down_on[button].draggable?(button) && @mouse_pos.distance(@mouse_down_position[button]) > @min_drag_distance
|
164
190
|
@dragging_element = @mouse_down_on[button]
|
165
|
-
@dragging_element.publish(:
|
191
|
+
@dragging_element.publish(:begin_drag, window.mouse_x, window.mouse_y, button)
|
166
192
|
end
|
167
193
|
|
168
194
|
if @dragging_element
|
169
|
-
@dragging_element.publish(:
|
170
|
-
|
171
|
-
@mouse_over.publish(:"holding_#{button}_mouse_button", window.mouse_x, window.mouse_y)
|
195
|
+
@dragging_element.publish(:drag_update, window.mouse_x, window.mouse_y, button) if @dragging_element
|
196
|
+
elsif @mouse_over
|
197
|
+
@mouse_over.publish(:"holding_#{button}_mouse_button", window.mouse_x, window.mouse_y)
|
172
198
|
end
|
173
199
|
end
|
174
200
|
|
@@ -180,5 +206,13 @@ module CyberarmEngine
|
|
180
206
|
def request_recalculate
|
181
207
|
@pending_recalculate_request = true
|
182
208
|
end
|
209
|
+
|
210
|
+
def show_menu(list_box)
|
211
|
+
@menu = list_box
|
212
|
+
end
|
213
|
+
|
214
|
+
def hide_menu
|
215
|
+
@menu = nil
|
216
|
+
end
|
183
217
|
end
|
184
|
-
end
|
218
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module Gosu
|
2
2
|
class Color
|
3
|
-
def _dump(
|
3
|
+
def _dump(_level)
|
4
4
|
[
|
5
|
-
"%02X" %
|
6
|
-
"%02X" %
|
7
|
-
"%02X" %
|
8
|
-
"%02X" %
|
5
|
+
"%02X" % alpha,
|
6
|
+
"%02X" % red,
|
7
|
+
"%02X" % green,
|
8
|
+
"%02X" % blue
|
9
9
|
].join
|
10
10
|
end
|
11
11
|
|
@@ -21,17 +21,18 @@ module CyberarmEngine
|
|
21
21
|
@hash = Marshal.load(Marshal.dump(hash))
|
22
22
|
end
|
23
23
|
|
24
|
-
def method_missing(method, *args
|
24
|
+
def method_missing(method, *args)
|
25
25
|
if method.to_s.end_with?("=")
|
26
26
|
raise "Did not expect more than 1 argument" if args.size > 1
|
27
|
-
|
27
|
+
|
28
|
+
@hash[method.to_s.sub("=", "").to_sym] = args.first
|
28
29
|
|
29
30
|
elsif args.size == 0
|
30
|
-
|
31
|
+
@hash[method]
|
31
32
|
|
32
33
|
else
|
33
34
|
raise ArgumentError, "Did not expect arguments"
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|
37
|
-
end
|
38
|
+
end
|
@@ -11,17 +11,21 @@ module CyberarmEngine
|
|
11
11
|
|
12
12
|
def theme_defaults(options)
|
13
13
|
raise "Error" unless self.class.ancestors.include?(CyberarmEngine::Element)
|
14
|
+
|
14
15
|
_theme = THEME
|
15
|
-
_theme = _theme
|
16
|
+
_theme = deep_merge(_theme, options[:theme]) if options[:theme]
|
16
17
|
_theme.delete(:theme) if options[:theme]
|
17
18
|
|
18
19
|
hash = {}
|
19
20
|
class_names = self.class.ancestors
|
20
|
-
class_names = class_names[0..class_names.index(CyberarmEngine::Element)].map!
|
21
|
+
class_names = class_names[0..class_names.index(CyberarmEngine::Element)].map! do |c|
|
22
|
+
c.to_s.split("::").last.to_sym
|
23
|
+
end.reverse!
|
21
24
|
|
22
25
|
class_names.each do |klass|
|
23
26
|
next unless data = _theme.dig(klass)
|
24
|
-
|
27
|
+
|
28
|
+
data.each do |_key, _value|
|
25
29
|
hash.merge!(data)
|
26
30
|
end
|
27
31
|
end
|
@@ -32,7 +36,7 @@ module CyberarmEngine
|
|
32
36
|
# Derived from Rails Hash#deep_merge!
|
33
37
|
# Enables passing partial themes through Element options without issue
|
34
38
|
def deep_merge(original, intergrate, &block)
|
35
|
-
|
39
|
+
original.merge(intergrate) do |key, this_val, other_val|
|
36
40
|
if this_val.is_a?(Hash) && other_val.is_a?(Hash)
|
37
41
|
deep_merge(this_val, other_val, &block)
|
38
42
|
elsif block_given?
|
@@ -41,8 +45,6 @@ module CyberarmEngine
|
|
41
45
|
other_val
|
42
46
|
end
|
43
47
|
end
|
44
|
-
|
45
|
-
return hash
|
46
48
|
end
|
47
49
|
|
48
50
|
THEME = {
|
@@ -51,28 +53,30 @@ module CyberarmEngine
|
|
51
53
|
y: 0,
|
52
54
|
z: 30,
|
53
55
|
|
54
|
-
width:
|
56
|
+
width: nil,
|
55
57
|
height: nil,
|
56
|
-
color:
|
58
|
+
color: Gosu::Color::WHITE,
|
57
59
|
background: Gosu::Color::NONE,
|
58
|
-
margin:
|
59
|
-
padding:
|
60
|
+
margin: 0,
|
61
|
+
padding: 0,
|
60
62
|
border_thickness: 0,
|
61
63
|
border_color: Gosu::Color::NONE,
|
62
|
-
border_radius: 0
|
64
|
+
border_radius: 0
|
63
65
|
},
|
64
66
|
|
65
67
|
Button: { # < Label
|
66
|
-
margin:
|
67
|
-
padding:
|
68
|
+
margin: 1,
|
69
|
+
padding: 4,
|
68
70
|
border_thickness: 1,
|
69
71
|
border_color: ["ffd59674".hex, "ffff8746".hex],
|
70
72
|
border_radius: 0,
|
71
73
|
background: ["ffc75e61".to_i(16), "ffe26623".to_i(16)],
|
74
|
+
text_align: :center,
|
75
|
+
text_wrap: :none,
|
72
76
|
|
73
77
|
hover: {
|
74
|
-
color: Gosu::Color.rgb(200,200,200),
|
75
|
-
background:
|
78
|
+
color: Gosu::Color.rgb(200, 200, 200),
|
79
|
+
background: ["ffB23E41".to_i(16), "ffFF7C00".to_i(16)]
|
76
80
|
},
|
77
81
|
|
78
82
|
active: {
|
@@ -89,18 +93,22 @@ module CyberarmEngine
|
|
89
93
|
caret_color: Gosu::Color::WHITE,
|
90
94
|
caret_interval: 500,
|
91
95
|
selection_color: Gosu::Color.rgba(255, 128, 50, 200),
|
96
|
+
text_align: :left
|
92
97
|
},
|
93
98
|
|
94
99
|
Image: { # < Element
|
100
|
+
color: Gosu::Color::WHITE,
|
95
101
|
retro: false
|
96
102
|
},
|
97
103
|
|
98
104
|
Label: { # < Element
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
105
|
+
text_size: 28,
|
106
|
+
text_wrap: :none, # :word_wrap, :break_word, :none
|
107
|
+
text_shadow: false,
|
108
|
+
text_align: :left,
|
109
|
+
font: "Arial",
|
110
|
+
margin: 0,
|
111
|
+
padding: 2
|
104
112
|
},
|
105
113
|
|
106
114
|
ToggleButton: { # < Button
|
@@ -60,22 +60,15 @@ module CyberarmEngine
|
|
60
60
|
Vector.new(0, 0, -1)
|
61
61
|
end
|
62
62
|
|
63
|
+
attr_accessor :x, :y, :z, :weight
|
64
|
+
|
63
65
|
def initialize(x = 0, y = 0, z = 0, weight = 0)
|
64
|
-
@x
|
66
|
+
@x = x
|
67
|
+
@y = y
|
68
|
+
@z = z
|
69
|
+
@weight = weight
|
65
70
|
end
|
66
71
|
|
67
|
-
def x; @x; end
|
68
|
-
def x=(n); @x = n; end
|
69
|
-
|
70
|
-
def y; @y; end
|
71
|
-
def y=(n); @y = n; end
|
72
|
-
|
73
|
-
def z; @z; end
|
74
|
-
def z=(n); @z = n; end
|
75
|
-
|
76
|
-
def weight; @weight; end
|
77
|
-
def weight=(n); @weight = n; end
|
78
|
-
|
79
72
|
alias w weight
|
80
73
|
alias w= weight=
|
81
74
|
|
@@ -83,14 +76,14 @@ module CyberarmEngine
|
|
83
76
|
def ==(other)
|
84
77
|
if other.is_a?(Numeric)
|
85
78
|
@x == other &&
|
86
|
-
|
87
|
-
|
88
|
-
|
79
|
+
@y == other &&
|
80
|
+
@z == other &&
|
81
|
+
@weight == other
|
89
82
|
elsif other.is_a?(Vector)
|
90
83
|
@x == other.x &&
|
91
|
-
|
92
|
-
|
93
|
-
|
84
|
+
@y == other.y &&
|
85
|
+
@z == other.z &&
|
86
|
+
@weight == other.weight
|
94
87
|
else
|
95
88
|
other == self
|
96
89
|
end
|
@@ -137,6 +130,17 @@ module CyberarmEngine
|
|
137
130
|
operator("*", other)
|
138
131
|
end
|
139
132
|
|
133
|
+
def multiply_transform(transform)
|
134
|
+
e = transform.elements
|
135
|
+
|
136
|
+
x = @x * e[0] + @y * e[1] + @z * e[2] + 1 * e[3]
|
137
|
+
y = @x * e[4] + @y * e[5] + @z * e[6] + 1 * e[7]
|
138
|
+
z = @x * e[8] + @y * e[9] + @z * e[10] + 1 * e[11]
|
139
|
+
w = @x * e[12] + @y * e[13] + @z * e[14] + 1 * e[15]
|
140
|
+
|
141
|
+
Vector.new(x / 1, y / 1, z / 1, w / 1)
|
142
|
+
end
|
143
|
+
|
140
144
|
# Divides Vector and Numeric or Vector and Vector, excluding {weight}
|
141
145
|
# @return [CyberarmEngine::Vector]
|
142
146
|
def /(other)
|
@@ -161,20 +165,20 @@ module CyberarmEngine
|
|
161
165
|
def dot(other)
|
162
166
|
product = 0
|
163
167
|
|
164
|
-
a =
|
168
|
+
a = to_a
|
165
169
|
b = other.to_a
|
166
170
|
|
167
171
|
3.times do |i|
|
168
|
-
product
|
172
|
+
product += (a[i] * b[i])
|
169
173
|
end
|
170
174
|
|
171
|
-
|
175
|
+
product
|
172
176
|
end
|
173
177
|
|
174
178
|
# cross product of {Vector}
|
175
179
|
# @return [CyberarmEngine::Vector]
|
176
180
|
def cross(other)
|
177
|
-
a =
|
181
|
+
a = to_a
|
178
182
|
b = other.to_a
|
179
183
|
|
180
184
|
Vector.new(
|
@@ -187,7 +191,7 @@ module CyberarmEngine
|
|
187
191
|
# returns degrees
|
188
192
|
# @return [Float]
|
189
193
|
def angle(other)
|
190
|
-
Math.acos(
|
194
|
+
Math.acos(normalized.dot(other.normalized)) * 180 / Math::PI
|
191
195
|
end
|
192
196
|
|
193
197
|
# returns magnitude of Vector, ignoring #weight
|
@@ -209,7 +213,6 @@ module CyberarmEngine
|
|
209
213
|
self / Vector.new(mag, mag, mag)
|
210
214
|
end
|
211
215
|
|
212
|
-
|
213
216
|
# returns a direction {Vector}
|
214
217
|
#
|
215
218
|
# z is pitch
|
@@ -254,19 +257,19 @@ module CyberarmEngine
|
|
254
257
|
# 2D distance using X and Y
|
255
258
|
# @return [Float]
|
256
259
|
def distance(other)
|
257
|
-
Math.sqrt((@x-other.x)**2 + (@y-other.y)**2)
|
260
|
+
Math.sqrt((@x - other.x)**2 + (@y - other.y)**2)
|
258
261
|
end
|
259
262
|
|
260
263
|
# 2D distance using X and Z
|
261
264
|
# @return [Float]
|
262
265
|
def gl_distance2d(other)
|
263
|
-
Math.sqrt((@x-other.x)**2 + (@z-other.z)**2)
|
266
|
+
Math.sqrt((@x - other.x)**2 + (@z - other.z)**2)
|
264
267
|
end
|
265
268
|
|
266
269
|
# 3D distance using X, Y, and Z
|
267
270
|
# @return [Float]
|
268
271
|
def distance3d(other)
|
269
|
-
Math.sqrt((@x-other.x)**2 + (@y-other.y)**2 + (@z-other.z)**2)
|
272
|
+
Math.sqrt((@x - other.x)**2 + (@y - other.y)**2 + (@z - other.z)**2)
|
270
273
|
end
|
271
274
|
|
272
275
|
# Converts {Vector} to Array
|
@@ -284,7 +287,7 @@ module CyberarmEngine
|
|
284
287
|
# Converts {Vector} to Hash
|
285
288
|
# @return [Hash]
|
286
289
|
def to_h
|
287
|
-
{x: @x, y: @y, z: @z, weight: @weight}
|
290
|
+
{ x: @x, y: @y, z: @z, weight: @weight }
|
288
291
|
end
|
289
292
|
end
|
290
|
-
end
|
293
|
+
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module CyberarmEngine
|
2
2
|
class Window < Gosu::Window
|
3
3
|
IMAGES = {}
|
4
|
-
SAMPLES= {}
|
5
|
-
SONGS
|
4
|
+
SAMPLES = {}
|
5
|
+
SONGS = {}
|
6
6
|
|
7
7
|
attr_accessor :show_cursor
|
8
|
+
attr_writer :exit_on_opengl_error
|
8
9
|
attr_reader :last_frame_time
|
9
10
|
|
10
11
|
def self.now
|
@@ -12,19 +13,20 @@ module CyberarmEngine
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def self.dt
|
15
|
-
$window.last_frame_time/1000.0
|
16
|
+
$window.last_frame_time / 1000.0
|
16
17
|
end
|
17
18
|
|
18
|
-
def initialize(width: 800, height: 600, fullscreen: false, update_interval: 1000.0/60, resizable: false)
|
19
|
+
def initialize(width: 800, height: 600, fullscreen: false, update_interval: 1000.0 / 60, resizable: false, borderless: false)
|
19
20
|
@show_cursor = false
|
20
21
|
|
21
|
-
super(width, height, fullscreen: fullscreen, update_interval: update_interval, resizable: resizable)
|
22
|
+
super(width, height, fullscreen: fullscreen, update_interval: update_interval, resizable: resizable, borderless: borderless)
|
22
23
|
$window = self
|
23
|
-
@last_frame_time = Gosu.milliseconds-1
|
24
|
+
@last_frame_time = Gosu.milliseconds - 1
|
24
25
|
@current_frame_time = Gosu.milliseconds
|
25
26
|
self.caption = "CyberarmEngine #{CyberarmEngine::VERSION} #{Gosu.language}"
|
26
27
|
|
27
28
|
@states = []
|
29
|
+
@exit_on_opengl_error = false
|
28
30
|
|
29
31
|
setup if defined?(setup)
|
30
32
|
end
|
@@ -37,7 +39,7 @@ module CyberarmEngine
|
|
37
39
|
Stats.clear
|
38
40
|
|
39
41
|
current_state.update if current_state
|
40
|
-
@last_frame_time = Gosu.milliseconds
|
42
|
+
@last_frame_time = Gosu.milliseconds - @current_frame_time
|
41
43
|
@current_frame_time = Gosu.milliseconds
|
42
44
|
end
|
43
45
|
|
@@ -46,7 +48,15 @@ module CyberarmEngine
|
|
46
48
|
end
|
47
49
|
|
48
50
|
def dt
|
49
|
-
@last_frame_time/1000.0
|
51
|
+
@last_frame_time / 1000.0
|
52
|
+
end
|
53
|
+
|
54
|
+
def aspect_ratio
|
55
|
+
width / height.to_f
|
56
|
+
end
|
57
|
+
|
58
|
+
def exit_on_opengl_error?
|
59
|
+
@exit_on_opengl_error
|
50
60
|
end
|
51
61
|
|
52
62
|
def button_down(id)
|
@@ -59,8 +69,8 @@ module CyberarmEngine
|
|
59
69
|
current_state.button_up(id) if current_state
|
60
70
|
end
|
61
71
|
|
62
|
-
def push_state(klass, options={})
|
63
|
-
options = {setup: true}.merge(options)
|
72
|
+
def push_state(klass, options = {})
|
73
|
+
options = { setup: true }.merge(options)
|
64
74
|
|
65
75
|
if klass.instance_of?(klass.class) && defined?(klass.options)
|
66
76
|
@states << klass
|
@@ -68,12 +78,12 @@ module CyberarmEngine
|
|
68
78
|
else
|
69
79
|
@states << klass.new(options) if child_of?(klass, GameState)
|
70
80
|
@states << klass.new if child_of?(klass, Element::Container)
|
71
|
-
current_state.setup if current_state.
|
81
|
+
current_state.setup if current_state.instance_of?(klass) && options[:setup]
|
72
82
|
end
|
73
83
|
end
|
74
84
|
|
75
85
|
private def child_of?(input, klass)
|
76
|
-
input.ancestors.detect {|c| c == klass}
|
86
|
+
input.ancestors.detect { |c| c == klass }
|
77
87
|
end
|
78
88
|
|
79
89
|
def current_state
|
@@ -81,10 +91,8 @@ module CyberarmEngine
|
|
81
91
|
end
|
82
92
|
|
83
93
|
def previous_state
|
84
|
-
if @states.size > 1 && state = @states[@states.size-2]
|
85
|
-
|
86
|
-
else
|
87
|
-
return nil
|
94
|
+
if @states.size > 1 && state = @states[@states.size - 2]
|
95
|
+
state
|
88
96
|
end
|
89
97
|
end
|
90
98
|
|
@@ -93,10 +101,11 @@ module CyberarmEngine
|
|
93
101
|
end
|
94
102
|
|
95
103
|
# Sourced from https://gist.github.com/ippa/662583
|
96
|
-
def draw_circle(cx,cy,r, z = 9999,color = Gosu::Color::GREEN, step = 10)
|
104
|
+
def draw_circle(cx, cy, r, z = 9999, color = Gosu::Color::GREEN, step = 10)
|
97
105
|
0.step(360, step) do |a1|
|
98
106
|
a2 = a1 + step
|
99
|
-
draw_line(cx + Gosu.offset_x(a1, r), cy + Gosu.offset_y(a1, r), color, cx + Gosu.offset_x(a2, r),
|
107
|
+
draw_line(cx + Gosu.offset_x(a1, r), cy + Gosu.offset_y(a1, r), color, cx + Gosu.offset_x(a2, r),
|
108
|
+
cy + Gosu.offset_y(a2, r), color, z)
|
100
109
|
end
|
101
110
|
end
|
102
111
|
end
|