SlideShare a Scribd company logo
1 of 16
Download to read offline
경량 Flyweight
게임 프로그래밍 패턴
이데아 게임즈 손진화
숲에 들어갈 나무들
한 그루의 나무에 필요한 데이터
 줄기, 가지, 잎의 형태를 나타내는 폴리곤 메시
 나무 껍질과 잎사귀 텍스처
 숲에서의 위치와 방향
 각각의 나무가 다르게 보이도록 크기와 음영 같은
값을 조절할 수 있는 매개변수
숲에 들어갈 나무들
메모리를 절약할 방법이
없을까?
숲에 들어갈 나무들
 실제 나무 객체는 중복된 데이터가 있을 것이다
(모델링, 텍스쳐)
 중복되는 데이터와 객체 별로 고유한 데이터를
분리해보자
숲에 들어갈 나무들
이제 Tree객체는 공유 데이터는 참조하기만 하고
고유한 데이터만 가지고 있다
Instanced rendering
 한 번의 드로우 콜로 같은 객체를 여러 개
그리는 방식
 GPU에 데이터 전송 시 공유 데이터와 고유 데이터
를 분리해서 보내기 때문에 전송 되는 데이터 양이
적어진다
 그래픽 카드나 API에서
지원하고 있음
경량 패턴
 어떤 객체의 개수가 너무 많아서 좀 더 가볍게
만들고 싶을 때 사용한다
 객체 데이터를 공유 데이터와 고유 데이터로 분리
 공유 데이터
고유상태(intrinsic state), 자유문맥(context-free)
 고유 데이터
외부상태(extrinsic state)
지형 정보
 지형을 타일 기반으로 구현
 각 지형에 필요한 속성
- 플레이어가 얼마나 빠르게 이동할 수 있는지 이동
비용 값
- 강이나 바다처럼 보트로 건너갈 수 있는 곳인지
여부
- 렌더링할 때 사용할 텍스쳐
지형 정보 구현1
지형 정보를 World 클래스
내의 여러 곳에서 처리하고
있다 (개선 필요)
지형 정보 구현2
지형 정보 구현2
 모든 Terrain 인스턴스는 3가지의 값 중 하나를
가지게 될 것 이다
 메모리를 절약하는 방향으로 개선이 필요함
지형 정보 구현3
지형 정보 구현3
공유 객체의 생명주기를
안전하게 관리하기 위해
Wolrd 클래스 내에
선언하고 지형정보를
초기화 한다
성능에 대해서
 공유 객체에 접근하려면 포인터를 거쳐서 접근해야
되기 때문에 캐시 미스가 자주 일어난다면 성능이
떨어질 수는 있지만 측정해본 결과 성능이 크게 떨
어지거나 하지는 않았다
테스트 코드 : https://git.io/vwkEL
성능에 대해서
 경량 패턴을 사용하면 객체를 마구 늘리지
않으면서도 객체지향 방식의 장점을 취할 수 있다
 열거형을 선언해 수많은 switch문을 만들
생각이라면 경량 패턴을 고려해 보자
관련 자료
 어떤 경량 객체가 실제 필요한지 예측 할 수 없다면
필요할 때 만드는 것이 좋은데 객체 생성과정을
숨기고 싶다면 팩토리 메소드 패턴을 활용
 경량 객체를 중복으로 생성하지 않으려면 이미 생성
한 객체를 관리하고 있어야 한다 이때 객체 풀 패턴
(19장)을 활용
 상태 패턴(7장)을 쓸 때 각 상태를 처리하는 클래스
는 멤버 변수가 하나도 없는 경우가 종종 있는데
이때 경량 패턴 활용

More Related Content

Similar to 게임 프로그래밍 패턴 3장

DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)beom kyun choi
 
