//---------------------------------------------------------------------------- bool Lattice::Load (FileIO& inFile) { int numBytes = (int)strlen(msHeader) + 1; char* buffer = new1<char>(numBytes); inFile.Read(sizeof(char), numBytes, buffer); buffer[numBytes-1] = 0; if (strncmp(buffer, msHeader, numBytes) != 0) { delete1(buffer); mNumDimensions = 0; mQuantity = 0; mBounds = 0; mOffsets = 0; return false; } delete1(buffer); inFile.Read(sizeof(int), &mNumDimensions); delete1(mBounds); mBounds = new1<int>(mNumDimensions); inFile.Read(sizeof(int), mNumDimensions, mBounds); delete1(mOffsets); mOffsets = new1<int>(mNumDimensions); ComputeQuantityAndOffsets(); return true; }
bool Delaunay<Real>::Load (FileIO& inFile) { delete1(mIndices); delete1(mAdjacencies); // Fixed-size members. int type; inFile.Read(sizeof(int), &type); mQueryType = (Query::Type)type; inFile.Read(sizeof(int), &mNumVertices); inFile.Read(sizeof(int), &mDimension); inFile.Read(sizeof(int), &mNumSimplices); inFile.Read(sizeof(Real), &mEpsilon); // Variable-size members. int numIndices; inFile.Read(sizeof(int), &numIndices); if (1 <= mDimension && mDimension <= 3) { assertion(numIndices == (mDimension+1)*mNumSimplices, "Inconsistent index count\n"); mIndices = new1<int>(numIndices); mAdjacencies = new1<int>(numIndices); inFile.Read(sizeof(int), numIndices, mIndices); inFile.Read(sizeof(int), numIndices, mAdjacencies); return true; } mIndices = 0; mAdjacencies = 0; return mDimension == 0; }
//---------------------------------------------------------------------------- void VertexBufferAccessor::Read (FileIO& inFile) { 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) { inFile.Read(table[j][1], table[j][2], vertex + table[j][0]); } } }
//---------------------------------------------------------------------------- void VertexBufferAccessor::Read (FileIO& inFile) { 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); } // Read 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) { inFile.Read(table[j][1], table[j][2], vertex + table[j][0]); } } }
// --------------------------------------------------------------------------- // スナップショット復元 // bool WinCore::LoadShapshot(const char* filename, const char* diskname) { LockObj lock(this); FileIO file; if (!file.Open(filename, FileIO::readonly)) return false; SnapshotHeader ssh; if (file.Read(&ssh, sizeof(ssh)) != sizeof(ssh)) return false; if (memcmp(ssh.id, SNAPSHOT_ID, 16)) return false; if (ssh.major != ssmajor || ssh.minor > ssminor) return false; // applyconfig const uint fl1a = Config::subcpucontrol | Config::fullspeed | Config::enableopna | Config::enablepcg | Config::fv15k | Config::cpuburst | Config::cpuclockmode | Config::digitalpalette | Config::opnona8 | Config::opnaona8 | Config::enablewait; const uint fl2a = Config::disableopn44; config.flags = (config.flags & ~fl1a) | (ssh.flags & fl1a); config.flag2 = (config.flag2 & ~fl2a) | (ssh.flag2 & fl2a); config.basicmode = ssh.basicmode; config.clock = ssh.clock; config.erambanks = ssh.erambanks; config.cpumode = ssh.cpumode; config.mainsubratio = ssh.mainsubratio; ApplyConfig(&config); // Reset PC88::Reset(); // 読み込み uint8* buf = new uint8[ssh.datasize]; bool r = false; if (buf) { bool read = false; if (ssh.flags & 0x80000000) { int32 csize; file.Read(&csize, 4); if (csize < 0) { csize = -csize; uint8* cbuf = new uint8[csize]; if (cbuf) { ulong bufsize = ssh.datasize; file.Read(cbuf, csize); read = uncompress(buf, &bufsize, cbuf, csize) == Z_OK; delete[] cbuf; } } } else read = file.Read(buf, ssh.datasize) == ssh.datasize; if (read) { r = devlist.LoadStatus(buf); if (r && diskname) { for (uint i=0; i<2; i++) { diskmgr->Unmount(i); diskmgr->Mount(i, diskname, false, ssh.disk[i], false); } } if (!r) { statusdisplay.Show(70, 3000, "バージョンが異なります"); PC88::Reset(); } } delete[] buf; } return r; }