void asyncLoad( AssetPath path, AssetPromisePtr pr, AssetContentPtr c, Progress::Work w ) { try { { // TODO: Do this properly... // Get the contents of the file std::ifstream fs(path.c_str(), std::ios::binary); if( !fs.is_open() ) BOOST_THROW_EXCEPTION( InexistentAssetPathException(path) ); fs.seekg(0,std::ios::end); std::vector<char> buf((unsigned)fs.tellg() + 1); fs.seekg(0,std::ios::beg); fs.read(&buf[0],buf.capacity()); buf.resize((unsigned)fs.gcount()); fs.close(); // call the loading method on the AssetContent c->asyncLoad(buf); } mngr.prog_.makeProgress(w); // after loading is done, set the promise value to the content pr->set_value(c); } catch( ... ) { // transfer exceptions to the main thread pr->set_exception(boost::current_exception()); } boost::this_thread::yield(); }
bool AudioDeviceNULL::DoLoadStream( AudioStream* streamhandle, ConstString fname ) { AssetPath filename = fname.c_str(); bool b_uncompressed = (strstr(filename.c_str(),"streams")!=0); bool b_looped = (strstr(filename.c_str(),"Music")!=0) | (strstr(filename.c_str(),"stings")!=0); b_looped |= (strstr(filename.c_str(),"music")!=0) | (strstr(filename.c_str(),"Stings")!=0); NullStreamData* psdata = new NullStreamData; float fmaxtime = 0.0f; streamhandle->SetPlatformHandle( psdata ); if( false == b_uncompressed ) { ork::EndianContext ec; ec.mendian = EENDIAN_LITTLE; filename.SetExtension( "mkr" ); CFile ifile( filename, ork::EFM_READ ); int icount = 0; ifile.Read( & icount, sizeof(icount) ); swapbytes_dynamic( icount ); psdata->stream_markers.reserve(icount); for( int i=0; i<icount; i++ ) { float ftime = 0.0f; int istrlen = 0; ifile.Read( & ftime, sizeof(ftime) ); ifile.Read( & istrlen, sizeof(istrlen) ); swapbytes_dynamic( ftime ); swapbytes_dynamic( istrlen ); char* pstring = new char[ istrlen+1 ]; memset( pstring, 0, istrlen+1 ); ifile.Read( pstring, istrlen ); orkprintf( "StreamMarker<%d> time<%f> name<%s>\n", i, ftime, pstring ); //FMOD_SYNCPOINT *syncpoint = 0; unsigned int offset = int(ftime*1000.0f); //FMOD_TIMEUNIT offsettype = FMOD_TIMEUNIT_MS; const char *name = pstring; //FMOD_SYNCPOINT ** point //fmod_result = phandle->addSyncPoint( offset, offsettype, name, & syncpoint ); if( ftime > fmaxtime ) { fmaxtime =ftime; } psdata->stream_markers.insert( std::pair<Char8,float>( name,ftime ) ); //OrkAssert( fmod_result == FMOD_OK ); } ifile.Close(); } psdata->mfstreamlen = fmaxtime+3.0f; psdata->stream_markers.insert( std::pair<Char8,float>( "END",psdata->mfstreamlen ) ); return true; }