[Unite2015 박민근] 유니티 최적화 테크닉 총정리
[Unite2015 박민근] 유니티 최적화 테크닉 총정리[Unite2015 박민근] 유니티 최적화 테크닉 총정리
[Unite2015 박민근] 유니티 최적화 테크닉 총정리MinGeun Park
 
[Gpg2권 박민근] 1.21 3ds max 스킨 익스포터 및 애니메이션 툴킷
[Gpg2권 박민근] 1.21 3ds max 스킨 익스포터 및 애니메이션 툴킷[Gpg2권 박민근] 1.21 3ds max 스킨 익스포터 및 애니메이션 툴킷
[Gpg2권 박민근] 1.21 3ds max 스킨 익스포터 및 애니메이션 툴킷MinGeun Park
 
06_게임엔진 활용팁
06_게임엔진 활용팁06_게임엔진 활용팁
06_게임엔진 활용팁noerror
 
NDC 2016, [슈판워] 맨땅에서 데이터 분석 시스템 만들어나가기
NDC 2016, [슈판워] 맨땅에서 데이터 분석 시스템 만들어나가기NDC 2016, [슈판워] 맨땅에서 데이터 분석 시스템 만들어나가기
NDC 2016, [슈판워] 맨땅에서 데이터 분석 시스템 만들어나가기Wonha Ryu
 
[데브루키]노대영_프린이를 위하여(프로그래밍 어린이)
[데브루키]노대영_프린이를 위하여(프로그래밍 어린이)[데브루키]노대영_프린이를 위하여(프로그래밍 어린이)
[데브루키]노대영_프린이를 위하여(프로그래밍 어린이)대영 노
 
임태현, MMO 서버 개발 포스트 모템, NDC2012
임태현, MMO 서버 개발 포스트 모템, NDC2012임태현, MMO 서버 개발 포스트 모템, NDC2012
임태현, MMO 서버 개발 포스트 모템, NDC2012devCAT Studio, NEXON
 
디자인패턴 1~13
디자인패턴 1~13디자인패턴 1~13
디자인패턴 1~13Shin heemin
 
Head first디자인패턴 1~13_희민_호준
Head first디자인패턴 1~13_희민_호준Head first디자인패턴 1~13_희민_호준
Head first디자인패턴 1~13_희민_호준HoJun Sung
 
객체지향 개념 (쫌 아는체 하기)
객체지향 개념 (쫌 아는체 하기)객체지향 개념 (쫌 아는체 하기)
객체지향 개념 (쫌 아는체 하기)Seung-June Lee
 
게임 개체 팩토리
게임 개체 팩토리게임 개체 팩토리
게임 개체 팩토리종규 우
 
게임 프로그래밍 패턴 20장
게임 프로그래밍 패턴 20장게임 프로그래밍 패턴 20장
게임 프로그래밍 패턴 20장진화 손
 
[Cygnus] grid component
[Cygnus] grid component[Cygnus] grid component
[Cygnus] grid componentHwa-young Lee
 
[NDC 2014] 던전앤파이터 클라이언트 로딩 최적화
[NDC 2014] 던전앤파이터 클라이언트 로딩 최적화[NDC 2014] 던전앤파이터 클라이언트 로딩 최적화
[NDC 2014] 던전앤파이터 클라이언트 로딩 최적화Jaeseung Ha
 
NoSQL 간단한 소개
NoSQL 간단한 소개NoSQL 간단한 소개
NoSQL 간단한 소개Wonchang Song
 
05_동기화_개요
05_동기화_개요05_동기화_개요
05_동기화_개요noerror
 
[Gpg1권 박민근] 1.0 1.4 요약 정리
[Gpg1권 박민근] 1.0 1.4 요약 정리[Gpg1권 박민근] 1.0 1.4 요약 정리
[Gpg1권 박민근] 1.0 1.4 요약 정리MinGeun Park
 

Similar to 게임 프로그래밍 패턴 3장 (20)

DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)
 
