cyberarm_engine 0.22.0 → 0.24.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/assets/shaders/fragment/g_buffer.glsl +30 -0
  3. data/assets/shaders/fragment/lighting.glsl +69 -0
  4. data/assets/shaders/include/light_struct.glsl +11 -0
  5. data/assets/shaders/include/material_struct.glsl +16 -0
  6. data/assets/shaders/vertex/g_buffer.glsl +28 -0
  7. data/assets/shaders/vertex/lighting.glsl +24 -0
  8. data/lib/cyberarm_engine/background_image.rb +1 -1
  9. data/lib/cyberarm_engine/builtin/intro_state.rb +3 -3
  10. data/lib/cyberarm_engine/common.rb +14 -2
  11. data/lib/cyberarm_engine/console.rb +10 -10
  12. data/lib/cyberarm_engine/game_object.rb +1 -1
  13. data/lib/cyberarm_engine/game_state.rb +4 -0
  14. data/lib/cyberarm_engine/gosu_ext/draw_arc.rb +98 -0
  15. data/lib/cyberarm_engine/gosu_ext/draw_circle.rb +31 -0
  16. data/lib/cyberarm_engine/gosu_ext/draw_path.rb +17 -0
  17. data/lib/cyberarm_engine/model.rb +7 -6
  18. data/lib/cyberarm_engine/notification.rb +83 -0
  19. data/lib/cyberarm_engine/notification_manager.rb +242 -0
  20. data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +1 -0
  21. data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +16 -10
  22. data/lib/cyberarm_engine/opengl/renderer/renderer.rb +12 -1
  23. data/lib/cyberarm_engine/opengl/shader.rb +2 -2
  24. data/lib/cyberarm_engine/opengl.rb +13 -1
  25. data/lib/cyberarm_engine/stats.rb +181 -10
  26. data/lib/cyberarm_engine/text.rb +3 -0
  27. data/lib/cyberarm_engine/ui/border_canvas.rb +2 -2
  28. data/lib/cyberarm_engine/ui/element.rb +74 -26
  29. data/lib/cyberarm_engine/ui/elements/container.rb +95 -25
  30. data/lib/cyberarm_engine/ui/elements/edit_line.rb +6 -0
  31. data/lib/cyberarm_engine/ui/elements/image.rb +2 -2
  32. data/lib/cyberarm_engine/ui/elements/progress.rb +5 -0
  33. data/lib/cyberarm_engine/ui/elements/slider.rb +6 -3
  34. data/lib/cyberarm_engine/ui/elements/text_block.rb +19 -1
  35. data/lib/cyberarm_engine/ui/gui_state.rb +53 -27
  36. data/lib/cyberarm_engine/ui/style.rb +2 -1
  37. data/lib/cyberarm_engine/vector.rb +35 -16
  38. data/lib/cyberarm_engine/version.rb +1 -1
  39. data/lib/cyberarm_engine/window.rb +40 -8
  40. data/lib/cyberarm_engine.rb +8 -2
  41. data/mrbgem.rake +29 -0
  42. metadata +15 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '084b65265f65a631e6a27bf59c7dfd738af16aeb86b3298c30503d4560a87f58'
4
- data.tar.gz: c73cf6b9f66780c230f331409ef5256d7364cf1b6d05e515bf638b8fa3722417
3
+ metadata.gz: 5af070a65180730f1435091615fa8160c0763fbdc552918c63c93037b41571f0
4
+ data.tar.gz: f426d50db35a7f6b520a239bda8f9eed39d6e1b77ea77a1a7f9cca1c0b9edb0e
5
5
  SHA512:
6
- metadata.gz: 40fd281091cbf5fa84c6f166ab9bdb24e893fd29f987309e2f1fa812737281dbee1612ef12a6b18bd7677bf50b69916f7379976871f78014dd8e49376c789023
7
- data.tar.gz: 7884dc297c81d0add9fdd77cf38fad94765010502944f59cb31ed47cd54bf9e3f85746f488ffdc66d2e555656a7ab3d2b9c0780277593d05b0dea4f5aa5c17b8
6
+ metadata.gz: dbe115990e1e9ae8f7c86a2152a16e7ff7dd752cd84029b2e30b41cbce533b9649abea04009bf2c763b033ec64be89c85f60ef8d07040c450ba57e4fb1a1fe95
7
+ data.tar.gz: 18bf468ce8ccb6547e6f578f668f0cb9774d0833f60f8956ac4e98d68c5de61d4b3c1f3079e12e5032a92f4d3a2335a18ae7b4ac7ab15f7eeccd531ae0c64e0a
@@ -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 out_position, out_color, out_normal, out_uv, out_frag_pos, out_camera_pos;
9
+ out vec4 outputFragColor;
10
+ flat in int out_has_texture;
11
+
12
+ uniform sampler2D diffuse_texture;
13
+
14
+ void main() {
15
+ vec3 result;
16
+
17
+ if (out_has_texture == 0) {
18
+ result = out_color;
19
+ } else {
20
+ result = texture(diffuse_texture, out_uv.xy).xyz + 0.25;
21
+ }
22
+
23
+ fragPosition = out_position;
24
+ fragColor = vec4(result, 1.0);
25
+ fragNormal = out_normal;
26
+ fragUV = out_uv;
27
+
28
+ float gamma = 2.2;
29
+ outputFragColor.rgb = pow(fragColor.rgb, vec3(1.0 / gamma));
30
+ }
@@ -0,0 +1,69 @@
1
+ #version 330 core
2
+ out vec4 frag_color;
3
+
4
+ @include "light_struct"
5
+ const int DIRECTIONAL = 0;
6
+ const int POINT = 1;
7
+ const int SPOT = 2;
8
+
9
+ flat in Light out_lights[7];
10
+ in vec2 out_tex_coords;
11
+ flat in int out_light_count;
12
+
13
+ uniform sampler2D diffuse, position, texcoord, normal, depth;
14
+
15
+ vec4 directionalLight(Light light) {
16
+ vec3 norm = normalize(texture(normal, out_tex_coords).rgb);
17
+ vec3 diffuse_color = texture(diffuse, out_tex_coords).rgb;
18
+ vec3 frag_pos = texture(position, out_tex_coords).rgb;
19
+
20
+ vec3 lightDir = normalize(light.position - frag_pos);
21
+ float diff = max(dot(norm, lightDir), 0);
22
+
23
+ vec3 _ambient = light.ambient;
24
+ vec3 _diffuse = light.diffuse * diff;
25
+ vec3 _specular = light.specular;
26
+
27
+ return vec4(_diffuse + _ambient + _specular, 1.0);
28
+ }
29
+
30
+ vec4 pointLight(Light light) {
31
+ return vec4(0.25, 0.25, 0.25, 1);
32
+ }
33
+
34
+ vec4 spotLight(Light light) {
35
+ return vec4(0.5, 0.5, 0.5, 1);
36
+ }
37
+
38
+ vec4 calculateLighting(Light light) {
39
+ vec4 result;
40
+
41
+ // switch(light.type) {
42
+ // case DIRECTIONAL: {
43
+ // result = directionalLight(light);
44
+ // }
45
+ // case SPOT: {
46
+ // result = spotLight(light);
47
+ // }
48
+ // default: {
49
+ // result = pointLight(light);
50
+ // }
51
+ // }
52
+
53
+ if (light.type == DIRECTIONAL) {
54
+ result = directionalLight(light);
55
+ } else {
56
+ result = pointLight(light);
57
+ }
58
+
59
+ return result;
60
+ }
61
+
62
+ void main() {
63
+ frag_color = vec4(0.0);
64
+
65
+ for(int i = 0; i < out_light_count; i++)
66
+ {
67
+ frag_color += texture(diffuse, out_tex_coords) * calculateLighting(out_lights[i]);
68
+ }
69
+ }
@@ -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,16 @@
1
+ struct Material {
2
+ vec3 color;
3
+ vec3 roughness;
4
+ vec3 metalic;
5
+ vec3 specular;
6
+
7
+ bool use_color_texture;
8
+ bool use_roughness_texture;
9
+ bool use_metalic_texture;
10
+ bool use_specular_texture;
11
+
12
+ sampler2D color_tex;
13
+ sampler2D roughness_tex;
14
+ sampler2D metalic_tex;
15
+ sampler2D specular_tex;
16
+ };
@@ -0,0 +1,28 @@
1
+ # version 330 core
2
+
3
+ layout(location = 0) in vec3 in_position;
4
+ layout(location = 1) in vec3 in_color;
5
+ layout(location = 2) in vec3 in_normal;
6
+ layout(location = 3) in vec3 in_uv;
7
+
8
+ uniform mat4 projection, view, model;
9
+ uniform int has_texture;
10
+ uniform vec3 camera_pos;
11
+
12
+ out vec3 out_position, out_color, out_normal, out_uv;
13
+ out vec3 out_frag_pos, out_view_pos, out_camera_pos;
14
+ flat out int out_has_texture;
15
+
16
+ void main() {
17
+ // projection * view * model * position
18
+ out_position = in_position;
19
+ out_color = in_color;
20
+ out_normal= normalize(transpose(inverse(mat3(model))) * in_normal);
21
+ out_uv = in_uv;
22
+ out_has_texture = has_texture;
23
+ out_camera_pos = camera_pos;
24
+
25
+ out_frag_pos = vec3(model * vec4(in_position, 1.0));
26
+
27
+ gl_Position = projection * view * model * vec4(in_position, 1.0);
28
+ }
@@ -0,0 +1,24 @@
1
+ #version 330 core
2
+ @include "light_struct"
3
+
4
+ layout (location = 0) in vec3 in_position;
5
+ layout (location = 1) in vec2 in_tex_coords;
6
+
7
+ uniform sampler2D diffuse, position, texcoord, normal, depth;
8
+ uniform int light_count;
9
+ uniform Light lights[7];
10
+
11
+ out vec2 out_tex_coords;
12
+ flat out int out_light_count;
13
+ flat out Light out_lights[7];
14
+
15
+ void main() {
16
+ gl_Position = vec4(in_position.x, in_position.y, in_position.z, 1.0);
17
+ out_tex_coords = in_tex_coords;
18
+ out_light_count = light_count;
19
+
20
+ for(int i = 0; i < light_count; i++)
21
+ {
22
+ out_lights[i] = lights[i];
23
+ }
24
+ }
@@ -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
@@ -18,7 +18,7 @@ module CyberarmEngine
18
18
 
19
19
  @gosu_logo = generate_proxy("Gosu", "Game Library", 0xff_111111)
20
20
  @ruby_logo = generate_proxy("Ruby", "Programming Language", 0xff_880000)
21
- @opengl_logo = generate_proxy("OpenGL", "Graphics API", 0xff_5586a4) if defined?(OpenGL)
21
+ @opengl_logo = generate_proxy("OpenGL", "Graphics API", 0xff_5586a4) if RUBY_ENGINE != "mruby" && defined?(OpenGL)
22
22
 
23
23
  base_time = Gosu.milliseconds
24
24
 
@@ -31,6 +31,18 @@ module CyberarmEngine
31
31
  window.show_cursor = boolean
32
32
  end
33
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
+
34
46
  def draw_rect(x, y, width, height, color, z = 0, mode = :default)
35
47
  Gosu.draw_rect(x, y, width, height, color, z, mode)
36
48
  end
@@ -40,7 +52,7 @@ module CyberarmEngine
40
52
  end
41
53
 
42
54
  def lighten(color, amount = 25)
43
- if defined?(color.alpha)
55
+ if color.respond_to?(:alpha)
44
56
  Gosu::Color.rgba(color.red + amount, color.green + amount, color.blue + amount, color.alpha)
45
57
  else
46
58
  Gosu::Color.rgb(color.red + amount, color.green + amount, color.blue + amount)
@@ -48,7 +60,7 @@ module CyberarmEngine
48
60
  end
49
61
 
50
62
  def darken(color, amount = 25)
51
- if defined?(color.alpha)
63
+ if color.respond_to?(:alpha)
52
64
  Gosu::Color.rgba(color.red - amount, color.green - amount, color.blue - amount, color.alpha)
53
65
  else
54
66
  Gosu::Color.rgb(color.red - amount, color.green - amount, color.blue - amount)
@@ -103,7 +103,7 @@ module CyberarmEngine
103
103
 
104
104
  def button_down(id)
105
105
  case id
106
- when Gosu::KbEnter, Gosu::KbReturn
106
+ when Gosu::KB_ENTER, Gosu::KB_RETURN
107
107
  return unless @text_input.text.length.positive?
108
108
 
109
109
  @history.text += "\n<c=999999>> #{@text_input.text}</c>"
@@ -113,12 +113,12 @@ module CyberarmEngine
113
113
  handle_command
114
114
  @text_input.text = ""
115
115
 
116
- when Gosu::KbUp
116
+ when Gosu::KB_UP
117
117
  @command_history_index -= 1
118
118
  @command_history_index = 0 if @command_history_index.negative?
119
119
  @text_input.text = @command_history[@command_history_index]
120
120
 
121
- when Gosu::KbDown
121
+ when Gosu::KB_DOWN
122
122
  @command_history_index += 1
123
123
  if @command_history_index > @command_history.size - 1
124
124
  @text_input.text = "" unless @command_history_index > @command_history.size
@@ -127,7 +127,7 @@ module CyberarmEngine
127
127
  @text_input.text = @command_history[@command_history_index]
128
128
  end
129
129
 
130
- when Gosu::KbTab
130
+ when Gosu::KB_TAB
131
131
  split = @text_input.text.split(" ")
132
132
 
133
133
  if !@text_input.text.end_with?(" ") && split.size == 1
@@ -142,7 +142,7 @@ module CyberarmEngine
142
142
  cmd.autocomplete(self)
143
143
  end
144
144
 
145
- when Gosu::KbBacktick
145
+ when Gosu::KB_BACKTICK
146
146
  # Remove backtick character from input
147
147
  @text_input.text = if @text_input.text.size > 1
148
148
  @text_input.text[0..@text_input.text.size - 2]
@@ -151,7 +151,7 @@ module CyberarmEngine
151
151
  end
152
152
 
153
153
  # Copy
154
- when Gosu::KbC
154
+ when Gosu::KB_C
155
155
  if control_down? && shift_down?
156
156
  @memory = @text_input.text[caret_start..caret_end - 1] if caret_start != caret_end
157
157
  p @memory
@@ -160,7 +160,7 @@ module CyberarmEngine
160
160
  end
161
161
 
162
162
  # Paste
163
- when Gosu::KbV
163
+ when Gosu::KB_V
164
164
  if control_down? && shift_down?
165
165
  string = @text_input.text.chars.insert(caret_pos, @memory).join
166
166
  _caret_pos = caret_pos
@@ -170,7 +170,7 @@ module CyberarmEngine
170
170
  end
171
171
 
172
172
  # Cut
173
- when Gosu::KbX
173
+ when Gosu::KB_X
174
174
  if control_down? && shift_down?
175
175
  @memory = @text_input.text[caret_start..caret_end - 1] if caret_start != caret_end
176
176
  string = @text_input.text.chars
@@ -182,7 +182,7 @@ module CyberarmEngine
182
182
  end
183
183
 
184
184
  # Delete word to left of caret
185
- when Gosu::KbW
185
+ when Gosu::KB_W
186
186
  if control_down?
187
187
  split = @text_input.text.split(" ")
188
188
  split.delete(split.last)
@@ -190,7 +190,7 @@ module CyberarmEngine
190
190
  end
191
191
 
192
192
  # Clear history
193
- when Gosu::KbL
193
+ when Gosu::KB_L
194
194
  @history.text = "" if control_down?
195
195
  end
196
196
  end
@@ -42,7 +42,7 @@ module CyberarmEngine
42
42
  @radius = if options[:radius]
43
43
  options[:radius]
44
44
  else
45
- defined?(@image.width) ? ((@image.width + @image.height) / 4) * scale : 1
45
+ @image.respond_to?(:width) ? ((@image.width + @image.height) / 4) * scale : 1
46
46
  end
47
47
  end
48
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
 
