📄 engine.cpp
字号:
/*
* ============================================================================
* Name : CGlobalData from GlobalData.cpp
* Part of : Game
* Created : 2003-06-16 by Qiu Wei Min
* Implementation notes:
*
* Initial content was generated by Series 60 AppWizard.
* Modified : 2003-09-03 by Zheng Jie Sheng
* Version :
* Copyright: Gameloft S.A.
* ============================================================================
*/
// INCLUDE FILES
#include <AEE.h>
#include <AEEfile.h>
#include <AEEStdLib.h>
#include <AEETAPI.h>
#include "engine.h"
#include "..\game\game.h"
#include "ResFile.h"
#include "keyinput.h"
#include "AEELicense.h"
#include "..\System\Sysdef.h"
#include "..\system\network.h"
//CEngine * CEngine::m_pInst = NULL;
// ================= MEMBER FUNCTIONS =======================
void CEngine::Construct()
{
m_initStep = 0;
m_TimerError = SUCCESS;
m_TimerCpt = 0;
//m_pInst = this;
bool ret = true;
pFileMgr = NULL;
m_pMemory = NULL;
m_pInput = NULL;
m_lasterror = ERROR_NONE;
m_tickCount = 0;
m_pGfx = NULL;
m_pResFile = NULL;
m_pStrings = NULL;
m_nString = 0;
m_pInput = NULL;
m_pSound = NULL;
isSuspend = 0;
memLow = 0;
pLicense = NULL;
m_pGame = NULL;
m_pFont = NULL;
m_pNetwork = NULL;
isKeyPressed=false;
ismemoryfailed=false;
#ifndef LG
m_bSoundVolumeSet=false;
#endif
//It's importent to check if ISHELL_CreateInstance() is success
if(ISHELL_CreateInstance(this->m_pIShell, AEECLSID_FILEMGR,(void **)&pFileMgr) != SUCCESS)
{
pFileMgr = NULL;//make sure the pointer is NULL
SetLastError(ERROR_CREATEINST);
}
//license
if(ISHELL_CreateInstance(this->m_pIShell, AEECLSID_LICENSE,(void **)&pLicense) != SUCCESS)
{
pLicense = NULL;
SetLastError(ERROR_CREATEINST);
}
//Qiu Li add for online connection, 2005/03/24
#ifdef ONLINE
if (ISHELL_CreateInstance(this->m_pIShell, AEECLSID_WEB, (void**)(&m_pIWeb)) != SUCCESS)
{
m_pIWeb = NULL;
DBGPRINTF("Cannot create WEB");
SetLastError(ERROR_CREATEINST);
}
if (ISHELL_CreateInstance(this->m_pIShell, AEECLSID_WEBUTIL,(void **)&m_pIWebUtil) != SUCCESS)
{
m_pIWebUtil = NULL;
DBGPRINTF("Cannot create WEBUTIL");
SetLastError(ERROR_CREATEINST);
}
#ifndef AEE_SIMULATOR
if (ISHELL_CreateInstance(this->m_pIShell, AEECLSID_TAPI,(void **)&pITAPI) != SUCCESS)
{
pITAPI = NULL;
DBGPRINTF("Cannot create ITAPI");
SetLastError(ERROR_CREATEINST);
}
#endif
#endif
//Qiu Li end
//return ret;
}
void CEngine::Deconstruct()
{
if(m_pSound)
{
delete m_pSound;
m_pSound = NULL;
}
if(m_pGame)
{
delete m_pGame;
m_pGame = NULL;
}
if(m_pInput)
{
delete m_pInput;
m_pInput = NULL;
}
if(m_pResFile)
{
delete m_pResFile;
m_pResFile = NULL;
}
if(m_pGfx)
{
delete m_pGfx;
m_pGfx = NULL;
}
if(m_pMemory)
{
delete m_pMemory;
m_pMemory = NULL;
}
if(pFileMgr)
{
IFILEMGR_Release((IFileMgr *)pFileMgr);
pFileMgr = NULL;
}
if(pLicense)
{
ILICENSE_Release((ILicense *)pLicense);
pLicense = NULL;
}
if(m_pFont)
{
delete m_pFont;
m_pFont = NULL;
}
// m_pInst = NULL;
#ifdef ONLINE
//Qiu Li add for online connection, 2005/03/24
if( m_pNetwork )
{
delete m_pNetwork;
m_pNetwork = NULL;
}
if(m_pIWeb)
{
IWEB_Release((IWeb *)m_pIWeb);
m_pIWeb = NULL;
}
if(m_pIWebResp)
{
IWEBRESP_Release((IWebResp *)m_pIWebResp);
m_pIWebResp = NULL;
}
if(m_pIWebUtil)
{
IWEBUTIL_Release((IWebUtil *)m_pIWebUtil);
m_pIWebUtil = NULL;
}
#ifndef AEE_SIMULATOR
if(pITAPI)
{
ITAPI_Release((ITAPI *)pITAPI);
pITAPI = NULL;
}
#endif
#endif
//Qiu Li end
}
void CEngine::SetGamePointer(CGameBase *pGame)
{
m_pGame = pGame;
}
bool CEngine::FirstTimeInit()
{
m_pMemory = new CSimpleMemory();
if(m_pMemory == NULL || !m_pMemory->Init(GLOBAL_MEMORY_SIZE, LOCAL_MEMORY_SIZE))
{
memLow = 1;
SetLastError(ERROR_MEMORY);
return false;
}
m_initStep = 1;
m_pInput = new CKeyinput();
m_pGfx = new CGfx(this);
m_pResFile = new CResFile(this);
if(m_pGfx == NULL || m_pResFile == NULL || m_pInput == NULL)
{
memLow = 1;
SetLastError(ERROR_MEMORY);
return false;
}
m_initStep = 2;
if(!m_pResFile->Open(RES_FILE))
{
SetLastError(ERROR_FILE);
return false;
}
m_initStep = 3;
if(!GetGfx()->GetVideo())
{
IDIB* p1 = NULL;
if (SUCCESS != IDISPLAY_GetDeviceBitmap (m_pIDisplay, (IBitmap**)&p1))
{
return false;
}
IBITMAP_Release((IBitmap*)p1);
SetVideoBuffer((char*)((IDIB*)p1)->pBmp, ((IDIB*)p1)->cx, ((IDIB*)p1)->cy);
}
m_initStep = 4;
m_pFont = new CFont(this);
m_pSound = new CSound(this);
if(NULL == m_pFont || NULL == m_pSound)
{
SetLastError(ERROR_MEMORY);
return false;
}
m_initStep = 5;
m_pFont->loadFont();
if((!m_pSound->soundInit()) || (!m_pFont->loadFont()))
return false;
m_pGame = new CGame(this);
if(NULL == m_pGame)
{
SetLastError(ERROR_MEMORY);
return false;
}
m_initStep = 6;
if (GetLastError()>0)
return false;
m_initStep = 7;
#ifdef ONLINE
m_pNetwork = new CNetwork(this);
if(NULL == m_pNetwork)
{
SetLastError(ERROR_MEMORY);
return false;
}
#endif
m_initStep = 8;
//#ifndef AEE_SIMULATOR
// {
// TAPIStatus * ps;
// if( pITAPI )
// {
// ITAPI_GetStatus(pITAPI, ps);
// DBGPRINTF("phone num: %s", ps->szMobileID);
// }
// else{
// DBGPRINTF("Cannot create ITAPI");
// }
// }
//#endif
return true;
}
int CEngine::Tick()
{
m_pSound->Update();
m_pInput->updateKey();
#ifdef TIME_STASTIC
m_TimeOffsets[TIMET_COLLISION] = GETUPTIMEMS();
#endif
m_pGame->update();
#ifdef TIME_STASTIC
m_TimeOffsets[TIMET_COLLISION] = GETUPTIMEMS() - m_TimeOffsets[TIMET_COLLISION];
#endif
#ifdef TIME_STASTIC
m_TimeOffsets[TIMET_RENDERALL] = GETUPTIMEMS();
#endif
m_pGame->paint();
return 0;
}
void CEngine::SetVideoBuffer(void *pBuff, int w, int h)
{
GFXBMP *p = m_pGfx->GetVideo();
if(p)
{
p->pData = (unsigned char*)pBuff;
p->w = (short)w;
p->h = (short)h;
}
else
m_pGfx->SetVideoBmp(m_pGfx->CreateNativeBmp(pBuff, w, h, true));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -