示例#1
0
void LightManager::SetPause(TimerTypes eTimer, bool pause)
{
	if(eTimer == TIMER_ALL || eTimer == TIMER_LIGHTS)
	{
		std::for_each(m_lightTimers.begin(), m_lightTimers.end(), PauseTimer(pause));
		std::for_each(m_extraTimers.begin(), m_extraTimers.end(), PauseTimer(pause));
	}

	if(eTimer == TIMER_ALL || eTimer == TIMER_SUN)
		m_sunTimer.TogglePause();
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTeamRoundTimer::InputDisable( inputdata_t &input )
{ 
	PauseTimer();
	m_bIsDisabled = true;

	if ( m_bShowInHUD )
	{
		SetActiveTimer( NULL );
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTeamRoundTimer::Spawn( void )
{
	Precache();

#ifdef CLIENT_DLL
	SetNextClientThink( CLIENT_THINK_ALWAYS );
#else

	int nTimerTime = 0;

	// do we have a setup time?
	if ( m_nSetupTimeLength > 0 )
	{
		nTimerTime = m_nSetupTimeLength;
		SetState( RT_STATE_SETUP );
	}
	else
	{
		nTimerTime = m_nTimerInitialLength;
		SetState( RT_STATE_NORMAL );
	}

	m_nTimeToUseAfterSetupFinished = m_nTimerInitialLength;

	if ( IsDisabled() )  // we need to get the data initialized before actually become disabled
	{
		m_bIsDisabled = false;
		PauseTimer(); // start paused
		SetTimeRemaining( nTimerTime );
		m_bIsDisabled = true;
	}
	else
	{
		PauseTimer(); // start paused
		SetTimeRemaining( nTimerTime );
	}

	m_nTimerLength = nTimerTime;

	BaseClass::Spawn();
#endif
}
示例#4
0
	UInt Time::CreateTimer(const bool _bStart)
	{
		bool bResult = true;

		TimerPtrVec::iterator iTimer = m_vpTimers.begin();
		TimerPtrVec::iterator iEnd = m_vpTimers.end();
		TimerPtr pTimer = NULL;
		UInt uResult = 0;

		while (iEnd != iTimer)
		{
			if (false == (*iTimer)->m_bIsActive)
			{
				pTimer = *iTimer;
				break;
			}
			++iTimer;
			++uResult;
		}

		if (NULL == pTimer)
		{
			pTimer = new Timer(m_lTicksPerSeconds);
			m_vpTimers.push_back(pTimer);
		}

		if (false == _bStart)
		{
			float fTemp;
			bResult = ResetTimer(uResult, fTemp) && PauseTimer(uResult);
		}

		if (false == bResult)
		{
			pTimer->Release();
			uResult = 0xffffffff;
		}

		return uResult;
	}
示例#5
0
//******************************************************************************************
//main program function
//******************************************************************************************
void main(void) {
	Sys_Init();      			// System Initialization
	Port_Init();     			// Initialize ports 2 and 3
	Interrupt_Init();			//Initialize Interrupts
	Timer_Init();				//Initialize timer 0
	putchar(' ');    		
	printf("\r\nStart\r\n");
	while(1) {	
		BILED0=1;	//Turn OFF the BILED
		BILED1=1;
		printf("\rHow To Play:\r\nIf Red Led is on the player must Push button 0\r\nIf Green Led is on the player must Push button 1\r\nIf both Leds are on the player must push both Buttons\r\nKeep in mind you will only have 1 sec push the corresponding button/s\r\nA correct input will make the Clear Led flash green, while an incorrect input will make it flash red\r\nTo begin press any key\r\n");	

		keyinput=getchar();
		
		previousnum=keyinput%3;
		i=0;
		numC=0;
		while (i<=9) {
			StopAndResetTimer();
			if(!SS) {
				StartTimer();
				randomnum = random();					//create a random number. where randomnum is a 
				while (randomnum==previousnum) {
					randomnum = random();
				}							//check to see if the random number was used before
	
				if (randomnum==0) {						
					LED0=0;					//turn it on
					debounce(); 			
					LED0=1; 				//turn it off
					if (PB0==0 && PB1==1) {
						correct();		//store correct answer;
					} else {
						incorrect();
					}
				} else if (randomnum==1) {						
					LED1=0; 				//turn it on
					debounce(); 			
					LED1=1; 				//turn it off
					if (PB0==1 && PB1==0) {
						correct();
					} else {
						incorrect();
					}	
				} else{						//rand num is 2, light LED0 and LED1 for 1 second
					LED0=0;
					LED1=0;
					debounce();
					LED0=1;
					LED1=1;
					if (PB0==0 && PB1==0){
						correct();
					} else 	{
						incorrect();
					}
				}
				
				previousnum=randomnum;
				i++;									//increment i
			} else 	{
				PauseTimer();
			}

		}// end while < 9
		printf("\r\n Number of correct answers = %d\r\n", numC);		//display results
		ending();
		TR0 = 0;								//turn off timer
		BILED1=1;
		BILED0=1;
		while (!SS);							//wait until the switch is turned off and back on again to loop
		while (SS);								
	}	
}//end main
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTeamRoundTimer::RoundTimerThink( void )
{
	if ( TeamplayRoundBasedRules()->IsInPreMatch() == true && IsDisabled() == false )
	{
		inputdata_t data;
		InputDisable( data );
	}

	if ( IsDisabled() || m_bTimerPaused || IsInCommentaryMode() || gpGlobals->eLoadType == MapLoad_Background )
	{
		SetContextThink( &CTeamRoundTimer::RoundTimerThink, gpGlobals->curtime + 0.05, ROUND_TIMER_THINK );
		return;
	}

	// Don't do anything when the game has been won or if we're loading a bugbait report
	if ( TeamplayRoundBasedRules()->RoundHasBeenWon() ||
		 TeamplayRoundBasedRules()->IsLoadingBugBaitReport() )
	{
		// We want to stop timers when the round has been won, but we don't want to 
		// force mapmakers to deal with having to unpause it. This little hack works around that.
		if ( !m_bTimerPaused )
		{
			PauseTimer();
			m_bPauseDueToWin = true;
		}

		SetContextThink( &CTeamRoundTimer::RoundTimerThink, gpGlobals->curtime + 0.05, ROUND_TIMER_THINK );
		return;
	}
	else if ( m_bPauseDueToWin )
	{
		ResumeTimer();
		m_bPauseDueToWin = false;
	}

	float flTime = GetTimeRemaining();

	if ( flTime > 0 && ShowInHud() ) // is this the timer we're showing in the HUD?
	{
		TeamplayRoundBasedRules()->SetOvertime( false );
	}

	if ( flTime <= 0.0f && m_bFireFinished )
	{
		// Allow the gamerules to prevent timer expiration (i.e. while a control point is contested)
		if ( !TeamplayGameRules()->TimerMayExpire() )
		{
			// we don't want the timer to keep going (negative time)
			m_flTimerEndTime = gpGlobals->curtime;

			// is this the timer we're showing in the HUD?
			if ( ShowInHud() )
			{
				TeamplayRoundBasedRules()->SetOvertime( true );
			}

			// Think slower
			SetContextThink( &CTeamRoundTimer::RoundTimerThink, gpGlobals->curtime + 1.0, ROUND_TIMER_THINK );
			return;
		}

		m_OnFinished.FireOutput( this, this );
		m_bFireFinished = false;
	}
	else if ( flTime <= 300.0 && m_bFire5MinRemain )
	{
		m_On5MinRemain.FireOutput( this, this );
		m_bFire5MinRemain = false;
	}
	else if ( flTime <= 240.0 && m_bFire4MinRemain )
	{
		m_On4MinRemain.FireOutput( this, this );
		m_bFire4MinRemain = false;
	}
	else if ( flTime <= 180.0 && m_bFire3MinRemain )
	{
		m_On3MinRemain.FireOutput( this, this );
		m_bFire3MinRemain = false;
	}
	else if ( flTime <= 120.0 && m_bFire2MinRemain )
	{
		m_On2MinRemain.FireOutput( this, this );
		m_bFire2MinRemain = false;
	}
	else if ( flTime <= 60.0 && m_bFire1MinRemain )
	{
		m_On1MinRemain.FireOutput( this, this );
		m_bFire1MinRemain = false;
	}
	else if ( flTime <= 30.0 && m_bFire30SecRemain )
	{
		m_On30SecRemain.FireOutput( this, this );
		m_bFire30SecRemain = false;
	}
	else if ( flTime <= 10.0 && m_bFire10SecRemain )
	{
		m_On10SecRemain.FireOutput( this, this );
		m_bFire10SecRemain = false;
	}
	else if ( flTime <= 5.0 && m_bFire5SecRemain )
	{
		m_On5SecRemain.FireOutput( this, this );
		m_bFire5SecRemain = false;
	}
	else if ( flTime <= 4.0 && m_bFire4SecRemain )
	{
		m_On4SecRemain.FireOutput( this, this );
		m_bFire4SecRemain = false;
	}
	else if ( flTime <= 3.0 && m_bFire3SecRemain )
	{
		m_On3SecRemain.FireOutput( this, this );
		m_bFire3SecRemain = false;
	}
	else if ( flTime <= 2.0 && m_bFire2SecRemain )
	{
		m_On2SecRemain.FireOutput( this, this );
		m_bFire2SecRemain = false;
	}
	else if ( flTime <= 1.0 && m_bFire1SecRemain )
	{
		m_On1SecRemain.FireOutput( this, this );
		m_bFire1SecRemain = false;
	}

	SetContextThink( &CTeamRoundTimer::RoundTimerThink, gpGlobals->curtime + 0.05, ROUND_TIMER_THINK );
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTeamRoundTimer::InputPause( inputdata_t &input )
{
	PauseTimer();
}
示例#8
0
void MxBase::Alloc(const char *Name, unsigned RowCount, unsigned ColCount,
  const SeqDB *DB, unsigned IdA, unsigned IdB, const SeqData *SA, const SeqData *SB)
	{
	StartTimer(MxBase_Alloc);

	++m_AllocCount;
	if (m_AllocatedRowCount == 0)
		++m_ZeroAllocCount;

	if (DB != 0)
		{
		asserta(IdA != UINT_MAX);
		asserta(IdB != UINT_MAX);
		asserta(RowCount >= DB->GetSeqLength(IdA) + 1);
		asserta(ColCount >= DB->GetSeqLength(IdB) + 1);
		}
	if (RowCount > m_AllocatedRowCount || ColCount > m_AllocatedColCount)
		{
		if (m_AllocatedRowCount > 0)
			{
			if (opt_logmemgrows)
				Log("MxBase::Alloc grow %s %u x %u -> %u x %u, %s bytes\n",
				  Name, m_AllocatedRowCount, m_AllocatedColCount,
				  RowCount, ColCount,
				  IntToStr(GetBytes()));
			++m_GrowAllocCount;
			}

		m_TotalBytes -= GetBytes();

		PauseTimer(MxBase_Alloc);
		StartTimer(MxBase_FreeData);
		FreeData();
		EndTimer(MxBase_FreeData);
		StartTimer(MxBase_Alloc);

		unsigned N = max(RowCount + 16, m_AllocatedRowCount);
		unsigned M = max(ColCount + 16, m_AllocatedColCount);
		N = max(N, M);

		PauseTimer(MxBase_Alloc);
		StartTimer(MxBase_AllocData);
		AllocData(N, N);
		EndTimer(MxBase_AllocData);
		StartTimer(MxBase_Alloc);

		m_TotalBytes += GetBytes();
		if (m_TotalBytes > m_MaxBytes)
			m_MaxBytes = m_TotalBytes;
		}
	
	unsigned n = sizeof(m_Name)-1;
	strncpy(m_Name, Name, n);
	m_Name[n] = 0;
	m_RowCount = RowCount;
	m_ColCount = ColCount;
	m_SeqDB = DB;
	m_IdA = IdA;
	m_IdB = IdB;
	m_SA = SA;
	m_SB = SB;

	EndTimer(MxBase_Alloc);
	}
示例#9
0
void LightEnv::SetPause( bool pause )
{
	m_sunTimer.SetPause(pause);
	std::for_each(m_lightTimers.begin(), m_lightTimers.end(), PauseTimer(pause));
}
示例#10
0
void LightEnv::TogglePause()
{
	bool isPaused = m_sunTimer.TogglePause();
	std::for_each(m_lightTimers.begin(), m_lightTimers.end(), PauseTimer(isPaused));
}
void ProcessSpeaker(void)
{
	u08 static state = 0;
	u08 sound;
	if (GetMessage(MSG_BEEP_STOP))
	{
		state = 0;
		SPEAKER_ON = 0;
		return;
	}
	switch (state)
	{
	case 0:
		if (GetMessage(MSG_BEEP))
			state = 1;
		break;
	case 1:
		sound = bufferGetFromFront(&speakerBuffer);
		if (sound == LONG_BEEP)
		{
			state = 2;
			SPEAKER_ON = 1;
			StartTimer(TIMER_SPEAKER);
		}
		else if (sound == SHORT_BEEP)
		{
			state = 3;
			SPEAKER_ON = 1;
			StartTimer(TIMER_SPEAKER);
		}
		else if (sound == CLICK)
		{
			state = 5;
			SPEAKER_ON = 1;
			StartTimer(TIMER_SPEAKER);
		}
		else if (sound == 0)
		{
			SPEAKER_ON = 0;
			state = 0;
		}
		break;
	case 2:
		if (GetTimer(TIMER_SPEAKER) >= 500 * msec)
		{
			state = 4;
			StartTimer(TIMER_SPEAKER);
			SPEAKER_ON = 0;
		}
		break;
	case 3:
		if (GetTimer(TIMER_SPEAKER) >= 20 * msec)
		{
			state = 4;
			StartTimer(TIMER_SPEAKER);
			SPEAKER_ON = 0;
		}
		break;
	case 4:
		if (GetTimer(TIMER_SPEAKER) >= 100 * msec)
		{
			state = 1;
			PauseTimer(TIMER_SPEAKER);
		}
		break;
	case 5:
		if (GetTimer(TIMER_SPEAKER) >= 1 * msec)
		{
			state = 4;
			StartTimer(TIMER_SPEAKER);
			SPEAKER_ON = 0;
		}
		break;

	default:
		break;
	}
}