• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ Timers类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中Timers的典型用法代码示例。如果您正苦于以下问题:C++ Timers类的具体用法?C++ Timers怎么用?C++ Timers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Timers类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: pollTimers

void Timer::pollTimers()
{
  // Generate messages for timers
  if (!timers.empty()) {
    int t = ji_clock;
    int count;

    for (Timers::iterator it=timers.begin(), end=timers.end(); it != end; ++it) {
      Timer* timer = *it;
      if (timer && timer->m_lastTime >= 0) {
        count = 0;
        while (t - timer->m_lastTime > timer->m_interval) {
          timer->m_lastTime += timer->m_interval;
          ++count;

          /* we spend too much time here */
          if (ji_clock - t > timer->m_interval) {
            timer->m_lastTime = ji_clock;
            break;
          }
        }

        if (count > 0) {
          ASSERT(timer->m_owner != NULL);

          Message* msg = new TimerMessage(count, timer);
          msg->addRecipient(timer->m_owner);
          Manager::getDefault()->enqueueMessage(msg);
        }
      }
    }
  }
}
开发者ID:CalinLeafshade,项目名称:aseprite,代码行数:33,代码来源:timer.cpp


示例2: ASSERT

Timer::~Timer()
{
  Timers::iterator it = std::find(timers.begin(), timers.end(), this);
  ASSERT(it != timers.end());
  timers.erase(it);

  // Remove messages of this timer in the queue
  Manager::getDefault()->removeMessagesForTimer(this);
}
开发者ID:CalinLeafshade,项目名称:aseprite,代码行数:9,代码来源:timer.cpp


示例3: clearTimers

	/**
	*	Clears and releases all existing timers.
	*/
	void clearTimers()
	{
		// this has to be called at a different time
		// than fini, that's why it's a separate method
		for( Timers::iterator iTimer = gTimers.begin(); iTimer != gTimers.end(); iTimer++ )
		{
			Py_DECREF( iTimer->function );
			Py_DECREF( iTimer->arguments );
		}
		gTimers.clear();
	}
开发者ID:siredblood,项目名称:tree-bumpkin-project,代码行数:14,代码来源:py_callback.cpp


示例4: main

void main()
{
	/*CLoggingStream errors(L"errorLogs");

	g_Scripts.reset(new Scripting::Scripts(errors, 
		"D:\\Development\\C++\\Phasor - Copy\\Release"));

	g_Scripts->OpenScript("lua_test");
	g_Scripts->OpenScript("lua_test1");
	//Scripting::OpenScript("lua_test1");

	Scripting::PhasorCaller caller;
	caller.AddArg("hello");
	Scripting::Result result = caller.Call("funca");
	caller.AddArg("hello_again");
	caller.Call("funca");
	std::cout << result.size() << std::endl;

	g_Scripts->CloseScript("lua_test");
	g_Scripts->CloseScript("lua_test1");*/
	/*PhasorThread thread;
	thread.run();
	std::unique_ptr<PhasorThreadEvent> e = TestEvent::Create(0);
	thread.InvokeInAux(std::move(e));

	for (int i =0; i < 100000; i++)
	{
		thread.ProcessEvents();
		Sleep(5);

		//if (count == 100) break;
	}
	thread.close();
	while (!thread.has_closed()) {
		Sleep(10);
	}*/
	Timers timers;
	timer_t timer = TestTimer::Create(1000);
	timers.AddTimer(std::move(timer));
	timer_t timer1 = TestTimer1::Create(1000, timer->GetID());
	
	timer_t timer2 = TestTimer1::Create(1000, timer1->GetID());
	timers.AddTimer(std::move(timer2));
	timers.AddTimer(std::move(timer1));
	while (1)
	{
		timers.Process();
		Sleep(20);
	}
}
开发者ID:twhitcomb,项目名称:Phasor,代码行数:50,代码来源:main.cpp


示例5: pollTimers

void Timer::pollTimers()
{
  assert_ui_thread();

  // Generate messages for timers
  if (running_timers != 0) {
    ASSERT(!timers.empty());
    base::tick_t t = base::current_tick();

    for (auto timer : timers) {
      if (timer && timer->isRunning()) {
        int64_t count = ((t - timer->m_lastTick) / timer->m_interval);
        if (count > 0) {
          timer->m_lastTick += count * timer->m_interval;

          ASSERT(timer->m_owner != nullptr);

          Message* msg = new TimerMessage(count, timer);
          msg->setRecipient(timer->m_owner);
          Manager::getDefault()->enqueueMessage(msg);
        }
      }
    }
  }
}
开发者ID:aseprite,项目名称:aseprite,代码行数:25,代码来源:timer.cpp


