コード例 #1
0
ファイル: fileinterface.cpp プロジェクト: bargle/SympEngine
BaseFile* FileInterface::OpenFile(const char* szFilename, EFileType eType, EFileFlags eFlags)
{
	switch(eType)
	{
	case BINARY_FILE:
		{
			BinaryFile* pFile = new BinaryFile;
			if(pFile)
			{
				GEN_RESULT res = pFile->Open(szFilename, eFlags);
				if(RESULT_OK == res)
				{
					return (BaseFile*)pFile;
				}
			}
		}
		break;
	case TEXT_FILE:
		{
			//TODO:
		}
		break;
	default:
		break;
	}

	return NULL;
}
コード例 #2
0
/**
 *
 *  @author OLiver
 */
bool Savegame::Save(const std::string& filename)
{
    BinaryFile file;

    if(!file.Open(filename, OFM_WRITE))
        return false;

    bool ret = Save(file);

    file.Close();

    return ret;
}
コード例 #3
0
/**
 *
 *  @author OLiver
 */
bool Savegame::Load(const std::string& filePath, const bool load_players, const bool load_sgd)
{
    BinaryFile file;

    if(!file.Open(filePath, OFM_READ))
        return false;

    bool ret = Load(file, load_players, load_sgd);

    file.Close();

    return ret;
}
コード例 #4
0
    bool AssimpModelImporter::ConvertToPyrosFormat(const std::string &Filename)
    {
        BinaryFile *bin = new BinaryFile();

        if (bin->Open(Filename.c_str(), 'w')) 
        {
        // Save Materials
        int32 materialsSize = materials.size();
        bin->Write(&materialsSize, sizeof(int32));
        for (std::vector<MaterialProperties>::iterator i=materials.begin();i!=materials.end();i++)
        {
            // Material ID
            bin->Write(&(*i).id,sizeof(int32));

            // Material Name
            int32 nameSize = (*i).Name.size();
            bin->Write(&nameSize,sizeof(int32));
            if (nameSize>0)
                bin->Write((*i).Name.c_str(),sizeof(char)*nameSize);

            // Color
            uchar Out = (uchar)(*i).haveColor;
            bin->Write(&Out, sizeof(uchar));

            bin->Write(&(*i).Color, sizeof(Vec4));

            // Specular
            Out = (uchar)(*i).haveSpecular;
            bin->Write(&Out, sizeof(uchar));

            bin->Write(&(*i).Specular, sizeof(Vec4));

            // Ambient
            Out = (uchar)(*i).haveAmbient;
            bin->Write(&Out, sizeof(uchar));

            bin->Write(&(*i).Ambient, sizeof(Vec4));

            // Emissive
            Out = (uchar)(*i).haveEmissive;
            bin->Write(&Out, sizeof(uchar));

            bin->Write(&(*i).Emissive, sizeof(Vec4));

            // WireFrame
            Out = (uchar)(*i).WireFrame;
            bin->Write(&Out, sizeof(uchar));

            // Twosided
            Out = (uchar)(*i).Twosided;
            bin->Write(&Out, sizeof(uchar));

            // Opacity
            bin->Write(&(*i).Opacity,sizeof(f32));

            // Shininess
            bin->Write(&(*i).Shininess,sizeof(f32));

            // Shininess Strength
            bin->Write(&(*i).ShininessStrength,sizeof(f32));

            // Textures
            // Color Map
            Out = (uchar)(*i).haveColorMap;
            bin->Write(&Out, sizeof(uchar));

            int32 colorMapSize = (*i).colorMap.size();
            bin->Write(&colorMapSize,sizeof(int32));
            if (colorMapSize>0)
                bin->Write((*i).colorMap.c_str(),sizeof(char)*colorMapSize);

            // Specular Map
            Out = (uchar)(*i).haveSpecularMap;
            bin->Write(&Out, sizeof(uchar));

            int32 specularMapSize = (*i).specularMap.size();
            bin->Write(&specularMapSize,sizeof(int32));
            if (specularMapSize>0)
                bin->Write((*i).specularMap.c_str(),sizeof(char)*specularMapSize);

            // Normal Map
            Out = (uchar)(*i).haveNormalMap;
            bin->Write(&Out, sizeof(uchar));
            
            int32 normalMapSize = (*i).normalMap.size();
            bin->Write(&normalMapSize,sizeof(int32));
            if (normalMapSize>0)
                bin->Write((*i).normalMap.c_str(),sizeof(char)*normalMapSize);

            // Have Bones
            Out = (uchar)(*i).haveBones;
            bin->Write(&Out, sizeof(uchar));
        }

        // Skeleton
        int32 skeletonSize = skeleton.size();
        bin->Write(&skeletonSize,sizeof(int32));
        if (skeletonSize>0)
        {
            // Write ids
            for (std::map<uint32, Bone>::iterator i=skeleton.begin();i!=skeleton.end();i++)
            {
                bin->Write(&(*i).first, sizeof(uint32));

                // Name
                int32 nameSize = (*i).second.name.size();
                bin->Write(&nameSize,sizeof(int32));
                if (nameSize>0)
                    bin->Write((*i).second.name.c_str(),sizeof(char)*nameSize);

                // Self
                bin->Write(&(*i).second.self, sizeof(int32));

                // Parent
                bin->Write(&(*i).second.parent, sizeof(int32));

                // Pos
                bin->Write(&(*i).second.pos, sizeof(Vec3));

                // Rot
                bin->Write(&(*i).second.rot, sizeof(Quaternion));

                // Scale
                bin->Write(&(*i).second.scale, sizeof(Vec3));

                // BindPose
                bin->Write(&(*i).second.bindPoseMat.m[0], sizeof(Matrix));

                // Skinned
                uchar Out = (uchar)(*i).second.skinned;
                bin->Write(&Out, sizeof(uchar));
            }
        }

        // SubMeshes
        int32 subMeshesSize = subMeshes.size();
        bin->Write(&subMeshesSize, sizeof(int32));
        for (std::vector<SubMesh>::iterator i=subMeshes.begin();i!=subMeshes.end();i++)
        {
            // Name
            int32 nameSize = (*i).Name.size();
            bin->Write(&nameSize,sizeof(int32));
            if (nameSize>0)
                bin->Write((*i).Name.c_str(),sizeof(char)*nameSize);

            // Index
            int32 indexSize = (*i).tIndex.size();
            bin->Write(&indexSize,sizeof(int32));
            if (indexSize>0)
                bin->Write(&(*i).tIndex[0], sizeof(int32)*indexSize);

            // Vertex
            int32 vertexSize = (*i).tVertex.size();
            bin->Write(&vertexSize,sizeof(int32));
            if (vertexSize>0)
                bin->Write(&(*i).tVertex[0], sizeof(Vec3)*vertexSize);

            // Normal
            int32 normalSize = (*i).tNormal.size();
            bin->Write(&normalSize,sizeof(int32));
            if (normalSize>0)
                bin->Write(&(*i).tNormal[0], sizeof(Vec3)*normalSize);

            // Tangent
            int32 tangentSize = (*i).tTangent.size();
            bin->Write(&tangentSize,sizeof(int32));
            if (tangentSize>0)
            {
                bin->Write(&(*i).tTangent[0], sizeof(Vec3)*tangentSize);
                bin->Write(&(*i).tBitangent[0], sizeof(Vec3)*tangentSize);
            }

            // Texcoord
            int32 texcoordSize = (*i).tTexcoord.size();
            bin->Write(&texcoordSize, sizeof(int32));
            if (texcoordSize>0)
                bin->Write(&(*i).tTexcoord[0], sizeof(Vec2)*texcoordSize);

            // Vertex Color
            int32 vertexColorSize = (*i).tVertexColor.size();
            bin->Write(&vertexColorSize, sizeof(int32));
            if (vertexColorSize>0)
                bin->Write(&(*i).tVertexColor[0], sizeof(Vec4)*vertexColorSize);

            // Bones
            int32 BonesSize = (*i).tBonesID.size();
            bin->Write(&BonesSize, sizeof(int32));
            if (BonesSize>0)
            {
                bin->Write(&(*i).tBonesID[0], sizeof(Vec4)*BonesSize);
                bin->Write(&(*i).tBonesWeight[0], sizeof(Vec4)*BonesSize);
            }

            // Map Bones IDs
            int32 MapBoneIDsSize = (*i).MapBoneIDs.size();
            bin->Write(&MapBoneIDsSize, sizeof(int32));
            if (MapBoneIDsSize>0)
            {
                // Copy Index
                for (std::map<int32,int32>::iterator k=(*i).MapBoneIDs.begin();k!=(*i).MapBoneIDs.end();k++)
                {
                    bin->Write(&(*k).first, sizeof(int32));
                    bin->Write(&(*k).second, sizeof(int32));
                }
            }

            // Offset Matrix
            int32 BoneOffsetMatrixSize = (*i).BoneOffsetMatrix.size();
            bin->Write(&BoneOffsetMatrixSize, sizeof(int32));
            if (BoneOffsetMatrixSize>0)
            {
                // Copy Index
                for (std::map<int32,Matrix>::iterator k=(*i).BoneOffsetMatrix.begin();k!=(*i).BoneOffsetMatrix.end();k++)
                {
                    bin->Write(&(*k).first, sizeof(int32));
                    bin->Write(&(*k).second.m[0], sizeof(Matrix));
                }
            }

            // Material ID
            bin->Write(&(*i).materialID, sizeof(int32));
        }

        bin->Close();

        delete bin;

        return true;
        } else return false;
    }
コード例 #5
0
ファイル: Savegame.cpp プロジェクト: vader1986/s25client
bool Savegame::Load(const std::string& filePath, const bool load_players, const bool load_sgd)
{
    BinaryFile file;

    return file.Open(filePath, OFM_READ) && Load(file, load_players, load_sgd);
}
コード例 #6
0
ファイル: Savegame.cpp プロジェクト: vader1986/s25client
bool Savegame::Save(const std::string& filename)
{
    BinaryFile file;

    return file.Open(filename, OFM_WRITE) &&  Save(file);
}