Exemplo n.º 1
0
static int simulationUpdate(DATA* data, threadData_t *threadData, SOLVER_INFO* solverInfo)
{
  prefixedName_updateContinuousSystem(data, threadData);

  if (solverInfo->solverMethod == S_SYM_IMP_EULER) data->callback->symEulerUpdate(data, solverInfo->solverStepSize);

  saveZeroCrossings(data, threadData);
  messageClose(LOG_SOLVER);

  /***** Event handling *****/
  if (measure_time_flag) rt_tick(SIM_TIMER_EVENT);

  int syncRet = handleTimers(data, threadData, solverInfo);
  int syncRet1;
  do
  {
    int eventType = checkEvents(data, threadData, solverInfo->eventLst, &(solverInfo->currentTime), solverInfo);
    if(eventType > 0 || syncRet == 2) /* event */
    {
      threadData->currentErrorStage = ERROR_EVENTHANDLING;
      infoStreamPrint(LOG_EVENTS, 1, "%s event at time=%.12g", eventType == 1 ? "time" : "state", solverInfo->currentTime);
      /* prevent emit if noEventEmit flag is used */
      if (!(omc_flag[FLAG_NOEVENTEMIT])) /* output left limit */
        sim_result.emit(&sim_result, data, threadData);
      handleEvents(data, threadData, solverInfo->eventLst, &(solverInfo->currentTime), solverInfo);
      messageClose(LOG_EVENTS);
      threadData->currentErrorStage = ERROR_SIMULATION;

      solverInfo->didEventStep = 1;
      overwriteOldSimulationData(data);
    }
    else /* no event */
    {
      solverInfo->laststep = solverInfo->currentTime;
      solverInfo->didEventStep = 0;
    }

    if (measure_time_flag) rt_accumulate(SIM_TIMER_EVENT);
    /***** End event handling *****/


    /***** check state selection *****/
    if (stateSelection(data, threadData, 1, 1))
    {
      /* if new set is calculated reinit the solver */
      solverInfo->didEventStep = 1;
      overwriteOldSimulationData(data);
    }

    /* Check for warning of variables out of range assert(min<x || x>xmax, ...)*/
    data->callback->checkForAsserts(data, threadData);

    storePreValues(data);
    storeOldValues(data);

    syncRet1 = handleTimers(data, threadData, solverInfo);
    syncRet = syncRet1 == 0 ? syncRet : syncRet1;
  } while (syncRet1);
  return syncRet;
}
Exemplo n.º 2
0
//-------------------------------------------------------------------------------------
void Loginapp::handleMainTick()
{
	g_kbetime++;
	threadPool_.onMainThreadTick();
	networkInterface().processChannels(&LoginappInterface::messageHandlers);
	pendingLoginMgr_.process();
	pendingCreateMgr_.process();
	handleTimers();
}
Exemplo n.º 3
0
void EntityApp<E>::handleGameTick()
{
	// time_t t = ::time(NULL);
	// DEBUG_MSG("EntityApp::handleGameTick[%"PRTime"]:%u\n", t, time_);

	g_kbetime++;
	threadPool_.onMainThreadTick();
	handleTimers();
	getNetworkInterface().handleChannels(KBEngine::Mercury::MessageHandlers::pMainMessageHandlers);
}
Exemplo n.º 4
0
//-------------------------------------------------------------------------------------
void Dbmgr::handleMainTick()
{
	 //time_t t = ::time(NULL);
	 //DEBUG_MSG("Dbmgr::handleGameTick[%"PRTime"]:%u\n", t, time_);
	
	g_kbetime++;
	threadPool_.onMainThreadTick();
	DBUtil::handleMainTick();
	handleTimers();
	networkInterface().processChannels(&DbmgrInterface::messageHandlers);
}
Exemplo n.º 5
0
void ApplicationContext::update()
{
  if (_app_state == ApplicationLifeState::RUNNABLE)
  {
    _app_state = ApplicationLifeState::RUNNING;
    handleEvents();
    handleTimers();
    if (_app_state == ApplicationLifeState::RUNNING)
      onUpdate();
    if (_app_state == ApplicationLifeState::RUNNING)
      _app_state = ApplicationLifeState::RUNNABLE;
    _last_update_time = System::getInstance()->getTime();
  }
}
Exemplo n.º 6
0
//-------------------------------------------------------------------------------------
void PythonApp::handleTimeout(TimerHandle handle, void * arg)
{
	ServerApp::handleTimeout(handle, arg);

	switch (reinterpret_cast<uintptr>(arg))
	{
	case TIMEOUT_GAME_TICK:
		++g_kbetime;
		handleTimers();
		break;
	default:
		break;
	}
}
Exemplo n.º 7
0
//-------------------------------------------------------------------------------------
void ClientApp::handleGameTick()
{
	g_kbetime++;
	threadPool_.onMainThreadTick();
	handleTimers();
	
	if(lastAddr.ip != 0)
	{
		getNetworkInterface().deregisterChannel(lastAddr);
		getNetworkInterface().registerChannel(pServerChannel_);
		lastAddr.ip = 0;
	}

	getNetworkInterface().processAllChannelPackets(KBEngine::Mercury::MessageHandlers::pMainMessageHandlers);
	tickSend();

	switch(state_)
	{
		case C_STATE_INIT:
			state_ = C_STATE_PLAY;
			break;
		case C_STATE_INITLOGINAPP_CHANNEL:
			state_ = C_STATE_PLAY;
			break;
		case C_STATE_LOGIN:

			state_ = C_STATE_PLAY;

			if(!ClientObjectBase::login())
			{
				WARNING_MSG("ClientApp::handleGameTick: login is failed!\n");
				return;
			}

			break;
		case C_STATE_LOGIN_GATEWAY_CHANNEL:
			{
				state_ = C_STATE_PLAY;

				bool exist = false;

				if(pServerChannel_->endpoint())
				{
					lastAddr = pServerChannel_->endpoint()->addr();
					getNetworkInterface().dispatcher().deregisterFileDescriptor(*pServerChannel_->endpoint());
					exist = getNetworkInterface().findChannel(pServerChannel_->endpoint()->addr()) != NULL;
				}

				bool ret = initBaseappChannel() != NULL;
				if(ret)
				{
					if(!exist)
					{
						getNetworkInterface().registerChannel(pServerChannel_);
						pTCPPacketReceiver_ = new Mercury::TCPPacketReceiver(*pServerChannel_->endpoint(), getNetworkInterface());
					}
					else
					{
						pTCPPacketReceiver_->endpoint(pServerChannel_->endpoint());
					}

					getNetworkInterface().dispatcher().registerFileDescriptor(*pServerChannel_->endpoint(), pTCPPacketReceiver_);
					
					// 先握手然后等helloCB之后再进行登录
					Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject();
					(*pBundle).newMessage(BaseappInterface::hello);
					(*pBundle) << KBEVersion::versionString();
					
					if(Mercury::g_channelExternalEncryptType == 1)
					{
						pBlowfishFilter_ = new Mercury::BlowfishFilter();
						(*pBundle).appendBlob(pBlowfishFilter_->key());
						pServerChannel_->pFilter(NULL);
					}
					else
					{
						std::string key = "";
						(*pBundle).appendBlob(key);
					}

					pServerChannel_->pushBundle(pBundle);
					// ret = ClientObjectBase::loginGateWay();
				}
			}
			break;
		case C_STATE_LOGIN_GATEWAY:

			state_ = C_STATE_PLAY;

			if(!ClientObjectBase::loginGateWay())
			{
				WARNING_MSG("ClientApp::handleGameTick: loginGateWay is failed!\n");
				return;
			}

			break;
		case C_STATE_PLAY:
			break;
		default:
			KBE_ASSERT(false);
			break;
	};
}
Exemplo n.º 8
0
int main(void)
{
	int8_t encCnt = 0;
	uint8_t action = ACTION_NOACTION;

	/* Init hardware */
	hwInit();
	#if 0
	if (extFunc == USE_DS18B20) {
		ds18x20ConvertTemp();
		setSensTimer(TEMP_MEASURE_TIME);
	}
	#endif
	while (1) {
		#if 0
		/* Control temperature */
		if (extFunc == USE_DS18B20) {
			if (getSensTimer() == 0) {
				ds18x20GetAllTemps();
				ds18x20ConvertTemp();
				setSensTimer(SENSOR_POLL_INTERVAL);
			}
			tempControlProcess();
		}
		#endif
		/* Emulate poweroff if any of timers expired */
		if (getStbyTimer() == 0 || getSilenceTimer() == 0)
			action = CMD_RC_STBY;

		/* Check alarm and update time */
		if (action == ACTION_NOACTION)
			action = checkAlarmAndTime();

		/* Convert input command to action */
		if (action == ACTION_NOACTION)
			action = getAction();

		/* Handle action */
		handleAction(action);

		/* Handle encoder */
		encCnt = getEncoder();				/* Get value from encoder */
		if (action == CMD_RC_VOL_UP)		/* Emulate VOLUME_UP action as encoder action */
			encCnt++;
		if (action == CMD_RC_VOL_DOWN)	/* Emulate VOLUME_DOWN action as encoder action */
			encCnt--;
		handleEncoder(encCnt);

		/* Reset silence timer on any action */
		if (encCnt || (action != ACTION_NOACTION && action != ACTION_EXIT_STANDBY))
			enableSilenceTimer();

		/* Reset handled action */
		action = ACTION_NOACTION;

		/* Check if we need exit to default mode*/
		handleExitDefaultMode();

		/* Switch to timer mode if it expires */
		handleTimers();

		/* Clear screen if mode has changed */
		handleModeChange();

		/* Show things */
		showScreen();
	}

	return 0;
}