gs2d::str_type::string ETHSpriteDensityManager::ChooseSpriteVersion(const gs2d::str_type::string& fullFilePath,
										   const gs2d::VideoPtr& video, ETHSpriteDensityManager::DENSITY_LEVEL& densityLevel)
{
	const Platform::FileManagerPtr fileManager = video->GetFileManager();
	const bool shouldUseFullHdResources = ShouldUseFullHdResources(video);
	if (shouldUseFullHdResources)
	{
		const string fullHdVersionFileName(AssembleResourceName(fullFilePath, FULL_HD_VERSION_PATH_NAME));
		if (fileManager->FileExists(fullHdVersionFileName))
		{
			densityLevel = ETHSpriteDensityManager::FULL_HD;
			return fullHdVersionFileName;
		}
	}

	if (ShouldUseHdResources(video) || shouldUseFullHdResources)
	{
		const string hdVersionFileName(AssembleResourceName(fullFilePath, HD_VERSION_PATH_NAME));
		if (fileManager->FileExists(hdVersionFileName))
		{
			densityLevel = ETHSpriteDensityManager::HD;
			return hdVersionFileName;
		}
	}

	densityLevel = ETHSpriteDensityManager::DEFAULT;
	return fullFilePath;
}
예제 #2
0
void ZombieManager::AddZombies(gs2d::VideoPtr video, SpriteResourceManager& spr)
{
	if (m_zombies.size() < MAX_ZOMBIES)
	{
		if (video->GetElapsedTime() - m_lastAddTime > ZOMBIE_ADD_INTERVAL)
		{
			const Vector2 spawnPos = m_normalizedSpawnSpots[GetNextSpawnSpot()] * video->GetScreenSizeF();

			str_type::string spriteName = m_spriteNames[Randomizer::Int(m_spriteNames.size()-1)];
			ZombiePtr newZombie = ZombiePtr(new Zombie(video, spawnPos, spriteName));
			newZombie->FillSpritePtr(spr, video);
			m_zombies.push_back(newZombie);
			m_lastAddTime = video->GetElapsedTime();
		}
	}
}
ETHBackBufferTargetManager::ETHBackBufferTargetManager(gs2d::VideoPtr video, const ETHAppEnmlFile& file, const Platform::Logger& logger)
{
	const gs2d::str_type::string fixedWidth  = file.GetFixedWidth();
	const gs2d::str_type::string fixedHeight = file.GetFixedHeight();
	if (!ComputeLength(video, fixedWidth, fixedHeight, true))
	{
		ComputeLength(video, fixedHeight, fixedWidth, false);
	}
	const gs2d::math::Vector2 screenSize(video->GetScreenSizeF());
	m_bufferSize.x = gs2d::math::Min(screenSize.x, m_bufferSize.x);
	m_bufferSize.y = gs2d::math::Min(screenSize.y, m_bufferSize.y);

	gs2d::str_type::stringstream ss; ss << GS_L("Backbuffer created as ") << m_bufferSize.x << GS_L(", ") << m_bufferSize.y
										<< GS_L(" on ");
	if (m_bufferSize == screenSize)
	{
		m_backBuffer = ETHDynamicBackBufferPtr(new ETHNoDynamicBackBuffer(video, m_bufferSize));
		ss << GS_L("default backbuffer mode");
	}
	else
	{
		m_backBuffer = ETHDynamicBackBufferPtr(new ETHDefaultDynamicBackBuffer(video, m_bufferSize));
		ss << GS_L("dynamic framebuffer mode");
	}
	m_targetScale = m_bufferSize.x / screenSize.x;

	CreateOBB();

	logger.Log(ss.str(), Platform::Logger::INFO);
}
bool ETHBackBufferTargetManager::ComputeLength(gs2d::VideoPtr video, const gs2d::str_type::string& thisSide, const gs2d::str_type::string& otherSide, const bool isWidth)
{
	if (IsAuto(thisSide))
	{
		const gs2d::math::Vector2 screenSize(video->GetScreenSizeF());
		if (IsAuto(otherSide))
		{
			m_bufferSize = screenSize;
			return true;
		}
		else
		{
			float otherValue = -1.0f;
			ENML_SSCANF(otherSide.c_str(), GS_L("%f"), &otherValue);
			if (isWidth)
				m_bufferSize.x = ceilf(otherValue * (screenSize.x / screenSize.y));
			else
				m_bufferSize.y = ceilf(otherValue * (screenSize.y / screenSize.x));
			return false;
		}
	}
	else
	{
		int value = -1;
		ENML_SSCANF(thisSide.c_str(), GS_L("%i"), &value);
		if (isWidth)
			m_bufferSize.x = static_cast<float>(value);
		else
			m_bufferSize.y = static_cast<float>(value);
		return false;
	}
}
ETHBackBufferTargetManager::ETHBackBufferTargetManager(gs2d::VideoPtr video)
{
	m_bufferSize = video->GetScreenSizeF();
	m_backBuffer = ETHDynamicBackBufferPtr(new ETHNoDynamicBackBuffer(video, m_bufferSize));
	m_targetScale = 1.0f;
	CreateOBB();
}
ETHBackBufferTargetManagerPtr ETHBackBufferTargetManager::Create(gs2d::VideoPtr video,
																 const ETHAppEnmlFile& file, const Platform::Logger& logger,
																 ETHInput& ethInput)
{
	ETHBackBufferTargetManagerPtr r(new ETHBackBufferTargetManager(video, file, logger));
	video->SetScreenSizeChangeListener(r);
	ethInput.SetTargetManager(r);
	return r;
}
ETHBackBufferTargetManager::ETHBackBufferTargetManager(gs2d::VideoPtr video, const gs2d::enml::File& file, const Platform::Logger& logger)
{
	const gs2d::str_type::string fixedWidth  = file.get(GS_L("window"), GS_L("fixedWidth"));
	const gs2d::str_type::string fixedHeight = file.get(GS_L("window"), GS_L("fixedHeight"));
	if (!ComputeLength(video, fixedWidth, fixedHeight, true))
	{
		ComputeLength(video, fixedHeight, fixedWidth, false);
	}
	const gs2d::math::Vector2 screenSize(video->GetScreenSizeF());
	m_bufferSize.x = gs2d::math::Min(screenSize.x, m_bufferSize.x);
	m_bufferSize.y = gs2d::math::Min(screenSize.y, m_bufferSize.y);

	m_backBuffer = (m_bufferSize == screenSize) ? 
					ETHDynamicBackBufferPtr(new ETHNoDynamicBackBuffer(video, m_bufferSize)) :
					ETHDynamicBackBufferPtr(new ETHDefaultDynamicBackBuffer(video, m_bufferSize));
	m_targetScale = m_bufferSize.x / screenSize.x;

	gs2d::str_type::stringstream ss; ss << GS_L("Backbuffer created as ") << m_bufferSize.x << GS_L(", ") << m_bufferSize.y;
	logger.Log(ss.str(), Platform::Logger::INFO);
}
bool ETHSpriteDensityManager::ShouldUseFullHdResources(const gs2d::VideoPtr& video) const
{
	return (video->GetScreenSize().y >= static_cast<int>(minScreenHeightForFullHdResources));
}
ETHDefaultDynamicBackBuffer::ETHDefaultDynamicBackBuffer(const gs2d::VideoPtr& video, const gs2d::math::Vector2& size) :
	m_video(video)
{
	m_target = video->CreateRenderTarget(static_cast<unsigned int>(size.x), static_cast<unsigned int>(size.y), gs2d::Texture::TF_DEFAULT);
}
ETHBackBufferTargetManagerPtr ETHBackBufferTargetManager::Create(gs2d::VideoPtr video)
{
	ETHBackBufferTargetManagerPtr r(new ETHBackBufferTargetManager(video));
	video->SetScreenSizeChangeListener(r);
	return r;
}