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,216 +1,216 @@
1
- module CyberarmEngine
2
- class Model
3
- include OpenGL
4
- include CyberarmEngine
5
-
6
- attr_accessor :objects, :materials, :vertices, :uvs, :texures, :normals, :faces, :colors, :bones, :material_file,
7
- :current_material, :current_object, :vertex_count, :smoothing
8
- attr_reader :position, :bounding_box, :textured_material, :file_path, :positions_buffer_id, :colors_buffer_id,
9
- :normals_buffer_id, :uvs_buffer_id, :textures_buffer_id, :vertex_array_id, :aabb_tree,
10
- :vertices_count
11
-
12
- def initialize(file_path:)
13
- @file_path = file_path
14
-
15
- @material_file = nil
16
- @current_object = nil
17
- @current_material = nil
18
- @vertex_count = 0
19
-
20
- @objects = []
21
- @materials = {}
22
- @vertices = []
23
- @colors = []
24
- @uvs = []
25
- @normals = []
26
- @faces = []
27
- @bones = []
28
- @smoothing = 0
29
-
30
- @vertices_count = 0
31
-
32
- @bounding_box = BoundingBox.new
33
- start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
34
-
35
- type = File.basename(file_path).split(".").last.to_sym
36
- parser = Model::Parser.find(type)
37
- raise "Unsupported model type '.#{type}', supported models are: #{Model::Parser.supported_formats}" unless parser
38
-
39
- parse(parser)
40
-
41
- @vertices_count = @vertices.size
42
-
43
- @has_texture = false
44
-
45
- @materials.each do |_key, material|
46
- @has_texture = true if material.texture_id
47
- end
48
-
49
- allocate_gl_objects
50
- populate_vertex_buffer
51
- configure_vao
52
-
53
- @objects.each { |o| @vertex_count += o.vertices.size }
54
-
55
- start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
56
- build_collision_tree
57
- puts " Building mesh collision tree took #{((Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond) - start_time) / 1000.0).round(2)} seconds"
58
- end
59
-
60
- def parse(parser)
61
- parser.new(self).parse
62
- end
63
-
64
- def calculate_bounding_box(vertices, bounding_box)
65
- unless bounding_box.min.x.is_a?(Float)
66
- vertex = vertices.last
67
- bounding_box.min.x = vertex.x
68
- bounding_box.min.y = vertex.y
69
- bounding_box.min.z = vertex.z
70
-
71
- bounding_box.max.x = vertex.x
72
- bounding_box.max.y = vertex.y
73
- bounding_box.max.z = vertex.z
74
- end
75
-
76
- vertices.each do |vertex|
77
- bounding_box.min.x = vertex.x if vertex.x <= bounding_box.min.x
78
- bounding_box.min.y = vertex.y if vertex.y <= bounding_box.min.y
79
- bounding_box.min.z = vertex.z if vertex.z <= bounding_box.min.z
80
-
81
- bounding_box.max.x = vertex.x if vertex.x >= bounding_box.max.x
82
- bounding_box.max.y = vertex.y if vertex.y >= bounding_box.max.y
83
- bounding_box.max.z = vertex.z if vertex.z >= bounding_box.max.z
84
- end
85
- end
86
-
87
- def allocate_gl_objects
88
- # Allocate arrays for future use
89
- @vertex_array_id = nil
90
- buffer = " " * 4
91
- glGenVertexArrays(1, buffer)
92
- @vertex_array_id = buffer.unpack1("L2")
93
-
94
- # Allocate buffers for future use
95
- @positions_buffer_id = nil
96
- buffer = " " * 4
97
- glGenBuffers(1, buffer)
98
- @positions_buffer_id = buffer.unpack1("L2")
99
-
100
- @colors_buffer_id = nil
101
- buffer = " " * 4
102
- glGenBuffers(1, buffer)
103
- @colors_buffer_id = buffer.unpack1("L2")
104
-
105
- @normals_buffer_id = nil
106
- buffer = " " * 4
107
- glGenBuffers(1, buffer)
108
- @normals_buffer_id = buffer.unpack1("L2")
109
-
110
- @uvs_buffer_id = nil
111
- buffer = " " * 4
112
- glGenBuffers(1, buffer)
113
- @uvs_buffer_id = buffer.unpack1("L2")
114
- end
115
-
116
- def populate_vertex_buffer
117
- pos = []
118
- colors = []
119
- norms = []
120
- uvs = []
121
-
122
- @faces.each do |face|
123
- pos << face.vertices.map { |vert| [vert.x, vert.y, vert.z] }
124
- colors << face.colors.map { |color| [color.red, color.green, color.blue] }
125
- norms << face.normals.map { |vert| [vert.x, vert.y, vert.z, vert.weight] }
126
-
127
- uvs << face.uvs.map { |vert| [vert.x, vert.y, vert.z] } if has_texture?
128
- end
129
-
130
- glBindBuffer(GL_ARRAY_BUFFER, @positions_buffer_id)
131
- glBufferData(GL_ARRAY_BUFFER, pos.flatten.size * Fiddle::SIZEOF_FLOAT, pos.flatten.pack("f*"), GL_STATIC_DRAW)
132
-
133
- glBindBuffer(GL_ARRAY_BUFFER, @colors_buffer_id)
134
- glBufferData(GL_ARRAY_BUFFER, colors.flatten.size * Fiddle::SIZEOF_FLOAT, colors.flatten.pack("f*"),
135
- GL_STATIC_DRAW)
136
-
137
- glBindBuffer(GL_ARRAY_BUFFER, @normals_buffer_id)
138
- glBufferData(GL_ARRAY_BUFFER, norms.flatten.size * Fiddle::SIZEOF_FLOAT, norms.flatten.pack("f*"), GL_STATIC_DRAW)
139
-
140
- if has_texture?
141
- glBindBuffer(GL_ARRAY_BUFFER, @uvs_buffer_id)
142
- glBufferData(GL_ARRAY_BUFFER, uvs.flatten.size * Fiddle::SIZEOF_FLOAT, uvs.flatten.pack("f*"), GL_STATIC_DRAW)
143
- end
144
-
145
- glBindBuffer(GL_ARRAY_BUFFER, 0)
146
- end
147
-
148
- def configure_vao
149
- glBindVertexArray(@vertex_array_id)
150
- gl_error?
151
-
152
- # index, size, type, normalized, stride, pointer
153
- # vertices (positions)
154
- glBindBuffer(GL_ARRAY_BUFFER, @positions_buffer_id)
155
- gl_error?
156
-
157
- # in_position
158
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nil)
159
- gl_error?
160
- # colors
161
- glBindBuffer(GL_ARRAY_BUFFER, @colors_buffer_id)
162
- # in_color
163
- glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, nil)
164
- gl_error?
165
- # normals
166
- glBindBuffer(GL_ARRAY_BUFFER, @normals_buffer_id)
167
- # in_normal
168
- glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, nil)
169
- gl_error?
170
-
171
- if has_texture?
172
- # uvs
173
- glBindBuffer(GL_ARRAY_BUFFER, @uvs_buffer_id)
174
- # in_uv
175
- glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, nil)
176
- gl_error?
177
- end
178
-
179
- glBindBuffer(GL_ARRAY_BUFFER, 0)
180
- glBindVertexArray(0)
181
- end
182
-
183
- def build_collision_tree
184
- @aabb_tree = AABBTree.new
185
-
186
- @faces.each do |face|
187
- box = BoundingBox.new
188
- box.min = face.vertices.first.dup
189
- box.max = face.vertices.first.dup
190
-
191
- face.vertices.each do |vertex|
192
- if vertex.sum < box.min.sum
193
- box.min = vertex.dup
194
- elsif vertex.sum > box.max.sum
195
- box.max = vertex.dup
196
- end
197
- end
198
-
199
- # FIXME: Handle negatives
200
- box.min *= 1.5
201
- box.max *= 1.5
202
- @aabb_tree.insert(face, box)
203
- end
204
- end
205
-
206
- def has_texture?
207
- @has_texture
208
- end
209
-
210
- def release_gl_resources
211
- if @vertex_array_id
212
-
213
- end
214
- end
215
- end
216
- end
1
+ module CyberarmEngine
2
+ class Model
3
+ include OpenGL
4
+ include CyberarmEngine
5
+
6
+ attr_accessor :objects, :materials, :vertices, :uvs, :texures, :normals, :faces, :colors, :bones, :material_file,
7
+ :current_material, :current_object, :vertex_count, :smoothing
8
+ attr_reader :position, :bounding_box, :textured_material, :file_path, :positions_buffer_id, :colors_buffer_id,
9
+ :normals_buffer_id, :uvs_buffer_id, :textures_buffer_id, :vertex_array_id, :aabb_tree,
10
+ :vertices_count
11
+
12
+ def initialize(file_path:)
13
+ @file_path = file_path
14
+
15
+ @material_file = nil
16
+ @current_object = nil
17
+ @current_material = nil
18
+ @vertex_count = 0
19
+
20
+ @objects = []
21
+ @materials = {}
22
+ @vertices = []
23
+ @colors = []
24
+ @uvs = []
25
+ @normals = []
26
+ @faces = []
27
+ @bones = []
28
+ @smoothing = 0
29
+
30
+ @vertices_count = 0
31
+
32
+ @bounding_box = BoundingBox.new
33
+ start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
34
+
35
+ type = File.basename(file_path).split(".").last.to_sym
36
+ parser = Model::Parser.find(type)
37
+ raise "Unsupported model type '.#{type}', supported models are: #{Model::Parser.supported_formats}" unless parser
38
+
39
+ parse(parser)
40
+
41
+ @vertices_count = @vertices.size
42
+
43
+ @has_texture = false
44
+
45
+ @materials.each do |_key, material|
46
+ @has_texture = true if material.texture_id
47
+ end
48
+
49
+ allocate_gl_objects
50
+ populate_vertex_buffer
51
+ configure_vao
52
+
53
+ @objects.each { |o| @vertex_count += o.vertices.size }
54
+
55
+ start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
56
+ build_collision_tree
57
+ puts " Building mesh collision tree took #{((Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond) - start_time) / 1000.0).round(2)} seconds"
58
+ end
59
+
60
+ def parse(parser)
61
+ parser.new(self).parse
62
+ end
63
+
64
+ def calculate_bounding_box(vertices, bounding_box)
65
+ unless bounding_box.min.x.is_a?(Float)
66
+ vertex = vertices.last
67
+ bounding_box.min.x = vertex.x
68
+ bounding_box.min.y = vertex.y
69
+ bounding_box.min.z = vertex.z
70
+
71
+ bounding_box.max.x = vertex.x
72
+ bounding_box.max.y = vertex.y
73
+ bounding_box.max.z = vertex.z
74
+ end
75
+
76
+ vertices.each do |vertex|
77
+ bounding_box.min.x = vertex.x if vertex.x <= bounding_box.min.x
78
+ bounding_box.min.y = vertex.y if vertex.y <= bounding_box.min.y
79
+ bounding_box.min.z = vertex.z if vertex.z <= bounding_box.min.z
80
+
81
+ bounding_box.max.x = vertex.x if vertex.x >= bounding_box.max.x
82
+ bounding_box.max.y = vertex.y if vertex.y >= bounding_box.max.y
83
+ bounding_box.max.z = vertex.z if vertex.z >= bounding_box.max.z
84
+ end
85
+ end
86
+
87
+ def allocate_gl_objects
88
+ # Allocate arrays for future use
89
+ @vertex_array_id = nil
90
+ buffer = " " * 4
91
+ glGenVertexArrays(1, buffer)
92
+ @vertex_array_id = buffer.unpack1("L2")
93
+
94
+ # Allocate buffers for future use
95
+ @positions_buffer_id = nil
96
+ buffer = " " * 4
97
+ glGenBuffers(1, buffer)
98
+ @positions_buffer_id = buffer.unpack1("L2")
99
+
100
+ @colors_buffer_id = nil
101
+ buffer = " " * 4
102
+ glGenBuffers(1, buffer)
103
+ @colors_buffer_id = buffer.unpack1("L2")
104
+
105
+ @normals_buffer_id = nil
106
+ buffer = " " * 4
107
+ glGenBuffers(1, buffer)
108
+ @normals_buffer_id = buffer.unpack1("L2")
109
+
110
+ @uvs_buffer_id = nil
111
+ buffer = " " * 4
112
+ glGenBuffers(1, buffer)
113
+ @uvs_buffer_id = buffer.unpack1("L2")
114
+ end
115
+
116
+ def populate_vertex_buffer
117
+ pos = []
118
+ colors = []
119
+ norms = []
120
+ uvs = []
121
+
122
+ @faces.each do |face|
123
+ pos << face.vertices.map { |vert| [vert.x, vert.y, vert.z] }
124
+ colors << face.colors.map { |color| [color.red, color.green, color.blue] }
125
+ norms << face.normals.map { |vert| [vert.x, vert.y, vert.z, vert.weight] }
126
+
127
+ uvs << face.uvs.map { |vert| [vert.x, vert.y, vert.z] } if has_texture?
128
+ end
129
+
130
+ glBindBuffer(GL_ARRAY_BUFFER, @positions_buffer_id)
131
+ glBufferData(GL_ARRAY_BUFFER, pos.flatten.size * Fiddle::SIZEOF_FLOAT, pos.flatten.pack("f*"), GL_STATIC_DRAW)
132
+
133
+ glBindBuffer(GL_ARRAY_BUFFER, @colors_buffer_id)
134
+ glBufferData(GL_ARRAY_BUFFER, colors.flatten.size * Fiddle::SIZEOF_FLOAT, colors.flatten.pack("f*"),
135
+ GL_STATIC_DRAW)
136
+
137
+ glBindBuffer(GL_ARRAY_BUFFER, @normals_buffer_id)
138
+ glBufferData(GL_ARRAY_BUFFER, norms.flatten.size * Fiddle::SIZEOF_FLOAT, norms.flatten.pack("f*"), GL_STATIC_DRAW)
139
+
140
+ if has_texture?
141
+ glBindBuffer(GL_ARRAY_BUFFER, @uvs_buffer_id)
142
+ glBufferData(GL_ARRAY_BUFFER, uvs.flatten.size * Fiddle::SIZEOF_FLOAT, uvs.flatten.pack("f*"), GL_STATIC_DRAW)
143
+ end
144
+
145
+ glBindBuffer(GL_ARRAY_BUFFER, 0)
146
+ end
147
+
148
+ def configure_vao
149
+ glBindVertexArray(@vertex_array_id)
150
+ gl_error?
151
+
152
+ # index, size, type, normalized, stride, pointer
153
+ # vertices (positions)
154
+ glBindBuffer(GL_ARRAY_BUFFER, @positions_buffer_id)
155
+ gl_error?
156
+
157
+ # in_position
158
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nil)
159
+ gl_error?
160
+ # colors
161
+ glBindBuffer(GL_ARRAY_BUFFER, @colors_buffer_id)
162
+ # in_color
163
+ glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, nil)
164
+ gl_error?
165
+ # normals
166
+ glBindBuffer(GL_ARRAY_BUFFER, @normals_buffer_id)
167
+ # in_normal
168
+ glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, nil)
169
+ gl_error?
170
+
171
+ if has_texture?
172
+ # uvs
173
+ glBindBuffer(GL_ARRAY_BUFFER, @uvs_buffer_id)
174
+ # in_uv
175
+ glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, nil)
176
+ gl_error?
177
+ end
178
+
179
+ glBindBuffer(GL_ARRAY_BUFFER, 0)
180
+ glBindVertexArray(0)
181
+ end
182
+
183
+ def build_collision_tree
184
+ @aabb_tree = AABBTree.new
185
+
186
+ @faces.each do |face|
187
+ box = BoundingBox.new
188
+ box.min = face.vertices.first.dup
189
+ box.max = face.vertices.first.dup
190
+
191
+ face.vertices.each do |vertex|
192
+ if vertex.sum < box.min.sum
193
+ box.min = vertex.dup
194
+ elsif vertex.sum > box.max.sum
195
+ box.max = vertex.dup
196
+ end
197
+ end
198
+
199
+ # FIXME: Handle negatives
200
+ box.min *= 1.5
201
+ box.max *= 1.5
202
+ @aabb_tree.insert(face, box)
203
+ end
204
+ end
205
+
206
+ def has_texture?
207
+ @has_texture
208
+ end
209
+
210
+ def release_gl_resources
211
+ if @vertex_array_id
212
+
213
+ end
214
+ end
215
+ end
216
+ end
@@ -1,31 +1,31 @@
1
- module CyberarmEngine
2
- module ModelCache
3
- CACHE = {}
4
-
5
- def self.find_or_cache(manifest:)
6
- model_file = manifest.file_path + "/model/#{manifest.model}"
7
-
8
- type = File.basename(model_file).split(".").last.to_sym
9
-
10
- if model = load_model_from_cache(type, model_file)
11
- model
12
- else
13
- model = CyberarmEngine::Model.new(file_path: model_file)
14
- cache_model(type, model_file, model)
15
-
16
- model
17
- end
18
- end
19
-
20
- def self.load_model_from_cache(type, model_file)
21
- return CACHE[type][model_file] if CACHE[type].is_a?(Hash) && (CACHE[type][model_file])
22
-
23
- false
24
- end
25
-
26
- def self.cache_model(type, model_file, model)
27
- CACHE[type] = {} unless CACHE[type].is_a?(Hash)
28
- CACHE[type][model_file] = model
29
- end
30
- end
31
- end
1
+ module CyberarmEngine
2
+ module ModelCache
3
+ CACHE = {}
4
+
5
+ def self.find_or_cache(manifest:)
6
+ model_file = manifest.file_path + "/model/#{manifest.model}"
7
+
8
+ type = File.basename(model_file).split(".").last.to_sym
9
+
10
+ if model = load_model_from_cache(type, model_file)
11
+ model
12
+ else
13
+ model = CyberarmEngine::Model.new(file_path: model_file)
14
+ cache_model(type, model_file, model)
15
+
16
+ model
17
+ end
18
+ end
19
+
20
+ def self.load_model_from_cache(type, model_file)
21
+ return CACHE[type][model_file] if CACHE[type].is_a?(Hash) && (CACHE[type][model_file])
22
+
23
+ false
24
+ end
25
+
26
+ def self.cache_model(type, model_file, model)
27
+ CACHE[type] = {} unless CACHE[type].is_a?(Hash)
28
+ CACHE[type][model_file] = model
29
+ end
30
+ end
31
+ end
@@ -1,83 +1,83 @@
1
- module CyberarmEngine
2
- class Notification
3
- WIDTH = 500
4
- HEIGHT = 64
5
- EDGE_WIDTH = 8
6
- TRANSITION_DURATION = 750
7
- PADDING = 8
8
-
9
- TTL_LONG = 5_000
10
- TTL_MEDIUM = 3_250
11
- TTL_SHORT = 1_500
12
- TIME_TO_LIVE = TTL_MEDIUM
13
-
14
- BACKGROUND_COLOR = Gosu::Color.new(0xaa313533)
15
- EDGE_COLOR = Gosu::Color.new(0xaa010101)
16
- ICON_COLOR = Gosu::Color.new(0xddffffff)
17
- TITLE_COLOR = Gosu::Color.new(0xddffffff)
18
- TAGLINE_COLOR = Gosu::Color.new(0xddaaaaaa)
19
-
20
- TITLE_SIZE = 28
21
- TAGLINE_SIZE = 18
22
- ICON_SIZE = HEIGHT - PADDING * 2
23
-
24
- TITLE_FONT = Gosu::Font.new(TITLE_SIZE, bold: true)
25
- TAGLINE_FONT = Gosu::Font.new(TAGLINE_SIZE)
26
-
27
- PRIORITY_HIGH = 1.0
28
- PRIORITY_MEDIUM = 0.5
29
- PRIORITY_LOW = 0.0
30
-
31
- LINEAR_TRANSITION = :linear
32
- EASE_IN_OUT_TRANSITION = :ease_in_out
33
-
34
- attr_reader :priority, :title, :tagline, :icon, :time_to_live, :transition_duration, :transition_type
35
- def initialize(
36
- host:, priority:, title:, title_color: TITLE_COLOR, tagline: "", tagline_color: TAGLINE_COLOR, icon: nil, icon_color: ICON_COLOR,
37
- edge_color: EDGE_COLOR, background_color: BACKGROUND_COLOR, time_to_live: TIME_TO_LIVE, transition_duration: TRANSITION_DURATION,
38
- transition_type: EASE_IN_OUT_TRANSITION
39
- )
40
- @host = host
41
-
42
- @priority = priority
43
- @title = title
44
- @title_color = title_color
45
- @tagline = tagline
46
- @tagline_color = tagline_color
47
- @icon = icon
48
- @icon_color = icon_color
49
- @edge_color = edge_color
50
- @background_color = background_color
51
- @time_to_live = time_to_live
52
- @transition_duration = transition_duration
53
- @transition_type = transition_type
54
-
55
- @icon_scale = ICON_SIZE.to_f / @icon.width if @icon
56
- end
57
-
58
- def draw
59
- Gosu.draw_rect(0, 0, WIDTH, HEIGHT, @background_color)
60
-
61
- if @host.edge == :top
62
- Gosu.draw_rect(0, HEIGHT - EDGE_WIDTH, WIDTH, EDGE_WIDTH, @edge_color)
63
- @icon.draw(EDGE_WIDTH + PADDING, PADDING, 0, @icon_scale, @icon_scale, @icon_color) if @icon
64
-
65
- elsif @host.edge == :bottom
66
- Gosu.draw_rect(0, 0, WIDTH, EDGE_WIDTH, @edge_color)
67
- @icon.draw(EDGE_WIDTH + PADDING, PADDING, 0, @icon_scale, @icon_scale, @icon_color) if @icon
68
-
69
- elsif @host.edge == :right
70
- Gosu.draw_rect(0, 0, EDGE_WIDTH, HEIGHT, @edge_color)
71
- @icon.draw(EDGE_WIDTH + PADDING, PADDING, 0, @icon_scale, @icon_scale, @icon_color) if @icon
72
-
73
- else
74
- Gosu.draw_rect(WIDTH - EDGE_WIDTH, 0, EDGE_WIDTH, HEIGHT, @edge_color)
75
- @icon.draw(PADDING, PADDING, 0, @icon_scale, @icon_scale, @icon_color) if @icon
76
- end
77
-
78
- icon_space = @icon ? ICON_SIZE + PADDING : 0
79
- TITLE_FONT.draw_text(@title, PADDING + EDGE_WIDTH + icon_space, PADDING, 0, 1, 1, @title_color)
80
- TAGLINE_FONT.draw_text(@tagline, PADDING + EDGE_WIDTH + icon_space, PADDING + TITLE_FONT.height, 0, 1, 1, @tagline_color)
81
- end
82
- end
1
+ module CyberarmEngine
2
+ class Notification
3
+ WIDTH = 500
4
+ HEIGHT = 64
5
+ EDGE_WIDTH = 8
6
+ TRANSITION_DURATION = 750
7
+ PADDING = 8
8
+
9
+ TTL_LONG = 5_000
10
+ TTL_MEDIUM = 3_250
11
+ TTL_SHORT = 1_500
12
+ TIME_TO_LIVE = TTL_MEDIUM
13
+
14
+ BACKGROUND_COLOR = Gosu::Color.new(0xaa313533)
15
+ EDGE_COLOR = Gosu::Color.new(0xaa010101)
16
+ ICON_COLOR = Gosu::Color.new(0xddffffff)
17
+ TITLE_COLOR = Gosu::Color.new(0xddffffff)
18
+ TAGLINE_COLOR = Gosu::Color.new(0xddaaaaaa)
19
+
20
+ TITLE_SIZE = 28
21
+ TAGLINE_SIZE = 18
22
+ ICON_SIZE = HEIGHT - PADDING * 2
23
+
24
+ TITLE_FONT = Gosu::Font.new(TITLE_SIZE, bold: true)
25
+ TAGLINE_FONT = Gosu::Font.new(TAGLINE_SIZE)
26
+
27
+ PRIORITY_HIGH = 1.0
28
+ PRIORITY_MEDIUM = 0.5
29
+ PRIORITY_LOW = 0.0
30
+
31
+ LINEAR_TRANSITION = :linear
32
+ EASE_IN_OUT_TRANSITION = :ease_in_out
33
+
34
+ attr_reader :priority, :title, :tagline, :icon, :time_to_live, :transition_duration, :transition_type
35
+ def initialize(
36
+ host:, priority:, title:, title_color: TITLE_COLOR, tagline: "", tagline_color: TAGLINE_COLOR, icon: nil, icon_color: ICON_COLOR,
37
+ edge_color: EDGE_COLOR, background_color: BACKGROUND_COLOR, time_to_live: TIME_TO_LIVE, transition_duration: TRANSITION_DURATION,
38
+ transition_type: EASE_IN_OUT_TRANSITION
39
+ )
40
+ @host = host
41
+
42
+ @priority = priority
43
+ @title = title
44
+ @title_color = title_color
45
+ @tagline = tagline
46
+ @tagline_color = tagline_color
47
+ @icon = icon
48
+ @icon_color = icon_color
49
+ @edge_color = edge_color
50
+ @background_color = background_color
51
+ @time_to_live = time_to_live
52
+ @transition_duration = transition_duration
53
+ @transition_type = transition_type
54
+
55
+ @icon_scale = ICON_SIZE.to_f / @icon.width if @icon
56
+ end
57
+
58
+ def draw
59
+ Gosu.draw_rect(0, 0, WIDTH, HEIGHT, @background_color)
60
+
61
+ if @host.edge == :top
62
+ Gosu.draw_rect(0, HEIGHT - EDGE_WIDTH, WIDTH, EDGE_WIDTH, @edge_color)
63
+ @icon.draw(EDGE_WIDTH + PADDING, PADDING, 0, @icon_scale, @icon_scale, @icon_color) if @icon
64
+
65
+ elsif @host.edge == :bottom
66
+ Gosu.draw_rect(0, 0, WIDTH, EDGE_WIDTH, @edge_color)
67
+ @icon.draw(EDGE_WIDTH + PADDING, PADDING, 0, @icon_scale, @icon_scale, @icon_color) if @icon
68
+
69
+ elsif @host.edge == :right
70
+ Gosu.draw_rect(0, 0, EDGE_WIDTH, HEIGHT, @edge_color)
71
+ @icon.draw(EDGE_WIDTH + PADDING, PADDING, 0, @icon_scale, @icon_scale, @icon_color) if @icon
72
+
73
+ else
74
+ Gosu.draw_rect(WIDTH - EDGE_WIDTH, 0, EDGE_WIDTH, HEIGHT, @edge_color)
75
+ @icon.draw(PADDING, PADDING, 0, @icon_scale, @icon_scale, @icon_color) if @icon
76
+ end
77
+
78
+ icon_space = @icon ? ICON_SIZE + PADDING : 0
79
+ TITLE_FONT.draw_text(@title, PADDING + EDGE_WIDTH + icon_space, PADDING, 0, 1, 1, @title_color)
80
+ TAGLINE_FONT.draw_text(@tagline, PADDING + EDGE_WIDTH + icon_space, PADDING + TITLE_FONT.height, 0, 1, 1, @tagline_color)
81
+ end
82
+ end
83
83
  end