# core/scene (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/core/scene/

씬.
- 원본은 Scene 클래스를 상속해 create / tick / draw 를 덮어쓴다.
- 러스트 판은 Scene 트레이트를 구현하고, 씬 공통 상태(노드 트리, 터치 대상)는 SceneBase 에 둔다.
- 노드는 SceneBase 의 NodeTree 가 들고, 게임 코드는 NodeId 핸들로 가리킨다. (get_node_tree_mut().create_child(...))
  원본의 super.tick() / super.draw() 자리는 get_scene_base_mut().tick() / .draw() 를 부른다.
- 원본 GameScene 의 pre_draw (캔버스 전체를 배경색으로 칠하고 뷰 좌표계를 거는 것)는 SceneBase::draw_scene_background 로 옮겼다.
- 트윈은 원본처럼 씬이 목록으로 들고(start_tween), tick 에서 노드 → 터치 다음에 돌리며 끝난 것을 뺀다.
  원본은 트윈 객체로 가리키지만, 러스트 판은 트윈을 넘겨받고 TweenId 를 돌려준다. (stop_tween(tween_id))
- 원본 SceneManager.unloadScene(scene) 은 씬 객체로 가리킨다. 러스트 판은 엔진이 씬을 들고 있어 load_scene 이 돌려주는 SceneId 나
  씬 공통 상태(&SceneBase, 원본처럼 씬으로)로 가리킨다. 씬 스스로는 get_scene_base().get_scene_id() 로 자기 핸들을 안다.
- 내릴 때는 원본처럼 finalize 다음 unload 를 부르고, 러스트 판은 씬을 버리기 직전에 destroy 를 더 부른다.
- 원본 async load(engine) 자리: load 에서 Engine::spawn_scene_task 로 불러오기 작업을 맡기고 track_task 로 씬에 맡긴다.
  작업 안에서는 원본처럼 await 로 애셋을 기다리고, SceneContext::with 안에서 씬과 엔진을 만진다. 맡긴 작업과 애셋이 모두 끝나야 initialize 를 부른다.
  애셋 손잡이를 track_asset 으로 맡기는 동기 꼴도 그대로 된다. (둘을 섞어도 된다)
  원본 await unload(engine) 자리: unload 에서 맡긴 작업(track_task)이 끝날 때까지 씬은 목록에 남아 tick, draw 를 받고, 끝나면 목록에서 빠진다.
  그 뒤에도 그 씬의 작업이 남았으면 원본의 Promise 사슬처럼 다 끝날 때까지 씬 값이 살고(tick, draw 는 받지 않는다), 불러오는 도중에 내린 씬은
  원본 SceneManager.loadScene 처럼 불러오기가 끝나면 initialize 까지 받는다. 다 끝나면 엔진이 destroy 를 부르고 버린다.
- 원본 Scene.load 가 루트를 뷰 크기로 맞추는 것(자리 0, 왼쪽 위 피벗, 콘텐츠 크기는 뷰 크기)은 엔진이 create 와 load 사이에 한다.
  원본 SceneManager.loadScene 처럼 맡긴 애셋이 다 끝난 뒤에도 로딩 화면(draw_on_load)을 최소 0.3초 더 보이고 initialize 를 부른다.
- 씬의 터치 훅(touch_press, touch_move, touch_release, touch_cancel, touch_wheel)은 원본 Scene.tickTouch 차례로 엔진이 tick 뒤에 부른다.
  SceneBase.tick 은 씬 꼴과 상관없이 가장 앞의 누를 수 있는 노드에도 넘긴다. (원본 Scene.tickTouch 가 씬의 TouchRaycaster 로 넘기는 것과 같다)
- 씬 훅은 원본과 달리 엔진(&Engine)을 받는다. (전역 엔진 Engine::get_engine 과 같은 엔진이다)

## SceneId (struct) (Clone, Copy, Debug, PartialEq, Eq, Hash, From<&SceneBase>)

씬 핸들. (Engine::load_scene 이 돌려주고 Engine::unload_scene 이 받는다)

예제: 씬 둘을 불러 핸들로 하나만 내리기

