cyberarm_engine 0.21.0 → 0.23.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c2a84a8ea330594a18b0768f5453347a50e3c4f5e2c5a896e8f6d24f559b44f
4
- data.tar.gz: 1c7fc5eb93f3549a8dccc1a38b810ae3d45a264096fccaae0efae8b34778ef3a
3
+ metadata.gz: c883f949982d339928785f9dbcbe710a7df483ba698ce6e3e95d38d300cf4e03
4
+ data.tar.gz: 17364dddce1f68533a01b9b69d591792bf4c9495341fc3a9726d77e70fa8246f
5
5
  SHA512:
6
- metadata.gz: db9cc74b11276ae1f7499a33d79edef4180737906a6bdc5d8d755eb63cee9fdc3cd44349ee11852e519eb9bb16788a4a9f2e46aeb1798404f6570575e76fcc73
7
- data.tar.gz: 9e2d553ec0871db57ba78397d182aadc78cbc57d401f3dcac5386d008d9cff9254b006753fbbecec8a7931b7f08ce60010308c0c424e2f8caf27f9a3a0da53e3
6
+ metadata.gz: cd9fdd1da003de3a01e1d56ba1cedff869ef702ed0f070725f8a234f5a4686bd7798bc1239a0f346d0191fd2709e2c91816a461a20bb7c862fdff940ca3968c6
7
+ data.tar.gz: 7d6afa770c285bd0c841607eda82d1bc36f1b70b15f5c6864db837822855f54243d5a44c64395ae6bf161c74d424ac9a529b5241161c520f481844df06ef1b5d
@@ -0,0 +1,30 @@
1
+ # version 330 core
2
+
3
+ layout(location = 0) out vec3 fragPosition;
4
+ layout (location = 1) out vec4 fragColor;
5
+ layout (location = 2) out vec3 fragNormal;
6
+ layout (location = 3) out vec3 fragUV;
7
+
8
+ in vec3 outPosition, outColor, outNormal, outUV, outFragPos, outCameraPos;
9
+ out vec4 outputFragColor;
10
+ flat in int outHasTexture;
11
+
12
+ uniform sampler2D diffuse_texture;
13
+
14
+ void main() {
15
+ vec3 result;
16
+
17
+ if (outHasTexture == 0) {
18
+ result = outColor;
19
+ } else {
20
+ result = texture(diffuse_texture, outUV.xy).xyz + 0.25;
21
+ }
22
+
23
+ fragPosition = outPosition;
24
+ fragColor = vec4(result, 1.0);
25
+ fragNormal = outNormal;
26
+ fragUV = outUV;
27
+
28
+ float gamma = 2.2;
29
+ outputFragColor.rgb = pow(fragColor.rgb, vec3(1.0 / gamma));
30
+ }
@@ -0,0 +1,63 @@
1
+ #version 330 core
2
+ out vec4 FragColor;
3
+
4
+ @include "light_struct"
5
+ const int DIRECTIONAL = 0;
6
+ const int POINT = 1;
7
+ const int SPOT = 2;
8
+
9
+ in vec2 outTexCoords;
10
+ flat in Light outLight[1];
11
+
12
+ uniform sampler2D diffuse, position, texcoord, normal, depth;
13
+
14
+ vec4 directionalLight(Light light) {
15
+ vec3 norm = normalize(texture(normal, outTexCoords).rgb);
16
+ vec3 diffuse_color = texture(diffuse, outTexCoords).rgb;
17
+ vec3 fragPos = texture(position, outTexCoords).rgb;
18
+
19
+ vec3 lightDir = normalize(light.position - fragPos);
20
+ float diff = max(dot(norm, lightDir), 0);
21
+
22
+ vec3 _ambient = light.ambient;
23
+ vec3 _diffuse = light.diffuse * diff;
24
+ vec3 _specular = light.specular;
25
+
26
+ return vec4(_diffuse + _ambient + _specular, 1.0);
27
+ }
28
+
29
+ vec4 pointLight(Light light) {
30
+ return vec4(0.25, 0.25, 0.25, 1);
31
+ }
32
+
33
+ vec4 spotLight(Light light) {
34
+ return vec4(0.5, 0.5, 0.5, 1);
35
+ }
36
+
37
+ vec4 calculateLighting(Light light) {
38
+ vec4 result;
39
+
40
+ // switch(light.type) {
41
+ // case DIRECTIONAL: {
42
+ // result = directionalLight(light);
43
+ // }
44
+ // case SPOT: {
45
+ // result = spotLight(light);
46
+ // }
47
+ // default: {
48
+ // result = pointLight(light);
49
+ // }
50
+ // }
51
+
52
+ if (light.type == DIRECTIONAL) {
53
+ result = directionalLight(light);
54
+ } else {
55
+ result = pointLight(light);
56
+ }
57
+
58
+ return result;
59
+ }
60
+
61
+ void main() {
62
+ FragColor = texture(diffuse, outTexCoords) * calculateLighting(outLight[0]);
63
+ }
@@ -0,0 +1,11 @@
1
+ struct Light {
2
+ int type;
3
+ vec3 direction;
4
+ vec3 position;
5
+
6
+ vec3 diffuse;
7
+ vec3 ambient;
8
+ vec3 specular;
9
+
10
+ float intensity;
11
+ };
@@ -0,0 +1,28 @@
1
+ # version 330 core
2
+
3
+ layout(location = 0) in vec3 inPosition;
4
+ layout(location = 1) in vec3 inColor;
5
+ layout(location = 2) in vec3 inNormal;
6
+ layout(location = 3) in vec3 inUV;
7
+
8
+ uniform mat4 projection, view, model;
9
+ uniform int hasTexture;
10
+ uniform vec3 cameraPos;
11
+
12
+ out vec3 outPosition, outColor, outNormal, outUV;
13
+ out vec3 outFragPos, outViewPos, outCameraPos;
14
+ flat out int outHasTexture;
15
+
16
+ void main() {
17
+ // projection * view * model * position
18
+ outPosition = inPosition;
19
+ outColor = inColor;
20
+ outNormal= normalize(transpose(inverse(mat3(model))) * inNormal);
21
+ outUV = inUV;
22
+ outHasTexture = hasTexture;
23
+ outCameraPos = cameraPos;
24
+
25
+ outFragPos = vec3(model * vec4(inPosition, 1.0));
26
+
27
+ gl_Position = projection * view * model * vec4(inPosition, 1.0);
28
+ }
@@ -0,0 +1,17 @@
1
+ #version 330 core
2
+ @include "light_struct"
3
+
4
+ layout (location = 0) in vec3 inPosition;
5
+ layout (location = 1) in vec2 inTexCoords;
6
+
7
+ uniform sampler2D diffuse, position, texcoord, normal, depth;
8
+ uniform Light light[1];
9
+
10
+ out vec2 outTexCoords;
11
+ flat out Light outLight[1];
12
+
13
+ void main() {
14
+ gl_Position = vec4(inPosition.x, inPosition.y, inPosition.z, 1.0);
15
+ outTexCoords = inTexCoords;
16
+ outLight = light;
17
+ }
@@ -27,7 +27,6 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = %w[lib assets]
29
29
 
