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