oops - restore assets modification to load scripts

This commit is contained in:
Kae 2024-04-08 18:10:09 +10:00
parent 4a3ffadecb
commit b89b8d585e
2 changed files with 7 additions and 5 deletions

View File

@ -147,8 +147,10 @@ Assets::Assets(Settings settings, StringList assetSources) {
pushGlobalContext("assets", makeBaseAssetCallbacks()); pushGlobalContext("assets", makeBaseAssetCallbacks());
auto decorateLuaContext = [&](LuaContext& context, MemoryAssetSourcePtr newFiles) { auto decorateLuaContext = [&](LuaContext& context, MemoryAssetSourcePtr newFiles) {
auto callbacks = makeBaseAssetCallbacks();
if (newFiles) { if (newFiles) {
// re-add the assets callbacks with more functions
context.remove("assets");
auto callbacks = makeBaseAssetCallbacks();
callbacks.registerCallback("add", [&newFiles](LuaEngine& engine, String const& path, LuaValue const& data) { callbacks.registerCallback("add", [&newFiles](LuaEngine& engine, String const& path, LuaValue const& data) {
ByteArray bytes; ByteArray bytes;
if (auto str = engine.luaMaybeTo<String>(data)) if (auto str = engine.luaMaybeTo<String>(data))
@ -184,9 +186,9 @@ Assets::Assets(Settings settings, StringList assetSources) {
m_filesByExtension[AssetPath::extension(path).toLower()].erase(path); m_filesByExtension[AssetPath::extension(path).toLower()].erase(path);
return erased; return erased;
}); });
}
context.setCallbacks("assets", callbacks); context.setCallbacks("assets", callbacks);
}
}; };
auto addSource = [&](String const& sourcePath, AssetSourcePtr source) { auto addSource = [&](String const& sourcePath, AssetSourcePtr source) {

View File

@ -231,6 +231,7 @@ void Mixer::stopAll(float rampTime) {
void Mixer::read(int16_t* outBuffer, size_t frameCount, ExtraMixFunction extraMixFunction) { void Mixer::read(int16_t* outBuffer, size_t frameCount, ExtraMixFunction extraMixFunction) {
// Make this method as least locky as possible by copying all the needed // Make this method as least locky as possible by copying all the needed
// member data before the expensive audio / effect stuff. // member data before the expensive audio / effect stuff.
float speed;
unsigned sampleRate; unsigned sampleRate;
unsigned channels; unsigned channels;
float volume; float volume;
@ -240,6 +241,7 @@ void Mixer::read(int16_t* outBuffer, size_t frameCount, ExtraMixFunction extraMi
{ {
MutexLocker locker(m_mutex); MutexLocker locker(m_mutex);
speed = m_speed;
sampleRate = m_sampleRate; sampleRate = m_sampleRate;
channels = m_channels; channels = m_channels;
volume = m_volume.value; volume = m_volume.value;
@ -266,8 +268,6 @@ void Mixer::read(int16_t* outBuffer, size_t frameCount, ExtraMixFunction extraMi
for (size_t i = 0; i < bufferSize; ++i) for (size_t i = 0; i < bufferSize; ++i)
outBuffer[i] = 0; outBuffer[i] = 0;
float speed = m_speed;
{ {
MutexLocker locker(m_queueMutex); MutexLocker locker(m_queueMutex);
// Mix all active sounds // Mix all active sounds