示例6: ApplicationEntryPoint

void ApplicationEntryPoint()
{
    BOOL result;
    //RAM         RamTest    ( (UINT32*)RAMTestBase, (UINT32)RAMTestSize, (ENDIAN_TYPE)ENDIANESS, BUS_WIDTH );
    TimedEvents eventsTest;
    //UART        usartTest  ( COMTestPort, 9600, USART_PARITY_NONE, 8, USART_STOP_BITS_ONE, USART_FLOW_NONE );
    GPIO        gpioTest   ( GPIOTestPin );   
    //SPI         spiTest    ( SPIChipSelect, SPIModule, g_EEPROM_STM95x );
    Timers      timersTest ( DisplayInterval, TimerDuration );

    do
    {   
        //result = RamTest.Execute   ( STREAM__OUT );       
        result = eventsTest.Execute( STREAM__OUT );
        //result = usartTest.Execute ( STREAM__OUT );
        result = gpioTest.Execute  ( STREAM__OUT );
        //result = spiTest.Execute   ( STREAM__OUT );
        result = timersTest.Execute( STREAM__OUT );

    } while(FALSE); // run only once!

    while(TRUE);
}
开发者ID:EddieGarmon,项目名称:netduino-netmf,代码行数:23,代码来源:NativeSample.cpp


示例7: callNextFrame

	/**
	*	This function adds a script 'timer' to be called next tick
	*
	*	It is used by routines which want to make script calls but can't
	*	because they're in the middle of something scripts might mess up
	*	(like iterating over the scene to tick or draw it)
	*
	*	The optional age parameter specifies the age of the call,
	*	i.e. how far in the past it wanted to be made.
	*	Older calls are called back first.
	*
	*	@note: This function steals the references to both fn and args
	*/
	void callNextFrame( PyObject * fn, PyObject * args,
								const char * reason, double age )
	{
		TimerHandle handle;
		if(!gFreeTimerHandles.empty())
		{
			handle = gFreeTimerHandles.top();
			handle.issueCount++;
			gFreeTimerHandles.pop();
		}
		else
		{
			if (gTimers.size() >= USHRT_MAX)
			{
				PyErr_SetString( PyExc_TypeError, "callNextFrame: Callback handle overflow." );
				return;
			}
			handle.id = gTimers.size() + 1;
			handle.issueCount = 1;
		}

		TimerRecord newTR = { getTotalGameTime() - age, fn, args, reason, { handle.i32 } };
		gTimers.push_back( newTR );
	}
开发者ID:siredblood,项目名称:tree-bumpkin-project,代码行数:37,代码来源:py_callback.cpp


示例8: OnServerClose

void OnServerClose()
{
    *g_PhasorLog << "Closing the server..." << endl;

    halo::game::cleanupPlayers(true);

    g_Scripts.reset();
    g_Timers.RemoveAllTimers();

    g_Thread.close();
    for (int i = 0; i < 100; i++) {
        if (g_Thread.has_closed()) break;
        Sleep(10);
    }

    scriptOutput.reset();
    g_PhasorLog.reset();
    g_ScriptsLog.reset();
    g_GameLog.reset();
    g_RconLog.reset();
    g_PrintStream.reset();

    ExitProcess(0);
}
开发者ID:ChadSki,项目名称:Phasor,代码行数:24,代码来源:main.cpp


示例9: m_owner

namespace ui {

typedef std::list<Timer*> Timers;

static Timers timers; // Registered timers

Timer::Timer(int interval, Widget* owner)
  : m_owner(owner ? owner: Manager::getDefault())
  , m_interval(interval)
  , m_lastTime(-1)
{
  ASSERT(m_owner != NULL);

  timers.push_back(this);
}

Timer::~Timer()
{
  Timers::iterator it = std::find(timers.begin(), timers.end(), this);
  ASSERT(it != timers.end());
  timers.erase(it);

  // Remove messages of this timer in the queue
  Manager::getDefault()->removeMessagesForTimer(this);
}

bool Timer::isRunning() const
{
  return (m_lastTime >= 0);
}

void Timer::start()
{
  m_lastTime = ji_clock;
}

void Timer::stop()
{
  m_lastTime = -1;
}

void Timer::tick()
{
  onTick();
}

void Timer::setInterval(int interval)
{
  m_interval = interval;
}

void Timer::onTick()
{
  // Fire Tick signal.
  Tick();
}

void Timer::pollTimers()
{
  // Generate messages for timers
  if (!timers.empty()) {
    int t = ji_clock;
    int count;

    for (Timers::iterator it=timers.begin(), end=timers.end(); it != end; ++it) {
      Timer* timer = *it;
      if (timer && timer->m_lastTime >= 0) {
        count = 0;
        while (t - timer->m_lastTime > timer->m_interval) {
          timer->m_lastTime += timer->m_interval;
          ++count;

          /* we spend too much time here */
          if (ji_clock - t > timer->m_interval) {
            timer->m_lastTime = ji_clock;
            break;
          }
        }

        if (count > 0) {
          ASSERT(timer->m_owner != NULL);

          Message* msg = new TimerMessage(count, timer);
          msg->addRecipient(timer->m_owner);
          Manager::getDefault()->enqueueMessage(msg);
        }
      }
    }
  }
}

void Timer::checkNoTimers()
{
  ASSERT(timers.empty());
}

} // namespace ui
开发者ID:CalinLeafshade,项目名称:aseprite,代码行数:97,代码来源:timer.cpp