30
- spec.add_dependency "clipboard", "~> 1.3"
31
30
  spec.add_dependency "excon", "~> 0.88"
32
31
  spec.add_dependency "gosu", "~> 1.1"
33
32
  spec.add_dependency "gosu_more_drawables", "~> 0.3"
@@ -75,7 +75,7 @@ module CyberarmEngine
75
75
  end
76
76
 
77
77
  def draw_fill
78
- if @width * width_scale > height * height_scale
78
+ if (@image.width * width_scale) >= @width && (@image.height * width_scale) >= @height
79
79
  draw_fill_width
80
80
  else
81
81
  draw_fill_height
@@ -7,8 +7,8 @@ module CyberarmEngine
7
7
  @title_size = 56
8
8
  @caption_size = 24
9
9
 
10
- @title = CyberarmEngine::Text.new("", size: @title_size, shadow_color: 0xaa_222222)
11
- @caption = CyberarmEngine::Text.new("", size: @caption_size, shadow_color: 0xaa_222222)
10
+ @title = CyberarmEngine::Text.new("", size: @title_size, shadow_color: 0xaa_222222, static: true)
11
+ @caption = CyberarmEngine::Text.new("", size: @caption_size, shadow_color: 0xaa_222222, static: true)
12
12
 
13
13
  @spacer_width = 256
14
14
  @spacer_height = 6
@@ -8,8 +8,11 @@ module CyberarmEngine
8
8
  window.current_state
9
9
  end
10
10
 
