• Advertisement
Sign in to follow this  

OOP Design flaw?

This topic is 2682 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

So I have been working on trying to get my game engine to allow the user to go full screen. I understand all the code completely on how to do this but am have problems trying to execute it because of the way my game engine is structured.

My game engine class is initialise my engine and directx, the code looks like this:



void CEngine::Initialise(char *cAppName, int iXPos, int iYPos, int iWidth, int iHeight, int argc, char **argv)
{
c_pPlatform->Initialise(cAppName,iXPos,iYPos,iWidth,iHeight,argc,argv);
c_pRender->Initialise(c_pPlatform);
CLogger::Write("everything has been initialised");


}



so c_pPlatform initialises the window and contains my windows procedure. c_pRender then initialises my directx.

So what I want to do is in the windows procedure class call upon a function in my render class.

Do I need to rethink how my engine is designed or is there some way of doing what I want?

I hope that is clear to follow.

Many Thanks

Share this post


Link to post
Share on other sites
Advertisement
You want to get access to your render class in the window procedure, if I understand you right.

You could just declare a global variable with your renderer. I assume you don't want to do that.

Alternatively, you can use SetWindowLong() to store user data for your window, allowing you to retrieve this data (a pointer to your renderer) in the window procedure, using GetWindowLong().

[Edited by - Konfusius on October 18, 2010 5:11:02 AM]

Share this post


Link to post
Share on other sites
Yes thats exactly what I am trying to do.

So then should I use the SetWindowslong right after I create my window? I can then create a local function inside my CPlatform of which I can call in the windows procedure. Within that function call I then can use getwindowlong and re-set my window and etc.

Will I have access to my direct 3d paramaters because as of my knowledge i need to change them for the fullscreen as well.

Many Thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by agisler
So then should I use the SetWindowslong right after I create my window? I can then create a local function inside my CPlatform of which I can call in the windows procedure. Within that function call I then can use getwindowlong and re-set my window and etc.

Yes, exactly.

Quote:
Will I have access to my direct 3d paramaters because as of my knowledge i need to change them for the fullscreen as well.

That depends entirely on your code/class design. If CPlatform can't access the needed Direct3D parameters, you'll have to find a way to make this data available to CPlatform. Since this will likely be the only (or at least one of very few) reason to expose CRenderer internals to CPlatform, it seems to be an practical and acceptable solution to just declare CPlatform a friend class of CRenderer.

[Edited by - Konfusius on October 18, 2010 10:27:01 AM]

Share this post


Link to post
Share on other sites
Ok. I am a bit lost on how the whole SetWindowlong and GetWindowLong work despite the searching I have done on these function calls.

However I do think i have solved the solution. Don't entirely understand what I have done [wink]. From what I do understand is I have grabbed the instance of the directx class and placed it into a pointer so that I can then call upon the ToggleFullScreen function. Here is my windows procedure now.



LRESULT CALLBACK CPlatform::WindowsProcedure( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
switch ( message )
{
case WM_DESTROY:
PostQuitMessage( 0 );
return 0;
case WM_KEYDOWN:
switch ( wParam )
{
case VK_ESCAPE:
PostQuitMessage( 0 );
break;
case VK_RETURN:
CDirectx *c_pDirectx=CDirectx::Instance();
c_pDirectx->ToggleFullscreen();
break;
}
return 0;
}
return DefWindowProc( hWnd, message, wParam, lParam );
}



The CEngine class initializes CRender of which CRender then initializes my CDirectx class.

I have not declared CDirectx or CPlatform as a friend class in either one of the classes which is why I am a bit confused on how I can create a directx pointer. I am still new to OOP. [grin]

As always thanks for the help!! [smile]

Share this post


Link to post
Share on other sites
I see that your class design is good (better than one would expect of "OOP newbies" [smile]), so I would just propose the following instead:



LRESULT CALLBACK CPlatform::WindowsProcedure( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
switch ( message )
{
case WM_DESTROY:
PostQuitMessage( 0 );
return 0;
case WM_KEYDOWN:
switch ( wParam )
{
case VK_ESCAPE:
PostQuitMessage( 0 );
break;
case VK_RETURN:
// either this:
// c_pRender->getDirectX()->ToggleFullscreen();
// or better (DirectX not exposed), so:
c_pRender->ToggleFullscreen(); // -> calls c_pDirectX->ToggleFullscreen()
break;
}
return 0;
}
return DefWindowProc( hWnd, message, wParam, lParam );
}


Share this post


Link to post
Share on other sites
Quote:
Original post by Konfusius
I see that your class design is good (better than one would expect of "OOP newbies" [smile]), so I would just propose the following instead:

*** Source Snippet Removed ***


haha thanks. To be fair though I am currently on a placement at a games studio and I have borrowed a lot of the design from them. [smile] I do understand about 90% of how the code works but there is still bits that are fuzzy.

I think your way is better and more consistant with how the rest of engine works. So I will go that way.

Thanks for the help.

@Konfusius - gave you a excellent rating!! [smile]

Edit: It turns out I have to call CRender first otherwise I will no longer have any values in my attributes. This also includes my directx parameters lol

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement