์์ :) https://github.com/eazuooz/WindowAPI/tree/ccd364e29392d46b4bfa76bcc4268d49eace278e
GitHub - eazuooz/WindowAPI
Contribute to eazuooz/WindowAPI development by creating an account on GitHub.
github.com
์ค์ง ํ๊ฐ์ ์ธ์คํด์ค๋ง ๊ฐ๋๋ก ๋ณด์ฅํ๊ณ , ์ด์ ๋ํ ์ ์ญ์ ์ธ ์ ๊ทผ์ ์ ์ ๊ณตํฉ๋๋ค.
(GOF์ ๋์์ธ ํจํด 181p)
Gof์ ์ฑ๊ธํด ํจํด์ ์๋์ ๋ฌ๋ฆฌ ๋๋ณด๋ค๋ ์ค์ด ๋ง๋ค. Gof๋ ์ฑ๊ธํด ํจํด์ ๋จ์ฉํ์ง ๋ง๋ผ๊ณ ๊ฐ์กฐ ํ์ง๋ง, ๊ฐ๋ฐ์๋ค ์ค์์ ๊ท๋ด์ ๋ฃ๋ ์ด๋ ๋ง์ง ์๋ค.
๋ค๋ฅธ ํจํด๋ค๋ ๊ทธ๋ ์ง๋ง, ์ฑ๊ธํด์ ๋ถ์ ๋นํ ๊ณณ์ ์ฌ์ฉํ๋ฉด ์ด์์ ๋ถ๋ชฉ์ ๋๋ ๊ฒ๋งํผ์ด๋ ์ธ๋ชจ๊ฐ ์๋ค.
์๋ ๋จ์ฉ ๋๋ ํจํด์ด๋ค ๋ณด๋ ์ฑ๊ธํด์ ํผํ ๋ฐฉ๋ฒ์ ์ฃผ๋ก ๋ค๋ฃจ๊ฒ ์ง๋ง, ๊ทธ๋๋ ์ฐ์ ์ ์ฑ๊ธํด ํจํด์ ๋ํด ์ดํด๋ณด์.
//์ฒซ๋ฒ์งธ ์
class FileSystem
{
public:
static FileSystem& instance()
{
if(instance_ NULL) {
instance_ = new FileSystem();
}
return *instance_;
}
private:
FileSystem() {}
static FileSystem* instance_;
}
//๋๋ฒ์งธ ์
class FileSystem
{
public:
static FileSystem& instance()
{
static FileSystem* instance = new FileSystem();
return *instance;
}
private:
FileSystem() {}
}
์ถ์ฒ: https://boycoding.tistory.com/109 [์๋
์ฝ๋ฉ:ํฐ์คํ ๋ฆฌ]
class Application
{
public:
static Application& GetInstance()
{
if (mDestroyed)
{
new(mInstance) Application();
atexit(KillApplication);
mDestroyed = false;
}
else if (mInstance == nullptr)
{
Create();
}
return *mInstance;
}
private:
Application() {}
Application(const Application& other) {}
~Application() { mDestroyed = true; }
static void Create()
{
static Application instance;
mInstance = &instance;
}
static void KillApplication()
{
mInstance->~Application();
}
static Application* mInstance;
static bool mDestroyed;
};
์ ์ญ์ ์ธ ์ ๊ทผ์ ์ ์ ๊ณต
๋ก๊น , ์ฝํ ์ธ ๋ก๋ฉ, ๊ฒ์ ์ ์ฅ๋ฑ ์ฌ๋ฌ ๋ด๋ถ ์์คํ ์์ ํ์ผ ์์คํ ๋ ํผ ํด๋์ค๋ฅผ ์ฌ์ฉํ ๊ฒ์ด๋ค. ์ด๋ค ์์คํ ์์ ํ์ผ ์์คํ ํด๋์ค ์ธ์คํด์ค๋ฅผ ๋ฐ๋ก ์์ฑํ ์ ์์ผ๋ฏ๋ก ์ฑ๊ธํด ํจํด์ ํ๋์ ์ธ์คํด์ค๋ง ์์ฑํ๋ ๊ฒ์ ๋ํด์, ๊ทธ ์ธ์คํด์ค๋ฅผ ์ ์ญ์์ ์ ๊ทผํ ์ ์๋ ๋ฉ์๋๋ฅผ ์ ๊ณตํ๋ค.
์ฑ๊ธํด์ ์ ์ฌ์ฉํ๋๊ฐ?
1. ํ๋ฒ๋ ์ฌ์ฉํ์ง ์๋๋ค๋ฉด ์์ ์ธ์คํด์ค๋ฅผ ์์ฑํ์ง ์๋๋ค.
2. ๋ฐํ์์ ์ด๊ธฐํ๋๋ค.
3. ์ฑ๊ธํด์ ์์ํ ์ ์๋ค.
์ด์ ์ฐ๋ฆฌ ๊ฒ์ ์์ง์ ํ๋ ์์ํฌ๋ฅผ ์ฑ๊ธํด ํจํด์ ์ด์ฉํด์ ๋ง๋ค์ด๋ณด์.
์์ง์ ์ค๊ณ ํ๊ธฐ์ ์์ ์์ฃผ ์ฌ์ฉํด์ผํ ๋ฐ์ดํฐํ์ ๋ค์ ๋ค์์คํ์ด์ค, ๊ทธ๋ฆฌ๊ณ ์๋ฃํ๋ค์ ๋ฏธ๋ฆฌ ์ ์ธํด๋๋ ค๊ณ ํ๋ค.
Common.h ํ์ผ์ ์์ฑํ๊ณ ํด๋น ํด๋์ค์์ ์์ฃผ ์ฌ์ฉ ๋๋ STL๊ณผ ์ฌ๋ฌ๊ฐ์ง ๋ฐ์ดํฐ ํ์ ๋ค์ ์ ์ธํด๋์๋ค.
#pragma once
#include "framework.h"
#include <string>
#include <vector>
#include <list>
#include <map>
using std::vector;
using std::list;
using std::map;
using std::make_pair;
using std::string;
using std::wstring;
struct WindowImplData
{
HWND hWnd;
HDC hdc;
UINT height;
UINT width;
void Clear()
{
hWnd = NULL;
hdc = NULL;
height = 0;
width = 0;
}
};
struct Vector2
{
float y;
float x;
};
using Pos = POINT;
์ฐ๋ฆฌ์ ๋ฉ์ธ ํ๋ก๊ทธ๋จ Application ํ๋ก๊ทธ๋จ์ด๋ค.
#pragma once
#include "Common.h"
// ์ฐ๋ฆฌ์ ๋ฉ์ธ ํ๋ก๊ทธ๋จ
// Singleton patten
namespace ya
{
class Application
{
public:
static Application& GetInstance()
{
if (mInstance == nullptr)
{
mInstance = new Application();
}
return *mInstance;
}
Application();
~Application();
void Initialize(WindowImplData data);
void Tick();
private:
static Application* mInstance;
static int mIsStatic;
WindowImplData mWindowData;
};
}
Initialize ํจ์์์ ์ด๊ธฐํ์์ ํ์ํ ๋ฐ์ดํฐ๋ค์ ์ธํ ํด์ค๋ค.
Tick() ํจ์๋ main ํจ์์์ ์ฐ๋ฆฌ๊ฐ GetMessage๊ตฌ์กฐ๋ฅผ ๋ณ๊ฒฝํ ๋ถ๋ถ์ธ PeekMessage์ ๊ฒ์ ์คํ๋ถ๋ถ์์
๋งค ํ๋ ์๋ง๋ค ์คํ๋ ๊ฒ์ด๋ค.
while(true)
{
if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
{
if (WM_QUIT == msg.message)
break;
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
{
// ๊ฒ์ ์คํ
ya::Application::GetInstance().Tick();
}
}
๊ทธ๋ฆฌ๊ณ ์ถ๊ฐ์ ์ผ๋ก ์์ผ๋ก ์ฌ์ฉ๋ ๋ชจ๋ ๊ฐ์ฒด์์ ์ฌ์ฉ๋ Entity ํด๋์ค๋ฅผ ์ ์ธํ๋ค.
์ด๋ฆ์ด ํ์ํ ๋ชจ๋ ํ๋ก๊ทธ๋จ๋ด์์ ํ ๋น๋ ๊ฐ์ฒด๋ค์ ์ด Entity ํด๋์ค๋ฅผ ์์๋ฐ์ ์ฌ์ฉํ ๊ฒ์ด๋ค.
Entity ํด๋์ค๋ ๊ณตํต์ ์ผ๋ก Class๋ก ์ ์ธ๋ ์๋ฃํ๋ค์ด ์ฌ์ฉํ ๋ฐ์ดํฐ๋ค์ ๊ฐ์ง๊ณ ์์ ๊ฒ์ด๋ค.
์ : ์ด๋ฆ, ๊ฒฝ๋ก, ๋ฐ์ดํฐ ํฌ๊ธฐ๋ฑ
#pragma once
#include "Common.h"
namespace ya
{
class Entity
{
public:
Entity();
virtual ~Entity();
void SetName(const wstring& name) { mName = name; }
const wstring& GetName() { return mName; }
private:
wstring mName;
};
}
Object๋ ์ฐ๋ฆฌ ๊ฒ์์์ ํ๋ฉด์์ ๋๋ํ๋ผ ๋ชจ๋ ๋ฌผ์ฒด๋ฅผ ํ๋์ Object๋ผ๊ณ ์ ์ ํ๊ฒ ๋ค.
ํ๋ ์ด์ด, ๋ชฌ์คํฐ, UI ๋ฑ๋ฑ ์ถ๊ฐ๋ก ๋์ ๋ณด์ด์ง ์๋ Timer๋ ๋ชฌ์คํฐ ์คํฐ์ ๋์์ฃผ๋ Class๋ก ๋ง๋ค์ด์ง ๊ฐ์ฒด๋ฑ ๋์ ๋ณด์ง์ด ์๋๊ฒ๋ ํ๋์ ๊ฐ์ฒด๊ฐ ๋๋ค.
๋ค์๋งํด์ Class๋ก ๋ฉ๋ชจ๋ฆฌ ํ ๋น๋ ์์ด๋ค์ ํ๋์ ๊ฐ์ฒด๋ผ๊ณ ์๊ฐํ๋ฉด ๋๋ค.
๋ณ์๋ฑ์ ์ด์ฉํ์ง ์๊ณ ์ด๋ ๊ฒ ํ๋์ ๊ฐ์ฒด๋จ์๋ก ํ๋ก๊ทธ๋๋ฐ ํ๋ ๋ฐฉ๋ฒ์ ๊ฐ์ฒด์งํฅํ๋ก๊ทธ๋๋ฐ ์ด๋ผ๊ณ ๋งํ๋ค.
์ง๊ธ ๋น์ฅ ๊ฐ์ฒด์งํฅ ํ๋ก๊ทธ๋๋ฐ์ ๊น์ด ์ดํดํ๊ธฐ์๋ ์ด๋ ค์ฐ๋ ์ด์ ๋๋ง ์๊ณ ๋์ด ๊ฐ๋๋ก ํ์
#pragma once
#include "Common.h"
#include "yaEntity.h"
namespace ya
{
class Object : public Entity
{
public:
Object();
~Object();
private:
Pos mPos;
};
}
๊ตฌ์กฐ๋ฅผ ์ดํดํ๋ค๋ฉด ์์ ๋ฅผ ๋ฐ๋ผ์ ์คํ์์ผ ๋ณด์.
๋ค์๊ณผ ๊ฐ์ด ์ข์ฐ์ํ ๋ฐฉํฅํค๋ฅผ ์ด์ฉํด ํ๋ฉด์ ์ฌ๊ฐํ์ด ์ด๋ํ๋ค๋ฉด ๋ฌธ์ ์์ด ๊ตฌ์กฐ๋ฅผ ์์ฑ์ํจ๊ฒ์ด๋ค.
'๐ Development Study > ๐ป Win32API' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Input (0) | 2022.09.15 |
---|---|
Scene, Object, Time (0) | 2022.09.15 |
FrameWork (1) | 2022.09.07 |
DC์ ์ ๋ณด์์ (0) | 2022.09.06 |
WinMain (2) | 2022.09.05 |
๋๊ธ