11
- def previous_state
12
- window.previous_state
11
+ def previous_state(state = nil)
12
+ raise "Only available for CyberarmEngine::GameState and subclasses" unless is_a?(CyberarmEngine::GameState) || state.is_a?(CyberarmEngine::GameState)
13
+
14
+ i = window.states.index(state || self)
15
+ window.states[i - 1] unless (i - 1).negative?
13
16
  end
14
17
 
15
18
  def pop_state
@@ -28,6 +31,18 @@ module CyberarmEngine
28
31
  window.show_cursor = boolean
29
32
  end
30
33
 
34
+ def find_element_by_tag(container, tag, list = [])
35
+ return unless container
36
+
37
+ container.children.each do |child|
38
+ list << child if child.style.tag == tag
39
+
40
+ find_element_by_tag(child, tag, list) if child.is_a?(CyberarmEngine::Element::Container)
41
+ end
42
+
43
+ list.first
44
+ end
45
+
31
46
  def draw_rect(x, y, width, height, color, z = 0, mode = :default)
32
47
  Gosu.draw_rect(x, y, width, height, color, z, mode)
33
48
  end
@@ -34,6 +34,10 @@ module CyberarmEngine
34
34
  true
35
35
  end
36
36
 
37
+ def needs_repaint?
38
+ true
39
+ end
40
+
37
41
  def drop(filename)
38
42
  end
39
43
 
@@ -1,6 +1,7 @@
1
1
  module CyberarmEngine
2
2
  class GBuffer
3
3
  attr_reader :screen_vbo, :vertices, :uvs
4
+ attr_reader :width, :height
4
5
 
5
6
  def initialize(width:, height:)
6
7
  @width = width
@@ -11,7 +11,19 @@ module CyberarmEngine
11
11
  if e != GL_NO_ERROR
12
12
  warn "OpenGL error detected by handler at: #{caller[0]}"
13
13
  warn " #{gluErrorString(e)} (#{e})\n"
14
- exit if window.exit_on_opengl_error?
14
+ exit if Window.instance&.exit_on_opengl_error?
15
+ end
16
+ end
17
+
18
+ def preload_default_shaders
19
+ shaders = %w[g_buffer lighting]
20
+ shaders.each do |shader|
21
+ Shader.new(
22
+ name: shader,
23
+ includes_dir: "#{CYBERARM_ENGINE_ROOT_PATH}/assets/shaders/include",
24
+ vertex: "#{CYBERARM_ENGINE_ROOT_PATH}/assets/shaders/vertex/#{shader}.glsl",
25
+ fragment: "#{CYBERARM_ENGINE_ROOT_PATH}/assets/shaders/fragment/#{shader}.glsl"
26
+ )
15
27
  end
16
28
  end
17
29
  end
@@ -22,19 +22,21 @@ module CyberarmEngine
22
22
  else
23
23
  @color = Gosu::Color::WHITE
24
24
  end
25
- @mode = options[:mode] || :default
25
+ @mode = options[:mode] || :default
26
26
  @alignment = options[:alignment] || nil
27
27
 
28
28
  @border = options[:border]
29
29
  @border = true if options[:border].nil?
30
30
  @border_size = options[:border_size] || 1
31
31
  @border_alpha = options[:border_alpha] || 30
32
- @border_color = options[:border_color]
32
+ @border_color = options[:border_color] || Gosu::Color::BLACK
33
33
 
34
34
  @shadow = options[:shadow]
35
35
  @shadow_size = options[:shadow_size] || 2
36
36
  @shadow_alpha = options[:shadow_alpha] || 30
37
- @shadow_color = options[:shadow_color]
37
+ @shadow_color = options[:shadow_color] || Gosu::Color::BLACK
38
+
39
+ @static = options[:static] || (options[:static].nil? || options[:static] == false ? false : true)
38
40
 
39
41
  @textobject = check_cache(@size, @font)
40
42
 
@@ -84,46 +86,49 @@ module CyberarmEngine
84
86
  end
85
87
 
86
88
  def text=(string)
87
- @rendered_border = nil
89
+ invalidate_cache! if @text != string
88
90
  @text = string
89
91
  end
90
92
 
91
93
  def factor_x=(n)
92
- @rendered_border = nil
94
+ invalidate_cache! if @factor_x != n
93
95
  @factor_x = n
94
96
  end
95
97
 
96
98
  def factor_y=(n)
97
- @rendered_border = nil
99
+ invalidate_cache! if @factor_y != n
98
100
  @factor_y = n
99
101
  end
100
102
 
101
103
  def color=(color)
102
- @rendered_border = nil
104
+ old_color = @color
105
+
103
106
  if color
104
107
  @color = color.is_a?(Gosu::Color) ? color : Gosu::Color.new(color)
105
108
  else
106
109
  raise "color cannot be nil"
107
110
  end
111
+
112
+ invalidate_cache! if old_color != color
108
113
  end
109
114
 
110
115
  def border=(boolean)
111
- @rendered_border = nil
116
+ invalidate_cache! if @border != boolean
112
117
  @border = boolean
113
118
  end
114
119
 
115
120
  def border_size=(n)
116
- @rendered_border = nil
121
+ invalidate_cache! if @border_size != n
117
122
  @border_size = n
118
123
  end
119
124
 
120
125
  def border_alpha=(n)
121
- @rendered_border = nil
126
+ invalidate_cache! if @border_alpha != n
122
127
  @border_alpha = n
123
128
  end
124
129
 
125
130
  def border_color=(n)
126
- @rendered_border = nil
131
+ invalidate_cache! if @border_color != n
127
132
  @border_color = n
128
133
  end
129
134
 
@@ -132,11 +137,27 @@ module CyberarmEngine
132
137
  end
133
138
 
134
139
  def text_width(text = @text)
135
- textobject.text_width(text) + @border_size + @shadow_size
140
+ spacing = 0
141
+ spacing += @border_size if @border
142
+ spacing += @shadow_size if @shadow
143
+
144
+ if text == @text && @static && @gosu_cached_text_image
145
+ @gosu_cached_text_image&.width + spacing
146
+ else
147
+ textobject.text_width(text) + spacing
148
+ end
136
149
  end
137
150
 
138
151
  def markup_width(text = @text)
139
- textobject.markup_width(text) + @border_size + @shadow_size
152
+ spacing = 0
153
+ spacing += @border_size if @border
154
+ spacing += @shadow_size if @shadow
155
+
156
+ if text == @text && @static && @gosu_cached_text_image
157
+ @gosu_cached_text_image&.width + spacing
158
+ else
159
+ textobject.markup_width(text) + spacing
160
+ end
140
161
  end
141
162
 
142
163
  def height(text = @text)
@@ -148,39 +169,72 @@ module CyberarmEngine
148
169
  end
149
170
 
150
171
  def draw(method = :draw_markup)
151
- if @border && !ARGV.join.include?("--no-border")
152
- border_alpha = @color.alpha <= 30 ? @color.alpha : @border_alpha
153
- border_color = @border_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue,
154
- border_alpha)
155
- white = Gosu::Color::WHITE
172
+ if @static
173
+ if @border && !@cached_text_border_image
174
+ _x = @border_size
175
+ _y = @border_size
176
+ _width = method == :draw_markup ? text_width : markup_width
177
+ img = Gosu::Image.send(:"from_#{method.to_s.split("_").last}", @text, @size, font: @font)
178
+
179
+ @cached_text_border_image = Gosu.render((_width + (@border_size * 2)).ceil, (height + (@border_size * 2)).ceil) do
180
+ img.draw(-_x, 0, @z, @factor_x, @factor_y, @border_color, @mode)
181
+ img.draw(-_x, -_y, @z, @factor_x, @factor_y, @border_color, @mode)
182
+
183
+ img.draw(0, -_y, @z, @factor_x, @factor_y, @border_color, @mode)
184
+ img.draw(_x, -_y, @z, @factor_x, @factor_y, @border_color, @mode)
185
+
186
+ img.draw(_x, 0, @z, @factor_x, @factor_y, @border_color, @mode)
187
+ img.draw(_x, _y, @z, @factor_x, @factor_y, @border_color, @mode)
188
+
189
+ img.draw(0, _y, @z, @factor_x, @factor_y, @border_color, @mode)
190
+ img.draw(-_x, _y, @z, @factor_x, @factor_y, @border_color, @mode)
191
+ end
192
+ end
193
+
194
+ @cached_text_shadow_image ||= Gosu::Image.send(:"from_#{method.to_s.split("_").last}", @text, @size, font: @font) if @shadow
156
195
 
157
- _x = @border_size
158
- _y = @border_size
159
- _width = method == :draw_markup ? text_width : markup_width
196
+ @gosu_cached_text_image ||= Gosu::Image.send(:"from_#{method.to_s.split("_").last}", @text, @size, font: @font)
160
197
 
