vanilladocs
vanillapunch.com
API / misc/frameprobe

misc/frameprobe

처지는 기기 가리기. (vanilla.js misc/frameprobe.js 의 FrameProbe)

  • 처음 몇 초의 프레임 간격을 재어, 무거운 효과를 끄는 가벼운 길을 저절로 켤 때 쓴다.
  • 재기 시작하고 기다리는 초가 지난 뒤 재는 초 동안 매 프레임의 간격을 본다. (처음 몇 초는 모형과 그림을 받느라 끊긴다)
  • 목표 간격(최대 프레임의 한 칸, 무제한이면 60 프레임의 한 칸)의 처진 배를 넘긴 프레임이 처진 몫 이상이면 처지는 기기다.
  • 한 칸이 아니라 1.4 배로 보는 까닭: 90 Hz 화면은 최대 60 에서 엔진이 한 장 걸러 그려 늘 22 ms 간격이고, 그것은 기기가 처지는 것이 아니다.
  • 60 Hz 와 120 Hz 화면에서 한 장을 놓친 프레임(33 ms, 25 ms)은 처진 것으로 센다. 넷에 하나 꼴이면 48 fps 밑이다.
  • 처지는 기기로 정하면 다시 재지 않는다. 다 재기 전에 창이 가려지면 restart 로 처음부터 다시 잰다. 처지지 않았으면 무거운 장면에서 measure_again 으로 한 번 더 잴 수 있다.
  • 엔진을 들여오지 않는다. 프레임 간격과 최대 프레임은 부르는 쪽이 넘긴다.

Detects slow devices. (FrameProbe of vanilla.js misc/frameprobe.js)

  • Measures the frame intervals of the first few seconds, used to automatically turn on a light path that disables heavy effects.
  • After the wait seconds from the start of measuring have passed, looks at each frame's interval during the measure seconds. (the first few seconds stutter while models and images load)
  • If the share of frames exceeding the slow factor times the target interval (one tick of the maximum frame rate, or one tick of 60 frames if unlimited) is at least the slow share, it is a slow device.
  • Why 1.4 times instead of one tick: a 90 Hz screen at a maximum of 60 has the engine drawing every other frame, always 22 ms apart, and that is not the device being slow.
  • On 60 Hz and 120 Hz screens, frames that missed one refresh (33 ms, 25 ms) are counted as slow. One in four means below 48 fps.
  • Once decided as a slow device, it does not measure again. If the window is hidden before measuring is done, restart measures again from the beginning. If not slow, measure_again can measure once more in a heavy scene.
  • Does not import the engine. The caller passes the frame interval and the maximum frame rate.

FrameProbestruct traits Default

짝Counterpart: vanilla.js FrameProbe소스source

처지는 기기 가리기. (처음 몇 초의 프레임 간격으로 무거운 효과를 끌지 정한다)

  • 처음 기다리는 초 2, 재는 초 4, 처진 배 1.4, 처진 몫 0.25, 무제한일 때 목표 60 프레임.

Detects slow devices. (decides whether to turn off heavy effects from the frame intervals of the first few seconds)

  • Initial wait 2 seconds, measure 4 seconds, slow factor 1.4, slow share 0.25, target 60 frames when unlimited.
예제Example세 프레임에 하나씩 끊기는 기기는 처지는 기기로 정한다A device that stutters once every three frames is decided as slow
use vanilla::FrameProbe;

let mut frame_probe = FrameProbe::new();
let mut frame_index = 0;
let mut is_done = false;
while !is_done {
	let frame_seconds = if frame_index % 3 == 0 {
		1.0 / 20.0
	}
	else {
		1.0 / 60.0
	};
	is_done = frame_probe.measure_frame(frame_seconds, 60.0);
	frame_index += 1;
}
assert!(frame_probe.is_finished());
assert!(frame_probe.is_slow());
assert!(frame_probe.read_slow_frame_share() >= 0.25);
예제Example씬에서 다 잰 프레임에 한 번 가벼운 길을 켜기Turn on the light path once in the scene on the frame measuring finishes
use vanilla::{Engine, FrameProbe};

fn tick_frame_probe(frame_probe: &mut FrameProbe, engine: &Engine, is_light_mode: &mut bool) {
	let frame_seconds = engine.get_time_manager().get_unscale_delta_time();
	let maximum_frame_per_second = engine.get_maximum_frame_per_second();
	if frame_probe.measure_frame(frame_seconds, maximum_frame_per_second) && frame_probe.is_slow() {
		*is_light_mode = true;
	}
}
생성자constructorpub fn new() -> FrameProbe#0.4.0 부터since 0.4.0소스source

