Esempio n. 1
0
void RenderThread::run()
{
  DEBUGOUT << "RenderThread for" << renderMe << "started";
  QImage renderImage = RenderUtils::renderPagePart(m_page.page, renderMe.requestedPageSize(), renderMe.pagePart());
  if ( renderImage.isNull() )
  {
    qWarning() << "RenderThread for" << renderMe << "failed";
    QSharedPointer<RenderingIdentifier> ri( new RenderingIdentifier(renderMe) );
    emit renderingFailed(ri);
    return;
  }

  QList< AdjustedLink > links;

  for( Poppler::Link* link: m_page.page->links() )
  {
    QSharedPointer<Poppler::Link> ptrLink(link);
    try{
      AdjustedLink al(renderMe, ptrLink);
      links.append(al);
    } catch( AdjustedLink::OutsidePage & e) {
      // no-op
    }
  }
  QSharedPointer<RenderedPage> renderResult(new RenderedPage( renderImage, links, renderMe ));
  DEBUGOUT << "RenderThread for" << renderMe << "successful, image has size" << renderResult->getImage().size();
  emit renderingFinished(renderResult);
}
Esempio n. 2
0
void Main()
{
	ResourceLoader resources;

	auto sampler = SamplerState(SamplerState::Default2D);
	sampler.filter = TextureFilter::MinMagMipPoint;
	Graphics2D::SetSamplerState(sampler);

	Window::Resize(320 * 2, 240 * 2);
	Window::SetTitle(L"まちへかえろう(仮)");

	Array<HurdleObject> hurdles;
	Array<BuildingLayer> buildingLayers;
	Array<BuildingLayer2> buildingLayers2;

	Map::instance().init(40, 15);

	for (int i = 0; i < 40; i++)
	{
		Map::instance().set(i, 14, 5);
		Map::instance().set(i, 13, 5);
		Map::instance().set(i, 12, 4);
		Map::instance().set(i, 11, 3);
		Map::instance().set(i, 10, 3);
		Map::instance().set(i, 9, 2);
		Map::instance().set(i, 8, 1);
	}
	auto viewLeft = 0.0;
	auto mycharDead = false;
	ScreenState currentState = ScreenState::InTitle, prevState = currentState;
	bool prevSpacePressed = false;

	auto TitleTimer = TimerMillisec();

	ScriptEngine asEngine;
	asEngine.RegisterMethod(L"int getAt(double x, double y)", &Map::getAt, Map::instance());
	asEngine.RegisterProperty(L"double _viewX", &viewLeft);
	asEngine.RegisterProperty(L"bool _isGameOvered", &mycharDead);
	asEngine.RegisterFunction(L"void playJumpSound()", PlayJumpSound);
	auto context_mychar = asEngine.CreateContextFromScript(L"res/scripts/Mychar.as");

	Record::instance().init();

	int fc = 0;
	while (System::Update())
	{
		bool spacePressedInFrame = !prevSpacePressed && Input::KeySpace.pressed;
		prevSpacePressed = Input::KeySpace.pressed;

		asEngine.setFrameCount(fc);

		switch (currentState)
		{
		case ScreenState::InTitle:
			if (!TitleTimer.isActive) TitleTimer.start();
			renderBackgrounds(viewLeft, resources);
			renderBuildingLayers(buildingLayers, buildingLayers2, resources);
			renderMap(viewLeft, resources);
			renderTitle(TitleTimer.elapsed(), resources);
			renderCurrentMax();

			if (spacePressedInFrame)
			{
				// GameInit
				SoundAsset(SoundResourceLoader::decide).play();
				viewLeft = 0.0;
				mycharDead = false;
				context_mychar.Reenter();
				buildingLayers.clear();
				buildingLayers2.clear();
				hurdles.clear();
				currentState = ScreenState::Gaming;
			}
			break;
		case ScreenState::Gaming:
			// appear hurdles at random
			if (RandomBool(0.02))
			{
				if (hurdles.empty() || hurdles.back().getPos().x - (viewLeft + 320.0f) < -48.0f)
				{
					// allocate space least 48 logical-pixels
					hurdles.emplace_back(HurdleObject(Vec2(viewLeft + 320.0f, 8.0f * 16.0f + 8.0f)));
				}
			}
			// appear building at random
			if (RandomBool(0.02 / 30.0))
			{
				if (buildingLayers.empty() || buildingLayers.back().getPos().x < 0.0f)
				{
					buildingLayers.emplace_back(BuildingLayer(Vec2(320.0f, -60.0f)));
				}
			}
			if (RandomBool(0.01 / 30.0))
			{
				if (buildingLayers2.empty() || buildingLayers2.back().getPos().x < 0.0f)
				{
					buildingLayers2.emplace_back(BuildingLayer2(Vec2(320.0f, -60.0f)));
				}
			}

			asEngine.setFrameCount(fc);
			context_mychar.Execute();

			renderBackgrounds(viewLeft, resources);
			renderBuildingLayers(buildingLayers, buildingLayers2, resources);
			renderMap(viewLeft, resources);
			if (renderHurdlesAndHitTest(viewLeft, context_mychar.GetGlobalDoubleVec2(L"x", L"y"), hurdles, resources))
			{
				if (!mycharDead) SoundAsset(SoundResourceLoader::died).play();
				mycharDead = true;
			}
			renderPlayer(viewLeft, context_mychar.GetGlobalDouble(L"angle"), context_mychar.GetGlobalDoubleVec2(L"x", L"y"), resources);
			renderInfo(toScore(context_mychar.GetGlobalDouble(L"x")));

			// Host Processes
			if (mycharDead && context_mychar.GetGlobalDouble(L"x") < viewLeft - 120.0f)
			{
				// update record
				Record::instance().recordScore(toScore(context_mychar.GetGlobalDouble(L"x")));
				currentState = ScreenState::Result;
			}
			break;
		case ScreenState::Result:
			renderBackgrounds(viewLeft, resources);
			renderBuildingLayers(buildingLayers, buildingLayers2, resources);
			renderMap(viewLeft, resources);
			renderHurdlesAndHitTest(viewLeft, context_mychar.GetGlobalDoubleVec2(L"x", L"y"), hurdles, resources);
			renderResult(toScore(context_mychar.GetGlobalDouble(L"x")), Record::instance().isUpdated(), fc);

			if (spacePressedInFrame)
			{
				// GameInit
				SoundAsset(SoundResourceLoader::decide).play();
				TitleTimer.reset();
				currentState = ScreenState::InTitle;
			}
			break;
		}
		if (prevState != currentState)
		{
			fc = 0;
		}
		prevState = currentState;

		// Common Postprocesses
		fc++;
		viewLeft += 2.5f;
	}

	Map::instance().clean();
}