Project/Win32API로 던그리드 모작
더블버퍼링
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { HDC hDC; PAINTSTRUCT ps; // ... switch (uMsg) { // ... case WM_PAINT: hDC = BeginPaint(hWnd, &ps); BackBuffer.Draw(hDC); EndPaint(hWnd, &ps); break; // ... } // ... } Colored by Color Scripter cs WM_PAINT 메시지가 발생할 때마다 DC에 새롭게 그림을 그리면 기존의 그림을 비우고 새로운 그림을 그리기까지의 시간이 있기 때문에 flickering 현상이 나타난다 BackBuffer에 그림을 미리 그려 놓고, D..
싱글톤 패턴
https://jartlife.tistory.com/52 타이머 - 프레임 관리 게임의 동작 게임은 일정 시간 간격마다 사용자 입력을 처리하고 객체들을 업데이트한 뒤 객체들을 렌더링한다. 따라서 게임에서 타이머의 역할은 매우 중요하다. 게임의 거의 모든 기반이 타 jartlife.tistory.com 위 글에서 복잡한 디자인 패턴 없이 싱글톤을 구현했다. 위 글에서 사용한 방법이 훨씬 더 나은 방법이라 생각되지만, 이 글에서 구현한 싱글톤 패턴이 불가피할 상황이 있을지도 모르므로 글은 남겨둔다. // singleton.h #ifndef _singleton #define _singleton template class Singleton { public: static auto& getinst() { stati..
좌표 변환
// xyutility.h #ifndef _xyutility #define _xyutility #include auto xytrans(const RECT& destrt, const RECT& srcrt, const POINT& pt) { auto xdiff = pt.x - srcrt.left; auto ydiff = pt.y - srcrt.top; auto widthratio = (destrt.right - destrt.left) / static_cast(srcrt.right - srcrt.left); auto heightratio = (destrt.bottom - destrt.top) / static_cast(srcrt.bottom - srcrt.top); // windows.h의 POINT는 LONG..