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, 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);
}
ETHBackBufferTargetManager::ETHBackBufferTargetManager(gs2d::VideoPtr video)
{
	m_bufferSize = video->GetScreenSizeF();
	m_backBuffer = ETHDynamicBackBufferPtr(new ETHNoDynamicBackBuffer(video, m_bufferSize));
	m_targetScale = 1.0f;
	CreateOBB();
}
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 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);
}