LCOV - code coverage report
Current view: top level - source/soundmanager/items - CSoundItem.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 1 35 2.9 %
Date: 2023-01-19 00:18:29 Functions: 2 8 25.0 %

          Line data    Source code
       1             : /* Copyright (C) 2021 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #include "precompiled.h"
      19             : 
      20             : #include "CSoundItem.h"
      21             : 
      22             : #if CONFIG2_AUDIO
      23             : 
      24             : #include "soundmanager/SoundManager.h"
      25             : #include "soundmanager/data/SoundData.h"
      26             : 
      27             : #include <mutex>
      28             : 
      29           0 : CSoundItem::CSoundItem()
      30             : {
      31           0 :     ResetVars();
      32           0 : }
      33             : 
      34           0 : CSoundItem::CSoundItem(CSoundData* sndData)
      35             : {
      36           0 :     ResetVars();
      37           0 :     if (InitOpenAL())
      38           0 :         Attach(sndData);
      39           0 : }
      40             : 
      41           0 : CSoundItem::~CSoundItem()
      42             : {
      43           0 :     Stop();
      44           0 :     ReleaseOpenAL();
      45           0 : }
      46             : 
      47           0 : bool CSoundItem::IdleTask()
      48             : {
      49           0 :     if ( m_ALSource == 0 )
      50           0 :         return false;
      51             : 
      52           0 :     HandleFade();
      53             : 
      54           0 :     if (m_LastPlay && m_ALSource)
      55             :     {
      56           0 :         std::lock_guard<std::mutex> lock(m_ItemMutex);
      57             :         int proc_state;
      58           0 :         alGetSourcei(m_ALSource, AL_SOURCE_STATE, &proc_state);
      59           0 :         AL_CHECK;
      60           0 :         m_ShouldBePlaying = (proc_state != AL_STOPPED && proc_state != AL_INITIAL && proc_state != AL_PAUSED);
      61           0 :         return m_ShouldBePlaying;
      62             :     }
      63           0 :     return true;
      64             : }
      65             : 
      66           0 : void CSoundItem::Attach(CSoundData* itemData)
      67             : {
      68           0 :     if (m_SoundData != NULL)
      69             :     {
      70           0 :         CSoundData::ReleaseSoundData(m_SoundData);
      71           0 :         m_SoundData = 0;
      72             :     }
      73             : 
      74           0 :     if (itemData != NULL)
      75             :     {
      76           0 :         AL_CHECK;
      77           0 :         alSourcei(m_ALSource, AL_BUFFER, 0);
      78           0 :         AL_CHECK;
      79           0 :         m_SoundData = itemData->IncrementCount();
      80           0 :         alSourcei(m_ALSource, AL_BUFFER, m_SoundData->GetBuffer());
      81             : 
      82           0 :         AL_CHECK;
      83             :     }
      84           3 : }
      85             : 
      86             : #endif // CONFIG2_AUDIO

Generated by: LCOV version 1.13