Ejemplo n.º 1
0
    void DiMeshSerializerImpl::ReadSubMesh( DiDataStreamPtr& stream, DiMesh* pMesh )
    {
        DI_SERIAL_LOG("Reading submesh..");

        DiSubMesh* sm = pMesh->CreateSubMesh();

        unsigned short streamID = 0;

        DiString material = ReadString(stream);
        sm->SetMaterialName(material);

        DI_SERIAL_LOG("Liking material: %s", material.c_str());

        unsigned int indexCount = 0;
        ReadInts(stream, &indexCount, 1);

        DI_SERIAL_LOG("Indeices count: %d", indexCount);

        bool idx32bit;
        ReadBools(stream, &idx32bit, 1);

        DI_SERIAL_LOG("Index size: %d", idx32bit?32:16);

        uint16 primitive;
        ReadShorts(stream,&primitive,1);
        sm->SetPrimitiveType((DiPrimitiveType)primitive);

        DI_SERIAL_LOG("Primitive type: %d", primitive);

        if (indexCount > 0)
        {
            void* indexdata = sm->CreateIndexData(indexCount,idx32bit?TRUE:FALSE);
            int size = indexCount * (sm->GetIndexSize() / 8);
            stream->Read(indexdata, size);
            DI_SERIAL_LOG("%d bytes readed", size);
        }

        streamID = ReadChunk(stream);
        if (streamID != DI_GEOMETRY)
        {
            DI_ERROR("Bad stream ID");
            return;
        }

        ReadGeometry(stream, sm);

        if (!stream->Eof())
        {
            streamID = ReadChunk(stream);
            if (streamID == DI_MESH_WEIGHTS)
            {
                ReadSubMeshBoneWeights(stream,sm);
            }
            else
            {
                if (!stream->Eof())
                    stream->Skip(-MSTREAM_OVERHEAD_SIZE);
            }
        }
    }
Ejemplo n.º 2
0
bool MeshLoaderB3D::Load(const char* file) {
	_file = new lfFile;
	if( !_file->Open(file) )
		return false;

	_mesh = new Mesh;
	lfStr head = ReadChunk();
	int nB3DVersion = _file->ReadInt();

	Sys_Printf("load b3d file %s, version %s %d\n", file, head.c_str(), nB3DVersion);

	while( CheckSize() ) {
		lfStr t = ReadChunk();
		if (t == "TEXS")
			ReadTexs();
		else if (t == "BRUS")
			ReadBrus();
		else if (t == "NODE")
			_mesh->SetJoint(ReadNode());

		ExitChunk();
	}

	delete _file;
	_file = NULL;

	// The MESH chunk describes a mesh. 
	// A mesh only has one VRTS chunk, but potentially many TRIS chunks.
	srfTriangles_t* tri = _mesh->GetGeometries(0);
	tri->numIndices = _indices.size();
	_indices.set_free_when_destroyed(false);
	tri->indices = _indices.pointer();

	return true;
}
Ejemplo n.º 3
0
    void DiMotionSerializerImpl::ImportMotion( DiDataStreamPtr& stream, DiMotion* pDest )
    {
        ReadFileHeader(stream);

        if (!stream->Eof())
        {
            uint16 streamID = ReadChunk(stream);
            while(!stream->Eof() &&
                (streamID == DI_SKELETON ||
                streamID == DI_POSE ||
                streamID == DI_ANIMATION))
            {
                switch(streamID)
                {
                case DI_SKELETON:
                    ReadSkeleton(stream,pDest);
                    break;

                case DI_ANIMATION:
                    ReadAnimations(stream, pDest);
                    break;

                case DI_POSE:
                    ReadPoses(stream,pDest);
                    break;
                }

                if (!stream->Eof())
                    streamID = ReadChunk(stream);

            }
            if (!stream->Eof())
                stream->Skip(-MSTREAM_OVERHEAD_SIZE);
        }
    }
