//----------------------------------------------------------------------------// int OggBuffer::vorbisSeek(void *datasource, ogg_int64_t offset, int whence) { size_t spaceToEOF; ogg_int64_t actualOffset; Ogre::DataStreamPtr vorbisData; vorbisData = *(Ogre::DataStreamPtr*)datasource; switch (whence) { case SEEK_SET: if (vorbisData->size() >= offset) actualOffset = offset; else actualOffset = vorbisData->size(); vorbisData->seek((int)actualOffset); break; case SEEK_CUR: spaceToEOF = vorbisData->size() - vorbisData->tell(); if (offset < spaceToEOF) actualOffset = (offset); else actualOffset = spaceToEOF; vorbisData->seek( static_cast<size_t>(vorbisData->tell() + actualOffset)); break; case SEEK_END: vorbisData->seek(vorbisData->size()); break; default: SoundSystem::getSingleton().logMessage("*** ERROR *** Unknown seek command in VorbisSeek"); break; }; return 0; }
int64_t FFmpeg_Decoder::seek(void *user_data, int64_t offset, int whence) { Ogre::DataStreamPtr stream = static_cast<FFmpeg_Decoder*>(user_data)->mDataStream; whence &= ~AVSEEK_FORCE; if(whence == AVSEEK_SIZE) return stream->size(); if(whence == SEEK_SET) stream->seek(offset); else if(whence == SEEK_CUR) stream->seek(stream->tell()+offset); else if(whence == SEEK_END) stream->seek(stream->size()+offset); else return -1; return stream->tell(); }
int64_t OgreResource_Seek(void *user_data, int64_t offset, int whence) { Ogre::DataStreamPtr stream = static_cast<VideoState*>(user_data)->stream; whence &= ~AVSEEK_FORCE; if(whence == AVSEEK_SIZE) return stream->size(); if(whence == SEEK_SET) stream->seek((size_t)offset); else if(whence == SEEK_CUR) stream->seek((size_t)(stream->tell() + offset)); else if(whence == SEEK_END) stream->seek((size_t)(stream->size() + offset)); else return -1; return stream->tell(); }
int OOSStreamSeek(void *datasource, ogg_int64_t offset, int whence) { Ogre::DataStreamPtr dataStream = *reinterpret_cast<Ogre::DataStreamPtr*>(datasource); switch(whence) { case SEEK_SET: dataStream->seek(offset); break; case SEEK_END: dataStream->seek(dataStream->size()); // Falling through purposefully here case SEEK_CUR: dataStream->skip(offset); break; } return 0; }
bool RocketInterface::Seek(Rocket::Core::FileHandle file, long offset, int origin) { if (!file) return false; Ogre::DataStreamPtr stream = *reinterpret_cast<Ogre::DataStreamPtr*>(file); long pos = 0; size_t size = stream->size(); if (origin == SEEK_CUR) pos = stream->tell() + offset; else if (origin == SEEK_END) pos = size + offset; else pos = offset; if (pos < 0 || pos > (long)size) return false; stream->seek((size_t)pos); return true; }
void MapFileSerializer::importMapFile( Ogre::DataStreamPtr& stream, WorldMapFile& dest ) { const auto fileSize = stream->size(); auto numBlocks = fileSize / kWorldMapBlockSize; for ( unsigned int j=0; j<numBlocks; j++ ) { SBlock block; const size_t basePos = kWorldMapBlockSize*j; stream->seek( basePos ); // Read the offset to compressed data in this block BlockHeader header = {}; for ( auto i=0u; i<16; i++) { readUInt32( stream, header.mCompressedDataOffsets[i] ); } for ( auto i=0u; i<16; i++) { SBlockPart blockPart; // Go to the offset stream->seek( basePos + header.mCompressedDataOffsets[i] ); // Read the size of the compressed data uint32 compressedDataSize = 0; readUInt32( stream, compressedDataSize ); // Go back to before the compressed data size stream->seek( basePos + header.mCompressedDataOffsets[i] ); // Read the compressed data into a temp buffer, including the compressed data size std::vector<uint8> buffer( compressedDataSize + 4 ); stream->read(buffer.data(), buffer.size()); // Decompress the data auto decompressed = LzsBuffer::Decompress(buffer); Ogre::MemoryDataStream decStream(decompressed.data(), decompressed.size(), false, true); readUInt16(decStream, blockPart.mHeader.NumberOfTriangles); readUInt16(decStream, blockPart.mHeader.NumberOfVertices); /* std::cout << "block: " << j << " from offset " << header.mCompressedDataOffsets[i] << " old size: " << buffer.size() << " decompressed size is " << decompressed.size() << " header is tris: " << blockPart.mHeader.NumberOfTriangles << " verts " << blockPart.mHeader.NumberOfVertices << std::endl;*/ blockPart.mTris.resize(blockPart.mHeader.NumberOfTriangles); for ( int k=0; k<blockPart.mHeader.NumberOfTriangles; k++) { BlockTriangle& s = blockPart.mTris[k]; readUInt8( decStream, s.Vertex0Index ); readUInt8( decStream, s.Vertex1Index ); readUInt8( decStream, s.Vertex2Index ); readUInt8( decStream, s.WalkabilityInfo ); //readUInt8( decStream, s.Unknown ); readUInt8( decStream, s.uVertex0 ); readUInt8( decStream, s.vVertex0 ); readUInt8( decStream, s.uVertex1 ); readUInt8( decStream, s.vVertex1 ); readUInt8( decStream, s.uVertex2 ); readUInt8( decStream, s.vVertex2 ); readUInt16( decStream, s.TextureInfo ); s.TextureInfo = s.TextureInfo & 0x1FF; //readUInt16( decStream, s.Location ); /* std::cout << "v0: " << int(s.Vertex0Index) << " v1 " << int(s.Vertex1Index) << " v2 " << int(s.Vertex2Index) << " walk " << int(s.WalkabilityInfo) << " u1 " << int(s.uVertex1) << " v1 " << int(s.vVertex1) << " v2 " << int(s.uVertex2) << " u2 " << int(s.vVertex2) << " texture " << s.TextureInfo << " locId " << s.Location << std::endl;*/ } blockPart.mNormal.resize( blockPart.mHeader.NumberOfVertices ); blockPart.mVertices.resize( blockPart.mHeader.NumberOfVertices ); // All verts for ( int k=0; k<blockPart.mHeader.NumberOfVertices; k++) { Vertex& v = blockPart.mVertices[k]; readInt16( decStream, v.X ); readInt16( decStream, v.Y ); readInt16( decStream, v.Z ); readUInt16( decStream, v.Unused ); } // Then all normals for ( int k=0; k<blockPart.mHeader.NumberOfVertices; k++) { Normal& n = blockPart.mNormal[k]; readInt16( decStream, n.X ); readInt16( decStream, n.Y ); readInt16( decStream, n.Z ); readUInt16( decStream, n.Unused ); } block.mMeshes.push_back( blockPart ); } mBlocks.push_back(block); } }
bool OgreNetworkReply::seek(qint64 pos) { QNetworkReply::seek(pos); mDataStream->seek(pos); return (mDataStream->tell() == pos); }
Ogre::Codec::DecodeResult MTGACodec::decode(Ogre::DataStreamPtr& stream) const { // Read 4 character code mtga_header_s hdr; //uint32 fileType; stream->read(&hdr, sizeof(hdr)); if (LodResource_Bitmap != hdr.magic) { OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "This is not a MTGA file!", "MTGACodec::decode"); } mtga_pal_s pal[256]; assert(stream->size() == sizeof(hdr)+hdr.uncompressedSize + sizeof(pal)); stream->seek(sizeof(mtga_header_s)+hdr.uncompressedSize); stream->read(pal,sizeof(pal)); bool isTransparent = false; mtga_pal_s& clr = pal[0]; if( (clr.r == 0 && clr.g >250 && clr.b > 250) || (clr.r > 250 && clr.g ==0 && clr.b > 250)) isTransparent = true; Ogre::ImageCodec::ImageData* imgData = OGRE_NEW Ogre::ImageCodec::ImageData(); imgData->format = PF_BYTE_BGRA; imgData->width = hdr.width; imgData->height = hdr.height; imgData->num_mipmaps = 3; imgData->depth = 1; imgData->size = Image::calculateSize(imgData->num_mipmaps, 1, imgData->width, imgData->height, imgData->depth, imgData->format); Ogre::MemoryDataStreamPtr pixelData; pixelData.bind(OGRE_NEW MemoryDataStream(imgData->size)); // Now deal with the data unsigned char* destPtr = pixelData->getPtr(); stream->seek(sizeof(mtga_header_s)); size_t width = hdr.width; size_t height = hdr.height; for(size_t mip = 0; mip <= imgData->num_mipmaps; ++mip) { for (size_t y = 0; y < height; y ++) { for (size_t x = 0; x < width; x ++) { unsigned char idx; stream->read(&idx,1); mtga_pal_s& clr = pal[idx]; assert(destPtr-pixelData->getPtr() < imgData->size); *destPtr++ = clr.b; *destPtr++ = clr.g; *destPtr++ = clr.r; *destPtr++ = (idx == 0 && isTransparent)?0:255; } } width /=2; height /=2; } DecodeResult ret; ret.first = pixelData; ret.second = CodecDataPtr(imgData); return ret; }
void seek(size_t pos) { inp->seek(pos); }
void CollisionMesh::loadImpl (void) { APP_ASSERT(masterShape==NULL); Ogre::DataStreamPtr file; try { file = Ogre::ResourceGroupManager::getSingleton().openResource(name.substr(1), "GRIT"); } catch (Ogre::Exception &e) { GRIT_EXCEPT(e.getDescription()); } std::string ext = name.substr(name.length()-5); uint32_t fourcc = 0; for (int i=0 ; i<4 ; ++i) { unsigned char c; file->read(&c, 1); fourcc |= c << (i*8); } file->seek(0); std::string dir = grit_dirname(name); const btVector3 ZV(0,0,0); const btQuaternion ZQ(0,0,0,1); bool compute_inertia = false; bool is_static = false; if (fourcc==0x4c4f4342) { //BCOL Ogre::MemoryDataStreamPtr mem = Ogre::MemoryDataStreamPtr(OGRE_NEW Ogre::MemoryDataStream(name,file)); BColFile &bcol = *reinterpret_cast<BColFile*>(mem->getPtr()); is_static = bcol.mass == 0.0f; // static masterShape = new btCompoundShape(); BColMaterialMap mmap(dir,name); for (unsigned i=0 ; i<bcol.hullNum ; ++i) { BColHull &p = *bcol.hulls(i); btConvexHullShape *s2 = new btConvexHullShape(); s2->setMargin(p.margin); for (unsigned j=0 ; j<p.vertNum ; ++j) { BColVert &v = *p.verts(j); s2->addPoint(btVector3(v.x, v.y, v.z)); } masterShape->addChildShape(btTransform(ZQ,ZV), s2); partMaterials.push_back(mmap(p.mat.name())); } for (unsigned i=0 ; i<bcol.boxNum ; ++i) { BColBox &p = *bcol.boxes(i); btBoxShape *s2 = new btBoxShape(btVector3(p.dx/2,p.dy/2,p.dz/2)); s2->setMargin(p.margin); masterShape->addChildShape(btTransform(btQuaternion(p.qx,p.qy,p.qz,p.qw), btVector3(p.px,p.py,p.pz)), s2); partMaterials.push_back(mmap(p.mat.name())); } for (unsigned i=0 ; i<bcol.cylNum ; ++i) { BColCyl &p = *bcol.cyls(i); btCylinderShape *s2 = new btCylinderShapeZ(btVector3(p.dx/2,p.dy/2,p.dz/2)); s2->setMargin(p.margin); masterShape->addChildShape(btTransform(btQuaternion(p.qx,p.qy,p.qz,p.qw), btVector3(p.px,p.py,p.pz)), s2); partMaterials.push_back(mmap(p.mat.name())); } for (unsigned i=0 ; i<bcol.coneNum ; ++i) { BColCone &p = *bcol.cones(i); btConeShape *s2 = new btConeShapeZ(p.radius,p.height); s2->setMargin(p.margin); masterShape->addChildShape(btTransform(btQuaternion(p.qx,p.qy,p.qz,p.qw), btVector3(p.px,p.py,p.pz)), s2); partMaterials.push_back(mmap(p.mat.name())); } for (unsigned i=0 ; i<bcol.planeNum ; ++i) { BColPlane &p = *bcol.planes(i); btStaticPlaneShape *s2 = new btStaticPlaneShape(btVector3(p.nx,p.ny,p.nz),p.d); masterShape->addChildShape(btTransform(ZQ,ZV), s2); partMaterials.push_back(mmap(p.mat.name())); } for (unsigned i=0 ; i<bcol.sphereNum ; ++i) { BColSphere &p = *bcol.spheres(i); btSphereShape *s2 = new btSphereShape(p.radius); masterShape->addChildShape(btTransform(ZQ, btVector3(p.px,p.py,p.pz)), s2); partMaterials.push_back(mmap(p.mat.name())); } if (bcol.triMeshFaceNum > 0) { bcolVerts.resize(bcol.triMeshVertNum); bcolFaces.resize(bcol.triMeshFaceNum); memcpy(&bcolVerts[0], bcol.triMeshVerts(0), bcol.triMeshVertNum * sizeof(BColVert)); memcpy(&bcolFaces[0], bcol.triMeshFaces(0), bcol.triMeshFaceNum * sizeof(BColFace)); faceMaterials.reserve(bcol.triMeshFaceNum); int counter = 0; float accum_area = 0; for (unsigned i=0 ; i<bcol.triMeshFaceNum ; ++i) { BColFace &face = *bcol.triMeshFaces(i); PhysicalMaterial *mat = mmap(face.mat.name()); faceMaterials.push_back(mat); CollisionMesh::ProcObjFace po_face(to_v3(bcolVerts[face.v1]), to_v3(bcolVerts[face.v2]), to_v3(bcolVerts[face.v3])); procObjFaceDB[mat->id].faces.push_back(po_face); float area = (po_face.AB.cross(po_face.AC)).length(); APP_ASSERT(area>=0); procObjFaceDB[mat->id].areas.push_back(area); procObjFaceDB[mat->id].totalArea += area; if (++counter = 10) { counter = 0; accum_area = 0; procObjFaceDB[mat->id].areas10.push_back(accum_area); } accum_area += area; } btTriangleIndexVertexArray *v = new btTriangleIndexVertexArray( bcolFaces.size(), reinterpret_cast<int*>(&(bcolFaces[0].v1)), sizeof(BColFace), bcolVerts.size(), &(bcolVerts[0].x), sizeof(BColVert)); if (is_static) { btBvhTriangleMeshShape *tm = new btBvhTriangleMeshShape(v,true,true); tm->setMargin(bcol.triMeshMargin); btTriangleInfoMap* tri_info_map = new btTriangleInfoMap(); tri_info_map->m_edgeDistanceThreshold = bcol.triMeshEdgeDistanceThreshold; btGenerateInternalEdgeInfo(tm,tri_info_map); masterShape->addChildShape(btTransform::getIdentity(), tm); } else { // skip over dynamic trimesh } } setMass(bcol.mass); setLinearDamping(bcol.linearDamping); setAngularDamping(bcol.angularDamping); setLinearSleepThreshold(bcol.linearSleepThreshold); setAngularSleepThreshold(bcol.angularSleepThreshold); setCCDMotionThreshold(bcol.ccdMotionThreshold); setCCDSweptSphereRadius(bcol.ccdSweptSphereRadius); setInertia(Vector3(bcol.inertia[0],bcol.inertia[1],bcol.inertia[2])); compute_inertia = !bcol.inertiaProvided; } else if (fourcc==0x4c4f4354) { //TCOL ProxyStreamBuf proxy(file); std::istream stream(&proxy); quex::tcol_lexer qlex(&stream); TColFile tcol; parse_tcol_1_0(name,&qlex,tcol); is_static = tcol.mass == 0.0f; // static masterShape = new btCompoundShape(); if (tcol.usingCompound) { TColCompound &c = tcol.compound; for (size_t i=0 ; i<c.hulls.size() ; ++i) { const TColHull &h = c.hulls[i]; btConvexHullShape *s2 = new btConvexHullShape(); s2->setMargin(h.margin); for (unsigned j=0 ; j<h.vertexes.size() ; ++j) { const Vector3 &v = h.vertexes[j]; s2->addPoint(to_bullet(v)); } masterShape->addChildShape(btTransform(ZQ,ZV), s2); partMaterials.push_back(phys_mats.getMaterial(dir,name,h.material)); } for (size_t i=0 ; i<c.boxes.size() ; ++i) { const TColBox &b = c.boxes[i]; /* implement with hulls btConvexHullShape *s2 = new btConvexHullShape(); s2->addPoint(btVector3(-b.dx/2+b.margin, -b.dy/2+b.margin, -b.dz/2+b.margin)); s2->addPoint(btVector3(-b.dx/2+b.margin, -b.dy/2+b.margin, b.dz/2-b.margin)); s2->addPoint(btVector3(-b.dx/2+b.margin, b.dy/2-b.margin, -b.dz/2+b.margin)); s2->addPoint(btVector3(-b.dx/2+b.margin, b.dy/2-b.margin, b.dz/2-b.margin)); s2->addPoint(btVector3( b.dx/2-b.margin, -b.dy/2+b.margin, -b.dz/2+b.margin)); s2->addPoint(btVector3( b.dx/2-b.margin, -b.dy/2+b.margin, b.dz/2-b.margin)); s2->addPoint(btVector3( b.dx/2-b.margin, b.dy/2-b.margin, -b.dz/2+b.margin)); s2->addPoint(btVector3( b.dx/2-b.margin, b.dy/2-b.margin, b.dz/2-b.margin)); */ btBoxShape *s2 =new btBoxShape(btVector3(b.dx/2,b.dy/2,b.dz/2)); s2->setMargin(b.margin); masterShape->addChildShape(btTransform(btQuaternion(b.qx,b.qy,b.qz,b.qw), btVector3(b.px,b.py,b.pz)), s2); partMaterials.push_back(phys_mats.getMaterial(dir,name,b.material)); } for (size_t i=0 ; i<c.cylinders.size() ; ++i) { const TColCylinder &cyl = c.cylinders[i]; btCylinderShape *s2 = new btCylinderShapeZ(btVector3(cyl.dx/2,cyl.dy/2,cyl.dz/2)); s2->setMargin(cyl.margin); masterShape->addChildShape( btTransform(btQuaternion(cyl.qx,cyl.qy,cyl.qz,cyl.qw), btVector3(cyl.px,cyl.py,cyl.pz)), s2); partMaterials.push_back(phys_mats.getMaterial(dir,name,cyl.material)); } for (size_t i=0 ; i<c.cones.size() ; ++i) { const TColCone &cone = c.cones[i]; btConeShapeZ *s2 = new btConeShapeZ(cone.radius,cone.height); s2->setMargin(cone.margin); masterShape->addChildShape( btTransform(btQuaternion(cone.qx,cone.qy,cone.qz,cone.qw), btVector3(cone.px,cone.py,cone.pz)), s2); partMaterials.push_back(phys_mats.getMaterial(dir,name,cone.material)); } for (size_t i=0 ; i<c.planes.size() ; ++i) { const TColPlane &p = c.planes[i]; btStaticPlaneShape *s2 = new btStaticPlaneShape(btVector3(p.nx,p.ny,p.nz),p.d); masterShape->addChildShape(btTransform(ZQ,ZV), s2); partMaterials.push_back(phys_mats.getMaterial(dir,name,p.material)); } for (size_t i=0 ; i<c.spheres.size() ; ++i) { const TColSphere &sp = c.spheres[i]; btSphereShape *s2 = new btSphereShape(sp.radius); masterShape->addChildShape(btTransform(ZQ, btVector3(sp.px,sp.py,sp.pz)), s2); partMaterials.push_back(phys_mats.getMaterial(dir,name,sp.material)); } } if (tcol.usingTriMesh) { TColTriMesh &t = tcol.triMesh; std::swap(verts, t.vertexes); std::swap(faces, t.faces); faceMaterials.reserve(faces.size()); int counter = 0; float accum_area = 0; for (TColFaces::const_iterator i=faces.begin(), i_=faces.end() ; i!=i_ ; ++i) { //optimisation possible here by changing the TCol struct to be more liek what //bullet wants, and then re-using memory PhysicalMaterial *mat = phys_mats.getMaterial(dir,name,i->material); faceMaterials.push_back(mat); CollisionMesh::ProcObjFace po_face(verts[i->v1], verts[i->v2], verts[i->v3]); procObjFaceDB[mat->id].faces.push_back(po_face); float area = (po_face.AB.cross(po_face.AC)).length(); APP_ASSERT(area>=0); procObjFaceDB[mat->id].areas.push_back(area); procObjFaceDB[mat->id].totalArea += area; if (++counter = 10) { counter = 0; accum_area = 0; procObjFaceDB[mat->id].areas10.push_back(accum_area); } accum_area += area; } btTriangleIndexVertexArray *v = new btTriangleIndexVertexArray( faces.size(), &(faces[0].v1), sizeof(TColFace), verts.size(), &(verts[0].x), sizeof(Vector3)); if (is_static) { btBvhTriangleMeshShape *tm = new btBvhTriangleMeshShape(v,true,true); tm->setMargin(t.margin); btTriangleInfoMap* tri_info_map = new btTriangleInfoMap(); tri_info_map->m_edgeDistanceThreshold = t.edgeDistanceThreshold; btGenerateInternalEdgeInfo(tm,tri_info_map); masterShape->addChildShape(btTransform::getIdentity(), tm); } else { // Skip over dynamic trimesh } } setMass(tcol.mass); setInertia(Vector3(tcol.inertia_x,tcol.inertia_y,tcol.inertia_z)); setLinearDamping(tcol.linearDamping); setAngularDamping(tcol.angularDamping); setLinearSleepThreshold(tcol.linearSleepThreshold); setAngularSleepThreshold(tcol.angularSleepThreshold); setCCDMotionThreshold(tcol.ccdMotionThreshold); setCCDSweptSphereRadius(tcol.ccdSweptSphereRadius); compute_inertia = !tcol.hasInertia; } else { GRIT_EXCEPT("Collision mesh \""+name+"\" seems to be corrupt."); } if (is_static) { setInertia(Vector3(0,0,0)); } else { if (faceMaterials.size() > 0) { CERR << "While loading \"" + name + "\": Dynamic trimesh not supported." << std::endl; } if (compute_inertia) { btVector3 i; masterShape->calculateLocalInertia(mass,i); setInertia(from_bullet(i)); } } }