void Scene::updateLua() { LuaEngine* sceneLuaEngine = getLuaEngine(); clearRenderFunctions();//Clean up last rendered stuff if(sceneLuaEngine) { if(sceneLuaEngine->isValid() && !sceneLuaEngine->shouldShutdown()){ //sceneLuaEngine->runGarbageCollector(); LuaEvent loopEvent = BindingCore_Events_Engine::createLoopEvent(sceneLuaEngine, uTickf); sceneLuaEngine->dispatchEvent(loopEvent); } } }
void LevelScene::update() { if(m_luaEngine.shouldShutdown()) { m_fader.setFade(10, 1.0, 1.0); setExiting(0, LvlExit::EXIT_Error); } Scene::update(); if(!m_isPauseMenu) tickAnimations(uTickf); if(!m_isLevelContinues) { //Level exit timeout m_exitLevelDelay -= uTickf; if(m_exitLevelDelay <= 0.0) { m_doExit = true; if(m_fader.isNull()) { if(PGE_MusPlayer::isPlaying()) PGE_MusPlayer::fadeOut(500); m_fader.setFade(10, 1.0, 0.01); } } } if(m_doExit) { if(m_exitLevelCode == LvlExit::EXIT_Closed) { m_fader.setFull(); m_isRunning = false; } else { if(m_fader.isFull()) m_isRunning = false; } } else if(m_isPauseMenu) processPauseMenu(); else { //Update physics is not pause menu updateLua();//Process LUA code m_systemEvents.processEvents(uTickf); m_events.processTimers(uTickf); //update cameras for(PGE_LevelCamera &cam : m_cameras) cam.updatePre(uTickf); processEffects(uTickf); if(!m_isTimeStopped) //if activated Time stop bonus or time disabled by special event { //Make world step processPhysics(uTickf); } while(!m_blockTransforms.empty()) { transformTask_block x = m_blockTransforms.front(); x.block->transformTo_x(x.id); m_blockTransforms.pop_front(); } // Send controller states to controllable objects m_player1Controller->sendControls(); m_player2Controller->sendControls(); //update players for(LVL_Player *plr : m_itemsPlayers) { plr->update(uTickf); if(PGE_Window::showDebugInfo) { m_debug_player_jumping = plr->m_jumpPressed; m_debug_player_onground = plr->onGround(); m_debug_player_foots = (int)plr->l_contactB.size(); } } for(size_t i = 0; i < m_blocksInFade.size(); i++) { if(m_blocksInFade[i]->tickFader(uTickf)) { m_blocksInFade.erase(m_blocksInFade.begin() + (int)i); i--; } } //Process activated NPCs //for(size_t i = 0; i < m_npcActive.size(); i++) for(auto i = m_npcActive.begin(); i != m_npcActive.end();) { LVL_Npc *n = *i; n->update(uTickf); if(n->isKilled()) { i = m_npcActive.erase(i); continue; } else if(n->activationTimeout <= 0) { if(!n->warpSpawing) n->deActivate(); if(n->wasDeactivated) { if(!isVizibleOnScreen(n->m_momentum) || !n->isVisible() || !n->is_activity) { n->wasDeactivated = false; i = m_npcActive.erase(i); continue; } } } ++i; } if(!m_isTimeStopped) //if activated Time stop bonus or time disabled by special event { //Process and resolve collisions processAllCollisions(); } /***************Collect garbage****************/ if(!m_npcDead.empty()) collectGarbageNPCs(); if(!m_playersDead.empty()) collectGarbagePlayers(); if(!m_blocksToDelete.empty()) collectGarbageBlocks(); /**********************************************/ //update cameras for(PGE_LevelCamera &cam : m_cameras) { cam.updatePost(uTickf); //! --------------DRAW HUD-------------------------------------- // TODO: Implement separated render queue for elements of HUD and provide render functions // are will draw HUD elements after world has drawn. LuaEngine *sceneLuaEngine = getLuaEngine(); if(sceneLuaEngine) { if(sceneLuaEngine->isValid() && !sceneLuaEngine->shouldShutdown()) { LuaEvent drawHUDEvent = BindingCore_Events_Engine::createDrawLevelHUDEvent(sceneLuaEngine, &cam, &m_playerStates[(size_t)(cam.playerID - 1)]); sceneLuaEngine->dispatchEvent(drawHUDEvent); } } //! ------------------------------------------------------------ } //Add effects into the render table for(Scene_Effect &item : WorkingEffects) { renderArrayAddFunction([&item](double camPosX, double camPosY) { item.render(camPosX, camPosY); }, item.m_zIndex); } //Clear garbage (be careful!) //luaEngine.runGarbageCollector(); } //Process interprocessing commands cache process_InterprocessCommands(); //Process Z-sort of the render functions renderArrayPrepare(); //Process message boxes m_messages.process(); }