[Unite2015 박민근] 유니티 최적화 테크닉 총정리
[Unite2015 박민근] 유니티 최적화 테크닉 총정리[Unite2015 박민근] 유니티 최적화 테크닉 총정리
[Unite2015 박민근] 유니티 최적화 테크닉 총정리
 
[Gpg2권 박민근] 1.21 3ds max 스킨 익스포터 및 애니메이션 툴킷
[Gpg2권 박민근] 1.21 3ds max 스킨 익스포터 및 애니메이션 툴킷[Gpg2권 박민근] 1.21 3ds max 스킨 익스포터 및 애니메이션 툴킷
[Gpg2권 박민근] 1.21 3ds max 스킨 익스포터 및 애니메이션 툴킷
 
엑셀왕국
엑셀왕국엑셀왕국
엑셀왕국
 
Gpg1
Gpg1Gpg1
Gpg1
 
06_게임엔진 활용팁
06_게임엔진 활용팁06_게임엔진 활용팁
06_게임엔진 활용팁
 
NDC 2016, [슈판워] 맨땅에서 데이터 분석 시스템 만들어나가기
NDC 2016, [슈판워] 맨땅에서 데이터 분석 시스템 만들어나가기NDC 2016, [슈판워] 맨땅에서 데이터 분석 시스템 만들어나가기
NDC 2016, [슈판워] 맨땅에서 데이터 분석 시스템 만들어나가기
 
[데브루키]노대영_프린이를 위하여(프로그래밍 어린이)
[데브루키]노대영_프린이를 위하여(프로그래밍 어린이)[데브루키]노대영_프린이를 위하여(프로그래밍 어린이)
[데브루키]노대영_프린이를 위하여(프로그래밍 어린이)
 
React js 1
React js   1React js   1
React js 1
 
임태현, MMO 서버 개발 포스트 모템, NDC2012
임태현, MMO 서버 개발 포스트 모템, NDC2012임태현, MMO 서버 개발 포스트 모템, NDC2012
임태현, MMO 서버 개발 포스트 모템, NDC2012
 
디자인패턴 1~13
디자인패턴 1~13디자인패턴 1~13
디자인패턴 1~13
 
Head first디자인패턴 1~13_희민_호준
Head first디자인패턴 1~13_희민_호준Head first디자인패턴 1~13_희민_호준
Head first디자인패턴 1~13_희민_호준
 
객체지향 개념 (쫌 아는체 하기)
객체지향 개념 (쫌 아는체 하기)객체지향 개념 (쫌 아는체 하기)
객체지향 개념 (쫌 아는체 하기)
 
게임 개체 팩토리
게임 개체 팩토리게임 개체 팩토리
게임 개체 팩토리
 
게임 프로그래밍 패턴 20장
게임 프로그래밍 패턴 20장게임 프로그래밍 패턴 20장
게임 프로그래밍 패턴 20장
 
[Cygnus] grid component
[Cygnus] grid component[Cygnus] grid component
[Cygnus] grid component
 
[NDC 2014] 던전앤파이터 클라이언트 로딩 최적화
[NDC 2014] 던전앤파이터 클라이언트 로딩 최적화[NDC 2014] 던전앤파이터 클라이언트 로딩 최적화
[NDC 2014] 던전앤파이터 클라이언트 로딩 최적화
 
NoSQL 간단한 소개
NoSQL 간단한 소개NoSQL 간단한 소개
NoSQL 간단한 소개
 
05_동기화_개요
05_동기화_개요05_동기화_개요
05_동기화_개요
 
[Gpg1권 박민근] 1.0 1.4 요약 정리
[Gpg1권 박민근] 1.0 1.4 요약 정리[Gpg1권 박민근] 1.0 1.4 요약 정리
[Gpg1권 박민근] 1.0 1.4 요약 정리
 

More from 진화 손

