cyberarm_engine 0.25.0 → 0.30.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.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +9 -8
  3. data/.rubocop.yml +7 -7
  4. data/.travis.yml +5 -5
  5. data/Gemfile +6 -6
  6. data/Gemfile.lock +37 -25
  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 -115
  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/assets/textures/ui/circle.png +0 -0
  17. data/assets/textures/ui/circle_small.png +0 -0
  18. data/assets/textures/ui/rounded.png +0 -0
  19. data/assets/textures/ui/rounded_bottom.png +0 -0
  20. data/assets/textures/ui/rounded_left.png +0 -0
  21. data/assets/textures/ui/rounded_left_bottom.png +0 -0
  22. data/assets/textures/ui/rounded_left_top.png +0 -0
  23. data/assets/textures/ui/rounded_right.png +0 -0
  24. data/assets/textures/ui/rounded_right_bottom.png +0 -0
  25. data/assets/textures/ui/rounded_right_top.png +0 -0
  26. data/assets/textures/ui/rounded_small.png +0 -0
  27. data/assets/textures/ui/rounded_tiny.png +0 -0
  28. data/assets/textures/ui/rounded_top.png +0 -0
  29. data/assets/textures/ui/square.png +0 -0
  30. data/bin/console +14 -14
  31. data/bin/setup +8 -8
  32. data/cyberarm_engine.gemspec +35 -36
  33. data/lib/cyberarm_engine/animator.rb +219 -219
  34. data/lib/cyberarm_engine/background.rb +156 -158
  35. data/lib/cyberarm_engine/background_image.rb +93 -93
  36. data/lib/cyberarm_engine/background_nine_slice.rb +182 -142
  37. data/lib/cyberarm_engine/bounding_box.rb +150 -150
  38. data/lib/cyberarm_engine/builtin/intro_state.rb +130 -130
  39. data/lib/cyberarm_engine/cache/download_manager.rb +123 -123
  40. data/lib/cyberarm_engine/cache.rb +4 -4
  41. data/lib/cyberarm_engine/common.rb +133 -131
  42. data/lib/cyberarm_engine/config_file.rb +46 -46
  43. data/lib/cyberarm_engine/console/command.rb +157 -157
  44. data/lib/cyberarm_engine/console/commands/help_command.rb +43 -43
  45. data/lib/cyberarm_engine/console/subcommand.rb +99 -99
  46. data/lib/cyberarm_engine/console.rb +248 -248
  47. data/lib/cyberarm_engine/event_bus.rb +39 -0
  48. data/lib/cyberarm_engine/game_object.rb +244 -244
  49. data/lib/cyberarm_engine/game_state.rb +134 -124
  50. data/lib/cyberarm_engine/gosu_ext/draw_arc.rb +111 -111
  51. data/lib/cyberarm_engine/gosu_ext/draw_circle.rb +30 -30
  52. data/lib/cyberarm_engine/gosu_ext/draw_path.rb +17 -17
  53. data/lib/cyberarm_engine/model/material.rb +21 -21
  54. data/lib/cyberarm_engine/model/mesh.rb +131 -131
  55. data/lib/cyberarm_engine/model/parser.rb +74 -74
  56. data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -138
  57. data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -154
  58. data/lib/cyberarm_engine/model.rb +216 -216
  59. data/lib/cyberarm_engine/model_cache.rb +31 -31
  60. data/lib/cyberarm_engine/notification.rb +82 -82
  61. data/lib/cyberarm_engine/notification_manager.rb +241 -241
  62. data/lib/cyberarm_engine/opengl/light.rb +52 -52
  63. data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -46
  64. data/lib/cyberarm_engine/opengl/perspective_camera.rb +41 -41
  65. data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -249
  66. data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +167 -167
  67. data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +307 -307
  68. data/lib/cyberarm_engine/opengl/renderer/renderer.rb +33 -33
  69. data/lib/cyberarm_engine/opengl/shader.rb +408 -408
  70. data/lib/cyberarm_engine/opengl/texture.rb +69 -69
  71. data/lib/cyberarm_engine/opengl.rb +53 -53
  72. data/lib/cyberarm_engine/pathfinding/graph.rb +64 -0
  73. data/lib/cyberarm_engine/pathfinding/graph_search.rb +6 -0
  74. data/lib/cyberarm_engine/pathfinding/graph_searches/astar_search.rb +6 -0
  75. data/lib/cyberarm_engine/pathfinding/graph_searches/breadth_first_search.rb +27 -0
  76. data/lib/cyberarm_engine/pathfinding/graph_searches/dijkstra_search.rb +6 -0
  77. data/lib/cyberarm_engine/pathfinding/graphs/grid.rb +52 -0
  78. data/lib/cyberarm_engine/ray.rb +56 -56
  79. data/lib/cyberarm_engine/result.rb +19 -0
  80. data/lib/cyberarm_engine/stats.rb +200 -200
  81. data/lib/cyberarm_engine/text.rb +288 -260
  82. data/lib/cyberarm_engine/timer.rb +27 -23
  83. data/lib/cyberarm_engine/transform.rb +296 -296
  84. data/lib/cyberarm_engine/trees/aabb_node.rb +126 -126
  85. data/lib/cyberarm_engine/trees/aabb_tree.rb +55 -55
  86. data/lib/cyberarm_engine/trees/aabb_tree_debug.rb +29 -29
  87. data/lib/cyberarm_engine/ui/border_canvas.rb +102 -102
  88. data/lib/cyberarm_engine/ui/dialog.rb +24 -0
  89. data/lib/cyberarm_engine/ui/dsl.rb +170 -142
  90. data/lib/cyberarm_engine/ui/element.rb +664 -662
  91. data/lib/cyberarm_engine/ui/elements/button.rb +99 -100
  92. data/lib/cyberarm_engine/ui/elements/check_box.rb +58 -54
  93. data/lib/cyberarm_engine/ui/elements/container.rb +413 -407
  94. data/lib/cyberarm_engine/ui/elements/edit_box.rb +200 -179
  95. data/lib/cyberarm_engine/ui/elements/edit_line.rb +299 -297
  96. data/lib/cyberarm_engine/ui/elements/flow.rb +15 -15
  97. data/lib/cyberarm_engine/ui/elements/image.rb +78 -72
  98. data/lib/cyberarm_engine/ui/elements/list_box.rb +79 -79
  99. data/lib/cyberarm_engine/ui/elements/menu.rb +27 -27
  100. data/lib/cyberarm_engine/ui/elements/menu_item.rb +6 -6
  101. data/lib/cyberarm_engine/ui/elements/progress.rb +95 -93
  102. data/lib/cyberarm_engine/ui/elements/radio.rb +6 -6
  103. data/lib/cyberarm_engine/ui/elements/slider.rb +111 -107
  104. data/lib/cyberarm_engine/ui/elements/stack.rb +11 -11
  105. data/lib/cyberarm_engine/ui/elements/text_block.rb +236 -222
  106. data/lib/cyberarm_engine/ui/elements/toggle_button.rb +71 -67
  107. data/lib/cyberarm_engine/ui/elements/widget.rb +45 -0
  108. data/lib/cyberarm_engine/ui/event.rb +54 -54
  109. data/lib/cyberarm_engine/ui/gui_state.rb +402 -326
  110. data/lib/cyberarm_engine/ui/page.rb +39 -0
  111. data/lib/cyberarm_engine/ui/style.rb +94 -61
  112. data/lib/cyberarm_engine/ui/theme.rb +237 -225
  113. data/lib/cyberarm_engine/vector.rb +312 -312
  114. data/lib/cyberarm_engine/version.rb +4 -4
  115. data/lib/cyberarm_engine/window.rb +234 -195
  116. data/lib/cyberarm_engine.rb +88 -76
  117. data/mrbgem.rake +29 -29
  118. metadata +30 -5
