Esempio n. 1
0
void SFXWrapAroundBuffer::write( SFXStreamPacket* const* packets, U32 num )
{
   AssertFatal( SFXInternal::isSFXThread(), "SFXWrapAroundBuffer::write() - not on SFX thread" );

   for( U32 i = 0; i < num; ++ i )
   {
      const SFXStreamPacket* packet = packets[ i ];
      
      // Determine where in the buffer to copy the data to.  In case we are crossing over
      // the wrap-around point, we need to copy in two slices.

      U32 offset1    = 0;
      U32 offset2    = 0;
      U32 numBytes1  = 0;
      U32 numBytes2  = 0;

      offset1        = mWriteOffset % mBufferSize;
      numBytes1      = packet->size;

      if( offset1 + numBytes1 > mBufferSize )
      {
         // Crossing wrap-around point.
         
         numBytes1   = mBufferSize - offset1;
         numBytes2   = packet->size - numBytes1;
      }

      offset2        = offset1 + numBytes1;
      
      #ifdef DEBUG_SPEW
      Platform::outputDebugString( "[SFXWrapAroundBuffer] writing %i bytes from packet #%i at %i (stream offset: %i)",
         numBytes1, packet->mIndex, offset1, mWriteOffset );
      #endif
      
      // Copy the packet data.
      
      _copyData( offset1, packet->data, numBytes1 );
      if( numBytes2 > 0 )
      {
         #ifdef DEBUG_SPEW
         Platform::outputDebugString( "[SFXWrapAroundBuffer] writing %i more bytes at %i",
            numBytes2, offset2 );
         #endif
         
         _copyData( offset2, &packet->data[ numBytes1 ], numBytes2 );
      }
   
      dFetchAndAdd( mWriteOffset, packet->size );

      // Free the packet.

      destructSingle( packet );
   }
}
Esempio n. 2
0
void MeshManager::createMesh(const std::string& name,
					const FloatDataContainer& vertices,
					const FloatDataContainer& uvs,
					const FloatDataContainer& normals,
					const ShortDataContainer& indices,
					CollisionShape type
					)
{
	assert(m_meshes.find(name) == m_meshes.end());
	BasicMesh* result = new BasicMesh();

	result->m_name = name;
	_copyData(vertices, result->m_vertices);
	result->m_verticesCount = vertices.size() / 3;
	_copyData(indices, result->m_indices);
	_copyData(uvs, result->m_uvs);
	_copyData(normals, result->m_normals);
	_copyData(indices, result->m_indices);
	result->m_indicesCount = indices.size() / 3;
	result->setCollisionType(type);

	m_meshes[name] = result;
}
Esempio n. 3
0
bool DataHDDIORaw::read( const Box_i32& dim, void* dst )
{
    static bool errorReported = false;
    if( sizeof(std::streamoff) < sizeof(int64_t) && !errorReported )
    {
        LOG_ERROR << "sizeof(std::streamoff) < sizeof(int64_t): reading from large files is probably broken!" << std::endl;
        errorReported = true;
    }

    assert( isSourceSizeValid() );

    if( !dim.valid( ))
    {
        LOG_ERROR << "Input dimensions are invalid" << std::endl;
        return false;
    }

    const Vec3_ui32 srcDim = getSourceDims();
    const Vec3_ui32 dstDim = dim.getDim();

    // get actual coordinates
    Box_i32 bb( Vec3_ui32(0), srcDim );
    bb = bb.intersect( dim );

    const byte bytes = getBytesNum();
    if( bb != dim ) // our area is smaller than requested => clean initial data
        memset( dst, 0, dim.getAreaSize()*bytes );

    if( !bb.valid( ))
        return true;

    const Vec3_ui32 bbDim = bb.getDim();

    char* dstByte = reinterpret_cast<char*>( dst );

    // shift of the destination
    const uint64_t dstShift = ( uint64_t(dstDim.h)*dstDim.w*( bb.s.d-dim.s.d ) +
                                                   dstDim.w*( bb.s.h-dim.s.h ) +
                                                            ( bb.s.w-dim.s.w )  ) * uint64_t(bytes);
    dstByte += dstShift;

    // shift of the source
    const int64_t srcZ = int64_t(srcDim.h) * srcDim.w * bb.s.d * uint64_t(bytes);
    const int64_t srcY =                     srcDim.w * bb.s.h * uint64_t(bytes);
    const int64_t srcX =                                bb.s.w * uint64_t(bytes);

    // amout of data we are going to use
    const int64_t sliceSize = srcDim.h * srcDim.w * bbDim.d * bytes;

    if( srcZ != _oldZ || static_cast<int64_t>(bbDim.d) != _oldD )
    {
//        LOG_INFO << "  New depth to read from a raw file: " << srcZ << std::endl;

        const std::string& fName = getDataFileName();
        if( static_cast<int64_t>(util::fileSize( fName )) < srcZ+sliceSize )
        {
            LOG_ERROR << "File: " << fName.c_str() << " is too smll to read " << sliceSize 
                      << " bytes within the offset: " << srcZ << std::endl;
            return false;
        }

        util::InFile inFile;
        if( !inFile.open( fName, std::ios::binary, true ))
            return false;

        _tmp.resize( sliceSize );

        if( !inFile.read( srcZ, sliceSize, &_tmp[0] ))
            return false;

        _oldZ = srcZ;
        _oldD = static_cast<int64_t>(bbDim.d);
    }

    _copyData( dstByte, &_tmp[srcY+srcX], bbDim, dstDim, srcDim, bytes );

    return true;
}