Expose assets lua callbacks to patch contexts
This commit is contained in:
parent
9ef38ce076
commit
4a3ffadecb
@ -17,7 +17,6 @@ end
|
|||||||
function patch(config)
|
function patch(config)
|
||||||
local layout = config.paneLayout
|
local layout = config.paneLayout
|
||||||
layout.panefeature.positionLocked = false
|
layout.panefeature.positionLocked = false
|
||||||
|
|
||||||
-- Create the camera pan speed widgets
|
-- Create the camera pan speed widgets
|
||||||
shift(clone(layout, "zoomLabel", "cameraSpeedLabel"), 100).value = "CAMERA PAN SPEED"
|
shift(clone(layout, "zoomLabel", "cameraSpeedLabel"), 100).value = "CAMERA PAN SPEED"
|
||||||
shift(clone(layout, "zoomSlider", "cameraSpeedSlider"), 100)
|
shift(clone(layout, "zoomSlider", "cameraSpeedSlider"), 100)
|
||||||
@ -26,7 +25,6 @@ function patch(config)
|
|||||||
config.cameraSpeedList = jarray()
|
config.cameraSpeedList = jarray()
|
||||||
for i = 1, 50 do config.cameraSpeedList[i] = i / 10 end
|
for i = 1, 50 do config.cameraSpeedList[i] = i / 10 end
|
||||||
for i = 1, 32 do config.zoomList[i] = i end
|
for i = 1, 32 do config.zoomList[i] = i end
|
||||||
|
|
||||||
-- Create anti-aliasing toggle
|
-- Create anti-aliasing toggle
|
||||||
shift(clone(layout, "multiTextureLabel", "antiAliasingLabel"), 98).value = "SUPER-SAMPLED AA"
|
shift(clone(layout, "multiTextureLabel", "antiAliasingLabel"), 98).value = "SUPER-SAMPLED AA"
|
||||||
shift(clone(layout, "multiTextureCheckbox", "antiAliasingCheckbox"), 99)
|
shift(clone(layout, "multiTextureCheckbox", "antiAliasingCheckbox"), 99)
|
||||||
|
@ -161,7 +161,7 @@ public:
|
|||||||
virtual void render(RenderPrimitive primitive) = 0;
|
virtual void render(RenderPrimitive primitive) = 0;
|
||||||
virtual void renderBuffer(RenderBufferPtr const& renderBuffer, Mat3F const& transformation = Mat3F::identity()) = 0;
|
virtual void renderBuffer(RenderBufferPtr const& renderBuffer, Mat3F const& transformation = Mat3F::identity()) = 0;
|
||||||
|
|
||||||
virtual void flush() = 0;
|
virtual void flush(Mat3F const& transformation = Mat3F::identity()) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -482,8 +482,8 @@ void OpenGlRenderer::renderBuffer(RenderBufferPtr const& renderBuffer, Mat3F con
|
|||||||
renderGlBuffer(*convert<GlRenderBuffer>(renderBuffer.get()), transformation);
|
renderGlBuffer(*convert<GlRenderBuffer>(renderBuffer.get()), transformation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGlRenderer::flush() {
|
void OpenGlRenderer::flush(Mat3F const& transformation) {
|
||||||
flushImmediatePrimitives();
|
flushImmediatePrimitives(transformation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGlRenderer::setScreenSize(Vec2U screenSize) {
|
void OpenGlRenderer::setScreenSize(Vec2U screenSize) {
|
||||||
@ -889,13 +889,13 @@ void OpenGlRenderer::uploadTextureImage(PixelFormat pixelFormat, Vec2U size, uin
|
|||||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat.value(format), size[0], size[1], 0, format, type, data);
|
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat.value(format), size[0], size[1], 0, format, type, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGlRenderer::flushImmediatePrimitives() {
|
void OpenGlRenderer::flushImmediatePrimitives(Mat3F const& transformation) {
|
||||||
if (m_immediatePrimitives.empty())
|
if (m_immediatePrimitives.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_immediateRenderBuffer->set(m_immediatePrimitives);
|
m_immediateRenderBuffer->set(m_immediatePrimitives);
|
||||||
m_immediatePrimitives.resize(0);
|
m_immediatePrimitives.resize(0);
|
||||||
renderGlBuffer(*m_immediateRenderBuffer, Mat3F::identity());
|
renderGlBuffer(*m_immediateRenderBuffer, transformation);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto OpenGlRenderer::createGlTexture(ImageView const& image, TextureAddressing addressing, TextureFiltering filtering)
|
auto OpenGlRenderer::createGlTexture(ImageView const& image, TextureAddressing addressing, TextureFiltering filtering)
|
||||||
|
@ -42,7 +42,7 @@ public:
|
|||||||
void render(RenderPrimitive primitive) override;
|
void render(RenderPrimitive primitive) override;
|
||||||
void renderBuffer(RenderBufferPtr const& renderBuffer, Mat3F const& transformation) override;
|
void renderBuffer(RenderBufferPtr const& renderBuffer, Mat3F const& transformation) override;
|
||||||
|
|
||||||
void flush() override;
|
void flush(Mat3F const& transformation) override;
|
||||||
|
|
||||||
void setScreenSize(Vec2U screenSize);
|
void setScreenSize(Vec2U screenSize);
|
||||||
|
|
||||||
@ -205,7 +205,7 @@ private:
|
|||||||
|
|
||||||
shared_ptr<GlRenderBuffer> createGlRenderBuffer();
|
shared_ptr<GlRenderBuffer> createGlRenderBuffer();
|
||||||
|
|
||||||
void flushImmediatePrimitives();
|
void flushImmediatePrimitives(Mat3F const& transformation = Mat3F::identity());
|
||||||
|
|
||||||
void renderGlBuffer(GlRenderBuffer const& renderBuffer, Mat3F const& transformation);
|
void renderGlBuffer(GlRenderBuffer const& renderBuffer, Mat3F const& transformation);
|
||||||
|
|
||||||
|
@ -118,8 +118,8 @@ Assets::Assets(Settings settings, StringList assetSources) {
|
|||||||
table.set(p.first, luaEngine->createWrappedFunction(p.second));
|
table.set(p.first, luaEngine->createWrappedFunction(p.second));
|
||||||
luaEngine->setGlobal(name, table);
|
luaEngine->setGlobal(name, table);
|
||||||
};
|
};
|
||||||
pushGlobalContext("sb", LuaBindings::makeUtilityCallbacks());
|
|
||||||
auto decorateLuaContext = [this](LuaContext& context, MemoryAssetSourcePtr newFiles) {
|
auto makeBaseAssetCallbacks = [this]() {
|
||||||
LuaCallbacks callbacks;
|
LuaCallbacks callbacks;
|
||||||
callbacks.registerCallbackWithSignature<StringSet, String>("byExtension", bind(&Assets::scanExtension, this, _1));
|
callbacks.registerCallbackWithSignature<StringSet, String>("byExtension", bind(&Assets::scanExtension, this, _1));
|
||||||
callbacks.registerCallbackWithSignature<Json, String>("json", bind(&Assets::json, this, _1));
|
callbacks.registerCallbackWithSignature<Json, String>("json", bind(&Assets::json, this, _1));
|
||||||
@ -140,7 +140,14 @@ Assets::Assets(Settings settings, StringList assetSources) {
|
|||||||
callbacks.registerCallback("scan", [this](Maybe<String> const& a, Maybe<String> const& b) -> StringList {
|
callbacks.registerCallback("scan", [this](Maybe<String> const& a, Maybe<String> const& b) -> StringList {
|
||||||
return b ? scan(a.value(), *b) : scan(a.value());
|
return b ? scan(a.value(), *b) : scan(a.value());
|
||||||
});
|
});
|
||||||
|
return callbacks;
|
||||||
|
};
|
||||||
|
|
||||||
|
pushGlobalContext("sb", LuaBindings::makeUtilityCallbacks());
|
||||||
|
pushGlobalContext("assets", makeBaseAssetCallbacks());
|
||||||
|
|
||||||
|
auto decorateLuaContext = [&](LuaContext& context, MemoryAssetSourcePtr newFiles) {
|
||||||
|
auto callbacks = makeBaseAssetCallbacks();
|
||||||
if (newFiles) {
|
if (newFiles) {
|
||||||
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;
|
||||||
@ -872,7 +879,7 @@ ImageConstPtr Assets::readImage(String const& path) const {
|
|||||||
image = make_shared<Image>(Image::readPng(p->source->open(p->sourceName)));
|
image = make_shared<Image>(Image::readPng(p->source->open(p->sourceName)));
|
||||||
|
|
||||||
if (!p->patchSources.empty()) {
|
if (!p->patchSources.empty()) {
|
||||||
MutexLocker luaLocker(m_luaMutex);
|
RecursiveMutexLocker luaLocker(m_luaMutex);
|
||||||
LuaEngine* luaEngine = as<LuaEngine>(m_luaEngine.get());
|
LuaEngine* luaEngine = as<LuaEngine>(m_luaEngine.get());
|
||||||
LuaValue result = luaEngine->createUserData(*image);
|
LuaValue result = luaEngine->createUserData(*image);
|
||||||
luaLocker.unlock();
|
luaLocker.unlock();
|
||||||
@ -953,7 +960,7 @@ Json Assets::readJson(String const& path) const {
|
|||||||
auto& patchSource = pair.second;
|
auto& patchSource = pair.second;
|
||||||
auto patchStream = patchSource->read(patchPath);
|
auto patchStream = patchSource->read(patchPath);
|
||||||
if (patchPath.endsWith(".lua")) {
|
if (patchPath.endsWith(".lua")) {
|
||||||
MutexLocker luaLocker(m_luaMutex);
|
RecursiveMutexLocker luaLocker(m_luaMutex);
|
||||||
// Kae: i don't like that lock. perhaps have a LuaEngine and patch context cache per worker thread later on?
|
// Kae: i don't like that lock. perhaps have a LuaEngine and patch context cache per worker thread later on?
|
||||||
LuaContextPtr& context = m_patchContexts[patchPath];
|
LuaContextPtr& context = m_patchContexts[patchPath];
|
||||||
if (!context) {
|
if (!context) {
|
||||||
|
@ -320,7 +320,7 @@ private:
|
|||||||
// Lua
|
// Lua
|
||||||
RefPtr<RefCounter> m_luaEngine; // dumb but to avoid including Lua.hpp in here...
|
RefPtr<RefCounter> m_luaEngine; // dumb but to avoid including Lua.hpp in here...
|
||||||
mutable StringMap<LuaContextPtr> m_patchContexts;
|
mutable StringMap<LuaContextPtr> m_patchContexts;
|
||||||
mutable Mutex m_luaMutex;
|
mutable RecursiveMutex m_luaMutex;
|
||||||
|
|
||||||
// Paths of all used asset sources, in load order.
|
// Paths of all used asset sources, in load order.
|
||||||
StringList m_assetSources;
|
StringList m_assetSources;
|
||||||
|
Loading…
Reference in New Issue
Block a user