Exemple #1
0
void ProcessKbd(void)
{
	int16_t result;
	static bool newconsf=false;
	bool state;

	while((result = VGLKeyboardGetCh()) != 0) {

		state=UpdateStates(&result);
		if(newconsf==true && pausef==true) {
                  /* return to game ? */
		  if(state==false) 
		    continue;
		  else newconsf=false;			/* yes */
                }
		
		while(newconsf==false && state==true &&
		      result>=F1KEY && result<=F10KEY && altpressed) {
		    /* Alt-Fn pressed to switch consoles */
		    int activecons=0;
		    int newcons=result-F1KEY+1;
		    ioctl(0, VT_GETACTIVE, &activecons);
		    if(newcons==activecons) /* to another console ? */
			break;
		    
		    newconsf=true;
		    /* do switch */
		    ioctl(0,VT_ACTIVATE,(caddr_t)(long)newcons); 
		    if(started==true && pausef==false) {
			    pausef=true;
			    testpause(); /* force pause if game active */
		    }
		    else {
		        VGLCheckSwitch(); /* game not active - just switch */
		        /* now wait for another keyboard strike */
			result=VGLKeyboardGetCh();
			while(1) {
			    if(result!=0) {
				state=UpdateStates(&result);
				    if(state==true)     /* ignore releases */
					break;	
			        }
		    	    usleep(500);	/* don't waste CPU when idle */
			    result=VGLKeyboardGetCh();
			}
		    }
		    newconsf=false; /* switched back */
		}

		if(state == true)
			continue;

		if(klen == KBLEN) /* Buffer is full, drop some pieces */
			memcpy(kbuffer, kbuffer + 1, --klen);
		kbuffer[klen++] = result;
	}
}
Exemple #2
0
void CGUIControl::QueueAnimation(ANIMATION_TYPE animType)
{
  MarkDirtyRegion();
  if (!CheckAnimation(animType))
    return;
  CAnimation *reverseAnim = GetAnimation((ANIMATION_TYPE)-animType, false);
  CAnimation *forwardAnim = GetAnimation(animType);
  // we first check whether the reverse animation is in progress (and reverse it)
  // then we check for the normal animation, and queue it
  if (reverseAnim && reverseAnim->IsReversible() && (reverseAnim->GetState() == ANIM_STATE_IN_PROCESS || reverseAnim->GetState() == ANIM_STATE_DELAYED))
  {
    reverseAnim->QueueAnimation(ANIM_PROCESS_REVERSE);
    if (forwardAnim) forwardAnim->ResetAnimation();
  }
  else if (forwardAnim)
  {
    forwardAnim->QueueAnimation(ANIM_PROCESS_NORMAL);
    if (reverseAnim) reverseAnim->ResetAnimation();
  }
  else
  { // hidden and visible animations delay the change of state.  If there is no animations
    // to perform, then we should just change the state straightaway
    if (reverseAnim) reverseAnim->ResetAnimation();
    UpdateStates(animType, ANIM_PROCESS_NORMAL, ANIM_STATE_APPLIED);
  }
}
void ConfigurationDialog::OnDeleteAllAlarms( wxCommandEvent& event )
{
    for(unsigned int i=0; i<Alarm::s_Alarms.size(); i++)
        m_lAlarms->DeleteItem(0);
    Alarm::DeleteAll();
    Alarm::s_Alarms.clear();

    UpdateStates();
    g_watchdog_pi->m_WatchdogDialog->UpdateAlarms();
}
void ConfigurationDialog::OnDeleteAlarm( wxCommandEvent& event )
{
    std::vector<Alarm*>::iterator it = Alarm::s_Alarms.begin();
    for(int i=0; i<CurrentSelection(); i++)
        it++;
    delete *it;
    Alarm::s_Alarms.erase(it);
    m_lAlarms->DeleteItem(CurrentSelection());

    UpdateStates();

    g_watchdog_pi->m_WatchdogDialog->UpdateAlarms();
}
void ConfigurationDialog::OnNewAlarm( wxCommandEvent& event )
{
    NewAlarmDialog dlg(this);
    if(dlg.ShowModal() == wxID_CANCEL)
        return;

    Alarm::NewAlarm((AlarmType)dlg.m_lAlarmType->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED));

    wxListItem item;
    long index = m_lAlarms->InsertItem(m_lAlarms->GetItemCount(), item);

    m_lAlarms->SetItemState(m_lAlarms->GetItemCount() - 1,
                            wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
    g_watchdog_pi->m_WatchdogDialog->UpdateAlarms();

    UpdateItem(index);
    UpdateStates();

    OnEditAlarm(event);
    if(m_bOnEditAlarmOK) return;
    else OnDeleteAlarm(event);
}
Exemple #6
0
bool CGUIControl::Animate(unsigned int currentTime)
{
  // check visible state outside the loop, as it could change
  GUIVISIBLE visible = m_visible;

  m_transform.Reset();
  bool changed = false;

  CPoint center(GetXPosition() + GetWidth() * 0.5f, GetYPosition() + GetHeight() * 0.5f);
  for (unsigned int i = 0; i < m_animations.size(); i++)
  {
    CAnimation &anim = m_animations[i];
    anim.Animate(currentTime, HasProcessed() || visible == DELAYED);
    // Update the control states (such as visibility)
    UpdateStates(anim.GetType(), anim.GetProcess(), anim.GetState());
    // and render the animation effect
    changed |= (anim.GetProcess() != ANIM_PROCESS_NONE);
    anim.RenderAnimation(m_transform, center);

/*    // debug stuff
    if (anim.currentProcess != ANIM_PROCESS_NONE)
    {
      if (anim.effect == EFFECT_TYPE_ZOOM)
      {
        if (IsVisible())
          CLog::Log(LOGDEBUG, "Animating control %d with a %s zoom effect %s. Amount is %2.1f, visible=%s", m_controlID, anim.type == ANIM_TYPE_CONDITIONAL ? (anim.lastCondition ? "conditional_on" : "conditional_off") : (anim.type == ANIM_TYPE_VISIBLE ? "visible" : "hidden"), anim.currentProcess == ANIM_PROCESS_NORMAL ? "normal" : "reverse", anim.amount, IsVisible() ? "true" : "false");
      }
      else if (anim.effect == EFFECT_TYPE_FADE)
      {
        if (IsVisible())
          CLog::Log(LOGDEBUG, "Animating control %d with a %s fade effect %s. Amount is %2.1f. Visible=%s", m_controlID, anim.type == ANIM_TYPE_CONDITIONAL ? (anim.lastCondition ? "conditional_on" : "conditional_off") : (anim.type == ANIM_TYPE_VISIBLE ? "visible" : "hidden"), anim.currentProcess == ANIM_PROCESS_NORMAL ? "normal" : "reverse", anim.amount, IsVisible() ? "true" : "false");
      }
    }*/
  }

  return changed;
}
Exemple #7
0
bool CGUIControl::CheckAnimation(ANIMATION_TYPE animType)
{
  // rule out the animations we shouldn't perform
  if (!IsVisible() || !HasProcessed())
  { // hidden or never processed - don't allow exit or entry animations for this control
    if (animType == ANIM_TYPE_WINDOW_CLOSE)
    { // could be animating a (delayed) window open anim, so reset it
      ResetAnimation(ANIM_TYPE_WINDOW_OPEN);
      return false;
    }
  }
  if (!IsVisible())
  { // hidden - only allow hidden anims if we're animating a visible anim
    if (animType == ANIM_TYPE_HIDDEN && !IsAnimating(ANIM_TYPE_VISIBLE))
    {
      // update states to force it hidden
      UpdateStates(animType, ANIM_PROCESS_NORMAL, ANIM_STATE_APPLIED);
      return false;
    }
    if (animType == ANIM_TYPE_WINDOW_OPEN)
      return false;
  }
  return true;
}
ConfigurationDialog::ConfigurationDialog( watchdog_pi &_watchdog_pi, wxWindow* parent)
    : ConfigurationDialogBase( parent ), m_watchdog_pi(_watchdog_pi)
{
    wxFileConfig *pConf = GetOCPNConfigObject();
    pConf->SetPath ( _T( "/Settings/Watchdog" ) );
    int enabled = pConf->Read ( _T ( "Enabled" ), 1L );

    m_rbAlways->SetValue(enabled == 1);
    m_rbOnce->SetValue(enabled == 2);
    m_rbVisible->SetValue(enabled == 3);
    m_rbNever->SetValue(enabled == 0);

    m_lAlarms->InsertColumn(ALARM_TYPE, _("Type"));
    m_lAlarms->InsertColumn(ALARM_OPTIONS, _("Options"));
    m_lAlarms->InsertColumn(ALARM_ACTION, _("Action"));

    for(unsigned int i=0; i<Alarm::s_Alarms.size(); i++) {
        wxListItem item;
        m_lAlarms->InsertItem(i, item);
        UpdateItem(i);
    }
    UpdateStates();
    
}
Exemple #9
0
void AI_HandleMove(int bMyMove, const tMove *Move)
{
	if( gbFirstTurn )
	{
		gbFirstTurn = false;
		
		AI_int_InitialiseBoardState();

		// Reverse the first move
		if( Move->dir != DIR_INVAL )
		{
			tPiece	*p;
			switch(Move->dir)
			{
			case DIR_INVAL:	ASSERT(Move->dir != DIR_INVAL);	break;
			case DIR_LEFT:	p = GetPieceByPos( Move->x-1, Move->y );	break ;
			case DIR_RIGHT:	p = GetPieceByPos( Move->x+1, Move->y );	break ;
			case DIR_UP:	p = GetPieceByPos( Move->x, Move->y-1 );	break ;
			case DIR_DOWN:	p = GetPieceByPos( Move->x, Move->y+1 );	break ;
			}
			MovePieceTo( p, Move->x, Move->y );
			p->StartX = Move->x;
			p->StartY = Move->y;
		}
	}

	if(Move->result == RESULT_VICTORY)
	{
		// TODO: Distiguish between victory conditions?
		// - Note flag location?

		// TODO: Save back initial board state
		DB_WriteBackInitialState(gsOpponentDbFilename, !gMyColour, gpCurrentGameState->Opponent.Pieces);
	}

	if( !bMyMove )
	{
		if( Move->dir != DIR_INVAL )
			UpdateStates(Move);
	}
	else
	{
		tPiece	*p = GetPieceByPos(Move->x, Move->y);
		ASSERT(p);

	 	int newx = p->X, newy = p->Y;
		switch(Move->dir)
		{
		case DIR_INVAL:	break;
		case DIR_LEFT:	newx -= Move->dist;	break;
		case DIR_RIGHT:	newx += Move->dist;	break;
		case DIR_UP:	newy -= Move->dist;	break;
		case DIR_DOWN:	newy += Move->dist;	break;
		}
		tPiece	*target = GetPieceByPos(newx, newy);

		switch(Move->result)
		{
		case RESULT_ILLEGAL:	break;
		case RESULT_INVAL:	break;
		case RESULT_OK:
			MovePieceTo(p, newx, newy);
			break;
		case RESULT_KILL:
			UpdateRank(target, Move->defender);
			RemovePiece(target);
			MovePieceTo(p, newx, newy);
			PieceExposed(p);	// TODO: Update oponent's view
			giTurnsSinceLastTake = 0;
			break;
		case RESULT_DIES:
		case RESULT_VICTORY:
			UpdateRank(target, Move->defender);
			PieceExposed(p);
			RemovePiece(p);
			giTurnsSinceLastTake = 0;
			break;
		case RESULT_BOTHDIE:
			UpdateRank(target, Move->defender);
			PieceExposed(p);
			RemovePiece(p);
			RemovePiece(target);
			giTurnsSinceLastTake = 0;
			break;
		}
	}
}
Exemple #10
0
void idKeypad::Think( void )
{
	int i;

	//glows.
	if (state == ACTIVE)
	{
		if (gameLocal.GetLocalPlayer()->focusFrobEnt)
		{
			bool isHover = false;
			int i;
			int hoverIndex = gameLocal.GetLocalPlayer()->focusFrobEnt->entityNumber;

			for (i = 0; i < 9; i++)
			{
				if (hoverIndex == frobcubes[i]->entityNumber)
				{
					SetSkin(skin_glow[i]);
					isHover = true;
				}
			}

			if (!isHover)
			{
				SetSkin(0); //default.
				bluebox->Hide();
			}
			else
			{
				//show bluebox.
				bluebox->Show();

				idAngles remoteAng = gameLocal.GetLocalPlayer()->viewAngles;
				remoteAng.yaw += 180 + 30;
				remoteAng.pitch *= -1;
				remoteAng.pitch += 3 * idMath::Sin(gameLocal.time * 0.0005f); //sway
				remoteAng.yaw += 3 + 3 * idMath::Sin(gameLocal.time * 0.0003f);  //sway
				bluebox->SetAngles( remoteAng );

				idVec3	up, right;
				remoteAng.ToVectors( NULL, &right, &up );

				idVec3 finalPos = gameLocal.GetLocalPlayer()->GetEyePosition() 
					+ (gameLocal.GetLocalPlayer()->viewAngles.ToForward() * 12.0f) 
					+ (up * -5.0f)
					+ (right * 7.0f);

				bluebox->GetPhysics()->SetOrigin(finalPos);
				//bluebox->GetPhysics()->SetOrigin(
			}
		}
		else
		{
			SetSkin(0); //default.

			//hide bluebox.
			bluebox->Hide();
		}
	}

	//handle the button animations.
	for (i = 0; i < 9; i++)
	{
		if (gameLocal.time > transitions[i])
		{
			jointHandle_t joint;
			joint = animator.GetJointHandle( GetJointViaIndex(i) );
			animator.ClearJoint(joint);
		}
	}

	UpdateStates();
	
	idAnimatedEntity::Think();
	idAnimatedEntity::Present();
}
Exemple #11
0
/*
 * This is the most important function in localization. go through the poles in pole list
 * and calculate weight and make decisions...
 */
