-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathapplicationWin32.cpp
68 lines (55 loc) · 1.78 KB
/
applicationWin32.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
ml::ApplicationWin32::ApplicationWin32(HINSTANCE instance, UINT windowWidth, UINT windowHeight, const std::string &name, GraphicsDeviceType graphicsType, ApplicationCallback &callback, unsigned int initWindowPosX, unsigned int initWindowPosY) :
m_callback(callback),
m_window(*this)
{
m_initialized = false;
m_window.init(instance, windowWidth, windowHeight, name, m_callback.msgProcCallback, initWindowPosX, initWindowPosY);
switch(graphicsType)
{
case GraphicsDeviceTypeD3D11:
m_graphics = new D3D11GraphicsDevice();
break;
default:
MLIB_ERROR("invalid graphics device type");
}
m_graphics->init(m_window);
m_data = new ApplicationData(&m_window, m_graphics, &m_input);
m_callback.init(*m_data);
}
ml::ApplicationWin32::~ApplicationWin32()
{
delete m_graphics;
delete m_data;
m_bResizeEvent = false;
}
void ml::ApplicationWin32::messageLoop(bool vsync /*= false*/)
{
bool messageReceived;
MSG msg;
msg.message = WM_NULL;
PeekMessage( &msg, nullptr, 0U, 0U, PM_NOREMOVE );
m_initialized = true;
while( WM_QUIT != msg.message )
{
// Use PeekMessage() so we can use idle time to render the scene.
messageReceived = ( PeekMessage( &msg, nullptr, 0U, 0U, PM_REMOVE ) != 0 );
if( messageReceived )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
if (m_bResizeEvent) {
m_bResizeEvent = false; //not 100% sure if that doesn't lead to a raise condition and may cause resize misses...
data().graphics.resize(data().window);
callback().resize(data());
}
for(int i = 0; i < m_input.keyCount; i++)
if(m_input.keys[i]) m_callback.keyPressed(*m_data, i);
m_graphics->renderBeginFrame();
m_callback.render(*m_data);
m_graphics->renderEndFrame(vsync);
}
}
}