当前位置: 首页>>代码示例>>C++>>正文


C++ Timer::WindBackStartingTime方法代码示例

本文整理汇总了C++中common::Timer::WindBackStartingTime方法的典型用法代码示例。如果您正苦于以下问题:C++ Timer::WindBackStartingTime方法的具体用法?C++ Timer::WindBackStartingTime怎么用?C++ Timer::WindBackStartingTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common::Timer的用法示例。


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

示例1: WindBack

/* Wind back the frame counter when a save state is loaded. Currently we don't know what that means in
   time so we just guess that the time is proportional the the number of frames
   
   Todo: There are many assumptions here: We probably want to replace the time here by the actual time
   that we save together with the save state or the input recording for example. And have it adjusted
   for full speed playback (whether it's 30 fps or 60 fps or some other speed that the game is natively
   capped at). Also the input interrupts do not occur as often as the frame renderings, they occur more
   often. So we may want to move the input recording to fram updates, or perhaps sync the input interrupts
   to frame updates.
   */
void WindBack(int Counter)
{
	/* Counter should be smaller than g_FrameCounter, however it currently updates faster than the
	   frames so currently it may not be the same. Therefore I use the abs() function. */
	int AbsoluteFrameDifference = abs(g_FrameCounter - Counter);
	float FractionalFrameDifference = (float) AbsoluteFrameDifference / (float) g_FrameCounter;

	// Update the frame counter
	g_FrameCounter = Counter;

	// Approximate a time to wind back the clock to
	// Get the current time
	u64 CurrentTimeMs = ReRecTimer.GetTimeElapsed();
	// Save the current time in seconds in a new double
	double CurrentTimeSeconds = (double) (CurrentTimeMs / 1000);
	// Reduce it by the same proportion as the counter was wound back
	CurrentTimeSeconds = CurrentTimeSeconds * FractionalFrameDifference;
	// Update the clock
	ReRecTimer.WindBackStartingTime((u64)CurrentTimeSeconds * 1000);

	// Logging
	DEBUG_LOG(CONSOLE, "WindBack: %i %u\n", Counter, (u64)CurrentTimeSeconds);
}
开发者ID:madnessw,项目名称:thesnow,代码行数:33,代码来源:CoreRerecording.cpp


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