kasa 유연한 컨텐츠 개발을 위한 온라인 게임 아키텍처

Post on 04-Jul-2015

1.014 Views

Category:

Documents

12 Downloads

Preview:

Click to see full reader

TRANSCRIPT

유연한 컨텐츠 개발을 위한

온라인 게임 아키텍처

Kasa Study (2012/11/01) 박성준

온라인 게임 액체처럼 만들자

콘솔 게임

온라인 게임

그렇다면..

컨텐츠는 누가 만들어야 할까요?

서버 프로그래머?

클라이언트 프로그래머?

서버

프로그래머

컨텐츠

프로그래머

클라이언트

프로그래머

그래픽스

프로그래머 물리 엔진

프로그래머

인공 지능

프로그래머

사운드

프로그래머

게임 플레이

프로그래머

스크립터

UI

프로그래머

Input

프로그래머

네트워크

프로그래머

프로그래머

네트워크 프로그래머

툴 프로그래머

그래픽스 프로그래머

물리 엔진 프로그래머

인공 지능 프로그래머

사운드 프로그래머

게임 플레이 프로그래머

스크립터

UI 프로그래머

Input 프로그래머

DB 프로그래머

서버 클라이언트 컨텐츠

컨텐츠 개발 컨셉

• 세션 중심 개발

• 유저와 서버 사이의 1:1 이벤트

• 존 입장 / 변경 / 퇴장

• 옵션 정보 저장

• 게임 외적인 이벤트

• 게임 오브젝트 중심 개발

• 게임 오브젝트들 사이의 이벤트

• 이동 / 공격 / 피격

• 아이템 떨어뜨리기 / 줍기

• 게임 내적인 이벤트

Shodown

Core

Engine

Contents

Tools

Server Platform

Core

Engine

Contents

Logic

Server Client Tools

Core

Core.Native

Core.Net

FileModule

LogModule

ShodownFile

ShodownLog

인터페이스 프로젝트

인터페이스의 구현 프로젝트

전반적으로 사용되는 것들..

Core

FileModule LogModule

Shodown File

Shodown Log

Engine

Graphics

DB

Input

Sound

Network

UI

수정중인 오픈 라이브러리…

인터페이스 프로젝트

인터페이스의 구현 프로젝트

테스트 프로젝트

그 외 기타 등등(xml, lua, fx 등)

Graphic Manager

IGraphic Factory

IGraphic Source

IRenderer

Gamebryo Factory

Graphic Source

Renderer

GraphicModule

GamebryoWrapper

Graphic Object

컨텐츠를 개발할 때에는 컨텐츠’만’ 개발하자

플레이어가 몬스터를 강베기 스킬로 공격한다

플레이어 모델을 띄운다 몬스터 모델을 띄운다 강베기 애니메이션을 재생한다 피격 애니메이션을 재생한다 데미지 계산을 한다 HP를 깎는다 이펙트를 터뜨린다 사운드를 재생시킨다 UI 연출을 한다 모델을 어떻게?

애니메이션을 어떻게? 이펙트 렌더링을 어떻게? 사운드 재생을 어떻게? 이미지를 화면에 어떻게?

Contents GameBase

System

Server

System

Client

System Client

Logic

Server

SinglePlay

Test

클라이언트 컨텐츠

공통 컨텐츠

서버 컨텐츠

클라이언트 실행 파일 / 모듈의 조합

로직 서버 실행 파일 / 모듈의 조합

싱글 테스트 실행 파일 / 모듈의 조합

ClientSystem ServerSystem

GameBase System

Client SinglePlayTest LogicServer

ClientSystem ServerSystem

GameBase System

Network Module

Database Module

Graphic Module

UI Module

Sound Module

Input Module

Database Module

Network Module

Graphic Module

UI Module

Sound Module

Input Module

ADO Database

DBS Connector

Lua Database

Gamebryo Wrapper

Scaleform Wrapper

Shodown Sound

Shodown Input

Client LogicServer

Gamebryo Wrapper

Scaleform Wrapper

Shodown Sound

Shodown Input

ADO Database

DBS Connector

Lua Database

SinglePlayTest

세션 중심 개발

• 유저와 서버 사이의 1:1 이벤트

• 존 입장 / 변경 / 퇴장

• 옵션 정보 저장

• 등 게임 외적인 이벤트

Network Manager

Network Factory

ServerBase

ClientBase

ClientObject Base

ClientSession Base

