Ejemplo n.º 1
0
	void GameLogicProcessor::FrameStart()
	{
		// LOG(EngineLog, BE_LOG_VERBOSE) << "GameLogicProcessor::FrameStart\n";

		// Initialize all components not yet initialized
		for (ComponentHandle hdl : m_notInitialized)
		{
			auto& pieces = gameLogicHolder->getComponent(hdl)->m_gamelogics;
			for (size_t i = 0; i < pieces.size(); ++i)
			{
				GameLogic* logic = pieces[i];
				GameLogic::RunEvents ev = logic->getRunEvents();
				if (ev & GameLogic::RunEvents::EFrameStart){
					m_onFrameStart.emplace_back(logic);
				}
				if (ev & GameLogic::RunEvents::EFrameMiddle){
					m_onFrameMiddle.emplace_back(logic);
				}
				if (ev & GameLogic::RunEvents::EFrameEnd){
					m_onFrameEnd.emplace_back(logic);
				}

				if (!logic->init()){
					LOG(EngineLog, BE_LOG_ERROR) << "GameLogicProcessor: GameLogicComponent " << hdl << " logic " << i << " failed to Init! ";
				}
			}
		}
		m_notInitialized.clear();

		// Run FrameStart on all components
		for (GameLogic* l : m_onFrameStart){
			l->frameStart();
		}
	}
Ejemplo n.º 2
0
	void GameLogicProcessor::onMessage(const MsgComponentDestroyed<GameLogicComponent>& msg)
	{
		GameLogicComponent* comp = gameLogicHolder->getComponent(msg.component);
		auto& pieces = comp->m_gamelogics;
		for (size_t i = 0; i < pieces.size(); ++i)
		{
			GameLogic* logic = pieces[i];
			GameLogic::RunEvents ev = logic->getRunEvents();
			if (ev & GameLogic::RunEvents::EFrameStart) {
				removeFrom(logic, m_onFrameStart);
			}

			if (ev & GameLogic::RunEvents::EFrameMiddle) {
				removeFrom(logic, m_onFrameMiddle);
			}

			if (ev & GameLogic::RunEvents::EFrameEnd) {
				removeFrom(logic, m_onFrameEnd);
			}

			logic->end();
		}
	}