コード例 #1
0
ファイル: JMBrkr.cpp プロジェクト: jimmccurdy/ArchiveGit
//================================================
// LaunchOptimizationWizard
//================================================
BOOL CJMBrkr::LaunchOptimizationWizard()
{
	COptimizeDlg dlgOptimize;
	dlgOptimize.DoModal();

	return true;
}
コード例 #2
0
ファイル: mainfrm.cpp プロジェクト: midasdas/psdl-editor
LRESULT CMainFrame::OnOptimizePSDL(WORD, WORD, HWND, BOOL&)
{
	psdl *pPSDL = m_psdlDoc.GetDocument();

	unsigned long i, j, nVertices = pPSDL->_vertices.size();
	unsigned long* vertexRemap = new unsigned long[nVertices];
	unsigned long nRemaining = nVertices;

	for (i = 0; i < nVertices; ++i)
	{
		j = i;
		vertexRemap[i] = j;
	}

	for (i = 0; i < nVertices; ++i)
	{
		for (j = 0; j < nVertices; ++j)
		{
			if (i != j && vertexRemap[j] == j && pPSDL->get_vertex(i)->Match(*pPSDL->get_vertex(j)))
			{
				vertexRemap[j] = i;
				--nRemaining;
			}
		}
	}

	delete[] vertexRemap;

	ATLTRACE("Vertex count reduced from %u to %u\n", nVertices, nRemaining);
	return 0;

	COptimizeDlg dlg;

	if (IDOK == dlg.DoModal())
	{
/*		if (g_optimizeProps.bTextureRefs)
		{
		//	vector<vertexMap> textureMap[3];
			vector<std::string> newTexList;

			for (size_t i = 0; i < m_psdlDoc.NumBlocks(); i++)
			{
				psdl::block* pBlock = m_psdlDoc.GetBlock(i);

			//	if (pBlock->num_attributes() < 1) continue;

				vector<psdl::attribute*>::iterator it = pBlock->_attributes.begin();

				while (it != pBlock->_attributes.end())
				{
					unsigned char nAtbType = (*it)->type;

					if (nAtbType == ATB_TEXTURE)
					{
						if (it == pBlock->_attributes.end() - 1 ||
							*(it+1) && (*(it+1))->type == nAtbType)
						{
							it = pBlock->_attributes.erase(it);
						}
						else
							++it;

					// WRONG !!
					//	if (nLastTexRef == nTexRef)
					//	{
					//		if ((*it)->last)
					//		{
					//			(*(it - 1))->last = true;
					//		}

					//		it = pBlock->_attributes.erase(it);
					//		pBlock->addAttributeSize(-2);

					//		ATLTRACE("Double texture reference: 0x%x = 0x%x\n", nTexRef, nLastTexRef);
					//	}
					//	else
					//	{
					//		++it;
					//	}
					}
					else
						++it;
				}

				if (g_optimizeProps.bTextures)
				{
					unsigned char nMin = 0, nMax = 0;
					psdl::texture *pLastTex = NULL;

					it = pBlock->_attributes.begin();

					while (it != pBlock->_attributes.end())
					{
						switch ((*it)->type)
						{
							case ATB_TEXTURE:     nMin = 0;	break;
							case ATB_SIDEWALK:    nMin = 2;	break;
							case ATB_CROSSWALK:
							case ATB_ROAD:
							case ATB_DIVIDEDROAD: nMin = 3;	break;
							case ATB_TUNNEL:      nMin = 6;	break;
							default:              nMin = 1;
						}

						nMax = max(nMin, nMax);

						if (pLastTex && ((*it)->type == ATB_TEXTURE || it == pBlock->_attributes.end() - 1))
						{
							ATLTRACE("@ block %x, attribute %x: reassigning textures (%d)", i, it - pBlock->_attributes.begin(), nMax);

							vector<std::string>::iterator fnd;

							vector<std::string>::iterator first = m_psdlDoc.GetDocument()->_textures.begin() + pLastTex->i_texture;
							vector<std::string>::iterator last  = first + nMax;

							fnd = search(newTexList.begin(), newTexList.end(), first, last);

							if (fnd != newTexList.end())
							{
								pLastTex->type = ATB_TEXTURE;
								pLastTex->i_texture = fnd - newTexList.begin();
								ATLTRACE(": using existing");
							}
							else
							{
								pLastTex->type = ATB_TEXTURE;
								pLastTex->i_texture = newTexList.size();
								copy(first, last, back_inserter(newTexList));
								ATLTRACE(": new entry (0x%x)", newTexList.size() - 1);
							}

							ATLTRACE("\n");
						}

						if ((*it)->type == ATB_TEXTURE)
						{
							pLastTex = static_cast<psdl::texture*>(*it);
						}

						++it;
					}
				}
			}

		//	if (g_optimizeProps.bTextures)
		//		m_psdlDoc.GetDocument()->_textures = newTexList;
		//	//	g_psdl->m_aTextures.assign(newTexList.begin(), newTexList.end());
		//	}
		}*/
/*
		if (g_optimizeProps.bTextures)
		{
			size_t i = 0, j = 0;
			vector<vertexMap> textureMap;
			vector<vertexMap>::iterator it;
			vector<char*> newTexList;
			psdl::Attribute *atb;
			psdl::Texture *tex = 0;

			atb = g_psdl->nextAttribute(ATB_DIVIDEDROAD, tex, 0);
			do
			{
				if (tex)
				{
					it = textureMap.begin();
					while (it != textureMap.end())
					{
						if (it->from == tex->textureRef)
						{
							tex->textureRef = it->to;
							break;
						}
						++it;
					}
					if (it == textureMap.end())
					{
						vertexMap map = { tex->textureRef, newTexList.size() };
						tex->textureRef = newTexList.size();
						textureMap.push_back(map);
					}
				}
			}
			while (atb = g_psdl->nextAttribute(ATB_DIVIDEDROAD, tex));
		}*/

		m_view.Invalidate();
	}

	return 0;
}