Compare commits

...

8 Commits

8 changed files with 87 additions and 67 deletions

View File

@@ -9,6 +9,7 @@ require "json"
require_relative "cyberarm_engine/version" require_relative "cyberarm_engine/version"
require_relative "cyberarm_engine/stats" require_relative "cyberarm_engine/stats"
require_relative "cyberarm_engine/result"
require_relative "cyberarm_engine/common" require_relative "cyberarm_engine/common"
@@ -69,6 +70,8 @@ require_relative "cyberarm_engine/ui/gui_state"
require_relative "cyberarm_engine/builtin/intro_state" require_relative "cyberarm_engine/builtin/intro_state"
at_exit do if RUBY_ENGINE != "mruby" && defined?(StackProf)
StackProf.results("./_prof.txt") if RUBY_ENGINE != "mruby" && defined?(StackProf) at_exit do
StackProf.results("./_stackprof.dmp")
end
end end

View File

@@ -35,36 +35,14 @@ module CyberarmEngine
end end
def update def update
origin_x = (@x + (@width / 2)) @top_left.x = @x
origin_y = (@y + (@height / 2)) @top_left.y = @y
@top_right.x = @x + @width
points = [ @top_right.y = @y
@top_left = Vector.new(@x, @y), @bottom_left.x = @x
@top_right = Vector.new(@x + @width, @y), @bottom_left.y = @y + @height
@bottom_left = Vector.new(@x, @y + @height), @bottom_right.x = @x + @width
@bottom_right = Vector.new(@x + @width, @y + @height) @bottom_right.y = @y + @height
]
[@top_left, @top_right, @bottom_left, @bottom_right].each do |vector|
temp_x = vector.x - origin_x
temp_y = vector.y - origin_y
# 90 is up here, while gosu uses 0 for up.
radians = (@angle + 90).gosu_to_radians
vector.x = (@x + (@width / 2)) + ((temp_x * Math.cos(radians)) - (temp_y * Math.sin(radians)))
vector.y = (@y + (@height / 2)) + ((temp_x * Math.sin(radians)) + (temp_y * Math.cos(radians)))
end
# [
# [:top, @top_left, @top_right],
# [:right, @top_right, @bottom_right],
# [:bottom, @bottom_right, @bottom_left],
# [:left, @bottom_left, @top_left]
# ].each do |edge|
# points.each do |point|
# puts "#{edge.first} -> #{shortest_distance(point, edge[1], edge[2])}"
# end
# end
end end
def shortest_distance(point, la, lb) def shortest_distance(point, la, lb)

View File

@@ -0,0 +1,20 @@
module CyberarmEngine
# result pattern
class Result
attr_accessor :error, :data
def initialize(data: nil, error: nil)
@data = data
@error = error
end
def okay?
!@error
end
def error?
@error || @data.nil?
end
end
end

View File

@@ -210,7 +210,7 @@ module CyberarmEngine
end end
end end
t = Gosu.milliseconds # t = Gosu.milliseconds
# Move children to parent after positioning # Move children to parent after positioning
@children.each do |child| @children.each do |child|
child.x += (@x + @style.border_thickness_left) - style.margin_left child.x += (@x + @style.border_thickness_left) - style.margin_left
@@ -224,7 +224,7 @@ module CyberarmEngine
update_child_element_visibity(child) update_child_element_visibity(child)
end end
puts "TOOK: #{Gosu.milliseconds - t}ms to recalculate #{self.class}:0x#{object_id.to_s(16)}'s #{@children.count} children" if is_root? # puts "TOOK: #{Gosu.milliseconds - t}ms to recalculate #{self.class}:0x#{object_id.to_s(16)}'s #{@children.count} children" if is_root?
update_background update_background

View File

@@ -16,6 +16,8 @@ module CyberarmEngine
) )
@raw_text = text @raw_text = text
@text_width = @text.width
@text_height = @text.height
end end
def update def update
@@ -29,7 +31,7 @@ module CyberarmEngine
def render def render
# Gosu.clip_to is too expensive to always use so check if we actually need it. # Gosu.clip_to is too expensive to always use so check if we actually need it.
if @text.width > width || @text.height > height if @text_width > width || @text_height > height
Gosu.clip_to(@x, @y, width, height) do Gosu.clip_to(@x, @y, width, height) do
@text.draw @text.draw
end end
@@ -53,8 +55,12 @@ module CyberarmEngine
handle_text_wrapping(_width) handle_text_wrapping(_width)
@width = _width || @text.width.floor # Update cached text width and height
@height = _height || @text.height.floor @text_width = @text.width
@text_height = @text.height
@width = _width || @text_width.floor
@height = _height || @text_height.floor
@text.y = @style.border_thickness_top + @style.padding_top + @y @text.y = @style.border_thickness_top + @style.padding_top + @y
@text.z = @z + 3 @text.z = @z + 3
@@ -64,26 +70,26 @@ module CyberarmEngine
when :left when :left
@text.x = @style.border_thickness_left + @style.padding_left + @x @text.x = @style.border_thickness_left + @style.padding_left + @x
when :center when :center
@text.x = if @text.width <= width @text.x = if @text_width <= width
@x + width / 2 - @text.width / 2 @x + width / 2 - @text_width / 2
else # Act as left aligned else # Act as left aligned
@style.border_thickness_left + @style.padding_left + @x @style.border_thickness_left + @style.padding_left + @x
end end
when :right when :right
@text.x = @x + outer_width - (@text.width + @style.border_thickness_right + @style.padding_right) @text.x = @x + outer_width - (@text_width + @style.border_thickness_right + @style.padding_right)
end end
end end
if (vertical_alignment = @options[:text_v_align]) if (vertical_alignment = @options[:text_v_align])
case vertical_alignment case vertical_alignment
when :center when :center
@text.y = if @text.height <= height @text.y = if @text_height <= height
@y + height / 2 - @text.height / 2 @y + height / 2 - @text_height / 2
else else
@style.border_thickness_top + @style.padding_top + @y @style.border_thickness_top + @style.padding_top + @y
end end
when :bottom when :bottom
@text.y = @y + outer_height - (@text.height + @style.border_thickness_bottom + @style.padding_bottom) @text.y = @y + outer_height - (@text_height + @style.border_thickness_bottom + @style.padding_bottom)
end end
end end