IConnect Observer

IAccept Observer

ServerSession Base

ServerObject Base

Server Session

Client Session

Server Session

Client Session

Server Session

Client Session

Server Session

Client Session

Server Session

Client Session

Server

Client Client Client Client Client

Server Base

Accept Observer

Client Base

Network Manager

Server Base

Accept Observer

Client Base

Network Manager

Server Base

Accept Observer

접속

Client Base

Network Manager

Server Base

Accept Observer

접속

Client Base

Network Manager

Server Base

Accept Observer

접속

Client Session

생성

Client Base

Network Manager

Server Base

Accept Observer

접속

연결

Client Session

생성

Client Base

Network Manager

Server Base

Accept Observer

접속

연결

알림

Client Session

생성

Client Base

Network Manager

Server Base

Accept Observer

접속

연결

알림

User

Client Session

생성

Client Base

Network Manager

Server Base

Accept Observer

접속

연결

알림

User

Server Session

Client Session

생성

Client Base

Network Manager

Server Base

Accept Observer

접속

연결

알림

User

연결

Server Session

Client Session

생성

Client Base

Network Manager

Server Base

Accept Observer

접속

연결

알림

User

연결

Server Session

Client Session

생성 Client Base

Network Manager

Client Session

User

Server Session

메시지 하나로 끝나는 일은 없다

Coroutine

A B

시간 흐름

A

B

C

문제는…

• 게임 로직은 C++로 만든다!

• C++에서 코루틴을 쓰고 싶다!

• C++은 코루틴을 지원하지 않는다?!

Boost 비공식 라이브러리

문제는…

• 윈도우 비스타/2008 이상에서만 동작한다!

• 서버는 윈도우 2008 이상을 사용하면 된다…

• 하지만 클라이언트에서는 못쓴다!!

• 이유는 몇몇 Fiber 관련 API 때문…

Boost 공식 라이브러리 포함

STL TR 시리즈에 context와 coroutine이 포함되길 기대합니다..

Coroutine도 Boost 포함 예정

Call

Yield

Resume

Yield

Resume

Yield

Resume

End

유저시퀀스

• 유저 별로 발생하는 게임 외적인 이벤트 로직의 객체화 • 시퀀스 하나 = 이벤트의 처음부터 끝까지 • 내부적으로 boost::coroutine을 사용하여 구현

외부 인터페이스

User에 접근 가능

코루틴 인터페이스

실제 실행 함수

코루틴 함수

User

User – Update()에서 실행

버퍼에서 데이터 Pop 하여 받으려는 변수로 바로 가져옴

Network - OnRecv()에서 실행

유저 시퀀스의 스택 메모리에 할당됨

Thread가 달라도 문제 없음

유저시퀀스는 추가복사 없이 데이터를 로직 코드로 바로 가져올 수 있다

메시지에서 사용할 데이터 형식 메시지 타입

선언한 순서로 메시지ID 할당

버퍼에 데이터 넣기

버퍼에서 데이터 꺼내기

메시지ID + 데이터 타입

죄송합니다.. 시간에 쫓겨 급해서 Boost 전처리기 메타를 썼습니다..

시퀀스 생성

User - Update

코루틴 생성 후 Yield

Resume Wait() 만나면

Yield

메시지 도착

Resume 데이터 Pop

Yield

User - Update

Resume

유저시퀀스의 로직은 모두 User 객체의 Update에서 실행되는 것을 보장한다

코 루틴

메인 루틴

: Network Thread

: Main Thread

유저시퀀스에서 프로시저 호출

User

Database Object

Server Session

User 객체가 요청한 프로시저 결과는 User 객체가 받는다

User 객체가 전송한 메시지는 해당 User가 받는다

DatabaseModule NetworkModule

유저시퀀스에서 유저시퀀스 호출

게임 오브젝트 중심 개발

• 게임 오브젝트들 사이의 이벤트

• 이동 / 공격 / 피격

• 아이템 떨어뜨리기 / 줍기

• 등 게임 내적인 이벤트

• 플레이어, 몬스터 등 캐릭터

• 바위, 나무, 건물 등 배경 오브젝트

• 함정, 회복아이템 등 트리거

• 미사일, 수류탄, 파편 등

• 카메라, 광원 등

• 캐릭터가 서있는 지형

오브젝

캐릭터

지형

프랍

트리거

광원

카메라

발사체

레벨

게임 오브젝트!

