cyberarm_engine 0.24.5 → 0.25.1

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: 7c44575f9a8fbd0035a9c3c29f5300b346fdc9cb739342c1b6208cb8add1a676
4
- data.tar.gz: '090cd515e5af9c480afb1314cddf56721a5dda85f3c7c8a7fe4c97b8faeb19f1'
3
+ metadata.gz: 684e4ba3ba113566003f54546d230b73a2e114de9ffb37a61c82459399fed368
4
+ data.tar.gz: ed6d16a4e889f8d7c744aff3c75b3688adeaae6ae63c670d43fc2416af3cc5c3
5
5
  SHA512:
6
- metadata.gz: 35613cc87423553e0976471dfa63559623c528d57826441eceb32bfdb58f3e7e0abeb1505895a8c9b5e2b7f1fa8814c482579a293d9816f944100c8bf01ebd46
7
- data.tar.gz: 247a5aa8f53dab456b6847f1c7918e2f4ac9a42748b3cdd64c6e99ca132dbd8ae4db5c5fcd522584266ccb1c46fbad3793d8b2ad51ceeeb4499574444a764823
6
+ metadata.gz: 9210c849bb6c757930f887f4af71c4782e199d3b46583da9152d3daead65887c34286fc7ebdce52226cebf342d23fd9434f6f99f441ecad1e8cfed7c37d64093
7
+ data.tar.gz: fa421d854aec6c8ef906b7e6882ec443d070517daf40650cd11abc98513db9ae7d412492de15467516ac8bb9abe3838f3bf5434577092e419195128311734301
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cyberarm_engine (0.24.4)
4
+ cyberarm_engine (0.24.5)
5
5
  gosu (~> 1.1)
6
6
 
7
7
  GEM
@@ -13,6 +13,7 @@ GEM
13
13
 
14
14
  PLATFORMS
15
15
  x64-mingw-ucrt
16
+ x86_64-linux
16
17
 
17
18
  DEPENDENCIES
18
19
  bundler (~> 2.2)
@@ -21,4 +22,4 @@ DEPENDENCIES
21
22
  rake (~> 13.0)
22
23
 
23
24
  BUNDLED WITH
24
- 2.5.3
25
+ 2.6.8
@@ -35,36 +35,14 @@ module CyberarmEngine
35
35
  end
36
36
 
37
37
  def update
38
- origin_x = (@x + (@width / 2))
39
- origin_y = (@y + (@height / 2))
40
-
41
- points = [
42
- @top_left = Vector.new(@x, @y),
43
- @top_right = Vector.new(@x + @width, @y),
44
- @bottom_left = Vector.new(@x, @y + @height),
45
- @bottom_right = Vector.new(@x + @width, @y + @height)
46
- ]
47
-
48
- [@top_left, @top_right, @bottom_left, @bottom_right].each do |vector|
49
- temp_x = vector.x - origin_x
50
- temp_y = vector.y - origin_y
51
-
52
- # 90 is up here, while gosu uses 0 for up.
53
- radians = (@angle + 90).gosu_to_radians
54
- vector.x = (@x + (@width / 2)) + ((temp_x * Math.cos(radians)) - (temp_y * Math.sin(radians)))
55
- vector.y = (@y + (@height / 2)) + ((temp_x * Math.sin(radians)) + (temp_y * Math.cos(radians)))
56
- end
57
-
58
- # [
59
- # [:top, @top_left, @top_right],
60
- # [:right, @top_right, @bottom_right],
61
- # [:bottom, @bottom_right, @bottom_left],
62
- # [:left, @bottom_left, @top_left]
63
- # ].each do |edge|
64
- # points.each do |point|
65
- # puts "#{edge.first} -> #{shortest_distance(point, edge[1], edge[2])}"
66
- # end
67
- # end
38
+ @top_left.x = @x
39
+ @top_left.y = @y
40
+ @top_right.x = @x + @width
41
+ @top_right.y = @y
42
+ @bottom_left.x = @x
43
+ @bottom_left.y = @y + @height
44
+ @bottom_right.x = @x + @width
45
+ @bottom_right.y = @y + @height
68
46
  end
69
47
 
