vanilladocs
vanillapunch.com
API / misc/graphicsqualitygovernor

misc/graphicsqualitygovernor

그래픽 품질 정하기. (vanilla.js misc/graphicsqualitygovernor.js 의 GraphicsQualityGovernor)

  • 설정과 프레임 재기로 가벼운 길을 쓸지 정하고, 렌더 배율 상한을 고른다.
  • 가벼운 길(is_lite)을 정하는 차례: 덮어쓰기(주소의 ?light 같은 것) → 설정 낮음(늘 가벼움), 높음(늘 아님) → 자동. 자동이면 처음부터 가벼운 길(set_auto_lite_default, 손가락 기기 같은 것)이거나 FrameProbe 가 처지는 기기로 잰 때 가벼운 길이다.
  • 매 프레임 update(프레임 초, 최대 프레임) 를 부르면 자동일 때만 FrameProbe 로 잰다. 가벼운 길이 바뀐 프레임에 true 를 돌려준다.
  • 렌더 배율 상한: set_render_pixel_ratio_limits(보통, 가벼운 길) 로 주고 apply_render_pixel_ratio(view_manager) 가 바뀔 때만 건다. (0 이면 제한 없음)
  • 가벼운 길에서 무엇을 줄일지(그림자, 바깥선, 효과, 그리는 수)는 게임이 is_lite 를 읽어 정한다.
  • 주소: apply_search_text 는 쿼리 글("?light", "?a=1&light=0")을 받는다. 원본 URLSearchParams 처럼 읽는다. (앞의 ? 하나를 떼고 & 로 나누며 빈 조각은 건너뛰고, 처음 = 에서 이름과 값을 가르고, + 는 빈칸, %XX 는 바이트로 풀어 UTF-8 로 읽는다. 같은 이름이 여럿이면 첫 값) apply_page_query 는 웹에서 페이지 주소의 쿼리를 읽는다. 데스크탑은 페이지 주소가 없어 환경 변수 VANILLA_<이름>(대문자 뱀꼴, light → VANILLA_LIGHT)을 읽는다.

Graphics quality decision. (GraphicsQualityGovernor of vanilla.js misc/graphicsqualitygovernor.js)

  • Decides whether to use the lite path from settings and frame measurement, and picks the render pixel ratio limit.
  • Order of deciding the lite path (is_lite): override (like ?light in the address) → setting low (always lite), high (never) → auto. In auto, it is the lite path if lite from the start (set_auto_lite_default, such as touch devices) or when FrameProbe measured a slow device.
  • Calling update(frame seconds, max frames) every frame measures with FrameProbe only in auto. Returns true on the frame the lite path changed.
  • Render pixel ratio limit: give it with set_render_pixel_ratio_limits(normal, lite path), and apply_render_pixel_ratio(view_manager) applies it only when it changes. (0 means no limit)
  • What to reduce on the lite path (shadows, outlines, effects, draw counts) is decided by the game reading is_lite.
  • Address: apply_search_text takes query text ("?light", "?a=1&light=0"). Reads it like the original URLSearchParams. (strips one leading ?, splits by &, skips empty pieces, splits the name and value at the first =, + is a space, %XX is decoded as bytes and read as UTF-8. If the same name appears several times, the first value) apply_page_query reads the query of the page address on the web. Desktop has no page address, so it reads the environment variable VANILLA_<name> (upper snake case, light → VANILLA_LIGHT).

GraphicsQualityGovernorstruct traits Default

짝Counterpart: vanilla.js GraphicsQualityGovernor소스source

그래픽 품질 정하기.

  • 덮어쓰기, 품질 설정, 자동(프레임 재기) 차례로 가벼운 길인지 정하고, 길마다 렌더 배율 상한을 건다.

Graphics quality governor.

  • Decides whether to use the light path in the order override, quality setting, auto (frame measurement), and applies the render pixel ratio limit for each path.
예제Example느린 프레임이 이어지면 자동으로 가벼운 길Automatically take the light path when slow frames continue
use vanilla::GraphicsQualityGovernor;

let mut governor = GraphicsQualityGovernor::new();
governor.set_render_pixel_ratio_limits(0.0, 1.5);
governor.get_frame_probe_mut().set_seconds(0.0, 1.0);
let mut changed_count = 0;
for _ in 0..40 {
	if governor.update(0.05, 60.0) {
		changed_count += 1;
	}
}
assert!(governor.is_lite());
assert_eq!(changed_count, 1);
assert_eq!(governor.read_max_render_pixel_ratio(), 1.5);
생성자constructorpub fn new() -> GraphicsQualityGovernor#0.4.0 부터since 0.4.0소스source

생성. (자동, 덮어쓰기 없음, 렌더 배율 제한 없음)

Constructor. (Auto, no override, no render pixel ratio limit)

반환ReturnsGraphicsQualityGovernor 가벼운 길이 아닌 새 품질 정하기. (FrameProbe 는 기본값)A new quality governor not on the light path. (FrameProbe at defaults)

짝Counterpart: vanilla.js GraphicsQualityGovernor.constructor

메서드methodpub fn set_quality(&mut self, quality: GraphicsQuality)#0.4.0 부터since 0.4.0소스source

품질 설정.

Quality setting.

qualityGraphicsQuality
품질 설정 값. (덮어쓰기가 있으면 그것이 먼저다)Quality setting value. (an override takes precedence if present)

짝Counterpart: vanilla.js GraphicsQualityGovernor.setQuality

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

품질 설정 반환.

Returns the quality setting.

반환ReturnsGraphicsQuality 지금 품질 설정 값.Current quality setting value.

짝Counterpart: vanilla.js GraphicsQualityGovernor.getQuality

메서드methodpub fn set_lite_override(&mut self, lite_override: Option<bool>)#0.4.0 부터since 0.4.0소스source

덮어쓰기 설정. (Some(true) 면 늘 가벼운 길, Some(false) 면 늘 아님, None 이면 풀기)

Sets the override. (Some(true) always light, Some(false) never, None clears it)

lite_overrideOption<bool>
덮어쓰기 값.Override value.

짝Counterpart: vanilla.js GraphicsQualityGovernor.setLiteOverride

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

덮어쓰기 반환.

Returns the override.

반환ReturnsOption<bool> 지금 덮어쓰기 값. 없으면 None.Current override value. None if none.

짝Counterpart: vanilla.js GraphicsQualityGovernor.getLiteOverride

메서드methodpub fn apply_search_text(&mut self, search_text: &str, lite_key: &str)#0.4.0 부터since 0.4.0소스source

쿼리 글로 덮어쓰기. (lite_key 가 있으면 가벼운 길, 값이 "0" 이나 "false" 면 늘 아님, 없으면 그대로)

Overrides from query text. (light if lite_key is present, never if its value is "0" or "false", unchanged if absent)

search_text&str
쿼리 글. ("?light", "?a=1&light=0" 처럼, 앞의 ? 는 없어도 된다)Query text. (like "?light", "?a=1&light=0", the leading ? is optional)
lite_key&str
찾을 이름. (풀어 쓴 이름과 견준다, 같은 이름이 여럿이면 첫 값)Name to look for. (compared with the decoded name, the first value if it appears more than once)

짝Counterpart: vanilla.js GraphicsQualityGovernor.applySearchText

예제Example주소의 light 로 덮어쓰기Override with light in the address
use vanilla::GraphicsQualityGovernor;

let mut governor = GraphicsQualityGovernor::new();
governor.apply_search_text("?a=1&light", "light");
assert_eq!(governor.get_lite_override(), Some(true));
governor.apply_search_text("?light=0", "light");
assert_eq!(governor.get_lite_override(), Some(false));
governor.apply_search_text("?other=1", "light");
assert_eq!(governor.get_lite_override(), Some(false));
메서드methodpub fn apply_page_query(&mut self, lite_key: &str)#0.4.0 부터since 0.4.0소스source

페이지 주소의 쿼리로 덮어쓰기. (웹은 주소의 쿼리, 데스크탑은 환경 변수 VANILLA_<이름> 을 읽는다. 값이 0 이나 false 가 아니면 가벼운 길)

Overrides with the query of the page address. (reads the address query on the web, the environment variable VANILLA_<name> on desktop. The lite path if the value is not 0 or false)

lite_key&str
쿼리 이름. (웹은 페이지 주소 쿼리에서, 데스크탑은 환경 변수 VANILLA_ 뒤에 이 이름을 대문자 뱀꼴로 붙인 것에서 읽는다. platform::read_page_query_value)Query name. (read from the page address query on the web, and on desktop from the environment variable VANILLA_ followed by this name in upper snake case. platform::read_page_query_value)

짝Counterpart: vanilla.js GraphicsQualityGovernor.applyPageQuery

메서드methodpub fn set_auto_lite_default(&mut self, is_auto_lite_default: bool)#0.4.0 부터since 0.4.0소스source

자동일 때 처음부터 가벼운 길인지 설정. (손가락 기기처럼 재기 전부터 가볍게 갈 때)

Sets whether auto starts on the lite path. (When going lite even before measuring, like touch devices)

is_auto_lite_defaultbool
true 면 자동일 때 프레임을 재지 않고 가벼운 길이다.If true, auto is light without measuring frames.

짝Counterpart: vanilla.js GraphicsQualityGovernor.setAutoLiteDefault

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

자동일 때 처음부터 가벼운 길인지 반환.

Returns whether auto starts on the lite path.

반환Returnsbool set_auto_lite_default 로 정한 값. (기본 false)Value set with set_auto_lite_default. (default false)

짝Counterpart: vanilla.js GraphicsQualityGovernor.isAutoLiteDefault

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

프레임 재기 반환.

Returns the frame probe.

반환Returns&FrameProbe 자동일 때 쓰는 프레임 재기의 참조.Reference to the frame probe used in auto.

짝Counterpart: vanilla.js GraphicsQualityGovernor.getFrameProbe

메서드methodpub fn get_frame_probe_mut(&mut self) -> &mut FrameProbe#0.4.0 부터since 0.4.0소스source