```rust
use vanilla::{Engine, EngineConfiguration, Scene, SceneBase, SceneId};

struct EmptyScene {
	scene_base: SceneBase,
}

impl Scene for EmptyScene {
	fn get_scene_base(&self) -> &SceneBase {
		&self.scene_base
	}

	fn get_scene_base_mut(&mut self) -> &mut SceneBase {
		&mut self.scene_base
	}
}

let engine = Engine::new(EngineConfiguration::new());
let first_scene_id: SceneId = engine.load_scene(Box::new(EmptyScene { scene_base: SceneBase::new() }));
let second_scene_id: SceneId = engine.load_scene(Box::new(EmptyScene { scene_base: SceneBase::new() }));
assert_ne!(first_scene_id, second_scene_id);
engine.unload_scene(second_scene_id);
```

## SceneBase (struct) (Default)

씬 공통 상태.
- 노드 트리, 트윈 목록, 맡긴 애셋과 작업, 터치 대상, 배경색을 든다. 씬 구조체가 하나 들고 get_scene_base 로 내준다.

예제: 노드를 만들고 트윈으로 움직이기

```rust
use vanilla::{SceneBase, Tween, TweenProperty, Vector2};

let mut scene_base = SceneBase::new();
let root_id = scene_base.get_root_id();
let player_id = scene_base.get_node_tree_mut().create_child(root_id, "player");
let tween = Tween::create_node_tween(player_id, TweenProperty::LocalPosition, Vector2::zero(), Vector2::create(100.0, 0.0), 1.0);
let tween_id = scene_base.start_tween(tween);
assert_eq!(scene_base.get_tween_count(), 1);
scene_base.tick_tweens(0.5);
assert_eq!(scene_base.get_node_tree()[player_id].get_local_position(), Vector2::create(50.0, 0.0));
scene_base.tick_tweens(0.5);
assert_eq!(scene_base.get_tween_count(), 0);
assert!(scene_base.get_tween(tween_id).is_none());
```

- `pub fn new() -> SceneBase` (constructor, since 0.3.2): 생성.
  - returns SceneBase: 새 씬 공통 상태. (루트 하나인 노드 트리, 배경색 검정, 불러오기 전, 기즈모 끔)
- `pub fn is_wheel_handled(&self) -> bool` (method, since 0.4.0): 이번 프레임의 휠을 받아 쓴 컴포넌트(스크롤 칸 등)가 있었는지. (tick_touch 뒤에 읽는다, 없으면 게임이 지도 확대 등에 쓴다)
  - returns bool: 이번 프레임의 휠을 컴포넌트가 썼으면 true.
- `pub fn get_scene_id(&self) -> Option<SceneId>` (method, since 0.4.0): 씬 핸들. (엔진에 load_scene 으로 넘긴 뒤부터 있다)
  - returns Option<SceneId>: 이 씬의 핸들. (load_scene 전이면 None)
- `pub fn set_first_touch_callback(&mut self, first_touch_callback: Box<dyn FnMut()>)` (method, since 0.3.2): 첫 터치 콜백 설정. (처음 누를 때 한 번. 웹에서 오디오 잠금을 푸는 자리, 원본 TouchRaycaster)
  - `first_touch_callback` Box<dyn FnMut()>: 처음 누를 때 부를 함수. (앞서 건 함수는 바꾼다)
- `pub fn set_touch_dispatch_enabled(&mut self, is_enabled: bool)` (method, since 0.4.0): 노드에 터치 넘기기 켜고 끄기. (원본 Scene.setTouchDispatchEnabled, setTouchRaycaster(null) 과 같은 효과)
  - 끄면 tick_touch 가 노드에 누름, 이동, 뗌, 휠을 넘기지 않고(첫 터치 콜백도 부르지 않는다) 씬의 터치 훅만 불린다. (훅에서 가로채 직접 넘길 때)
  - `is_enabled` bool: 노드에 넘기면 참. (기본 참)

  예제: 씬 기본 넘기기를 끄고 훅에서 직접 받기

  ```rust
  use vanilla::SceneBase;
  
  let mut scene_base = SceneBase::new();
  scene_base.set_touch_dispatch_enabled(false);
  assert!(!scene_base.is_touch_dispatch_enabled());
  ```

