Ejemplo n.º 1
0
Cursor::Cursor()
{
	mSystem = new thor::ParticleSystem(TextureManager::get().getTexture("assets/gfx/particle.png"));

	mEmitter.setEmissionRate(16.0f);
	mEmitter.setParticleLifetime( thor::Distributions::uniform(sf::seconds(4), sf::seconds(4)) );

	mEmitter.setParticleRotation( thor::Distributions::uniform(0.f, 360.f) );

	mEmitter.setParticleScale(sf::Vector2f(0.3,0.3));
	mEmitter.setParticleVelocity(sf::Vector2f(0, 1000.0f));
	mEmitter.setParticleScale(sf::Vector2f(4.f,4.f));

	mSystem->addEmitter(thor::refEmitter(mEmitter));

	thor::ColorGradient gradient;
	gradient[0.0f] = sf::Color::Magenta;
	gradient[0.1f] = sf::Color::Red;
	gradient[0.2f] = sf::Color::Blue;
	gradient[0.3f] = sf::Color::Cyan;
	gradient[0.4f] = sf::Color::Green;
	gradient[0.5f] = sf::Color::Red;
	gradient[0.6f] = sf::Color::Magenta;
	gradient[0.7f] = sf::Color::Cyan;
	gradient[0.8f] = sf::Color::Red;
	gradient[0.9f] = sf::Color::Blue;
	gradient[1.0f] = sf::Color::Red;

	thor::ColorAnimation colorizer(gradient);
	thor::FadeAnimation fader(0.15f, 0.15f);

	mSystem->addAffector( thor::AnimationAffector(colorizer) );
	mSystem->addAffector( thor::AnimationAffector(fader) );
}
Ejemplo n.º 2
0
Snake::Snake(const sf::Vector2f& position, Game* game, unsigned initialSize)
: Entity(position, game, EntityType::Snake)
, position_(position)
, game_(game)
, direction_(Direction::Up)
, canShoot_(true)
, life_(100)	
, score_(0)
, FireRate(sf::seconds(0.25f))
, TakeDamageDelay(sf::seconds(0.4f))
{
	// The initial size should never be zero.
	assert(initialSize != 0);

	for (unsigned i = 0; i < initialSize; ++i)
	{	
		nodes_.push_back(SnakeNode({ position.x, position.y + SnakeNode::Size * i }, (i == 0 ? true : false)));
	}

	srand(time(NULL));

	particleSystem_.setTexture(game_->getTextureHolder().getTexture("particle"));
	thor::ColorGradient gradient;
	gradient[0.f] = sf::Color::Green;
	gradient[0.5f] = sf::Color::Red;
	gradient[1.f] = sf::Color::Black;
	thor::ColorAnimation colorizer(gradient);
	thor::FadeAnimation fader(0.1f, 0.1f);

	particleSystem_.addAffector(thor::AnimationAffector(colorizer));
	particleSystem_.addAffector(thor::AnimationAffector(fader));
}
Ejemplo n.º 3
0
bool runTests() {
    bandit::detail::options opt(0, {});
    bandit::detail::default_failure_formatter formatter;
    bandit::detail::colorizer colorizer(true);
    bandit::detail::dots_reporter reporter(formatter, colorizer);

    bandit::detail::register_listener(&reporter);

    bandit::detail::run_policy_ptr run_policy(new bandit::detail::always_run_policy());
    register_run_policy(run_policy.get());

    bandit::run(opt, bandit::detail::specs(), bandit::detail::context_stack(), reporter);

    return reporter.did_we_pass();
}
Ejemplo n.º 4
0
void MazeWindow::createMaze() {
  
  auto selected = algorithmSelector->currentText();
  auto factory = MakerFactory::byName(selected);
  
  maker = factory->maker();

  int w,h;
  w = h = dimensionSetter->value();
  stepCount = 0;
  maker->setGrid(Grid(w,h));
  mazeWidget->setMaker(maker);
  mazeWidget->setColorizer(factory->colorizer());
  mazeWidget->repaint();
}
Ejemplo n.º 5
0
 inline int run(int argc, char * argv[]) {
     bandit::detail::options opt(argc, argv);
     bandit::detail::failure_formatter_ptr formatter(bandit::detail::create_formatter(opt));
     bandit::detail::colorizer colorizer(!opt.no_color());
     bandit::detail::listener_ptr reporter(bandit::detail::create_reporter(opt, formatter.get(), colorizer));
     
     listener_adapter * listener = new listener_adapter(reporter.get());
     bandit::detail::registered_listener(listener);
     
     bandit::detail::run_policy_ptr run_policy = create_run_policy(opt);
     registered_run_policy(run_policy.get());
     
     testing::InitGoogleMock(&argc, argv);
     
     auto & gtest_listeners = testing::UnitTest::GetInstance()->listeners();
     delete gtest_listeners.Release(gtest_listeners.default_result_printer());
     gtest_listeners.Append(listener);
     
     return bandit::run(opt, bandit::detail::specs(), bandit::detail::context_stack(), *listener);
 }
