mirror of
https://github.com/whoahq/whoa.git
synced 2026-02-01 00:02:45 +03:00
feat(sound): add support for caching disk sounds
This commit is contained in:
parent
b2447e7197
commit
d4cd3e4bc1
@ -9,6 +9,7 @@
|
||||
#define LOG_WRITE(result, ...) \
|
||||
SESound::Log_Write(__LINE__, __FILE__, result, __VA_ARGS__);
|
||||
|
||||
STORM_LIST(SoundCacheNode) SESound::s_CacheList;
|
||||
SCritSect SESound::s_CritSect3;
|
||||
int32_t SESound::s_Initialized;
|
||||
SCritSect SESound::s_InternalCritSect;
|
||||
@ -86,7 +87,7 @@ FMOD_RESULT DoneLoadingCallback(FMOD_SOUND* fmodSound, FMOD_RESULT callbackResul
|
||||
// Mark cache sound node as loaded
|
||||
|
||||
if (lookup->m_internal->m_useCache) {
|
||||
static_cast<SEDiskSound*>(lookup->m_internal)->m_cacheNode->loaded = 1;
|
||||
static_cast<SEDiskSound*>(lookup->m_internal)->m_cacheNode->m_loaded = 1;
|
||||
}
|
||||
|
||||
SESound::s_LoadingCritSect.Leave();
|
||||
@ -390,13 +391,44 @@ int32_t SESound::LoadDiskSound(FMOD::System* fmodSystem, const char* filename, F
|
||||
}
|
||||
}
|
||||
|
||||
// Generate name
|
||||
|
||||
char fmodName[300];
|
||||
SStrPrintf(fmodName, sizeof(fmodName), "%-24d%s", internal->m_uniqueID, filename);
|
||||
|
||||
// TODO
|
||||
// Generate cache key
|
||||
|
||||
char cacheKey[400];
|
||||
auto loopStr = fmodMode & FMOD_LOOP_NORMAL ? "_LOOP_" : "_NOLOOP_";
|
||||
auto positionStr = fmodMode & FMOD_2D ? "_2D_" : "_3D_";
|
||||
SStrPrintf(cacheKey, sizeof(cacheKey), "%s%s%s", filename, positionStr, loopStr);
|
||||
|
||||
auto cacheHashval = SStrHash(cacheKey);
|
||||
|
||||
// Load from cache
|
||||
|
||||
if (useCache) {
|
||||
// TODO
|
||||
for (auto cacheNode = SESound::s_CacheList.Head(); cacheNode; cacheNode = SESound::s_CacheList.Link(cacheNode)->Next()) {
|
||||
if (cacheNode->m_hashval == cacheHashval) {
|
||||
// Cache hit
|
||||
|
||||
internal->m_fmodSound = cacheNode->m_fmodSound;
|
||||
internal->m_useCache = 1;
|
||||
internal->m_cacheNode = cacheNode;
|
||||
|
||||
// TODO
|
||||
|
||||
if (cacheNode->m_loaded) {
|
||||
internal->m_nonblockingReady = 1;
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
||||
SESound::s_LoadingCritSect.Leave();
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Validate file exists
|
||||
@ -415,8 +447,6 @@ int32_t SESound::LoadDiskSound(FMOD::System* fmodSystem, const char* filename, F
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t nonblockingReady = 0;
|
||||
|
||||
fmodMode |= FMOD_VIRTUAL_PLAYFROMSTART | FMOD_IGNORETAGS | FMOD_NONBLOCKING;
|
||||
|
||||
uint32_t maxCacheSize = 1048576;
|
||||
@ -462,14 +492,25 @@ int32_t SESound::LoadDiskSound(FMOD::System* fmodSystem, const char* filename, F
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Create cache node
|
||||
|
||||
if (useCache) {
|
||||
auto cacheNode = STORM_NEW(SoundCacheNode);
|
||||
|
||||
cacheNode->m_fmodSound = internal->m_fmodSound;
|
||||
cacheNode->m_hashval = cacheHashval;
|
||||
SStrCopy(cacheNode->m_filename, filename, sizeof(cacheNode->m_filename));
|
||||
|
||||
// TODO
|
||||
|
||||
internal->m_useCache = 1;
|
||||
internal->m_cacheNode = cacheNode;
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
||||
// Used to permit instant playback of cached sounds
|
||||
internal->m_nonblockingReady = nonblockingReady;
|
||||
// No cache hit (yet)
|
||||
internal->m_nonblockingReady = 0;
|
||||
|
||||
s_LoadingCritSect.Leave();
|
||||
|
||||
|
||||
@ -14,6 +14,7 @@ struct SOUND_INTERNAL_LOOKUP : TSHashObject<SOUND_INTERNAL_LOOKUP, HASHKEY_NONE>
|
||||
class SESound {
|
||||
public:
|
||||
// Public static variables
|
||||
static STORM_LIST(SoundCacheNode) s_CacheList;
|
||||
static SCritSect s_CritSect3;
|
||||
static int32_t s_Initialized;
|
||||
static SCritSect s_InternalCritSect;
|
||||
|
||||
@ -4,6 +4,10 @@
|
||||
#define LOG_WRITE(result, ...) \
|
||||
SESound::Log_Write(__LINE__, __FILE__, result, __VA_ARGS__);
|
||||
|
||||
SoundCacheNode::SoundCacheNode() {
|
||||
SESound::s_CacheList.LinkToTail(this);
|
||||
}
|
||||
|
||||
SESoundInternal::SESoundInternal() {
|
||||
// TODO
|
||||
this->m_uniqueID = SESound::s_UniqueID++;
|
||||
|
||||
@ -8,14 +8,18 @@
|
||||
class SESound;
|
||||
class SFile;
|
||||
|
||||
struct SoundCacheNode : TSLinkedNode<SoundCacheNode> {
|
||||
// Member variables
|
||||
FMOD::Sound* sound;
|
||||
int32_t loaded;
|
||||
char filename[128];
|
||||
uint32_t hashval;
|
||||
// TODO dword94
|
||||
// TODO dword98
|
||||
class SoundCacheNode : public TSLinkedNode<SoundCacheNode> {
|
||||
public:
|
||||
// Member variables
|
||||
FMOD::Sound* m_fmodSound = nullptr;
|
||||
int32_t m_loaded = 0;
|
||||
char m_filename[128];
|
||||
uint32_t m_hashval = 0;
|
||||
// TODO dword94
|
||||
// TODO dword98
|
||||
|
||||
// Member functions
|
||||
SoundCacheNode();
|
||||
};
|
||||
|
||||
class SESoundInternal : public TSLinkedNode<SESoundInternal> {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user