View File

@@ -54,27 +54,29 @@ module CyberarmEngine
end end
def draw def draw
# t = Gosu.milliseconds
# report_recalculate_time = @pending_recalculate_request || @pending_element_recalculate_requests.size.positive?
StackProf.start(mode: :wall) if RUBY_ENGINE != "mruby" && defined?(StackProf)
Stats.frame.start_timing(:gui_element_recalculate_requests) Stats.frame.start_timing(:gui_element_recalculate_requests)
# puts "PENDING REQUESTS: #{@pending_element_recalculate_requests.size}" if @pending_element_recalculate_requests.size.positive? # puts "PENDING REQUESTS: #{@pending_element_recalculate_requests.size}" if @pending_element_recalculate_requests.size.positive?
@pending_recalculate_request = true if @pending_element_recalculate_requests.size.positive? @pending_element_recalculate_requests.shift(&:recalculate)
# @pending_element_recalculate_requests.each(&:recalculate)
@pending_element_recalculate_requests.clear
Stats.frame.end_timing(:gui_element_recalculate_requests) Stats.frame.end_timing(:gui_element_recalculate_requests)
if @pending_recalculate_request Stats.frame.start_timing(:gui_recalculate)
Stats.frame.start_timing(:gui_recalculate)
StackProf.start(mode: :wall) if RUBY_ENGINE != "mruby" && defined?(StackProf)
@root_container.recalculate
StackProf.stop if RUBY_ENGINE != "mruby" && defined?(StackProf)
while(@pending_recalculate_request)
@pending_recalculate_request = false @pending_recalculate_request = false
Stats.frame.end_timing(:gui_recalculate) @root_container.recalculate
end end
StackProf.stop if RUBY_ENGINE != "mruby" && defined?(StackProf)
Stats.frame.end_timing(:gui_recalculate)
# puts "TOOK: #{Gosu.milliseconds - t}ms to recalculate #{self.class}:0x#{object_id.to_s(16)}" if report_recalculate_time && Gosu.milliseconds - t > 0
super super
if @menu if @menu

View File

@@ -19,6 +19,30 @@ module CyberarmEngine
class Style class Style
attr_reader :hash attr_reader :hash
%i[
x y z width height min_width min_height max_width max_height color background
background_image background_image_mode background_image_color
background_nine_slice background_nine_slice_mode background_nine_slice_color background_nine_slice_from_edge
background_nine_slice_left background_nine_slice_top background_nine_slice_right background_nine_slice_bottom
border_color border_color_left border_color_right border_color_top border_color_bottom
border_thickness border_thickness_left border_thickness_right border_thickness_top border_thickness_bottom
padding padding_left padding_right padding_top padding_bottom
margin margin_left margin_right margin_top margin_bottom
background_canvas background_nine_slice_canvas background_image_canvas border_canvas
fraction_background scroll fill text_wrap v_align h_align delay tag
image_width image_height
default hover active disabled
].each do |item|
define_method(item) do
@hash[item]
end
define_method(:"#{item}=") do |value|
@hash[item] = value
end
end
def initialize(hash = {}) def initialize(hash = {})
h = hash h = hash
# h = Marshal.load(Marshal.dump(hash)) # h = Marshal.load(Marshal.dump(hash))
@@ -33,18 +57,5 @@ module CyberarmEngine
@hash = h @hash = h
end end
def method_missing(method, *args)
if method.to_s.end_with?("=")
raise "Did not expect more than 1 argument" if args.size > 1
@hash[method.to_s.sub("=", "").to_sym] = args.first
elsif args.empty?
@hash[method]
else
raise ArgumentError, "Did not expect arguments"
end
end
end end
end end

View File

@@ -1,4 +1,4 @@
module CyberarmEngine module CyberarmEngine
NAME = "InDev".freeze NAME = "InDev".freeze
VERSION = "0.24.5".freeze VERSION = "0.25.1".freeze
end end