프레임 재기 반환. (기다리는 초, 판정 문턱을 바꾸거나 무거운 장면에서 measure_again 할 때)

Returns the frame probe. (to change the wait seconds or decision thresholds, or to measure_again in a heavy scene)

반환Returns&mut FrameProbe 자동일 때 쓰는 프레임 재기의 변경용 참조.Mutable reference to the frame probe used in auto.

짝Counterpart: vanilla.js GraphicsQualityGovernor.getFrameProbe

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

가벼운 길로 그리는지.

Whether drawing on the lite path.

반환Returnsbool 덮어쓰기가 있으면 그 값. 없으면 낮음은 true, 높음은 false, 자동은 처음부터 가벼운 길이거나 FrameProbe 가 처지는 기기로 쟀으면 true.The override value if any. Otherwise true for low, false for high, and for auto, true if light from the start or FrameProbe measured a slow device.

짝Counterpart: vanilla.js GraphicsQualityGovernor.isLite

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

한 프레임. (자동이고 아직 가벼운 길이 아니면 프레임을 잰다, 가벼운 길이 바뀐 프레임에 true)

  • 덮어쓰기가 없고, 자동이고, 처음부터 가벼운 길이 아닐 때만 FrameProbe 로 잰다.

One frame. (measures frames if auto and not yet light, true on the frame the light path changes)

  • Measures with FrameProbe only when there is no override, it is auto, and it is not light from the start.
frame_secondsf64
이번 프레임 간격. (초)This frame's interval. (seconds)
maximum_frame_per_secondf64
최대 프레임. (0 이하면 FrameProbe 의 무제한 목표 프레임으로 본다)Maximum frame rate. (0 or less is treated as FrameProbe's unlimited target frame rate)

반환Returnsbool 지난 update 때와 is_lite 가 달라졌으면 true. (설정이나 덮어쓰기로 바뀐 것도 다음 update 에서 true)true if is_lite differs from the last update. (changes from the setting or override are also true on the next update)

짝Counterpart: vanilla.js GraphicsQualityGovernor.update

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

렌더 배율 상한 설정. (보통 길과 가벼운 길, 0 이면 제한 없음)

Sets the render pixel ratio cap. (Normal path and lite path, 0 means no limit)

normal_max_render_pixel_ratiof64
보통 길의 렌더 배율 상한. (음수는 0)Render pixel ratio limit for the normal path. (negative is 0)
lite_max_render_pixel_ratiof64
가벼운 길의 렌더 배율 상한. (음수는 0)Render pixel ratio limit for the light path. (negative is 0)

짝Counterpart: vanilla.js GraphicsQualityGovernor.setRenderPixelRatioLimits

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

지금 길의 렌더 배율 상한.

Render pixel ratio cap of the current path.

반환Returnsf64 is_lite 면 가벼운 길의 상한, 아니면 보통 길의 상한. (0 이면 제한 없음)The light path limit if is_lite, otherwise the normal path limit. (0 means no limit)

짝Counterpart: vanilla.js GraphicsQualityGovernor.readMaxRenderPixelRatio

메서드methodpub fn apply_render_pixel_ratio(&self, view_manager: &mut ViewManager) -> bool#0.4.0 부터since 0.4.0소스source

렌더 배율 상한 걸기. (ViewManager 의 값과 다를 때만, 걸었으면 true)

Applies the render pixel ratio cap. (Only when it differs from the ViewManager value, true if applied)

view_manager&mut ViewManager
상한을 걸 뷰 관리자.View manager to apply the limit to.

반환Returnsbool 값이 달라 새로 걸었으면 true. 이미 같으면 false.true if newly applied because the value differed. false if already the same.

짝Counterpart: vanilla.js GraphicsQualityGovernor.applyRenderPixelRatio

예제Example바뀔 때만 걸기Apply only when it changes
use vanilla::{GraphicsQualityGovernor, Vector2, ViewManager, ViewScaleMode};

let mut governor = GraphicsQualityGovernor::new();
governor.set_render_pixel_ratio_limits(2.0, 1.0);
let mut view_manager = ViewManager::new(Vector2::create(1280.0, 720.0), ViewScaleMode::StretchShort);
assert!(governor.apply_render_pixel_ratio(&mut view_manager));
assert_eq!(view_manager.get_max_render_pixel_ratio(), 2.0);
assert!(!governor.apply_render_pixel_ratio(&mut view_manager));

GraphicsQualityenum traits Clone, Copy, Debug, Default, PartialEq, Eq

짝Counterpart: vanilla.js GraphicsQuality소스source

그래픽 품질 설정 값. (원본 GraphicsQuality.auto, high, low)

Graphics quality setting value. (original GraphicsQuality.auto, high, low)

이름Name설명Description
Auto자동. (처음부터 가벼운 길이거나 FrameProbe 가 처지는 기기로 잰 때 가벼운 길, 기본값)Auto. (light if light from the start or when FrameProbe measured a slow device, the default)
High높음. (늘 가벼운 길이 아니다)High. (never the lite path)
Low낮음. (늘 가벼운 길)Low. (always the lite path)