Esempio n. 1
0
		Ref<Image> Image::load_from_data (const Ptr<IData> data) {
			static Stopwatch t;
			static unsigned count = 0; ++count;

			Ref<Image> loaded_image;
			Shared<Buffer> buffer;

			t.start();

			buffer = data->buffer();

			switch (buffer->mimetype()) {
			case IMAGE_JPEG:
				loaded_image = load_jpeg_image(data);
				break;
			case IMAGE_PNG:
				loaded_image = load_png_image(data);
				break;
			//case Data::IMAGE_DDS:
			//	loaded_image = load_ddsimage(data);
			default:
				logger()->log(LOG_ERROR, "Could not load image: Unsupported image format.");
			}

			t.pause();

			logger()->log(LOG_INFO, LogBuffer() << "*** Total time to load " << count << " images: " << t.time() << "s");

			return loaded_image;
		}
TestCase * Grader07::testSpellCheck(std::string filename)
{
  Commands07 cmds07;
  std::vector<std::string> words;
  std::vector<SpellCheckCmd> commands;

  cmds07.readReads("words", words);
  cmds07.loadSpellCheckCommands(filename, commands);

  if(words.size() == 0){
    return failed("cannot read input file #1");
  }

  if(commands.size() == 0){
    return failed("cannot read input file #2");
  }

  Stopwatch watch;
  watch.start();

  ISpellCheck * checker = (ISpellCheck *) createObject("ISpellCheck");
  if(checker == NULL){
    return nullObject("ISpellCheck");
  }

  watch.pause();
  checker->loadDictionary(words);
  watch.unpause();

  for(size_t i = 0; i < commands.size(); ++i){
    SpellCheckCmd cmd = commands[i];
    std::vector<std::string> product_corrections = checker->suggestCorrections(cmd.word);
    watch.pause();
    std::sort(product_corrections.begin(), product_corrections.end());
    if(product_corrections != cmd.corrections){
      return failed("corrections mismatch");
    }
    watch.unpause();
  }

  watch.stop();
  return passed(watch.getTime());
}
Esempio n. 3
0
void Main()
{
	Window::SetTitle(L"10.00");

	Stopwatch stopwatch;

	Effect effect;

	const Font font(50);

	const Vec2 pos = font(L"00.00").regionCenter(Window::Center()).pos;

	while (System::Update())
	{
		if ((!stopwatch.isActive() || stopwatch.isPaused()) && Input::MouseL.clicked)
		{
			Graphics::SetVSyncEnabled(false);
			stopwatch.start();
		}
		else if (stopwatch.isActive() && Input::MouseL.clicked)
		{
			Graphics::SetVSyncEnabled(false);
			stopwatch.pause();
		}
		else if (Input::MouseR.clicked)
		{
			stopwatch.reset();
		}
		else if (stopwatch.isPaused() && stopwatch.ms() / 10 == 10'00)
		{
			Graphics::SetVSyncEnabled(true);
			effect.add<Firework>(Circular(200, Random(TwoPi)) + Window::Center(), 30);
		}

		font(L"{:0>2}.{:0>2}"_fmt, stopwatch.s(), stopwatch.ms() % 1000 / 10).draw(pos);

		if (effect.hasEffects())
		{
			Graphics2D::SetBlendState(BlendState::Additive);

			effect.update();

			Graphics2D::SetBlendState(BlendState::Default);
		}
		else
		{
			System::Sleep(4ms);
		}
	}
}
Esempio n. 4
0
void DynamicGameLoader::reload()
{
	std::cout << ConsoleColour(Console::BLUE) << "\n**RELOADING GAME**" << std::endl;
	Stopwatch timer;
	
	core->onSuspended();
	unload();
	load();
	hotPatch();
	core->onReloaded();

	timer.pause();
	
	std::cout << "Done in " << timer.elapsedSeconds() << " seconds.\n" << ConsoleColour() << std::endl;
}
TestCase * Grader07::testStringSearch(std::string cmds_filename, std::string input_filename)
{
  std::vector<StringSearchCmd> commands;

  Commands07 cmds07;
  cmds07.loadStringSearchCommmands(cmds_filename, commands);
  std::string to_search = cmds07.readStringFile(input_filename);

  if(commands.size() == 0){
    return failed("cannot read input file #1");
  }

  if(to_search == ""){
    return failed("cannot read input file #2");
  }

  Stopwatch watch;
  watch.start();

  IStringSearch * searcher = (IStringSearch *) createObject("IStringSearch");
  if(searcher == NULL){
    return nullObject("IStringSearch");
  }

  watch.pause();
  searcher->prepareText(to_search);
  watch.unpause();

  for(size_t i = 0; i < commands.size(); ++i){
    StringSearchCmd cmd = commands[i];
    std::vector<int> product_results = searcher->search(cmd.to_find);
    if(product_results.size() != cmd.positions.size()){
      return failed("incorrect return size");
    }
    std::sort(product_results.begin(), product_results.end());
    if(product_results != cmd.positions){
      return failed("at least one incorrect return index");
    }
  }

  watch.stop();
  return passed(watch.getTime());
}
Esempio n. 6
0
    // Wait until the the frame is completed or rendering is aborted.
    IRendererController::Status wait_for_event(IFrameRenderer& frame_renderer)
    {
        bool is_paused = false;

        while (true)
        {
            if (!frame_renderer.is_rendering())
                return IRendererController::TerminateRendering;

            const IRendererController::Status status = m_renderer_controller->get_status();

            switch (status)
            {
              case IRendererController::ContinueRendering:
                if (is_paused)
                {
                    frame_renderer.resume_rendering();
                    m_renderer_controller->on_rendering_resume();
                    m_stopwatch.resume();
                    is_paused = false;
                }
                break;

              case IRendererController::PauseRendering:
                if (!is_paused)
                {
                    frame_renderer.pause_rendering();
                    m_renderer_controller->on_rendering_pause();
                    m_stopwatch.pause();
                    is_paused = true;
                }
                break;

              default:
                return status;
            }

            m_renderer_controller->on_progress();

            foundation::sleep(1);   // namespace qualifer required
        }
    }
        /// <summary>
        /// EasingControllerを一時停止します。
        /// </summary>
         /// <returns>
        /// なし
        /// </returns>
		void pause()
		{
			m_stopwatch.pause();
		}
TestCase * Grader02::testWorkload4(int len, int order, int merge_count,
	int merge_len){

	std::vector<int> input;
	std::vector<int> sorted;
	createVector(input, sorted, order, len, false);

	Stopwatch watch;
	watch.start();

	IPriorityQueue * queue = (IPriorityQueue *)createObject("IPriorityQueue4");
	if (queue == NULL){
		return nullObject("IPriorityQueue4");
	}

	watch.pause();
	GoldPriorityQueue gold_queue(sorted);

	for (size_t i = 0; i < merge_len; ++i){
		int key = input[i];
		std::string value = randomValue();
		gold_queue.push_back(key, value);

		watch.unpause();
		IKeyValue * key_value = (IKeyValue *)createObject("IKeyValue4");
		if (key_value == NULL){
			return nullObject("IKeyValue4");
		}

		key_value->setKey(key);
		key_value->setValue(value);

		queue->enqueue(key_value);

		int size = queue->size();
		if (size != gold_queue.size()){
			return failed("after enqueue, size is incorrect");
		}

		int user_key = queue->lowestKey();
		IVectorString * user_values = queue->lowestValues();
		gold_queue.iterate();
		int gold_key = gold_queue.lowestKey();
		std::vector<std::string> values = gold_queue.getValues(gold_key);
		watch.pause();

		if (gold_key != user_key){
			return failed("after enqueue, lowest key is incorrect");
		}

		if (valuesEqual(user_values, values) == false){
			return failed("after enqueue, values incorrect");
		}
	}

	for (int i = 1; i < merge_count; ++i){
		watch.unpause();
		IPriorityQueue * queue2 = (IPriorityQueue *)createObject("IPriorityQueue4");
		if (queue == NULL){
			return nullObject("IPriorityQueue4");
		}

		watch.pause();

		for (int j = (i * merge_len); j < ((i + 1) * merge_len); ++j){
			int key = input[j];
			std::string value = randomValue();
			gold_queue.push_back(key, value);

			watch.unpause();
			IKeyValue * key_value = (IKeyValue *)createObject("IKeyValue4");
			if (key_value == NULL){
				return nullObject("IKeyValue4");
			}

			key_value->setKey(key);
			key_value->setValue(value);

			queue2->enqueue(key_value);
			watch.pause();
		}

		watch.unpause();
		queue->merge(queue2);
		watch.pause();

		gold_queue.iterate();

		watch.unpause();
		int user_key = queue->lowestKey();
		IVectorString * user_values = queue->lowestValues();
		watch.pause();

		int gold_key = gold_queue.lowestKey();
		std::vector<std::string> values = gold_queue.getValues(gold_key);

		if (gold_key != user_key){
			return failed("during dequeue, lowest key is incorrect");
		}

		if (valuesEqual(user_values, values) == false){
			return failed("during dequeue, values incorrect");
		}
	}

	return passed(watch.getTime());
}
TestCase * Grader02::testWorkload1(int len, int order){

	std::vector<int> input;
	std::vector<int> sorted;
	createVector(input, sorted, order, len, true);

	Stopwatch watch;
	watch.start();

	IPriorityQueue * queue = (IPriorityQueue *)createObject("IPriorityQueue1");
	if (queue == NULL){
		return nullObject("IPriorityQueue1");
	}

	watch.pause();
	GoldPriorityQueue gold_queue(sorted);
	for (size_t i = 0; i < input.size(); ++i){
		int key = input[i];
		std::string value = randomValue();
		gold_queue.push_back(key, value);

		watch.unpause();
		IKeyValue * key_value = (IKeyValue *)createObject("IKeyValue1");
		if (key_value == NULL){
			return nullObject("IKeyValue1");
		}

		key_value->setKey(key);
		key_value->setValue(value);

		queue->enqueue(key_value);

		int size = queue->size();
		if (size != gold_queue.size()){
			return failed("after enqueue, size is incorrect");
		}

		int user_key = queue->lowestKey();
		IVectorString * user_values = queue->lowestValues();
		gold_queue.iterate();
		int gold_key = gold_queue.lowestKey();
		std::vector<std::string> values = gold_queue.getValues(gold_key);
		watch.pause();

		if (gold_key != user_key){
			return failed("after enqueue, lowest key is incorrect");
		}

		if (valuesEqual(user_values, values) == false){
			return failed("after enqueue, values incorrect");
		}

		bool check_sort = true;
		if (len != 10 && i % 100 != 0){
			check_sort = false;
		}

		if (check_sort){
			watch.unpause();
			IVectorKeyValue * user_sorted = queue->returnSorted();
			watch.pause();
			if (sortedEqual(user_sorted, gold_queue.returnSorted()) == false){
				return failed("after enqueue, sorted is not equal");
			}
		}
	}

	gold_queue.iterate();
	int count = 0;
	while (gold_queue.hasNext()){
		watch.unpause();
		int user_key = queue->lowestKey();
		IVectorString * user_values = queue->lowestValues();
		watch.pause();

		int gold_key = gold_queue.lowestKey();
		std::vector<std::string> values = gold_queue.getValues(gold_key);

		if (gold_key != user_key){
			return failed("during dequeue, lowest key is incorrect");
		}

		if (valuesEqual(user_values, values) == false){
			return failed("during dequeue, values incorrect");
		}

		watch.unpause();
		int size = queue->size();
		watch.pause();
		if (size != gold_queue.size()){
			return failed("during dequeue, size is incorrect");
		}

		bool check_sort = true;
		if (len != 10 && count % 100 != 0){
			check_sort = false;
		}

		if (check_sort){
			IVectorKeyValue * user_sorted = queue->returnSorted();
			std::vector<std::pair<int, std::string> > gold_sorted = gold_queue.returnSorted();
			if (sortedEqual(user_sorted, gold_sorted) == false){
				return failed("during dequeue, sorted is not equal");
			}
		}

		watch.unpause();
		queue->dequeue();
		watch.pause();
		gold_queue.dequeue();
		++count;
	}

	return passed(watch.getTime());
}