cyberarm_engine 0.24.4 → 0.24.5
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/.gitignore +8 -8
- data/.rubocop.yml +7 -7
- data/.travis.yml +5 -5
- data/Gemfile +6 -6
- data/Gemfile.lock +24 -0
- data/LICENSE.txt +21 -21
- data/README.md +74 -74
- data/Rakefile +10 -10
- data/assets/shaders/fragment/g_buffer.glsl +30 -30
- data/assets/shaders/fragment/lighting.glsl +115 -69
- data/assets/shaders/include/light_struct.glsl +11 -11
- data/assets/shaders/include/material_struct.glsl +16 -16
- data/assets/shaders/vertex/g_buffer.glsl +28 -28
- data/assets/shaders/vertex/lighting.glsl +24 -24
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/cyberarm_engine.gemspec +36 -36
- data/lib/cyberarm_engine/animator.rb +219 -219
- data/lib/cyberarm_engine/background.rb +180 -179
- data/lib/cyberarm_engine/background_image.rb +93 -93
- data/lib/cyberarm_engine/background_nine_slice.rb +142 -142
- data/lib/cyberarm_engine/bounding_box.rb +150 -150
- data/lib/cyberarm_engine/builtin/intro_state.rb +130 -130
- data/lib/cyberarm_engine/cache/download_manager.rb +123 -123
- data/lib/cyberarm_engine/cache.rb +4 -4
- data/lib/cyberarm_engine/common.rb +128 -128
- data/lib/cyberarm_engine/config_file.rb +46 -46
- data/lib/cyberarm_engine/console/command.rb +157 -157
- data/lib/cyberarm_engine/console/commands/help_command.rb +43 -43
- data/lib/cyberarm_engine/console/subcommand.rb +99 -99
- data/lib/cyberarm_engine/console.rb +248 -248
- data/lib/cyberarm_engine/game_object.rb +244 -244
- data/lib/cyberarm_engine/game_state.rb +124 -124
- data/lib/cyberarm_engine/gosu_ext/draw_arc.rb +97 -97
- data/lib/cyberarm_engine/gosu_ext/draw_circle.rb +30 -30
- data/lib/cyberarm_engine/gosu_ext/draw_path.rb +17 -17
- data/lib/cyberarm_engine/model/material.rb +21 -21
- data/lib/cyberarm_engine/model/{model_object.rb → mesh.rb} +131 -131
- data/lib/cyberarm_engine/model/parser.rb +74 -74
- data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -138
- data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -154
- data/lib/cyberarm_engine/model.rb +216 -213
- data/lib/cyberarm_engine/model_cache.rb +31 -31
- data/lib/cyberarm_engine/notification.rb +82 -82
- data/lib/cyberarm_engine/notification_manager.rb +241 -241
- data/lib/cyberarm_engine/opengl/light.rb +52 -50
- data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -46
- data/lib/cyberarm_engine/opengl/perspective_camera.rb +41 -38
- data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -249
- data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +167 -165
- data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +307 -304
- data/lib/cyberarm_engine/opengl/renderer/renderer.rb +33 -33
- data/lib/cyberarm_engine/opengl/shader.rb +408 -406
- data/lib/cyberarm_engine/opengl/texture.rb +69 -69
- data/lib/cyberarm_engine/opengl.rb +53 -40
- data/lib/cyberarm_engine/ray.rb +56 -56
- data/lib/cyberarm_engine/stats.rb +200 -200
- data/lib/cyberarm_engine/text.rb +260 -260
- data/lib/cyberarm_engine/timer.rb +23 -23
- data/lib/cyberarm_engine/transform.rb +296 -296
- data/lib/cyberarm_engine/trees/aabb_node.rb +126 -0
- data/lib/cyberarm_engine/trees/aabb_tree.rb +55 -0
- data/lib/cyberarm_engine/trees/aabb_tree_debug.rb +29 -0
- data/lib/cyberarm_engine/ui/border_canvas.rb +102 -102
- data/lib/cyberarm_engine/ui/dsl.rb +142 -142
- data/lib/cyberarm_engine/ui/element.rb +662 -662
- data/lib/cyberarm_engine/ui/elements/button.rb +100 -100
- data/lib/cyberarm_engine/ui/elements/check_box.rb +54 -54
- data/lib/cyberarm_engine/ui/elements/container.rb +404 -404
- data/lib/cyberarm_engine/ui/elements/edit_box.rb +179 -179
- data/lib/cyberarm_engine/ui/elements/edit_line.rb +297 -297
- data/lib/cyberarm_engine/ui/elements/flow.rb +15 -15
- data/lib/cyberarm_engine/ui/elements/image.rb +72 -72
- data/lib/cyberarm_engine/ui/elements/list_box.rb +79 -79
- data/lib/cyberarm_engine/ui/elements/menu.rb +27 -27
- data/lib/cyberarm_engine/ui/elements/menu_item.rb +6 -6
- data/lib/cyberarm_engine/ui/elements/progress.rb +93 -93
- data/lib/cyberarm_engine/ui/elements/radio.rb +6 -6
- data/lib/cyberarm_engine/ui/elements/slider.rb +107 -107
- data/lib/cyberarm_engine/ui/elements/stack.rb +11 -11
- data/lib/cyberarm_engine/ui/elements/text_block.rb +216 -216
- data/lib/cyberarm_engine/ui/elements/toggle_button.rb +67 -67
- data/lib/cyberarm_engine/ui/event.rb +54 -54
- data/lib/cyberarm_engine/ui/gui_state.rb +321 -321
- data/lib/cyberarm_engine/ui/style.rb +50 -50
- data/lib/cyberarm_engine/ui/theme.rb +225 -225
- data/lib/cyberarm_engine/vector.rb +312 -312
- data/lib/cyberarm_engine/version.rb +4 -4
- data/lib/cyberarm_engine/window.rb +195 -195
- data/lib/cyberarm_engine.rb +70 -78
- data/mrbgem.rake +29 -29
- metadata +8 -7
@@ -1,242 +1,242 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class NotificationManager
|
3
|
-
EDGE_TOP = :top
|
4
|
-
EDGE_BOTTOM = :bottom
|
5
|
-
EDGE_RIGHT = :right
|
6
|
-
EDGE_LEFT = :left
|
7
|
-
|
8
|
-
MODE_DEFAULT = :slide
|
9
|
-
MODE_CIRCLE = :circle
|
10
|
-
|
11
|
-
attr_reader :edge, :mode, :max_visible, :notifications
|
12
|
-
def initialize(edge: EDGE_RIGHT, mode: MODE_DEFAULT, window:, max_visible: 1)
|
13
|
-
@edge = edge
|
14
|
-
@mode = mode
|
15
|
-
@window = window
|
16
|
-
@max_visible = max_visible
|
17
|
-
|
18
|
-
@notifications = []
|
19
|
-
@drivers = []
|
20
|
-
@slots = Array.new(max_visible, nil)
|
21
|
-
end
|
22
|
-
|
23
|
-
def draw
|
24
|
-
@drivers.each do |driver|
|
25
|
-
case @edge
|
26
|
-
when :left, :right
|
27
|
-
x = @edge == :right ? @window.width + driver.x : -Notification::WIDTH + driver.x
|
28
|
-
y = driver.y + Notification::HEIGHT / 2
|
29
|
-
|
30
|
-
Gosu.translate(x, y + (Notification::HEIGHT + Notification::PADDING) * driver.slot) do
|
31
|
-
driver.draw
|
32
|
-
end
|
33
|
-
|
34
|
-
when :top, :bottom
|
35
|
-
x = @window.width / 2 - Notification::WIDTH / 2
|
36
|
-
y = @edge == :top ? driver.y - Notification::HEIGHT : @window.height + driver.y
|
37
|
-
slot_position = (Notification::HEIGHT + Notification::PADDING) * driver.slot
|
38
|
-
slot_position *= -1 if @edge == :bottom
|
39
|
-
|
40
|
-
Gosu.translate(x, y + slot_position) do
|
41
|
-
driver.draw
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def update
|
48
|
-
show_next_notification if @drivers.size < @max_visible
|
49
|
-
@drivers.each do |driver|
|
50
|
-
if driver.done?
|
51
|
-
@slots[driver.slot] = nil
|
52
|
-
@drivers.delete(driver)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
@drivers.each(&:update)
|
57
|
-
end
|
58
|
-
|
59
|
-
def show_next_notification
|
60
|
-
notification = @notifications.sort { |n| n.priority }.reverse.shift
|
61
|
-
return unless notification
|
62
|
-
return if available_slot_index < lowest_used_slot
|
63
|
-
@notifications.delete(notification)
|
64
|
-
|
65
|
-
@drivers << Driver.new(edge: @edge, mode: @mode, notification: notification, slot: available_slot_index)
|
66
|
-
slot = @slots[available_slot_index] = @drivers.last
|
67
|
-
end
|
68
|
-
|
69
|
-
def available_slot_index
|
70
|
-
@slots.each_with_index do |slot, i|
|
71
|
-
return i unless slot
|
72
|
-
end
|
73
|
-
|
74
|
-
return -1
|
75
|
-
end
|
76
|
-
|
77
|
-
def lowest_used_slot
|
78
|
-
@slots.each_with_index do |slot, i|
|
79
|
-
return i if slot
|
80
|
-
end
|
81
|
-
|
82
|
-
return -1
|
83
|
-
end
|
84
|
-
|
85
|
-
def highest_used_slot
|
86
|
-
_slot = -1
|
87
|
-
@slots.each_with_index do |slot, i|
|
88
|
-
_slot = i if slot
|
89
|
-
end
|
90
|
-
|
91
|
-
return _slot
|
92
|
-
end
|
93
|
-
|
94
|
-
def create_notification(**args)
|
95
|
-
notification = Notification.new(host: self, **args)
|
96
|
-
@notifications << notification
|
97
|
-
end
|
98
|
-
|
99
|
-
class Driver
|
100
|
-
attr_reader :x, :y, :notification, :slot
|
101
|
-
def initialize(edge:, mode:, notification:, slot:)
|
102
|
-
@edge = edge
|
103
|
-
@mode = mode
|
104
|
-
@notification = notification
|
105
|
-
@slot = slot
|
106
|
-
|
107
|
-
@x, @y = 0, 0
|
108
|
-
@delta = Gosu.milliseconds
|
109
|
-
@accumulator = 0.0
|
110
|
-
|
111
|
-
@born_at = Gosu.milliseconds
|
112
|
-
@duration_completed_at = Float::INFINITY
|
113
|
-
@transition_completed_at = Float::INFINITY
|
114
|
-
end
|
115
|
-
|
116
|
-
def transition_in_complete?
|
117
|
-
Gosu.milliseconds - @born_at >= @notification.transition_duration
|
118
|
-
end
|
119
|
-
|
120
|
-
def duration_completed?
|
121
|
-
Gosu.milliseconds - @transition_completed_at >= @notification.time_to_live
|
122
|
-
end
|
123
|
-
|
124
|
-
def done?
|
125
|
-
Gosu.milliseconds - @duration_completed_at >= @notification.transition_duration
|
126
|
-
end
|
127
|
-
|
128
|
-
def draw
|
129
|
-
ratio = 0.0
|
130
|
-
|
131
|
-
if not transition_in_complete?
|
132
|
-
ratio = animation_ratio
|
133
|
-
elsif transition_in_complete? and not duration_completed?
|
134
|
-
ratio = 1.0
|
135
|
-
elsif duration_completed?
|
136
|
-
ratio = 1.0 - animation_ratio
|
137
|
-
end
|
138
|
-
|
139
|
-
case @mode
|
140
|
-
when MODE_DEFAULT
|
141
|
-
Gosu.clip_to(0, 0, Notification::WIDTH, Notification::HEIGHT * ratio) do
|
142
|
-
@notification.draw
|
143
|
-
end
|
144
|
-
when MODE_CIRCLE
|
145
|
-
half = Notification::WIDTH / 2
|
146
|
-
|
147
|
-
Gosu.clip_to(half - (half * ratio), 0, Notification::WIDTH * ratio, Notification::HEIGHT) do
|
148
|
-
@notification.draw
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
def update
|
154
|
-
case @mode
|
155
|
-
when MODE_DEFAULT
|
156
|
-
update_default
|
157
|
-
when MODE_CIRCLE
|
158
|
-
update_circle
|
159
|
-
end
|
160
|
-
|
161
|
-
@accumulator += Gosu.milliseconds - @delta
|
162
|
-
@delta = Gosu.milliseconds
|
163
|
-
end
|
164
|
-
|
165
|
-
|
166
|
-
def update_default
|
167
|
-
case @edge
|
168
|
-
when :left, :right
|
169
|
-
if not transition_in_complete? # Slide In
|
170
|
-
@x = @edge == :right ? -x_offset : x_offset
|
171
|
-
elsif transition_in_complete? and not duration_completed?
|
172
|
-
@x = @edge == :right ? -Notification::WIDTH : Notification::WIDTH if @x.abs != Notification::WIDTH
|
173
|
-
@transition_completed_at = Gosu.milliseconds if @transition_completed_at == Float::INFINITY
|
174
|
-
@accumulator = 0.0
|
175
|
-
elsif duration_completed? # Slide Out
|
176
|
-
@x = @edge == :right ? x_offset - Notification::WIDTH : Notification::WIDTH - x_offset
|
177
|
-
@x = 0 if @edge == :left and @x <= 0
|
178
|
-
@x = 0 if @edge == :right and @x >= 0
|
179
|
-
@duration_completed_at = Gosu.milliseconds if @duration_completed_at == Float::INFINITY
|
180
|
-
end
|
181
|
-
|
182
|
-
when :top, :bottom
|
183
|
-
if not transition_in_complete? # Slide In
|
184
|
-
@y = @edge == :top ? y_offset : -y_offset
|
185
|
-
elsif transition_in_complete? and not duration_completed?
|
186
|
-
@y = @edge == :top ? Notification::HEIGHT : -Notification::HEIGHT if @x.abs != Notification::HEIGHT
|
187
|
-
@transition_completed_at = Gosu.milliseconds if @transition_completed_at == Float::INFINITY
|
188
|
-
@accumulator = 0.0
|
189
|
-
elsif duration_completed? # Slide Out
|
190
|
-
@y = @edge == :top ? Notification::HEIGHT - y_offset : y_offset - Notification::HEIGHT
|
191
|
-
@y = 0 if @edge == :top and @y <= 0
|
192
|
-
@y = 0 if @edge == :bottom and @y >= 0
|
193
|
-
@duration_completed_at = Gosu.milliseconds if @duration_completed_at == Float::INFINITY
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
def update_circle
|
199
|
-
case @edge
|
200
|
-
when :top, :bottom
|
201
|
-
@y = @edge == :top ? Notification::HEIGHT : -Notification::HEIGHT
|
202
|
-
when :left, :right
|
203
|
-
@x = @edge == :right ? -Notification::WIDTH : Notification::WIDTH
|
204
|
-
end
|
205
|
-
|
206
|
-
if transition_in_complete? and not duration_completed?
|
207
|
-
@transition_completed_at = Gosu.milliseconds if @transition_completed_at == Float::INFINITY
|
208
|
-
@accumulator = 0.0
|
209
|
-
elsif duration_completed?
|
210
|
-
@duration_completed_at = Gosu.milliseconds if @duration_completed_at == Float::INFINITY
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
def animation_ratio
|
215
|
-
x = (@accumulator / @notification.transition_duration)
|
216
|
-
|
217
|
-
case @notification.transition_type
|
218
|
-
when Notification::LINEAR_TRANSITION
|
219
|
-
x.clamp(0.0, 1.0)
|
220
|
-
when Notification::EASE_IN_OUT_TRANSITION # https://easings.net/#easeInOutQuint
|
221
|
-
(x < 0.5 ? 16 * x * x * x * x * x : 1 - ((-2 * x + 2) ** 5) / 2).clamp(0.0, 1.0)
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
def x_offset
|
226
|
-
if not transition_in_complete? or duration_completed?
|
227
|
-
Notification::WIDTH * animation_ratio
|
228
|
-
else
|
229
|
-
0
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
def y_offset
|
234
|
-
if not transition_in_complete? or duration_completed?
|
235
|
-
Notification::HEIGHT * animation_ratio
|
236
|
-
else
|
237
|
-
0
|
238
|
-
end
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
class NotificationManager
|
3
|
+
EDGE_TOP = :top
|
4
|
+
EDGE_BOTTOM = :bottom
|
5
|
+
EDGE_RIGHT = :right
|
6
|
+
EDGE_LEFT = :left
|
7
|
+
|
8
|
+
MODE_DEFAULT = :slide
|
9
|
+
MODE_CIRCLE = :circle
|
10
|
+
|
11
|
+
attr_reader :edge, :mode, :max_visible, :notifications
|
12
|
+
def initialize(edge: EDGE_RIGHT, mode: MODE_DEFAULT, window:, max_visible: 1)
|
13
|
+
@edge = edge
|
14
|
+
@mode = mode
|
15
|
+
@window = window
|
16
|
+
@max_visible = max_visible
|
17
|
+
|
18
|
+
@notifications = []
|
19
|
+
@drivers = []
|
20
|
+
@slots = Array.new(max_visible, nil)
|
21
|
+
end
|
22
|
+
|
23
|
+
def draw
|
24
|
+
@drivers.each do |driver|
|
25
|
+
case @edge
|
26
|
+
when :left, :right
|
27
|
+
x = @edge == :right ? @window.width + driver.x : -Notification::WIDTH + driver.x
|
28
|
+
y = driver.y + Notification::HEIGHT / 2
|
29
|
+
|
30
|
+
Gosu.translate(x, y + (Notification::HEIGHT + Notification::PADDING) * driver.slot) do
|
31
|
+
driver.draw
|
32
|
+
end
|
33
|
+
|
34
|
+
when :top, :bottom
|
35
|
+
x = @window.width / 2 - Notification::WIDTH / 2
|
36
|
+
y = @edge == :top ? driver.y - Notification::HEIGHT : @window.height + driver.y
|
37
|
+
slot_position = (Notification::HEIGHT + Notification::PADDING) * driver.slot
|
38
|
+
slot_position *= -1 if @edge == :bottom
|
39
|
+
|
40
|
+
Gosu.translate(x, y + slot_position) do
|
41
|
+
driver.draw
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def update
|
48
|
+
show_next_notification if @drivers.size < @max_visible
|
49
|
+
@drivers.each do |driver|
|
50
|
+
if driver.done?
|
51
|
+
@slots[driver.slot] = nil
|
52
|
+
@drivers.delete(driver)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
@drivers.each(&:update)
|
57
|
+
end
|
58
|
+
|
59
|
+
def show_next_notification
|
60
|
+
notification = @notifications.sort { |n| n.priority }.reverse.shift
|
61
|
+
return unless notification
|
62
|
+
return if available_slot_index < lowest_used_slot
|
63
|
+
@notifications.delete(notification)
|
64
|
+
|
65
|
+
@drivers << Driver.new(edge: @edge, mode: @mode, notification: notification, slot: available_slot_index)
|
66
|
+
slot = @slots[available_slot_index] = @drivers.last
|
67
|
+
end
|
68
|
+
|
69
|
+
def available_slot_index
|
70
|
+
@slots.each_with_index do |slot, i|
|
71
|
+
return i unless slot
|
72
|
+
end
|
73
|
+
|
74
|
+
return -1
|
75
|
+
end
|
76
|
+
|
77
|
+
def lowest_used_slot
|
78
|
+
@slots.each_with_index do |slot, i|
|
79
|
+
return i if slot
|
80
|
+
end
|
81
|
+
|
82
|
+
return -1
|
83
|
+
end
|
84
|
+
|
85
|
+
def highest_used_slot
|
86
|
+
_slot = -1
|
87
|
+
@slots.each_with_index do |slot, i|
|
88
|
+
_slot = i if slot
|
89
|
+
end
|
90
|
+
|
91
|
+
return _slot
|
92
|
+
end
|
93
|
+
|
94
|
+
def create_notification(**args)
|
95
|
+
notification = Notification.new(host: self, **args)
|
96
|
+
@notifications << notification
|
97
|
+
end
|
98
|
+
|
99
|
+
class Driver
|
100
|
+
attr_reader :x, :y, :notification, :slot
|
101
|
+
def initialize(edge:, mode:, notification:, slot:)
|
102
|
+
@edge = edge
|
103
|
+
@mode = mode
|
104
|
+
@notification = notification
|
105
|
+
@slot = slot
|
106
|
+
|
107
|
+
@x, @y = 0, 0
|
108
|
+
@delta = Gosu.milliseconds
|
109
|
+
@accumulator = 0.0
|
110
|
+
|
111
|
+
@born_at = Gosu.milliseconds
|
112
|
+
@duration_completed_at = Float::INFINITY
|
113
|
+
@transition_completed_at = Float::INFINITY
|
114
|
+
end
|
115
|
+
|
116
|
+
def transition_in_complete?
|
117
|
+
Gosu.milliseconds - @born_at >= @notification.transition_duration
|
118
|
+
end
|
119
|
+
|
120
|
+
def duration_completed?
|
121
|
+
Gosu.milliseconds - @transition_completed_at >= @notification.time_to_live
|
122
|
+
end
|
123
|
+
|
124
|
+
def done?
|
125
|
+
Gosu.milliseconds - @duration_completed_at >= @notification.transition_duration
|
126
|
+
end
|
127
|
+
|
128
|
+
def draw
|
129
|
+
ratio = 0.0
|
130
|
+
|
131
|
+
if not transition_in_complete?
|
132
|
+
ratio = animation_ratio
|
133
|
+
elsif transition_in_complete? and not duration_completed?
|
134
|
+
ratio = 1.0
|
135
|
+
elsif duration_completed?
|
136
|
+
ratio = 1.0 - animation_ratio
|
137
|
+
end
|
138
|
+
|
139
|
+
case @mode
|
140
|
+
when MODE_DEFAULT
|
141
|
+
Gosu.clip_to(0, 0, Notification::WIDTH, Notification::HEIGHT * ratio) do
|
142
|
+
@notification.draw
|
143
|
+
end
|
144
|
+
when MODE_CIRCLE
|
145
|
+
half = Notification::WIDTH / 2
|
146
|
+
|
147
|
+
Gosu.clip_to(half - (half * ratio), 0, Notification::WIDTH * ratio, Notification::HEIGHT) do
|
148
|
+
@notification.draw
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def update
|
154
|
+
case @mode
|
155
|
+
when MODE_DEFAULT
|
156
|
+
update_default
|
157
|
+
when MODE_CIRCLE
|
158
|
+
update_circle
|
159
|
+
end
|
160
|
+
|
161
|
+
@accumulator += Gosu.milliseconds - @delta
|
162
|
+
@delta = Gosu.milliseconds
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
def update_default
|
167
|
+
case @edge
|
168
|
+
when :left, :right
|
169
|
+
if not transition_in_complete? # Slide In
|
170
|
+
@x = @edge == :right ? -x_offset : x_offset
|
171
|
+
elsif transition_in_complete? and not duration_completed?
|
172
|
+
@x = @edge == :right ? -Notification::WIDTH : Notification::WIDTH if @x.abs != Notification::WIDTH
|
173
|
+
@transition_completed_at = Gosu.milliseconds if @transition_completed_at == Float::INFINITY
|
174
|
+
@accumulator = 0.0
|
175
|
+
elsif duration_completed? # Slide Out
|
176
|
+
@x = @edge == :right ? x_offset - Notification::WIDTH : Notification::WIDTH - x_offset
|
177
|
+
@x = 0 if @edge == :left and @x <= 0
|
178
|
+
@x = 0 if @edge == :right and @x >= 0
|
179
|
+
@duration_completed_at = Gosu.milliseconds if @duration_completed_at == Float::INFINITY
|
180
|
+
end
|
181
|
+
|
182
|
+
when :top, :bottom
|
183
|
+
if not transition_in_complete? # Slide In
|
184
|
+
@y = @edge == :top ? y_offset : -y_offset
|
185
|
+
elsif transition_in_complete? and not duration_completed?
|
186
|
+
@y = @edge == :top ? Notification::HEIGHT : -Notification::HEIGHT if @x.abs != Notification::HEIGHT
|
187
|
+
@transition_completed_at = Gosu.milliseconds if @transition_completed_at == Float::INFINITY
|
188
|
+
@accumulator = 0.0
|
189
|
+
elsif duration_completed? # Slide Out
|
190
|
+
@y = @edge == :top ? Notification::HEIGHT - y_offset : y_offset - Notification::HEIGHT
|
191
|
+
@y = 0 if @edge == :top and @y <= 0
|
192
|
+
@y = 0 if @edge == :bottom and @y >= 0
|
193
|
+
@duration_completed_at = Gosu.milliseconds if @duration_completed_at == Float::INFINITY
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def update_circle
|
199
|
+
case @edge
|
200
|
+
when :top, :bottom
|
201
|
+
@y = @edge == :top ? Notification::HEIGHT : -Notification::HEIGHT
|
202
|
+
when :left, :right
|
203
|
+
@x = @edge == :right ? -Notification::WIDTH : Notification::WIDTH
|
204
|
+
end
|
205
|
+
|
206
|
+
if transition_in_complete? and not duration_completed?
|
207
|
+
@transition_completed_at = Gosu.milliseconds if @transition_completed_at == Float::INFINITY
|
208
|
+
@accumulator = 0.0
|
209
|
+
elsif duration_completed?
|
210
|
+
@duration_completed_at = Gosu.milliseconds if @duration_completed_at == Float::INFINITY
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def animation_ratio
|
215
|
+
x = (@accumulator / @notification.transition_duration)
|
216
|
+
|
217
|
+
case @notification.transition_type
|
218
|
+
when Notification::LINEAR_TRANSITION
|
219
|
+
x.clamp(0.0, 1.0)
|
220
|
+
when Notification::EASE_IN_OUT_TRANSITION # https://easings.net/#easeInOutQuint
|
221
|
+
(x < 0.5 ? 16 * x * x * x * x * x : 1 - ((-2 * x + 2) ** 5) / 2).clamp(0.0, 1.0)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def x_offset
|
226
|
+
if not transition_in_complete? or duration_completed?
|
227
|
+
Notification::WIDTH * animation_ratio
|
228
|
+
else
|
229
|
+
0
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def y_offset
|
234
|
+
if not transition_in_complete? or duration_completed?
|
235
|
+
Notification::HEIGHT * animation_ratio
|
236
|
+
else
|
237
|
+
0
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
242
|
end
|
@@ -1,50 +1,52 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class Light
|
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
|
-
glLightfv(@light_id,
|
36
|
-
glLightfv(@light_id,
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
struct.to_a.compact
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
class Light
|
3
|
+
include OpenGL
|
4
|
+
|
5
|
+
DIRECTIONAL = 0
|
6
|
+
POINT = 1
|
7
|
+
SPOT = 2
|
8
|
+
|
9
|
+
attr_reader :light_id
|
10
|
+
attr_accessor :type, :ambient, :diffuse, :specular, :position, :direction, :intensity
|
11
|
+
|
12
|
+
def initialize(
|
13
|
+
id:,
|
14
|
+
type: Light::POINT,
|
15
|
+
ambient: Vector.new(0.5, 0.5, 0.5),
|
16
|
+
diffuse: Vector.new(1, 1, 1),
|
17
|
+
specular: Vector.new(0.2, 0.2, 0.2),
|
18
|
+
position: Vector.new(0, 0, 0),
|
19
|
+
direction: Vector.new(0, 0, 0),
|
20
|
+
intensity: 1
|
21
|
+
)
|
22
|
+
@light_id = id
|
23
|
+
@type = type
|
24
|
+
|
25
|
+
@ambient = ambient
|
26
|
+
@diffuse = diffuse
|
27
|
+
@specular = specular
|
28
|
+
@position = position
|
29
|
+
@direction = direction
|
30
|
+
|
31
|
+
@intensity = intensity
|
32
|
+
end
|
33
|
+
|
34
|
+
def draw
|
35
|
+
glLightfv(@light_id, GL_AMBIENT, convert(@ambient).pack("f*"))
|
36
|
+
glLightfv(@light_id, GL_DIFFUSE, convert(@diffuse, true).pack("f*"))
|
37
|
+
glLightfv(@light_id, GL_SPECULAR, convert(@specular, true).pack("f*"))
|
38
|
+
glLightfv(@light_id, GL_POSITION, convert(@position).pack("f*"))
|
39
|
+
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1)
|
40
|
+
glEnable(GL_LIGHTING)
|
41
|
+
glEnable(@light_id)
|
42
|
+
end
|
43
|
+
|
44
|
+
def convert(struct, apply_intensity = false)
|
45
|
+
if apply_intensity
|
46
|
+
struct.to_a.compact.map { |i| i * @intensity }
|
47
|
+
else
|
48
|
+
struct.to_a.compact
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,46 +1,46 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class OrthographicCamera
|
3
|
-
attr_accessor :position, :orientation, :zoom, :left, :right, :bottom, :top,
|
4
|
-
:min_view_distance, :max_view_distance
|
5
|
-
|
6
|
-
def initialize(
|
7
|
-
position:, right:, top:, orientation: Vector.new(0, 0, 0),
|
8
|
-
zoom: 1, left: 0, bottom: 0,
|
9
|
-
min_view_distance: 0.1, max_view_distance: 200.0
|
10
|
-
)
|
11
|
-
@position = position
|
12
|
-
@orientation = orientation
|
13
|
-
|
14
|
-
@zoom = zoom
|
15
|
-
|
16
|
-
@left = left
|
17
|
-
@right = right
|
18
|
-
@bottom = bottom
|
19
|
-
@top = top
|
20
|
-
|
21
|
-
@min_view_distance = min_view_distance
|
22
|
-
@max_view_distance = max_view_distance
|
23
|
-
end
|
24
|
-
|
25
|
-
# Immediate mode renderering fallback
|
26
|
-
def draw
|
27
|
-
glMatrixMode(GL_PROJECTION)
|
28
|
-
glLoadIdentity
|
29
|
-
glOrtho(@left, @right, @bottom, @top, @min_view_distance, @max_view_distance)
|
30
|
-
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
|
31
|
-
glRotatef(@orientation.x, 1, 0, 0)
|
32
|
-
glRotatef(@orientation.y, 0, 1, 0)
|
33
|
-
glTranslatef(-@position.x, -@position.y, -@position.z)
|
34
|
-
glMatrixMode(GL_MODELVIEW)
|
35
|
-
glLoadIdentity
|
36
|
-
end
|
37
|
-
|
38
|
-
def projection_matrix
|
39
|
-
Transform.orthographic(@left, @right, @bottom, @top, @min_view_distance, @max_view_distance)
|
40
|
-
end
|
41
|
-
|
42
|
-
def view_matrix
|
43
|
-
Transform.translate_3d(@position * -1) * Transform.rotate_3d(@orientation)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
class OrthographicCamera
|
3
|
+
attr_accessor :position, :orientation, :zoom, :left, :right, :bottom, :top,
|
4
|
+
:min_view_distance, :max_view_distance
|
5
|
+
|
6
|
+
def initialize(
|
7
|
+
position:, right:, top:, orientation: Vector.new(0, 0, 0),
|
8
|
+
zoom: 1, left: 0, bottom: 0,
|
9
|
+
min_view_distance: 0.1, max_view_distance: 200.0
|
10
|
+
)
|
11
|
+
@position = position
|
12
|
+
@orientation = orientation
|
13
|
+
|
14
|
+
@zoom = zoom
|
15
|
+
|
16
|
+
@left = left
|
17
|
+
@right = right
|
18
|
+
@bottom = bottom
|
19
|
+
@top = top
|
20
|
+
|
21
|
+
@min_view_distance = min_view_distance
|
22
|
+
@max_view_distance = max_view_distance
|
23
|
+
end
|
24
|
+
|
25
|
+
# Immediate mode renderering fallback
|
26
|
+
def draw
|
27
|
+
glMatrixMode(GL_PROJECTION)
|
28
|
+
glLoadIdentity
|
29
|
+
glOrtho(@left, @right, @bottom, @top, @min_view_distance, @max_view_distance)
|
30
|
+
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
|
31
|
+
glRotatef(@orientation.x, 1, 0, 0)
|
32
|
+
glRotatef(@orientation.y, 0, 1, 0)
|
33
|
+
glTranslatef(-@position.x, -@position.y, -@position.z)
|
34
|
+
glMatrixMode(GL_MODELVIEW)
|
35
|
+
glLoadIdentity
|
36
|
+
end
|
37
|
+
|
38
|
+
def projection_matrix
|
39
|
+
Transform.orthographic(@left, @right, @bottom, @top, @min_view_distance, @max_view_distance)
|
40
|
+
end
|
41
|
+
|
42
|
+
def view_matrix
|
43
|
+
Transform.translate_3d(@position * -1) * Transform.rotate_3d(@orientation)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|