diff --git a/config/GZ2E01/symbols.txt b/config/GZ2E01/symbols.txt index 23431e5ed7..8032ae73c2 100644 --- a/config/GZ2E01/symbols.txt +++ b/config/GZ2E01/symbols.txt @@ -22058,7 +22058,7 @@ data_80451274 = .sbss:0x80451274; // type:object size:0x1 scope:local align:4 da mNoLoad__16JASBasicWaveBank = .sbss:0x80451278; // type:object size:0x4 scope:global align:4 sUsedHeapSize__11JASWSParser = .sbss:0x80451280; // type:object size:0x4 scope:global align:4 data:4byte sUsedHeapSize__12JASBNKParser = .sbss:0x80451288; // type:object size:0x4 scope:global align:4 data:4byte -data_8045128C = .sbss:0x8045128C; // type:object size:0x1 scope:local align:4 data:byte +__init__memPool___46JASPoolAllocObject_MultiThreaded<10JASChannel> = .sbss:0x8045128C; // type:object size:0x1 scope:local align:4 data:byte sAramHeap__16JASWaveArcLoader = .sbss:0x80451290; // type:object size:0x4 scope:global align:4 data:4byte sBankDisposeListSize__10JASChannel = .sbss:0x80451298; // type:object size:0x4 scope:global align:4 data:4byte sDspDacBuffer__9JASDriver = .sbss:0x804512A0; // type:object size:0x4 scope:global align:4 data:4byte diff --git a/configure.py b/configure.py index 3d0617d508..554798a8d7 100755 --- a/configure.py +++ b/configure.py @@ -1031,7 +1031,7 @@ config.libs = [ Object(MatchingFor(ALL_GCN), "JSystem/JAudio2/JASBasicWaveBank.cpp"), Object(MatchingFor(ALL_GCN), "JSystem/JAudio2/JASSimpleWaveBank.cpp"), Object(MatchingFor(ALL_GCN), "JSystem/JAudio2/JASWSParser.cpp"), - Object(NonMatching, "JSystem/JAudio2/JASBNKParser.cpp"), # missing bss var + Object(MatchingFor(ALL_GCN), "JSystem/JAudio2/JASBNKParser.cpp"), Object(MatchingFor(ALL_GCN), "JSystem/JAudio2/JASWaveArcLoader.cpp"), Object(MatchingFor(ALL_GCN), "JSystem/JAudio2/JASChannel.cpp"), Object(MatchingFor(ALL_GCN), "JSystem/JAudio2/JASLfo.cpp"), @@ -1106,7 +1106,7 @@ config.libs = [ Object(Equivalent, "Z2AudioLib/Z2SceneMgr.cpp"), # weak func order Object(MatchingFor(ALL_GCN), "Z2AudioLib/Z2FxLineMgr.cpp"), Object(MatchingFor(ALL_GCN), "Z2AudioLib/Z2SoundInfo.cpp"), - Object(Equivalent, "Z2AudioLib/Z2Audience.cpp"), # weak func order + Object(MatchingFor(ALL_GCN), "Z2AudioLib/Z2Audience.cpp"), Object(MatchingFor(ALL_GCN), "Z2AudioLib/Z2SoundObject.cpp"), Object(MatchingFor(ALL_GCN), "Z2AudioLib/Z2SoundObjMgr.cpp"), Object(MatchingFor(ALL_GCN), "Z2AudioLib/Z2Creature.cpp"), diff --git a/include/JSystem/JAudio2/JASHeapCtrl.h b/include/JSystem/JAudio2/JASHeapCtrl.h index f7eda37587..5a7b2550f8 100644 --- a/include/JSystem/JAudio2/JASHeapCtrl.h +++ b/include/JSystem/JAudio2/JASHeapCtrl.h @@ -50,11 +50,18 @@ struct JASGenericMemPool { void* alloc(u32); void free(void*, u32); + u32 getFreeMemCount() const { + return freeMemCount; + } + + u32 getTotalMemCount() const { + return totalMemCount; + } + /* 0x00 */ void* field_0x0; /* 0x04 */ u32 freeMemCount; /* 0x08 */ u32 totalMemCount; /* 0x0C */ u32 usedMemCount; - }; namespace JASThreadingModel { @@ -87,6 +94,13 @@ namespace JASThreadingModel { A0* mMutex; }; }; + + template + struct SingleThreaded { + struct Lock { + Lock(const A0& param_0) {} + }; + }; }; // namespace JASThreadingModel /** @@ -96,17 +110,32 @@ namespace JASThreadingModel { template class JASMemPool : public JASGenericMemPool { public: - void newMemPool(int param_0) { JASGenericMemPool::newMemPool(sizeof(T), param_0); } + void newMemPool(int param_0) { + typename JASThreadingModel::SingleThreaded >::Lock lock(*this); + JASGenericMemPool::newMemPool(sizeof(T), param_0); + } void* alloc(u32 n) { JUT_ASSERT(182, n == sizeof(T)); + typename JASThreadingModel::SingleThreaded >::Lock lock(*this); return JASGenericMemPool::alloc(n); } void free(void* ptr, u32 n) { JUT_ASSERT(187, n == sizeof(T)); + typename JASThreadingModel::SingleThreaded >::Lock lock(*this); JASGenericMemPool::free(ptr, n); } + + u32 getFreeMemCount() const { + typename JASThreadingModel::SingleThreaded >::Lock lock(*this); + return JASGenericMemPool::getFreeMemCount(); + } + + u32 getTotalMemCount() const { + typename JASThreadingModel::SingleThreaded >::Lock lock(*this); + return JASGenericMemPool::getTotalMemCount(); + } }; namespace JASKernel { JKRHeap* getSystemHeap(); }; @@ -255,25 +284,35 @@ template class JASPoolAllocObject { public: static void* operator new(size_t n) { - JASMemPool* memPool = getMemPool_(); - return memPool->alloc(sizeof(T)); + JASMemPool& memPool_ = getMemPool_(); + return memPool_.alloc(n); } static void* operator new(size_t n, void* ptr) { return ptr; } static void operator delete(void* ptr, size_t n) { - JASMemPool* memPool_ = getMemPool_(); - memPool_->free(ptr, sizeof(T)); + JASMemPool& memPool_ = getMemPool_(); + memPool_.free(ptr, n); } static void newMemPool(int param_0) { - JASMemPool* memPool_ = getMemPool_(); - memPool_->newMemPool(param_0); + JASMemPool& memPool_ = getMemPool_(); + memPool_.newMemPool(param_0); + } + static u32 getFreeMemCount() { + JASMemPool& memPool_ = getMemPool_(); + return memPool_.getFreeMemCount(); + } + static u32 getTotalMemCount() { + JASMemPool& memPool_ = getMemPool_(); + return memPool_.getTotalMemCount(); } private: - static JASMemPool* getMemPool_() { + // Fakematch? Is memPool_ both an in-function static and an out-of-function static? + static JASMemPool memPool_; + static JASMemPool& getMemPool_() { static JASMemPool memPool_; - return &memPool_; + return memPool_; } }; @@ -308,25 +347,28 @@ template class JASPoolAllocObject_MultiThreaded { public: static void* operator new(size_t n) { - JASMemPool_MultiThreaded* memPool_ = getMemPool(); - return memPool_->alloc(sizeof(T)); + JASMemPool_MultiThreaded& memPool_ = getMemPool(); + return memPool_.alloc(sizeof(T)); } static void* operator new(size_t n, void* ptr) { return ptr; } static void operator delete(void* ptr, size_t n) { - JASMemPool_MultiThreaded* memPool_ = getMemPool(); - memPool_->free(ptr, sizeof(T)); + JASMemPool_MultiThreaded& memPool_ = getMemPool(); + memPool_.free(ptr, sizeof(T)); } static void newMemPool(int n) { - getMemPool()->newMemPool(n); + JASMemPool_MultiThreaded& memPool_ = getMemPool(); + memPool_.newMemPool(n); } private: - static JASMemPool_MultiThreaded* getMemPool() { + // Fakematch? Is memPool_ both an in-function static and an out-of-function static? + static JASMemPool_MultiThreaded memPool_; + static JASMemPool_MultiThreaded& getMemPool() { static JASMemPool_MultiThreaded memPool_; - return &memPool_; + return memPool_; } }; diff --git a/include/JSystem/JMath/JMATrigonometric.h b/include/JSystem/JMath/JMATrigonometric.h index 25b79a72dc..276ea2399e 100644 --- a/include/JSystem/JMath/JMATrigonometric.h +++ b/include/JSystem/JMath/JMATrigonometric.h @@ -31,28 +31,28 @@ struct TSinCosTable { T sinShort(s16 v) const { return table[(u16)v >> (16U - N)].first; } T cosShort(s16 v) const { return table[(u16)v >> (16U - N)].second; } - inline T sinLap(T v) { + inline T sinLap(T v) const { if (v < (T)0.0) { return -table[(u16)(-(T)(1 << N) * v) & ((1 << N) - 1)].first; } return table[(u16)((T)(1 << N) * v) & ((1 << N) - 1)].first; } - inline T sinDegree(T degree) { + inline T sinDegree(T degree) const { if (degree < (T)0.0) { return -table[(u16)(-((T)(1 << N) / (T)360.0) * degree) & ((1 << N) - 1)].first; } return table[(u16)(((T)(1 << N) / (T)360.0) * degree) & ((1 << N) - 1)].first; } - inline T cosDegree(T degree) { + inline T cosDegree(T degree) const { if (degree < (T)0.0) { degree = -degree; } return table[(u16)(((T)(1 << N) / (T)360.0) * degree) & ((1 << N) - 1)].second; } - inline T sinRadian(T radian) { + inline T sinRadian(T radian) const { if (radian < (T)0.0) { return -table[(u16)(-(T)(1 << N) / TAngleConstant_::RADIAN_DEG360() * radian) & ((1 << N) - 1)].first; } diff --git a/include/Z2AudioLib/Z2Audience.h b/include/Z2AudioLib/Z2Audience.h index 8b8dc99805..dd30b87948 100644 --- a/include/Z2AudioLib/Z2Audience.h +++ b/include/Z2AudioLib/Z2Audience.h @@ -221,6 +221,8 @@ struct Z2Audience : public JAIAudience, public JASGlobalInstance { virtual u32 calcPriority(JAIAudible* audible); virtual void mixChannelOut(const JASSoundParams& outParams, JAIAudible* audible, int channelNum); + bool isActive() const; + Z2SpotMic* getLinkMic() { return mLinkMic; } JGeometry::TVec3 getAudioCamPos(int camID) { return *mAudioCamera[camID].getPos(); diff --git a/src/JSystem/JAudio2/JASAramStream.cpp b/src/JSystem/JAudio2/JASAramStream.cpp index ba010aeb9b..32cbf21603 100644 --- a/src/JSystem/JAudio2/JASAramStream.cpp +++ b/src/JSystem/JAudio2/JASAramStream.cpp @@ -498,7 +498,7 @@ void JASAramStream::updateChannel(u32 i_callbackType, JASChannel* i_channel, field_0x0b4 = i_dspChannel->field_0x074 + i_dspChannel->field_0x064; if (field_0x118 >= field_0x160 - 2) { JUT_WARN_DEVICE(810, 1, "%s", "buffer under error"); - field_0x0ae |= 4; + field_0x0ae |= (u8)4; } } else { if (field_0x12c & 1) { diff --git a/src/JSystem/JAudio2/JASBNKParser.cpp b/src/JSystem/JAudio2/JASBNKParser.cpp index f789774cde..dbaad63bee 100644 --- a/src/JSystem/JAudio2/JASBNKParser.cpp +++ b/src/JSystem/JAudio2/JASBNKParser.cpp @@ -305,3 +305,7 @@ JASOscillator::Point const* JASBNKParser::Ver0::getOscTableEndPtr(JASOscillator: } while (tmp <= 10); return points; } + +// Fakematch? Why is this here? +template<> +JASMemPool_MultiThreaded JASPoolAllocObject_MultiThreaded::memPool_; diff --git a/src/JSystem/JAudio2/JASHeapCtrl.cpp b/src/JSystem/JAudio2/JASHeapCtrl.cpp index d244adb0c2..af2c9b953a 100644 --- a/src/JSystem/JAudio2/JASHeapCtrl.cpp +++ b/src/JSystem/JAudio2/JASHeapCtrl.cpp @@ -195,11 +195,19 @@ JASGenericMemPool::~JASGenericMemPool() { JKRSolidHeap* JASDram; -void JASGenericMemPool::newMemPool(u32 size, int param_1) { +// TODO: What is this and Where does it go? +struct TNextOnFreeList { + u8 pad[4]; +}; // Size: 0x4 + +void JASGenericMemPool::newMemPool(u32 n, int param_1) { + JUT_ASSERT(734, n >= sizeof(TNextOnFreeList)); + void* runner; for (int i = 0; i < param_1; i++) { - void* chunk = new (JASDram, 0) u8[size]; - *(void**)chunk = field_0x0; - field_0x0 = chunk; + runner = new (JASDram, 0) u8[n]; + JUT_ASSERT(739, runner); + *(void**)runner = field_0x0; + field_0x0 = runner; } freeMemCount += param_1; totalMemCount += param_1; diff --git a/src/Z2AudioLib/Z2Audience.cpp b/src/Z2AudioLib/Z2Audience.cpp index dd7baa72ca..fa466f962b 100644 --- a/src/Z2AudioLib/Z2Audience.cpp +++ b/src/Z2AudioLib/Z2Audience.cpp @@ -500,7 +500,11 @@ Z2Audience::Z2Audience() : JASGlobalInstance(true), field_0x4(1.0f), } Z2Audience::~Z2Audience() { - // JUT_ASSERT(751, !isActive()); // TODO: need to setup rest of JASMemPool stuff + JUT_ASSERT(751, !isActive()); +} + +bool Z2Audience::isActive() const { + return Z2Audible::getTotalMemCount() != Z2Audible::getFreeMemCount(); } void Z2Audience::setAudioCamera(f32 (*param_0)[4], Vec& pos, Vec& param_2, f32 param_3,