- `pub fn is_touch_dispatch_enabled(&self) -> bool` (method, since 0.4.0): 노드에 터치를 넘기는지.
  - returns bool: 넘기면 참.
- `pub fn get_touch_target(&self) -> Option<NodeId>` (method, since 0.3.2): 지금 눌려 있는 노드. (원본 TouchRaycaster.getTouchTarget)
  - returns Option<NodeId>: 누를 때 찾은 맨 위의 누를 수 있는 노드. (누르고 있지 않거나 빈 곳을 눌렀으면 None)
- `pub fn track_asset(&mut self, asset: &dyn Asset)` (method, since 0.3.2): 애셋 맡기기. (load 에서 읽기를 요청한 애셋. 맡긴 것이 다 읽히면 엔진이 initialize 를 부른다)
  - `asset` &dyn Asset: load 를 요청한 애셋. (읽기 손잡이가 없는 애셋은 맡기지 않는다)
- `pub fn track_load_handle(&mut self, load_handle: &AssetLoadHandle)` (method, since 0.3.2): 읽기 손잡이 맡기기. (애셋 꼴이 아닌 것)
  - `load_handle` &AssetLoadHandle: 기다릴 읽기 손잡이. (복제해 든다)
- `pub fn track_audio_asset(&mut self, audio_asset: &Rc<AudioAsset>)` (method, since 0.3.2): 오디오 애셋 맡기기. (engine.load_audio_asset 으로 받은 것. 웹은 디코딩이 끝나야 읽힌 것으로 친다)
  - `audio_asset` &Rc<AudioAsset>: 기다릴 오디오 애셋. (읽혔거나 실패하면 끝난 것으로 친다)
- `pub fn track_task(&mut self, task_handle: &TaskHandle)` (method, since 0.4.0): 작업 맡기기. (원본 async load 자리, load 에서 spawn_scene_task 로 맡긴 불러오기 작업. 끝나야 엔진이 initialize 를 부른다)
  - unload 에서 맡기면 원본 await scene.unload 처럼 끝나야 내리기가 끝난다. (그동안 씬은 목록에 남는다)
  - `task_handle` &TaskHandle: 기다릴 작업의 손잡이. (spawn_scene_task, spawn_task 가 돌려준 것)

  예제: 원본 async load 자리: load 에서 불러오기 작업을 맡기기

  ```rust
  use vanilla::{Engine, Scene, SceneBase, SceneContext};
  
  struct StageScene {
  	scene_base: SceneBase,
  	stage_byte_count: usize,
  }
  
  impl Scene for StageScene {
  	fn get_scene_base(&self) -> &SceneBase {
  		&self.scene_base
  	}
  
  	fn get_scene_base_mut(&mut self) -> &mut SceneBase {
  		&mut self.scene_base
  	}
  
  	fn load(&mut self, engine: &Engine) {
  		let task_handle = engine.spawn_scene_task(self, |mut scene_context: SceneContext<StageScene>| async move {
  			let load_handle = scene_context.with(|_scene, engine| engine.request_asset_bytes("examples/assets/scenedocument.scene.json"));
  			if let Ok(bytes) = load_handle.await {
  				scene_context.with(|scene, _engine| {
  					scene.stage_byte_count = bytes.len();
  				});
  			}
  		});
  		self.scene_base.track_task(&task_handle);
  	}
  
  	fn initialize(&mut self, _engine: &Engine) {
  		println!("{}", self.stage_byte_count);
  	}
  }
  ```

- `pub fn are_tracked_unloads_finished(&self) -> bool` (method, since 0.4.0): unload 에서 맡긴 것이 다 끝났는지. (읽혔거나 실패했거나 작업이 끝났거나)
  - returns bool: unload 에서 맡긴 것이 모두 끝났으면 true. (맡긴 것이 없으면 true)
