示例#1
0
bool CD3DSkelMesh::Load_MP(ILTStream& File)
{
	// Read in out Min/Max Bones (effecting this guy)...
	File.Read(&m_iMinBone,sizeof(m_iMinBone));
	File.Read(&m_iMaxBone,sizeof(m_iMaxBone));

	// What type of Vert do we need?
	switch (m_iMaxBonesPerVert)
	{
	case 2  : m_VertType = eINDEXED_B1; break;
	case 3  : m_VertType = eINDEXED_B2; break;
	case 4  : m_VertType = eINDEXED_B3; break;
	default : assert(0); return false;
	}

	// If we are using re-indexed bones, read them in...
	if (m_bReIndexedBones)
	{
		uint32 iBoneCount = 0;
		File.Read(&iBoneCount,sizeof(iBoneCount));
		assert(iBoneCount < 10000 && "Crazy bone count, checked your packed model format.");
		LT_MEM_TRACK_ALLOC(m_pReIndexedBoneList = new uint32[iBoneCount],LT_MEM_TYPE_RENDERER);
		File.Read(m_pReIndexedBoneList,sizeof(uint32)*iBoneCount);
	}

	// Read in our Verts...
	for (uint32 i=0;i<4;++i)
	{
		if (!m_VertStreamFlags[i])
			continue;

		uint32 iVertexSize	= 0;									// Figure out the vertex size...
		uint32 iVertFlags	= 0;
		uint32 iUVSets		= 0;
		GetVertexFlags_and_Size(m_VertType,m_VertStreamFlags[i],iVertFlags,iVertexSize,iUVSets,m_bNonFixPipeData);

		uint32 iSize = iVertexSize * m_iVertCount;					// Alloc the VertData...
		LT_MEM_TRACK_ALLOC(m_pVertData[i] = new uint8[iSize],LT_MEM_TYPE_RENDERER);
		File.Read(m_pVertData[i],iSize);
	}

	// Read in pIndexList...
	LT_MEM_TRACK_ALLOC(m_pIndexData = new uint8[sizeof(uint16) * m_iPolyCount * 3],LT_MEM_TYPE_RENDERER);
	File.Read(m_pIndexData,sizeof(uint16) * m_iPolyCount * 3);

	// Create the VBs and stuff...
	ReCreateObject();

	return true;
}
示例#2
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;
}
示例#3
0
bool CD3DSkelMesh::Load_RD(ILTStream& File)
{
	// What type of Vert do we need?
	switch (m_iMaxBonesPerTri)
	{
	case 1  : m_VertType = eNO_WORLD_BLENDS; break;
	case 2  : m_VertType = eNONINDEXED_B1; break;
	case 3  : m_VertType = eNONINDEXED_B2; break;
	case 4  : m_VertType = eNONINDEXED_B3; break;
	default : assert(0); return false;
	}

	// Read in our Verts...
	for (uint32 i=0;i<4;++i)
	{
		if (!m_VertStreamFlags[i]) continue;

		uint32 iVertexSize	= 0;									// Figure out the vertex size...
		uint32 iVertFlags	= 0;
		uint32 iUVSets		= 0;
		GetVertexFlags_and_Size(m_VertType,m_VertStreamFlags[i],iVertFlags,iVertexSize,iUVSets,m_bNonFixPipeData);

		uint32 iSize = iVertexSize * m_iVertCount;					// Alloc the VertData...
		LT_MEM_TRACK_ALLOC(m_pVertData[i] = new uint8[iSize],LT_MEM_TYPE_RENDERER);
		File.Read(m_pVertData[i],iSize);
	}

	// Read in pIndexList...
	LT_MEM_TRACK_ALLOC(m_pIndexData = new uint8[sizeof(uint16) * m_iPolyCount * 3],LT_MEM_TYPE_RENDERER);
	File.Read(m_pIndexData,sizeof(uint16) * m_iPolyCount * 3);

	// Allocate and read in the BoneSets...
	File.Read(&m_iBoneSetCount,sizeof(m_iBoneSetCount));
	LT_MEM_TRACK_ALLOC(m_pBoneSetArray = new BoneSetListItem[m_iBoneSetCount],LT_MEM_TYPE_RENDERER);
	if (!m_pBoneSetArray)
		return false;
	File.Read(m_pBoneSetArray,sizeof(BoneSetListItem)*m_iBoneSetCount);

	// Create the VBs and stuff...
	ReCreateObject();

	return true;
}
示例#4
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);
}
示例#5
0
bool CD3DSkelMesh::Load(ILTStream& File, LTB_Header& LTBHeader)
{
	if (LTBHeader.m_iFileType != LTB_D3D_MODEL_FILE)
	{
		OutputDebugString("Error: Wrong file type in CD3DSkelMesh::Load\n");
		return false;
	}
	if (LTBHeader.m_iVersion  != CD3D_LTB_LOAD_VERSION)
	{
		OutputDebugString("Error: Wrong file version in CD3DSkelMesh::Load\n");
		return false;
	}

	// Read in the basics...
	uint32 iObjSize; File.Read(&iObjSize,sizeof(iObjSize));
	File.Read(&m_iVertCount,sizeof(m_iVertCount));
	File.Read(&m_iPolyCount,sizeof(m_iPolyCount));
	File.Read(&m_iMaxBonesPerTri,sizeof(m_iMaxBonesPerTri));
	File.Read(&m_iMaxBonesPerVert,sizeof(m_iMaxBonesPerVert));
	File.Read(&m_bReIndexedBones,sizeof(m_bReIndexedBones));
	File.Read(&m_VertStreamFlags[0],sizeof(uint32)*4);

	// Are we using Matrix Palettes...
	bool bUseMatrixPalettes;
	File.Read(&bUseMatrixPalettes,sizeof(bUseMatrixPalettes));

	if (bUseMatrixPalettes)
	{
		m_eRenderMethod = eD3DRenderMatrixPalettes;
		return Load_MP(File);
	}
	else
	{
		m_eRenderMethod = eD3DRenderDirect;
		return Load_RD(File);
	}
}
//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;
}
示例#7
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);
}
/* IStream methods */
STDMETHODIMP CLTDMFileStream::Read( void* pv, ULONG cb, ULONG* pcbRead )
{
#ifdef USE_DSTREAM

	// make sure our file item pointer is valid
	if (m_pOpenQueueItem == NULL) 
	{
		return E_FAIL;
	}

	// make sure the file is open and get a pointer to the ILTStream
	ILTStream* pLTStream = m_pOpenQueueItem->LockDStream();
	if (pLTStream == LTNULL)
	{
		return E_FAIL;
	}

	// read in the data
	if (pLTStream->Read( pv, cb) != LT_OK)
	{
		m_pOpenQueueItem->UnLockDStream();
		return E_FAIL;
	}

	// set the number of bytes read
	if (pcbRead != NULL) *pcbRead = cb;

	m_pOpenQueueItem->UnLockDStream();

	return S_OK;
#endif

#ifdef USE_REZMGR
	// if the loader doesn't exist fail
	if (m_pLoader == NULL) 
	{
		LTDMConOutError("LTDirectMusic loader failed to read from file because no directmusic loader exists\n");
		return E_FAIL;
	}

	m_pLoader->EnterRezMgrCriticalSection();

	// if the rezmgr is not open
	if (!m_pLoader->GetRezMgr()->IsOpen()) 
	{
		LTDMConOutError("LTDirectMusic loader failed to read from file because rez file was not open\n");
		m_pLoader->LeaveRezMgrCriticalSection();
		return E_FAIL;
	}

	// variable to hold the actual number of bytes that were read in when read is called
	size_t nBytesRead;

	// read the data from the rez file
	nBytesRead = m_pRezItem->Read(pv, cb, m_nCurPos);

	// advance seek pos
	m_nCurPos += nBytesRead;

	// return OK if we read all of the requested data
	if(cb == nBytesRead) 
	{
		// set the number of bytes read callback if it is not NULL
		if(pcbRead != NULL)*pcbRead = nBytesRead;

		m_pLoader->LeaveRezMgrCriticalSection();
		return S_OK;
	}

	// if we didn't read all of the data fail
	else
	{
		m_pLoader->LeaveRezMgrCriticalSection();
		return E_FAIL;
	}

	m_pLoader->LeaveRezMgrCriticalSection();
#endif

#ifdef USE_FILE
	size_t dw;
	dw = fread( pv, sizeof(char), cb, m_pFile );
	if( cb == dw )
	{
		if( pcbRead != NULL )
		{
			*pcbRead = cb;
		}
		return S_OK;
	}
	return E_FAIL ;
#endif
}
bool CD3DVAMesh::Load(ILTStream& File, LTB_Header& LTBHeader)
{
	if (LTBHeader.m_iFileType != LTB_D3D_MODEL_FILE)
	{
		OutputDebugString("Error: Wrong file type in CD3DSkelMesh::Load\n");
		return false;
	}
	if (LTBHeader.m_iVersion  != CD3D_LTB_LOAD_VERSION)
	{
		OutputDebugString("Error: Wrong file version in CD3DSkelMesh::Load\n");
		return false;
	}

	// Read in the basics...
	uint32 iObjSize; File.Read(&iObjSize,sizeof(iObjSize));
	File.Read(&m_iVertCount,sizeof(m_iVertCount));
	File.Read(&m_iUnDupVertCount,sizeof(m_iUnDupVertCount));
	File.Read(&m_iPolyCount,sizeof(m_iPolyCount));
	File.Read(&m_iMaxBonesPerTri,sizeof(m_iMaxBonesPerTri));
	File.Read(&m_iMaxBonesPerVert,sizeof(m_iMaxBonesPerVert));
	File.Read(&m_VertStreamFlags[0],sizeof(uint32)*4);
	File.Read(&m_iAnimNodeIdx,sizeof(m_iAnimNodeIdx));
	File.Read(&m_iBoneEffector,sizeof(m_iBoneEffector));

	// Read in our Verts...
	for (uint32 i=0;i<4;++i)
	{
		if (!m_VertStreamFlags[i]) continue;

		uint32 iVertexSize	= 0;									// Figure out the vertex size...
		uint32 iVertFlags	= 0;
		uint32 iUVSets		= 0;
		GetVertexFlags_and_Size(eNO_WORLD_BLENDS,m_VertStreamFlags[i],iVertFlags,iVertexSize,iUVSets,m_bNonFixPipeData);

		uint32 iSize = iVertexSize * m_iVertCount;					// Alloc the VertData...
		LT_MEM_TRACK_ALLOC(m_pVertData[i] = new uint8[iSize],LT_MEM_TYPE_RENDERER);
		File.Read(m_pVertData[i],iSize);
	}

	// Read in pIndexList...
	LT_MEM_TRACK_ALLOC(m_pIndexData = new uint8[sizeof(uint16) * m_iPolyCount * 3],LT_MEM_TYPE_RENDERER);
	File.Read(m_pIndexData,sizeof(uint16) * m_iPolyCount * 3);

	// Read in m_pDupMapList...
	File.Read(&m_iDupMapListCount,sizeof(m_iDupMapListCount)); assert(m_iDupMapListCount < 1000000 && "Invalid VA VertData");
	LT_MEM_TRACK_ALLOC(m_pDupMapList = new DupMap[m_iDupMapListCount],LT_MEM_TYPE_RENDERER);
	File.Read(m_pDupMapList,sizeof(DupMap) * m_iDupMapListCount);

	// Create the VBs and stuff...
	ReCreateObject();

	return true;
}