Nokia N97 SDK
Example Applications Guide

gamecontroller.h

00001 /*
00002 * ==============================================================================
00003 *  Name        : gamecontroller.h
00004 *  Part of     : OpenC / OpenCOpenglEx
00005 *  Interface   : 
00006 *  Description : Contains the class declarations of CGameController 
00007 *                & CWsEventReceiver.
00008 *  Version     : 
00009 *
00010 *  Copyright (c) 2007 Nokia Corporation.
00011 *  This material, including documentation and any related 
00012 *  computer programs, is protected by copyright controlled by 
00013 *  Nokia Corporation.
00014 * ==============================================================================
00015 */
00016 #ifndef __GAME_CONTROLLER_CLASS__
00017 #define __GAME_CONTROLLER_CLASS__
00018 
00019 #include <gles/egl.h> // for egl functions.
00020 #include <e32base.h>  // for CBase
00021 #include <w32std.h>   // for TWsEvent
00022 
00023 // CONSTANTS
00024 const TUint KBufferSize = 32;
00025 
00026 // Error constants
00027 const TInt KErrConfigFailed = -6001;
00028 const TInt KErrCreateWindowSurfaceFailed = -6002;
00029 const TInt KErrCreateContextFailed = -6003;
00030 const TInt KErrSetContextFailed = -6004;
00031 const TInt KErrCoeEnvNotCreated = -6005;
00032 const TInt KErrCoeEnvNotInitialized = -6006;
00033 
00034 // Forward declarations
00035 class CGame;
00036 class RWindow;
00037 class CWsEventReceiver;
00038 
00039 // CLASS DECLARATION
00040 
00041 /**
00042  * The Game Controller class.
00043  * Controls the intialization of the Game and mediates the 
00044  * Key Event delivery to the game.
00045  */
00046 class CGameController : public CBase 
00047 {
00048 public:
00049     /**
00050      * Two phase constructor.
00051      *
00052      * @param aEglDisplay the egl display to drawn on.
00053      */
00054     static CGameController* NewLC( EGLDisplay aEglDisplay );
00055     
00056     /**
00057      * Starts the Game Loop.
00058      *
00059      * @param aGame A reference to the game object.
00060      */    
00061     void StartGameL( CGame& aGame );    
00062 
00063     /**
00064      * Handles a Windows Server event.
00065      * This is called by the CWsEventReciever whenever it has
00066      * a pending Windows Server Event.
00067      *
00068      * @param aEvent A reference to the Windows server event.
00069      */        
00070     void HandleWsEvent( const TWsEvent& aEvent );
00071 
00072     /**
00073      * Destructor.
00074      */            
00075     ~CGameController();
00076     
00077 private: // Constructors.
00078     /**
00079      * Constructor.
00080      *
00081      * @param aEglDisplay A handle to the egl display.
00082      */
00083     CGameController( EGLDisplay aEglDisplay );    
00084     
00085     /**
00086      * Two phase constructor.
00087      * Intializes the EGL Context and surface.
00088      */
00089     void ConstructL();
00090 private: // Helper functions.
00091     /**
00092      * Runs the Active Scheduler so that the any pending
00093      * Active Objects get a chance to run.
00094      * @param aIsBlocking If ETrue, the API blocks till a asynchronous 
00095      *                    event occurs.
00096      */
00097     void ProcessBackgroundTasks( TBool aIsBlocking );
00098     
00099     /**
00100      * Creates a RWindow and intializes it to cover the full 
00101      * screen.
00102      */    
00103     void CreateNativeWindowL();
00104 private: // Data
00105     /** Handle to the EGL Display */
00106     EGLDisplay iEglDisplay;
00107  
00108     /** Handle to the EGL Surface */
00109     EGLSurface iEglSurface;
00110     
00111     /** Handle to the EGL Context */    
00112     EGLContext iEglContext;
00113     
00114     /** Handle to Symbian's Window */    
00115     RWindow* iWindow;
00116 
00117     /** The Active Object that waits for Windows Server Events */    
00118     CWsEventReceiver* iWsEventReceiver;
00119     
00120     /** The Game */
00121     CGame* iGame;
00122     
00123     /** Handle to the Windows Server session */
00124     RWsSession iWsSession;
00125 
00126     /** Handle to the Window group */
00127     RWindowGroup iWindowGroup;
00128     
00129     /** The Screen device */
00130     CWsScreenDevice* iWsScreenDevice;
00131     
00132     /** Flag for the applications focus state */
00133     TBool iIsAppInFocus;
00134     
00135     /** Flag to check if the Window is visible */
00136     TBool iIsVisible;
00137 
00138 }; // CGameController
00139 
00140 /**
00141  * The Active Object that waits for Windows Server events
00142  * and passes it on the Game Controller.
00143  */
00144 class CWsEventReceiver : public CActive
00145 {
00146 public: 
00147     /**
00148      * Recieves events from the Windows Server.
00149      *
00150      * This function gets called in the 
00151      * CGameController::ProcessBackgroundTasks() function,
00152      * when the CActiveScheduler gets a chance to run.
00153      */
00154     virtual void RunL();
00155     
00156     /**
00157      * Cancels event request from the Windows Server.
00158      */    
00159     virtual void DoCancel();
00160 
00161     /**
00162      * Static Constructor.
00163      *
00164      * @param aParent The Game Controller requesting for the events.
00165      */    
00166     static CWsEventReceiver* NewL( CGameController& aParent );
00167     
00168     /**
00169      * Destructor.
00170      */    
00171     ~CWsEventReceiver();
00172 
00173 private: // Constructors
00174     /**
00175      * Constructor.
00176      */
00177     CWsEventReceiver();
00178 
00179     /**
00180      * Two phase Constructor.
00181      *
00182      * @param aParent The Game controller which will be notified of
00183      *                Windows Server events .
00184      */    
00185     void ConstructL( CGameController& aParent );                
00186 
00187 private: // Data.
00188     /** The Windows Server Session */
00189     RWsSession iWsSession;
00190     
00191     /** The Game controller */
00192     CGameController* iParent;    
00193 
00194 };
00195 
00196 #endif //__GAME_CONTROLLER_CLASS__

© Nokia 2009

Back to top