Ejemplo n.º 6
0
void OnMouseUp(thor::ActionContext<std::string> context)
{
	emitter.setParticlePosition(window.mapPixelToCoords(sf::Mouse::getPosition(window)));
	if (selected_rune == 1)
	{
		// Build color gradient
		thor::ColorGradient gradient;
		gradient[0.f] = sf::Color::Yellow;
		gradient[0.5f] = sf::Color::Red;
		gradient[1.f] = sf::Color::Black;

		// Create color and fade in/out animations
		thor::ColorAnimation colorizer(gradient);
		thor::FadeAnimation fader(0.1f, 0.1f);

		particle_system.clearAffectors();
		// Add particle affectors
		particle_system.addAffector(thor::AnimationAffector(colorizer));
		particle_system.addAffector(thor::AnimationAffector(fader));
		particle_system.addAffector(thor::TorqueAffector(100.f));

		emitter.setParticlePosition(window.mapPixelToCoords(sf::Mouse::getPosition(window)));
		emitter.setParticleVelocity(thor::Distributions::circle(sf::Vector2f(0.0f, 0.0f), 100.f));
		emitter.setEmissionRate(50.0f);
		particle_system.addEmitter(thor::refEmitter(emitter), sf::seconds(0.35f));
	}
	else if (selected_rune == 2)
	{
		// Build color gradient
		thor::ColorGradient gradient;
		gradient[0.f] = sf::Color::Blue;
		gradient[0.5f] = sf::Color::Black;
		gradient[1.f] = sf::Color::Black;

		// Create color and fade in/out animations
		thor::ColorAnimation colorizer(gradient);
		thor::FadeAnimation fader(0.1f, 0.1f);

		particle_system.clearAffectors();
		// Add particle affectors
		particle_system.addAffector(thor::AnimationAffector(colorizer));
		particle_system.addAffector(thor::AnimationAffector(fader));
		particle_system.addAffector(thor::TorqueAffector(100.f));

		emitter.setParticlePosition(window.mapPixelToCoords(sf::Mouse::getPosition(window)));
		emitter.setParticleVelocity(thor::Distributions::deflect(sf::Vector2f(0.0f, -100.0f), 90.0f));
		emitter.setEmissionRate(100.0f);
		particle_system.addEmitter(thor::refEmitter(emitter), sf::seconds(0.35f));
	}
	else if (selected_rune == 3)
	{
		// Build color gradient
		thor::ColorGradient gradient;
		gradient[0.f] = sf::Color::Green;
		gradient[0.5f] = sf::Color::Cyan;
		gradient[1.f] = sf::Color::Black;

		// Create color and fade in/out animations
		thor::ColorAnimation colorizer(gradient);
		thor::FadeAnimation fader(0.1f, 0.1f);

		particle_system.clearAffectors();
		// Add particle affectors
		particle_system.addAffector(thor::AnimationAffector(colorizer));
		particle_system.addAffector(thor::AnimationAffector(fader));
		particle_system.addAffector(thor::TorqueAffector(100.f));

		emitter.setParticlePosition(window.mapPixelToCoords(sf::Mouse::getPosition(window)));
		emitter.setParticleVelocity(thor::Distributions::rect(sf::Vector2f(0.0f, 0.0f), sf::Vector2f(100.0f, 100.0f)));
		emitter.setEmissionRate(150.0f);
		particle_system.addEmitter(thor::refEmitter(emitter), sf::seconds(2.0f));
	}
	else if (selected_rune == 4)
	{
		// Build color gradient
		thor::ColorGradient gradient;
		gradient[0.f] = sf::Color::Magenta;
		gradient[0.5f] = sf::Color::Green;
		gradient[1.f] = sf::Color::Black;

		// Create color and fade in/out animations
		thor::ColorAnimation colorizer(gradient);
		thor::FadeAnimation fader(0.1f, 0.1f);

		particle_system.clearAffectors();
		// Add particle affectors
		particle_system.addAffector(thor::AnimationAffector(colorizer));
		particle_system.addAffector(thor::AnimationAffector(fader));
		particle_system.addAffector(thor::TorqueAffector(100.f));
		emitter.setParticleVelocity(thor::Distributions::circle(sf::Vector2f(0.0f, 0.0f), 250.0f));
		emitter.setEmissionRate(500.0f);
		particle_system.addEmitter(thor::refEmitter(emitter), sf::seconds(1.0f));
	}
}
Ejemplo n.º 7
0
Archivo: main.cpp Proyecto: LLNL/lbann
//-----------------------------------------------------------------------------
bool test_image_io(const std::string filename,
  const main_params& mp,
  const cropper_params& rp,
  const resizer_params& sp,
  const augmenter_params& ap)
{

  int transform_idx = 0;
  int mean_extractor_idx = -1;
  unsigned int num_bytes = mp.m_num_bytes; // size of image in bytes

  lbann::cv_process pp;
  { // Initialize the image processor
    if (rp.m_is_set) { // If cropper parameters are given
      // Setup a cropper
      std::unique_ptr<lbann::cv_cropper> cropper(new(lbann::cv_cropper));
      cropper->set(rp.m_crop_sz.first, rp.m_crop_sz.second, rp.m_rand_center, rp.m_roi_sz, rp.m_adaptive_interpolation);
      pp.add_transform(std::move(cropper));
      num_bytes = rp.m_crop_sz.first * rp.m_crop_sz.second * 3;
      transform_idx ++;
    }

    if (sp.m_is_set) { // If resizer parameters are given
      // Setup a cropper
      std::unique_ptr<lbann::cv_resizer> resizer(new(lbann::cv_resizer));
      resizer->set(sp.m_width, sp.m_height, rp.m_adaptive_interpolation);
      pp.add_transform(std::move(resizer));
      num_bytes = sp.m_width * sp.m_height * 3;
      transform_idx ++;
    }

    if (ap.m_is_set) { // Set up an augmenter
      std::unique_ptr<lbann::cv_augmenter> augmenter(new(lbann::cv_augmenter));
      augmenter->set(ap.m_hflip, ap.m_vflip, ap.m_rot, ap.m_hshift, ap.m_vshift, ap.m_shear);
      pp.add_transform(std::move(augmenter));
      transform_idx ++;
    }

    if (mp.m_enable_colorizer) { // Set up a colorizer
      std::unique_ptr<lbann::cv_colorizer> colorizer(new(lbann::cv_colorizer));
      pp.add_transform(std::move(colorizer));
      transform_idx ++;
    }

    if (mp.m_enable_decolorizer) { // Set up a colorizer
      std::unique_ptr<lbann::cv_decolorizer> decolorizer(new(lbann::cv_decolorizer));
      pp.add_transform(std::move(decolorizer));
      transform_idx ++;
    }

    if (mp.m_enable_mean_extractor) { // set up a mean extractor
      mean_extractor_idx = transform_idx;
      std::unique_ptr<lbann::cv_mean_extractor> mean_extractor(new(lbann::cv_mean_extractor));
      if (rp.m_is_set)
        mean_extractor->set(rp.m_crop_sz.first, rp.m_crop_sz.second, 3, mp.m_mean_batch_size);
      else
        mean_extractor->set(mp.m_mean_batch_size);
      pp.add_transform(std::move(mean_extractor));
      transform_idx ++;
    }

    if (!mp.is_normalizer_off()) { // Set up a normalizer
      if (mp.is_channel_wise_normalizer()) {
        std::unique_ptr<lbann::cv_normalizer> normalizer(new(lbann::cv_normalizer));
        normalizer->z_score(true);
        pp.add_normalizer(std::move(normalizer));
      } else {
        std::unique_ptr<lbann::cv_subtractor> normalizer(new(lbann::cv_subtractor));
#if 0
        cv::Mat img_to_sub = cv::imread(mp.m_mean_image_name);
        if (img_to_sub.empty()) {
          std::cout << mp.m_mean_image_name << " does not exist" << std::endl;
          return false;
        }
        normalizer->set_mean(img_to_sub);
#else
        std::vector<lbann::DataType> mean = {0.40625, 0.45703, 0.48047};
        normalizer->set_mean(mean);
        std::vector<lbann::DataType> stddev = {0.3, 0.5, 0.3};
        normalizer->set_stddev(stddev);
#endif
        pp.add_normalizer(std::move(normalizer));
      }
      transform_idx ++;
    }
  }

  // Load an image bytestream into memory
  std::vector<unsigned char> buf;
  bool ok = lbann::load_file(filename, buf);
  if (!ok) {
    std::cout << "Failed to load" << std::endl;
    return false;
  }

  int width = 0;
  int height = 0;
  int type = 0;

  ::Mat Images;
  ::Mat Image_v; // matrix view
  Images.Resize(((num_bytes==0)? 1: num_bytes), 2); // minibatch

  size_t img_begin = 0;
  size_t img_end = buf.size();
  for (unsigned int i=0; i < mp.m_num_iter; ++i)
  {
    // This has nothing to do with the image type but only to create view on a block of bytes
    using InputBuf_T = lbann::cv_image_type<uint8_t>;
    // Construct a zero copying view to a portion of a preloaded data buffer
    const cv::Mat inbuf(1, (img_end - img_begin), InputBuf_T::T(1), &(buf[img_begin]));

    if (num_bytes == 0) {
      ok = lbann::image_utils::import_image(inbuf, width, height, type, pp, Images);
      num_bytes = Images.Height();
      El::View(Image_v, Images, El::IR(0, num_bytes), El::IR(0, 1));
    } else {
      El::View(Image_v, Images, El::IR(0, num_bytes), El::IR(0, 1));
      //ok = lbann::image_utils::import_image(buf, width, height, type, pp, Image_v);
      ok = lbann::image_utils::import_image(inbuf, width, height, type, pp, Image_v);
    }
    if (!ok) {
      std::cout << "Failed to import" << std::endl;
      return false;
    }
    //if ((i%3 == 0u) && (mp.m_enable_mean_extractor)) {
    //  dynamic_cast<lbann::cv_mean_extractor*>(pp.get_transform(mean_extractor_idx))->reset();
    //}
  }

  // Print out transforms
  const unsigned int num_transforms = pp.get_num_transforms();
  const std::vector<std::unique_ptr<lbann::cv_transform> >& transforms = pp.get_transforms();

  for(unsigned int i=0u; i < num_transforms; ++i) {
    std::cout << std::endl << "------------ transform " << i << "-------------" << std::endl;
    std::cout << *transforms[i] << std::endl;
  }

  if (mp.m_enable_mean_extractor) {
    // Extract the mean of images
    cv::Mat mean_image;
    mean_image = dynamic_cast<lbann::cv_mean_extractor*>(pp.get_transform(mean_extractor_idx))->extract<uint16_t>();
    cv::imwrite("mean.png", mean_image);
  }

  // Export the unnormalized image
  const std::string ext = lbann::get_ext_name(filename);
  std::vector<unsigned char> outbuf;
  ok = lbann::image_utils::export_image(ext, outbuf, width, height, type, pp, Image_v);
  write_file("copy." + ext, outbuf);
  return ok;
}
void loadingScreen()
{
    sf::Clock timer;
    sf::Sprite SFMLlogo;
    sf::Texture SFMLlogoT;

    SFMLlogoT.loadFromFile(workingDirectory + "assets/graphics/UI/mainMenu/sfLogo.png");

    SFMLlogo.setTexture(SFMLlogoT);
    SFMLlogo.setPosition(screenCornerX + 10, screenCornerY + screenY - 100);

    while(timer.getElapsedTime().asSeconds() < 1.f)
    {
        app << sf::Color(0, 0, 0);

        if(timer.getElapsedTime().asSeconds() < 1.f)
            SFMLlogo.setColor(sf::Color(255, 255, 255, (timer.getElapsedTime().asSeconds() / 1.f) * 255));

        app << SFMLlogo;
        app.display();
    }

    cout << "-----Loading screen (" << date() << ")-----" << endl;

    cout << "Loading settings... ";
    settings.load();
    cout << "[OK]" << endl;

    cout << "Setting framerate controller... ";
    app.setVerticalSyncEnabled(false);

    string FPScontroller = settings.FPScontroller;
    if(FPScontroller == "v-sync")
    {
        app.setVerticalSyncEnabled(true);
        cout << "(v-sync) [OK]" << endl;
    }
    else if(FPScontroller == "custom")
    {
        app.setFramerateLimit(settings.FPSlimit);
        cout << "(custom: " << settings.FPSlimit << ") [OK]" << endl;
    }
    else if(FPScontroller == "none")
    {
        cout << "(none) it can cause screen tearing etc. [WARNING]" << endl;
    }
    else
    {
        cout << "ERROR: unknown controller, using \"v-sync\" [fail]" << endl;
        app.setVerticalSyncEnabled(true);
    }

    cout << "Loading sounds... ";
    app.soundsManager.init(settings);

    string weaponSounds[] = {"autoRockets", "autoTurret", "enemyStandard", "laser", "minigun", "saw", "shotgun", "standard"};
    for(int i = 0; i < 8; i++)
        app.soundsManager.loadFromFile("assets/sounds/weapons/" + weaponSounds[i] + "/shot.flac", weaponSounds[i] + "/shot", 30);

    app.soundsManager.loadFromFile("assets/sounds/music.wav", "russianMusic", 50);
    app.soundsManager.createMusic(app.soundsManager.getIdByName("russianMusic"));
    cout << "[OK]" << endl;

    cout << "Loading animations... ";
    xml::xmlDocument doc(workingDirectory + "assets/xml/animations.xml");
    xml_node<> *node = doc.getRootNode();
    node = node -> first_node();

    while(node != NULL)
    {
        loadAnimationTextures(workingDirectory + xml::getNodeAttribute(node, "file"));
        node = node -> next_sibling();
    }
    cout << "[OK]" << endl;

    cout << "Loading languages... ";
    languageManager.loadFromFile("assets/languages/default.lang");
    cout << "[OK]" << endl;

    cout << "Loading graphics... ";
    textureManagerInit();

    cout << "Loading some graphics... ";
    textureManager.add("assets/graphics/UI/game/info.png", "game/info.png");
    textureManager.add("assets/graphics/UI/game/HPbar.png", "game/HPbar.png");
    textureManager.add("assets/graphics/UI/game/symbol1.png", "symbol1", true);
    textureManager.add("assets/graphics/UI/game/symbol2.png", "symbol2", true);
    textureManager.add("assets/graphics/UI/game/symbol3.png", "symbol3", true);
    textureManager.add("assets/graphics/UI/game/ammoBar.png", "game/ammoBar.png");
    textureManager.add("assets/graphics/UI/game/arrow.png", "game/arrow.png", true);
    textureManager.add("assets/graphics/UI/game/noAmmoBar.png", "game/noAmmoBar.png");
    textureManager.add("assets/graphics/bullets/saw/fly/texture.png", "n***a", true);
    textureManager.add("assets/graphics/UI/game/shieldBar.png", "game/shieldBar.png");
    textureManager.add("assets/graphics/UI/game/RegainingShieldBar.png", "game/RegainingShieldBar.png");

    for(int i = 0; i < 3; i++)
        symbols[i].setTexture(textureManager.get("symbol" + toString(i + 1)));

    bitFont.loadFromFile(workingDirectory + "assets/fonts/BitFont.ttf");
    cout << "[OK]" << endl;

    cout << "Creating particle systems... ";
    pSystems::soulsParticles.setTexture(textureManager.get("game/soul.png"));
    thor::ColorGradient gradient;
	gradient[0.f] = sf::Color(255, 255, 255, 255);
	gradient[1.f] = sf::Color(255, 255, 255, 0);
    thor::ColorAnimation colorizer(gradient);
    pSystems::soulsParticles.addAffector(thor::AnimationAffector(colorizer));
    pSystems::soulsParticles.addAffector(blackHoleAffector);
    pSystems::soulsParticles.addAffector(bulletAffector);
    cout << "[OK]" << endl;

    while(timer.getElapsedTime().asSeconds() < 2.f){}
}
Ejemplo n.º 9
0
int main()
{
	// Create window
	sf::RenderWindow window(sf::VideoMode(800, 600), "Thor Particles");
	
	// Load texture
	sf::Texture texture;
	if (!texture.loadFromFile("Media/particle.png"))
		return EXIT_FAILURE;
	
	// Create emitter
	thor::UniversalEmitter::Ptr emitter = thor::UniversalEmitter::create();
	emitter->setEmissionRate(30.f);
	emitter->setParticleLifetime(sf::seconds(5.f));

	// Create particle system
	thor::ParticleSystem system(texture);
	system.addEmitter(emitter);

	// Build color gradient (green -> teal -> blue)
	thor::ColorGradient gradient;
	gradient[0.f] = sf::Color(0, 150, 0);
	gradient[0.5f] = sf::Color(0, 150, 100);
	gradient[1.f] = sf::Color(0, 0, 150);

	// Create color and fade in/out animations
	thor::ColorAnimation colorizer(gradient);
	thor::FadeAnimation fader(0.1f, 0.1f);

	// Add particle affectors
	system.addAffector( thor::AnimationAffector::create(colorizer) );
	system.addAffector( thor::AnimationAffector::create(fader) );
	system.addAffector( thor::TorqueAffector::create(100.f) );
	system.addAffector( thor::ForceAffector::create(sf::Vector2f(0.f, 100.f))  );

	// Attributes that influence emitter
	thor::PolarVector2f velocity(200.f, -90.f);
	bool paused = false;

	sf::Font font;
	if (!font.loadFromFile("Media/sansation.ttf"))
		return 1;

	// Instruction text
	sf::Text instructions(
		"Left click: Pause\n"
		"Mouse wheel: Change direction\n",
		font, 12);

	// Create clock to measure frame time
	sf::Clock frameClock;

	// Main loop
	for (;;)
	{
		// Handle events
		sf::Event event;
		while (window.pollEvent(event))
		{
			switch (event.type)
			{
				// [X]: Quit
				case sf::Event::Closed:
					return 0;
					
				// Escape: Quit
				case sf::Event::KeyPressed:
					if (event.key.code == sf::Keyboard::Escape)
						return 0;

				// Left mouse button: Enable/disable glow
				case sf::Event::MouseButtonPressed:
					if (event.mouseButton.button == sf::Mouse::Left)
						paused = !paused;
					break;

				// Mouse wheel: Change emission direction
				case sf::Event::MouseWheelMoved:
					velocity.phi += 12.f * event.mouseWheel.delta;
					break;
			}
		}
		
		// Update particle system and emitter
		const sf::Time frameTime = frameClock.restart();
		if (!paused)
			system.update(frameTime);

		// Set initial particle position and velocity, rotate vector randomly by maximal 10 degrees
		emitter->setParticlePosition( window.mapPixelToCoords(sf::Mouse::getPosition(window)) );
		emitter->setParticleVelocity( thor::Distributions::deflect(velocity, 10.f) );

		// Draw everything
		window.clear(sf::Color(30, 30, 30));
		window.draw(instructions);
		window.draw(system);
		window.display();
	}
}
Ejemplo n.º 10
0
void Highlighter::runWrapped()
{
	#if PTE_DEBUG_HIGHLIGHTING
	print("Highlighter::run().0\n");
	#endif
	
	Ref<Token, Owner> rootToken0 = 0;
	
	while (true)
	{
		#if PTE_PROFILE_HIGHLIGHTING
		stages_ = -2;
		#endif
		
		restart_->acquireAll();
		if (shutdown_->tryAcquire()) break;
		
		if (rootToken0) {
			#if PTE_PROFILE_HIGHLIGHTING
			stages_ = -1;
			#endif
			
			// force tree destruction at this point
			// (reducing heap utilization a little bit and making tree destruction a little bit more
			//  deterministic (although leafs aren't destroyed at this point;))
			rootToken0 = 0;
			
			if (restart_->tryAcquire()) {
				restart_->release();
				continue;
			}
		}
		
		#if PTE_PROFILE_HIGHLIGHTING
		stages_ = 0;
		#endif
		#if PTE_DEBUG_HIGHLIGHTING
		print("Highlighter::run().1\n");
		#endif
		
		bool restartRequested = false;
		
		for (int depth = 0; depth < languageStack_->numLayers(); ++depth)
		{
			Ref<LanguageLayer> languageLayer = languageStack_->layer(depth);
			
			#if PTE_DEBUG_HIGHLIGHTING
			print("Highlighter::run(): depth = %%\n", depth);
			#endif
			
			access_->acquire();
			SequenceAdapter source(document_);
			Ref<Token, Owner> rootToken1 = languageLayer->syntax()->match(&source);
			if (rootToken1) {
				// extent match range if incomplete match
				if (source.has(rootToken1->i1())) {
					// print("Highlighter::highlight(): Incomplete match: rootToken1->i1() = %%\n", rootToken1->i1());
					int i1 = rootToken1->i1();
					while (source.has(i1)) ++i1;
					rootToken1->setRange(rootToken1->i0(), i1);
				}
				else {
					/*print("Highlighter::highlight(): rootToken1->countChildren() = %%\n", rootToken1->countChildren());
					print("Highlighter::highlight(): rootToken1->rule() = %%\n", rootToken1->rule());*/
				}
			}
			access_->release();
			
			if (restart_->tryAcquire()) {
				restart_->release();
				restartRequested = true;
				break;
			}
			
			if (depth > 0)
				Token::meld(rootToken1, rootToken0);
			rootToken0 = rootToken1;
		}
		if (restartRequested)
			continue;
		
		#if PTE_DEBUG_HIGHLIGHTING
		print("Highlighter::run().3: document_->filePath() = %%\n", document_->filePath().toUtf8().data());
		#endif
		#if PTE_PROFILE_HIGHLIGHTING
		stages_ = 3;
		#endif
		
		if (rootToken0) {
			bool needUpdate = false;
			
			// print("Highlighter::run().3.1: rootToken0->i0(), rootToken0->i1() = %%, %%\n", rootToken0->i0(), rootToken0->i1());
			Mutex& mutex = localStatic<Mutex, Highlighter>();
			Guard<Mutex> guard(&mutex); // workaround hack, protects against unresolved race conditions
			access_->acquire();
			// print("Highlighter::run().3.2\n");;
			DocumentColorizer colorizer(languageStack_, document_);
			rootToken0->glow(&colorizer);
			needUpdate = colorizer.needUpdate();
			// print("Highlighter::run().3.3\n");
			access_->release();
			
			if (restart_->tryAcquire()) {
				restart_->release();
				continue;
			}
			
			#if PTE_DEBUG_HIGHLIGHTING
			print("Highlighter::run().4\n");
			#endif
			#if PTE_PROFILE_HIGHLIGHTING
			stages_ = 4;
			#endif
			
			if (needUpdate)
				emit ready();
			
			#if PTE_DEBUG_HIGHLIGHTING
			print("Highlighter::run().5\n");
			#endif
			#if PTE_PROFILE_HIGHLIGHTING
			stages_ = 5;
			#endif
			
			syncMutex_->acquire();
			sync_->broadcast();
			syncMutex_->release();
			
			#if PTE_DEBUG_HIGHLIGHTING
			print("Highlighter::run().s\n");
			#endif
			#if PTE_PROFILE_HIGHLIGHTING
			stages_ = 6;
			#endif
		}
	}
	
	#if PTE_DEBUG_HIGHLIGHTING
	print("Highlighter::run().e: %%\n", (void*)this);
	#endif
}