# View & Mode Change

{% embed url="<https://youtu.be/3z2tIkXE_xA>" %}

## <mark style="background-color:yellow;">Scene View와 Game View 정의</mark>

* **Scene View**
  * 정의: 게임 개발자가 씬(장면)을 편집하고 조작하는 에디터 환경의 뷰
  * 목적: 게임 객체 배치, 속성 편집, 씬 구성 등 개발 과정에 사용
  * 구현 방식: GUIManager 클래스의 \_isSceneView 플래그로 제어

```
// GUIManager.h
bool _isSceneView = true;

bool isSceneView() { return _isSceneView; }
```

* **Game View**
  * 정의: 실제 게임이 실행될 때 플레이어가 보게 될 뷰
  * 목적: 최종 사용자 경험 테스트, 게임 동작 확인
  * 전환 방식: \_isSceneView 플래그를 false로 설정하여 전환

## <mark style="background-color:yellow;">Scene View와 Game View의 카메라 차이</mark>

* **EditorCamera (Scene View)**
  * 목적: 개발자의 자유로운 씬 탐색과 편집을 위한 카메라
  * 주요 특징:
    * WASD 키로 이동, 마우스 오른쪽 버튼으로 회전
    * 에디터 전용 입력 처리 (INPUT.GetSceneButton() 사용)
    * 에디터 모드에서도 GetEditorDeltaTime()을 사용해 지속적으로 움직임

```
// EditorCamera.cpp의 주요 부분
void EditorCamera::Update()
{
    if (!GUI.isSceneView())
        return;

    if (INPUT.GetSceneButton(KEY_TYPE::RBUTTON))
    {
        // 마우스 리셋 및 카메라 제어 로직
        float dt = (ENGINE.IsEditMode() || ENGINE.IsPausedMode()) ? 
                    TIME.GetEditorDeltaTime() : TIME.GetDeltaTime();

        // WASD 이동 로직
        // 마우스 회전 로직
    }
}
```

* **MainCamera (Game View)**
  * 목적: 실제 게임에서 플레이어가 보게 될 시점
  * 주요 특징:
    * 게임 로직에 의해 제어됨 (스크립트 컴포넌트로 구현)
    * 게임 입력에만 반응 (INPUT.GetButton() 사용)
    * Play 모드에서만 움직임 (GetDeltaTime()이 0이 아닐 때)

```
// Scene.cpp에서 카메라 전환 로직
void Scene::Start()
{
    if (ENGINE.GetEngineMode() == EngineMode::Edit || ENGINE.GetEngineMode() == EngineMode::Pause)
        SwitchMainCameraToEditorCamera();
    else
        SwitchMainCameraToMainCamera();
    
    // ...
}
```

## <mark style="background-color:yellow;">Edit, Play, Pause 모드의 차이</mark>

* **Edit 모드**
  * 정의: 씬을 편집하고 게임 객체를 조작하는 기본 에디터 모드
  * 특징:
    * \_editScene 객체에서 작업
    * 게임 로직 실행되지 않음 (Update 메서드는 호출되지만 deltaTime은 0)
    * 씬 영구 수정 가능
    * GetDeltaTime()은 0을 반환, 게임 시뮬레이션 정지

* **Play 모드**
  * 정의: 실제 게임 실행을 시뮬레이션하는 모드
  * 특징:
    * <mark style="color:red;">Edit 모드의 씬을 복사</mark>하여 \_playScene으로 생성
    * 모든 게임 로직 정상 실행
    * 씬 변경 사항은 일시적 (Edit 모드로 돌아가면 모두 초기화)
    * GetDeltaTime()이 실제 경과 시간 반환

* **Pause 모드**
  * 정의: Play 모드에서 게임 실행을 일시정지한 상태
  * 특징:
    * Play 모드의 씬 상태 유지하면서 시간만 정지
    * 게임 로직은 호출되지만 deltaTime이 0이라 진행되지 않음
    * GetDeltaTime()은 0을 반환하지만, GetEditorDeltaTime()은 계속 시간 측정

* **모드 전환 처리 로직**

```
// EngineBody.cpp
void EngineBody::SetEngineMode(EngineMode mode)
{
    // 같은 모드 설정 처리 또는 Pause 토글
    if (_engineMode == mode)
    {
        if (mode == EngineMode::Pause)
            _engineMode = _prevEngineMode;
        else
            return;
    }
    // Pause 모드 전환 - 이전 모드 기억
    else if (mode == EngineMode::Pause)
    {
        _prevEngineMode = _engineMode;
        _engineMode = mode;
    }
    // Play 모드 전환 - 씬 복사
    else if (mode == EngineMode::Play)
    {
        // 현재 편집 씬 저장
        _editScene = SCENE.GetActiveScene();
        // 복사본 생성
        _playScene = SCENE.LoadPlayScene(_editScene->GetSceneName());

        // 엔진 상태 리셋
        SCENE.Reset();
        RENDER.Reset();
        GUI.ResetSelectedObject();

        // 플레이 모드로 전환
        _engineMode = mode;
        SCENE.SetActiveScene(_playScene);
        SCENE.Init();
        RENDER.Init();
    }
    // Edit 모드 전환 - 원본 씬 복원
    else if (mode == EngineMode::Edit)
    {
        // 엔진 상태 리셋
        SCENE.Reset();
        RENDER.Reset();
        GUI.ResetSelectedObject();

        // 편집 모드로 전환
        _engineMode = mode;
        SCENE.SetActiveScene(_editScene);
        _playScene = nullptr;

        SCENE.Init();
        RENDER.Init();
    }
}
```

## <mark style="background-color:yellow;">시간 관리 방식</mark>

* 두 가지 시간 측정 메커니즘
  * EditorDeltaTime: 항상 실제 경과 시간을 측정
  * DeltaTime: 모드에 따라 0 또는 실제 시간 반환

* **모드별 시관 관리**
  * Edit 모드:
    * GetDeltaTime() → 0 반환 (게임 로직 정지)
      * GetEditorDeltaTime() → 실제 시간 반환 (에디터 UI, 카메라 등은 계속 작동)
  * Play 모드:
    * GetDeltaTime() → 실제 시간 반환 (게임 정상 실행)
      * GetEditorDeltaTime() → 실제 시간 반환
  * Pause 모드:
    * GetDeltaTime() → 0 반환 (게임 로직 정지)
      * GetEditorDeltaTime() → 실제 시간 반환 (에디터 기능 계속 작동)

* **시간 관리 코드**

```
// TimeManager.cpp
void TimeManager::Update()
{
    uint64 currentCount;
    ::QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&currentCount));

    // 에디터 시간은 항상 측정
    _editorDeltaTime = (currentCount - _prevCount) / static_cast<float>(_frequency);

    // 게임 시간은 조건부 측정
    if (_isEnginePause || _isPaused || ENGINE.GetEngineMode() == EngineMode::Edit)
    {
        _deltaTime = 0.0f;
        _prevCount = currentCount; // 누적 방지
        return;
    }

    _deltaTime = (currentCount - _prevCount) / static_cast<float>(_frequency);
    _prevCount = currentCount;
    
    // FPS 계산 등 추가 작업
}

float TimeManager::GetDeltaTime()
{
    if (ENGINE.GetEngineMode() == EngineMode::Edit || ENGINE.GetEngineMode() == EngineMode::Pause)
        return 0.0f;
    return _deltaTime;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jihoon-jungs-organization.gitbook.io/jihoon_engine/feature-and-description/view-and-mode-change.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
