Skip to content

Commit

Permalink
overlord: move back to arrays for sound names
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziemas committed Nov 11, 2023
1 parent 8abd83c commit b20dcec
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 14 deletions.
6 changes: 2 additions & 4 deletions game/overlord/common/sbank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ void InitBanks() {
}

bank->unk4 = 0;

bank->name.resize(16);
strcpy(bank->name.data(), "<unused>");
}

Expand Down Expand Up @@ -122,7 +120,7 @@ s32 LookupSoundIndex(const char* name, SoundBank** bank_out) {
}

for (int i = 0; i < (int)bank->sound_count; i++) {
if (bank->sound[i].name == name) {
if (memcmp(bank->sound[i].name.data(), name, 16) == 0) {
*bank_out = bank;
return i;
}
Expand All @@ -141,7 +139,7 @@ SoundBank* LookupBank(const char* name) {
}
auto bank = gBanks[idx];

if (bank->name == name && bank->in_use) {
if ((memcmp(bank->name.data(), name, 16) == 0) && bank->in_use) {
return bank;
}
idx--;
Expand Down
4 changes: 2 additions & 2 deletions game/overlord/common/sbank.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#include "common/common_types.h"

struct SoundRecord {
std::string name{"<unused>"};
std::array<char, 16> name;
u32 fallof_params;
};

struct SoundBank {
std::string name{"<unused>"};
std::array<char, 16> name;
u32 bank_handle;
u32 sound_count;

Expand Down
4 changes: 2 additions & 2 deletions game/overlord/common/soundcommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ void PrintBankInfo(SoundBank* bank) {
// we dont need this and it spams the console too much
return;

printf("Bank %s\n\n", bank->name.c_str());
printf("Bank %s\n\n", bank->name.data());
for (u32 i = 0; i < bank->sound_count; i++) {
// Some characters use the full 16 characters (bonelurker-grunt) and dont have a null terminator
std::string name = std::string(bank->sound[i].name, 16);
std::string name = std::string(bank->sound[i].name.data(), 16);
printf("%d : %16s : min %d max %d curve %d\n", i, name.c_str(),
bank->sound[i].fallof_params & 0x3fff, (bank->sound[i].fallof_params >> 14) & 0x3fff,
bank->sound[i].fallof_params >> 28);
Expand Down
2 changes: 1 addition & 1 deletion game/overlord/common/ssound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ void PrintActiveSounds() {
for (auto& s : gSounds) {
if (s.id != 0 && s.is_music == 0) {
if (s.bank_entry != nullptr) {
u32 len = s.bank_entry->name.length();
u32 len = strlen(s.bank_entry->name.data());
if (len > 16) {
len = 16;
}
Expand Down
6 changes: 2 additions & 4 deletions game/overlord/jak1/fake_iso.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,13 @@ uint32_t FS_LoadMusic(char* name, s32* bank_handle) {
// original overlord uses good old fread into a struct instance
// lets use BinaryReader instead
static void parseSoundBank(BinaryReader data, SoundBank& bank) {
auto name = data.read<std::array<char, 16>>();
bank.name = name.data();
bank.name = data.read<std::array<char, 16>>();
bank.bank_handle = data.read<u32>();
bank.sound_count = data.read<u32>();
bank.sound.resize(bank.sound_count);

for (auto& snd : bank.sound) {
name = data.read<std::array<char, 16>>();
snd.name = name.data();
snd.name = data.read<std::array<char, 16>>();
snd.fallof_params = data.read<u32>();
}
}
Expand Down
2 changes: 1 addition & 1 deletion game/overlord/jak1/srpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,4 +508,4 @@ s32 VBlank_Handler(void*) {

return 1;
}
} // namespace jak1
} // namespace jak1

0 comments on commit b20dcec

Please sign in to comment.