- `pub fn are_tracked_assets_finished(&self) -> bool` (method, since 0.3.2): 맡긴 애셋이 다 끝났는지. (읽혔거나 실패했거나. 실패한 애셋 때문에 씬이 멈추지 않게 한다)
  - returns bool: 불러오기에 맡긴 애셋과 작업이 모두 끝났으면 true. (맡긴 것이 없으면 true)
- `pub fn are_tracked_assets_finished_except(&self, excluded_load_handle: &AssetLoadHandle) -> bool` (method, since 0.4.0): 맡긴 애셋이 하나를 빼고 다 끝났는지. (GameSceneBase 가 로딩 문을 빼고 원본 loadAssets 가 끝났는지 볼 때)
  - `excluded_load_handle` &AssetLoadHandle: 끝났는지 보지 않을 읽기 손잡이. (같은 읽기를 가리키는 손잡이를 모두 뺀다)
  - returns bool: 그 손잡이를 뺀 나머지가 모두 끝났으면 true.
- `pub fn get_tracked_asset_progress(&self) -> f64` (method, since 0.3.2): 맡긴 애셋 가운데 끝난 비율. (로딩 화면 진행 막대용, 맡긴 것이 없으면 1)
  - returns f64: 끝난 수 / 맡긴 수. (0 ~ 1, 실패한 것도 끝난 것으로 센다)

  예제: 읽기 손잡이 둘의 진행 비율

  ```rust
  use vanilla::{AssetLoadHandle, SceneBase};
  
  let mut scene_base = SceneBase::new();
  let scene_load_handle = AssetLoadHandle::create_pending("examples/assets/scenedocument.scene.json");
  let atlas_load_handle = AssetLoadHandle::create_pending("examples/assets/atlas/icons.json");
  scene_base.track_load_handle(&scene_load_handle);
  scene_base.track_load_handle(&atlas_load_handle);
  assert_eq!(scene_base.get_tracked_asset_progress(), 0.0);
  scene_load_handle.finish(Ok(b"{}".to_vec()));
  assert_eq!(scene_base.get_tracked_asset_progress(), 0.5);
  atlas_load_handle.finish(Err(String::from("not found")));
  assert!(scene_base.are_tracked_assets_finished());
  ```

- `pub fn clear_tracked_assets(&mut self)` (method, since 0.3.2): 맡긴 애셋 비우기. (initialize 직전에 엔진이 부른다)
- `pub fn has_ever_touched(&self) -> bool` (method, since 0.3.2): 한 번이라도 눌린 적이 있는지. (원본 Scene.hasEverTouched, 처음 누를 때 참이 된다)
  - returns bool: 이 씬에서 한 번이라도 눌렀으면 true.
- `pub fn get_node_tree(&self) -> &NodeTree` (method, since 0.3.2): 노드 트리.
  - returns &NodeTree: 이 씬의 노드 트리.
- `pub fn get_engine(&self) -> Result<&'static crate::core::engine::Engine, crate::core::globalengine::EngineAccessError>` (method, since 0.4.0): 엔진 반환. (원본 Scene.getEngine, 이 씬을 불러온 엔진. 러스트 판은 엔진이 하나라 전역 엔진을 준다)
  - Engine::get_engine 과 같다. 씬 함수, 컴포넌트, async 작업 어디서나 씬 함수의 engine 인자와 같은 엔진을 준다.
  - returns Result<&'static crate::core::engine::Engine, crate::core::globalengine::EngineAccessError>: 전역 엔진, 못 꺼내면 그 까닭.
- `pub fn get_node_tree_mut(&mut self) -> &mut NodeTree` (method, since 0.3.2): 노드 트리. (변경용)
  - returns &mut NodeTree: 이 씬의 노드 트리. (노드 만들기, 붙이기, 지우기)
- `pub fn get_root_id(&self) -> NodeId` (method, since 0.3.2): 루트 노드 핸들.
  - returns NodeId: 노드 트리의 루트 노드 핸들.
- `pub fn get_root(&self) -> &WorldNode` (method, since 0.3.2): 루트 노드.
  - returns &WorldNode: 루트 노드. (엔진이 create 와 load 사이에 뷰 크기로 맞춘다)