Ejemplo n.º 4
0
bool L3DS::FindChunk(LChunk &target, const LChunk &parent)
{
    if (Pos() >= parent.end)
        return false;
    LChunk chunk;
    chunk = ReadChunk();
    while (( chunk.id != target.id) && (chunk.end <= parent.end))
    {
        SkipChunk(chunk);
        if (chunk.end >= parent.end)
            break;
        unsigned short id = chunk.id;
        uint end = chunk.end;
        chunk = ReadChunk();
        // try to detect a endless loop amz
        if(id == chunk.id && end == chunk.end)
            break;
    }
    if (chunk.id == target.id)
    {
        target.start = chunk.start;
        target.end = chunk.end;
        return true;
    }
    return false;
}
Ejemplo n.º 5
0
    void DiMeshSerializerImpl::ImportMesh( DiDataStreamPtr& stream, DiMesh* pMesh )
    {
        ReadFileHeader(stream);

        if (!stream->Eof())
        {
            uint16 streamID = ReadChunk(stream);
            while(!stream->Eof() &&
                (
                streamID == DI_SUBMESH ||
                streamID == DI_MESH_BOUNDS))
            {
                switch(streamID)
                {
                case DI_SUBMESH:
                    ReadSubMesh(stream, pMesh);
                    break;

                case DI_MESH_BOUNDS:
                    ReadBoundsInfo(stream, pMesh);
                    break;
                }

                if (!stream->Eof())
                {
                    streamID = ReadChunk(stream);
                }

            }
            if (!stream->Eof())
            {
                stream->Skip(-MSTREAM_OVERHEAD_SIZE);
            }
        }
    }