示例10: setTotalGameTimeFn

namespace Script
{
	/**
	 * Store a callback function that can tell caller the total time that
	 * game has been running. The application should call setTotalGameTimeFn
	 * to set this up.
	 */
	TotalGameTimeFn s_totalGameTimeFn = NULL;

	/**
	 * Set the callback function.
	 */
	void setTotalGameTimeFn( TotalGameTimeFn fn )
	{
		s_totalGameTimeFn = fn;
	}

	/**
	 * Get total amount of time that game has been running.
	 */
	double getTotalGameTime()
	{
		return s_totalGameTimeFn();
	}

	/**
	*	This union is used by the BigWorld client callback
	*	system. It provides a handle to a callback request.
	*/
	union TimerHandle
	{
		uint32 i32;
		struct
		{
			uint16 id;
			uint16 issueCount;
		};
	};

	typedef std::stack<TimerHandle>		TimerHandleStack;
	TimerHandleStack					gFreeTimerHandles;

	/**
	*	This structure is used by the BigWorld client callback
	*	system.  It records a single callback request.
	*/
	struct TimerRecord
	{
		/**
		*	This method returns whether or not the input record occurred later than
		*	this one.
		*
		*	@return True if input record is earlier (higher priority),
		*		false otherwise.
		*/
		bool operator <( const TimerRecord & b ) const
		{
			return b.time < this->time;
		}

		double		time;			///< The time of the record.
		PyObject	* function;		///< The function associated with the record.
		PyObject	* arguments;	///< The arguments associated with the record.
		const char	* source;		///< The source of this timer record
		TimerHandle	handle;			///< The handle issued for this callback.
	};


	typedef std::list<TimerRecord>	Timers;
	Timers	gTimers;

	/**
	*	Clears and releases all existing timers.
	*/
	void clearTimers()
	{
		// this has to be called at a different time
		// than fini, that's why it's a separate method
		for( Timers::iterator iTimer = gTimers.begin(); iTimer != gTimers.end(); iTimer++ )
		{
			Py_DECREF( iTimer->function );
			Py_DECREF( iTimer->arguments );
		}
		gTimers.clear();
	}

