129 lines
2.6 KiB
Ruby
129 lines
2.6 KiB
Ruby
App.run 720, 480, "Stress Test", fps: 60
|
|
|
|
scene = Scene.new
|
|
|
|
font = Font.new "assets/fonts/charybdis.ttf", 24, pixel_art: true
|
|
|
|
# primary factor in slowing teh system down is number of gpu textures
|
|
# i.e if we increase images or unique texts, we will see a significant drop in fps,
|
|
# but if we just increase number of elements with same image, the engine should be able to handle it much better
|
|
|
|
# --- Generate images ---
|
|
images = []
|
|
1.times do |i|
|
|
images << Image.new("assets/images/menu_bg.png", pixel_art: true)
|
|
end
|
|
|
|
# --- Animation pool stress ---
|
|
animations = []
|
|
1.times do |i|
|
|
anim = Animation.new(images.sample(5), fps: 5 + (i % 30))
|
|
animations << anim
|
|
end
|
|
|
|
# --- Massive element pool ---
|
|
elements = []
|
|
|
|
App.language = :en
|
|
|
|
App.localize(:en, :btn_text, "Stress Test %{count}")
|
|
|
|
App.localize(:en, :text, "Random Text")
|
|
|
|
1000.times do |i|
|
|
elements << ElementText.new(
|
|
:text,
|
|
font,
|
|
rand(0xFFFFFF),
|
|
{},
|
|
position: { x: rand(0..700), y: rand(0..450) },
|
|
z: rand(-10..10),
|
|
click_mode: :pass,
|
|
alpha: rand
|
|
)
|
|
end
|
|
|
|
1000.times do |i|
|
|
elements << ElementImage.new(
|
|
animations.sample,
|
|
position: { x: rand(0..700), y: rand(0..450) },
|
|
z: rand(-10..10),
|
|
alpha: rand,
|
|
scale: { x: rand * 2, y: rand * 2 },
|
|
click_mode: :pass
|
|
)
|
|
end
|
|
|
|
1000.times do |i|
|
|
elements << ElementRect.new(
|
|
20 + rand(100),
|
|
20 + rand(100),
|
|
rand(0xFFFFFF),
|
|
position: { x: rand(0..700), y: rand(0..450) },
|
|
z: rand(-10..10),
|
|
rotation: rand(360),
|
|
alpha: rand,
|
|
click_mode: :pass
|
|
)
|
|
end
|
|
|
|
text = ElementText.new(
|
|
:btn_text,
|
|
font,
|
|
0xFF0000,
|
|
{ count: 0 },
|
|
position: { x: 20, y: 20 },
|
|
z: 100,
|
|
click_mode: :block
|
|
)
|
|
|
|
scene << text
|
|
elements.each { |e| scene << e }
|
|
|
|
# --- FPS thrashing test ---
|
|
fps_values = [30, 60, 120, 240]
|
|
|
|
i = 0
|
|
click_counter = 0
|
|
|
|
text.click do
|
|
click_counter += 1
|
|
text.params[:count] = click_counter
|
|
end
|
|
|
|
start_time ||= Time.now
|
|
frame_count ||= 0
|
|
accum_dt ||= 0.0
|
|
last_log ||= 0.0
|
|
|
|
App.update do |dt|
|
|
frame_count += 1
|
|
accum_dt += dt
|
|
|
|
now = Time.now
|
|
elapsed = now - start_time
|
|
|
|
# log every second
|
|
if elapsed - last_log >= 1.0
|
|
dt_fps = frame_count / accum_dt
|
|
real_fps = frame_count / elapsed
|
|
|
|
puts "---- FPS REPORT ----"
|
|
puts "Engine FPS (dt): #{dt_fps.round(2)}"
|
|
puts "Real FPS (wall): #{real_fps.round(2)}"
|
|
puts "Avg dt: #{(accum_dt / frame_count * 1000).round(3)} ms"
|
|
puts "Frame count: #{frame_count}"
|
|
puts "--------------------"
|
|
|
|
last_log = elapsed
|
|
end
|
|
|
|
i += 1
|
|
|
|
# --- Input spam check ---
|
|
if App.pressed?(:mouse_left)
|
|
puts "Mouse pressed at #{App.mouse_position}"
|
|
end
|
|
end
|
|
|
|
App.start scene |