Exemple #1
0
Handler<Sprite> SpriteManager::queryRawSprite(ImageFormat const format, const int width, const int height)
{
	typedef chisa::gl::internal::WidthOrder<Sprite> SpriteOrder;
	auto it = std::lower_bound(this->unusedSprite_.begin(), this->unusedSprite_.end(),
			std::tuple<ImageFormat, int,int>(format, width, height), Sprite::CompareByTexture());
	//横幅が同じ場合は、縦幅も大きいか同じであることが保証される。
	//横幅が優先なので、横幅が違う場合は高さは短いかもしれない
	if(it == this->unusedSprite_.end() || (*it)->texture().format() != format || (*it)->texture().height() < height || (*it)->texture().width() < width) {
		Handler<Sprite> spr ( new Sprite(this, format, geom::IntBox(width, height)) );
		spr->resize(width, height);
		return spr;
	}else{
		Handler<Sprite> spr(*it);
		this->unusedSprite_.erase(it);
		spr->resize(width, height);
		return spr;
	}
}