2022-03-03 14:42:26 -08:00
|
|
|
|
/* Copyright (C) 2022 Wildfire Games.
|
2023-07-27 13:54:46 -07:00
|
|
|
|
* This file is part of 0 A.D.
|
2010-04-04 14:24:39 -07:00
|
|
|
|
*
|
2023-07-27 13:54:46 -07:00
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2010-04-04 14:24:39 -07:00
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
|
*
|
2023-07-27 13:54:46 -07:00
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2010-04-04 14:24:39 -07:00
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
*
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-07-27 13:54:46 -07:00
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2010-04-04 14:24:39 -07:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "simulation2/system/Component.h"
|
|
|
|
|
|
#include "ICmpSoundManager.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "simulation2/MessageTypes.h"
|
|
|
|
|
|
#include "simulation2/components/ICmpPosition.h"
|
2011-02-11 15:02:19 -08:00
|
|
|
|
#include "simulation2/components/ICmpRangeManager.h"
|
2013-06-16 19:30:40 -07:00
|
|
|
|
#include "simulation2/components/ICmpOwnership.h"
|
|
|
|
|
|
|
2013-06-13 05:12:44 -07:00
|
|
|
|
#include "soundmanager/ISoundManager.h"
|
2010-04-04 14:24:39 -07:00
|
|
|
|
|
2022-03-03 14:42:26 -08:00
|
|
|
|
class CCmpSoundManager final : public ICmpSoundManager
|
2010-04-04 14:24:39 -07:00
|
|
|
|
{
|
|
|
|
|
|
public:
|
2013-06-13 17:24:51 -07:00
|
|
|
|
static void ClassInit(CComponentManager& UNUSED(componentManager) )
|
2010-04-04 14:24:39 -07:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DEFAULT_COMPONENT_ALLOCATOR(SoundManager)
|
|
|
|
|
|
|
2010-04-23 09:09:03 -07:00
|
|
|
|
static std::string GetSchema()
|
|
|
|
|
|
{
|
|
|
|
|
|
return "<a:component type='system'/><empty/>";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
|
void Init(const CParamNode& UNUSED(paramNode)) override
|
2010-04-04 14:24:39 -07:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
|
void Deinit() override
|
2010-04-04 14:24:39 -07:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
|
void Serialize(ISerializer& UNUSED(serialize)) override
|
2010-04-04 14:24:39 -07:00
|
|
|
|
{
|
|
|
|
|
|
// Do nothing here - sounds are purely local, and don't need to be preserved across saved games etc
|
|
|
|
|
|
// (If we add music support in here then we might want to save the music state, though)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
|
void Deserialize(const CParamNode& paramNode, IDeserializer& UNUSED(deserialize)) override
|
2010-04-04 14:24:39 -07:00
|
|
|
|
{
|
2011-01-16 06:08:38 -08:00
|
|
|
|
Init(paramNode);
|
2010-04-04 14:24:39 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
|
void PlaySoundGroup(const std::wstring& name, entity_id_t source) override
|
2010-04-04 14:24:39 -07:00
|
|
|
|
{
|
2018-02-24 10:13:03 -08:00
|
|
|
|
if (!g_SoundManager || (source == INVALID_ENTITY))
|
2013-06-13 17:24:51 -07:00
|
|
|
|
return;
|
|
|
|
|
|
|
2013-06-16 19:30:40 -07:00
|
|
|
|
int currentPlayer = GetSimContext().GetCurrentDisplayedPlayer();
|
2010-04-04 14:24:39 -07:00
|
|
|
|
|
2018-02-24 10:13:03 -08:00
|
|
|
|
CmpPtr<ICmpRangeManager> cmpRangeManager(GetSystemEntity());
|
2020-06-13 02:05:40 -07:00
|
|
|
|
if (!cmpRangeManager || (cmpRangeManager->GetLosVisibility(source, currentPlayer) != LosVisibility::VISIBLE))
|
2013-06-14 09:05:57 -07:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), source);
|
2018-02-24 10:13:03 -08:00
|
|
|
|
if (!cmpPosition || !cmpPosition->IsInWorld())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
bool playerOwned = false;
|
|
|
|
|
|
CmpPtr<ICmpOwnership> cmpOwnership(GetSimContext(), source);
|
|
|
|
|
|
if (cmpOwnership)
|
|
|
|
|
|
playerOwned = cmpOwnership->GetOwner() == currentPlayer;
|
|
|
|
|
|
|
|
|
|
|
|
CVector3D sourcePos = CVector3D(cmpPosition->GetPosition());
|
|
|
|
|
|
g_SoundManager->PlayAsGroup(name, sourcePos, source, playerOwned);
|
2010-04-04 14:24:39 -07:00
|
|
|
|
}
|
2013-06-16 19:30:40 -07:00
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
|
void PlaySoundGroupAtPosition(const std::wstring& name, const CFixedVector3D& sourcePos) override
|
2017-09-28 12:26:07 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (!g_SoundManager)
|
|
|
|
|
|
return;
|
|
|
|
|
|
g_SoundManager->PlayAsGroup(name, CVector3D(sourcePos), INVALID_ENTITY, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
|
void PlaySoundGroupForPlayer(const VfsPath& groupPath, const player_id_t playerId) const override
|
2020-11-18 01:14:08 -08:00
|
|
|
|
{
|
|
|
|
|
|
if (!g_SoundManager)
|
|
|
|
|
|
return;
|
|
|
|
|
|
g_SoundManager->PlayAsGroup(groupPath, CVector3D(0.f, 0.f, 0.f), INVALID_ENTITY, GetSimContext().GetCurrentDisplayedPlayer() == playerId);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
|
void StopMusic() override
|
2014-09-12 14:38:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (!g_SoundManager)
|
|
|
|
|
|
return;
|
|
|
|
|
|
g_SoundManager->Pause(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-04-04 14:24:39 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
REGISTER_COMPONENT_TYPE(SoundManager)
|
2012-08-31 12:08:41 -07:00
|
|
|
|
|
|
|
|
|
|
|