MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / ThreadedSoundLoop

Function ThreadedSoundLoop

Source/Sound/threaded_sound_wrapper.cpp:394–638  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

392}
393
394static void ThreadedSoundLoop() {
395 bool running = true;
396 bool initialized = false;
397 Sound* sound = NULL;
398 const unsigned int minimum_tick = 16;
399
400 PROFILER_NAME_THREAD(g_profiler_ctx, "Sound Thread");
401
402 while (running) {
403 PROFILER_ENTER(g_profiler_ctx, "Sound Loop");
404
405 unsigned int start_time = SDL_TS_GetTicks();
406
407 std::queue<ThreadedSoundMessage> reinsertion;
408
409 PROFILER_ENTER(g_profiler_ctx, "Polling events");
410
411 // Run until the message queue is empty
412 while (message_queue_in.Count() > 0) {
413 ThreadedSoundMessage msg = message_queue_in.Pop();
414
415 if (msg.GetType() == ThreadedSoundMessage::Initialize) {
416 if (false == initialized) {
417 NameCurrentThread("Sound thread");
418 std::string preferred_device = tsdb.GetPreferredDevice();
419 sound = new Sound(preferred_device.c_str());
420 initialized = true;
421 tsdb.SetUsedDevice(sound->GetUsedDevice());
422 tsdb.SetAvailableDevices(sound->GetAvailableDevices());
423 } else {
424 LOGE << "Trying to double initialize threaded sound system" << std::endl;
425 }
426 } else if (initialized) {
427 if (msg.GetType() == ThreadedSoundMessage::Dispose) {
428 if (sound) {
429 sound->Dispose();
430 delete sound;
431 sound = NULL;
432 running = false;
433 initialized = false;
434 }
435 } else if (msg.GetType() == ThreadedSoundMessage::InFUpdateGameTimestep) {
436 float f;
437 msg.GetData(&f, sizeof(float));
438 sound->UpdateGameTimestep(f);
439 } else if (msg.GetType() == ThreadedSoundMessage::InFUpdateGameTimescale) {
440 float f;
441 msg.GetData(&f, sizeof(float));
442 sound->UpdateGameTimescale(f);
443 } else if (msg.GetType() == ThreadedSoundMessage::InFSetAirWhoosh) {
444 float v[2];
445 msg.GetData(v, sizeof(v));
446 sound->setAirWhoosh(v[0], v[1]);
447 } else if (msg.GetType() == ThreadedSoundMessage::InFUpdateListener) {
448 vec3 v[4];
449 msg.GetData(v, sizeof(v));
450 sound->updateListener(v[0], v[1], v[2], v[3]);
451 } else if (msg.GetType() == ThreadedSoundMessage::InFPlay) {

Callers

nothing calls this directly

Calls 15

SDL_TS_GetTicksFunction · 0.85
NameCurrentThreadFunction · 0.85
strscpyFunction · 0.85
SetUsedDeviceMethod · 0.80
SetAvailableDevicesMethod · 0.80
GetRealHandleMethod · 0.80
SetHandleMethod · 0.80
GetStringDataMethod · 0.80
GetAllHandlesMethod · 0.80
RemoveHandleMethod · 0.80
GetAmbientTrianglesMethod · 0.80
CountMethod · 0.45

Tested by

no test coverage detected