C++20 Remove std::weak_equality and std::strong_equality.pdf
C++20 Remove std::weak_equality and std::strong_equality.pdfC++20 Remove std::weak_equality and std::strong_equality.pdf
C++20 Remove std::weak_equality and std::strong_equality.pdf진화 손
 
C++20 std::execution::unseq.pdf
C++20 std::execution::unseq.pdfC++20 std::execution::unseq.pdf
C++20 std::execution::unseq.pdf진화 손
 
C++ 20 class template argument deduction for alias templates
C++ 20 class template argument deduction for alias templatesC++ 20 class template argument deduction for alias templates
C++ 20 class template argument deduction for alias templates진화 손
 
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...C++ 20 Make stateful allocator propagation more consistent for operator+(basi...
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...진화 손
 
C++ 20 Unevaluated asm-declaration in constexpr functions
C++ 20 Unevaluated asm-declaration in constexpr functionsC++ 20 Unevaluated asm-declaration in constexpr functions
C++ 20 Unevaluated asm-declaration in constexpr functions진화 손
 
C++20 Utility functions to implement uses-allocator construction.pdf
C++20 Utility functions to implement uses-allocator construction.pdfC++20 Utility functions to implement uses-allocator construction.pdf
C++20 Utility functions to implement uses-allocator construction.pdf진화 손
 
C++ 20 std__reference_wrapper for incomplete types
C++ 20 std__reference_wrapper for incomplete typesC++ 20 std__reference_wrapper for incomplete types
C++ 20 std__reference_wrapper for incomplete types진화 손
 
C++ 20 Stronger Unicode requirements
C++ 20 Stronger Unicode requirementsC++ 20 Stronger Unicode requirements
C++ 20 Stronger Unicode requirements진화 손
 
C++20 Concepts library
C++20 Concepts libraryC++20 Concepts library
C++20 Concepts library진화 손
 
C++20 Coroutine
C++20 CoroutineC++20 Coroutine
C++20 Coroutine진화 손
 
C++ 20 Relaxing the range-for loop customization point finding rules
C++ 20 Relaxing the range-for loop customization point finding rulesC++ 20 Relaxing the range-for loop customization point finding rules
C++ 20 Relaxing the range-for loop customization point finding rules진화 손
 
C++ 20 Relaxing the structured bindings customization point finding rules
C++ 20 Relaxing the structured bindings customization point finding rulesC++ 20 Relaxing the structured bindings customization point finding rules
C++ 20 Relaxing the structured bindings customization point finding rules진화 손
 
C++20 explicit(bool)
C++20 explicit(bool)C++20 explicit(bool)
C++20 explicit(bool)진화 손
 
C++20 std::map::contains
C++20 std::map::containsC++20 std::map::contains
C++20 std::map::contains진화 손
 
C++20 Comparing unordered containers
C++20 Comparing unordered containersC++20 Comparing unordered containers
C++20 Comparing unordered containers진화 손
 
C++20 Attributes [[likely]] and [[unlikely]]
C++20 Attributes [[likely]] and [[unlikely]]C++20 Attributes [[likely]] and [[unlikely]]
C++20 Attributes [[likely]] and [[unlikely]]진화 손
 
C++ 20 Lambdas in unevaluated contexts
C++ 20 Lambdas in unevaluated contextsC++ 20 Lambdas in unevaluated contexts
C++ 20 Lambdas in unevaluated contexts진화 손
 
C++20 Library support for operator<=> <compare>
C++20 Library support for operator<=> <compare>C++20 Library support for operator<=> <compare>
C++20 Library support for operator<=> <compare>진화 손
 
C++20 Atomic std::shared_ptr and std::weak_ptr
C++20 Atomic std::shared_ptr and std::weak_ptrC++20 Atomic std::shared_ptr and std::weak_ptr
C++20 Atomic std::shared_ptr and std::weak_ptr진화 손
 
C++20 Default member initializers for bit-fields
C++20 Default member initializers for bit-fieldsC++20 Default member initializers for bit-fields
C++20 Default member initializers for bit-fields진화 손
 

More from 진화 손 (20)

C++20 Remove std::weak_equality and std::strong_equality.pdf
C++20 Remove std::weak_equality and std::strong_equality.pdfC++20 Remove std::weak_equality and std::strong_equality.pdf
C++20 Remove std::weak_equality and std::strong_equality.pdf
 
C++20 std::execution::unseq.pdf
C++20 std::execution::unseq.pdfC++20 std::execution::unseq.pdf
C++20 std::execution::unseq.pdf
 
C++ 20 class template argument deduction for alias templates
C++ 20 class template argument deduction for alias templatesC++ 20 class template argument deduction for alias templates
C++ 20 class template argument deduction for alias templates
 
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...C++ 20 Make stateful allocator propagation more consistent for operator+(basi...
C++ 20 Make stateful allocator propagation more consistent for operator+(basi...
 
C++ 20 Unevaluated asm-declaration in constexpr functions
C++ 20 Unevaluated asm-declaration in constexpr functionsC++ 20 Unevaluated asm-declaration in constexpr functions
C++ 20 Unevaluated asm-declaration in constexpr functions
 
C++20 Utility functions to implement uses-allocator construction.pdf
C++20 Utility functions to implement uses-allocator construction.pdfC++20 Utility functions to implement uses-allocator construction.pdf
C++20 Utility functions to implement uses-allocator construction.pdf
 
C++ 20 std__reference_wrapper for incomplete types
C++ 20 std__reference_wrapper for incomplete typesC++ 20 std__reference_wrapper for incomplete types
C++ 20 std__reference_wrapper for incomplete types
 
C++ 20 Stronger Unicode requirements
C++ 20 Stronger Unicode requirementsC++ 20 Stronger Unicode requirements
C++ 20 Stronger Unicode requirements
 
C++20 Concepts library
C++20 Concepts libraryC++20 Concepts library
C++20 Concepts library
 
C++20 Coroutine
C++20 CoroutineC++20 Coroutine
C++20 Coroutine
 
C++ 20 Relaxing the range-for loop customization point finding rules
C++ 20 Relaxing the range-for loop customization point finding rulesC++ 20 Relaxing the range-for loop customization point finding rules
C++ 20 Relaxing the range-for loop customization point finding rules
 
C++ 20 Relaxing the structured bindings customization point finding rules
C++ 20 Relaxing the structured bindings customization point finding rulesC++ 20 Relaxing the structured bindings customization point finding rules
C++ 20 Relaxing the structured bindings customization point finding rules
 
C++20 explicit(bool)
C++20 explicit(bool)C++20 explicit(bool)
C++20 explicit(bool)
 
C++20 std::map::contains
C++20 std::map::containsC++20 std::map::contains
C++20 std::map::contains
 
C++20 Comparing unordered containers
C++20 Comparing unordered containersC++20 Comparing unordered containers
C++20 Comparing unordered containers
 
C++20 Attributes [[likely]] and [[unlikely]]
C++20 Attributes [[likely]] and [[unlikely]]C++20 Attributes [[likely]] and [[unlikely]]
C++20 Attributes [[likely]] and [[unlikely]]
 
C++ 20 Lambdas in unevaluated contexts
C++ 20 Lambdas in unevaluated contextsC++ 20 Lambdas in unevaluated contexts
C++ 20 Lambdas in unevaluated contexts
 
C++20 Library support for operator<=> <compare>
C++20 Library support for operator<=> <compare>C++20 Library support for operator<=> <compare>
C++20 Library support for operator<=> <compare>
 
C++20 Atomic std::shared_ptr and std::weak_ptr
C++20 Atomic std::shared_ptr and std::weak_ptrC++20 Atomic std::shared_ptr and std::weak_ptr
C++20 Atomic std::shared_ptr and std::weak_ptr
 
C++20 Default member initializers for bit-fields
C++20 Default member initializers for bit-fieldsC++20 Default member initializers for bit-fields
C++20 Default member initializers for bit-fields
 

게임 프로그래밍 패턴 3장

  • 1. 경량 Flyweight 게임 프로그래밍 패턴 이데아 게임즈 손진화
  • 2. 숲에 들어갈 나무들 한 그루의 나무에 필요한 데이터  줄기, 가지, 잎의 형태를 나타내는 폴리곤 메시  나무 껍질과 잎사귀 텍스처  숲에서의 위치와 방향  각각의 나무가 다르게 보이도록 크기와 음영 같은 값을 조절할 수 있는 매개변수
  • 3. 숲에 들어갈 나무들 메모리를 절약할 방법이 없을까?
  • 4. 숲에 들어갈 나무들  실제 나무 객체는 중복된 데이터가 있을 것이다 (모델링, 텍스쳐)  중복되는 데이터와 객체 별로 고유한 데이터를 분리해보자
  • 5. 숲에 들어갈 나무들 이제 Tree객체는 공유 데이터는 참조하기만 하고 고유한 데이터만 가지고 있다
  • 6. Instanced rendering  한 번의 드로우 콜로 같은 객체를 여러 개 그리는 방식  GPU에 데이터 전송 시 공유 데이터와 고유 데이터 를 분리해서 보내기 때문에 전송 되는 데이터 양이 적어진다  그래픽 카드나 API에서 지원하고 있음
  • 7. 경량 패턴  어떤 객체의 개수가 너무 많아서 좀 더 가볍게 만들고 싶을 때 사용한다  객체 데이터를 공유 데이터와 고유 데이터로 분리  공유 데이터 고유상태(intrinsic state), 자유문맥(context-free)  고유 데이터 외부상태(extrinsic state)
  • 8. 지형 정보  지형을 타일 기반으로 구현  각 지형에 필요한 속성 - 플레이어가 얼마나 빠르게 이동할 수 있는지 이동 비용 값 - 강이나 바다처럼 보트로 건너갈 수 있는 곳인지 여부 - 렌더링할 때 사용할 텍스쳐
  • 9. 지형 정보 구현1 지형 정보를 World 클래스 내의 여러 곳에서 처리하고 있다 (개선 필요)
  • 11. 지형 정보 구현2  모든 Terrain 인스턴스는 3가지의 값 중 하나를 가지게 될 것 이다  메모리를 절약하는 방향으로 개선이 필요함
  • 13. 지형 정보 구현3 공유 객체의 생명주기를 안전하게 관리하기 위해 Wolrd 클래스 내에 선언하고 지형정보를 초기화 한다
  • 14. 성능에 대해서  공유 객체에 접근하려면 포인터를 거쳐서 접근해야 되기 때문에 캐시 미스가 자주 일어난다면 성능이 떨어질 수는 있지만 측정해본 결과 성능이 크게 떨 어지거나 하지는 않았다 테스트 코드 : https://git.io/vwkEL
  • 15. 성능에 대해서  경량 패턴을 사용하면 객체를 마구 늘리지 않으면서도 객체지향 방식의 장점을 취할 수 있다  열거형을 선언해 수많은 switch문을 만들 생각이라면 경량 패턴을 고려해 보자
  • 16. 관련 자료  어떤 경량 객체가 실제 필요한지 예측 할 수 없다면 필요할 때 만드는 것이 좋은데 객체 생성과정을 숨기고 싶다면 팩토리 메소드 패턴을 활용  경량 객체를 중복으로 생성하지 않으려면 이미 생성 한 객체를 관리하고 있어야 한다 이때 객체 풀 패턴 (19장)을 활용  상태 패턴(7장)을 쓸 때 각 상태를 처리하는 클래스 는 멤버 변수가 하나도 없는 경우가 종종 있는데 이때 경량 패턴 활용