コード例 #1
0
ファイル: worldgl.cpp プロジェクト: mimoccc/OSM3D
WorldGL::WorldGL ()
{
	m_Window_Width = 800;
	m_Window_Height = 600;
	m_Window_FullscreenWidth = GetSystemMetrics (SM_CXSCREEN);
	m_Window_FullscreenHeight = GetSystemMetrics (SM_CYSCREEN);
	m_Window_IsOpen = false;
	m_Window_IsFullscreen = false;
	m_Window_VerticalSync = false;

	m_Timer_UseAccurateFramerateLimiting = true;

	m_Timer_Start = Timer_GetTime ();
	m_Timer_FrameCount = 0;
	m_Timer_FrameTrackStart = 0;
	m_Timer_FPS = 0;
	m_Timer_UpdatedFPS = false;

	m_Timer_StartHR = Timer_GetTimeHR ();

	m_FpsCap = 60;

	m_Window_LastRenderTickHR = 0;

	m_InputContainer.nullKeys ();
	m_InputContainer.nullMouse ();
	m_InputContainer.nullMouseButton ();
	m_Input_ScrollAmount = 0;

	m_KeyUpdateAmount = 0;

	SDL_GetMouseState (&(m_InputContainer.m_MouseX), &(m_InputContainer.m_MouseY));

	//SDL_ShowCursor (false);
}
コード例 #2
0
ファイル: Timers.c プロジェクト: yguo89/RTOS
/******** Timer_GetCCPPeriod ************************************************
// Count the number of system ticks during one period of CCP input frequency										
// Input: timer is one of the Timer_T value ( Timer1A, Timer1B... )
// Output: none										
// ------------------------------------------------------------------------*/
void Timer_GetCCPPeriod	( Timer_T timer )
{
	unsigned long ticks = 0;
	static unsigned long last_time = 0;
	static unsigned long this_time = 0;
	static char counter = 0;
	portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;

	if ( counter )
	{
		// finish
		this_time = Timer_GetTime ( timer );

		if ( this_time >= last_time )
		{
			// sysTick overflow, flush data
			last_time = 0;
			this_time = 0;
			counter = 0;
		}
		else
		{
			// get the number of ticks in a period, push on to the Queue
			ticks = last_time - this_time;
			while ( xQueueSendFromISR (CCPQueue[timer], &ticks, &xHigherPriorityTaskWoken) != pdTRUE );

			// reset ISR and disable interrupt
			counter = 0;
			Timer_Disable ( timer ) ;
		}

	}
	else
	{
		// begin
		last_time = Timer_GetTime ( timer );

		// next interrupt will finish system tick calculation
		counter = 1;
	}
}
コード例 #3
0
ファイル: Sensor.c プロジェクト: yguo89/RTOS
// *************** Sensor_ReadTimerValue ***************
int Sensor_ReadCCPTimerValue ( PORT_T *port )
{
	return Timer_GetTime ( (Timer_T)(port->port_number-1) );
} 
コード例 #4
0
ファイル: timer.c プロジェクト: YTakami/makecontroller
/** Sets the requested entry to run.
  This routine adds the entry to the running queue and then decides if it needs
  to start the timer (if it's not running) or alter the timer's clock for a shorter
  period.
  @param timerEntry pointer to the FastTimerEntry to be run. 
  */