70
48
  def shortest_distance(point, la, lb)
@@ -1,5 +1,7 @@
1
1
  module CyberarmEngine
2
2
  module Common
3
+ ImageBlob = Data.define(:to_blob, :columns, :rows)
4
+
3
5
  def push_state(klass, options = {})
4
6
  window.push_state(klass, options)
5
7
  end
@@ -85,7 +87,8 @@ module CyberarmEngine
85
87
  unless asset
86
88
  instance = nil
87
89
  instance = if klass == Gosu::Image
88
- klass.new(path, retro: retro, tileable: tileable)
90
+ path_or_blob = path.is_a?(String) ? path : ImageBlob.new(path.to_blob, path.width, path.height)
91
+ klass.new(path_or_blob, retro: retro, tileable: tileable)
89
92
  else
90
93
  klass.new(path)
91
94
  end
@@ -33,12 +33,23 @@ module Gosu
33
33
  #
34
34
  # @return [void]
35
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
36
  return if percentage == 0.0
39
37
 
40
- 0.step((359 * percentage), percentage > 0 ? segments : -segments) do |angle|
41
- angle2 = angle + segments
38
+ angle_per_segment = 360.0 / segments
39
+ arc_completion = 360 * percentage
40
+ next_segment_angle = angle_per_segment
41
+
42
+ angle = 0
43
+ loop do
44
+ break if angle >= arc_completion
45
+
46
+ if angle + angle_per_segment > arc_completion
47
+ next_segment_angle = arc_completion - angle
48
+ else
49
+ next_segment_angle = angle_per_segment
50
+ end
51
+
52
+ angle2 = angle + next_segment_angle
42
53
 
43
54
  point_a_left_x = x + Gosu.offset_x(angle, radius - thickness)
44
55
  point_a_left_y = y + Gosu.offset_y(angle, radius - thickness)
@@ -93,6 +104,8 @@ module Gosu
93
104
  z, mode
94
105
  )
95
106
  end
107
+
108
+ angle += next_segment_angle
96
109
  end
97
110
  end
98
- end
111
+ end
@@ -0,0 +1,20 @@
1
+ module CyberarmEngine
2
+ # result pattern
3
+ class Result
4
+ attr_accessor :error, :data
5
+
6
+ def initialize(data: nil, error: nil)
7
+ @data = data
8
+ @error = error
9
+ end
10
+
11
+ def okay?
12
+ !@error
13
+ end
14
+
15
+ def error?
16
+ @error || @data.nil?
17
+ end
18
+ end
19
+ end
20
+
@@ -7,13 +7,13 @@ module CyberarmEngine
7
7
  attr_reader :children, :gui_state, :scroll_position, :scroll_target_position
8
8
 
9
9
  def self.current_container
10
- @@current_container
10
+ @current_container
11
11
  end
12
12
 
13
13
  def self.current_container=(container)
14
14
  raise ArgumentError, "Expected container to an an instance of CyberarmEngine::Element::Container, got #{container.class}" unless container.is_a?(CyberarmEngine::Element::Container)
15
15
 
16
- @@current_container = container
16
+ @current_container = container
17
17
  end
18
18
 
19
19
  def initialize(options = {}, block = nil)
@@ -26,6 +26,11 @@ module CyberarmEngine
26
26
  @scroll_chunk = 120
27
27
  @scroll_speed = 40
28
28
 
29
+ if @gui_state
30
+ @width = window.width
31
+ @height = window.height
32
+ end
33
+
29
34
  @text_color = options[:color]
30
35
 
31
36
  @children = []
@@ -34,7 +39,7 @@ module CyberarmEngine
34
39
  end
35
40
 
36
41
  def build
37
- @block.call(self) if @block
42
+ @block&.call(self)
38
43
 
39
44
  root.gui_state.request_recalculate_for(self)
40
45
  end
@@ -53,7 +58,7 @@ module CyberarmEngine
53
58
  old_container = CyberarmEngine::Element::Container.current_container
54
59
 
55
60
  CyberarmEngine::Element::Container.current_container = self
56
- block.call(self) if block
61
+ block&.call(self)
57
62
 