생성.

Constructor.

반환ReturnsFrameProbe 아직 재지 않은 새 재기. (기다리는 초 2, 재는 초 4, 처진 배 1.4, 처진 몫 0.25, 무제한 목표 60)A new probe that has not measured yet. (wait 2 seconds, measure 4 seconds, slow factor 1.4, slow share 0.25, unlimited target 60)

짝Counterpart: vanilla.js FrameProbe.constructor

메서드methodpub fn measure_frame(&mut self, frame_seconds: f64, maximum_frame_per_second: f64) -> bool#0.4.0 부터since 0.4.0소스source

한 프레임 재기. (다 재는 프레임에 true 를 돌려준다)

  • 흐른 시간이 기다리는 초 이하인 프레임은 세지 않는다. 처진 간격은 처진 배 / 목표 프레임(초)이고, 그보다 긴 프레임을 처진 것으로 센다.

Measures one frame. (returns true on the frame measuring finishes)

  • Frames whose elapsed time is within the wait seconds are not counted. The slow interval is slow factor / target frame rate (seconds), and frames longer than that are counted as slow.
frame_secondsf64
지난 프레임부터 흐른 시간. (초, 0 이하이거나 NaN 이면 무시)Time elapsed since the last frame. (seconds, ignored if 0 or less or NaN)
maximum_frame_per_secondf64
엔진의 최대 프레임. (0 이하면 무제한으로 보고 set_unlimited_target_frame_per_second 의 목표를 쓴다)The engine's maximum frame rate. (0 or less is treated as unlimited and the target from set_unlimited_target_frame_per_second is used)

반환Returnsbool 이 프레임으로 재기가 끝났으면 true. 아직이거나 이미 끝났으면 false.true if measuring finished with this frame. false if not yet or already finished.

짝Counterpart: vanilla.js FrameProbe.measureFrame

예제Example고른 60 프레임은 처지지 않는다A steady 60 frames is not slow
use vanilla::FrameProbe;

let mut frame_probe = FrameProbe::new();
frame_probe.set_seconds(0.5, 1.0);
let mut frame_count = 0;
while !frame_probe.measure_frame(1.0 / 60.0, 60.0) {
	frame_count += 1;
}
assert!(frame_count >= 89);
assert!(!frame_probe.is_slow());
assert!(!frame_probe.measure_frame(1.0 / 60.0, 60.0));
메서드methodpub fn restart(&mut self)#0.4.0 부터since 0.4.0소스source

처음부터 다시 재기. (다 재기 전에 창이 가려졌을 때, 다 잰 뒤면 그대로 둔다)

Measures again from the start. (when the window was hidden before measuring finished, left as is if already finished)

짝Counterpart: vanilla.js FrameProbe.restart

메서드methodpub fn measure_again(&mut self)#0.4.0 부터since 0.4.0소스source

다 잰 재기를 한 번 더 열기. (처지지 않았을 때만, 기다리는 초부터 처음처럼)

Reopens a finished probe for one more measurement. (only if not slow, from the wait seconds as at the start)

짝Counterpart: vanilla.js FrameProbe.measureAgain

메서드methodpub fn is_finished(&self) -> bool#0.4.0 부터since 0.4.0소스source

다 쟀는지 반환.

Returns whether measuring is finished.

반환Returnsbool 재기가 끝났으면 true. (measure_again 으로 다시 열면 false)true if measuring has finished. (false after reopening with measure_again)

짝Counterpart: vanilla.js FrameProbe.isFinished

메서드methodpub fn is_slow(&self) -> bool#0.4.0 부터since 0.4.0소스source

처지는 기기인지 반환. (다 재기 전에는 false)

Returns whether it is a slow device. (false before measuring finishes)

반환Returnsbool 다 잰 결과 처진 프레임 몫이 처진 몫 이상이었으면 true.true if the measured share of slow frames was at least the slow share.

짝Counterpart: vanilla.js FrameProbe.isSlow

메서드methodpub fn read_slow_frame_share(&self) -> f64#0.4.0 부터since 0.4.0소스source

지금까지의 처진 프레임 몫 반환. (잰 프레임이 없으면 0)

Returns the slow frame fraction so far. (0 if no frames were measured)

