Skip to main content

Ghost API Overview

1. Overview

이 문서는 Ghost 라이브러리의 Public API를 설명한다.

Ghost API는 다음 기능을 제공한다.

  • Window 생성 및 관리
  • 플랫폼 이벤트 수집
  • CPU Writable Surface 접근
  • 시간 측정

Ghost API는 플랫폼 독립 인터페이스를 제공하며
플랫폼 구현은 내부 platform 모듈에서 수행된다.


2. API Entry Header

Ghost 라이브러리의 모든 Public API는 다음 헤더를 통해 접근할 수 있다.

#include <ghost/ghost.hpp>

이 헤더는 Ghost의 모든 public 모듈을 포함한다.


3. API Modules

Ghost Public API는 다음 모듈로 구성된다.

ModuleDescription
common공통 타입 및 설정
id핸들 및 ID 시스템
windowWindow 관리 및 Surface API
time시간 측정 API
native_event플랫폼 이벤트 시스템

모듈 구조

ghost/
├── common
├── id
├── window
├── time
└── native_event

4. Core API Components

Ghost API는 다음 핵심 컴포넌트로 구성된다.

ComponentDescription
WindowWindow 생성 및 관리
WindowDescWindow 생성 설정
CpuSurfaceCPU Writable Surface
NativeEvent플랫폼 이벤트
NativeEventQueue이벤트 저장
Clock시간 측정

5. Window API

Window API는 Ghost 라이브러리의 주요 기능을 제공한다.

주요 기능

  • Window 생성
  • 이벤트 처리
  • Surface 접근
  • 화면 출력

사용 헤더

#include <ghost/window/window.hpp>

6. Event API

플랫폼 이벤트는 NativeEvent 시스템으로 제공된다.

주요 기능

  • OS 메시지 수집
  • 이벤트 구조 저장
  • 이벤트 조회

사용 헤더

#include <ghost/native_event/native_event.hpp>

7. Time API

시간 측정 기능은 Clock API로 제공된다.

주요 기능

  • 현재 시간 반환

사용 헤더

#include <ghost/time/clock.hpp>

8. ID System

Window 객체는 내부적으로 ID 시스템을 사용한다.

관련 타입

  • GhostWindowId
  • Handle 시스템

사용 헤더

#include <ghost/id/ids.hpp>
#include <ghost/id/handle.hpp>

9. Basic Usage

다음은 Ghost API의 기본 사용 예시이다.

#include <ghost/window/window.hpp>

int main() {

ghost::WindowDesc desc{};
desc.title = "ghost_smoke";
desc.width = 640;
desc.height = 360;
desc.visible = false;

auto result = ghost::Window::create(desc);
if (!result) {
return 0;
}

ghost::Window window = std::move(result.value());

window.poll_events();

auto surface = window.acquire_cpu_surface();
if (surface.valid()) {
window.release_cpu_surface();
}

window.destroy();

return 0;
}

10. API Design Principles

Ghost API는 다음 설계 원칙을 따른다.

PrincipleDescription
Platform AbstractionOS 의존 코드 분리
Minimal Interface최소 API 제공
Explicit Lifecycle명시적 리소스 관리
Raw Event Model플랫폼 이벤트 raw 유지

11. Public Headers

Ghost Public API는 다음 헤더로 구성된다.

ghost/common/config.hpp
ghost/common/result.hpp

ghost/id/ids.hpp
ghost/id/handle.hpp

ghost/window/surface_types.hpp
ghost/window/cpu_surface.hpp
ghost/window/window_desc.hpp
ghost/window/window.hpp

ghost/time/clock_types.hpp
ghost/time/clock.hpp

ghost/native_event/native_event_types.hpp
ghost/native_event/native_event_queue.hpp
ghost/native_event/native_event.hpp

12. Platform Layer

Ghost API는 플랫폼 구현을 직접 노출하지 않는다.

플랫폼 구현은 다음 모듈에 위치한다.

ghost/platform/win32

이 계층은 Public API에 포함되지 않는다.


13. Summary

Ghost API는 다음 기능을 제공하는 플랫폼 추상화 라이브러리이다.

  • Window 시스템
  • Native Event 시스템
  • CPU Surface 접근
  • 시간 측정

API는 플랫폼 독립 인터페이스로 제공되며
플랫폼 구현은 내부 backend에서 처리된다.