예제 #1
0
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
0
	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());
	}