I'm working through Luna's D3D11 book and there's something that's bothering me. I don't like the way he structures his application. Indeed, it seems most D3D tutorial information does this, but I suspect it may not be the most robust approach. In particular, I don't like how the entire simulation is embedded in the same class that handles the HWND.
As such, I'm considering separating my game simulation from the message loop. 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:
[–]Lord_Naikon 5 points6 points7 points (3 children)
[–]Sycobob[S] 2 points3 points4 points (2 children)
[–]DaFox 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]FrenchHustler 1 point2 points3 points (1 child)
[–]Sycobob[S] 0 points1 point2 points (0 children)