Exemplo n.º 1
0
 virtual void Work()
 {
   unsigned int start = ht_GetMSCount();
   const int cnt = 30000000;
   for( int i = 0 ; i < cnt ; i++ )
   {
     g_List2Thread.Add(&mNum);
   }
   unsigned int d = ht_GetMSCount() - start;
   printf("Producer d = %f mcs\n", (d*1000.0f)/cnt);
 }
Exemplo n.º 2
0
//------------------------------------------------------------------------------------
void TBehaviourClient::Work()
{
  mClient->Work();
  mHandler.Work();

  unsigned int now = ht_GetMSCount();
  if(now < mTimeNextState)
    return;

  mTimeNextState = RandomTime();
  switch(mState)
  {
    case eInit:
    case eIdle:
      Connect();
      mState = eConnect;
      break;
    case eConnect:
      Close();
      mState = eIdle;
      break;
    case eStop:
      break;
  }
}
Exemplo n.º 3
0
//---------------------------------------------------------------------------
void TTestControlTank::Recv(void* data, int size)
{
	if(size!=sizeof(TDesc))
	{
		BL_FIX_BUG();
		return;
	}
	//*(mDesc) = *((TDesc*)data);
	memcpy(mDesc.get(), data, size);
	mTimeRecv_ms = ht_GetMSCount();
}
Exemplo n.º 4
0
//---------------------------------------------------------------------------
void TTestControlTank::SetupParamForNow()
{
	unsigned int now_ms = ht_GetMSCount();
	unsigned int delta = now_ms - mTimeRecv_ms;

	float angleGun    = mDesc->mAngleGun    + delta * mDesc->mSpeedRotateGun;
	float angleTurret = mDesc->mAngleTurret + delta * mDesc->mSpeedRotateTurret;

	mTank->RotateTurret(angleTurret);
	mTank->RotateVerticalGun(angleGun);
}
Exemplo n.º 5
0
//---------------------------------------------------------------------------
void TTestControlTank::UpdateAngle()
{
	unsigned int now_ms = ht_GetMSCount();
	unsigned int delta = (mTimeLastUpdate_ms==0) ? 0:
												now_ms - mTimeLastUpdate_ms;
	
	mDesc->mAngleGun    = mDesc->mAngleGun    + delta * mDesc->mSpeedRotateGun;
	mDesc->mAngleTurret = mDesc->mAngleTurret + delta * mDesc->mSpeedRotateTurret;

	mTimeLastUpdate_ms = now_ms;
}
Exemplo n.º 6
0
//----------------------------------------------------------------
bool TModuleServerLogic::WorkInherit()
{
  InputFromSynchroPoint();
  bool res = WorkServer();
  CalcAndWaitRestTime();

  EndWork();
  res &= !NeedExit();

  mStartTime = ht_GetMSCount();
  return res;
}
//----------------------------------------------------------------------------------------------
void TPhysicEngine_Bullet::Work(bool first_start)
{
  // делать замеры времени самостоятельно
  unsigned int now_ms = ht_GetMSCount();
  unsigned int dt = now_ms - mPrevTimeWork;
  float dt_sec = first_start ? 0 : dt/1000.0f;

  BOOST_FOREACH(TMapIntWorldVT& ID_World, mMapIDWorld)
    ID_World.second.pWorld->stepSimulation(dt_sec, 1, dt_sec);

  mPrevTimeWork = now_ms;
}
Exemplo n.º 8
0
//----------------------------------------------------------------
void TModuleServerLogic::CalcAndWaitRestTime()
{
  if(mCycleTime_ms == 0)
    return;

  unsigned int now = ht_GetMSCount();

  unsigned int work_time = now - mStartTime;// потрачено времени
  double loadProcent = (work_time*100.0)/mCycleTime_ms;// расчет нагрузки
  mStatLoad.add(loadProcent);                         // занести в статистику

  GetLogger(STR_NAME_SERVER_LOGIC)->WriteF("%d\n",int(mStatLoad.aver()));
  // спать остаток времени
  if(now>mCycleTime_ms+mStartTime) return;
  unsigned int time_sleep = mStartTime + mCycleTime_ms - now;
  ht_msleep(time_sleep);
}
Exemplo n.º 9
0
//-----------------------------------------------------------------
void TModuleTimer::WorkTimer()
{
  unsigned int now_ms = ht_GetMSCount();
  int cnt = mVecTimer.size();
  for( int i = 0 ; i < cnt ; i++)
  {
    TDescTimer* pDesc = mVecTimer[i];
    if(pDesc->enable)
      if(pDesc->start_time_ms + pDesc->interval_ms < now_ms)
      {
        pDesc->start_time_ms = now_ms;
        TEvent event;
        event.id = pDesc->id;
        AddEventCopy(mLogicID, &event,sizeof(event));
      }
  }
}
Exemplo n.º 10
0
  // делать замеры времени самостоятельно
  BOOST_FOREACH(TMapIntPtrWorldVT& ID_World, mMapIDWorld)
  {
    TWorld* pWorld = ID_World.second;
    if(pWorld->state==eStateRealTime || pWorld->state==eStateControlTime)
    {
      unsigned int now_ms = ht_GetMSCount();
      unsigned int dt = now_ms - pWorld->prevTimeWork;

      bool first_start = pWorld->state != pWorld->prevState;
      float dt_sec = first_start ? 0 : dt/1000.0f;
      
      if(pWorld->state==eStateControlTime)
        dt_sec /= pWorld->ratioRealTimeToControl;

      pWorld->pWorld->stepSimulation(dt_sec, 1, dt_sec);
      
      pWorld->prevTimeWork = now_ms;
      pWorld->prevState = pWorld->state;
    }
  }