- `pub fn get_root_mut(&mut self) -> &mut WorldNode` (method, since 0.3.2): 루트 노드. (변경용)
  - returns &mut WorldNode: 루트 노드.
- `pub fn set_loaded(&mut self, is_loaded: bool)` (method, since 0.3.2): 로드 완료 설정.
  - `is_loaded` bool: 불러오기를 마쳤는지. (엔진이 initialize 뒤에 true 로 둔다)
- `pub fn is_loaded(&self) -> bool` (method, since 0.3.2): 로드 완료 여부.
  - returns bool: initialize 를 마쳤으면 true. (그 전에는 엔진이 tick, draw 대신 draw_on_load 를 부른다)
- `pub fn set_gizmo_visible(&mut self, is_gizmo_visible: bool)` (method, since 0.3.2): 기즈모 표시 설정.
  - `is_gizmo_visible` bool: true 면 엔진이 post_draw 뒤에 draw_gizmos 를 부른다.
- `pub fn is_gizmo_visible(&self) -> bool` (method, since 0.3.2): 기즈모 표시 여부.
  - returns bool: 기즈모를 그리면 true. (기본 false)
- `pub fn set_scene_background_color(&mut self, color: impl Into<Color>)` (method, since 0.3.2): 배경색 설정. (draw_scene_background 가 칠한다)
  - `color` impl Into<Color>: 배경색. (Color 나 "#202020" 같은 색 글)
- `pub fn get_scene_background_color(&self) -> Color` (method, since 0.3.2): 배경색 반환.
  - returns Color: 배경색. (기본 검정)
- `pub fn tick(&mut self, time_delta: f64)` (method, since 0.3.2): 기본 갱신. (루트 노드 → 터치 → 트윈)
  - `time_delta` f64: 배율을 곱한 프레임 간격. (초)
- `pub fn tick_tweens(&mut self, time_delta: f64)` (method, since 0.3.2): 트윈 목록 갱신. (원본처럼 뒤에서부터 돌고, 끝난 트윈은 목록에서 뺀다)
  - 같은 속성을 둘이 움직이면 먼저 시작한 트윈이 나중에 돌아 이긴다. (원본과 같음)
  - `time_delta` f64: 진행할 시간. (초)
- `pub fn start_tween(&mut self, mut tween: Tween) -> TweenId` (method, since 0.3.2): 트윈 시작. (트윈을 넘겨받아 start 하고 목록 끝에 붙인다. 가리킬 핸들을 돌려준다)
  - `tween` Tween: 돌릴 트윈. (씬이 소유한다)
  - returns TweenId: 그 트윈의 핸들. (stop_tween, get_tween 에 넘긴다)
- `pub fn stop_tween(&mut self, tween_id: TweenId)` (method, since 0.3.2): 트윈 중단. (완료 콜백 없이 멈추고 목록에서 뺀다. 이미 끝나 빠졌으면 아무것도 하지 않는다)
  - `tween_id` TweenId: 멈출 트윈의 핸들. (start_tween 이 돌려준 것)
- `pub fn stop_all_tweens(&mut self)` (method, since 0.3.2): 모든 트윈 중단.
- `pub fn get_tween(&self, tween_id: TweenId) -> Option<&Tween>` (method, since 0.3.2): 트윈 반환. (끝나서 목록에서 빠졌으면 None. 원본에서 트윈 객체를 들고 묻던 자리)
  - `tween_id` TweenId: 찾을 트윈의 핸들.
  - returns Option<&Tween>: 돌고 있는 그 트윈. (끝났거나 멈춰 빠졌으면 None)
- `pub fn get_tween_mut(&mut self, tween_id: TweenId) -> Option<&mut Tween>` (method, since 0.3.2): 트윈 반환. (변경용)
  - `tween_id` TweenId: 찾을 트윈의 핸들.
  - returns Option<&mut Tween>: 돌고 있는 그 트윈. (끝났거나 멈춰 빠졌으면 None)
- `pub fn get_tween_count(&self) -> usize` (method, since 0.3.2): 돌고 있는 트윈 수.
  - returns usize: 목록의 트윈 수. (대기 중인 것 포함)
