📄 bowling3d.cpp
字号:
/*===========================================================================
FILE: Bowling3D.c
===========================================================================*/
/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h" // Module interface definitions
#include "AEEAppGen.h" // Applet interface definitions
#include "AEEShell.h" // Shell interface definitions
#include "AEEFile.h" // File interface definitions
#include "..\..\..\Program\LGVX8000\bowling3d.bid"
#include "..\System\engine.h"
#include "..\System\SimpleMemory.h"
#include "Game.h"
#include "..\System\keyinput.h"
/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean Bowling3D_HandleEvent(IApplet* pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
static void GameApp_OnTimer(void *pData);
/*===============================================================================
FUNCTION DEFINITIONS
=============================================================================== */
static void GameApp_InitEngine(CEngine *pMe)
{
pMe->Construct();
pMe->FirstTimeInit();
// pMe->SetGamePointer(new CGame(pMe));
}
static void GameApp_DestroyEngine(CEngine *pMe)
{
pMe->Deconstruct();
}
/*===========================================================================
FUNCTION: AEEClsCreateInstance
DESCRIPTION
This function is invoked while the app is being loaded. All Modules must provide this
function. Ensure to retain the same name and parameters for this function.
In here, the module must verify the ClassID and then invoke the AEEApplet_New() function
that has been provided in AEEAppGen.c.
After invoking AEEApplet_New(), this function can do app specific initialization. In this
example, a generic structure is provided so that app developers need not change app specific
initialization section every time except for a call to IDisplay_InitAppData().
This is done as follows: InitAppData() is called to initialize AppletData
instance. It is app developers responsibility to fill-in app data initialization
code of InitAppData(). App developer is also responsible to release memory
allocated for data contained in AppletData -- this can be done in
IDisplay_FreeAppData().
PROTOTYPE:
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
PARAMETERS:
clsID: [in]: Specifies the ClassID of the applet which is being loaded
pIShell: [in]: Contains pointer to the IShell object.
pIModule: pin]: Contains pointer to the IModule object to the current module to which
this app belongs
ppObj: [out]: On return, *ppObj must point to a valid IApplet structure. Allocation
of memory for this structure and initializing the base data members is done by AEEApplet_New().
DEPENDENCIES
none
RETURN VALUE
AEE_SUCCESS: If the app needs to be loaded and if AEEApplet_New() invocation was
successful
EFAILED: If the app does not need to be loaded or if errors occurred in
AEEApplet_New(). If this function returns FALSE, the app will not be loaded.
SIDE EFFECTS
none
===========================================================================*/
int AEEClsCreateInstance(AEECLSID ClsId, IShell *pIShell, IModule *po, void **ppObj)
{
*ppObj = NULL;
if( ClsId == AEECLSID_BOWLING3D )
{
// Create the applet and make room for the applet structure
if( AEEApplet_New(sizeof(CEngine),
ClsId,
pIShell,
po,
(IApplet**)ppObj,
(AEEHANDLER)Bowling3D_HandleEvent,
NULL )) // the FreeAppData function is called after sending EVT_APP_STOP to the HandleEvent function
{
return(AEE_SUCCESS);
}
}
return(EFAILED);
}
/*===========================================================================
FUNCTION SampleAppWizard_HandleEvent
DESCRIPTION
This is the EventHandler for this app. All events to this app are handled in this
function. All APPs must supply an Event Handler.
PROTOTYPE:
boolean SampleAppWizard_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
PARAMETERS:
pi: Pointer to the AEEApplet structure. This structure contains information specific
to this applet. It was initialized during the AEEClsCreateInstance() function.
ecode: Specifies the Event sent to this applet
wParam, dwParam: Event specific data.
DEPENDENCIES
none
RETURN VALUE
TRUE: If the app has processed the event
FALSE: If the app did not process the event
SIDE EFFECTS
none
===========================================================================*/
static boolean Bowling3D_HandleEvent(IApplet* pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
CEngine* pMe = (CEngine*)pi;
DBGPRINTF("DEBUG: event code: %x", eCode);
DBGPRINTF("DEBUG: TimerCPT: %d, TimerError: %d", pMe->m_TimerCpt, pMe->m_TimerError);
#ifndef SAMSUNG
//only for LG. fix the freezing bug
if(pMe->m_pGame!=NULL)// the class CGame have been initialized
if(pMe->m_pGame->m_frameStartTick!=0)// not the first time
{
if((GETUPTIMEMS()-pMe->m_pGame->m_frameStartTick)>2000)// the system have not respond to the timer for a long time
{
ISHELL_SetTimer(pMe->m_pIShell, 0, GameApp_OnTimer, pMe);// reset the timer
}
}
#endif
switch (eCode)
{
case EVT_APP_START:
GameApp_InitEngine(pMe);
pMe->m_TimerError = ISHELL_SetTimer(pMe->m_pIShell, 100, GameApp_OnTimer, pMe);
if (pMe->m_TimerError == SUCCESS)
pMe->m_TimerCpt=1;
return(TRUE);
case EVT_APP_STOP:
GameApp_DestroyEngine(pMe);
return TRUE;
case EVT_KEY_PRESS:
/* if(pMe->memLow)
{
ISHELL_CloseApplet(pMe->m_pIShell, FALSE);
return FALSE;
}
*/
if(pMe->GetInput()){
pMe->GetInput()->HandleKey((AVKType)wParam, EVT_KEY_PRESS);
//pMe->m_pGame->inputTick(pMe->GetInput()->gk_pressed); // added by Milo 09-27
}
if(pMe->ismemoryfailed) pMe->isKeyPressed=true;
return TRUE;
case EVT_KEY_RELEASE:
if(pMe->GetInput())
pMe->GetInput()->HandleKey((AVKType)wParam, EVT_KEY_RELEASE);
return TRUE;
case EVT_APP_NO_SLEEP: //to avoid to enter sleep mode when cpu in playing
return TRUE;
case EVT_KEY:
return TRUE;
case EVT_APP_SUSPEND:
pMe->isSuspend=1;
((CGame*)(pMe->m_pGame))->pauseMIDI();
pMe->GetInput()->ResetAll();
return TRUE;
case EVT_APP_RESUME:
pMe->isSuspend=0;
if(!((CGame*)(pMe->m_pGame))->GetPause())
((CGame*)(pMe->m_pGame))->resumeMIDI();
DBGPRINTF("DEBUG: App Resume");
return TRUE;
case EVT_APP_MESSAGE:
return TRUE;
#ifdef SAMSUNG
case EVT_FLIP:
ISHELL_CloseApplet(pMe->m_pIShell, TRUE);
return true;
#endif
default:
break;
}
return FALSE;
}
const AECHAR szNoMem1[][30] = {
L"Not enough memory",
L"to run this game!",
L"Try to restart",
L"mobile and run",
L"again. If you see",
L"this info again,",
L"please contact",
L"support@",
L"gameloft.com",
L"Press any key",
L"to exit..."
};
#define FRAME_LIMIT 40 // limit to 20 fps
static void GameApp_OnTimer(void *pData)
{
CEngine*pMe = (CEngine*)pData;
pMe->m_TimerCpt--;
long delay = 1;
int timeOfFrame;
if( NULL == pMe->GetMem() || ! pMe->GetMem()->IsInitSuccess()
||pMe->ismemoryfailed || pMe->GetLastError()>0) // if the mem is ok
{
AECHAR error[40];
char serror[40];
SPRINTF(serror, "STEP: %d, ERROR: %d", pMe->m_initStep, pMe->GetLastError());
STRTOWSTR(serror, error, 40);
IDISPLAY_ClearScreen (pMe->m_pIDisplay);
int i;
for(i=0;i<11;i++)
IDISPLAY_DrawText(pMe->m_pIDisplay, // Display instance
AEE_FONT_NORMAL, // Use BOLD font
szNoMem1[i], // Text - Normally comes from resource
-1, // -1 = Use full string length
0, // Ignored - IDF_ALIGN_CENTER
10+i*12 + ((i>=9)?5:0), // Ignored - IDF_ALIGN_MIDDLE
NULL, // No clipping
IDF_ALIGN_CENTER);
//display error code for loading
IDISPLAY_DrawText(pMe->m_pIDisplay, // Display instance
AEE_FONT_NORMAL, // Use BOLD font
error, // Text - Normally comes from resource
-1, // -1 = Use full string length
0, //
180, //
NULL, // No clipping
IDF_ALIGN_CENTER);
IDISPLAY_Update (pMe->m_pIDisplay);
if (pMe->isKeyPressed)
{
ISHELL_CloseApplet(pMe->m_pIShell, FALSE);
return;
}
pMe->m_TimerError = ISHELL_SetTimer(pMe->m_pIShell, 50, GameApp_OnTimer, pMe);
if (pMe->m_TimerError == SUCCESS)
pMe->m_TimerCpt++;
return;
}
pMe->m_pGame->m_frameStartTick = GETUPTIMEMS();
if(!pMe->isSuspend)
{
DBGPRINTF("DEBUG: GameS: %d, MatchS: %d, MenuS: %d", ((CGame *)(pMe->m_pGame))->m_GameState,
((CGame *)(pMe->m_pGame))->m_MatchState, ((CGame *)(pMe->m_pGame))->m_pMenu->m_iState);
pMe->Tick();
} // the main loop of the game
else
{
((CGame *)(pMe->m_pGame))->m_isSuspend=1;
DBGPRINTF("DEBUG: Suspending");
}
timeOfFrame = GETUPTIMEMS() - pMe->m_pGame->m_frameStartTick;
// DBGPRINTF("frame time: %d", timeOfFrame);
if(pMe->m_pGame->m_running)
{
#ifdef AEE_SIMULATOR
ISHELL_SetTimer(pMe->m_pIShell, 50, GameApp_OnTimer, pMe);
#else
int offset=10;
if(timeOfFrame>=0 && timeOfFrame<FRAME_LIMIT+5)
offset=FRAME_LIMIT-timeOfFrame+5;
pMe->m_TimerError = ISHELL_SetTimer(pMe->m_pIShell,
offset,
GameApp_OnTimer,
pMe);
if (pMe->m_TimerError == SUCCESS)
pMe->m_TimerCpt++;
// ISHELL_SetTimer(pMe->m_pIShell, 10, GameApp_OnTimer, pMe);
#endif
}
else
ISHELL_CloseApplet(pMe->m_pIShell, FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -