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


C++ Stopwatch::GetElapsedSeconds方法代码示例

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


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

示例1: main

int main(int argc, char* argv[])
{
	LinearEquationSystemFactory factory;
	LinearEquationSystemSolver solver;

	for (; n <= nLimit; n *= multiplier)
	{
		float minTime = FLT_MAX;
		for (int attempt = 0; attempt < repeatsNumber; ++attempt)
		{
			LinearEquationSystem* system = factory.Create(n);
			NUMBER* solution = new NUMBER[n];

			stopwatch.Start();			
			solver.Solve(system, solution);
			stopwatch.Stop();

			float elapsedSeconds = stopwatch.GetElapsedSeconds();
			if (elapsedSeconds < minTime)
			{
				minTime = elapsedSeconds;
			}

			bool result = checker.IsCorrectSolution(system, solution);
			printf("Correct: %s \n", result ? "yes" : "no");

			delete system;
			delete []solution;
		}

		printf("N = %d, Elapsed seconds: %f\n", n, minTime);
	}
}
开发者ID:alxmglk,项目名称:jacobi-method,代码行数:33,代码来源:main.cpp

示例2: StartGame

	void Engine::StartGame()
	{
		myGameIsRunning = true;

		// Close the game when we hit the close button
		myEventHost->RegisterEvent<CloseButtonPressedEvent>([=](CloseButtonPressedEvent &ev)
		{
			myGameIsRunning = false;
		});

		// Show the window
		myRenderer->GetWindow()->SetVisible(true);

		Stopwatch stopwatch;
		std::vector<RenderCommand> *currentRenderCommands = new std::vector<RenderCommand>();

		float time = 0.f;

		while (myGameIsRunning == true)
		{
			float deltaTime = stopwatch.GetElapsedSeconds();
			time += deltaTime;
			stopwatch.Restart();

			myRenderer->TriggerEvents();

			std::swap(currentRenderCommands, myNewRenderCommands);

			float progressToNextFixedUpdate = (myTimeAccumulator / myTimeStep);

			myTimeAccumulator += deltaTime;

			Matrix33f worldToViewport;
			Transformation cameraTransformation = mySceneHost->GetCurrentScene()->GetCamera().GetTransformation();

			auto gameLogicWork = myThreadPool->QueueWorkItem(std::function<void()>([=]
			{
				while (myTimeAccumulator >= myTimeStep)
				{
					myEventHost->TriggerEvent(UpdateEvent(myTimeStep));
					myEventHost->TriggerEvent(EndUpdateEvent());
					myTimeAccumulator -= myTimeStep;
				}

				myEventHost->TriggerEvent(DrawEvent());
			}));

			Vector2f windowSize = Vector2f(myRenderer->GetWindow()->GetSize());
			worldToViewport *= Matrix33f::CreateScale(2.f / windowSize.x, -2.f / windowSize.y, 1.f) * Matrix33f::CreateTranslation(-cameraTransformation.Position.x, -cameraTransformation.Position.y) * Matrix33f::CreateRotateAroundZ(cameraTransformation.Rotation);

			myRenderer->SetWorldToViewportMatrix(worldToViewport);

			myRenderer->Clear();
			RenderTarget &renderTarget = *myRenderer->GetRenderTarget();
			
			for (size_t i = 0; i < currentRenderCommands->size(); i++)
			{
				RenderCommand currentCommand = (*currentRenderCommands)[i];

				Vector2f position = currentCommand.previousPosition + (currentCommand.currentPosition - currentCommand.previousPosition) * progressToNextFixedUpdate;

				renderTarget.Render(currentCommand.texture, position);
			}
			currentRenderCommands->clear();

			myRenderer->PresentBackBuffer();

			float beginSleep = stopwatch.GetElapsedSeconds();
			std::this_thread::sleep_for(std::chrono::microseconds(1));

			// Wait for the game logic update to finish
			gameLogicWork->Wait();

			if (mySceneHost->GetCurrentScene() == nullptr)
			{
				myGameIsRunning = false;
			}
		}

		delete currentRenderCommands;

		myEventHost->TriggerEvent(ExitingEvent());
	}
开发者ID:HighQuality,项目名称:OGLRenderer,代码行数:83,代码来源:Engine.cpp


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