BUT MainWindow also needs a reference to GraphicsEngine because, in its WndProc, it checks for resizing messages and has to:
1) Check if id3d11Device is in a valid state.
2) Call GraphicsEngine::OnResize() depending on the message.
Sort of like:
Code: Select all
// WM_SIZE is sent when the user resizes the window.
case WM_SIZE :
...
if( mGfx && mGfx->isD3DDeviceValid() )
{
...
else if( wParam == SIZE_MAXIMIZED )
{
mAppPaused = false ;
mMinimized = false ;
mMaximized = true ;
mGfx->OnResize() ;
}
...
My temporary solution that "I had a bad feeling about" was to:
1) Have MainWindow store a pointer to GraphicsEngine.
2) Implement a method called "SetGfx( GraphicsEngine* gfx ) in MainWindow".
3) Have the Framework call SetGfx() after initializing both GraphicsEngine and MainWindow&.
This way Framework sets MainWindow::GraphicsEngine* mGfx.
To sum up:
Code: Select all
class MainWindow
{
public :
void SetGfx( GraphicsEngine* gfx ) { mGfx = gfx ; }
private :
GraphicsEngine* mGfx ;
}
class Framework
{
public :
Framework( MainWindow& wnd ) :
mWnd( wnd ),
mGfx( wnd, ... ),
...
{
mWnd.SetGfx( &mGfx ) ;
}
private :
MainWindow& mWnd ;
GraphicsEngine mGfx ;
}
Then I decided to use https://en.wikipedia.org/wiki/Observer_pattern. I made MainWindow store two Observable objects for 1) d3d11Device validity check, 2) OnResize() requests. I registered the GraphicsEngine (now a child of Observer) to those Observable objects in Framework constructor and finally, in WndProc(), I substituted the d3d11Device check and OnResize() calls with their respective Observable objects' OnNotify() calls.
I'm too lazy to share the new code but briefly, if the parameter to OnNotify( void* data = nullptr ) is left blank (defaults to nullptr), GraphicsEngine assumes an OnResize() call was requested, else it reinterprets the data to be the address of a boolean variable and fills that with (md3dDevice != nullptr).
Which solution makes sense ? Or do any of them make sense at all ? How would you gentlemen or ladies solve this dilemma ?
P.S: Now that I think about it, does a game nowadays really need resizing support