- `pub fn tick_touch(&mut self, _time_delta: f64)` (method, since 0.3.2): 터치 갱신. (눌린 곳 맨 위의 interactable 노드를 찾아 눌림 / 이동 / 뗌을 전달)
  - 휠은 누름과 상관없이 그 자리의 가장 앞 스크롤 칸이나 누를 수 있는 노드부터 부모 쪽으로 넘긴다.
  - `_time_delta` f64: 배율을 곱한 프레임 간격. (초, 원본 tickTouch(timeDelta) 와 같은 인자. 입력은 엔진의 입력 매니저에서 읽는다)
- `pub fn draw(&mut self, graphic: &mut Graphic)` (method, since 0.3.2): 기본 출력. (루트 노드 재귀)
  - `graphic` &mut Graphic: 그릴 그래픽.
- `pub fn draw_scene_background(&self, graphic: &mut Graphic)` (method, since 0.3.2): 캔버스 전체를 배경색으로 칠하고 뷰 좌표계를 건다. (원본 GameScene.preDraw)
  - `graphic` &mut Graphic: 칠할 그래픽. (끝나면 뷰 좌표계가 걸려 있다)

  예제: pre_draw 에서 배경 칠하기

  ```rust
  use vanilla::{Engine, Graphic, Scene, SceneBase};
  
  struct MainScene {
  	scene_base: SceneBase,
  }
  
  impl Scene for MainScene {
  	fn get_scene_base(&self) -> &SceneBase {
  		&self.scene_base
  	}
  
  	fn get_scene_base_mut(&mut self) -> &mut SceneBase {
  		&mut self.scene_base
  	}
  
  	fn load(&mut self, _engine: &Engine) {
  		self.scene_base.set_scene_background_color("#203040");
  	}
  
  	fn pre_draw(&mut self, graphic: &mut Graphic) {
  		self.scene_base.draw_scene_background(graphic);
  	}
  }
  ```

## SceneAny (trait)

씬을 그 타입으로 꺼내기. (SceneContext 가 &mut dyn Scene 을 작업을 맡긴 씬의 타입으로 되돌릴 때 쓴다, 모든 씬에 저절로 붙는다)

예제: `Box<dyn Scene>` 을 씬 타입으로 되돌리기

```rust
use vanilla::core::scene::SceneAny;
use vanilla::{Scene, SceneBase};

struct MainScene {
	scene_base: SceneBase,
	score: u32,
}

impl Scene for MainScene {
	fn get_scene_base(&self) -> &SceneBase {
		&self.scene_base
	}

	fn get_scene_base_mut(&mut self) -> &mut SceneBase {
		&mut self.scene_base
	}
}

let mut boxed_scene: Box<dyn Scene> = Box::new(MainScene { scene_base: SceneBase::new(), score: 7 });
let main_scene = boxed_scene.as_scene_any_mut().downcast_mut::<MainScene>().unwrap();
assert_eq!(main_scene.score, 7);
```

- `fn as_scene_any_mut(&mut self) -> &mut dyn std::any::Any` (method, since 0.4.0): Any 로 빌리기.
  - returns &mut dyn std::any::Any: 이 씬을 `dyn Any` 로 빌린 것. (downcast_mut 로 씬 타입으로 되돌린다)

## Scene (trait) (SceneAny)

씬 트레이트.
- get_scene_base, get_scene_base_mut 만 꼭 구현하고, 나머지 훅은 필요한 것만 덮어쓴다.

예제: 흰 사각형 하나를 그리는 첫 씬 (examples/quickstart.rs)

```rust
use vanilla::{Colors, Engine, EngineConfiguration, Graphic, Rect, Scene, SceneBase, Vector2};

struct MainScene {
	scene_base: SceneBase,
}

impl Scene for MainScene {
	fn get_scene_base(&self) -> &SceneBase {
		&self.scene_base
	}

	fn get_scene_base_mut(&mut self) -> &mut SceneBase {
		&mut self.scene_base
	}

	fn pre_draw(&mut self, graphic: &mut Graphic) {
		self.scene_base.draw_scene_background(graphic);
	}

	fn draw(&mut self, graphic: &mut Graphic) {
		graphic.set_fill_color(Colors::WHITE);
		graphic.draw_rect(Rect::create(100.0, 100.0, 200.0, 120.0));
	}
}

let mut engine_configuration = EngineConfiguration::new();
engine_configuration.reference_resolution_size = Vector2::create(1280.0, 720.0);
let engine = Engine::new(engine_configuration);
let main_scene = MainScene {
	scene_base: SceneBase::new(),
};
if let Err(error) = engine.run(Box::new(main_scene)) {
	eprintln!("{}", error);
}
```

예제: 누른 자리 받기

```rust
use vanilla::{Engine, Scene, SceneBase, Vector2};

struct TouchScene {
	scene_base: SceneBase,
	last_touch_position: Vector2,
}

impl Scene for TouchScene {
	fn get_scene_base(&self) -> &SceneBase {
		&self.scene_base
	}

	fn get_scene_base_mut(&mut self) -> &mut SceneBase {
		&mut self.scene_base
	}

	fn touch_press(&mut self, view_input_position: Vector2) {
		self.last_touch_position = view_input_position;
	}
}
```

- `fn get_scene_base(&self) -> &SceneBase` (method, since 0.3.2): 씬 공통 상태 반환.
  - returns &SceneBase: 씬이 든 씬 공통 상태.
- `fn get_scene_base_mut(&mut self) -> &mut SceneBase` (method, since 0.3.2): 씬 공통 상태 반환. (변경용)
  - returns &mut SceneBase: 씬이 든 씬 공통 상태.
- `fn create(&mut self)` (method, since 0.3.2): 생성. (엔진이 씬을 불러올 때 load 앞에 한 번, 원본 create)
  - 씬 공통 상태는 SceneBase::new 가 이미 만들었다. 엔진이 필요 없는 칸 채우기를 여기서 한다. (엔진은 Engine::get_engine())
- `fn load(&mut self, _engine: &Engine)` (method, since 0.4.0): 불러오기. (엔진이 씬을 불러올 때 create 뒤에 한 번, 원본 async load. 노드 트리와 애셋을 여기서 만든다)
  - 원본 await 자리: engine.spawn_scene_task(self, |mut scene_context| async move { ... }) 로 맡긴 작업을 get_scene_base_mut().track_task 로 맡긴다.
    맡긴 애셋과 작업이 다 끝나야 initialize 로 넘어간다. (원본 load 의 Promise 가 끝나는 때)
  - `_engine` &Engine: 엔진. (애셋 읽기, 작업 맡기기, 매니저)
- `fn initialize(&mut self, _engine: &Engine)` (method, since 0.3.2): 초기화. (load 에서 맡긴 애셋이 다 읽히고 0.3 초 뒤 한 번. 원본 initialize. 맡긴 것이 없어도 load 뒤 0.3 초를 기다린다)
  - 웹은 애셋이 나중에 오므로, 애셋을 쓰는 노드는 여기서 만든다. 데스크탑은 load 에서 만들어도 된다.
  - `_engine` &Engine: 엔진.
- `fn draw_on_load(&mut self, _graphic: &mut Graphic)` (method, since 0.3.2): 로딩 중 출력. (initialize 전까지 tick / draw 대신 불린다. 원본 drawOnLoad)
  - `_graphic` &mut Graphic: 로딩 화면을 그릴 그래픽.
- `fn finalize(&mut self, _engine: &Engine)` (method, since 0.4.0): 종료처리. (내릴 때 unload 앞에 한 번, 원본 finalize)
  - `_engine` &Engine: 엔진.
- `fn unload(&mut self, _engine: &Engine)` (method, since 0.4.0): 로딩 해제. (내릴 때 finalize 뒤에 한 번, 원본 async unload. 여기서 track_task 로 맡긴 작업이 끝나야 내리기가 끝난다)
  - `_engine` &Engine: 엔진.
