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.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +8 -8
  3. data/.rubocop.yml +7 -7
  4. data/.travis.yml +5 -5
  5. data/Gemfile +6 -6
  6. data/Gemfile.lock +24 -0
  7. data/LICENSE.txt +21 -21
  8. data/README.md +74 -74
  9. data/Rakefile +10 -10
  10. data/assets/shaders/fragment/g_buffer.glsl +30 -30
  11. data/assets/shaders/fragment/lighting.glsl +115 -69
  12. data/assets/shaders/include/light_struct.glsl +11 -11
  13. data/assets/shaders/include/material_struct.glsl +16 -16
  14. data/assets/shaders/vertex/g_buffer.glsl +28 -28
  15. data/assets/shaders/vertex/lighting.glsl +24 -24
  16. data/bin/console +14 -14
  17. data/bin/setup +8 -8
  18. data/cyberarm_engine.gemspec +36 -36
  19. data/lib/cyberarm_engine/animator.rb +219 -219
  20. data/lib/cyberarm_engine/background.rb +180 -179
  21. data/lib/cyberarm_engine/background_image.rb +93 -93
  22. data/lib/cyberarm_engine/background_nine_slice.rb +142 -142
  23. data/lib/cyberarm_engine/bounding_box.rb +150 -150
  24. data/lib/cyberarm_engine/builtin/intro_state.rb +130 -130
  25. data/lib/cyberarm_engine/cache/download_manager.rb +123 -123
  26. data/lib/cyberarm_engine/cache.rb +4 -4
  27. data/lib/cyberarm_engine/common.rb +128 -128
  28. data/lib/cyberarm_engine/config_file.rb +46 -46
  29. data/lib/cyberarm_engine/console/command.rb +157 -157
  30. data/lib/cyberarm_engine/console/commands/help_command.rb +43 -43
  31. data/lib/cyberarm_engine/console/subcommand.rb +99 -99
  32. data/lib/cyberarm_engine/console.rb +248 -248
  33. data/lib/cyberarm_engine/game_object.rb +244 -244
  34. data/lib/cyberarm_engine/game_state.rb +124 -124
  35. data/lib/cyberarm_engine/gosu_ext/draw_arc.rb +97 -97
  36. data/lib/cyberarm_engine/gosu_ext/draw_circle.rb +30 -30
  37. data/lib/cyberarm_engine/gosu_ext/draw_path.rb +17 -17
  38. data/lib/cyberarm_engine/model/material.rb +21 -21
  39. data/lib/cyberarm_engine/model/{model_object.rb → mesh.rb} +131 -131
  40. data/lib/cyberarm_engine/model/parser.rb +74 -74
  41. data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -138
  42. data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -154
  43. data/lib/cyberarm_engine/model.rb +216 -213
  44. data/lib/cyberarm_engine/model_cache.rb +31 -31
  45. data/lib/cyberarm_engine/notification.rb +82 -82
  46. data/lib/cyberarm_engine/notification_manager.rb +241 -241
  47. data/lib/cyberarm_engine/opengl/light.rb +52 -50
  48. data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -46
  49. data/lib/cyberarm_engine/opengl/perspective_camera.rb +41 -38
  50. data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -249
  51. data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +167 -165
  52. data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +307 -304
  53. data/lib/cyberarm_engine/opengl/renderer/renderer.rb +33 -33
  54. data/lib/cyberarm_engine/opengl/shader.rb +408 -406
  55. data/lib/cyberarm_engine/opengl/texture.rb +69 -69
  56. data/lib/cyberarm_engine/opengl.rb +53 -40
  57. data/lib/cyberarm_engine/ray.rb +56 -56
  58. data/lib/cyberarm_engine/stats.rb +200 -200
  59. data/lib/cyberarm_engine/text.rb +260 -260
  60. data/lib/cyberarm_engine/timer.rb +23 -23
  61. data/lib/cyberarm_engine/transform.rb +296 -296
  62. data/lib/cyberarm_engine/trees/aabb_node.rb +126 -0
  63. data/lib/cyberarm_engine/trees/aabb_tree.rb +55 -0
  64. data/lib/cyberarm_engine/trees/aabb_tree_debug.rb +29 -0
  65. data/lib/cyberarm_engine/ui/border_canvas.rb +102 -102
  66. data/lib/cyberarm_engine/ui/dsl.rb +142 -142
  67. data/lib/cyberarm_engine/ui/element.rb +662 -662
  68. data/lib/cyberarm_engine/ui/elements/button.rb +100 -100
  69. data/lib/cyberarm_engine/ui/elements/check_box.rb +54 -54
  70. data/lib/cyberarm_engine/ui/elements/container.rb +404 -404
  71. data/lib/cyberarm_engine/ui/elements/edit_box.rb +179 -179
  72. data/lib/cyberarm_engine/ui/elements/edit_line.rb +297 -297
  73. data/lib/cyberarm_engine/ui/elements/flow.rb +15 -15
  74. data/lib/cyberarm_engine/ui/elements/image.rb +72 -72
  75. data/lib/cyberarm_engine/ui/elements/list_box.rb +79 -79
  76. data/lib/cyberarm_engine/ui/elements/menu.rb +27 -27
  77. data/lib/cyberarm_engine/ui/elements/menu_item.rb +6 -6
  78. data/lib/cyberarm_engine/ui/elements/progress.rb +93 -93
  79. data/lib/cyberarm_engine/ui/elements/radio.rb +6 -6
  80. data/lib/cyberarm_engine/ui/elements/slider.rb +107 -107
  81. data/lib/cyberarm_engine/ui/elements/stack.rb +11 -11
  82. data/lib/cyberarm_engine/ui/elements/text_block.rb +216 -216
  83. data/lib/cyberarm_engine/ui/elements/toggle_button.rb +67 -67
  84. data/lib/cyberarm_engine/ui/event.rb +54 -54
  85. data/lib/cyberarm_engine/ui/gui_state.rb +321 -321
  86. data/lib/cyberarm_engine/ui/style.rb +50 -50
  87. data/lib/cyberarm_engine/ui/theme.rb +225 -225
  88. data/lib/cyberarm_engine/vector.rb +312 -312
  89. data/lib/cyberarm_engine/version.rb +4 -4
  90. data/lib/cyberarm_engine/window.rb +195 -195
  91. data/lib/cyberarm_engine.rb +70 -78
  92. data/mrbgem.rake +29 -29
  93. metadata +8 -7
@@ -1,179 +1,180 @@
1
- module CyberarmEngine
2
- class Background
3
- attr_accessor :x, :y, :z, :width, :height, :angle, :debug
4
- attr_reader :background
5
-
6
- def initialize(x: 0, y: 0, z: 0, width: 0, height: 0, background: Gosu::Color::BLACK, angle: 0, debug: false)
7
- @x = x
8
- @y = y
9
- @z = z
10
- @width = width
11
- @height = height
12
- @debug = debug
13
-
14
- @paint = Paint.new(background)
15
- @angle = angle
16
-
17
- @top_left = Vector.new(@x, @y)
18
- @top_right = Vector.new(@x + @width, @y)
19
- @bottom_left = Vector.new(@x, @y + @height)
20
- @bottom_right = Vector.new(@x + @width, @y + @height)
21
- end
22
-
23
- def draw
24
- Gosu.clip_to(@x, @y, @width, @height) do
25
- Gosu.draw_quad(
26
- @top_left.x, @top_left.y, @paint.top_left,
27
- @top_right.x, @top_right.y, @paint.top_right,
28
- @bottom_right.x, @bottom_right.y, @paint.bottom_right,
29
- @bottom_left.x, @bottom_left.y, @paint.bottom_left,
30
- @z
31
- )
32
- end
33
-
34
- debug_outline if @debug
35
- end
36
-
37
- def update
38
- origin_x = (@x + (@width / 2))
39
- origin_y = (@y + (@height / 2))
40
-
41
- points = [
42
- @top_left = Vector.new(@x, @y),
43
- @top_right = Vector.new(@x + @width, @y),
44
- @bottom_left = Vector.new(@x, @y + @height),
45
- @bottom_right = Vector.new(@x + @width, @y + @height)
46
- ]
47
-
48
- [@top_left, @top_right, @bottom_left, @bottom_right].each do |vector|
49
- temp_x = vector.x - origin_x
50
- temp_y = vector.y - origin_y
51
-
52
- # 90 is up here, while gosu uses 0 for up.
53
- radians = (@angle + 90).gosu_to_radians
54
- vector.x = (@x + (@width / 2)) + ((temp_x * Math.cos(radians)) - (temp_y * Math.sin(radians)))
55
- vector.y = (@y + (@height / 2)) + ((temp_x * Math.sin(radians)) + (temp_y * Math.cos(radians)))
56
- end
57
-
58
- # [
59
- # [:top, @top_left, @top_right],
60
- # [:right, @top_right, @bottom_right],
61
- # [:bottom, @bottom_right, @bottom_left],
62
- # [:left, @bottom_left, @top_left]
63
- # ].each do |edge|
64
- # points.each do |point|
65
- # puts "#{edge.first} -> #{shortest_distance(point, edge[1], edge[2])}"
66
- # end
67
- # end
68
- end
69
-
70
- def shortest_distance(point, la, lb)
71
- a = la.x - lb.x
72
- b = la.y - lb.y
73
- c = Gosu.distance(la.x, la.y, lb.x, lb.y)
74
- p a, b, c
75
- d = (a * point.x + b * point.y + c).abs / Math.sqrt(a * a + b * b)
76
- puts "Distance: #{d}"
77
- exit!
78
- d
79
- end
80
-
81
- def debug_outline
82
- # Top
83
- Gosu.draw_line(
84
- @x, @y, Gosu::Color::RED,
85
- @x + @width, @y, Gosu::Color::RED,
86
- @z
87
- )
88
-
89
- # Right
90
- Gosu.draw_line(
91
- @x + @width, @y, Gosu::Color::RED,
92
- @x + @width, @y + @height, Gosu::Color::RED,
93
- @z
94
- )
95
-
96
- # Bottom
97
- Gosu.draw_line(
98
- @x + @width, @y + @height, Gosu::Color::RED,
99
- @x, @y + @height, Gosu::Color::RED,
100
- @z
101
- )
102
-
103
- # Left
104
- Gosu.draw_line(
105
- @x, @y + @height, Gosu::Color::RED,
106
- @x, @y, Gosu::Color::RED,
107
- @z
108
- )
109
- end
110
-
111
- def background=(_background)
112
- @paint.set(_background)
113
- update
114
- end
115
-
116
- def angle=(n)
117
- @angle = n
118
- update
119
- end
120
- end
121
-
122
- class Paint
123
- attr_accessor :top_left, :top_right, :bottom_left, :bottom_right
124
-
125
- def initialize(background)
126
- set(background)
127
- end
128
-
129
- def set(background)
130
- @background = background
131
-
132
- if background.is_a?(Numeric)
133
- @top_left = background
134
- @top_right = background
135
- @bottom_left = background
136
- @bottom_right = background
137
- elsif background.is_a?(Gosu::Color)
138
- @top_left = background
139
- @top_right = background
140
- @bottom_left = background
141
- @bottom_right = background
142
- elsif background.is_a?(Array)
143
- if background.size == 1
144
- set(background.first)
145
- elsif background.size == 2
146
- @top_left = background.first
147
- @top_right = background.last
148
- @bottom_left = background.first
149
- @bottom_right = background.last
150
- elsif background.size == 4
151
- @top_left = background[0]
152
- @top_right = background[1]
153
- @bottom_left = background[2]
154
- @bottom_right = background[3]
155
- else
156
- raise ArgumentError, "background array was empty or had wrong number of elements (expected 2 or 4 elements)"
157
- end
158
- elsif background.is_a?(Hash)
159
- @top_left = background[:top_left]
160
- @top_right = background[:top_right]
161
- @bottom_left = background[:bottom_left]
162
- @bottom_right = background[:bottom_right]
163
- elsif background.is_a?(Range)
164
- set([background.begin, background.begin, background.end, background.end])
165
- else
166
- raise ArgumentError, "background '#{background.inspect}' of type '#{background.class}' was not able to be processed"
167
- end
168
- end
169
- end
170
- end
171
-
172
- # Add <=> method to support Range based gradients
173
- module Gosu
174
- class Color
175
- def <=>(_other)
176
- self
177
- end
178
- end
179
- end
1
+ module CyberarmEngine
2
+ class Background
3
+ attr_accessor :x, :y, :z, :width, :height, :angle, :debug
4
+ attr_reader :background
5
+
6
+ def initialize(x: 0, y: 0, z: 0, width: 0, height: 0, background: Gosu::Color::BLACK, angle: 0, debug: false)
7
+ @x = x
8
+ @y = y
9
+ @z = z
10
+ @width = width
11
+ @height = height
12
+ @debug = debug
13
+
14
+ @paint = Paint.new(background)
15
+ @angle = angle
16
+
17
+ @top_left = Vector.new(@x, @y)
18
+ @top_right = Vector.new(@x + @width, @y)
19
+ @bottom_left = Vector.new(@x, @y + @height)
20
+ @bottom_right = Vector.new(@x + @width, @y + @height)
21
+ end
22
+
23
+ def draw
24
+ Gosu.clip_to(@x, @y, @width, @height) do
25
+ Gosu.draw_quad(
26
+ @top_left.x, @top_left.y, @paint.top_left,
27
+ @top_right.x, @top_right.y, @paint.top_right,
28
+ @bottom_right.x, @bottom_right.y, @paint.bottom_right,
29
+ @bottom_left.x, @bottom_left.y, @paint.bottom_left,
30
+ @z
31
+ )
32
+ end
33
+
34
+ debug_outline if @debug
35
+ end
36
+
37
+ def update
38
+ origin_x = (@x + (@width / 2))
39
+ origin_y = (@y + (@height / 2))
40
+
41
+ points = [
42
+ @top_left = Vector.new(@x, @y),
43
+ @top_right = Vector.new(@x + @width, @y),
44
+ @bottom_left = Vector.new(@x, @y + @height),
45
+ @bottom_right = Vector.new(@x + @width, @y + @height)
46
+ ]
47
+
48
+ [@top_left, @top_right, @bottom_left, @bottom_right].each do |vector|
49
+ temp_x = vector.x - origin_x
50
+ temp_y = vector.y - origin_y
51
+
52
+ # 90 is up here, while gosu uses 0 for up.
53
+ radians = (@angle + 90).gosu_to_radians
54
+ vector.x = (@x + (@width / 2)) + ((temp_x * Math.cos(radians)) - (temp_y * Math.sin(radians)))
55
+ vector.y = (@y + (@height / 2)) + ((temp_x * Math.sin(radians)) + (temp_y * Math.cos(radians)))
56
+ end
57
+
58
+ # [
59
+ # [:top, @top_left, @top_right],
60
+ # [:right, @top_right, @bottom_right],
61
+ # [:bottom, @bottom_right, @bottom_left],
62
+ # [:left, @bottom_left, @top_left]
63
+ # ].each do |edge|
64
+ # points.each do |point|
65
+ # puts "#{edge.first} -> #{shortest_distance(point, edge[1], edge[2])}"
66
+ # end
67
+ # end
68
+ end
69
+
70
+ def shortest_distance(point, la, lb)
71
+ a = la.x - lb.x
72
+ b = la.y - lb.y
73
+ c = Gosu.distance(la.x, la.y, lb.x, lb.y)
74
+ p a, b, c
75
+ d = (a * point.x + b * point.y + c).abs / Math.sqrt(a * a + b * b)
76
+ puts "Distance: #{d}"
77
+ exit!
78
+ d
79
+ end
80
+
81
+ def debug_outline
82
+ # Top
83
+ Gosu.draw_line(
84
+ @x, @y, Gosu::Color::RED,
85
+ @x + @width, @y, Gosu::Color::RED,
86
+ @z
87
+ )
88
+
89
+ # Right
90
+ Gosu.draw_line(
91
+ @x + @width, @y, Gosu::Color::RED,
92
+ @x + @width, @y + @height, Gosu::Color::RED,
93
+ @z
94
+ )
95
+
96
+ # Bottom
97
+ Gosu.draw_line(
98
+ @x + @width, @y + @height, Gosu::Color::RED,
99
+ @x, @y + @height, Gosu::Color::RED,
100
+ @z
101
+ )
102
+
103
+ # Left
104
+ Gosu.draw_line(
105
+ @x, @y + @height, Gosu::Color::RED,
106
+ @x, @y, Gosu::Color::RED,
107
+ @z
108
+ )
109
+ end
110
+
111
+ def background=(_background)
112
+ @paint.set(_background)
113
+ update
114
+ end
115
+
116
+ def angle=(n)
117
+ @angle = n
118
+ update
119
+ end
120
+ end
121
+
122
+ class Paint
123
+ attr_accessor :top_left, :top_right, :bottom_left, :bottom_right
124
+
125
+ def initialize(background)
126
+ set(background)
127
+ end
128
+
129
+ def set(background)
130
+ @background = background
131
+
132
+ if background.is_a?(Numeric)
133
+ @top_left = background
134
+ @top_right = background
135
+ @bottom_left = background
136
+ @bottom_right = background
137
+ elsif background.is_a?(Gosu::Color)
138
+ @top_left = background
139
+ @top_right = background
140
+ @bottom_left = background
141
+ @bottom_right = background
142
+ elsif background.is_a?(Array)
143
+ if background.size == 1
144
+ set(background.first)
145
+ elsif background.size == 2
146
+ @top_left = background.first
147
+ @top_right = background.last
148
+ @bottom_left = background.first
149
+ @bottom_right = background.last
150
+ elsif background.size == 4
151
+ @top_left = background[0]
152
+ @top_right = background[1]
153
+ @bottom_left = background[2]
154
+ @bottom_right = background[3]
155
+ else
156
+ raise ArgumentError, "background array was empty or had wrong number of elements (expected 2 or 4 elements)"
157
+ end
158
+ elsif background.is_a?(Hash)
159
+ @top_left = background[:top_left]
160
+ @top_right = background[:top_right]
161
+ @bottom_left = background[:bottom_left]
162
+ @bottom_right = background[:bottom_right]
163
+ elsif background.is_a?(Range)
164
+ set([background.begin, background.begin, background.end, background.end])
165
+ else
166
+ raise ArgumentError, "background '#{background.inspect}' of type '#{background.class}' was not able to be processed"
167
+ end
168
+ end
169
+ end
170
+ end
171
+
172
+ # Add <=> method to support Range based gradients
173
+ # NOTE: Disabled, causes stack overflow 🙃
174
+ # module Gosu
175
+ # class Color
176
+ # def <=>(_other)
177
+ # self
178
+ # end
179
+ # end
180
+ # end
@@ -1,93 +1,93 @@
1
- module CyberarmEngine
2
- class BackgroundImage
3
- include CyberarmEngine::Common
4
- attr_accessor :x, :y, :z, :mode
5
- attr_reader :image, :width, :height, :color
6
-
7
- def initialize(image_path: nil, x: 0, y: 0, z: 0, width: 0, height: 0, mode: :fill, color: Gosu::Color::WHITE)
8
- @image_path = image_path
9
- @image = get_image(image_path) if image_path
10
-
11
- @x = x
12
- @y = y
13
- @z = z
14
- @width = width
15
- @height = height
16
-
17
- @mode = mode
18
-
19
- @color = color
20
-
21
- @cached_tiling = nil
22
- end
23
-
24
- def image=(image_path)
25
- @cached_tiling = nil if image_path != @image_path
26
- @image_path = image_path
27
- @image = image_path ? get_image(image_path) : image_path
28
- end
29
-
30
- def width=(n)
31
- @cached_tiling = nil if @width != n
32
- @width = n
33
- end
34
-
35
- def height=(n)
36
- @cached_tiling = nil if @height != n
37
- @height = n
38
- end
39
-
40
- def color=(c)
41
- @cached_tiling = nil if @color != c
42
- @color = c
43
- end
44
-
45
- def width_scale
46
- (@width.to_f / @image.width).abs
47
- end
48
-
49
- def height_scale
50
- (@height.to_f / @image.height).abs
51
- end
52
-
53
- def draw
54
- return unless @image
55
-
56
- Gosu.clip_to(@x, @y, @width, @height) do
57
- send(:"draw_#{mode}")
58
- end
59
- end
60
-
61
- def draw_stretch
62
- @image.draw(@x, @y, @z, width_scale, height_scale, @color)
63
- end
64
-
65
- def draw_tiled
66
- @cached_tiling ||= Gosu.record(@width, @height) do
67
- height_scale.ceil.times do |y|
68
- width_scale.ceil.times do |x|
69
- @image.draw(x * @image.width, y * @image.height, @z, 1, 1, @color)
70
- end
71
- end
72
- end
73
-
74
- @cached_tiling.draw(@x, @y, @z)
75
- end
76
-
77
- def draw_fill
78
- if (@image.width * width_scale) >= @width && (@image.height * width_scale) >= @height
79
- draw_fill_width
80
- else
81
- draw_fill_height
82
- end
83
- end
84
-
85
- def draw_fill_width
86
- @image.draw(@x, @y, @z, width_scale, width_scale, @color)
87
- end
88
-
89
- def draw_fill_height
90
- @image.draw(@x, @y, @z, height_scale, height_scale, @color)
91
- end
92
- end
93
- end
1
+ module CyberarmEngine
2
+ class BackgroundImage
3
+ include CyberarmEngine::Common
4
+ attr_accessor :x, :y, :z, :mode
5
+ attr_reader :image, :width, :height, :color
6
+
7
+ def initialize(image_path: nil, x: 0, y: 0, z: 0, width: 0, height: 0, mode: :fill, color: Gosu::Color::WHITE)
8
+ @image_path = image_path
9
+ @image = get_image(image_path) if image_path
10
+
11
+ @x = x
12
+ @y = y
13
+ @z = z
14
+ @width = width
15
+ @height = height
16
+
17
+ @mode = mode
18
+
19
+ @color = color
20
+
21
+ @cached_tiling = nil
22
+ end
23
+
24
+ def image=(image_path)
25
+ @cached_tiling = nil if image_path != @image_path
26
+ @image_path = image_path
27
+ @image = image_path ? get_image(image_path) : image_path
28
+ end
29
+
30
+ def width=(n)
31
+ @cached_tiling = nil if @width != n
32
+ @width = n
33
+ end
34
+
35
+ def height=(n)
36
+ @cached_tiling = nil if @height != n
37
+ @height = n
38
+ end
39
+
40
+ def color=(c)
41
+ @cached_tiling = nil if @color != c
42
+ @color = c
43
+ end
44
+
45
+ def width_scale
46
+ (@width.to_f / @image.width).abs
47
+ end
48
+
49
+ def height_scale
50
+ (@height.to_f / @image.height).abs
51
+ end
52
+
53
+ def draw
54
+ return unless @image
55
+
56
+ Gosu.clip_to(@x, @y, @width, @height) do
57
+ send(:"draw_#{mode}")
58
+ end
59
+ end
60
+
61
+ def draw_stretch
62
+ @image.draw(@x, @y, @z, width_scale, height_scale, @color)
63
+ end
64
+
65
+ def draw_tiled
66
+ @cached_tiling ||= Gosu.record(@width, @height) do
67
+ height_scale.ceil.times do |y|
68
+ width_scale.ceil.times do |x|
69
+ @image.draw(x * @image.width, y * @image.height, @z, 1, 1, @color)
70
+ end
71
+ end
72
+ end
73
+
74
+ @cached_tiling.draw(@x, @y, @z)
75
+ end
76
+
77
+ def draw_fill
78
+ if (@image.width * width_scale) >= @width && (@image.height * width_scale) >= @height
79
+ draw_fill_width
80
+ else
81
+ draw_fill_height
82
+ end
83
+ end
84
+
85
+ def draw_fill_width
86
+ @image.draw(@x, @y, @z, width_scale, width_scale, @color)
87
+ end
88
+
89
+ def draw_fill_height
90
+ @image.draw(@x, @y, @z, height_scale, height_scale, @color)
91
+ end
92
+ end
93
+ end