int Timer_Set( TimerEntry* timerEntry )
{
  // this could be a lot smarter - for example, modifying the current period?
  if ( !Timer.servicing ) 
    TaskEnterCritical();

  if ( !Timer.running )
  {
    Timer_SetActive( true );
    Timer_SetTimeTarget( timerEntry->timeInitial );
    Timer_Enable();
  }  

  // Calculate how long remaining
  int target = Timer_GetTimeTarget();
  int timeCurrent = Timer_GetTime();
  int remaining = target - timeCurrent;

  // Get the entry ready to roll
  timerEntry->timeCurrent = timerEntry->timeInitial;

  // Add entry
  TimerEntry* first = Timer.first;
  Timer.first = timerEntry;
  timerEntry->next = first;

  // Are we actually servicing an interupt right now?
  if ( !Timer.servicing )
  {
    // No - so does the time requested by this new timer make the time need to come earlier?
    if ( timerEntry->timeCurrent < ( remaining - TIMER_MARGIN ) )
    {
      // Damn it!  Reschedule the next callback
      Timer_SetTimeTarget( target - ( remaining - timerEntry->timeCurrent ));
    }
    else
    {
      // pretend that the existing time has been with us for the whole slice so that when the 
      // IRQ happens it credits the correct (reduced) time.
      timerEntry->timeCurrent += timeCurrent;
    }
  }
  else
  {
    // Yep... we're servicing something right now

    // Make sure the previous pointer is OK.  This comes up if we were servicing the first item
    // and it subsequently wants to delete itself, it would need to alter the next pointer of the 
    // the new head... err... kind of a pain, this
    if ( Timer.previous == NULL )
      Timer.previous = timerEntry;

    // Need to make sure that if this new time is the lowest yet, that the IRQ routine 
    // knows that.  Since we added this entry onto the beginning of the list, the IRQ
    // won't look at it again
    if ( Timer.nextTime == -1 || Timer.nextTime > timerEntry->timeCurrent )
        Timer.nextTime = timerEntry->timeCurrent;
  }

  if ( !Timer.servicing ) 
    TaskExitCritical();

  return CONTROLLER_OK;
}
コード例 #5
0
ファイル: worldgl.cpp プロジェクト: mimoccc/OSM3D
int WorldGL::Timer_GetDelta ()
{
	int prevTicks = m_Timer_Start;
	m_Timer_Start = Timer_GetTime ();
	return m_Timer_Start - prevTicks;
}
コード例 #6
0
ファイル: worldgl.cpp プロジェクト: mimoccc/OSM3D
void WorldGL::Window_Refresh ()
{
	//	Try to Sleep instead of going into the SDL's CPU-heavy while(true) loop
	//	TODO: A different method of framerate limiting should be applied when vertical-sync
	//		is enabled (TODO TODO: Implement vertical sync toggling)
	if (m_Window_LastRenderTickHR != 0 && m_FpsCap != -1)
	{
		ubigint timePerFrame = (ubigint)(1.0 / Timer_GetResolutionHR ()) / m_FpsCap;

		ubigint curTicks = Timer_GetTimeHR ();
		//	Only sleep if we've got some leftover time to spend
		if (curTicks - m_Window_LastRenderTickHR < timePerFrame)
		{
			ubigint cpuTicks = (ubigint)(timePerFrame - (curTicks - m_Window_LastRenderTickHR));
			int sleepTime = (int)(cpuTicks * Timer_GetResolutionHR () * 1000.0);
			Sleep (sleepTime);
		}

		
		//	Spin while we wait for the rest of the time to get chewed up (yes, by the time we're
		//		done here we'll still need to SDL_GL_SwapBuffers, but that's not significant)
		while (Timer_GetTimeHR () - m_Window_LastRenderTickHR < timePerFrame && m_Timer_UseAccurateFramerateLimiting)
		{
		}
	}

	SDL_GL_SwapBuffers ();
	m_Timer_FrameCount++;

	ubigint ticks = Timer_GetTimeHR ();
	m_Window_LastRenderTickHR = ticks;

	if (m_Timer_FrameTrackStart == 0)
		m_Timer_FrameTrackStart = ticks;

	if (Timer_GetTime () - m_Timer_FrameTrackStart >= 1000)
	{
		m_Timer_FPS = m_Timer_FrameCount;
		m_Timer_FrameCount = 0;

		m_Timer_FrameTrackStart = Timer_GetTime ();

		m_Timer_UpdatedFPS = true;
	}

	//	Reset key press/release states
	for (unsigned int i = 0; i < m_KeyUpdateAmount; i++)
	{
		switch (m_KeyUpdateList [i].m_Update)
		{
		case (KeyUpdate::UPDATE_DOWN):	m_InputContainer.m_KeyState [m_KeyUpdateList [i].m_Key].down = false;	break;
		case (KeyUpdate::UPDATE_UP):	m_InputContainer.m_KeyState [m_KeyUpdateList [i].m_Key].up	 = false;	break;
		}
	}
	m_KeyUpdateAmount = 0;

	//	Reset mouse button states as well
	m_InputContainer.m_LeftMouseButton.down = false;
	m_InputContainer.m_LeftMouseButton.up = false;

	m_InputContainer.m_MiddleMouseButton.down = false;
	m_InputContainer.m_MiddleMouseButton.up = false;

	m_InputContainer.m_RightMouseButton.down = false;
	m_InputContainer.m_RightMouseButton.up = false;

	m_Input_ScrollAmount = 0;

	m_Events.clear ();
}