void SceneGame::update() { unsigned int i; // if keyboard is up, check for key press if(keyboardUp) { // update the keyboard state s3eKeyboardUpdate(); // see if a key is pressed for(i=0; i<26; i++) { if(s3eKeyboardGetState(s3eKeys[i]) != 0) { pressKey(i); playInputSound(); } } } // check for back button pressed if(s3eKeyboardGetState(s3eKeyAbsBSK) != 0) { GameButtonMenu* buttonMenu = (GameButtonMenu*)this->getChildByTag(SceneGameTagButtonMenu); buttonMenu->buttonPressed(); } // update the other nodes IGNode::update(); }
int CCApplication::Run() { IW_CALLSTACK("CCApplication::Run"); if ( ! initInstance() || !applicationDidFinishLaunching() ) { return 0; } int64 updateTime = s3eTimerGetMs(); while (!s3eDeviceCheckQuitRequest()) { int64 currentTime = s3eTimerGetMs(); if (currentTime - updateTime > m_nAnimationInterval) { updateTime = currentTime; s3eDeviceYield(0); s3eKeyboardUpdate(); s3ePointerUpdate(); ccAccelerationUpdate(); CCDirector::sharedDirector()->mainLoop(); } else { s3eDeviceYield(0); } } return -1; }
//-------------------------------------------------------------------------- // Main global function //-------------------------------------------------------------------------- S3E_MAIN_DECL void IwMain() { #ifdef EXAMPLE_DEBUG_ONLY // Test for Debug only examples #endif // Example main loop ExampleInit(); uint64 timeOld = s3eTimerGetMs(); while (1) { s3eDeviceYield(0); s3eKeyboardUpdate(); s3ePointerUpdate(); uint64 timeNew = s3eTimerGetMs(); float dt = (timeNew - timeOld) * 0.001f; timeOld = timeNew; bool result = ExampleUpdate(dt); if ( (result == false) || (s3eKeyboardGetState(s3eKeyEsc) & S3E_KEY_STATE_DOWN)|| (s3eKeyboardGetState(s3eKeyLSK) & S3E_KEY_STATE_DOWN)|| (s3eDeviceCheckQuitRequest()) ) break; ExampleRender(); //s3eSurfaceShow(); } ExampleShutDown(); }
// Main entry point for the application int main() { int i = 0; bool hidden = false; bool adsAvailable = false; bool noView = false; if(AdmobAdsAvailable()){ InitAds("a14bd815ee70598"); adsAvailable = true; } // Wait for a quit request from the host OS while (!s3eDeviceCheckQuitRequest()) { // Fill background blue s3eSurfaceClear(0, 0, 255); // Print a line of debug text to the screen at top left (0,0) // Starting the text with the ` (backtick) char followed by 'x' and a hex value // determines the colour of the text. s3eDebugPrint(120, 150, "`xffffffHello, World!", 0); if (noView){ s3eDebugPrint(120, 190, "`xff1111No view", 0); }else{ s3eDebugPrint(120, 190, "`x11ff11Ok", 0); } // Flip the surface buffer to screen s3eSurfaceShow(); // Sleep for 0ms to allow the OS to process events etc. s3eDeviceYield(1); if(adsAvailable){ i++; if(i>15000){ i = 0; if (hidden) { noView = ShowAds() != 0; } else { noView = HideAds() != 0; } hidden = !hidden; } } s3eKeyboardUpdate(); if(s3eKeyboardGetState(s3eKeyBack) & S3E_KEY_STATE_DOWN){ break; } } return 0; }
//-------------------------------------------------------------------------- // Main global function //-------------------------------------------------------------------------- S3E_MAIN_DECL void IwMain() { #ifdef EXAMPLE_DEBUG_ONLY // Test for Debug only examples #endif onInit(); while (1) { s3eDeviceYield(0); s3eKeyboardUpdate(); bool result = onUpdate(); if ( (result == false) || (s3eKeyboardGetState(s3eKeyEsc) & S3E_KEY_STATE_DOWN) || (s3eKeyboardGetState(s3eKeyLSK) & S3E_KEY_STATE_DOWN) || (s3eDeviceCheckQuitRequest()) ) { break; } onRender(); s3eSurfaceShow(); } onShutDown(); }
//----------------------------------------------------------------------------- // Main global function //----------------------------------------------------------------------------- int main() { #ifdef EXAMPLE_DEBUG_ONLY // Test for Debug only examples #ifndef IW_DEBUG DisplayMessage("This example is designed to run from a Debug build. Please build the example in Debug mode and run it again."); return 0; #endif #endif //IwGx can be initialised in a number of different configurations to help the linker eliminate unused code. //Normally, using IwGxInit() is sufficient. //To only include some configurations, see the documentation for IwGxInit_Base(), IwGxInit_GLRender() etc. IwGxInit(); // Example main loop ExampleInit(); // Set screen clear colour IwGxSetColClear(0xff, 0xff, 0xff, 0xff); IwGxPrintSetColour(128, 128, 128); while (1) { s3eDeviceYield(0); s3eKeyboardUpdate(); s3ePointerUpdate(); int64 start = s3eTimerGetMs(); bool result = ExampleUpdate(); if ( (result == false) || (s3eKeyboardGetState(s3eKeyEsc) & S3E_KEY_STATE_DOWN) || (s3eKeyboardGetState(s3eKeyAbsBSK) & S3E_KEY_STATE_DOWN) || (s3eDeviceCheckQuitRequest()) ) break; // Clear the screen IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F); RenderButtons(); RenderSoftkeys(); ExampleRender(); // Attempt frame rate while ((s3eTimerGetMs() - start) < MS_PER_FRAME) { int32 yield = (int32) (MS_PER_FRAME - (s3eTimerGetMs() - start)); if (yield<0) break; s3eDeviceYield(yield); } } ExampleShutDown(); DeleteButtons(); IwGxTerminate(); return 0; }
//! runs the device. Returns false if device wants to be deleted bool CIrrDeviceMarmalade::run() { s3eDeviceYield(); s3ePointerUpdate(); s3eKeyboardUpdate(); os::Timer::tick(); return !Close; }
int main() { IwGxInit(); Iw2DInit(); AppWarp::Client* WarpClientRef; AppWarp::Client::initialize("b29f4030aba3b2bc7002c4eae6815a4130c862c386e43ae2a0a092b27de1c5af","bf45f27e826039754f8dda659166d59ffb7b9dce830ac51d6e6b576ae4b26f7e"); WarpClientRef = AppWarp::Client::getInstance(); MenuScreen *menu = new MenuScreen; GameScreen *game = new GameScreen(WarpClientRef); Game *gm = new Game; gm->AddScene("game",game); gm->AddScene("menu",menu); menu->game = game; menu->app = gm; Listener listener(WarpClientRef,game); WarpClientRef->setConnectionRequestListener(&listener); WarpClientRef->setRoomRequestListener(&listener); WarpClientRef->setNotificationListener(&listener); s3ePointerRegister(S3E_POINTER_BUTTON_EVENT,(s3eCallback)HandleSingleTouchButtonCB,gm); while(!s3eDeviceCheckQuitRequest()) { s3eKeyboardUpdate(); if(s3eKeyboardGetState(s3eKeyAbsBSK) & S3E_KEY_STATE_DOWN) break; WarpClientRef->update(); s3ePointerUpdate(); IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F); IwGxPrintSetScale(2); IwGxPrintString(0,0,game->msg.c_str()); gm->Move(); gm->Render(); Iw2DSurfaceShow(); s3eDeviceYield(); } s3ePointerUnRegister(S3E_POINTER_BUTTON_EVENT,(s3eCallback)HandleSingleTouchButtonCB); gm->CleanUp(); delete menu; delete game; delete gm; WarpClientRef->terminate(); Iw2DTerminate(); IwGxTerminate(); }
// "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 CInput::Update() { // Update the pointer if it is available if (PointerAvailable) s3ePointerUpdate(); // Update key system if it is available if (KeysAvailable) s3eKeyboardUpdate(); }
int CCApplication::Run() { IW_CALLSTACK("CCApplication::Run"); s3eBool quitRequested = 0; bool bNeedQuit = false; if (!applicationDidFinishLaunching() ) { return 0; } uint64 updateTime = 0 ; while (true) { updateTime = s3eTimerGetMs(); s3eDeviceYield(0); s3eKeyboardUpdate(); s3ePointerUpdate(); ccAccelerationUpdate(); quitRequested = s3eDeviceCheckQuitRequest(); if( quitRequested) { CCDirector* pDirector = CCDirector::sharedDirector(); // if opengl view has been released, delete the director. if (pDirector->getOpenGLView() == NULL) { CC_SAFE_DELETE(pDirector); bNeedQuit = true; } else { pDirector->end(); } } if( bNeedQuit ) { break; } CCDirector::sharedDirector()->mainLoop(); while ((s3eTimerGetMs() - updateTime) < m_nAnimationInterval) { int32 yield = (int32) (m_nAnimationInterval - (s3eTimerGetMs() - updateTime)); if (yield<0) break; s3eDeviceYield(yield); } } return -1; }
int main() { Initialize(); // --HowTo: Load the tmx map from the json file tmxparser::Map_t *map = new tmxparser::Map_t; tmxparser::parseTmxFromJSON_file("testLevel.json", map); // --HowTo: Create a renderer tmxparser::TmxRenderer *renderer = new tmxparser::TmxRenderer(map); // an offset to use for scrolling the map CIwFVec2 offset(0,0); IwGxSetColClear(0x2f, 0x3f, 0x3f, 0xff); // Loop forever, until the user or the OS performs some action to quit the app while (!s3eDeviceCheckQuitRequest()) { //Update the input systems s3eKeyboardUpdate(); s3ePointerUpdate(); // Clear the surface IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F); // --HowTo: render all layers, at original pixel size: //renderer->Render(offset); // --HowTo: render all layers at reduced/scaled tile size renderer->Render(offset, CIwFVec2(64.0f, 64.0f)); // --HowTo: render only one layer at original pixel size //renderer->RenderLayer(0, offset, CIwFVec2(0.0f, 0.0f)); // --HowTo: render only one layer at scaled pixel size //renderer->RenderLayer(0, offset, CIwFVec2(64.0f, 64.0f)); // advance offset offset.x += 3; if (offset.x>1900) offset.x =0; // Standard EGL-style flush of drawing to the surface IwGxFlush(); IwGxSwapBuffers(); s3eDeviceYield(0); } delete renderer; delete map; Terminate(); // Return return 0; }
//----------------------------------------------------------------------------- // Main global function //----------------------------------------------------------------------------- int main() { #ifdef EXAMPLE_DEBUG_ONLY // Test for Debug only examples #ifndef IW_DEBUG DisplayMessage("This example is designed to run from a Debug build. Please build the example in Debug mode and run it again."); return 0; #endif #endif Iw2DInit(); // Example main loop ExampleInit(); // Set screen clear colour while (1) { s3eDeviceYield(0); s3eKeyboardUpdate(); s3ePointerUpdate(); int64 start = s3eTimerGetMs(); bool result = ExampleUpdate(); if ( (result == false) || (s3eKeyboardGetState(s3eKeyEsc) & S3E_KEY_STATE_DOWN) || (s3eKeyboardGetState(s3eKeyAbsBSK) & S3E_KEY_STATE_DOWN) || (s3eDeviceCheckQuitRequest()) ) break; // Clear the screen Iw2DSurfaceClear(0xffffffff); RenderSoftkeys(); ExampleRender(); // Attempt frame rate while ((s3eTimerGetMs() - start) < MS_PER_FRAME) { int32 yield = (int32) (MS_PER_FRAME - (s3eTimerGetMs() - start)); if (yield<0) break; s3eDeviceYield(yield); } } ExampleShutDown(); Iw2DTerminate(); return 0; }
int HelloWorldMain() { HelloWorldInit(); while (!s3eDeviceCheckQuitRequest()) { s3eDeviceYield(0); s3eKeyboardUpdate(); s3ePointerUpdate(); HelloWorldRender(); if(!HelloWorldUpdate()) break; } HelloWorldShutDown(); return 0; }
int CCApplication::Run() { IW_CALLSTACK("CCApplication::Run"); s3eBool quitRequested = 0; if ( ! initInstance() || !applicationDidFinishLaunching() ) { return 0; } int64 updateTime = s3eTimerGetMs(); while (true) { int64 currentTime = s3eTimerGetMs(); if (currentTime - updateTime > m_nAnimationInterval) { updateTime = currentTime; s3eDeviceYield(0); s3eKeyboardUpdate(); s3ePointerUpdate(); ccAccelerationUpdate(); quitRequested = s3eDeviceCheckQuitRequest() ; if( quitRequested && CCDirector::sharedDirector()->getOpenGLView() != NULL ) { CCDirector::sharedDirector()->end() ; // end status will be processed in CCDirector::sharedDirector()->mainLoop(); } CCDirector::sharedDirector()->mainLoop(); if( quitRequested ) { break ; } } else { s3eDeviceYield(0); } } return -1; }
// Helper function to display message for Debug-Only Examples void DisplayMessage(const char* strmessage) { uint16* screen = (uint16*)s3eSurfacePtr(); int32 width = s3eSurfaceGetInt(S3E_SURFACE_WIDTH); int32 height = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT); int32 pitch = s3eSurfaceGetInt(S3E_SURFACE_PITCH); for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) screen[y * pitch/2 + x] = 0; s3eDebugPrint(0, 10, strmessage, 1); s3eSurfaceShow(); while (!s3eDeviceCheckQuitRequest() && !s3eKeyboardAnyKey()) { s3eDeviceYield(0); s3eKeyboardUpdate(); } }
bool ExamplesMainUpdate() { s3eDeviceYield(0); s3eKeyboardUpdate(); s3ePointerUpdate(); int64 start = s3eTimerGetMs(); if (!ExampleUpdate() || ExampleCheckQuit()) { s3eDebugTracePrintf("ExampleUpdate returned false, exiting.."); return false; } // Clear the screen if (g_ClearScreen) IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F); ButtonsRender(); if (g_DrawCursor) CursorRender(); SoftkeysRender(); // User code render ExampleRender(); // Attempt frame rate while ((s3eTimerGetMs() - start) < MS_PER_FRAME) { int32 yield = (int32) (MS_PER_FRAME - (s3eTimerGetMs() - start)); if (yield<0) break; s3eDeviceYield(yield); } IwGxFlush(); IwGxSwapBuffers(); return true; }
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 update() { ThreadMessages::message msg; while (_threadMessages.peek(msg, true)) {} #ifdef __S3E__ s3eDeviceYield(0); s3eKeyboardUpdate(); s3ePointerUpdate(); bool done = false; if (s3eDeviceCheckQuitRequest()) done = true; if (s3eKeyboardGetState(s3eKeyEsc) & S3E_KEY_STATE_PRESSED) done = true; return done; #endif #if OXYGINE_SDL || EMSCRIPTEN //log::messageln("update"); bool done = false; SDL_Event event; while (SDL_PollEvent(&event)) { #if !EMSCRIPTEN //emscripten handled events from callback SDL_handleEvent(event, done); #endif } return done; #endif log::warning("update not implemented"); return true; }
int FrameworkApplication::MainLoop (void) { IwTrace(FUNCTIONS, ("FrameworkApplication -> MainLoop()")); // Выход из главного цикла по прямому запросу операционки или если фреймоворк событие клавиатуры интерпретировал как команду на выход. while (!s3eDeviceCheckQuitRequest()) { // Содержательный игровой цикл if (EachFrame()) break; // Рендеринг объектов if (Render()) break; s3eDeviceYield(0); // Здесь будут игры с FPS-ом. // Выход по клавиатуре происходит отсюда временно, потом событие будет через Stage прокидываться. s3eKeyboardUpdate(); if ((s3eKeyboardGetState(s3eKeyEsc) & S3E_KEY_STATE_DOWN) || (s3eKeyboardGetState(s3eKeyLSK) & S3E_KEY_STATE_DOWN)) break; } return 0; }
int main() { GameInit(); DrawMap(); // DrawMap(); while(!s3eDeviceCheckQuitRequest()) { s3ePointerUpdate(); s3eKeyboardUpdate(); if(s3ePointerGetState(S3E_POINTER_BUTTON_SELECT)) { Go(s3ePointerGetX(),s3ePointerGetY()); } // S3E applications should yield frequently s3eDeviceYield(); } return 0; }
int main() { // create game object engine.Init("Game"); engine.ChangeState(IntroState::Instance()); while(engine.Running()) { engine.HandleEvent(); engine.Update(); engine.Draw(); s3ePointerUpdate(); s3eKeyboardUpdate(); // S3E applications should yield frequently s3eDeviceYield(); } // clear up game object engine.Destroy(); return 0; }
S3E_MAIN_DECL void IwMain() { Init(); // Set screen clear colour IwGxSetColClear(0, 0, 0, 0xff); IwGxPrintSetColour(128, 128, 128); while (1) { s3eDeviceYield(0); s3eKeyboardUpdate(); s3ePointerUpdate(); int64 start = s3eTimerGetMs(); bool result = Update(); if ( ((result == false) || (s3eKeyboardGetState(s3eKeyEsc) & S3E_KEY_STATE_DOWN) || (s3eKeyboardGetState(s3eKeyAbsBSK) & S3E_KEY_STATE_DOWN) || (s3eDeviceCheckQuitRequest())) ) break; Render(); // Attempt frame rate while ((s3eTimerGetMs() - start) < MS_PER_FRAME) { int32 yield = (int32) (MS_PER_FRAME - (s3eTimerGetMs() - start)); if (yield<0) break; s3eDeviceYield(yield); } } ShutDown(); }
void Game::Run() { uint64 now = s3eTimerGetMs(); while( true ) { s3eDeviceYield( 0 ); s3eKeyboardUpdate(); m_touchManager->Update(); m_accelerometerManager->Update(); m_webManager->Update(); if( ( s3eKeyboardGetState( s3eKeyEsc ) & S3E_KEY_STATE_DOWN ) || ( s3eKeyboardGetState( s3eKeyAbsBSK ) & S3E_KEY_STATE_DOWN ) || ( s3eDeviceCheckQuitRequest() ) ) { break; } const uint64 newTime = s3eTimerGetMs(); const uint64 deltaTime = newTime - now; now = newTime; Update( deltaTime ); Render(); while( ( s3eTimerGetMs() - newTime) < s_msPerFrame ) { const int32 yield = static_cast<int32>( s_msPerFrame - ( s3eTimerGetMs() - newTime ) ); if( yield < 0 ) { break; } s3eDeviceYield( yield ); } } }
//-------------------------------------------------------------------------- // Main global function //-------------------------------------------------------------------------- S3E_MAIN_DECL void IwMain() { #ifdef EXAMPLE_DEBUG_ONLY // Test for Debug only examples #endif // Example main loop input_engine = GetInputEngine(); game_class = new Game(); game_class->Initialize(); input_engine->RegisterInputController(game_class); //graphics_engine = GetHPTGraphicsEngine(); //graphics_engine->SetBackgroundColor(100,100,255); //ExampleInit(); s3eDeviceRegister(S3E_DEVICE_PAUSE,PauseCallback,NULL); s3eDeviceRegister(S3E_DEVICE_UNPAUSE,UnPauseCallback,NULL); s3eSurfaceRegister(S3E_SURFACE_SCREENSIZE,ScreenCallback,NULL); while (1) { s3eDeviceYield(0); s3eKeyboardUpdate(); //bool result = ExampleUpdate(); if( /*(result == false) ||*/ (s3eKeyboardGetState(s3eKeyEsc) & S3E_KEY_STATE_DOWN) || (s3eKeyboardGetState(s3eKeyLSK) & S3E_KEY_STATE_DOWN) || (s3eDeviceCheckQuitRequest())) break; input_engine->InputChanged(); game_class->ExecuteGame(); //ExampleRender(); //graphics_engine->BeginFrame(); //graphics_engine->EndFrame(); //s3eSurfaceShow(); } input_engine->Release(); delete game_class; //graphics_engine->Release(); //ExampleShutDown(); }
bool ExamplesMainUpdate() { s3eKeyboardUpdate(); s3ePointerUpdate(); if (!ExampleUpdate()) { s3eDebugTracePrintf("ExampleUpdate returned false, exiting.."); return false; } if (g_ClearScreen) s3eSurfaceClear(0xff,0xff,0xff); ExampleRender(); ButtonsRender(); SoftkeysRender(); if (g_DrawCursor) CursorRender(); s3eSurfaceShow(); s3eDeviceYield(FRAMETIME); return true; }
void doMain() { if(s3ePointerGetInt(S3E_POINTER_MULTI_TOUCH_AVAILABLE)){ s3ePointerRegister(S3E_POINTER_TOUCH_EVENT, (s3eCallback)MultiTouchButtonCB, NULL); s3ePointerRegister(S3E_POINTER_TOUCH_MOTION_EVENT, (s3eCallback)MultiTouchMotionCB, NULL); } else { s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, (s3eCallback)SingleTouchButtonCB, NULL); s3ePointerRegister(S3E_POINTER_MOTION_EVENT, (s3eCallback)SingleTouchMotionCB, NULL); } IwGetResManager()->LoadGroup("resource_groups/palate.group"); palateGroup = IwGetResManager()->GetGroupNamed("Palate"); std::vector<int> ui_texture_hashes; uint background_hash = IwHashString("background_clean"); CIwResList* resources = palateGroup->GetListHashed(IwHashString("CIwTexture")); for(CIwManaged** itr = resources->m_Resources.GetBegin(); itr != resources->m_Resources.GetEnd(); ++itr) { if(background_hash != (*itr)->m_Hash) { ui_texture_hashes.push_back((*itr)->m_Hash); } } CIwMaterial* background = new CIwMaterial(); background->SetTexture((CIwTexture*)palateGroup->GetResNamed("background_clean", IW_GX_RESTYPE_TEXTURE)); background->SetModulateMode(CIwMaterial::MODULATE_NONE); background->SetAlphaMode(CIwMaterial::ALPHA_DEFAULT); unit_ui = new CIwMaterial(); unit_ui->SetModulateMode(CIwMaterial::MODULATE_NONE); unit_ui->SetAlphaMode(CIwMaterial::ALPHA_DEFAULT); unit_ui->SetTexture((CIwTexture*)palateGroup->GetResNamed("TAKE2", IW_GX_RESTYPE_TEXTURE)); CIwSVec2 bg_wh(320, 480); CIwSVec2 ui_wh(80, 480); CIwSVec2 ui_offset(240, 0); CIwSVec2 uv(0, 0); CIwSVec2 duv(IW_GEOM_ONE, IW_GEOM_ONE); init(); IwGxLightingOff(); IwGxSetColClear(255, 255, 255, 255); float worldScrollMultiplier = 0.75; if(s3eDeviceGetInt(S3E_DEVICE_OS) == S3E_OS_ID_IPHONE) { worldScrollMultiplier = 0.925; } while (1) { int64 start = s3eTimerGetMs(); s3eDeviceYield(0); s3eKeyboardUpdate(); s3ePointerUpdate(); if ((s3eKeyboardGetState(s3eKeyEsc) & S3E_KEY_STATE_DOWN) || (s3eKeyboardGetState(s3eKeyAbsBSK) & S3E_KEY_STATE_DOWN) || (s3eDeviceCheckQuitRequest())) { break; } switch(currentState) { case MAIN_MENU: if(s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED) { currentState = IN_GAME; } if(frameCount % FRAMES_PER_UPDATE == 0) { mainMenu->tick(); } mainMenu->render(); break; case IN_GAME: IwGxSetMaterial(background); IwGxSetScreenSpaceSlot(-1); IwGxDrawRectScreenSpace(&CIwSVec2::g_Zero, &bg_wh, &uv, &duv); IwGxSetMaterial(unit_ui); IwGxSetScreenSpaceSlot(1); IwGxDrawRectScreenSpace(&ui_offset, &ui_wh, &uv, &duv); if (worldScrollSpeed > .0005 || worldScrollSpeed < -.0005) { game->rotate(worldScrollSpeed); worldScrollSpeed *= worldScrollMultiplier; } if(frameCount % FRAMES_PER_UPDATE == 0) { game->tick(); } game->render(); if(!renderTouches()) { break; } break; } IwGxFlush(); IwGxSwapBuffers(); // Attempt frame rate while ((s3eTimerGetMs() - start) < MS_PER_FRAME){ int32 yield = (MS_PER_FRAME - (s3eTimerGetMs() - start)); if (yield < 0) { break; } s3eDeviceYield(yield); } frameCount++; IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F); } delete game; delete mainMenu; delete localPlayer; delete opponentPlayer; delete background; delete unit_ui; palateGroup->Finalise(); for(int i = 0; i < MAX_TOUCHES; ++i) if(touches[i].unit) delete touches[i].unit; }
void GameplayState::HandleEvent(StateEngine* state) { m_Moving = false; if ( (s3eKeyboardGetState(s3eKeySpace) & S3E_POINTER_STATE_DOWN) && m_SpacePressed == false) { if (m_CharacterIndex == MANDY) { characters[MANDY]->Jump(); } m_SpacePressed = true; } if( (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_DOWN)) { m_ClickLocation = (CIwFVec2((s3ePointerGetX() - (float)m_Cam->GetPosition().x) , (s3ePointerGetY() - (float)m_Cam->GetPosition().y ))); for (int i = 0; i < 3; i++) { // Check collision with the character portraits if (m_Portraits[i]->isColliding(CIwFVec2((float)s3ePointerGetX(), (float)s3ePointerGetY()))) { if (m_CharacterIndex != i) { m_Cam->SetPosition(CIwSVec2(static_cast<int16>(-characters[i]->GetPosition().x + (screenWidth /2)), static_cast<int16>(-characters[i]->GetPosition().y + (screenHeight - characters[i]->GetHeight())))); m_CharacterIndex = i; // Set the character to be the element that was collided against m_PortraitSounds[i]->Play(); } } } if (n_guiButtons[0]->isColliding((CIwFVec2((float)s3ePointerGetX(), (float)s3ePointerGetY())))) { if (characters[m_CharacterIndex]->GetDirection() == FACING_RIGHT) characters[m_CharacterIndex]->SetDirection(FACING_LEFT); m_Moving = true; characters[m_CharacterIndex]->MoveBy(CIwFVec2((-5 * state->m_deltaTime) - characters[m_CharacterIndex]->GetMovSpeed().x, 0),state->m_deltaTime); CheckCollisions(m_CharacterIndex); } if (n_guiButtons[1]->isColliding((CIwFVec2((float)s3ePointerGetX(), (float)s3ePointerGetY())))) { if (characters[m_CharacterIndex]->GetDirection() == FACING_LEFT) characters[m_CharacterIndex]->SetDirection(FACING_RIGHT); m_Moving = true; characters[m_CharacterIndex]->MoveBy(CIwFVec2((5 * state->m_deltaTime) + characters[m_CharacterIndex]->GetMovSpeed().x, 0),state->m_deltaTime); CheckCollisions(m_CharacterIndex); } if (characters[DAVE]->isColliding(characters[NIGEL]->GetPosition()) && (m_canThrow == false) && m_CharacterIndex == DAVE) { if (characters[NIGEL]->isColliding((CIwFVec2(s3ePointerGetX() - (float)m_Cam->GetPosition().x , s3ePointerGetY() - (float)m_Cam->GetPosition().y )))) { while (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_DOWN) { // Continue to poll input s3ePointerUpdate(); s3eKeyboardUpdate(); m_canThrow = true; m_throwingTarget->SetPosition((CIwFVec2((s3ePointerGetX() - (float)m_Cam->GetPosition().x) - ( m_throwingTarget->GetWidth() /2) , (s3ePointerGetY() - (float)m_Cam->GetPosition().y ) - (m_throwingTarget->GetHeight() /2)))); m_throwingTarget->UpdateCollider(); // Draw the current state or else we'll be in a loop that will show no updated frame state->Draw(); m_ThrowingSound->ResetCounter(); } m_isThrowing = true; m_ThrowingSound->Play(); m_CharacterIndex = NIGEL; } } m_MouseClicked = true; } if (m_isThrowing) { characters[NIGEL]->UpdateCollider(); if (m_canThrow) { if (!characters[NIGEL]->isColliding(m_throwingTarget, CIwFVec2(m_throwingTarget->GetWidth() /2, -(m_throwingTarget->GetHeight() / 2))) && m_ThrowingTargetSide == 0 && m_Moving == false) { m_ThrowingNigelSound->Play(); characters[NIGEL]->LerpTo(CIwFVec2(m_throwingTarget->GetPosition().x, m_throwingTarget->GetPosition().y), 0.05f); } else { m_canThrow = false; m_ThrowingNigelSound->ResetCounter(); } } else { m_isThrowing = false; characters[NIGEL]->MoveBy(CIwFVec2(m_ThrowingTargetSide * 2,2),state->m_deltaTime); } } if (m_gameOver) { state->ChangeState(GameoverState::Instance()); } }
bool update() { ThreadMessages::message msg; while (_threadMessages.peek(msg, true)) { } #ifdef __S3E__ s3eDeviceYield(0); s3eKeyboardUpdate(); s3ePointerUpdate(); bool done = false; if (s3eDeviceCheckQuitRequest()) done = true; if (s3eKeyboardGetState(s3eKeyEsc) & S3E_KEY_STATE_PRESSED) done = true; return done; #endif #if OXYGINE_SDL || EMSCRIPTEN //log::messageln("update"); Input *input = &Input::instance; bool done = false; SDL_Event event; while (SDL_PollEvent(&event)) { Event ev(Input::event_platform); ev.userData = &event; Input::instance.dispatchEvent(&ev); ObjectScript::processKeyboardEvent(&ev, getStage().get()); switch(event.type) { case SDL_QUIT: done = true; break; case SDL_WINDOWEVENT: { /* if (event.window.event == SDL_WINDOWEVENT_ENTER) active = false; if (event.window.event == SDL_WINDOWEVENT_LEAVE) active = true; */ if (event.window.event == SDL_WINDOWEVENT_MINIMIZED) active = false; if (event.window.event == SDL_WINDOWEVENT_RESTORED) active = true; bool newFocus = focus; if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) newFocus = false; if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) newFocus = true; if (focus != newFocus) { focus = newFocus; #if HANDLE_FOCUS_LOST if (focus) focusAcquired(); log::messageln("focus: %d", (int)focus); Event ev(focus ? Stage::ACTIVATE : Stage::DEACTIVATE); if (getStage()) getStage()->dispatchEvent(&ev); if (!focus) focusLost(); #endif } //log::messageln("SDL_SYSWMEVENT %d", (int)event.window.event); break; } case SDL_MOUSEWHEEL: input->sendPointerWheelEvent(event.wheel.y, &input->_pointerMouse); break; case SDL_KEYDOWN: { KeyEvent ev(KeyEvent::KEY_DOWN, &event.key); getStage()->dispatchEvent(&ev); } break; case SDL_KEYUP: { KeyEvent ev(KeyEvent::KEY_UP, &event.key); getStage()->dispatchEvent(&ev); } break; #if SDL_VIDEO_OPENGL case SDL_MOUSEMOTION: input->sendPointerMotionEvent((float)event.motion.x, (float)event.motion.y, 1.0f, &input->_pointerMouse); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: { MouseButton b = MouseButton_Left; switch(event.button.button) { case 1: b = MouseButton_Left; break; case 2: b = MouseButton_Middle; break; case 3: b = MouseButton_Right; break; } input->sendPointerButtonEvent(b, (float)event.button.x, (float)event.button.y, 1.0f, event.type == SDL_MOUSEBUTTONDOWN ? TouchEvent::TOUCH_DOWN : TouchEvent::TOUCH_UP, &input->_pointerMouse); } break; #else case SDL_FINGERMOTION: { //log::messageln("SDL_FINGERMOTION"); Vector2 pos = convertTouch(event); input->sendPointerMotionEvent( pos.x, pos.y, event.tfinger.pressure, input->getTouchByID((int)event.tfinger.fingerId)); } break; case SDL_FINGERDOWN: case SDL_FINGERUP: { //log::messageln("SDL_FINGER"); Vector2 pos = convertTouch(event); input->sendPointerButtonEvent( MouseButton_Touch, pos.x, pos.y, event.tfinger.pressure, event.type == SDL_FINGERDOWN ? TouchEvent::TOUCH_DOWN : TouchEvent::TOUCH_UP, input->getTouchByID((int)event.tfinger.fingerId)); } break; #endif } } return done; #elif EMSCRIPTEN return false; #endif log::warning("update not implemented"); return true; }
int main(int, char**) { IwGxInit(); // Setup Dear ImGui binding IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls ImGui_Marmalade_Init(true); // Setup style ImGui::StyleColorsDark(); //ImGui::StyleColorsClassic(); // Load Fonts // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. // - Read 'misc/fonts/README.txt' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f); //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //IM_ASSERT(font != NULL); bool show_demo_window = true; bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); // Main loop while (true) { if (s3eDeviceCheckQuitRequest()) break; // Poll and handle inputs // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. s3eKeyboardUpdate(); s3ePointerUpdate(); // Start the Dear ImGui frame ImGui_Marmalade_NewFrame(); ImGui::NewFrame(); // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!). if (show_demo_window) ImGui::ShowDemoWindow(&show_demo_window); // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window. { static float f = 0.0f; static int counter = 0; ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it. ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too) ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state ImGui::Checkbox("Another Window", &show_another_window); ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated) counter++; ImGui::SameLine(); ImGui::Text("counter = %d", counter); ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); ImGui::End(); } // 3. Show another simple window. if (show_another_window) { ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked) ImGui::Text("Hello from another window!"); if (ImGui::Button("Close Me")) show_another_window = false; ImGui::End(); } // Rendering ImGui::Render(); IwGxSetColClear(clear_color.x * 255, clear_color.y * 255, clear_color.z * 255, clear_color.w * 255); IwGxClear(); ImGui_Marmalade_RenderDrawData(ImGui::GetDrawData()); IwGxSwapBuffers(); s3eDeviceYield(0); } // Cleanup ImGui_Marmalade_Shutdown(); ImGui::DestroyContext(); IwGxTerminate(); return 0; }