Ejemplo n.º 6
0
void L3DS::ReadCamera(const LChunk &parent)
{
    LVector3 v,t;
    LCamera camera;
    camera.SetName(m_objName);
    v.x = ReadFloat();
    v.y = ReadFloat();
    v.z = ReadFloat();
    t.x = ReadFloat();
    t.y = ReadFloat();
    t.z = ReadFloat();
    camera.SetPosition(v);
    camera.SetTarget(t);
    camera.SetBank(ReadFloat());
    camera.SetFOV(2400.0f/ReadFloat());
    LChunk chunk = ReadChunk();
    while (chunk.end <= parent.end)
    {
        switch (chunk.id)
        {
        case CAM_RANGES:
            camera.SetNearplane(ReadFloat());
            camera.SetFarplane(ReadFloat());
            break;
        default:
            break;
        }
        SkipChunk(chunk);
        if (chunk.end >= parent.end)
            break;
        chunk = ReadChunk();

    }
    m_cameras.push_back(camera);
}
Ejemplo n.º 7
0
void L3DS::ReadFaceList(const LChunk &chunk, LMesh &mesh)
{
    // variables 
    unsigned short count, t;    
    uint i;
    LTri tri;
    LChunk ch;
    char str[20];
    //uint mat;

    // consistency checks
    if (chunk.id != TRI_FACELIST)
    {
        ErrorMsg("L3DS::ReadFaceList - internal error: wrong chunk passed as parameter");
        return;
    }
    GotoChunk(chunk);
    tri.smoothingGroups = 1;
    // read the number of faces
    count = ReadShort();
    mesh.SetTriangleArraySize(count);
    for (i=0; i<count; i++)
    {
        tri.a = ReadShort();
        tri.b = ReadShort();
        tri.c = ReadShort();
        ReadShort();
        mesh.SetTri(tri, i);
    }
    // now read the optional chunks
    ch = ReadChunk();
    int mat_id;
    while (ch.end <= chunk.end)
    {
        switch (ch.id)
        {
        case TRI_MAT_GROUP:
            ReadASCIIZ(str, 20);
			mat_id=0;
			if (FindMaterial(str)!=NULL)
				mat_id = FindMaterial(str)->GetID();
            mesh.AddMaterial(mat_id);
            count = ReadShort();
            for (i=0; i<count; i++) 
            {
                t = ReadShort();
                mesh.GetTri(t).materialId = mat_id;
            }                
            break;
        case TRI_SMOOTH_GROUP:
            for (i=0; i<mesh.GetTriangleCount(); i++)
                mesh.GetTri(i).smoothingGroups = (ulong) ReadInt();
            break;
        }
        SkipChunk(ch);
        ch = ReadChunk();
    }
}
Ejemplo n.º 8
0
void L3DS::ReadLight(const LChunk &parent)
{
    float t;
    LVector3 v;
    LLight light;
    light.SetName(m_objName);
    v.x = ReadFloat();
    v.y = ReadFloat();
    v.z = ReadFloat();
    light.SetPosition(v);
    LChunk chunk = ReadChunk();
    while (chunk.end <= parent.end)
    {
        switch (chunk.id)
        {
        case COLOR_24:
        case COLOR_F:
        case LIN_COLOR_F:
        case LIN_COLOR_24:
            light.SetColor(ReadColor(chunk));
            break;
        case SPOTLIGHT:
            v.x = ReadFloat();
            v.y = ReadFloat();
            v.z = ReadFloat();
            light.SetTarget(v);
            t = ReadFloat();
            light.SetHotspot(t);
            t = ReadFloat();
            light.SetFalloff(t);
            break;
        case LIT_INRANGE:
            light.SetAttenuationstart(ReadFloat());
            break;
        case LIT_OUTRANGE:
            light.SetAttenuationend(ReadFloat());
            break;
        default:
            break;
        }
        SkipChunk(chunk);
        if (chunk.end >= parent.end)
            break;
        chunk = ReadChunk();

    }
    m_lights.push_back(light);
}
Ejemplo n.º 9
0
bool CLeadingPropCoder::DeCode_EffectUnitProp( const CDataChunk& inData , OBJ_HANDLE handle )
{
	CLeadingProp* pEffectUnitProp = (CLeadingProp*)(handle);
	CBufFile tData( inData.GetBuffer(), inData.GetSize() );
	tData.SafeRead( (char*)&pEffectUnitProp->m_eTextOp,				sizeof(SPR_BLENDOP) );
	tData.SafeRead( (char*)&pEffectUnitProp->m_JumpSpeed,				sizeof(int32) );
	tData.SafeRead( (char*)&pEffectUnitProp->m_JumpNum,				sizeof(int32) );
	tData.SafeRead( (char*)&pEffectUnitProp->m_eLType,				sizeof(CLeadingProp::eLP_LKType) );
	tData.SafeRead( (char*)&pEffectUnitProp->m_eSSType,				sizeof(CLeadingProp::eLP_StartScr) );

	tData.SafeRead( (char*)&pEffectUnitProp->m_fStartAngle,			sizeof(float) );
	tData.SafeRead( (char*)&pEffectUnitProp->m_fRotSpeed,				sizeof(float) );
	tData.SafeRead( (char*)&pEffectUnitProp->m_fUVSpeed,				sizeof(float) );
	tData.SafeRead( (char*)&pEffectUnitProp->m_nPieceCount,			sizeof(uint32) );
	tData.SafeRead( (char*)&pEffectUnitProp->m_nDouCount,				sizeof(uint32) );
	tData.SafeRead( (char*)&pEffectUnitProp->m_fDouPercent,			sizeof(float) );
	tData.SafeRead( (char*)&pEffectUnitProp->m_fDouInterval,			sizeof(float) );

	tData.SafeRead( (char*)&pEffectUnitProp->m_eBlendModel,			sizeof(SPR_BLENDMODE) );
	tData.SafeRead( (char*)&pEffectUnitProp->m_eZTest,				sizeof(Z_TEST) );
	tData.SafeRead( (char*)&pEffectUnitProp->m_bLightEnable,			sizeof(BOOL) );
	tData.SafeRead( (char*)&pEffectUnitProp->m_fZBias,				sizeof(float) );
	CDataChunk tChunk;
	tData.SafeRead(&tChunk.GetHdr(),sizeof(CDataChunk::ChunkHdr));
	ReadChunk(tData,tChunk);
	_DoDecode(tChunk,pEffectUnitProp);
	return true;
}
Ejemplo n.º 10
0
bool CSpritePropCoder::DeCode_EffectUnitProp( const CDataChunk& inData , OBJ_HANDLE handle )
{
	CSpriteProp* pEffectUnitProp = (CSpriteProp*)(handle);
	CBufFile tData( inData.GetBuffer(), inData.GetSize() );

	tData.SafeRead(&pEffectUnitProp->m_BirthTime,				sizeof(int) );
	tData.SafeRead(&pEffectUnitProp->m_DeleteTime,			sizeof(int) );
	tData.SafeRead(&pEffectUnitProp->m_eTextOp,				sizeof(SPR_BLENDOP) );
	LoadMapValueSafe( tData, pEffectUnitProp->m_UVRCenter );
	LoadMapValueSafe( tData, pEffectUnitProp->m_XYZcale );
	tData.SafeRead(&pEffectUnitProp->m_fStartAngle,			sizeof(float) );
	tData.SafeRead(&pEffectUnitProp->m_fWidthRatio,			sizeof(float) );
	tData.SafeRead(&pEffectUnitProp->m_fZBias,				sizeof(float) );
	tData.SafeRead(&pEffectUnitProp->m_vecRotate,				sizeof(CVector3f) );
	tData.SafeRead(&pEffectUnitProp->m_vecNormal,				sizeof(CVector3f) );
	tData.SafeRead(&pEffectUnitProp->m_fMinSize,				sizeof(float) );
	tData.SafeRead(&pEffectUnitProp->m_fMaxSize,				sizeof(float) );
	tData.SafeRead(&pEffectUnitProp->m_eFaceType,				sizeof(SPR_FACE) );
	tData.SafeRead(&pEffectUnitProp->m_eBlendModel,			sizeof(SPR_BLENDMODE) );
	tData.SafeRead(&pEffectUnitProp->m_eZTest,				sizeof(Z_TEST) );
	tData.SafeRead(&pEffectUnitProp->m_bLightEnable,			sizeof(BOOL) );

	pEffectUnitProp->CaculateProp();
	CDataChunk tChunk;
	tData.SafeRead(&tChunk.GetHdr(),sizeof(CDataChunk::ChunkHdr));
	ReadChunk(tData,tChunk);
	_DoDecode(tChunk,pEffectUnitProp);
	return true;
}
void C3DSLoader::ReadNextObjChunk(t3DModel *pModel, t3DObject *pObject, tChunk *pPreChunk)   
{      
	int buffer[50000] = {0};              
	m_CurrentChunk = new tChunk;   
  
	while (pPreChunk->bytesRead < pPreChunk->length)   
	{      
		ReadChunk(m_CurrentChunk);   
  
		switch (m_CurrentChunk->ID)   
		{   
		case OBJ_MESH:                   
			ReadNextObjChunk(pModel, pObject, m_CurrentChunk);   
			break;   
		case OBJ_VERTICES:             
			ReadVertices(pObject, m_CurrentChunk);   
			break;   
		case OBJ_FACES:                  
			ReadVertexIndices(pObject, m_CurrentChunk);   
			break;   
		case OBJ_MATERIAL:              
			ReadObjMat(pModel, pObject, m_CurrentChunk);               
			break;   
		case OBJ_UV:                      
			ReadUVCoordinates(pObject, m_CurrentChunk);   
			break;   
		default:     
			m_CurrentChunk->bytesRead += fread(buffer, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer);   
			break;   
		}      
		pPreChunk->bytesRead += m_CurrentChunk->bytesRead;   
	}   
	delete m_CurrentChunk;   
	m_CurrentChunk = pPreChunk;   
}   
Ejemplo n.º 12
0
/* 0 if adpcm, -1 otherwise */
static int ac_isWAVEadpcm(void *data, UNUSED(ALuint size), int encoding) {
    alWaveFMT_LOKI *format;
    Chunk riffchunk = { 0, 0, 0 };
    int offset = 12;

    do {
        ReadChunk(data, &offset, &riffchunk);
    } while ((riffchunk.magic == WAVE) ||
             (riffchunk.magic == RIFF));

    if(riffchunk.magic != FMT) {
        return -1;
    }

    format = (alWaveFMT_LOKI *) riffchunk.data;

    if(swap16le(format->encoding) == encoding) {
        return 0;
    }

#ifdef DEBUG_CONVERT
    fprintf(stderr, "encoding | format->enc %d|%d\n",
            format->encoding, encoding);
#endif

    return -1;
}
Ejemplo n.º 13
0
bool CPolyTrailPropCoder::DeCode_EffectUnitProp( const CDataChunk& inData , OBJ_HANDLE handle )
{
	CPolyTrailProp* pEffectUnitProp = (CPolyTrailProp*)(handle);
	CBufFile tData( inData.GetBuffer(), inData.GetSize() );

	tData.SafeRead(&pEffectUnitProp->m_eTextOp,				sizeof(SPR_BLENDOP));
	tData.SafeRead(&pEffectUnitProp->m_fRefractIndex, sizeof(float));
	tData.SafeRead(&pEffectUnitProp->m_DeclTime,				sizeof(int32) );
	tData.SafeRead(&pEffectUnitProp->m_Smooth,				sizeof(int32) );
	tData.SafeRead(&pEffectUnitProp->m_sRefSkelatal,			sizeof(IDNAME) );
	tData.SafeRead(&pEffectUnitProp->m_bSingleSide,			sizeof(BOOL) ); 
	tData.SafeRead(&pEffectUnitProp->m_eStrip,				sizeof(POLY_TRAIL_TYPE) );
	tData.SafeRead(&pEffectUnitProp->m_vecRotate,				sizeof(CVector3f) );
	tData.SafeRead(&pEffectUnitProp->m_MinTrailWidth,			sizeof(float) );
	tData.SafeRead(&pEffectUnitProp->m_MaxTrailWidth,			sizeof(float) );
	tData.SafeRead(&pEffectUnitProp->m_UnitLifeSpan,			sizeof(int32) );
	tData.SafeRead(&pEffectUnitProp->m_eBlendModel,			sizeof(SPR_BLENDMODE) );
	tData.SafeRead(&pEffectUnitProp->m_eZTest,				sizeof(Z_TEST) );
	tData.SafeRead(&pEffectUnitProp->m_bLightEnable,			sizeof(BOOL) );
	CDataChunk tChunk;
	tData.SafeRead(&tChunk.GetHdr(),sizeof(CDataChunk::ChunkHdr));
	ReadChunk(tData,tChunk);
	_DoDecode(tChunk,pEffectUnitProp);
	return true;
}
Ejemplo n.º 14
0
/*----------------------------------------------------------------------
|       main
+---------------------------------------------------------------------*/
int
main(int /*argc*/, char** /*argv*/)
{
    // setup debugging
#if defined(WIN32) && defined(_DEBUG)
    int flags = _crtDbgFlag       |
                _CRTDBG_ALLOC_MEM_DF      |
                _CRTDBG_DELAY_FREE_MEM_DF |
                _CRTDBG_CHECK_ALWAYS_DF;

    _CrtSetDbgFlag(flags);
    //AllocConsole();
    //freopen("CONOUT$", "w", stdout);
#endif

    NPT_RingBuffer buffer(BUFFER_SIZE);

    for (int i=0; i<100000000; i++) {
        if (NPT_FAILED(WriteChunk(buffer))) {
            printf("WriteChunk failed\n");
            return 1;
        }
        if (NPT_FAILED(ReadChunk(buffer))) {
            printf("ReadChunk failed\n");
            return 1;
        }
    }

    printf("RingBufferTest1 passed\n");

    return 0;
}
Ejemplo n.º 15
0
void C3DSLoader::ReadObjectChunk(tChunk& pObjectChunk,C3DMesh& pMesh)
{
	//get a fresh working chunk
	tChunk currentChunk={0};

	//read the sub chunks until we find the end of the parent chunk
	while(pObjectChunk.bytesRead < pObjectChunk.length)
	{
		//Read the next chunk
		ReadChunk(currentChunk);

		switch(currentChunk.ID)
		{
		case OBJECT_MESH:					
		
			// We found a new object, so let's read in it's info using recursion
			ReadTrimeshChunk(currentChunk,pMesh);
			break;
		default:
			currentChunk.bytesRead+=fread(m_iBuffer,1,currentChunk.length-currentChunk.bytesRead,m_FilePointer);
			break;
		}//end switch
 
		//Just read and discard unknown or unwanted chunks
		pObjectChunk.bytesRead+=currentChunk.bytesRead;
	}//end while

}//end ReadObjectChunk
Ejemplo n.º 16
0
void Programmer::VerifyMainBlock(const std::string& hexfilename, const bool ignoreCheck)
{
	// is MainBlock readback disabled?
	if (!ignoreCheck  &&  !CanReadMainBlock())
		throw std::string("MainBlock readback is disabled by the target configuration.");

	ProgressBar pb("Verifying");
	
	FlashMemory flash(flashSize);
	flash.LoadHex(hexfilename);		// read the HEX file
	
	FlashMemory verifyFlash(flashSize);

	int address = 0;
	while (address < flashSize)
	{
		ReadChunk(false, verifyFlash, address);

		address += PROG_CHUNK_SIZE;

		// update the progress bar
		pb.Refresh(address / double(flashSize));
	}

	// now compare
	if (flash != verifyFlash)
	{
		//flash.SaveHex("orig.hex");
		//verifyFlash.SaveHex("verif.hex");
		throw std::string("MainBlock verification failed.");
	}
}
Ejemplo n.º 17
0
//////////////////////////////////////////////////////////////////
//加载模型
bool CLoad3DS::Import3DS(t3DModel *pModel, char *strFileName)
{
	char strMessage[255] = {0};

	m_FilePointer = fopen(strFileName, "rb");

	if(!m_FilePointer) 
	{
		sprintf(strMessage, "Unable to find the file: %s!", strFileName);
		MessageBox(NULL, strMessage, "Error", MB_OK);
		return false;
	}

	ReadChunk(m_CurrentChunk);

	if (m_CurrentChunk->ID != PRIMARY)
	{ 
		sprintf(strMessage, "Unable to load PRIMARY chuck from file: %s!", strFileName);
		MessageBox(NULL, strMessage, "Error", MB_OK);
		return false;
	}

	ReadNextChunk(pModel, m_CurrentChunk);

	ComputeNormals(pModel);

	return true;
}
Ejemplo n.º 18
0
bool CLightningPropCoder::DeCode_EffectUnitProp( const CDataChunk& inData , OBJ_HANDLE handle )
{
	CLightningProp* pEffectUnitProp = (CLightningProp*)(handle);
	CBufFile tData( inData.GetBuffer(), inData.GetSize() );

	tData.SafeRead(&pEffectUnitProp->m_vecRotate,				sizeof(CVector3f) );
	tData.SafeRead(&pEffectUnitProp->m_vecNormal,				sizeof(CVector3f) );
	tData.SafeRead(&pEffectUnitProp->m_fStartAngle,			sizeof(float) );
	tData.SafeRead(&pEffectUnitProp->m_fWidthRatio,			sizeof(float) );
	tData.SafeRead(&pEffectUnitProp->m_fMinSize,				sizeof(float) );
	tData.SafeRead(&pEffectUnitProp->m_fMaxSize,				sizeof(float) );
	tData.SafeRead(&pEffectUnitProp->m_vecSrc,				sizeof(CVector3f) );
	tData.SafeRead(&pEffectUnitProp->m_fDitherMax,			sizeof(float) );
	tData.SafeRead(&pEffectUnitProp->m_fDitherMin,			sizeof(float) );
	tData.SafeRead(&pEffectUnitProp->m_nSubNum,				sizeof(int) );
	tData.SafeRead(&pEffectUnitProp->m_eFaceType,				sizeof(SPR_FACE) );
	tData.SafeRead(&pEffectUnitProp->m_eBlendModel,			sizeof(SPR_BLENDMODE) );
	tData.SafeRead(&pEffectUnitProp->m_eZTest,				sizeof(Z_TEST) );
	tData.SafeRead(&pEffectUnitProp->m_bLightEnable,			sizeof(BOOL) );
	tData.SafeRead(&pEffectUnitProp->m_fZBias,				sizeof(float) );
	CDataChunk tChunk;
	tData.SafeRead(&tChunk.GetHdr(),sizeof(CDataChunk::ChunkHdr));
	ReadChunk(tData,tChunk);
	_DoDecode(tChunk,pEffectUnitProp);
	return true;
}
Ejemplo n.º 19
0
bool CModelRenderStylePropCoder::DeCode_EffectUnitProp( const CDataChunk& inData , OBJ_HANDLE handle )
{
	CModelRenderStyleProp* pEffectUnitProp = (CModelRenderStyleProp*)(handle);
	CBufFile tData( inData.GetBuffer(), inData.GetSize() );
	LoadMapValueSafe(tData, pEffectUnitProp->m_ClipDistMap);
	tData.SafeRead(&pEffectUnitProp->m_ClipPlane.originPlane, sizeof(CPlane));
	pEffectUnitProp->CaculateProp();
	int32 n = 0;
	tData.SafeRead( (char*)&n,						sizeof(int32) );
	pEffectUnitProp->m_ApplyClass.resize(n);
	for( int32 i = 0; i < n; ++i )
		LoadStringSafeT( tData, pEffectUnitProp->m_ApplyClass[i] );
	tData.SafeRead(&pEffectUnitProp->m_SpecularColor,			sizeof(CColor) );
	tData.SafeRead(&pEffectUnitProp->m_vecTextMoveVel,		sizeof(CVector2f) );
	tData.SafeRead(&pEffectUnitProp->m_fTextAngularVel,		sizeof(float) );
	tData.SafeRead(&pEffectUnitProp->m_bDiffuseAmbient,		sizeof(BOOL) );
	tData.SafeRead(&pEffectUnitProp->m_bSpecular,				sizeof(BOOL) );
	tData.SafeRead(&pEffectUnitProp->m_bSetTextureMatrix,		sizeof(BOOL) );
	
	CDataChunk tChunk;
	tData.SafeRead(&tChunk.GetHdr(),sizeof(CDataChunk::ChunkHdr));
	ReadChunk(tData,tChunk);
	_DoDecode(tChunk,pEffectUnitProp);
	return true;
}
Ejemplo n.º 20
0
void AGG::Cache::LoadOrgICN(Sprite & sp, const ICN::icn_t icn, const u16 index, bool reflect)
{
    std::vector<u8> body;

    if(ReadChunk(ICN::GetString(icn), body))
    {
	// loading original
	DEBUG(DBG_ENGINE, DBG_TRACE, "AGG::Cache::LoadOrgICN: " << ICN::GetString(icn) << ", " << index);

	const u16 count = ReadLE16(&body[0]);
	ICN::Header header1, header2;

	header1.Load(&body[6 + index * ICN::Header::SizeOf()]);
	if(index + 1 != count) header2.Load(&body[6 + (index + 1) * ICN::Header::SizeOf()]);

	const u32 size_data = (index + 1 != count ? header2.OffsetData() - header1.OffsetData() :
				    // total size
				    ReadLE32(&body[2]) - header1.OffsetData());

	sp.Set(header1.Width(), header1.Height(), ICN::RequiresAlpha(icn));
	sp.SetOffset(header1.OffsetX(), header1.OffsetY());
	sp.SetColorKey();
	Sprite::DrawICN(sp, &body[6 + header1.OffsetData()], size_data, reflect);
	Sprite::AddonExtensionModify(sp, icn, index);
    }
    else
	Error::Except("AGG::Cache::LoadOrgICN: ReadChunk: ", ICN::GetString(icn));
}
Ejemplo n.º 21
0
// lock file, test for CAPS header type
int CCapsLoader::Lock(PCAPSFILE pcf)
{
	// close previous file
	Unlock();

	// open file
	if (file.Open(pcf)) {
		Unlock();
		return ccidErrFile;
	}

	// set read mode
	readmode=(pcf->flag & CFF_WRITE) ? false : true;

	// get file size, no file skip
	flen=file.GetSize();

	// check for caps id
	if (ReadChunk(true) != ccidFile) {
		Unlock();
		return ccidErrType;
	}

	return ccidCaps;
}
Ejemplo n.º 22
0
__regargs PaletteT *LoadPalette(const char *filename) {
  PaletteT *palette = NULL;
  IffFileT iff;

  if (OpenIff(&iff, filename)) {
    if (iff.header.type == ID_ILBM) {
      while (ParseChunk(&iff)) {
        switch (iff.chunk.type) {
          case ID_CMAP:
            palette = NewPalette(iff.chunk.length / sizeof(ColorT));
            ReadChunk(&iff, palette->colors);
            break;

          default:
            SkipChunk(&iff);
            break;
        }
      }
    }

    CloseIff(&iff);
  }

  return palette;
}
Ejemplo n.º 23
0
/* load TIL object to AGG::Cache */
void AGG::Cache::LoadTIL(const TIL::til_t til)
{
    til_cache_t & v = til_cache[til];

    if(v.sprites) return;

    DEBUG(DBG_ENGINE , DBG_INFO, "AGG::Cache::LoadTIL: " << TIL::GetString(til));

    std::vector<u8> body;

    if(ReadChunk(TIL::GetString(til), body))
    {
	const u16 count = ReadLE16(&body.at(0));
	const u16 width = ReadLE16(&body.at(2));
	const u16 height= ReadLE16(&body.at(4));

	const u32 tile_size = width * height;
	const u32 body_size = 6 + count * tile_size;

	// check size
	if(body.size() != body_size)
	{
	    DEBUG(DBG_ENGINE , DBG_WARN, "AGG::Cache::LoadTIL: size mismach, skipping...");
	    return;
	}

	v.count = count * 4;  // rezerve for rotate sprites
	v.sprites = new Surface [v.count];

	for(u16 ii = 0; ii < count; ++ii)
	    v.sprites[ii].Set(&body[6 + ii * tile_size], width, height, 1, false);
    }
}
Ejemplo n.º 24
0
void CLoad3DS::ReadColorChunk(mo3DSMaterialInfo *pMaterial, tChunk *pChunk, int colortype)
{
    // Read the color chunk info
    ReadChunk(m_TempChunk);

	switch(colortype) {
		case MAT_DIFFUSE_COLOR:                        // This holds the R G B color of our object
			m_TempChunk->bytesRead += fread(pMaterial->colorDiffuse, 1, m_TempChunk->length - m_TempChunk->bytesRead, m_FilePointer);
            break;

		case MAT_AMBIENT_COLOR:
			m_TempChunk->bytesRead += fread(pMaterial->colorAmbient, 1, m_TempChunk->length - m_TempChunk->bytesRead, m_FilePointer);
			break;

		case MAT_SPECULAR_COLOR:
			m_TempChunk->bytesRead += fread(pMaterial->colorSpecular, 1, m_TempChunk->length - m_TempChunk->bytesRead, m_FilePointer);
			break;
		// Read in the R G B color(3 bytes - 0 through 255)
		default:
			break;
	}

    // Add the bytes read to our chunk
    pChunk->bytesRead += m_TempChunk->bytesRead;
}
void CLoad3DS::ReadColorChunk(tMaterialInfo *pMaterial, tChunk *pChunk)
{

	ReadChunk(m_TempChunk);
	m_TempChunk->bytesRead += ASSET_READ(pMaterial->color, 1, m_TempChunk->length - m_TempChunk->bytesRead, m_FilePointer);
	pChunk->bytesRead += m_TempChunk->bytesRead;
}
Ejemplo n.º 26
0
/* load XMI object to AGG::Cache */
void AGG::Cache::LoadMID(const XMI::xmi_t xmi)
{
    std::vector<u8> & v = mid_cache[xmi];

    if(v.size()) return;

    DEBUG(DBG_ENGINE , DBG_INFO, "AGG::Cache::LoadMID: " << XMI::GetString(xmi));

    if(! Mixer::isValid()) return;

    std::vector<u8> body;

    if(ReadChunk(XMI::GetString(xmi), body))
    {
	MIDI::Xmi x;
	MIDI::Mid m;
	MIDI::MTrk track;

	x.Read(body);
	track.ImportXmiEVNT(x.EVNT());

	m.AddTrack(track);
	m.SetPPQN(64);

	m.Write(v);
    }
}
bool C3DSLoader::Import3DS(t3DModel *pModel, char *strFileName)   
{      
	char strMessage[255] = {0};   

	m_FilePointer = fopen(strFileName, "rb");   

	if(!m_FilePointer)    
	{      
		sprintf(strMessage, "%s!", strFileName);   
		return false;   
	}   

	ReadChunk(m_CurrentChunk);   

	if (m_CurrentChunk->ID != PRIMARY)   
	{      
		return false;   
	}   

	ReadNextChunk(pModel, m_CurrentChunk);   
 
	ComputeNormals(pModel);   

	CleanUp();   

	return true;   
}   
Ejemplo n.º 28
0
FileInfo * VFSPlugin_LWO::Read(unsigned char *buffer, unsigned int length)
{
	m_offset	= 0;
	m_buffer	= buffer;
	m_length	= length;

	m_fileinfo					=	new MeshFileInfo();
	m_fileinfo->mesh			=	fusion->Mesh->CreateMesh();
	m_fileinfo->filelength	=	m_length;

	//	Read the FORM tag
	if(ReadLong() != ID_FORM)	return NULL;

	//	Read the entire data size
	long chunklen = ReadLong()-4;

	//	Read the LWO2 tag
	if(ReadLong() != ID_LWO2)	return NULL;

	//	Read chunks
	while(chunklen > 0)	chunklen -= ReadChunk();

	//	Process Surface (turn it into a useable mesh)
	ProcessSurface();

	//	Return a ptr to the file info
	return m_fileinfo;	
}
void C3DSLoader::ReadNextMatChunk(t3DModel *pModel, tChunk *pPreChunk)   
{      
	int buffer[50000] = {0};         
	m_CurrentChunk = new tChunk;  
	while (pPreChunk->bytesRead < pPreChunk->length)   
	{      
		ReadChunk(m_CurrentChunk);   
		switch (m_CurrentChunk->ID)   
		{   
		case MATNAME:                      
			m_CurrentChunk->bytesRead += fread(pModel->pMaterials[pModel->numOfMaterials - 1].strName, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer);   
			break;   
		case MATDIFFUSE:                         
			ReadColor(&(pModel->pMaterials[pModel->numOfMaterials - 1]), m_CurrentChunk);   
			break;   
		case MATMAP:                           
			ReadNextMatChunk(pModel, m_CurrentChunk);   
			break;   
		case MATMAPFILE:                       
			m_CurrentChunk->bytesRead += fread(pModel->pMaterials[pModel->numOfMaterials - 1].strFile, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer);   
			break;   
		default:      
			m_CurrentChunk->bytesRead += fread(buffer, 1, m_CurrentChunk->length - m_CurrentChunk->bytesRead, m_FilePointer);   
			break;   
		}     
		pPreChunk->bytesRead += m_CurrentChunk->bytesRead;   
	}   
	delete m_CurrentChunk;   
	m_CurrentChunk = pPreChunk;   
}   
Ejemplo n.º 30
0
   std::shared_ptr<ByteBuffer> 
   File::ReadFile()
   {
      int iFileSize = GetSize();

      return ReadChunk(iFileSize);
   }