@@ -1,158 +1,156 @@
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
- @top_left.x = @x
39
- @top_left.y = @y
40
- @top_right.x = @x + @width
41
- @top_right.y = @y
42
- @bottom_left.x = @x
43
- @bottom_left.y = @y + @height
44
- @bottom_right.x = @x + @width
45
- @bottom_right.y = @y + @height
46
- end
47
-
48
- def shortest_distance(point, la, lb)
49
- a = la.x - lb.x
50
- b = la.y - lb.y
51
- c = Gosu.distance(la.x, la.y, lb.x, lb.y)
52
- p a, b, c
53
- d = (a * point.x + b * point.y + c).abs / Math.sqrt(a * a + b * b)
54
- puts "Distance: #{d}"
55
- exit!
56
- d
57
- end
58
-
59
- def debug_outline
60
- # Top
61
- Gosu.draw_line(
62
- @x, @y, Gosu::Color::RED,
63
- @x + @width, @y, Gosu::Color::RED,
64
- @z
65
- )
66
-
67
- # Right
68
- Gosu.draw_line(
69
- @x + @width, @y, Gosu::Color::RED,
70
- @x + @width, @y + @height, Gosu::Color::RED,
71
- @z
72
- )
73
-
74
- # Bottom
75
- Gosu.draw_line(
76
- @x + @width, @y + @height, Gosu::Color::RED,
77
- @x, @y + @height, Gosu::Color::RED,
78
- @z
79
- )
80
-
81
- # Left
82
- Gosu.draw_line(
83
- @x, @y + @height, Gosu::Color::RED,
84
- @x, @y, Gosu::Color::RED,
85
- @z
86
- )
87
- end
88
-
89
- def background=(_background)
90
- @paint.set(_background)
91
- update
92
- end
93
-
94
- def angle=(n)
95
- @angle = n
96
- update
97
- end
98
- end
99
-
100
- class Paint
101
- attr_accessor :top_left, :top_right, :bottom_left, :bottom_right
102
-
103
- def initialize(background)
104
- set(background)
105
- end
106
-
107
- def set(background)
108
- @background = background
109
-
110
- if background.is_a?(Numeric)
111
- @top_left = background
112
- @top_right = background
113
- @bottom_left = background
114
- @bottom_right = background
115
- elsif background.is_a?(Gosu::Color)
116
- @top_left = background
117
- @top_right = background
118
- @bottom_left = background
119
- @bottom_right = background
120
- elsif background.is_a?(Array)
121
- if background.size == 1
122
- set(background.first)
123
- elsif background.size == 2
124
- @top_left = background.first
125
- @top_right = background.last
126
- @bottom_left = background.first
127
- @bottom_right = background.last
128
- elsif background.size == 4
129
- @top_left = background[0]
130
- @top_right = background[1]
131
- @bottom_left = background[2]
132
- @bottom_right = background[3]
133
- else
134
- raise ArgumentError, "background array was empty or had wrong number of elements (expected 2 or 4 elements)"
135
- end
136
- elsif background.is_a?(Hash)
137
- @top_left = background[:top_left]
138
- @top_right = background[:top_right]
139
- @bottom_left = background[:bottom_left]
140
- @bottom_right = background[:bottom_right]
141
- elsif background.is_a?(Range)
142
- set([background.begin, background.begin, background.end, background.end])
143
- else
144
- raise ArgumentError, "background '#{background.inspect}' of type '#{background.class}' was not able to be processed"
145
- end
146
- end
147
- end
148
- end
149
-
150
- # Add <=> method to support Range based gradients
151
- # NOTE: Disabled, causes stack overflow 🙃
152
- # module Gosu
153
- # class Color
154
- # def <=>(_other)
155
- # self
156
- # end
157
- # end
158
- # 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
+ if @angle.zero?
25
+ render
26
+ else
27
+ Gosu.clip_to(@x, @y, @width, @height) do
28
+ render
29
+ end
30
+ end
31
+
32
+ debug_outline if @debug
33
+ end
34
+
35
+ def render
36
+ Gosu.draw_quad(
37
+ @top_left.x, @top_left.y, @paint.top_left,
38
+ @top_right.x, @top_right.y, @paint.top_right,
39
+ @bottom_right.x, @bottom_right.y, @paint.bottom_right,
40
+ @bottom_left.x, @bottom_left.y, @paint.bottom_left,
41
+ @z
42
+ )
43
+ end
44
+
45
+ def update
46
+ @top_left.x = @x
47
+ @top_left.y = @y
48
+ @top_right.x = @x + @width
49
+ @top_right.y = @y
50
+ @bottom_left.x = @x
51
+ @bottom_left.y = @y + @height
52
+ @bottom_right.x = @x + @width
53
+ @bottom_right.y = @y + @height
54
+ end
55
+
56
+ def shortest_distance(point, la, lb)
57
+ a = la.x - lb.x
58
+ b = la.y - lb.y
59
+ c = Gosu.distance(la.x, la.y, lb.x, lb.y)
60
+ p a, b, c
61
+ d = (a * point.x + b * point.y + c).abs / Math.sqrt(a * a + b * b)
62
+ puts "Distance: #{d}"
63
+ exit!
64
+ d
65
+ end
66
+
67
+ def debug_outline
68
+ # Top
69
+ Gosu.draw_line(
70
+ @x, @y, Gosu::Color::RED,
71
+ @x + @width, @y, Gosu::Color::RED,
72
+ @z
73
+ )
74
+
75
+ # Right
76
+ Gosu.draw_line(
77
+ @x + @width, @y, Gosu::Color::RED,
78
+ @x + @width, @y + @height, Gosu::Color::RED,
79
+ @z
80
+ )
81
+
82
+ # Bottom
83
+ Gosu.draw_line(
84
+ @x + @width, @y + @height, Gosu::Color::RED,
85
+ @x, @y + @height, Gosu::Color::RED,
86
+ @z
87
+ )
88
+
89
+ # Left
90
+ Gosu.draw_line(
91
+ @x, @y + @height, Gosu::Color::RED,
92
+ @x, @y, Gosu::Color::RED,
93
+ @z
94
+ )
95
+ end
96
+
97
+ def background=(_background)
98
+ @paint.set(_background)
99
+ update
100
+ end
101
+
102
+ def angle=(n)
103
+ @angle = n
104
+ update
105
+ end
106
+ end
107
+
108
+ class Paint
109
+ attr_accessor :top_left, :top_right, :bottom_left, :bottom_right
110
+
111
+ def initialize(background)
112
+ set(background)
113
+ end
114
+
115
+ def set(background)
116
+ @background = background
117
+
118
+ if background.is_a?(Numeric)
119
+ @top_left = background
120
+ @top_right = background
121
+ @bottom_left = background
122
+ @bottom_right = background
123
+ elsif background.is_a?(Gosu::Color)
124
+ @top_left = background
125
+ @top_right = background
126
+ @bottom_left = background
127
+ @bottom_right = background
128
+ elsif background.is_a?(Array)
129
+ if background.size == 1
130
+ set(background.first)
131
+ elsif background.size == 2
132
+ @top_left = background.first
133
+ @top_right = background.last
134
+ @bottom_left = background.first
135
+ @bottom_right = background.last
136
+ elsif background.size == 4
137
+ @top_left = background[0]
138
+ @top_right = background[1]
139
+ @bottom_left = background[2]
140
+ @bottom_right = background[3]
141
+ else
142
+ raise ArgumentError, "background array was empty or had wrong number of elements (expected 2 or 4 elements)"
143
+ end
144
+ elsif background.is_a?(Hash)
145
+ @top_left = background[:top_left]
146
+ @top_right = background[:top_right]
147
+ @bottom_left = background[:bottom_left]
148
+ @bottom_right = background[:bottom_right]
149
+ elsif background.is_a?(Range)
150
+ set([background.begin, background.begin, background.end, background.end])
151
+ else
152
+ raise ArgumentError, "background '#{background.inspect}' of type '#{background.class}' was not able to be processed"
153
+ end
154
+ end
155
+ end
156
+ 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