isle-portable/LEGO1/lego/legoomni/src/audio/legocachesoundmanager.cpp
Christian Semmler e0af725fb6
Updates from isledecomp/isle (#19)
* Refactor JukeBox, add enum for music (#988)

* Refactor JukeBox, add enum for music

* add BETA annotation

* Fix BETA annotation

* Fix BETA annotation

* Fix

* Consolidate state and building entity classes (#989)

* Match LegoCacheSoundManager::FindSoundByKey (#991)

* Match LegoCacheSoundManager::FindSoundByKey

* Remove space

* Implement/match LegoActor::Mute (#992)

* Add more annotations to ISLE (#990)

* Minor improvements in ISLE.EXE

* Add more annotations

* Fix

* Comment out

* Fix lint

* Add enum for actor IDs (#993)

* Implement/match LegoEntity::ClickAnimation (#994)

* Implement/match LegoEntity::VTable0x38

* Update names

* Implement/match LegoEntity::SwitchSound / SwitchMove / SwitchColor / SwitchMood (#995)

* Implement/match LegoEntity::SwitchSound

* Name

* Name

* Implement/match LegoEntity::SwitchMove

* Mood

* Implement/match LegoCharacterManager::SwitchColor (#996)

* Implement/match IslePathActor::Exit (#997)

* Implement/match IslePathActor::Exit

* Name

* Name

* Partially fix vector interface

* Revert "Partially fix vector interface"

This reverts commit 6e7a1e2b08fd82012b28be3054eeff65428eb4d1.

* Revert "Revert "Partially fix vector interface""

This reverts commit e3860e3c9fa1f8937b702d6c81d6e3bb4dadecc6.

* Fix

* Remove some COMPAT_MODE

* Implement/match Ambulance::Notify (#998)

* Update isleapp.cpp

* Streamline MxVideoParamFlags (#999)

* Streamline MxVideoParamFlags

* Remove this-> from MxOmniCreateFlags

---------

Co-authored-by: MS <disinvite@users.noreply.github.com>
2024-06-07 21:32:27 +02:00

173 lines
3.7 KiB
C++

#include "legocachesoundmanager.h"
#include "legoworld.h"
#include "misc.h"
DECOMP_SIZE_ASSERT(LegoCacheSoundEntry, 0x08)
DECOMP_SIZE_ASSERT(LegoCacheSoundManager, 0x20)
// FUNCTION: LEGO1 0x1003cf20
LegoCacheSoundManager::~LegoCacheSoundManager()
{
LegoCacheSound* sound;
while (!m_set.empty()) {
sound = (*m_set.begin()).GetSound();
m_set.erase(m_set.begin());
sound->FUN_10006b80();
delete sound;
}
while (!m_list.empty()) {
sound = (*m_list.begin()).GetSound();
m_list.erase(m_list.begin());
sound->FUN_10006b80();
// DECOMP: delete should not be inlined here
delete sound;
}
}
// FUNCTION: LEGO1 0x1003d050
MxResult LegoCacheSoundManager::Tickle()
{
#ifdef COMPAT_MODE
Set100d6b4c::iterator setIter;
for (setIter = m_set.begin(); setIter != m_set.end(); setIter++) {
#else
for (Set100d6b4c::iterator setIter = m_set.begin(); setIter != m_set.end(); setIter++) {
#endif
LegoCacheSound* sound = (*setIter).GetSound();
if (sound->GetUnknown0x58()) {
sound->FUN_10006be0();
}
}
List100d6b4c::iterator listIter = m_list.begin();
while (listIter != m_list.end()) {
LegoCacheSound* sound = (*listIter).GetSound();
if (sound->GetUnknown0x58()) {
sound->FUN_10006be0();
listIter++;
}
else {
sound->FUN_10006b80();
m_list.erase(listIter++);
delete sound;
}
}
return SUCCESS;
}
// FUNCTION: LEGO1 0x1003d170
LegoCacheSound* LegoCacheSoundManager::FindSoundByKey(const char* p_key)
{
char* key = new char[strlen(p_key) + 1];
strcpy(key, p_key);
Set100d6b4c::iterator it = m_set.find(LegoCacheSoundEntry(NULL, key));
if (it != m_set.end()) {
return (*it).GetSound();
}
return NULL;
}
// FUNCTION: LEGO1 0x1003d290
LegoCacheSound* LegoCacheSoundManager::ManageSoundEntry(LegoCacheSound* p_sound)
{
Set100d6b4c::iterator it = m_set.find(LegoCacheSoundEntry(p_sound));
if (it != m_set.end()) {
LegoCacheSound* sound = (*it).GetSound();
if (sound->GetUnknown0x58()) {
m_list.push_back(LegoCacheSoundEntry(p_sound));
return p_sound;
}
else {
delete p_sound;
return sound;
}
}
m_set.insert(LegoCacheSoundEntry(p_sound));
LegoWorld* world = CurrentWorld();
if (world) {
world->Add(p_sound);
}
return p_sound;
}
// FUNCTION: LEGO1 0x1003dae0
// FUNCTION: BETA10 0x10065502
LegoCacheSound* LegoCacheSoundManager::Play(const char* p_key, const char* p_name, MxBool p_looping)
{
return Play(FindSoundByKey(p_key), p_name, p_looping);
}
// FUNCTION: LEGO1 0x1003db10
// FUNCTION: BETA10 0x10065537
LegoCacheSound* LegoCacheSoundManager::Play(LegoCacheSound* p_sound, const char* p_name, MxBool p_looping)
{
if (!p_sound) {
return NULL;
}
if (p_sound->GetUnknown0x58()) {
LegoCacheSound* clone = p_sound->Clone();
if (clone) {
LegoCacheSound* sound = ManageSoundEntry(clone);
sound->Play(p_name, p_looping);
return sound;
}
}
else {
p_sound->Play(p_name, p_looping);
return p_sound;
}
return NULL;
}
// FUNCTION: LEGO1 0x1003dc40
void LegoCacheSoundManager::Destroy(LegoCacheSound*& p_sound)
{
#ifdef COMPAT_MODE
Set100d6b4c::iterator setIter;
for (setIter = m_set.begin(); setIter != m_set.end(); setIter++) {
#else
for (Set100d6b4c::iterator setIter = m_set.begin(); setIter != m_set.end(); setIter++) {
#endif
if ((*setIter).GetSound() == p_sound) {
p_sound->FUN_10006b80();
delete p_sound;
m_set.erase(setIter);
return;
}
}
#ifdef COMPAT_MODE
List100d6b4c::iterator listIter;
for (listIter = m_list.begin();; listIter++) {
#else
for (List100d6b4c::iterator listIter = m_list.begin();; listIter++) {
#endif
if (listIter == m_list.end()) {
return;
}
LegoCacheSound* sound = (*listIter).GetSound();
if (sound == p_sound) {
p_sound->FUN_10006b80();
delete sound;
m_list.erase(listIter);
return;
}
}
}