vanilladocs
vanillapunch.com
API / misc/frameprobe

misc/frameprobe

처지는 기기 가리기. (처음 몇 초의 프레임 간격을 재어, 무거운 효과를 끄는 가벼운 길을 저절로 켤 때 쓴다)

Detects slow devices. (measures frame intervals for the first few seconds, used to automatically turn on a lightweight path that disables heavy effects)

FrameProbe

짝Counterpart: vanilla-engine FrameProbe

처지는 기기 가리기. (처음 몇 초의 프레임 간격을 재어, 무거운 효과를 끄는 가벼운 길을 저절로 켤 때 쓴다)

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

Detects slow devices. (measures frame intervals for the first few seconds, used to automatically turn on a lightweight path that disables heavy effects)

  • After measuring starts and the wait seconds pass, looks at each frame's interval during the measure seconds. (the first few seconds stutter while models and images load)
  • If frames exceeding the slow multiple of the target interval (one frame at the max frame rate, or one frame at 60 if unlimited) make up at least the slow fraction, it is a slow device.
  • Why 1.4 times rather than one frame: a 90 Hz screen with max 60 has the engine draw every other refresh, so the interval is always 22 ms, and that is not the device being slow.
  • On 60 Hz and 120 Hz screens, a frame that missed one refresh (33 ms, 25 ms) counts as slow. One in four means below 48 fps.
  • Once judged a slow device, it does not measure again. If the window is hidden before measuring finishes, restart() measures again from the start. If not slow, measureAgain() can measure once more in a heavy scene.
  • Does not import the engine or the browser. The caller passes the frame interval and max frame rate.
예제Example프레임 간격을 넘겨 처지는 기기 가리기Detect a slow device by feeding frame intervals
import { FrameProbe } from "./build/vanilla.js";

const frameProbe = new FrameProbe();
frameProbe.setSeconds(0.5, 1);
let isFinished = false;
for (let frame = 0; frame < 120 && !isFinished; ++frame) {
	const frameSeconds = frame % 3 === 0 ? 1 / 30 : 1 / 60;
	isFinished = frameProbe.measureFrame(frameSeconds, 60);
}
console.log(frameProbe.isFinished(), frameProbe.isSlow(), frameProbe.readSlowFrameShare());
생성자constructorconstructor()#0.4.0 부터since 0.4.0소스source

생성.

Constructor.

짝Counterpart: vanilla-engine FrameProbe.new

메서드methodmeasureFrame(frameSeconds, maximumFramePerSecond)#0.4.0 부터since 0.4.0소스source

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

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

frameSecondsnumber
지난 프레임과의 간격. (초)Interval since the last frame. (seconds)
maximumFramePerSecondnumber
최대 프레임. (0 이면 무제한)Max frame rate. (0 means unlimited)

반환Returnsboolean 이 프레임에서 다 쟀으면 참. (다 쟀거나 간격이 0 이하이면 거짓)True if measuring finished on this frame. (false if already finished or the interval is 0 or less)

짝Counterpart: vanilla-engine FrameProbe.measure_frame

메서드methodrestart()#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-engine FrameProbe.restart

메서드methodmeasureAgain()#0.4.0 부터since 0.4.0소스source

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

  • 켤 때의 가벼운 장면 뒤 무거운 장면에서 다시 잴 때 쓴다.

Reopens a finished measurement once more. (only when not slow, from the wait seconds as at first)

  • Used to measure again in a heavy scene after the light scene at startup.

짝Counterpart: vanilla-engine FrameProbe.measure_again

메서드methodisFinished()#0.4.0 부터since 0.4.0소스source

다 쟀는지 반환.

Returns whether measuring is finished.

반환Returnsboolean 다 쟀으면 참.True if measuring has finished.

짝Counterpart: vanilla-engine FrameProbe.is_finished

메서드methodisSlow()#0.4.0 부터since 0.4.0소스source

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

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

반환Returnsboolean 처지는 기기로 정했으면 참.True if judged to be a slow device.

짝Counterpart: vanilla-engine FrameProbe.is_slow

메서드methodreadSlowFrameShare()#0.4.0 부터since 0.4.0소스source

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

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

반환Returnsnumber 처진 프레임 수를 잰 프레임 수로 나눈 몫. (0 ~ 1)Slow frame count divided by the measured frame count. (0 ~ 1)

짝Counterpart: vanilla-engine FrameProbe.read_slow_frame_share

메서드methodsetSeconds(warmupSeconds, probeSeconds)#0.4.0 부터since 0.4.0소스source

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

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

warmupSecondsnumber
재기 전에 기다리는 초. (음수면 0, 처음은 2)Seconds to wait before measuring. (0 if negative, 2 at first)
probeSecondsnumber
재는 초. (음수면 0, 처음은 4)Seconds to measure. (0 if negative, 4 at first)

짝Counterpart: vanilla-engine FrameProbe.set_seconds

메서드methodgetWarmupSeconds()#0.4.0 부터since 0.4.0소스source

기다리는 초 반환.

Returns the wait seconds.

반환Returnsnumber 재기 전에 기다리는 초.Seconds to wait before measuring.

짝Counterpart: vanilla-engine FrameProbe.get_warmup_seconds

메서드methodgetProbeSeconds()#0.4.0 부터since 0.4.0소스source

재는 초 반환.

Returns the measure seconds.

반환Returnsnumber 재는 초.Seconds to measure.

짝Counterpart: vanilla-engine FrameProbe.get_probe_seconds

메서드methodsetSlowFrameThreshold(slowFrameRatio, slowFrameShare)#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)

slowFrameRationumber
처진 프레임으로 셀 간격. (목표 간격의 배, 처음은 1.4)Interval counted as a slow frame. (a multiple of the target interval, 1.4 at first)
slowFrameSharenumber
처지는 기기로 볼 처진 프레임의 몫. (0 ~ 1, 처음은 0.25)Share of slow frames that marks a slow device. (0 ~ 1, 0.25 at first)

짝Counterpart: vanilla-engine FrameProbe.set_slow_frame_threshold

메서드methodgetSlowFrameRatio()#0.4.0 부터since 0.4.0소스source

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

Returns the interval multiple counted as a slow frame.

반환Returnsnumber 처진 프레임으로 셀 간격의 배.Multiple of the interval counted as a slow frame.

짝Counterpart: vanilla-engine FrameProbe.get_slow_frame_ratio

메서드methodgetSlowFrameShare()#0.4.0 부터since 0.4.0소스source

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

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

반환Returnsnumber 처지는 기기로 볼 처진 프레임의 몫.Share of slow frames that marks a slow device.

짝Counterpart: vanilla-engine FrameProbe.get_slow_frame_share

메서드methodsetUnlimitedTargetFramePerSecond(unlimitedTargetFramePerSecond)#0.4.0 부터since 0.4.0소스source

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

Sets the target when the max frame rate is unlimited.

unlimitedTargetFramePerSecondnumber
최대 프레임이 0(무제한)일 때 목표로 볼 초당 프레임. (처음은 60)Frames per second used as the target when the maximum frame rate is 0 (unlimited). (60 at first)

짝Counterpart: vanilla-engine FrameProbe.set_unlimited_target_frame_per_second

메서드methodgetUnlimitedTargetFramePerSecond()#0.4.0 부터since 0.4.0소스source

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

Returns the target when the max frame rate is unlimited.

반환Returnsnumber 최대 프레임이 무제한일 때의 목표 초당 프레임.Target frames per second when the maximum frame rate is unlimited.

짝Counterpart: vanilla-engine FrameProbe.get_unlimited_target_frame_per_second