161
- @rendered_border ||= Gosu.render((_width + (border_size * 2)).ceil, (height + (@border_size * 2)).ceil) do
162
- @textobject.send(method, @text, _x - @border_size, _y, @z, @factor_x, @factor_y, white, @mode)
163
- @textobject.send(method, @text, _x - @border_size, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
198
+ @cached_text_border_image.draw(@x, @y, @z, @factor_x, @factor_y, @border_color, @mode) if @border
164
199
 
165
- @textobject.send(method, @text, _x, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
166
- @textobject.send(method, @text, _x + @border_size, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
200
+ @cached_text_shadow_image.draw(@x + @shadow_size, @y + @shadow_size, @z, @factor_x, @factor_y, @shadow_color, @mode) if @shadow
167
201
 
168
- @textobject.send(method, @text, _x, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
169
- @textobject.send(method, @text, _x - @border_size, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
202
+ @gosu_cached_text_image.draw(@x, @y, @z, @factor_x, @factor_y, @color, @mode)
203
+ else
204
+ if @border && !ARGV.join.include?("--no-border")
205
+ border_alpha = @color.alpha <= 30 ? @color.alpha : @border_alpha
206
+ border_color = @border_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue,
207
+ border_alpha)
208
+ white = Gosu::Color::WHITE
209
+
210
+ _x = @border_size
211
+ _y = @border_size
212
+ _width = method == :draw_markup ? text_width : markup_width
213
+
214
+ @cached_text_border_image ||= Gosu.render((_width + (border_size * 2)).ceil, (height + (@border_size * 2)).ceil) do
215
+ @textobject.send(method, @text, _x - @border_size, _y, @z, @factor_x, @factor_y, white, @mode)
216
+ @textobject.send(method, @text, _x - @border_size, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
217
+
218
+ @textobject.send(method, @text, _x, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
219
+ @textobject.send(method, @text, _x + @border_size, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
220
+
221
+ @textobject.send(method, @text, _x, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
222
+ @textobject.send(method, @text, _x - @border_size, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
223
+
224
+ @textobject.send(method, @text, _x + @border_size, _y, @z, @factor_x, @factor_y, white, @mode)
225
+ @textobject.send(method, @text, _x + @border_size, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
226
+ end
170
227
 
171
- @textobject.send(method, @text, _x + @border_size, _y, @z, @factor_x, @factor_y, white, @mode)
172
- @textobject.send(method, @text, _x + @border_size, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
228
+ @cached_text_border_image.draw(@x - @border_size, @y - @border_size, @z, @factor_x, @factor_y, border_color)
173
229
  end
174
230
 
175
- @rendered_border.draw(@x - @border_size, @y - @border_size, @z, @factor_x, @factor_y, border_color)
176
- end
231
+ if @shadow
232
+ shadow_color = @shadow_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue, @shadow_alpha)
233
+ @textobject.send(method, @text, @x + @shadow_size, @y + @shadow_size, @z, @factor_x, @factor_y, shadow_color, @mode)
234
+ end
177
235
 
178
- if @shadow
179
- shadow_color = @shadow_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue, @shadow_alpha)
180
- @textobject.send(method, @text, @x + @shadow_size, @y + @shadow_size, @z, @factor_x, @factor_y, shadow_color, @mode)
236
+ @textobject.send(method, @text, @x, @y, @z, @factor_x, @factor_y, @color, @mode)
181
237
  end
182
-
183
- @textobject.send(method, @text, @x, @y, @z, @factor_x, @factor_y, @color, @mode)
184
238
  end
185
239
 
186
240
  def alpha=(n)
@@ -193,5 +247,11 @@ module CyberarmEngine
193
247
 
194
248
  def update
195
249
  end
250
+
251
+ def invalidate_cache!
252
+ @cached_text_border_image = nil
253
+ @cached_text_shadow_image = nil
254
+ @gosu_cached_text_image = nil
255
+ end
196
256
  end
197
257
  end
@@ -62,11 +62,11 @@ module CyberarmEngine
62
62
 
63
63
  def update
64
64
  # TOP
65
- @top.x = @element.x # + @element.border_thickness_left
65
+ @top.x = @element.x + @element.style.border_thickness_left
66
66
  @top.y = @element.y
67
67
  @top.z = @element.z
68
68
 
69
- @top.width = @element.width
69
+ @top.width = @element.width - @element.style.border_thickness_left
70
70
  @top.height = @element.style.border_thickness_top
71
71
 
72
72
  # RIGHT