Ejemplo n.º 1
0
/*
=================
rvEffect::ClientPredictionThink
=================
*/
void rvEffect::ClientPredictionThink( void ) {
    if ( gameLocal.isNewFrame ) {
        Think ( );
    }
    RunPhysics();
    Present();
}
Ejemplo n.º 2
0
//handles the updating routines.
void CEngine::DoThink()
{
	long iElapsedTicks = SDL_GetTicks() - m_lLastTick;
	m_lLastTick = SDL_GetTicks();
	Think(iElapsedTicks);
	m_iFPSTickCounter += iElapsedTicks;
}
Ejemplo n.º 3
0
/*
================
idItem::ClientPredictionThink
================
*/
void idItem::ClientPredictionThink( void ) {
	// only think forward because the state is not synced through snapshots
	if ( !gameLocal.isNewFrame ) {
		return;
	}
	Think();
}
Ejemplo n.º 4
0
void Philosopher(int phil) {
    Think(phil);

    int first = phil;
    int second = (phil+1)%PHIL_COUNT;


    pthread_mutex_lock(&footman_mutex);
    while (footman_count == (PHIL_COUNT-1)) pthread_cond_wait(&footman_cond, &footman_mutex);
    footman_count++;
    pthread_mutex_unlock(&footman_mutex);

    pthread_mutex_lock(&chopstick_mutexes[first]);
    pthread_mutex_lock(&chopstick_mutexes[second]);

    Eat(phil);

    pthread_mutex_unlock(&chopstick_mutexes[first]);
    pthread_mutex_unlock(&chopstick_mutexes[second]);

    pthread_mutex_lock(&footman_mutex);
    footman_count--;
    pthread_cond_signal(&footman_cond);
    pthread_mutex_unlock(&footman_mutex);
}
Ejemplo n.º 5
0
void CLogicThread::ThinkAllAffectedSentence(CTaskDialog* Dialog){
	deque<InfectedText>::iterator It = m_Text.m_InfectedSentenceList.begin();
	while(It != m_Text.m_InfectedSentenceList.end()){
		InfectedText& Text = *It;
		Think(Dialog,(CSentence*)Text.Text,Text.AlterPos);
		It++;
	}
    m_Text.m_InfectedSentenceList.clear();
};
Ejemplo n.º 6
0
void CLogicThread::ThinkAllAffectedClause(CTaskDialog* Dialog){
	deque<InfectedText>::iterator It = m_Text.m_InfectedClauseList.begin();
	while(It != m_Text.m_InfectedClauseList.end()){
		InfectedText& Text = *It;
        CClause* Clause = (CClause*)Text.Text;
		Think(Dialog,Clause,Text.AlterPos);
		It++;
	}
	m_Text.m_InfectedClauseList.clear();
}
Ejemplo n.º 7
0
void ParseGo(POS *p, char *ptr) {

  char token[180], bestmove_str[6], ponder_str[6];
  int pv[MAX_PLY];

  Timer.Clear();
  pondering = 0;

  for (;;) {
    ptr = ParseToken(ptr, token);
    if (*token == '\0')
      break;
    if (strcmp(token, "ponder") == 0) {
      pondering = 1;
    } else if (strcmp(token, "wtime") == 0) {
      ptr = ParseToken(ptr, token);
      Timer.SetData(W_TIME, atoi(token));
    } else if (strcmp(token, "btime") == 0) {
      ptr = ParseToken(ptr, token);
      Timer.SetData(B_TIME, atoi(token));
    } else if (strcmp(token, "winc") == 0) {
      ptr = ParseToken(ptr, token);
      Timer.SetData(W_INC, atoi(token));
    } else if (strcmp(token, "binc") == 0) {
      ptr = ParseToken(ptr, token);
      Timer.SetData(B_INC, atoi(token));
    } else if (strcmp(token, "movestogo") == 0) {
      ptr = ParseToken(ptr, token);
      Timer.SetData(MOVES_TO_GO, atoi(token));
    } else if (strcmp(token, "nodes") == 0) {
      ptr = ParseToken(ptr, token);
      Timer.SetData(FLAG_INFINITE, 1);
      Timer.SetData(MAX_NODES, atoi(token));
    } else if (strcmp(token, "movetime") == 0) {
      ptr = ParseToken(ptr, token);
      Timer.SetData(MOVE_TIME, atoi(token) );
    } else if (strcmp(token, "depth") == 0) {
      ptr = ParseToken(ptr, token);
      Timer.SetData(FLAG_INFINITE, 1);
      Timer.SetData(MAX_DEPTH, atoi(token));
    } else if (strcmp(token, "infinite") == 0) {
      Timer.SetData(FLAG_INFINITE, 1);
    }
  }

  Timer.SetSideData(p->side);
  Timer.SetMoveTiming();
  Think(p, pv);
  MoveToStr(pv[0], bestmove_str);
  if (pv[1]) {
    MoveToStr(pv[1], ponder_str);
    printf("bestmove %s ponder %s\n", bestmove_str, ponder_str);
  } else
    printf("bestmove %s\n", bestmove_str);
}
Ejemplo n.º 8
0
void EnvironmentObject::render() {
	Think();
	if (camera->frustum.pointInFrustum(position)) {
		model->setScale(scale);
		model->setPosition(position);		
		model->setRotation(rotation);

		glBindTexture(GL_TEXTURE_2D,texture);
		model->drawObjectFrame(1,model->kDrawImmediate);
	}
}
Ejemplo n.º 9
0
/*
================
idBrittleFracture::ClientThink
================
*/
void idBrittleFracture::ClientThink( const int curTime, const float fraction, const bool predict )
{

	// only think forward because the state is not synced through snapshots
	if( !gameLocal.isNewFrame )
	{
		return;
	}
	
	Think();
}
Ejemplo n.º 10
0
bool FXParticle::Update( void )
{
	// There should be a think function, otherwise what's the point of using a particle?
	if ( Think )
	{
		// All particle attributes need to be updated in the think function since
		//	nothing is auto-updated.  This is done to ensure the most flexibility.
		return Think( this, m_cowner );
	}

	return true;
}
Ejemplo n.º 11
0
void CChickenBoid::Update(float dt,SBoidContext &bc)
{
	if(m_physicsControlled)
	{
		UpdatePhysics(dt,bc);

		if(m_bThrown && m_pPhysics)
		{
			pe_status_awake tmp;
			bool bAwake = m_pPhysics->GetStatus(&tmp) != 0;

			if(!bAwake)
			{
				// Falled on ground after being thrown.
				m_bThrown = false;
				m_physicsControlled = false;
			}
		}

		return;
	}

	if(m_dead)
		return;

	m_lastThinkTime += dt;

	if(bc.waterLevel > bc.terrainZ)
		bc.terrainZ = bc.waterLevel;

	if(bc.followPlayer)
	{
		if(m_pos.GetSquaredDistance(bc.playerPos) > MAX_CHICKEN_DISTANCE_FROM_PLAYER*MAX_CHICKEN_DISTANCE_FROM_PLAYER)
		{
			float z = bc.MinHeight + (Boid::Frand()+1)/2.0f*(bc.MaxHeight - bc.MinHeight);
			m_pos = bc.playerPos + Vec3(Boid::Frand()*MAX_CHICKEN_DISTANCE_FROM_PLAYER,Boid::Frand()*MAX_CHICKEN_DISTANCE_FROM_PLAYER,z);
			m_pos.z = bc.engine->GetTerrainElevation(m_pos.x,m_pos.y) + bc.fBoidRadius*0.5f;
			m_speed = bc.MinSpeed;
			m_heading = Vec3(Boid::Frand(),Boid::Frand(),0).GetNormalized();
		}
	}

	Think(dt,bc);

	if(!m_landing)
	{
		// Calc movement with current velocity.
		CalcMovement(dt,bc,true);

		UpdateAnimationSpeed(bc);
		m_accel.Set(0,0,0);
	}
}
Ejemplo n.º 12
0
void *action(void* id)
{
	int tid = (int)id;
	while(1)
	{
		printf("Philosopher #%d is going to eat.\n", tid);
		Eat(tid, model_eat);
		printf("Philosopher #%d 's eating is done.\n", tid);
		Think(tid, model_think);
	}
	return NULL;
}
Ejemplo n.º 13
0
void aiC::Execute(bool serverHasUpdatedGameState)
{
 switch(aiStatus) {


    // just started, need to connect with server
    case 0:
	if(netConnected()) aiStatus++;
	else if(timeGet() - aiLastCommand > 2000)
	{
	    pf("ai %s, trying to connect:\n", Name);
	    cmd("name AI-%s", Name);
	    cmd("join localhost");
	    aiLastCommand = timeGet();
	}
    break;



    // waiting for other players to join
    case 1:
	if(game && game->Turn > 0) aiStatus++;
	else
	    //if(playercount() > 1)
		if(timeGet() - aiLastCommand > 2000)
		{
		    cmd("ready");
		    aiLastCommand = timeGet();
		}
    break;



    // choose picks
    case 2:
	if(self->Status == BRAIN_ACTIVE) aiStatus++;
	else if(timeGet() - aiLastCommand > 2000)
	{
	    Pick();
	    aiLastCommand = timeGet();
	}

    // play
    case 3:
	if(serverHasUpdatedGameState)
	    Think();
    break;
 }
}
Ejemplo n.º 14
0
 void Eat()
 {
     std::cout << name_ << ": Begin eating" << std::endl;
     
     int lockAIndex = holdForkIndex_;
     int lockBIndex = (holdForkIndex_ + 1) % MAX_FORKS;
     
     std::lock(fork[lockAIndex], fork[lockBIndex]);
     
     Think();
     
     std::lock_guard<std::mutex> locka(fork[lockAIndex], std::adopt_lock);
     std::cout << name_ << ": Hold fork: " << lockAIndex << std::endl;
     
     Think();
     
     std::lock_guard<std::mutex> lockb(fork[lockBIndex], std::adopt_lock);
     std::cout << name_ << ": Hold fork: " << lockBIndex << std::endl;
     
     // eating
     std::this_thread::sleep_for(std::chrono::microseconds(10));
     
     std::cout << name_ << " End eating" << std::endl;
 }