오브젝트

오브젝트

오브젝트

오브젝

캐릭터

지형

프랍

트리거

광원

카메라

발사체

레벨

상호작용

게임 = 게임 오브젝트 사이의 상호작용

컴포넌트 + 게임 오브젝트

컴포넌트 설계는 좋지만..

• 의존적인 컴포넌트 구분!

• 메시지 통신X 메시지 객체 통신!

• 그렇지만 의존성은 피하자!

• 스크립트 친화적 구현!

의존적인 컴포넌트?

Controller

• 의존적인 컴포넌트는 컨트롤러의 속성을 가진다 • 다른 컴포넌트에 접근하는걸 고려하여 디자인 • 컴포넌트와는 다르게 활성화/비활성화 존재

Entity

AAA Controller

AAA Component

BBB Component

BBB Controller

Owner Entity가 가진 다른 컴포넌트와 컨트롤러에 접근 가능!

메시지 통신?

분산되는 로직 처리

= 응집력이 떨어진다

순서대로 로직 처리가 힘듦

= 작업 스트레스 증가

1. 액션 단위로 로직 처리 2. 액션객체가 컴포넌트들에 접근

3. 게임 오브젝트는 액션들을 관리

죄송합니다.. 시간에 쫓겨 급해서 Boost 전처리기 메타를 썼습니다..

전처리기 메타 코드가 만들어내는 코드

Action의 데이터

위에서 정의한 Action데이터로 virtual void Do( 데이터 ) = 0; 순수 가상 함수가 만들어진다

GetOwner()를 이용하여 Action이 실행된 Entity를 얻어올 수 있다

액션의 구현

Entity

AAA Action

AAA Component

BBB Component

AAA Controller

Owner Entity가 가진 다른 컴포넌트와 컨트롤러에 접근 가능!

DoAction 호출

생성

접근

Entity

Entity Handler DoAction 함수를 가진다

다른 객체에 접근을 위해..

Controller와 Action의 Owner로 노출

다른 Entity / 또는 외부에서 접근

Entity:: Update

Controller

Entity:: Update Action

Component System:: Update

업데이트 순서

Server Object

Client Object

Server Object

Server Object

Client Object

Client Object

Server

Client

Client Object

Client Object

Client Object

Client

NPC1

NPC1

NPC1

Player1

Player1 Player1

NPC2

NPC2 NPC2

게임 오브젝트와 네트워크 통신

Server Object

Server Object

Server Object

NPC1 Player1 NPC2

Server Base

Server Object

Server Object

Server Object

NPC1 Player1 NPC2

Server Base

Server Object

Server Object

Server Object

NPC1 Player1 NPC2

Server Base

ID : 0 ID : 1 ID : 2

Server Object

Server Object

Server Object

NPC1 Player1 NPC2

Server Base

ID : 0 ID : 1 ID : 2

Client Base

Server Object

Server Object

Server Object

NPC1 Player1 NPC2

Server Base

ID : 0 ID : 1 ID : 2

Player1

Client Object

Client Object

Client Object

NPC1 NPC2

ID : 0 ID : 1 ID : 2

Client Base

Server Object

Server Object

Server Object

NPC1 Player1 NPC2

Server Base

ID : 0 ID : 1 ID : 2

Player1

Client Object

Client Object

Client Object

NPC1 NPC2

ID : 0 ID : 1 ID : 2

Client Base

Server Object

Server Object

Server Object

NPC1 Player1 NPC2

Server Base

ID : 0 ID : 1 ID : 2

Player1

Client Object

Client Object

Client Object

NPC1 NPC2

ID : 0 ID : 1 ID : 2

Client Base

Server Object

Server Object

Server Object

NPC1 Player1 NPC2

Server Base

ID : 0 ID : 1 ID : 2

Player1

Client Object

Client Object

Client Object

NPC1 NPC2

ID : 0 ID : 1 ID : 2

Client Base

Client Base

Player1

Client Object

Client Object

Client Object

NPC1 NPC2

ID : 0 ID : 1 ID : 2

Server Object

Server Object

Server Object

NPC1 Player1 NPC2

Server Base

ID : 0 ID : 1 ID : 2

Player1

Client Object

Client Object

Client Object

NPC1 NPC2

ID : 0 ID : 1 ID : 2

Client Base

Client Base

Player1

Client Object

Client Object

Client Object

NPC1 NPC2

ID : 0 ID : 1 ID : 2