58
63
  CyberarmEngine::Element::Container.current_container = old_container
59
64
 
@@ -66,7 +71,7 @@ module CyberarmEngine
66
71
  old_container = CyberarmEngine::Element::Container.current_container
67
72
 
68
73
  CyberarmEngine::Element::Container.current_container = self
69
- block.call(self) if block
74
+ block&.call(self)
70
75
 
71
76
  CyberarmEngine::Element::Container.current_container = old_container
72
77
 
@@ -89,9 +94,7 @@ module CyberarmEngine
89
94
  def debug_draw
90
95
  super
91
96
 
92
- @children.each do |child|
93
- child.debug_draw
94
- end
97
+ @children.each(&:debug_draw)
95
98
  end
96
99
 
97
100
  def update
@@ -111,7 +114,7 @@ module CyberarmEngine
111
114
 
112
115
  case child
113
116
  when Container
114
- if element = child.hit_element?(child_x, child_y)
117
+ if (element = child.hit_element?(child_x, child_y))
115
118
  return element
116
119
  end
117
120
  else
@@ -221,7 +224,7 @@ module CyberarmEngine
221
224
 
222
225
  update_child_element_visibity(child)
223
226
  end
224
- # puts "TOOK: #{Gosu.milliseconds - t}ms to recalculate #{self.class}:0x#{self.object_id.to_s(16)}'s #{@children.count} children"
227
+ # puts "TOOK: #{Gosu.milliseconds - t}ms to recalculate #{self.class}:0x#{object_id.to_s(16)}'s #{@children.count} children" if is_root?
225
228
 
226
229
  update_background
227
230
 
@@ -299,15 +302,15 @@ module CyberarmEngine
299
302
  return unless @style.scroll
300
303
 
301
304
  # Allow overscrolling UP, only if one can scroll DOWN
302
- if height < scroll_height
303
- if @scroll_target_position.y > 0
304
- @scroll_target_position.y = @scroll_chunk
305
- else
306
- @scroll_target_position.y += @scroll_chunk
307
- end
305
+ return unless height < scroll_height
308
306
 
309
- return :handled
307
+ if @scroll_target_position.y.positive?
308
+ @scroll_target_position.y = @scroll_chunk
309
+ else
310
+ @scroll_target_position.y += @scroll_chunk
310
311
  end
312
+
313
+ :handled
311
314
  end
312
315
 
313
316
  def mouse_wheel_down(sender, x, y)
@@ -315,13 +318,13 @@ module CyberarmEngine
315
318
 
316
319
  return unless height < scroll_height
317
320
 
318
- if @scroll_target_position.y > 0
321
+ if @scroll_target_position.y.positive?
319
322
  @scroll_target_position.y = -@scroll_chunk
320
323
  else
321
324
  @scroll_target_position.y -= @scroll_chunk
322
325
  end
323
326
 
324
- return :handled
327
+ :handled
325
328
  end
326
329
 
327
330
  def scroll_jump_to_top(sender, x, y)
@@ -330,7 +333,7 @@ module CyberarmEngine
330
333
  @scroll_position.y = 0
331
334
  @scroll_target_position.y = 0
332
335
 
333
- return :handled
336
+ :handled
334
337
  end
335
338
 
336
339
  def scroll_jump_to_end(sender, x, y)
@@ -339,7 +342,7 @@ module CyberarmEngine
339
342
  @scroll_position.y = -max_scroll_height
340
343
  @scroll_target_position.y = -max_scroll_height
341
344
 
342
- return :handled
345
+ :handled
343
346
  end
344
347
 
345
348
  def scroll_page_up(sender, x, y)
@@ -349,7 +352,7 @@ module CyberarmEngine
349
352
  @scroll_position.y = 0 if @scroll_position.y > 0
350
353
  @scroll_target_position.y = @scroll_position.y
351
354
 
352
- return :handled
355
+ :handled
353
356
  end
354
357
 
355
358
  def scroll_page_down(sender, x, y)
@@ -359,7 +362,7 @@ module CyberarmEngine
359
362
  @scroll_position.y = -max_scroll_height if @scroll_position.y < -max_scroll_height
360
363
  @scroll_target_position.y = @scroll_position.y
361
364
 
362
- return :handled
365
+ :handled
363
366
  end
364
367
 
365
368
  def scroll_top
@@ -16,6 +16,8 @@ module CyberarmEngine
16
16
  )
17
17
 
18
18
  @raw_text = text
19
+ @text_width = @text.width
20
+ @text_height = @text.height
19
21
  end
20
22
 
21
23
  def update
@@ -29,7 +31,7 @@ module CyberarmEngine
29
31
 
30
32
  def render
31
33
  # Gosu.clip_to is too expensive to always use so check if we actually need it.
32
- if @text.width > width || @text.height > height
34
+ if @text_width > width || @text_height > height
33
35
  Gosu.clip_to(@x, @y, width, height) do
34
36
  @text.draw
35
37
  end
@@ -53,8 +55,12 @@ module CyberarmEngine
53
55
 
54
56
  handle_text_wrapping(_width)
55
57
 
56
- @width = _width || @text.width.floor
57
- @height = _height || @text.height.floor
58
+ # Update cached text width and height
59
+ @text_width = @text.width
60
+ @text_height = @text.height
61
+
62
+ @width = _width || @text_width.floor
63
+ @height = _height || @text_height.floor
58
64
 
59
65
  @text.y = @style.border_thickness_top + @style.padding_top + @y
60
66
  @text.z = @z + 3
@@ -64,26 +70,26 @@ module CyberarmEngine
64
70
  when :left
65
71
  @text.x = @style.border_thickness_left + @style.padding_left + @x
66
72
  when :center
67
- @text.x = if @text.width <= width
68
- @x + width / 2 - @text.width / 2
73
+ @text.x = if @text_width <= width
74
+ @x + width / 2 - @text_width / 2
69
75
  else # Act as left aligned
70
76
  @style.border_thickness_left + @style.padding_left + @x
71
77
  end
72
78
  when :right
73
- @text.x = @x + outer_width - (@text.width + @style.border_thickness_right + @style.padding_right)
79
+ @text.x = @x + outer_width - (@text_width + @style.border_thickness_right + @style.padding_right)
74
80
  end
75
81
  end
76
82
 
77
83
  if (vertical_alignment = @options[:text_v_align])
78
84
  case vertical_alignment
79
85
  when :center
80
- @text.y = if @text.height <= height
81
- @y + height / 2 - @text.height / 2
86
+ @text.y = if @text_height <= height
87
+ @y + height / 2 - @text_height / 2
82
88
  else
83
89
  @style.border_thickness_top + @style.padding_top + @y
84
90
  end
85
91
  when :bottom
86
- @text.y = @y + outer_height - (@text.height + @style.border_thickness_bottom + @style.padding_bottom)
92
+ @text.y = @y + outer_height - (@text_height + @style.border_thickness_bottom + @style.padding_bottom)
87
93
  end
88
94
  end
89
95
 
@@ -54,24 +54,29 @@ module CyberarmEngine
54
54
  end
55
55
 
56
56
  def draw
57
+ # t = Gosu.milliseconds
58
+ # report_recalculate_time = @pending_recalculate_request || @pending_element_recalculate_requests.size.positive?
59
+
60
+ StackProf.start(mode: :wall) if RUBY_ENGINE != "mruby" && defined?(StackProf)
57
61
  Stats.frame.start_timing(:gui_element_recalculate_requests)
58
62
 
59
63
  # puts "PENDING REQUESTS: #{@pending_element_recalculate_requests.size}" if @pending_element_recalculate_requests.size.positive?
60
- @pending_element_recalculate_requests.each(&:recalculate)
61
- @pending_element_recalculate_requests.clear
64
+ @pending_element_recalculate_requests.shift(&:recalculate)
62
65
 
63
66
  Stats.frame.end_timing(:gui_element_recalculate_requests)
64
67
 
65
- if @pending_recalculate_request
66
- Stats.frame.start_timing(:gui_recalculate)
67
-
68
- @root_container.recalculate
68
+ Stats.frame.start_timing(:gui_recalculate)
69
69
 
70
+ while(@pending_recalculate_request)
70
71
  @pending_recalculate_request = false
