I'm considering separating my game simulation from the message loop. It seems odd to me to have other systems tied directly to the window in which my game is running. Most examples I see are implemented similar to the following (I'm glossing over details here, code is only meant to get the idea across)
... WndProc(...)
{
//PeekMessage
//Update input
//Update timer
//Update simulation
//Update renderer
}
To increase separation of concerns, I'd like to move the update of input, simulation and renderer out of the specific window itself. This seems simple to accomplish
... WinMain(...)
{
//Update window
//Update input
//Update timer
//Update simulation
//Update renderer
}
... WndProc(...)
{
//PeekMessage
}
There is information that must be obtained from the window to be consumed by the rest of the game. Namely, input (if using the message system), window size, window focus, etc. I should be able to use callbacks or passing in references to state objects the window will update to get this information.
This approach allows me to separate each concern into it's own class. The window code is implemented in a Window
class, input in Input
, etc. I can use WinMain
or a Game
class to create each system and coordinate state between them.
Further, it allows me to divorce the renderer from the HWND
itself. It seems smelly to me to have the renderer embedded directly within the Window
. What if something happens to the window? What if I want to use the same renderer to output multiple views into separate windows (via CreateAdditionalSwapChain
)?
The questions that arise from this:
Primary:
- It seems I can just rebuild the swap chain to hook up to a new window. Do scenarios exist where the
HWND
could be invalidated or destroyed but I want to retain my rendering context? Or is this overkill?
Secondary:
Are there flaws to this approach I'm not considering?
Are there better implementations I'm not considering?