本文整理汇总了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);
}
}
示例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());
}