@@ -0,0 +1,98 @@
1
+ module Gosu
2
+ # Draw an arc around the point x and y.
3
+ #
4
+ # Color accepts the following: *Gosu::Color*, *Array* (with 2 colors), or a *Hash* with keys: _from:_ and _to:_ both colors.
5
+ #
6
+ # With a *Gosu::Color* the arc will be painted with color
7
+ #
8
+ # With an *Array* the first *Gosu::Color* with be the innermost color and the last *Gosu::Color* with be the outermost color
9
+ #
10
+ # With a *Hash* the arc will smoothly transition from the start of the arc to the end
11
+ # @example
12
+ # # Using a Hash
13
+ # Gosu.draw_arc(100, 100, 50, 0.5, 128, 4, {from: Gosu::Color::BLUE, to: Gosu::Color::GREEN}, 0, :default)
14
+ #
15
+ # # Using an Array
16
+ # Gosu.draw_arc(100, 100, 50, 0.5, 128, 4, [Gosu::Color::BLUE, Gosu::Color::GREEN], 0, :default)
17
+ #
18
+ # # Using a Gosu::Color
19
+ # Gosu.draw_arc(100, 100, 50, 0.5, 128, 4, Gosu::Color::BLUE, 0, :default)
20
+ #
21
+ #
22
+ # @param x X position.
23
+ # @param y Y position.
24
+ # @param radius radius of arc, in pixels.
25
+ # @param percentage how complete the segment is, _0.0_ is 0% and _1.0_ is 100%.
26
+ # @param segments how many segments for arc, more will appear smoother, less will appear jagged.
27
+ # @param thickness how thick arc will be.
28
+ # @param color [Gosu::Color, Array<Gosu::Color, Gosu::Color>, Hash{from: start_color, to: end_color}] color or colors to draw the arc with.
29
+ # @param z Z position.
30
+ # @param mode blend mode.
31
+ #
32
+ # @note _thickness_ is subtracted from radius, meaning that the arc will grow towards the origin, not away from it.
33
+ #
34
+ # @return [void]
35
+ def self.draw_arc(x, y, radius, percentage = 1.0, segments = 128, thickness = 4, color = Gosu::Color::WHITE, z = 0, mode = :default)
36
+ segments = 360.0 / segments
37
+
38
+ return if percentage == 0.0
39
+
40
+ 0.step((359 * percentage), percentage > 0 ? segments : -segments) do |angle|
41
+ angle2 = angle + segments
42
+
43
+ point_a_left_x = x + Gosu.offset_x(angle, radius - thickness)
44
+ point_a_left_y = y + Gosu.offset_y(angle, radius - thickness)
45
+
46
+ point_a_right_x = x + Gosu.offset_x(angle2, radius - thickness)
47
+ point_a_right_y = y + Gosu.offset_y(angle2, radius - thickness)
48
+
49
+ point_b_left_x = x + Gosu.offset_x(angle, radius)
50
+ point_b_left_y = y + Gosu.offset_y(angle, radius)
51
+
52
+ point_b_right_x = x + Gosu.offset_x(angle2, radius)
53
+ point_b_right_y = y + Gosu.offset_y(angle2, radius)
54
+
55
+ if color.is_a?(Array)
56
+ Gosu.draw_quad(
57
+ point_a_left_x, point_a_left_y, color.first,
58
+ point_b_left_x, point_b_left_y, color.last,
59
+ point_a_right_x, point_a_right_y, color.first,
60
+ point_b_right_x, point_b_right_y, color.last,
61
+ z, mode
62
+ )
63
+ elsif color.is_a?(Hash)
64
+ start_color = color[:from]
65
+ end_color = color[:to]
66
+
67
+ color_a = Gosu::Color.rgba(
68
+ (end_color.red - start_color.red) * (angle / 360.0) + start_color.red,
69
+ (end_color.green - start_color.green) * (angle / 360.0) + start_color.green,
70
+ (end_color.blue - start_color.blue) * (angle / 360.0) + start_color.blue,
71
+ (end_color.alpha - start_color.alpha) * (angle / 360.0) + start_color.alpha,
72
+ )
73
+ color_b = Gosu::Color.rgba(
74
+ (end_color.red - start_color.red) * (angle2 / 360.0) + start_color.red,
75
+ (end_color.green - start_color.green) * (angle2 / 360.0) + start_color.green,
76
+ (end_color.blue - start_color.blue) * (angle2 / 360.0) + start_color.blue,
77
+ (end_color.alpha - start_color.alpha) * (angle2 / 360.0) + start_color.alpha,
78
+ )
79
+
80
+ Gosu.draw_quad(
81
+ point_a_left_x, point_a_left_y, color_a,
82
+ point_b_left_x, point_b_left_y, color_a,
83
+ point_a_right_x, point_a_right_y, color_b,
84
+ point_b_right_x, point_b_right_y, color_b,
85
+ z, mode
86
+ )
87
+ else
88
+ Gosu.draw_quad(
89
+ point_a_left_x, point_a_left_y, color,
90
+ point_b_left_x, point_b_left_y, color,
91
+ point_a_right_x, point_a_right_y, color,
92
+ point_b_right_x, point_b_right_y, color,
93
+ z, mode
94
+ )
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,31 @@
1
+ module Gosu
2
+ ##
3
+ # Draw a filled circled around point X and Y.
4
+ #
5
+ # @param x X position.
6
+ # @param y Y position.
7
+ # @param radius radius of circle, in pixels.
8
+ # @param step_size resolution of circle, more steps will apear smoother, less will appear jagged.
9
+ # @param color color to draw circle with.
10
+ # @param mode blend mode.
11
+ #
12
+ # @return [void]
13
+ def self.draw_circle(x, y, radius, step_size = 36, color = Gosu::Color::WHITE, z = 0, mode = :default)
14
+ step_size = (360.0 / step_size).floor
15
+
16
+ 0.step(359, step_size) do |angle|
17
+ angle2 = angle + step_size
18
+
19
+ point_lx = x + Gosu.offset_x(angle, radius)
20
+ point_ly = y + Gosu.offset_y(angle, radius)
21
+ point_rx = x + Gosu.offset_x(angle2, radius)
22
+ point_ry = y + Gosu.offset_y(angle2, radius)
23
+
24
+ Gosu.draw_triangle(
25
+ point_lx, point_ly, color,
26
+ point_rx, point_ry, color,
27
+ x, y, color, z, mode
28
+ )
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,17 @@
1
+ module Gosu
2
+ PathNode = Struct.new(:x, :y)
3
+
4
+ def self.draw_path(nodes, color = Gosu::Color::WHITE, z = 0, mode = :default)
5
+ last_node = nodes.first
6
+
7
+ nodes[1..nodes.size - 1].each do |current_node|
8
+ Gosu.draw_line(
9
+ last_node.x, last_node.y, color,
10
+ current_node.x, current_node.y, color,
11
+ z, mode
12
+ )
13
+
14
+ last_node = current_node
15
+ end
16
+ end
17
+ end
@@ -49,8 +49,9 @@ module CyberarmEngine
49
49
 
