virtual void Run() { while ( !g_Audio.FInitialized ) {} clPtr<AudioSource> Src = new AudioSource(); Src->BindWaveform( new OggProvider( LoadFileAsBlob( "test.ogg" ) ) ); // TODO: try Src->BindWaveform( new ModPlugProvider( LoadFileAsBlob( "test.it" ) ) ); Src->Play(); FPendingExit = false; double Seconds = Env_GetSeconds(); while ( !IsPendingExit() ) { float DeltaSeconds = static_cast<float>( Env_GetSeconds() - Seconds ); Src->Update( DeltaSeconds ); Seconds = Env_GetSeconds(); } Src = NULL; g_Audio.Exit( true ); exit( 0 ); }
void clLoaderThread::Run() { Env->Logger->SetCurrentThreadName( "Loader" ); guard(); while ( !IsPendingExit() ) { if ( FLoadOps.empty() ) { Env->ReleaseTimeslice( 10 ); continue; } // 1. Extract loading command from dequeue iLoadOp* Op = ExtractLoadOp(); // 2. Load file and switch default & current object in resource Op->Load(); Env->Logger->Log( L_PARANOID, "Async loaded resource: " + Op->GetResource()->GetFileName() ); delete( Op ); } Env->Logger->Log( L_NOTICE, "Loader thread exited" ); unguard(); }
void clAudioThread::Run() { Env->Logger->SetCurrentThreadName( "Audio" ); guard(); #if L_AUDIO_USE_OPENAL LAL::clALExtRetriever* OpenAL = new LAL::clALExtRetriever; FATAL( !OpenAL->Reload(), "Unable to initialize OpenAL" ); // now initialize OpenAL InitOpenAL(); #endif double Seconds = Env->GetSeconds(); while ( !IsPendingExit() ) { float DeltaSeconds = static_cast<float>( Env->GetSeconds() - Seconds ); { LMutex Lock( &FMutex ); // update sources std::for_each( FActiveSources.begin(), FActiveSources.end(), std::bind2nd( std::mem_fun( &iAudioSource::Update ), DeltaSeconds ) ); } Seconds = Env->GetSeconds(); Env->ReleaseTimeslice( 100 ); } Env->Logger->Log( L_NOTICE, "Deallocating sources" ); { LMutex Lock( &FMutex ); while ( !FActiveSources.empty() ) { delete( FActiveSources.back() ); } } #if L_AUDIO_USE_OPENAL ShutdownOpenAL(); delete( OpenAL ); #endif Env->Logger->Log( L_NOTICE, "Audio thread exited" ); unguard(); }
void clWorkerThread::Run() { FPendingExit = false; while ( !IsPendingExit() ) { FCurrentTask = ExtractTask(); if ( FCurrentTask && !FCurrentTask->IsPendingExit() ) { FCurrentTask->Run(); } // we need to reset current task since ExtractTask() is blocking operation and could take some time FCurrentTask = NULL; } }
void clAudioThread::Run() { if ( !LoadAL() ) { return; } // We should use actual device name if the default does not work FDevice = alcOpenDevice( NULL ); FContext = alcCreateContext( FDevice, NULL ); alcMakeContextCurrent( FContext ); FInitialized = true; FPendingExit = false; double Seconds = GetSeconds(); while ( !IsPendingExit() ) { float DeltaSeconds = static_cast<float>( GetSeconds() - Seconds ); { LMutex Lock( &FMutex ); for ( auto i = FActiveSources.begin(); i != FActiveSources.end(); i++ ) { ( *i )->Update( DeltaSeconds ); } } Seconds = GetSeconds(); Env_Sleep( 100 ); } alcDestroyContext( FContext ); alcCloseDevice( FDevice ); UnloadAL(); }
void clDownloadTask::InvokeCallback() { tthread::lock_guard<tthread::mutex> Lock( FExitingMutex ); if ( !IsPendingExit() ) { if ( FCurlCode != 0 ) { FResult = nullptr; } if ( FCallback ) { FCallback->FTaskID = GetTaskID(); FCallback->FResult = FResult; FCallback->FTask = clPtr<clDownloadTask>( this ); FCallback->FCurlCode = FCurlCode; FCallback->Invoke(); FCallback = nullptr; } } }
clPtr<iTask> clWorkerThread::ExtractTask() { tthread::lock_guard<tthread::mutex> Lock( FTasksMutex ); while ( FPendingTasks.empty() && !IsPendingExit() ) { FCondition.wait( FTasksMutex ); } if ( FPendingTasks.empty() ) { return clPtr<iTask>(); } std::list< clPtr<iTask> >::iterator Best = FPendingTasks.begin(); for ( std::list< clPtr<iTask> >::iterator i = FPendingTasks.begin(); i != FPendingTasks.end(); ++i ) { if ( ( *i )->GetPriority() > ( *Best )->GetPriority() ) { Best = i; } } clPtr<iTask> T = *Best; FPendingTasks.erase( Best ); return T; }