PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Custom Game framework

I am just starting to use PF and am having a small problem. I am trying to use an interface type of class (vitual funcs) that will represent a "screen" in my game. There will be one active screen at a time that all of the Game methods will get forwarded to (key, mouse, draw, etc.) For instance I may have screen such as Splash, MainMenu, GameOptions, etc.

What I am having trouble with is that most of the variables/methods that are part of the Game class (m_keys, GetDisplay(), Shutdown(), etc.) are Protected so I cannot access them from any other class except my main game one. I need to get access to these in order to do anything really.

I thought about changing them to public and recompiling PF but then I would have to keep changing it for future releases of PF. So here I am... asking for some input instead!!

My questions...

1. Does anyone know what these were declared Protected in the first place instead of Public (outside of the OOP "rules").

2. Has anyone else created a framework that they use for creating games? If so how did you get around this type of issue?

Thanks for any input!!
i used game_state struct to exchange data between game subclasses. It had enum for current application states. So GameLoop checked it an if it was GS_QUIT called Shutdown
Couldn't you just declare these components as friends of your Game class?
My Globals.h is linked to every cpp file in project. Somewhere in Globals.h:

Code:
extern Pyromania * pPyr;

Where Pyromania is my game class.
In one of .cpp
Code:
_Module.Init( 0, hInstance );
Pyromania game;
pPyr = &game;
game.Run();


After that you can use this pointer in other cpp files.
For example:

Code:
void Menu::MinimizeMe()
{
pPyr->ShowWindow(SW_MINIMIZE);
}


About Shudown- it's not safety to shutdown from any other class than a game class(in the end of loop, after Update).
But if you really need it you can do it without recompilation of PF with a small cheat, just:

Code:
public:
void Pyromania::Exit()
{
Shutdown();
}


So you can now use pPyr->Exit(); in any other class :wink:

Or even this:

Code:
PHAL::KeyList * Pyromania::GiveMeGiveMeYourKeyList()
{
return &m;_keys;
}


ElSeeker wrote:
1. Does anyone know what these were declared Protected in the first place instead of Public (outside of the OOP "rules").

I think it's just to be safety- you will have troubles with quitting Shutdown not in the right place, for example.