void Algorithm::ParticleFilter(list<PoleData> & poleList) //i have array of single poles
{
	/*
	 * if there is only one or two poles we can't trust that. so wait for more than 1.
	 * but if the oldest pole is very old, make an iteration.
	 */
	if (/*poleList.front().time-(*m_currTimePtr) > 50000 && */poleList.size()<=2) return;

	//reset counter
	m_stepsWithoutPolePicture=0;

#ifdef LOCALIZATION_DEBUG
	printf("Algorithm::ParticleFilter(list<PoleData> & poleList):\n");
	printf("have %d poles to go through\n",poleList.size());
#endif

	//this was a try to make a low pass filter to throw poles with noise. not tested.
	//TODO try to do this. not so important.
	//	bool DoneLPF = poleList.size() < 3 ? true:false; // lpf only for 3 or more poles;
	//	PoleData temp[3];
	//	int i;
	//	list<PoleData>::iterator it;
	//	list<PoleData>::iterator itErase;

	double w;
	while (poleList.size()>0)
	{
		//LPF stuff
		/*
		//		cout<<"START 1  "<<poleList.size()<<endl;
		//		it = poleList.begin();
		//		PoleId ID = it->id;
		//		i=0;
		//		while((!DoneLPF) && it!= poleList.end()) //LPF
		//		{
		//			cout<<"START 2  "<<poleList.size()<<"\ti= "<<i<<endl;
		//			if(it->id == ID)
		//			{
		//				if(it->distFromMe < 0)
		//				{
		//					DoneLPF = true;
		//					continue;
		//				}
		//				else
		//				{
		//					temp[i] = *it;
		//					if(i == 1)
		//						itErase = it;// the pole to erase
		//					it++;
		//					i++;
		//				}
		//			}
		//			if(i == 3)
		//			{
		//				cout<<"IF 2  "<<poleList.size()<<"\ti= "<<i<<endl;
		//				DoneLPF = true;
		//				if((fabs(temp[0].distFromMe - temp[2].distFromMe) < fabs(temp[0].distFromMe - temp[1].distFromMe )) && (temp[2].time - temp[0].time < 1000000))
		//				{
		//					poleList.erase(itErase);
		//				}
		//			}
		//		}
		*/

		PoleData pole=poleList.front();
		poleList.pop_front();

#ifdef LOCALIZATION_DEBUG
		cout<<"\t#poles: "<<poleList.size()<<" \t";
		cout<<"Dist: "<<pole.distFromMe<<"\tID: "<<pole.id<<endl;

		//if(DoneLPF && i==3)
		//	cout<<"Dist: "<<temp[1].distFromMe<<"\tID: "<<temp[1].id<<"\tTHROWED"<<endl;
#endif

		//go through each particle and calculate the wieght
		for (State_iterator it = m_currState.begin(); it != m_currState.end() ;it++)//update weight
		{
			/*
			 * TODO: OMG found a bug!!
			 * what happens when the pole.id==GOAL_UNKNOWN_BACK ???!!!
			 * TODO FIXME
			 */
			if (pole.id==GOAL_UNKNOWN_FRONT) // either left or right front pole, give maximum weight.
			{
				double w0,w1;
				pole.id=GOAL_LEFT_FRONT;
				w0=getWeightFromPole(pole,*it);
				pole.id=GOAL_RIGHT_FRONT;
				w1=getWeightFromPole(pole,*it);
				pole.id=GOAL_UNKNOWN_FRONT;
				if (w0>w1) w=w0; else w=w1;
			}
			else //We know what pole it is.
			{
				w=getWeightFromPole(pole,*it);
			}

			//give new weight for the particle, while considering old weight.
			(it->weight)*=w;
		}
	}

	double sumOfWeight=0;
	for (State_iterator it = m_currState.begin(); it != m_currState.end() ;it++) {
		sumOfWeight+=it->weight;
	}
	sumOfWeight = 1 / sumOfWeight;

	//if all the sum of weight is very low, it means all the particles are out
	if (sumOfWeight<0.001)
		m_outOfLocation=true;
	else
		m_outOfLocation=false;

	//TODO use the sumOfWeight we calculated before and send to this function
	//normalize weight for the monte carlo
	NormalizeWeight(sumOfWeight); //sum of weights = 1

	//choose new set
	UpdateStates();
}
Exemple #12
0
//This function will eventually replace the above function to handle
// POIs instead of poles
//TODO compare this function to the previous and see if we can upgrade some of the things
// they were unable to do last year
void Algorithm::ParticleFilter(list<PoiData>& poiList)
{
/*
	 * if there is only one or two poles we can't trust that. so wait for more than 1.
	 * but if the oldest pole is very old, make an iteration.
	 */
	//if (/*poleList.front().time-(*m_currTimePtr) > 50000 && */poleList.size()<=2) return;
	//TODO verify this line!!
	if(/**m_currTimePtr - poiList.front().time < 50000 ||*/ poiList.size() <= 2)
		return;

	//reset counter
	m_stepsWithoutPolePicture=0;

#ifdef LOCALIZATION_DEBUG
	cout << "[Algorithm::ParticleFilter]: have " << poiList.size() << " POIs to go through" << endl;
#endif

	//TODO attempt to create a LPF for the POIs
	double w, maxW;
	while (poiList.size()>0)
	{
		PoiData poi = poiList.front();
		poiList.pop_front();

#ifdef LOCALIZATION_DEBUG
		cout<<"\t#POIs: "<<poiList.size()<<" \t";
		cout<<"Dist: "<<poi.distFromMe<<"\tID: "<<poi.id<<endl;
#endif

		//go through each particle and calculate the weight
		for (State_iterator it = m_currState.begin(); it != m_currState.end() ;it++)//update weight
		{
			if (poi.id==UNKNOWN)
			{
				w = 0;
				maxW = 0;
				for(int i=0;i<NUMBER_OF_POIS;i++)
				{
					poi.id = (PoiId)i;
					w = GetWeightFromPoi(poi,*it);
					maxW = w > maxW ? w : maxW;
				}
				w = maxW;
				poi.id = UNKNOWN;
			}
			else //We know what poi it is.
			{
				w = GetWeightFromPoi(poi,*it);
			}

			//give new weight for the particle, while considering old weight.
			(it->weight)*=w;
		}
	}

	double sumOfWeight=0;
	for (State_iterator it = m_currState.begin(); it != m_currState.end() ;it++) {
		sumOfWeight += it->weight;
	}

	//if all the sum of weight is very low, it means all the particles are out
	if ((sumOfWeight/m_currState.size()) < 0.001)
		m_outOfLocation=true;
	else
		m_outOfLocation=false;

	NormalizeWeight(sumOfWeight);

	//choose new set
	UpdateStates();
}
Exemple #13
0
void WeatherRouting::OnComputationTimer( wxTimerEvent & )
{
    bool update = false;
    for(std::list<RouteMapOverlay*>::iterator it = m_RunningRouteMaps.begin();
        it != m_RunningRouteMaps.end(); )
    {
        RouteMapOverlay *routemapoverlay = *it;
        if(!routemapoverlay->Running())
        {
            UpdateRouteMap(routemapoverlay);
            it = m_RunningRouteMaps.erase(it);

            m_gProgress->SetValue(m_RoutesToRun - m_WaitingRouteMaps.size() - m_RunningRouteMaps.size());
            update = true;

            /* update report if needed */
            if(m_ReportDialog.IsShown())
            {
                if(routemapoverlay == CurrentRouteMap())
                    m_ReportDialog.SetRouteMapOverlay(routemapoverlay);
            }

            continue;
        } else
            it++;

        /* get a new grib for the route map if needed */
        if(routemapoverlay->NeedsGrib())
        {
            m_RouteMapOverlayNeedingGrib = routemapoverlay;
            routemapoverlay->RequestGrib(routemapoverlay->NewTime());
            m_RouteMapOverlayNeedingGrib = NULL;
        }
    }

    if((int)m_RunningRouteMaps.size() < m_SettingsDialog.m_sConcurrentThreads->GetValue()
       && m_WaitingRouteMaps.size())
    {
        RouteMapOverlay *routemapoverlay = m_WaitingRouteMaps.front();
        m_WaitingRouteMaps.pop_front();
        routemapoverlay->Start();
        UpdateRouteMap(routemapoverlay);
        m_RunningRouteMaps.push_back(routemapoverlay);
        update = true;
    }

    static int cycles; /* don't refresh all the time */
    if(++cycles > 25 && CurrentRouteMap() && CurrentRouteMap()->Updated())
    {
        cycles = 0;
        m_StatisticsDialog.SetRunTime(m_RunTime += wxDateTime::Now() - m_StartTime);
        if(m_StatisticsDialog.IsShown())
            m_StatisticsDialog.SetRouteMapOverlay(CurrentRouteMap());

        m_StartTime = wxDateTime::Now();
        GetParent()->Refresh();
    }

    if(update)
        UpdateStates();

    if(m_RunningRouteMaps.size())
    {
        /* todo, instead of respawning the funky timer here,
         maybe we can do it from the thread instead to eliminate the delay */
        m_tCompute.Start(25, true);
        return;
    }

    Stop();
}
Exemple #14
0
void WeatherRouting::OnResetAll ( wxCommandEvent& event )
{
    Reset();
    UpdateStates();
}
Exemple #15
0
void ProcessFrame()
{
	UpdateStates();	
	RenderFrame();
}