当前位置: 首页>>代码示例>>C++>>正文


C++ Chunk::CreateImage方法代码示例

本文整理汇总了C++中Chunk::CreateImage方法的典型用法代码示例。如果您正苦于以下问题:C++ Chunk::CreateImage方法的具体用法?C++ Chunk::CreateImage怎么用?C++ Chunk::CreateImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Chunk的用法示例。


在下文中一共展示了Chunk::CreateImage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

// Working thread for the pool
ThreadResult * ThreadPoolWork(ThreadOrder * order)
{
	ThreadString * next = (ThreadString *)order;
	ChunkPrefs prefs = next->prefs;
	Chunk * chunk = next->chunk;
	chunk->pref = prefs;
	// Alpha
	if (prefs.version == ALPHA)
	{
		chunk->Load(next->file);
	}
	// Beta
	else if (prefs.version == BETA)
	{
		chunk->Load((BYTE *)next->file.c_str(), next->file.size());
	}
	if (chunk->isValid())
	{
		chunk->CreateImage();
		return (ThreadResult *)1;
	}
	return (ThreadResult *)0;
}
开发者ID:McTwist,项目名称:PixelMap,代码行数:24,代码来源:Level.cpp

示例2: CreateImage

// Create image saved in file
int Level::CreateImage(const STRING & file)
{
	if (cancel)
		return LVL_ERR_CANCEL;
	state = CREATEIMAGE;
	if (chunks.empty())
		return LVL_ERR_NOCHUNKS;
	INT64 minX = MAPCOORD;
	INT64 minY = MAPCOORD;
	INT64 maxX = -MAPCOORD;
	INT64 maxY = -MAPCOORD;

	blocks = chunks.size() << 8;
	bool doRender = !(prefs.flags & CHUNKP_NORENDER);

	// Calculate size
	for (list<Chunk *>::iterator i = chunks.begin(); i != chunks.end(); ++i)
	{
		Chunk * chunk = (*i);
		if (!chunk->isValid())
			continue;
		if (doRender)
		{
			COORDS x = chunk->GetX();
			COORDS y = chunk->GetY();
			if (x < minX)
				minX = x;
			if (y < minY)
				minY = y;
			if (x > maxX)
				maxX = x;
			if (y > maxY)
				maxY = y;
		}

		// And add to amount while we are processing
		amount += chunk->amount;
	}

	if (cancel)
		return LVL_ERR_CANCEL;

	if (doRender)
	{
		// No valid chunks?
		if (minX == MAPCOORD && minY == MAPCOORD &&
			maxX == -MAPCOORD && maxY == -MAPCOORD)
			return LVL_ERR_INVALIDCHUNKS;

		prefs.rotation = abs((prefs.rotation / 90) * 90) % 360;
		float rad = (2 * 3.14159265f * prefs.rotation) / 360;

		UINT
			maxWidth = (UINT)(maxX - minX),
			maxHeight = (UINT)(maxY - minY);

		UINT
			width = (maxWidth + 1) * MAPX, 
			height = (maxHeight + 1) * MAPY;

		// Foolproof
		if (width == 0 || height == 0)
			return LVL_ERR_INVALIDSIZE;

		// Rotate
		{
			float rCos = cos(rad);
			float rSin = sin(rad);
			rCos = (rCos < 0) ? -rCos : rCos;
			rSin = (rSin < 0) ? -rSin : rSin;
			UINT newWidth = UINT(width * rCos + height * rSin);
			UINT newHeight = UINT(height * rCos + width * rSin);
			width = newWidth;
			height = newHeight;
		}

		// Foolproof
		if (width == 0 || height == 0)
			return LVL_ERR_INVALIDSIZE;

		bool useCache = !prefs.cache.empty();
		ImageCache cache(height, width);
		Image * image = 0;

		if (!useCache)
		{
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
			// No more than 1 GiB
			if (width * height * sizeof(Color) > min(1073741824, Computer::GetAvailableMemory()))
				return LVL_ERR_TOOLARGE;
			try
			{
				image = new Image(height, width);
				if (image == 0)
					throw LVL_ERR_TOOLARGE;
			}
			catch (Level_Error error)
//.........这里部分代码省略.........
开发者ID:McTwist,项目名称:PixelMap,代码行数:101,代码来源:Level.cpp

示例3: LoadSingle

// Load singlethreaded
void Level::LoadSingle()
{
	// Go through all files
	Chunk * temp = 0;
	while (files.empty() == false && cancel == false)
	{
		if (prefs.version == ALPHA)
		{
			temp = new Chunk();
			// Load chunk
			temp->pref = prefs;
			temp->Load(files.top());
			files.pop();
			// Everything is fine
			if (temp->isValid())
			{
				temp->CreateImage();
				chunks.push_back(temp);
			}
			else
			{
				// Display correct total chunks
				--total;
				// Evade memory leak
				delete temp;
			}
			// Do some aftermath
			result = chunks.size();
			work = total - result;
			done = ((float)result/(float)total);
		}
		else if (prefs.version == BETA)
		{
			RegionReader region = RegionReader();
			region.Load(files.top());
			files.pop();
			// Reduce amount
			total -= 1024 - region.GetAmountChunks();
			// Go through region
			for (int i = 0; i < region.GetAmountChunks() && cancel == false; ++i)
			{
				temp = new Chunk();
				// Load chunk
				temp->pref = prefs;
				UINT size = 0;
				BYTE * data = region.GetChunk(i, size);
				temp->Load(data, size);
				// Everything is fine
				if (temp->isValid())
				{
					temp->CreateImage();
					chunks.push_back(temp);
				}
				else
				{
					// Display correct total chunks
					--total;
					// Evade memory leak
					delete temp;
				}
				// Do some aftermath
				result = chunks.size();
				work = total - result;
				done = ((float)result/(float)total);
			}
		}
	}
}
开发者ID:McTwist,项目名称:PixelMap,代码行数:69,代码来源:Level.cpp


注:本文中的Chunk::CreateImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。