반환Returnsf64 처진 프레임 수 / 잰 프레임 수. (0 ~ 1)Slow frame count / measured frame count. (0 ~ 1)

짝Counterpart: vanilla.js FrameProbe.readSlowFrameShare

메서드methodpub fn set_seconds(&mut self, warmup_seconds: f64, probe_seconds: f64)#0.4.0 부터since 0.4.0소스source

기다리는 초와 재는 초 설정. (재기 전에 정한다)

Sets the wait seconds and measure seconds. (set before measuring)

warmup_secondsf64
재기 전에 기다리는 시간. (초, 0 보다 작으면 0, 처음 2)Time to wait before measuring. (seconds, 0 if less than 0, initially 2)
probe_secondsf64
기다린 뒤 재는 시간. (초, 0 보다 작으면 0, 처음 4)Time to measure after waiting. (seconds, 0 if less than 0, initially 4)

짝Counterpart: vanilla.js FrameProbe.setSeconds

메서드methodpub fn get_warmup_seconds(&self) -> f64#0.4.0 부터since 0.4.0소스source

기다리는 초 반환.

Returns the wait seconds.

반환Returnsf64 재기 전에 기다리는 시간. (초)Time to wait before measuring. (seconds)

짝Counterpart: vanilla.js FrameProbe.getWarmupSeconds

메서드methodpub fn get_probe_seconds(&self) -> f64#0.4.0 부터since 0.4.0소스source

재는 초 반환.

Returns the measure seconds.

반환Returnsf64 기다린 뒤 재는 시간. (초)Time to measure after waiting. (seconds)

짝Counterpart: vanilla.js FrameProbe.getProbeSeconds

메서드methodpub fn set_slow_frame_threshold(&mut self, slow_frame_ratio: f64, slow_frame_share: f64)#0.4.0 부터since 0.4.0소스source

처진 프레임의 판정 설정. (목표 간격의 배, 처지는 기기로 볼 몫)

Sets the slow frame criteria. (multiple of the target interval, fraction to count as a slow device)

slow_frame_ratiof64
목표 간격의 몇 배보다 길면 처진 프레임으로 셀지. (처음 1.4)How many times the target interval a frame must exceed to count as slow. (initially 1.4)
slow_frame_sharef64
처진 프레임이 잰 프레임의 이 몫 이상이면 처지는 기기다. (0 ~ 1, 처음 0.25)If slow frames are at least this share of measured frames, it is a slow device. (0 ~ 1, initially 0.25)

짝Counterpart: vanilla.js FrameProbe.setSlowFrameThreshold

메서드methodpub fn get_slow_frame_ratio(&self) -> f64#0.4.0 부터since 0.4.0소스source

처진 프레임으로 셀 간격의 배 반환.

Returns the interval multiple counted as a slow frame.

반환Returnsf64 목표 간격에 곱하는 배. (처음 1.4)Factor multiplied by the target interval. (initially 1.4)

짝Counterpart: vanilla.js FrameProbe.getSlowFrameRatio

메서드methodpub fn get_slow_frame_share(&self) -> f64#0.4.0 부터since 0.4.0소스source

처지는 기기로 볼 처진 프레임의 몫 반환.

Returns the fraction of slow frames to count as a slow device.

반환Returnsf64 처진 몫. (0 ~ 1, 처음 0.25)Slow share. (0 ~ 1, initially 0.25)

짝Counterpart: vanilla.js FrameProbe.getSlowFrameShare

메서드methodpub fn set_unlimited_target_frame_per_second(&mut self, unlimited_target_frame_per_second: f64)#0.4.0 부터since 0.4.0소스source

최대 프레임이 무제한일 때의 목표 설정.

Sets the target when the max frame rate is unlimited.

unlimited_target_frame_per_secondf64
measure_frame 에 0 이하의 최대 프레임이 오면 쓸 목표 프레임. (초당 프레임, 처음 60)Target frame rate used when measure_frame gets a maximum frame rate of 0 or less. (frames per second, initially 60)

짝Counterpart: vanilla.js FrameProbe.setUnlimitedTargetFramePerSecond

메서드methodpub fn get_unlimited_target_frame_per_second(&self) -> f64#0.4.0 부터since 0.4.0소스source

최대 프레임이 무제한일 때의 목표 반환.

Returns the target when the max frame rate is unlimited.

반환Returnsf64 목표 프레임. (초당 프레임)Target frame rate. (frames per second)

짝Counterpart: vanilla.js FrameProbe.getUnlimitedTargetFramePerSecond