// "main" is the S3E entry point int main() { Iw2DInit(); IwUtilInit(); // create game object pGame = new CGame; int currentUpdate = GetUpdateFrame(); int nextUpdate = currentUpdate; s3ePointerUpdate(); // to exit correctly, applications should poll for quit requests while(!s3eDeviceCheckQuitRequest()) { // run logic at a fixed frame rate (defined by UPS) // block until the next frame (don't render unless at // least one update has occurred) while(!s3eDeviceCheckQuitRequest()) { nextUpdate = GetUpdateFrame(); if( nextUpdate != currentUpdate ) break; s3eDeviceYield(1); } // execute update steps int frames = nextUpdate - currentUpdate; frames = MIN(MAX_UPDATES, frames); while(frames--) { pGame->Update(nextUpdate - currentUpdate); } currentUpdate = nextUpdate; // render the results pGame->Render(); // if an application uses polling input the application // must call update once per frame s3ePointerUpdate(); s3eKeyboardUpdate(); // S3E applications should yield frequently s3eDeviceYield(); } // clear up game object delete pGame; Ground::DestroyGround(); IwUtilTerminate(); Iw2DTerminate(); return 0; }
void CFrameScaleCtrlImp::Update() { if ( m_iFrameCur != (int)GetUpdateFrame()) { m_iFrameCur = (int)GetUpdateFrame(); //通知keyframe控件 MSG_SYS_SELCHANGE msg(NULL); m_pOwnContext->EventCollect(msg); } CCtrlBase::Update(); }
int main() { Iw2DInit(); game = new Game(); game->Initialize(); game->NewGame(); int currentUpdate = GetUpdateFrame(); int nextUpdate = currentUpdate; s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, (s3eCallback) MouseEventCallback, NULL); while(!s3eDeviceCheckQuitRequest()) { while(!s3eDeviceCheckQuitRequest()) { nextUpdate = GetUpdateFrame(); if( nextUpdate != currentUpdate ) break; s3eDeviceYield(1); } // execute update steps int frames = nextUpdate - currentUpdate; frames = MIN(MAX_UPDATES, frames); while(frames--) { game->Update(); } Iw2DSurfaceClear(0xffffffff); game->Render(); Iw2DSurfaceShow(); s3ePointerUpdate(); s3eKeyboardUpdate(); s3eDeviceYield(); } delete game; Iw2DTerminate(); return 0; }
bool GameApp::Run() { if (SDL_Init(SDL_INIT_EVERYTHING) < 0) { return false; } mWindow = SDL_CreateWindow(mTitle, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, mWidth, mHeight, SDL_WINDOW_SHOWN); if (mWindow == 0) { SDL_Quit(); return false; } else { mWindowSurface = SDL_GetWindowSurface(mWindow); mGraphics = new Graphics(mWindowSurface, mWidth, mHeight); } int currentUpdate = GetUpdateFrame(); int nextUpdate = currentUpdate; while (!mShouldTerminate) { // Vänta. while (nextUpdate == currentUpdate) { nextUpdate = GetUpdateFrame(); SDL_Delay(1); } // Uppdatera. int frames = nextUpdate - currentUpdate; if (frames > mMaxUpdates) frames = mMaxUpdates; while (frames--) { if (mNewScreen) { delete mScreen; mScreen = mNewScreen; mNewScreen = 0; } if (mScreen) { mScreen->Update(); } } currentUpdate = nextUpdate; // Events ligger i en kö. SDL_Event e; while (SDL_PollEvent(&e) != 0 ) { if (e.type == SDL_QUIT ) { mShouldTerminate = true; } else if (e.type == SDL_KEYDOWN) { if (mScreen && !mNewScreen) { mScreen->KeyDown(e.key.keysym.sym); } } else if (e.type == SDL_KEYUP) { if (mScreen && !mNewScreen) { mScreen->KeyUp(e.key.keysym.sym); } } } // Rita. if (mScreen && !mNewScreen) { mScreen->Draw(mGraphics); } SDL_UpdateWindowSurface(mWindow); } delete mScreen; delete mNewScreen; delete mGraphics; SDL_FreeSurface(mWindowSurface); mWindowSurface = 0; SDL_DestroyWindow(mWindow); mWindow = 0; SDL_Quit(); return true; }