PocketMatrix forums

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

I need your comments: CGDApplication

Hi,

I'm basically done testing and I would like some comments on my new baseclass. The current feature set is:

New Base class : GDApplication!
Features:
- Tested and approved for Stationary PCs, Pocket PCs and Smartphones.
- Support for full screen and windowed DirectDraw modes on Stationary PCs.
- Full support for stylus (down, up, move, doubleclick) and key input (down, up).
- Support for easy to use, dynamic rotation of the display with no performance loss.
- Flexible and easy to use configuration system.
- Multithreaded main loop for time critical operations.
- Full Minimize/Restore functionality with synchronized pause of main loop.
- Hides all notifications in the background.
- FPS lock (the application will always run at constant FPS independent of CPU speed)
- Full source code included

You begin by subclassing CGDApplication, the interface looks like:

Code:
//-----------------------------------------------------------------------------
// Name: class CMyGDApplication
// Desc: Main class to run this application. Most functionality is inherited
// from the CGDApplication base class.
//-----------------------------------------------------------------------------
class CMyGDApplication : public CGDApplication
{
// Construction
public:
CMyGDApplication(const GDAPPCONFIG& config);

// Attributes
protected:

// Operations
protected:

// Implementation
public:
virtual HRESULT InitInstance();
virtual HRESULT ExitInstance();
virtual HRESULT CreateSurfaces(CGapiDisplay& display, HINSTANCE hInstance);
virtual HRESULT ProcessNextFrame(CGapiSurface& backbuffer, BOOL bFrametimeOverflow);
virtual HRESULT KeyDown(DWORD dwKey, GDKEYLIST& keylist);
virtual HRESULT KeyUp(DWORD dwKey, GDKEYLIST& keylist);
virtual HRESULT StylusDown(POINT p);
virtual HRESULT StylusUp(POINT p);
virtual HRESULT StylusDblClk(POINT p);
virtual HRESULT StylusMove(POINT p);
virtual ~CMyGDApplication();
};


The configuration struct looks like this:

Code:
typedef struct _GDAPPCONFIG
{
HINSTANCE hInstance; // Application instance [ mandatory ]
const TCHAR* pAppTitle; // Application title [ mandatory ]
DWORD dwTargetFPS; // Target number of frame updates / second [ mandatory ]
DWORD dwDisplayFlags; // Flags sent to OpenDisplay [ optional ]
DWORD dwDisplayMode; // Flags sent to SetDisplayMode [ optional ]
DWORD dwWindowIcon; // (Stationary PCs) Window icon [ optional ]
DWORD dwWindowBorder; // (Stationary PCs) Window border style [ optional ]
} GDAPPCONFIG;


Typically you kick off the application from WinMain:

Code:
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Entry point to the program. Initializes everything, and goes into a
// message-processing loop. Exit the loop by calling Shutdown().
//-----------------------------------------------------------------------------
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR pCmdLine, int nCmdShow)
{
GDAPPCONFIG config;
ZeroMemory(&config, sizeof(GDAPPCONFIG));

config.hInstance = hInst;
config.pAppTitle = TEXT("My App");
config.dwWindowIcon = IDI_APP;
config.dwDisplayFlags = GDOPENDISPLAY_SCALEX2;
config.dwDisplayMode = GDDISPMODE_LANDSCAPE1;
config.dwTargetFPS = 30;

// Create the application
CMyGDApplication myapp(config);

// Start main loop
return myapp.Run();

// CGDApplication will now call:
// - InitInstance()
// - CreateSurfaces() <- will also be called if display is rotated
// - ProcessNextFrame() <- until Shutdown() is called
// - ExitInstance()
}


The entire specification of CGDApplication looks like:

Code:
class CGDApplication
{
// Construction
public:
CGDApplication(const GDAPPCONFIG& config);

// Attributes
private:
enum
{
WM_USER_MINIMIZE = WM_USER + 1
};
HWND m_hWnd;
BOOL m_bActiveWindow;
BOOL m_bDisplayModeShouldChange;
BOOL m_bWindowShouldMinimize;
HANDLE m_hThread;
BOOL m_bThreadShouldExit;
BOOL m_bThreadShouldSuspend;
HANDLE m_hThreadIsFinished;
HANDLE m_hThreadIsSuspended;
TCHAR m_szWndClass[MAX_PATH];
TCHAR m_szError[MAX_PATH];
CGapiDisplay m_display;
CGapiSurface m_backbuffer;
CGapiInput m_input;
protected:
GDAPPCONFIG m_config;
CGapiTimer m_timer;

// Operations
public:
HRESULT Run();
HRESULT Shutdown();
HRESULT Minimize();
HRESULT SetDisplayMode(DWORD dwDisplayMode);
HRESULT SetError(const TCHAR* pErrorDesc, HRESULT hr = 0);
protected:
virtual HRESULT InitInstance() { return S_OK; }
virtual HRESULT ExitInstance() { return S_OK; }
virtual HRESULT CreateSurfaces(CGapiDisplay& display, HINSTANCE hInstance) { return S_OK; }
virtual HRESULT ProcessNextFrame(CGapiSurface& backbuffer, BOOL bFrametimeOverflow) { return S_OK; }
virtual HRESULT KeyDown(DWORD dwKey, GDKEYLIST& keylist) { return S_OK; }
virtual HRESULT KeyUp(DWORD dwKey, GDKEYLIST& keylist) { return S_OK; }
virtual HRESULT StylusDown(POINT p) { return S_OK; }
virtual HRESULT StylusUp(POINT p) { return S_OK; }
virtual HRESULT StylusDblClk(POINT p) { return S_OK; }
virtual HRESULT StylusMove(POINT p) { return S_OK; }
private:
BOOL IsFullscreen();
HRESULT CreateMainWindow();
HRESULT DestroyMainWindow();
HRESULT OpenDisplay();
HRESULT CloseDisplay();
static HRESULT ToggleFullscreen(HWND hWnd, BOOL bFullscreen);
static LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
static unsigned __stdcall ThreadFunc(LPVOID pParam);

// Implementation
public:
virtual ~CGDApplication();
};


So.. What do you think. Anything I have missed? I plan to release GapiDraw 1.03 this weekend (have some more checking to do on the RLE decoding), and would like the base class to be as feature complete as possible.

/Johan
Just wanted to say that a small change has already been done. ProcessNextFrame now instead takes a "DWORD dwFlags" parameter instead of a boolean. Current flags are (1) fps overrun and (2) return from suspend (so that it's possible to create zoom-in effects etc when returning to the game)...

Code:
virtual HRESULT ProcessNextFrame(CGapiSurface& backbuffer, DWORD dwFlags);


/Johan
Hello Johan,

I am using GapiDraw to create a commercial grade game, one which is getting to be quite complex.

I usually prefer the modular approach to a toolkit, for example a class for input, another for the screen management, etc.

However, the prospect of having all maintenance tasks done with your GDApplication class, and just having to initialize it in WinMain is something I find extremely apealing.

Even if I have several years of Windows programming experience, I'm always wondering if messages are properly handled. This is especially true since I only have around 6 months experience on the PocketPC platform.

You say that you want your base class as complete as possible. If you mean that you want it to handle most of the mondain task like messaging and such, I agree and look forward to seeing that.

Up to now GapiDraw has allowing me to do anything that my publisher expects from a commercial title, and it also lets me concentrate on my code instead of the video particularities of each devices.

Using GapiDraw instead of doing the graphics myself has been the single best choices I have made in this project. It will let me deliver a quality game on time.

Thanks. What else can I say?
Looks good. Also looks quite similar to what I had been working on, but I hadn't made my code multi-threaded. I'll definitely switch over with the release of 1.03.

Thanks!

-Ionitor
Thanks for the comments! Really... :D
Pejo Software - Per · 29 Jun 2002, 08:04 UTC
Here are some comments!

Maybe I'm stupid but I don't see how you can process Windows messages when subclassing CGDApplication. Perhaps MainWndProc could call some virtual function in CGDApplication. To do this you can have a static member that is a pointer to the instance of CGDApplication (there should be only one).

I see no reason why some of the methods like run shouldn't be virtual. You may want to customize some parts of the application without changing the base class.

Maybe I have gotten everything wrong. I have tendency to do that!!

Now to the biggest problem of GapiDraw: You are making it to easy for just anybody to make great apps :)
I guess it's always best to not having to re-arrange the superclass in every project. I'll add a virtual WndProc and make Run, Shutdown etc virtuals as well... Thanks!

/Johan