Beispiel #1
0
LTBOOL CScreenSpriteMgr::CacheSprite(CScreenSprite * pSprite, char * pFile)
{
	ILTStream * pStream;
	char buf[1024];

	pSprite->m_pName = strdup(pFile);

	g_pLTClient->OpenFile(pFile, &pStream);
	if (pStream)
	{
		int nFrames;
		int nFrameRate;
		int bTransparency;
		int bTranslucency;
		int iChromakey;

		pStream->Read(&nFrames, 4);
		pSprite->m_nFrames = nFrames;

		pStream->Read(&nFrameRate, 4);
		pSprite->m_nFrameRate = nFrameRate;
		pSprite->m_fOneFrameTime = 1.0f / (float)nFrameRate;

		pStream->Read(&bTransparency, 4);
		pStream->Read(&bTranslucency, 4);
		pStream->Read(&iChromakey, 4);

		if (nFrames < 1 && nFrames > 64)
		{
			// We have an error.
			// FIXME report it
			pStream->Release();
			return LTFALSE;
		}
		for (int i = 0; i < nFrames; i++)
		{
			short iLen;
			pStream->Read(&iLen, 2);
			if (iLen < 1 || iLen > 1023)
			{
				// We have an error.
				// FIXME report it
				pStream->Release();
				return LTFALSE;
			}
			memset(buf,0,1024);
			pStream->Read(&buf, iLen);

			int iFrameID = CacheTexture(buf);
			pSprite->m_FrameArray.push_back(m_FrameArray[iFrameID]);
		}
		pStream->Release();

		return LTTRUE;
	}
	return (LTFALSE);
}
// Load a render style (ltb file) and create a render object for it...
CRenderStyle* D3DRenderStyles::LoadRenderStyle(const char* szFilename)
{
	FileRef ref; 
	CD3DRenderStyle* pRenderStyle	= NULL;
	
	ref.m_FileType		= TYPECODE_RSTYLE;
	ref.m_pFilename		= szFilename;

	FileIdentifier* pIdent	= client_file_mgr->GetFileIdentifier(&ref, TYPECODE_RSTYLE);

	if (pIdent) 
	{
		if (pIdent->m_pData) {
			// Is it already loaded?
			pRenderStyle	= (CD3DRenderStyle*)pIdent->m_pData; 
			pRenderStyle->IncRefCount(); 
		}
		else 
		{
			ILTStream* pFileStream = client_file_mgr->OpenFile(&ref);

			if (pFileStream) 
			{					// Create and Load it...
				pRenderStyle = g_Device.CreateRenderStyle();
				if (!pRenderStyle) return NULL;

				if (!pRenderStyle->Load_LTBData(pFileStream)) 
				{ 
					g_Device.DestroyRenderStyle(pRenderStyle); 
					pFileStream->Release(); 
					string szTmp = "Couldn't Load Renderstyle "; 
					szTmp += szFilename; szTmp += "\n"; 
					OutputDebugString(szTmp.c_str()); 
					return false; 
				} 

				// We're keeping a pointer to it in the m_pData member, so inc it's ref count. 
				// This means that all loaded render styles wont be freed until all files are flushed.
				pIdent->m_pData	= pRenderStyle; 
				pRenderStyle->IncRefCount(); 
				pRenderStyle->SetFilename( szFilename ) ; 
				pFileStream->Release(); 
			} 
		} 
	}	

	return pRenderStyle;
}
Beispiel #3
0
bool CClientFXDB::LoadFxGroups(ILTClient* pClient, const char *sFileName )
{
	ILTStream *pFxFile;

	// Attempt to open the client fx file
	pClient->OpenFile(sFileName, &pFxFile);

	if(!pFxFile)
		return false;

	char szTag[MAX_TAG_SIZE] = {0};

	//remember where we are in our list of effects, so that we don't reinitalize keys that are already
	//in the list
	CLinkListNode<FX_GROUP *> *pTailNode = m_collGroupFX.GetTail();

	// Figure out if we are reading a binary file or text...
	pFxFile->Read( szTag, 7 );
	pFxFile->SeekTo( 0 );

	// This is a text file if we can read an asci "Groups:".
	bool bText = !_stricmp( szTag, "Groups:" );
	ReadFXGroups( bText, pFxFile, m_collGroupFX );

	//clean up the file
	pFxFile->Release();
	pFxFile = NULL;


	// Run through the FX groups we added to the end of the list and setup any non-instance specific
	// information
	CLinkListNode<FX_GROUP *> *pFxGroupNode = (pTailNode) ? pTailNode : m_collGroupFX.GetHead();

	while (pFxGroupNode)
	{
		uint32 nNumKeys = pFxGroupNode->m_Data->m_nNumKeys;

		for(uint32 nCurrKey = 0; nCurrKey < nNumKeys; nCurrKey++)
		{
			FX_KEY *pKey = &pFxGroupNode->m_Data->m_pKeys[nCurrKey];

			float tmLength = pKey->m_tmEnd - pKey->m_tmStart;

			if (tmLength >= pFxGroupNode->m_Data->m_tmTotalTime - 0.01f)
			{
				pKey->m_bContinualLoop = true;
			}
			else
			{
				pKey->m_bContinualLoop = false;
			}
		}

		pFxGroupNode = pFxGroupNode->m_pNext;
	}

	// Success !!
	return true;
}
LTRESULT CLTRenderMgr::AddEffectShader (const char *pFileName, 
								  int EffectShaderID, 
								  const uint32 *pVertexElements, 
								  uint32 VertexElementsSize, 
								  HEFFECTPOOL EffectPoolID)
{
	if (!pFileName)
	{
		RETURN_ERROR(1, CLTRenderMgr::AddEffectShader, LT_INVALIDPARAMS);
	}

	FileRef ref;
	ref.m_FileType = FILE_ANYFILE;
	ref.m_pFilename = pFileName;
	ILTStream *pStream = client_file_mgr->OpenFile(&ref);
	if (!pStream)
	{
		RETURN_ERROR(3, CLTRenderMgr::AddEffectShader, LT_NOTFOUND);
	}

	if(!LTEffectShaderMgr::GetSingleton().AddEffectShader(pStream, pFileName, EffectShaderID, pVertexElements, VertexElementsSize, EffectPoolID))
	{
		// Close the file.
		if (pStream != NULL)
		{
			pStream->Release();
			pStream = NULL;
		}

		return LT_ERROR;
	}
	

	// Close the file.
	if (pStream != NULL)
	{
		pStream->Release();
		pStream = NULL;
	}

	return LT_OK;
}
Beispiel #5
0
// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CTO2MissionButeMgr::Init
//
//	PURPOSE:	Initialization
//
// ----------------------------------------------------------------------- //
LTBOOL CDMButeMgr::Init(const char* szAttributeFile)
{
    if(!szAttributeFile) return LTFALSE;

	// See if we already have this attribute file loaded.
	if( m_strAttributeFile.GetLength( ) && m_strAttributeFile.CompareNoCase( szAttributeFile ) == 0 )
		return LTTRUE;
    
	// Start fresh.
	Term( );

    ILTStream* pDStream = LTNULL;
    LTRESULT dr = g_pLTBase->OpenFile(szAttributeFile, &pDStream);
    bool bFound = (dr == LT_OK && pDStream);
	if (pDStream)
		pDStream->Release();


	if (!bFound || !Parse(szAttributeFile)) 
		return LTFALSE;

	return LTTRUE;
};
//loads the specified script
bool CTextureScriptInterpreter::LoadScript(const char* pszFilename)
{
	//clear out any old script
	Free();

	//now we need to open up the new file
	FileRef Ref; 
	Ref.m_FileType			= TYPECODE_UNKNOWN;
	Ref.m_pFilename			= pszFilename;
	FileIdentifier* pIdent	= g_pIClientFileMgr->GetFileIdentifier(&Ref, TYPECODE_UNKNOWN);

	//open up the stream
	ILTStream* pStream = g_pIClientFileMgr->OpenFile(&Ref);

	if(!pStream)
		return false;

	//read in the version
	uint16 nVersion;
	*pStream >> nVersion;

	//make sure the version is correct
	if(nVersion != TS_CURR_VERSION)
	{
		pStream->Release();
		return false;
	}
	//now read in the size of the variable names
	uint32 nVarSize;
	*pStream >> nVarSize;

	//skip over the variables
	pStream->SeekTo(pStream->GetPos() + nVarSize);

	//read in our input type, output type and our dirty flags
	uint32 nInput;
	uint32 nOutput;
	uint32 nDirty;

	*pStream >> nInput >> nOutput >> nDirty;

	//now read in the constant table
	uint32 nNumConstants;
	*pStream >> nNumConstants;
	assert(nNumConstants < TS_NUMCONSTANTS);

	//now read all the constants into the table
	for(uint32 nCurrConstant = 0; nCurrConstant < nNumConstants; nCurrConstant++)
	{
		*pStream >> m_fVarList[TSVAR_CONSTANT + nCurrConstant];
	}

	//now it is time to read in the actual bytecode
	*pStream >> m_nByteCodeLen;

	//allocate our buffer
	LT_MEM_TRACK_ALLOC(m_pByteCode = new uint8 [m_nByteCodeLen],LT_MEM_TYPE_RENDER_TEXTURESCRIPT);

	//check the allocation
	if(!m_pByteCode)
	{
		pStream->Release();
		m_nByteCodeLen = 0;
		return false;
	}

	//read in our buffer
	pStream->Read(m_pByteCode, m_nByteCodeLen);

	//close our stream
	pStream->Release();

	//now we need to figure out our internal flags
	m_nFlags = 0;

	//setup info based upon input
	switch(nInput)
	{
	case TSINPUT_CSNORMAL:		m_eInput = INPUT_NORMAL;		break;
	case TSINPUT_CSPOS:			m_eInput = INPUT_POS;			break;
	case TSINPUT_CSREFLECTION:	m_eInput = INPUT_REFLECTION;	break;
	case TSINPUT_UV:			m_eInput = INPUT_UV;			break;
	case TSINPUT_WSNORMAL:		m_eInput = INPUT_NORMAL;		m_nFlags |= FLAG_WORLDSPACE; break;
	case TSINPUT_WSPOS:			m_eInput = INPUT_POS;			m_nFlags |= FLAG_WORLDSPACE; break;
	case TSINPUT_WSREFLECTION:	m_eInput = INPUT_REFLECTION;	m_nFlags |= FLAG_WORLDSPACE; break;
	default:
		assert(false);
		break;
	}

	//setup info based upon output
	switch(nOutput)
	{
	case TSOUTPUT_2:		m_nFlags |= FLAG_COORD2;					break;
	case TSOUTPUT_3:		m_nFlags |= FLAG_COORD3;					break;
	case TSOUTPUT_3PROJ:	m_nFlags |= FLAG_COORD3 | FLAG_PROJECTED;	break;
	case TSOUTPUT_4PROJ:	m_nFlags |= FLAG_COORD4 | FLAG_PROJECTED;	break;
	default:
		assert(false);
		break;
	}

	//setup info based upon dirty flags
	if(nDirty & TSDIRTY_EVERYUPDATE)
		m_nFlags |= FLAG_DIRTYONFRAME;
	if(nDirty & TSDIRTY_USERVARCHANGED)
		m_nFlags |= FLAG_DIRTYONVAR;	

	//success
	return true;
}
Beispiel #7
0
void d3d_DrawPolyGrid(const ViewParams &Params, LTObject *pObj)
{
	//the global pixel shader to be used for the water bumpmapping and a flag indicating if
	//creation failed
	bool				s_bPixelShaderFailed = false;

	//make sure that the polygrid is valid
	assert(pObj);

	//get our polygrid
    LTPolyGrid *pGrid = (LTPolyGrid*)pObj;

	// Make sure it's initialized.
	if(!pGrid->m_Data)
		return;

	//must have an index buffer
	if(!pGrid->m_Indices || (pGrid->m_nIndices == 0))
		return;

	//and of course, make sure that the size is reasonable
	if((pGrid->m_Width < 2) || (pGrid->m_Height < 2))
		return;

	IncFrameStat(eFS_PolyGridTriangles, pGrid->m_nTris);

	//cache the half dimensions
	float fHalfGridWidth  = ((float)pGrid->m_Width - 1) * 0.5f;
	float fHalfGridHeight = ((float)pGrid->m_Height - 1) * 0.5f;

	//now we need to build our color lookup table for this polygrid, this is faster for any
	//polygrid that is larger than 8x8, and even then we can get a nice tight loop that
	//should still be rather optimal

	// Set the blending mode based on the flags.
	uint32 nSrcBlend, nDestBlend, nFog, nFogColor;
	d3d_GetBlendStates(pGrid, nSrcBlend, nDestBlend, nFog, nFogColor);
	StateSet ssSrcBlend(D3DRS_SRCBLEND, nSrcBlend);
	StateSet ssDestBlend(D3DRS_DESTBLEND, nDestBlend);
	StateSet ssFog(D3DRS_FOGENABLE, nFog);
	StateSet ssFogColor(D3DRS_FOGCOLOR, nFogColor);

	//flag indicating whether or not
	bool bEnvMap		= false;
	bool bCubicEnvMap	= false;
	bool bBumpMap		= false;

	//vertex information
	uint32 nVertexSize  = sizeof(CPolyGridVertex);
	uint32 nVertexFVF	= POLYGRIDVERTEX_FORMAT;

	//UV scales to adjust the texture by (defaults to 1, but if we are bump mapping, this will
	//be set to the detail texture scale)
	float	fPGUScale	= 1.0f;
	float	fPGVScale	= 1.0f;

	// Set the texture if necessary.
	SpriteTracker* pTracker;

	LTPixelShader *pPixelShader = NULL;

	if(pGrid->m_pSprite)
	{
		pTracker = &pGrid->m_SpriteTracker;
		if(pTracker->m_pCurFrame)
		{
			SharedTexture* pTex = pTracker->m_pCurFrame->m_pTex;
			if(pTex)
			{
				//get the type of this texture
				ESharedTexType eTexType = pTex->m_eTexType;

				//the base texture
				SharedTexture* pBaseTex		= NULL;
				//the environment map
				SharedTexture* pEnvMapTex	= pGrid->m_pEnvMap;
				//the bumpmap
				SharedTexture* pBumpMapTex	= NULL;

				//determine our texture data
				if(pGrid->m_nPGFlags & PG_NORMALMAPSPRITE)
				{
					//only use a bump map texture if we actually have an environment map
					if(pEnvMapTex)
						pBumpMapTex	= pTex;
				}
				else
				{
					//we have a normal texture
					pBaseTex	= pTex;
				}

				// Set up the environment mapping texture if applicable
				if(	pEnvMapTex && g_CV_EnvMapPolyGrids.m_Val)
				{
					//see if the is a cubic environment map
					RTexture *pRenderTexture = (RTexture*)pEnvMapTex->m_pRenderData;
					if(pRenderTexture && pRenderTexture->IsCubeMap())
					{
						bCubicEnvMap = true;
					}

					bEnvMap = true;
				}

				if(	pBumpMapTex && g_CV_BumpMapPolyGrids.m_Val)
				{
					//we now need to make sure that the bump map shader is valid

					//see if we need to load it
					if (!s_bPixelShaderFailed)
					{
						// Get the pixel shader.
						pPixelShader = LTPixelShaderMgr::GetSingleton().GetPixelShader(LTPixelShader::PIXELSHADER_ENVBUMPMAP);
						if (NULL == pPixelShader)
						{
							FileRef ref;
							ref.m_FileType 	= FILE_ANYFILE;
							ref.m_pFilename = "ps\\envbumpmap.psh";

							// Try to load it.
							ILTStream *pStream = g_pIClientFileMgr->OpenFile(&ref);
							if (NULL != pStream)
							{
								if (LTPixelShaderMgr::GetSingleton().AddPixelShader(pStream, ref.m_pFilename,
																					LTPixelShader::PIXELSHADER_ENVBUMPMAP, true))
								{
									pPixelShader = LTPixelShaderMgr::GetSingleton().GetPixelShader(LTPixelShader::PIXELSHADER_ENVBUMPMAP);
								}

								// Close the file.
								pStream->Release();
							}
						}
					}

					// See if we can continue.
					if (NULL != pPixelShader && pPixelShader->IsValidShader())
					{
						bBumpMap	= true;
						nVertexSize = sizeof(CPolyGridBumpVertex);
						nVertexFVF	= POLYGRIDBUMPVERTEX_FORMAT;
						fPGUScale	= ((RTexture*)pBumpMapTex->m_pRenderData)->m_DetailTextureScale;
						fPGVScale	= fPGUScale;
					}
					else
					{
						//we failed to create the shader, the device can't support it
						s_bPixelShaderFailed = true;
					}
				}

				//setup the textures based upon the configuration
				if(bBumpMap)
				{
					d3d_SetTexture(pBumpMapTex, 0, eFS_PolyGridBumpMapTexMemory);
					d3d_SetTexture(pEnvMapTex, 3, eFS_PolyGridEnvMapTexMemory);
				}
				else
				{
					LTEffectImpl* pEffect = (LTEffectImpl*)LTEffectShaderMgr::GetSingleton().GetEffectShader(pGrid->m_nEffectShaderID);
					if(pEffect)
					{
						ID3DXEffect* pD3DEffect = pEffect->GetEffect();
						if(pD3DEffect)
						{
							nVertexSize = sizeof(CPolyGridEffectVertex); 

							RTexture* pRTexture = (RTexture*)pBaseTex->m_pRenderData;
							pD3DEffect->SetTexture("texture0", pRTexture->m_pD3DTexture);

							if(bEnvMap)
							{
								pRTexture = (RTexture*)pEnvMapTex->m_pRenderData;
								pD3DEffect->SetTexture("texture1", pRTexture->m_pD3DTexture);
							}

						}
					}else
					{
						d3d_SetTexture(pBaseTex, 0, eFS_PolyGridBaseTexMemory);

						if(bEnvMap)
						{
							d3d_SetTexture(pEnvMapTex, 1, eFS_PolyGridEnvMapTexMemory);
						}
					}
				}
			}
			else
			{
				//if we didn't set any texture, we need to make sure and clear out the texture
				//channel
				d3d_DisableTexture(0);
			}
		}
	}

	//specify that we were visible
	pGrid->m_Flags |= FLAG_INTERNAL1;

	// Build the vertex list.
	uint32 nBufferSize = pGrid->m_Width * pGrid->m_Height * nVertexSize;
	if(nBufferSize > g_TriVertListSize)
	{
		//we need to reallocate our list of vertices
		dfree(g_TriVertList);
		LT_MEM_TRACK_ALLOC(g_TriVertList = dalloc(nBufferSize),LT_MEM_TYPE_RENDERER);

		//check the allocation
		if(!g_TriVertList)
		{
			g_TriVertListSize = 0;
			return;
		}

		g_TriVertListSize = nBufferSize;
	}

	//determine if this polygrid should be lit or not
	bool bFresnel = (pGrid->m_nPGFlags & PG_FRESNEL) && (g_CV_FresnelPolyGrids.m_Val) ? true : false;

	//determine what alpha value we should use
	uint8 nColorAlpha = 0;
	if(!bEnvMap)
		nColorAlpha = 255;
	else if(!bFresnel)
		nColorAlpha = 128;

	float fScaledR = pGrid->m_ColorR * MATH_ONE_OVER_255;
	float fScaledG = pGrid->m_ColorG * MATH_ONE_OVER_255;
	float fScaledB = pGrid->m_ColorB * MATH_ONE_OVER_255;

	uint32 nColorTable[256];
	for(uint32 nCurrColor = 0; nCurrColor < 256; nCurrColor++)
	{
		//Note that the color table is 0..255, object color is 0..255 as well
		nColorTable[nCurrColor] = D3DRGBA_255(	pGrid->m_ColorTable[nCurrColor].x * fScaledR,
												pGrid->m_ColorTable[nCurrColor].y * fScaledG,
												pGrid->m_ColorTable[nCurrColor].z * fScaledB,
												nColorAlpha);
	}

	//setup our world matrix to represent a space that holds the orientation of the polygrid
	//as well as the center position. This allows all operations to take place
	//as if performed on the XZ plane (note that we don't do the scale as that tends
	//to mess up normals)
	LTMatrix mWorldTrans;
	LTVector vUnitScale(1.0f, 1.0f, 1.0f);
	d3d_SetupTransformation(&pGrid->GetPos(), (float*)&pGrid->m_Rotation, &vUnitScale, &mWorldTrans);
	d3d_SetD3DMat(D3DTS_WORLD, &mWorldTrans);

	//calculate our position increments
	float fXInc			= pGrid->GetDims().x * 2.0f / (pGrid->m_Width - 1);
	float fZInc			= pGrid->GetDims().z * 2.0f / (pGrid->m_Height - 1);
	float fYScale		= pGrid->GetDims().y / 127.0f;

	float fXStart		= -fHalfGridWidth * fXInc;
	float fCurrX		= fXStart;
	float fCurrZ		= -fHalfGridHeight * fZInc;


	int8* pDataPos		= (int8*)pGrid->m_Data;
	int8* pDataEnd		= pDataPos + pGrid->m_Width * pGrid->m_Height;
	int8* pLineDataEnd	= pDataPos + pGrid->m_Width;

	uint32* pColor		= nColorTable + 128;

	float fXScale		= pGrid->m_xScale / ((pGrid->m_Width - 1) * fXInc);
	float fZScale		= pGrid->m_yScale / ((pGrid->m_Height - 1) * fZInc);

	float fStartU		= (float)fmod(pGrid->m_xPan * fPGUScale, 1.0f);
	float fStartV		= (float)fmod(pGrid->m_yPan * fPGVScale, 1.0f);

	float fCurrU		= fStartU;
	float fCurrV		= fStartV;

	float fUInc			= fXInc * fXScale * fPGUScale;
	float fVInc			= fZInc * fZScale * fPGVScale;

	int32 nWidth		= pGrid->m_Width;
	float fSpacingX		= fXInc * 2.0f;
	float fSpacingZ		= fZInc * 2.0f;

	uint32 nNumVerts;

	bool bEffect = false;
	LTEffectImpl* pEffect = (LTEffectImpl*)LTEffectShaderMgr::GetSingleton().GetEffectShader(pGrid->m_nEffectShaderID);
	if(pEffect)
	{
		ID3DXEffect* pD3DEffect = pEffect->GetEffect();
		if(pD3DEffect)
		{
			bEffect = true;
		}
	}

	if(bBumpMap)
	{
		CPolyGridBumpVertex* pVertexPos = (CPolyGridBumpVertex*)g_TriVertList;

		if(pGrid->m_pValidMask)
		{
			//this polygrid has a valid mask, meaning that we need to skip over vertices
			//as needed
			uint32* pCurrMask = pGrid->m_pValidMask;

			//amount to adjust the mask at the end of a line
			uint32 nMaskLineAdjust = (pGrid->m_Width % 32) ? 1 : 0;

			uint32 nShift;
			uint32 nNormalY1 = 0;
			uint32 nNormalY2 = nWidth;

			float fWidthTimesHeight = fSpacingX * fSpacingZ;

			while(pDataPos < pDataEnd)
			{
				nShift = 0x1;

				while(pDataPos < pLineDataEnd)
				{
					if(*pCurrMask & nShift)
					{
						//this is valid, add this vertex
						d3d_SetupVertexPos(pVertexPos, fCurrX, *pDataPos * fYScale, fCurrZ, pColor[*pDataPos], fCurrU, fCurrV);

						//generate a normal for it
						GenerateBasisSpace(pDataPos, pVertexPos, -1, 1, nNormalY1, nNormalY2, fSpacingX, fSpacingZ, fWidthTimesHeight, fYScale);

						//move along to the next vertex
						pVertexPos++;
					}

					pDataPos++;
					fCurrX += fXInc;
					fCurrU += fUInc;

					if(nShift == 0x80000000)
					{
						pCurrMask++;
						nShift = 1;
					}
					else
					{
						nShift <<= 1;
					}
				}

				//reset the line
				fCurrX = fXStart;

				//update our threshold for when to move onto the next line
				pLineDataEnd += pGrid->m_Width;
				pCurrMask += nMaskLineAdjust;

				//update our position
				fCurrZ += fZInc;
				fCurrU  = fStartU;
				fCurrV += fVInc;

				//update the normal offsets to ensure we don't go outside of our buffer
				nNormalY1 = -nWidth;
				if(pLineDataEnd >= pDataEnd)
					nNormalY2 = 0;
			}

			nNumVerts = pVertexPos - (CPolyGridBumpVertex*)g_TriVertList;
		}
		else
		{
			nNumVerts = pGrid->m_Width * pGrid->m_Height;

			while(pDataPos < pDataEnd)
			{
				while(pDataPos < pLineDataEnd)
				{
					d3d_SetupVertexPos(pVertexPos, fCurrX, *pDataPos * fYScale, fCurrZ, pColor[*pDataPos], fCurrU, fCurrV);

					pDataPos++;
					pVertexPos++;
					fCurrX += fXInc;
					fCurrU += fUInc;
				}

				//reset the line
				fCurrX = fXStart;

				//update our threshold for when to move onto the next line
				pLineDataEnd += pGrid->m_Width;

				//update our position
				fCurrZ += fZInc;
				fCurrU  = fStartU;
				fCurrV += fVInc;
			}

			//now we need to generate the normals for the polygrid
			GeneratePolyGridVectors(pGrid, (CPolyGridBumpVertex*)g_TriVertList, GenerateBasisSpace);
		}
	}
	else if(bEffect)
	{
		CPolyGridEffectVertex* pVertexPos = (CPolyGridEffectVertex*)g_TriVertList;

		if(pGrid->m_pValidMask)
		{
			//this polygrid has a valid mask, meaning that we need to skip over vertices
			//as needed
			uint32* pCurrMask = pGrid->m_pValidMask;

			//amount to adjust the mask at the end of a line
			uint32 nMaskLineAdjust = (pGrid->m_Width % 32) ? 1 : 0;

			uint32 nShift;
			uint32 nNormalY1 = 0;
			uint32 nNormalY2 = nWidth;

			float fWidthTimesHeight = fSpacingX * fSpacingZ;

			while(pDataPos < pDataEnd)
			{
				nShift = 0x1;

				while(pDataPos < pLineDataEnd)
				{
					if(*pCurrMask & nShift)
					{
						//this is valid, add this vertex
						d3d_SetupVertexPos(pVertexPos, fCurrX, *pDataPos * fYScale, fCurrZ, pColor[*pDataPos], fCurrU, fCurrV);

						//generate a normal for it
						GenerateEffectBasisSpace(pDataPos, pVertexPos, -1, 1, nNormalY1, nNormalY2, fSpacingX, fSpacingZ, fWidthTimesHeight, fYScale);

						//move along to the next vertex
						pVertexPos++;
					}

					pDataPos++;
					fCurrX += fXInc;
					fCurrU += fUInc;

					if(nShift == 0x80000000)
					{
						pCurrMask++;
						nShift = 1;
					}
					else
					{
						nShift <<= 1;
					}
				}

				//reset the line
				fCurrX = fXStart;

				//update our threshold for when to move onto the next line
				pLineDataEnd += pGrid->m_Width;
				pCurrMask += nMaskLineAdjust;

				//update our position
				fCurrZ += fZInc;
				fCurrU  = fStartU;
				fCurrV += fVInc;

				//update the normal offsets to ensure we don't go outside of our buffer
				nNormalY1 = -nWidth;
				if(pLineDataEnd >= pDataEnd)
					nNormalY2 = 0;
			}

			nNumVerts = pVertexPos - (CPolyGridEffectVertex*)g_TriVertList;
		}
		else
		{
			nNumVerts = pGrid->m_Width * pGrid->m_Height;

			while(pDataPos < pDataEnd)
			{
				while(pDataPos < pLineDataEnd)
				{
					d3d_SetupVertexPos(pVertexPos, fCurrX, *pDataPos * fYScale, fCurrZ, pColor[*pDataPos], fCurrU, fCurrV);

					pDataPos++;
					pVertexPos++;
					fCurrX += fXInc;
					fCurrU += fUInc;
				}

				//reset the line
				fCurrX = fXStart;

				//update our threshold for when to move onto the next line
				pLineDataEnd += pGrid->m_Width;

				//update our position
				fCurrZ += fZInc;
				fCurrU  = fStartU;
				fCurrV += fVInc;
			}

			//now we need to generate the normals for the polygrid
			LTEffectImpl* pEffect = (LTEffectImpl*)LTEffectShaderMgr::GetSingleton().GetEffectShader(pGrid->m_nEffectShaderID);
			if(pEffect)
			{
				ID3DXEffect* pD3DEffect = pEffect->GetEffect();
				if(pD3DEffect)
				{
					GeneratePolyGridVectors(pGrid, (CPolyGridEffectVertex*)g_TriVertList, GenerateEffectBasisSpace);
				}
			}
			else
			{
				GeneratePolyGridVectors(pGrid, (CPolyGridVertex*)g_TriVertList, GenerateNormal);
			}
		}
	}
	else //fixed function
	{
		CPolyGridVertex* pVertexPos = (CPolyGridVertex*)g_TriVertList;

		if(pGrid->m_pValidMask)
		{
			//this polygrid has a valid mask, meaning that we need to skip over vertices
			//as needed
			uint32* pCurrMask = pGrid->m_pValidMask;

			//amount to adjust the mask at the end of a line
			uint32 nMaskLineAdjust = (pGrid->m_Width % 32) ? 1 : 0;

			uint32 nShift;
			uint32 nNormalY1 = 0;
			uint32 nNormalY2 = nWidth;

			float fWidthTimesHeight = fSpacingX * fSpacingZ;

			while(pDataPos < pDataEnd)
			{
				nShift = 0x1;

				while(pDataPos < pLineDataEnd)
				{
					if(*pCurrMask & nShift)
					{
						//this is valid, add this vertex
						d3d_SetupVertexPos(pVertexPos, fCurrX, *pDataPos * fYScale, fCurrZ, pColor[*pDataPos], fCurrU, fCurrV);

						//generate a normal for it
						GenerateNormal(pDataPos, pVertexPos, -1, 1, nNormalY1, nNormalY2, fSpacingX, fSpacingZ, fWidthTimesHeight, fYScale);

						//move along to the next vertex
						pVertexPos++;
					}

					pDataPos++;
					fCurrX += fXInc;
					fCurrU += fUInc;

					if(nShift == 0x80000000)
					{
						pCurrMask++;
						nShift = 1;
					}
					else
					{
						nShift <<= 1;
					}
				}

				//reset the line
				fCurrX = fXStart;

				//update our threshold for when to move onto the next line
				pLineDataEnd += pGrid->m_Width;
				pCurrMask += nMaskLineAdjust;

				//update our position
				fCurrZ += fZInc;
				fCurrU  = fStartU;
				fCurrV += fVInc;

				//update the normal offsets to ensure we don't go outside of our buffer
				nNormalY1 = -nWidth;
				if(pLineDataEnd >= pDataEnd)
					nNormalY2 = 0;
			}

			nNumVerts = pVertexPos - (CPolyGridVertex*)g_TriVertList;
		}
		else
		{
			nNumVerts = pGrid->m_Width * pGrid->m_Height;

			while(pDataPos < pDataEnd)
			{
				while(pDataPos < pLineDataEnd)
				{
					d3d_SetupVertexPos(pVertexPos, fCurrX, *pDataPos * fYScale, fCurrZ, pColor[*pDataPos], fCurrU, fCurrV);

					pDataPos++;
					pVertexPos++;
					fCurrX += fXInc;
					fCurrU += fUInc;
				}

				//reset the line
				fCurrX = fXStart;

				//update our threshold for when to move onto the next line
				pLineDataEnd += pGrid->m_Width;

				//update our position
				fCurrZ += fZInc;
				fCurrU  = fStartU;
				fCurrV += fVInc;
			}

			//now we need to generate the normals for the polygrid
			LTEffectImpl* pEffect = (LTEffectImpl*)LTEffectShaderMgr::GetSingleton().GetEffectShader(pGrid->m_nEffectShaderID);
			if(pEffect)
			{
				ID3DXEffect* pD3DEffect = pEffect->GetEffect();
				if(pD3DEffect)
				{
					GeneratePolyGridVectors(pGrid, (CPolyGridEffectVertex*)g_TriVertList, GenerateEffectBasisSpace);
				}
			}
			else
			{
				GeneratePolyGridVectors(pGrid, (CPolyGridVertex*)g_TriVertList, GenerateNormal);
			}
		}
	}

	// Set environment map texture coordinates.
	if(bEnvMap && !bBumpMap)
	{
		d3d_SetEnvMapTextureStates(Params, pTracker->m_pCurFrame->m_pTex->m_eTexType, pGrid, bCubicEnvMap);
	}

	//see if we are just doing a base texture
	if(!bEnvMap && !bBumpMap)
	{
		d3d_SetDefaultBlendStates();
	}

	//generate the alpha if we can use it
	if(bBumpMap)
	{
		GeneratePolyGridFresnelAlphaAndCamera(Params.m_Pos, (CPolyGridBumpVertex*)g_TriVertList, pGrid, nNumVerts);
	}
	else if(bFresnel)
	{
		GeneratePolyGridFresnelAlpha(Params.m_Pos, (CPolyGridVertex*)g_TriVertList, pGrid, nNumVerts);
	}

	//make the backfacing polygons cull
	StateSet ssCullMode(D3DRS_CULLMODE, (pGrid->m_nPGFlags & PG_NOBACKFACECULL) ? D3DCULL_NONE : D3DCULL_CCW);

	//setup the pixel shader if we are bumpmapping
	if(bBumpMap)
	{
		assert(NULL != pPixelShader && pPixelShader->IsValidShader());

		// Set the pixel shader constants.
		float *pConstants = pPixelShader->GetConstants();
		pConstants[0] = 0.0f;
		pConstants[1] = 0.0f;
		pConstants[2] = 0.0f;
		pConstants[3] = pGrid->m_ColorA / 255.0f;
		LTPixelShaderMgr::GetSingleton().SetPixelShaderConstants(pPixelShader);

		// Install the pixel shader.
		LTPixelShaderMgr::GetSingleton().InstallPixelShader(pPixelShader);

		//now actually draw the polygrid
		D3D_CALL(PD3DDEVICE->SetVertexShader(NULL));
		D3D_CALL(PD3DDEVICE->SetFVF(nVertexFVF));
		
		int nNumPolies = (pGrid->m_nIndices/3);

		// Is this polygrid larger than our buffer? If so, break it into smaller patches.
		if(nNumPolies > g_CV_PolyGridBufferSize)
		{
			int32 nRemainingPolies = nNumPolies;
			uint32 nCurrentVertPosition = 0;

			while(nRemainingPolies > 0)
			{
				uint32 nPoliesThisFrame = (nRemainingPolies > g_CV_PolyGridBufferSize) ? g_CV_PolyGridBufferSize: nRemainingPolies;
				D3D_CALL(PD3DDEVICE->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST,0,nNumVerts,nPoliesThisFrame,&pGrid->m_Indices[nCurrentVertPosition],D3DFMT_INDEX16,g_TriVertList, nVertexSize));
				nCurrentVertPosition += nPoliesThisFrame*3;
				nRemainingPolies -= nPoliesThisFrame;
			}
		}
		else
		{
			D3D_CALL(PD3DDEVICE->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST,0,nNumVerts,(pGrid->m_nIndices)/3,pGrid->m_Indices,D3DFMT_INDEX16,g_TriVertList, nVertexSize));
		}

		// Uninstall the pixel shader.
		LTPixelShaderMgr::GetSingleton().UninstallPixelShader();

		d3d_DisableTexture(0);
		d3d_DisableTexture(3);
	}
	else
	{
		//now actually draw the polygrid
		D3D_CALL(PD3DDEVICE->SetVertexShader(NULL));
		D3D_CALL(PD3DDEVICE->SetFVF(nVertexFVF));

		int nNumPolies = (pGrid->m_nIndices/3);

		// Is this polygrid larger than our buffer? If so, break it into smaller patches.
		if(nNumPolies > g_CV_PolyGridBufferSize)
		{
			int32 nRemainingPolies = nNumPolies;
			uint32 nCurrentVertPosition = 0;

			while(nRemainingPolies > 0)
			{
				uint32 nPoliesThisFrame = (nRemainingPolies > g_CV_PolyGridBufferSize) ? g_CV_PolyGridBufferSize: nRemainingPolies;
				
				LTEffectImpl* pEffect = (LTEffectImpl*)LTEffectShaderMgr::GetSingleton().GetEffectShader(pGrid->m_nEffectShaderID);
				if(pEffect)
				{
					pEffect->UploadVertexDeclaration();

					ID3DXEffect* pD3DEffect = pEffect->GetEffect();
					if(pD3DEffect)
					{
						i_client_shell->OnEffectShaderSetParams(pEffect, NULL, NULL, LTShaderDeviceStateImp::GetSingleton());

						UINT nPasses = 0;
						pD3DEffect->Begin(&nPasses, 0);

						for(UINT i = 0; i < nPasses; ++i)
						{
							pD3DEffect->BeginPass(i);
							D3D_CALL(PD3DDEVICE->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST,0,nNumVerts,nPoliesThisFrame,&pGrid->m_Indices[nCurrentVertPosition],D3DFMT_INDEX16,g_TriVertList, nVertexSize));
							pD3DEffect->EndPass();
						}

						pD3DEffect->End();
					}

				}
				else
				{
					D3D_CALL(PD3DDEVICE->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST,0,nNumVerts,nPoliesThisFrame,&pGrid->m_Indices[nCurrentVertPosition],D3DFMT_INDEX16,g_TriVertList, nVertexSize));
				}

				nCurrentVertPosition += nPoliesThisFrame*3;
				nRemainingPolies -= nPoliesThisFrame;
			}
		}
		else
		{
			LTEffectImpl* pEffect = (LTEffectImpl*)LTEffectShaderMgr::GetSingleton().GetEffectShader(pGrid->m_nEffectShaderID);
			if(pEffect)
			{
				pEffect->UploadVertexDeclaration();

				ID3DXEffect* pD3DEffect = pEffect->GetEffect();
				if(pD3DEffect)
				{
					i_client_shell->OnEffectShaderSetParams(pEffect, NULL, NULL, LTShaderDeviceStateImp::GetSingleton());

					UINT nPasses = 0;
					pD3DEffect->Begin(&nPasses, 0);
					
					for(UINT i = 0; i < nPasses; ++i)
					{
						pD3DEffect->BeginPass(i);
						D3D_CALL(PD3DDEVICE->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST,0,nNumVerts,(pGrid->m_nIndices)/3,pGrid->m_Indices,D3DFMT_INDEX16,g_TriVertList, nVertexSize));
						pD3DEffect->EndPass();
					}

					pD3DEffect->End();
				}

			}
			else
			{
				// No Effect Shader, just fixed function.
				D3D_CALL(PD3DDEVICE->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST,0,nNumVerts,(pGrid->m_nIndices)/3,pGrid->m_Indices,D3DFMT_INDEX16,g_TriVertList, nVertexSize));
			}
			
		}

		d3d_DisableTexture(0);
		d3d_DisableTexture(1);
	}

	if (bEnvMap)
		d3d_UnsetEnvMapTextureStates();

	//reset our world transform so that it won't mess up the rendering of other objects
	d3d_SetD3DMat(D3DTS_WORLD, &Params.m_mIdentity);
}
Beispiel #8
0
// Loads the texture and installs it.
LTRESULT r_LoadSystemTexture(SharedTexture *pSharedTexture)
{
	LTRESULT dResult;
	FileRef ref;

	FileIdentifier *pIdent = pSharedTexture->m_pFile;

	if (!pIdent) 
		return LT_NOTINITIALIZED;

	uint32 nBaseWidth;
	uint32 nBaseHeight;

	//the texture data that is associated with the texture
	TextureData* pTextureData = NULL;

	ILTStream *pStream = client_file_mgr->OpenFileIdentifier(pIdent);
	if (pStream) 
	{
		dResult = dtx_Create(pStream, &pTextureData, nBaseWidth, nBaseHeight);
		pStream->Release();

		if (dResult != LT_OK) 
			return dResult; 
	}
	else 
	{
		RETURN_ERROR_PARAM(1, r_LoadSystemTexture, LT_MISSINGFILE, pIdent->m_Filename); 
	}

	//make sure to setup the texture information
	pSharedTexture->SetTextureInfo(nBaseWidth, nBaseHeight, pTextureData->m_PFormat);

	// Add the new texture to the MRU list.
	dl_AddHead(&g_SysCache.m_List, &pTextureData->m_Link, pTextureData);
	g_SysCache.m_CurMem += pTextureData->m_AllocSize;

	// Store its pointer in the SharedTexture.
	pSharedTexture->m_pEngineData = pTextureData;
	pTextureData->m_pSharedTexture = pSharedTexture;

	// Load in any linked textures depending upon what the user entered in the command string. Note
	//that these are exclusive

	ConParse parse;

	//Normal detail texturing
	parse.Init(pTextureData->m_Header.m_CommandString);
	if (parse.ParseFind("DetailTex", LTFALSE, 1)) 
	{

        //validate the argument count
        if(parse.m_nArgs < 2)
        {
		    RETURN_ERROR_PARAM(1, r_LoadSystemTexture, LT_INVALIDDATA, "DetailTex : parse.m_Args[1]"); 
        }

		ref.m_FileType = FILE_CLIENTFILE;
		ref.m_pFilename = parse.m_Args[1];
		pSharedTexture->SetLinkedTexture(eLinkedTex_Detail, g_pClientMgr->AddSharedTexture(&ref));
		pSharedTexture->m_eTexType = eSharedTexType_Detail; 
		return LT_OK;
	}

	//Normal environment mapping
	parse.Init(pTextureData->m_Header.m_CommandString);
	if (parse.ParseFind("EnvMap", LTFALSE, 1)) 
	{

        //validate the argument count
        if(parse.m_nArgs < 2)
        {
		    RETURN_ERROR_PARAM(1, r_LoadSystemTexture, LT_INVALIDDATA, "EnvMap : parse.m_Args[1]"); 
        }

		ref.m_FileType = FILE_CLIENTFILE;
		ref.m_pFilename = parse.m_Args[1];
		pSharedTexture->SetLinkedTexture(eLinkedTex_EnvMap, g_pClientMgr->AddSharedTexture(&ref));
		pSharedTexture->m_eTexType = eSharedTexType_EnvMap; 
		return LT_OK;
	}

	//Environment mapping blended with the alpha of the base texture
	parse.Init(pTextureData->m_Header.m_CommandString);
	if (parse.ParseFind("EnvMapAlpha", LTFALSE, 1)) 
	{

        //validate the argument count
        if(parse.m_nArgs < 2)
        {
		    RETURN_ERROR_PARAM(1, r_LoadSystemTexture, LT_INVALIDDATA, "EnvMapAlpha : parse.m_Args[1]"); 
        }

		ref.m_FileType = FILE_CLIENTFILE;
		ref.m_pFilename = parse.m_Args[1];
		pSharedTexture->SetLinkedTexture(eLinkedTex_EnvMap, g_pClientMgr->AddSharedTexture(&ref));
		pSharedTexture->m_eTexType = eSharedTexType_EnvMapAlpha; 
		return LT_OK;
	}

	//Environment mapping with a bumpmap texture
	parse.Init(pTextureData->m_Header.m_CommandString);
	if (parse.ParseFind("EnvBumpMap", LTFALSE, 2)) 
	{
        //validate the argument count
        if(parse.m_nArgs < 3)
        {
            if(parse.m_nArgs < 2)
            {
		        RETURN_ERROR_PARAM(1, r_LoadSystemTexture, LT_INVALIDDATA, "EnvBumpMap : parse.m_Args[1]"); 
            }

		    RETURN_ERROR_PARAM(1, r_LoadSystemTexture, LT_INVALIDDATA, "EnvBumpMap : parse.m_Args[2]"); 
        }

		//handle loading up the environment map first
		ref.m_FileType = FILE_CLIENTFILE;
		ref.m_pFilename = parse.m_Args[1];
		pSharedTexture->SetLinkedTexture(eLinkedTex_EnvMap, g_pClientMgr->AddSharedTexture(&ref));

		//now handle loading up the bumpmap
		ref.m_FileType = FILE_CLIENTFILE;
		ref.m_pFilename = parse.m_Args[2];
		pSharedTexture->SetLinkedTexture(eLinkedTex_BumpMap, g_pClientMgr->AddSharedTexture(&ref));

		//setup the shader type
		pSharedTexture->m_eTexType = eSharedTexType_EnvBumpMap; 
		return LT_OK;
	}

	//Environment mapping with a bumpmap texture but no fallback
	parse.Init(pTextureData->m_Header.m_CommandString);
	if (parse.ParseFind("EnvBumpMapNoFallback", LTFALSE, 2)) 
	{

        //validate the argument count
        if(parse.m_nArgs < 3)
        {
            if(parse.m_nArgs < 2)
            {
		        RETURN_ERROR_PARAM(1, r_LoadSystemTexture, LT_INVALIDDATA, "EnvBumpMapNoFallback : parse.m_Args[1]"); 
            }

		    RETURN_ERROR_PARAM(1, r_LoadSystemTexture, LT_INVALIDDATA, "EnvBumpMapNoFallback : parse.m_Args[2]"); 
        }

		//handle loading up the environment map first
		ref.m_FileType = FILE_CLIENTFILE;
		ref.m_pFilename = parse.m_Args[1];
		pSharedTexture->SetLinkedTexture(eLinkedTex_EnvMap, g_pClientMgr->AddSharedTexture(&ref));

		//now handle loading up the bumpmap
		ref.m_FileType = FILE_CLIENTFILE;
		ref.m_pFilename = parse.m_Args[2];
		pSharedTexture->SetLinkedTexture(eLinkedTex_BumpMap, g_pClientMgr->AddSharedTexture(&ref));

		//setup the shader type
		pSharedTexture->m_eTexType = eSharedTexType_EnvBumpMap_NoFallback; 
		return LT_OK;
	}


	//DOT3 bumpmap texture
	parse.Init(pTextureData->m_Header.m_CommandString);
	if (parse.ParseFind("DOT3BumpMap", LTFALSE, 1)) 
	{

		//validate the argument count
		if(parse.m_nArgs < 2)
		{
			RETURN_ERROR_PARAM(1, r_LoadSystemTexture, LT_INVALIDDATA, "DOT3BumpMap : parse.m_Args[1]"); 
		}


		//now handle loading up the bumpmap
		ref.m_FileType = FILE_CLIENTFILE;
		ref.m_pFilename = parse.m_Args[1];
		pSharedTexture->SetLinkedTexture(eLinkedTex_BumpMap, g_pClientMgr->AddSharedTexture(&ref));

		//setup the shader type
		pSharedTexture->m_eTexType = eSharedTexType_DOT3BumpMap; 
		return LT_OK;
	}



	//Environment mapping with a DOT3 bumpmap texture but no fallback
	parse.Init(pTextureData->m_Header.m_CommandString);
	if (parse.ParseFind("DOT3EnvBumpMap", LTFALSE, 2)) 
	{

        //validate the argument count
        if(parse.m_nArgs < 3)
        {
            if(parse.m_nArgs < 2)
            {
		        RETURN_ERROR_PARAM(1, r_LoadSystemTexture, LT_INVALIDDATA, "DOT3EnvBumpMap : parse.m_Args[1]"); 
            }

		    RETURN_ERROR_PARAM(1, r_LoadSystemTexture, LT_INVALIDDATA, "DOT3EnvBumpMap : parse.m_Args[2]"); 
        }

		//handle loading up the environment map first
		ref.m_FileType = FILE_CLIENTFILE;
		ref.m_pFilename = parse.m_Args[1];
		pSharedTexture->SetLinkedTexture(eLinkedTex_EnvMap, g_pClientMgr->AddSharedTexture(&ref));

		//now handle loading up the bumpmap
		ref.m_FileType = FILE_CLIENTFILE;
		ref.m_pFilename = parse.m_Args[2];
		pSharedTexture->SetLinkedTexture(eLinkedTex_BumpMap, g_pClientMgr->AddSharedTexture(&ref));

		//setup the shader type
		pSharedTexture->m_eTexType = eSharedTexType_DOT3EnvBumpMap; 
		return LT_OK;
	}


	//Effect File Support
	parse.Init(pTextureData->m_Header.m_CommandString);
	if (parse.ParseFind("Effect", LTFALSE, 1)) 
	{
		//validate the argument count
		if(parse.m_nArgs < 2)
		{
			RETURN_ERROR_PARAM(1, r_LoadSystemTexture, LT_INVALIDDATA, "Effect : parse.m_Args[1]"); 
		}

		// Set up our shader ID
		pSharedTexture->m_nShaderID = (int)atoi(parse.m_Args[1]);
		pSharedTexture->m_eTexType = eSharedTexType_Effect;

		if(parse.m_nArgs > 2)
		{
			ref.m_FileType = FILE_CLIENTFILE;
			ref.m_pFilename = parse.m_Args[2];
			pSharedTexture->SetLinkedTexture(eLinkedTex_EffectTexture1, g_pClientMgr->AddSharedTexture(&ref));
			pSharedTexture->m_eTexType = eSharedTexType_Effect;
		}

		if(parse.m_nArgs > 3)
		{
			ref.m_FileType = FILE_CLIENTFILE;
			ref.m_pFilename = parse.m_Args[3];
			pSharedTexture->SetLinkedTexture(eLinkedTex_EffectTexture2, g_pClientMgr->AddSharedTexture(&ref));
			pSharedTexture->m_eTexType = eSharedTexType_Effect;
		}

		if(parse.m_nArgs > 4)
		{
			ref.m_FileType = FILE_CLIENTFILE;
			ref.m_pFilename = parse.m_Args[4];
			pSharedTexture->SetLinkedTexture(eLinkedTex_EffectTexture3, g_pClientMgr->AddSharedTexture(&ref));
			pSharedTexture->m_eTexType = eSharedTexType_Effect;
		}

		if(parse.m_nArgs > 5)
		{
			ref.m_FileType = FILE_CLIENTFILE;
			ref.m_pFilename = parse.m_Args[5];
			pSharedTexture->SetLinkedTexture(eLinkedTex_EffectTexture4, g_pClientMgr->AddSharedTexture(&ref));
			pSharedTexture->m_eTexType = eSharedTexType_Effect;
		}

		return LT_OK;
	}

	//just a normal texture...
	return LT_OK;
}
Beispiel #9
0
LTBOOL CGameButeMgr::Parse(const char* sButeFile)
{
	// Sanity checks...

    if (!sButeFile)	return(LTFALSE);


	BOOL bRet = TRUE;


	//if there is no g_pLTBase, then we can't read from the stream
	if (!g_pLTBase || !m_bInRezFile)
	{

		// Append the GAME directory onto the filename if this file is normally
		// stored in the .rez file...

		if (m_bInRezFile)
		{
			m_strAttributeFile.Format("Game\\%s", sButeFile);
		}
		else
		{
			m_strAttributeFile.Format("%s", sButeFile);
		}


		if (m_pCryptKey)
		{
			bRet = m_buteMgr.Parse(m_strAttributeFile, m_pCryptKey);
		}
		else
		{
			bRet = m_buteMgr.Parse(m_strAttributeFile);
		}

		return bRet;
	}


	// Open the file...

	m_strAttributeFile = sButeFile;

    ILTStream* pDStream = LTNULL;

    LTRESULT dr = g_pLTBase->OpenFile(m_strAttributeFile, &pDStream);

    if (dr != LT_OK || !pDStream)
	{
		char sError[512];
		sprintf(sError,"ERROR CGameButeMgr couldn't open file %s!",m_strAttributeFile);
		GBM_DisplayError(sError);

#ifdef _CLIENTBUILD
        g_pLTClient->ShutdownWithMessage(sError);
#endif
		return(FALSE);
	}


	// Read the file...

	unsigned long uLen = pDStream->GetLen();

	char* pData = debug_newa(char, uLen);
	if (!pData)
	{
		pDStream->Release();
		GBM_DisplayError("ERROR CGameButeMgr couldn't allocate data for stream.");
		return(FALSE);
	}

	pDStream->Read(pData, uLen);


	// Setup the save file name.  This is for saving the attribute file from
	// the game and is ONLY used during development...

	CString strSaveFilename = "";

#ifndef _FINAL

	strSaveFilename = sButeFile;

	if (m_bInRezFile)
	{
		strSaveFilename.Format("Game\\%s", sButeFile);
	}

#endif // _FINAL


	// Parse the file...

	if (m_pCryptKey)
	{
		bRet = m_buteMgr.Parse(pData, uLen, m_pCryptKey, strSaveFilename);
	}
	else
	{
		bRet = m_buteMgr.Parse(pData, uLen, 0, strSaveFilename);
	}


	// Clean up...

	pDStream->Release();
	debug_deletea(pData);


	// Check for an error...

	if (!bRet)
	{
		TRACE("ERROR CGameButeMgr::Parse() (%s)!\n", sButeFile);
		return(FALSE);
	}


	// All done...

	return(TRUE);
}
LTBOOL CGameButeMgr::Parse(ILTCSBase *pInterface, const char* sButeFile)
{
	// Sanity checks...

    if (!sButeFile)	return(LTFALSE);


	BOOL bRet = TRUE;

	// NOTE!!! When _REZFILE is defined, this code will need to be 
	// updated to support being called from DEdit!!!!
	// (from a IObjectPlugin::PreHook_EditStringList() call)...

#if !defined(_REZFILE)

	// If we're going to allow the bute file to be saved by the game, it must
	// be read in from a file (not a .rez file)...

	// Append the NOLF directory onto the filename if this file is normally
	// stored in the .rez file...

	if (m_bInRezFile)
	{
		m_strAttributeFile.Format("NOLF\\%s", sButeFile);
	}
	else
	{
		m_strAttributeFile.Format("%s", sButeFile);
	}


	if (m_pCryptKey)
	{
		bRet = m_buteMgr.Parse(m_strAttributeFile, m_pCryptKey);
	}
	else
	{
		bRet = m_buteMgr.Parse(m_strAttributeFile);
	}

	return bRet;

#endif  // !_REZFILE

	m_strAttributeFile = sButeFile;

	// Open the file...

	char sConstFile[256];
	strncpy(sConstFile, sButeFile, 255);

    ILTStream* pDStream;

    LTRESULT dr = pInterface->OpenFile(sConstFile, &pDStream);

    if (dr != LT_OK)
	{
		char sError[512];
		sprintf(sError,"ERROR CGameButeMgr couldn't open file %s!",sButeFile);
		GBM_DisplayError(sError);

#ifdef _CLIENTBUILD
        g_pLTClient->ShutdownWithMessage(sError);
#endif
		return(FALSE);
	}


	// Read the file...

	unsigned long uLen = pDStream->GetLen();

	char* pData = debug_newa(char, uLen);
	if (!pData)
	{
		pDStream->Release();
		GBM_DisplayError("CGameButeMgr couldn't allocate data for stream.");
		return(FALSE);
	}

	pDStream->Read(pData, uLen);


	// Parse the file...

	if (m_pCryptKey)
	{
		bRet = m_buteMgr.Parse(pData, uLen, m_pCryptKey);
	}
	else
	{
		bRet = m_buteMgr.Parse(pData, uLen);
	}


	// Clean up...

	pDStream->Release();
	debug_deletea(pData);


	// Check for an error...

	if (!bRet)
	{
		TRACE("CGameButeMgr::Parse() ERROR!\n");
		return(FALSE);
	}


	// All done...

	return(TRUE);
}
Beispiel #11
0
uint32 GetWorldTextureInfo(CPreWorld *pWorld, CGLinkedList<TInfo*> &theList)
{
	GPOS			pos;
	CPreSurface		*pSurface;
	uint32			nFlagsGotten;
	TInfo			*pFlags;
	char			fileName[MAX_PATH];
	ILTStream		*pStream;
	TextureData		*pData;

	char			pszTextureName[MAX_PATH];

	nFlagsGotten = 0;

	for(pos=pWorld->m_Surfaces; pos; )
	{
		pSurface = pWorld->m_Surfaces.GetNext(pos);
	
		for(uint32 nCurrTex = 0; nCurrTex < CPreSurface::NUM_TEXTURES; nCurrTex++)
		{
			CPreTexture& Tex = pSurface->m_Texture[nCurrTex];

			if(!Tex.IsValid())
				continue;

			pFlags = FindTInfo(theList, Tex.m_pTextureName);
			if(pFlags)
			{
				++nFlagsGotten;
			}
			else
			{
				//see if this is a sprite
				if(CSpriteFile::IsSprite(Tex.m_pTextureName))
				{
					//build up the sprite filename
					sprintf(fileName, "%s\\%s", g_pGlobs->m_ProjectDir, Tex.m_pTextureName);

					//open up the file
					CSpriteFile Sprite;

					if(!Sprite.Load(fileName))
						continue;

					if(Sprite.GetNumFrames() > 0)
					{
						//read in the first string
						strcpy(pszTextureName, Sprite.GetFrame(0));
					}
				}
				else
				{
					//we have a texture, so lets copy it over
					strcpy(pszTextureName, Tex.m_pTextureName);
				}

				sprintf(fileName, "%s\\%s", g_pGlobs->m_ProjectDir, pszTextureName);
				
				pStream = streamsim_Open(fileName, "rb");
				if(pStream)
				{
					if(dtx_Create(pStream, &pData, TRUE, TRUE) == DE_OK)
					{
						pFlags = new TInfo;
						pFlags->m_Width = pData->m_Header.m_BaseWidth;
						pFlags->m_Height = pData->m_Header.m_BaseHeight;
						pFlags->m_pTextureName = (char*)Tex.m_pTextureName;
						pFlags->m_Flags = (uint16)pData->m_Header.m_UserFlags;
						theList.Append(pFlags);
						
						++nFlagsGotten;
						dtx_Destroy(pData);
					}
				
					pStream->Release();
				}
			}
		}
	}

	return nFlagsGotten;
}