Ejemplo n.º 15
0
void DBot::Tick ()
{
	Super::Tick ();

	if (player->mo == NULL || bglobal.freeze)
	{
		return;
	}

	BotThinkCycles.Clock();
	bglobal.m_Thinking = true;
	Think ();
	bglobal.m_Thinking = false;
	BotThinkCycles.Unclock();
}
Ejemplo n.º 16
0
///
/// Run one step of the application
///
void SceneManager::Step(void)
{
	// Invoke begin method
	if(_stepBeginMethod != NULL)
		_stepBeginMethod();

	// Check frame time
	if(_renderWindow->GetFrameTime() > 0)
	{
		// Check events
		_eventListener->CheckEvents();

		// Think methods
		Think(_environementProvider->GetAeroplaneArray()[0]);
	}

	// Set scene view
	_renderWindow->SetView(*_sceneView);
	_sceneView->SetCenter(sf::Vector2f(
		GetEnvironementProvider()->GetAeroplaneArray()[0]->GetPosition().x,
		std::min<float>(GetEnvironementProvider()->GetAeroplaneArray()[0]->GetPosition().y,_renderWindow->GetHeight()/2.f)));
	_sceneView->SetHalfSize(400.f*_zoomFactor, 300.f*_zoomFactor);

	//Draw methods
	_renderWindow->Clear(sf::Color(150,186,219));
	Draw(_sceneImageSprite);
	Draw(GetEnvironementProvider()->GetAeroplaneArray()[0]);

	// Set DashBoard view
	_renderWindow->SetView(_renderWindow->GetDefaultView());

	// Set FrameRate
	_frameRate = 1/_renderWindow->GetFrameTime();

	// Draw dashboard
	_dashboard->Draw(_renderWindow);

	// Display renderWindow
	_renderWindow->Display();

	// Invoke end method
	if(_stepEndMethod != NULL)
		_stepEndMethod();
}
Ejemplo n.º 17
0
void* PhilosopherTask(void* id){
	long long philosopher_id = (long long)id;
	long long resourse1_id = (long long)id;
	long long resourse2_id = ((long long)id + 1) % PHILOSOPHERS_COUNT;

	while(true) {
		Think(philosopher_id);
		if (pthread_mutex_trylock(&resourses[resourse1_id]) != 0){
			continue;
		}
		if (pthread_mutex_trylock(&resourses[resourse2_id]) != 0){
			pthread_mutex_unlock(&resourses[resourse1_id]);
			continue;
		}
		Eat(philosopher_id);
		pthread_mutex_unlock(&resourses[resourse2_id]);
		pthread_mutex_unlock(&resourses[resourse1_id]);
	}
}
Ejemplo n.º 18
0
int CHud::UpdateClientData(client_data_t *cdata, float time)
{
	memcpy(m_vecOrigin, cdata->origin, sizeof(vec3_t));
	memcpy(m_vecAngles, cdata->viewangles, sizeof(vec3_t));
	
	m_iKeyBits = CL_ButtonBits( 0 );
	m_iWeaponBits = cdata->iWeaponBits;

	in_fov = cdata->fov;

	Think();

	cdata->fov = m_iFOV;
	
	CL_ResetButtonBits( m_iKeyBits );

	// return 1 if in anything in the client_data struct has been changed, 0 otherwise
	return 1;
}
Ejemplo n.º 19
0
void CScript::Play()
{
    m_flStartTime = GameServer()->GetGameTime();

    m_aActors.clear();
    for (size_t i = 0; i < m_aEvents.size(); i++ )
    {
        CScriptEvent* pEvent = &m_aEvents[i];

        tvector<CBaseEntity*> apEntities;
        CBaseEntity::FindEntitiesByName(pEvent->m_sName, apEntities);

        for (size_t j = 0; j < apEntities.size(); j++)
        {
            CScriptActor* pActor = &m_aActors[pEvent->m_sName].push_back();
            pActor->m_hEntity = apEntities[j];
        }
    }

    Think();
}
Ejemplo n.º 20
0
//-----------------------------------------------------------------------------------------------
void AISprite::updateBehavior()
{
	if (tree == 0) return;
	
	//Think about what we are doing
	Think();
	
	if (m_run_behavior)
	{
		tree->RunBehavior(m_behavior_name);
		tree->TickActiveBehavior();
	}
	else
	{
		if (m_run_behavior_default)
		{
			//Run default behavior
			tree->RunBehavior(m_default_behavior);
			tree->TickActiveBehavior();
		}
	}
}
Ejemplo n.º 21
0
void Computer(int column,int row)
{
    int flag=2,C_row,C_col,*Coorp;
    int x,y/*,color=WHITE*/;
    SAVE(column,row,2);  /* 把当前玩家的棋子坐标和下棋方存到文件  1--电脑  2--人 */
    C_col=(column-5)/30;
    C_row=(row-5)/30;
    Coording[C_col][C_row]=flag;

    Coorp=Think(C_col,C_row);    /* 分析棋局的函数   用数组传回 x y 坐标*/

    flag=1;
    /* x=rand()%5;
       y=rand()%5; */

    x=*Coorp;
    y=*(Coorp+1);

    /*SAVE(column+x*30,row+y*30,1);*/

    SAVE(x,y,1);

    /*C_col=(column+x*30-5)/30;
      C_row=(row+y*30-5)/30; */


    C_col=(x-5)/30;
    C_row=(y-5)/30;
    Coording[C_col][C_row]=flag;
    /*color=getcolor();*/
    setfillstyle(SOLID_FILL,BLACK);
    setcolor(BLACK);

    /*sector(column+x*30,row+y*30,0,360,15,15);*/

    sector(x,y,0,360,15,15);
    setcolor(WHITE);
    return ;
}
Ejemplo n.º 22
0
// 人 vs AI
void
GameManVsCom(void)
{
  BOARD board;
  uint64_t pos, valid;

  Init(&board);
  DispBoard(&board);
  while(board.teban != GAME_OVER){
    valid = GenValidMove(&board);

    if(board.teban == SENTE){     // 先手(人) の処理
      while(1){
        pos = GetPos();
        if(pos == INPUT_ERROR){
          printf("エラーです。\n");
          continue;
        }
        else if((pos & valid) == 0){
          printf("非合法手です。\n");
          continue;
        }
        break;
      }
    }
    else if(board.teban == GOTE){ // 後手 (AI) の処理
      // コンピュータ側の処理をここにかく
      pos = Think(&board, valid);
    }

    Put(&board, pos);
    DispBoard(&board);
    CheckFinishPass(&board);
  }

  ShowResult(&board);
  return;
}
// called when server is in a relatively idle state (like during the briefing)
//  we can use this time to scan for missions if we need to
void CASW_Mission_Chooser_Source_Local::IdleThink()
{
	// if we're not currently building any lists, try to start building one
	if (!m_bBuildingMapList && !m_bBuildingCampaignList && !m_bBuildingSavedCampaignList)
	{
		if (!m_bBuiltMapList)
		{
			BuildMapList();
		}
		else
		{
			if (!m_bBuiltCampaignList)
			{
				BuildCampaignList();
			}
			else if (!m_bBuiltSavedCampaignList)
			{
				BuildSavedCampaignList();
			}
		}
	}
	Think();
}
Ejemplo n.º 24
0
byte CRCrack3::CrackSche()
{
	//破解深度
	g_dwCrackDepth = m_tCrackParam.dwCrackDepth;

	byte byWinBitmap = m_tCrackParam.byWinBitmap;
	byte byChair1 = m_tCrackParam.byChair1;
	byte byType = m_tCrackParam.byType;
	byte byRspType = m_tCrackParam.byRspType;
	byte byGrade = m_tCrackParam.byGrade;
	byte byCount = m_tCrackParam.byCount;

	byte byResult = Crack(byWinBitmap, byChair1, byType, byRspType, byGrade, byCount, SCORE_5);

	//暴力破解成功
	if (byResult == CONTRACT_YES)
	{
		GetResult(&m_tCrackResult);
		if (IsStupidPut(m_tCrackResult.byRspType, m_tCrackResult.byGrade, m_tCrackResult.byCount))
		{
			//寻找更优解
			byResult = Optimize(byWinBitmap, byChair1, byType, m_tCrackResult.byRspType, m_tCrackResult.byGrade, m_tCrackResult.byCount, SCORE_5);
			if (byResult != CONTRACT_YES)
			{
				//还原为第一个Stupid解
				SetResult(&m_tCrackResult);
			}
		}
		return SCORE_5;
	}

	//采用类人思考
	InitThkParam();
	Think(byChair1, byType, byRspType, byGrade, byCount);

	return byResult == INTERRUPT ? SCORE_UNK : SCORE_1;
}
Ejemplo n.º 25
0
bool FXSpawner::Update( void )
{
	UpdateOrigin();
	UpdateVelocity();
	UpdateScale();
	UpdateAlpha();
	
	//FIXME: This is being double called...
	if ( Cull() == false )
	{
		if ( m_nextThink < cg.time )
		{
			if (Think != NULL)
				Think( m_origin, m_angles, m_velocity, m_startRGB );

			m_nextThink = cg.time + ( ( m_delay + ( m_variance * crandom() )) );

			if ( m_flags & FXF_SPAWN_ONCE )
				return false;
		}
	}
	
	return true;
}
Ejemplo n.º 26
0
void CGameRules::FrameUpdatePostEntityThink()
{
	VPROF( "CGameRules::FrameUpdatePostEntityThink" );
	Think();
}
Ejemplo n.º 27
0
/*
================
idLight::ClientPredictionThink
================
*/
void idLight::ClientPredictionThink( void ) {
	Think();
}
Ejemplo n.º 28
0
/*
================
idBarrel::ClientPredictionThink
================
*/
void idBarrel::ClientPredictionThink( void ) {
	Think();
}
Ejemplo n.º 29
0
void CBoidBird::Update( float dt,SBoidContext &bc )
{
	if (m_physicsControlled)
	{
		UpdatePhysics(dt,bc);
		return;
	}
	if (m_dead)
		return;
	
	if (m_heading.IsZero())
		m_heading = Vec3(1,0,0);

	m_lastThinkTime += dt;

	{
		if (bc.followPlayer && !m_spawnFromPt)
		{
			if (m_pos.GetSquaredDistance(bc.playerPos) > MAX_BIRDS_DISTANCE*MAX_BIRDS_DISTANCE)
			{
				float z = bc.MinHeight + (Boid::Frand()+1)/2.0f*(bc.MaxHeight - bc.MinHeight);
				m_pos = bc.playerPos + Vec3(Boid::Frand()*MAX_BIRDS_DISTANCE,Boid::Frand()*MAX_BIRDS_DISTANCE,z );
				m_speed = bc.MinSpeed + ((Boid::Frand()+1)/2.0f) / (bc.MaxSpeed - bc.MinSpeed);
				m_heading = Vec3(Boid::Frand(),Boid::Frand(),0).GetNormalized();
			}
		}

		if(m_status == Bird::TAKEOFF)
		{
			float timePassed = (gEnv->pTimer->GetFrameStartTime() - m_takeOffStartTime).GetSeconds();
			if(m_playingTakeOffAnim &&  timePassed >= m_TakeOffAnimLength)
			{
				m_playingTakeOffAnim = false;
				PlayAnimationId(Bird::ANIM_FLY,true);
			}
			else if( timePassed > TAKEOFF_TIME)
			{
				SetStatus(Bird::FLYING);
			}

		}

		if(m_status == Bird::LANDING)
		{
			Vec3 vDist(m_landingPoint - m_pos);
			float dist2 = vDist.GetLengthSquared2D();
			float dist = sqrt_tpl(dist2 + vDist.z*vDist.z);

			if(dist > 0.02f && m_pos.z > m_landingPoint.z)
			{
				//if(vDist.z < 3 && m_heading)
				vDist /= dist;
				float fInterpSpeed = 2+fabs(m_heading.Dot(vDist))*3.f;
				Interpolate(m_heading,vDist, fInterpSpeed, dt);
				m_heading.NormalizeSafe(); 
			
				if(m_heading.z < vDist.z)
				{
					Interpolate(m_heading.z,vDist.z,3.0f,dt);
					m_heading.NormalizeSafe();
				}

				bool wasLandDeceleratingAlready = m_landDecelerating;
				m_accel.zero();
				m_landDecelerating = dist < bc.landDecelerationHeight;
				if(m_landDecelerating)
				{
					float newspeed= m_startLandSpeed* dist/3.f;
					if(m_speed > newspeed)
						m_speed = newspeed;
 					if(m_speed < 0.2f)
 						m_speed = 0.2f;
					if(!wasLandDeceleratingAlready)
						PlayAnimationId(Bird::ANIM_LANDING_DECELERATING, true);
				}
				else
					m_startLandSpeed = m_speed;
			}
			else
				Landed(bc);

			CalcMovementBird( dt,bc,true );
			UpdatePitch(dt,bc);
			return;

		}

		if (m_status != Bird::ON_GROUND)
		{
			Think(dt,bc);

			// Calc movement with current velocity.
			CalcMovementBird( dt,bc,true );
		}
		else 
		{
			if(bc.walkSpeed > 0 && m_onGroundStatus == Bird::OGS_WALKING)
				ThinkWalk(dt,bc);
			CalcMovementBird( dt,bc,true );
		}

		m_accel.Set(0,0,0);
		UpdatePitch(dt,bc);

		// Check if landing/on ground after think().
		if ( m_status == Bird::LANDING ||(m_dying && m_status != Bird::ON_GROUND))
		{
			float LandEpsilon = 0.5f;

			// Check if landed on water.
			if (m_pos.z-bc.waterLevel < LandEpsilon+0.1f && !m_dying)
			{
				//! From water immidiatly take off.
				//! Gives fishing effect. 
				TakeOff(bc);
			}

		}

		m_actionTime += dt;

		if (m_status == Bird::ON_GROUND )
			UpdateOnGroundAction(dt, bc);
		else
		{
			if(!bc.noLanding && m_actionTime > m_maxActionTime 
				&& !static_cast<CBirdsFlock*>(m_flock)->IsPlayerNearOrigin())
				Land();
		}
	}








}
Ejemplo n.º 30
0
/*
================
rvVehicleAnimated::ClientPredictionThink
================
*/
void rvVehicleAnimated::ClientPredictionThink ( void ) {
	Think();
}