Fix loop to be more accuratly timed, and added custom ruby libs inclusion setup

This commit is contained in:
2026-05-20 17:30:38 +01:00
parent 1a337608f3
commit 7d48b226ab
11 changed files with 1117 additions and 27 deletions
+20 -9
View File
@@ -22,6 +22,7 @@ rect.on_click do
rect.color = rect.color == 0xFF0000 ?
0x00FF00 :
0xFF0000
main_scene << text unless main_scene.elements.include?(text)
text.params[:name] = text.params[:name] == "Me" ?
"You" :
"Me"
@@ -30,35 +31,45 @@ end
App.map_key :mouse_left, :press
start = Time.now
c_ = 0.0
c_c = 0
main_scene.on_update do |delta_time|
# puts "Delta time: #{delta_time}ms"
c_ += delta_time
c_c += 1
# puts "Delta time: #{delta_time}s"
# commented out to avoid spamming the console, but you can uncomment to see the delta time being printed every frame
# runs at 60fps, so you should see around 16-17ms being printed
el = main_scene.elements_at(App.mouse_position)
puts App.text_input if App.text_input != ""
pp App.text_input if App.text_input != ""
next unless App.pressed?(:press)
puts "#{App.pressed?(:press)}, #{App.down?(:press)}, #{App.released?(:press)}"
pp "#{App.pressed?(:press)}, #{App.down?(:press)}, #{App.released?(:press)}"
for elem in el
if elem == image_element
puts "Down over image element"
pp "Down over image element"
elsif elem == rect
puts "Down over rect element"
pp "Down over rect element"
elsif elem == text
puts "Down over text element"
pp "Down over text element"
end
end
end
main_scene << text
main_scene << rect
main_scene << image_element
# main_scene.delete(text) # Uncomment to test element deletion
main_scene.delete(text)
App.start main_scene
App.start main_scene
p "Average delta time: #{c_ / c_c}s"
p "Time since start (real): #{Time.now - start}s"
p "Time since start (from dt): #{c_}s"