50
50
  @objects.each { |o| @vertex_count += o.vertices.size }
51
51
 
52
- start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
52
+ # start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
53
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"
54
55
  end
55
56
 
56
57
  def parse(parser)
@@ -150,24 +151,24 @@ module CyberarmEngine
150
151
  glBindBuffer(GL_ARRAY_BUFFER, @positions_buffer_id)
151
152
  gl_error?
152
153
 
153
- # inPosition
154
+ # in_position
154
155
  glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nil)
155
156
  gl_error?
156
157
  # colors
157
158
  glBindBuffer(GL_ARRAY_BUFFER, @colors_buffer_id)
158
- # inColor
159
+ # in_color
159
160
  glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, nil)
160
161
  gl_error?
161
162
  # normals
162
163
  glBindBuffer(GL_ARRAY_BUFFER, @normals_buffer_id)
163
- # inNormal
164
+ # in_normal
164
165
  glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, nil)
165
166
  gl_error?
166
167
 
167
168
  if has_texture?
168
169
  # uvs
169
170
  glBindBuffer(GL_ARRAY_BUFFER, @uvs_buffer_id)
170
- # inUV
171
+ # in_uv
171
172
  glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, nil)
172
173
  gl_error?
173
174
  end
@@ -177,7 +178,7 @@ module CyberarmEngine
177
178
  end
178
179
 
179
180
  def build_collision_tree
180
- @aabb_tree = AABBTree.new
181
+ @aabb_tree = IMICFPS::AABBTree.new
181
182
 
182
183
  @faces.each do |face|
183
184
  box = BoundingBox.new
@@ -0,0 +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
83
+ end