Пример #1
0
//----------------------------------------------------------------------------
bool Lattice::Save (FileIO& outFile) const
{
    outFile.Write(sizeof(char), (int)strlen(msHeader) + 1, msHeader);
    outFile.Write(sizeof(int), &mNumDimensions);
    outFile.Write(sizeof(int), mNumDimensions, mBounds);
    return true;
}
Пример #2
0
// ---------------------------------------------------------------------------
//	スナップショット保存
//
bool WinCore::SaveShapshot(const char* filename)
{
	LockObj lock(this);

	bool docomp = !!(config.flag2 & Config::compresssnapshot);

	uint size = devlist.GetStatusSize();
	uint8* buf = new uint8[docomp ? size * 129 / 64 + 20 : size];
	if (!buf)
		return false;
	memset(buf, 0, size);

	if (devlist.SaveStatus(buf))
	{
		ulong esize = size * 129 / 64 + 20-4;
		if (docomp)
		{
			if (Z_OK != compress(buf+size+4, &esize, buf, size))
			{
				delete[] buf;
				return false;
			}
			*(int32*) (buf+size) = -(long)esize;
			esize += 4;
		}

		SnapshotHeader ssh;
		memcpy(ssh.id, SNAPSHOT_ID, 16);

		ssh.major = ssmajor;
		ssh.minor = ssminor;
		ssh.datasize = size;
		ssh.basicmode = config.basicmode;
		ssh.clock = int16(config.clock);
		ssh.erambanks = uint16(config.erambanks);
		ssh.cpumode = int16(config.cpumode);
		ssh.mainsubratio = int16(config.mainsubratio);
		ssh.flags = config.flags | (esize < size ? 0x80000000 : 0);
		ssh.flag2 = config.flag2;
		for (uint i=0; i<2; i++)
			ssh.disk[i] = (int8) diskmgr->GetCurrentDisk(i);

		FileIO file;
		if (file.Open(filename, FileIO::create))
		{
			file.Write(&ssh, sizeof(ssh));
			if (esize < size)
				file.Write(buf+size, esize);
			else
				file.Write(buf, size);
		}
	}
	delete[] buf;
	return true;
}
Пример #3
0
bool Delaunay<Real>::Save (FileIO& outFile) const
{
    // Fixed-size members.
    int type = (int)mQueryType;
    outFile.Write(sizeof(int), &type);

    outFile.Write(sizeof(int), &mNumVertices);
    outFile.Write(sizeof(int), &mDimension);
    outFile.Write(sizeof(int), &mNumSimplices);
    outFile.Write(sizeof(Real), &mEpsilon);

    // The member mOwner is not streamed because on a Load call, this
    // object will allocate the vertices and own this memory.

    // Variable-size members.
    int numIndices;
    if (1 <= mDimension && mDimension <= 3)
    {
        numIndices = (mDimension+1)*mNumSimplices;
        outFile.Write(sizeof(int), &numIndices);
        outFile.Write(sizeof(int), numIndices, mIndices);
        outFile.Write(sizeof(int), numIndices, mAdjacencies);
        return true;
    }

    numIndices = 0;
    outFile.Write(sizeof(int), &numIndices);
    return mDimension == 0;
}
Пример #4
0
//----------------------------------------------------------------------------
void Visual::SaveVertexBuffer (FileIO& outFile)
{
    int numElements = mVBuffer->GetNumElements();
    int elementSize = mVBuffer->GetElementSize();
    Buffer::Usage vbusage = mVBuffer->GetUsage();
    int usage = (int)vbusage;
    outFile.Write(sizeof(int), &numElements);
    outFile.Write(sizeof(int), &elementSize);
    outFile.Write(sizeof(int), &usage);

    VertexBufferAccessor vba(mVFormat, mVBuffer);
    vba.Write(outFile);
}
//----------------------------------------------------------------------------
void VertexBufferAccessor::Write (FileIO& outFile)
{
	assertion(mStride == mVBuffer->GetElementSize(),
		"Format stride and vertex size must match (for now).\n");

	// 为VertexBuffer的顶点属性建立一张表。每个顶点的属性都有offset,属性元素字
	// 节大小以及属性元素个数。举例来说,一个元素属性的offset为0,格式为AT_FLOAT3
	// 具有的(offset,size,numComponents) = (0,4,3)。
	Tuple<3, unsigned int> table[VertexFormat::AM_MAX_ATTRIBUTES];
	const int numAttributes = mVFormat->GetNumAttributes();
	unsigned int streamIndex, offset, index;
	VertexFormat::AttributeType type;
	VertexFormat::AttributeUsage usage;
	int j;
	for (j = 0; j < numAttributes; ++j)
	{
		mVFormat->GetAttribute(j, streamIndex, offset, type, usage, index);
		table[j][0] = offset;
		table[j][1] = VertexFormat::GetComponentSize(type);
		table[j][2] = VertexFormat::GetNumComponents(type);
	}

	// 将顶点持久化
	const int numElements = mVBuffer->GetNumElements();
	char* vertex = mData;
	for (int i = 0; i < numElements; ++i, vertex += mStride)
	{
		for (j = 0; j < numAttributes; ++j)
		{
			outFile.Write(table[j][1], table[j][2], vertex + table[j][0]);
		}
	}
}
Пример #6
0
//----------------------------------------------------------------------------
void VertexBufferAccessor::Write (FileIO& outFile)
{
	assertion(mStride == mVBuffer->GetElementSize(),
	          "Format stride and vertex size must match (for now).\n");

	// Build a table for the attributes of the vertex buffer.  Each attribute
	// has an offset, a size for a component of the attribute, and the number
	// of components of that size.  For example, an attribute with offset 0
	// and type AT_FLOAT3 has (offset,size,numComponents) = (0,4,3).
	Tuple<3, unsigned int> table[VertexFormat::AM_MAX_ATTRIBUTES];
	const int numAttributes = mVFormat->GetNumAttributes();
	unsigned int streamIndex, offset, index;
	VertexFormat::AttributeType type;
	VertexFormat::AttributeUsage usage;
	int j;
	for (j = 0; j < numAttributes; ++j)
	{
		mVFormat->GetAttribute(j, streamIndex, offset, type, usage, index);
		table[j][0] = offset;
		table[j][1] = VertexFormat::GetComponentSize(type);
		table[j][2] = VertexFormat::GetNumComponents(type);
	}

	// Write vertices one at a time to allow for byte swapping (endianness).
	const int numElements = mVBuffer->GetNumElements();
	char* vertex = mData;
	for (int i = 0; i < numElements; ++i, vertex += mStride)
	{
		for (j = 0; j < numAttributes; ++j)
		{
			outFile.Write(table[j][1], table[j][2], vertex + table[j][0]);
		}
	}
}
Пример #7
0
//----------------------------------------------------------------------------
void Visual::SaveVertexFormat (FileIO& outFile)
{
    int numAttributes = mVFormat->GetNumAttributes();
    outFile.Write(sizeof(int), &numAttributes);

    for (int i = 0; i < numAttributes; ++i)
    {
        unsigned int streamIndex, offset, usageIndex;
        VertexFormat::AttributeType vftype;
        VertexFormat::AttributeUsage vfusage;
        mVFormat->GetAttribute(i, streamIndex, offset, vftype, vfusage,
                               usageIndex);
        int type = (int)vftype;
        int usage = (int)vfusage;

        outFile.Write(sizeof(unsigned int), &streamIndex);
        outFile.Write(sizeof(unsigned int), &offset);
        outFile.Write(sizeof(int), &type);
        outFile.Write(sizeof(int), &usage);
        outFile.Write(sizeof(unsigned int), &usageIndex);
    }

    int stride = mVFormat->GetStride();
    outFile.Write(sizeof(int), &stride);
}
Пример #8
0
//----------------------------------------------------------------------------
void Visual::SaveIndexBuffer (FileIO& outFile)
{
    if (mIBuffer)
    {
        int numElements = mIBuffer->GetNumElements();
        int elementSize = mIBuffer->GetElementSize();
        Buffer::Usage ibusage = mIBuffer->GetUsage();
        int usage = (int)ibusage;
        int offset = mIBuffer->GetOffset();
        outFile.Write(sizeof(int), &numElements);
        outFile.Write(sizeof(int), &elementSize);
        outFile.Write(sizeof(int), &usage);
        outFile.Write(sizeof(int), &offset);

        outFile.Write(elementSize, mIBuffer->GetNumBytes()/elementSize,
                      mIBuffer->GetData());
    }
    else
    {
        int numElements = 0;
        outFile.Write(sizeof(int), &numElements);
    }
}