	/**
	*	This function calls any script timers which have expired by now
	*/
	void tick( double timeNow )
	{
		const int MAX_TIMER_CALLS_PER_FRAME = 1000;

		Timers  timersToCall;
		Timers::iterator iter = gTimers.begin();
		while ( iter != gTimers.end() ) 
		{
			if ( iter->time <= timeNow )
			{
				timersToCall.push_back( *iter );
//.........这里部分代码省略.........
开发者ID:siredblood,项目名称:tree-bumpkin-project,代码行数:101,代码来源:py_callback.cpp


示例11: tick

	/**
	*	This function calls any script timers which have expired by now
	*/
	void tick( double timeNow )
	{
		const int MAX_TIMER_CALLS_PER_FRAME = 1000;

		Timers  timersToCall;
		Timers::iterator iter = gTimers.begin();
		while ( iter != gTimers.end() ) 
		{
			if ( iter->time <= timeNow )
			{
				timersToCall.push_back( *iter );
				iter = gTimers.erase( iter );
			}
			else
			{
				++iter;
			}
		}

		// Using a reverse iterator, since the TimerRecord comparison operator causes
		// the sorted list to be in reverse order (earlier timers are later in the list).
		stable_sort( timersToCall.begin(), timersToCall.end() );
		int numExpired = 0;
		Timers::reverse_iterator revIter = timersToCall.rbegin();
		for ( ; revIter != timersToCall.rend() && numExpired < MAX_TIMER_CALLS_PER_FRAME; ++revIter )
		{
			TimerRecord& timer = *revIter;

			gFreeTimerHandles.push( timer.handle );

			Script::call( timer.function, timer.arguments, timer.source );
			// Script::call decrefs timer.function and timer.arguments for us

			numExpired++;
		}


		if (numExpired >= MAX_TIMER_CALLS_PER_FRAME)
		{
			// If there are too many to run this frame, put the remainder back into the main list.
			for ( ; revIter != timersToCall.rend(); ++revIter )
			{
				TimerRecord& timer = *revIter;
				gTimers.push_back( timer );
			}

			//ERROR_MSG( "BigWorldClientScript::tick: Loop interrupted because"
			//	" too many timers (> %d) wanted to expire this frame!",
			//	numExpired );
		}
	}
开发者ID:siredblood,项目名称:tree-bumpkin-project,代码行数:54,代码来源:py_callback.cpp


示例12: timer

	CAFKDetection::CAFKDetection(s_player& player, Timers& timers)
		: player(player), timers(timers), move_count(0), afk_duration(0)
	{
		timer_ptr timer(new CAFKDetectionEvent(60000,*this));
		timer_id = timers.AddTimer(std::move(timer));
	}
开发者ID:th3w1zard1,项目名称:Phasor,代码行数:6,代码来源:AFKDetection.cpp


示例13: haveTimers

bool Timer::haveTimers()
{
  return !timers.empty();
}
开发者ID:aseprite,项目名称:aseprite,代码行数:4,代码来源:timer.cpp


示例14: checkNoTimers

void Timer::checkNoTimers()
{
  ASSERT(timers.empty());
}
开发者ID:CalinLeafshade,项目名称:aseprite,代码行数:4,代码来源:timer.cpp


示例15: m_owner

namespace ui {

typedef std::vector<Timer*> Timers;

static Timers timers; // Registered timers
static int running_timers = 0;

Timer::Timer(int interval, Widget* owner)
  : m_owner(owner ? owner: Manager::getDefault())
  , m_interval(interval)
  , m_running(false)
  , m_lastTick(0)
{
  ASSERT(m_owner != nullptr);
  assert_ui_thread();

  timers.push_back(this);
}

Timer::~Timer()
{
  assert_ui_thread();

  auto it = std::find(timers.begin(), timers.end(), this);
  ASSERT(it != timers.end());
  if (it != timers.end())
    timers.erase(it);

  // Stop the timer and remove it from the message queue.
  stop();
}

void Timer::start()
{
  assert_ui_thread();

  m_lastTick = base::current_tick();
  if (!m_running) {
    m_running = true;
    ++running_timers;
  }
}

void Timer::stop()
{
  assert_ui_thread();

  if (m_running) {
    m_running = false;
    --running_timers;

    // Remove messages of this timer in the queue. The expected behavior
    // is that when we stop a timer, we'll not receive more messages
    // about it (even if there are enqueued messages waiting in the
    // message queue).
    Manager::getDefault()->removeMessagesForTimer(this);
  }
}

void Timer::tick()
{
  assert_ui_thread();

  onTick();
}

void Timer::setInterval(int interval)
{
  m_interval = interval;
}

void Timer::onTick()
{
  // Fire Tick signal.
  Tick();
}

void Timer::pollTimers()
{
  assert_ui_thread();

  // Generate messages for timers
  if (running_timers != 0) {
    ASSERT(!timers.empty());
    base::tick_t t = base::current_tick();

    for (auto timer : timers) {
      if (timer && timer->isRunning()) {
        int64_t count = ((t - timer->m_lastTick) / timer->m_interval);
        if (count > 0) {
          timer->m_lastTick += count * timer->m_interval;

          ASSERT(timer->m_owner != nullptr);

          Message* msg = new TimerMessage(count, timer);
          msg->setRecipient(timer->m_owner);
          Manager::getDefault()->enqueueMessage(msg);
        }
      }
    }
//.........这里部分代码省略.........
开发者ID:aseprite,项目名称:aseprite,代码行数:101,代码来源:timer.cpp


示例16: ASSERT

Timer::~Timer()
{
  assert_ui_thread();

  auto it = std::find(timers.begin(), timers.end(), this);
  ASSERT(it != timers.end());
  if (it != timers.end())
    timers.erase(it);

  // Stop the timer and remove it from the message queue.
  stop();
}
开发者ID:aseprite,项目名称:aseprite,代码行数:12,代码来源:timer.cpp



注:本文中的Timers类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ pi::Timespan类代码示例发布时间:2022-05-31
下一篇:
C++ Timer_Object类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap