mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-12-23 00:28:51 -05:00
Fix Missing Custom Sequences (#2649)
* Modifies custom sequence loading to bypass other sounds being loaded in AudioCollection to fix missing custom sequences on load. * Modified `audio_load`'s sequenceMap allocation to utilize `AudioCollection`'s sequenceMap size to account for all audio assets already loaded into that sequenceMap. This gives a non-arbitrary number in addition to the vanilla sequence count to allocate with for `audio_load`'s sequenceMap. Added `HasSequenceNum` to `AudioCollection` as well to streamline the check against `AudioCollection`'s sequenceMap to skip the non-sequence assets in there. Added clarification comment for seqNum and MAX_AUTHENTIC_SEQID section. * Clarified comment about AudioCollection seqNum and MAX_AUTHENTIC_SEQID. * A bit more on comment from the last commit.
This commit is contained in:
parent
0c43fe7e48
commit
f7703e14e8
@ -261,6 +261,10 @@ extern "C" void AudioCollection_AddToCollection(char *otrPath, uint16_t seqNum)
|
||||
AudioCollection::Instance->AddToCollection(otrPath, seqNum);
|
||||
}
|
||||
|
||||
bool AudioCollection::HasSequenceNum(uint16_t seqId) {
|
||||
return sequenceMap.contains(seqId);
|
||||
}
|
||||
|
||||
const char* AudioCollection::GetSequenceName(uint16_t seqId) {
|
||||
auto seqIt = sequenceMap.find(seqId);
|
||||
if (seqIt != sequenceMap.end()) {
|
||||
@ -269,6 +273,18 @@ const char* AudioCollection::GetSequenceName(uint16_t seqId) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
size_t AudioCollection::SequenceMapSize() {
|
||||
return sequenceMap.size();
|
||||
}
|
||||
|
||||
extern "C" const char* AudioCollection_GetSequenceName(uint16_t seqId) {
|
||||
return AudioCollection::Instance->GetSequenceName(seqId);
|
||||
}
|
||||
|
||||
extern "C" bool AudioCollection_HasSequenceNum(uint16_t seqId) {
|
||||
return AudioCollection::Instance->HasSequenceNum(seqId);
|
||||
}
|
||||
|
||||
extern "C" size_t AudioCollection_SequenceMapSize() {
|
||||
return AudioCollection::Instance->SequenceMapSize();
|
||||
}
|
@ -58,8 +58,12 @@ class AudioCollection {
|
||||
uint16_t GetReplacementSequence(uint16_t seqId);
|
||||
void InitializeShufflePool();
|
||||
const char* GetSequenceName(uint16_t seqId);
|
||||
bool HasSequenceNum(uint16_t seqId);
|
||||
size_t SequenceMapSize();
|
||||
};
|
||||
#else
|
||||
void AudioCollection_AddToCollection(char *otrPath, uint16_t seqNum);
|
||||
const char* AudioCollection_GetSequenceName(uint16_t seqId);
|
||||
bool AudioCollection_HasSequenceNum(uint16_t seqId);
|
||||
size_t AudioCollection_SequenceMapSize();
|
||||
#endif
|
@ -1346,7 +1346,7 @@ void AudioLoad_Init(void* heap, size_t heapSize) {
|
||||
int customSeqListSize = 0;
|
||||
char** seqList = ResourceMgr_ListFiles("audio/sequences*", &seqListSize);
|
||||
char** customSeqList = ResourceMgr_ListFiles("custom/music/*", &customSeqListSize);
|
||||
sequenceMapSize = (size_t)(seqListSize + customSeqListSize);
|
||||
sequenceMapSize = (size_t)(AudioCollection_SequenceMapSize() + customSeqListSize);
|
||||
sequenceMap = malloc(sequenceMapSize * sizeof(char*));
|
||||
gAudioContext.seqLoadStatus = malloc(sequenceMapSize * sizeof(char*));
|
||||
|
||||
@ -1366,16 +1366,27 @@ void AudioLoad_Init(void* heap, size_t heapSize) {
|
||||
int startingSeqNum = MAX_AUTHENTIC_SEQID; // 109 is the highest vanilla sequence
|
||||
qsort(customSeqList, customSeqListSize, sizeof(char*), strcmp_sort);
|
||||
|
||||
// Because AudioCollection's sequenceMap actually has more than sequences (including instruments from 130-135 and sfx in the 2000s, 6000s, 10000s, 14000s, 18000s, and 26000s),
|
||||
// it's better here to keep track of the next empty seqNum in AudioCollection instead of just skipping past the instruments at 130 with a higher MAX_AUTHENTIC_SEQID,
|
||||
// especially if those others could be added to in the future. However, this really needs to be streamlined with specific ranges in AudioCollection for types, or unifying
|
||||
// AudioCollection and the various maps in here
|
||||
int seqNum = startingSeqNum;
|
||||
|
||||
for (size_t i = startingSeqNum; i < startingSeqNum + customSeqListSize; i++) {
|
||||
// ensure that what would be the next sequence number is actually unassigned in AudioCollection
|
||||
while (AudioCollection_HasSequenceNum(seqNum)) {
|
||||
seqNum++;
|
||||
}
|
||||
int j = i - startingSeqNum;
|
||||
AudioCollection_AddToCollection(customSeqList[j], i);
|
||||
AudioCollection_AddToCollection(customSeqList[j], seqNum);
|
||||
SequenceData sDat = ResourceMgr_LoadSeqByName(customSeqList[j]);
|
||||
sDat.seqNumber = i;
|
||||
sDat.seqNumber = seqNum;
|
||||
|
||||
char* str = malloc(strlen(customSeqList[j]) + 1);
|
||||
strcpy(str, customSeqList[j]);
|
||||
|
||||
sequenceMap[sDat.seqNumber] = str;
|
||||
seqNum++;
|
||||
}
|
||||
|
||||
free(customSeqList);
|
||||
|
Loading…
Reference in New Issue
Block a user