Exemplo n.º 11
0
int main(int argc, char** argv)
{
  GetLogger()->Register(STR_NAME_MMO_ENGINE);
  GetLogger()->Register(STR_NAME_NET_TRANSPORT);
  GetLogger()->Init("Client_Test");
  GetLogger()->SetPrintf(false);
  GetLogger()->SetEnable(false);

  THandlerMMO_Client handler;

  TInputCmdTestMMO_Client inputCmd;
  bool res = inputCmd.SetArg(argc, argv);
  BL_ASSERT(res);

  TInputCmdTestMMO_Client::TInput inputArg;
  inputCmd.Get(inputArg);

  TMakerTransport makerTransport;
  std::vector<nsMMOEngine::TClient*> pArrClient;
  for( int i = 0 ; i < inputArg.count ; i++ )
  {
    nsMMOEngine::TClient* pClient = new nsMMOEngine::TClient;
    pClient->Init(&makerTransport);
    nsMMOEngine::TDescOpen descOpen;
    descOpen.port = inputArg.begin_port + i;
    pClient->Open(&descOpen); 
    pClient->SetDstObject(&handler);
    pClient->SetSelfID(descOpen.port);
    
    pArrClient.push_back(pClient);
  }

  const char* sLocalHost = inputArg.ip_server.data();
  unsigned int masterIP = boost::asio::ip::address_v4::from_string(sLocalHost).to_ulong();
  int indexClientOnLogin = 0;
  while(true)
  {
    unsigned int startTime = ht_GetMSCount();
    // Login
    int cnt = std::min(inputArg.count, indexClientOnLogin+STEP_LOGIN);
    for( int i = indexClientOnLogin ; i < cnt ; i++ )
    {
      char sLogin[100];
      sprintf(sLogin, "%d", inputArg.begin_id + i);
      pArrClient[i]->Login(masterIP, MASTER_PORT,
        sLogin, strlen(sLogin), (void*)PASSWORD_CLIENT, strlen(PASSWORD_CLIENT));
    }
    indexClientOnLogin = cnt;

    // Work
    for( int i = 0 ; i < indexClientOnLogin ; i++ )
      pArrClient[i]->Work();
    handler.Work();
    // burn rest time
    unsigned int deltaTime = ht_GetMSCount() - startTime;
    static int old_delta_time = -1;
    if((old_delta_time!=deltaTime)&&
       (deltaTime>70))
    {
      printf("dTime=%d\n", deltaTime);
      old_delta_time = deltaTime;
    }
    if(deltaTime < CLIENT_QUANT_TIME)
      ht_msleep(CLIENT_QUANT_TIME-deltaTime);
  }

  return 0;
}
Exemplo n.º 12
0
  //  }
  //  unsigned int delta = ht_GetMSCount() - start;
  //  float speed = float(delta)/cnt;
  //  printf("Generate RSA key on client speed = %f\n", speed);
  //  //printf("max = %u, min = %u\n", max, min);
  //  //BOOST_FOREACH(unsigned int d, lDelta)
  //    //printf("delta=%u\n",d);
  //}
  //_getch();

  // на стороне Клиента
  mngCtxClient.SendRSA_PublicKey(ip_port_server, RSApublicKey);
  
  // отослали Серверу
  int cnt = 0;
  unsigned int start = ht_GetMSCount();
  for( int i = 0 ; i < cnt ; i++ )
  {
    res = mngCtxServer.RecvRSA_PublicKey(TIP_Port(0,i), (char*)RSApublicKey.GetPtr(), RSApublicKey.GetSize());
    mngCtxServer.SendAES_Key(TIP_Port(0,i), AESkey);
  }
  unsigned int delta = ht_GetMSCount() - start;
  float speed = float(delta)/cnt;
  printf("Recv RSA key on server and generate AES key speed = %f\n", speed);
  //_getch();

  res = mngCtxServer.RecvRSA_PublicKey(ip_port_client, (char*)RSApublicKey.GetPtr(), RSApublicKey.GetSize());
  mngCtxServer.SendAES_Key(ip_port_client, AESkey);

  // отослали Клиенту
  res = mngCtxClient.RecvAES_Key(ip_port_server, (char*)AESkey.GetPtr(), AESkey.GetSize());
Exemplo n.º 13
0
//------------------------------------------------------------------------------------
unsigned int TBehaviourClient::RandomTime()
{
  return ht_GetMSCount() + (unsigned int)(eDefTimeBegin + eDefTimeDelta * float(rand())/RAND_MAX);
}