Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/CCmpSoundManager.cpp
Show All 11 Lines | |||||
* GNU General Public License for more details. | * GNU General Public License for more details. | ||||
* | * | ||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "CCmpSoundManager.h" | |||||
#include "simulation2/system/Component.h" | #include "simulation2/system/Component.h" | ||||
#include "ICmpSoundManager.h" | |||||
#include "simulation2/MessageTypes.h" | #include "simulation2/MessageTypes.h" | ||||
#include "simulation2/components/ICmpPosition.h" | #include "simulation2/components/ICmpPosition.h" | ||||
#include "simulation2/components/ICmpRangeManager.h" | #include "simulation2/components/ICmpRangeManager.h" | ||||
#include "simulation2/components/ICmpOwnership.h" | #include "simulation2/components/ICmpOwnership.h" | ||||
#include "soundmanager/ISoundManager.h" | #include "soundmanager/ISoundManager.h" | ||||
class CCmpSoundManager final : public ICmpSoundManager | void CCmpSoundManager::ClassInit(CComponentManager& UNUSED(componentManager) ) | ||||
{ | {} | ||||
public: | |||||
static void ClassInit(CComponentManager& UNUSED(componentManager) ) | IComponent* CCmpSoundManager::Allocate(const ScriptInterface&, JS::HandleValue) | ||||
{ | { | ||||
return nullptr; | |||||
} | } | ||||
DEFAULT_COMPONENT_ALLOCATOR(SoundManager) | void CCmpSoundManager::Deallocate(IComponent*) | ||||
{} | |||||
static std::string GetSchema() | int CCmpSoundManager::GetComponentTypeId() const | ||||
{ | { | ||||
return "<a:component type='system'/><empty/>"; | return CID_SoundManager; | ||||
} | } | ||||
void Init(const CParamNode& UNUSED(paramNode)) override | std::string CCmpSoundManager::GetSchema() | ||||
{ | { | ||||
return "<a:component type='system'/><empty/>"; | |||||
} | } | ||||
void Deinit() override | void CCmpSoundManager::Init(const CParamNode& UNUSED(paramNode)) | ||||
{ | {} | ||||
} | |||||
void Serialize(ISerializer& UNUSED(serialize)) override | void CCmpSoundManager::Deinit() | ||||
{} | |||||
void CCmpSoundManager::Serialize(ISerializer& UNUSED(serialize)) | |||||
{ | { | ||||
// Do nothing here - sounds are purely local, and don't need to be preserved across saved games etc | // 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) | // (If we add music support in here then we might want to save the music state, though) | ||||
} | } | ||||
void Deserialize(const CParamNode& paramNode, IDeserializer& UNUSED(deserialize)) override | void CCmpSoundManager::Deserialize(const CParamNode& paramNode, IDeserializer& UNUSED(deserialize)) | ||||
{ | { | ||||
Init(paramNode); | Init(paramNode); | ||||
} | } | ||||
void PlaySoundGroup(const std::wstring& name, entity_id_t source) override | void CCmpSoundManager::PlaySoundGroup(const std::wstring& name, entity_id_t source) | ||||
{ | { | ||||
if (!g_SoundManager || (source == INVALID_ENTITY)) | if (!g_SoundManager || (source == INVALID_ENTITY)) | ||||
return; | return; | ||||
int currentPlayer = GetSimContext().GetCurrentDisplayedPlayer(); | int currentPlayer = GetSimContext().GetCurrentDisplayedPlayer(); | ||||
CmpPtr<ICmpRangeManager> cmpRangeManager(GetSystemEntity()); | CmpPtr<ICmpRangeManager> cmpRangeManager(GetSystemEntity()); | ||||
if (!cmpRangeManager || (cmpRangeManager->GetLosVisibility(source, currentPlayer) != LosVisibility::VISIBLE)) | if (!cmpRangeManager || (cmpRangeManager->GetLosVisibility(source, currentPlayer) != | ||||
LosVisibility::VISIBLE)) | |||||
return; | return; | ||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), source); | CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), source); | ||||
if (!cmpPosition || !cmpPosition->IsInWorld()) | if (!cmpPosition || !cmpPosition->IsInWorld()) | ||||
return; | return; | ||||
bool playerOwned = false; | bool playerOwned = false; | ||||
CmpPtr<ICmpOwnership> cmpOwnership(GetSimContext(), source); | CmpPtr<ICmpOwnership> cmpOwnership(GetSimContext(), source); | ||||
if (cmpOwnership) | if (cmpOwnership) | ||||
playerOwned = cmpOwnership->GetOwner() == currentPlayer; | playerOwned = cmpOwnership->GetOwner() == currentPlayer; | ||||
CVector3D sourcePos = CVector3D(cmpPosition->GetPosition()); | CVector3D sourcePos = CVector3D(cmpPosition->GetPosition()); | ||||
g_SoundManager->PlayAsGroup(name, sourcePos, source, playerOwned); | g_SoundManager->PlayAsGroup(name, sourcePos, source, playerOwned); | ||||
} | } | ||||
void PlaySoundGroupAtPosition(const std::wstring& name, const CFixedVector3D& sourcePos) override | void CCmpSoundManager::PlaySoundGroupAtPosition(const std::wstring& name, const CFixedVector3D& sourcePos) | ||||
{ | { | ||||
if (!g_SoundManager) | if (!g_SoundManager) | ||||
return; | return; | ||||
g_SoundManager->PlayAsGroup(name, CVector3D(sourcePos), INVALID_ENTITY, false); | g_SoundManager->PlayAsGroup(name, CVector3D(sourcePos), INVALID_ENTITY, false); | ||||
} | } | ||||
void PlaySoundGroupForPlayer(const VfsPath& groupPath, const player_id_t playerId) const override | void CCmpSoundManager::PlaySoundGroupForPlayer(const VfsPath& groupPath, const player_id_t playerId) const | ||||
{ | { | ||||
if (!g_SoundManager) | if (!g_SoundManager) | ||||
return; | return; | ||||
g_SoundManager->PlayAsGroup(groupPath, CVector3D(0.f, 0.f, 0.f), INVALID_ENTITY, GetSimContext().GetCurrentDisplayedPlayer() == playerId); | g_SoundManager->PlayAsGroup(groupPath, CVector3D(0.f, 0.f, 0.f), INVALID_ENTITY, | ||||
GetSimContext().GetCurrentDisplayedPlayer() == playerId); | |||||
} | } | ||||
void StopMusic() override | void CCmpSoundManager::StopMusic() | ||||
{ | { | ||||
if (!g_SoundManager) | if (!g_SoundManager) | ||||
return; | return; | ||||
g_SoundManager->Pause(true); | g_SoundManager->Pause(true); | ||||
} | } | ||||
}; | |||||
REGISTER_COMPONENT_TYPE(SoundManager) | REGISTER_COMPONENT_TYPE(SoundManager) | ||||
Wildfire Games · Phabricator