71
72
 
72
- Stats.frame.end_timing(:gui_recalculate)
73
+ @root_container.recalculate
73
74
  end
74
75
 
76
+ StackProf.stop if RUBY_ENGINE != "mruby" && defined?(StackProf)
77
+ Stats.frame.end_timing(:gui_recalculate)
78
+ # puts "TOOK: #{Gosu.milliseconds - t}ms to recalculate #{self.class}:0x#{object_id.to_s(16)}" if report_recalculate_time && Gosu.milliseconds - t > 0
79
+
75
80
  super
76
81
 
77
82
  if @menu
@@ -19,6 +19,30 @@ module CyberarmEngine
19
19
  class Style
20
20
  attr_reader :hash
21
21
 
22
+ %i[
23
+ x y z width height min_width min_height max_width max_height color background
24
+ background_image background_image_mode background_image_color
25
+ background_nine_slice background_nine_slice_mode background_nine_slice_color background_nine_slice_from_edge
26
+ background_nine_slice_left background_nine_slice_top background_nine_slice_right background_nine_slice_bottom
27
+ border_color border_color_left border_color_right border_color_top border_color_bottom
28
+ border_thickness border_thickness_left border_thickness_right border_thickness_top border_thickness_bottom
29
+ padding padding_left padding_right padding_top padding_bottom
30
+ margin margin_left margin_right margin_top margin_bottom
31
+ background_canvas background_nine_slice_canvas background_image_canvas border_canvas
32
+
33
+ fraction_background scroll fill text_wrap v_align h_align delay tag
34
+ image_width image_height
35
+
36
+ default hover active disabled
37
+ ].each do |item|
38
+ define_method(item) do
39
+ @hash[item]
40
+ end
41
+ define_method(:"#{item}=") do |value|
42
+ @hash[item] = value
43
+ end
44
+ end
45
+
22
46
  def initialize(hash = {})
23
47
  h = hash
24
48
  # h = Marshal.load(Marshal.dump(hash))
@@ -33,18 +57,5 @@ module CyberarmEngine
33
57
 
34
58
  @hash = h
35
59
  end
36
-
37
- def method_missing(method, *args)
38
- if method.to_s.end_with?("=")
39
- raise "Did not expect more than 1 argument" if args.size > 1
40
-
41
- @hash[method.to_s.sub("=", "").to_sym] = args.first
42
-
43
- elsif args.empty?
44
- @hash[method]
45
- else
46
- raise ArgumentError, "Did not expect arguments"
47
- end
48
- end
49
60
  end
50
61
  end
@@ -1,4 +1,4 @@
1
1
  module CyberarmEngine
2
2
  NAME = "InDev".freeze
3
- VERSION = "0.24.5".freeze
3
+ VERSION = "0.25.1".freeze
4
4
  end
@@ -9,6 +9,7 @@ require "json"
9
9
 
10
10
  require_relative "cyberarm_engine/version"
11
11
  require_relative "cyberarm_engine/stats"
12
+ require_relative "cyberarm_engine/result"
12
13
 
13
14
  require_relative "cyberarm_engine/common"
14
15
 
@@ -68,3 +69,9 @@ require_relative "cyberarm_engine/game_state"
68
69
  require_relative "cyberarm_engine/ui/gui_state"
69
70
 
70
71
  require_relative "cyberarm_engine/builtin/intro_state"
72
+
73
+ if RUBY_ENGINE != "mruby" && defined?(StackProf)
74
+ at_exit do
75
+ StackProf.results("./_stackprof.dmp")
76
+ end
77
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cyberarm_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.24.5
4
+ version: 0.25.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyberarm
@@ -131,6 +131,7 @@ files:
131
131
  - lib/cyberarm_engine/opengl/shader.rb
132
132
  - lib/cyberarm_engine/opengl/texture.rb
133
133
  - lib/cyberarm_engine/ray.rb
134
+ - lib/cyberarm_engine/result.rb
134
135
  - lib/cyberarm_engine/stats.rb
135
136
  - lib/cyberarm_engine/text.rb
136
137
  - lib/cyberarm_engine/timer.rb