- `fn destroy(&mut self)` (method, since 0.3.2): 해제. (엔진이 씬을 내릴 때 unload 뒤, 씬을 버리기 직전에 한 번. 그 씬의 작업이 남았으면 다 끝난 뒤)
- `fn touch_press(&mut self, _view_input_position: Vector2)` (method, since 0.4.0): 터치 누름. (원본 Scene.touchPress, 엔진이 tick 뒤에 부른다)
  - `_view_input_position` Vector2: 누른 자리. (뷰 좌표)
- `fn touch_move(&mut self, _view_input_position: Vector2)` (method, since 0.4.0): 터치 이동. (누르고 있는 동안, 누른 프레임과 뗀 프레임에는 부르지 않는다)
  - `_view_input_position` Vector2: 지금 자리. (뷰 좌표)
- `fn touch_release(&mut self, _view_input_position: Vector2)` (method, since 0.4.0): 터치 뗌. (한 프레임 안에 눌렀다 떼면 누름 뒤에 바로)
  - `_view_input_position` Vector2: 뗀 자리. (뷰 좌표)
- `fn touch_cancel(&mut self, _view_input_position: Vector2)` (method, since 0.4.0): 터치 취소됨.
  - `_view_input_position` Vector2: 취소된 때의 자리. (뷰 좌표)
- `fn touch_wheel(&mut self, _view_input_position: Vector2, _wheel_delta: Vector2)` (method, since 0.4.0): 마우스 휠. (이번 프레임에 쌓인 휠이 있을 때)
  - `_view_input_position` Vector2: 마우스 자리. (뷰 좌표)
  - `_wheel_delta` Vector2: 이번 프레임에 쌓인 휠 양. (x 가로, y 세로, 입력 매니저의 get_wheel_delta_x, get_wheel_delta_y)
- `fn on_page_process_restored(&mut self)` (method, since 0.4.0): 페이지 프로세스 파기 뒤 복원. (Chromium 의 freeze 뒤 resume, bfcache 에서 돌아온 pageshow 등)
  - 엔진이 소리를 다시 깨우고 입력 상태를 비운 뒤 불러온 모든 씬에 부른다.
- `fn on_page_visibility_restored(&mut self)` (method, since 0.4.0): 페이지 가시성 복원. (백그라운드 → 포어그라운드, 웹 visibilitychange 의 visible, 데스크탑 창 가림이 풀림)
  - 엔진이 소리를 다시 깨우고 입력 상태를 비운 뒤 불러온 모든 씬에 부른다.
- `fn resize(&mut self, _canvas_native_size: Vector2)` (method, since 0.3.2): 화면 영역 변경. (창 크기가 바뀌었을 때, 불러온 직후에도 한 번)
  - `_canvas_native_size` Vector2: 창 안쪽 논리 크기. (뷰 매니저의 get_canvas_native_size)
- `fn tick(&mut self, time_delta: f64)` (method, since 0.3.2): 주기적 갱신.
  - 기본 구현은 씬 공통 상태의 tick 을 부른다. 덮어쓰면 get_scene_base_mut().tick(time_delta) 를 직접 부른다.
  - `time_delta` f64: 배율을 곱한 프레임 간격. (초, 시간 관리자의 get_time_delta)
- `fn pre_draw(&mut self, _graphic: &mut Graphic)` (method, since 0.3.2): 이전 출력.
  - `_graphic` &mut Graphic: 그릴 그래픽.
- `fn draw(&mut self, graphic: &mut Graphic)` (method, since 0.3.2): 출력.
  - 기본 구현은 씬 공통 상태의 draw 로 노드 트리를 그린다.
  - `graphic` &mut Graphic: 그릴 그래픽.
- `fn post_draw(&mut self, _graphic: &mut Graphic)` (method, since 0.3.2): 이후 출력.
  - `_graphic` &mut Graphic: 그릴 그래픽.
- `fn draw_gizmos(&mut self, _graphic: &mut Graphic)` (method, since 0.3.2): 기즈모 출력.
  - 기즈모 표시(set_gizmo_visible)를 켠 씬에만 post_draw 뒤에 부른다.
  - `_graphic` &mut Graphic: 그릴 그래픽.