Entity가 받은 메시지는 어떻게?

Action과 Message를 연결 Message가 ServerObject/ClientObject에 도착하면 연결된 Action 실행

Network Action

Manager

Server/ Client Object

Network - OnRecv

Action

생성 함수

메시지에서 사용할 데이터 형식 메시지 타입

선언한 순서로 메시지ID 할당

버퍼에 데이터 넣기

버퍼에서 데이터 꺼내기

메시지ID + 데이터 타입

네트워크로 받은 메시지 버퍼

메시지를 받은 엔터티 액션 실행을 위한

함수포인터

ServerObject와 연결 ClientObject와 연결

메시지와 Action의 연결 선언

메시지와 Action의 연결 정의

메시지와 Action의 데이터가 같아야만 컴파일이 된다

액션과 네트워크 통신의 연결

게임 오브젝트와 스크립트

lua_state

컨트롤러 테이블 컨트롤러 테이블 컨트롤러 테이블

Controller Table

컨트롤러 테이블 컨트롤러 테이블 컨트롤러 테이블

Component Table

컨트롤러 테이블 컨트롤러 테이블 컨트롤러 테이블 Instance

Table Lua Thread

컨트롤러와 스크립트의 연결

Entity

Controller Script

Manager

Controller 정보 lua_state에 입력

Entity별로 lua table과 lua thread 생성

Controller Instance lua table 생성하여 Controller userdata와 연결

C++

AAA Controller Instance1

AAA Controller

AAA Controller Instance3

AAA Controller Instance2

AAA Controller Instance4

Lua

AAA Controller Instance1

AAA Controller Instance2

AAA Controller Instance3

AAA Controller Instance4

Class

Instance

table

table

AAA Controller Instance1

AAA Controller

userdata

meta table

AAA Controller Instance1

AAA Controller Instance1

AAA Controller Instance1

부모 클래스와 자식 클래스 모두 연결할 경우?

C++

AAA Controller

Lua

AAA Controller Instance

상속

BBB Controller

BBB Controller Instance

AAA Controller

AAA Controller Instance

meta table

BBB Controller

BBB Controller Instance

BBB Controller Instance AAA

Controller Instance

meta table

스크립트와 연결

스크립트 함수 실행

C++ 함수 실행

스크립트에서 컴포넌트 접근

Entity

Component Script

Manager

Component 정보 lua_state에 입력

C++

AAA Component Instance1

AAA Component

AAA Component Instance3

AAA Component Instance2

AAA Component Instance4

Lua

Class

Instance

table AAA Component

userdata AAA

Component Instance1

AAA Component Instance2

AAA Component Instance3

AAA Component Instance4

Entity

Entity Wrapper

Entity

Controller Script

Manager

Controller 정보 lua_state에 입력

Entity별로 lua table과 lua thread 생성

Controller Instance lua table 생성하여 Controller userdata와 연결

Controller의 owner로 EntityWrapper 생성 후 Controller Instance lua table에 “owner” Set

컴포넌트 설계의 장점 멀티쓰레딩!

Game Loop

Animation Physics Rendering Audio

어떻게?!

Game Loop

Set up

Thread0

Thread1 Thread2

Thread3

Process Result

• Controller는 Owner가 가지고 있는 것만 접근

-> Owner의 Component / Controller

• 다른 Entity에는 DoAction으로 할 일 전달

• Entity별로 Controller들 업데이트

Entity별로 Action Queue 처리

Component별로 업데이트

현재 구조를 보면…

• Entity는 다른 Entity에 직접 접근 X

• Component는 다른 Component에 직접 접근 X

• Entity별로 Controller들 업데이트

Entity별로 Action Queue 처리

Component별로 업데이트

다시 정리해보면

Entity:: Update

Controller

Entity:: Update Action

Component System:: Update

업데이트 순서

Game Loop

Set up

Thread0 Thread1 Thread2 Thread3

Set up

Thread0 Thread1 Thread2 Thread3

Set up

Thread0 Thread1 Thread2 Thread3

Process Result

Controller

Action

Component

유연한 컨텐츠 개발을 위해서

무조건 데이터 드리븐 X

컨텐츠와 컨텐츠가 아닌 것 분리

기능별로 모듈화

최대한 응집성이 떨어지지 않게

수치 데이터 + 로직 모듈 + 모듈 조합 스크립트 = 데이터드리븐

감사합니다 (Q&A)

top related