mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2026-03-22 12:06:13 +00:00
Compare commits
11 Commits
0fac4a0397
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 250e51ef0c | |||
| 3102bbe4c3 | |||
| 530e01d939 | |||
| 752a4752ba | |||
| e4a4f779b0 | |||
| 958d4e65f9 | |||
| 0519253e03 | |||
| 97055885a6 | |||
| b5912de980 | |||
| b0376d85d9 | |||
| a30d66fafb |
@@ -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
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ module CyberarmEngine
|
|||||||
include Common
|
include Common
|
||||||
|
|
||||||
attr_accessor :options, :global_pause
|
attr_accessor :options, :global_pause
|
||||||
attr_reader :game_objects
|
attr_reader :game_objects, :timers
|
||||||
|
|
||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
@options = options
|
@options = options
|
||||||
@game_objects = []
|
@game_objects = []
|
||||||
|
@timers = []
|
||||||
@global_pause = false
|
@global_pause = false
|
||||||
window.text_input = nil unless options[:preserve_text_input]
|
window.text_input = nil unless options[:preserve_text_input]
|
||||||
|
|
||||||
@@ -28,6 +29,8 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def update
|
def update
|
||||||
@game_objects.each(&:update)
|
@game_objects.each(&:update)
|
||||||
|
@timers.each(&:update)
|
||||||
|
@timers.delete_if(&:dead?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def needs_redraw?
|
def needs_redraw?
|
||||||
@@ -120,5 +123,9 @@ module CyberarmEngine
|
|||||||
def add_game_object(object)
|
def add_game_object(object)
|
||||||
@game_objects << object
|
@game_objects << object
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_timer(timer)
|
||||||
|
@timers << timer
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
20
lib/cyberarm_engine/result.rb
Normal file
20
lib/cyberarm_engine/result.rb
Normal 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
|
||||||
|
|
||||||
@@ -19,5 +19,9 @@ module CyberarmEngine
|
|||||||
@block.call if @block
|
@block.call if @block
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dead?
|
||||||
|
@triggered && !@looping
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
module CyberarmEngine
|
module CyberarmEngine
|
||||||
module DSL
|
module DSL
|
||||||
|
def every(milliseconds, &block)
|
||||||
|
element_parent.gui_state.add_timer(
|
||||||
|
CyberarmEngine::Timer.new(milliseconds, true, &block)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def after(milliseconds, &block)
|
||||||
|
element_parent.gui_state.add_timer(
|
||||||
|
CyberarmEngine::Timer.new(milliseconds, false, &block)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def flow(options = {}, &block)
|
def flow(options = {}, &block)
|
||||||
container(CyberarmEngine::Element::Flow, options, &block)
|
container(CyberarmEngine::Element::Flow, options, &block)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,19 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def caret_position_under_mouse(mouse_x, mouse_y)
|
def caret_position_under_mouse(mouse_x, mouse_y)
|
||||||
active_line = row_at(mouse_y)
|
# get y scroll offset of element to get EditBox's selected row
|
||||||
|
y_scroll_offset = 0
|
||||||
|
e = parent
|
||||||
|
while (e)
|
||||||
|
if e.is_a?(Container)
|
||||||
|
y_scroll_offset += e.scroll_position.y
|
||||||
|
|
||||||
|
# root element has no parent so loop will terminate
|
||||||
|
e = e.parent
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
active_line = row_at(mouse_y - y_scroll_offset)
|
||||||
right_offset = column_at(mouse_x, mouse_y)
|
right_offset = column_at(mouse_x, mouse_y)
|
||||||
|
|
||||||
buffer = @text_input.text.lines[0..active_line].join if active_line != 0
|
buffer = @text_input.text.lines[0..active_line].join if active_line != 0
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ module CyberarmEngine
|
|||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
@options = options
|
@options = options
|
||||||
@game_objects = []
|
@game_objects = []
|
||||||
|
@timers = []
|
||||||
@global_pause = false
|
@global_pause = false
|
||||||
|
|
||||||
@down_keys = {}
|
@down_keys = {}
|
||||||
@@ -54,27 +55,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)
|
while(@pending_recalculate_request)
|
||||||
@root_container.recalculate
|
|
||||||
StackProf.stop if RUBY_ENGINE != "mruby" && defined?(StackProf)
|
|
||||||
|
|
||||||
@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
|
||||||
@@ -269,10 +272,14 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def redirect_scroll_jump_to(edge)
|
def redirect_scroll_jump_to(edge)
|
||||||
|
return if window.text_input
|
||||||
|
|
||||||
@mouse_over.publish(:"scroll_jump_to_#{edge}", window.mouse_x, window.mouse_y) if (@mouse_over && !@menu) || (@mouse_over && @mouse_over == @menu)
|
@mouse_over.publish(:"scroll_jump_to_#{edge}", window.mouse_x, window.mouse_y) if (@mouse_over && !@menu) || (@mouse_over && @mouse_over == @menu)
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirect_scroll_page(edge)
|
def redirect_scroll_page(edge)
|
||||||
|
return if window.text_input
|
||||||
|
|
||||||
@mouse_over.publish(:"scroll_page_#{edge}", window.mouse_x, window.mouse_y) if (@mouse_over && !@menu) || (@mouse_over && @mouse_over == @menu)
|
@mouse_over.publish(:"scroll_page_#{edge}", window.mouse_x, window.mouse_y) if (@mouse_over && !@menu) || (@mouse_over && @mouse_over == @menu)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user